@cimplify/sdk 0.81.0 → 0.83.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.
- package/dist/advanced.d.mts +3 -3
- package/dist/advanced.d.ts +3 -3
- package/dist/{chunk-SRJEMEVZ.js → chunk-FKBXZ2A6.js} +212 -6
- package/dist/{chunk-7PAQR3VC.mjs → chunk-I6RE4BKH.mjs} +4 -2
- package/dist/{chunk-IZDJEDR4.js → chunk-ODEPW244.js} +5 -3
- package/dist/{chunk-BRVIXGUW.mjs → chunk-PLTP6HWW.mjs} +212 -6
- package/dist/{client-C51FFhDz.d.mts → client-Cogz7C1t.d.mts} +2 -2
- package/dist/{client-Q_m-GkTl.d.ts → client-Cq3B-WXv.d.ts} +2 -2
- package/dist/{client-Cx3WLhMj.d.mts → client-DnHP_2Jw.d.mts} +3 -2
- package/dist/{client-BmDNlUMx.d.ts → client-xc2aQSB4.d.ts} +3 -2
- package/dist/{index-Moe4cGMB.d.ts → index-C4xE31-D.d.ts} +3 -3
- package/dist/{index-Bu76UyFz.d.mts → index-Dy8D3r9b.d.mts} +3 -3
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/mock/cli.mjs +309 -19
- package/dist/mock/library.js +223 -6
- package/dist/mock/library.mjs +216 -7
- package/dist/mock/msw.js +212 -6
- package/dist/mock/msw.mjs +212 -6
- package/dist/{payment-B7qzWdaJ.d.mts → payment-T_0MUE9o.d.mts} +1 -1
- package/dist/{payment-mVIJIJcq.d.ts → payment-nH9OCUg2.d.ts} +1 -1
- package/dist/{price-CS1IsORZ.d.ts → price-B8WMoldA.d.ts} +1 -1
- package/dist/{price-BfOaGqjx.d.mts → price-Bg7hujK_.d.mts} +1 -1
- package/dist/{product-BgFOFmQw.d.mts → product-DXhjLQ_w.d.mts} +1 -0
- package/dist/{product-BgFOFmQw.d.ts → product-DXhjLQ_w.d.ts} +1 -0
- package/dist/react.d.mts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +2 -1
- package/dist/react.mjs +2 -1
- package/dist/{server-hP9NLtTh.d.mts → server-DaovvB9J.d.mts} +87 -3
- package/dist/{server-N4Q24CnO.d.ts → server-ZGCyuz4V.d.ts} +87 -3
- package/dist/server.d.mts +4 -4
- package/dist/server.d.ts +4 -4
- package/dist/testing/msw.d.mts +2 -2
- package/dist/testing/msw.d.ts +2 -2
- package/dist/testing/msw.js +2 -2
- package/dist/testing/msw.mjs +1 -1
- package/dist/testing/suite.d.mts +6 -6
- package/dist/testing/suite.d.ts +6 -6
- package/dist/testing/suite.js +21 -21
- package/dist/testing/suite.mjs +2 -2
- package/dist/testing.d.mts +11 -5
- package/dist/testing.d.ts +11 -5
- package/dist/testing.js +77 -77
- package/dist/testing.mjs +3 -3
- package/dist/utils.d.mts +4 -4
- package/dist/utils.d.ts +4 -4
- package/package.json +1 -1
package/dist/mock/library.js
CHANGED
|
@@ -5901,6 +5901,14 @@ function createLinkService({ clock, ids }) {
|
|
|
5901
5901
|
};
|
|
5902
5902
|
}
|
|
5903
5903
|
|
|
5904
|
+
// src/mock/state/snapshot.ts
|
|
5905
|
+
function applySnapshot(reg, data) {
|
|
5906
|
+
for (const [k, v] of Object.entries(data)) {
|
|
5907
|
+
const store = reg[k];
|
|
5908
|
+
if (store) store.loadJSON(v);
|
|
5909
|
+
}
|
|
5910
|
+
}
|
|
5911
|
+
|
|
5904
5912
|
// src/mock/seeds/image.ts
|
|
5905
5913
|
var CDN_BASE_URL = "https://static-tmp.cimplify.io";
|
|
5906
5914
|
function seedImage(industry, slug) {
|
|
@@ -10268,15 +10276,217 @@ function applySeed(registry, name) {
|
|
|
10268
10276
|
return fn(registry);
|
|
10269
10277
|
}
|
|
10270
10278
|
|
|
10279
|
+
// src/mock/seeds/context.ts
|
|
10280
|
+
var SEED_ISO = "2026-01-01T00:00:00.000Z";
|
|
10281
|
+
var ID_PREFIX = {
|
|
10282
|
+
business: "bus_",
|
|
10283
|
+
category: "cat_",
|
|
10284
|
+
collection: "col_",
|
|
10285
|
+
product: "prod_",
|
|
10286
|
+
service: "svc_"
|
|
10287
|
+
};
|
|
10288
|
+
var DEFAULT_CURRENCY = "GHS";
|
|
10289
|
+
function slugify(value) {
|
|
10290
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
10291
|
+
}
|
|
10292
|
+
function makeSeedContext(registry) {
|
|
10293
|
+
let current;
|
|
10294
|
+
const requireBusiness = () => {
|
|
10295
|
+
if (current) return current;
|
|
10296
|
+
const sole = registry.businesses.list();
|
|
10297
|
+
if (sole.length === 1) {
|
|
10298
|
+
current = sole[0];
|
|
10299
|
+
return current;
|
|
10300
|
+
}
|
|
10301
|
+
throw new Error("Seed must create a business (ctx.business) before adding child records.");
|
|
10302
|
+
};
|
|
10303
|
+
const resolveCategoryId = (cat) => {
|
|
10304
|
+
if (!cat) return void 0;
|
|
10305
|
+
if (typeof cat !== "string") return cat.id;
|
|
10306
|
+
if (registry.categories.get(cat)) return cat;
|
|
10307
|
+
return registry.categories.list().find((c) => c.slug === cat)?.id;
|
|
10308
|
+
};
|
|
10309
|
+
const resolveCollectionId = (col) => {
|
|
10310
|
+
if (!col) return void 0;
|
|
10311
|
+
if (typeof col !== "string") return col.id;
|
|
10312
|
+
if (registry.collections.get(col)) return col;
|
|
10313
|
+
return registry.collections.list().find((c) => c.slug === col)?.id;
|
|
10314
|
+
};
|
|
10315
|
+
return {
|
|
10316
|
+
registry,
|
|
10317
|
+
business(input) {
|
|
10318
|
+
const handle = input.handle ?? slugify(input.name);
|
|
10319
|
+
const id = `${ID_PREFIX.business}${slugify(handle)}`;
|
|
10320
|
+
const business = {
|
|
10321
|
+
business_type: "other",
|
|
10322
|
+
email: `hello@${handle}.test`,
|
|
10323
|
+
default_currency: DEFAULT_CURRENCY,
|
|
10324
|
+
default_offers_table_service: false,
|
|
10325
|
+
default_accepts_online_orders: true,
|
|
10326
|
+
status: "active",
|
|
10327
|
+
created_by: "seed",
|
|
10328
|
+
preferences: {},
|
|
10329
|
+
is_online_only: true,
|
|
10330
|
+
enabled_payment_types: ["mobile_money"],
|
|
10331
|
+
default_location_settings: {},
|
|
10332
|
+
country_code: "GH",
|
|
10333
|
+
timezone: "Africa/Accra",
|
|
10334
|
+
...input,
|
|
10335
|
+
id,
|
|
10336
|
+
handle,
|
|
10337
|
+
created_at: input.created_at ?? SEED_ISO,
|
|
10338
|
+
updated_at: input.updated_at ?? SEED_ISO
|
|
10339
|
+
};
|
|
10340
|
+
registry.businesses.put(id, business);
|
|
10341
|
+
current = business;
|
|
10342
|
+
return business;
|
|
10343
|
+
},
|
|
10344
|
+
category(input) {
|
|
10345
|
+
const business = requireBusiness();
|
|
10346
|
+
const slug = input.slug ?? slugify(input.name);
|
|
10347
|
+
const id = `${ID_PREFIX.category}${slug}`;
|
|
10348
|
+
const category = {
|
|
10349
|
+
id,
|
|
10350
|
+
business_id: business.id,
|
|
10351
|
+
name: input.name,
|
|
10352
|
+
slug,
|
|
10353
|
+
description: input.description,
|
|
10354
|
+
image: input.image,
|
|
10355
|
+
product_ids: [],
|
|
10356
|
+
display_order: input.displayOrder ?? 0,
|
|
10357
|
+
is_active: true,
|
|
10358
|
+
created_at: SEED_ISO,
|
|
10359
|
+
updated_at: SEED_ISO
|
|
10360
|
+
};
|
|
10361
|
+
registry.categories.put(id, category);
|
|
10362
|
+
return category;
|
|
10363
|
+
},
|
|
10364
|
+
collection(input) {
|
|
10365
|
+
const business = requireBusiness();
|
|
10366
|
+
const slug = input.slug ?? slugify(input.name);
|
|
10367
|
+
const id = `${ID_PREFIX.collection}${slug}`;
|
|
10368
|
+
const collection = {
|
|
10369
|
+
id,
|
|
10370
|
+
business_id: business.id,
|
|
10371
|
+
name: input.name,
|
|
10372
|
+
slug,
|
|
10373
|
+
description: input.description,
|
|
10374
|
+
product_ids: [],
|
|
10375
|
+
is_active: true,
|
|
10376
|
+
created_at: SEED_ISO,
|
|
10377
|
+
updated_at: SEED_ISO
|
|
10378
|
+
};
|
|
10379
|
+
registry.collections.put(id, collection);
|
|
10380
|
+
return collection;
|
|
10381
|
+
},
|
|
10382
|
+
product(input) {
|
|
10383
|
+
const business = requireBusiness();
|
|
10384
|
+
const slug = input.slug ?? slugify(input.name);
|
|
10385
|
+
const id = `${ID_PREFIX.product}${slug}`;
|
|
10386
|
+
const categoryId = resolveCategoryId(input.category);
|
|
10387
|
+
const collectionId = resolveCollectionId(input.collection);
|
|
10388
|
+
const product = {
|
|
10389
|
+
id,
|
|
10390
|
+
business_id: business.id,
|
|
10391
|
+
name: input.name,
|
|
10392
|
+
slug,
|
|
10393
|
+
description: input.description,
|
|
10394
|
+
product_type: input.productType ?? "product",
|
|
10395
|
+
base_price: input.price,
|
|
10396
|
+
currency: input.currency ?? business.default_currency,
|
|
10397
|
+
image: input.image,
|
|
10398
|
+
images: input.images ?? (input.image ? [input.image] : []),
|
|
10399
|
+
is_available: true,
|
|
10400
|
+
category_ids: categoryId ? [categoryId] : [],
|
|
10401
|
+
collection_ids: collectionId ? [collectionId] : [],
|
|
10402
|
+
add_on_ids: [],
|
|
10403
|
+
variant_ids: [],
|
|
10404
|
+
tags: input.tags ?? [],
|
|
10405
|
+
calories: input.calories,
|
|
10406
|
+
allergies: input.allergies ?? [],
|
|
10407
|
+
ingredients: input.ingredients ?? [],
|
|
10408
|
+
pairings: [],
|
|
10409
|
+
is_signature: input.isSignature ?? false,
|
|
10410
|
+
is_new: input.isNew ?? false,
|
|
10411
|
+
duration_minutes: input.durationMinutes,
|
|
10412
|
+
metadata: input.metadata,
|
|
10413
|
+
created_at: SEED_ISO,
|
|
10414
|
+
updated_at: SEED_ISO
|
|
10415
|
+
};
|
|
10416
|
+
registry.products.put(id, product);
|
|
10417
|
+
if (categoryId) {
|
|
10418
|
+
const cat = registry.categories.get(categoryId);
|
|
10419
|
+
if (cat && !cat.product_ids.includes(id)) cat.product_ids.push(id);
|
|
10420
|
+
}
|
|
10421
|
+
if (collectionId) {
|
|
10422
|
+
const col = registry.collections.get(collectionId);
|
|
10423
|
+
if (col && !col.product_ids.includes(id)) col.product_ids.push(id);
|
|
10424
|
+
}
|
|
10425
|
+
return product;
|
|
10426
|
+
},
|
|
10427
|
+
service(input) {
|
|
10428
|
+
const business = requireBusiness();
|
|
10429
|
+
const id = `${ID_PREFIX.service}${slugify(input.name)}`;
|
|
10430
|
+
const service = {
|
|
10431
|
+
id,
|
|
10432
|
+
business_id: business.id,
|
|
10433
|
+
name: input.name,
|
|
10434
|
+
description: input.description,
|
|
10435
|
+
duration_minutes: input.durationMinutes,
|
|
10436
|
+
price: input.price,
|
|
10437
|
+
is_available: true
|
|
10438
|
+
};
|
|
10439
|
+
registry.services.put(id, service);
|
|
10440
|
+
return service;
|
|
10441
|
+
},
|
|
10442
|
+
image: seedImage,
|
|
10443
|
+
extend(name) {
|
|
10444
|
+
const result = applySeed(registry, name);
|
|
10445
|
+
current = registry.businesses.get(result.businessId) ?? current;
|
|
10446
|
+
return result;
|
|
10447
|
+
}
|
|
10448
|
+
};
|
|
10449
|
+
}
|
|
10450
|
+
function defineSeed(seed) {
|
|
10451
|
+
return seed;
|
|
10452
|
+
}
|
|
10453
|
+
|
|
10454
|
+
// src/mock/seeds/source.ts
|
|
10455
|
+
var SNAPSHOT_META_KEY = "__meta";
|
|
10456
|
+
function loadSnapshot(registry, data, businessId) {
|
|
10457
|
+
applySnapshot(registry, data);
|
|
10458
|
+
if (businessId) return { businessId };
|
|
10459
|
+
const meta = data[SNAPSHOT_META_KEY];
|
|
10460
|
+
if (meta?.defaultBusinessId) return { businessId: meta.defaultBusinessId };
|
|
10461
|
+
const businesses = registry.businesses.list();
|
|
10462
|
+
if (businesses.length === 1) return { businessId: businesses[0].id };
|
|
10463
|
+
if (businesses.length === 0) {
|
|
10464
|
+
throw new Error("Seed snapshot has no business. Add one, or set __meta.defaultBusinessId.");
|
|
10465
|
+
}
|
|
10466
|
+
throw new Error(
|
|
10467
|
+
`Seed snapshot has ${businesses.length} businesses; set __meta.defaultBusinessId to pick one.`
|
|
10468
|
+
);
|
|
10469
|
+
}
|
|
10470
|
+
function resolveSeed(registry, source) {
|
|
10471
|
+
if (typeof source === "string") return applySeed(registry, source);
|
|
10472
|
+
switch (source.kind) {
|
|
10473
|
+
case "builtin":
|
|
10474
|
+
return applySeed(registry, source.name);
|
|
10475
|
+
case "json":
|
|
10476
|
+
return loadSnapshot(registry, source.data, source.businessId);
|
|
10477
|
+
case "fn":
|
|
10478
|
+
return source.seed(makeSeedContext(registry));
|
|
10479
|
+
}
|
|
10480
|
+
}
|
|
10481
|
+
|
|
10271
10482
|
// src/mock/deps.ts
|
|
10272
10483
|
function createDeps(options = {}) {
|
|
10273
10484
|
const clock = createClock({ frozenAt: options.frozenAt });
|
|
10274
10485
|
const ids = createIdGen(options.rngSeed);
|
|
10275
10486
|
const bus = createBus({ idGen: () => ids.raw("evt"), clock: () => clock.now() });
|
|
10276
10487
|
const registry = createStateRegistry();
|
|
10277
|
-
const
|
|
10278
|
-
|
|
10279
|
-
let defaultBusinessId = seedResult.businessId;
|
|
10488
|
+
const seedSource = options.seed ?? "default";
|
|
10489
|
+
let defaultBusinessId = resolveSeed(registry, seedSource).businessId;
|
|
10280
10490
|
const auth = createAuthService({
|
|
10281
10491
|
registry,
|
|
10282
10492
|
clock,
|
|
@@ -10330,11 +10540,10 @@ function createDeps(options = {}) {
|
|
|
10330
10540
|
return defaultBusinessId;
|
|
10331
10541
|
},
|
|
10332
10542
|
chaos,
|
|
10333
|
-
resetAll(
|
|
10543
|
+
resetAll(next) {
|
|
10334
10544
|
for (const store of Object.values(registry)) store.reset();
|
|
10335
10545
|
bus.clear();
|
|
10336
|
-
|
|
10337
|
-
defaultBusinessId = r.businessId;
|
|
10546
|
+
defaultBusinessId = resolveSeed(registry, next ?? seedSource).businessId;
|
|
10338
10547
|
return defaultBusinessId;
|
|
10339
10548
|
}
|
|
10340
10549
|
};
|
|
@@ -10437,9 +10646,17 @@ function setupWebhooks(bus, opts) {
|
|
|
10437
10646
|
});
|
|
10438
10647
|
}
|
|
10439
10648
|
|
|
10649
|
+
exports.SEED_ISO = SEED_ISO;
|
|
10650
|
+
exports.SNAPSHOT_META_KEY = SNAPSHOT_META_KEY;
|
|
10440
10651
|
exports.applySeed = applySeed;
|
|
10652
|
+
exports.applySnapshot = applySnapshot;
|
|
10441
10653
|
exports.createDeps = createDeps;
|
|
10442
10654
|
exports.createMockApp = createMockApp;
|
|
10655
|
+
exports.defineSeed = defineSeed;
|
|
10656
|
+
exports.loadSnapshot = loadSnapshot;
|
|
10657
|
+
exports.makeSeedContext = makeSeedContext;
|
|
10658
|
+
exports.resolveSeed = resolveSeed;
|
|
10443
10659
|
exports.setupWebhooks = setupWebhooks;
|
|
10444
10660
|
exports.signPayload = signPayload;
|
|
10661
|
+
exports.slugify = slugify;
|
|
10445
10662
|
exports.verifySignature = verifySignature;
|
package/dist/mock/library.mjs
CHANGED
|
@@ -5899,6 +5899,14 @@ function createLinkService({ clock, ids }) {
|
|
|
5899
5899
|
};
|
|
5900
5900
|
}
|
|
5901
5901
|
|
|
5902
|
+
// src/mock/state/snapshot.ts
|
|
5903
|
+
function applySnapshot(reg, data) {
|
|
5904
|
+
for (const [k, v] of Object.entries(data)) {
|
|
5905
|
+
const store = reg[k];
|
|
5906
|
+
if (store) store.loadJSON(v);
|
|
5907
|
+
}
|
|
5908
|
+
}
|
|
5909
|
+
|
|
5902
5910
|
// src/mock/seeds/image.ts
|
|
5903
5911
|
var CDN_BASE_URL = "https://static-tmp.cimplify.io";
|
|
5904
5912
|
function seedImage(industry, slug) {
|
|
@@ -10266,15 +10274,217 @@ function applySeed(registry, name) {
|
|
|
10266
10274
|
return fn(registry);
|
|
10267
10275
|
}
|
|
10268
10276
|
|
|
10277
|
+
// src/mock/seeds/context.ts
|
|
10278
|
+
var SEED_ISO = "2026-01-01T00:00:00.000Z";
|
|
10279
|
+
var ID_PREFIX = {
|
|
10280
|
+
business: "bus_",
|
|
10281
|
+
category: "cat_",
|
|
10282
|
+
collection: "col_",
|
|
10283
|
+
product: "prod_",
|
|
10284
|
+
service: "svc_"
|
|
10285
|
+
};
|
|
10286
|
+
var DEFAULT_CURRENCY = "GHS";
|
|
10287
|
+
function slugify(value) {
|
|
10288
|
+
return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
|
|
10289
|
+
}
|
|
10290
|
+
function makeSeedContext(registry) {
|
|
10291
|
+
let current;
|
|
10292
|
+
const requireBusiness = () => {
|
|
10293
|
+
if (current) return current;
|
|
10294
|
+
const sole = registry.businesses.list();
|
|
10295
|
+
if (sole.length === 1) {
|
|
10296
|
+
current = sole[0];
|
|
10297
|
+
return current;
|
|
10298
|
+
}
|
|
10299
|
+
throw new Error("Seed must create a business (ctx.business) before adding child records.");
|
|
10300
|
+
};
|
|
10301
|
+
const resolveCategoryId = (cat) => {
|
|
10302
|
+
if (!cat) return void 0;
|
|
10303
|
+
if (typeof cat !== "string") return cat.id;
|
|
10304
|
+
if (registry.categories.get(cat)) return cat;
|
|
10305
|
+
return registry.categories.list().find((c) => c.slug === cat)?.id;
|
|
10306
|
+
};
|
|
10307
|
+
const resolveCollectionId = (col) => {
|
|
10308
|
+
if (!col) return void 0;
|
|
10309
|
+
if (typeof col !== "string") return col.id;
|
|
10310
|
+
if (registry.collections.get(col)) return col;
|
|
10311
|
+
return registry.collections.list().find((c) => c.slug === col)?.id;
|
|
10312
|
+
};
|
|
10313
|
+
return {
|
|
10314
|
+
registry,
|
|
10315
|
+
business(input) {
|
|
10316
|
+
const handle = input.handle ?? slugify(input.name);
|
|
10317
|
+
const id = `${ID_PREFIX.business}${slugify(handle)}`;
|
|
10318
|
+
const business = {
|
|
10319
|
+
business_type: "other",
|
|
10320
|
+
email: `hello@${handle}.test`,
|
|
10321
|
+
default_currency: DEFAULT_CURRENCY,
|
|
10322
|
+
default_offers_table_service: false,
|
|
10323
|
+
default_accepts_online_orders: true,
|
|
10324
|
+
status: "active",
|
|
10325
|
+
created_by: "seed",
|
|
10326
|
+
preferences: {},
|
|
10327
|
+
is_online_only: true,
|
|
10328
|
+
enabled_payment_types: ["mobile_money"],
|
|
10329
|
+
default_location_settings: {},
|
|
10330
|
+
country_code: "GH",
|
|
10331
|
+
timezone: "Africa/Accra",
|
|
10332
|
+
...input,
|
|
10333
|
+
id,
|
|
10334
|
+
handle,
|
|
10335
|
+
created_at: input.created_at ?? SEED_ISO,
|
|
10336
|
+
updated_at: input.updated_at ?? SEED_ISO
|
|
10337
|
+
};
|
|
10338
|
+
registry.businesses.put(id, business);
|
|
10339
|
+
current = business;
|
|
10340
|
+
return business;
|
|
10341
|
+
},
|
|
10342
|
+
category(input) {
|
|
10343
|
+
const business = requireBusiness();
|
|
10344
|
+
const slug = input.slug ?? slugify(input.name);
|
|
10345
|
+
const id = `${ID_PREFIX.category}${slug}`;
|
|
10346
|
+
const category = {
|
|
10347
|
+
id,
|
|
10348
|
+
business_id: business.id,
|
|
10349
|
+
name: input.name,
|
|
10350
|
+
slug,
|
|
10351
|
+
description: input.description,
|
|
10352
|
+
image: input.image,
|
|
10353
|
+
product_ids: [],
|
|
10354
|
+
display_order: input.displayOrder ?? 0,
|
|
10355
|
+
is_active: true,
|
|
10356
|
+
created_at: SEED_ISO,
|
|
10357
|
+
updated_at: SEED_ISO
|
|
10358
|
+
};
|
|
10359
|
+
registry.categories.put(id, category);
|
|
10360
|
+
return category;
|
|
10361
|
+
},
|
|
10362
|
+
collection(input) {
|
|
10363
|
+
const business = requireBusiness();
|
|
10364
|
+
const slug = input.slug ?? slugify(input.name);
|
|
10365
|
+
const id = `${ID_PREFIX.collection}${slug}`;
|
|
10366
|
+
const collection = {
|
|
10367
|
+
id,
|
|
10368
|
+
business_id: business.id,
|
|
10369
|
+
name: input.name,
|
|
10370
|
+
slug,
|
|
10371
|
+
description: input.description,
|
|
10372
|
+
product_ids: [],
|
|
10373
|
+
is_active: true,
|
|
10374
|
+
created_at: SEED_ISO,
|
|
10375
|
+
updated_at: SEED_ISO
|
|
10376
|
+
};
|
|
10377
|
+
registry.collections.put(id, collection);
|
|
10378
|
+
return collection;
|
|
10379
|
+
},
|
|
10380
|
+
product(input) {
|
|
10381
|
+
const business = requireBusiness();
|
|
10382
|
+
const slug = input.slug ?? slugify(input.name);
|
|
10383
|
+
const id = `${ID_PREFIX.product}${slug}`;
|
|
10384
|
+
const categoryId = resolveCategoryId(input.category);
|
|
10385
|
+
const collectionId = resolveCollectionId(input.collection);
|
|
10386
|
+
const product = {
|
|
10387
|
+
id,
|
|
10388
|
+
business_id: business.id,
|
|
10389
|
+
name: input.name,
|
|
10390
|
+
slug,
|
|
10391
|
+
description: input.description,
|
|
10392
|
+
product_type: input.productType ?? "product",
|
|
10393
|
+
base_price: input.price,
|
|
10394
|
+
currency: input.currency ?? business.default_currency,
|
|
10395
|
+
image: input.image,
|
|
10396
|
+
images: input.images ?? (input.image ? [input.image] : []),
|
|
10397
|
+
is_available: true,
|
|
10398
|
+
category_ids: categoryId ? [categoryId] : [],
|
|
10399
|
+
collection_ids: collectionId ? [collectionId] : [],
|
|
10400
|
+
add_on_ids: [],
|
|
10401
|
+
variant_ids: [],
|
|
10402
|
+
tags: input.tags ?? [],
|
|
10403
|
+
calories: input.calories,
|
|
10404
|
+
allergies: input.allergies ?? [],
|
|
10405
|
+
ingredients: input.ingredients ?? [],
|
|
10406
|
+
pairings: [],
|
|
10407
|
+
is_signature: input.isSignature ?? false,
|
|
10408
|
+
is_new: input.isNew ?? false,
|
|
10409
|
+
duration_minutes: input.durationMinutes,
|
|
10410
|
+
metadata: input.metadata,
|
|
10411
|
+
created_at: SEED_ISO,
|
|
10412
|
+
updated_at: SEED_ISO
|
|
10413
|
+
};
|
|
10414
|
+
registry.products.put(id, product);
|
|
10415
|
+
if (categoryId) {
|
|
10416
|
+
const cat = registry.categories.get(categoryId);
|
|
10417
|
+
if (cat && !cat.product_ids.includes(id)) cat.product_ids.push(id);
|
|
10418
|
+
}
|
|
10419
|
+
if (collectionId) {
|
|
10420
|
+
const col = registry.collections.get(collectionId);
|
|
10421
|
+
if (col && !col.product_ids.includes(id)) col.product_ids.push(id);
|
|
10422
|
+
}
|
|
10423
|
+
return product;
|
|
10424
|
+
},
|
|
10425
|
+
service(input) {
|
|
10426
|
+
const business = requireBusiness();
|
|
10427
|
+
const id = `${ID_PREFIX.service}${slugify(input.name)}`;
|
|
10428
|
+
const service = {
|
|
10429
|
+
id,
|
|
10430
|
+
business_id: business.id,
|
|
10431
|
+
name: input.name,
|
|
10432
|
+
description: input.description,
|
|
10433
|
+
duration_minutes: input.durationMinutes,
|
|
10434
|
+
price: input.price,
|
|
10435
|
+
is_available: true
|
|
10436
|
+
};
|
|
10437
|
+
registry.services.put(id, service);
|
|
10438
|
+
return service;
|
|
10439
|
+
},
|
|
10440
|
+
image: seedImage,
|
|
10441
|
+
extend(name) {
|
|
10442
|
+
const result = applySeed(registry, name);
|
|
10443
|
+
current = registry.businesses.get(result.businessId) ?? current;
|
|
10444
|
+
return result;
|
|
10445
|
+
}
|
|
10446
|
+
};
|
|
10447
|
+
}
|
|
10448
|
+
function defineSeed(seed) {
|
|
10449
|
+
return seed;
|
|
10450
|
+
}
|
|
10451
|
+
|
|
10452
|
+
// src/mock/seeds/source.ts
|
|
10453
|
+
var SNAPSHOT_META_KEY = "__meta";
|
|
10454
|
+
function loadSnapshot(registry, data, businessId) {
|
|
10455
|
+
applySnapshot(registry, data);
|
|
10456
|
+
if (businessId) return { businessId };
|
|
10457
|
+
const meta = data[SNAPSHOT_META_KEY];
|
|
10458
|
+
if (meta?.defaultBusinessId) return { businessId: meta.defaultBusinessId };
|
|
10459
|
+
const businesses = registry.businesses.list();
|
|
10460
|
+
if (businesses.length === 1) return { businessId: businesses[0].id };
|
|
10461
|
+
if (businesses.length === 0) {
|
|
10462
|
+
throw new Error("Seed snapshot has no business. Add one, or set __meta.defaultBusinessId.");
|
|
10463
|
+
}
|
|
10464
|
+
throw new Error(
|
|
10465
|
+
`Seed snapshot has ${businesses.length} businesses; set __meta.defaultBusinessId to pick one.`
|
|
10466
|
+
);
|
|
10467
|
+
}
|
|
10468
|
+
function resolveSeed(registry, source) {
|
|
10469
|
+
if (typeof source === "string") return applySeed(registry, source);
|
|
10470
|
+
switch (source.kind) {
|
|
10471
|
+
case "builtin":
|
|
10472
|
+
return applySeed(registry, source.name);
|
|
10473
|
+
case "json":
|
|
10474
|
+
return loadSnapshot(registry, source.data, source.businessId);
|
|
10475
|
+
case "fn":
|
|
10476
|
+
return source.seed(makeSeedContext(registry));
|
|
10477
|
+
}
|
|
10478
|
+
}
|
|
10479
|
+
|
|
10269
10480
|
// src/mock/deps.ts
|
|
10270
10481
|
function createDeps(options = {}) {
|
|
10271
10482
|
const clock = createClock({ frozenAt: options.frozenAt });
|
|
10272
10483
|
const ids = createIdGen(options.rngSeed);
|
|
10273
10484
|
const bus = createBus({ idGen: () => ids.raw("evt"), clock: () => clock.now() });
|
|
10274
10485
|
const registry = createStateRegistry();
|
|
10275
|
-
const
|
|
10276
|
-
|
|
10277
|
-
let defaultBusinessId = seedResult.businessId;
|
|
10486
|
+
const seedSource = options.seed ?? "default";
|
|
10487
|
+
let defaultBusinessId = resolveSeed(registry, seedSource).businessId;
|
|
10278
10488
|
const auth = createAuthService({
|
|
10279
10489
|
registry,
|
|
10280
10490
|
clock,
|
|
@@ -10328,11 +10538,10 @@ function createDeps(options = {}) {
|
|
|
10328
10538
|
return defaultBusinessId;
|
|
10329
10539
|
},
|
|
10330
10540
|
chaos,
|
|
10331
|
-
resetAll(
|
|
10541
|
+
resetAll(next) {
|
|
10332
10542
|
for (const store of Object.values(registry)) store.reset();
|
|
10333
10543
|
bus.clear();
|
|
10334
|
-
|
|
10335
|
-
defaultBusinessId = r.businessId;
|
|
10544
|
+
defaultBusinessId = resolveSeed(registry, next ?? seedSource).businessId;
|
|
10336
10545
|
return defaultBusinessId;
|
|
10337
10546
|
}
|
|
10338
10547
|
};
|
|
@@ -10435,4 +10644,4 @@ function setupWebhooks(bus, opts) {
|
|
|
10435
10644
|
});
|
|
10436
10645
|
}
|
|
10437
10646
|
|
|
10438
|
-
export { applySeed, createDeps, createMockApp, setupWebhooks, signPayload, verifySignature };
|
|
10647
|
+
export { SEED_ISO, SNAPSHOT_META_KEY, applySeed, applySnapshot, createDeps, createMockApp, defineSeed, loadSnapshot, makeSeedContext, resolveSeed, setupWebhooks, signPayload, slugify, verifySignature };
|