@kiva/kv-shop 2.1.2 → 3.0.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/dist/_virtual/_commonjs-dynamic-modules.js +6 -0
- package/dist/_virtual/_commonjsHelpers.js +8 -0
- package/dist/_virtual/_plugin-vue_export-helper.js +9 -0
- package/dist/_virtual/dropin.js +11 -0
- package/dist/_virtual/dropin2.js +4 -0
- package/dist/basket.js +35 -12
- package/dist/basketCredits.js +78 -14
- package/dist/basketItems.js +27 -8
- package/dist/basketTotals.js +38 -10
- package/dist/basketVerification.js +6 -6
- package/dist/checkoutStatus.js +52 -8
- package/dist/components/KvPaymentSelect.css +1 -0
- package/dist/components/KvPaymentSelect.js +23 -0
- package/dist/components/KvPaymentSelect2.js +110 -0
- package/dist/index.d.ts +321 -20
- package/dist/index.js +49 -96
- package/dist/managedAccount.js +62 -8
- package/dist/oneTimeCheckout.js +156 -12
- package/dist/receipt.js +143 -12
- package/dist/shopError.js +41 -6
- package/dist/shopQueries.js +82 -11
- package/dist/subscriptionCheckout.js +88 -7
- package/dist/useBraintreeDropIn.js +145 -9
- package/dist/util/cookie.js +11 -0
- package/dist/util/poll.js +17 -0
- package/dist/util/redirect.js +8 -0
- package/dist/util/visitorId.js +7 -0
- package/dist/validatePreCheckout.js +44 -11
- package/dist/vendor/braintree-web-drop-in/dist/browser/dropin.js +12223 -0
- package/package.json +28 -26
- package/dist/basket.cjs +0 -141
- package/dist/basket.d.ts +0 -8
- package/dist/basketCredits.cjs +0 -250
- package/dist/basketCredits.d.ts +0 -32
- package/dist/basketItems.cjs +0 -205
- package/dist/basketItems.d.ts +0 -26
- package/dist/basketTotals.cjs +0 -228
- package/dist/basketTotals.d.ts +0 -37
- package/dist/basketVerification.cjs +0 -41
- package/dist/basketVerification.d.ts +0 -10
- package/dist/checkoutStatus.cjs +0 -111
- package/dist/checkoutStatus.d.ts +0 -20
- package/dist/chunk-4ODZGLWK.js +0 -64
- package/dist/chunk-ASZJVUQ7.js +0 -72
- package/dist/chunk-FBF4WMN6.js +0 -49
- package/dist/chunk-FC4QW6QA.js +0 -106
- package/dist/chunk-FCAOCO7O.js +0 -17
- package/dist/chunk-GVVI7X2R.js +0 -196
- package/dist/chunk-IIN37LC7.js +0 -45
- package/dist/chunk-IOZ5ERDX.js +0 -121
- package/dist/chunk-KCUOMCSN.js +0 -58
- package/dist/chunk-LZ4UMRCV.js +0 -16
- package/dist/chunk-RQNRQ2E5.js +0 -155
- package/dist/chunk-SRGYGDAX.js +0 -80
- package/dist/chunk-TPJPGUO7.js +0 -12
- package/dist/chunk-UJXHTR43.js +0 -86
- package/dist/chunk-VZ3VDRRP.js +0 -167
- package/dist/chunk-Z7JRY3QE.js +0 -34
- package/dist/components/KvPaymentSelect.vue +0 -380
- package/dist/index.cjs +0 -1227
- package/dist/managedAccount.cjs +0 -231
- package/dist/managedAccount.d.ts +0 -59
- package/dist/oneTimeCheckout.cjs +0 -636
- package/dist/oneTimeCheckout.d.ts +0 -21
- package/dist/receipt.cjs +0 -191
- package/dist/receipt.d.ts +0 -16
- package/dist/shopError.cjs +0 -88
- package/dist/shopError.d.ts +0 -14
- package/dist/shopQueries.cjs +0 -248
- package/dist/shopQueries.d.ts +0 -8
- package/dist/subscriptionCheckout.cjs +0 -187
- package/dist/subscriptionCheckout.d.ts +0 -13
- package/dist/useBraintreeDropIn.cjs +0 -258
- package/dist/useBraintreeDropIn.d.ts +0 -25
- package/dist/validatePreCheckout.cjs +0 -218
- package/dist/validatePreCheckout.d.ts +0 -28
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiva/kv-shop",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
|
-
"main": "dist/index.cjs",
|
|
9
8
|
"module": "dist/index.js",
|
|
10
9
|
"types": "dist/index.d.ts",
|
|
11
10
|
"files": [
|
|
@@ -13,47 +12,50 @@
|
|
|
13
12
|
],
|
|
14
13
|
"exports": {
|
|
15
14
|
".": {
|
|
16
|
-
"
|
|
17
|
-
"import": "./dist/index.js"
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./components/*": "./dist/components/*.js",
|
|
19
|
+
"./components/*.js": "./dist/components/*.js"
|
|
20
20
|
},
|
|
21
21
|
"scripts": {
|
|
22
|
-
"build": "
|
|
22
|
+
"build": "vite build",
|
|
23
23
|
"lint": "eslint --ext .ts,.vue ./src",
|
|
24
24
|
"test": "jest"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
|
+
"@apollo/client": "^3.13.1",
|
|
28
|
+
"@kiva/kv-analytics": "^1.3.0",
|
|
29
|
+
"@kiva/kv-components": "^6.0.0",
|
|
30
|
+
"@kiva/vite-plugin-vue-lib-css": "^2.0.0",
|
|
31
|
+
"@types/braintree-web-drop-in": "^1.39.3",
|
|
27
32
|
"@types/jest": "^29.5.14",
|
|
28
33
|
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
29
34
|
"@typescript-eslint/parser": "^5.59.7",
|
|
35
|
+
"@vitejs/plugin-vue": "^5.2.1",
|
|
30
36
|
"@vue/eslint-config-typescript": "^11.0.3",
|
|
37
|
+
"braintree-web-drop-in": "^1.44.1",
|
|
31
38
|
"eslint-plugin-vue": "^9.14.0",
|
|
32
39
|
"jest": "^29.7.0",
|
|
33
40
|
"jest-environment-jsdom": "^29.5.0",
|
|
41
|
+
"numeral": "^2.0.6",
|
|
34
42
|
"ts-jest": "^29.2.5",
|
|
35
|
-
"tsup": "^6.7.0",
|
|
36
43
|
"typescript": "^5.0.4",
|
|
37
|
-
"
|
|
44
|
+
"vite": "^6.1.1",
|
|
45
|
+
"vite-plugin-dts": "^4.5.0",
|
|
46
|
+
"vite-plugin-no-bundle": "^4.0.0",
|
|
47
|
+
"vue": "^3.5.13",
|
|
38
48
|
"vue-eslint-parser": "^9.3.0"
|
|
39
49
|
},
|
|
40
|
-
"dependencies": {
|
|
41
|
-
"@apollo/client": "^3.7.14",
|
|
42
|
-
"@kiva/kv-analytics": "^1.3.0",
|
|
43
|
-
"@kiva/kv-components": "^5.3.7",
|
|
44
|
-
"@types/braintree-web-drop-in": "^1.34.2",
|
|
45
|
-
"braintree-web-drop-in": "^1.37.0",
|
|
46
|
-
"numeral": "^2.0.6",
|
|
47
|
-
"vue-demi": "^0.14.7"
|
|
48
|
-
},
|
|
49
50
|
"peerDependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
"
|
|
55
|
-
"optional": true
|
|
56
|
-
}
|
|
51
|
+
"@apollo/client": "3.x",
|
|
52
|
+
"@kiva/kv-analytics": "1.x",
|
|
53
|
+
"@kiva/kv-components": "5 || 6",
|
|
54
|
+
"numeral": "2.x",
|
|
55
|
+
"vue": "3.x"
|
|
57
56
|
},
|
|
58
|
-
"
|
|
57
|
+
"bundleDependencies": [
|
|
58
|
+
"braintree-web-drop-in"
|
|
59
|
+
],
|
|
60
|
+
"gitHead": "081bd6d623814f7eb5cd6b79e31afd684665fff0"
|
|
59
61
|
}
|
package/dist/basket.cjs
DELETED
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/basket.ts
|
|
20
|
-
var basket_exports = {};
|
|
21
|
-
__export(basket_exports, {
|
|
22
|
-
createBasket: () => createBasket,
|
|
23
|
-
getBasketID: () => getBasketID,
|
|
24
|
-
hasBasketExpired: () => hasBasketExpired,
|
|
25
|
-
setBasketID: () => setBasketID
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(basket_exports);
|
|
28
|
-
var import_core = require("@apollo/client/core/core.cjs");
|
|
29
|
-
|
|
30
|
-
// src/util/cookie.ts
|
|
31
|
-
var getCookieValue = (name) => {
|
|
32
|
-
if (typeof document !== void 0) {
|
|
33
|
-
return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
var setCookieValue = (name, value, options = "") => {
|
|
37
|
-
if (typeof document !== void 0) {
|
|
38
|
-
document.cookie = `${name}=${encodeURIComponent(value)};${options}`;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
// src/shopError.ts
|
|
43
|
-
var ShopError = class extends Error {
|
|
44
|
-
constructor({ code, original }, ...params) {
|
|
45
|
-
super(...params);
|
|
46
|
-
if (Error.captureStackTrace) {
|
|
47
|
-
Error.captureStackTrace(this, ShopError);
|
|
48
|
-
}
|
|
49
|
-
this.name = "ShopError";
|
|
50
|
-
this.code = code;
|
|
51
|
-
this.original = original;
|
|
52
|
-
}
|
|
53
|
-
aggregateErrors(errors) {
|
|
54
|
-
this.errors = errors;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
function parseShopError(error) {
|
|
58
|
-
if (error instanceof ShopError) {
|
|
59
|
-
return error;
|
|
60
|
-
}
|
|
61
|
-
const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
|
|
62
|
-
const errorMessage = typeof error === "string" ? error : error?.message ?? "";
|
|
63
|
-
if (errorCode === "invalidMethodParameter" && errorMessage.includes("paymentMethod.create")) {
|
|
64
|
-
return new ShopError({
|
|
65
|
-
code: "paymentMethod.create.invalidMethodParameter",
|
|
66
|
-
original: error
|
|
67
|
-
}, "There was a problem validating your payment information. Please double-check the details and try again.");
|
|
68
|
-
}
|
|
69
|
-
if (errorMessage.includes("Invalid request: ")) {
|
|
70
|
-
const finalError = errorMessage.split("Invalid request: ")[1].split("., ").map((e) => e.matchAll(/[A-Z_]+: (.*)/g))[0];
|
|
71
|
-
const finalCode = finalError[1];
|
|
72
|
-
const finalMessage = finalError[2];
|
|
73
|
-
return new ShopError({
|
|
74
|
-
code: `paymentMethod.${finalCode}`,
|
|
75
|
-
original: error
|
|
76
|
-
}, finalMessage);
|
|
77
|
-
}
|
|
78
|
-
if (errorCode === "insufficientFunds" || errorMessage.includes("There is not enough credit")) {
|
|
79
|
-
return new ShopError({
|
|
80
|
-
code: "shop.insufficientFunds",
|
|
81
|
-
original: error
|
|
82
|
-
}, "There is not enough money to complete the checkout. Please double-check the details and try again.");
|
|
83
|
-
}
|
|
84
|
-
if (errorCode === "shop.invalidBasketId" || errorCode === "shop.basketRequired" || errorCode === "shop.alreadyCheckedOut") {
|
|
85
|
-
return new ShopError({
|
|
86
|
-
code: errorCode,
|
|
87
|
-
original: error
|
|
88
|
-
}, "There was a problem with your basket. Please, refresh the page and try again.");
|
|
89
|
-
}
|
|
90
|
-
if (errorCode === "donationAmountTooLarge") {
|
|
91
|
-
return new ShopError({
|
|
92
|
-
code: errorCode,
|
|
93
|
-
original: error
|
|
94
|
-
}, errorMessage);
|
|
95
|
-
}
|
|
96
|
-
return new ShopError({
|
|
97
|
-
code: "shop.unknown",
|
|
98
|
-
original: error
|
|
99
|
-
}, "An unknown error occurred.");
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/basket.ts
|
|
103
|
-
function getBasketID() {
|
|
104
|
-
return getCookieValue("kvbskt");
|
|
105
|
-
}
|
|
106
|
-
function setBasketID(basketId) {
|
|
107
|
-
setCookieValue("kvbskt", basketId, "path=/;secure;");
|
|
108
|
-
}
|
|
109
|
-
async function createBasketHelper(apollo) {
|
|
110
|
-
try {
|
|
111
|
-
return apollo.mutate({
|
|
112
|
-
mutation: import_core.gql`mutation createNewBasketForUser { shop { id createBasket } }`
|
|
113
|
-
}).then(({ data }) => {
|
|
114
|
-
const newBasketId = data.shop?.createBasket ?? null;
|
|
115
|
-
if (newBasketId) {
|
|
116
|
-
setBasketID(newBasketId);
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
} catch (error) {
|
|
120
|
-
throw parseShopError(error);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
var activeBasketCreationQuery = null;
|
|
124
|
-
async function createBasket(apollo) {
|
|
125
|
-
if (activeBasketCreationQuery) {
|
|
126
|
-
return activeBasketCreationQuery;
|
|
127
|
-
}
|
|
128
|
-
activeBasketCreationQuery = createBasketHelper(apollo);
|
|
129
|
-
return activeBasketCreationQuery;
|
|
130
|
-
}
|
|
131
|
-
function hasBasketExpired(error) {
|
|
132
|
-
const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
|
|
133
|
-
return ["shop.invalidBasketId", "shop.basketRequired", "shop.alreadyCheckedOut"].includes(errorCode);
|
|
134
|
-
}
|
|
135
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
-
0 && (module.exports = {
|
|
137
|
-
createBasket,
|
|
138
|
-
getBasketID,
|
|
139
|
-
hasBasketExpired,
|
|
140
|
-
setBasketID
|
|
141
|
-
});
|
package/dist/basket.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { ApolloClient } from '@apollo/client/core/core.cjs';
|
|
2
|
-
|
|
3
|
-
declare function getBasketID(): string;
|
|
4
|
-
declare function setBasketID(basketId: any): void;
|
|
5
|
-
declare function createBasket(apollo: ApolloClient<any>): Promise<any>;
|
|
6
|
-
declare function hasBasketExpired(error: any): boolean;
|
|
7
|
-
|
|
8
|
-
export { createBasket, getBasketID, hasBasketExpired, setBasketID };
|
package/dist/basketCredits.cjs
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// src/basketCredits.ts
|
|
20
|
-
var basketCredits_exports = {};
|
|
21
|
-
__export(basketCredits_exports, {
|
|
22
|
-
applyKivaCredit: () => applyKivaCredit,
|
|
23
|
-
applyPromoCredit: () => applyPromoCredit,
|
|
24
|
-
removeKivaCredit: () => removeKivaCredit,
|
|
25
|
-
removePromoCredit: () => removePromoCredit
|
|
26
|
-
});
|
|
27
|
-
module.exports = __toCommonJS(basketCredits_exports);
|
|
28
|
-
var import_core2 = require("@apollo/client/core/core.cjs");
|
|
29
|
-
|
|
30
|
-
// src/basket.ts
|
|
31
|
-
var import_core = require("@apollo/client/core/core.cjs");
|
|
32
|
-
|
|
33
|
-
// src/util/cookie.ts
|
|
34
|
-
var getCookieValue = (name) => {
|
|
35
|
-
if (typeof document !== void 0) {
|
|
36
|
-
return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
var setCookieValue = (name, value, options = "") => {
|
|
40
|
-
if (typeof document !== void 0) {
|
|
41
|
-
document.cookie = `${name}=${encodeURIComponent(value)};${options}`;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/shopError.ts
|
|
46
|
-
var ShopError = class extends Error {
|
|
47
|
-
constructor({ code, original }, ...params) {
|
|
48
|
-
super(...params);
|
|
49
|
-
if (Error.captureStackTrace) {
|
|
50
|
-
Error.captureStackTrace(this, ShopError);
|
|
51
|
-
}
|
|
52
|
-
this.name = "ShopError";
|
|
53
|
-
this.code = code;
|
|
54
|
-
this.original = original;
|
|
55
|
-
}
|
|
56
|
-
aggregateErrors(errors) {
|
|
57
|
-
this.errors = errors;
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
function parseShopError(error) {
|
|
61
|
-
if (error instanceof ShopError) {
|
|
62
|
-
return error;
|
|
63
|
-
}
|
|
64
|
-
const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
|
|
65
|
-
const errorMessage = typeof error === "string" ? error : error?.message ?? "";
|
|
66
|
-
if (errorCode === "invalidMethodParameter" && errorMessage.includes("paymentMethod.create")) {
|
|
67
|
-
return new ShopError({
|
|
68
|
-
code: "paymentMethod.create.invalidMethodParameter",
|
|
69
|
-
original: error
|
|
70
|
-
}, "There was a problem validating your payment information. Please double-check the details and try again.");
|
|
71
|
-
}
|
|
72
|
-
if (errorMessage.includes("Invalid request: ")) {
|
|
73
|
-
const finalError = errorMessage.split("Invalid request: ")[1].split("., ").map((e) => e.matchAll(/[A-Z_]+: (.*)/g))[0];
|
|
74
|
-
const finalCode = finalError[1];
|
|
75
|
-
const finalMessage = finalError[2];
|
|
76
|
-
return new ShopError({
|
|
77
|
-
code: `paymentMethod.${finalCode}`,
|
|
78
|
-
original: error
|
|
79
|
-
}, finalMessage);
|
|
80
|
-
}
|
|
81
|
-
if (errorCode === "insufficientFunds" || errorMessage.includes("There is not enough credit")) {
|
|
82
|
-
return new ShopError({
|
|
83
|
-
code: "shop.insufficientFunds",
|
|
84
|
-
original: error
|
|
85
|
-
}, "There is not enough money to complete the checkout. Please double-check the details and try again.");
|
|
86
|
-
}
|
|
87
|
-
if (errorCode === "shop.invalidBasketId" || errorCode === "shop.basketRequired" || errorCode === "shop.alreadyCheckedOut") {
|
|
88
|
-
return new ShopError({
|
|
89
|
-
code: errorCode,
|
|
90
|
-
original: error
|
|
91
|
-
}, "There was a problem with your basket. Please, refresh the page and try again.");
|
|
92
|
-
}
|
|
93
|
-
if (errorCode === "donationAmountTooLarge") {
|
|
94
|
-
return new ShopError({
|
|
95
|
-
code: errorCode,
|
|
96
|
-
original: error
|
|
97
|
-
}, errorMessage);
|
|
98
|
-
}
|
|
99
|
-
return new ShopError({
|
|
100
|
-
code: "shop.unknown",
|
|
101
|
-
original: error
|
|
102
|
-
}, "An unknown error occurred.");
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// src/basket.ts
|
|
106
|
-
function getBasketID() {
|
|
107
|
-
return getCookieValue("kvbskt");
|
|
108
|
-
}
|
|
109
|
-
function setBasketID(basketId) {
|
|
110
|
-
setCookieValue("kvbskt", basketId, "path=/;secure;");
|
|
111
|
-
}
|
|
112
|
-
async function createBasketHelper(apollo) {
|
|
113
|
-
try {
|
|
114
|
-
return apollo.mutate({
|
|
115
|
-
mutation: import_core.gql`mutation createNewBasketForUser { shop { id createBasket } }`
|
|
116
|
-
}).then(({ data }) => {
|
|
117
|
-
const newBasketId = data.shop?.createBasket ?? null;
|
|
118
|
-
if (newBasketId) {
|
|
119
|
-
setBasketID(newBasketId);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
} catch (error) {
|
|
123
|
-
throw parseShopError(error);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
var activeBasketCreationQuery = null;
|
|
127
|
-
async function createBasket(apollo) {
|
|
128
|
-
if (activeBasketCreationQuery) {
|
|
129
|
-
return activeBasketCreationQuery;
|
|
130
|
-
}
|
|
131
|
-
activeBasketCreationQuery = createBasketHelper(apollo);
|
|
132
|
-
return activeBasketCreationQuery;
|
|
133
|
-
}
|
|
134
|
-
function hasBasketExpired(error) {
|
|
135
|
-
const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
|
|
136
|
-
return ["shop.invalidBasketId", "shop.basketRequired", "shop.alreadyCheckedOut"].includes(errorCode);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// src/shopQueries.ts
|
|
140
|
-
var watchQueries = /* @__PURE__ */ new Set();
|
|
141
|
-
async function callShopMutation(apollo, options, maxretries = 2) {
|
|
142
|
-
try {
|
|
143
|
-
const result = await apollo.mutate({
|
|
144
|
-
...options,
|
|
145
|
-
variables: {
|
|
146
|
-
...options.variables,
|
|
147
|
-
basketId: getBasketID()
|
|
148
|
-
},
|
|
149
|
-
refetchQueries: options.awaitRefetchQueries ? Array.from(watchQueries) : []
|
|
150
|
-
});
|
|
151
|
-
if (result?.errors?.length) {
|
|
152
|
-
const basketErrors = result?.errors.filter((err) => hasBasketExpired(err));
|
|
153
|
-
if (basketErrors.length) {
|
|
154
|
-
if (maxretries > 0) {
|
|
155
|
-
await createBasket(apollo);
|
|
156
|
-
return callShopMutation(apollo, options, maxretries - 1);
|
|
157
|
-
}
|
|
158
|
-
throw basketErrors[0];
|
|
159
|
-
}
|
|
160
|
-
if (result?.errors?.length) {
|
|
161
|
-
throw result.errors[0];
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return result?.data;
|
|
165
|
-
} catch (e) {
|
|
166
|
-
throw parseShopError(e);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// src/basketCredits.ts
|
|
171
|
-
async function applyKivaCredit(apollo) {
|
|
172
|
-
const data = await callShopMutation(apollo, {
|
|
173
|
-
awaitRefetchQueries: true,
|
|
174
|
-
mutation: import_core2.gql`mutation applyKivaCredit($basketId: String) {
|
|
175
|
-
shop (basketId: $basketId) {
|
|
176
|
-
id
|
|
177
|
-
addCreditByType(creditType: kiva_credit)
|
|
178
|
-
}
|
|
179
|
-
}`
|
|
180
|
-
});
|
|
181
|
-
return !!data?.shop?.addCreditByType;
|
|
182
|
-
}
|
|
183
|
-
async function removeKivaCredit(apollo) {
|
|
184
|
-
const data = await callShopMutation(apollo, {
|
|
185
|
-
awaitRefetchQueries: true,
|
|
186
|
-
mutation: import_core2.gql`mutation removeKivaCredit($basketId: String) {
|
|
187
|
-
shop (basketId: $basketId) {
|
|
188
|
-
id
|
|
189
|
-
removeCreditByType(creditType: kiva_credit)
|
|
190
|
-
}
|
|
191
|
-
}`
|
|
192
|
-
});
|
|
193
|
-
return !!data?.shop?.removeCreditByType;
|
|
194
|
-
}
|
|
195
|
-
async function applyPromoCredit(apollo, options) {
|
|
196
|
-
if (!options?.variables?.creditType || !options?.variables?.redemptionCode) {
|
|
197
|
-
return Promise.resolve({
|
|
198
|
-
errors: [
|
|
199
|
-
{
|
|
200
|
-
message: "Missing required parameter.",
|
|
201
|
-
extensions: { code: "upc.missing_parameter" }
|
|
202
|
-
}
|
|
203
|
-
]
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
const data = await callShopMutation(apollo, {
|
|
207
|
-
awaitRefetchQueries: true,
|
|
208
|
-
fetchPolicy: options?.fetchPolicy ?? "network-only",
|
|
209
|
-
mutation: import_core2.gql`mutation applyPromoCredit(
|
|
210
|
-
$basketId: String,
|
|
211
|
-
$creditType: CreditTypeEnum!,
|
|
212
|
-
$redemptionCode: String
|
|
213
|
-
) {
|
|
214
|
-
shop (basketId: $basketId) {
|
|
215
|
-
id
|
|
216
|
-
addCreditByType(creditType: $creditType, redemptionCode: $redemptionCode)
|
|
217
|
-
}
|
|
218
|
-
}`,
|
|
219
|
-
variables: { ...options?.variables }
|
|
220
|
-
});
|
|
221
|
-
return data;
|
|
222
|
-
}
|
|
223
|
-
async function removePromoCredit(apollo, options) {
|
|
224
|
-
if (!options?.variables?.creditType && !options?.variables?.redemptionCode) {
|
|
225
|
-
return Promise.resolve(false);
|
|
226
|
-
}
|
|
227
|
-
const data = await callShopMutation(apollo, {
|
|
228
|
-
awaitRefetchQueries: true,
|
|
229
|
-
fetchPolicy: options?.fetchPolicy ?? "network-only",
|
|
230
|
-
mutation: import_core2.gql`mutation removePromoCredit(
|
|
231
|
-
$basketId: String,
|
|
232
|
-
$creditType: CreditTypeEnum!,
|
|
233
|
-
$redemptionCode: String
|
|
234
|
-
) {
|
|
235
|
-
shop (basketId: $basketId) {
|
|
236
|
-
id
|
|
237
|
-
removeCreditByType(creditType: $creditType, redemptionCode: $redemptionCode)
|
|
238
|
-
}
|
|
239
|
-
}`,
|
|
240
|
-
variables: { ...options?.variables }
|
|
241
|
-
});
|
|
242
|
-
return !!data?.shop?.removeCreditByType;
|
|
243
|
-
}
|
|
244
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
245
|
-
0 && (module.exports = {
|
|
246
|
-
applyKivaCredit,
|
|
247
|
-
applyPromoCredit,
|
|
248
|
-
removeKivaCredit,
|
|
249
|
-
removePromoCredit
|
|
250
|
-
});
|
package/dist/basketCredits.d.ts
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ApolloClient, MutationOptions } from '@apollo/client/core/core.cjs';
|
|
2
|
-
|
|
3
|
-
interface ApplyKivaCreditData {
|
|
4
|
-
shop: {
|
|
5
|
-
id: string;
|
|
6
|
-
addCreditByType: boolean;
|
|
7
|
-
} | null;
|
|
8
|
-
}
|
|
9
|
-
declare function applyKivaCredit(apollo: ApolloClient<any>): Promise<boolean>;
|
|
10
|
-
interface RemoveKivaCreditData {
|
|
11
|
-
shop: {
|
|
12
|
-
id: string;
|
|
13
|
-
removeCreditByType: boolean;
|
|
14
|
-
} | null;
|
|
15
|
-
}
|
|
16
|
-
declare function removeKivaCredit(apollo: ApolloClient<any>): Promise<boolean>;
|
|
17
|
-
interface ApplyPromoCreditData {
|
|
18
|
-
shop: {
|
|
19
|
-
id: string;
|
|
20
|
-
addCreditByType: boolean;
|
|
21
|
-
} | null;
|
|
22
|
-
}
|
|
23
|
-
declare function applyPromoCredit(apollo: ApolloClient<any>, options: MutationOptions<any>): Promise<any>;
|
|
24
|
-
interface RemovePromoCreditData {
|
|
25
|
-
shop: {
|
|
26
|
-
id: string;
|
|
27
|
-
removeCreditByType: boolean;
|
|
28
|
-
} | null;
|
|
29
|
-
}
|
|
30
|
-
declare function removePromoCredit(apollo: ApolloClient<any>, options: MutationOptions<any>): Promise<boolean>;
|
|
31
|
-
|
|
32
|
-
export { ApplyKivaCreditData, ApplyPromoCreditData, RemoveKivaCreditData, RemovePromoCreditData, applyKivaCredit, applyPromoCredit, removeKivaCredit, removePromoCredit };
|