@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
package/dist/server.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CimplifyClient } from './client-
|
|
2
|
-
export { aN as Result } from './client-
|
|
1
|
+
import { C as CimplifyClient } from './client-Dh-bHyhU.mjs';
|
|
2
|
+
export { aN as Result } from './client-Dh-bHyhU.mjs';
|
|
3
3
|
export { am as Category, h as CimplifyError, ao as Collection, U as Product, a7 as ProductWithDetails } from './payment-DA1i5hhk.mjs';
|
|
4
4
|
|
|
5
5
|
interface ServerClientOptions {
|
package/dist/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CimplifyClient } from './client-
|
|
2
|
-
export { aN as Result } from './client-
|
|
1
|
+
import { C as CimplifyClient } from './client-D6ZisKco.js';
|
|
2
|
+
export { aN as Result } from './client-D6ZisKco.js';
|
|
3
3
|
export { am as Category, h as CimplifyError, ao as Collection, U as Product, a7 as ProductWithDetails } from './payment-DA1i5hhk.js';
|
|
4
4
|
|
|
5
5
|
interface ServerClientOptions {
|
package/dist/server.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
5
|
-
|
|
3
|
+
var chunk3FS3ZDKX_js = require('./chunk-3FS3ZDKX.js');
|
|
4
|
+
require('./chunk-HBRCVJL4.js');
|
|
5
|
+
require('./chunk-BN2CXGMO.js');
|
|
6
|
+
var chunkQBQCMQ4F_js = require('./chunk-QBQCMQ4F.js');
|
|
6
7
|
var react = require('react');
|
|
7
8
|
|
|
8
9
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
@@ -18,7 +19,7 @@ function readEnv(...keys) {
|
|
|
18
19
|
var getServerClient = react.cache((opts = {}) => {
|
|
19
20
|
const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ?? DEFAULT_DEV_URL;
|
|
20
21
|
const publicKey = opts.secretKey ?? readEnv("CIMPLIFY_SECRET_KEY", "NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY") ?? "mock-dev";
|
|
21
|
-
const client =
|
|
22
|
+
const client = chunk3FS3ZDKX_js.createCimplifyClient({
|
|
22
23
|
baseUrl,
|
|
23
24
|
publicKey,
|
|
24
25
|
suppressPublicKeyWarning: true
|
|
@@ -93,7 +94,7 @@ async function revalidateByTag(tag) {
|
|
|
93
94
|
|
|
94
95
|
Object.defineProperty(exports, "CimplifyError", {
|
|
95
96
|
enumerable: true,
|
|
96
|
-
get: function () { return
|
|
97
|
+
get: function () { return chunkQBQCMQ4F_js.CimplifyError; }
|
|
97
98
|
});
|
|
98
99
|
exports.getServerClient = getServerClient;
|
|
99
100
|
exports.revalidateBusiness = revalidateBusiness;
|
package/dist/server.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { createCimplifyClient } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
|
|
1
|
+
import { createCimplifyClient } from './chunk-5OK3YDZC.mjs';
|
|
2
|
+
import './chunk-XZPO5GEM.mjs';
|
|
3
|
+
import './chunk-NRT6PVW5.mjs';
|
|
4
|
+
export { CimplifyError } from './chunk-XPXAZXF2.mjs';
|
|
4
5
|
import { cache } from 'react';
|
|
5
6
|
|
|
6
7
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { A as AppHandle, C as CreateAppOptions } from '../server-CWpUlLOQ.mjs';
|
|
2
|
+
import 'hono';
|
|
3
|
+
|
|
4
|
+
interface MswHandlerSetup {
|
|
5
|
+
handlers: unknown[];
|
|
6
|
+
deps: AppHandle["deps"];
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
reset: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface MswAdapterOptions extends CreateAppOptions {
|
|
12
|
+
/** Override the base URL handlers register against. Default `http://localhost:8787`. */
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function createMswHandlers(options?: MswAdapterOptions): Promise<MswHandlerSetup>;
|
|
16
|
+
|
|
17
|
+
export { type MswAdapterOptions, createMswHandlers };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { A as AppHandle, C as CreateAppOptions } from '../server-CWpUlLOQ.js';
|
|
2
|
+
import 'hono';
|
|
3
|
+
|
|
4
|
+
interface MswHandlerSetup {
|
|
5
|
+
handlers: unknown[];
|
|
6
|
+
deps: AppHandle["deps"];
|
|
7
|
+
baseUrl: string;
|
|
8
|
+
reset: () => void;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface MswAdapterOptions extends CreateAppOptions {
|
|
12
|
+
/** Override the base URL handlers register against. Default `http://localhost:8787`. */
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function createMswHandlers(options?: MswAdapterOptions): Promise<MswHandlerSetup>;
|
|
16
|
+
|
|
17
|
+
export { type MswAdapterOptions, createMswHandlers };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkCCSONJCO_js = require('../chunk-CCSONJCO.js');
|
|
4
|
+
require('../chunk-QBQCMQ4F.js');
|
|
5
|
+
|
|
6
|
+
// src/mock/msw.ts
|
|
7
|
+
async function createMswHandlers(options = {}) {
|
|
8
|
+
const baseUrl = options.baseUrl ?? "http://localhost:8787";
|
|
9
|
+
const handle = chunkCCSONJCO_js.createMockApp(options);
|
|
10
|
+
const msw = await import('msw').catch(() => {
|
|
11
|
+
throw new Error("msw is required to use @cimplify/sdk/mock/msw \u2014 install it as a peer dependency");
|
|
12
|
+
});
|
|
13
|
+
const proxy = async ({ request }) => {
|
|
14
|
+
const url = new URL(request.url);
|
|
15
|
+
const path = url.pathname + url.search;
|
|
16
|
+
const init = {
|
|
17
|
+
method: request.method,
|
|
18
|
+
headers: request.headers,
|
|
19
|
+
body: ["GET", "HEAD"].includes(request.method) ? void 0 : await request.text()
|
|
20
|
+
};
|
|
21
|
+
return handle.request(path, init);
|
|
22
|
+
};
|
|
23
|
+
const apiBase = baseUrl.replace(/\/$/, "");
|
|
24
|
+
const handlers = [
|
|
25
|
+
msw.http.all(`${apiBase}/api/v1/*`, proxy),
|
|
26
|
+
msw.http.all(`${apiBase}/_mock/*`, proxy),
|
|
27
|
+
msw.http.get(`${apiBase}/healthz`, proxy)
|
|
28
|
+
];
|
|
29
|
+
return {
|
|
30
|
+
handlers,
|
|
31
|
+
deps: handle.deps,
|
|
32
|
+
baseUrl,
|
|
33
|
+
reset: () => handle.deps.resetAll()
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// src/testing/msw-adapter.ts
|
|
38
|
+
async function createMswHandlers2(options = {}) {
|
|
39
|
+
return createMswHandlers(options);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
exports.createMswHandlers = createMswHandlers2;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createMockApp } from '../chunk-MJBSVUHO.mjs';
|
|
2
|
+
import '../chunk-XPXAZXF2.mjs';
|
|
3
|
+
|
|
4
|
+
// src/mock/msw.ts
|
|
5
|
+
async function createMswHandlers(options = {}) {
|
|
6
|
+
const baseUrl = options.baseUrl ?? "http://localhost:8787";
|
|
7
|
+
const handle = createMockApp(options);
|
|
8
|
+
const msw = await import('msw').catch(() => {
|
|
9
|
+
throw new Error("msw is required to use @cimplify/sdk/mock/msw \u2014 install it as a peer dependency");
|
|
10
|
+
});
|
|
11
|
+
const proxy = async ({ request }) => {
|
|
12
|
+
const url = new URL(request.url);
|
|
13
|
+
const path = url.pathname + url.search;
|
|
14
|
+
const init = {
|
|
15
|
+
method: request.method,
|
|
16
|
+
headers: request.headers,
|
|
17
|
+
body: ["GET", "HEAD"].includes(request.method) ? void 0 : await request.text()
|
|
18
|
+
};
|
|
19
|
+
return handle.request(path, init);
|
|
20
|
+
};
|
|
21
|
+
const apiBase = baseUrl.replace(/\/$/, "");
|
|
22
|
+
const handlers = [
|
|
23
|
+
msw.http.all(`${apiBase}/api/v1/*`, proxy),
|
|
24
|
+
msw.http.all(`${apiBase}/_mock/*`, proxy),
|
|
25
|
+
msw.http.get(`${apiBase}/healthz`, proxy)
|
|
26
|
+
];
|
|
27
|
+
return {
|
|
28
|
+
handlers,
|
|
29
|
+
deps: handle.deps,
|
|
30
|
+
baseUrl,
|
|
31
|
+
reset: () => handle.deps.resetAll()
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/testing/msw-adapter.ts
|
|
36
|
+
async function createMswHandlers2(options = {}) {
|
|
37
|
+
return createMswHandlers(options);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { createMswHandlers2 as createMswHandlers };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { TestAPI } from 'vitest';
|
|
2
|
+
import { T as TestClientHandle } from '../client-B_Ei3ENB.mjs';
|
|
3
|
+
import { C as CreateAppOptions } from '../server-CWpUlLOQ.mjs';
|
|
4
|
+
import '../client-Dh-bHyhU.mjs';
|
|
5
|
+
import '../payment-DA1i5hhk.mjs';
|
|
6
|
+
import 'hono';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Pre-baked test suites for scaffolded storefronts.
|
|
10
|
+
*
|
|
11
|
+
* Templates' `__tests__/*.test.ts` files are now ~5 lines each — they
|
|
12
|
+
* import their `brand` and call `createBrandSuite` / `createCartFlowSuite`
|
|
13
|
+
* / `createContractSuite`. One bug fix in this file → every template
|
|
14
|
+
* picks it up on `bun update @cimplify/sdk`.
|
|
15
|
+
*
|
|
16
|
+
* // __tests__/brand.test.ts in any template:
|
|
17
|
+
* import { createBrandSuite } from "@cimplify/sdk/testing/suite";
|
|
18
|
+
* import { brand } from "../lib/brand";
|
|
19
|
+
* createBrandSuite({ brand });
|
|
20
|
+
*
|
|
21
|
+
* // __tests__/cart-flow.test.ts:
|
|
22
|
+
* import { createCartFlowSuite } from "@cimplify/sdk/testing/suite";
|
|
23
|
+
* import { brand } from "../lib/brand";
|
|
24
|
+
* createCartFlowSuite({ seed: brand.mock.seed, businessId: brand.mock.businessId });
|
|
25
|
+
*
|
|
26
|
+
* // __tests__/contract.test.ts:
|
|
27
|
+
* import { createContractSuite } from "@cimplify/sdk/testing/suite";
|
|
28
|
+
* import { brand } from "../lib/brand";
|
|
29
|
+
* createContractSuite({ seed: brand.mock.seed });
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Brand sanity suite. Catches: missing required fields, placeholder
|
|
34
|
+
* strings shipped to prod, invalid email/url/locale/currency formats,
|
|
35
|
+
* mismatched seed/businessId pairing.
|
|
36
|
+
*
|
|
37
|
+
* Pass `extend` to append custom cases inside the same describe block:
|
|
38
|
+
*
|
|
39
|
+
* createBrandSuite({
|
|
40
|
+
* brand,
|
|
41
|
+
* extend: (it) => {
|
|
42
|
+
* it("uses our merchant's currency", () => {
|
|
43
|
+
* expect(brand.currency).toBe("GHS");
|
|
44
|
+
* });
|
|
45
|
+
* },
|
|
46
|
+
* });
|
|
47
|
+
*/
|
|
48
|
+
declare function createBrandSuite(opts: {
|
|
49
|
+
brand: unknown;
|
|
50
|
+
label?: string;
|
|
51
|
+
extend?: (it: TestAPI) => void;
|
|
52
|
+
}): void;
|
|
53
|
+
interface CartFlowOptions extends CreateAppOptions {
|
|
54
|
+
/** Expected business ID — asserts cart responses match the merchant. */
|
|
55
|
+
businessId?: string;
|
|
56
|
+
/** Override the describe() label. */
|
|
57
|
+
label?: string;
|
|
58
|
+
/** Append custom cases inside the same describe block. Receives a `TestClientHandle` getter. */
|
|
59
|
+
extend?: (ctx: {
|
|
60
|
+
getHandle: () => TestClientHandle;
|
|
61
|
+
it: TestAPI;
|
|
62
|
+
}) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Cart flow suite. Boots the in-process mock, exercises add/dedupe/remove
|
|
66
|
+
* with shape assertions on every response. Catches: SDK ↔ mock contract
|
|
67
|
+
* drift, missing fields on cart items, add-to-cart not persisting,
|
|
68
|
+
* variant/payload silently dropped.
|
|
69
|
+
*/
|
|
70
|
+
declare function createCartFlowSuite(opts?: CartFlowOptions): void;
|
|
71
|
+
interface ContractOptions extends CreateAppOptions {
|
|
72
|
+
label?: string;
|
|
73
|
+
extend?: (ctx: {
|
|
74
|
+
getHandle: () => TestClientHandle;
|
|
75
|
+
it: TestAPI;
|
|
76
|
+
}) => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Shape contract suite. Exercises the schemas against actual mock
|
|
80
|
+
* traffic. Catches: outbound payloads dropping required fields,
|
|
81
|
+
* inbound responses missing fields the storefront depends on.
|
|
82
|
+
*/
|
|
83
|
+
declare function createContractSuite(opts?: ContractOptions): void;
|
|
84
|
+
|
|
85
|
+
export { createBrandSuite, createCartFlowSuite, createContractSuite };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { TestAPI } from 'vitest';
|
|
2
|
+
import { T as TestClientHandle } from '../client-Bep2FooI.js';
|
|
3
|
+
import { C as CreateAppOptions } from '../server-CWpUlLOQ.js';
|
|
4
|
+
import '../client-D6ZisKco.js';
|
|
5
|
+
import '../payment-DA1i5hhk.js';
|
|
6
|
+
import 'hono';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Pre-baked test suites for scaffolded storefronts.
|
|
10
|
+
*
|
|
11
|
+
* Templates' `__tests__/*.test.ts` files are now ~5 lines each — they
|
|
12
|
+
* import their `brand` and call `createBrandSuite` / `createCartFlowSuite`
|
|
13
|
+
* / `createContractSuite`. One bug fix in this file → every template
|
|
14
|
+
* picks it up on `bun update @cimplify/sdk`.
|
|
15
|
+
*
|
|
16
|
+
* // __tests__/brand.test.ts in any template:
|
|
17
|
+
* import { createBrandSuite } from "@cimplify/sdk/testing/suite";
|
|
18
|
+
* import { brand } from "../lib/brand";
|
|
19
|
+
* createBrandSuite({ brand });
|
|
20
|
+
*
|
|
21
|
+
* // __tests__/cart-flow.test.ts:
|
|
22
|
+
* import { createCartFlowSuite } from "@cimplify/sdk/testing/suite";
|
|
23
|
+
* import { brand } from "../lib/brand";
|
|
24
|
+
* createCartFlowSuite({ seed: brand.mock.seed, businessId: brand.mock.businessId });
|
|
25
|
+
*
|
|
26
|
+
* // __tests__/contract.test.ts:
|
|
27
|
+
* import { createContractSuite } from "@cimplify/sdk/testing/suite";
|
|
28
|
+
* import { brand } from "../lib/brand";
|
|
29
|
+
* createContractSuite({ seed: brand.mock.seed });
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Brand sanity suite. Catches: missing required fields, placeholder
|
|
34
|
+
* strings shipped to prod, invalid email/url/locale/currency formats,
|
|
35
|
+
* mismatched seed/businessId pairing.
|
|
36
|
+
*
|
|
37
|
+
* Pass `extend` to append custom cases inside the same describe block:
|
|
38
|
+
*
|
|
39
|
+
* createBrandSuite({
|
|
40
|
+
* brand,
|
|
41
|
+
* extend: (it) => {
|
|
42
|
+
* it("uses our merchant's currency", () => {
|
|
43
|
+
* expect(brand.currency).toBe("GHS");
|
|
44
|
+
* });
|
|
45
|
+
* },
|
|
46
|
+
* });
|
|
47
|
+
*/
|
|
48
|
+
declare function createBrandSuite(opts: {
|
|
49
|
+
brand: unknown;
|
|
50
|
+
label?: string;
|
|
51
|
+
extend?: (it: TestAPI) => void;
|
|
52
|
+
}): void;
|
|
53
|
+
interface CartFlowOptions extends CreateAppOptions {
|
|
54
|
+
/** Expected business ID — asserts cart responses match the merchant. */
|
|
55
|
+
businessId?: string;
|
|
56
|
+
/** Override the describe() label. */
|
|
57
|
+
label?: string;
|
|
58
|
+
/** Append custom cases inside the same describe block. Receives a `TestClientHandle` getter. */
|
|
59
|
+
extend?: (ctx: {
|
|
60
|
+
getHandle: () => TestClientHandle;
|
|
61
|
+
it: TestAPI;
|
|
62
|
+
}) => void;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Cart flow suite. Boots the in-process mock, exercises add/dedupe/remove
|
|
66
|
+
* with shape assertions on every response. Catches: SDK ↔ mock contract
|
|
67
|
+
* drift, missing fields on cart items, add-to-cart not persisting,
|
|
68
|
+
* variant/payload silently dropped.
|
|
69
|
+
*/
|
|
70
|
+
declare function createCartFlowSuite(opts?: CartFlowOptions): void;
|
|
71
|
+
interface ContractOptions extends CreateAppOptions {
|
|
72
|
+
label?: string;
|
|
73
|
+
extend?: (ctx: {
|
|
74
|
+
getHandle: () => TestClientHandle;
|
|
75
|
+
it: TestAPI;
|
|
76
|
+
}) => void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Shape contract suite. Exercises the schemas against actual mock
|
|
80
|
+
* traffic. Catches: outbound payloads dropping required fields,
|
|
81
|
+
* inbound responses missing fields the storefront depends on.
|
|
82
|
+
*/
|
|
83
|
+
declare function createContractSuite(opts?: ContractOptions): void;
|
|
84
|
+
|
|
85
|
+
export { createBrandSuite, createCartFlowSuite, createContractSuite };
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunk53J2WE4S_js = require('../chunk-53J2WE4S.js');
|
|
4
|
+
require('../chunk-3FS3ZDKX.js');
|
|
5
|
+
require('../chunk-HBRCVJL4.js');
|
|
6
|
+
require('../chunk-BN2CXGMO.js');
|
|
7
|
+
require('../chunk-CCSONJCO.js');
|
|
8
|
+
require('../chunk-QBQCMQ4F.js');
|
|
9
|
+
var vitest = require('vitest');
|
|
10
|
+
|
|
11
|
+
var PLACEHOLDER_PHRASES = [
|
|
12
|
+
"lorem ipsum",
|
|
13
|
+
"todo",
|
|
14
|
+
"fixme",
|
|
15
|
+
"placeholder",
|
|
16
|
+
"your business name",
|
|
17
|
+
"your store"
|
|
18
|
+
];
|
|
19
|
+
function createBrandSuite(opts) {
|
|
20
|
+
vitest.describe(opts.label ?? "brand schema", () => {
|
|
21
|
+
vitest.it("conforms to the Cimplify brand contract", () => {
|
|
22
|
+
vitest.expect(() => chunk53J2WE4S_js.assertBrand(opts.brand)).not.toThrow();
|
|
23
|
+
});
|
|
24
|
+
vitest.it("declares a known mock seed", () => {
|
|
25
|
+
const b = opts.brand;
|
|
26
|
+
vitest.expect(chunk53J2WE4S_js.SeedNameSchema.safeParse(b.mock?.seed).success).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
vitest.it("has no placeholder copy left in", () => {
|
|
29
|
+
const flat = JSON.stringify(opts.brand).toLowerCase();
|
|
30
|
+
for (const phrase of PLACEHOLDER_PHRASES) {
|
|
31
|
+
vitest.expect(flat, `brand contains placeholder phrase "${phrase}"`).not.toContain(phrase);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
vitest.it("uses the bus_ businessId convention", () => {
|
|
35
|
+
const b = opts.brand;
|
|
36
|
+
vitest.expect(b.mock?.businessId).toMatch(/^bus_/);
|
|
37
|
+
});
|
|
38
|
+
vitest.it("zod-parses cleanly", () => {
|
|
39
|
+
const result = chunk53J2WE4S_js.BrandSchema.safeParse(opts.brand);
|
|
40
|
+
if (!result.success) {
|
|
41
|
+
throw new Error(
|
|
42
|
+
"Brand schema violations:\n" + result.error.issues.map((i) => ` \u2022 brand.${i.path.join(".")}: ${i.message}`).join("\n")
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
vitest.expect(result.success).toBe(true);
|
|
46
|
+
});
|
|
47
|
+
opts.extend?.(vitest.it);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
function createCartFlowSuite(opts = {}) {
|
|
51
|
+
vitest.describe(opts.label ?? "cart flow against in-process mock", () => {
|
|
52
|
+
let h;
|
|
53
|
+
vitest.beforeEach(() => {
|
|
54
|
+
h = chunk53J2WE4S_js.createTestClient(opts);
|
|
55
|
+
});
|
|
56
|
+
vitest.afterEach(() => h.dispose());
|
|
57
|
+
vitest.it("starts with an empty cart matching the canonical shape", async () => {
|
|
58
|
+
const res = await h.client.cart.get();
|
|
59
|
+
vitest.expect(res.ok).toBe(true);
|
|
60
|
+
if (!res.ok) return;
|
|
61
|
+
vitest.expect(() => chunk53J2WE4S_js.assertCart(res.value)).not.toThrow();
|
|
62
|
+
vitest.expect(res.value.items).toHaveLength(0);
|
|
63
|
+
});
|
|
64
|
+
vitest.it("adds the first product, persists it, and returns a shape-valid cart", async () => {
|
|
65
|
+
const { product, variantId } = await chunk53J2WE4S_js.fixtures.addFirstProduct(h.client);
|
|
66
|
+
vitest.expect(product.id).toBeTruthy();
|
|
67
|
+
const get = await h.client.cart.get();
|
|
68
|
+
vitest.expect(get.ok).toBe(true);
|
|
69
|
+
if (!get.ok) return;
|
|
70
|
+
vitest.expect(() => chunk53J2WE4S_js.assertCart(get.value)).not.toThrow();
|
|
71
|
+
vitest.expect(get.value.items).toHaveLength(1);
|
|
72
|
+
vitest.expect(get.value.items[0]?.item_id).toBe(product.id);
|
|
73
|
+
if (variantId) {
|
|
74
|
+
vitest.expect(get.value.items[0]?.variant_id).toBe(variantId);
|
|
75
|
+
const variantInfo = get.value.items[0]?.variant_info;
|
|
76
|
+
vitest.expect(variantInfo?.display_attributes).toBeDefined();
|
|
77
|
+
}
|
|
78
|
+
vitest.expect(parseFloat(String(get.value.pricing.subtotal))).toBeGreaterThan(0);
|
|
79
|
+
});
|
|
80
|
+
vitest.it("dedupes by line_key when adding the same product twice", async () => {
|
|
81
|
+
await chunk53J2WE4S_js.fixtures.addFirstProduct(h.client);
|
|
82
|
+
await chunk53J2WE4S_js.fixtures.addFirstProduct(h.client);
|
|
83
|
+
const res = await h.client.cart.get();
|
|
84
|
+
vitest.expect(res.ok).toBe(true);
|
|
85
|
+
if (!res.ok) return;
|
|
86
|
+
vitest.expect(res.value.items).toHaveLength(1);
|
|
87
|
+
vitest.expect(res.value.items[0]?.quantity).toBe(2);
|
|
88
|
+
});
|
|
89
|
+
vitest.it("removes items and zeroes the subtotal", async () => {
|
|
90
|
+
await chunk53J2WE4S_js.fixtures.addFirstProduct(h.client);
|
|
91
|
+
const before = await h.client.cart.get();
|
|
92
|
+
if (!before.ok) throw before.error;
|
|
93
|
+
const itemId = before.value.items[0]?.id;
|
|
94
|
+
vitest.expect(itemId).toBeTruthy();
|
|
95
|
+
const removed = await h.client.cart.removeItem(itemId);
|
|
96
|
+
vitest.expect(removed.ok).toBe(true);
|
|
97
|
+
const after = await h.client.cart.get();
|
|
98
|
+
if (!after.ok) throw after.error;
|
|
99
|
+
vitest.expect(after.value.items).toHaveLength(0);
|
|
100
|
+
vitest.expect(parseFloat(String(after.value.pricing.subtotal))).toBe(0);
|
|
101
|
+
});
|
|
102
|
+
if (opts.businessId) {
|
|
103
|
+
vitest.it("returns the brand's businessId on cart responses", async () => {
|
|
104
|
+
const res = await h.client.cart.get();
|
|
105
|
+
if (!res.ok) throw res.error;
|
|
106
|
+
vitest.expect(res.value.business_id).toBe(opts.businessId);
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
opts.extend?.({ getHandle: () => h, it: vitest.it });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function createContractSuite(opts = {}) {
|
|
113
|
+
vitest.describe(opts.label ?? "SDK \u2194 mock contract", () => {
|
|
114
|
+
let h;
|
|
115
|
+
vitest.beforeEach(() => {
|
|
116
|
+
h = chunk53J2WE4S_js.createTestClient(opts);
|
|
117
|
+
});
|
|
118
|
+
vitest.afterEach(() => h.dispose());
|
|
119
|
+
vitest.it("AddItemPayload schema accepts a minimal valid body", () => {
|
|
120
|
+
const result = chunk53J2WE4S_js.AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: 1 });
|
|
121
|
+
vitest.expect(result.success).toBe(true);
|
|
122
|
+
});
|
|
123
|
+
vitest.it("AddItemPayload schema rejects negative quantity", () => {
|
|
124
|
+
const result = chunk53J2WE4S_js.AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: -1 });
|
|
125
|
+
vitest.expect(result.success).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
vitest.it("AddItemPayload schema rejects empty item_id", () => {
|
|
128
|
+
const result = chunk53J2WE4S_js.AddItemPayloadSchema.safeParse({ item_id: "", quantity: 1 });
|
|
129
|
+
vitest.expect(result.success).toBe(false);
|
|
130
|
+
});
|
|
131
|
+
vitest.it("Cart line items returned by the mock match CartItemSchema", async () => {
|
|
132
|
+
const { product } = await chunk53J2WE4S_js.fixtures.addFirstProduct(h.client);
|
|
133
|
+
const get = await h.client.cart.get();
|
|
134
|
+
if (!get.ok) throw get.error;
|
|
135
|
+
vitest.expect(get.value.items.length).toBeGreaterThan(0);
|
|
136
|
+
for (const item of get.value.items) {
|
|
137
|
+
const result = chunk53J2WE4S_js.CartItemSchema.safeParse(item);
|
|
138
|
+
if (!result.success) {
|
|
139
|
+
const issues = result.error.issues.map((i) => ` \u2022 ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
140
|
+
throw new Error(`Cart item shape mismatch for ${product.name}:
|
|
141
|
+
${issues}`);
|
|
142
|
+
}
|
|
143
|
+
vitest.expect(result.success).toBe(true);
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
vitest.it("CheckoutResponse from the mock includes bill_token", async () => {
|
|
147
|
+
await chunk53J2WE4S_js.fixtures.addFirstProduct(h.client);
|
|
148
|
+
const cartRes = await h.client.cart.get();
|
|
149
|
+
if (!cartRes.ok) throw cartRes.error;
|
|
150
|
+
const checkout = await h.client.checkout.process({
|
|
151
|
+
cart_id: cartRes.value.id,
|
|
152
|
+
customer: chunk53J2WE4S_js.fixtures.customer(),
|
|
153
|
+
order_type: "delivery",
|
|
154
|
+
payment_method: "mobile_money",
|
|
155
|
+
mobile_money_details: { phone_number: "+233244000000", provider: "mtn" }
|
|
156
|
+
});
|
|
157
|
+
vitest.expect(checkout.ok).toBe(true);
|
|
158
|
+
if (!checkout.ok) return;
|
|
159
|
+
const result = chunk53J2WE4S_js.CheckoutResponseSchema.safeParse(checkout.value);
|
|
160
|
+
if (!result.success) {
|
|
161
|
+
const issues = result.error.issues.map((i) => ` \u2022 ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
162
|
+
throw new Error(`CheckoutResponse shape mismatch:
|
|
163
|
+
${issues}`);
|
|
164
|
+
}
|
|
165
|
+
vitest.expect(checkout.value.bill_token).toBeTruthy();
|
|
166
|
+
vitest.expect(checkout.value.order_id).toBeTruthy();
|
|
167
|
+
});
|
|
168
|
+
opts.extend?.({ getHandle: () => h, it: vitest.it });
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
exports.createBrandSuite = createBrandSuite;
|
|
173
|
+
exports.createCartFlowSuite = createCartFlowSuite;
|
|
174
|
+
exports.createContractSuite = createContractSuite;
|