@w6w/sdk 0.5.0 → 0.9.8
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/README.md +185 -32
- package/dist/mod.d.ts +10 -4
- package/dist/mod.d.ts.map +1 -1
- package/dist/mod.js +3 -0
- package/dist/mod.js.map +1 -1
- package/dist/src/client.d.ts +37 -5
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/client.js +40 -5
- package/dist/src/client.js.map +1 -1
- package/dist/src/config.d.ts +83 -6
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +41 -5
- package/dist/src/config.js.map +1 -1
- package/dist/src/connections.d.ts +3 -2
- package/dist/src/connections.d.ts.map +1 -1
- package/dist/src/connections.js +7 -2
- package/dist/src/connections.js.map +1 -1
- package/dist/src/console/aliases.d.ts +137 -0
- package/dist/src/console/aliases.d.ts.map +1 -0
- package/dist/src/console/aliases.js +113 -0
- package/dist/src/console/aliases.js.map +1 -0
- package/dist/src/console/api-calls.d.ts +4 -3
- package/dist/src/console/api-calls.d.ts.map +1 -1
- package/dist/src/console/api-calls.js +4 -3
- package/dist/src/console/api-calls.js.map +1 -1
- package/dist/src/console/apps.d.ts +181 -8
- package/dist/src/console/apps.d.ts.map +1 -1
- package/dist/src/console/apps.js +67 -12
- package/dist/src/console/apps.js.map +1 -1
- package/dist/src/console/auth.d.ts +245 -7
- package/dist/src/console/auth.d.ts.map +1 -1
- package/dist/src/console/auth.js +177 -8
- package/dist/src/console/auth.js.map +1 -1
- package/dist/src/console/commerce.d.ts +428 -0
- package/dist/src/console/commerce.d.ts.map +1 -0
- package/dist/src/console/commerce.js +220 -0
- package/dist/src/console/commerce.js.map +1 -0
- package/dist/src/console/dashboard.d.ts +8 -0
- package/dist/src/console/dashboard.d.ts.map +1 -1
- package/dist/src/console/dashboard.js.map +1 -1
- package/dist/src/console/endpoints.d.ts +79 -6
- package/dist/src/console/endpoints.d.ts.map +1 -1
- package/dist/src/console/endpoints.js.map +1 -1
- package/dist/src/console/functions.d.ts +35 -4
- package/dist/src/console/functions.d.ts.map +1 -1
- package/dist/src/console/functions.js +13 -0
- package/dist/src/console/functions.js.map +1 -1
- package/dist/src/console/mod.d.ts +32 -7
- package/dist/src/console/mod.d.ts.map +1 -1
- package/dist/src/console/mod.js +26 -1
- package/dist/src/console/mod.js.map +1 -1
- package/dist/src/console/otp.d.ts +127 -0
- package/dist/src/console/otp.d.ts.map +1 -0
- package/dist/src/console/otp.js +118 -0
- package/dist/src/console/otp.js.map +1 -0
- package/dist/src/console/passkeys.d.ts +246 -0
- package/dist/src/console/passkeys.d.ts.map +1 -0
- package/dist/src/console/passkeys.js +192 -0
- package/dist/src/console/passkeys.js.map +1 -0
- package/dist/src/console/reliability.d.ts +101 -6
- package/dist/src/console/reliability.d.ts.map +1 -1
- package/dist/src/console/reliability.js +16 -5
- package/dist/src/console/reliability.js.map +1 -1
- package/dist/src/console/step-tests.d.ts +7 -1
- package/dist/src/console/step-tests.d.ts.map +1 -1
- package/dist/src/console/step-tests.js +1 -1
- package/dist/src/console/step-tests.js.map +1 -1
- package/dist/src/console/subscriptions.d.ts +38 -16
- package/dist/src/console/subscriptions.d.ts.map +1 -1
- package/dist/src/console/subscriptions.js +7 -13
- package/dist/src/console/subscriptions.js.map +1 -1
- package/dist/src/console/tenant-login-flags.d.ts +106 -0
- package/dist/src/console/tenant-login-flags.d.ts.map +1 -0
- package/dist/src/console/tenant-login-flags.js +113 -0
- package/dist/src/console/tenant-login-flags.js.map +1 -0
- package/dist/src/console/tenant-oauth-apps.d.ts +75 -14
- package/dist/src/console/tenant-oauth-apps.d.ts.map +1 -1
- package/dist/src/console/tenant-oauth-apps.js +37 -11
- package/dist/src/console/tenant-oauth-apps.js.map +1 -1
- package/dist/src/console/tokens.d.ts +2 -0
- package/dist/src/console/tokens.d.ts.map +1 -1
- package/dist/src/console/tokens.js.map +1 -1
- package/dist/src/console/workflows.d.ts +14 -0
- package/dist/src/console/workflows.d.ts.map +1 -1
- package/dist/src/console/workflows.js +13 -0
- package/dist/src/console/workflows.js.map +1 -1
- package/dist/src/documents.d.ts +9 -5
- package/dist/src/documents.d.ts.map +1 -1
- package/dist/src/documents.js +6 -3
- package/dist/src/documents.js.map +1 -1
- package/dist/src/endpoints.d.ts +75 -0
- package/dist/src/endpoints.d.ts.map +1 -0
- package/dist/src/endpoints.js +47 -0
- package/dist/src/endpoints.js.map +1 -0
- package/dist/src/functions.d.ts +236 -0
- package/dist/src/functions.d.ts.map +1 -0
- package/dist/src/functions.js +201 -0
- package/dist/src/functions.js.map +1 -0
- package/dist/src/http.d.ts +58 -10
- package/dist/src/http.d.ts.map +1 -1
- package/dist/src/http.js +82 -11
- package/dist/src/http.js.map +1 -1
- package/dist/src/me.d.ts +3 -2
- package/dist/src/me.d.ts.map +1 -1
- package/dist/src/me.js +7 -2
- package/dist/src/me.js.map +1 -1
- package/dist/src/run.d.ts +19 -5
- package/dist/src/run.d.ts.map +1 -1
- package/dist/src/run.js +14 -4
- package/dist/src/run.js.map +1 -1
- package/dist/src/server/mod.d.ts +100 -0
- package/dist/src/server/mod.d.ts.map +1 -0
- package/dist/src/server/mod.js +121 -0
- package/dist/src/server/mod.js.map +1 -0
- package/dist/src/team.d.ts +204 -0
- package/dist/src/team.d.ts.map +1 -0
- package/dist/src/team.js +161 -0
- package/dist/src/team.js.map +1 -0
- package/dist/src/types.d.ts +143 -10
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +27 -0
- package/dist/src/types.js.map +1 -1
- package/dist/src/vars.d.ts +5 -3
- package/dist/src/vars.d.ts.map +1 -1
- package/dist/src/vars.js +14 -4
- package/dist/src/vars.js.map +1 -1
- package/dist/src/version.js +1 -1
- package/dist/src/workflows.d.ts +261 -9
- package/dist/src/workflows.d.ts.map +1 -1
- package/dist/src/workflows.js +246 -7
- package/dist/src/workflows.js.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,428 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `client.console.commerce.*` — the checked-in plan catalog, and the caller's
|
|
3
|
+
* own resolved subscription.
|
|
4
|
+
*
|
|
5
|
+
* **Studio-internal, not the published partner contract.** This namespace
|
|
6
|
+
* lives under the `console` subpath export (`@w6w/sdk/console`), excluded from
|
|
7
|
+
* `endpoints.json` and from the root barrel (`mod.ts`) — see `docs/console.md`
|
|
8
|
+
* and this task's contract. `@w6w/sdk`'s instance-state mechanism pin still
|
|
9
|
+
* applies here exactly as it does to every other namespace
|
|
10
|
+
* (`docs/implementation.md` §MECHANISM PIN — instance state, never globals):
|
|
11
|
+
* this class holds no state of its own beyond the injected host, so two
|
|
12
|
+
* clients in one process never share a credential.
|
|
13
|
+
*
|
|
14
|
+
* **The public/guarded split is per METHOD, not per file, exactly like
|
|
15
|
+
* `console.auth`.** `plans()` is registered above the auth guard
|
|
16
|
+
* (`packages/server/packages/api/commerce/plans-route.ts`'s own doc comment:
|
|
17
|
+
* "PUBLIC: registered above the auth guard by `commerce/edge.ts`") and reads
|
|
18
|
+
* nothing from the request, so it passes `requireAuth: false` and the
|
|
19
|
+
* transport never even attempts to attach a bearer. `subscription()` derives
|
|
20
|
+
* the account from the JWT (`subscription-route.ts`'s own doc comment:
|
|
21
|
+
* "GUARDED") and uses the default, unconditional `requireAuth`.
|
|
22
|
+
*
|
|
23
|
+
* **Both responses carry an envelope key — unlike `console.dashboard`.** The
|
|
24
|
+
* server answers `c.json({ plans: … })` (`plans-route.ts`) and
|
|
25
|
+
* `c.json({ subscription: { plan, status, canUpgrade } })`
|
|
26
|
+
* (`subscription-route.ts`), so both methods here call this package's
|
|
27
|
+
* `unwrap()` helper rather than returning `res.body` verbatim.
|
|
28
|
+
*
|
|
29
|
+
* **`allowance()` (W-12) is the caller's own EFFECTIVE allowance, credits and
|
|
30
|
+
* current-month usage** — `GET /commerce/allowance`, AUTHENTICATED like
|
|
31
|
+
* `subscription()`, unwrapped from the `allowance` envelope. `credits.balance`
|
|
32
|
+
* is SIGNED and never clamped: negative means over by that many executions.
|
|
33
|
+
* Egress-pinned: never `reason`, `setBy`, `grantedBy`, `grants`, `override` or
|
|
34
|
+
* a `/stripe/i` key at any depth — those are operator/control-internal, not
|
|
35
|
+
* account-facing. Any non-200 (including a 424 `control_unavailable` or an old
|
|
36
|
+
* control's 404 `text/plain`) is treated as "unavailable" by callers.
|
|
37
|
+
*
|
|
38
|
+
* @module
|
|
39
|
+
*/
|
|
40
|
+
import type { HttpResponse, RequestOptions } from "../http.ts";
|
|
41
|
+
/**
|
|
42
|
+
* The slice of `W6WClient` this namespace needs: the transport, and nothing
|
|
43
|
+
* else. Structural rather than a concrete client type, so the namespace stays
|
|
44
|
+
* independently constructible in a test and this module never imports the
|
|
45
|
+
* client back — mirrors `ReliabilityHost` in `./reliability.ts`.
|
|
46
|
+
*/
|
|
47
|
+
export interface CommerceHost {
|
|
48
|
+
/** Perform one request. */
|
|
49
|
+
request<T>(options: RequestOptions): Promise<HttpResponse<T>>;
|
|
50
|
+
}
|
|
51
|
+
/** A quota on some countable resource, as `PlanQuotas`' fields each carry one. */
|
|
52
|
+
export type Quota = {
|
|
53
|
+
readonly kind: "unlimited";
|
|
54
|
+
} | {
|
|
55
|
+
readonly kind: "custom";
|
|
56
|
+
} | {
|
|
57
|
+
readonly kind: "capped";
|
|
58
|
+
readonly included: number;
|
|
59
|
+
} | {
|
|
60
|
+
readonly kind: "metered";
|
|
61
|
+
readonly included: number;
|
|
62
|
+
readonly per: number;
|
|
63
|
+
readonly unitAmount: number;
|
|
64
|
+
};
|
|
65
|
+
/** The monitor-cadence limit: how often a health check may run. */
|
|
66
|
+
export interface MonitorLimit {
|
|
67
|
+
readonly quota: Quota;
|
|
68
|
+
readonly minCadenceMinutes: number | "custom";
|
|
69
|
+
}
|
|
70
|
+
/** How long check-run bodies and metadata are retained. */
|
|
71
|
+
export interface RetentionLimit {
|
|
72
|
+
readonly bodiesDays: number | "custom";
|
|
73
|
+
readonly metadataDays: number | "custom";
|
|
74
|
+
}
|
|
75
|
+
/** Every countable resource a plan bounds. */
|
|
76
|
+
export interface PlanQuotas {
|
|
77
|
+
readonly runs: Quota;
|
|
78
|
+
/** Concurrent runs — the server's own `parallelExecutions` dimension. */
|
|
79
|
+
readonly parallelExecutions: Quota;
|
|
80
|
+
readonly monitors: MonitorLimit;
|
|
81
|
+
readonly retention: RetentionLimit;
|
|
82
|
+
readonly projects: Quota;
|
|
83
|
+
readonly seats: Quota;
|
|
84
|
+
}
|
|
85
|
+
/** Whether a plan may self-host, and the annual surcharge if so. */
|
|
86
|
+
export interface SelfHostLicence {
|
|
87
|
+
readonly available: boolean;
|
|
88
|
+
readonly annualSurcharge: number | null;
|
|
89
|
+
}
|
|
90
|
+
/** The feature toggles a plan grants. */
|
|
91
|
+
export interface PlanCapabilities {
|
|
92
|
+
readonly catalogImport: boolean;
|
|
93
|
+
readonly privateRegistry: boolean;
|
|
94
|
+
readonly implSwapAndConfig: boolean;
|
|
95
|
+
readonly versionPinsAndBlocks: boolean;
|
|
96
|
+
readonly egressCaptureExport: boolean;
|
|
97
|
+
readonly embeddedWhiteLabel: boolean;
|
|
98
|
+
readonly sso: boolean;
|
|
99
|
+
readonly auditLog: boolean;
|
|
100
|
+
readonly rbac: boolean;
|
|
101
|
+
readonly dataResidency: boolean;
|
|
102
|
+
readonly selfHostLicence: SelfHostLicence;
|
|
103
|
+
}
|
|
104
|
+
/** A plan's support tier. */
|
|
105
|
+
export type SupportLevel = "community" | "email" | "email-1-business-day" | "sla-named-contact-dpa";
|
|
106
|
+
/** Everything a plan bounds or grants: quotas, capabilities, and support level. */
|
|
107
|
+
export interface PlanLimits {
|
|
108
|
+
readonly quotas: PlanQuotas;
|
|
109
|
+
readonly capabilities: PlanCapabilities;
|
|
110
|
+
readonly support: SupportLevel;
|
|
111
|
+
}
|
|
112
|
+
/** Which cadence a {@link PlanPricePoint} recurs on. */
|
|
113
|
+
export type BillingInterval = "month" | "year";
|
|
114
|
+
/**
|
|
115
|
+
* One published price point. `unitAmount` is integer cents charged per ONE
|
|
116
|
+
* `interval` — an annual point's amount is what is charged once a year, NOT a
|
|
117
|
+
* monthly equivalent, so `$500/yr` arrives as `50000` beside a monthly `5000`.
|
|
118
|
+
*
|
|
119
|
+
* Both figures are authored server-side and neither is derived from the other.
|
|
120
|
+
* A client may compute a saving percentage from the pair for DISPLAY; nothing
|
|
121
|
+
* should reconstruct a price from one and a rate.
|
|
122
|
+
*/
|
|
123
|
+
export interface PlanPricePoint {
|
|
124
|
+
readonly unitAmount: number;
|
|
125
|
+
readonly interval: BillingInterval;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The `price` arm of a plan — exactly what `plans-route.ts`'s `toWirePlan`
|
|
129
|
+
* allowlists. Never `productId`/`lookupKey`/`metered`: the rail (Stripe) is an
|
|
130
|
+
* implementation detail and the product id / lookup key are server
|
|
131
|
+
* configuration, not published pricing.
|
|
132
|
+
*
|
|
133
|
+
* Only the `billable` arm carries price data. `none` (Free) and
|
|
134
|
+
* `contact-sales` (Enterprise) carry no amount, no interval and no currency.
|
|
135
|
+
*/
|
|
136
|
+
export type PlanPrice = {
|
|
137
|
+
readonly kind: "none";
|
|
138
|
+
} | {
|
|
139
|
+
readonly kind: "contact-sales";
|
|
140
|
+
} | {
|
|
141
|
+
readonly kind: "billable";
|
|
142
|
+
readonly currency: "usd";
|
|
143
|
+
readonly monthly: PlanPricePoint;
|
|
144
|
+
/** `null` when the plan is offered monthly only. */
|
|
145
|
+
readonly annual: PlanPricePoint | null;
|
|
146
|
+
};
|
|
147
|
+
/** One entry in the checked-in plan catalog, as `GET /commerce/plans` returns it. */
|
|
148
|
+
export interface Plan {
|
|
149
|
+
/** `"free" | "team" | "business" | "enterprise"` today, typed `string` on the wire. */
|
|
150
|
+
readonly key: string;
|
|
151
|
+
readonly name: string;
|
|
152
|
+
readonly description: string;
|
|
153
|
+
readonly rank: number;
|
|
154
|
+
readonly retired: boolean;
|
|
155
|
+
/** Whether an upgrade INTO this plan must go through sales rather than self-serve checkout — true only for `enterprise` today. Optional/forward-compatible on this SDK copy: absent means false. */
|
|
156
|
+
readonly topTier?: boolean;
|
|
157
|
+
readonly features: readonly string[];
|
|
158
|
+
readonly limits: PlanLimits;
|
|
159
|
+
readonly price: PlanPrice;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* The caller's resolved subscription, as `GET /commerce/subscription`
|
|
163
|
+
* returns it. `status` is the SUBSCRIPTION's status, never a vendor/HTTP
|
|
164
|
+
* status; `plan` is a catalog key, not a display name. Named
|
|
165
|
+
* `CommerceSubscription` rather than the bare `Subscription` — that name is
|
|
166
|
+
* already taken by `console/subscriptions.ts` (webhook-trigger
|
|
167
|
+
* subscriptions, an unrelated domain despite the shared word).
|
|
168
|
+
*/
|
|
169
|
+
export interface CommerceSubscription {
|
|
170
|
+
readonly plan: string;
|
|
171
|
+
readonly status: string;
|
|
172
|
+
readonly canUpgrade: boolean;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* One entry in the caller's own invoice history, as `GET /commerce/invoices`
|
|
176
|
+
* returns it. `id` is OUR id (`commerce.invoice.id`), never a Stripe id;
|
|
177
|
+
* `status` is Stripe's own vocabulary, verbatim. Newest first, ordered
|
|
178
|
+
* server-side by `createdAt` — not `issuedAt`, which is nullable and
|
|
179
|
+
* therefore not a total order for a hand-entered SLA row.
|
|
180
|
+
*/
|
|
181
|
+
export interface Invoice {
|
|
182
|
+
readonly id: string;
|
|
183
|
+
readonly number: string | null;
|
|
184
|
+
readonly status: string;
|
|
185
|
+
readonly amountDueCents: number;
|
|
186
|
+
readonly amountPaidCents: number;
|
|
187
|
+
readonly currency: string;
|
|
188
|
+
readonly hostedInvoiceUrl: string | null;
|
|
189
|
+
readonly issuedAt: string | null;
|
|
190
|
+
readonly dueAt: string | null;
|
|
191
|
+
readonly createdAt: string;
|
|
192
|
+
}
|
|
193
|
+
/** Which cadence a checkout is for — mirrors `PlanPrice`'s own `BillingInterval`. */
|
|
194
|
+
export type CheckoutInterval = "month" | "year";
|
|
195
|
+
/** `client.console.commerce.checkout()`'s input. */
|
|
196
|
+
export interface CheckoutInput {
|
|
197
|
+
readonly planKey: string;
|
|
198
|
+
readonly interval: CheckoutInterval;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* `POST /commerce/checkout`'s response — a hosted Stripe payment page URL,
|
|
202
|
+
* and NOTHING else: never a raw Checkout Session id, price id or product id
|
|
203
|
+
* (the server's own D-3 rule — no Stripe id crosses the wire in either
|
|
204
|
+
* direction).
|
|
205
|
+
*/
|
|
206
|
+
export interface CheckoutResult {
|
|
207
|
+
readonly url: string;
|
|
208
|
+
}
|
|
209
|
+
/** `client.console.commerce.confirmCheckout()`'s input — the `checkout_session_id` the browser was redirected back with. */
|
|
210
|
+
export interface ConfirmCheckoutInput {
|
|
211
|
+
readonly sessionId: string;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* `POST /commerce/contact-sales`'s input. `account` is never sent by the
|
|
215
|
+
* caller — the server stamps it from the bearer's own principal.
|
|
216
|
+
*/
|
|
217
|
+
export interface ContactSalesInput {
|
|
218
|
+
readonly name: string;
|
|
219
|
+
readonly email: string;
|
|
220
|
+
readonly company?: string;
|
|
221
|
+
readonly message: string;
|
|
222
|
+
}
|
|
223
|
+
/** `POST /commerce/contact-sales`'s response. */
|
|
224
|
+
export interface ContactSalesResult {
|
|
225
|
+
readonly id: string;
|
|
226
|
+
}
|
|
227
|
+
/** `client.console.commerce.previewSubscriptionChange()` / `.changeSubscription()`'s shared input. */
|
|
228
|
+
export interface ChangeSubscriptionInput {
|
|
229
|
+
readonly planKey: string;
|
|
230
|
+
readonly interval: CheckoutInterval;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* `POST /commerce/subscription/preview`'s response — what Stripe would
|
|
234
|
+
* charge (positive) or credit (negative) TODAY for this change, in integer
|
|
235
|
+
* cents. Never a raw Stripe invoice object; never rounded/clamped — a large
|
|
236
|
+
* negative value here is a large credit, expected when moving off a
|
|
237
|
+
* part-used ANNUAL plan (Stripe carries the excess forward to future
|
|
238
|
+
* invoices automatically — see the server's `SubscriptionChangeService`).
|
|
239
|
+
*/
|
|
240
|
+
export interface SubscriptionChangePreview {
|
|
241
|
+
readonly amountDueCents: number;
|
|
242
|
+
readonly currency: string;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* `POST /commerce/subscription/change`'s response. `subscription` here is
|
|
246
|
+
* NARROWER than {@link CommerceSubscription} — no `canUpgrade` — the server
|
|
247
|
+
* has no reason to recompute it against the wire's own move; re-fetch
|
|
248
|
+
* `subscription()` if the caller needs it refreshed.
|
|
249
|
+
*/
|
|
250
|
+
export interface SubscriptionChangeResult {
|
|
251
|
+
readonly subscription: {
|
|
252
|
+
readonly plan: string;
|
|
253
|
+
readonly status: string;
|
|
254
|
+
};
|
|
255
|
+
readonly charge: SubscriptionChangePreview;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* A metered/countable dimension's value as `GET /commerce/allowance` states
|
|
259
|
+
* it — a real number, or one of the catalog's two non-numeric arms. Mirrors
|
|
260
|
+
* the vocabulary of `PlanQuotas`' own `Quota.kind` but is deliberately flat
|
|
261
|
+
* (W-12): this endpoint reports one EFFECTIVE number per dimension, never a
|
|
262
|
+
* `{kind, included}` shape.
|
|
263
|
+
*/
|
|
264
|
+
export type AllowanceValue = number | "unlimited" | "custom";
|
|
265
|
+
/**
|
|
266
|
+
* The caller's own accrued extra-usage balance (HITL-1 (b) — "extra
|
|
267
|
+
* executions", not a Stripe balance credit and not a comped plan). `balance`
|
|
268
|
+
* is SIGNED and never clamped: `granted - consumed`, so a negative value means
|
|
269
|
+
* the account is over by that many executions.
|
|
270
|
+
*/
|
|
271
|
+
export interface AccountAllowanceCredits {
|
|
272
|
+
readonly granted: number;
|
|
273
|
+
readonly consumed: number;
|
|
274
|
+
readonly balance: number;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The account's effective per-dimension limits for the current month — the
|
|
278
|
+
* override where the operator set one, the catalog value otherwise. Same 8
|
|
279
|
+
* dimensions `PlanQuotas`/`PlanLimits` bound, flattened to one
|
|
280
|
+
* {@link AllowanceValue} each; no `override`/`metered` field travels on this
|
|
281
|
+
* wire (that provenance is operator/control-internal, never account-facing —
|
|
282
|
+
* see this module's egress pin).
|
|
283
|
+
*/
|
|
284
|
+
export interface AccountAllowanceLimits {
|
|
285
|
+
readonly runs: AllowanceValue;
|
|
286
|
+
readonly parallelExecutions: AllowanceValue;
|
|
287
|
+
readonly monitors: AllowanceValue;
|
|
288
|
+
readonly monitorMinCadenceMinutes: AllowanceValue;
|
|
289
|
+
readonly retentionBodiesDays: AllowanceValue;
|
|
290
|
+
readonly retentionMetadataDays: AllowanceValue;
|
|
291
|
+
readonly projects: AllowanceValue;
|
|
292
|
+
readonly seats: AllowanceValue;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* `GET /commerce/allowance`'s response (W-12) — the caller's own effective
|
|
296
|
+
* allowance, credits and current-month usage. `month` is the reporting month
|
|
297
|
+
* (`"YYYY-MM"`); `executions` is actual usage so far; `included` is the
|
|
298
|
+
* effective monthly allowance; `overage` is executions beyond `included`,
|
|
299
|
+
* reported but not consumed by this SDK's own callers (no enforcement,
|
|
300
|
+
* HITL-3).
|
|
301
|
+
*/
|
|
302
|
+
export interface AccountAllowance {
|
|
303
|
+
readonly month: string;
|
|
304
|
+
readonly executions: number;
|
|
305
|
+
readonly included: AllowanceValue;
|
|
306
|
+
readonly overage: number;
|
|
307
|
+
readonly credits: AccountAllowanceCredits;
|
|
308
|
+
readonly limits: AccountAllowanceLimits;
|
|
309
|
+
readonly customTerms: boolean;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* The `console.commerce` namespace on a `W6WClient`.
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```ts
|
|
316
|
+
* const plans = await client.console.commerce.plans();
|
|
317
|
+
* const { canUpgrade } = await client.console.commerce.subscription();
|
|
318
|
+
* ```
|
|
319
|
+
*/
|
|
320
|
+
export declare class CommerceApi {
|
|
321
|
+
#private;
|
|
322
|
+
/**
|
|
323
|
+
* @param host - The client this namespace issues requests through.
|
|
324
|
+
*/
|
|
325
|
+
constructor(host: CommerceHost);
|
|
326
|
+
/**
|
|
327
|
+
* Fetch the checked-in plan catalog.
|
|
328
|
+
*
|
|
329
|
+
* PUBLIC — sends no bearer, even on a client that already holds one
|
|
330
|
+
* (`requireAuth: false`): the route reads nothing from the request and its
|
|
331
|
+
* output is byte-identical for every caller.
|
|
332
|
+
*
|
|
333
|
+
* @returns The catalog, unwrapped from the `plans` envelope.
|
|
334
|
+
* @throws {ApiError} On any non-2xx.
|
|
335
|
+
*/
|
|
336
|
+
plans(): Promise<Plan[]>;
|
|
337
|
+
/**
|
|
338
|
+
* Fetch the caller's own resolved subscription.
|
|
339
|
+
*
|
|
340
|
+
* AUTHENTICATED — the default `requireAuth` applies: the account is
|
|
341
|
+
* derived server-side from the principal.
|
|
342
|
+
*
|
|
343
|
+
* @returns The subscription, unwrapped from the `subscription` envelope.
|
|
344
|
+
* @throws {ApiError} On any non-2xx, e.g. `409` when the resolved plan key
|
|
345
|
+
* is not in the catalog or is ambiguous.
|
|
346
|
+
*/
|
|
347
|
+
subscription(): Promise<CommerceSubscription>;
|
|
348
|
+
/**
|
|
349
|
+
* Fetch the caller's own invoice history, newest first.
|
|
350
|
+
*
|
|
351
|
+
* AUTHENTICATED — the default `requireAuth` applies: the account is
|
|
352
|
+
* derived server-side from the principal.
|
|
353
|
+
*
|
|
354
|
+
* @returns The invoices, unwrapped from the `invoices` envelope.
|
|
355
|
+
* @throws {ApiError} On any non-2xx.
|
|
356
|
+
*/
|
|
357
|
+
invoices(): Promise<Invoice[]>;
|
|
358
|
+
/**
|
|
359
|
+
* Open a live Stripe Checkout Session for a billable plan/interval.
|
|
360
|
+
* AUTHENTICATED — the account is resolved server-side from the bearer.
|
|
361
|
+
*
|
|
362
|
+
* @returns The hosted payment page URL. Redirect the browser to it
|
|
363
|
+
* (`window.location.href = url`); do not fetch it.
|
|
364
|
+
* @throws {ApiError} `409 plan_not_billable` for a `contact-sales`/`none`
|
|
365
|
+
* plan or an interval the plan doesn't offer; `409 price_not_synced` if
|
|
366
|
+
* the catalog says billable but Stripe has no matching active price yet;
|
|
367
|
+
* `409 plan_not_self_serve` if the account's CURRENT plan is a top-tier
|
|
368
|
+
* plan — an upgrade off it goes through sales, not self-serve checkout.
|
|
369
|
+
*/
|
|
370
|
+
checkout(input: CheckoutInput): Promise<CheckoutResult>;
|
|
371
|
+
/**
|
|
372
|
+
* Confirm a Checkout Session on return from Stripe (the
|
|
373
|
+
* `checkout_session_id` query param `checkout()`'s success URL carries
|
|
374
|
+
* back). Verified against Stripe itself, never trusted from the URL alone
|
|
375
|
+
* — see the server's `CheckoutService` for what this deliberately does not
|
|
376
|
+
* cover (no webhook yet: a session completed after the tab closed is
|
|
377
|
+
* invisible to it).
|
|
378
|
+
*
|
|
379
|
+
* @returns The confirmed subscription.
|
|
380
|
+
* @throws {ApiError} `404 checkout_session_not_found`; `403
|
|
381
|
+
* checkout_session_mismatch` if the session belongs to a different
|
|
382
|
+
* account; `409 checkout_not_paid` if payment hasn't completed yet.
|
|
383
|
+
*/
|
|
384
|
+
confirmCheckout(input: ConfirmCheckoutInput): Promise<CommerceSubscription>;
|
|
385
|
+
/**
|
|
386
|
+
* Submit an Enterprise "contact sales" lead. AUTHENTICATED — captured
|
|
387
|
+
* durably server-side regardless of whether outbound mail is configured
|
|
388
|
+
* (see the server's `ContactSalesService`).
|
|
389
|
+
*/
|
|
390
|
+
contactSales(input: ContactSalesInput): Promise<ContactSalesResult>;
|
|
391
|
+
/**
|
|
392
|
+
* Preview what moving the CALLER'S OWN existing subscription to a
|
|
393
|
+
* different plan/interval would charge or credit TODAY, without applying
|
|
394
|
+
* anything. AUTHENTICATED.
|
|
395
|
+
*
|
|
396
|
+
* @throws {ApiError} `409 no_active_subscription` if the account has no
|
|
397
|
+
* active Stripe subscription to change — use {@link checkout} instead;
|
|
398
|
+
* `409 plan_not_self_serve` if the account's CURRENT plan is a top-tier
|
|
399
|
+
* plan — an upgrade off it goes through sales, not self-serve checkout.
|
|
400
|
+
*/
|
|
401
|
+
previewSubscriptionChange(input: ChangeSubscriptionInput): Promise<SubscriptionChangePreview>;
|
|
402
|
+
/**
|
|
403
|
+
* Apply the change {@link previewSubscriptionChange} previewed — moves the
|
|
404
|
+
* caller's existing Stripe subscription to the new plan/interval with
|
|
405
|
+
* proration, and charges/credits the net difference immediately.
|
|
406
|
+
* AUTHENTICATED.
|
|
407
|
+
*
|
|
408
|
+
* @throws {ApiError} `409 no_active_subscription` if the account has no
|
|
409
|
+
* active Stripe subscription to change — use {@link checkout} instead;
|
|
410
|
+
* `409 plan_not_self_serve` if the account's CURRENT plan is a top-tier
|
|
411
|
+
* plan — an upgrade off it goes through sales, not self-serve checkout.
|
|
412
|
+
*/
|
|
413
|
+
changeSubscription(input: ChangeSubscriptionInput): Promise<SubscriptionChangeResult>;
|
|
414
|
+
/**
|
|
415
|
+
* Fetch the caller's own effective allowance, credits and current-month
|
|
416
|
+
* usage (W-12).
|
|
417
|
+
*
|
|
418
|
+
* AUTHENTICATED — the default `requireAuth` applies: the account is
|
|
419
|
+
* derived server-side from the principal.
|
|
420
|
+
*
|
|
421
|
+
* @returns The allowance, unwrapped from the `allowance` envelope.
|
|
422
|
+
* @throws {ApiError} On any non-2xx, including `424 control_unavailable`
|
|
423
|
+
* when the host cannot reach control — callers should treat ANY non-200
|
|
424
|
+
* here as "unavailable", not just this one code.
|
|
425
|
+
*/
|
|
426
|
+
allowance(): Promise<AccountAllowance>;
|
|
427
|
+
}
|
|
428
|
+
//# sourceMappingURL=commerce.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commerce.d.ts","sourceRoot":"","sources":["../../../src/console/commerce.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;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OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,OAAO,EAAE,uBAAuB,CAAC;IAC1C,QAAQ,CAAC,MAAM,EAAE,sBAAsB,CAAC;IACxC,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;;;;GAQG;AACH,qBAAa,WAAW;;IAGtB;;OAEG;gBACS,IAAI,EAAE,YAAY;IAI9B;;;;;;;;;OASG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;IAS9B;;;;;;;;;OASG;IACG,YAAY,IAAI,OAAO,CAAC,oBAAoB,CAAC;IAQnD;;;;;;;;OAQG;IACG,QAAQ,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAQpC;;;;;;;;;;;OAWG;IACG,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC;IAS7D;;;;;;;;;;;;OAYG;IACG,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IASjF;;;;OAIG;IACG,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC,kBAAkB,CAAC;IASzE;;;;;;;;;OASG;IACG,yBAAyB,CAC7B,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,yBAAyB,CAAC;IASrC;;;;;;;;;;OAUG;IACG,kBAAkB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAS3F;;;;;;;;;;;OAWG;IACG,SAAS,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAO7C"}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `client.console.commerce.*` — the checked-in plan catalog, and the caller's
|
|
3
|
+
* own resolved subscription.
|
|
4
|
+
*
|
|
5
|
+
* **Studio-internal, not the published partner contract.** This namespace
|
|
6
|
+
* lives under the `console` subpath export (`@w6w/sdk/console`), excluded from
|
|
7
|
+
* `endpoints.json` and from the root barrel (`mod.ts`) — see `docs/console.md`
|
|
8
|
+
* and this task's contract. `@w6w/sdk`'s instance-state mechanism pin still
|
|
9
|
+
* applies here exactly as it does to every other namespace
|
|
10
|
+
* (`docs/implementation.md` §MECHANISM PIN — instance state, never globals):
|
|
11
|
+
* this class holds no state of its own beyond the injected host, so two
|
|
12
|
+
* clients in one process never share a credential.
|
|
13
|
+
*
|
|
14
|
+
* **The public/guarded split is per METHOD, not per file, exactly like
|
|
15
|
+
* `console.auth`.** `plans()` is registered above the auth guard
|
|
16
|
+
* (`packages/server/packages/api/commerce/plans-route.ts`'s own doc comment:
|
|
17
|
+
* "PUBLIC: registered above the auth guard by `commerce/edge.ts`") and reads
|
|
18
|
+
* nothing from the request, so it passes `requireAuth: false` and the
|
|
19
|
+
* transport never even attempts to attach a bearer. `subscription()` derives
|
|
20
|
+
* the account from the JWT (`subscription-route.ts`'s own doc comment:
|
|
21
|
+
* "GUARDED") and uses the default, unconditional `requireAuth`.
|
|
22
|
+
*
|
|
23
|
+
* **Both responses carry an envelope key — unlike `console.dashboard`.** The
|
|
24
|
+
* server answers `c.json({ plans: … })` (`plans-route.ts`) and
|
|
25
|
+
* `c.json({ subscription: { plan, status, canUpgrade } })`
|
|
26
|
+
* (`subscription-route.ts`), so both methods here call this package's
|
|
27
|
+
* `unwrap()` helper rather than returning `res.body` verbatim.
|
|
28
|
+
*
|
|
29
|
+
* **`allowance()` (W-12) is the caller's own EFFECTIVE allowance, credits and
|
|
30
|
+
* current-month usage** — `GET /commerce/allowance`, AUTHENTICATED like
|
|
31
|
+
* `subscription()`, unwrapped from the `allowance` envelope. `credits.balance`
|
|
32
|
+
* is SIGNED and never clamped: negative means over by that many executions.
|
|
33
|
+
* Egress-pinned: never `reason`, `setBy`, `grantedBy`, `grants`, `override` or
|
|
34
|
+
* a `/stripe/i` key at any depth — those are operator/control-internal, not
|
|
35
|
+
* account-facing. Any non-200 (including a 424 `control_unavailable` or an old
|
|
36
|
+
* control's 404 `text/plain`) is treated as "unavailable" by callers.
|
|
37
|
+
*
|
|
38
|
+
* @module
|
|
39
|
+
*/
|
|
40
|
+
import { unwrap } from "../types.js";
|
|
41
|
+
/**
|
|
42
|
+
* The `console.commerce` namespace on a `W6WClient`.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const plans = await client.console.commerce.plans();
|
|
47
|
+
* const { canUpgrade } = await client.console.commerce.subscription();
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export class CommerceApi {
|
|
51
|
+
#host;
|
|
52
|
+
/**
|
|
53
|
+
* @param host - The client this namespace issues requests through.
|
|
54
|
+
*/
|
|
55
|
+
constructor(host) {
|
|
56
|
+
this.#host = host;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Fetch the checked-in plan catalog.
|
|
60
|
+
*
|
|
61
|
+
* PUBLIC — sends no bearer, even on a client that already holds one
|
|
62
|
+
* (`requireAuth: false`): the route reads nothing from the request and its
|
|
63
|
+
* output is byte-identical for every caller.
|
|
64
|
+
*
|
|
65
|
+
* @returns The catalog, unwrapped from the `plans` envelope.
|
|
66
|
+
* @throws {ApiError} On any non-2xx.
|
|
67
|
+
*/
|
|
68
|
+
async plans() {
|
|
69
|
+
const res = await this.#host.request({
|
|
70
|
+
method: "GET",
|
|
71
|
+
path: "/commerce/plans",
|
|
72
|
+
requireAuth: false,
|
|
73
|
+
});
|
|
74
|
+
return unwrap(res, "plans");
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Fetch the caller's own resolved subscription.
|
|
78
|
+
*
|
|
79
|
+
* AUTHENTICATED — the default `requireAuth` applies: the account is
|
|
80
|
+
* derived server-side from the principal.
|
|
81
|
+
*
|
|
82
|
+
* @returns The subscription, unwrapped from the `subscription` envelope.
|
|
83
|
+
* @throws {ApiError} On any non-2xx, e.g. `409` when the resolved plan key
|
|
84
|
+
* is not in the catalog or is ambiguous.
|
|
85
|
+
*/
|
|
86
|
+
async subscription() {
|
|
87
|
+
const res = await this.#host.request({
|
|
88
|
+
method: "GET",
|
|
89
|
+
path: "/commerce/subscription",
|
|
90
|
+
});
|
|
91
|
+
return unwrap(res, "subscription");
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Fetch the caller's own invoice history, newest first.
|
|
95
|
+
*
|
|
96
|
+
* AUTHENTICATED — the default `requireAuth` applies: the account is
|
|
97
|
+
* derived server-side from the principal.
|
|
98
|
+
*
|
|
99
|
+
* @returns The invoices, unwrapped from the `invoices` envelope.
|
|
100
|
+
* @throws {ApiError} On any non-2xx.
|
|
101
|
+
*/
|
|
102
|
+
async invoices() {
|
|
103
|
+
const res = await this.#host.request({
|
|
104
|
+
method: "GET",
|
|
105
|
+
path: "/commerce/invoices",
|
|
106
|
+
});
|
|
107
|
+
return unwrap(res, "invoices");
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Open a live Stripe Checkout Session for a billable plan/interval.
|
|
111
|
+
* AUTHENTICATED — the account is resolved server-side from the bearer.
|
|
112
|
+
*
|
|
113
|
+
* @returns The hosted payment page URL. Redirect the browser to it
|
|
114
|
+
* (`window.location.href = url`); do not fetch it.
|
|
115
|
+
* @throws {ApiError} `409 plan_not_billable` for a `contact-sales`/`none`
|
|
116
|
+
* plan or an interval the plan doesn't offer; `409 price_not_synced` if
|
|
117
|
+
* the catalog says billable but Stripe has no matching active price yet;
|
|
118
|
+
* `409 plan_not_self_serve` if the account's CURRENT plan is a top-tier
|
|
119
|
+
* plan — an upgrade off it goes through sales, not self-serve checkout.
|
|
120
|
+
*/
|
|
121
|
+
async checkout(input) {
|
|
122
|
+
const res = await this.#host.request({
|
|
123
|
+
method: "POST",
|
|
124
|
+
path: "/commerce/checkout",
|
|
125
|
+
body: input,
|
|
126
|
+
});
|
|
127
|
+
return unwrap(res, "checkout");
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Confirm a Checkout Session on return from Stripe (the
|
|
131
|
+
* `checkout_session_id` query param `checkout()`'s success URL carries
|
|
132
|
+
* back). Verified against Stripe itself, never trusted from the URL alone
|
|
133
|
+
* — see the server's `CheckoutService` for what this deliberately does not
|
|
134
|
+
* cover (no webhook yet: a session completed after the tab closed is
|
|
135
|
+
* invisible to it).
|
|
136
|
+
*
|
|
137
|
+
* @returns The confirmed subscription.
|
|
138
|
+
* @throws {ApiError} `404 checkout_session_not_found`; `403
|
|
139
|
+
* checkout_session_mismatch` if the session belongs to a different
|
|
140
|
+
* account; `409 checkout_not_paid` if payment hasn't completed yet.
|
|
141
|
+
*/
|
|
142
|
+
async confirmCheckout(input) {
|
|
143
|
+
const res = await this.#host.request({
|
|
144
|
+
method: "POST",
|
|
145
|
+
path: "/commerce/checkout/confirm",
|
|
146
|
+
body: { sessionId: input.sessionId },
|
|
147
|
+
});
|
|
148
|
+
return unwrap(res, "subscription");
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Submit an Enterprise "contact sales" lead. AUTHENTICATED — captured
|
|
152
|
+
* durably server-side regardless of whether outbound mail is configured
|
|
153
|
+
* (see the server's `ContactSalesService`).
|
|
154
|
+
*/
|
|
155
|
+
async contactSales(input) {
|
|
156
|
+
const res = await this.#host.request({
|
|
157
|
+
method: "POST",
|
|
158
|
+
path: "/commerce/contact-sales",
|
|
159
|
+
body: input,
|
|
160
|
+
});
|
|
161
|
+
return unwrap(res, "lead");
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Preview what moving the CALLER'S OWN existing subscription to a
|
|
165
|
+
* different plan/interval would charge or credit TODAY, without applying
|
|
166
|
+
* anything. AUTHENTICATED.
|
|
167
|
+
*
|
|
168
|
+
* @throws {ApiError} `409 no_active_subscription` if the account has no
|
|
169
|
+
* active Stripe subscription to change — use {@link checkout} instead;
|
|
170
|
+
* `409 plan_not_self_serve` if the account's CURRENT plan is a top-tier
|
|
171
|
+
* plan — an upgrade off it goes through sales, not self-serve checkout.
|
|
172
|
+
*/
|
|
173
|
+
async previewSubscriptionChange(input) {
|
|
174
|
+
const res = await this.#host.request({
|
|
175
|
+
method: "POST",
|
|
176
|
+
path: "/commerce/subscription/preview",
|
|
177
|
+
body: input,
|
|
178
|
+
});
|
|
179
|
+
return unwrap(res, "preview");
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Apply the change {@link previewSubscriptionChange} previewed — moves the
|
|
183
|
+
* caller's existing Stripe subscription to the new plan/interval with
|
|
184
|
+
* proration, and charges/credits the net difference immediately.
|
|
185
|
+
* AUTHENTICATED.
|
|
186
|
+
*
|
|
187
|
+
* @throws {ApiError} `409 no_active_subscription` if the account has no
|
|
188
|
+
* active Stripe subscription to change — use {@link checkout} instead;
|
|
189
|
+
* `409 plan_not_self_serve` if the account's CURRENT plan is a top-tier
|
|
190
|
+
* plan — an upgrade off it goes through sales, not self-serve checkout.
|
|
191
|
+
*/
|
|
192
|
+
async changeSubscription(input) {
|
|
193
|
+
const res = await this.#host.request({
|
|
194
|
+
method: "POST",
|
|
195
|
+
path: "/commerce/subscription/change",
|
|
196
|
+
body: input,
|
|
197
|
+
});
|
|
198
|
+
return res.body;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Fetch the caller's own effective allowance, credits and current-month
|
|
202
|
+
* usage (W-12).
|
|
203
|
+
*
|
|
204
|
+
* AUTHENTICATED — the default `requireAuth` applies: the account is
|
|
205
|
+
* derived server-side from the principal.
|
|
206
|
+
*
|
|
207
|
+
* @returns The allowance, unwrapped from the `allowance` envelope.
|
|
208
|
+
* @throws {ApiError} On any non-2xx, including `424 control_unavailable`
|
|
209
|
+
* when the host cannot reach control — callers should treat ANY non-200
|
|
210
|
+
* here as "unavailable", not just this one code.
|
|
211
|
+
*/
|
|
212
|
+
async allowance() {
|
|
213
|
+
const res = await this.#host.request({
|
|
214
|
+
method: "GET",
|
|
215
|
+
path: "/commerce/allowance",
|
|
216
|
+
});
|
|
217
|
+
return unwrap(res, "allowance");
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
//# sourceMappingURL=commerce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commerce.js","sourceRoot":"","sources":["../../../src/console/commerce.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAqSrC;;;;;;;;GAQG;AACH,MAAM,OAAO,WAAW;IACb,KAAK,CAAe;IAE7B;;OAEG;IACH,YAAY,IAAkB;QAC5B,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC;IACpB,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,KAAK;QACT,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAoB;YACtD,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,iBAAiB;YACvB,WAAW,EAAE,KAAK;SACnB,CAAC,CAAC;QACH,OAAO,MAAM,CAAS,GAAG,EAAE,OAAO,CAAC,CAAC;IACtC,CAAC;IAED;;;;;;;;;OASG;IACH,KAAK,CAAC,YAAY;QAChB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAyC;YAC3E,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,wBAAwB;SAC/B,CAAC,CAAC;QACH,OAAO,MAAM,CAAuB,GAAG,EAAE,cAAc,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,QAAQ;QACZ,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAA0B;YAC5D,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,oBAAoB;SAC3B,CAAC,CAAC;QACH,OAAO,MAAM,CAAY,GAAG,EAAE,UAAU,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,QAAQ,CAAC,KAAoB;QACjC,MAAM,GAAG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,MAAM,EAAE,MAAM;YACd,IAAI,EAAE,+BAA+B;YACrC,IAAI,EAAE,KAAK;SACZ,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,IAAI,CAAC;IAClB,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK,CAAC,SAAS;QACb,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,OAAO,CAAkC;YACpE,MAAM,EAAE,KAAK;YACb,IAAI,EAAE,qBAAqB;SAC5B,CAAC,CAAC;QACH,OAAO,MAAM,CAAmB,GAAG,EAAE,WAAW,CAAC,CAAC;IACpD,CAAC;CACF"}
|
|
@@ -72,6 +72,14 @@ export interface DashboardStats {
|
|
|
72
72
|
summary: string | null;
|
|
73
73
|
occurredAt: string;
|
|
74
74
|
workflowId: string | null;
|
|
75
|
+
/** The Function's `fn_…` id; non-null only for `kind: "function"` rows. */
|
|
76
|
+
functionId: string | null;
|
|
77
|
+
/** Wall-clock duration in milliseconds; `null` when unknown. */
|
|
78
|
+
durationMs: number | null;
|
|
79
|
+
/** The owning project id; `null` when none. */
|
|
80
|
+
project: string | null;
|
|
81
|
+
/** The step's id within its workflow; non-null only on `kind: "workflow_step"` rows. */
|
|
82
|
+
stepId: string | null;
|
|
75
83
|
}>;
|
|
76
84
|
}
|
|
77
85
|
/**
|