@zveltio/sdk 2.0.8 → 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.
- package/README.md +17 -4
- package/dist/build/index.d.ts +77 -0
- package/dist/build/index.d.ts.map +1 -0
- package/dist/build/index.js +157 -0
- package/dist/client.d.ts +103 -7
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +129 -28
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +21 -3
- package/dist/crdt.d.ts.map +1 -1
- package/dist/crdt.js +11 -2
- package/dist/ddl/index.d.ts +173 -0
- package/dist/ddl/index.d.ts.map +1 -0
- package/dist/ddl/index.js +33 -0
- package/dist/errors.d.ts +58 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +124 -0
- package/dist/extension/action-refusal.d.ts +27 -0
- package/dist/extension/action-refusal.d.ts.map +1 -0
- package/dist/extension/action-refusal.js +29 -0
- package/dist/extension/capabilities.d.ts +71 -0
- package/dist/extension/capabilities.d.ts.map +1 -0
- package/dist/extension/capabilities.js +79 -0
- package/dist/extension/dates.d.ts +7 -0
- package/dist/extension/dates.d.ts.map +1 -0
- package/dist/extension/dates.js +14 -0
- package/dist/extension/index.d.ts +1570 -10
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/extension/index.js +17 -1
- package/dist/extension/jsonb.d.ts +62 -0
- package/dist/extension/jsonb.d.ts.map +1 -0
- package/dist/extension/jsonb.js +64 -0
- package/dist/extension/multipart.d.ts +58 -0
- package/dist/extension/multipart.d.ts.map +1 -0
- package/dist/extension/multipart.js +61 -0
- package/dist/extension/numeric.d.ts +94 -0
- package/dist/extension/numeric.d.ts.map +1 -0
- package/dist/extension/numeric.js +162 -0
- package/dist/extension/permission-gate.d.ts +52 -0
- package/dist/extension/permission-gate.d.ts.map +1 -0
- package/dist/extension/permission-gate.js +125 -0
- package/dist/extension/reserved-paths.d.ts +10 -0
- package/dist/extension/reserved-paths.d.ts.map +1 -0
- package/dist/extension/reserved-paths.js +23 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/local-store.d.ts +14 -1
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-store.js +93 -16
- package/dist/offline/index.d.ts +75 -0
- package/dist/offline/index.d.ts.map +1 -0
- package/dist/offline/index.js +251 -0
- package/dist/publish/index.d.ts +94 -0
- package/dist/publish/index.d.ts.map +1 -0
- package/dist/publish/index.js +153 -0
- package/dist/realtime.d.ts +25 -1
- package/dist/realtime.d.ts.map +1 -1
- package/dist/realtime.js +53 -5
- package/dist/rpc/index.d.ts +68 -0
- package/dist/rpc/index.d.ts.map +1 -0
- package/dist/rpc/index.js +63 -0
- package/dist/schema-codegen.d.ts +84 -0
- package/dist/schema-codegen.d.ts.map +1 -0
- package/dist/schema-codegen.js +503 -0
- package/dist/schema-watcher.d.ts +10 -2
- package/dist/schema-watcher.d.ts.map +1 -1
- package/dist/schema-watcher.js +26 -13
- package/dist/studio/index.d.ts +85 -0
- package/dist/studio/index.d.ts.map +1 -0
- package/dist/studio/index.js +183 -0
- package/dist/studio/slot-owner-registry.d.ts +13 -0
- package/dist/studio/slot-owner-registry.d.ts.map +1 -0
- package/dist/studio/slot-owner-registry.js +21 -0
- package/dist/svelte.d.ts +1 -1
- package/dist/svelte.d.ts.map +1 -1
- package/dist/svelte.js +4 -2
- package/dist/sync-manager.d.ts +49 -4
- package/dist/sync-manager.d.ts.map +1 -1
- package/dist/sync-manager.js +175 -24
- package/dist/testing/index.d.ts +121 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +305 -0
- package/dist/testing/with-test-db.d.ts +119 -0
- package/dist/testing/with-test-db.d.ts.map +1 -0
- package/dist/testing/with-test-db.js +320 -0
- package/dist/tests/action-refusal.test.d.ts +2 -0
- package/dist/tests/action-refusal.test.d.ts.map +1 -0
- package/dist/tests/action-refusal.test.js +13 -0
- package/dist/tests/client.test.d.ts +2 -0
- package/dist/tests/client.test.d.ts.map +1 -0
- package/dist/tests/client.test.js +164 -0
- package/dist/tests/crdt-orset.test.d.ts +2 -0
- package/dist/tests/crdt-orset.test.d.ts.map +1 -0
- package/dist/tests/crdt-orset.test.js +23 -0
- package/dist/tests/local-store.test.js +44 -0
- package/dist/tests/migration-parse.test.d.ts +2 -0
- package/dist/tests/migration-parse.test.d.ts.map +1 -0
- package/dist/tests/migration-parse.test.js +17 -0
- package/dist/tests/multipart.test.d.ts +2 -0
- package/dist/tests/multipart.test.d.ts.map +1 -0
- package/dist/tests/multipart.test.js +37 -0
- package/dist/tests/offline-provider-crdt.test.d.ts +2 -0
- package/dist/tests/offline-provider-crdt.test.d.ts.map +1 -0
- package/dist/tests/offline-provider-crdt.test.js +206 -0
- package/dist/tests/realtime.test.d.ts +2 -0
- package/dist/tests/realtime.test.d.ts.map +1 -0
- package/dist/tests/realtime.test.js +220 -0
- package/dist/tests/reserved-paths.test.d.ts +2 -0
- package/dist/tests/reserved-paths.test.d.ts.map +1 -0
- package/dist/tests/reserved-paths.test.js +21 -0
- package/dist/tests/sync-manager.test.d.ts +2 -0
- package/dist/tests/sync-manager.test.d.ts.map +1 -0
- package/dist/tests/sync-manager.test.js +123 -0
- package/dist/tests/today-in.test.d.ts +2 -0
- package/dist/tests/today-in.test.d.ts.map +1 -0
- package/dist/tests/today-in.test.js +14 -0
- package/dist/tests/validate-manifest-actions.test.d.ts +2 -0
- package/dist/tests/validate-manifest-actions.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-actions.test.js +82 -0
- package/dist/tests/validate-manifest-dependencies.test.d.ts +2 -0
- package/dist/tests/validate-manifest-dependencies.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-dependencies.test.js +27 -0
- package/dist/tests/validate-manifest-forward-credentials.test.d.ts +2 -0
- package/dist/tests/validate-manifest-forward-credentials.test.d.ts.map +1 -0
- package/dist/tests/validate-manifest-forward-credentials.test.js +35 -0
- package/dist/tests/validate-sdui-data-endpoints.test.d.ts +2 -0
- package/dist/tests/validate-sdui-data-endpoints.test.d.ts.map +1 -0
- package/dist/tests/validate-sdui-data-endpoints.test.js +41 -0
- package/dist/tests/with-test-db.test.d.ts +2 -0
- package/dist/tests/with-test-db.test.d.ts.map +1 -0
- package/dist/tests/with-test-db.test.js +57 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +3 -1
- package/dist/validate/index.d.ts +148 -0
- package/dist/validate/index.d.ts.map +1 -0
- package/dist/validate/index.js +887 -0
- package/dist/validate/migration-parse.d.ts +22 -0
- package/dist/validate/migration-parse.d.ts.map +1 -0
- package/dist/validate/migration-parse.js +11 -0
- package/dist/validate/shared-message-keys.d.ts +16 -0
- package/dist/validate/shared-message-keys.d.ts.map +1 -0
- package/dist/validate/shared-message-keys.js +227 -0
- package/package.json +56 -4
- package/dist/client/Auth.d.ts +0 -19
- package/dist/client/Auth.d.ts.map +0 -1
- package/dist/client/Auth.js +0 -45
- package/dist/client/QueryBuilder.d.ts +0 -17
- package/dist/client/QueryBuilder.d.ts.map +0 -1
- package/dist/client/QueryBuilder.js +0 -76
- package/dist/client/RealtimeClient.d.ts +0 -22
- package/dist/client/RealtimeClient.d.ts.map +0 -1
- package/dist/client/RealtimeClient.js +0 -96
- package/dist/client/ZveltioClient.d.ts +0 -20
- package/dist/client/ZveltioClient.d.ts.map +0 -1
- package/dist/client/ZveltioClient.js +0 -78
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
|
+
}
|