jaypie
Prerequisites: Node.js 22+
Overview
Section titled âOverviewâThe jaypie package is the main entry point for Jaypie applications.
It re-exports utilities from multiple Jaypie packages for convenient single-import access.
Installation
Section titled âInstallationânpm install jaypieQuick Reference
Section titled âQuick ReferenceâRe-exported Packages
Section titled âRe-exported Packagesâ| Package | Exports |
|---|---|
@jaypie/aws |
getEnvSecret, getSecret, loadEnvSecrets, sendMessage, getMessages |
@jaypie/datadog |
submitMetric |
@jaypie/errors |
All error classes, isJaypieError, jaypieErrorFromStatus |
@jaypie/express |
expressHandler, expressStreamHandler, cors |
@jaypie/kit |
force, uuid, sleep, cloneDeep, environment checks |
@jaypie/lambda |
lambdaHandler, lambdaStreamHandler |
@jaypie/logger |
log |
Exports
Section titled âExportsâError Classes
Section titled âError Classesâimport { BadGatewayError, BadRequestError, ConfigurationError, ForbiddenError, GatewayTimeoutError, GoneError, InternalError, MethodNotAllowedError, NotFoundError, NotImplementedError, RejectedError, TeapotError, TooManyRequestsError, UnavailableError, UnauthorizedError, isJaypieError, jaypieErrorFromStatus,} from "jaypie";Handlers
Section titled âHandlersâimport { expressHandler, expressStreamHandler, lambdaHandler, lambdaStreamHandler, cors,} from "jaypie";Logging
Section titled âLoggingâimport { log } from "jaypie";
log.trace("message");log.debug("message");log.info("message");log.warn("message");log.error("message");log.fatal("message");log.var({ key: value });Utilities
Section titled âUtilitiesâimport { cloneDeep, force, sleep, uuid,} from "jaypie";
// Type coercionforce.array(value);force.boolean(value);force.number(value);force.object(value);force.positive(value);force.string(value);
// UUID generationconst id = uuid();
// Async sleepawait sleep(1000);
// Deep cloneconst copy = cloneDeep(original);Environment Checks
Section titled âEnvironment Checksâimport { isLocalEnv, isNodeTestEnv, isProductionEnv,} from "jaypie";
if (isLocalEnv()) { /* PROJECT_ENV === "local" */ }if (isProductionEnv()) { /* PROJECT_ENV === "production" */ }if (isNodeTestEnv()) { /* NODE_ENV === "test" */ }AWS Integration
Section titled âAWS Integrationâimport { getEnvSecret, getMessages, getSecret, getSingletonMessage, loadEnvSecrets, sendMessage,} from "jaypie";
// Secretsconst secret = await getEnvSecret("API_KEY");await loadEnvSecrets("API_KEY", "DB_URI");
// SQSawait sendMessage({ data: "payload" });const messages = getMessages(sqsEvent);Datadog
Section titled âDatadogâimport { submitMetric } from "jaypie";
submitMetric("api.requests", 1, { endpoint: "/users" });Constants
Section titled âConstantsâimport { HTTP, JAYPIE } from "jaypie";
HTTP.CODE.OK; // 200HTTP.CODE.NOT_FOUND; // 404JAYPIE.LIB.EXPRESS; // "@jaypie/express"Usage Examples
Section titled âUsage ExamplesâExpress Handler
Section titled âExpress Handlerâimport { expressHandler, log, NotFoundError } from "jaypie";
export default expressHandler( async (req, res) => { log.trace("[getUser] fetching"); const user = await db.users.findById(req.params.id); if (!user) throw NotFoundError(); return { data: user }; }, { name: "getUser", secrets: ["MONGODB_URI"], });Lambda Handler
Section titled âLambda Handlerâimport { lambdaHandler, log, getMessages } from "jaypie";
export const handler = lambdaHandler( async (event) => { const messages = getMessages(event); for (const msg of messages) { log.trace("[process] handling message"); await processMessage(msg); } return { processed: messages.length }; }, { name: "processQueue", });Peer Dependencies
Section titled âPeer DependenciesâFor additional functionality, install optional packages:
# LLM integrationnpm install @jaypie/llm
# CDK constructsnpm install @jaypie/constructsRelated
Section titled âRelatedâ- Handler Lifecycle - Handler patterns
- Error Handling - Error types
- Logging - Logging best practices
- @jaypie/kit - Utility functions