Add a resource limit
Cap how many persistent resources a subscriber may own.
Cap how many persistent resources a subscriber may own.
Each plan caps a persistent object such as projects or jobs. Use this for counts, not request rates.
import * as fs from "@farthershore/business";
const requests = fs.requests();
const api = fs.backend("api", {
transport: { mode: "direct" },
meters: [requests],
default: true,
});
const projects = fs.resource("projects", {
display: "Projects",
countSource: "action_inferred",
cap: fs.scope.subscription,
});
const projectRoutes = fs.route("/v1/projects", {
get: { backend: api, costs: [requests.fixed(1)] },
post: { backend: api, creates: projects, costs: [requests.fixed(1)] },
});
const deleteProject = fs.route("/v1/projects/{id}", {
delete: { backend: api, deletes: projects, costs: [requests.fixed(1)] },
});
fs.plan("starter", {
kind: fs.plan.kind.free,
grants: [projectRoutes, deleteProject],
limits: [requests.perMinute(600), projects.max(5)],
});
Run farthershore build --format json, then push to an env/* branch. Wait
until env list contains the preview environment before creating or binding
the same logical api backend slug there. If automatic branch-prefix creation
did not occur, create the preview explicitly first:
farthershore env list <business> --format json
farthershore backend create <business> --env <environment> \
--name "Preview API" --slug api --transport direct \
--idempotency-key <persisted-backend-create-attempt-key> \
--origin-url https://preview-api.example.com --default --format json
farthershore backend list <business> --format json
Filter the structured backend list by the preview's environment id.
Create five projects with a preview subscriber. The sixth create must be denied; deleting one must make one slot available.
creates or
deletes, or the backend did not complete successfully.deletes: projects on the delete operation.projects ref in route
effects and projects.max(5); do not substitute matching strings.Revert the new resource, action bindings, and cap together. Do not remove or reduce a live limit without reviewing subscriber impact.
Read limits and Business SDK reference.
Add an action-inferred
projectsresource limit to the existing Farther Shore business. Bind create and delete actions, cap the relevant plans, run the local build, and show how to verify the boundary in preview. Do not publish.