@tailor-platform/sdk 1.57.0 → 1.59.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/CHANGELOG.md +75 -0
  2. package/dist/{application-CdkoGX27.mjs → application-FnWOxBk7.mjs} +48 -28
  3. package/dist/application-FnWOxBk7.mjs.map +1 -0
  4. package/dist/application-VOdgMtOD.mjs +4 -0
  5. package/dist/{authconnection-TsdLYaLs.d.mts → authconnection-BIYzEh2p.d.mts} +2 -2
  6. package/dist/authconnection-D8SJGMpj.mjs.map +1 -1
  7. package/dist/cli/erd-viewer-assets/app.js +4 -4
  8. package/dist/cli/index.mjs +172 -20
  9. package/dist/cli/index.mjs.map +1 -1
  10. package/dist/cli/lib.d.mts +581 -2
  11. package/dist/cli/lib.mjs +4 -3
  12. package/dist/cli/lib.mjs.map +1 -1
  13. package/dist/client-B-jRdlC_.mjs +4 -0
  14. package/dist/{client-DLPEPJ_s.mjs → client-W5P4NYYX.mjs} +154 -12
  15. package/dist/client-W5P4NYYX.mjs.map +1 -0
  16. package/dist/configure/index.d.mts +2 -2
  17. package/dist/configure/index.mjs +8 -8
  18. package/dist/configure/index.mjs.map +1 -1
  19. package/dist/{crashreport-Bm2mN5tg.mjs → crashreport-D3DvAzdg.mjs} +3 -3
  20. package/dist/crashreport-D3DvAzdg.mjs.map +1 -0
  21. package/dist/{crashreport-C5oHvHUC.mjs → crashreport-lnVTnbB5.mjs} +1 -1
  22. package/dist/file-B58Dm-2P.mjs.map +1 -1
  23. package/dist/{file-VTJbbOL3.d.mts → file-BzK8z3X-.d.mts} +2 -2
  24. package/dist/globals-ByrCoDip.mjs +109 -0
  25. package/dist/globals-ByrCoDip.mjs.map +1 -0
  26. package/dist/iconv-DreIffeM.mjs.map +1 -1
  27. package/dist/{iconv-Chu6Hit2.d.mts → iconv-kwrmd1U_.d.mts} +2 -2
  28. package/dist/{idp-Di9N4FSJ.d.mts → idp-BlBPtXJ-.d.mts} +2 -2
  29. package/dist/idp-Ch95ag8h.mjs.map +1 -1
  30. package/dist/{index-B61gFI9a.d.mts → index-Cr6ufjZ5.d.mts} +12 -9
  31. package/dist/{index-DTSQthwF.d.mts → index-DRhMpdnA.d.mts} +7 -7
  32. package/dist/{job-CEAJLiGp.mjs → job-BpsFXPbi.mjs} +8 -17
  33. package/dist/job-BpsFXPbi.mjs.map +1 -0
  34. package/dist/mock-Dpu__UeJ.mjs +805 -0
  35. package/dist/mock-Dpu__UeJ.mjs.map +1 -0
  36. package/dist/registry-D0uB0OrK.mjs +178 -0
  37. package/dist/registry-D0uB0OrK.mjs.map +1 -0
  38. package/dist/{repl-editor-ihh8koiR.mjs → repl-editor-Y9QJDL0K.mjs} +3 -9
  39. package/dist/{repl-editor-ihh8koiR.mjs.map → repl-editor-Y9QJDL0K.mjs.map} +1 -1
  40. package/dist/runtime/authconnection.d.mts +1 -1
  41. package/dist/runtime/file.d.mts +1 -1
  42. package/dist/runtime/globals.d.mts +5 -5
  43. package/dist/runtime/iconv.d.mts +1 -1
  44. package/dist/runtime/idp.d.mts +1 -1
  45. package/dist/runtime/index.d.mts +7 -7
  46. package/dist/runtime/secretmanager.d.mts +1 -1
  47. package/dist/runtime/workflow.d.mts +1 -1
  48. package/dist/{runtime-1YuaoNr8.mjs → runtime-CrUa8Z2k.mjs} +383 -402
  49. package/dist/runtime-CrUa8Z2k.mjs.map +1 -0
  50. package/dist/secretmanager-B9h-U_8U.mjs.map +1 -1
  51. package/dist/{secretmanager-BhpDmxwT.d.mts → secretmanager-CKLB3wAQ.d.mts} +2 -2
  52. package/dist/utils/test/index.d.mts +6 -6
  53. package/dist/utils/test/index.mjs +7 -7
  54. package/dist/utils/test/index.mjs.map +1 -1
  55. package/dist/vitest/environment.mjs +3 -4
  56. package/dist/vitest/environment.mjs.map +1 -1
  57. package/dist/vitest/index.d.mts +167 -120
  58. package/dist/vitest/index.mjs +6 -6
  59. package/dist/vitest/index.mjs.map +1 -1
  60. package/dist/vitest/setup.d.mts +1 -1
  61. package/dist/vitest/setup.mjs +4 -3
  62. package/dist/vitest/setup.mjs.map +1 -1
  63. package/dist/workflow--aPbA8Uq.mjs.map +1 -1
  64. package/dist/{workflow-dYYH7QFa.d.mts → workflow-CMamswkK.d.mts} +2 -2
  65. package/dist/{workflow.generated-Kz-nQrTf.d.mts → workflow.generated-CV77NlFp.d.mts} +3 -2
  66. package/docs/cli/application.md +5 -5
  67. package/docs/cli/auth.md +55 -6
  68. package/docs/cli/function.md +2 -2
  69. package/docs/cli/staticwebsite.md +137 -0
  70. package/docs/cli-reference.md +17 -14
  71. package/docs/configuration.md +1 -1
  72. package/docs/generator/builtin.md +1 -1
  73. package/docs/runtime.md +9 -12
  74. package/docs/services/auth.md +0 -11
  75. package/docs/services/staticwebsite.md +13 -0
  76. package/docs/testing.md +92 -85
  77. package/package.json +8 -8
  78. package/dist/application-CdkoGX27.mjs.map +0 -1
  79. package/dist/application-x_mURdR0.mjs +0 -4
  80. package/dist/client-DLPEPJ_s.mjs.map +0 -1
  81. package/dist/client-DrzwCD1W.mjs +0 -4
  82. package/dist/crashreport-Bm2mN5tg.mjs.map +0 -1
  83. package/dist/job-CEAJLiGp.mjs.map +0 -1
  84. package/dist/mock-B6PI49C_.mjs +0 -844
  85. package/dist/mock-B6PI49C_.mjs.map +0 -1
  86. package/dist/runtime-1YuaoNr8.mjs.map +0 -1
  87. package/dist/test-env-key-CSnK4W1Y.mjs +0 -30
  88. package/dist/test-env-key-CSnK4W1Y.mjs.map +0 -1
