@tiledev/sdk-shopify 0.9.1 → 0.10.1
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/README.md +653 -50
- package/dist/alertSettings.d.ts.map +1 -1
- package/dist/alertSettings.js +2 -0
- package/dist/alertSettings.js.map +1 -1
- package/dist/attribution.d.ts +21 -0
- package/dist/attribution.d.ts.map +1 -1
- package/dist/attribution.js +17 -0
- package/dist/attribution.js.map +1 -1
- package/dist/auth/pkce.d.ts +30 -0
- package/dist/auth/pkce.d.ts.map +1 -0
- package/dist/auth/pkce.js +128 -0
- package/dist/auth/pkce.js.map +1 -0
- package/dist/auth/session.d.ts +118 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +896 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/storeCredit.d.ts +64 -0
- package/dist/auth/storeCredit.d.ts.map +1 -0
- package/dist/auth/storeCredit.js +274 -0
- package/dist/auth/storeCredit.js.map +1 -0
- package/dist/cart.d.ts +25 -1
- package/dist/cart.d.ts.map +1 -1
- package/dist/cart.js +95 -2
- package/dist/cart.js.map +1 -1
- package/dist/cartPolicy.js +4 -4
- package/dist/checkout.d.ts +123 -0
- package/dist/checkout.d.ts.map +1 -0
- package/dist/checkout.js +205 -0
- package/dist/checkout.js.map +1 -0
- package/dist/customer.d.ts.map +1 -1
- package/dist/customer.js +8 -0
- package/dist/customer.js.map +1 -1
- package/dist/index.d.ts +12 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +74 -2
- package/dist/index.js.map +1 -1
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +2 -0
- package/dist/messages.js.map +1 -1
- package/dist/money.d.ts +16 -0
- package/dist/money.d.ts.map +1 -1
- package/dist/money.js +55 -0
- package/dist/money.js.map +1 -1
- package/dist/orders.d.ts +99 -0
- package/dist/orders.d.ts.map +1 -0
- package/dist/orders.js +439 -0
- package/dist/orders.js.map +1 -0
- package/dist/productPage.d.ts +100 -0
- package/dist/productPage.d.ts.map +1 -0
- package/dist/productPage.js +298 -0
- package/dist/productPage.js.map +1 -0
- package/dist/productStore.d.ts +1 -1
- package/dist/productStore.d.ts.map +1 -1
- package/dist/productStore.js +63 -5
- package/dist/productStore.js.map +1 -1
- package/dist/products.d.ts.map +1 -1
- package/dist/products.js +15 -3
- package/dist/products.js.map +1 -1
- package/dist/purchaseRules.d.ts +74 -0
- package/dist/purchaseRules.d.ts.map +1 -0
- package/dist/purchaseRules.js +73 -0
- package/dist/purchaseRules.js.map +1 -0
- package/dist/queries.d.ts +15 -13
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +43 -7
- package/dist/queries.js.map +1 -1
- package/dist/react/ShopifyProvider.d.ts +167 -25
- package/dist/react/ShopifyProvider.d.ts.map +1 -1
- package/dist/react/ShopifyProvider.js +352 -207
- package/dist/react/ShopifyProvider.js.map +1 -1
- package/dist/react/appForeground.d.ts +6 -0
- package/dist/react/appForeground.d.ts.map +1 -0
- package/dist/react/appForeground.js +19 -0
- package/dist/react/appForeground.js.map +1 -0
- package/dist/react/appForeground.native.d.ts +2 -0
- package/dist/react/appForeground.native.d.ts.map +1 -0
- package/dist/react/appForeground.native.js +23 -0
- package/dist/react/appForeground.native.js.map +1 -0
- package/dist/react/index.d.ts +7 -1
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +23 -1
- package/dist/react/index.js.map +1 -1
- package/dist/react/tileCreditClient.d.ts +4 -0
- package/dist/react/tileCreditClient.d.ts.map +1 -0
- package/dist/react/tileCreditClient.js +27 -0
- package/dist/react/tileCreditClient.js.map +1 -0
- package/dist/react/useAppDiscountCode.d.ts +19 -0
- package/dist/react/useAppDiscountCode.d.ts.map +1 -0
- package/dist/react/useAppDiscountCode.js +44 -0
- package/dist/react/useAppDiscountCode.js.map +1 -0
- package/dist/react/useCartStoreCredit.d.ts +25 -0
- package/dist/react/useCartStoreCredit.d.ts.map +1 -0
- package/dist/react/useCartStoreCredit.js +292 -0
- package/dist/react/useCartStoreCredit.js.map +1 -0
- package/dist/react/useOrders.d.ts +104 -0
- package/dist/react/useOrders.d.ts.map +1 -0
- package/dist/react/useOrders.js +287 -0
- package/dist/react/useOrders.js.map +1 -0
- package/dist/react/useProduct.d.ts.map +1 -1
- package/dist/react/useProduct.js +1 -9
- package/dist/react/useProduct.js.map +1 -1
- package/dist/react/useProductFeed.d.ts.map +1 -1
- package/dist/react/useProductFeed.js +33 -5
- package/dist/react/useProductFeed.js.map +1 -1
- package/dist/react/useProductPage.d.ts +148 -0
- package/dist/react/useProductPage.d.ts.map +1 -0
- package/dist/react/useProductPage.js +178 -0
- package/dist/react/useProductPage.js.map +1 -0
- package/dist/react/useProductRecommendations.d.ts +27 -0
- package/dist/react/useProductRecommendations.d.ts.map +1 -0
- package/dist/react/useProductRecommendations.js +76 -0
- package/dist/react/useProductRecommendations.js.map +1 -0
- package/dist/react/useStoreCredit.d.ts +58 -0
- package/dist/react/useStoreCredit.d.ts.map +1 -0
- package/dist/react/useStoreCredit.js +209 -0
- package/dist/react/useStoreCredit.js.map +1 -0
- package/dist/react/useTileCredit.d.ts +4 -3
- package/dist/react/useTileCredit.d.ts.map +1 -1
- package/dist/react/useTileCredit.js +63 -55
- package/dist/react/useTileCredit.js.map +1 -1
- package/dist/shopify.d.ts.map +1 -1
- package/dist/shopify.js +2 -0
- package/dist/shopify.js.map +1 -1
- package/dist/storedList.d.ts +27 -0
- package/dist/storedList.d.ts.map +1 -0
- package/dist/storedList.js +152 -0
- package/dist/storedList.js.map +1 -0
- package/dist/tileCredit.d.ts +25 -10
- package/dist/tileCredit.d.ts.map +1 -1
- package/dist/tileCredit.js +97 -45
- package/dist/tileCredit.js.map +1 -1
- package/dist/types.d.ts +407 -34
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +1 -2
- package/dist/types.js.map +1 -1
- package/dist/variants.d.ts.map +1 -1
- package/dist/variants.js +4 -3
- package/dist/variants.js.map +1 -1
- package/dist/waitlist.d.ts +4 -0
- package/dist/waitlist.d.ts.map +1 -0
- package/dist/waitlist.js +213 -0
- package/dist/waitlist.js.map +1 -0
- package/dist/wishlist.d.ts.map +1 -1
- package/dist/wishlist.js +70 -47
- package/dist/wishlist.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.STORED_DETAILS_BUDGET = void 0;
|
|
4
|
+
exports.createStoredList = createStoredList;
|
|
5
|
+
/** Characters of stored details per list. See the note above. */
|
|
6
|
+
exports.STORED_DETAILS_BUDGET = 1000000;
|
|
7
|
+
function createStoredList(codec) {
|
|
8
|
+
let storage = null;
|
|
9
|
+
let key = '';
|
|
10
|
+
/** False once the stored list failed to read: writing then would replace a list we never saw. */
|
|
11
|
+
let writable = true;
|
|
12
|
+
/** The entries under `k`, de-duplicated; `null` when it could not be read at all. */
|
|
13
|
+
async function readList(k) {
|
|
14
|
+
if (!storage)
|
|
15
|
+
return [];
|
|
16
|
+
let raw;
|
|
17
|
+
try {
|
|
18
|
+
raw = await Promise.resolve(storage.getItem(k));
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (!raw)
|
|
24
|
+
return [];
|
|
25
|
+
let parsed;
|
|
26
|
+
try {
|
|
27
|
+
parsed = JSON.parse(raw);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
parsed = undefined;
|
|
31
|
+
}
|
|
32
|
+
if (!Array.isArray(parsed)) {
|
|
33
|
+
try {
|
|
34
|
+
const backup = `${k}:unreadable`;
|
|
35
|
+
if (!(await Promise.resolve(storage.getItem(backup))))
|
|
36
|
+
await Promise.resolve(storage.setItem(backup, raw));
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
/* best effort */
|
|
40
|
+
}
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
const seen = new Set();
|
|
44
|
+
const out = [];
|
|
45
|
+
for (const v of parsed) {
|
|
46
|
+
const item = codec.read(v);
|
|
47
|
+
if (!item)
|
|
48
|
+
continue;
|
|
49
|
+
const id = codec.idOf(item);
|
|
50
|
+
if (seen.has(id))
|
|
51
|
+
continue;
|
|
52
|
+
seen.add(id);
|
|
53
|
+
out.push(item);
|
|
54
|
+
}
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
function serialize(items) {
|
|
58
|
+
let budget = exports.STORED_DETAILS_BUDGET;
|
|
59
|
+
return JSON.stringify(items.map((item) => {
|
|
60
|
+
const details = codec.detailsOf(item);
|
|
61
|
+
if (details == null)
|
|
62
|
+
return codec.write(item, details);
|
|
63
|
+
const size = JSON.stringify(details).length;
|
|
64
|
+
if (size > budget)
|
|
65
|
+
return codec.write(item, undefined);
|
|
66
|
+
budget -= size;
|
|
67
|
+
return codec.write(item, details);
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
async function save(items) {
|
|
71
|
+
if (!storage || !writable)
|
|
72
|
+
return false;
|
|
73
|
+
try {
|
|
74
|
+
await Promise.resolve(storage.setItem(key, serialize(items)));
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
// Storage full or unavailable: the list in memory stays correct regardless.
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
open(nextStorage, nextKey) {
|
|
84
|
+
storage = nextStorage;
|
|
85
|
+
key = nextKey;
|
|
86
|
+
writable = true;
|
|
87
|
+
},
|
|
88
|
+
async load() {
|
|
89
|
+
const items = await readList(key);
|
|
90
|
+
writable = items !== null;
|
|
91
|
+
return items !== null && items !== void 0 ? items : [];
|
|
92
|
+
},
|
|
93
|
+
async mergeOnce(items, keys) {
|
|
94
|
+
if (!storage || !writable || keys.length === 0)
|
|
95
|
+
return items;
|
|
96
|
+
const markerKey = `${key}:merged`;
|
|
97
|
+
let merged = [];
|
|
98
|
+
try {
|
|
99
|
+
const raw = await Promise.resolve(storage.getItem(markerKey));
|
|
100
|
+
const parsed = raw ? JSON.parse(raw) : [];
|
|
101
|
+
if (Array.isArray(parsed))
|
|
102
|
+
merged = parsed.filter((k) => typeof k === 'string');
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return items;
|
|
106
|
+
}
|
|
107
|
+
const pending = keys.filter((k) => k !== key && !merged.includes(k));
|
|
108
|
+
if (pending.length === 0)
|
|
109
|
+
return items;
|
|
110
|
+
const seen = new Set(items.map(codec.idOf));
|
|
111
|
+
const next = items.slice();
|
|
112
|
+
for (const k of pending) {
|
|
113
|
+
const found = await readList(k);
|
|
114
|
+
if (found === null)
|
|
115
|
+
return items;
|
|
116
|
+
for (const item of found) {
|
|
117
|
+
const id = codec.idOf(item);
|
|
118
|
+
if (seen.has(id))
|
|
119
|
+
continue;
|
|
120
|
+
seen.add(id);
|
|
121
|
+
next.push(item);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (next.length > items.length) {
|
|
125
|
+
// Newest first across the lists; entries without a date keep their order, last.
|
|
126
|
+
next.sort((a, b) => codec.addedAt(b) - codec.addedAt(a));
|
|
127
|
+
// Not recorded if it couldn't be stored: merged again next launch, which skips what's there.
|
|
128
|
+
if (!(await save(next)))
|
|
129
|
+
return next;
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
await Promise.resolve(storage.setItem(markerKey, JSON.stringify([...merged, ...pending])));
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
/* merged again next launch: entries already saved are skipped */
|
|
136
|
+
}
|
|
137
|
+
return next;
|
|
138
|
+
},
|
|
139
|
+
save,
|
|
140
|
+
async clear() {
|
|
141
|
+
if (!storage || !writable)
|
|
142
|
+
return;
|
|
143
|
+
try {
|
|
144
|
+
await Promise.resolve(storage.removeItem(key));
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
/* ignore */
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=storedList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storedList.js","sourceRoot":"","sources":["../src/storedList.ts"],"names":[],"mappings":";;;AAwCA,4CAqIC;AAhKD,iEAAiE;AACpD,QAAA,qBAAqB,GAAG,OAAS,CAAC;AA0B/C,SAAgB,gBAAgB,CAAI,KAAyB;IAC3D,IAAI,OAAO,GAAkC,IAAI,CAAC;IAClD,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,iGAAiG;IACjG,IAAI,QAAQ,GAAG,IAAI,CAAC;IAEpB,qFAAqF;IACrF,KAAK,UAAU,QAAQ,CAAC,CAAS;QAC/B,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,CAAC;QACxB,IAAI,GAAkB,CAAC;QACvB,IAAI,CAAC;YACH,GAAG,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAClD,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,CAAC,GAAG;YAAE,OAAO,EAAE,CAAC;QACpB,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,SAAS,CAAC;QACrB,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;YAC3B,IAAI,CAAC;gBACH,MAAM,MAAM,GAAG,GAAG,CAAC,aAAa,CAAC;gBACjC,IAAI,CAAC,CAAC,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;oBAAE,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,E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,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBACzD,6FAA6F;gBAC7F,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC;oBAAE,OAAO,IAAI,CAAC;YACvC,CAAC;YACD,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7F,CAAC;YAAC,MAAM,CAAC;gBACP,iEAAiE;YACnE,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAED,IAAI;QAEJ,KAAK,CAAC,KAAK;YACT,IAAI,CAAC,OAAO,IAAI,CAAC,QAAQ;gBAAE,OAAO;YAClC,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;YACjD,CAAC;YAAC,MAAM,CAAC;gBACP,YAAY;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/tileCredit.d.ts
CHANGED
|
@@ -8,12 +8,22 @@ export declare function moneyToCents(money: string | number): number;
|
|
|
8
8
|
export declare const DEFAULT_TILE_CREDIT_BASE_URL = "https://tile-credit.apptile.io";
|
|
9
9
|
export declare class TileCreditClient implements TileCreditAPI {
|
|
10
10
|
private readonly baseUrl;
|
|
11
|
-
private readonly
|
|
11
|
+
private readonly getAccessToken;
|
|
12
|
+
private readonly renewAccessToken;
|
|
12
13
|
private readonly shopDomain;
|
|
13
14
|
private readonly signal?;
|
|
14
15
|
private readonly timeoutMs;
|
|
15
16
|
constructor(config: TileCreditConfig);
|
|
17
|
+
/**
|
|
18
|
+
* One request with a token read just now. A 401 renews the token once (`renewAccessToken`) and sends
|
|
19
|
+
* the request again; a second 401, or no new token, is `unauthorized`. Nothing here signs anyone out:
|
|
20
|
+
* the service also answers 401 for a shop it doesn't know.
|
|
21
|
+
*/
|
|
16
22
|
private call;
|
|
23
|
+
/** A token from `source`, or `unauthorized` (signed out) / `network` (couldn't be renewed). */
|
|
24
|
+
private tokenOrThrow;
|
|
25
|
+
private send;
|
|
26
|
+
private read;
|
|
17
27
|
getWallet(): Promise<TileCreditWallet>;
|
|
18
28
|
getLedger(opts?: {
|
|
19
29
|
limit?: number;
|
|
@@ -24,7 +34,7 @@ export declare class TileCreditClient implements TileCreditAPI {
|
|
|
24
34
|
}>;
|
|
25
35
|
getConfig(): Promise<TileCreditPublicConfig>;
|
|
26
36
|
/**
|
|
27
|
-
* Ledger + gift-cards joined into one history feed
|
|
37
|
+
* Ledger + gift-cards joined into one history feed. Each redeem
|
|
28
38
|
* row gets `.card` populated with the masked info (last4 / status / expiry)
|
|
29
39
|
* so you can render "•••• adf7 · depleted" in one pass. Non-redeem rows
|
|
30
40
|
* pass through unchanged with `card: null`.
|
|
@@ -39,17 +49,21 @@ export declare class TileCreditClient implements TileCreditAPI {
|
|
|
39
49
|
}): Promise<TileCreditHistoryPage>;
|
|
40
50
|
redeem(input: TileCreditRedeemInput): Promise<TileCreditRedeemResult>;
|
|
41
51
|
}
|
|
42
|
-
/** Configure the
|
|
43
|
-
*
|
|
44
|
-
* customer (`token` is baked in for the lifetime of the instance). */
|
|
52
|
+
/** Configure the shared client. Safe to call multiple times — it replaces the instance. With a fixed
|
|
53
|
+
* `customerAccessToken`, configure again for each new token; with `getAccessToken` it stays fresh. */
|
|
45
54
|
export declare function configureTileCredit(config: TileCreditConfig): TileCreditAPI;
|
|
46
55
|
export declare function getTileCreditClient(): TileCreditAPI | null;
|
|
47
56
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
57
|
+
* @deprecated Use `useCartStoreCredit()` in a React app: it allows one Apply at a time, finds its card
|
|
58
|
+
* on the cart, and writes through the provider's cart queue (this writes to the cart directly, so the
|
|
59
|
+
* provider's cart state is stale until it reads the cart again). Kept for callers without React.
|
|
60
|
+
*
|
|
61
|
+
* Mints a gift card with the shared client and adds it to the cart, keeping the cart's other gift
|
|
62
|
+
* cards (`cartGiftCardCodesAdd`; this used `cartGiftCardCodesUpdate`, which took them off). The cart's
|
|
63
|
+
* country is set only when it has none (`countryFallback`, else the shop's), keeping its email, and the
|
|
64
|
+
* shopper when `customerAccessToken` is passed; it used to replace the identity with the country alone,
|
|
65
|
+
* which dropped both. Throws `TileCreditError('cart_refused')` when Shopify didn't put the card on the
|
|
66
|
+
* cart; the card then only holds the credit (nothing is charged), and the next redeem disables it.
|
|
53
67
|
*/
|
|
54
68
|
export declare function redeemAndApplyToCart(opts: {
|
|
55
69
|
cartId: string;
|
|
@@ -57,6 +71,7 @@ export declare function redeemAndApplyToCart(opts: {
|
|
|
57
71
|
idempotencyKey?: string;
|
|
58
72
|
reason?: string;
|
|
59
73
|
countryFallback?: string;
|
|
74
|
+
customerAccessToken?: string;
|
|
60
75
|
}): Promise<{
|
|
61
76
|
redeemed: TileCreditRedeemResult;
|
|
62
77
|
cart: Cart;
|
package/dist/tileCredit.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tileCredit.d.ts","sourceRoot":"","sources":["../src/tileCredit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tileCredit.d.ts","sourceRoot":"","sources":["../src/tileCredit.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,gBAAgB,EAIhB,qBAAqB,EACrB,wBAAwB,EAExB,oBAAoB,EACpB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAOjB;yDACyD;AACzD,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMlD;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,KAA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;;;GAWG;AACH,wBAAsB,oBAAoB,CAAC,IAAI,EAAE;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,mBAAmB,CAAC,EAAE,MAAM,CAAC;CAC9B,GAAG,OAAO,CAAC;IAAE,QAAQ,EAAE,sBAAsB,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CA2B5D"}
|
package/dist/tileCredit.js
CHANGED
|
@@ -9,15 +9,19 @@ exports.redeemAndApplyToCart = redeemAndApplyToCart;
|
|
|
9
9
|
/**
|
|
10
10
|
* Tile Credit — customer wallet + gift-card mint client.
|
|
11
11
|
*
|
|
12
|
-
* A typed, error-normalized wrapper around the tile-credit
|
|
13
|
-
*
|
|
14
|
-
* The service resolves shop → appId
|
|
15
|
-
* appId, only the shop domain + the customer access token.
|
|
12
|
+
* A typed, error-normalized wrapper around the tile-credit service (`https://tile-credit.apptile.io`).
|
|
13
|
+
* Talks to `/public/*` on behalf of one signed-in customer: `Authorization: Customer <token>` and
|
|
14
|
+
* `x-shopify-shop-domain`. The service resolves shop → appId itself.
|
|
16
15
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
16
|
+
* How the money moves (the service's reserve-at-mint model): **redeeming reserves, it doesn't charge.**
|
|
17
|
+
* `redeem` mints a Shopify gift card for the amount and reserves it; the wallet is charged only for
|
|
18
|
+
* what an order actually uses (`orders/create`), so the balance is unchanged by a redeem. One card is
|
|
19
|
+
* active per customer: a new redeem disables the previous one. The same idempotency key returns the
|
|
20
|
+
* same card (`duplicate: true`), but two redeems at once with different keys mint two cards, so a
|
|
21
|
+
* caller allows one at a time (`useCartStoreCredit` does).
|
|
22
|
+
*
|
|
23
|
+
* The token is read before every request (`getAccessToken`) and renewed once on a 401
|
|
24
|
+
* (`renewAccessToken`). This file is dependency-free (pure `fetch`).
|
|
21
25
|
*/
|
|
22
26
|
const client_1 = require("./client");
|
|
23
27
|
const cart_1 = require("./cart");
|
|
@@ -77,21 +81,58 @@ const DEFAULT_TIMEOUT = 20000;
|
|
|
77
81
|
exports.DEFAULT_TILE_CREDIT_BASE_URL = 'https://tile-credit.apptile.io';
|
|
78
82
|
class TileCreditClient {
|
|
79
83
|
constructor(config) {
|
|
80
|
-
var _a;
|
|
81
|
-
|
|
82
|
-
|
|
84
|
+
var _a, _b, _c;
|
|
85
|
+
const fixed = config.customerAccessToken;
|
|
86
|
+
if (!config.getAccessToken && !fixed)
|
|
87
|
+
throw new Error('TileCreditClient: getAccessToken or customerAccessToken is required');
|
|
83
88
|
if (!config.shopDomain)
|
|
84
89
|
throw new Error('TileCreditClient: shopDomain is required');
|
|
85
90
|
// baseUrl is optional — falls back to the hosted tile-credit service.
|
|
86
91
|
this.baseUrl = (config.baseUrl || exports.DEFAULT_TILE_CREDIT_BASE_URL).replace(/\/+$/, '');
|
|
87
|
-
this.
|
|
92
|
+
this.getAccessToken = (_a = config.getAccessToken) !== null && _a !== void 0 ? _a : (async () => fixed !== null && fixed !== void 0 ? fixed : null);
|
|
93
|
+
this.renewAccessToken = (_b = config.renewAccessToken) !== null && _b !== void 0 ? _b : null;
|
|
88
94
|
this.shopDomain = config.shopDomain.toLowerCase();
|
|
89
95
|
this.signal = config.signal;
|
|
90
|
-
this.timeoutMs = (
|
|
96
|
+
this.timeoutMs = (_c = config.timeoutMs) !== null && _c !== void 0 ? _c : DEFAULT_TIMEOUT;
|
|
91
97
|
}
|
|
92
98
|
// ─── HTTP core ──────────────────────────────────────────────────────────
|
|
99
|
+
/**
|
|
100
|
+
* One request with a token read just now. A 401 renews the token once (`renewAccessToken`) and sends
|
|
101
|
+
* the request again; a second 401, or no new token, is `unauthorized`. Nothing here signs anyone out:
|
|
102
|
+
* the service also answers 401 for a shop it doesn't know.
|
|
103
|
+
*/
|
|
93
104
|
async call(path, init = {}) {
|
|
94
|
-
|
|
105
|
+
const token = await this.tokenOrThrow(() => this.getAccessToken());
|
|
106
|
+
const first = await this.send(path, init, token);
|
|
107
|
+
if (first.status !== 401 || !this.renewAccessToken)
|
|
108
|
+
return this.read(first);
|
|
109
|
+
const renew = this.renewAccessToken;
|
|
110
|
+
const renewed = await this.tokenOrThrow(() => renew()).catch((error) => {
|
|
111
|
+
// No new token: the service's own answer stands.
|
|
112
|
+
if (error instanceof types_1.TileCreditError && error.code === 'unauthorized')
|
|
113
|
+
return null;
|
|
114
|
+
throw error;
|
|
115
|
+
});
|
|
116
|
+
if (!renewed)
|
|
117
|
+
return this.read(first);
|
|
118
|
+
return this.read(await this.send(path, init, renewed));
|
|
119
|
+
}
|
|
120
|
+
/** A token from `source`, or `unauthorized` (signed out) / `network` (couldn't be renewed). */
|
|
121
|
+
async tokenOrThrow(source) {
|
|
122
|
+
let token;
|
|
123
|
+
try {
|
|
124
|
+
token = await source();
|
|
125
|
+
}
|
|
126
|
+
catch (error) {
|
|
127
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
128
|
+
throw new types_1.TileCreditError('network', `Couldn't get the customer's token: ${msg}`);
|
|
129
|
+
}
|
|
130
|
+
if (!token)
|
|
131
|
+
throw new types_1.TileCreditError('unauthorized', 'No signed-in customer');
|
|
132
|
+
return token;
|
|
133
|
+
}
|
|
134
|
+
async send(path, init, token) {
|
|
135
|
+
var _a;
|
|
95
136
|
// Combine the constructor signal with a per-request timeout signal so
|
|
96
137
|
// either can cancel the fetch; AbortController.abort() is idempotent.
|
|
97
138
|
const controller = new AbortController();
|
|
@@ -110,7 +151,7 @@ class TileCreditClient {
|
|
|
110
151
|
headers: {
|
|
111
152
|
'content-type': 'application/json',
|
|
112
153
|
accept: 'application/json',
|
|
113
|
-
Authorization: `Customer ${
|
|
154
|
+
Authorization: `Customer ${token}`,
|
|
114
155
|
'x-shopify-shop-domain': this.shopDomain,
|
|
115
156
|
},
|
|
116
157
|
body: init.body === undefined ? undefined : JSON.stringify(init.body),
|
|
@@ -126,16 +167,9 @@ class TileCreditClient {
|
|
|
126
167
|
body = { error: text.slice(0, 500) };
|
|
127
168
|
}
|
|
128
169
|
}
|
|
129
|
-
|
|
130
|
-
const code = statusToCode(res.status);
|
|
131
|
-
const msg = (body && (body.message || body.error)) || `${res.status} ${res.statusText}`;
|
|
132
|
-
throw new types_1.TileCreditError(code, msg, res.status, (_b = body === null || body === void 0 ? void 0 : body.details) !== null && _b !== void 0 ? _b : undefined);
|
|
133
|
-
}
|
|
134
|
-
return body;
|
|
170
|
+
return { status: res.status, ok: res.ok, statusText: res.statusText, body };
|
|
135
171
|
}
|
|
136
172
|
catch (e) {
|
|
137
|
-
if (e instanceof types_1.TileCreditError)
|
|
138
|
-
throw e;
|
|
139
173
|
// fetch throws on network / timeout / abort — normalize to `network`.
|
|
140
174
|
const msg = e instanceof Error ? e.message : String(e);
|
|
141
175
|
throw new types_1.TileCreditError('network', `${url} → ${msg}`);
|
|
@@ -146,7 +180,16 @@ class TileCreditClient {
|
|
|
146
180
|
this.signal.removeEventListener('abort', outerAbort);
|
|
147
181
|
}
|
|
148
182
|
}
|
|
149
|
-
|
|
183
|
+
read(res) {
|
|
184
|
+
var _a, _b;
|
|
185
|
+
if (!res.ok) {
|
|
186
|
+
const code = statusToCode(res.status);
|
|
187
|
+
const msg = (res.body && (res.body.message || res.body.error)) || `${res.status} ${res.statusText}`;
|
|
188
|
+
throw new types_1.TileCreditError(code, msg, res.status, (_b = (_a = res.body) === null || _a === void 0 ? void 0 : _a.details) !== null && _b !== void 0 ? _b : undefined);
|
|
189
|
+
}
|
|
190
|
+
return res.body;
|
|
191
|
+
}
|
|
192
|
+
// ─── Public API — one method per endpoint ───────────────────────────────
|
|
150
193
|
async getWallet() {
|
|
151
194
|
const raw = await this.call('/public/me');
|
|
152
195
|
return {
|
|
@@ -184,7 +227,7 @@ class TileCreditClient {
|
|
|
184
227
|
};
|
|
185
228
|
}
|
|
186
229
|
/**
|
|
187
|
-
* Ledger + gift-cards joined into one history feed
|
|
230
|
+
* Ledger + gift-cards joined into one history feed. Each redeem
|
|
188
231
|
* row gets `.card` populated with the masked info (last4 / status / expiry)
|
|
189
232
|
* so you can render "•••• adf7 · depleted" in one pass. Non-redeem rows
|
|
190
233
|
* pass through unchanged with `card: null`.
|
|
@@ -228,12 +271,11 @@ class TileCreditClient {
|
|
|
228
271
|
}
|
|
229
272
|
exports.TileCreditClient = TileCreditClient;
|
|
230
273
|
// ---------------------------------------------------------------------------
|
|
231
|
-
// Facade —
|
|
274
|
+
// Facade — one client for callers without React
|
|
232
275
|
// ---------------------------------------------------------------------------
|
|
233
276
|
let activeClient = null;
|
|
234
|
-
/** Configure the
|
|
235
|
-
*
|
|
236
|
-
* customer (`token` is baked in for the lifetime of the instance). */
|
|
277
|
+
/** Configure the shared client. Safe to call multiple times — it replaces the instance. With a fixed
|
|
278
|
+
* `customerAccessToken`, configure again for each new token; with `getAccessToken` it stays fresh. */
|
|
237
279
|
function configureTileCredit(config) {
|
|
238
280
|
activeClient = new TileCreditClient(config);
|
|
239
281
|
return activeClient;
|
|
@@ -242,33 +284,43 @@ function getTileCreditClient() {
|
|
|
242
284
|
return activeClient;
|
|
243
285
|
}
|
|
244
286
|
/**
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
287
|
+
* @deprecated Use `useCartStoreCredit()` in a React app: it allows one Apply at a time, finds its card
|
|
288
|
+
* on the cart, and writes through the provider's cart queue (this writes to the cart directly, so the
|
|
289
|
+
* provider's cart state is stale until it reads the cart again). Kept for callers without React.
|
|
290
|
+
*
|
|
291
|
+
* Mints a gift card with the shared client and adds it to the cart, keeping the cart's other gift
|
|
292
|
+
* cards (`cartGiftCardCodesAdd`; this used `cartGiftCardCodesUpdate`, which took them off). The cart's
|
|
293
|
+
* country is set only when it has none (`countryFallback`, else the shop's), keeping its email, and the
|
|
294
|
+
* shopper when `customerAccessToken` is passed; it used to replace the identity with the country alone,
|
|
295
|
+
* which dropped both. Throws `TileCreditError('cart_refused')` when Shopify didn't put the card on the
|
|
296
|
+
* cart; the card then only holds the credit (nothing is charged), and the next redeem disables it.
|
|
250
297
|
*/
|
|
251
298
|
async function redeemAndApplyToCart(opts) {
|
|
252
|
-
var _a
|
|
299
|
+
var _a;
|
|
253
300
|
if (!activeClient) {
|
|
254
301
|
throw new types_1.TileCreditError('unauthorized', 'Tile Credit not configured — call shopify.tileCredit.configure(...)');
|
|
255
302
|
}
|
|
256
|
-
// Ensure the Shopify SDK is initialized —
|
|
257
|
-
// to run cartBuyerIdentityUpdate + cartGiftCardCodesUpdate below.
|
|
303
|
+
// Ensure the Shopify SDK is initialized — its Storefront client writes the cart below.
|
|
258
304
|
(0, client_1.getConfig)(); // throws with a friendly message if init() wasn't called
|
|
259
|
-
|
|
305
|
+
const current = await cart_1.cart.get(opts.cartId);
|
|
306
|
+
if (!current)
|
|
307
|
+
throw new types_1.TileCreditError('cart_refused', 'The cart no longer exists');
|
|
308
|
+
// Mint the credit (the same key returns the same card, so a retry never mints a second).
|
|
260
309
|
const redeemed = await activeClient.redeem({
|
|
261
310
|
amountCents: opts.amountCents,
|
|
262
311
|
idempotencyKey: opts.idempotencyKey,
|
|
263
312
|
reason: (_a = opts.reason) !== null && _a !== void 0 ? _a : 'Wallet redemption',
|
|
264
313
|
});
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
314
|
+
const { cart, notApplied } = await (0, cart_1.addGiftCardsKeepingBuyer)(current, [redeemed.code], {
|
|
315
|
+
countryCode: async () => { var _a, _b; return (_b = (_a = opts.countryFallback) !== null && _a !== void 0 ? _a : (await money_1.shop.countryCode())) !== null && _b !== void 0 ? _b : 'US'; },
|
|
316
|
+
customerAccessToken: opts.customerAccessToken,
|
|
317
|
+
});
|
|
318
|
+
if (notApplied.length) {
|
|
319
|
+
throw new types_1.TileCreditError('cart_refused', `Shopify didn't apply the gift card ending in ${redeemed.last4}`, undefined, {
|
|
320
|
+
last4: redeemed.last4,
|
|
321
|
+
giftCardGid: redeemed.giftCardGid,
|
|
322
|
+
});
|
|
323
|
+
}
|
|
272
324
|
return { redeemed, cart };
|
|
273
325
|
}
|
|
274
326
|
//# sourceMappingURL=tileCredit.js.map
|
package/dist/tileCredit.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tileCredit.js","sourceRoot":"","sources":["../src/tileCredit.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"tileCredit.js","sourceRoot":"","sources":["../src/tileCredit.ts"],"names":[],"mappings":";;;AA4CA,oCAMC;AAGD,oCAIC;AAwOD,kDAGC;AAED,kDAEC;AAcD,oDAkCC;AAxVD;;;;;;;;;;;;;;;;GAgBG;AACH,qCAAqC;AACrC,iCAAmE;AACnE,mCAA+B;AAiB/B,mCAA0C;AAE1C,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;yDACyD;AACzD,SAAgB,YAAY,CAAC,KAAa;IACxC,MAAM,IAAI,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;IAClC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IACpC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAChD,OAAO,GAAG,IAAI,GAAG,KAAK,IAAI,IAAI,EAAE,CAAC;AACnC,CAAC;AAED,qEAAqE;AACrE,SAAgB,YAAY,CAAC,KAAsB;IACjD,MAAM,CAAC,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAA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