@kiva/kv-shop 1.3.2 → 1.4.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.
Files changed (56) hide show
  1. package/dist/basket.cjs +44 -15
  2. package/dist/basket.d.ts +4 -4
  3. package/dist/basket.js +5 -8
  4. package/dist/basketCredits.cjs +197 -0
  5. package/dist/basketCredits.d.ts +18 -0
  6. package/dist/basketCredits.js +12 -0
  7. package/dist/basketItems.cjs +70 -33
  8. package/dist/basketItems.d.ts +11 -1
  9. package/dist/basketItems.js +5 -3
  10. package/dist/basketTotals.cjs +228 -0
  11. package/dist/basketTotals.d.ts +37 -0
  12. package/dist/basketTotals.js +12 -0
  13. package/dist/basketVerification.cjs +41 -0
  14. package/dist/basketVerification.d.ts +10 -0
  15. package/dist/basketVerification.js +8 -0
  16. package/dist/checkoutStatus.cjs +110 -0
  17. package/dist/checkoutStatus.d.ts +20 -0
  18. package/dist/checkoutStatus.js +10 -0
  19. package/dist/{chunk-B7RLQXI6.js → chunk-2NC7LGGO.js} +14 -12
  20. package/dist/{chunk-IYCMZ5WV.js → chunk-4ODZGLWK.js} +21 -0
  21. package/dist/chunk-AI6E33YE.js +33 -0
  22. package/dist/chunk-CBJJUUVR.js +121 -0
  23. package/dist/chunk-DZGZX4F6.js +45 -0
  24. package/dist/chunk-EJ5NGYPO.js +145 -0
  25. package/dist/chunk-FCAOCO7O.js +17 -0
  26. package/dist/chunk-JBQ2KNMP.js +50 -0
  27. package/dist/{chunk-SLMBU6L7.js → chunk-JXQPCEKG.js} +9 -2
  28. package/dist/{chunk-TIASV6B2.js → chunk-KV4SOUVF.js} +1 -1
  29. package/dist/chunk-LZ4UMRCV.js +16 -0
  30. package/dist/chunk-MRCBNXPS.js +35 -0
  31. package/dist/chunk-PC4WUPYU.js +78 -0
  32. package/dist/chunk-TPJPGUO7.js +12 -0
  33. package/dist/components/KvPaymentSelect.vue +8 -1
  34. package/dist/index.cjs +489 -56
  35. package/dist/index.d.ts +12 -5
  36. package/dist/index.js +55 -21
  37. package/dist/oneTimeCheckout.cjs +396 -9
  38. package/dist/oneTimeCheckout.d.ts +11 -10
  39. package/dist/oneTimeCheckout.js +10 -5
  40. package/dist/shopError.cjs +21 -0
  41. package/dist/shopError.d.ts +2 -0
  42. package/dist/shopError.js +1 -1
  43. package/dist/shopQueries.cjs +248 -0
  44. package/dist/shopQueries.d.ts +8 -0
  45. package/dist/shopQueries.js +13 -0
  46. package/dist/subscriptionCheckout.cjs +21 -0
  47. package/dist/subscriptionCheckout.js +2 -2
  48. package/dist/useBraintreeDropIn.cjs +29 -1
  49. package/dist/useBraintreeDropIn.d.ts +9 -9
  50. package/dist/useBraintreeDropIn.js +2 -2
  51. package/dist/validatePreCheckout.cjs +210 -0
  52. package/dist/validatePreCheckout.d.ts +22 -0
  53. package/dist/validatePreCheckout.js +13 -0
  54. package/package.json +2 -2
  55. package/dist/chunk-M4CJOCIQ.js +0 -26
  56. package/dist/chunk-NC7RAUNV.js +0 -66
package/dist/basket.cjs CHANGED
@@ -21,14 +21,24 @@ var basket_exports = {};
21
21
  __export(basket_exports, {
22
22
  createBasket: () => createBasket,
23
23
  getBasketID: () => getBasketID,
24
- getCookieValue: () => getCookieValue,
25
24
  hasBasketExpired: () => hasBasketExpired,
26
- setBasketID: () => setBasketID,
27
- setCookieValue: () => setCookieValue
25
+ setBasketID: () => setBasketID
28
26
  });
29
27
  module.exports = __toCommonJS(basket_exports);
30
28
  var import_core = require("@apollo/client/core");
31
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
+
32
42
  // src/shopError.ts