@@ -1,844 +0,0 @@
1
-
2
- import { r as writeWorkflowTestEnv, t as clearWorkflowTestEnv } from "./test-env-key-CSnK4W1Y.mjs";
3
-
4
- //#region src/vitest/mock.ts
5
- /**
6
- * Mock implementations for Tailor Platform APIs.
7
- *
8
- * Provides singleton mock objects that are automatically injected into
9
- * globalThis by the tailor-runtime Vitest environment. Tests can configure
10
- * responses and assert on recorded calls via the exported mock objects.
11
- */
12
- const STATE_KEY = "__tailorMockState";
13
- const RUNTIME_FLAG_KEY = "__tailorRuntimeActive";
14
- function getState() {
15
- const g = globalThis;
16
- if (!g["__tailorMockState"]) g[STATE_KEY] = createDefaultState();
17
- return g[STATE_KEY];
18
- }
19
- function createDefaultState() {
20
- return {
21
- queryResolver: () => [],
22
- queryResultQueue: [],
23
- executedQueries: [],
24
- createdClients: [],
25
- jobHandler: () => null,
26
- jobResultQueue: [],
27
- triggeredJobs: [],
28
- triggerHandler: "mock-execution-id",
29
- waitHandler: null,
30
- resolveHandler: null,
31
- workflowCalls: [],
32
- secretStore: {},
33
- secretCalls: [],
34
- authTokens: {},
35
- authCalls: [],
36
- idpResolver: () => null,
37
- idpResultQueue: [],
38
- idpCalls: [],
39
- fileResolver: () => null,
40
- fileResultQueue: [],
41
- fileCalls: [],
42
- iconvResolver: null,
43
- iconvCalls: []
44
- };
45
- }
46
- /**
47
- * Mock control object for TailorDB operations.
48
- *
49
- * Automatically injected into `globalThis.tailordb` by the tailor-runtime environment.
50
- * Use this object to configure query responses and assert on executed queries.
51
- * @example
52
- * ```typescript
53
- * import { tailordbMock } from "@tailor-platform/sdk/vitest";
54
- *
55
- * beforeEach(() => tailordbMock.reset());
56
- *
57
- * test("content-based", () => {
58
- * tailordbMock.setQueryResolver((query) => {
59
- * if (query.includes("SELECT")) return [{ id: "1" }];
60
- * return [];
61
- * });
62
- * });
63
- *
64
- * test("order-based", () => {
65
- * tailordbMock.enqueueResults(
66
- * [], // BEGIN (empty result)
67
- * [{ age: 30 }], // SELECT (one row)
68
- * [], // COMMIT (empty result)
69
- * );
70
- * });
71
- * ```
72
- */
73
- const tailordbMock = {
74
- /**
75
- * Set a fallback query resolver. Called when the result queue is empty.
76
- * @param resolver - Function that returns rows for a given query and params
77
- */
78
- setQueryResolver(resolver) {
79
- getState().queryResolver = resolver;
80
- },
81
- /**
82
- * Enqueue rows for the next `queryObject` call. Arguments are the row objects returned
83
- * by that single query. Call with no arguments for an empty result. Consumed in FIFO
84
- * order; when the queue is exhausted, subsequent calls fall back to `setQueryResolver`
85
- * (default: empty rows). Use `enqueueResults` to stage rows for multiple queries in one
86
- * call.
87
- * @param rows - Row objects to return from the next `queryObject` call
88
- */
89
- enqueueResult(...rows) {
90
- getState().queryResultQueue.push(rows);
91
- },
92
- /**
93
- * Enqueue rows for multiple subsequent `queryObject` calls. Each argument is a rows
94
- * array for one query, consumed in FIFO order.
95
- * @param rowsList - Rows arrays, one per upcoming query
96
- */
97
- enqueueResults(...rowsList) {
98
- getState().queryResultQueue.push(...rowsList);
99
- },
100
- /**
101
- * All queries executed via `queryObject`, in order.
102
- * @returns Executed queries array
103
- */
104
- get executedQueries() {
105
- return getState().executedQueries;
106
- },
107
- /**
108
- * All TailorDB clients created, with their namespace and end state.
109
- * @returns Created clients array
110
- */
111
- get createdClients() {
112
- return getState().createdClients;
113
- },
114
- /** Reset all TailorDB mock state. Call in `beforeEach`. */
115
- reset() {
116
- const state = getState();
117
- state.queryResolver = () => [];
118
- state.queryResultQueue.length = 0;
119
- state.executedQueries.length = 0;
120
- state.createdClients.length = 0;
121
- }
122
- };
123
- /**
124
- * Mock control object for workflow operations.
125
- *
126
- * Automatically injected into `globalThis.tailor.workflow` by the tailor-runtime environment.
127
- * @example
128
- * ```typescript
129
- * import { workflowMock } from "@tailor-platform/sdk/vitest";
130
- *
131
- * beforeEach(() => workflowMock.reset());
132
- *
133
- * test("job handler", () => {
134
- * workflowMock.setJobHandler((jobName, args) => {
135
- * if (jobName === "validate") return { valid: true };
136
- * return null;
137
- * });
138
- * });
139
- *
140
- * test("wait point", () => {
141
- * workflowMock.setWaitHandler(() => ({ approved: true }));
142
- * // …
143
- * expect(workflowMock.waitCalls).toEqual([{ key: "approval", payload: undefined }]);
144
- * });
145
- *
146
- * test("resolve point", () => {
147
- * workflowMock.setResolveHandler((_executionId, _key, callback) =>
148
- * callback({ approved: true }),
149
- * );
150
- * // …
151
- * expect(workflowMock.resolveCalls).toEqual([
152
- * { executionId: "mock-execution-id", key: "approval" },
153
- * ]);
154
- * });
155
- * ```
156
- */
157
- const workflowMock = {
158
- /**
159
- * Set a fallback job handler. Called when the result queue is empty.
160
- * @param handler - Function that returns a result for a given job name and args
161
- */
162
- setJobHandler(handler) {
163
- getState().jobHandler = handler;
164
- },
165
- /**
166
- * Enqueue a single result for the next `triggerJobFunction` call. Consumed in FIFO
167
- * order; when the queue is exhausted, subsequent calls fall back to `setJobHandler`
168
- * (default: null). Use `enqueueResults` to stage multiple results in one call.
169
- * @param result - Result to return from the next `triggerJobFunction` call
170
- */
171
- enqueueResult(result) {
172
- getState().jobResultQueue.push(result);
173
- },
174
- /**
175
- * Enqueue results for multiple subsequent `triggerJobFunction` calls.
176
- * @param results - Results to enqueue, one per upcoming call
177
- */
178
- enqueueResults(...results) {
179
- const queue = getState().jobResultQueue;
180
- for (const result of results) queue.push(result);
181
- },
182
- /**
183
- * All jobs triggered via `triggerJobFunction`, in order.
184
- * @returns Triggered jobs array
185
- */
186
- get triggeredJobs() {
187
- return getState().triggeredJobs;
188
- },
189
- /**
190
- * Configure what `tailor.workflow.triggerWorkflow` returns. Pass a string to return
191
- * the same execution ID for every call, or a function `(name, args, options) => string`
192
- * to compute one per call. Default: `"mock-execution-id"`.
193
- * @param handler - Static execution ID or a function that returns one
194
- */
195
- setTriggerHandler(handler) {
196
- getState().triggerHandler = handler;
197
- },
198
- /**
199
- * Configure what `tailor.workflow.wait` returns. Pass a function `(key, payload) => unknown`
200
- * to compute one per call, or any other value to return it for every call. Default: `null`.
201
- * @param handler - Static value or a function that returns one
202
- */
203
- setWaitHandler: ((handler) => {
204
- getState().waitHandler = handler;
205
- }),
206
- /**
207
- * Set the `env` passed to job bodies invoked via `createWorkflowJob().trigger()`.
208
- * Cleared by `workflowMock.reset()`.
209
- * @param env - Env passed to job bodies.
210
- */
211
- setEnv(env) {
212
- writeWorkflowTestEnv({ ...env });
213
- },
214
- /**
215
- * Configure how `tailor.workflow.resolve` runs the user-supplied callback. The handler
216
- * receives `(executionId, key, callback)` — invoke `callback(payload)` to drive
217
- * resolve→wait wiring in tests. Default: callback is not invoked (records the call only).
218
- * @param handler - Function invoked per `resolve` call
219
- */
220
- setResolveHandler(handler) {
221
- getState().resolveHandler = handler;
222
- },
223
- /**
224
- * Calls to triggerWorkflow, wait, resolve (not triggerJobFunction — use triggeredJobs).
225
- * @returns Workflow calls array
226
- */
227
- get calls() {
228
- return getState().workflowCalls;
229
- },
230
- /**
231
- * `tailor.workflow.wait` calls reshaped as `{ key, payload }` for assertions.
232
- * @returns Wait call records
233
- */
234
- get waitCalls() {
235
- return getState().workflowCalls.filter((c) => c.method === "wait").map((c) => ({
236
- key: c.args[0],
237
- payload: c.args[1]
238
- }));
239
- },
240
- /**
241
- * `tailor.workflow.resolve` calls reshaped as `{ executionId, key }` for assertions.
242
- * @returns Resolve call records
243
- */
244
- get resolveCalls() {
245
- return getState().workflowCalls.filter((c) => c.method === "resolve").map((c) => ({
246
- executionId: c.args[0],
247
- key: c.args[1]
248
- }));
249
- },
250
- /** Reset all workflow mock state. Call in `beforeEach`. */
251
- reset() {
252
- const state = getState();
253
- state.jobHandler = () => null;
254
- state.jobResultQueue.length = 0;
255
- state.triggeredJobs.length = 0;
256
- state.triggerHandler = "mock-execution-id";
257
- state.waitHandler = null;
258
- state.resolveHandler = null;
259
- state.workflowCalls.length = 0;
260
- clearWorkflowTestEnv();
261
- }
262
- };
263
- /** Mock control for `tailor.secretmanager` — secret store and call recording. */
264
- const secretmanagerMock = {
265
- setSecrets(secrets) {
266
- getState().secretStore = secrets;
267
- },
268
- get calls() {
269
- return getState().secretCalls;
270
- },
271
- reset() {
272
- const state = getState();
273
- state.secretStore = {};
274
- state.secretCalls.length = 0;
275
- }
276
- };
277
- /** Mock control for `tailor.authconnection` — token store and call recording. */
278
- const authconnectionMock = {
279
- setTokens(tokens) {
280
- getState().authTokens = tokens;
281
- },
282
- get calls() {
283
- return getState().authCalls;
284
- },
285
- reset() {
286
- const state = getState();
287
- state.authTokens = {};
288
- state.authCalls.length = 0;
289
- }
290
- };
291
- /** Mock control for `tailor.idp` — IDP client responses and call recording. */
292
- const idpMock = {
293
- setResolver(resolver) {
294
- getState().idpResolver = resolver;
295
- },
296
- /**
297
- * Enqueue a single result for the next IDP call. Consumed in FIFO order; falls back
298
- * to `setResolver` when exhausted. Use `enqueueResults` to stage multiple in one call.
299
- * @param result - Result to return from the next IDP call
300
- */
301
- enqueueResult(result) {
302
- getState().idpResultQueue.push(result);
303
- },
304
- /**
305
- * Enqueue results for multiple subsequent IDP calls.
306
- * @param results - Results to enqueue, one per upcoming call
307
- */
308
- enqueueResults(...results) {
309
- const queue = getState().idpResultQueue;
310
- for (const result of results) queue.push(result);
311
- },
312
- get calls() {
313
- return getState().idpCalls;
314
- },
315
- reset() {
316
- const state = getState();
317
- state.idpResolver = () => null;
318
- state.idpResultQueue.length = 0;
319
- state.idpCalls.length = 0;
320
- }
321
- };
322
- /** Mock control for `tailordb.file` — file operation responses and call recording. */
323
- const fileMock = {
324
- setResolver(resolver) {
325
- getState().fileResolver = resolver;
326
- },
327
- /**
328
- * Enqueue a single result for the next `tailordb.file` call. Consumed in FIFO order;
329
- * falls back to `setResolver` when exhausted. Use `enqueueResults` to stage multiple
330
- * in one call.
331
- * @param result - Result to return from the next file call
332
- */
333
- enqueueResult(result) {
334
- getState().fileResultQueue.push(result);
335
- },
336
- /**
337
- * Enqueue results for multiple subsequent `tailordb.file` calls.
338
- * @param results - Results to enqueue, one per upcoming call
339
- */
340
- enqueueResults(...results) {
341
- const queue = getState().fileResultQueue;
342
- for (const result of results) queue.push(result);
343
- },
344
- get calls() {
345
- return getState().fileCalls;
346
- },
347
- reset() {
348
- const state = getState();
349
- state.fileResolver = () => null;
350
- state.fileResultQueue.length = 0;
351
- state.fileCalls.length = 0;
352
- }
353
- };
354
- /** Mock control for `tailor.iconv` — encoding call recording. */
355
- const iconvMock = {
356
- setResolver(resolver) {
357
- getState().iconvResolver = resolver;
358
- },
359
- get calls() {
360
- return getState().iconvCalls;
361
- },
362
- reset() {
363
- const state = getState();
364
- state.iconvResolver = null;
365
- state.iconvCalls.length = 0;
366
- }
367
- };
368
- var MockQueryResult = class {
369
- command;
370
- rowCount;
371
- rows;
372
- constructor(rows) {
373
- this.command = "";
374
- this.rowCount = rows.length;
375
- this.rows = rows;
376
- }
377
- };
378
- var MockTransaction = class {
379
- async begin() {}
380
- async commit() {}
381
- async rollback() {}
382
- async queryObject(query, params = []) {
383
- return resolveQuery(query, params);
384
- }
385
- };
386
- var MockTailordbClient = class {
387
- #record;
388
- constructor(config) {
389
- this.#record = {
390
- namespace: config?.namespace,
391
- ended: false
392
- };
393
- getState().createdClients.push(this.#record);
394
- }
395
- async connect() {}
396
- async end() {
397
- this.#record.ended = true;
398
- }
399
- async queryObject(query, params = []) {
400
- return resolveQuery(query, params);
401
- }
402
- createTransaction(name) {
403
- if (!name) throw new Error("Transaction name must be a non-empty string");
404
- return new MockTransaction();
405
- }
406
- };
407
- function resolveQuery(query, params) {
408
- const state = getState();
409
- state.executedQueries.push({
410
- query,
411
- params
412
- });
413
- if (state.queryResultQueue.length > 0) return new MockQueryResult(state.queryResultQueue.shift());
414
- return new MockQueryResult(state.queryResolver(query, params) ?? []);
415
- }
416
- function mockTriggerJobFunction(jobName, args) {
417
- const state = getState();
418
- state.triggeredJobs.push({
419
- jobName,
420
- args
421
- });
422
- if (state.jobResultQueue.length > 0) return state.jobResultQueue.shift();
423
- return state.jobHandler(jobName, args);
424
- }
425
- async function mockTriggerWorkflow(workflowName, args, options) {
426
- const state = getState();
427
- state.workflowCalls.push({
428
- method: "triggerWorkflow",
429
- args: [
430
- workflowName,
431
- args,
432
- options
433
- ]
434
- });
435
- const handler = state.triggerHandler;
436
- return typeof handler === "function" ? handler(workflowName, args, options) : handler;
437
- }
438
- function mockWait(key, payload) {
439
- const state = getState();
440
- state.workflowCalls.push({
441
- method: "wait",
442
- args: [key, payload]
443
- });
444
- const handler = state.waitHandler;
445
- return typeof handler === "function" ? handler(key, payload) : handler;
446
- }
447
- async function mockResolve(executionId, key, callback) {
448
- const state = getState();
449
- state.workflowCalls.push({
450
- method: "resolve",
451
- args: [
452
- executionId,
453
- key,
454
- callback
455
- ]
456
- });
457
- if (state.resolveHandler) await state.resolveHandler(executionId, key, callback);
458
- }
459
- function mockGetInvoker() {
460
- return null;
461
- }
462
- async function mockGetSecrets(vault, names) {
463
- const state = getState();
464
- state.secretCalls.push({
465
- method: "getSecrets",
466
- vault,
467
- names
468
- });
469
- const vaultData = state.secretStore[vault] ?? {};
470
- const result = {};
471
- for (const name of names) if (name in vaultData) result[name] = vaultData[name];
472
- return result;
473
- }
474
- async function mockGetSecret(vault, name) {
475
- const state = getState();
476
- state.secretCalls.push({
477
- method: "getSecret",
478
- vault,
479
- name
480
- });
481
- return state.secretStore[vault]?.[name];
482
- }
483
- async function mockGetConnectionToken(connectionName) {
484
- const state = getState();
485
- state.authCalls.push({ connectionName });
486
- return state.authTokens[connectionName] ?? { access_token: "mock-token" };
487
- }
488
- const IDP_DEFAULTS = {
489
- users: {
490
- users: [],
491
- nextPageToken: null,
492
- totalCount: 0
493
- },
494
- user: {
495
- id: "mock-id",
496
- name: "mock-user",
497
- disabled: false
498
- },
499
- userByName: {
500
- id: "mock-id",
501
- name: "mock-user",
502
- disabled: false
503
- },
504
- createUser: {
505
- id: "mock-id",
506
- name: "mock-user",
507
- disabled: false
508
- },
509
- updateUser: {
510
- id: "mock-id",
511
- name: "mock-user",
512
- disabled: false
513
- },
514
- deleteUser: true,
515
- sendPasswordResetEmail: true
516
- };
517
- function resolveIdpCall(method, args, namespace) {
518
- const state = getState();
519
- state.idpCalls.push({
520
- method,
521
- args,
522
- namespace
523
- });
524
- if (state.idpResultQueue.length > 0) return state.idpResultQueue.shift();
525
- const resolved = state.idpResolver(method, args, namespace);
526
- if (resolved != null) return resolved;
527
- const fallback = IDP_DEFAULTS[method];
528
- return fallback === void 0 ? void 0 : structuredClone(fallback);
529
- }
530
- var MockIdpClient = class {
531
- #namespace;
532
- constructor(config) {
533
- this.#namespace = config.namespace;
534
- }
535
- async users(options) {
536
- return resolveIdpCall("users", [options], this.#namespace);
537
- }
538
- async user(userId) {
539
- return resolveIdpCall("user", [userId], this.#namespace);
540
- }
541
- async userByName(name) {
542
- return resolveIdpCall("userByName", [name], this.#namespace);
543
- }
544
- async createUser(input) {
545
- return resolveIdpCall("createUser", [input], this.#namespace);
546
- }
547
- async updateUser(input) {
548
- return resolveIdpCall("updateUser", [input], this.#namespace);
549
- }
550
- async deleteUser(userId) {
551
- return resolveIdpCall("deleteUser", [userId], this.#namespace);
552
- }
553
- async sendPasswordResetEmail(input) {
554
- return resolveIdpCall("sendPasswordResetEmail", [input], this.#namespace);
555
- }
556
- };
557
- function isUtf8(encoding) {
558
- return encoding === "UTF8" || encoding === "UTF-8";
559
- }
560
- function defaultIconvResult(method, args) {
561
- switch (method) {
562
- case "convert":
563
- case "convertBuffer": return isUtf8(args[2]) ? "" : new Uint8Array();
564
- case "decode": return "";
565
- case "encode": return isUtf8(args[1]) ? "" : new Uint8Array();
566
- case "encodings": return [];
567
- default: return;
568
- }
569
- }
570
- function resolveIconvCall(method, args) {
571
- const state = getState();
572
- state.iconvCalls.push({
573
- method,
574
- args: [...args]
575
- });
576
- if (state.iconvResolver) {
577
- const result = state.iconvResolver(method, args);
578
- if (result != null) return result;
579
- }
580
- return defaultIconvResult(method, args);
581
- }
582
- function mockConvert(str, fromEncoding, toEncoding) {
583
- return resolveIconvCall("convert", [
584
- str,
585
- fromEncoding,
586
- toEncoding
587
- ]);
588
- }
589
- function mockConvertBuffer(buffer, fromEncoding, toEncoding) {
590
- return resolveIconvCall("convertBuffer", [
591
- buffer,
592
- fromEncoding,
593
- toEncoding
594
- ]);
595
- }
596
- function mockDecode(buffer, encoding) {
597
- return resolveIconvCall("decode", [buffer, encoding]);
598
- }
599
- function mockEncode(str, encoding) {
600
- return resolveIconvCall("encode", [str, encoding]);
601
- }
602
- function mockEncodings() {
603
- return resolveIconvCall("encodings", []);
604
- }
605
- var MockIconv = class {
606
- #fromEncoding;
607
- #toEncoding;
608
- constructor(fromEncoding, toEncoding) {
609
- this.#fromEncoding = fromEncoding;
610
- this.#toEncoding = toEncoding;
611
- }
612
- convert(input) {
613
- return resolveIconvCall("convert", [
614
- input,
615
- this.#fromEncoding,
616
- this.#toEncoding
617
- ]);
618
- }
619
- };
620
- const FILE_DEFAULTS = {
621
- upload: { metadata: {
622
- fileSize: 0,
623
- sha256sum: ""
624
- } },
625
- download: {
626
- data: new Uint8Array(),
627
- metadata: {
628
- contentType: "",
629
- fileSize: 0,
630
- sha256sum: "",
631
- lastUploadedAt: ""
632
- }
633
- },
634
- downloadAsBase64: {
635
- data: "",
636
- metadata: {
637
- contentType: "",
638
- fileSize: 0,
639
- sha256sum: "",
640
- lastUploadedAt: ""
641
- }
642
- },
643
- delete: void 0,
644
- getMetadata: {
645
- contentType: "",
646
- fileSize: 0,
647
- sha256sum: "",
648
- urlPath: ""
649
- },
650
- downloadStream: null,
651
- uploadStream: { metadata: {
652
- fileSize: 0,
653
- sha256sum: ""
654
- } }
655
- };
656
- function resolveFileCall(method, namespace, typeName, fieldName, recordId) {
657
- const state = getState();
658
- const call = {
659
- method,
660
- namespace,
661
- typeName,
662
- fieldName,
663
- recordId
664
- };
665
- state.fileCalls.push(call);
666
- if (state.fileResultQueue.length > 0) return state.fileResultQueue.shift();
667
- const resolved = state.fileResolver(method, call);
668
- if (resolved != null) return resolved;
669
- const fallback = FILE_DEFAULTS[method];
670
- return fallback === void 0 ? void 0 : structuredClone(fallback);
671
- }
672
- const mockTailordbFile = {
673
- async upload(namespace, typeName, fieldName, recordId, _data, _options) {
674
- return resolveFileCall("upload", namespace, typeName, fieldName, recordId);
675
- },
676
- async download(namespace, typeName, fieldName, recordId) {
677
- return resolveFileCall("download", namespace, typeName, fieldName, recordId);
678
- },
679
- async downloadAsBase64(namespace, typeName, fieldName, recordId) {
680
- return resolveFileCall("downloadAsBase64", namespace, typeName, fieldName, recordId);
681
- },
682
- async delete(namespace, typeName, fieldName, recordId) {
683
- resolveFileCall("delete", namespace, typeName, fieldName, recordId);
684
- },
685
- async getMetadata(namespace, typeName, fieldName, recordId) {
686
- return resolveFileCall("getMetadata", namespace, typeName, fieldName, recordId);
687
- },
688
- async openDownloadStream(namespace, typeName, fieldName, recordId) {
689
- return toFileStream(resolveFileCall("openDownloadStream", namespace, typeName, fieldName, recordId));
690
- },
691
- async downloadStream(namespace, typeName, fieldName, recordId) {
692
- const resolved = resolveFileCall("downloadStream", namespace, typeName, fieldName, recordId);
693
- if (resolved != null) return resolved;
694
- return {
695
- body: new ReadableStream({ start(c) {
696
- c.close();
697
- } }),
698
- metadata: {
699
- contentType: "",
700
- fileSize: 0,
701
- sha256sum: "",
702
- lastUploadedAt: ""
703
- }
704
- };
705
- },
706
- async uploadStream(namespace, typeName, fieldName, recordId, _readableStream, _options) {
707
- return resolveFileCall("uploadStream", namespace, typeName, fieldName, recordId);
708
- }
709
- };
710
- function toFileStream(value) {
711
- if (value !== null && typeof value === "object" && Symbol.asyncIterator in value && typeof value.close === "function") return value;
712
- if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) throw new TypeError("fileMock.openDownloadStream expects an iterable of StreamValue items (e.g. [{ type: \"chunk\", data, position }, { type: \"complete\" }]); got raw bytes. Wrap the bytes in a structured chunk first.");
713
- if (value !== null && typeof value === "object" && (Symbol.iterator in value || Symbol.asyncIterator in value)) {
714
- const source = value;
715
- const inner = Symbol.asyncIterator in source ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
716
- const stream = {
717
- async next() {
718
- const r = await inner.next();
719
- if (!r.done) assertStreamValue(r.value);
720
- return r.done ? {
721
- done: true,
722
- value: void 0
723
- } : r;
724
- },
725
- async close() {},
726
- [Symbol.asyncIterator]() {
727
- return stream;
728
- }
729
- };
730
- return stream;
731
- }
732
- const empty = {
733
- async next() {
734
- return {
735
- done: true,
736
- value: void 0
737
- };
738
- },
739
- async close() {},
740
- [Symbol.asyncIterator]() {
741
- return empty;
742
- }
743
- };
744
- return empty;
745
- }
746
- function assertStreamValue(v) {
747
- if (v === null || typeof v !== "object") throw new TypeError(`fileMock.openDownloadStream expected a StreamValue item ({ type: "metadata" | "chunk" | "complete", ... }); got ${typeof v === "object" ? "null" : typeof v}.`);
748
- if (v instanceof ArrayBuffer || ArrayBuffer.isView(v)) throw new TypeError("fileMock.openDownloadStream expected a StreamValue item, got raw bytes. Wrap the bytes in a structured chunk first (e.g. { type: \"chunk\", data, position }).");
749
- const type = v.type;
750
- if (type !== "metadata" && type !== "chunk" && type !== "complete") throw new TypeError(`fileMock.openDownloadStream expected a StreamValue item with type "metadata" | "chunk" | "complete"; got ${JSON.stringify(type)}.`);
751
- }
752
- var TailorErrorsMock = class extends Error {
753
- errors;
754
- constructor(errors) {
755
- if (!Array.isArray(errors)) throw new TypeError("TailorErrors: errors must be an array");
756
- const validated = errors.map((e, i) => {
757
- if (typeof e.message !== "string") throw new TypeError(`TailorErrors: errors[${i}].message must be a string`);
758
- if (!Array.isArray(e.path)) throw new TypeError(`TailorErrors: errors[${i}].path must be an array`);
759
- return {
760
- message: e.message,
761
- path: e.path
762
- };
763
- });
764
- super(`TailorErrors: ${JSON.stringify({ errors: validated })}`);
765
- this.name = "TailorErrors";
766
- this.errors = validated;
767
- }
768
- };
769
- var TailorErrorMessageMock = class extends Error {
770
- constructor(message) {
771
- super(message);
772
- this.name = "TailorErrorMessage";
773
- }
774
- };
775
- var TailorDBFileErrorMock = class extends Error {
776
- code;
777
- cause;
778
- constructor(message, code, cause) {
779
- super(message);
780
- this.name = "TailorDBFileError";
781
- this.code = code;
782
- this.cause = cause;
783
- }
784
- };
785
- /**
786
- * Inject all platform API mocks into globalThis.
787
- * Called by the tailor-runtime Vitest environment during setup.
788
- * @param global - The global object to inject mocks into
789
- */
790
- function injectMocks(global) {
791
- const g = global;
792
- g[STATE_KEY] = createDefaultState();
793
- g[RUNTIME_FLAG_KEY] = true;
794
- g.tailordb = {
795
- Client: MockTailordbClient,
796
- file: mockTailordbFile
797
- };
798
- g.tailor = {
799
- secretmanager: {
800
- getSecrets: mockGetSecrets,
801
- getSecret: mockGetSecret
802
- },
803
- authconnection: { getConnectionToken: mockGetConnectionToken },
804
- workflow: {
805
- triggerJobFunction: mockTriggerJobFunction,
806
- triggerWorkflow: mockTriggerWorkflow,
807
- wait: mockWait,
808
- resolve: mockResolve
809
- },
810
- context: { getInvoker: mockGetInvoker },
811
- idp: { Client: MockIdpClient },
812
- iconv: {
813
- convert: mockConvert,
814
- convertBuffer: mockConvertBuffer,
815
- decode: mockDecode,
816
- encode: mockEncode,
817
- encodings: mockEncodings,
818
- Iconv: MockIconv
819
- }
820
- };
821
- g.TailorErrors = TailorErrorsMock;
822
- g.TailorErrorMessage = TailorErrorMessageMock;
823
- g.TailorDBFileError = TailorDBFileErrorMock;
824
- }
825
- /**
826
- * Remove all injected mocks from globalThis.
827
- * Called by the tailor-runtime Vitest environment during teardown.
828
- * @param global - The global object to clean up mocks from
829
- */
830
- function cleanupMocks(global) {
831
- const g = global;
832
- delete g.tailordb;
833
- delete g.tailor;
834
- delete g.TailorErrors;
835
- delete g.TailorErrorMessage;
836
- delete g.TailorDBFileError;
837
- delete g[STATE_KEY];
838
- delete g[RUNTIME_FLAG_KEY];
839
- clearWorkflowTestEnv();
840
- }
841
-
842
- //#endregion
843
- export { fileMock as a, injectMocks as c, workflowMock as d, cleanupMocks as i, secretmanagerMock as l, STATE_KEY as n, iconvMock as o, authconnectionMock as r, idpMock as s, RUNTIME_FLAG_KEY as t, tailordbMock as u };
844
- //# sourceMappingURL=mock-B6PI49C_.mjs.map