@cimplify/sdk 0.44.16 → 0.44.18

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 (37) hide show
  1. package/dist/advanced.js +22 -21
  2. package/dist/advanced.mjs +3 -2
  3. package/dist/{chunk-MBGQP6FZ.js → chunk-3FS3ZDKX.js} +60 -60
  4. package/dist/chunk-53J2WE4S.js +657 -0
  5. package/dist/{chunk-UXLQ7WXI.mjs → chunk-5OK3YDZC.mjs} +2 -2
  6. package/dist/{chunk-MNIKXG7W.js → chunk-BN2CXGMO.js} +5 -272
  7. package/dist/{chunk-XL4CX75J.js → chunk-CCSONJCO.js} +235 -781
  8. package/dist/{chunk-CFD4J32N.js → chunk-HBRCVJL4.js} +22 -21
  9. package/dist/{chunk-ZLEFMQC6.mjs → chunk-MJBSVUHO.mjs} +2 -498
  10. package/dist/{chunk-6AZZ6AOF.mjs → chunk-NRT6PVW5.mjs} +4 -251
  11. package/dist/chunk-QBQCMQ4F.js +271 -0
  12. package/dist/chunk-VDH3O7UB.mjs +604 -0
  13. package/dist/chunk-XPXAZXF2.mjs +250 -0
  14. package/dist/{chunk-7NML226B.mjs → chunk-XZPO5GEM.mjs} +2 -1
  15. package/dist/client-B_Ei3ENB.d.mts +86 -0
  16. package/dist/client-Bep2FooI.d.ts +86 -0
  17. package/dist/index.js +145 -144
  18. package/dist/index.mjs +4 -3
  19. package/dist/react.js +81 -80
  20. package/dist/react.mjs +4 -3
  21. package/dist/server.js +6 -5
  22. package/dist/server.mjs +4 -3
  23. package/dist/testing/msw.d.mts +17 -0
  24. package/dist/testing/msw.d.ts +17 -0
  25. package/dist/testing/msw.js +42 -0
  26. package/dist/testing/msw.mjs +40 -0
  27. package/dist/testing/suite.d.mts +25 -0
  28. package/dist/testing/suite.d.ts +25 -0
  29. package/dist/testing/suite.js +28 -23
  30. package/dist/testing/suite.mjs +9 -4
  31. package/dist/testing.d.mts +643 -117
  32. package/dist/testing.d.ts +643 -117
  33. package/dist/testing.js +107 -59
  34. package/dist/testing.mjs +51 -4
  35. package/dist/utils.js +29 -28
  36. package/dist/utils.mjs +2 -1
  37. package/package.json +11 -2
