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