@tiledev/sdk-shopify 0.2.5
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/LICENSE +21 -0
- package/README.md +269 -0
- package/dist/blogs.d.ts +3 -0
- package/dist/blogs.d.ts.map +1 -0
- package/dist/blogs.js +72 -0
- package/dist/blogs.js.map +1 -0
- package/dist/cart.d.ts +3 -0
- package/dist/cart.d.ts.map +1 -0
- package/dist/cart.js +96 -0
- package/dist/cart.js.map +1 -0
- package/dist/cartPolicy.d.ts +15 -0
- package/dist/cartPolicy.d.ts.map +1 -0
- package/dist/cartPolicy.js +74 -0
- package/dist/cartPolicy.js.map +1 -0
- package/dist/client.d.ts +15 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +130 -0
- package/dist/client.js.map +1 -0
- package/dist/collections.d.ts +3 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +44 -0
- package/dist/collections.js.map +1 -0
- package/dist/customer.d.ts +3 -0
- package/dist/customer.d.ts.map +1 -0
- package/dist/customer.js +124 -0
- package/dist/customer.js.map +1 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +63 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/messages.d.ts +24 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +81 -0
- package/dist/messages.js.map +1 -0
- package/dist/money.d.ts +18 -0
- package/dist/money.d.ts.map +1 -0
- package/dist/money.js +93 -0
- package/dist/money.js.map +1 -0
- package/dist/products.d.ts +6 -0
- package/dist/products.d.ts.map +1 -0
- package/dist/products.js +193 -0
- package/dist/products.js.map +1 -0
- package/dist/queries.d.ts +55 -0
- package/dist/queries.d.ts.map +1 -0
- package/dist/queries.js +582 -0
- package/dist/queries.js.map +1 -0
- package/dist/react/ShopifyProvider.d.ts +181 -0
- package/dist/react/ShopifyProvider.d.ts.map +1 -0
- package/dist/react/ShopifyProvider.js +785 -0
- package/dist/react/ShopifyProvider.js.map +1 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +14 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/useTileCredit.d.ts +34 -0
- package/dist/react/useTileCredit.d.ts.map +1 -0
- package/dist/react/useTileCredit.js +96 -0
- package/dist/react/useTileCredit.js.map +1 -0
- package/dist/shopify.d.ts +3 -0
- package/dist/shopify.d.ts.map +1 -0
- package/dist/shopify.js +54 -0
- package/dist/shopify.js.map +1 -0
- package/dist/tileCredit.d.ts +64 -0
- package/dist/tileCredit.d.ts.map +1 -0
- package/dist/tileCredit.js +274 -0
- package/dist/tileCredit.js.map +1 -0
- package/dist/types.d.ts +785 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +25 -0
- package/dist/types.js.map +1 -0
- package/dist/variants.d.ts +3 -0
- package/dist/variants.d.ts.map +1 -0
- package/dist/variants.js +67 -0
- package/dist/variants.js.map +1 -0
- package/dist/wishlist.d.ts +4 -0
- package/dist/wishlist.d.ts.map +1 -0
- package/dist/wishlist.js +232 -0
- package/dist/wishlist.js.map +1 -0
- package/package.json +63 -0
- package/react/package.json +6 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setShopInfo = setShopInfo;
|
|
4
|
+
exports.getMoneyFormat = getMoneyFormat;
|
|
5
|
+
exports.getCurrencyCode = getCurrencyCode;
|
|
6
|
+
exports.setConfig = setConfig;
|
|
7
|
+
exports.getConfig = getConfig;
|
|
8
|
+
exports.isConfigured = isConfigured;
|
|
9
|
+
exports.request = request;
|
|
10
|
+
exports.assertNoUserErrors = assertNoUserErrors;
|
|
11
|
+
const types_1 = require("./types");
|
|
12
|
+
const state = { config: null, moneyFormat: null, currencyCode: null };
|
|
13
|
+
function setShopInfo(info) {
|
|
14
|
+
if (info.moneyFormat)
|
|
15
|
+
state.moneyFormat = info.moneyFormat;
|
|
16
|
+
if (info.currencyCode)
|
|
17
|
+
state.currencyCode = info.currencyCode;
|
|
18
|
+
}
|
|
19
|
+
/** Null until the shop query resolves. */
|
|
20
|
+
function getMoneyFormat() {
|
|
21
|
+
return state.moneyFormat;
|
|
22
|
+
}
|
|
23
|
+
function getCurrencyCode() {
|
|
24
|
+
return state.currencyCode;
|
|
25
|
+
}
|
|
26
|
+
const DEFAULT_API_VERSION = '2024-10';
|
|
27
|
+
function setConfig(config) {
|
|
28
|
+
if (!config.storeDomain)
|
|
29
|
+
throw new Error('shopify.init: storeDomain is required');
|
|
30
|
+
if (!config.storefrontAccessToken)
|
|
31
|
+
throw new Error('shopify.init: storefrontAccessToken is required');
|
|
32
|
+
state.config = config;
|
|
33
|
+
}
|
|
34
|
+
function getConfig() {
|
|
35
|
+
if (!state.config)
|
|
36
|
+
throw new types_1.ShopifyError('shopify.init() must be called before any other method');
|
|
37
|
+
return state.config;
|
|
38
|
+
}
|
|
39
|
+
function isConfigured() {
|
|
40
|
+
return state.config !== null;
|
|
41
|
+
}
|
|
42
|
+
function endpoint() {
|
|
43
|
+
const c = getConfig();
|
|
44
|
+
const version = c.apiVersion || DEFAULT_API_VERSION;
|
|
45
|
+
return `https://${c.storeDomain}/api/${version}/graphql.json`;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Fragments are composed via template literals, so one included by two parents is
|
|
49
|
+
* emitted twice — Shopify rejects that with "Fragment name X must be unique."
|
|
50
|
+
* Keeps the first definition of each name.
|
|
51
|
+
*/
|
|
52
|
+
function deduplicateFragments(operation) {
|
|
53
|
+
const seen = new Set();
|
|
54
|
+
let result = '';
|
|
55
|
+
let i = 0;
|
|
56
|
+
while (i < operation.length) {
|
|
57
|
+
const idx = operation.indexOf('fragment ', i);
|
|
58
|
+
if (idx === -1) {
|
|
59
|
+
result += operation.slice(i);
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
result += operation.slice(i, idx);
|
|
63
|
+
const afterKeyword = idx + 'fragment '.length;
|
|
64
|
+
const nameMatch = operation.slice(afterKeyword).match(/^([A-Za-z_][A-Za-z0-9_]*)/);
|
|
65
|
+
if (!nameMatch) {
|
|
66
|
+
result += operation.slice(idx);
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
const name = nameMatch[1];
|
|
70
|
+
const openBrace = operation.indexOf('{', afterKeyword + name.length);
|
|
71
|
+
if (openBrace === -1) {
|
|
72
|
+
result += operation.slice(idx);
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
let depth = 1;
|
|
76
|
+
let j = openBrace + 1;
|
|
77
|
+
while (j < operation.length && depth > 0) {
|
|
78
|
+
const ch = operation[j];
|
|
79
|
+
if (ch === '{')
|
|
80
|
+
depth++;
|
|
81
|
+
else if (ch === '}')
|
|
82
|
+
depth--;
|
|
83
|
+
j++;
|
|
84
|
+
}
|
|
85
|
+
const fragmentBlock = operation.slice(idx, j);
|
|
86
|
+
if (!seen.has(name)) {
|
|
87
|
+
seen.add(name);
|
|
88
|
+
result += fragmentBlock;
|
|
89
|
+
}
|
|
90
|
+
i = j;
|
|
91
|
+
}
|
|
92
|
+
return result;
|
|
93
|
+
}
|
|
94
|
+
async function request(operation, variables) {
|
|
95
|
+
const c = getConfig();
|
|
96
|
+
const query = deduplicateFragments(operation);
|
|
97
|
+
const res = await fetch(endpoint(), {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
headers: {
|
|
100
|
+
'Content-Type': 'application/json',
|
|
101
|
+
'X-Shopify-Storefront-Access-Token': c.storefrontAccessToken,
|
|
102
|
+
'Accept': 'application/json',
|
|
103
|
+
'Accept-Language': c.language || 'en',
|
|
104
|
+
},
|
|
105
|
+
body: JSON.stringify({ query, variables: variables !== null && variables !== void 0 ? variables : {} }),
|
|
106
|
+
});
|
|
107
|
+
if (!res.ok) {
|
|
108
|
+
let bodyText = '';
|
|
109
|
+
try {
|
|
110
|
+
bodyText = await res.text();
|
|
111
|
+
}
|
|
112
|
+
catch { /* ignore */ }
|
|
113
|
+
throw new types_1.ShopifyError(`Shopify Storefront API HTTP ${res.status}: ${res.statusText}${bodyText ? ` — ${bodyText.slice(0, 200)}` : ''}`);
|
|
114
|
+
}
|
|
115
|
+
const json = (await res.json());
|
|
116
|
+
if (json.errors && json.errors.length > 0) {
|
|
117
|
+
throw new types_1.ShopifyError(`GraphQL error: ${json.errors.map((e) => e.message).join('; ')}`);
|
|
118
|
+
}
|
|
119
|
+
if (json.data === undefined || json.data === null) {
|
|
120
|
+
throw new types_1.ShopifyError('GraphQL response had no `data` field');
|
|
121
|
+
}
|
|
122
|
+
return json.data;
|
|
123
|
+
}
|
|
124
|
+
/** Throws if a Shopify mutation payload contains userErrors. */
|
|
125
|
+
function assertNoUserErrors(label, errors) {
|
|
126
|
+
if (errors && errors.length > 0) {
|
|
127
|
+
throw new types_1.ShopifyError(`${label} failed: ${errors.map((e) => e.message).join('; ')}`, errors);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;AAWA,kCAGC;AAGD,wCAEC;AAED,0CAEC;AAID,8BAIC;AAED,8BAGC;AAED,oCAEC;AA4DD,0BAgCC;AAGD,gDAOC;AA9ID,mCAAiE;AASjE,MAAM,KAAK,GAAkB,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;AAErF,SAAgB,WAAW,CAAC,IAAmE;IAC7F,IAAI,IAAI,CAAC,WAAW;QAAE,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;IAC3D,IAAI,IAAI,CAAC,YAAY;QAAE,KAAK,CAAC,YAA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,MAAM,GAAG,CAAC,IAAI,EAAE,CAAuB,CAAC;IACtD,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,oBAAY,CACpB,kBAAkB,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACjE,CAAC;IACJ,CAAC;IACD,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAClD,MAAM,IAAI,oBAAY,CAAC,sCAAsC,CAAC,CAAC;IACjE,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC;AACnB,CAAC;AAED,gEAAgE;AAChE,SAAgB,kBAAkB,CAAC,KAAa,EAAE,MAAsC;IACtF,IAAI,MAAM,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,oBAAY,CACpB,GAAG,KAAK,YAAY,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAC7D,MAAM,CACP,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.d.ts","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAOV,qBAAqB,EACtB,MAAM,SAAS,CAAC;AAcjB,eAAO,MAAM,WAAW,EAAE,qBAoCzB,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collections = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
const products_1 = require("./products");
|
|
6
|
+
const queries_1 = require("./queries");
|
|
7
|
+
exports.collections = {
|
|
8
|
+
async list(opts) {
|
|
9
|
+
var _a, _b;
|
|
10
|
+
const data = await (0, client_1.request)(queries_1.COLLECTIONS_LIST_QUERY, {
|
|
11
|
+
first: (_a = opts === null || opts === void 0 ? void 0 : opts.first) !== null && _a !== void 0 ? _a : 20,
|
|
12
|
+
after: opts === null || opts === void 0 ? void 0 : opts.after,
|
|
13
|
+
query: opts === null || opts === void 0 ? void 0 : opts.query,
|
|
14
|
+
sortKey: opts === null || opts === void 0 ? void 0 : opts.sortKey,
|
|
15
|
+
reverse: (_b = opts === null || opts === void 0 ? void 0 : opts.reverse) !== null && _b !== void 0 ? _b : false,
|
|
16
|
+
});
|
|
17
|
+
return data.collections;
|
|
18
|
+
},
|
|
19
|
+
async byHandle(handle) {
|
|
20
|
+
const data = await (0, client_1.request)(queries_1.COLLECTION_BY_HANDLE_QUERY, { handle });
|
|
21
|
+
return data.collection;
|
|
22
|
+
},
|
|
23
|
+
async products(handle, opts) {
|
|
24
|
+
var _a, _b, _c;
|
|
25
|
+
const data = await (0, client_1.request)(queries_1.COLLECTION_PRODUCTS_QUERY, {
|
|
26
|
+
handle,
|
|
27
|
+
first: (_a = opts === null || opts === void 0 ? void 0 : opts.first) !== null && _a !== void 0 ? _a : 20,
|
|
28
|
+
after: opts === null || opts === void 0 ? void 0 : opts.after,
|
|
29
|
+
sortKey: opts === null || opts === void 0 ? void 0 : opts.sortKey,
|
|
30
|
+
reverse: (_b = opts === null || opts === void 0 ? void 0 : opts.reverse) !== null && _b !== void 0 ? _b : false,
|
|
31
|
+
filters: opts === null || opts === void 0 ? void 0 : opts.filters,
|
|
32
|
+
});
|
|
33
|
+
if (!data.collection) {
|
|
34
|
+
return { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false, startCursor: null, endCursor: null }, filters: [] };
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
nodes: data.collection.products.nodes.map(products_1.normalizeProduct),
|
|
38
|
+
pageInfo: data.collection.products.pageInfo,
|
|
39
|
+
filters: (_c = data.collection.products.filters) !== null && _c !== void 0 ? _c : [],
|
|
40
|
+
collection: { handle: data.collection.handle, title: data.collection.title },
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=collections.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"collections.js","sourceRoot":"","sources":["../src/collections.ts"],"names":[],"mappings":";;;AAAA,qCAAmC;AACnC,yCAA8C;AAC9C,uCAImB;AAuBN,QAAA,WAAW,GAA0B;IAChD,KAAK,CAAC,IAAI,CAAC,IAAkB;;QAC3B,MAAM,IAAI,GAAG,MAAM,IAAA,gBAAO,EAAiB,gCAAsB,EAAE;YACjE,KAAK,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,mCAAI,EAAE;YACxB,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK;YAClB,KAAK,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK;YAClB,OAAO,EAAE,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO;YACtB,OAAO,EAAE,MAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,mCAAI,KAAK;SAChC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc;QAC3B,MAAM,IAAI,GAAG,MAAM,IAAA,gBAAO,EAAgB,oCAA0B,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;QAClF,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAc,EAAE,IAAkB;;QAC/C,MAAM,IAAI,GAAG,MAAM,IAAA,gBAAO,EAAwB,mCAAyB,EAAE;YAC3E,MAAM;YACN,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,CAAC"}
|
package/dist/customer.js
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.customer = void 0;
|
|
4
|
+
const client_1 = require("./client");
|
|
5
|
+
const queries_1 = require("./queries");
|
|
6
|
+
function normalizeOrder(o) {
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
8
|
+
return {
|
|
9
|
+
id: o.id,
|
|
10
|
+
orderNumber: o.orderNumber,
|
|
11
|
+
name: o.name,
|
|
12
|
+
processedAt: o.processedAt,
|
|
13
|
+
fulfillmentStatus: (_a = o.fulfillmentStatus) !== null && _a !== void 0 ? _a : null,
|
|
14
|
+
financialStatus: (_b = o.financialStatus) !== null && _b !== void 0 ? _b : null,
|
|
15
|
+
statusUrl: o.statusUrl,
|
|
16
|
+
currencyCode: o.currencyCode,
|
|
17
|
+
email: (_c = o.email) !== null && _c !== void 0 ? _c : null,
|
|
18
|
+
phone: (_d = o.phone) !== null && _d !== void 0 ? _d : null,
|
|
19
|
+
totalPrice: o.totalPrice,
|
|
20
|
+
subtotalPrice: (_e = o.subtotalPrice) !== null && _e !== void 0 ? _e : null,
|
|
21
|
+
totalShippingPrice: o.totalShippingPrice,
|
|
22
|
+
totalTax: (_f = o.totalTax) !== null && _f !== void 0 ? _f : null,
|
|
23
|
+
totalRefunded: o.totalRefunded,
|
|
24
|
+
shippingAddress: (_g = o.shippingAddress) !== null && _g !== void 0 ? _g : null,
|
|
25
|
+
lineItems: ((_j = (_h = o.lineItems) === null || _h === void 0 ? void 0 : _h.nodes) !== null && _j !== void 0 ? _j : []).map((line) => {
|
|
26
|
+
var _a;
|
|
27
|
+
return ({
|
|
28
|
+
title: line.title,
|
|
29
|
+
quantity: line.quantity,
|
|
30
|
+
variant: (_a = line.variant) !== null && _a !== void 0 ? _a : null,
|
|
31
|
+
originalTotalPrice: line.originalTotalPrice,
|
|
32
|
+
discountedTotalPrice: line.discountedTotalPrice,
|
|
33
|
+
});
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
exports.customer = {
|
|
38
|
+
async signup(input) {
|
|
39
|
+
var _a;
|
|
40
|
+
const created = await (0, client_1.request)(queries_1.CUSTOMER_CREATE_MUTATION, {
|
|
41
|
+
input: {
|
|
42
|
+
email: input.email,
|
|
43
|
+
password: input.password,
|
|
44
|
+
firstName: input.firstName,
|
|
45
|
+
lastName: input.lastName,
|
|
46
|
+
acceptsMarketing: (_a = input.acceptsMarketing) !== null && _a !== void 0 ? _a : false,
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
(0, client_1.assertNoUserErrors)('customerCreate', created.customerCreate.customerUserErrors);
|
|
50
|
+
if (!created.customerCreate.customer) {
|
|
51
|
+
throw new Error('customerCreate returned no customer');
|
|
52
|
+
}
|
|
53
|
+
// Signup does not auto-login, so mint a token.
|
|
54
|
+
const accessToken = await this.login({ email: input.email, password: input.password });
|
|
55
|
+
return { customer: created.customerCreate.customer, accessToken };
|
|
56
|
+
},
|
|
57
|
+
async login(input) {
|
|
58
|
+
const data = await (0, client_1.request)(queries_1.CUSTOMER_ACCESS_TOKEN_CREATE_MUTATION, {
|
|
59
|
+
input: { email: input.email, password: input.password },
|
|
60
|
+
});
|
|
61
|
+
(0, client_1.assertNoUserErrors)('customerAccessTokenCreate', data.customerAccessTokenCreate.customerUserErrors);
|
|
62
|
+
if (!data.customerAccessTokenCreate.customerAccessToken) {
|
|
63
|
+
throw new Error('customerAccessTokenCreate returned no token');
|
|
64
|
+
}
|
|
65
|
+
return data.customerAccessTokenCreate.customerAccessToken;
|
|
66
|
+
},
|
|
67
|
+
async logout(accessToken) {
|
|
68
|
+
var _a;
|
|
69
|
+
const data = await (0, client_1.request)(queries_1.CUSTOMER_ACCESS_TOKEN_DELETE_MUTATION, {
|
|
70
|
+
customerAccessToken: accessToken,
|
|
71
|
+
});
|
|
72
|
+
if (((_a = data.customerAccessTokenDelete.userErrors) === null || _a === void 0 ? void 0 : _a.length) > 0) {
|
|
73
|
+
// Logout should succeed regardless.
|
|
74
|
+
// eslint-disable-next-line no-console
|
|
75
|
+
console.warn('[shopify.customer.logout]', data.customerAccessTokenDelete.userErrors);
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
async profile(accessToken) {
|
|
79
|
+
const data = await (0, client_1.request)(queries_1.CUSTOMER_QUERY, { accessToken });
|
|
80
|
+
return data.customer;
|
|
81
|
+
},
|
|
82
|
+
async recoverPassword(email) {
|
|
83
|
+
const data = await (0, client_1.request)(queries_1.CUSTOMER_RECOVER_MUTATION, { email });
|
|
84
|
+
(0, client_1.assertNoUserErrors)('customerRecover', data.customerRecover.customerUserErrors);
|
|
85
|
+
},
|
|
86
|
+
async updateProfile(accessToken, patch) {
|
|
87
|
+
const data = await (0, client_1.request)(queries_1.CUSTOMER_UPDATE_MUTATION, {
|
|
88
|
+
accessToken,
|
|
89
|
+
customer: {
|
|
90
|
+
firstName: patch.firstName,
|
|
91
|
+
lastName: patch.lastName,
|
|
92
|
+
phone: patch.phone,
|
|
93
|
+
acceptsMarketing: patch.acceptsMarketing,
|
|
94
|
+
},
|
|
95
|
+
});
|
|
96
|
+
(0, client_1.assertNoUserErrors)('customerUpdate', data.customerUpdate.customerUserErrors);
|
|
97
|
+
if (!data.customerUpdate.customer) {
|
|
98
|
+
throw new Error('customerUpdate returned no customer');
|
|
99
|
+
}
|
|
100
|
+
return data.customerUpdate.customer;
|
|
101
|
+
},
|
|
102
|
+
async orders(accessToken, opts) {
|
|
103
|
+
var _a;
|
|
104
|
+
const data = await (0, client_1.request)(queries_1.CUSTOMER_ORDERS_QUERY, {
|
|
105
|
+
accessToken,
|
|
106
|
+
first: (_a = opts === null || opts === void 0 ? void 0 : opts.first) !== null && _a !== void 0 ? _a : 20,
|
|
107
|
+
after: opts === null || opts === void 0 ? void 0 : opts.after,
|
|
108
|
+
});
|
|
109
|
+
if (!data.customer) {
|
|
110
|
+
return { nodes: [], pageInfo: { hasNextPage: false, hasPreviousPage: false, startCursor: null, endCursor: null } };
|
|
111
|
+
}
|
|
112
|
+
return {
|
|
113
|
+
nodes: data.customer.orders.nodes.map(normalizeOrder),
|
|
114
|
+
pageInfo: data.customer.orders.pageInfo,
|
|
115
|
+
};
|
|
116
|
+
},
|
|
117
|
+
async orderById(accessToken, orderId) {
|
|
118
|
+
var _a;
|
|
119
|
+
// Storefront API does not expose an order-by-id query; fetch list and filter.
|
|
120
|
+
const list = await this.orders(accessToken, { first: 250 });
|
|
121
|
+
return (_a = list.nodes.find((o) => o.id === orderId)) !== null && _a !== void 0 ? _a : null;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=customer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"customer.js","sourceRoot":"","sources":["../src/customer.ts"],"names":[],"mappings":";;;AAAA,qCAAuD;AACvD,uCAQmB;AAiCnB,SAAS,cAAc,CAAC,CAAM;;IAC5B,OAAO;QACL,EAAE,EAAE,CAAC,CAAC,EAAE;QACR,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,WAAW,EAAE,CAAC,CAAC,WAAW;QAC1B,iBAAiB,EAAE,MAAA,CAAC,CAAC,iBAAiB,mCAAI,IAAI;QAC9C,eAAe,EAAE,MAAA,CAAC,CAAC,eAAe,mCAAI,IAAI;QAC1C,SAAS,EAAE,CAAC,CAAC,SAAS;QACtB,YAAY,EAAE,CAAC,CAAC,YAAY;QAC5B,KAAK,EAAE,MAAA,CAAC,CAAC,KAAK,mCAAI,IAAI;QACtB,KAAK,EAAE,MAAA,CAAC,CAAC,KAAK,mCAAI,IAAI;QACtB,UAAU,EAAE,CAAC,CAAC,UAAU;QACxB,aAAa,EAAE,MAAA,CAAC,CAAC,aAAa,mCAAI,IAAI;QACtC,kBAAkB,EAAE,CAAC,CAAC,kBAAkB;QACxC,QAAQ,E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AAW,EAAE,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,WAAW,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,CAAC;QACrH,CAAC;QACD,OAAO;YACL,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,cAAc,CAAC;YACrD,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ;SACxC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,WAAmB,EAAE,OAAe;;QAClD,8EAA8E;QAC9E,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;QAC5D,OAAO,MAAA,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,mCAAI,IAAI,CAAC;IAC1D,CAAC;CACF,CAAC"}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AuthFailureReason, UserError } from './types';
|
|
2
|
+
/** Shopify rejected the CONTENTS of a mutation, as opposed to failing to answer
|
|
3
|
+
* it — only `userErrors` populate `errors[]`, so transport and GraphQL
|
|
4
|
+
* failures arrive empty. */
|
|
5
|
+
export declare function isUserErrorRejection(error: unknown): boolean;
|
|
6
|
+
export declare function userErrorsOf(error: unknown): UserError[];
|
|
7
|
+
/**
|
|
8
|
+
* True when a cart write failed because the merchandise cannot be sold right
|
|
9
|
+
* now. Shopify's own codes are checked first; the message sniff is the fallback
|
|
10
|
+
* for the storefront responses that carry no code.
|
|
11
|
+
*/
|
|
12
|
+
export declare function isOutOfStockError(error: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Which auth alert a failed customer mutation deserves. `invalid-credentials`
|
|
15
|
+
* is Shopify's `UNIDENTIFIED_CUSTOMER`; everything else stays `unknown` so the
|
|
16
|
+
* caller can decide between generic copy and the raw error.
|
|
17
|
+
*/
|
|
18
|
+
export declare function classifyAuthFailure(error: unknown): AuthFailureReason;
|
|
19
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE5D;;6BAE6B;AAC7B,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAE5D;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,EAAE,CAExD;AAUD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAWzD;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,iBAAiB,CAUrE"}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isUserErrorRejection = isUserErrorRejection;
|
|
4
|
+
exports.userErrorsOf = userErrorsOf;
|
|
5
|
+
exports.isOutOfStockError = isOutOfStockError;
|
|
6
|
+
exports.classifyAuthFailure = classifyAuthFailure;
|
|
7
|
+
// Turning Shopify's rejections into something a screen can act on.
|
|
8
|
+
//
|
|
9
|
+
// `assertNoUserErrors` flattens a mutation's `userErrors` into one
|
|
10
|
+
// `ShopifyError` whose message is prose — fine for logs, useless for choosing
|
|
11
|
+
// between "Out of stock" and "Something went wrong". The codes survive on
|
|
12
|
+
// `ShopifyError.errors[]`, so classification reads them back out.
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
/** Shopify rejected the CONTENTS of a mutation, as opposed to failing to answer
|
|
15
|
+
* it — only `userErrors` populate `errors[]`, so transport and GraphQL
|
|
16
|
+
* failures arrive empty. */
|
|
17
|
+
function isUserErrorRejection(error) {
|
|
18
|
+
return error instanceof types_1.ShopifyError && error.errors.length > 0;
|
|
19
|
+
}
|
|
20
|
+
function userErrorsOf(error) {
|
|
21
|
+
return error instanceof types_1.ShopifyError ? error.errors : [];
|
|
22
|
+
}
|
|
23
|
+
function hasCode(errors, ...codes) {
|
|
24
|
+
return errors.some((e) => !!e.code && codes.includes(e.code));
|
|
25
|
+
}
|
|
26
|
+
function messageMatches(errors, pattern) {
|
|
27
|
+
return errors.some((e) => pattern.test(e.message || ''));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* True when a cart write failed because the merchandise cannot be sold right
|
|
31
|
+
* now. Shopify's own codes are checked first; the message sniff is the fallback
|
|
32
|
+
* for the storefront responses that carry no code.
|
|
33
|
+
*/
|
|
34
|
+
function isOutOfStockError(error) {
|
|
35
|
+
const errors = userErrorsOf(error);
|
|
36
|
+
if (errors.length === 0)
|
|
37
|
+
return false;
|
|
38
|
+
return (hasCode(errors, 'MERCHANDISE_OUT_OF_STOCK', 'MERCHANDISE_NOT_ENOUGH_STOCK', 'PRODUCT_NOT_AVAILABLE') || messageMatches(errors, /out of stock|not enough (units|stock)|sold out|unavailable/i));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Which auth alert a failed customer mutation deserves. `invalid-credentials`
|
|
42
|
+
* is Shopify's `UNIDENTIFIED_CUSTOMER`; everything else stays `unknown` so the
|
|
43
|
+
* caller can decide between generic copy and the raw error.
|
|
44
|
+
*/
|
|
45
|
+
function classifyAuthFailure(error) {
|
|
46
|
+
const errors = userErrorsOf(error);
|
|
47
|
+
if (errors.length === 0)
|
|
48
|
+
return 'unknown';
|
|
49
|
+
if (hasCode(errors, 'UNIDENTIFIED_CUSTOMER'))
|
|
50
|
+
return 'invalid-credentials';
|
|
51
|
+
if (hasCode(errors, 'TAKEN'))
|
|
52
|
+
return 'email-taken';
|
|
53
|
+
if (hasCode(errors, 'TOO_SHORT', 'TOO_LONG', 'INVALID', 'BLANK'))
|
|
54
|
+
return 'invalid-input';
|
|
55
|
+
if (hasCode(errors, 'CUSTOMER_DISABLED'))
|
|
56
|
+
return 'account-disabled';
|
|
57
|
+
if (messageMatches(errors, /unidentified|incorrect email or password/i))
|
|
58
|
+
return 'invalid-credentials';
|
|
59
|
+
if (messageMatches(errors, /already been taken|has an account/i))
|
|
60
|
+
return 'email-taken';
|
|
61
|
+
return 'unknown';
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":";;AAYA,oDAEC;AAED,oCAEC;AAeD,8CAWC;AAOD,kDAUC;AA7DD,mEAAmE;AACnE,EAAE;AACF,mEAAmE;AACnE,8EAA8E;AAC9E,0EAA0E;AAC1E,kEAAkE;AAClE,mCAAuC;AAGvC;;6BAE6B;AAC7B,SAAgB,oBAAoB,CAAC,KAAc;IACjD,OAAO,KAAK,YAAY,oBAAY,IAAI,KAAK,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,YAAY,CAAC,KAAc;IACzC,OAAO,KAAK,YAAY,oBAAY,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3D,CAAC;AAED,SAAS,OAAO,CAAC,MAAmB,EAAE,GAAG,KAAe;IACtD,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,SAAS,cAAc,CAAC,MAAmB,EAAE,OAAe;IAC1D,OAAO,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAA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money';
|
|
3
|
+
export { getMoneyFormat, getCurrencyCode } from './client';
|
|
4
|
+
export { DEFAULT_MESSAGES, message, getMessages, setMessages, patchMessages, setMessageResolver, limitExceededMessage, } from './messages';
|
|
5
|
+
export { setCartPolicy, getCartPolicy, maxLineItems, projectedLineCount, wouldExceedLineLimit, } from './cartPolicy';
|
|
6
|
+
export { classifyAuthFailure, isOutOfStockError, isUserErrorRejection, userErrorsOf, } from './errors';
|
|
7
|
+
export { TileCreditClient, configureTileCredit, getTileCreditClient, redeemAndApplyToCart, centsToMoney, moneyToCents, } from './tileCredit';
|
|
8
|
+
export { TileCreditError } from './types';
|
|
9
|
+
export type * from './types';
|
|
10
|
+
export { ShopifyProvider, useShopify, useCart, useWishlist, useCustomer, useCheckout, useShopifyMessage, useTileCredit, type ShopifyProviderProps, type ShopifyEvent, type ShopifyEventType, type CartState, type WishlistState, type CustomerState, type CheckoutState, type UseTileCreditOptions, type UseTileCreditState, } from './react';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,OAAO,EACP,WAAW,EACX,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,aAAa,EACb,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,GACb,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,YAAY,GACb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,mBAAmB,SAAS,CAAC;AAO7B,OAAO,EACL,eAAe,EACf,UAAU,EACV,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,EACX,iBAAiB,EACjB,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,GACxB,MAAM,SAAS,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useTileCredit = exports.useShopifyMessage = exports.useCheckout = exports.useCustomer = exports.useWishlist = exports.useCart = exports.useShopify = exports.ShopifyProvider = exports.TileCreditError = exports.moneyToCents = exports.centsToMoney = exports.redeemAndApplyToCart = exports.getTileCreditClient = exports.configureTileCredit = exports.TileCreditClient = exports.userErrorsOf = exports.isUserErrorRejection = exports.isOutOfStockError = exports.classifyAuthFailure = exports.wouldExceedLineLimit = exports.projectedLineCount = exports.maxLineItems = exports.getCartPolicy = exports.setCartPolicy = exports.limitExceededMessage = exports.setMessageResolver = exports.patchMessages = exports.setMessages = exports.getMessages = exports.message = exports.DEFAULT_MESSAGES = exports.getCurrencyCode = exports.getMoneyFormat = exports.shop = exports.applyMoneyFormat = exports.formatMoney = exports.default = exports.shopify = void 0;
|
|
4
|
+
var shopify_1 = require("./shopify");
|
|
5
|
+
Object.defineProperty(exports, "shopify", { enumerable: true, get: function () { return shopify_1.shopify; } });
|
|
6
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return shopify_1.shopify; } });
|
|
7
|
+
var money_1 = require("./money");
|
|
8
|
+
Object.defineProperty(exports, "formatMoney", { enumerable: true, get: function () { return money_1.formatMoney; } });
|
|
9
|
+
Object.defineProperty(exports, "applyMoneyFormat", { enumerable: true, get: function () { return money_1.applyMoneyFormat; } });
|
|
10
|
+
Object.defineProperty(exports, "shop", { enumerable: true, get: function () { return money_1.shop; } });
|
|
11
|
+
var client_1 = require("./client");
|
|
12
|
+
Object.defineProperty(exports, "getMoneyFormat", { enumerable: true, get: function () { return client_1.getMoneyFormat; } });
|
|
13
|
+
Object.defineProperty(exports, "getCurrencyCode", { enumerable: true, get: function () { return client_1.getCurrencyCode; } });
|
|
14
|
+
var messages_1 = require("./messages");
|
|
15
|
+
Object.defineProperty(exports, "DEFAULT_MESSAGES", { enumerable: true, get: function () { return messages_1.DEFAULT_MESSAGES; } });
|
|
16
|
+
Object.defineProperty(exports, "message", { enumerable: true, get: function () { return messages_1.message; } });
|
|
17
|
+
Object.defineProperty(exports, "getMessages", { enumerable: true, get: function () { return messages_1.getMessages; } });
|
|
18
|
+
Object.defineProperty(exports, "setMessages", { enumerable: true, get: function () { return messages_1.setMessages; } });
|
|
19
|
+
Object.defineProperty(exports, "patchMessages", { enumerable: true, get: function () { return messages_1.patchMessages; } });
|
|
20
|
+
Object.defineProperty(exports, "setMessageResolver", { enumerable: true, get: function () { return messages_1.setMessageResolver; } });
|
|
21
|
+
Object.defineProperty(exports, "limitExceededMessage", { enumerable: true, get: function () { return messages_1.limitExceededMessage; } });
|
|
22
|
+
var cartPolicy_1 = require("./cartPolicy");
|
|
23
|
+
Object.defineProperty(exports, "setCartPolicy", { enumerable: true, get: function () { return cartPolicy_1.setCartPolicy; } });
|
|
24
|
+
Object.defineProperty(exports, "getCartPolicy", { enumerable: true, get: function () { return cartPolicy_1.getCartPolicy; } });
|
|
25
|
+
Object.defineProperty(exports, "maxLineItems", { enumerable: true, get: function () { return cartPolicy_1.maxLineItems; } });
|
|
26
|
+
Object.defineProperty(exports, "projectedLineCount", { enumerable: true, get: function () { return cartPolicy_1.projectedLineCount; } });
|
|
27
|
+
Object.defineProperty(exports, "wouldExceedLineLimit", { enumerable: true, get: function () { return cartPolicy_1.wouldExceedLineLimit; } });
|
|
28
|
+
var errors_1 = require("./errors");
|
|
29
|
+
Object.defineProperty(exports, "classifyAuthFailure", { enumerable: true, get: function () { return errors_1.classifyAuthFailure; } });
|
|
30
|
+
Object.defineProperty(exports, "isOutOfStockError", { enumerable: true, get: function () { return errors_1.isOutOfStockError; } });
|
|
31
|
+
Object.defineProperty(exports, "isUserErrorRejection", { enumerable: true, get: function () { return errors_1.isUserErrorRejection; } });
|
|
32
|
+
Object.defineProperty(exports, "userErrorsOf", { enumerable: true, get: function () { return errors_1.userErrorsOf; } });
|
|
33
|
+
var tileCredit_1 = require("./tileCredit");
|
|
34
|
+
Object.defineProperty(exports, "TileCreditClient", { enumerable: true, get: function () { return tileCredit_1.TileCreditClient; } });
|
|
35
|
+
Object.defineProperty(exports, "configureTileCredit", { enumerable: true, get: function () { return tileCredit_1.configureTileCredit; } });
|
|
36
|
+
Object.defineProperty(exports, "getTileCreditClient", { enumerable: true, get: function () { return tileCredit_1.getTileCreditClient; } });
|
|
37
|
+
Object.defineProperty(exports, "redeemAndApplyToCart", { enumerable: true, get: function () { return tileCredit_1.redeemAndApplyToCart; } });
|
|
38
|
+
Object.defineProperty(exports, "centsToMoney", { enumerable: true, get: function () { return tileCredit_1.centsToMoney; } });
|
|
39
|
+
Object.defineProperty(exports, "moneyToCents", { enumerable: true, get: function () { return tileCredit_1.moneyToCents; } });
|
|
40
|
+
var types_1 = require("./types");
|
|
41
|
+
Object.defineProperty(exports, "TileCreditError", { enumerable: true, get: function () { return types_1.TileCreditError; } });
|
|
42
|
+
// React helpers re-exported from the ROOT entry so consumers can write
|
|
43
|
+
// import { useShopify, useTileCredit } from '@apptile/sdk-shopify'
|
|
44
|
+
// without paying for the `/react` subpath — the tile-packet-bundler only
|
|
45
|
+
// builds a single per-package bundle per platform, so requests to
|
|
46
|
+
// `@apptile/sdk-shopify/react` return no bundle on web preview.
|
|
47
|
+
var react_1 = require("./react");
|
|
48
|
+
Object.defineProperty(exports, "ShopifyProvider", { enumerable: true, get: function () { return react_1.ShopifyProvider; } });
|
|
49
|
+
Object.defineProperty(exports, "useShopify", { enumerable: true, get: function () { return react_1.useShopify; } });
|
|
50
|
+
Object.defineProperty(exports, "useCart", { enumerable: true, get: function () { return react_1.useCart; } });
|
|
51
|
+
Object.defineProperty(exports, "useWishlist", { enumerable: true, get: function () { return react_1.useWishlist; } });
|
|
52
|
+
Object.defineProperty(exports, "useCustomer", { enumerable: true, get: function () { return react_1.useCustomer; } });
|
|
53
|
+
Object.defineProperty(exports, "useCheckout", { enumerable: true, get: function () { return react_1.useCheckout; } });
|
|
54
|
+
Object.defineProperty(exports, "useShopifyMessage", { enumerable: true, get: function () { return react_1.useShopifyMessage; } });
|
|
55
|
+
Object.defineProperty(exports, "useTileCredit", { enumerable: true, get: function () { return react_1.useTileCredit; } });
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qCAAwD;AAA/C,kGAAA,OAAO,OAAA;AAAE,kGAAA,OAAO,OAAW;AACpC,iCAA8D;AAArD,oGAAA,WAAW,OAAA;AAAE,yGAAA,gBAAgB,OAAA;AAAE,6FAAA,IAAI,OAAA;AAC5C,mCAA2D;AAAlD,wGAAA,cAAc,OAAA;AAAE,yGAAA,eAAe,OAAA;AACxC,uCAQoB;AAPlB,4GAAA,gBAAgB,OAAA;AAChB,mGAAA,OAAO,OAAA;AACP,uGAAA,WAAW,OAAA;AACX,uGAAA,WAAW,OAAA;AACX,yGAAA,aAAa,OAAA;AACb,8GAAA,kBAAkB,OAAA;AAClB,gHAAA,oBAAoB,OAAA;AAEtB,2CAMsB;AALpB,2GAAA,aAAa,OAAA;AACb,2GAAA,aAAa,OAAA;AACb,0GAAA,YAAY,OAAA;AACZ,gHAAA,kBAAkB,OAAA;AAClB,kHAAA,oBAAoB,OAAA;AAEtB,mCAKkB;AAJhB,6GAAA,mBAAmB,OAAA;AACnB,2GAAA,iBAAiB,OAAA;AACjB,8GAAA,oBAAoB,OAAA;AACpB,sGAAA,YAAY,OAAA;AAEd,2CAOsB;AANpB,8GAAA,gBAAgB,OAAA;AAChB,iHAAA,mBAAmB,OAAA;AACnB,iHAAA,mBAAmB,OAAA;AACnB,kHAAA,oBAAoB,OAAA;AACpB,0GAAA,YAAY,OAAA;AACZ,0GAAA,YAAY,OAAA;AAEd,iCAA0C;AAAjC,wGAAA,eAAe,OAAA;AAGxB,uEAAuE;AACvE,qEAAqE;AACrE,yEAAyE;AACzE,kEAAkE;AAClE,gEAAgE;AAChE,iCAkBiB;AAjBf,wGAAA,eAAe,OAAA;AACf,mGAAA,UAAU,OAAA;AACV,gGAAA,OAAO,OAAA;AACP,oGAAA,WAAW,OAAA;AACX,oGAAA,WAAW,OAAA;AACX,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AACjB,sGAAA,aAAa,OAAA"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { AlertMessageKey, AlertMessages, MessageResolver } from './types';
|
|
2
|
+
/** Ships the same copy the v1 Shopify panel used as its placeholders. */
|
|
3
|
+
export declare const DEFAULT_MESSAGES: Readonly<Record<AlertMessageKey, string>>;
|
|
4
|
+
/**
|
|
5
|
+
* Replaces the override set — a full swap, not a merge, so clearing a field in
|
|
6
|
+
* the Settings panel falls back to the default rather than sticking.
|
|
7
|
+
*/
|
|
8
|
+
export declare function setMessages(messages?: AlertMessages | null): void;
|
|
9
|
+
/** Merges into the current overrides. For a Live Layer publish of one field. */
|
|
10
|
+
export declare function patchMessages(messages: AlertMessages): void;
|
|
11
|
+
export declare function setMessageResolver(resolver?: MessageResolver | null): void;
|
|
12
|
+
export declare function getMessages(): AlertMessages;
|
|
13
|
+
/**
|
|
14
|
+
* The string to show for `key`. Never throws and never returns empty — an
|
|
15
|
+
* override of `''` (a cleared panel field) is treated as "not set".
|
|
16
|
+
*/
|
|
17
|
+
export declare function message(key: AlertMessageKey): string;
|
|
18
|
+
/**
|
|
19
|
+
* `cart.limitExceeded` mentions a number, and the default says 25 while the
|
|
20
|
+
* configured limit may be anything. Substitutes the real one into the default
|
|
21
|
+
* copy; an explicit override is left exactly as authored.
|
|
22
|
+
*/
|
|
23
|
+
export declare function limitExceededMessage(max: number): string;
|
|
24
|
+
//# sourceMappingURL=messages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../src/messages.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE/E,yEAAyE;AACzE,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CAAC,MAAM,CAAC,eAAe,EAAE,MAAM,CAAC,CActE,CAAC;AAcF;;;GAGG;AACH,wBAAgB,WAAW,CAAC,QAAQ,CAAC,EAAE,aAAa,GAAG,IAAI,GAAG,IAAI,CAEjE;AAED,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI,CAE3D;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,eAAe,GAAG,IAAI,GAAG,IAAI,CAE1E;AAED,wBAAgB,WAAW,IAAI,aAAa,CAE3C;AAED;;;GAGG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,eAAe,GAAG,MAAM,CAcpD;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAIxD"}
|
package/dist/messages.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_MESSAGES = void 0;
|
|
4
|
+
exports.setMessages = setMessages;
|
|
5
|
+
exports.patchMessages = patchMessages;
|
|
6
|
+
exports.setMessageResolver = setMessageResolver;
|
|
7
|
+
exports.getMessages = getMessages;
|
|
8
|
+
exports.message = message;
|
|
9
|
+
exports.limitExceededMessage = limitExceededMessage;
|
|
10
|
+
/** Ships the same copy the v1 Shopify panel used as its placeholders. */
|
|
11
|
+
exports.DEFAULT_MESSAGES = {
|
|
12
|
+
'cart.added': 'Product added to the Cart',
|
|
13
|
+
'cart.removed': 'Product removed from the Cart',
|
|
14
|
+
'cart.limitExceeded': 'You can not add more than 25 items on cart',
|
|
15
|
+
'cart.outOfStock': 'Sorry, this item is out of stock',
|
|
16
|
+
'wishlist.added': 'Saved to your wishlist',
|
|
17
|
+
'wishlist.removed': 'Removed from wishlist',
|
|
18
|
+
'wishlist.empty': 'Your wishlist is empty',
|
|
19
|
+
'auth.loginSuccess': 'Welcome back!',
|
|
20
|
+
'auth.loginFailed': 'Incorrect email or password',
|
|
21
|
+
'auth.loggedOut': 'You have been signed out',
|
|
22
|
+
'auth.resetLinkSent': 'Check your email for a reset link',
|
|
23
|
+
'checkout.orderPlaced': 'Your order has been placed 🎉',
|
|
24
|
+
'checkout.paymentFailed': 'Payment could not be processed',
|
|
25
|
+
};
|
|
26
|
+
/** i18n keys the Translations workspace uses, where they differ from ours. */
|
|
27
|
+
const TRANSLATION_KEYS = {
|
|
28
|
+
'cart.added': 'toast.added_to_cart',
|
|
29
|
+
};
|
|
30
|
+
const state = { overrides: {}, translate: null };
|
|
31
|
+
/**
|
|
32
|
+
* Replaces the override set — a full swap, not a merge, so clearing a field in
|
|
33
|
+
* the Settings panel falls back to the default rather than sticking.
|
|
34
|
+
*/
|
|
35
|
+
function setMessages(messages) {
|
|
36
|
+
state.overrides = messages ? { ...messages } : {};
|
|
37
|
+
}
|
|
38
|
+
/** Merges into the current overrides. For a Live Layer publish of one field. */
|
|
39
|
+
function patchMessages(messages) {
|
|
40
|
+
state.overrides = { ...state.overrides, ...messages };
|
|
41
|
+
}
|
|
42
|
+
function setMessageResolver(resolver) {
|
|
43
|
+
state.translate = resolver !== null && resolver !== void 0 ? resolver : null;
|
|
44
|
+
}
|
|
45
|
+
function getMessages() {
|
|
46
|
+
return { ...state.overrides };
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The string to show for `key`. Never throws and never returns empty — an
|
|
50
|
+
* override of `''` (a cleared panel field) is treated as "not set".
|
|
51
|
+
*/
|
|
52
|
+
function message(key) {
|
|
53
|
+
var _a;
|
|
54
|
+
const override = state.overrides[key];
|
|
55
|
+
if (typeof override === 'string' && override.trim() !== '')
|
|
56
|
+
return override;
|
|
57
|
+
const fallback = exports.DEFAULT_MESSAGES[key];
|
|
58
|
+
if (state.translate) {
|
|
59
|
+
try {
|
|
60
|
+
const translated = state.translate((_a = TRANSLATION_KEYS[key]) !== null && _a !== void 0 ? _a : key, fallback);
|
|
61
|
+
if (typeof translated === 'string' && translated.trim() !== '')
|
|
62
|
+
return translated;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// A broken resolver must not cost the shopper their toast.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return fallback;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* `cart.limitExceeded` mentions a number, and the default says 25 while the
|
|
72
|
+
* configured limit may be anything. Substitutes the real one into the default
|
|
73
|
+
* copy; an explicit override is left exactly as authored.
|
|
74
|
+
*/
|
|
75
|
+
function limitExceededMessage(max) {
|
|
76
|
+
const text = message('cart.limitExceeded');
|
|
77
|
+
if (state.overrides['cart.limitExceeded'])
|
|
78
|
+
return text;
|
|
79
|
+
return text.replace('25', String(max));
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=messages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.js","sourceRoot":"","sources":["../src/messages.ts"],"names":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