@@ -0,0 +1,604 @@
1
+ import { createCimplifyClient } from './chunk-5OK3YDZC.mjs';
2
+ import { createMockApp } from './chunk-MJBSVUHO.mjs';
3
+ import { z } from 'zod';
4
+
5
+ var cimplifyRegistry = z.registry();
6
+ function registerSchema(schema, meta) {
7
+ cimplifyRegistry.add(schema, meta);
8
+ return schema;
9
+ }
10
+ var MoneySchema = registerSchema(
11
+ z.string().regex(/^-?\d+\.\d{2}$/, 'Money must be a decimal string with exactly 2 decimals (e.g. "12.50")'),
12
+ { id: "Money", description: "Strict 2-decimal money string", version: "1.0.0" }
13
+ );
14
+ var MoneyLooseSchema = registerSchema(
15
+ z.string().regex(/^-?\d+(\.\d+)?$/, "Must be a decimal string"),
16
+ { id: "MoneyLoose", description: "Decimal string with arbitrary precision", version: "1.0.0" }
17
+ );
18
+ var IsoDateTimeSchema = registerSchema(z.iso.datetime(), {
19
+ id: "IsoDateTime",
20
+ description: "ISO 8601 date-time",
21
+ version: "1.0.0"
22
+ });
23
+ var TimestampSchema = registerSchema(
24
+ z.union([z.iso.datetime(), z.string().min(1)]),
25
+ {
26
+ id: "Timestamp",
27
+ description: "ISO 8601 or any non-empty string (boundary use)",
28
+ version: "1.0.0"
29
+ }
30
+ );
31
+ var CurrencyCodeSchema = registerSchema(
32
+ z.string().length(3, "currency must be a 3-letter ISO 4217 code").regex(/^[A-Z]{3}$/, "currency must be uppercase letters"),
33
+ { id: "CurrencyCode", description: "ISO 4217 currency code", version: "1.0.0" }
34
+ );
35
+ var CountryCodeSchema = registerSchema(
36
+ z.string().length(2, "countryCode must be ISO 3166-1 alpha-2").regex(/^[A-Z]{2}$/, "countryCode must be uppercase letters"),
37
+ { id: "CountryCode", description: "ISO 3166-1 alpha-2 country code", version: "1.0.0" }
38
+ );
39
+ var LocaleSchema = registerSchema(
40
+ z.string().regex(/^[a-z]{2}(_[A-Z]{2})?$/, "locale must look like 'en' or 'en_GH'"),
41
+ { id: "Locale", description: "BCP-47-ish locale", version: "1.0.0" }
42
+ );
43
+ var PhoneE164Schema = registerSchema(
44
+ z.string().regex(/^\+?[0-9]{7,15}$/, "phoneTel should be E.164-ish digits (7\u201315)"),
45
+ { id: "PhoneE164", description: "E.164-ish phone number", version: "1.0.0" }
46
+ );
47
+ var SeedNameSchema = registerSchema(
48
+ z.enum([
49
+ "default",
50
+ "empty",
51
+ "reesa-storefront",
52
+ "restaurant",
53
+ "retail",
54
+ "services",
55
+ "grocery",
56
+ "fashion"
57
+ ]),
58
+ { id: "SeedName", description: "Mock seed identifier", version: "1.0.0" }
59
+ );
60
+ var ProductTypeSchema = registerSchema(
61
+ z.enum(["product", "service", "digital", "bundle", "composite"]),
62
+ { id: "ProductType", description: "Product type discriminator", version: "1.0.0" }
63
+ );
64
+ var LineTypeSchema = registerSchema(
65
+ z.enum(["simple", "service", "digital", "bundle", "composite"]),
66
+ { id: "LineType", description: "Cart line type discriminator", version: "1.0.0" }
67
+ );
68
+ var ServiceStatusSchema = registerSchema(
69
+ z.enum(["pending", "confirmed", "completed", "cancelled"]),
70
+ { id: "ServiceStatus", description: "Service booking status", version: "1.0.0" }
71
+ );
72
+ var SchemaViolationError = class extends Error {
73
+ constructor(message, label, issues) {
74
+ super(message);
75
+ this.label = label;
76
+ this.issues = issues;
77
+ this.name = "SchemaViolationError";
78
+ }
79
+ toJSON() {
80
+ return {
81
+ type: "https://cimplify.io/errors/schema-violation",
82
+ title: "Schema Violation",
83
+ status: 422,
84
+ detail: `${this.label} did not match its schema`,
85
+ errors: this.issues
86
+ };
87
+ }
88
+ };
89
+ function makeAssertion(schema, label) {
90
+ return (value) => {
91
+ const result = schema.safeParse(value);
92
+ if (!result.success) {
93
+ const pretty = z.prettifyError(result.error);
94
+ const issues = result.error.issues.map((i) => ({
95
+ path: i.path.map(String),
96
+ message: i.message,
97
+ code: i.code
98
+ }));
99
+ throw new SchemaViolationError(
100
+ `${label} schema violation:
101
+ ${pretty}`,
102
+ label,
103
+ issues
104
+ );
105
+ }
106
+ };
107
+ }
108
+ var BrandSocialSchema = z.object({
109
+ label: z.string().min(1),
110
+ href: z.string().url(),
111
+ icon: z.string().optional()
112
+ });
113
+ var BrandNavLinkSchema = z.object({
114
+ label: z.string().min(1),
115
+ href: z.string().min(1)
116
+ });
117
+ var BrandPolicySectionSchema = z.object({
118
+ heading: z.string().min(1),
119
+ body: z.union([
120
+ z.string().min(1),
121
+ z.object({ intro: z.string(), bullets: z.array(z.string()).min(1) })
122
+ ])
123
+ });
124
+ var BrandPolicyPageSchema = z.object({
125
+ eyebrow: z.string(),
126
+ title: z.string().min(1),
127
+ lastUpdated: z.string().min(1),
128
+ sections: z.array(BrandPolicySectionSchema).min(1)
129
+ });
130
+ var BrandContactSchema = z.object({
131
+ email: z.string().email(),
132
+ phone: z.string().min(1),
133
+ phoneTel: PhoneE164Schema,
134
+ streetAddress: z.string().min(1),
135
+ city: z.string().min(1),
136
+ countryCode: CountryCodeSchema,
137
+ hours: z.string().optional()
138
+ });
139
+ var BrandHeroSchema = z.object({
140
+ badge: z.string().optional(),
141
+ title: z.string().min(1),
142
+ subtitle: z.string().min(1),
143
+ primaryCta: BrandNavLinkSchema.optional(),
144
+ secondaryCta: BrandNavLinkSchema.optional()
145
+ });
146
+ var BrandFaqSchema = z.object({
147
+ eyebrow: z.string().optional(),
148
+ title: z.string().min(1),
149
+ sections: z.array(
150
+ z.object({
151
+ title: z.string(),
152
+ items: z.array(z.object({ q: z.string(), a: z.string() }))
153
+ })
154
+ )
155
+ });
156
+ var BrandSchema = registerSchema(
157
+ z.object({
158
+ // Identity
159
+ name: z.string().min(1),
160
+ shortName: z.string().min(1),
161
+ microTag: z.string(),
162
+ description: z.string().min(20, "description should be at least 20 characters"),
163
+ schemaType: z.string().min(1),
164
+ currency: CurrencyCodeSchema,
165
+ locale: LocaleSchema,
166
+ contact: BrandContactSchema,
167
+ socials: z.array(BrandSocialSchema),
168
+ header: z.object({ nav: z.array(BrandNavLinkSchema).min(1) }),
169
+ hero: BrandHeroSchema,
170
+ // Optional sections — render conditionally when present
171
+ trustItems: z.array(z.object({ title: z.string().min(1), body: z.string().min(1) })).optional(),
172
+ brandStrip: z.object({ headline: z.string(), logos: z.array(z.string()).min(1) }).optional(),
173
+ promo: z.object({
174
+ eyebrow: z.string().optional(),
175
+ title: z.string().min(1),
176
+ cta: BrandNavLinkSchema
177
+ }).optional(),
178
+ // Standalone policy pages
179
+ terms: BrandPolicyPageSchema,
180
+ privacy: BrandPolicyPageSchema,
181
+ shipping: BrandPolicyPageSchema,
182
+ returns: BrandPolicyPageSchema,
183
+ accessibility: BrandPolicyPageSchema,
184
+ // Misc
185
+ newsletter: z.object({
186
+ eyebrow: z.string().optional(),
187
+ title: z.string().min(1),
188
+ body: z.string()
189
+ }),
190
+ about: z.object({
191
+ eyebrow: z.string().optional(),
192
+ title: z.string().min(1),
193
+ body: z.union([z.string(), z.array(z.string())])
194
+ }),
195
+ faq: BrandFaqSchema,
196
+ account: z.object({
197
+ eyebrow: z.string().optional(),
198
+ title: z.string().min(1),
199
+ signin: z.object({ eyebrow: z.string().optional(), title: z.string().min(1) }).optional(),
200
+ signup: z.object({ eyebrow: z.string().optional(), title: z.string().min(1) }).optional()
201
+ }),
202
+ contactPage: z.object({
203
+ eyebrow: z.string().optional(),
204
+ title: z.string().min(1),
205
+ body: z.string()
206
+ }),
207
+ trackOrder: z.object({
208
+ eyebrow: z.string().optional(),
209
+ title: z.string().min(1),
210
+ body: z.string()
211
+ }),
212
+ footer: z.object({
213
+ sitemap: z.array(z.unknown()).optional(),
214
+ poweredBy: z.string().optional()
215
+ }),
216
+ llms: z.object({ summary: z.string().min(20) }),
217
+ mock: z.object({
218
+ seed: SeedNameSchema,
219
+ businessId: z.string().regex(/^bus_/, "businessId should start with 'bus_'")
220
+ })
221
+ }),
222
+ {
223
+ id: "Brand",
224
+ description: "Single-source-of-truth contract for lib/brand.ts in storefront templates",
225
+ version: "1.0.0"
226
+ }
227
+ );
228
+ var assertBrand = makeAssertion(BrandSchema, "brand");
229
+ var BundleSelectionInputSchema = z.object({
230
+ component_id: z.string(),
231
+ variant_id: z.string().optional(),
232
+ quantity: z.number().int().positive(),
233
+ scheduled_start: z.string().optional(),
234
+ scheduled_end: z.string().optional()
235
+ });
236
+ var CompositeSelectionInputSchema = z.object({
237
+ component_id: z.string().optional(),
238
+ source_product_id: z.string().optional(),
239
+ source_stock_id: z.string().optional(),
240
+ source_type: z.enum(["product", "stock", "add_on", "standalone"]).optional(),
241
+ quantity: z.number().int().positive().optional()
242
+ });
243
+ var CustomerInputValueSchema = z.object({
244
+ field_id: z.string(),
245
+ field_name: z.string().optional(),
246
+ field_type: z.string().optional(),
247
+ value: z.unknown()
248
+ });
249
+ var AddItemPayloadSchema = registerSchema(
250
+ z.object({
251
+ item_id: z.string().min(1),
252
+ quantity: z.number().int().positive(),
253
+ variant_id: z.string().optional(),
254
+ quote_id: z.string().optional(),
255
+ add_on_options: z.array(z.string()).optional(),
256
+ bundle_selections: z.array(BundleSelectionInputSchema).optional(),
257
+ composite_selections: z.array(CompositeSelectionInputSchema).optional(),
258
+ scheduled_start: z.string().optional(),
259
+ scheduled_end: z.string().optional(),
260
+ staff_id: z.string().optional(),
261
+ resource_id: z.string().optional(),
262
+ special_instructions: z.string().optional(),
263
+ customer_inputs: z.array(CustomerInputValueSchema).optional(),
264
+ billing_plan_id: z.string().optional(),
265
+ metadata: z.record(z.string(), z.unknown()).optional()
266
+ }),
267
+ {
268
+ id: "AddItemPayload",
269
+ description: "POST /cart/items request body \u2014 strict on shape, lenient on optional fields",
270
+ version: "1.0.0"
271
+ }
272
+ );
273
+ var assertAddItemPayload = makeAssertion(AddItemPayloadSchema, "payload");
274
+ var VariantDisplayAttributeSchema = z.object({
275
+ axis_id: z.string(),
276
+ axis_name: z.string(),
277
+ value_id: z.string(),
278
+ value_name: z.string()
279
+ });
280
+ var VariantInfoSchema = registerSchema(
281
+ z.object({
282
+ id: z.string(),
283
+ name: z.string(),
284
+ sku: z.string().optional(),
285
+ price_adjustment: MoneySchema,
286
+ display_attributes: z.array(VariantDisplayAttributeSchema).optional(),
287
+ images: z.array(z.string()).optional()
288
+ }),
289
+ {
290
+ id: "VariantInfo",
291
+ description: "Variant axis values + display attributes \u2014 emitted on cart line items",
292
+ version: "1.0.0"
293
+ }
294
+ );
295
+ var VariantDetailsSchema = z.object({
296
+ variant_id: z.string(),
297
+ sku: z.string().optional(),
298
+ properties: z.record(z.string(), z.string())
299
+ });
300
+ var ChosenPriceSchema = z.object({
301
+ base_price: MoneySchema,
302
+ final_price: MoneySchema,
303
+ markup_percentage: MoneySchema,
304
+ markup_amount: MoneySchema,
305
+ markup_discount_percentage: MoneySchema,
306
+ markup_discount_amount: MoneySchema
307
+ });
308
+ var AddOnDetailsSchema = z.object({
309
+ selected_options: z.array(z.unknown()),
310
+ total_add_on_price: MoneySchema,
311
+ add_ons: z.array(z.unknown())
312
+ });
313
+ var BundleResolvedSchema = z.looseObject({
314
+ bundle_id: z.string(),
315
+ selections: z.array(z.unknown())
316
+ });
317
+ var CompositeResolvedSchema = z.looseObject({
318
+ composite_id: z.string(),
319
+ selections: z.array(z.unknown()),
320
+ breakdown: z.object({
321
+ base_price: MoneySchema,
322
+ components_total: MoneySchema,
323
+ final_price: MoneySchema,
324
+ tier_applied: z.string().optional()
325
+ }).optional()
326
+ });
327
+ var DiscountDetailsSchema = z.object({
328
+ applied_count: z.number().int().nonnegative(),
329
+ total_amount: MoneySchema,
330
+ discount_ids: z.array(z.string())
331
+ });
332
+ var CartItemSchema = registerSchema(
333
+ z.looseObject({
334
+ id: z.string(),
335
+ cart_id: z.string(),
336
+ item_id: z.string(),
337
+ quantity: z.number().int().nonnegative(),
338
+ line_key: z.string(),
339
+ line_type: LineTypeSchema,
340
+ name: z.string(),
341
+ description: z.string().optional(),
342
+ image_url: z.string().optional(),
343
+ category_id: z.string().optional(),
344
+ category_name: z.string().optional(),
345
+ is_available: z.boolean(),
346
+ variant_id: z.string().optional(),
347
+ variant_name: z.string().optional(),
348
+ variant_info: VariantInfoSchema.optional(),
349
+ variant_details: VariantDetailsSchema.optional(),
350
+ base_price: MoneySchema,
351
+ add_ons_price: MoneySchema,
352
+ total_price: MoneySchema,
353
+ item_discount_amount: MoneySchema,
354
+ price_info: ChosenPriceSchema,
355
+ add_on_option_ids: z.array(z.string()),
356
+ add_on_ids: z.array(z.string()),
357
+ add_on_details: AddOnDetailsSchema,
358
+ add_on_options: z.array(z.unknown()),
359
+ add_ons: z.array(z.unknown()),
360
+ scheduled_start: z.string().optional(),
361
+ scheduled_end: z.string().optional(),
362
+ staff_id: z.string().optional(),
363
+ resource_id: z.string().optional(),
364
+ service_status: ServiceStatusSchema.optional(),
365
+ confirmation_code: z.string().optional(),
366
+ special_instructions: z.string().optional(),
367
+ customer_inputs: z.array(CustomerInputValueSchema).optional(),
368
+ bundle_selections: z.unknown().optional(),
369
+ bundle_resolved: BundleResolvedSchema.optional(),
370
+ composite_selections: z.unknown().optional(),
371
+ composite_resolved: CompositeResolvedSchema.optional(),
372
+ billing_plan_id: z.string().optional(),
373
+ applied_discount_ids: z.array(z.string()),
374
+ discount_details: DiscountDetailsSchema.optional(),
375
+ metadata: z.record(z.string(), z.unknown()).optional(),
376
+ created_at: TimestampSchema,
377
+ updated_at: TimestampSchema
378
+ }),
379
+ {
380
+ id: "CartItem",
381
+ description: "Cart line item \u2014 loose so backend additions don't break old SDK clients",
382
+ version: "1.0.0"
383
+ }
384
+ );
385
+ var assertCartItem = makeAssertion(CartItemSchema, "cartItem");
386
+ var CartPricingSchema = registerSchema(
387
+ z.object({
388
+ subtotal: MoneySchema,
389
+ total_discounts: MoneySchema,
390
+ tax_amount: MoneySchema,
391
+ service_charge: MoneySchema,
392
+ total_price: MoneySchema,
393
+ currency: CurrencyCodeSchema,
394
+ tax_rate: MoneySchema.optional(),
395
+ service_charge_rate: MoneySchema.optional()
396
+ }),
397
+ {
398
+ id: "CartPricing",
399
+ description: "Cart-level pricing roll-up \u2014 subtotal, tax, service, total",
400
+ version: "1.0.0"
401
+ }
402
+ );
403
+ var CartSchema = registerSchema(
404
+ z.looseObject({
405
+ id: z.string(),
406
+ business_id: z.string(),
407
+ items: z.array(CartItemSchema),
408
+ pricing: CartPricingSchema,
409
+ customer_info: z.object({
410
+ name: z.string(),
411
+ email: z.string().optional(),
412
+ phone: z.string().optional(),
413
+ address: z.string().optional()
414
+ }),
415
+ created_at: TimestampSchema,
416
+ updated_at: TimestampSchema,
417
+ expires_at: TimestampSchema,
418
+ status: z.string(),
419
+ source: z.string(),
420
+ channel: z.string()
421
+ }),
422
+ {
423
+ id: "Cart",
424
+ description: "Full cart envelope \u2014 loose for forward-compat with backend additions",
425
+ version: "1.0.0"
426
+ }
427
+ );
428
+ var assertCart = makeAssertion(CartSchema, "cart");
429
+ var CheckoutCustomerSchema = z.object({
430
+ name: z.string().min(1),
431
+ email: z.string().email(),
432
+ phone: z.string().min(1),
433
+ notes: z.string().optional(),
434
+ save_details: z.boolean().optional()
435
+ });
436
+ var CheckoutBodySchema = registerSchema(
437
+ z.object({
438
+ cart_id: z.string().min(1),
439
+ location_id: z.string().optional(),
440
+ customer: CheckoutCustomerSchema,
441
+ order_type: z.string().min(1),
442
+ address_info: z.record(z.string(), z.unknown()).optional(),
443
+ payment_method: z.string().min(1),
444
+ mobile_money_details: z.object({ phone_number: z.string(), provider: z.string() }).optional(),
445
+ special_instructions: z.string().optional(),
446
+ metadata: z.record(z.string(), z.unknown()).optional(),
447
+ pay_currency: z.string().optional(),
448
+ fx_quote_id: z.string().optional()
449
+ }),
450
+ {
451
+ id: "CheckoutBody",
452
+ description: "POST /checkout request body",
453
+ version: "1.0.0"
454
+ }
455
+ );
456
+ var assertCheckoutBody = makeAssertion(CheckoutBodySchema, "checkoutBody");
457
+ var AuthorizationTypeSchema = z.enum(["otp", "pin", "phone", "birthday", "address"]);
458
+ var NextActionSchema = z.discriminatedUnion("type", [
459
+ z.object({ type: z.literal("none") }),
460
+ z.object({ type: z.literal("redirect"), authorization_url: z.string() }),
461
+ z.object({
462
+ type: z.literal("authorization"),
463
+ authorization_type: z.string(),
464
+ display_text: z.string().optional()
465
+ })
466
+ ]);
467
+ var CheckoutResponseSchema = registerSchema(
468
+ z.looseObject({
469
+ order_id: z.string().min(1),
470
+ order_number: z.string().min(1),
471
+ payment_status: z.string().min(1),
472
+ payment_reference: z.string().optional(),
473
+ requires_authorization: z.boolean(),
474
+ authorization_type: AuthorizationTypeSchema.optional(),
475
+ next_action: NextActionSchema,
476
+ provider: z.string().optional(),
477
+ authorization_url: z.string().optional(),
478
+ display_text: z.string().optional(),
479
+ bill_token: z.string().optional(),
480
+ client_secret: z.string().optional(),
481
+ public_key: z.string().optional()
482
+ }),
483
+ {
484
+ id: "CheckoutResponse",
485
+ description: "POST /checkout response \u2014 loose for payment-provider field additions",
486
+ version: "1.0.0"
487
+ }
488
+ );
489
+ var assertCheckoutResponse = makeAssertion(CheckoutResponseSchema, "checkout");
490
+
491
+ // src/testing/client.ts
492
+ var TEST_BASE_URL = "http://test.local";
493
+ async function toForwardedRequest(input, init) {
494
+ if (input instanceof Request) {
495
+ return {
496
+ method: init?.method ?? input.method,
497
+ headers: new Headers(init?.headers ?? input.headers),
498
+ body: init?.body ?? (["GET", "HEAD"].includes(input.method) ? void 0 : await input.text())
499
+ };
500
+ }
501
+ return {
502
+ method: init?.method ?? "GET",
503
+ headers: new Headers(init?.headers ?? {}),
504
+ body: init?.body ?? void 0
505
+ };
506
+ }
507
+ function createTestClient(options = {}) {
508
+ const mock = createMockApp(options);
509
+ let sessionToken;
510
+ const fetchImpl = async (input, init) => {
511
+ const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
512
+ if (!url.startsWith(TEST_BASE_URL)) {
513
+ return globalThis.fetch(input, init);
514
+ }
515
+ const path = url.slice(TEST_BASE_URL.length);
516
+ const fwd = await toForwardedRequest(input, init);
517
+ if (sessionToken) fwd.headers.set("x-session-token", sessionToken);
518
+ const res = await mock.request(path, {
519
+ method: fwd.method,
520
+ headers: fwd.headers,
521
+ body: fwd.body
522
+ });
523
+ const echoed = res.headers.get("x-session-token");
524
+ if (echoed) sessionToken = echoed;
525
+ return res;
526
+ };
527
+ const client = createCimplifyClient({
528
+ baseUrl: TEST_BASE_URL,
529
+ publicKey: "test-public-key",
530
+ suppressPublicKeyWarning: true,
531
+ fetch: fetchImpl
532
+ });
533
+ return {
534
+ client,
535
+ mock,
536
+ reset: () => {
537
+ mock.deps.resetAll();
538
+ sessionToken = void 0;
539
+ },
540
+ dispose: () => {
541
+ mock.deps.resetAll();
542
+ sessionToken = void 0;
543
+ }
544
+ };
545
+ }
546
+ async function pickProduct(client, opts) {
547
+ const list = await client.catalogue.getProducts();
548
+ if (!list.ok) throw list.error;
549
+ const body = list.value;
550
+ const products = body.items ?? [];
551
+ if (products.length === 0) throw new Error("No products in catalogue (wrong seed?)");
552
+ if (opts.slug) {
553
+ const found = products.find((p) => p.slug === opts.slug);
554
+ if (!found) throw new Error(`Product slug "${opts.slug}" not found in catalogue`);
555
+ return found;
556
+ }
557
+ return products.find((p) => p.type === "product") ?? products[0];
558
+ }
559
+ var fixtures = {
560
+ /**
561
+ * Add the first available product (or a named one) to the cart.
562
+ * Picks the first variant if the product has variants.
563
+ */
564
+ async addFirstProduct(client, opts = {}) {
565
+ const product = await pickProduct(client, opts);
566
+ let variantId;
567
+ if (opts.withVariant !== false) {
568
+ const variants = await client.catalogue.getVariants(product.id);
569
+ if (variants.ok && variants.value.length > 0) {
570
+ variantId = variants.value[0]?.id;
571
+ }
572
+ }
573
+ const res = await client.cart.addItem({
574
+ item_id: product.id,
575
+ quantity: 1,
576
+ variant_id: variantId
577
+ });
578
+ if (!res.ok) throw res.error;
579
+ return { product, variantId };
580
+ },
581
+ /** A minimal valid customer object for checkout. */
582
+ customer(overrides = {}) {
583
+ return {
584
+ name: overrides.name ?? "Test Customer",
585
+ email: overrides.email ?? "test@example.com",
586
+ phone: overrides.phone ?? "+233244000000"
587
+ };
588
+ },
589
+ /**
590
+ * Run the full guest auth flow (request OTP → verify) and return
591
+ * the new session token. The mock's permissive auth mode echoes
592
+ * the code in `request_otp`, so we don't need to read it.
593
+ */
594
+ async authenticate(client, contact = "test@example.com", code = "123456") {
595
+ const req = await client.auth.requestOtp(contact);
596
+ if (!req.ok) throw req.error;
597
+ const verify = await client.auth.verifyOtp(contact, code);
598
+ if (!verify.ok) throw verify.error;
599
+ const value = verify.value;
600
+ return { token: value.session_token ?? "", customerId: value.customer_id ?? "" };
601
+ }
602
+ };
603
+
604
+ export { AddItemPayloadSchema, AddOnDetailsSchema, AuthorizationTypeSchema, BrandContactSchema, BrandFaqSchema, BrandHeroSchema, BrandNavLinkSchema, BrandPolicyPageSchema, BrandPolicySectionSchema, BrandSchema, BrandSocialSchema, BundleResolvedSchema, BundleSelectionInputSchema, CartItemSchema, CartPricingSchema, CartSchema, CheckoutBodySchema, CheckoutCustomerSchema, CheckoutResponseSchema, ChosenPriceSchema, CompositeResolvedSchema, CompositeSelectionInputSchema, CountryCodeSchema, CurrencyCodeSchema, CustomerInputValueSchema, DiscountDetailsSchema, IsoDateTimeSchema, LineTypeSchema, LocaleSchema, MoneyLooseSchema, MoneySchema, NextActionSchema, PhoneE164Schema, ProductTypeSchema, SchemaViolationError, SeedNameSchema, ServiceStatusSchema, TimestampSchema, VariantDetailsSchema, VariantDisplayAttributeSchema, VariantInfoSchema, assertAddItemPayload, assertBrand, assertCart, assertCartItem, assertCheckoutBody, assertCheckoutResponse, cimplifyRegistry, createTestClient, fixtures, makeAssertion, registerSchema };