@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.
Files changed (76) hide show
  1. package/dist/_virtual/_commonjs-dynamic-modules.js +6 -0
  2. package/dist/_virtual/_commonjsHelpers.js +8 -0
  3. package/dist/_virtual/_plugin-vue_export-helper.js +9 -0
  4. package/dist/_virtual/dropin.js +11 -0
  5. package/dist/_virtual/dropin2.js +4 -0
  6. package/dist/basket.js +35 -12
  7. package/dist/basketCredits.js +78 -14
  8. package/dist/basketItems.js +27 -8
  9. package/dist/basketTotals.js +38 -10
  10. package/dist/basketVerification.js +6 -6
  11. package/dist/checkoutStatus.js +52 -8
  12. package/dist/components/KvPaymentSelect.css +1 -0
  13. package/dist/components/KvPaymentSelect.js +23 -0
  14. package/dist/components/KvPaymentSelect2.js +110 -0
  15. package/dist/index.d.ts +321 -20
  16. package/dist/index.js +49 -96
  17. package/dist/managedAccount.js +62 -8
  18. package/dist/oneTimeCheckout.js +156 -12
  19. package/dist/receipt.js +143 -12
  20. package/dist/shopError.js +41 -6
  21. package/dist/shopQueries.js +82 -11
  22. package/dist/subscriptionCheckout.js +88 -7
  23. package/dist/useBraintreeDropIn.js +145 -9
  24. package/dist/util/cookie.js +11 -0
  25. package/dist/util/poll.js +17 -0
  26. package/dist/util/redirect.js +8 -0
  27. package/dist/util/visitorId.js +7 -0
  28. package/dist/validatePreCheckout.js +44 -11
  29. package/dist/vendor/braintree-web-drop-in/dist/browser/dropin.js +12223 -0
  30. package/package.json +28 -26
  31. package/dist/basket.cjs +0 -141
  32. package/dist/basket.d.ts +0 -8
  33. package/dist/basketCredits.cjs +0 -250
  34. package/dist/basketCredits.d.ts +0 -32
  35. package/dist/basketItems.cjs +0 -205
  36. package/dist/basketItems.d.ts +0 -26
  37. package/dist/basketTotals.cjs +0 -228
  38. package/dist/basketTotals.d.ts +0 -37
  39. package/dist/basketVerification.cjs +0 -41
  40. package/dist/basketVerification.d.ts +0 -10
  41. package/dist/checkoutStatus.cjs +0 -111
  42. package/dist/checkoutStatus.d.ts +0 -20
  43. package/dist/chunk-4ODZGLWK.js +0 -64
  44. package/dist/chunk-ASZJVUQ7.js +0 -72
  45. package/dist/chunk-FBF4WMN6.js +0 -49
  46. package/dist/chunk-FC4QW6QA.js +0 -106
  47. package/dist/chunk-FCAOCO7O.js +0 -17
  48. package/dist/chunk-GVVI7X2R.js +0 -196
  49. package/dist/chunk-IIN37LC7.js +0 -45
  50. package/dist/chunk-IOZ5ERDX.js +0 -121
  51. package/dist/chunk-KCUOMCSN.js +0 -58
  52. package/dist/chunk-LZ4UMRCV.js +0 -16
  53. package/dist/chunk-RQNRQ2E5.js +0 -155
  54. package/dist/chunk-SRGYGDAX.js +0 -80
  55. package/dist/chunk-TPJPGUO7.js +0 -12
  56. package/dist/chunk-UJXHTR43.js +0 -86
  57. package/dist/chunk-VZ3VDRRP.js +0 -167
  58. package/dist/chunk-Z7JRY3QE.js +0 -34
  59. package/dist/components/KvPaymentSelect.vue +0 -380
  60. package/dist/index.cjs +0 -1227
  61. package/dist/managedAccount.cjs +0 -231
  62. package/dist/managedAccount.d.ts +0 -59
  63. package/dist/oneTimeCheckout.cjs +0 -636
  64. package/dist/oneTimeCheckout.d.ts +0 -21
  65. package/dist/receipt.cjs +0 -191
  66. package/dist/receipt.d.ts +0 -16
  67. package/dist/shopError.cjs +0 -88
  68. package/dist/shopError.d.ts +0 -14
  69. package/dist/shopQueries.cjs +0 -248
  70. package/dist/shopQueries.d.ts +0 -8
  71. package/dist/subscriptionCheckout.cjs +0 -187
  72. package/dist/subscriptionCheckout.d.ts +0 -13
  73. package/dist/useBraintreeDropIn.cjs +0 -258
  74. package/dist/useBraintreeDropIn.d.ts +0 -25
  75. package/dist/validatePreCheckout.cjs +0 -218
  76. package/dist/validatePreCheckout.d.ts +0 -28