33
43
  var ShopError = class extends Error {
34
44
  constructor({ code, original }, ...params) {
@@ -40,8 +50,14 @@ var ShopError = class extends Error {
40
50
  this.code = code;
41
51
  this.original = original;
42
52
  }
53
+ aggregateErrors(errors) {
54
+ this.errors = errors;
55
+ }
43
56
  };
44
57
  function parseShopError(error) {
58
+ if (error instanceof ShopError) {
59
+ return error;
60
+ }
45
61
  const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
46
62
  const errorMessage = typeof error === "string" ? error : error?.message ?? "";
47
63
  if (errorCode === "invalidMethodParameter" && errorMessage.includes("paymentMethod.create")) {
@@ -50,6 +66,21 @@ function parseShopError(error) {
50
66
  original: error
51
67
  }, "There was a problem validating your payment information. Please double-check the details and try again.");
52
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
+ }
53
84
  if (errorCode === "shop.invalidBasketId" || errorCode === "shop.basketRequired" || errorCode === "shop.alreadyCheckedOut") {
54
85
  return new ShopError({
55
86
  code: errorCode,
@@ -69,21 +100,13 @@ function parseShopError(error) {
69
100
  }
70
101
 
71
102
  // src/basket.ts
72
- var getCookieValue = (name) => {
73
- if (typeof document !== void 0) {
74
- return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
75
- }
76
- };
77
- var setCookieValue = (name, value, options = "") => {
78
- document.cookie = `${name}=${encodeURIComponent(value)};${options}`;
79
- };
80
103
  function getBasketID() {
81
104
  return getCookieValue("kvbskt");
82
105
  }
83
106
  function setBasketID(basketId) {
84
107
  setCookieValue("kvbskt", basketId, "path=/;secure;");
85
108
  }
86
- async function createBasket(apollo) {
109
+ async function createBasketHelper(apollo) {
87
110
  try {
88
111
  return apollo.mutate({
89
112
  mutation: import_core.gql`mutation createNewBasketForUser { shop { id createBasket } }`
@@ -97,6 +120,14 @@ async function createBasket(apollo) {
97
120
  throw parseShopError(error);
98
121
  }
99
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
+ }
100
131
  function hasBasketExpired(error) {
101
132
  const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
102
133
  return ["shop.invalidBasketId", "shop.basketRequired", "shop.alreadyCheckedOut"].includes(errorCode);
@@ -105,8 +136,6 @@ function hasBasketExpired(error) {
105
136
  0 && (module.exports = {
106
137
  createBasket,
107
138
  getBasketID,
108
- getCookieValue,
109
139
  hasBasketExpired,
110
- setBasketID,
111
- setCookieValue
140
+ setBasketID
112
141
  });
package/dist/basket.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- declare const getCookieValue: (name: string) => string;
2
- declare const setCookieValue: (name: string, value: string, options?: string) => void;
1
+ import { ApolloClient } from '@apollo/client/core';
2
+
3
3
  declare function getBasketID(): string;
4
4
  declare function setBasketID(basketId: any): void;
5
- declare function createBasket(apollo: any): Promise<any>;
5
+ declare function createBasket(apollo: ApolloClient<any>): Promise<any>;
6
6
  declare function hasBasketExpired(error: any): boolean;
7
7
 
8
- export { createBasket, getBasketID, getCookieValue, hasBasketExpired, setBasketID, setCookieValue };
8
+ export { createBasket, getBasketID, hasBasketExpired, setBasketID };
package/dist/basket.js CHANGED
@@ -1,17 +1,14 @@
1
1
  import {
2
2
  createBasket,
3
3
  getBasketID,
4
- getCookieValue,
5
4
  hasBasketExpired,
6
- setBasketID,
7
- setCookieValue
8
- } from "./chunk-B7RLQXI6.js";
9
- import "./chunk-IYCMZ5WV.js";
5
+ setBasketID
6
+ } from "./chunk-2NC7LGGO.js";
7
+ import "./chunk-4ODZGLWK.js";
8
+ import "./chunk-LZ4UMRCV.js";
10
9
  export {
11
10
  createBasket,
12
11
  getBasketID,
13
- getCookieValue,
14
12
  hasBasketExpired,
15
- setBasketID,
16
- setCookieValue
13
+ setBasketID
17
14
  };
@@ -0,0 +1,197 @@
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
+ removeKivaCredit: () => removeKivaCredit
24
+ });
25
+ module.exports = __toCommonJS(basketCredits_exports);
26
+ var import_core2 = require("@apollo/client/core");
27
+
28
+ // src/basket.ts
29
+ var import_core = require("@apollo/client/core");
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
+ async function callShopMutation(apollo, options, maxretries = 2) {
140
+ try {
141
+ const result = await apollo.mutate({
142
+ ...options,
143
+ variables: {
144
+ ...options.variables,
145
+ basketId: getBasketID()
146
+ },
147
+ refetchQueries: options.awaitRefetchQueries ? Array.from(watchQueries) : []
148
+ });
149
+ if (result?.errors?.length) {
150
+ const basketErrors = result?.errors.filter((err) => hasBasketExpired(err));
151
+ if (basketErrors.length) {
152
+ if (maxretries > 0) {
153
+ await createBasket(apollo);
154
+ return callShopMutation(apollo, options, maxretries - 1);
155
+ }
156
+ throw basketErrors[0];
157
+ }
158
+ if (result?.errors?.length) {
159
+ throw result.errors[0];
160
+ }
161
+ }
162
+ return result?.data;
163
+ } catch (e) {
164
+ throw parseShopError(e);
165
+ }
166
+ }
167
+
168
+ // src/basketCredits.ts
169
+ async function applyKivaCredit(apollo) {
170
+ const data = await callShopMutation(apollo, {
171
+ awaitRefetchQueries: true,
172
+ mutation: import_core2.gql`mutation applyKivaCredit($basketId: String) {
173
+ shop (basketId: $basketId) {
174
+ id
175
+ addCreditByType(creditType: kiva_credit)
176
+ }
177
+ }`
178
+ });
179
+ return !!data?.shop?.addCreditByType;
180
+ }
181
+ async function removeKivaCredit(apollo) {
182
+ const data = await callShopMutation(apollo, {
183
+ awaitRefetchQueries: true,
184
+ mutation: import_core2.gql`mutation removeKivaCredit($basketId: String) {
185
+ shop (basketId: $basketId) {
186
+ id
187
+ removeCreditByType(creditType: kiva_credit)
188
+ }
189
+ }`
190
+ });
191
+ return !!data?.shop?.removeCreditByType;
192
+ }
193
+ // Annotate the CommonJS export names for ESM import in node:
194
+ 0 && (module.exports = {
195
+ applyKivaCredit,
196
+ removeKivaCredit
197
+ });
@@ -0,0 +1,18 @@
1
+ import { ApolloClient } from '@apollo/client/core';
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
+
18
+ export { ApplyKivaCreditData, RemoveKivaCreditData, applyKivaCredit, removeKivaCredit };
@@ -0,0 +1,12 @@
1
+ import {
2
+ applyKivaCredit,
3
+ removeKivaCredit
4
+ } from "./chunk-MRCBNXPS.js";
5
+ import "./chunk-CBJJUUVR.js";
6
+ import "./chunk-2NC7LGGO.js";
7
+ import "./chunk-4ODZGLWK.js";
8
+ import "./chunk-LZ4UMRCV.js";
9
+ export {
10
+ applyKivaCredit,
11
+ removeKivaCredit
12
+ };
@@ -38,6 +38,18 @@ var import_numeral = __toESM(require("numeral"), 1);
38
38
  // src/basket.ts
39
39
  var import_core = require("@apollo/client/core");
40
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
+
41
53
  // src/shopError.ts
42
54
  var ShopError = class extends Error {
43
55
  constructor({ code, original }, ...params) {
@@ -49,8 +61,14 @@ var ShopError = class extends Error {
49
61
  this.code = code;
50
62
  this.original = original;
51
63
  }
64
+ aggregateErrors(errors) {
65
+ this.errors = errors;
66
+ }
52
67
  };
53
68
  function parseShopError(error) {
69
+ if (error instanceof ShopError) {
70
+ return error;
71
+ }
54
72
  const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
55
73
  const errorMessage = typeof error === "string" ? error : error?.message ?? "";
56
74
  if (errorCode === "invalidMethodParameter" && errorMessage.includes("paymentMethod.create")) {
@@ -59,6 +77,21 @@ function parseShopError(error) {
59
77
  original: error
60
78
  }, "There was a problem validating your payment information. Please double-check the details and try again.");
61
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
+ }
62
95
  if (errorCode === "shop.invalidBasketId" || errorCode === "shop.basketRequired" || errorCode === "shop.alreadyCheckedOut") {
63
96
  return new ShopError({
64
97
  code: errorCode,
@@ -78,21 +111,13 @@ function parseShopError(error) {
78
111
  }
79
112
 
80
113
  // src/basket.ts
81
- var getCookieValue = (name) => {
82
- if (typeof document !== void 0) {
83
- return decodeURIComponent(document.cookie.match(`(^|;)\\s*${name}\\s*=\\s*([^;]+)`)?.pop() || "");
84
- }
85
- };
86
- var setCookieValue = (name, value, options = "") => {
87
- document.cookie = `${name}=${encodeURIComponent(value)};${options}`;
88
- };
89
114
  function getBasketID() {
90
115
  return getCookieValue("kvbskt");
91
116
  }
92
117
  function setBasketID(basketId) {
93
118
  setCookieValue("kvbskt", basketId, "path=/;secure;");
94
119
  }
95
- async function createBasket(apollo) {
120
+ async function createBasketHelper(apollo) {
96
121
  try {
97
122
  return apollo.mutate({
98
123
  mutation: import_core.gql`mutation createNewBasketForUser { shop { id createBasket } }`
@@ -106,59 +131,71 @@ async function createBasket(apollo) {
106
131
  throw parseShopError(error);
107
132
  }
108
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
+ }
109
142
  function hasBasketExpired(error) {
110
143
  const errorCode = error?.code ?? error?.extensions?.code ?? error?.name ?? "";
111
144
  return ["shop.invalidBasketId", "shop.basketRequired", "shop.alreadyCheckedOut"].includes(errorCode);
112
145
  }
113
146
 
114
- // src/basketItems.ts
115
- async function callShopMutation(apollo, mutation, variables, maxretries = 2) {
147
+ // src/shopQueries.ts
148
+ var watchQueries = /* @__PURE__ */ new Set();
149
+ async function callShopMutation(apollo, options, maxretries = 2) {
116
150
  try {
117
151
  const result = await apollo.mutate({
118
- mutation,
152
+ ...options,
119
153
  variables: {
120
- ...variables,
154
+ ...options.variables,
121
155
  basketId: getBasketID()
122
- }
156
+ },
157
+ refetchQueries: options.awaitRefetchQueries ? Array.from(watchQueries) : []
123
158
  });
124
159
  if (result?.errors?.length) {
125
160
  const basketErrors = result?.errors.filter((err) => hasBasketExpired(err));
126
161
  if (basketErrors.length) {
127
162
  if (maxretries > 0) {
128
163
  await createBasket(apollo);
129
- return callShopMutation(apollo, mutation, variables, maxretries - 1);
164
+ return callShopMutation(apollo, options, maxretries - 1);
130
165
  }
131
166
  throw basketErrors[0];
132
167
  }
133
- const otherErrors = result?.errors?.filter((err) => !hasBasketExpired(err));
134
- if (otherErrors.length) {
135
- throw otherErrors[0];
168
+ if (result?.errors?.length) {
169
+ throw result.errors[0];
136
170
  }
137
171
  }
138
172
  return result?.data;
139
173
  } catch (e) {
140
- if (e instanceof ShopError) {
141
- throw e;
142
- }
143
174
  throw parseShopError(e);
144
175
  }
145
176
  }
177
+
178
+ // src/basketItems.ts
146
179
  async function setTipDonation({ amount, apollo }) {
147
180
  const donationAmount = (0, import_numeral.default)(amount).format("0.00");
148
- const data = await callShopMutation(apollo, import_core2.gql`mutation setTipDonation($price: Money!, $basketId: String) {
149
- shop (basketId: $basketId) {
150
- id
151
- updateDonation (donation: {
152
- price: $price,
153
- isTip: true
154
- })
155
- {
181
+ const data = await callShopMutation(apollo, {
182
+ awaitRefetchQueries: true,
183
+ mutation: import_core2.gql`mutation setTipDonation($price: Money!, $basketId: String) {
184
+ shop (basketId: $basketId) {
156
185
  id
157
- price
158
- isTip
186
+ updateDonation (donation: {
187
+ price: $price,
188
+ isTip: true
189
+ })
190
+ {
191
+ id
192
+ price
193
+ isTip
194
+ }
159
195
  }
160
- }
161
- }`, { price: donationAmount });
196
+ }`,
197
+ variables: { price: donationAmount }
198
+ });
162
199
  return data?.shop?.updateDonation;
163
200
  }
164
201
  // Annotate the CommonJS export names for ESM import in node:
@@ -4,6 +4,16 @@ interface SetTipDonationOptions {
4
4
  amount: string | number;
5
5
  apollo: ApolloClient<any>;
6
6
  }
7
+ interface SetTipDonationData {
8
+ shop: {
9
+ id: string;
10
+ updateDonation: {
11
+ id: string;
12
+ price: string;
13
+ isTip: boolean;
14
+ } | null;
15
+ } | null;
16
+ }
7
17
  declare function setTipDonation({ amount, apollo }: SetTipDonationOptions): Promise<any>;
8
18
 
9
- export { SetTipDonationOptions, setTipDonation };
19
+ export { SetTipDonationData, SetTipDonationOptions, setTipDonation };
@@ -1,8 +1,10 @@
1
1
  import {
2
2
  setTipDonation
3
- } from "./chunk-NC7RAUNV.js";
4
- import "./chunk-B7RLQXI6.js";
5
- import "./chunk-IYCMZ5WV.js";
3
+ } from "./chunk-AI6E33YE.js";
4
+ import "./chunk-CBJJUUVR.js";
5
+ import "./chunk-2NC7LGGO.js";
6
+ import "./chunk-4ODZGLWK.js";
7
+ import "./chunk-LZ4UMRCV.js";
6
8
  export {
7
9
  setTipDonation
8
10
  };