@kiva/kv-shop 2.1.1 → 3.0.0
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/dist/basketItems.cjs
DELETED
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (let key of __getOwnPropNames(from))
|
|
14
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
-
|
|
29
|
-
// src/basketItems.ts
|
|
30
|
-
var basketItems_exports = {};
|
|
31
|
-
__export(basketItems_exports, {
|
|
32
|
-
setTipDonation: () => setTipDonation
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(basketItems_exports);
|
|
35
|
-
var import_core2 = require("@apollo/client/core/core.cjs");
|
|
36
|
-
var import_numeral = __toESM(require("numeral"), 1);
|
|
37
|
-
|
|
38
|
-
// src/basket.ts
|
|
39
|
-
var import_core = require("@apollo/client/core/core.cjs");
|
|
40
|
-
|
|
41
|
-
// src/util/cookie.ts
|
|
42
|
-
var getCookieValue = (name) => {
|
|
43
|
-
if (typeof document !== void 0) {
|
|
44
|
-
return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
var setCookieValue = (name, value, options = "") => {
|
|
48
|
-
if (typeof document !== void 0) {
|
|
49
|
-
document.cookie = `${name}=${encodeURIComponent(value)};${options}`;
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
// src/shopError.ts
|
|
54
|
-
var ShopError = class extends Error {
|
|
55
|
-
constructor({ code, original }, ...params) {
|
|
56
|
-
super(...params);
|
|
57
|
-
if (Error.captureStackTrace) {
|
|
58
|
-
Error.captureStackTrace(this, ShopError);
|
|
59
|
-
}
|
|
60
|
-
this.name = "ShopError";
|
|
61
|
-
this.code = code;
|
|
62
|
-
this.original = original;
|
|
63
|
-
}
|
|
64
|
-
aggregateErrors(errors) {
|
|
65
|
-
this.errors = errors;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
function parseShopError(error) {
|
|
69
|
-
if (error instanceof ShopError) {
|
|
70
|
-
return error;
|
|
71
|
-
}
|
|
72
|
-
const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
|
|
73
|
-
const errorMessage = typeof error === "string" ? error : error?.message ?? "";
|
|
74
|
-
if (errorCode === "invalidMethodParameter" && errorMessage.includes("paymentMethod.create")) {
|
|
75
|
-
return new ShopError({
|
|
76
|
-
code: "paymentMethod.create.invalidMethodParameter",
|
|
77
|
-
original: error
|
|
78
|
-
}, "There was a problem validating your payment information. Please double-check the details and try again.");
|
|
79
|
-
}
|
|
80
|
-
if (errorMessage.includes("Invalid request: ")) {
|
|
81
|
-
const finalError = errorMessage.split("Invalid request: ")[1].split("., ").map((e) => e.matchAll(/[A-Z_]+: (.*)/g))[0];
|
|
82
|
-
const finalCode = finalError[1];
|
|
83
|
-
const finalMessage = finalError[2];
|
|
84
|
-
return new ShopError({
|
|
85
|
-
code: `paymentMethod.${finalCode}`,
|
|
86
|
-
original: error
|
|
87
|
-
}, finalMessage);
|
|
88
|
-
}
|
|
89
|
-
if (errorCode === "insufficientFunds" || errorMessage.includes("There is not enough credit")) {
|
|
90
|
-
return new ShopError({
|
|
91
|
-
code: "shop.insufficientFunds",
|
|
92
|
-
original: error
|
|
93
|
-
}, "There is not enough money to complete the checkout. Please double-check the details and try again.");
|
|
94
|
-
}
|
|
95
|
-
if (errorCode === "shop.invalidBasketId" || errorCode === "shop.basketRequired" || errorCode === "shop.alreadyCheckedOut") {
|
|
96
|
-
return new ShopError({
|
|
97
|
-
code: errorCode,
|
|
98
|
-
original: error
|
|
99
|
-
}, "There was a problem with your basket. Please, refresh the page and try again.");
|
|
100
|
-
}
|
|
101
|
-
if (errorCode === "donationAmountTooLarge") {
|
|
102
|
-
return new ShopError({
|
|
103
|
-
code: errorCode,
|
|
104
|
-
original: error
|
|
105
|
-
}, errorMessage);
|
|
106
|
-
}
|
|
107
|
-
return new ShopError({
|
|
108
|
-
code: "shop.unknown",
|
|
109
|
-
original: error
|
|
110
|
-
}, "An unknown error occurred.");
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// src/basket.ts
|
|
114
|
-
function getBasketID() {
|
|
115
|
-
return getCookieValue("kvbskt");
|
|
116
|
-
}
|
|
117
|
-
function setBasketID(basketId) {
|
|
118
|
-
setCookieValue("kvbskt", basketId, "path=/;secure;");
|
|
119
|
-
}
|
|
120
|
-
async function createBasketHelper(apollo) {
|
|
121
|
-
try {
|
|
122
|
-
return apollo.mutate({
|
|
123
|
-
mutation: import_core.gql`mutation createNewBasketForUser { shop { id createBasket } }`
|
|
124
|
-
}).then(({ data }) => {
|
|
125
|
-
const newBasketId = data.shop?.createBasket ?? null;
|
|
126
|
-
if (newBasketId) {
|
|
127
|
-
setBasketID(newBasketId);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
} catch (error) {
|
|
131
|
-
throw parseShopError(error);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
var activeBasketCreationQuery = null;
|
|
135
|
-
async function createBasket(apollo) {
|
|
136
|
-
if (activeBasketCreationQuery) {
|
|
137
|
-
return activeBasketCreationQuery;
|
|
138
|
-
}
|
|
139
|
-
activeBasketCreationQuery = createBasketHelper(apollo);
|
|
140
|
-
return activeBasketCreationQuery;
|
|
141
|
-
}
|
|
142
|
-
function hasBasketExpired(error) {
|
|
143
|
-
const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
|
|
144
|
-
return ["shop.invalidBasketId", "shop.basketRequired", "shop.alreadyCheckedOut"].includes(errorCode);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
// src/shopQueries.ts
|
|
148
|
-
var watchQueries = /* @__PURE__ */ new Set();
|
|
149
|
-
async function callShopMutation(apollo, options, maxretries = 2) {
|
|
150
|
-
try {
|
|
151
|
-
const result = await apollo.mutate({
|
|
152
|
-
...options,
|
|
153
|
-
variables: {
|
|
154
|
-
...options.variables,
|
|
155
|
-
basketId: getBasketID()
|
|
156
|
-
},
|
|
157
|
-
refetchQueries: options.awaitRefetchQueries ? Array.from(watchQueries) : []
|
|
158
|
-
});
|
|
159
|
-
if (result?.errors?.length) {
|
|
160
|
-
const basketErrors = result?.errors.filter((err) => hasBasketExpired(err));
|
|
161
|
-
if (basketErrors.length) {
|
|
162
|
-
if (maxretries > 0) {
|
|
163
|
-
await createBasket(apollo);
|
|
164
|
-
return callShopMutation(apollo, options, maxretries - 1);
|
|
165
|
-
}
|
|
166
|
-
throw basketErrors[0];
|
|
167
|
-
}
|
|
168
|
-
if (result?.errors?.length) {
|
|
169
|
-
throw result.errors[0];
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return result?.data;
|
|
173
|
-
} catch (e) {
|
|
174
|
-
throw parseShopError(e);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// src/basketItems.ts
|
|
179
|
-
async function setTipDonation({ amount, apollo, metadata }) {
|
|
180
|
-
const donationAmount = (0, import_numeral.default)(amount).format("0.00");
|
|
181
|
-
const data = await callShopMutation(apollo, {
|
|
182
|
-
awaitRefetchQueries: true,
|
|
183
|
-
mutation: import_core2.gql`mutation setTipDonation($price: Money!, $basketId: String, $metadata: String) {
|
|
184
|
-
shop (basketId: $basketId) {
|
|
185
|
-
id
|
|
186
|
-
updateDonation (donation: {
|
|
187
|
-
price: $price,
|
|
188
|
-
isTip: true,
|
|
189
|
-
metadata: $metadata,
|
|
190
|
-
})
|
|
191
|
-
{
|
|
192
|
-
id
|
|
193
|
-
price
|
|
194
|
-
isTip
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
}`,
|
|
198
|
-
variables: { price: donationAmount, metadata }
|
|
199
|
-
});
|
|
200
|
-
return data?.shop?.updateDonation;
|
|
201
|
-
}
|
|
202
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
203
|
-
0 && (module.exports = {
|
|
204
|
-
setTipDonation
|
|
205
|
-
});
|
package/dist/basketItems.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ApolloClient } from '@apollo/client/core/core.cjs';
|
|
2
|
-
|
|
3
|
-
interface SetTipDonationOptions {
|
|
4
|
-
amount: string | number;
|
|
5
|
-
metadata?: string | null;
|
|
6
|
-
apollo: ApolloClient<any>;
|
|
7
|
-
}
|
|
8
|
-
interface SetTipDonationData {
|
|
9
|
-
shop: {
|
|
10
|
-
id: string;
|
|
11
|
-
updateDonation: {
|
|
12
|
-
id: string;
|
|
13
|
-
price: string;
|
|
14
|
-
isTip: boolean;
|
|
15
|
-
metadata: string | null;
|
|
16
|
-
} | null;
|
|
17
|
-
} | null;
|
|
18
|
-
}
|
|
19
|
-
declare function setTipDonation({ amount, apollo, metadata }: SetTipDonationOptions): Promise<{
|
|
20
|
-
id: string;
|
|
21
|
-
price: string;
|
|
22
|
-
isTip: boolean;
|
|
23
|
-
metadata: string | null;
|
|
24
|
-
}>;
|
|
25
|
-
|
|
26
|
-
export { SetTipDonationData, SetTipDonationOptions, setTipDonation };
|
package/dist/basketTotals.cjs
DELETED
|
@@ -1,228 +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/basketTotals.ts
|
|
20
|
-
var basketTotals_exports = {};
|
|
21
|
-
__export(basketTotals_exports, {
|
|
22
|
-
basketTotalsQuery: () => basketTotalsQuery,
|
|
23
|
-
watchBasketTotals: () => watchBasketTotals
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(basketTotals_exports);
|
|
26
|
-
var import_core2 = require("@apollo/client/core/core.cjs");
|
|
27
|
-
|
|
28
|
-
// src/basket.ts
|
|
29
|
-
var import_core = require("@apollo/client/core/core.cjs");
|
|
30
|
-
|
|
31
|
-
// src/util/cookie.ts
|
|
32
|
-
var getCookieValue = (name) => {
|
|
33
|
-
if (typeof document !== void 0) {
|
|
34
|
-
return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var setCookieValue = (name, value, options = "") => {
|
|
38
|
-
if (typeof document !== void 0) {
|
|
39
|
-
document.cookie = `${name}=${encodeURIComponent(value)};${options}`;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/shopError.ts
|
|
44
|
-
var ShopError = class extends Error {
|
|
45
|
-
constructor({ code, original }, ...params) {
|
|
46
|
-
super(...params);
|
|
47
|
-
if (Error.captureStackTrace) {
|
|
48
|
-
Error.captureStackTrace(this, ShopError);
|
|
49
|
-
}
|
|
50
|
-
this.name = "ShopError";
|
|
51
|
-
this.code = code;
|
|
52
|
-
this.original = original;
|
|
53
|
-
}
|
|
54
|
-
aggregateErrors(errors) {
|
|
55
|
-
this.errors = errors;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
function parseShopError(error) {
|
|
59
|
-
if (error instanceof ShopError) {
|
|
60
|
-
return error;
|
|
61
|
-
}
|
|
62
|
-
const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
|
|
63
|
-
const errorMessage = typeof error === "string" ? error : error?.message ?? "";
|
|
64
|
-
if (errorCode === "invalidMethodParameter" && errorMessage.includes("paymentMethod.create")) {
|
|
65
|
-
return new ShopError({
|
|
66
|
-
code: "paymentMethod.create.invalidMethodParameter",
|
|
67
|
-
original: error
|
|
68
|
-
}, "There was a problem validating your payment information. Please double-check the details and try again.");
|
|
69
|
-
}
|
|
70
|
-
if (errorMessage.includes("Invalid request: ")) {
|
|
71
|
-
const finalError = errorMessage.split("Invalid request: ")[1].split("., ").map((e) => e.matchAll(/[A-Z_]+: (.*)/g))[0];
|
|
72
|
-
const finalCode = finalError[1];
|
|
73
|
-
const finalMessage = finalError[2];
|
|
74
|
-
return new ShopError({
|
|
75
|
-
code: `paymentMethod.${finalCode}`,
|
|
76
|
-
original: error
|
|
77
|
-
}, finalMessage);
|
|
78
|
-
}
|
|
79
|
-
if (errorCode === "insufficientFunds" || errorMessage.includes("There is not enough credit")) {
|
|
80
|
-
return new ShopError({
|
|
81
|
-
code: "shop.insufficientFunds",
|
|
82
|
-
original: error
|
|
83
|
-
}, "There is not enough money to complete the checkout. Please double-check the details and try again.");
|
|
84
|
-
}
|
|
85
|
-
if (errorCode === "shop.invalidBasketId" || errorCode === "shop.basketRequired" || errorCode === "shop.alreadyCheckedOut") {
|
|
86
|
-
return new ShopError({
|
|
87
|
-
code: errorCode,
|
|
88
|
-
original: error
|
|
89
|
-
}, "There was a problem with your basket. Please, refresh the page and try again.");
|
|
90
|
-
}
|
|
91
|
-
if (errorCode === "donationAmountTooLarge") {
|
|
92
|
-
return new ShopError({
|
|
93
|
-
code: errorCode,
|
|
94
|
-
original: error
|
|
95
|
-
}, errorMessage);
|
|
96
|
-
}
|
|
97
|
-
return new ShopError({
|
|
98
|
-
code: "shop.unknown",
|
|
99
|
-
original: error
|
|
100
|
-
}, "An unknown error occurred.");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// src/basket.ts
|
|
104
|
-
function getBasketID() {
|
|
105
|
-
return getCookieValue("kvbskt");
|
|
106
|
-
}
|
|
107
|
-
function setBasketID(basketId) {
|
|
108
|
-
setCookieValue("kvbskt", basketId, "path=/;secure;");
|
|
109
|
-
}
|
|
110
|
-
async function createBasketHelper(apollo) {
|
|
111
|
-
try {
|
|
112
|
-
return apollo.mutate({
|
|
113
|
-
mutation: import_core.gql`mutation createNewBasketForUser { shop { id createBasket } }`
|
|
114
|
-
}).then(({ data }) => {
|
|
115
|
-
const newBasketId = data.shop?.createBasket ?? null;
|
|
116
|
-
if (newBasketId) {
|
|
117
|
-
setBasketID(newBasketId);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
120
|
-
} catch (error) {
|
|
121
|
-
throw parseShopError(error);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
var activeBasketCreationQuery = null;
|
|
125
|
-
async function createBasket(apollo) {
|
|
126
|
-
if (activeBasketCreationQuery) {
|
|
127
|
-
return activeBasketCreationQuery;
|
|
128
|
-
}
|
|
129
|
-
activeBasketCreationQuery = createBasketHelper(apollo);
|
|
130
|
-
return activeBasketCreationQuery;
|
|
131
|
-
}
|
|
132
|
-
function hasBasketExpired(error) {
|
|
133
|
-
const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
|
|
134
|
-
return ["shop.invalidBasketId", "shop.basketRequired", "shop.alreadyCheckedOut"].includes(errorCode);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// src/shopQueries.ts
|
|
138
|
-
var watchQueries = /* @__PURE__ */ new Set();
|
|
139
|
-
function watchShopQuery(apollo, options, maxretries = 2) {
|
|
140
|
-
let retries = 0;
|
|
141
|
-
watchQueries.add(options.query);
|
|
142
|
-
const observable = apollo.watchQuery({
|
|
143
|
-
...options,
|
|
144
|
-
variables: {
|
|
145
|
-
...options.variables,
|
|
146
|
-
basketId: getBasketID()
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
const oldSubscribe = observable.subscribe.bind(observable);
|
|
150
|
-
observable.subscribe = (...args) => {
|
|
151
|
-
let nextFn;
|
|
152
|
-
let errorFn;
|
|
153
|
-
let completeFn;
|
|
154
|
-
if (typeof args[0] === "function") {
|
|
155
|
-
[nextFn, errorFn, completeFn] = args;
|
|
156
|
-
} else {
|
|
157
|
-
nextFn = args[0]?.next;
|
|
158
|
-
errorFn = args[0]?.error;
|
|
159
|
-
completeFn = args[0]?.complete;
|
|
160
|
-
}
|
|
161
|
-
const newErrorFn = (err) => {
|
|
162
|
-
const basketErrors = err?.graphQLErrors?.filter((e) => hasBasketExpired(e));
|
|
163
|
-
if (basketErrors.length) {
|
|
164
|
-
if (retries < maxretries) {
|
|
165
|
-
createBasket(apollo).then(() => {
|
|
166
|
-
retries += 1;
|
|
167
|
-
observable.refetch({
|
|
168
|
-
...observable.variables,
|
|
169
|
-
basketId: getBasketID()
|
|
170
|
-
});
|
|
171
|
-
});
|
|
172
|
-
} else {
|
|
173
|
-
errorFn(parseShopError(basketErrors[0]));
|
|
174
|
-
}
|
|
175
|
-
} else {
|
|
176
|
-
if (err?.graphQLErrors?.length) {
|
|
177
|
-
errorFn(parseShopError(err.graphQLErrors[0]));
|
|
178
|
-
}
|
|
179
|
-
if (err?.networkError) {
|
|
180
|
-
errorFn(parseShopError(err.networkError));
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
};
|
|
184
|
-
return oldSubscribe(nextFn, newErrorFn, completeFn);
|
|
185
|
-
};
|
|
186
|
-
return observable;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// src/basketTotals.ts
|
|
190
|
-
var basketTotalsQuery = import_core2.gql`query basketTotals($basketId: String) {
|
|
191
|
-
shop (basketId: $basketId) {
|
|
192
|
-
id
|
|
193
|
-
basket {
|
|
194
|
-
id
|
|
195
|
-
totals {
|
|
196
|
-
bonusAppliedTotal
|
|
197
|
-
bonusAvailableTotal
|
|
198
|
-
creditAmountNeeded
|
|
199
|
-
creditAppliedTotal
|
|
200
|
-
creditAvailableTotal
|
|
201
|
-
donationTotal
|
|
202
|
-
itemTotal
|
|
203
|
-
freeTrialAppliedTotal
|
|
204
|
-
freeTrialAvailableTotal
|
|
205
|
-
loanReservationTotal
|
|
206
|
-
kivaCardTotal
|
|
207
|
-
kivaCreditAppliedTotal
|
|
208
|
-
kivaCreditAvailableTotal
|
|
209
|
-
kivaCreditRemaining
|
|
210
|
-
kivaCreditToReapply
|
|
211
|
-
redemptionCodeAppliedTotal
|
|
212
|
-
redemptionCodeAvailableTotal
|
|
213
|
-
universalCodeAppliedTotal
|
|
214
|
-
universalCodeAvailableTotal
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}`;
|
|
219
|
-
function watchBasketTotals(apollo) {
|
|
220
|
-
return watchShopQuery(apollo, {
|
|
221
|
-
query: basketTotalsQuery
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
225
|
-
0 && (module.exports = {
|
|
226
|
-
basketTotalsQuery,
|
|
227
|
-
watchBasketTotals
|
|
228
|
-
});
|
package/dist/basketTotals.d.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as _apollo_client_core_ObservableQuery from '@apollo/client/core/ObservableQuery';
|
|
2
|
-
import * as graphql_language_ast from 'graphql/language/ast';
|
|
3
|
-
import { ApolloClient } from '@apollo/client/core/core.cjs';
|
|
4
|
-
|
|
5
|
-
declare const basketTotalsQuery: graphql_language_ast.DocumentNode;
|
|
6
|
-
interface BasketTotalsData {
|
|
7
|
-
shop: {
|
|
8
|
-
id: string;
|
|
9
|
-
basket: {
|
|
10
|
-
id: string;
|
|
11
|
-
totals: {
|
|
12
|
-
bonusAppliedTotal: string;
|
|
13
|
-
bonusAvailableTotal: string;
|
|
14
|
-
creditAmountNeeded: string;
|
|
15
|
-
creditAppliedTotal: string;
|
|
16
|
-
creditAvailableTotal: string;
|
|
17
|
-
donationTotal: string;
|
|
18
|
-
itemTotal: string;
|
|
19
|
-
freeTrialAppliedTotal: string;
|
|
20
|
-
freeTrialAvailableTotal: string;
|
|
21
|
-
loanReservationTotal: string;
|
|
22
|
-
kivaCardTotal: string;
|
|
23
|
-
kivaCreditAppliedTotal: string;
|
|
24
|
-
kivaCreditAvailableTotal: string;
|
|
25
|
-
kivaCreditRemaining: string;
|
|
26
|
-
kivaCreditToReapply: string;
|
|
27
|
-
redemptionCodeAppliedTotal: string;
|
|
28
|
-
redemptionCodeAvailableTotal: string;
|
|
29
|
-
universalCodeAppliedTotal: string;
|
|
30
|
-
universalCodeAvailableTotal: string;
|
|
31
|
-
} | null;
|
|
32
|
-
} | null;
|
|
33
|
-
} | null;
|
|
34
|
-
}
|
|
35
|
-
declare function watchBasketTotals(apollo: ApolloClient<any>): _apollo_client_core_ObservableQuery.ObservableQuery<BasketTotalsData, any>;
|
|
36
|
-
|
|
37
|
-
export { BasketTotalsData, basketTotalsQuery, watchBasketTotals };
|
|
@@ -1,41 +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/basketVerification.ts
|
|
20
|
-
var basketVerification_exports = {};
|
|
21
|
-
__export(basketVerification_exports, {
|
|
22
|
-
VerificationState: () => VerificationState,
|
|
23
|
-
isBasketVerified: () => isBasketVerified
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(basketVerification_exports);
|
|
26
|
-
var VerificationState = /* @__PURE__ */ ((VerificationState2) => {
|
|
27
|
-
VerificationState2["VERIFIED"] = "verified";
|
|
28
|
-
VerificationState2["PENDING"] = "pending";
|
|
29
|
-
VerificationState2["REQUIRED"] = "required";
|
|
30
|
-
VerificationState2["MAY_BE_NEEDED"] = "may_be_needed";
|
|
31
|
-
VerificationState2["NOT_NEEDED"] = "not_needed";
|
|
32
|
-
return VerificationState2;
|
|
33
|
-
})(VerificationState || {});
|
|
34
|
-
function isBasketVerified(state) {
|
|
35
|
-
return state === "verified" /* VERIFIED */ || state === "not_needed" /* NOT_NEEDED */;
|
|
36
|
-
}
|
|
37
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
38
|
-
0 && (module.exports = {
|
|
39
|
-
VerificationState,
|
|
40
|
-
isBasketVerified
|
|
41
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
declare enum VerificationState {
|
|
2
|
-
VERIFIED = "verified",
|
|
3
|
-
PENDING = "pending",
|
|
4
|
-
REQUIRED = "required",
|
|
5
|
-
MAY_BE_NEEDED = "may_be_needed",
|
|
6
|
-
NOT_NEEDED = "not_needed"
|
|
7
|
-
}
|
|
8
|
-
declare function isBasketVerified(state: VerificationState): boolean;
|
|
9
|
-
|
|
10
|
-
export { VerificationState, isBasketVerified };
|
package/dist/checkoutStatus.cjs
DELETED
|
@@ -1,111 +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/checkoutStatus.ts
|
|
20
|
-
var checkoutStatus_exports = {};
|
|
21
|
-
__export(checkoutStatus_exports, {
|
|
22
|
-
getCheckoutStatus: () => getCheckoutStatus,
|
|
23
|
-
pollForFinishedCheckout: () => pollForFinishedCheckout
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(checkoutStatus_exports);
|
|
26
|
-
var import_core = require("@apollo/client/core/core.cjs");
|
|
27
|
-
|
|
28
|
-
// src/util/poll.ts
|
|
29
|
-
function wait(ms) {
|
|
30
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
31
|
-
}
|
|
32
|
-
async function poll(fn, fnCondition, interval, timeout) {
|
|
33
|
-
const endTime = Date.now() + timeout;
|
|
34
|
-
let result = await fn();
|
|
35
|
-
while (!fnCondition(result)) {
|
|
36
|
-
if (Date.now() > endTime) {
|
|
37
|
-
throw new Error("Polling timed out");
|
|
38
|
-
}
|
|
39
|
-
await wait(interval);
|
|
40
|
-
result = await fn();
|
|
41
|
-
}
|
|
42
|
-
return result;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// src/util/cookie.ts
|
|
46
|
-
var getCookieValue = (name) => {
|
|
47
|
-
if (typeof document !== void 0) {
|
|
48
|
-
return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// src/util/visitorId.ts
|
|
53
|
-
function getVisitorID() {
|
|
54
|
-
return getCookieValue("uiv");
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// src/checkoutStatus.ts
|
|
58
|
-
async function getCheckoutStatus({ apollo, transactionSagaId }) {
|
|
59
|
-
return apollo.query({
|
|
60
|
-
query: import_core.gql`
|
|
61
|
-
query checkoutStatus($transactionId: String!, $visitorId: String) {
|
|
62
|
-
checkoutStatus(transactionId: $transactionId, visitorId: $visitorId) {
|
|
63
|
-
basketId
|
|
64
|
-
errorCode
|
|
65
|
-
errorMessage
|
|
66
|
-
receipt {
|
|
67
|
-
checkoutId
|
|
68
|
-
}
|
|
69
|
-
requestedAt
|
|
70
|
-
status
|
|
71
|
-
transactionId
|
|
72
|
-
updatedAt
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
`,
|
|
76
|
-
variables: {
|
|
77
|
-
transactionId: transactionSagaId,
|
|
78
|
-
visitorId: getVisitorID()
|
|
79
|
-
},
|
|
80
|
-
fetchPolicy: "network-only"
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
async function pollForFinishedCheckout({
|
|
84
|
-
apollo,
|
|
85
|
-
transactionSagaId,
|
|
86
|
-
interval = 1e3,
|
|
87
|
-
timeout = 6e4
|
|
88
|
-
}) {
|
|
89
|
-
return poll(
|
|
90
|
-
// function to poll
|
|
91
|
-
() => getCheckoutStatus({
|
|
92
|
-
apollo,
|
|
93
|
-
transactionSagaId
|
|
94
|
-
}),
|
|
95
|
-
// function to check for completed status
|
|
96
|
-
(result) => {
|
|
97
|
-
const { status, errorCode, errorMessage } = result?.data?.checkoutStatus;
|
|
98
|
-
if (status === "COMPLETED" || errorCode || errorMessage) {
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
return false;
|
|
102
|
-
},
|
|
103
|
-
interval,
|
|
104
|
-
timeout
|
|
105
|
-
);
|
|
106
|
-
}
|
|
107
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
108
|
-
0 && (module.exports = {
|
|
109
|
-
getCheckoutStatus,
|
|
110
|
-
pollForFinishedCheckout
|
|
111
|
-
});
|
package/dist/checkoutStatus.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ApolloClient } from '@apollo/client/core/core.cjs';
|
|
2
|
-
|
|
3
|
-
interface GetCheckoutStatusOptions {
|
|
4
|
-
apollo: ApolloClient<any>;
|
|
5
|
-
transactionSagaId: string;
|
|
6
|
-
}
|
|
7
|
-
interface CheckoutStatusQueryResult {
|
|
8
|
-
data: {
|
|
9
|
-
checkoutStatus: any;
|
|
10
|
-
} | null;
|
|
11
|
-
errors?: any;
|
|
12
|
-
}
|
|
13
|
-
declare function getCheckoutStatus({ apollo, transactionSagaId }: GetCheckoutStatusOptions): Promise<CheckoutStatusQueryResult>;
|
|
14
|
-
interface PollForCheckoutStatusOptions extends GetCheckoutStatusOptions {
|
|
15
|
-
interval?: number;
|
|
16
|
-
timeout?: number;
|
|
17
|
-
}
|
|
18
|
-
declare function pollForFinishedCheckout({ apollo, transactionSagaId, interval, timeout, }: PollForCheckoutStatusOptions): Promise<CheckoutStatusQueryResult>;
|
|
19
|
-
|
|
20
|
-
export { CheckoutStatusQueryResult, GetCheckoutStatusOptions, PollForCheckoutStatusOptions, getCheckoutStatus, pollForFinishedCheckout };
|