@@ -1,231 +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/managedAccount.ts
20
- var managedAccount_exports = {};
21
- __export(managedAccount_exports, {
22
- getPromoFromBasket: () => getPromoFromBasket
23
- });
24
- module.exports = __toCommonJS(managedAccount_exports);
25
- var import_core2 = require("@apollo/client/core/core.cjs");
26
-
27
- // src/basket.ts
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
-
136
- // src/shopQueries.ts
137
- async function callShopQuery(apollo, options, maxretries = 2) {
138
- try {
139
- const result = await apollo.query({
140
- ...options,
141
- variables: {
142
- ...options.variables,
143
- basketId: getBasketID()
144
- }
145
- });
146
- if (result?.errors?.length) {
147
- const basketErrors = result?.errors.filter((err) => hasBasketExpired(err));
148
- if (basketErrors.length) {
149
- if (maxretries > 0) {
150
- await createBasket(apollo);
151
- return callShopQuery(apollo, options, maxretries - 1);
152
- }
153
- throw basketErrors[0];
154
- }
155
- if (result?.errors?.length) {
156
- throw result.errors[0];
157
- }
158
- }
159
- return result?.data;
160
- } catch (e) {
161
- throw parseShopError(e);
162
- }
163
- }
164
-
165
- // src/managedAccount.ts
166
- async function getPromoFromBasket(apollo, options) {
167
- if (!options?.variables?.promoFundId && !options?.variables?.basketId) {
168
- return Promise.resolve({ error: "promoFundId or basketId variable required" });
169
- }
170
- const data = await callShopQuery(apollo, {
171
- variables: { ...options?.variables },
172
- query: import_core2.gql`
173
- query promoCampaign($basketId: String, $promoFundId: String) {
174
- shop (basketId: $basketId) {
175
- id
176
- promoCampaign (promoFundId: $promoFundId) {
177
- promoFund {
178
- id
179
- displayName
180
- displayDescription
181
- promoPrice
182
- }
183
- promoGroup {
184
- id
185
- type
186
- teamId
187
- }
188
- managedAccount {
189
- managementType
190
- audience
191
- allowDonations
192
- sendKivaNewsletter
193
- id
194
- isEmployee
195
- formId
196
- pageId
197
- loanSearchCriteria {
198
- filters {
199
- cityState
200
- country
201
- currencyLossPossible
202
- dafEligible
203
- distributionModel
204
- status
205
- excludeNonRated
206
- expiringSoon
207
- gender
208
- hasResearchScore
209
- isGroup
210
- lenderFavorite
211
- loanLimit
212
- isMatched
213
- sector
214
- loanTags
215
- theme
216
- }
217
- sortBy
218
- }
219
- }
220
- }
221
- }
222
- }
223
- `,
224
- fetchPolicy: options?.fetchPolicy ?? "network-only"
225
- }, 0);
226
- return data;
227
- }
228
- // Annotate the CommonJS export names for ESM import in node:
229
- 0 && (module.exports = {
230
- getPromoFromBasket
231
- });
@@ -1,59 +0,0 @@
1
- import { ApolloClient, QueryOptions } from '@apollo/client/core/core.cjs';
2
-
3
- interface ShopPromoCampaignData {
4
- shop?: {
5
- id: string;
6
- promoCampaign?: {
7
- promoFund?: {
8
- id: number;
9
- displayName: string;
10
- displayDescription: string;
11
- promoPrice: string;
12
- };
13
- promoGroup?: {
14
- id: number;
15
- type: string;
16
- teamId: number;
17
- };
18
- managedAccount?: {
19
- managementType: string;
20
- audience: string;
21
- allowDonations: string;
22
- sendKivaNewsletter: string;
23
- id: number;
24
- isEmployee: boolean;
25
- formId: string;
26
- pageId: string;
27
- loanSearchCriteria: {
28
- filters: {
29
- cityState: [string];
30
- country: [string];
31
- currencyLossPossible: boolean;
32
- dafEligible: boolean;
33
- distributionModel: any | string;
34
- excludeNonRated: boolean;
35
- expiringSoon: boolean;
36
- gender: any | string;
37
- hasResearchScore: boolean;
38
- isGroup: boolean;
39
- lenderFavorite: number;
40
- loanLimit: number;
41
- loanTags: [number];
42
- isMatched: boolean;
43
- sector: [number];
44
- status: any | string;
45
- theme: [string];
46
- };
47
- sortBy: any | string | null;
48
- } | any | null;
49
- } | any | null;
50
- } | any | null;
51
- } | null;
52
- }
53
- interface ShopPromoCampaignError {
54
- shop?: any;
55
- error?: string | null;
56
- }
57
- declare function getPromoFromBasket(apollo: ApolloClient<any>, options: QueryOptions<any>): Promise<ShopPromoCampaignData | ShopPromoCampaignError | null>;
58
-
59
- export { ShopPromoCampaignData, ShopPromoCampaignError, getPromoFromBasket };