@cimplify/sdk 0.52.0 → 0.52.2
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.js +23 -22
- package/dist/advanced.mjs +4 -3
- package/dist/chunk-3G6RQLXK.mjs +21 -0
- package/dist/{chunk-6RP6OPYO.js → chunk-7Y2O3E4D.js} +3 -3
- package/dist/{chunk-Z2AYLZDF.mjs → chunk-AMZXALF6.mjs} +1 -21
- package/dist/{chunk-MBR2DBEN.mjs → chunk-APHYBBDD.mjs} +3 -3
- package/dist/{chunk-CYGLTD7D.js → chunk-EMS6DQIX.js} +61 -61
- package/dist/{chunk-DR4UPU6P.js → chunk-EQLT46ZR.js} +22 -22
- package/dist/{chunk-OFNVLUH4.mjs → chunk-GLAVTDDE.mjs} +2 -2
- package/dist/chunk-OWW5GUSB.js +28 -0
- package/dist/{chunk-GEWFWQYK.js → chunk-Q5VGDCQF.js} +235 -234
- package/dist/{chunk-632JEJUS.mjs → chunk-R3F55BRN.mjs} +2 -1
- package/dist/{chunk-D22UVSFN.js → chunk-ROURLUXG.js} +4 -4
- package/dist/{chunk-XY2DFX5K.mjs → chunk-TD3AY34U.mjs} +1 -1
- package/dist/{chunk-24FK7VFL.mjs → chunk-VZS453ON.mjs} +2 -2
- package/dist/{chunk-TKOTACKZ.js → chunk-XA3ZNR75.js} +0 -26
- package/dist/index.js +110 -109
- package/dist/index.mjs +5 -4
- package/dist/react.js +86 -85
- package/dist/react.mjs +5 -4
- package/dist/server/evict.d.mts +31 -0
- package/dist/server/evict.d.ts +31 -0
- package/dist/server/evict.js +75 -0
- package/dist/server/evict.mjs +73 -0
- package/dist/server.d.mts +1 -30
- package/dist/server.d.ts +1 -30
- package/dist/server.js +7 -76
- package/dist/server.mjs +6 -74
- package/dist/testing/msw.js +4 -3
- package/dist/testing/msw.mjs +3 -2
- package/dist/testing/suite.js +26 -25
- package/dist/testing/suite.mjs +7 -6
- package/dist/testing.js +82 -81
- package/dist/testing.mjs +8 -7
- package/dist/utils.js +30 -29
- package/dist/utils.mjs +3 -2
- package/package.json +7 -1
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('../chunk-OWW5GUSB.js');
|
|
4
|
+
var internal = require('@opennextjs/cloudflare/overrides/internal');
|
|
5
|
+
var cloudflareContext = require('@opennextjs/cloudflare/cloudflare-context');
|
|
6
|
+
|
|
7
|
+
var R2_BUCKET_BINDING = "NEXT_INC_CACHE_R2_BUCKET";
|
|
8
|
+
var R2_PREFIX_ENV = "NEXT_INC_CACHE_R2_PREFIX";
|
|
9
|
+
var PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
|
|
10
|
+
var CIMPLIFY_TAG_PREFIX = "cimplify:";
|
|
11
|
+
function r2Key(env, key, cacheType) {
|
|
12
|
+
return internal.computeCacheKey(key, {
|
|
13
|
+
prefix: env[R2_PREFIX_ENV],
|
|
14
|
+
buildId: globalThis.process?.env?.OPEN_NEXT_BUILD_ID,
|
|
15
|
+
cacheType
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function cimplifyTags(value) {
|
|
19
|
+
return (value?.tags ?? []).filter((t) => t.startsWith(CIMPLIFY_TAG_PREFIX));
|
|
20
|
+
}
|
|
21
|
+
function pathIndexFor(env) {
|
|
22
|
+
const ns = env[PATH_INDEX_BINDING];
|
|
23
|
+
const prefix = env[R2_PREFIX_ENV];
|
|
24
|
+
if (!ns || !prefix) return null;
|
|
25
|
+
return ns.get(ns.idFromName(prefix));
|
|
26
|
+
}
|
|
27
|
+
var evictIncrementalCache = {
|
|
28
|
+
name: "cimplify-evict-r2-cache",
|
|
29
|
+
async get(key, cacheType) {
|
|
30
|
+
const env = cloudflareContext.getCloudflareContext().env;
|
|
31
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
32
|
+
if (!r2) return null;
|
|
33
|
+
try {
|
|
34
|
+
const obj = await r2.get(r2Key(env, key, cacheType));
|
|
35
|
+
if (!obj) return null;
|
|
36
|
+
return {
|
|
37
|
+
value: await obj.json(),
|
|
38
|
+
lastModified: obj.uploaded.getTime()
|
|
39
|
+
};
|
|
40
|
+
} catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
async set(key, value, cacheType) {
|
|
45
|
+
const env = cloudflareContext.getCloudflareContext().env;
|
|
46
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
47
|
+
if (!r2) return;
|
|
48
|
+
const k = r2Key(env, key, cacheType);
|
|
49
|
+
try {
|
|
50
|
+
await r2.put(k, JSON.stringify(value));
|
|
51
|
+
} catch {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
const tags = cimplifyTags(value);
|
|
55
|
+
if (tags.length === 0) return;
|
|
56
|
+
const index = pathIndexFor(env);
|
|
57
|
+
if (!index) return;
|
|
58
|
+
try {
|
|
59
|
+
await index.indexAdd(key, k, tags, cacheType === "fetch");
|
|
60
|
+
} catch {
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
async delete(key) {
|
|
64
|
+
const env = cloudflareContext.getCloudflareContext().env;
|
|
65
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
66
|
+
if (!r2) return;
|
|
67
|
+
try {
|
|
68
|
+
await r2.delete(r2Key(env, key));
|
|
69
|
+
} catch {
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
var evict_incremental_cache_default = evictIncrementalCache;
|
|
74
|
+
|
|
75
|
+
exports.evictIncrementalCache = evict_incremental_cache_default;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import '../chunk-3G6RQLXK.mjs';
|
|
2
|
+
import { computeCacheKey } from '@opennextjs/cloudflare/overrides/internal';
|
|
3
|
+
import { getCloudflareContext } from '@opennextjs/cloudflare/cloudflare-context';
|
|
4
|
+
|
|
5
|
+
var R2_BUCKET_BINDING = "NEXT_INC_CACHE_R2_BUCKET";
|
|
6
|
+
var R2_PREFIX_ENV = "NEXT_INC_CACHE_R2_PREFIX";
|
|
7
|
+
var PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
|
|
8
|
+
var CIMPLIFY_TAG_PREFIX = "cimplify:";
|
|
9
|
+
function r2Key(env, key, cacheType) {
|
|
10
|
+
return computeCacheKey(key, {
|
|
11
|
+
prefix: env[R2_PREFIX_ENV],
|
|
12
|
+
buildId: globalThis.process?.env?.OPEN_NEXT_BUILD_ID,
|
|
13
|
+
cacheType
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
function cimplifyTags(value) {
|
|
17
|
+
return (value?.tags ?? []).filter((t) => t.startsWith(CIMPLIFY_TAG_PREFIX));
|
|
18
|
+
}
|
|
19
|
+
function pathIndexFor(env) {
|
|
20
|
+
const ns = env[PATH_INDEX_BINDING];
|
|
21
|
+
const prefix = env[R2_PREFIX_ENV];
|
|
22
|
+
if (!ns || !prefix) return null;
|
|
23
|
+
return ns.get(ns.idFromName(prefix));
|
|
24
|
+
}
|
|
25
|
+
var evictIncrementalCache = {
|
|
26
|
+
name: "cimplify-evict-r2-cache",
|
|
27
|
+
async get(key, cacheType) {
|
|
28
|
+
const env = getCloudflareContext().env;
|
|
29
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
30
|
+
if (!r2) return null;
|
|
31
|
+
try {
|
|
32
|
+
const obj = await r2.get(r2Key(env, key, cacheType));
|
|
33
|
+
if (!obj) return null;
|
|
34
|
+
return {
|
|
35
|
+
value: await obj.json(),
|
|
36
|
+
lastModified: obj.uploaded.getTime()
|
|
37
|
+
};
|
|
38
|
+
} catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
async set(key, value, cacheType) {
|
|
43
|
+
const env = getCloudflareContext().env;
|
|
44
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
45
|
+
if (!r2) return;
|
|
46
|
+
const k = r2Key(env, key, cacheType);
|
|
47
|
+
try {
|
|
48
|
+
await r2.put(k, JSON.stringify(value));
|
|
49
|
+
} catch {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const tags = cimplifyTags(value);
|
|
53
|
+
if (tags.length === 0) return;
|
|
54
|
+
const index = pathIndexFor(env);
|
|
55
|
+
if (!index) return;
|
|
56
|
+
try {
|
|
57
|
+
await index.indexAdd(key, k, tags, cacheType === "fetch");
|
|
58
|
+
} catch {
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
async delete(key) {
|
|
62
|
+
const env = getCloudflareContext().env;
|
|
63
|
+
const r2 = env[R2_BUCKET_BINDING];
|
|
64
|
+
if (!r2) return;
|
|
65
|
+
try {
|
|
66
|
+
await r2.delete(r2Key(env, key));
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var evict_incremental_cache_default = evictIncrementalCache;
|
|
72
|
+
|
|
73
|
+
export { evict_incremental_cache_default as evictIncrementalCache };
|
package/dist/server.d.mts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { C as CimplifyClient } from './client-C6J_RGlr.mjs';
|
|
2
2
|
export { aO as Result } from './client-C6J_RGlr.mjs';
|
|
3
|
-
import { IncrementalCache } from '@opennextjs/aws/types/overrides';
|
|
4
3
|
export { ap as Category, h as CimplifyError, ar as Collection, X as Product, aa as ProductWithDetails } from './product-C-xLzh7Q.mjs';
|
|
5
4
|
import './payment-9L_-GWqQ.mjs';
|
|
6
5
|
|
|
@@ -137,34 +136,6 @@ type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
|
|
|
137
136
|
/** The TS type of {@link CACHE_LIFE_PROBE} — the `"seconds"` literal. */
|
|
138
137
|
type CacheLifeProbe = typeof CACHE_LIFE_PROBE;
|
|
139
138
|
|
|
140
|
-
/**
|
|
141
|
-
* Cimplify incremental-cache override for Workers for Platforms storefronts.
|
|
142
|
-
*
|
|
143
|
-
* Replaces opennext's stale-while-revalidate model with an evict-on-invalidate
|
|
144
|
-
* model that fits Cimplify's event-driven domain:
|
|
145
|
-
*
|
|
146
|
-
* - `get`: standard R2 fetch. Returns the cached value or null.
|
|
147
|
-
* - `set`: writes to R2 AND emits a tag→cache_key index update to the shared
|
|
148
|
-
* `CIMPLIFY_PATH_INDEX` Durable Object (hosted in cimplify-tag-cache).
|
|
149
|
-
* - `delete`: standard R2 delete (called by opennext on explicit invalidate;
|
|
150
|
-
* also called by us from the Rust EvictionDispatcher path on tag events).
|
|
151
|
-
*
|
|
152
|
-
* The Rust EvictionDispatcher reads the index on bus events, deletes the
|
|
153
|
-
* matching R2 entries directly, and prunes the index — there is no SWR
|
|
154
|
-
* "background refresh" path. opennext's queue and `isStale` checks become
|
|
155
|
-
* no-ops; cached entries are by definition fresh (existed at write time and
|
|
156
|
-
* haven't been evicted), and absence means the next request synchronously
|
|
157
|
-
* re-renders.
|
|
158
|
-
*
|
|
159
|
-
* Why this exists: WfP user workers cannot have `WORKER_SELF_REFERENCE`,
|
|
160
|
-
* which is the binding every built-in opennext queue requires. Rather than
|
|
161
|
-
* recreate SWR via self-fetch tricks, we drop SWR for our domain — Cimplify
|
|
162
|
-
* always knows when data changes (every catalog mutation flows through the
|
|
163
|
-
* bus), so timer-based refresh adds no value.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
declare const evictIncrementalCache: IncrementalCache;
|
|
167
|
-
|
|
168
139
|
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
169
140
|
type RevalidateProfile$1 = string | {
|
|
170
141
|
expire: number;
|
|
@@ -222,4 +193,4 @@ interface RevalidateRouteOptions {
|
|
|
222
193
|
}
|
|
223
194
|
declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
|
|
224
195
|
|
|
225
|
-
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile$1 as RevalidateProfile, type RevalidateRouteOptions, type RevalidateProfile as RevalidateRouteProfile, type ServerClientOptions,
|
|
196
|
+
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile$1 as RevalidateProfile, type RevalidateRouteOptions, type RevalidateProfile as RevalidateRouteProfile, type ServerClientOptions, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { C as CimplifyClient } from './client-CX7IFIkL.js';
|
|
2
2
|
export { aO as Result } from './client-CX7IFIkL.js';
|
|
3
|
-
import { IncrementalCache } from '@opennextjs/aws/types/overrides';
|
|
4
3
|
export { ap as Category, h as CimplifyError, ar as Collection, X as Product, aa as ProductWithDetails } from './product-C-xLzh7Q.js';
|
|
5
4
|
import './payment-_e99nSRj.js';
|
|
6
5
|
|
|
@@ -137,34 +136,6 @@ type CacheLifeDefault = typeof CACHE_LIFE_DEFAULT;
|
|
|
137
136
|
/** The TS type of {@link CACHE_LIFE_PROBE} — the `"seconds"` literal. */
|
|
138
137
|
type CacheLifeProbe = typeof CACHE_LIFE_PROBE;
|
|
139
138
|
|
|
140
|
-
/**
|
|
141
|
-
* Cimplify incremental-cache override for Workers for Platforms storefronts.
|
|
142
|
-
*
|
|
143
|
-
* Replaces opennext's stale-while-revalidate model with an evict-on-invalidate
|
|
144
|
-
* model that fits Cimplify's event-driven domain:
|
|
145
|
-
*
|
|
146
|
-
* - `get`: standard R2 fetch. Returns the cached value or null.
|
|
147
|
-
* - `set`: writes to R2 AND emits a tag→cache_key index update to the shared
|
|
148
|
-
* `CIMPLIFY_PATH_INDEX` Durable Object (hosted in cimplify-tag-cache).
|
|
149
|
-
* - `delete`: standard R2 delete (called by opennext on explicit invalidate;
|
|
150
|
-
* also called by us from the Rust EvictionDispatcher path on tag events).
|
|
151
|
-
*
|
|
152
|
-
* The Rust EvictionDispatcher reads the index on bus events, deletes the
|
|
153
|
-
* matching R2 entries directly, and prunes the index — there is no SWR
|
|
154
|
-
* "background refresh" path. opennext's queue and `isStale` checks become
|
|
155
|
-
* no-ops; cached entries are by definition fresh (existed at write time and
|
|
156
|
-
* haven't been evicted), and absence means the next request synchronously
|
|
157
|
-
* re-renders.
|
|
158
|
-
*
|
|
159
|
-
* Why this exists: WfP user workers cannot have `WORKER_SELF_REFERENCE`,
|
|
160
|
-
* which is the binding every built-in opennext queue requires. Rather than
|
|
161
|
-
* recreate SWR via self-fetch tricks, we drop SWR for our domain — Cimplify
|
|
162
|
-
* always knows when data changes (every catalog mutation flows through the
|
|
163
|
-
* bus), so timer-based refresh adds no value.
|
|
164
|
-
*/
|
|
165
|
-
|
|
166
|
-
declare const evictIncrementalCache: IncrementalCache;
|
|
167
|
-
|
|
168
139
|
/** Next 16 cacheLife profile — a built-in name (`'max'`/`'hours'`/…) or `{expire: secs}`. */
|
|
169
140
|
type RevalidateProfile$1 = string | {
|
|
170
141
|
expire: number;
|
|
@@ -222,4 +193,4 @@ interface RevalidateRouteOptions {
|
|
|
222
193
|
}
|
|
223
194
|
declare function revalidateRouteHandler(req: Request, options?: RevalidateRouteOptions): Promise<Response>;
|
|
224
195
|
|
|
225
|
-
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile$1 as RevalidateProfile, type RevalidateRouteOptions, type RevalidateProfile as RevalidateRouteProfile, type ServerClientOptions,
|
|
196
|
+
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, type CacheLifeDefault, type CacheLifeProbe, CimplifyClient, type RevalidateProfile$1 as RevalidateProfile, type RevalidateRouteOptions, type RevalidateProfile as RevalidateRouteProfile, type ServerClientOptions, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
|
package/dist/server.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('./chunk-
|
|
5
|
-
require('./chunk-
|
|
6
|
-
var
|
|
3
|
+
var chunkEMS6DQIX_js = require('./chunk-EMS6DQIX.js');
|
|
4
|
+
require('./chunk-EQLT46ZR.js');
|
|
5
|
+
require('./chunk-7Y2O3E4D.js');
|
|
6
|
+
var chunkXA3ZNR75_js = require('./chunk-XA3ZNR75.js');
|
|
7
|
+
require('./chunk-OWW5GUSB.js');
|
|
7
8
|
var react = require('react');
|
|
8
|
-
var internal = require('@opennextjs/cloudflare/overrides/internal');
|
|
9
|
-
var cloudflareContext = require('@opennextjs/cloudflare/cloudflare-context');
|
|
10
9
|
|
|
11
10
|
var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
|
|
12
11
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
@@ -26,7 +25,7 @@ function readEnv(...keys) {
|
|
|
26
25
|
var getServerClient = react.cache((opts = {}) => {
|
|
27
26
|
const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ?? defaultBaseUrl();
|
|
28
27
|
const publicKey = opts.secretKey ?? readEnv("CIMPLIFY_SECRET_KEY", "NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY") ?? "mock-dev";
|
|
29
|
-
const client =
|
|
28
|
+
const client = chunkEMS6DQIX_js.createCimplifyClient({
|
|
30
29
|
baseUrl,
|
|
31
30
|
publicKey,
|
|
32
31
|
suppressPublicKeyWarning: true
|
|
@@ -68,73 +67,6 @@ var tags = {
|
|
|
68
67
|
// src/server/cache-life.ts
|
|
69
68
|
var CACHE_LIFE_DEFAULT = "max";
|
|
70
69
|
var CACHE_LIFE_PROBE = "seconds";
|
|
71
|
-
var R2_BUCKET_BINDING = "NEXT_INC_CACHE_R2_BUCKET";
|
|
72
|
-
var R2_PREFIX_ENV = "NEXT_INC_CACHE_R2_PREFIX";
|
|
73
|
-
var PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
|
|
74
|
-
var CIMPLIFY_TAG_PREFIX = "cimplify:";
|
|
75
|
-
function r2Key(env, key, cacheType) {
|
|
76
|
-
return internal.computeCacheKey(key, {
|
|
77
|
-
prefix: env[R2_PREFIX_ENV],
|
|
78
|
-
buildId: globalThis.process?.env?.OPEN_NEXT_BUILD_ID,
|
|
79
|
-
cacheType
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
function cimplifyTags(value) {
|
|
83
|
-
return (value?.tags ?? []).filter((t) => t.startsWith(CIMPLIFY_TAG_PREFIX));
|
|
84
|
-
}
|
|
85
|
-
function pathIndexFor(env) {
|
|
86
|
-
const ns = env[PATH_INDEX_BINDING];
|
|
87
|
-
const prefix = env[R2_PREFIX_ENV];
|
|
88
|
-
if (!ns || !prefix) return null;
|
|
89
|
-
return ns.get(ns.idFromName(prefix));
|
|
90
|
-
}
|
|
91
|
-
var evictIncrementalCache = {
|
|
92
|
-
name: "cimplify-evict-r2-cache",
|
|
93
|
-
async get(key, cacheType) {
|
|
94
|
-
const env = cloudflareContext.getCloudflareContext().env;
|
|
95
|
-
const r2 = env[R2_BUCKET_BINDING];
|
|
96
|
-
if (!r2) return null;
|
|
97
|
-
try {
|
|
98
|
-
const obj = await r2.get(r2Key(env, key, cacheType));
|
|
99
|
-
if (!obj) return null;
|
|
100
|
-
return {
|
|
101
|
-
value: await obj.json(),
|
|
102
|
-
lastModified: obj.uploaded.getTime()
|
|
103
|
-
};
|
|
104
|
-
} catch {
|
|
105
|
-
return null;
|
|
106
|
-
}
|
|
107
|
-
},
|
|
108
|
-
async set(key, value, cacheType) {
|
|
109
|
-
const env = cloudflareContext.getCloudflareContext().env;
|
|
110
|
-
const r2 = env[R2_BUCKET_BINDING];
|
|
111
|
-
if (!r2) return;
|
|
112
|
-
const k = r2Key(env, key, cacheType);
|
|
113
|
-
try {
|
|
114
|
-
await r2.put(k, JSON.stringify(value));
|
|
115
|
-
} catch {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const tags2 = cimplifyTags(value);
|
|
119
|
-
if (tags2.length === 0) return;
|
|
120
|
-
const index = pathIndexFor(env);
|
|
121
|
-
if (!index) return;
|
|
122
|
-
try {
|
|
123
|
-
await index.indexAdd(key, k, tags2, cacheType === "fetch");
|
|
124
|
-
} catch {
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
async delete(key) {
|
|
128
|
-
const env = cloudflareContext.getCloudflareContext().env;
|
|
129
|
-
const r2 = env[R2_BUCKET_BINDING];
|
|
130
|
-
if (!r2) return;
|
|
131
|
-
try {
|
|
132
|
-
await r2.delete(r2Key(env, key));
|
|
133
|
-
} catch {
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var evict_incremental_cache_default = evictIncrementalCache;
|
|
138
70
|
|
|
139
71
|
// src/server/revalidate.ts
|
|
140
72
|
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
@@ -389,11 +321,10 @@ function text(message, status) {
|
|
|
389
321
|
|
|
390
322
|
Object.defineProperty(exports, "CimplifyError", {
|
|
391
323
|
enumerable: true,
|
|
392
|
-
get: function () { return
|
|
324
|
+
get: function () { return chunkXA3ZNR75_js.CimplifyError; }
|
|
393
325
|
});
|
|
394
326
|
exports.CACHE_LIFE_DEFAULT = CACHE_LIFE_DEFAULT;
|
|
395
327
|
exports.CACHE_LIFE_PROBE = CACHE_LIFE_PROBE;
|
|
396
|
-
exports.evictIncrementalCache = evict_incremental_cache_default;
|
|
397
328
|
exports.getServerClient = getServerClient;
|
|
398
329
|
exports.refreshPage = refreshPage;
|
|
399
330
|
exports.revalidateAddOn = revalidateAddOn;
|
package/dist/server.mjs
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { createCimplifyClient } from './chunk-
|
|
2
|
-
import './chunk-
|
|
3
|
-
import './chunk-
|
|
4
|
-
export { CimplifyError } from './chunk-
|
|
1
|
+
import { createCimplifyClient } from './chunk-APHYBBDD.mjs';
|
|
2
|
+
import './chunk-GLAVTDDE.mjs';
|
|
3
|
+
import './chunk-TD3AY34U.mjs';
|
|
4
|
+
export { CimplifyError } from './chunk-AMZXALF6.mjs';
|
|
5
|
+
import './chunk-3G6RQLXK.mjs';
|
|
5
6
|
import { cache } from 'react';
|
|
6
|
-
import { computeCacheKey } from '@opennextjs/cloudflare/overrides/internal';
|
|
7
|
-
import { getCloudflareContext } from '@opennextjs/cloudflare/cloudflare-context';
|
|
8
7
|
|
|
9
8
|
var DEFAULT_PROD_URL = "https://storefronts.cimplify.io";
|
|
10
9
|
var DEFAULT_DEV_URL = "http://127.0.0.1:8787";
|
|
@@ -66,73 +65,6 @@ var tags = {
|
|
|
66
65
|
// src/server/cache-life.ts
|
|
67
66
|
var CACHE_LIFE_DEFAULT = "max";
|
|
68
67
|
var CACHE_LIFE_PROBE = "seconds";
|
|
69
|
-
var R2_BUCKET_BINDING = "NEXT_INC_CACHE_R2_BUCKET";
|
|
70
|
-
var R2_PREFIX_ENV = "NEXT_INC_CACHE_R2_PREFIX";
|
|
71
|
-
var PATH_INDEX_BINDING = "CIMPLIFY_PATH_INDEX";
|
|
72
|
-
var CIMPLIFY_TAG_PREFIX = "cimplify:";
|
|
73
|
-
function r2Key(env, key, cacheType) {
|
|
74
|
-
return computeCacheKey(key, {
|
|
75
|
-
prefix: env[R2_PREFIX_ENV],
|
|
76
|
-
buildId: globalThis.process?.env?.OPEN_NEXT_BUILD_ID,
|
|
77
|
-
cacheType
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function cimplifyTags(value) {
|
|
81
|
-
return (value?.tags ?? []).filter((t) => t.startsWith(CIMPLIFY_TAG_PREFIX));
|
|
82
|
-
}
|
|
83
|
-
function pathIndexFor(env) {
|
|
84
|
-
const ns = env[PATH_INDEX_BINDING];
|
|
85
|
-
const prefix = env[R2_PREFIX_ENV];
|
|
86
|
-
if (!ns || !prefix) return null;
|
|
87
|
-
return ns.get(ns.idFromName(prefix));
|
|
88
|
-
}
|
|
89
|
-
var evictIncrementalCache = {
|
|
90
|
-
name: "cimplify-evict-r2-cache",
|
|
91
|
-
async get(key, cacheType) {
|
|
92
|
-
const env = getCloudflareContext().env;
|
|
93
|
-
const r2 = env[R2_BUCKET_BINDING];
|
|
94
|
-
if (!r2) return null;
|
|
95
|
-
try {
|
|
96
|
-
const obj = await r2.get(r2Key(env, key, cacheType));
|
|
97
|
-
if (!obj) return null;
|
|
98
|
-
return {
|
|
99
|
-
value: await obj.json(),
|
|
100
|
-
lastModified: obj.uploaded.getTime()
|
|
101
|
-
};
|
|
102
|
-
} catch {
|
|
103
|
-
return null;
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
async set(key, value, cacheType) {
|
|
107
|
-
const env = getCloudflareContext().env;
|
|
108
|
-
const r2 = env[R2_BUCKET_BINDING];
|
|
109
|
-
if (!r2) return;
|
|
110
|
-
const k = r2Key(env, key, cacheType);
|
|
111
|
-
try {
|
|
112
|
-
await r2.put(k, JSON.stringify(value));
|
|
113
|
-
} catch {
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
const tags2 = cimplifyTags(value);
|
|
117
|
-
if (tags2.length === 0) return;
|
|
118
|
-
const index = pathIndexFor(env);
|
|
119
|
-
if (!index) return;
|
|
120
|
-
try {
|
|
121
|
-
await index.indexAdd(key, k, tags2, cacheType === "fetch");
|
|
122
|
-
} catch {
|
|
123
|
-
}
|
|
124
|
-
},
|
|
125
|
-
async delete(key) {
|
|
126
|
-
const env = getCloudflareContext().env;
|
|
127
|
-
const r2 = env[R2_BUCKET_BINDING];
|
|
128
|
-
if (!r2) return;
|
|
129
|
-
try {
|
|
130
|
-
await r2.delete(r2Key(env, key));
|
|
131
|
-
} catch {
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
var evict_incremental_cache_default = evictIncrementalCache;
|
|
136
68
|
|
|
137
69
|
// src/server/revalidate.ts
|
|
138
70
|
var DEFAULT_PROFILE = CACHE_LIFE_DEFAULT;
|
|
@@ -385,4 +317,4 @@ function text(message, status) {
|
|
|
385
317
|
return new Response(message, { status, headers: { "content-type": "text/plain" } });
|
|
386
318
|
}
|
|
387
319
|
|
|
388
|
-
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE,
|
|
320
|
+
export { CACHE_LIFE_DEFAULT, CACHE_LIFE_PROBE, getServerClient, refreshPage, revalidateAddOn, revalidateAddOns, revalidateBrand, revalidateBusiness, revalidateByTag, revalidateCategories, revalidateCategory, revalidateCollection, revalidateCollections, revalidateLocation, revalidateLocations, revalidatePricing, revalidateProduct, revalidateProducts, revalidateRouteHandler, revalidateStock, revalidateSubscription, revalidateSubscriptions, tags, updateAddOn, updateAddOns, updateBrand, updateBusiness, updateByTag, updateCategories, updateCategory, updateCollection, updateCollections, updateLocation, updateLocations, updatePricing, updateProduct, updateProducts, updateStock, updateSubscription, updateSubscriptions };
|
package/dist/testing/msw.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
3
|
+
var chunkQ5VGDCQF_js = require('../chunk-Q5VGDCQF.js');
|
|
4
|
+
require('../chunk-XA3ZNR75.js');
|
|
5
|
+
require('../chunk-OWW5GUSB.js');
|
|
5
6
|
|
|
6
7
|
// src/mock/msw.ts
|
|
7
8
|
async function createMswHandlers(options = {}) {
|
|
8
9
|
const baseUrl = options.baseUrl ?? "http://localhost:8787";
|
|
9
|
-
const handle =
|
|
10
|
+
const handle = chunkQ5VGDCQF_js.createMockApp(options);
|
|
10
11
|
const msw = await import('msw').catch(() => {
|
|
11
12
|
throw new Error("msw is required to use @cimplify/sdk/mock/msw \u2014 install it as a peer dependency");
|
|
12
13
|
});
|
package/dist/testing/msw.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createMockApp } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
import { createMockApp } from '../chunk-R3F55BRN.mjs';
|
|
2
|
+
import '../chunk-AMZXALF6.mjs';
|
|
3
|
+
import '../chunk-3G6RQLXK.mjs';
|
|
3
4
|
|
|
4
5
|
// src/mock/msw.ts
|
|
5
6
|
async function createMswHandlers(options = {}) {
|
package/dist/testing/suite.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('../chunk-
|
|
5
|
-
require('../chunk-
|
|
6
|
-
require('../chunk-
|
|
7
|
-
require('../chunk-
|
|
8
|
-
require('../chunk-
|
|
3
|
+
var chunkROURLUXG_js = require('../chunk-ROURLUXG.js');
|
|
4
|
+
require('../chunk-Q5VGDCQF.js');
|
|
5
|
+
require('../chunk-EMS6DQIX.js');
|
|
6
|
+
require('../chunk-EQLT46ZR.js');
|
|
7
|
+
require('../chunk-7Y2O3E4D.js');
|
|
8
|
+
require('../chunk-XA3ZNR75.js');
|
|
9
|
+
require('../chunk-OWW5GUSB.js');
|
|
9
10
|
var vitest = require('vitest');
|
|
10
11
|
|
|
11
12
|
var PLACEHOLDER_PHRASES = [
|
|
@@ -19,11 +20,11 @@ var PLACEHOLDER_PHRASES = [
|
|
|
19
20
|
function createBrandSuite(opts) {
|
|
20
21
|
vitest.describe(opts.label ?? "brand schema", () => {
|
|
21
22
|
vitest.it("conforms to the Cimplify brand contract", () => {
|
|
22
|
-
vitest.expect(() =>
|
|
23
|
+
vitest.expect(() => chunkROURLUXG_js.assertBrand(opts.brand)).not.toThrow();
|
|
23
24
|
});
|
|
24
25
|
vitest.it("declares a known mock seed", () => {
|
|
25
26
|
const b = opts.brand;
|
|
26
|
-
vitest.expect(
|
|
27
|
+
vitest.expect(chunkROURLUXG_js.SeedNameSchema.safeParse(b.mock?.seed).success).toBe(true);
|
|
27
28
|
});
|
|
28
29
|
vitest.it("has no placeholder copy left in", () => {
|
|
29
30
|
const offenders = [];
|
|
@@ -55,7 +56,7 @@ ${msg}`);
|
|
|
55
56
|
vitest.expect(b.mock?.businessId).toMatch(/^bus_/);
|
|
56
57
|
});
|
|
57
58
|
vitest.it("zod-parses cleanly", () => {
|
|
58
|
-
const result =
|
|
59
|
+
const result = chunkROURLUXG_js.BrandSchema.safeParse(opts.brand);
|
|
59
60
|
if (!result.success) {
|
|
60
61
|
throw new Error(
|
|
61
62
|
"Brand schema violations:\n" + result.error.issues.map((i) => ` \u2022 brand.${i.path.join(".")}: ${i.message}`).join("\n")
|
|
@@ -70,23 +71,23 @@ function createCartFlowSuite(opts = {}) {
|
|
|
70
71
|
vitest.describe(opts.label ?? "cart flow against in-process mock", () => {
|
|
71
72
|
let h;
|
|
72
73
|
vitest.beforeEach(() => {
|
|
73
|
-
h =
|
|
74
|
+
h = chunkROURLUXG_js.createTestClient(opts);
|
|
74
75
|
});
|
|
75
76
|
vitest.afterEach(() => h.dispose());
|
|
76
77
|
vitest.it("starts with an empty cart matching the canonical shape", async () => {
|
|
77
78
|
const res = await h.client.cart.get();
|
|
78
79
|
vitest.expect(res.ok).toBe(true);
|
|
79
80
|
if (!res.ok) return;
|
|
80
|
-
vitest.expect(() =>
|
|
81
|
+
vitest.expect(() => chunkROURLUXG_js.assertCart(res.value)).not.toThrow();
|
|
81
82
|
vitest.expect(res.value.items).toHaveLength(0);
|
|
82
83
|
});
|
|
83
84
|
vitest.it("adds the first product, persists it, and returns a shape-valid cart", async () => {
|
|
84
|
-
const { product, variantId } = await
|
|
85
|
+
const { product, variantId } = await chunkROURLUXG_js.fixtures.addFirstProduct(h.client);
|
|
85
86
|
vitest.expect(product.id).toBeTruthy();
|
|
86
87
|
const get = await h.client.cart.get();
|
|
87
88
|
vitest.expect(get.ok).toBe(true);
|
|
88
89
|
if (!get.ok) return;
|
|
89
|
-
vitest.expect(() =>
|
|
90
|
+
vitest.expect(() => chunkROURLUXG_js.assertCart(get.value)).not.toThrow();
|
|
90
91
|
vitest.expect(get.value.items).toHaveLength(1);
|
|
91
92
|
vitest.expect(get.value.items[0]?.item_id).toBe(product.id);
|
|
92
93
|
if (variantId) {
|
|
@@ -97,8 +98,8 @@ function createCartFlowSuite(opts = {}) {
|
|
|
97
98
|
vitest.expect(parseFloat(String(get.value.pricing.subtotal))).toBeGreaterThan(0);
|
|
98
99
|
});
|
|
99
100
|
vitest.it("dedupes by line_key when adding the same product twice", async () => {
|
|
100
|
-
await
|
|
101
|
-
await
|
|
101
|
+
await chunkROURLUXG_js.fixtures.addFirstProduct(h.client);
|
|
102
|
+
await chunkROURLUXG_js.fixtures.addFirstProduct(h.client);
|
|
102
103
|
const res = await h.client.cart.get();
|
|
103
104
|
vitest.expect(res.ok).toBe(true);
|
|
104
105
|
if (!res.ok) return;
|
|
@@ -106,7 +107,7 @@ function createCartFlowSuite(opts = {}) {
|
|
|
106
107
|
vitest.expect(res.value.items[0]?.quantity).toBe(2);
|
|
107
108
|
});
|
|
108
109
|
vitest.it("removes items and zeroes the subtotal", async () => {
|
|
109
|
-
await
|
|
110
|
+
await chunkROURLUXG_js.fixtures.addFirstProduct(h.client);
|
|
110
111
|
const before = await h.client.cart.get();
|
|
111
112
|
if (!before.ok) throw before.error;
|
|
112
113
|
const itemId = before.value.items[0]?.id;
|
|
@@ -132,28 +133,28 @@ function createContractSuite(opts = {}) {
|
|
|
132
133
|
vitest.describe(opts.label ?? "SDK \u2194 mock contract", () => {
|
|
133
134
|
let h;
|
|
134
135
|
vitest.beforeEach(() => {
|
|
135
|
-
h =
|
|
136
|
+
h = chunkROURLUXG_js.createTestClient(opts);
|
|
136
137
|
});
|
|
137
138
|
vitest.afterEach(() => h.dispose());
|
|
138
139
|
vitest.it("AddItemPayload schema accepts a minimal valid body", () => {
|
|
139
|
-
const result =
|
|
140
|
+
const result = chunkROURLUXG_js.AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: 1 });
|
|
140
141
|
vitest.expect(result.success).toBe(true);
|
|
141
142
|
});
|
|
142
143
|
vitest.it("AddItemPayload schema rejects negative quantity", () => {
|
|
143
|
-
const result =
|
|
144
|
+
const result = chunkROURLUXG_js.AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: -1 });
|
|
144
145
|
vitest.expect(result.success).toBe(false);
|
|
145
146
|
});
|
|
146
147
|
vitest.it("AddItemPayload schema rejects empty item_id", () => {
|
|
147
|
-
const result =
|
|
148
|
+
const result = chunkROURLUXG_js.AddItemPayloadSchema.safeParse({ item_id: "", quantity: 1 });
|
|
148
149
|
vitest.expect(result.success).toBe(false);
|
|
149
150
|
});
|
|
150
151
|
vitest.it("Cart line items returned by the mock match CartItemSchema", async () => {
|
|
151
|
-
const { product } = await
|
|
152
|
+
const { product } = await chunkROURLUXG_js.fixtures.addFirstProduct(h.client);
|
|
152
153
|
const get = await h.client.cart.get();
|
|
153
154
|
if (!get.ok) throw get.error;
|
|
154
155
|
vitest.expect(get.value.items.length).toBeGreaterThan(0);
|
|
155
156
|
for (const item of get.value.items) {
|
|
156
|
-
const result =
|
|
157
|
+
const result = chunkROURLUXG_js.CartItemSchema.safeParse(item);
|
|
157
158
|
if (!result.success) {
|
|
158
159
|
const issues = result.error.issues.map((i) => ` \u2022 ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
159
160
|
throw new Error(`Cart item shape mismatch for ${product.name}:
|
|
@@ -163,19 +164,19 @@ ${issues}`);
|
|
|
163
164
|
}
|
|
164
165
|
});
|
|
165
166
|
vitest.it("CheckoutResponse from the mock includes bill_token", async () => {
|
|
166
|
-
await
|
|
167
|
+
await chunkROURLUXG_js.fixtures.addFirstProduct(h.client);
|
|
167
168
|
const cartRes = await h.client.cart.get();
|
|
168
169
|
if (!cartRes.ok) throw cartRes.error;
|
|
169
170
|
const checkout = await h.client.checkout.process({
|
|
170
171
|
cart_id: cartRes.value.id,
|
|
171
|
-
customer:
|
|
172
|
+
customer: chunkROURLUXG_js.fixtures.customer(),
|
|
172
173
|
order_type: "delivery",
|
|
173
174
|
payment_method: "mobile_money",
|
|
174
175
|
mobile_money_details: { phone_number: "+233244000000", provider: "mtn" }
|
|
175
176
|
});
|
|
176
177
|
vitest.expect(checkout.ok).toBe(true);
|
|
177
178
|
if (!checkout.ok) return;
|
|
178
|
-
const result =
|
|
179
|
+
const result = chunkROURLUXG_js.CheckoutResponseSchema.safeParse(checkout.value);
|
|
179
180
|
if (!result.success) {
|
|
180
181
|
const issues = result.error.issues.map((i) => ` \u2022 ${i.path.join(".")}: ${i.message}`).join("\n");
|
|
181
182
|
throw new Error(`CheckoutResponse shape mismatch:
|
package/dist/testing/suite.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { assertBrand, SeedNameSchema, BrandSchema, createTestClient, assertCart, fixtures, AddItemPayloadSchema, CartItemSchema, CheckoutResponseSchema } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
4
|
-
import '../chunk-
|
|
5
|
-
import '../chunk-
|
|
6
|
-
import '../chunk-
|
|
1
|
+
import { assertBrand, SeedNameSchema, BrandSchema, createTestClient, assertCart, fixtures, AddItemPayloadSchema, CartItemSchema, CheckoutResponseSchema } from '../chunk-VZS453ON.mjs';
|
|
2
|
+
import '../chunk-R3F55BRN.mjs';
|
|
3
|
+
import '../chunk-APHYBBDD.mjs';
|
|
4
|
+
import '../chunk-GLAVTDDE.mjs';
|
|
5
|
+
import '../chunk-TD3AY34U.mjs';
|
|
6
|
+
import '../chunk-AMZXALF6.mjs';
|
|
7
|
+
import '../chunk-3G6RQLXK.mjs';
|
|
7
8
|
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
|
|
8
9
|
|
|
9
10
|
var PLACEHOLDER_PHRASES = [
|