@zveltio/sdk 3.0.0-beta.1 → 3.0.0-beta.100

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 (151) hide show
  1. package/README.md +17 -4
  2. package/dist/client.d.ts +103 -7
  3. package/dist/client.d.ts.map +1 -1
  4. package/dist/client.js +117 -27
  5. package/dist/core.d.ts.map +1 -1
  6. package/dist/core.js +21 -3
  7. package/dist/crdt.d.ts.map +1 -1
  8. package/dist/crdt.js +11 -2
  9. package/dist/ddl/index.d.ts +20 -0
  10. package/dist/ddl/index.d.ts.map +1 -1
  11. package/dist/errors.d.ts +58 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +124 -0
  14. package/dist/extension/action-refusal.d.ts +27 -0
  15. package/dist/extension/action-refusal.d.ts.map +1 -0
  16. package/dist/extension/action-refusal.js +29 -0
  17. package/dist/extension/capabilities.d.ts +71 -0
  18. package/dist/extension/capabilities.d.ts.map +1 -0
  19. package/dist/extension/capabilities.js +79 -0
  20. package/dist/extension/dates.d.ts +7 -0
  21. package/dist/extension/dates.d.ts.map +1 -0
  22. package/dist/extension/dates.js +14 -0
  23. package/dist/extension/index.d.ts +1086 -38
  24. package/dist/extension/index.d.ts.map +1 -1
  25. package/dist/extension/index.js +16 -0
  26. package/dist/extension/jsonb.d.ts +62 -0
  27. package/dist/extension/jsonb.d.ts.map +1 -0
  28. package/dist/extension/jsonb.js +64 -0
  29. package/dist/extension/multipart.d.ts +58 -0
  30. package/dist/extension/multipart.d.ts.map +1 -0
  31. package/dist/extension/multipart.js +61 -0
  32. package/dist/extension/numeric.d.ts +94 -0
  33. package/dist/extension/numeric.d.ts.map +1 -0
  34. package/dist/extension/numeric.js +162 -0
  35. package/dist/extension/permission-gate.d.ts +15 -0
  36. package/dist/extension/permission-gate.d.ts.map +1 -1
  37. package/dist/extension/permission-gate.js +33 -1
  38. package/dist/extension/reserved-paths.d.ts +10 -0
  39. package/dist/extension/reserved-paths.d.ts.map +1 -0
  40. package/dist/extension/reserved-paths.js +23 -0
  41. package/dist/index.d.ts +3 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +1 -0
  44. package/dist/local-store.d.ts +14 -1
  45. package/dist/local-store.d.ts.map +1 -1
  46. package/dist/local-store.js +92 -13
  47. package/dist/offline/index.d.ts +25 -55
  48. package/dist/offline/index.d.ts.map +1 -1
  49. package/dist/offline/index.js +173 -157
  50. package/dist/publish/index.d.ts.map +1 -1
  51. package/dist/publish/index.js +6 -1
  52. package/dist/realtime.d.ts +25 -1
  53. package/dist/realtime.d.ts.map +1 -1
  54. package/dist/realtime.js +47 -3
  55. package/dist/rpc/index.d.ts.map +1 -1
  56. package/dist/rpc/index.js +2 -0
  57. package/dist/schema-codegen.d.ts +25 -1
  58. package/dist/schema-codegen.d.ts.map +1 -1
  59. package/dist/schema-codegen.js +141 -7
  60. package/dist/schema-watcher.d.ts +10 -2
  61. package/dist/schema-watcher.d.ts.map +1 -1
  62. package/dist/schema-watcher.js +25 -10
  63. package/dist/studio/index.d.ts +1 -0
  64. package/dist/studio/index.d.ts.map +1 -1
  65. package/dist/studio/index.js +3 -0
  66. package/dist/studio/slot-owner-registry.d.ts +13 -0
  67. package/dist/studio/slot-owner-registry.d.ts.map +1 -0
  68. package/dist/studio/slot-owner-registry.js +21 -0
  69. package/dist/svelte.d.ts +1 -1
  70. package/dist/svelte.d.ts.map +1 -1
  71. package/dist/svelte.js +4 -2
  72. package/dist/sync-manager.d.ts +49 -4
  73. package/dist/sync-manager.d.ts.map +1 -1
  74. package/dist/sync-manager.js +173 -15
  75. package/dist/testing/index.d.ts.map +1 -1
  76. package/dist/testing/index.js +23 -1
  77. package/dist/testing/with-test-db.d.ts +1 -1
  78. package/dist/testing/with-test-db.d.ts.map +1 -1
  79. package/dist/testing/with-test-db.js +22 -15
  80. package/dist/tests/action-refusal.test.d.ts +2 -0
  81. package/dist/tests/action-refusal.test.d.ts.map +1 -0
  82. package/dist/tests/action-refusal.test.js +13 -0
  83. package/dist/tests/client.test.d.ts +2 -0
  84. package/dist/tests/client.test.d.ts.map +1 -0
  85. package/dist/tests/client.test.js +164 -0
  86. package/dist/tests/crdt-orset.test.d.ts +2 -0
  87. package/dist/tests/crdt-orset.test.d.ts.map +1 -0
  88. package/dist/tests/crdt-orset.test.js +23 -0
  89. package/dist/tests/local-store.test.js +44 -0
  90. package/dist/tests/migration-parse.test.d.ts +2 -0
  91. package/dist/tests/migration-parse.test.d.ts.map +1 -0
  92. package/dist/tests/migration-parse.test.js +17 -0
  93. package/dist/tests/multipart.test.d.ts +2 -0
  94. package/dist/tests/multipart.test.d.ts.map +1 -0
  95. package/dist/tests/multipart.test.js +37 -0
  96. package/dist/tests/offline-provider-crdt.test.d.ts +2 -0
  97. package/dist/tests/offline-provider-crdt.test.d.ts.map +1 -0
  98. package/dist/tests/offline-provider-crdt.test.js +206 -0
  99. package/dist/tests/realtime.test.d.ts +2 -0
  100. package/dist/tests/realtime.test.d.ts.map +1 -0
  101. package/dist/tests/realtime.test.js +220 -0
  102. package/dist/tests/reserved-paths.test.d.ts +2 -0
  103. package/dist/tests/reserved-paths.test.d.ts.map +1 -0
  104. package/dist/tests/reserved-paths.test.js +21 -0
  105. package/dist/tests/sync-manager.test.d.ts +2 -0
  106. package/dist/tests/sync-manager.test.d.ts.map +1 -0
  107. package/dist/tests/sync-manager.test.js +123 -0
  108. package/dist/tests/today-in.test.d.ts +2 -0
  109. package/dist/tests/today-in.test.d.ts.map +1 -0
  110. package/dist/tests/today-in.test.js +14 -0
  111. package/dist/tests/validate-manifest-actions.test.d.ts +2 -0
  112. package/dist/tests/validate-manifest-actions.test.d.ts.map +1 -0
  113. package/dist/tests/validate-manifest-actions.test.js +82 -0
  114. package/dist/tests/validate-manifest-dependencies.test.d.ts +2 -0
  115. package/dist/tests/validate-manifest-dependencies.test.d.ts.map +1 -0
  116. package/dist/tests/validate-manifest-dependencies.test.js +27 -0
  117. package/dist/tests/validate-manifest-forward-credentials.test.d.ts +2 -0
  118. package/dist/tests/validate-manifest-forward-credentials.test.d.ts.map +1 -0
  119. package/dist/tests/validate-manifest-forward-credentials.test.js +35 -0
  120. package/dist/tests/validate-sdui-data-endpoints.test.d.ts +2 -0
  121. package/dist/tests/validate-sdui-data-endpoints.test.d.ts.map +1 -0
  122. package/dist/tests/validate-sdui-data-endpoints.test.js +41 -0
  123. package/dist/tests/with-test-db.test.d.ts +2 -0
  124. package/dist/tests/with-test-db.test.d.ts.map +1 -0
  125. package/dist/tests/with-test-db.test.js +57 -0
  126. package/dist/types/index.d.ts.map +1 -1
  127. package/dist/validate/index.d.ts +53 -0
  128. package/dist/validate/index.d.ts.map +1 -1
  129. package/dist/validate/index.js +693 -7
  130. package/dist/validate/migration-parse.d.ts +10 -5
  131. package/dist/validate/migration-parse.d.ts.map +1 -1
  132. package/dist/validate/migration-parse.js +1 -1
  133. package/dist/validate/shared-message-keys.d.ts +16 -0
  134. package/dist/validate/shared-message-keys.d.ts.map +1 -0
  135. package/dist/validate/shared-message-keys.js +227 -0
  136. package/package.json +8 -8
  137. package/dist/client/Auth.d.ts +0 -19
  138. package/dist/client/Auth.d.ts.map +0 -1
  139. package/dist/client/Auth.js +0 -45
  140. package/dist/client/QueryBuilder.d.ts +0 -17
  141. package/dist/client/QueryBuilder.d.ts.map +0 -1
  142. package/dist/client/QueryBuilder.js +0 -85
  143. package/dist/client/RealtimeClient.d.ts +0 -22
  144. package/dist/client/RealtimeClient.d.ts.map +0 -1
  145. package/dist/client/RealtimeClient.js +0 -98
  146. package/dist/client/ZveltioClient.d.ts +0 -20
  147. package/dist/client/ZveltioClient.d.ts.map +0 -1
  148. package/dist/client/ZveltioClient.js +0 -78
  149. package/dist/generate-types.d.ts +0 -37
  150. package/dist/generate-types.d.ts.map +0 -1
  151. package/dist/generate-types.js +0 -157
