@cimplify/sdk 0.44.14 → 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.
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.d.ts +1 -1
- package/dist/advanced.js +22 -21
- package/dist/advanced.mjs +3 -2
- package/dist/{chunk-OMAP327U.js → chunk-3FS3ZDKX.js} +62 -61
- package/dist/chunk-53J2WE4S.js +657 -0
- package/dist/{chunk-3WD6U5RD.mjs → chunk-5OK3YDZC.mjs} +4 -3
- package/dist/{chunk-V2O5AO7I.js → chunk-BN2CXGMO.js} +5 -246
- package/dist/chunk-CCSONJCO.js +8824 -0
- package/dist/{chunk-BAWKQRIB.js → chunk-HBRCVJL4.js} +22 -21
- package/dist/chunk-MJBSVUHO.mjs +8822 -0
- package/dist/{chunk-6TVQQYQ5.mjs → chunk-NRT6PVW5.mjs} +4 -231
- package/dist/chunk-QBQCMQ4F.js +271 -0
- package/dist/chunk-VDH3O7UB.mjs +604 -0
- package/dist/chunk-XPXAZXF2.mjs +250 -0
- package/dist/{chunk-EZK2FXTM.mjs → chunk-XZPO5GEM.mjs} +2 -1
- package/dist/cli/commands/deploy.mjs +9 -1
- package/dist/client-B_Ei3ENB.d.mts +86 -0
- package/dist/client-Bep2FooI.d.ts +86 -0
- package/dist/{client-lvLvB1_K.d.ts → client-D6ZisKco.d.ts} +7 -0
- package/dist/{client-CkGlXZRd.d.mts → client-Dh-bHyhU.d.mts} +7 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +145 -144
- package/dist/index.mjs +4 -3
- package/dist/mock/cli.mjs +2 -1
- package/dist/mock/library.js +2 -1
- package/dist/mock/library.mjs +2 -1
- package/dist/mock/msw.js +2 -1
- package/dist/mock/msw.mjs +2 -1
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +81 -80
- package/dist/react.mjs +4 -3
- package/dist/server-CWpUlLOQ.d.mts +1003 -0
- package/dist/server-CWpUlLOQ.d.ts +1003 -0
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +6 -5
- package/dist/server.mjs +4 -3
- package/dist/testing/msw.d.mts +17 -0
- package/dist/testing/msw.d.ts +17 -0
- package/dist/testing/msw.js +42 -0
- package/dist/testing/msw.mjs +40 -0
- package/dist/testing/suite.d.mts +85 -0
- package/dist/testing/suite.d.ts +85 -0
- package/dist/testing/suite.js +174 -0
- package/dist/testing/suite.mjs +170 -0
- package/dist/testing.d.mts +1885 -0
- package/dist/testing.d.ts +1885 -0
- package/dist/testing.js +261 -0
- package/dist/testing.mjs +51 -0
- package/dist/utils.js +29 -28
- package/dist/utils.mjs +2 -1
- package/package.json +28 -4
- package/templates/storefront-bakery/__tests__/brand.test.ts +4 -0
- package/templates/storefront-bakery/__tests__/cart-flow.test.ts +4 -0
- package/templates/storefront-bakery/__tests__/contract.test.ts +4 -0
- package/templates/storefront-bakery/package.json +11 -3
- package/templates/storefront-bakery/vitest.config.ts +9 -0
- package/templates/storefront-fashion/__tests__/brand.test.ts +4 -0
- package/templates/storefront-fashion/__tests__/cart-flow.test.ts +4 -0
- package/templates/storefront-fashion/__tests__/contract.test.ts +4 -0
- package/templates/storefront-fashion/package.json +11 -3
- package/templates/storefront-fashion/vitest.config.ts +9 -0
- package/templates/storefront-grocery/__tests__/brand.test.ts +4 -0
- package/templates/storefront-grocery/__tests__/cart-flow.test.ts +4 -0
- package/templates/storefront-grocery/__tests__/contract.test.ts +4 -0
- package/templates/storefront-grocery/package.json +11 -3
- package/templates/storefront-grocery/vitest.config.ts +9 -0
- package/templates/storefront-restaurant/__tests__/brand.test.ts +4 -0
- package/templates/storefront-restaurant/__tests__/cart-flow.test.ts +4 -0
- package/templates/storefront-restaurant/__tests__/contract.test.ts +4 -0
- package/templates/storefront-restaurant/package.json +11 -3
- package/templates/storefront-restaurant/vitest.config.ts +9 -0
- package/templates/storefront-retail/__tests__/brand.test.ts +4 -0
- package/templates/storefront-retail/__tests__/cart-flow.test.ts +4 -0
- package/templates/storefront-retail/__tests__/contract.test.ts +4 -0
- package/templates/storefront-retail/package.json +11 -3
- package/templates/storefront-retail/vitest.config.ts +9 -0
- package/templates/storefront-services/__tests__/brand.test.ts +4 -0
- package/templates/storefront-services/__tests__/cart-flow.test.ts +4 -0
- package/templates/storefront-services/__tests__/contract.test.ts +4 -0
- package/templates/storefront-services/package.json +11 -3
- package/templates/storefront-services/vitest.config.ts +9 -0
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
import { assertBrand, SeedNameSchema, BrandSchema, createTestClient, assertCart, fixtures, AddItemPayloadSchema, CartItemSchema, CheckoutResponseSchema } from '../chunk-VDH3O7UB.mjs';
|
|
2
|
+
import '../chunk-5OK3YDZC.mjs';
|
|
3
|
+
import '../chunk-XZPO5GEM.mjs';
|
|
4
|
+
import '../chunk-NRT6PVW5.mjs';
|
|
5
|
+
import '../chunk-MJBSVUHO.mjs';
|
|
6
|
+
import '../chunk-XPXAZXF2.mjs';
|
|
7
|
+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
8
|
+
|
|
9
|
+
var PLACEHOLDER_PHRASES = [
|
|
10
|
+
"lorem ipsum",
|
|
11
|
+
"todo",
|
|
12
|
+
"fixme",
|
|
13
|
+
"placeholder",
|
|
14
|
+
"your business name",
|
|
15
|
+
"your store"
|
|
16
|
+
];
|
|
17
|
+
function createBrandSuite(opts) {
|
|
18
|
+
describe(opts.label ?? "brand schema", () => {
|
|
19
|
+
it("conforms to the Cimplify brand contract", () => {
|
|
20
|
+
expect(() => assertBrand(opts.brand)).not.toThrow();
|
|
21
|
+
});
|
|
22
|
+
it("declares a known mock seed", () => {
|
|
23
|
+
const b = opts.brand;
|
|
24
|
+
expect(SeedNameSchema.safeParse(b.mock?.seed).success).toBe(true);
|
|
25
|
+
});
|
|
26
|
+
it("has no placeholder copy left in", () => {
|
|
27
|
+
const flat = JSON.stringify(opts.brand).toLowerCase();
|
|
28
|
+
for (const phrase of PLACEHOLDER_PHRASES) {
|
|
29
|
+
expect(flat, `brand contains placeholder phrase "${phrase}"`).not.toContain(phrase);
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
it("uses the bus_ businessId convention", () => {
|
|
33
|
+
const b = opts.brand;
|
|
34
|
+
expect(b.mock?.businessId).toMatch(/^bus_/);
|
|
35
|
+
});
|
|
36
|
+
it("zod-parses cleanly", () => {
|
|
37
|
+
const result = BrandSchema.safeParse(opts.brand);
|
|
38
|
+
if (!result.success) {
|
|
39
|
+
throw new Error(
|
|
40
|
+
"Brand schema violations:\n" + result.error.issues.map((i) => ` \u2022 brand.${i.path.join(".")}: ${i.message}`).join("\n")
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
expect(result.success).toBe(true);
|
|
44
|
+
});
|
|
45
|
+
opts.extend?.(it);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function createCartFlowSuite(opts = {}) {
|
|
49
|
+
describe(opts.label ?? "cart flow against in-process mock", () => {
|
|
50
|
+
let h;
|
|
51
|
+
beforeEach(() => {
|
|
52
|
+
h = createTestClient(opts);
|
|
53
|
+
});
|
|
54
|
+
afterEach(() => h.dispose());
|
|
55
|
+
it("starts with an empty cart matching the canonical shape", async () => {
|
|
56
|
+
const res = await h.client.cart.get();
|
|
57
|
+
expect(res.ok).toBe(true);
|
|
58
|
+
if (!res.ok) return;
|
|
59
|
+
expect(() => assertCart(res.value)).not.toThrow();
|
|
60
|
+
expect(res.value.items).toHaveLength(0);
|
|
61
|
+
});
|
|
62
|
+
it("adds the first product, persists it, and returns a shape-valid cart", async () => {
|
|
63
|
+
const { product, variantId } = await fixtures.addFirstProduct(h.client);
|
|
64
|
+
expect(product.id).toBeTruthy();
|
|
65
|
+
const get = await h.client.cart.get();
|
|
66
|
+
expect(get.ok).toBe(true);
|
|
67
|
+
if (!get.ok) return;
|
|
68
|
+
expect(() => assertCart(get.value)).not.toThrow();
|
|
69
|
+
expect(get.value.items).toHaveLength(1);
|
|
70
|
+
expect(get.value.items[0]?.item_id).toBe(product.id);
|
|
71
|
+
if (variantId) {
|
|
72
|
+
expect(get.value.items[0]?.variant_id).toBe(variantId);
|
|
73
|
+
const variantInfo = get.value.items[0]?.variant_info;
|
|
74
|
+
expect(variantInfo?.display_attributes).toBeDefined();
|
|
75
|
+
}
|
|
76
|
+
expect(parseFloat(String(get.value.pricing.subtotal))).toBeGreaterThan(0);
|
|
77
|
+
});
|
|
78
|
+
it("dedupes by line_key when adding the same product twice", async () => {
|
|
79
|
+
await fixtures.addFirstProduct(h.client);
|
|
80
|
+
await fixtures.addFirstProduct(h.client);
|
|
81
|
+
const res = await h.client.cart.get();
|
|
82
|
+
expect(res.ok).toBe(true);
|
|
83
|
+
if (!res.ok) return;
|
|
84
|
+
expect(res.value.items).toHaveLength(1);
|
|
85
|
+
expect(res.value.items[0]?.quantity).toBe(2);
|
|
86
|
+
});
|
|
87
|
+
it("removes items and zeroes the subtotal", async () => {
|
|
88
|
+
await fixtures.addFirstProduct(h.client);
|
|
89
|
+
const before = await h.client.cart.get();
|
|
90
|
+
if (!before.ok) throw before.error;
|
|
91
|
+
const itemId = before.value.items[0]?.id;
|
|
92
|
+
expect(itemId).toBeTruthy();
|
|
93
|
+
const removed = await h.client.cart.removeItem(itemId);
|
|
94
|
+
expect(removed.ok).toBe(true);
|
|
95
|
+
const after = await h.client.cart.get();
|
|
96
|
+
if (!after.ok) throw after.error;
|
|
97
|
+
expect(after.value.items).toHaveLength(0);
|
|
98
|
+
expect(parseFloat(String(after.value.pricing.subtotal))).toBe(0);
|
|
99
|
+
});
|
|
100
|
+
if (opts.businessId) {
|
|
101
|
+
it("returns the brand's businessId on cart responses", async () => {
|
|
102
|
+
const res = await h.client.cart.get();
|
|
103
|
+
if (!res.ok) throw res.error;
|
|
104
|
+
expect(res.value.business_id).toBe(opts.businessId);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
opts.extend?.({ getHandle: () => h, it });
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function createContractSuite(opts = {}) {
|
|
111
|
+
describe(opts.label ?? "SDK \u2194 mock contract", () => {
|
|
112
|
+
let h;
|
|
113
|
+
beforeEach(() => {
|
|
114
|
+
h = createTestClient(opts);
|
|
115
|
+
});
|
|
116
|
+
afterEach(() => h.dispose());
|
|
117
|
+
it("AddItemPayload schema accepts a minimal valid body", () => {
|
|
118
|
+
const result = AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: 1 });
|
|
119
|
+
expect(result.success).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
it("AddItemPayload schema rejects negative quantity", () => {
|
|
122
|
+
const result = AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: -1 });
|
|
123
|
+
expect(result.success).toBe(false);
|
|
124
|
+
});
|
|
125
|
+
it("AddItemPayload schema rejects empty item_id", () => {
|
|
126
|
+
const result = AddItemPayloadSchema.safeParse({ item_id: "", quantity: 1 });
|
|
127
|
+
expect(result.success).toBe(false);
|
|
128
|
+
});
|
|
129
|
+
it("Cart line items returned by the mock match CartItemSchema", async () => {
|
|
130
|
+
const { product } = await fixtures.addFirstProduct(h.client);
|
|
131
|
+
const get = await h.client.cart.get();
|
|
132
|
+
if (!get.ok) throw get.error;
|
|
133
|
+
expect(get.value.items.length).toBeGreaterThan(0);
|
|
134
|
+
for (const item of get.value.items) {
|
|
135
|
+
const result = CartItemSchema.safeParse(item);
|
|
136
|
+
if (!result.success) {
|
|
137
|
+
const issues = result.error.issues.map((i) => ` \u2022 ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
138
|
+
throw new Error(`Cart item shape mismatch for ${product.name}:
|
|
139
|
+
${issues}`);
|
|
140
|
+
}
|
|
141
|
+
expect(result.success).toBe(true);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
it("CheckoutResponse from the mock includes bill_token", async () => {
|
|
145
|
+
await fixtures.addFirstProduct(h.client);
|
|
146
|
+
const cartRes = await h.client.cart.get();
|
|
147
|
+
if (!cartRes.ok) throw cartRes.error;
|
|
148
|
+
const checkout = await h.client.checkout.process({
|
|
149
|
+
cart_id: cartRes.value.id,
|
|
150
|
+
customer: fixtures.customer(),
|
|
151
|
+
order_type: "delivery",
|
|
152
|
+
payment_method: "mobile_money",
|
|
153
|
+
mobile_money_details: { phone_number: "+233244000000", provider: "mtn" }
|
|
154
|
+
});
|
|
155
|
+
expect(checkout.ok).toBe(true);
|
|
156
|
+
if (!checkout.ok) return;
|
|
157
|
+
const result = CheckoutResponseSchema.safeParse(checkout.value);
|
|
158
|
+
if (!result.success) {
|
|
159
|
+
const issues = result.error.issues.map((i) => ` \u2022 ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
160
|
+
throw new Error(`CheckoutResponse shape mismatch:
|
|
161
|
+
${issues}`);
|
|
162
|
+
}
|
|
163
|
+
expect(checkout.value.bill_token).toBeTruthy();
|
|
164
|
+
expect(checkout.value.order_id).toBeTruthy();
|
|
165
|
+
});
|
|
166
|
+
opts.extend?.({ getHandle: () => h, it });
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export { createBrandSuite, createCartFlowSuite, createContractSuite };
|