### Basic Wretch Client Setup and Usage Source: https://backpack.ns.nl/how-tos/rest-client Demonstrates how to initialize a Wretch client with a base URL and headers, and then make GET and PUT requests. Requires the 'wretch' library to be installed. ```typescript import wretch from "wretch"; const bookStoreClient = wretch() .url("https://my-book-store.com") .headers({ "X-Some-Api-Key": "..." }); const books = await bookStoreClient .get("/api/v1/books") .json(); await bookStoreClient .body({ isbn: "1234", title: "My book" }) .put("/api/v1/books"); ``` -------------------------------- ### Renovate Configuration Example Source: https://backpack.ns.nl/guides/cicd/renovate A starting point for your `renovate.json`. This configuration includes settings for npm packages, private package authentication via Nexus, and automerging for minor and patch updates. ```json { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:recommended" ], "hostRules": [ { "hostType": "npm", "matchHost": "nexus.topaas.ns.nl", "token": "{{ secrets.NEXUS_TOKEN }}", "authType": "Basic" } ], "addLabels": [ "renovate" ], "azure-pipelines": { "enabled": true }, "packageRules": [ { "matchPackagePatterns": [ "*" ], "matchManagers": [ "npm" ], "matchUpdateTypes": [ "patch", "minor" ], "groupName": "all minor and patch dependencies", "groupSlug": "all-minor-patch", "automerge": true, "autoApprove": true }, { "extends": [ "schedule:weekly" ], "matchManagers": [ "azure-pipelines" ], "matchDepNames": [ "CICD/pipeline-templates" ], "versioning": "semver", "automerge": true, "autoApprove": true }, { "matchDatasources": [ "azure-pipelines-tasks" ], "extractVersion": "^(?\\d+)" } ] } ``` -------------------------------- ### Install @backpack/mockserver-client Source: https://backpack.ns.nl/packages/@backpack/mockserver-client Install the mockserver client package using npm. ```bash npm install @backpack/mockserver-client ``` -------------------------------- ### Install @backpack/rest-client Source: https://backpack.ns.nl/packages/@backpack/rest-client Install the package using npm. Ensure Nexus is set up as a private registry. ```bash npm install @backpack/rest-client ``` -------------------------------- ### Install Dependencies Source: https://backpack.ns.nl/packages/@backpack/vite-plugin-lambda Install the plugin and its peer dependencies using npm. ```bash npm install -D @backpack/vite-plugin-lambda npm install -D vite express @types/express ``` -------------------------------- ### Quick Start with useMockServer (In-Memory) Source: https://backpack.ns.nl/packages/@backpack/mockserver-client Set up an in-memory mock server and define a mock response for a GET request. Verifies the response and checks if the request was received. ```typescript import { useMockServer } from "@backpack/mockserver-client/vitest"; const mockServer = useMockServer({ type: "in-memory" }).setup(); it("returns a greeting", async () => { await mockServer.whenGet("/hello").respondText("Hi!"); const res = await fetch("/hello"); const text = await res.text(); expect(text).toBe("Hi!"); await expect(mockServer).toHaveReceivedRequest({ method: "GET", path: "/hello", }); }); ``` -------------------------------- ### Install New Dependencies Source: https://backpack.ns.nl/guides/migrating/hono Install Hono, @backpack/hono, Vite, and @hono/vite-dev-server using npm. ```bash npm install -D hono @backpack/hono vite @hono/vite-dev-server ``` -------------------------------- ### Install @backpack/hono-mockserver Source: https://backpack.ns.nl/packages/@backpack/hono-mockserver Install the package using npm. Ensure Nexus is set up as a private registry beforehand. ```bash npm install @backpack/hono-mockserver ``` -------------------------------- ### Install @backpack/error-handling Source: https://backpack.ns.nl/packages/@backpack/error-handling Install the package using npm. Ensure Nexus is set up as a private registry. ```bash npm install @backpack/error-handling ``` -------------------------------- ### OpenAPI Specification for /hello/{name} Source: https://backpack.ns.nl/rfc/hono-adoption-v2 An example OpenAPI specification defining a GET endpoint with a path parameter and a JSON response. ```yaml paths: /hello/{name}: get: parameters: - name: name in: path required: true schema: type: string responses: "200": description: Successful response content: application/json: schema: type: object required: - message properties: message: type: string ``` -------------------------------- ### Install @backpack/cdk-constructs Source: https://backpack.ns.nl/packages/@backpack/cdk-constructs Install the package using npm. Ensure Nexus is set up as a private registry beforehand. ```bash npm install @backpack/cdk-constructs ``` -------------------------------- ### Example Prompts for Project Information Source: https://backpack.ns.nl/guides/tooling/ai Example prompts to query an AI agent for specific information about Backpack packages, versions, and Node.js compatibility. ```text Hi, do you know which packages are included in Backpack? What is the latest Backpack version right now? Which Node.js version should I use for this Backpack project? ``` -------------------------------- ### Install @backpack/aws-lambda Source: https://backpack.ns.nl/packages/@backpack/aws-lambda Install the package using npm. Ensure Nexus is set up as a private registry. ```bash npm install @backpack/aws-lambda ``` -------------------------------- ### Install Hono and @backpack/hono Source: https://backpack.ns.nl/guides/tooling/local-development Install Hono and the @backpack/hono package as development dependencies. ```bash npm install -D hono @backpack/hono ``` -------------------------------- ### Install AWS SDK Client Source: https://backpack.ns.nl/packages/@backpack/aws-secrets-manager Install the necessary AWS SDK client for Secrets Manager. ```bash npm install @aws-sdk/client-secrets-manager ``` -------------------------------- ### Install @backpack/hono Source: https://backpack.ns.nl/packages/@backpack/hono Install the package using npm. Ensure Nexus is set up as a private registry. ```bash npm install @backpack/hono ``` -------------------------------- ### Bootstrap DI Container for Lambda Cold Start Source: https://backpack.ns.nl/guides/development/dependency-injection Bootstrap the DI container during the cold start of your lambda function to leverage performance boosts. This example uses `@needle-di/core`. ```typescript import { bootstrapAsync } from "@needle-di/core"; import { defineRestLambda } from "@backpack/aws-lambda"; // on cold start, bootstrap a new instance with dependency injection const addBookLambda = await bootstrapAsync(AddBookLambda); // AWS Lambda handler export const handler = defineRestLambda((event) => { return addBookLambda.handle(event); }); ``` -------------------------------- ### Mockserver Client API - Basic Examples Source: https://backpack.ns.nl/packages/@backpack/mockserver-client Defines basic mock responses for GET requests and general API paths using glob patterns. ```APIDOC ## Mockserver Client API - Basic Examples ### Description Provides examples of how to set up mock responses for specific HTTP methods and paths. ### Method `whenGet` and `when` ### Endpoint `/hello` and `/api/**` ### Parameters - `whenGet("/hello")`: Sets up a mock for a GET request to the `/hello` endpoint. - `when("GET", "/api/**")`: Sets up a mock for a GET request to any path under `/api/`. ### Request Example ```ts await mockServer.whenGet("/hello").respondText("Hoi!"); await mockServer.when("GET", "/api/**").respondJson({ ok: true }); ``` ### Response - `respondText("Hoi!")`: Responds with plain text. - `respondJson({ ok: true })`: Responds with JSON. ``` -------------------------------- ### Install @backpack/http package Source: https://backpack.ns.nl/packages/@backpack/http Install the package using npm. Ensure Nexus is set up as a private registry. ```bash npm install @backpack/http ``` -------------------------------- ### Example YAML Configuration Source: https://backpack.ns.nl/packages/@backpack/config Provide configuration values in YAML format, ensuring they match the defined schema. ```yaml service: My Bookstore clients: foo: baseUrl: https://path.to/foo timeoutMilliseconds: 500 # ... ``` -------------------------------- ### Install @backpack/eslint-config Source: https://backpack.ns.nl/packages/@backpack/eslint-config Install the ESLint configuration package as a development dependency. ```bash npm install -D @backpack/eslint-config ``` -------------------------------- ### Install AWS SDK Libraries Source: https://backpack.ns.nl/packages/@backpack/amazon-dynamodb Install the necessary AWS SDK libraries for DynamoDB interaction. ```bash npm install @aws-sdk/client-dynamodb @aws-sdk/lib-dynamodb ``` -------------------------------- ### Install AWS SDK client for S3 Source: https://backpack.ns.nl/packages/@backpack/amazon-s3 Install the necessary AWS SDK client for S3 interaction. ```bash npm install @aws-sdk/client-s3 ``` -------------------------------- ### Install @backpack/config and Zod Source: https://backpack.ns.nl/packages/@backpack/config Install the package using npm. Ensure Nexus is set up as a private registry if needed. ```bash npm install @backpack/config zod ``` -------------------------------- ### Install @backpack/testing Source: https://backpack.ns.nl/packages/@backpack/testing Install the @backpack/testing package as a development dependency using npm. ```bash npm install -D @backpack/testing ``` -------------------------------- ### Install @backpack/i18n Source: https://backpack.ns.nl/packages/@backpack/i18n Install the package using npm. Ensure Nexus is set up as a private registry beforehand. ```bash npm install @backpack/i18n ``` -------------------------------- ### Install Swagger UI Express Source: https://backpack.ns.nl/packages/@backpack/vite-plugin-lambda Install the necessary packages for integrating Swagger UI with your project. ```bash npm install -D swagger-ui-express @types/swagger-ui-express yaml ``` -------------------------------- ### Example Prompt for Migration Plan Source: https://backpack.ns.nl/guides/tooling/ai An example prompt to ask an AI agent to investigate potential Backpack migrations based on `AGENTS.md` and Backpack documentation. ```text Hey, check AGENTS.md and investigate if this project needs important Backpack migrations. Check the Backpack docs, and give me a short migration plan before changing anything. ``` -------------------------------- ### Install @backpack/amazon-dynamodb Source: https://backpack.ns.nl/packages/@backpack/amazon-dynamodb Install the package using npm. Ensure Nexus is set up as a private registry. ```bash npm install @backpack/amazon-dynamodb ``` -------------------------------- ### Preview Documentation Locally Source: https://backpack.ns.nl/contributing/how-to-contribute Run this script to preview the documentation locally during development. Ensure you have the necessary dependencies installed. ```bash npm run dev:docs ``` -------------------------------- ### Install Vite and Hono Vite Dev Server Source: https://backpack.ns.nl/guides/tooling/local-development Install Vite and the @hono/vite-dev-server package for local development. ```bash npm install -D vite @hono/vite-dev-server ``` -------------------------------- ### Install @backpack/aws-secrets-manager Source: https://backpack.ns.nl/packages/@backpack/aws-secrets-manager Install the package using npm. ```bash npm install @backpack/aws-secrets-manager ``` -------------------------------- ### Install AWS SDK Client for SNS Source: https://backpack.ns.nl/packages/@backpack/amazon-sns Install the AWS SDK client for SNS, which is required by the @backpack/amazon-sns package. This should be done after installing the main package. ```bash npm install @aws-sdk/client-sns ``` -------------------------------- ### Start Local Development Server Source: https://backpack.ns.nl/guides/tooling/local-development Run the 'dev' npm script to start the local development server. Your API will be available locally through the Hono dev server. ```bash npm run dev ``` -------------------------------- ### Install @backpack/typescript-config Source: https://backpack.ns.nl/packages/@backpack/typescript-config Install the package as a development dependency using npm. ```bash npm install -D @backpack/typescript-config ``` -------------------------------- ### Install Vitest and Coverage Package Source: https://backpack.ns.nl/guides/testing/using-vitest Install Vitest and the v8 coverage package as development dependencies. ```sh npm i -D vitest @vitest/coverage-v8 ``` -------------------------------- ### Install @backpack/amazon-sqs Source: https://backpack.ns.nl/packages/@backpack/amazon-sqs Install the @backpack/amazon-sqs package using npm. Ensure Nexus is set up as a private registry beforehand. ```bash npm install @backpack/amazon-sqs ``` -------------------------------- ### Example package.json dependency Source: https://backpack.ns.nl/guides/tooling/working-with-npm Illustrates how a package dependency is declared in package.json with a version range. ```json { "dependencies": { "zod": "^4.1.0" } } ``` -------------------------------- ### Install AWS SDK Client for SQS Source: https://backpack.ns.nl/packages/@backpack/amazon-sqs Install the AWS SDK client for SQS. This is a required dependency for using the @backpack/amazon-sqs package. ```bash npm install @aws-sdk/client-sqs ``` -------------------------------- ### Customize Mock Server Setup Source: https://backpack.ns.nl/packages/@backpack/mockserver-client Customize the automatic setup behavior of the mock server, such as disabling automatic resets or matcher registration. ```typescript mockServer.setup({ reset: "manual", // Disable automatic beforeEach reset matchers: false, // Disable automatic matcher registration }); ``` -------------------------------- ### Install @backpack/amazon-s3 package Source: https://backpack.ns.nl/packages/@backpack/amazon-s3 Install the @backpack/amazon-s3 package using npm. Ensure Nexus is set up as a private registry. ```bash npm install @backpack/amazon-s3 ``` -------------------------------- ### Proposed Hono-based Local Development Setup Source: https://backpack.ns.nl/rfc/hono-adoption-discussion Demonstrates the new Hono-based approach for local development, utilizing `@hono/vite-dev-server` and custom adapters like `fromLambda` and `fromFetch`. This setup allows for direct use of Fetch-like handlers and adaptation of AWS-native handlers. ```typescript import { Hono } from "hono"; // custom adapters, do not yet exist import { fromLambda, fromFetch } from "@backpack/hono"; import { handler as getBooks } from "./get-books.lambda"; import { handler as addBook } from "./add-book.lambda"; import { requestHandler as helloWorld } from "./hello-world.lambda"; const app = new Hono(); // adapter for AWS-native handlers: app.get("/api/v1/books", fromLambda(getBooks)); app.post("/api/v1/books", fromLambda(addBook)); // adapter for Fetch-like request handlers: app.get("/api/v1/hello", fromFetch(helloWorld)); ``` -------------------------------- ### After: Vite Configuration with Hono Dev Server Source: https://backpack.ns.nl/guides/migrating/hono The new setup uses @hono/vite-dev-server for local development configuration. ```typescript import { defineConfig } from "vite"; import devServer from "@hono/vite-dev-server"; export default defineConfig({ plugins: [ devServer({ entry: "./server.ts", }), ], }); ``` -------------------------------- ### Install Backpack Vite Plugin Source: https://backpack.ns.nl/guides/upgrading/v0.13 Install the @backpack/vite package as a development dependency if your project uses ECMAScript decorators with Vite or Vitest. ```bash npm install -D @backpack/vite ``` -------------------------------- ### Before: Vite Configuration with VitePluginLambda Source: https://backpack.ns.nl/guides/migrating/hono The previous setup used @backpack/vite-plugin-lambda for local development configuration. ```typescript import { defineConfig } from "vite"; import { VitePluginLambda } from "@backpack/vite-plugin-lambda"; export default defineConfig({ plugins: [ VitePluginLambda({ appPath: "./server.ts", }), ], }); ``` -------------------------------- ### Example TypeScript Configuration Source: https://backpack.ns.nl/packages/@backpack/config Provide configuration values in a TypeScript file using a default export, matching the defined schema. ```typescript // (make sure to use a default export) export default { service: "My Bookstore", clients: { foo: { baseUrl: "https://path.to/foo", timeoutMilliseconds: 500, } // ... } } ``` -------------------------------- ### Install temporal-polyfill Source: https://backpack.ns.nl/guides/development/date-and-time Install the temporal-polyfill package using npm. This package provides Temporal API functionality for Node.js environments until native support is available. ```bash npm install temporal-polyfill ``` -------------------------------- ### Classic Lambda Handler for API Gateway Source: https://backpack.ns.nl/rfc/hono-adoption This is a simplified example of a classic Lambda handler using APIGatewayProxyEvent for handling GET requests with a path parameter. ```typescript export const handler = async (event: APIGatewayProxyEvent) => { const deviceId = event.pathParameters?.deviceId; if (event.httpMethod === "GET" && deviceId) { return { statusCode: 200, body: JSON.stringify({ id: deviceId }), }; } return { statusCode: 404, body: "Not found" }; }; ``` -------------------------------- ### Using Temporal API in Node.js Source: https://backpack.ns.nl/guides/development/date-and-time Import and use the Temporal API from the 'temporal-polyfill' package to get the current instant in time. This demonstrates basic usage after installation. ```typescript import { Temporal } from "temporal-polyfill"; console.log(`It is now ${Temporal.Now.instant()}`); ``` -------------------------------- ### Multiple Handlers within a Single Lambda using Hono Source: https://backpack.ns.nl/rfc/hono-adoption-discussion This example shows how to group multiple related endpoints under a single Lambda function using Hono's router. It defines two distinct GET endpoints. ```typescript const app = new Hono(); app.get("/api/v1/hello", (c) => c.text("Hello world!")); app.get("/api/v1/hello/:name", (c) => { const { name } = c.req.param(); return c.text(`Hello ${name}!`); }); export const handler = handle(app); // single handler to serve both endpoints ``` -------------------------------- ### OpenAPI Spec with API Gateway Integration Source: https://backpack.ns.nl/how-tos/rest-api Define an OpenAPI document with an endpoint and its integration details for AWS API Gateway. This example shows a GET request to '/hello' that integrates with a Lambda function using the 'x-amazon-apigateway-integration' extension. ```yaml openapi: 3.0.1 info: title: Sample API version: 1.0.0 paths: /hello: get: responses: '200': description: A greeting content: application/json: schema: type: object properties: message: type: string # OpenAPI extension for API Gateway integration x-amazon-apigateway-integration: httpMethod: POST # AWS integration method - must be POST regardless of endpoint method passthroughBehavior: "when_no_match" type: aws_proxy uri: Fn::Sub: "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorld.Arn}/invocations" ``` -------------------------------- ### Backpack Pre-configured REST Client Source: https://backpack.ns.nl/how-tos/rest-client Shows how to create a REST client using the `@backpack/rest-client` library, which includes default configurations like base URL, API key, and timeout. Requires the '@backpack/rest-client' package. ```typescript import { createRestClient } from "@backpack/rest-client"; const bookStoreClient = createRestClient({ baseUrl: "https://my-book-store.com", apiManagementApiKey: '...', timeout: 5_000, // ... }); const books = await bookStoreClient .get("/api/v1/books") .json(); ``` -------------------------------- ### API Management: Associate API with Multiple Products Source: https://backpack.ns.nl/release-notes/v0.12 Example of deploying an API and associating it with multiple API Management products using the `productIds` parameter in CI/CD pipeline templates. ```yaml resources: repositories: - repository: CICD name: CICD/pipeline-templates type: git ref: refs/tags/8.15.0 stages: - stage: Deploy jobs: - template: jobs/deploy/api-management/apim-deploy.yml@CICD parameters: environment: "test" apiId: "backpack-bookstore" productIds: - "backpack-public" - "backpack-internal" # ... ``` -------------------------------- ### After: Server Configuration with Hono and fromAwsLambdaHandler Source: https://backpack.ns.nl/guides/migrating/hono This snippet demonstrates the server configuration using Hono and fromAwsLambdaHandler from @backpack/hono. ```typescript import { Hono } from "hono"; import { fromAwsLambdaHandler } from "@backpack/hono"; import { handler as getPersons } from "./app/lambdas/get-persons.handler"; import { handler as addPerson } from "./app/lambdas/add-person.lambda"; const app = new Hono(); app.get("/api/v1/persons", fromAwsLambdaHandler(getPersons)); app.post("/api/v1/persons", fromAwsLambdaHandler(addPerson)); export default app; ``` -------------------------------- ### Force Initialize AI Agent Instructions Source: https://backpack.ns.nl/packages/@backpack/cli Use the `--force` option to add AI agent instructions even if no `@backpack/*` dependencies are detected in the project. ```shell npx @backpack/cli agents init --force ``` -------------------------------- ### Start Local Mockserver with Backpack CLI Source: https://backpack.ns.nl/packages/@backpack/cli Initiates a local mockserver instance for development and testing. By default, it runs on port 3001. This server can be connected to using `@backpack/mockserver-client`. ```bash npx @backpack/cli mock-server start ``` -------------------------------- ### Apply Recommended Tags with CDK Config Source: https://backpack.ns.nl/guides/infrastructure/resource-tagging Example of applying recommended tags to CDK resources using `@backpack/cdk-config`. It demonstrates dynamically setting the 'version' tag using the Git commit hash. ```typescript import { execSync } from "node:child_process"; import { App, Stack } from "aws-cdk-lib"; import { loadConfig, cdkLoader } from "@backpack/config"; import { BuildConfig } from "../config/BuildConfig"; const cdk = new App(); const buildConfig = await loadConfig({ schema: BuildConfig, loaders: [ cdkLoader(cdk, { configDirectory: "./cdk/config" }) ], }); // in this example, we use the current commit hash as version: const gitHash = execSync("git rev-parse HEAD").toString().trim(); const tags = { ...buildConfig.tags, version: gitHash }; const myStack = new Stack(cdk, `my-stack`, { // ... tags: tags, // apply tags to all resources in this stack }); ``` -------------------------------- ### Install @backpack/amazon-sns Source: https://backpack.ns.nl/packages/@backpack/amazon-sns Install the @backpack/amazon-sns package using npm. Ensure Nexus is set up as a private registry beforehand. ```bash npm install @backpack/amazon-sns ``` -------------------------------- ### Load and Validate Configuration at Startup Source: https://backpack.ns.nl/guides/development/configuration-and-secrets Load configuration using `@backpack/config` with a defined schema and loaders. This ensures configuration is validated once at startup. ```typescript import { loadConfig } from "@backpack/config"; export const config = await loadConfig({ schema: AppConfig, loaders: [/* ... */], }); ``` -------------------------------- ### Configure NPM Registry with npm config Source: https://backpack.ns.nl/guides/tooling/using-nexus Use these commands to set your NPM registry to Nexus and configure authentication. Replace $ACCESS_TOKEN with your personal token from Nexus. ```bash npm config set registry https://nexus.topaas.ns.nl/repository/NS_BACKPACK_NPMGroup/ npm config set //nexus.topaas.ns.nl/repository/NS_BACKPACK_NPMGroup/:_auth=$ACCESS_TOKEN ``` -------------------------------- ### Before: Server Configuration with Express and lambdaHandlers Source: https://backpack.ns.nl/guides/migrating/hono This snippet shows the server configuration using Express and lambdaHandlers from @backpack/vite-plugin-lambda. ```typescript import express from "express"; import { lambdaHandlers } from "@backpack/vite-plugin-lambda"; export const app = express(); app.use( lambdaHandlers({ handlers: { "/api/v1/persons": { get: { handler: () => import("./app/lambdas/get-persons.handler").then((it) => it.handler), }, post: { handler: () => import("./app/lambdas/add-person.lambda").then((it) => it.handler), }, }, }, }), ); export default app; ``` -------------------------------- ### Basic MockServer Request Matching Source: https://backpack.ns.nl/packages/@backpack/mockserver-client Defines basic mock responses for GET requests to '/hello' and any GET request matching '/api/**'. ```typescript await mockServer.whenGet("/hello").respondText("Hoi!"); await mockServer.when("GET", "/api/**").respondJson({ ok: true }); ``` -------------------------------- ### fromEnv Source: https://backpack.ns.nl/packages/@backpack/rest-client/middleware Loads credentials from environment variables. This is a convenient way to configure authentication in different environments. ```APIDOC ## fromEnv ### Description Loads credentials from environment variables. This is a convenient way to configure authentication in different environments. ### Method *Function* ### Endpoint N/A (SDK function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```javascript // Example usage within the rest client configuration // const client = new RestClient({ middleware: [fromEnv()] }); ``` ### Response *Returns a middleware function that reads credentials from environment variables.* #### Success Response (200) N/A (SDK function) #### Response Example N/A ``` -------------------------------- ### List installed npm dependencies Source: https://backpack.ns.nl/guides/tooling/working-with-npm Use `npm ls` to display the installed dependency tree. This command is useful for debugging and understanding dependency resolution. ```bash npm ls ``` ```bash npm ls typescript ``` ```bash npm ls eslint ``` -------------------------------- ### RFC 9457 Problem Details JSON Example Source: https://backpack.ns.nl/guides/development/error-handling/rest-apis An example of the JSON structure for RFC 9457 Problem Details, providing specific error information. ```json { "type": "/problems/out-of-credit", "status": 403, "title": "You do not have enough credit.", "detail": "Your current balance is 30, but that costs 50.", "balance": 30 } ``` -------------------------------- ### Initialize AGENTS.md with Backpack CLI Source: https://backpack.ns.nl/guides/tooling/ai Use this command to create a new `AGENTS.md` file in your project root, providing Backpack-specific instructions for AI coding agents. ```shell npx @backpack/cli agents init ``` -------------------------------- ### Upgrade Backpack Packages and Vitest Source: https://backpack.ns.nl/guides/upgrading/v0.8 Use npm-check-updates to update all `@backpack/*` dependencies to the latest `0.8.x` version and install `vitest` version `^4.0.0`. Run `npm install` to finalize. ```bash npx npm-check-updates '@backpack/*' -u npm install vitest@^4 npm install ``` -------------------------------- ### Retrieve Resource Tags with Backpack CLI Source: https://backpack.ns.nl/packages/@backpack/cli Use this command to fetch all recommended resource tags for a specified ASID. Ensure you have the Backpack CLI installed. ```bash npx @backpack/cli retrieve-tags your-asid-here ``` -------------------------------- ### Set up API Gateway with Backpack CDK Constructs Source: https://backpack.ns.nl/how-tos/rest-api This snippet demonstrates how to configure an API Gateway using the `ApiGateway` construct from `@backpack/cdk-constructs`. It includes options for defining the API with an OpenAPI spec, serving Swagger UI, integrating Lambda functions, enabling an ACL, and setting up a custom domain. ```typescript import { Stack, StackProps } from "aws-cdk-lib"; import { Construct } from "constructs"; import { ApiGateway, AccountDomainName, FileApiDefinition } from "@backpack/cdk-constructs"; export class AppStack extends Stack { constructor(scope: Construct, id: string, props?: StackProps) { super(scope, id, props); new ApiGateway(this, "MyRestApi", { restApiName: "My REST API", // optionally, provide an OpenAPI spec file used for routing, // with optionally, serving a Swagger UI in its gateway apiDefinition: new FileApiDefinition("./path/to/openapi.yaml"), // (or JSON) swaggerUI: true, // optionally, pass your Lambda functions to arrange invocation permissions. lambdaFunctions: [ /* lambda functions here */ ], // enable API Management ACL enableApiManagementAcl: true, // optionally, enable a custom domain customDomain: { // automatically creates api.my-service..cla.ns.nl: accountDomainName: new AccountDomainName(this, "AccountDomainName", { subDomain: "api.my-service" }) } }); } } ``` -------------------------------- ### Create Mock Server with Hono Source: https://backpack.ns.nl/packages/@backpack/hono-mockserver Create a mock server instance using createMockServer and an in-memory store. This can be mounted on any HTTP server. ```ts import { createMockServer, inMemoryStore } from "@backpack/hono-mockserver"; const app = createMockServer({ store: inMemoryStore(), }); ``` -------------------------------- ### Update S3 Service Imports Source: https://backpack.ns.nl/guides/migrating/common-serverless-library Install the @backpack/amazon-s3 package and update your S3 service imports. ```typescript import { S3Service } from '@backpack/amazon-s3'; ``` -------------------------------- ### Generate a New Backpack Project Source: https://backpack.ns.nl/packages/@backpack/cli Use npx to run the @backpack/cli generate-project command. Replace `[targetDirectory]` with the name for your new project's directory. ```shell npx @backpack/cli generate-project [targetDirectory] ```