@enlitt/protocol 0.0.0-stage → 0.1.1

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.
Files changed (51) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/LICENSE +21 -0
  3. package/README.md +15 -2
  4. package/dist/admin.d.cts +353 -0
  5. package/dist/admin.d.ts +354 -0
  6. package/dist/admin.d.ts.map +1 -0
  7. package/dist/authentication.d.cts +8 -0
  8. package/dist/authentication.d.ts +9 -0
  9. package/dist/authentication.d.ts.map +1 -0
  10. package/dist/canonical-integer.d.cts +48 -0
  11. package/dist/canonical-integer.d.ts +49 -0
  12. package/dist/canonical-integer.d.ts.map +1 -0
  13. package/dist/compatibility.d.cts +23 -0
  14. package/dist/compatibility.d.ts +24 -0
  15. package/dist/compatibility.d.ts.map +1 -0
  16. package/dist/contract.d.cts +67 -0
  17. package/dist/contract.d.ts +68 -0
  18. package/dist/contract.d.ts.map +1 -0
  19. package/dist/dashboard.d.cts +1078 -0
  20. package/dist/dashboard.d.ts +1079 -0
  21. package/dist/dashboard.d.ts.map +1 -0
  22. package/dist/errors.d.cts +113 -0
  23. package/dist/errors.d.ts +114 -0
  24. package/dist/errors.d.ts.map +1 -0
  25. package/dist/idempotency.d.cts +79 -0
  26. package/dist/idempotency.d.ts +80 -0
  27. package/dist/idempotency.d.ts.map +1 -0
  28. package/dist/index.cjs +5050 -0
  29. package/dist/index.cjs.map +1 -0
  30. package/dist/index.d.cts +33 -0
  31. package/dist/index.d.ts +34 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +4857 -0
  34. package/dist/index.js.map +1 -0
  35. package/dist/outreach.d.cts +73 -0
  36. package/dist/outreach.d.ts +74 -0
  37. package/dist/outreach.d.ts.map +1 -0
  38. package/dist/premium-operations.d.cts +84 -0
  39. package/dist/premium-operations.d.ts +85 -0
  40. package/dist/premium-operations.d.ts.map +1 -0
  41. package/dist/response-stream.d.cts +246 -0
  42. package/dist/response-stream.d.ts +247 -0
  43. package/dist/response-stream.d.ts.map +1 -0
  44. package/dist/responses.d.cts +233 -0
  45. package/dist/responses.d.ts +234 -0
  46. package/dist/responses.d.ts.map +1 -0
  47. package/dist/usage.d.cts +11 -0
  48. package/dist/usage.d.ts +12 -0
  49. package/dist/usage.d.ts.map +1 -0
  50. package/generated/contract.json +491 -0
  51. package/package.json +60 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ All notable protocol changes are documented here.
