@kiva/kv-shop 3.2.9 → 3.3.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.
@@ -1,9 +1,9 @@
1
1
  import { gql as r } from "@apollo/client/core";
2
2
  import p from "numeral";
3
3
  import { callShopMutation as m } from "./shopQueries.js";
4
- async function d({ amount: a, apollo: o, metadata: e }) {
5
- var i;
6
- const n = p(a).format("0.00"), t = await m(o, {
4
+ async function u({ amount: i, apollo: e, metadata: o }) {
5
+ var a;
6
+ const n = p(i).format("0.00"), t = await m(e, {
7
7
  awaitRefetchQueries: !0,
8
8
  mutation: r`mutation setTipDonation($price: Money!, $basketId: String, $metadata: String) {
9
9
  shop (basketId: $basketId) {
@@ -14,16 +14,21 @@ async function d({ amount: a, apollo: o, metadata: e }) {
14
14
  metadata: $metadata,
15
15
  })
16
16
  {
17
+ basketItemType
17
18
  id
18
- price
19
19
  isTip
20
+ isUserEdited
21
+ metadata {
22
+ campaignId
23
+ }
24
+ price
20
25
  }
21
26
  }
22
27
  }`,
23
- variables: { price: n, metadata: e }
28
+ variables: { price: n, metadata: o }
24
29
  });
25
- return (i = t == null ? void 0 : t.shop) == null ? void 0 : i.updateDonation;
30
+ return (a = t == null ? void 0 : t.shop) == null ? void 0 : a.updateDonation;
26
31
  }
27
32
  export {
28
- d as setTipDonation
33
+ u as setTipDonation
29
34
  };
package/dist/index.d.ts CHANGED
@@ -114,7 +114,7 @@ export declare function executeNewSubscriptionCheckout({ amount, apollo, dayOfMo
114
114
 
115
115
  export declare function executeOneTimeCheckout({ apollo, braintree, emailAddress, emailOptIn, valetInviter, deactivateRedirect, }: OneTimeCheckoutOptions): Promise<CheckoutStatusQueryResult>;
116
116
 
117
- export declare function executeOneTimeCheckoutForGivingFund({ amount, apollo, braintree, emailAddress, emailOptIn, fundTarget, userId, useKivaCredit, }: OneTimeCheckoutForGivingFundOptions): Promise<CheckoutStatusQueryResult>;
117
+ export declare function executeOneTimeCheckoutForGivingFund({ amount, apollo, braintree, emailAddress, emailOptIn, fundTarget, userId, useKivaCredit, }: OneTimeCheckoutForGivingFundOptions): Promise<OneTimeCheckoutForGivingFundResult>;
118
118
 
119
119
  export declare function getBasketID(): string;
120
120
 
@@ -154,6 +154,17 @@ export declare interface OneTimeCheckoutForGivingFundOptions {
154
154
  useKivaCredit?: boolean;
155
155
  }
156
156
 
157
+ export declare interface OneTimeCheckoutForGivingFundResult {
158
+ data: {
159
+ checkoutStatus: any;
160
+ donation: any;
161
+ givingFund: {
162
+ id: string;
163
+ };
164
+ } | null;
165
+ errors?: any;
166
+ }
167
+
157
168
  export declare interface OneTimeCheckoutOptions {
158
169
  apollo: ApolloClient<any>;
159
170
  braintree?: DropInWrapper;
@@ -1,20 +1,20 @@
1
1
  import { gql as $ } from "@apollo/client/core";
2
- import { trackTransaction as x } from "@kiva/kv-analytics";
3
- import T from "numeral";
4
- import { pollForFinishedCheckout as q } from "./checkoutStatus.js";
2
+ import { trackTransaction as E } from "@kiva/kv-analytics";
3
+ import R from "numeral";
4
+ import { pollForFinishedCheckout as D } from "./checkoutStatus.js";
5
5
  import { ShopError as v, parseShopError as S } from "./shopError.js";
6
- import { callShopQuery as B, callShopMutation as D } from "./shopQueries.js";
7
- import { validatePreCheckout as N } from "./validatePreCheckout.js";
8
- import { wait as E } from "./util/poll.js";
9
- import { getVisitorID as P } from "./util/visitorId.js";
10
- import { redirectTo as _ } from "./util/redirect.js";
11
- import { getCheckoutTrackingData as G } from "./receipt.js";
12
- import { addGivingFund as O } from "./givingFunds.js";
13
- import { setTipDonation as K } from "./basketItems.js";
14
- import { removeKivaCredit as Q } from "./basketCredits.js";
15
- async function R(e) {
6
+ import { callShopQuery as _, callShopMutation as N } from "./shopQueries.js";
7
+ import { validatePreCheckout as P } from "./validatePreCheckout.js";
8
+ import { wait as G } from "./util/poll.js";
9
+ import { getVisitorID as l } from "./util/visitorId.js";
10
+ import { redirectTo as O } from "./util/redirect.js";
11
+ import { getCheckoutTrackingData as K } from "./receipt.js";
12
+ import { addGivingFund as Q } from "./givingFunds.js";
13
+ import { setTipDonation as U } from "./basketItems.js";
14
+ import { removeKivaCredit as V } from "./basketCredits.js";
15
+ async function A(e) {
16
16
  var r, o, i;
17
- const t = await B(e, {
17
+ const t = await _(e, {
18
18
  query: $`
19
19
  query creditAmountNeeded($basketId: String) {
20
20
  shop (basketId: $basketId) {
@@ -32,7 +32,7 @@ async function R(e) {
32
32
  }, 0);
33
33
  return (i = (o = (r = t == null ? void 0 : t.shop) == null ? void 0 : r.basket) == null ? void 0 : o.totals) == null ? void 0 : i.creditAmountNeeded;
34
34
  }
35
- const U = $`
35
+ const j = $`
36
36
  mutation creditCheckout(
37
37
  $basketId: String,
38
38
  $visitorId: String
@@ -42,7 +42,7 @@ const U = $`
42
42
  transactionId: checkoutAsync (visitorId: $visitorId)
43
43
  }
44
44
  }
45
- `, V = $`
45
+ `, z = $`
46
46
  mutation depositCheckout(
47
47
  $basketId: String,
48
48
  $amount: Money!,
@@ -63,15 +63,15 @@ const U = $`
63
63
  }
64
64
  }
65
65
  `;
66
- function A(e) {
67
- return D(e, {
68
- mutation: U,
66
+ function F(e) {
67
+ return N(e, {
68
+ mutation: j,
69
69
  variables: {
70
- visitorId: P()
70
+ visitorId: l()
71
71
  }
72
72
  }, 0);
73
73
  }
74
- async function F({
74
+ async function x({
75
75
  apollo: e,
76
76
  braintree: t,
77
77
  amount: r
@@ -83,18 +83,18 @@ async function F({
83
83
  { code: "shop.dropinNoPaymentMethod" },
84
84
  "No payment method returned from braintree dropin"
85
85
  );
86
- const { nonce: i, deviceData: u, type: a } = o;
86
+ const { nonce: i, deviceData: u, type: d } = o;
87
87
  return {
88
- paymentType: a,
89
- mutation: D(e, {
90
- mutation: V,
88
+ paymentType: d,
89
+ mutation: N(e, {
90
+ mutation: z,
91
91
  variables: {
92
92
  nonce: i,
93
93
  amount: r,
94
94
  savePaymentMethod: !1,
95
95
  // save payment methods handled by braintree drop in UI
96
96
  deviceData: u,
97
- visitorId: P()
97
+ visitorId: l()
98
98
  }
99
99
  }, 0)
100
100
  };
@@ -102,19 +102,19 @@ async function F({
102
102
  throw S(o);
103
103
  }
104
104
  }
105
- async function l(e, t, r) {
105
+ async function B(e, t, r) {
106
106
  try {
107
- const o = await G(
107
+ const o = await K(
108
108
  e,
109
109
  t,
110
110
  r
111
111
  );
112
- x(o), await E(800);
112
+ E(o), await G(800);
113
113
  } catch (o) {
114
114
  console.error("Error tracking transaction", o);
115
115
  }
116
116
  }
117
- async function nt({
117
+ async function ct({
118
118
  apollo: e,
119
119
  braintree: t,
120
120
  emailAddress: r,
@@ -122,91 +122,105 @@ async function nt({
122
122
  valetInviter: i,
123
123
  deactivateRedirect: u
124
124
  }) {
125
- var I, d, g, h, p;
126
- await N({
125
+ var h, y, a, w, g;
126
+ await P({
127
127
  apollo: e,
128
128
  emailAddress: r,
129
129
  emailOptIn: o,
130
130
  valetInviter: i
131
131
  });
132
- const a = await R(e), f = T(a).value() > 0;
133
- if (f && !t)
132
+ const d = await A(e), k = R(d).value() > 0;
133
+ if (k && !t)
134
134
  throw new v({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
135
- let s, y = "";
136
- if (f) {
137
- const k = await F({
135
+ let n, f = "";
136
+ if (k) {
137
+ const p = await x({
138
138
  apollo: e,
139
139
  braintree: t,
140
- amount: a
140
+ amount: d
141
141
  });
142
- y = k.paymentType, s = await k.mutation;
142
+ f = p.paymentType, n = await p.mutation;
143
143
  } else
144
- s = await A(e);
145
- const w = (I = s == null ? void 0 : s.shop) == null ? void 0 : I.transactionId, c = await q({
144
+ n = await F(e);
145
+ const I = (h = n == null ? void 0 : n.shop) == null ? void 0 : h.transactionId, s = await D({
146
146
  apollo: e,
147
- transactionSagaId: w,
147
+ transactionSagaId: I,
148
148
  timeout: 3e5
149
149
  // five minutes
150
150
  });
151
- if ((d = c.errors) != null && d.length)
152
- throw S(c.errors[0]);
153
- const n = (p = (h = (g = c.data) == null ? void 0 : g.checkoutStatus) == null ? void 0 : h.receipt) == null ? void 0 : p.checkoutId;
154
- if (await l(e, n, y), u)
155
- return c;
156
- let m = `/checkout/post-purchase?kiva_transaction_id=${n}`;
157
- i != null && i.inviterId && (m += `&valet_inviter=${i.inviterId}`), await _(m);
151
+ if ((y = s.errors) != null && y.length)
152
+ throw S(s.errors[0]);
153
+ const m = (g = (w = (a = s.data) == null ? void 0 : a.checkoutStatus) == null ? void 0 : w.receipt) == null ? void 0 : g.checkoutId;
154
+ if (await B(e, m, f), u)
155
+ return s;
156
+ let c = `/checkout/post-purchase?kiva_transaction_id=${m}`;
157
+ i != null && i.inviterId && (c += `&valet_inviter=${i.inviterId}`), await O(c);
158
158
  }
159
- async function at({
159
+ async function dt({
160
160
  amount: e,
161
161
  apollo: t,
162
162
  braintree: r,
163
163
  emailAddress: o,
164
164
  emailOptIn: i,
165
165
  fundTarget: u,
166
- userId: a,
167
- useKivaCredit: f = !0
166
+ userId: d,
167
+ useKivaCredit: k = !0
168
168
  }) {
169
- var h, p, k, C, b;
170
- await N({
169
+ var p, b, C, M, T;
170
+ await P({
171
171
  apollo: t,
172
172
  emailAddress: o,
173
173
  emailOptIn: i
174
174
  });
175
- const y = `campaignId: ${(await O({
175
+ const n = await Q({
176
176
  apollo: t,
177
177
  fundTarget: u,
178
- userId: a ? `${a}` : void 0
179
- })).id}`;
180
- await K({
178
+ userId: d ? `${d}` : void 0
179
+ }), f = `campaignId: ${n.id}`, I = await U({
181
180
  amount: e,
182
- metadata: y,
181
+ metadata: f,
183
182
  apollo: t
184
- }), f || await Q(t);
185
- const w = await R(t), c = T(w).value() > 0;
186
- if (c && !r)
183
+ });
184
+ k || await V(t);
185
+ const s = await A(t), m = R(s).value() > 0;
186
+ if (m && !r)
187
187
  throw new v({ code: "shop.dropinRequired" }, "Braintree dropin required for credit deposit checkout");
188
- let n, m = "";
189
- if (c) {
190
- const M = await F({
188
+ let c, h = "";
189
+ if (m) {
190
+ const q = await x({
191
191
  apollo: t,
192
192
  braintree: r,
193
- amount: w
193
+ amount: s
194
194
  });
195
- m = M.paymentType, n = await M.mutation;
195
+ h = q.paymentType, c = await q.mutation;
196
196
  } else
197
- n = await A(t);
198
- const I = (h = n == null ? void 0 : n.shop) == null ? void 0 : h.transactionId, d = await q({
197
+ c = await F(t);
198
+ const y = (p = c == null ? void 0 : c.shop) == null ? void 0 : p.transactionId, a = await D({
199
199
  apollo: t,
200
- transactionSagaId: I,
200
+ transactionSagaId: y,
201
201
  timeout: 3e5
202
202
  // five minutes
203
203
  });
204
- if ((p = d.errors) != null && p.length)
205
- throw S(d.errors[0]);
206
- const g = (b = (C = (k = d.data) == null ? void 0 : k.checkoutStatus) == null ? void 0 : C.receipt) == null ? void 0 : b.checkoutId;
207
- return await l(t, g, m), d;
204
+ if ((b = a.errors) != null && b.length)
205
+ throw S(a.errors[0]);
206
+ const w = (T = (M = (C = a.data) == null ? void 0 : C.checkoutStatus) == null ? void 0 : M.receipt) == null ? void 0 : T.checkoutId;
207
+ return await B(t, w, h), {
208
+ data: {
209
+ ...a.data,
210
+ checkoutStatus: {
211
+ ...a.data.checkoutStatus
212
+ },
213
+ donation: {
214
+ ...I
215
+ },
216
+ givingFund: {
217
+ id: n.id
218
+ }
219
+ },
220
+ errors: a.errors ?? []
221
+ };
208
222
  }
209
223
  export {
210
- nt as executeOneTimeCheckout,
211
- at as executeOneTimeCheckoutForGivingFund
224
+ ct as executeOneTimeCheckout,
225
+ dt as executeOneTimeCheckoutForGivingFund
212
226
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-shop",
3
- "version": "3.2.9",
3
+ "version": "3.3.0",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -55,5 +55,5 @@
55
55
  "numeral": "2.x",
56
56
  "vue": "3.x"
57
57
  },
58
- "gitHead": "c153687be5fd01c127a6c117eb061899d3da5105"
58
+ "gitHead": "66f2edef6330f52bb77fd6acb06b70cced0b883f"
59
59
  }