@antasphere/chassis-contract 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +82 -0
- package/dist/define.d.ts +177 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +35 -0
- package/dist/define.js.map +1 -0
- package/dist/entitlements.d.ts +486 -0
- package/dist/entitlements.d.ts.map +1 -0
- package/dist/entitlements.js +344 -0
- package/dist/entitlements.js.map +1 -0
- package/dist/identity.d.ts +56 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +2 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/routes/index.d.ts +5403 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +940 -0
- package/dist/routes/index.js.map +1 -0
- package/dist/schemas/api-keys.d.ts +54 -0
- package/dist/schemas/api-keys.d.ts.map +1 -0
- package/dist/schemas/api-keys.js +48 -0
- package/dist/schemas/api-keys.js.map +1 -0
- package/dist/schemas/audit.d.ts +74 -0
- package/dist/schemas/audit.d.ts.map +1 -0
- package/dist/schemas/audit.js +65 -0
- package/dist/schemas/audit.js.map +1 -0
- package/dist/schemas/break-glass.d.ts +42 -0
- package/dist/schemas/break-glass.d.ts.map +1 -0
- package/dist/schemas/break-glass.js +38 -0
- package/dist/schemas/break-glass.js.map +1 -0
- package/dist/schemas/cli-auth.d.ts +59 -0
- package/dist/schemas/cli-auth.d.ts.map +1 -0
- package/dist/schemas/cli-auth.js +68 -0
- package/dist/schemas/cli-auth.js.map +1 -0
- package/dist/schemas/common.d.ts +96 -0
- package/dist/schemas/common.d.ts.map +1 -0
- package/dist/schemas/common.js +205 -0
- package/dist/schemas/common.js.map +1 -0
- package/dist/schemas/demo-passes.d.ts +90 -0
- package/dist/schemas/demo-passes.d.ts.map +1 -0
- package/dist/schemas/demo-passes.js +60 -0
- package/dist/schemas/demo-passes.js.map +1 -0
- package/dist/schemas/files.d.ts +39 -0
- package/dist/schemas/files.d.ts.map +1 -0
- package/dist/schemas/files.js +26 -0
- package/dist/schemas/files.js.map +1 -0
- package/dist/schemas/instance.d.ts +58 -0
- package/dist/schemas/instance.d.ts.map +1 -0
- package/dist/schemas/instance.js +70 -0
- package/dist/schemas/instance.js.map +1 -0
- package/dist/schemas/invitations.d.ts +100 -0
- package/dist/schemas/invitations.d.ts.map +1 -0
- package/dist/schemas/invitations.js +55 -0
- package/dist/schemas/invitations.js.map +1 -0
- package/dist/schemas/me.d.ts +81 -0
- package/dist/schemas/me.d.ts.map +1 -0
- package/dist/schemas/me.js +178 -0
- package/dist/schemas/me.js.map +1 -0
- package/dist/schemas/members.d.ts +60 -0
- package/dist/schemas/members.d.ts.map +1 -0
- package/dist/schemas/members.js +43 -0
- package/dist/schemas/members.js.map +1 -0
- package/dist/schemas/projects.d.ts +232 -0
- package/dist/schemas/projects.d.ts.map +1 -0
- package/dist/schemas/projects.js +140 -0
- package/dist/schemas/projects.js.map +1 -0
- package/dist/schemas/scope.d.ts +14 -0
- package/dist/schemas/scope.d.ts.map +1 -0
- package/dist/schemas/scope.js +5 -0
- package/dist/schemas/scope.js.map +1 -0
- package/dist/schemas/setup.d.ts +28 -0
- package/dist/schemas/setup.d.ts.map +1 -0
- package/dist/schemas/setup.js +28 -0
- package/dist/schemas/setup.js.map +1 -0
- package/dist/schemas/sso-connect.d.ts +30 -0
- package/dist/schemas/sso-connect.d.ts.map +1 -0
- package/dist/schemas/sso-connect.js +38 -0
- package/dist/schemas/sso-connect.js.map +1 -0
- package/dist/schemas/sso-logout.d.ts +17 -0
- package/dist/schemas/sso-logout.d.ts.map +1 -0
- package/dist/schemas/sso-logout.js +16 -0
- package/dist/schemas/sso-logout.js.map +1 -0
- package/dist/schemas/teams.d.ts +100 -0
- package/dist/schemas/teams.d.ts.map +1 -0
- package/dist/schemas/teams.js +84 -0
- package/dist/schemas/teams.js.map +1 -0
- package/dist/schemas/workspaces.d.ts +99 -0
- package/dist/schemas/workspaces.d.ts.map +1 -0
- package/dist/schemas/workspaces.js +96 -0
- package/dist/schemas/workspaces.js.map +1 -0
- package/dist/seams.d.ts +185 -0
- package/dist/seams.d.ts.map +1 -0
- package/dist/seams.js +37 -0
- package/dist/seams.js.map +1 -0
- package/dist/wire.d.ts +101 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +161 -0
- package/dist/wire.js.map +1 -0
- package/package.json +41 -3
- package/src/define.ts +64 -0
- package/src/entitlements.ts +527 -0
- package/src/identity.ts +49 -0
- package/src/index.ts +38 -0
- package/src/routes/index.ts +1146 -0
- package/src/schemas/api-keys.ts +53 -0
- package/src/schemas/audit.ts +74 -0
- package/src/schemas/break-glass.ts +46 -0
- package/src/schemas/cli-auth.ts +78 -0
- package/src/schemas/common.ts +206 -0
- package/src/schemas/demo-passes.ts +73 -0
- package/src/schemas/files.ts +30 -0
- package/src/schemas/instance.ts +71 -0
- package/src/schemas/invitations.ts +66 -0
- package/src/schemas/me.ts +184 -0
- package/src/schemas/members.ts +53 -0
- package/src/schemas/projects.ts +174 -0
- package/src/schemas/scope.ts +18 -0
- package/src/schemas/setup.ts +31 -0
- package/src/schemas/sso-connect.ts +40 -0
- package/src/schemas/sso-logout.ts +17 -0
- package/src/schemas/teams.ts +101 -0
- package/src/schemas/workspaces.ts +109 -0
- package/src/seams.ts +202 -0
- package/src/wire.ts +246 -0
- package/test/define.test.ts +59 -0
- package/test/hub-wire.test.ts +114 -0
- package/README.md +0 -3
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
/**
|
|
3
|
+
* The billing rail's declaration layer (the pay-per-use billing rail spec,
|
|
4
|
+
* §7 and §8b): a route says ONCE, next to its contract, what it meters, which
|
|
5
|
+
* limit it checks and which feature it needs. One chassis middleware reads
|
|
6
|
+
* the declaration and enforces it for every client of `/api/v1` at once (the
|
|
7
|
+
* dashboard, the CLI and the MCP tools are all HTTP clients of it), and a
|
|
8
|
+
* handler never checks or emits by hand.
|
|
9
|
+
*
|
|
10
|
+
* Client-safe on purpose: no Hono here. A route is referenced by its
|
|
11
|
+
* `{ method, path }` as the OpenAPI helper spells it (`{id}` params), so the
|
|
12
|
+
* tool's contract builds the registry from its route objects and the SDK can
|
|
13
|
+
* read the same declarations without pulling the server.
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* The plan tiers, a CLOSED enum the hub owns and this contract mirrors so a
|
|
17
|
+
* tool cannot invent one (§8b). `free` is the default with no subscription;
|
|
18
|
+
* `pro` is the paid plan. "Enterprise" is not a tier but a per-account
|
|
19
|
+
* override the hub serves.
|
|
20
|
+
*/
|
|
21
|
+
export const ENTITLEMENT_TIERS = ['free', 'pro'];
|
|
22
|
+
export const entitlementTierSchema = z.enum(ENTITLEMENT_TIERS);
|
|
23
|
+
/** The hub's name for the same closed enum (`BILLING_PLANS` in `@antasphere/contract`). */
|
|
24
|
+
export const BILLING_PLANS = ENTITLEMENT_TIERS;
|
|
25
|
+
/**
|
|
26
|
+
* The one scope of the tool → hub machine channel (§6): a `client_credentials`
|
|
27
|
+
* token on the registry client, reaching `/usage/*` and nothing else.
|
|
28
|
+
*/
|
|
29
|
+
export const USAGE_WRITE_SCOPE = 'usage:write';
|
|
30
|
+
/**
|
|
31
|
+
* The error codes the three tool routes of the hub (`POST /usage/events`,
|
|
32
|
+
* `GET /usage/entitlements`, `POST /usage/check`) answer with, and the status
|
|
33
|
+
* each rides on: the hub's `USAGE_ROUTE_ERRORS` (PRDCT-2677).
|
|
34
|
+
* `tool_credential_required`: the caller is not a registry tool's machine
|
|
35
|
+
* credential. `unknown_account`: no organization holds the `accountRef` (the
|
|
36
|
+
* check and the entitlements read; the ingest answers it per event instead).
|
|
37
|
+
* `validation_error`: the body or the query does not parse. The chassis maps
|
|
38
|
+
* the check's two (`check.ts`): a 404 `unknown_account` and a 400 are the
|
|
39
|
+
* hub's judgement, allowed and logged, never an outage.
|
|
40
|
+
*/
|
|
41
|
+
export const USAGE_ROUTE_ERRORS = {
|
|
42
|
+
tool_credential_required: 401,
|
|
43
|
+
unknown_account: 404,
|
|
44
|
+
validation_error: 400
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* The wire shape of one usage event as the hub ingests it: the hub's
|
|
48
|
+
* `usageEventSchema` (`packages/contract/src/schemas/billing.ts` of the hub,
|
|
49
|
+
* PRDCT-2625), copied here and checked against the hub's wire snapshot
|
|
50
|
+
* (`wire.ts`, `pnpm --filter @antasphere/chassis-contract wire:check`, the
|
|
51
|
+
* `hub-wire` CI job; PRDCT-2677), so the fake hub of the test kit refuses
|
|
52
|
+
* exactly what the real hub refuses (PRDCT-2629). `userId` is the HUB user
|
|
53
|
+
* (the SSO `sub`), never the tool's local id, and null when the actor is a
|
|
54
|
+
* resource owner the tool could not name; `accountRef` is the hub
|
|
55
|
+
* organization id (a uuid) the tool carries as its workspace's central
|
|
56
|
+
* account id. `toolSlug` is accepted by the hub only when it equals the
|
|
57
|
+
* calling token's registry slug — the chassis NEVER sends it: the token is
|
|
58
|
+
* the only authority on the tool's name, the body never names the tool
|
|
59
|
+
* (PRDCT-2629; `UsageEvent` in seams.ts has no such field).
|
|
60
|
+
*/
|
|
61
|
+
export const usageEventSchema = z
|
|
62
|
+
.object({
|
|
63
|
+
id: z.string().regex(/^[0-9A-HJKMNP-TV-Z]{26}$/, 'a ULID'),
|
|
64
|
+
actionKey: z.string().min(1).max(120).optional(),
|
|
65
|
+
meter: z.string().min(1).max(120).optional(),
|
|
66
|
+
quantity: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
67
|
+
unit: z.string().min(1).max(40),
|
|
68
|
+
occurredAt: z.iso.datetime({ offset: true }),
|
|
69
|
+
workspaceId: z.string().min(1).max(128),
|
|
70
|
+
accountRef: z.uuid(),
|
|
71
|
+
userId: z.string().min(1).max(128).nullable().optional(),
|
|
72
|
+
via: z.enum(['session', 'api_key', 'oauth']),
|
|
73
|
+
resourceType: z.string().min(1).max(80).nullable().optional(),
|
|
74
|
+
resourceId: z.string().min(1).max(256).nullable().optional(),
|
|
75
|
+
toolSlug: z.string().min(1).max(64).optional(),
|
|
76
|
+
source: z.object({
|
|
77
|
+
instanceId: z.string().min(1).max(128),
|
|
78
|
+
edition: z.string().min(1).max(32),
|
|
79
|
+
version: z.string().min(1).max(64)
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
.refine((e) => e.actionKey !== undefined || e.meter !== undefined, {
|
|
83
|
+
message: 'actionKey (or its legacy alias meter) is required',
|
|
84
|
+
path: ['actionKey']
|
|
85
|
+
});
|
|
86
|
+
/** The batch cap of `POST /usage/events` (the hub's `USAGE_EVENTS_BATCH_MAX`): at most this many events per post. */
|
|
87
|
+
export const USAGE_EVENTS_BATCH_MAX = 500;
|
|
88
|
+
/**
|
|
89
|
+
* The body of `POST /usage/events` as the hub parses it (its
|
|
90
|
+
* `usageEventsBatchSchema`): one to `USAGE_EVENTS_BATCH_MAX` elements, each
|
|
91
|
+
* judged on its own against `usageEventSchema` afterwards.
|
|
92
|
+
*/
|
|
93
|
+
export const usageEventsBatchSchema = z.object({
|
|
94
|
+
events: z.array(z.unknown()).min(1).max(USAGE_EVENTS_BATCH_MAX)
|
|
95
|
+
});
|
|
96
|
+
/**
|
|
97
|
+
* Why the hub did not accept an event (its `USAGE_REJECT_REASONS`, a closed
|
|
98
|
+
* list): `unknown_account`, `unknown_user`, `tool_mismatch`, and
|
|
99
|
+
* `invalid_event` (the element does not parse, its `occurredAt` falls outside
|
|
100
|
+
* the window, or its price exceeds `Number.MAX_SAFE_INTEGER`; `details` names
|
|
101
|
+
* the field).
|
|
102
|
+
*/
|
|
103
|
+
export const USAGE_REJECT_REASONS = [
|
|
104
|
+
'unknown_account',
|
|
105
|
+
'unknown_user',
|
|
106
|
+
'tool_mismatch',
|
|
107
|
+
'invalid_event'
|
|
108
|
+
];
|
|
109
|
+
export const usageRejectReasonSchema = z.enum(USAGE_REJECT_REASONS);
|
|
110
|
+
/**
|
|
111
|
+
* One element's answer. Since phase 2 an `accepted` result carries the
|
|
112
|
+
* `credits` the hub debited for it (0 when the action has no price).
|
|
113
|
+
*/
|
|
114
|
+
export const usageEventResultSchema = z.object({
|
|
115
|
+
id: z.string().nullable(),
|
|
116
|
+
status: z.enum(['accepted', 'duplicate', 'rejected']),
|
|
117
|
+
reason: usageRejectReasonSchema.optional(),
|
|
118
|
+
details: z.unknown().optional(),
|
|
119
|
+
credits: z.number().int().optional()
|
|
120
|
+
});
|
|
121
|
+
/**
|
|
122
|
+
* The hub's answer to `POST /usage/events`: one result per element, in the
|
|
123
|
+
* batch's order, and the three counts (always sent).
|
|
124
|
+
*/
|
|
125
|
+
export const usageIngestResultSchema = z.object({
|
|
126
|
+
results: z.array(usageEventResultSchema),
|
|
127
|
+
accepted: z.number().int(),
|
|
128
|
+
duplicate: z.number().int(),
|
|
129
|
+
rejected: z.number().int()
|
|
130
|
+
});
|
|
131
|
+
// ── The hub's window on an event's date (PRDCT-2630 at the hub, PRDCT-2644 here) ──
|
|
132
|
+
/**
|
|
133
|
+
* The window an event's `occurredAt` must fall in, measured against the
|
|
134
|
+
* moment the hub receives it: the hub's `USAGE_EVENT_MAX_PAST_MS` and
|
|
135
|
+
* `USAGE_EVENT_MAX_FUTURE_MS` (`packages/contract/src/schemas/billing.ts`
|
|
136
|
+
* of the hub), same names and values, checked against the hub's wire
|
|
137
|
+
* snapshot (`wire.ts`, `wire:check`, the `hub-wire` CI job; PRDCT-2677). Backward, seven days:
|
|
138
|
+
* the queue's retry budget is about eight and a half hours, so an outage of
|
|
139
|
+
* a night is covered many times over, and a week also covers an operator
|
|
140
|
+
* re-driving held jobs by hand. Forward, five minutes: the skew every JWT
|
|
141
|
+
* verifier already tolerates; anything further is a clock that is wrong.
|
|
142
|
+
* Outside the window the hub answers `rejected(invalid_event)` naming
|
|
143
|
+
* `occurredAt` and never clamps, so the poster refuses BEFORE posting: an
|
|
144
|
+
* event the hub would refuse on its date is held where it was made, never
|
|
145
|
+
* counted as a rejection at the hub (PRDCT-2644).
|
|
146
|
+
*/
|
|
147
|
+
export const USAGE_EVENT_MAX_PAST_MS = 7 * 24 * 60 * 60 * 1000;
|
|
148
|
+
export const USAGE_EVENT_MAX_FUTURE_MS = 5 * 60 * 1000;
|
|
149
|
+
/**
|
|
150
|
+
* Why an event's `occurredAt` is refused against the receipt time, or null
|
|
151
|
+
* when it falls inside the window (both bounds INCLUSIVE). The hub's
|
|
152
|
+
* `usageEventOccurrenceIssue`, copied (the wire snapshot's occurrence table
|
|
153
|
+
* checks it on the hub's offsets): the one comparison both
|
|
154
|
+
* halves run, the hub at ingest against its own clock, the chassis before
|
|
155
|
+
* posting against its best estimate of the receipt (its own clock), so the
|
|
156
|
+
* two never disagree on the sign or the edge.
|
|
157
|
+
*/
|
|
158
|
+
export function usageEventOccurrenceIssue(occurredAt, receivedAt) {
|
|
159
|
+
const delta = occurredAt.getTime() - receivedAt.getTime();
|
|
160
|
+
if (delta < -USAGE_EVENT_MAX_PAST_MS) {
|
|
161
|
+
return {
|
|
162
|
+
path: 'occurredAt',
|
|
163
|
+
message: `more than ${USAGE_EVENT_MAX_PAST_MS / 86_400_000} days before the hub received the event`
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
if (delta > USAGE_EVENT_MAX_FUTURE_MS) {
|
|
167
|
+
return {
|
|
168
|
+
path: 'occurredAt',
|
|
169
|
+
message: `more than ${USAGE_EVENT_MAX_FUTURE_MS / 60_000} minutes after the hub received the event`
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
// ── POST /usage/check: the price and the balance before an action (§5, §7 step 3) ──
|
|
175
|
+
/**
|
|
176
|
+
* The request of `POST /usage/check` (the hub's `UsageCheckRequest`,
|
|
177
|
+
* PRDCT-2663): the paying account, the action key and the quantity of THIS
|
|
178
|
+
* request. `unit` is accepted and ignored by the hub, which prices by its
|
|
179
|
+
* own row; it is sent so the answer's unit can be compared and a mismatch
|
|
180
|
+
* logged.
|
|
181
|
+
*/
|
|
182
|
+
export const usageCheckRequestSchema = z.object({
|
|
183
|
+
accountRef: z.uuid(),
|
|
184
|
+
actionKey: z.string().min(1).max(120),
|
|
185
|
+
quantity: z.number().int().min(0).max(Number.MAX_SAFE_INTEGER),
|
|
186
|
+
unit: z.string().min(1).max(40).optional()
|
|
187
|
+
});
|
|
188
|
+
/**
|
|
189
|
+
* The three reasons a check refuses (`null` when allowed), the hub's
|
|
190
|
+
* `USAGE_CHECK_REASONS`: `account_suspended` (checked first, whatever the
|
|
191
|
+
* price), `unpriceable` (the price of this quantity exceeds
|
|
192
|
+
* `Number.MAX_SAFE_INTEGER`: the hub clamps `credits` to that bound, and the
|
|
193
|
+
* ingest would reject the same event on its `quantity`) and
|
|
194
|
+
* `insufficient_credits` (`balance < credits`). Each is a refusal, never an
|
|
195
|
+
* outage (PRDCT-2677).
|
|
196
|
+
*/
|
|
197
|
+
export const USAGE_CHECK_REASONS = ['insufficient_credits', 'account_suspended', 'unpriceable'];
|
|
198
|
+
/**
|
|
199
|
+
* The hub's answer to `POST /usage/check` (its `UsageCheck`, PRDCT-2663),
|
|
200
|
+
* checked against the hub's wire snapshot (PRDCT-2677): advisory, no side effect. `credits` is the price of
|
|
201
|
+
* this quantity from the price book row effective now (0 and `priced:
|
|
202
|
+
* false` when the tool has no row for the action: views are never priced,
|
|
203
|
+
* an unknown key is not a refusal); `balance` the account's; `allowed` is
|
|
204
|
+
* `balance >= credits` unless the organization is suspended, which refuses
|
|
205
|
+
* whatever the price. `topUpUrl` is always present: the hub's billing page
|
|
206
|
+
* for that organization, what a `402 entitlement_denied` carries straight
|
|
207
|
+
* off the answer. No lower bound on `quantity` or `credits`, as at the hub: a
|
|
208
|
+
* copy stricter than the hub reads a valid answer as an outage.
|
|
209
|
+
*/
|
|
210
|
+
export const usageCheckSchema = z.object({
|
|
211
|
+
accountRef: z.uuid(),
|
|
212
|
+
actionKey: z.string(),
|
|
213
|
+
quantity: z.number().int(),
|
|
214
|
+
allowed: z.boolean(),
|
|
215
|
+
credits: z.number().int(),
|
|
216
|
+
balance: z.number().int(),
|
|
217
|
+
unit: z.string().nullable(),
|
|
218
|
+
priced: z.boolean(),
|
|
219
|
+
plan: entitlementTierSchema,
|
|
220
|
+
reason: z.enum(USAGE_CHECK_REASONS).nullable(),
|
|
221
|
+
topUpUrl: z.string()
|
|
222
|
+
});
|
|
223
|
+
/** The wire code of a credit refusal (§7 step 4), and its `details`. */
|
|
224
|
+
export const ENTITLEMENT_DENIED = 'entitlement_denied';
|
|
225
|
+
/** The key of a route's feature declaration, whichever shape it uses; null when none. */
|
|
226
|
+
export function featureKeyOf(entry) {
|
|
227
|
+
if (!entry.feature)
|
|
228
|
+
return null;
|
|
229
|
+
return typeof entry.feature === 'string' ? entry.feature : entry.feature.key;
|
|
230
|
+
}
|
|
231
|
+
/** The actor hook of a route, the entry's own or its meter's; null when the principal is the actor. */
|
|
232
|
+
export function actorHookOf(entry) {
|
|
233
|
+
return entry.actor ?? entry.meter?.actor ?? null;
|
|
234
|
+
}
|
|
235
|
+
/** `METHOD /path` — the registry key of a route. */
|
|
236
|
+
export function routeEntitlementKey(route) {
|
|
237
|
+
return `${route.method.toUpperCase()} ${route.path}`;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Build the registry from the tool's route objects. One entry per route: a
|
|
241
|
+
* second declaration of the same route throws at module load, so a typo or a
|
|
242
|
+
* copy cannot silently double or replace a price.
|
|
243
|
+
*/
|
|
244
|
+
export function declareRouteEntitlements(entries) {
|
|
245
|
+
const map = new Map();
|
|
246
|
+
for (const entry of entries) {
|
|
247
|
+
const key = routeEntitlementKey(entry.route);
|
|
248
|
+
if (map.has(key))
|
|
249
|
+
throw new Error(`route entitlement declared twice: ${key}`);
|
|
250
|
+
if (!entry.meter && !entry.limit && !entry.feature) {
|
|
251
|
+
throw new Error(`route entitlement declares nothing: ${key}`);
|
|
252
|
+
}
|
|
253
|
+
map.set(key, entry);
|
|
254
|
+
}
|
|
255
|
+
return map;
|
|
256
|
+
}
|
|
257
|
+
/** The declared body size of a request (its `Content-Length`), 0 when absent or malformed. */
|
|
258
|
+
export function declaredContentLength(ctx) {
|
|
259
|
+
const n = Number(ctx.headers.get('content-length') ?? '0');
|
|
260
|
+
return Number.isFinite(n) && n > 0 ? n : 0;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The stored size a handler recorded in its audit metadata (`sizeBytes`),
|
|
264
|
+
* falling back to the declared body size before the handler ran. The check
|
|
265
|
+
* sees the declared size, the emit sees the bytes that were actually kept.
|
|
266
|
+
*/
|
|
267
|
+
export function auditedSizeBytes(ctx) {
|
|
268
|
+
const stored = ctx.audit?.metadata?.sizeBytes;
|
|
269
|
+
if (typeof stored === 'number' && Number.isFinite(stored) && stored >= 0)
|
|
270
|
+
return stored;
|
|
271
|
+
return declaredContentLength(ctx);
|
|
272
|
+
}
|
|
273
|
+
// ── The tool's declared defaults, as `GET /instance` shows them ────────────
|
|
274
|
+
/**
|
|
275
|
+
* A priced action: the default the hub seeds its price book from (§7); the
|
|
276
|
+
* hub's rows win afterwards. `creditsPerUnit` credits buy `per` units of
|
|
277
|
+
* `unit` (`per` defaults to 1): an action metered in bytes and priced per
|
|
278
|
+
* mebibyte declares `{ creditsPerUnit: 5, unit: 'bytes', per: 1048576 }`,
|
|
279
|
+
* so the meter stays exact, the price reads as the seed table says it, and
|
|
280
|
+
* the two agree by construction (PRDCT-2627: the boot refuses a route whose
|
|
281
|
+
* meter unit differs from its action's). The hub prices an event as
|
|
282
|
+
* `creditsPerUnit × quantity / per`; rounding a fraction of a credit is the
|
|
283
|
+
* hub's rule, not the tool's.
|
|
284
|
+
*/
|
|
285
|
+
export const entitlementActionSchema = z.object({
|
|
286
|
+
key: z.string().min(1),
|
|
287
|
+
creditsPerUnit: z.number().int().min(0),
|
|
288
|
+
unit: z.string().min(1),
|
|
289
|
+
/** How many units one `creditsPerUnit` buys; 1 when absent. */
|
|
290
|
+
per: z.number().int().min(1).optional(),
|
|
291
|
+
label: z.string().min(1)
|
|
292
|
+
});
|
|
293
|
+
/**
|
|
294
|
+
* The credits an action declares for a quantity: `creditsPerUnit × quantity
|
|
295
|
+
* / per`, exact (a fraction is the hub's to round). A test pins the seed
|
|
296
|
+
* values with it, so a unit slip (5 per byte where 5 per MB was meant)
|
|
297
|
+
* fails before the price book is seeded from discovery.
|
|
298
|
+
*/
|
|
299
|
+
export function declaredCredits(action, quantity) {
|
|
300
|
+
return (action.creditsPerUnit * quantity) / (action.per ?? 1);
|
|
301
|
+
}
|
|
302
|
+
/** A limit's value per tier plus the oss value (the operator's own knob); null = unlimited. */
|
|
303
|
+
export const tierLimitSchema = z.object({
|
|
304
|
+
oss: z.number().nullable(),
|
|
305
|
+
free: z.number().nullable(),
|
|
306
|
+
pro: z.number().nullable()
|
|
307
|
+
});
|
|
308
|
+
/** A feature's switch per tier (oss has every feature: a self-hosted instance knows no plan). */
|
|
309
|
+
export const tierFeatureSchema = z.object({
|
|
310
|
+
free: z.boolean(),
|
|
311
|
+
pro: z.boolean()
|
|
312
|
+
});
|
|
313
|
+
export const toolEntitlementsSchema = z.object({
|
|
314
|
+
actions: z.array(entitlementActionSchema),
|
|
315
|
+
limits: z.record(z.string(), tierLimitSchema),
|
|
316
|
+
features: z.record(z.string(), tierFeatureSchema)
|
|
317
|
+
});
|
|
318
|
+
/**
|
|
319
|
+
* The hub's answer to `GET /usage/entitlements?accountRef=` (§5): the hub's
|
|
320
|
+
* `usageEntitlementsSchema` (PRDCT-2636), checked against the hub's wire
|
|
321
|
+
* snapshot (PRDCT-2677). The account's
|
|
322
|
+
* plan, resolved from the tier's defaults and the account's overrides; in
|
|
323
|
+
* phase 1 `limits` and `features` are empty and the tool's own declared
|
|
324
|
+
* values fill the numbers. A limit's value is a number or a boolean: the
|
|
325
|
+
* hub may switch a numeric limit off or on per account (`true` = unlimited,
|
|
326
|
+
* `false` = nothing allowed; `profiles.ts` resolves it so). Since phase 2
|
|
327
|
+
* (PRDCT-2663) the hub serves its real rows — every limit key it holds for
|
|
328
|
+
* the calling tool and the features on for the account — and `upgradeUrl`,
|
|
329
|
+
* its upgrade page for the organization carrying `org`, `tool` and `plan`;
|
|
330
|
+
* the chassis appends `&key=<key>&requiredPlan=<tier>` at refusal time.
|
|
331
|
+
* Required: every hub since 0.11.0 sends it.
|
|
332
|
+
*/
|
|
333
|
+
export const entitlementProfileSchema = z.object({
|
|
334
|
+
accountRef: z.uuid(),
|
|
335
|
+
plan: entitlementTierSchema,
|
|
336
|
+
/** Until when the plan is paid for (ISO 8601); null on `free` and on a live subscription. */
|
|
337
|
+
planUntil: z.string().nullable(),
|
|
338
|
+
limits: z.record(z.string(), z.union([z.number(), z.boolean()])),
|
|
339
|
+
features: z.array(z.string()),
|
|
340
|
+
upgradeUrl: z.string()
|
|
341
|
+
});
|
|
342
|
+
/** The wire code of a plan refusal, and its `details` (§7 step 2). */
|
|
343
|
+
export const PLAN_REQUIRED = 'plan_required';
|
|
344
|
+
//# sourceMappingURL=entitlements.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entitlements.js","sourceRoot":"","sources":["../src/entitlements.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;;;;;;;;;;GAYG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAM,EAAE,KAAK,CAAU,CAAC;AAE1D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;AAC/D,2FAA2F;AAC3F,MAAM,CAAC,MAAM,aAAa,GAAG,iBAAiB,CAAC;AAE/C;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAE/C;;;;;;;;;;GAUG;AACH,MA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BAAsB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC7C,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,uBAAuB,CAAC;IACzC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,eAAe,CAAC;IAC7C,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,iBAAiB,CAAC;CAClD,CAAC,CAAC;AAGH;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC/C,UAAU,EAAE,CAAC,CAAC,IAAI,EAAE;IACpB,IAAI,EAAE,qBAAqB;IAC3B,6FAA6F;IAC7F,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAChC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;IAChE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;IAC7B,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE;CACvB,CAAC,CAAC;AAGH,sEAAsE;AACtE,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A tool's IDENTITY: every value that names the tool where a person, an agent
|
|
3
|
+
* or an operator can see it. The chassis packages spell none of them; a tool
|
|
4
|
+
* writes ONE value of this type (in its own contract package, the one package
|
|
5
|
+
* its server, SDK, CLI and dashboard all depend on) and hands it to the three
|
|
6
|
+
* chassis entry points: `defineChassisContract` + `defineChassisRoutes` here,
|
|
7
|
+
* the server's `ToolDefinition.identity`, and the CLI's `defineCli`.
|
|
8
|
+
*
|
|
9
|
+
* Pure data, client-safe. The tool's domain WORDING (a refusal that names its
|
|
10
|
+
* resource) is not identity: it goes to the server's `copy` slot.
|
|
11
|
+
*/
|
|
12
|
+
export interface ToolIdentity<TScope extends string = string> {
|
|
13
|
+
/** Machine name, lower case (`acme`): the CLI's config namespace and its hub connect name. */
|
|
14
|
+
slug: string;
|
|
15
|
+
/** Human name (`Acme`): mails, the no-dashboard page, CLI messages, the name of an instance not set up yet. */
|
|
16
|
+
displayName: string;
|
|
17
|
+
/** API key prefix, without the underscore (`acm` mints `acm_<keyId>_<secret>`). Never change it once keys exist. */
|
|
18
|
+
apiKeyPrefix: string;
|
|
19
|
+
/** The scope vocabulary, by the part each scope plays. `dataExport` is the opt-in full-workspace export. */
|
|
20
|
+
scopes: {
|
|
21
|
+
read: TScope;
|
|
22
|
+
write: TScope;
|
|
23
|
+
dataExport: TScope;
|
|
24
|
+
};
|
|
25
|
+
/** How the OpenAPI document names the CLI key's grant (`things:read+write`). A literal: a contraction, not a join. */
|
|
26
|
+
cliKeyScopesLabel: string;
|
|
27
|
+
/**
|
|
28
|
+
* The tool's cloud home (PRDCT-2947): the instance Antasphere operates
|
|
29
|
+
* (`https://acme.antasphere.com`). The CLI resolves its URL there last
|
|
30
|
+
* (flag → env → profile → this), so `antasphere login` then `acme list`
|
|
31
|
+
* works on a clean machine; the implicit `cloud` profile lives at it. A
|
|
32
|
+
* self-hosted instance is named once, as a profile named for its host.
|
|
33
|
+
*/
|
|
34
|
+
cloud: {
|
|
35
|
+
url: string;
|
|
36
|
+
};
|
|
37
|
+
cli: {
|
|
38
|
+
/** The binary's name (`acme`). Must equal the `bin` key of the CLI's package.json. */
|
|
39
|
+
bin: string;
|
|
40
|
+
/** Prefix of the CLI's environment variables (`ACME` reads `ACME_URL`, `ACME_API_KEY`, `ACME_WORKSPACE`). */
|
|
41
|
+
envPrefix: string;
|
|
42
|
+
/** A pre-hub config directory still read once for migration (`~/.config/<dir>/config.json`). */
|
|
43
|
+
legacyConfigDir: string;
|
|
44
|
+
};
|
|
45
|
+
mcp: {
|
|
46
|
+
/** `serverInfo.name` of the bundled MCP server. */
|
|
47
|
+
serverName: string;
|
|
48
|
+
/** Prefix of the tool's MCP tool names, underscore included (`acme_`). The tool registers `<prefix>whoami`. */
|
|
49
|
+
toolPrefix: string;
|
|
50
|
+
};
|
|
51
|
+
/** OpenTelemetry `service.name`. */
|
|
52
|
+
otelServiceName: string;
|
|
53
|
+
/** The published container image. Read by nothing at run time: recorded so an instantiate script has one source. */
|
|
54
|
+
imageName: string;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=identity.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,WAAW,YAAY,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM;IAC1D,8FAA8F;IAC9F,IAAI,EAAE,MAAM,CAAC;IACb,+GAA+G;IAC/G,WAAW,EAAE,MAAM,CAAC;IACpB,oHAAoH;IACpH,YAAY,EAAE,MAAM,CAAC;IACrB,4GAA4G;IAC5G,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAC5D,sHAAsH;IACtH,iBAAiB,EAAE,MAAM,CAAC;IAC1B;;;;;;OAMG;IACH,KAAK,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB,GAAG,EAAE;QACH,sFAAsF;QACtF,GAAG,EAAE,MAAM,CAAC;QACZ,6GAA6G;QAC7G,SAAS,EAAE,MAAM,CAAC;QAClB,gGAAgG;QAChG,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,GAAG,EAAE;QACH,mDAAmD;QACnD,UAAU,EAAE,MAAM,CAAC;QACnB,+GAA+G;QAC/G,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,oCAAoC;IACpC,eAAe,EAAE,MAAM,CAAC;IACxB,oHAAoH;IACpH,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identity.js","sourceRoot":"","sources":["../src/identity.ts"],"names":[],"mappings":""}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export * from './schemas/common.js';
|
|
2
|
+
export * from './schemas/scope.js';
|
|
3
|
+
export * from './schemas/instance.js';
|
|
4
|
+
export * from './schemas/setup.js';
|
|
5
|
+
export { onboardingDismissedSchema, type OnboardingDismissed } from './schemas/me.js';
|
|
6
|
+
export * from './schemas/workspaces.js';
|
|
7
|
+
export * from './schemas/members.js';
|
|
8
|
+
export { cliAuthRequestSchema, cliAuthRequestedSchema, cliAuthCompleteSchema, cliAuthRevokedSchema, type CliAuthRequest, type CliAuthRequested, type CliAuthComplete, type CliAuthRevoked } from './schemas/cli-auth.js';
|
|
9
|
+
export * from './schemas/sso-connect.js';
|
|
10
|
+
export * from './schemas/sso-logout.js';
|
|
11
|
+
export * from './schemas/invitations.js';
|
|
12
|
+
export * from './schemas/audit.js';
|
|
13
|
+
export * from './schemas/break-glass.js';
|
|
14
|
+
export * from './schemas/files.js';
|
|
15
|
+
export * from './schemas/projects.js';
|
|
16
|
+
export * from './schemas/teams.js';
|
|
17
|
+
export * from './schemas/demo-passes.js';
|
|
18
|
+
export * from './seams.js';
|
|
19
|
+
export * from './entitlements.js';
|
|
20
|
+
export * from './wire.js';
|
|
21
|
+
export * from './define.js';
|
|
22
|
+
export type { ToolIdentity } from './identity.js';
|
|
23
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAAE,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtF,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,uBAAuB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Client-safe entry: pure zod schemas + seam types. No Hono anywhere on this
|
|
2
|
+
// path — the dashboard and SDK import from here and must stay server-free.
|
|
3
|
+
//
|
|
4
|
+
// The generic half of the platform contract. Everything is a static export
|
|
5
|
+
// EXCEPT what carries the tool's scope vocabulary: that comes out of
|
|
6
|
+
// `defineChassisContract({ scopes })`, instantiated once by the tool from its
|
|
7
|
+
// identity (`ToolIdentity`, ./identity.ts: the type only, the value is the tool's).
|
|
8
|
+
export * from './schemas/common.js';
|
|
9
|
+
export * from './schemas/scope.js';
|
|
10
|
+
export * from './schemas/instance.js';
|
|
11
|
+
export * from './schemas/setup.js';
|
|
12
|
+
export { onboardingDismissedSchema } from './schemas/me.js';
|
|
13
|
+
export * from './schemas/workspaces.js';
|
|
14
|
+
export * from './schemas/members.js';
|
|
15
|
+
export { cliAuthRequestSchema, cliAuthRequestedSchema, cliAuthCompleteSchema, cliAuthRevokedSchema } from './schemas/cli-auth.js';
|
|
16
|
+
export * from './schemas/sso-connect.js';
|
|
17
|
+
export * from './schemas/sso-logout.js';
|
|
18
|
+
export * from './schemas/invitations.js';
|
|
19
|
+
export * from './schemas/audit.js';
|
|
20
|
+
export * from './schemas/break-glass.js';
|
|
21
|
+
export * from './schemas/files.js';
|
|
22
|
+
export * from './schemas/projects.js';
|
|
23
|
+
export * from './schemas/teams.js';
|
|
24
|
+
export * from './schemas/demo-passes.js';
|
|
25
|
+
export * from './seams.js';
|
|
26
|
+
export * from './entitlements.js';
|
|
27
|
+
export * from './wire.js';
|
|
28
|
+
export * from './define.js';
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,2EAA2E;AAC3E,EAAE;AACF,2EAA2E;AAC3E,qEAAqE;AACrE,8EAA8E;AAC9E,oFAAoF;AACpF,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,yBAAyB,EAA4B,MAAM,iBAAiB,CAAC;AACtF,cAAc,yBAAyB,CAAC;AACxC,cAAc,sBAAsB,CAAC;AACrC,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EAKrB,MAAM,uBAAuB,CAAC;AAC/B,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AACzC,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|