@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
@@ -0,0 +1,805 @@
1
+
2
+ import { a as getRegisteredWorkflow, d as buildJobContext, f as clearWorkflowTestEnv, i as getRegisteredJob, m as platformSerialize, p as writeWorkflowTestEnv, t as TRIGGER_DEFAULT } from "./registry-D0uB0OrK.mjs";
3
+ import { vi } from "vitest";
4
+
5
+ //#region src/vitest/mock.ts
6
+ /**
7
+ * Mock controls for Tailor Platform APIs (vitest).
8
+ *
9
+ * Each `xMock()` factory installs `vi.fn()`-backed mocks for one platform
10
+ * namespace onto `globalThis` when acquired, and restores the previous value
11
+ * when the `using` scope exits. State lives in the per-acquisition vi.fns /
12
+ * closures — there is no shared global state bag — so nested/sequential scopes
13
+ * are isolated and namespaces never interfere with each other.
14
+ *
15
+ * Acquire a mock with a `using` declaration:
16
+ *
17
+ * ```ts
18
+ * test("...", () => {
19
+ * using wf = mockWorkflow();
20
+ * wf.setJobHandler(() => ({ ok: true }));
21
+ * }); // previous workflow mock restored here
22
+ * ```
23
+ *
24
+ * The friendly helpers (`setJobHandler`, `enqueueResult`, `triggeredJobs`, …)
25
+ * are thin wrappers over the underlying vi.fns, which are also exposed directly
26
+ * (`wf.triggerJobFunction`) for native matchers like
27
+ * `expect(wf.triggerJobFunction).toHaveBeenCalledWith(...)`.
28
+ */
29
+ function withDispose(facade, dispose) {
30
+ Object.defineProperty(facade, Symbol.dispose, {
31
+ value: dispose,
32
+ enumerable: false,
33
+ writable: true,
34
+ configurable: true
35
+ });
36
+ return facade;
37
+ }
38
+ function tailorRoot() {
39
+ const g = globalThis;
40
+ if (!g.tailor) g.tailor = { context: { getInvoker: () => null } };
41
+ return g.tailor;
42
+ }
43
+ function tailordbRoot() {
44
+ const g = globalThis;
45
+ if (!g.tailordb) g.tailordb = {};
46
+ return g.tailordb;
47
+ }
48
+ var MockQueryResult = class {
49
+ command;
50
+ rowCount;
51
+ rows;
52
+ constructor(rows) {
53
+ this.command = "";
54
+ this.rowCount = rows.length;
55
+ this.rows = rows;
56
+ }
57
+ };
58
+ /**
59
+ * Acquire a disposable mock for TailorDB operations. Installs a mock
60
+ * `tailordb.Client` whose `queryObject` is a shared `vi.fn()` (so query
61
+ * responses can be staged before the client is constructed). Restored on
62
+ * dispose.
63
+ * @returns Disposable TailorDB mock control object
64
+ * @example
65
+ * ```typescript
66
+ * import { mockTailordb } from "@tailor-platform/sdk/vitest";
67
+ *
68
+ * test("order-based", async () => {
69
+ * using db = mockTailordb();
70
+ * db.enqueueResults([], [{ age: 30 }], []); // BEGIN / SELECT / COMMIT
71
+ * // …
72
+ * expect(db.queryObject).toHaveBeenCalledTimes(3);
73
+ * expect(db.Client).toHaveBeenCalledWith({ namespace: "tailordb" });
74
+ * });
75
+ * ```
76
+ */
77
+ function mockTailordb() {
78
+ const root = tailordbRoot();
79
+ const prevClient = root.Client;
80
+ const queryObject = vi.fn(async (_query, _params = []) => new MockQueryResult([]));
81
+ const connect = vi.fn(async () => {});
82
+ const createdClients = [];
83
+ const Client = vi.fn(function(config) {
84
+ const record = {
85
+ namespace: config?.namespace,
86
+ ended: false
87
+ };
88
+ createdClients.push(record);
89
+ this.connect = connect;
90
+ this.end = vi.fn(async () => {
91
+ record.ended = true;
92
+ });
93
+ this.queryObject = queryObject;
94
+ this.createTransaction = (name) => {
95
+ if (!name) throw new Error("Transaction name must be a non-empty string");
96
+ return {
97
+ begin: async () => {},
98
+ commit: async () => {},
99
+ rollback: async () => {},
100
+ queryObject
101
+ };
102
+ };
103
+ });
104
+ root.Client = Client;
105
+ return withDispose({
106
+ /** The mock `tailordb.Client` constructor (`vi.fn`). */
107
+ Client,
108
+ /** The shared `queryObject` `vi.fn` used by every client and transaction. */
109
+ queryObject,
110
+ /**
111
+ * Set a fallback query resolver. Called when the enqueue queue is empty.
112
+ * @param resolver - Function that returns rows for a given query and params
113
+ */
114
+ setQueryResolver(resolver) {
115
+ queryObject.mockImplementation(async (query, params = []) => new MockQueryResult(resolver(query, params) ?? []));
116
+ },
117
+ /**
118
+ * Enqueue rows for the next `queryObject` call (FIFO; takes priority over
119
+ * `setQueryResolver`). Call with no arguments for an empty result.
120
+ * @param rows - Row objects to return from the next `queryObject` call
121
+ */
122
+ enqueueResult(...rows) {
123
+ queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));
124
+ },
125
+ /**
126
+ * Enqueue rows for multiple subsequent `queryObject` calls (FIFO).
127
+ * @param rowsList - Rows arrays, one per upcoming query
128
+ */
129
+ enqueueResults(...rowsList) {
130
+ for (const rows of rowsList) queryObject.mockImplementationOnce(async () => new MockQueryResult(rows));
131
+ },
132
+ /**
133
+ * All queries executed via `queryObject`, in order, derived from the vi.fn
134
+ * call records.
135
+ * @returns Executed queries array
136
+ */
137
+ get executedQueries() {
138
+ return queryObject.mock.calls.map(([query, params]) => ({
139
+ query,
140
+ params: params ?? []
141
+ }));
142
+ },
143
+ /**
144
+ * All TailorDB clients created, with their namespace and end state.
145
+ * @returns Created clients array
146
+ */
147
+ get createdClients() {
148
+ return createdClients;
149
+ },
150
+ /** Reset query responses and recorded calls (keeps the mock installed). */
151
+ reset() {
152
+ queryObject.mockReset();
153
+ queryObject.mockImplementation(async () => new MockQueryResult([]));
154
+ connect.mockClear();
155
+ Client.mockClear();
156
+ createdClients.length = 0;
157
+ }
158
+ }, () => {
159
+ root.Client = prevClient;
160
+ });
161
+ }
162
+ /**
163
+ * Acquire a disposable mock for workflow operations (`tailor.workflow`).
164
+ * Restored on dispose.
165
+ * @returns Disposable workflow mock control object
166
+ * @example
167
+ * ```typescript
168
+ * import { mockWorkflow } from "@tailor-platform/sdk/vitest";
169
+ *
170
+ * test("job handler", async () => {
171
+ * using wf = mockWorkflow();
172
+ * wf.setJobHandler((name) => (name === "validate" ? { valid: true } : null));
173
+ * await runWorkflowUnderTest(); // calls tailor.workflow.triggerJobFunction("validate", {})
174
+ * expect(wf.triggerJobFunction).toHaveBeenCalledWith("validate", {});
175
+ * });
176
+ * ```
177
+ */
178
+ function mockWorkflow() {
179
+ const root = tailorRoot();
180
+ const prev = root.workflow;
181
+ const defaultTriggerJob = (jobName, args) => {
182
+ const body = getRegisteredJob(jobName);
183
+ return body ? body(args, buildJobContext()) : null;
184
+ };
185
+ const defaultTriggerWorkflow = async (workflowName, args, _options) => {
186
+ const wf = getRegisteredWorkflow(workflowName);
187
+ if (wf) await installedTriggerJobFunction(wf.mainJobName, args);
188
+ return TRIGGER_DEFAULT;
189
+ };
190
+ const triggerJobFunction = vi.fn(defaultTriggerJob);
191
+ const triggerWorkflow = vi.fn(defaultTriggerWorkflow);
192
+ const wait = vi.fn((_key, _payload) => null);
193
+ const resolve = vi.fn(async (_executionId, _key, _callback) => {});
194
+ const installedTriggerJobFunction = (jobName, args) => {
195
+ const out = triggerJobFunction(jobName, platformSerialize(args));
196
+ return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
197
+ };
198
+ root.workflow = {
199
+ triggerJobFunction: installedTriggerJobFunction,
200
+ triggerWorkflow: (...call) => call.length >= 3 ? triggerWorkflow(call[0], platformSerialize(call[1]), call[2]) : triggerWorkflow(call[0], platformSerialize(call[1])),
201
+ wait: (key, payload) => wait(key, platformSerialize(payload)),
202
+ resolve: (executionId, key, callback) => resolve(executionId, key, (payload) => {
203
+ const out = callback(payload);
204
+ return out instanceof Promise ? out.then((v) => platformSerialize(v)) : platformSerialize(out);
205
+ })
206
+ };
207
+ return withDispose({
208
+ /** The `triggerJobFunction` `vi.fn`. */
209
+ triggerJobFunction,
210
+ /** The `triggerWorkflow` `vi.fn`. */
211
+ triggerWorkflow,
212
+ /** The `wait` `vi.fn`. */
213
+ wait,
214
+ /** The `resolve` `vi.fn`. */
215
+ resolve,
216
+ /**
217
+ * Set a fallback job handler. Called when the enqueue queue is empty.
218
+ * @param handler - Function returning a result for a job name and args
219
+ */
220
+ setJobHandler(handler) {
221
+ triggerJobFunction.mockImplementation((name, args) => handler(name, args));
222
+ },
223
+ /**
224
+ * Enqueue a single result for the next `triggerJobFunction` call (FIFO;
225
+ * takes priority over `setJobHandler`).
226
+ * @param result - Result to return from the next call
227
+ */
228
+ enqueueResult(result) {
229
+ triggerJobFunction.mockImplementationOnce(() => result);
230
+ },
231
+ /**
232
+ * Enqueue results for multiple subsequent `triggerJobFunction` calls (FIFO).
233
+ * @param results - Results to enqueue, one per upcoming call
234
+ */
235
+ enqueueResults(...results) {
236
+ for (const result of results) triggerJobFunction.mockImplementationOnce(() => result);
237
+ },
238
+ /**
239
+ * All jobs triggered via `triggerJobFunction`, in order.
240
+ * @returns Triggered jobs array
241
+ */
242
+ get triggeredJobs() {
243
+ return triggerJobFunction.mock.calls.map(([jobName, args]) => ({
244
+ jobName,
245
+ args
246
+ }));
247
+ },
248
+ /**
249
+ * Configure what `triggerWorkflow` returns. Pass a string (same id every
250
+ * call) or `(name, args, options) => string`. Default: a placeholder UUID.
251
+ * @param handler - Static execution ID or a function returning one
252
+ */
253
+ setTriggerHandler(handler) {
254
+ triggerWorkflow.mockImplementation(typeof handler === "function" ? async (name, args, options) => handler(name, args, options) : async () => handler);
255
+ },
256
+ /**
257
+ * Configure what `wait` returns. Pass `(key, payload) => unknown` or any
258
+ * other value to return it for every call. Default: `null`.
259
+ * @param handler - Static value or a function returning one
260
+ */
261
+ setWaitHandler: ((handler) => {
262
+ wait.mockImplementation(typeof handler === "function" ? (key, payload) => handler(key, payload) : () => handler);
263
+ }),
264
+ /**
265
+ * Set the `env` passed to job bodies invoked via `createWorkflowJob().trigger()`.
266
+ * Cleared on dispose / reset.
267
+ * @param env - Env passed to job bodies.
268
+ */
269
+ setEnv(env) {
270
+ writeWorkflowTestEnv({ ...env });
271
+ },
272
+ /**
273
+ * Configure how `resolve` runs the user-supplied callback. Default: callback
274
+ * is not invoked (records the call only).
275
+ * @param handler - Function invoked per `resolve` call
276
+ */
277
+ setResolveHandler(handler) {
278
+ resolve.mockImplementation(async (executionId, key, callback) => {
279
+ await handler(executionId, key, callback);
280
+ });
281
+ },
282
+ /**
283
+ * `wait` calls reshaped as `{ key, payload }` for assertions.
284
+ * @returns Wait call records
285
+ */
286
+ get waitCalls() {
287
+ return wait.mock.calls.map(([key, payload]) => ({
288
+ key,
289
+ payload
290
+ }));
291
+ },
292
+ /**
293
+ * `resolve` calls reshaped as `{ executionId, key }` for assertions.
294
+ * @returns Resolve call records
295
+ */
296
+ get resolveCalls() {
297
+ return resolve.mock.calls.map(([executionId, key]) => ({
298
+ executionId,
299
+ key
300
+ }));
301
+ },
302
+ /** Reset all workflow responses and recorded calls (keeps the mock installed). */
303
+ reset() {
304
+ triggerJobFunction.mockReset();
305
+ triggerJobFunction.mockImplementation(defaultTriggerJob);
306
+ triggerWorkflow.mockReset();
307
+ triggerWorkflow.mockImplementation(defaultTriggerWorkflow);
308
+ wait.mockReset();
309
+ wait.mockImplementation(() => null);
310
+ resolve.mockReset();
311
+ resolve.mockImplementation(async () => {});
312
+ clearWorkflowTestEnv();
313
+ }
314
+ }, () => {
315
+ root.workflow = prev;
316
+ clearWorkflowTestEnv();
317
+ });
318
+ }
319
+ const SECRET_STORE = Symbol("tailorSecretStore");
320
+ /**
321
+ * Acquire a disposable mock for `tailor.secretmanager`. The secret store is
322
+ * inherited (cloned) from the currently-installed mock on acquisition and
323
+ * restored on dispose, so secrets seeded outside the test survive across
324
+ * `using` scopes while per-test `setSecrets()` overrides stay isolated.
325
+ * @returns Disposable SecretManager mock control object
326
+ * @example
327
+ * ```typescript
328
+ * import { mockSecretmanager } from "@tailor-platform/sdk/vitest";
329
+ *
330
+ * test("reads secrets from vault", async () => {
331
+ * using sm = mockSecretmanager();
332
+ * sm.setSecrets({ "my-vault": { API_KEY: "sk-123" } });
333
+ * // …
334
+ * });
335
+ * ```
336
+ */
337
+ function mockSecretmanager() {
338
+ const root = tailorRoot();
339
+ const prev = root.secretmanager;
340
+ const holder = { store: structuredClone(prev?.[SECRET_STORE]?.store ?? {}) };
341
+ const getSecret = vi.fn(async (vault, name) => holder.store[vault]?.[name]);
342
+ const getSecrets = vi.fn(async (vault, names) => {
343
+ const vaultData = holder.store[vault] ?? {};
344
+ const result = {};
345
+ for (const name of names) if (name in vaultData) result[name] = vaultData[name];
346
+ return result;
347
+ });
348
+ root.secretmanager = {
349
+ getSecret,
350
+ getSecrets,
351
+ [SECRET_STORE]: holder
352
+ };
353
+ return withDispose({
354
+ /** The `getSecret` `vi.fn`. */
355
+ getSecret,
356
+ /** The `getSecrets` `vi.fn`. */
357
+ getSecrets,
358
+ setSecrets(secrets) {
359
+ holder.store = secrets;
360
+ },
361
+ get calls() {
362
+ return [...getSecret.mock.calls.map((args, i) => ({
363
+ order: getSecret.mock.invocationCallOrder[i] ?? 0,
364
+ call: {
365
+ method: "getSecret",
366
+ vault: args[0],
367
+ name: args[1]
368
+ }
369
+ })), ...getSecrets.mock.calls.map((args, i) => ({
370
+ order: getSecrets.mock.invocationCallOrder[i] ?? 0,
371
+ call: {
372
+ method: "getSecrets",
373
+ vault: args[0],
374
+ names: args[1]
375
+ }
376
+ }))].toSorted((a, b) => a.order - b.order).map((e) => e.call);
377
+ },
378
+ reset() {
379
+ holder.store = {};
380
+ getSecret.mockClear();
381
+ getSecrets.mockClear();
382
+ }
383
+ }, () => {
384
+ root.secretmanager = prev;
385
+ });
386
+ }
387
+ /**
388
+ * Acquire a disposable mock for `tailor.authconnection`. Restored on dispose.
389
+ * @returns Disposable AuthConnection mock control object
390
+ * @example
391
+ * ```typescript
392
+ * import { mockAuthconnection } from "@tailor-platform/sdk/vitest";
393
+ *
394
+ * test("returns configured token", async () => {
395
+ * using ac = mockAuthconnection();
396
+ * ac.setTokens({ google: { access_token: "ya29.xxx" } });
397
+ * // …
398
+ * });
399
+ * ```
400
+ */
401
+ function mockAuthconnection() {
402
+ const root = tailorRoot();
403
+ const prev = root.authconnection;
404
+ let tokens = {};
405
+ const getConnectionToken = vi.fn(async (connectionName) => tokens[connectionName] ?? { access_token: "mock-token" });
406
+ root.authconnection = { getConnectionToken };
407
+ return withDispose({
408
+ /** The `getConnectionToken` `vi.fn`. */
409
+ getConnectionToken,
410
+ setTokens(value) {
411
+ tokens = value;
412
+ },
413
+ get calls() {
414
+ return getConnectionToken.mock.calls.map(([connectionName]) => ({ connectionName }));
415
+ },
416
+ reset() {
417
+ tokens = {};
418
+ getConnectionToken.mockClear();
419
+ }
420
+ }, () => {
421
+ root.authconnection = prev;
422
+ });
423
+ }
424
+ const IDP_DEFAULTS = {
425
+ users: {
426
+ users: [],
427
+ nextPageToken: null,
428
+ totalCount: 0
429
+ },
430
+ user: {
431
+ id: "mock-id",
432
+ name: "mock-user",
433
+ disabled: false
434
+ },
435
+ userByName: {
436
+ id: "mock-id",
437
+ name: "mock-user",
438
+ disabled: false
439
+ },
440
+ createUser: {
441
+ id: "mock-id",
442
+ name: "mock-user",
443
+ disabled: false
444
+ },
445
+ updateUser: {
446
+ id: "mock-id",
447
+ name: "mock-user",
448
+ disabled: false
449
+ },
450
+ deleteUser: true,
451
+ sendPasswordResetEmail: true
452
+ };
453
+ /**
454
+ * Acquire a disposable mock for `tailor.idp`. Restored on dispose.
455
+ * @returns Disposable IDP mock control object
456
+ * @example
457
+ * ```typescript
458
+ * import { mockIdp } from "@tailor-platform/sdk/vitest";
459
+ *
460
+ * test("resolver-based", async () => {
461
+ * using idp = mockIdp();
462
+ * idp.setResolver((method) =>
463
+ * method === "user" ? { id: "u-1", name: "alice", disabled: false } : null,
464
+ * );
465
+ * // …
466
+ * });
467
+ * ```
468
+ */
469
+ function mockIdp() {
470
+ const root = tailorRoot();
471
+ const prev = root.idp;
472
+ const queue = [];
473
+ let resolver = () => null;
474
+ const calls = [];
475
+ function handle(method, args, namespace) {
476
+ calls.push({
477
+ method,
478
+ args,
479
+ namespace
480
+ });
481
+ if (queue.length > 0) return queue.shift();
482
+ const resolved = resolver(method, args, namespace);
483
+ if (resolved != null) return resolved;
484
+ const fallback = IDP_DEFAULTS[method];
485
+ return fallback === void 0 ? void 0 : structuredClone(fallback);
486
+ }
487
+ const Client = vi.fn(function(config) {
488
+ const namespace = config.namespace;
489
+ this.users = async (options) => handle("users", [options], namespace);
490
+ this.user = async (userId) => handle("user", [userId], namespace);
491
+ this.userByName = async (name) => handle("userByName", [name], namespace);
492
+ this.createUser = async (input) => handle("createUser", [input], namespace);
493
+ this.updateUser = async (input) => handle("updateUser", [input], namespace);
494
+ this.deleteUser = async (userId) => handle("deleteUser", [userId], namespace);
495
+ this.sendPasswordResetEmail = async (input) => handle("sendPasswordResetEmail", [input], namespace);
496
+ });
497
+ root.idp = { Client };
498
+ return withDispose({
499
+ /** The mock IDP `Client` constructor (`vi.fn`). */
500
+ Client,
501
+ setResolver(value) {
502
+ resolver = value;
503
+ },
504
+ /**
505
+ * Enqueue a single result for the next IDP call (FIFO; falls back to
506
+ * `setResolver` when exhausted).
507
+ * @param result - Result to return from the next IDP call
508
+ */
509
+ enqueueResult(result) {
510
+ queue.push(result);
511
+ },
512
+ /**
513
+ * Enqueue results for multiple subsequent IDP calls.
514
+ * @param results - Results to enqueue, one per upcoming call
515
+ */
516
+ enqueueResults(...results) {
517
+ queue.push(...results);
518
+ },
519
+ get calls() {
520
+ return calls;
521
+ },
522
+ reset() {
523
+ queue.length = 0;
524
+ resolver = () => null;
525
+ calls.length = 0;
526
+ }
527
+ }, () => {
528
+ root.idp = prev;
529
+ });
530
+ }
531
+ function isUtf8(encoding) {
532
+ return encoding === "UTF8" || encoding === "UTF-8";
533
+ }
534
+ function defaultIconvResult(method, args) {
535
+ switch (method) {
536
+ case "convert":
537
+ case "convertBuffer": return isUtf8(args[2]) ? "" : new Uint8Array();
538
+ case "decode": return "";
539
+ case "encode": return isUtf8(args[1]) ? "" : new Uint8Array();
540
+ case "encodings": return [];
541
+ default: return;
542
+ }
543
+ }
544
+ /**
545
+ * Acquire a disposable mock for `tailor.iconv`. Restored on dispose.
546
+ * @returns Disposable Iconv mock control object
547
+ * @example
548
+ * ```typescript
549
+ * import { mockIconv } from "@tailor-platform/sdk/vitest";
550
+ *
551
+ * test("mock encoding conversion", () => {
552
+ * using iconv = mockIconv();
553
+ * iconv.setResolver((method) => (method === "decode" ? "decoded-text" : null));
554
+ * // …
555
+ * });
556
+ * ```
557
+ */
558
+ function mockIconv() {
559
+ const root = tailorRoot();
560
+ const prev = root.iconv;
561
+ let resolver = null;
562
+ const calls = [];
563
+ function handle(method, args) {
564
+ calls.push({
565
+ method,
566
+ args: [...args]
567
+ });
568
+ if (resolver) {
569
+ const result = resolver(method, args);
570
+ if (result != null) return result;
571
+ }
572
+ return defaultIconvResult(method, args);
573
+ }
574
+ class MockIconv {
575
+ #fromEncoding;
576
+ #toEncoding;
577
+ constructor(fromEncoding, toEncoding) {
578
+ this.#fromEncoding = fromEncoding;
579
+ this.#toEncoding = toEncoding;
580
+ }
581
+ convert(input) {
582
+ return handle("convert", [
583
+ input,
584
+ this.#fromEncoding,
585
+ this.#toEncoding
586
+ ]);
587
+ }
588
+ }
589
+ root.iconv = {
590
+ convert: (str, from, to) => handle("convert", [
591
+ str,
592
+ from,
593
+ to
594
+ ]),
595
+ convertBuffer: (buf, from, to) => handle("convertBuffer", [
596
+ buf,
597
+ from,
598
+ to
599
+ ]),
600
+ decode: (buf, encoding) => handle("decode", [buf, encoding]),
601
+ encode: (str, encoding) => handle("encode", [str, encoding]),
602
+ encodings: () => handle("encodings", []),
603
+ Iconv: MockIconv
604
+ };
605
+ return withDispose({
606
+ setResolver(value) {
607
+ resolver = value;
608
+ },
609
+ get calls() {
610
+ return calls;
611
+ },
612
+ reset() {
613
+ resolver = null;
614
+ calls.length = 0;
615
+ }
616
+ }, () => {
617
+ root.iconv = prev;
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 toFileStream(value) {
657
+ if (value !== null && typeof value === "object" && Symbol.asyncIterator in value && typeof value.close === "function") return value;
658
+ if (value instanceof ArrayBuffer || ArrayBuffer.isView(value)) throw new TypeError("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.");
659
+ if (value !== null && typeof value === "object" && (Symbol.iterator in value || Symbol.asyncIterator in value)) {
660
+ const source = value;
661
+ const inner = Symbol.asyncIterator in source ? source[Symbol.asyncIterator]() : source[Symbol.iterator]();
662
+ const stream = {
663
+ async next() {
664
+ const r = await inner.next();
665
+ if (!r.done) assertStreamValue(r.value);
666
+ return r.done ? {
667
+ done: true,
668
+ value: void 0
669
+ } : r;
670
+ },
671
+ async close() {},
672
+ [Symbol.asyncIterator]() {
673
+ return stream;
674
+ }
675
+ };
676
+ return stream;
677
+ }
678
+ const empty = {
679
+ async next() {
680
+ return {
681
+ done: true,
682
+ value: void 0
683
+ };
684
+ },
685
+ async close() {},
686
+ [Symbol.asyncIterator]() {
687
+ return empty;
688
+ }
689
+ };
690
+ return empty;
691
+ }
692
+ function assertStreamValue(v) {
693
+ if (v === null || typeof v !== "object") throw new TypeError(`openDownloadStream expected a StreamValue item ({ type: "metadata" | "chunk" | "complete", ... }); got ${typeof v === "object" ? "null" : typeof v}.`);
694
+ if (v instanceof ArrayBuffer || ArrayBuffer.isView(v)) throw new TypeError("openDownloadStream expected a StreamValue item, got raw bytes. Wrap the bytes in a structured chunk first (e.g. { type: \"chunk\", data, position }).");
695
+ const type = v.type;
696
+ if (type !== "metadata" && type !== "chunk" && type !== "complete") throw new TypeError(`openDownloadStream expected a StreamValue item with type "metadata" | "chunk" | "complete"; got ${JSON.stringify(type)}.`);
697
+ }
698
+ /**
699
+ * Acquire a disposable mock for `tailordb.file`. Restored on dispose.
700
+ * @returns Disposable File mock control object
701
+ * @example
702
+ * ```typescript
703
+ * import { mockFile } from "@tailor-platform/sdk/vitest";
704
+ *
705
+ * test("mock file download", async () => {
706
+ * using file = mockFile();
707
+ * file.enqueueResult({ data: new Uint8Array([1, 2, 3]), metadata: { ... } });
708
+ * // …
709
+ * });
710
+ * ```
711
+ */
712
+ function mockFile() {
713
+ const root = tailordbRoot();
714
+ const prev = root.file;
715
+ const queue = [];
716
+ let resolver = () => null;
717
+ const calls = [];
718
+ function handle(method, namespace, typeName, fieldName, recordId) {
719
+ const call = {
720
+ method,
721
+ namespace,
722
+ typeName,
723
+ fieldName,
724
+ recordId
725
+ };
726
+ calls.push(call);
727
+ if (queue.length > 0) return queue.shift();
728
+ const resolved = resolver(method, call);
729
+ if (resolved != null) return resolved;
730
+ const fallback = FILE_DEFAULTS[method];
731
+ return fallback === void 0 ? void 0 : structuredClone(fallback);
732
+ }
733
+ root.file = {
734
+ async upload(namespace, typeName, fieldName, recordId) {
735
+ return handle("upload", namespace, typeName, fieldName, recordId);
736
+ },
737
+ async download(namespace, typeName, fieldName, recordId) {
738
+ return handle("download", namespace, typeName, fieldName, recordId);
739
+ },
740
+ async downloadAsBase64(namespace, typeName, fieldName, recordId) {
741
+ return handle("downloadAsBase64", namespace, typeName, fieldName, recordId);
742
+ },
743
+ async delete(namespace, typeName, fieldName, recordId) {
744
+ handle("delete", namespace, typeName, fieldName, recordId);
745
+ },
746
+ async getMetadata(namespace, typeName, fieldName, recordId) {
747
+ return handle("getMetadata", namespace, typeName, fieldName, recordId);
748
+ },
749
+ async openDownloadStream(namespace, typeName, fieldName, recordId) {
750
+ return toFileStream(handle("openDownloadStream", namespace, typeName, fieldName, recordId));
751
+ },
752
+ async downloadStream(namespace, typeName, fieldName, recordId) {
753
+ const resolved = handle("downloadStream", namespace, typeName, fieldName, recordId);
754
+ if (resolved != null) return resolved;
755
+ return {
756
+ body: new ReadableStream({ start(c) {
757
+ c.close();
758
+ } }),
759
+ metadata: {
760
+ contentType: "",
761
+ fileSize: 0,
762
+ sha256sum: "",
763
+ lastUploadedAt: ""
764
+ }
765
+ };
766
+ },
767
+ async uploadStream(namespace, typeName, fieldName, recordId) {
768
+ return handle("uploadStream", namespace, typeName, fieldName, recordId);
769
+ }
770
+ };
771
+ return withDispose({
772
+ setResolver(value) {
773
+ resolver = value;
774
+ },
775
+ /**
776
+ * Enqueue a single result for the next `tailordb.file` call (FIFO; falls
777
+ * back to `setResolver` when exhausted).
778
+ * @param result - Result to return from the next file call
779
+ */
780
+ enqueueResult(result) {
781
+ queue.push(result);
782
+ },
783
+ /**
784
+ * Enqueue results for multiple subsequent `tailordb.file` calls.
785
+ * @param results - Results to enqueue, one per upcoming call
786
+ */
787
+ enqueueResults(...results) {
788
+ queue.push(...results);
789
+ },
790
+ get calls() {
791
+ return calls;
792
+ },
793
+ reset() {
794
+ queue.length = 0;
795
+ resolver = () => null;
796
+ calls.length = 0;
797
+ }
798
+ }, () => {
799
+ root.file = prev;
800
+ });
801
+ }
802
+
803
+ //#endregion
804
+ export { mockSecretmanager as a, mockIdp as i, mockFile as n, mockTailordb as o, mockIconv as r, mockWorkflow as s, mockAuthconnection as t };
805
+ //# sourceMappingURL=mock-Dpu__UeJ.mjs.map