4
+
5
+ ## 0.1.1
6
+
7
+ - Added the per-application premium switch: the `premium_not_enabled` error code, `premium_enabled`
8
+ on application views, and `validateBusinessApplicationPremiumRequest`.
9
+ - Added the premium cost profile's charge histogram (`PremiumUnitsHistogram`,
10
+ `premiumUnitsHistogramBinCount`).
11
+ - Added the outreach visit contract (`POST`/`GET /v1/outreach/visits`).
12
+
13
+ ## 0.1.0
14
+
15
+ First public release.
16
+
17
+ - Added the provider-neutral `EnlittStandardRequest`, premium-operation validators, API versioning,
18
+ tolerant response parsing, a frozen error classifier, shared fixtures, and a generated
19
+ cross-language contract.
20
+ - Added CLI authorization validators (`/v1/cli/*`, CLI authorization view, CLI credential list),
21
+ the four device-flow error codes, `normalizeCliUserCode`, and the business key-list query validator.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Enlitt
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # `@enlitt/protocol`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Versioned runtime schemas and transport-level types shared by the Enlitt backend and SDK.
4
+
5
+ This package is framework-neutral. It contains the strict request validators, strict/tolerant
6
+ response readers, stable errors, streaming events, shared wire fixtures, and compatibility rules,
7
+ but no application or database behavior.
8
+
9
+ The generated cross-language contract is published as `@enlitt/protocol/contract.json`. Run
10
+ `pnpm --filter @enlitt/protocol generate:contract` after changing a protocol constant or closed set.
11
+
12
+ `validateAuthorizationExchangeResponse()` validates the login exchange's opaque
13
+ `session_token` and application-scoped stable `subject`. Servers emit the strict
14
+ shape; SDK callbacks read with `{ mode: "tolerant" }` so future response fields
15
+ do not interrupt login. A subject links an application's own user records and
16
+ is never accepted as a credential or model-request identity.
@@ -0,0 +1,353 @@
1
+ /**
2
+ * The operator-CLI wire contract: `POST /v1/admin/actions` (`specs/PROTOCOLS.md`
3
+ * "Admin actions"). It is not a public or browser API and is deliberately
4
+ * absent from `contract.json`'s route list; only the operator CLI and the
5
+ * backend admin route use these validators.
6
+ *
7
+ * Requests are strict: an unknown field, a missing required field, a float
8
+ * amount, or a write command without a reason is refused. Responses are read
9
+ * strictly by default, or tolerantly with `{ mode: "tolerant" }` (unknown
10
+ * fields dropped, future closed-enum members mapped to `"other"`).
11
+ *
12
+ * Amounts follow the shared rule: credits are milli-credit integer strings,
13
+ * money is minor-unit or NANOUSD integer strings (canonical base-10, no sign,
14
+ * no fraction). Instants are RFC 3339.
15
+ */
16
+ import { type ParseOptions } from "./compatibility.cjs";
17
+ import type { ResponseValidationResult } from "./responses.cjs";
18
+ type Result<T> = ResponseValidationResult<T>;
19
+ /** Read commands: they change nothing and need no reason. */
20
+ export declare const ADMIN_READ_COMMANDS: readonly ["inspect.user", "inspect.business", "inspect.app", "inspect.order", "inspect.call", "inspect.txn", "sql", "log", "report.platform"];
21
+ /** Write commands: a reason of 1 to 1,000 characters is required. */
22
+ export declare const ADMIN_WRITE_COMMANDS: readonly ["refund.cash", "refund.manual", "refund.mark_paid", "refund.cancel_manual", "credits.grant", "plan.set", "plan.reset", "status.suspend", "status.unsuspend", "payout.block", "payout.unblock", "payout.create", "payout.execute", "gift.create", "gift.revoke", "account.set_email", "account.release_phone", "account.set_app_limits", "account.set_default_limit"];
23
+ export declare const ADMIN_COMMAND_NAMES: readonly ["inspect.user", "inspect.business", "inspect.app", "inspect.order", "inspect.call", "inspect.txn", "sql", "log", "report.platform", "refund.cash", "refund.manual", "refund.mark_paid", "refund.cancel_manual", "credits.grant", "plan.set", "plan.reset", "status.suspend", "status.unsuspend", "payout.block", "payout.unblock", "payout.create", "payout.execute", "gift.create", "gift.revoke", "account.set_email", "account.release_phone", "account.set_app_limits", "account.set_default_limit"];
24
+ export type AdminCommandName = (typeof ADMIN_COMMAND_NAMES)[number];
25
+ export declare const ADMIN_ACTION_KINDS: readonly ["read", "write"];
26
+ export declare const ADMIN_ACTION_STATUSES: readonly ["started", "succeeded", "failed"];
27
+ export declare const ADMIN_SUBJECTS: readonly ["user", "business", "app"];
28
+ export declare const ADMIN_REASON_MAX_LENGTH = 1000;
29
+ export declare const ADMIN_SQL_MAX_LENGTH = 20000;
30
+ export declare const ADMIN_SQL_MAX_LIMIT = 1000;
31
+ export declare const ADMIN_LOG_MAX_LIMIT = 200;
32
+ export declare const ADMIN_SUSPEND_MAX_DAYS = 3650;
33
+ /** `report.platform` reports on at most the last 90 days; the weekly email uses 7. */
34
+ export declare const ADMIN_REPORT_MAX_DAYS = 90;
35
+ export declare const ADMIN_REPORT_DEFAULT_DAYS = 7;
36
+ /** How a `PlatformReportRow` value is measured, and so how a client formats it. */
37
+ export declare const PLATFORM_REPORT_UNITS: readonly ["count", "nano_usd", "usd_cents", "milli_credits"];
38
+ /** The request body limit the route enforces. */
39
+ export declare const ADMIN_REQUEST_MAX_BYTES: number;
40
+ export declare function isAdminCommandName(value: unknown): value is AdminCommandName;
41
+ /** `"read"` or `"write"` for a known command. */
42
+ export declare function adminCommandKind(command: AdminCommandName): "read" | "write";
43
+ export type AdminSubject = (typeof ADMIN_SUBJECTS)[number];
44
+ export interface AdminLimits {
45
+ readonly standard_per_call?: string;
46
+ readonly premium_per_call?: string;
47
+ }
48
+ export interface AdminCommandArgs {
49
+ "inspect.user": {
50
+ readonly id?: string;
51
+ readonly email?: string;
52
+ };
53
+ "inspect.business": {
54
+ readonly id?: string;
55
+ readonly email?: string;
56
+ };
57
+ "inspect.app": {
58
+ readonly id: string;
59
+ };
60
+ "inspect.order": {
61
+ readonly id: string;
62
+ };
63
+ "inspect.call": {
64
+ readonly id: string;
65
+ };
66
+ "inspect.txn": {
67
+ readonly id: string;
68
+ };
69
+ sql: {
70
+ readonly sql: string;
71
+ readonly limit?: number;
72
+ };
73
+ log: {
74
+ readonly operator?: string;
75
+ readonly target_id?: string;
76
+ readonly limit?: number;
77
+ readonly cursor?: string;
78
+ };
79
+ "report.platform": {
80
+ readonly days?: number;
81
+ };
82
+ "refund.cash": {
83
+ readonly order_id: string;
84
+ readonly amount_minor_units: string | null;
85
+ };
86
+ "refund.manual": {
87
+ readonly order_id: string;
88
+ readonly amount_minor_units: string;
89
+ };
90
+ "refund.mark_paid": {
91
+ readonly transaction_id: string;
92
+ readonly bank_reference: string;
93
+ };
94
+ "refund.cancel_manual": {
95
+ readonly transaction_id: string;
96
+ };
97
+ "credits.grant": {
98
+ readonly user_id: string;
99
+ readonly standard_units: string;
100
+ readonly premium_units: string;
101
+ readonly call_id: string | null;
102
+ };
103
+ "plan.set": {
104
+ readonly user_id: string;
105
+ readonly plan_id: string;
106
+ readonly catalog_version: string;
107
+ };
108
+ "plan.reset": {
109
+ readonly user_id: string;
110
+ };
111
+ "status.suspend": {
112
+ readonly subject: AdminSubject;
113
+ readonly id: string;
114
+ readonly days: number | null;
115
+ };
116
+ "status.unsuspend": {
117
+ readonly subject: AdminSubject;
118
+ readonly id: string;
119
+ };
120
+ "payout.block": {
121
+ readonly business_id: string;
122
+ };
123
+ "payout.unblock": {
124
+ readonly business_id: string;
125
+ };
126
+ "payout.create": {
127
+ readonly business_id: string;
128
+ readonly nano_usd: string;
129
+ };
130
+ "payout.execute": {
131
+ readonly transaction_id: string;
132
+ };
133
+ "gift.create": {
134
+ readonly product_kind: "subscription" | "bundle";
135
+ readonly product_id: string;
136
+ readonly catalog_version: string;
137
+ readonly expires_at: string | null;
138
+ };
139
+ "gift.revoke": {
140
+ readonly gift_code_id: string;
141
+ };
142
+ "account.set_email": {
143
+ readonly auth_user_id: string;
144
+ readonly email: string;
145
+ };
146
+ "account.release_phone": {
147
+ readonly user_id: string;
148
+ };
149
+ "account.set_app_limits": {
150
+ readonly user_id: string;
151
+ readonly application_id: string;
152
+ readonly limits: AdminLimits;
153
+ };
154
+ "account.set_default_limit": {
155
+ readonly user_id: string;
156
+ readonly premium_per_call: string;
157
+ };
158
+ }
159
+ export interface AdminActionSummary {
160
+ readonly action_id: string;
161
+ readonly operator: string;
162
+ readonly command: string;
163
+ readonly kind: "read" | "write";
164
+ readonly reason: string | null;
165
+ readonly status: "started" | "succeeded" | "failed";
166
+ readonly target_type: string | null;
167
+ readonly target_id: string | null;
168
+ readonly error_code: string | null;
169
+ readonly created_at: string;
170
+ readonly finished_at: string | null;
171
+ }
172
+ export type PlatformReportUnit = (typeof PLATFORM_REPORT_UNITS)[number];
173
+ /**
174
+ * One line of the platform report (`PROTOCOLS.md` "Admin actions"). Both values
175
+ * are decimal integer strings and may be negative; `window` is null on a
176
+ * snapshot row, whose `total` is the state at `window_end`.
177
+ */
178
+ export interface PlatformReportRow {
179
+ readonly label: string;
180
+ readonly unit: PlatformReportUnit;
181
+ readonly window: string | null;
182
+ readonly total: string;
183
+ }
184
+ /** The `report.platform` result; its sections and labels are owned by `specs/Admin.md`. */
185
+ export interface PlatformReport {
186
+ readonly environment: string;
187
+ readonly window_start: string;
188
+ readonly window_end: string;
189
+ readonly sections: readonly {
190
+ readonly title: string;
191
+ readonly rows: readonly PlatformReportRow[];
192
+ }[];
193
+ }
194
+ /** An `inspect.*` summary: backend-owned, content-free, shaped per record kind. */
195
+ export type AdminInspectResult = Readonly<Record<string, unknown>>;
196
+ export interface AdminCommandResult {
197
+ "inspect.user": AdminInspectResult;
198
+ "inspect.business": AdminInspectResult;
199
+ "inspect.app": AdminInspectResult;
200
+ "inspect.order": AdminInspectResult;
201
+ "inspect.call": AdminInspectResult;
202
+ "inspect.txn": AdminInspectResult;
203
+ sql: {
204
+ readonly columns: readonly string[];
205
+ readonly rows: readonly (readonly unknown[])[];
206
+ readonly truncated: boolean;
207
+ };
208
+ log: {
209
+ readonly actions: readonly AdminActionSummary[];
210
+ readonly next_cursor: string | null;
211
+ };
212
+ "report.platform": Pick<PlatformReport, keyof PlatformReport>;
213
+ "refund.cash": {
214
+ readonly order_id: string;
215
+ readonly refunds: readonly {
216
+ readonly transaction_id: string;
217
+ readonly amount_minor_units: string;
218
+ readonly status: string;
219
+ }[];
220
+ readonly remaining_minor_units: string;
221
+ };
222
+ "refund.manual": {
223
+ readonly transaction_id: string;
224
+ readonly status: "pending";
225
+ };
226
+ "refund.mark_paid": {
227
+ readonly transaction_id: string;
228
+ readonly status: "completed";
229
+ };
230
+ "refund.cancel_manual": {
231
+ readonly transaction_id: string;
232
+ readonly status: "canceled";
233
+ };
234
+ "credits.grant": {
235
+ readonly transaction_id: string;
236
+ readonly extra_credit: {
237
+ readonly standard_units: string;
238
+ readonly premium_units: string;
239
+ };
240
+ };
241
+ "plan.set": {
242
+ readonly subscription: unknown;
243
+ };
244
+ "plan.reset": {
245
+ readonly subscription: unknown;
246
+ readonly period_start: string;
247
+ readonly period_end: string;
248
+ };
249
+ "status.suspend": {
250
+ readonly subject: AdminSubject;
251
+ readonly id: string;
252
+ readonly status: "suspended";
253
+ readonly suspended_until: string | null;
254
+ /**
255
+ * What the billing step did for a user suspension: each order's refund
256
+ * outcome under the refund policy and whether the subscription was
257
+ * canceled. Null for a business or an app, which hold no purchase orders.
258
+ */
259
+ readonly billing: {
260
+ readonly refunds: readonly {
261
+ readonly order_id: string;
262
+ readonly outcome: "refunded" | "under_review" | "refused" | "ineligible";
263
+ readonly refund_minor_units: string;
264
+ readonly reason: string;
265
+ }[];
266
+ readonly subscription_canceled: boolean;
267
+ } | null;
268
+ };
269
+ "status.unsuspend": {
270
+ readonly subject: AdminSubject;
271
+ readonly id: string;
272
+ readonly status: "active";
273
+ };
274
+ "payout.block": {
275
+ readonly business_id: string;
276
+ readonly payout_blocked: boolean;
277
+ };
278
+ "payout.unblock": {
279
+ readonly business_id: string;
280
+ readonly payout_blocked: boolean;
281
+ };
282
+ "payout.create": {
283
+ readonly transaction_id: string;
284
+ readonly nano_usd: string;
285
+ readonly status: "pending";
286
+ };
287
+ "payout.execute": {
288
+ readonly transaction_id: string;
289
+ readonly status: string;
290
+ };
291
+ "gift.create": {
292
+ readonly gift_code_id: string;
293
+ readonly code: string | null;
294
+ };
295
+ "gift.revoke": {
296
+ readonly gift_code_id: string;
297
+ readonly status: "revoked";
298
+ };
299
+ "account.set_email": {
300
+ readonly auth_user_id: string;
301
+ readonly email: string;
302
+ };
303
+ "account.release_phone": {
304
+ readonly user_id: string;
305
+ readonly phone_released: true;
306
+ };
307
+ "account.set_app_limits": {
308
+ readonly application_id: string;
309
+ readonly limits: AdminLimits;
310
+ };
311
+ "account.set_default_limit": {
312
+ readonly user_id: string;
313
+ readonly new_application_premium_per_call_limit: string;
314
+ };
315
+ }
316
+ export interface AdminActionRequest {
317
+ readonly action_id: string;
318
+ readonly command: AdminCommandName;
319
+ readonly args: Readonly<Record<string, unknown>>;
320
+ readonly reason: string | null;
321
+ }
322
+ export interface AdminActionSuccessResponse {
323
+ readonly action_id: string;
324
+ readonly command: string;
325
+ readonly status: "succeeded";
326
+ readonly replayed: boolean;
327
+ readonly result: Readonly<Record<string, unknown>>;
328
+ }
329
+ export interface AdminActionErrorResponse {
330
+ readonly error: {
331
+ readonly code: string;
332
+ readonly message: string;
333
+ readonly param?: string;
334
+ };
335
+ readonly request_id: string;
336
+ readonly action_id?: string;
337
+ }
338
+ /** Validates `args` for one command (strict: unknown or missing fields fail). */
339
+ export declare function validateAdminCommandArgs<C extends AdminCommandName>(command: C, args: unknown): Result<AdminCommandArgs[C]>;
340
+ /** Validates a command's `result` object (tolerant mode drops unknown fields). */
341
+ export declare function validateAdminCommandResult<C extends AdminCommandName>(command: C, result: unknown, options?: ParseOptions): Result<AdminCommandResult[C]>;
342
+ /**
343
+ * `POST /v1/admin/actions` body: exactly `{ action_id, command, args, reason }`.
344
+ * The returned `args` are the validated, normalised arguments for `command`.
345
+ */
346
+ export declare function validateAdminActionRequest(value: unknown): Result<AdminActionRequest>;
347
+ /** `200` body of `POST /v1/admin/actions`; `result` is checked against the command. */
348
+ export declare function validateAdminActionResponse(value: unknown, options?: ParseOptions): Result<AdminActionSuccessResponse>;
349
+ /** Error body of the admin route: the dashboard envelope plus `action_id` when the body parsed. */
350
+ export declare function validateAdminActionErrorResponse(value: unknown, options?: ParseOptions): Result<AdminActionErrorResponse>;
351
+ /** One audit-log row, as returned by `log`. */
352
+ export declare function validateAdminActionSummary(value: unknown, options?: ParseOptions): Result<AdminActionSummary>;
353
+ export {};