@@ -0,0 +1,58 @@
1
+ /**
2
+ * Unified error envelope (H-13) — the SDK is the contract source of truth for
3
+ * error shapes, exactly as it is for `ZveltioExtension`.
4
+ *
5
+ * Every non-2xx response from the engine carries an RFC 9457 `problem+json`
6
+ * body: the standard fields (`type`, `title`, `status`, `detail`, `instance`)
7
+ * plus two Zveltio extensions:
8
+ * - `code` — a STABLE machine-readable string (e.g. `tenant.membership_required`)
9
+ * that clients can switch on without parsing prose.
10
+ * - `traceId` — correlates with server logs / the W3C trace, for support.
11
+ *
12
+ * The engine mirrors this shape (it can't import the SDK root at build time);
13
+ * keep the two in sync — this file is the canonical definition.
14
+ */
15
+ /** RFC 9457 problem-details object + Zveltio `code`/`traceId` extensions. */
16
+ export interface ProblemDetails {
17
+ /** URI reference identifying the problem type. `about:blank` when the HTTP
18
+ * status is the only semantics. */
19
+ type: string;
20
+ /** Short, human-readable summary — stable for a given `code`/status. */
21
+ title: string;
22
+ /** HTTP status code, duplicated in the body per RFC 9457. */
23
+ status: number;
24
+ /** Human-readable explanation specific to this occurrence. */
25
+ detail?: string;
26
+ /** URI reference for this specific occurrence — the request path. */
27
+ instance?: string;
28
+ /** Stable machine-readable error code, e.g. `tenant.membership_required`. */
29
+ code: string;
30
+ /** Correlation id for server logs / distributed trace. */
31
+ traceId?: string;
32
+ /** Optional structured details (e.g. per-field validation errors). */
33
+ errors?: unknown;
34
+ }
35
+ /** MIME type the engine sets on every error response. */
36
+ export declare const PROBLEM_CONTENT_TYPE = "application/problem+json";
37
+ /**
38
+ * Typed error thrown by the SDK client for any non-2xx response. Carries the
39
+ * parsed envelope; tolerant of legacy `{ error }` shapes during the beta.
40
+ */
41
+ export declare class ZveltioApiError extends Error {
42
+ readonly code: string;
43
+ readonly status: number;
44
+ readonly title: string;
45
+ readonly type: string;
46
+ readonly detail?: string;
47
+ readonly instance?: string;
48
+ readonly traceId?: string;
49
+ readonly errors?: unknown;
50
+ /** The full parsed problem object. */
51
+ readonly problem: ProblemDetails;
52
+ constructor(problem: ProblemDetails);
53
+ /** Parse a failed `fetch` Response into a typed error (tolerant fallback). */
54
+ static fromResponse(res: Response): Promise<ZveltioApiError>;
55
+ /** Build from raw parts — handles problem+json, legacy `{ error }`, or prose. */
56
+ static fromParts(status: number, bodyText: string, contentType?: string | null, url?: string): ZveltioApiError;
57
+ }
58
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,6EAA6E;AAC7E,MAAM,WAAW,cAAc;IAC7B;uCACmC;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,wEAAwE;IACxE,KAAK,EAAE,MAAM,CAAC;IACd,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;IACf,8DAA8D;IAC9D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qEAAqE;IACrE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,yDAAyD;AACzD,eAAO,MAAM,oBAAoB,6BAA6B,CAAC;AAE/D;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC;IAC1B,sCAAsC;IACtC,QAAQ,CAAC,OAAO,EAAE,cAAc,CAAC;gBAErB,OAAO,EAAE,cAAc;IAcnC,8EAA8E;WACjE,YAAY,CAAC,GAAG,EAAE,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC;IAKlE,iFAAiF;IACjF,MAAM,CAAC,SAAS,CACd,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,EAC3B,GAAG,CAAC,EAAE,MAAM,GACX,eAAe;CAmCnB"}
package/dist/errors.js ADDED
@@ -0,0 +1,124 @@
1
+ /**
2
+ * Unified error envelope (H-13) — the SDK is the contract source of truth for
3
+ * error shapes, exactly as it is for `ZveltioExtension`.
4
+ *
5
+ * Every non-2xx response from the engine carries an RFC 9457 `problem+json`
6
+ * body: the standard fields (`type`, `title`, `status`, `detail`, `instance`)
7
+ * plus two Zveltio extensions:
8
+ * - `code` — a STABLE machine-readable string (e.g. `tenant.membership_required`)
9
+ * that clients can switch on without parsing prose.
10
+ * - `traceId` — correlates with server logs / the W3C trace, for support.
11
+ *
12
+ * The engine mirrors this shape (it can't import the SDK root at build time);
13
+ * keep the two in sync — this file is the canonical definition.
14
+ */
15
+ /** MIME type the engine sets on every error response. */
16
+ export const PROBLEM_CONTENT_TYPE = 'application/problem+json';
17
+ /**
18
+ * Typed error thrown by the SDK client for any non-2xx response. Carries the
19
+ * parsed envelope; tolerant of legacy `{ error }` shapes during the beta.
20
+ */
21
+ export class ZveltioApiError extends Error {
22
+ code;
23
+ status;
24
+ title;
25
+ type;
26
+ detail;
27
+ instance;
28
+ traceId;
29
+ errors;
30
+ /** The full parsed problem object. */
31
+ problem;
32
+ constructor(problem) {
33
+ super(problem.detail || problem.title || `HTTP ${problem.status}`);
34
+ this.name = 'ZveltioApiError';
35
+ this.problem = problem;
36
+ this.code = problem.code;
37
+ this.status = problem.status;
38
+ this.title = problem.title;
39
+ this.type = problem.type;
40
+ this.detail = problem.detail;
41
+ this.instance = problem.instance;
42
+ this.traceId = problem.traceId;
43
+ this.errors = problem.errors;
44
+ }
45
+ /** Parse a failed `fetch` Response into a typed error (tolerant fallback). */
46
+ static async fromResponse(res) {
47
+ const text = await res.text().catch(() => '');
48
+ return ZveltioApiError.fromParts(res.status, text, res.headers.get('content-type'), res.url);
49
+ }
50
+ /** Build from raw parts — handles problem+json, legacy `{ error }`, or prose. */
51
+ static fromParts(status, bodyText, contentType, url) {
52
+ const fallbackTitle = statusTitle(status);
53
+ let parsed = null;
54
+ if (bodyText && (contentType?.includes('json') ?? bodyText.trimStart().startsWith('{'))) {
55
+ try {
56
+ parsed = JSON.parse(bodyText);
57
+ }
58
+ catch {
59
+ parsed = null;
60
+ }
61
+ }
62
+ if (parsed && typeof parsed.code === 'string' && typeof parsed.title === 'string') {
63
+ // Already an envelope.
64
+ return new ZveltioApiError({ ...parsed, status });
65
+ }
66
+ // Legacy shapes: { error: "msg" } | { message: "msg" } | { error: {...} }.
67
+ const legacyDetail = (typeof parsed?.error === 'string' && parsed.error) ||
68
+ (typeof parsed?.message === 'string' && parsed.message) ||
69
+ (bodyText && !parsed ? bodyText.slice(0, 500) : '') ||
70
+ undefined;
71
+ const legacyErrors = parsed?.error && typeof parsed.error === 'object' ? parsed.error : parsed?.errors;
72
+ return new ZveltioApiError({
73
+ type: 'about:blank',
74
+ title: fallbackTitle,
75
+ status,
76
+ code: defaultCode(status),
77
+ detail: legacyDetail,
78
+ instance: url,
79
+ errors: legacyErrors,
80
+ });
81
+ }
82
+ }
83
+ function statusTitle(status) {
84
+ return STATUS_TITLES[status] ?? (status >= 500 ? 'Server Error' : 'Request Error');
85
+ }
86
+ function defaultCode(status) {
87
+ return DEFAULT_CODES[status] ?? (status >= 500 ? 'internal_error' : 'request_error');
88
+ }
89
+ const STATUS_TITLES = {
90
+ 400: 'Bad Request',
91
+ 401: 'Unauthorized',
92
+ 403: 'Forbidden',
93
+ 404: 'Not Found',
94
+ 405: 'Method Not Allowed',
95
+ 409: 'Conflict',
96
+ 410: 'Gone',
97
+ 413: 'Payload Too Large',
98
+ 415: 'Unsupported Media Type',
99
+ 422: 'Unprocessable Entity',
100
+ 429: 'Too Many Requests',
101
+ 500: 'Internal Server Error',
102
+ 501: 'Not Implemented',
103
+ 502: 'Bad Gateway',
104
+ 503: 'Service Unavailable',
105
+ 504: 'Gateway Timeout',
106
+ };
107
+ const DEFAULT_CODES = {
108
+ 400: 'bad_request',
109
+ 401: 'unauthorized',
110
+ 403: 'forbidden',
111
+ 404: 'not_found',
112
+ 405: 'method_not_allowed',
113
+ 409: 'conflict',
114
+ 410: 'gone',
115
+ 413: 'payload_too_large',
116
+ 415: 'unsupported_media_type',
117
+ 422: 'validation_failed',
118
+ 429: 'rate_limited',
119
+ 500: 'internal_error',
120
+ 501: 'not_implemented',
121
+ 502: 'bad_gateway',
122
+ 503: 'unavailable',
123
+ 504: 'gateway_timeout',
124
+ };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * How an action says no to its caller: a business rule refused the request
3
+ * ("this invoice is already cancelled"), as opposed to the action failing.
4
+ *
5
+ * Any other throw answers 500. A thrown `ActionRefusal` answers its own 4xx
6
+ * status and `code`, and still rolls back what the action wrote before it.
7
+ *
8
+ * The engine recognises it by a registered symbol, not by `instanceof`: each
9
+ * extension bundles its own copy of this SDK, so its class is never the
10
+ * engine's.
11
+ */
12
+ export declare const ACTION_REFUSAL: unique symbol;
13
+ /** The statuses an action may refuse with. 401 and 407 are the host's: they mean "sign in". */
14
+ export type RefusalStatus = 400 | 403 | 404 | 409 | 410 | 412 | 422 | 423 | 429;
15
+ export declare class ActionRefusal extends Error {
16
+ readonly status: RefusalStatus;
17
+ readonly code: string;
18
+ readonly [ACTION_REFUSAL] = true;
19
+ /**
20
+ * @param status one of `RefusalStatus`; the engine answers 500 for any other.
21
+ * @param code a stable, machine-readable reason, `snake_case`.
22
+ * @param message shown to the caller as the problem's `detail` — never put
23
+ * internal error text in it.
24
+ */
25
+ constructor(status: RefusalStatus, code: string, message: string);
26
+ }
27
+ //# sourceMappingURL=action-refusal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action-refusal.d.ts","sourceRoot":"","sources":["../../src/extension/action-refusal.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,MAAuD,CAAC;AAE5F,+FAA+F;AAC/F,MAAM,MAAM,aAAa,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEhF,qBAAa,aAAc,SAAQ,KAAK;IAUpC,QAAQ,CAAC,MAAM,EAAE,aAAa;IAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM;IAVvB,QAAQ,CAAC,CAAC,cAAc,CAAC,QAAQ;IAEjC;;;;;OAKG;gBAEQ,MAAM,EAAE,aAAa,EACrB,IAAI,EAAE,MAAM,EACrB,OAAO,EAAE,MAAM;CAKlB"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * How an action says no to its caller: a business rule refused the request
3
+ * ("this invoice is already cancelled"), as opposed to the action failing.
4
+ *
5
+ * Any other throw answers 500. A thrown `ActionRefusal` answers its own 4xx
6
+ * status and `code`, and still rolls back what the action wrote before it.
7
+ *
8
+ * The engine recognises it by a registered symbol, not by `instanceof`: each
9
+ * extension bundles its own copy of this SDK, so its class is never the
10
+ * engine's.
11
+ */
12
+ export const ACTION_REFUSAL = Symbol.for('zveltio.extension.action-refusal');
13
+ export class ActionRefusal extends Error {
14
+ status;
15
+ code;
16
+ [ACTION_REFUSAL] = true;
17
+ /**
18
+ * @param status one of `RefusalStatus`; the engine answers 500 for any other.
19
+ * @param code a stable, machine-readable reason, `snake_case`.
20
+ * @param message shown to the caller as the problem's `detail` — never put
21
+ * internal error text in it.
22
+ */
23
+ constructor(status, code, message) {
24
+ super(message);
25
+ this.status = status;
26
+ this.code = code;
27
+ this.name = 'ActionRefusal';
28
+ }
29
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Capabilities as TYPES — roadmap R8: "an undeclared capability is a compile
3
+ * error, not a runtime refusal".
4
+ *
5
+ * The engine refuses a gated `ctx.internals` member whose capability the
6
+ * manifest does not declare (`CapabilityDeniedError`). That refusal happens the
7
+ * first time the code path runs — often in production, on the request that
8
+ * needed it. Declaring the capabilities to TypeScript as well moves the same
9
+ * answer to the editor:
10
+ *
11
+ * export default defineExtension(['ddl', 'secrets'], {
12
+ * name: 'my-ext',
13
+ * category: 'tools',
14
+ * async register(app, ctx) {
15
+ * await ctx.internals.encryptSecret('x'); // ok: 'secrets'
16
+ * await ctx.internals.deleteUser(db, 'u'); // compile error: needs 'auth:users'
17
+ * },
18
+ * });
19
+ *
20
+ * The list passed to `defineExtension` is a statement to the compiler; the
21
+ * manifest's `permissions` remains what the engine enforces and what an
22
+ * administrator approves. `zveltio extension validate` compares the two.
23
+ *
24
+ * These two tables mirror the engine's `CAPABILITIES` and `INTERNALS_CAPABILITY`
25
+ * (`packages/engine/src/lib/extensions/capabilities.ts`); the engine's unit test
26
+ * `sdk-capability-types.test.ts` fails when they drift apart.
27
+ */
28
+ /** Every capability an extension may declare, `net:<host>` aside. */
29
+ export declare const EXTENSION_CAPABILITIES: readonly ["db:admin", "tenant:enter", "ddl", "secrets", "auth:session", "auth:users", "identity:provision", "audit:read", "data:write", "data:system", "notifications", "files", "documents", "edge-functions", "introspection", "storage", "cron", "field-types"];
30
+ /** A capability name, including the parameterised `net:<host>`. */
31
+ export type Capability = (typeof EXTENSION_CAPABILITIES)[number] | `net:${string}`;
32
+ /** The `ctx.internals` members a capability unlocks. */
33
+ export declare const CAPABILITY_MEMBERS: {
34
+ readonly enqueueDDLJob: "ddl";
35
+ readonly introspectSchema: "introspection";
36
+ readonly extensionRegistry: "introspection";
37
+ readonly encryptSecret: "secrets";
38
+ readonly decryptSecret: "secrets";
39
+ readonly deriveTokenHash: "secrets";
40
+ readonly createBetterAuthSession: "auth:session";
41
+ readonly deleteUser: "auth:users";
42
+ readonly exportUserData: "auth:users";
43
+ readonly revokeUserSessions: "auth:users";
44
+ readonly setUserActive: "auth:users";
45
+ readonly liftOwnBan: "auth:users";
46
+ readonly provisionUser: "identity:provision";
47
+ readonly listTenantUsers: "identity:provision";
48
+ readonly updateUserProfile: "identity:provision";
49
+ readonly addTenantMember: "identity:provision";
50
+ readonly removeTenantMember: "identity:provision";
51
+ readonly setTenantMembershipEnd: "identity:provision";
52
+ readonly readAuditActivity: "audit:read";
53
+ readonly createRecord: "data:write";
54
+ readonly updateRecord: "data:write";
55
+ readonly deleteRecord: "data:write";
56
+ readonly asSystem: "data:system";
57
+ readonly enqueue: "data:system";
58
+ readonly sendNotification: "notifications";
59
+ readonly moveToTrash: "files";
60
+ readonly generatePDFAsync: "documents";
61
+ readonly runEdgeFunction: "edge-functions";
62
+ };
63
+ /** Members of `ctx.internals` that need a capability. */
64
+ export type GatedMember = keyof typeof CAPABILITY_MEMBERS;
65
+ /** The gated members the capabilities `C` unlock. */
66
+ export type MembersUnlockedBy<C extends string> = {
67
+ [K in GatedMember]: (typeof CAPABILITY_MEMBERS)[K] extends C ? K : never;
68
+ }[GatedMember];
69
+ /** The gated members `C` does NOT unlock — removed from the narrowed type. */
70
+ export type MembersLockedFor<C extends string> = Exclude<GatedMember, MembersUnlockedBy<C>>;
71
+ //# sourceMappingURL=capabilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../../src/extension/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,qEAAqE;AACrE,eAAO,MAAM,sBAAsB,oQAmBzB,CAAC;AAEX,mEAAmE;AACnE,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,GAAG,OAAO,MAAM,EAAE,CAAC;AAEnF,wDAAwD;AACxD,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6B6C,CAAC;AAE7E,yDAAyD;AACzD,MAAM,MAAM,WAAW,GAAG,MAAM,OAAO,kBAAkB,CAAC;AAE1D,qDAAqD;AACrD,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,MAAM,IAAI;KAC/C,CAAC,IAAI,WAAW,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,KAAK;CACzE,CAAC,WAAW,CAAC,CAAC;AAEf,8EAA8E;AAC9E,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,MAAM,IAAI,OAAO,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Capabilities as TYPES — roadmap R8: "an undeclared capability is a compile
3
+ * error, not a runtime refusal".
4
+ *
5
+ * The engine refuses a gated `ctx.internals` member whose capability the
6
+ * manifest does not declare (`CapabilityDeniedError`). That refusal happens the
7
+ * first time the code path runs — often in production, on the request that
8
+ * needed it. Declaring the capabilities to TypeScript as well moves the same
9
+ * answer to the editor:
10
+ *
11
+ * export default defineExtension(['ddl', 'secrets'], {
12
+ * name: 'my-ext',
13
+ * category: 'tools',
14
+ * async register(app, ctx) {
15
+ * await ctx.internals.encryptSecret('x'); // ok: 'secrets'
16
+ * await ctx.internals.deleteUser(db, 'u'); // compile error: needs 'auth:users'
17
+ * },
18
+ * });
19
+ *
20
+ * The list passed to `defineExtension` is a statement to the compiler; the
21
+ * manifest's `permissions` remains what the engine enforces and what an
22
+ * administrator approves. `zveltio extension validate` compares the two.
23
+ *
24
+ * These two tables mirror the engine's `CAPABILITIES` and `INTERNALS_CAPABILITY`
25
+ * (`packages/engine/src/lib/extensions/capabilities.ts`); the engine's unit test
26
+ * `sdk-capability-types.test.ts` fails when they drift apart.
27
+ */
28
+ /** Every capability an extension may declare, `net:<host>` aside. */
29
+ export const EXTENSION_CAPABILITIES = [
30
+ 'db:admin',
31
+ 'tenant:enter',
32
+ 'ddl',
33
+ 'secrets',
34
+ 'auth:session',
35
+ 'auth:users',
36
+ 'identity:provision',
37
+ 'audit:read',
38
+ 'data:write',
39
+ 'data:system',
40
+ 'notifications',
41
+ 'files',
42
+ 'documents',
43
+ 'edge-functions',
44
+ 'introspection',
45
+ 'storage',
46
+ 'cron',
47
+ 'field-types',
48
+ ];
49
+ /** The `ctx.internals` members a capability unlocks. */
50
+ export const CAPABILITY_MEMBERS = {
51
+ enqueueDDLJob: 'ddl',
52
+ introspectSchema: 'introspection',
53
+ extensionRegistry: 'introspection',
54
+ encryptSecret: 'secrets',
55
+ decryptSecret: 'secrets',
56
+ deriveTokenHash: 'secrets',
57
+ createBetterAuthSession: 'auth:session',
58
+ deleteUser: 'auth:users',
59
+ exportUserData: 'auth:users',
60
+ revokeUserSessions: 'auth:users',
61
+ setUserActive: 'auth:users',
62
+ liftOwnBan: 'auth:users',
63
+ provisionUser: 'identity:provision',
64
+ listTenantUsers: 'identity:provision',
65
+ updateUserProfile: 'identity:provision',
66
+ addTenantMember: 'identity:provision',
67
+ removeTenantMember: 'identity:provision',
68
+ setTenantMembershipEnd: 'identity:provision',
69
+ readAuditActivity: 'audit:read',
70
+ createRecord: 'data:write',
71
+ updateRecord: 'data:write',
72
+ deleteRecord: 'data:write',
73
+ asSystem: 'data:system',
74
+ enqueue: 'data:system',
75
+ sendNotification: 'notifications',
76
+ moveToTrash: 'files',
77
+ generatePDFAsync: 'documents',
78
+ runEdgeFunction: 'edge-functions',
79
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Today's date, `YYYY-MM-DD`, in `timeZone` (IANA) — what `ActionHost.timezone`
3
+ * and `JobHost.timezone` are for. `new Date().toISOString().slice(0, 10)` is the
4
+ * UTC date: wrong for the hours a non-UTC tenant's day and UTC's differ.
5
+ */
6
+ export declare function todayIn(timeZone: string, now?: Date): string;
7
+ //# sourceMappingURL=dates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/extension/dates.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAE,IAAiB,GAAG,MAAM,CAQxE"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Today's date, `YYYY-MM-DD`, in `timeZone` (IANA) — what `ActionHost.timezone`
3
+ * and `JobHost.timezone` are for. `new Date().toISOString().slice(0, 10)` is the
4
+ * UTC date: wrong for the hours a non-UTC tenant's day and UTC's differ.
5
+ */
6
+ export function todayIn(timeZone, now = new Date()) {
7
+ // en-CA formats a date as ISO YYYY-MM-DD.
8
+ return new Intl.DateTimeFormat('en-CA', {
9
+ timeZone,
10
+ year: 'numeric',
11
+ month: '2-digit',
12
+ day: '2-digit',
13
+ }).format(now);
14
+ }