@idonatedev/idonate-sdk 1.1.0-dev13 → 1.1.0-dev15
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/constants.d.ts +1 -1
- package/dist/constants.js +2 -6
- package/dist/esm/apple-pay.d.ts +12 -0
- package/dist/esm/apple-pay.js +74 -0
- package/dist/esm/cloudflare-challenge-handler.d.ts +5 -0
- package/dist/esm/cloudflare-challenge-handler.js +77 -0
- package/dist/esm/config-handler.d.ts +22 -0
- package/dist/esm/config-handler.js +47 -0
- package/dist/esm/constants.d.ts +18 -0
- package/dist/esm/constants.js +81 -0
- package/dist/esm/google-pay.d.ts +18 -0
- package/dist/esm/google-pay.js +140 -0
- package/dist/esm/idonate-client.d.ts +28 -0
- package/dist/esm/idonate-client.js +256 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +11 -0
- package/dist/esm/recaptcha.d.ts +12 -0
- package/dist/esm/recaptcha.js +89 -0
- package/dist/esm/shared.d.ts +3 -0
- package/dist/esm/shared.js +13 -0
- package/dist/esm/test-utils.d.ts +81 -0
- package/dist/esm/test-utils.js +94 -0
- package/dist/esm/tokenize/CardConnectTokenizer.d.ts +51 -0
- package/dist/esm/tokenize/CardConnectTokenizer.js +706 -0
- package/dist/esm/tokenize/SpreedlyTokenizer.d.ts +92 -0
- package/dist/esm/tokenize/SpreedlyTokenizer.js +1140 -0
- package/dist/esm/tokenize/Tokenizer.d.ts +37 -0
- package/dist/esm/tokenize/Tokenizer.js +146 -0
- package/dist/esm/tokenize/iats.d.ts +3 -0
- package/dist/esm/tokenize/iats.js +48 -0
- package/dist/esm/tokenize/index.d.ts +6 -0
- package/dist/esm/tokenize/index.js +6 -0
- package/dist/esm/tokenize/spreedly-secure.d.ts +8 -0
- package/dist/esm/tokenize/spreedly-secure.js +40 -0
- package/dist/esm/tokenize/styles.d.ts +4 -0
- package/dist/esm/tokenize/styles.js +46 -0
- package/dist/esm/tokenize/tokenizer-constants.d.ts +62 -0
- package/dist/esm/tokenize/tokenizer-constants.js +62 -0
- package/dist/esm/tokenize/tokenizer-utils.d.ts +19 -0
- package/dist/esm/tokenize/tokenizer-utils.js +139 -0
- package/dist/esm/tokenize/types.d.ts +144 -0
- package/dist/esm/tokenize/types.js +26 -0
- package/dist/esm/typeAdapters.d.ts +29 -0
- package/dist/esm/typeAdapters.js +188 -0
- package/dist/esm/types.d.ts +367 -0
- package/dist/esm/types.js +14 -0
- package/dist/esm/util.d.ts +17 -0
- package/dist/esm/util.js +113 -0
- package/package.json +13 -2
- package/umd/idonate-sdk.js +1 -1
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
export declare const ApplePaySessionStatus: {
|
|
2
|
+
readonly STATUS_SUCCESS: number;
|
|
3
|
+
readonly STATUS_FAILURE: number;
|
|
4
|
+
};
|
|
5
|
+
export type ApplePayPaymentRequest = ApplePayJS.ApplePayPaymentRequest;
|
|
6
|
+
export type ClientOptions = {
|
|
7
|
+
enableSandboxMode?: boolean;
|
|
8
|
+
spreedlyEnvironmentKey?: string;
|
|
9
|
+
overrideBaseUrl?: string;
|
|
10
|
+
overrideAuthApiBaseUrl?: string;
|
|
11
|
+
overrideEmbedApiBaseUrl?: string;
|
|
12
|
+
overrideDonorApiBaseUrl?: string;
|
|
13
|
+
overrideCardConnectBaseUrl?: string;
|
|
14
|
+
overrideApplePayUrl?: string;
|
|
15
|
+
pcScriptBase?: string;
|
|
16
|
+
pcScriptId?: string;
|
|
17
|
+
enableDelay: boolean;
|
|
18
|
+
secondsToDelay: number;
|
|
19
|
+
turnstileCdnUrl?: string;
|
|
20
|
+
turnstileSiteKey?: string;
|
|
21
|
+
sdkClientName?: string;
|
|
22
|
+
enableSpreedlySecureTokenization?: boolean;
|
|
23
|
+
organizationId?: number;
|
|
24
|
+
embedId?: string;
|
|
25
|
+
};
|
|
26
|
+
export type Address = {
|
|
27
|
+
address1: string;
|
|
28
|
+
address2?: string;
|
|
29
|
+
country: string;
|
|
30
|
+
city: string;
|
|
31
|
+
state: string;
|
|
32
|
+
zip: string;
|
|
33
|
+
};
|
|
34
|
+
export type Contact = {
|
|
35
|
+
salutation?: string;
|
|
36
|
+
firstName: string;
|
|
37
|
+
middleName?: string;
|
|
38
|
+
lastName: string;
|
|
39
|
+
fullName?: string;
|
|
40
|
+
company: string;
|
|
41
|
+
email?: string;
|
|
42
|
+
primaryPhone: string;
|
|
43
|
+
};
|
|
44
|
+
export type CreditCard = {
|
|
45
|
+
cardNumber: string;
|
|
46
|
+
verificationValue?: string;
|
|
47
|
+
expirationMonth: string;
|
|
48
|
+
expirationYear: string;
|
|
49
|
+
};
|
|
50
|
+
export type ACHAccount = {
|
|
51
|
+
accountNumber: string;
|
|
52
|
+
routingNumber: string;
|
|
53
|
+
accountHolderType: 'personal' | 'business';
|
|
54
|
+
accountType: 'checking' | 'savings';
|
|
55
|
+
};
|
|
56
|
+
export type PaymentMethodType = 'credit_card' | 'bank_account' | 'paypal' | 'apple_pay' | 'google_pay';
|
|
57
|
+
export type RecaptchaType = 'v2' | 'v3' | 'invisible' | 'organization' | 'nonce';
|
|
58
|
+
export type RecaptchaSecuredRequest = {
|
|
59
|
+
recaptchaType: RecaptchaType;
|
|
60
|
+
recaptchaToken: string;
|
|
61
|
+
};
|
|
62
|
+
export type RecurringFrequency = 'once' | 'weekly' | 'twicemonthly' | 'biweekly' | 'monthly' | 'quarterly' | 'semiannually' | 'annually';
|
|
63
|
+
export type UTMData = {
|
|
64
|
+
campaign?: string;
|
|
65
|
+
content?: string;
|
|
66
|
+
medium?: string;
|
|
67
|
+
source?: string;
|
|
68
|
+
term?: string;
|
|
69
|
+
};
|
|
70
|
+
export type TributeData = {
|
|
71
|
+
tributeDefinitionId: string;
|
|
72
|
+
tributeFirstName: string;
|
|
73
|
+
tributeLastName: string;
|
|
74
|
+
tributeAddress1: string;
|
|
75
|
+
tributeAddress2: string;
|
|
76
|
+
tributeCity: string;
|
|
77
|
+
tributeState: string;
|
|
78
|
+
tributePostalCode: string;
|
|
79
|
+
tributeCountry: string;
|
|
80
|
+
tributeFromName: string;
|
|
81
|
+
tributeType: string;
|
|
82
|
+
tributeRecipientEmail: string;
|
|
83
|
+
honorees: {
|
|
84
|
+
firstname: string;
|
|
85
|
+
lastname: string;
|
|
86
|
+
message: string;
|
|
87
|
+
}[];
|
|
88
|
+
tributeSendCard: boolean;
|
|
89
|
+
tributeIncludeAmount: boolean;
|
|
90
|
+
tributeSkipped: boolean;
|
|
91
|
+
useOnBillingAddress: boolean;
|
|
92
|
+
};
|
|
93
|
+
export type CreateDonationRequest = RecaptchaSecuredRequest & {
|
|
94
|
+
paymentGatewayId: string;
|
|
95
|
+
donorId?: string;
|
|
96
|
+
paymentMethodId: string;
|
|
97
|
+
retainPaymentMethod?: boolean;
|
|
98
|
+
paymentAmount: number;
|
|
99
|
+
currency: string;
|
|
100
|
+
billingContact: Contact;
|
|
101
|
+
billingAddress: Address;
|
|
102
|
+
referenceCode?: string;
|
|
103
|
+
designationId?: string;
|
|
104
|
+
designations?: {
|
|
105
|
+
id: string;
|
|
106
|
+
amount: number;
|
|
107
|
+
}[];
|
|
108
|
+
designationNote?: string;
|
|
109
|
+
campaignId?: string;
|
|
110
|
+
p2pFundraiserId?: string;
|
|
111
|
+
p2pFundraiserComment?: string;
|
|
112
|
+
p2pProgramId?: string;
|
|
113
|
+
organizationEventId?: string;
|
|
114
|
+
corporateMatchingId?: string;
|
|
115
|
+
advocateId?: string;
|
|
116
|
+
advocacyProgramId?: string;
|
|
117
|
+
advocacyTeamId?: string;
|
|
118
|
+
landingPageId?: number;
|
|
119
|
+
customerMeta?: {
|
|
120
|
+
[key: string]: string;
|
|
121
|
+
};
|
|
122
|
+
utm?: UTMData;
|
|
123
|
+
tribute?: TributeData;
|
|
124
|
+
recurringFrequency: RecurringFrequency;
|
|
125
|
+
recurringStart?: Date;
|
|
126
|
+
recurringEnd?: Date;
|
|
127
|
+
donorPaidFeeAmount?: number;
|
|
128
|
+
emailOptIn?: boolean;
|
|
129
|
+
anonymousOptIn?: boolean;
|
|
130
|
+
showNameToFundraiserOptIn?: boolean;
|
|
131
|
+
giftId?: string;
|
|
132
|
+
giftExtra?: string;
|
|
133
|
+
giftSkipped?: boolean;
|
|
134
|
+
embedId?: string;
|
|
135
|
+
convertedToRecurring?: boolean | undefined;
|
|
136
|
+
};
|
|
137
|
+
export type UtmFields = {
|
|
138
|
+
utm_campaign?: string;
|
|
139
|
+
utm_content?: string;
|
|
140
|
+
utm_medium?: string;
|
|
141
|
+
utm_source?: string;
|
|
142
|
+
utm_term?: string;
|
|
143
|
+
};
|
|
144
|
+
export type CashPaymentPayload = {
|
|
145
|
+
organization_id: string;
|
|
146
|
+
campaign_id: string;
|
|
147
|
+
reference_code: string;
|
|
148
|
+
double_the_donation_company_id: string;
|
|
149
|
+
donor_id: string;
|
|
150
|
+
hide_name: boolean;
|
|
151
|
+
show_name_to_fundraiser: boolean;
|
|
152
|
+
email_opt_in: boolean;
|
|
153
|
+
donor_paid_fee: number;
|
|
154
|
+
designation_note: string;
|
|
155
|
+
gift_id: string;
|
|
156
|
+
gift_extra: string;
|
|
157
|
+
gift_skipped: boolean;
|
|
158
|
+
p2p_fundraiser_id: string;
|
|
159
|
+
p2p_fundraiser_comment: string;
|
|
160
|
+
organization_event_id: string;
|
|
161
|
+
advocate_id: string;
|
|
162
|
+
advocacy_program_id: string;
|
|
163
|
+
advocacy_team_id: string;
|
|
164
|
+
page_id: number;
|
|
165
|
+
embed_id: string;
|
|
166
|
+
tribute_definition_id: string;
|
|
167
|
+
tribute_recipient_first_name: string;
|
|
168
|
+
tribute_recipient_last_name: string;
|
|
169
|
+
tribute_address1: string;
|
|
170
|
+
tribute_address2: string;
|
|
171
|
+
tribute_city: string;
|
|
172
|
+
tribute_state: string;
|
|
173
|
+
tribute_postal_code: string;
|
|
174
|
+
tribute_country: string;
|
|
175
|
+
tribute_from_name: string;
|
|
176
|
+
tribute_recipient_email: string;
|
|
177
|
+
honorees: {
|
|
178
|
+
firstname: string;
|
|
179
|
+
lastname: string;
|
|
180
|
+
message: string;
|
|
181
|
+
}[];
|
|
182
|
+
tribute_send_card: boolean;
|
|
183
|
+
tribute_include_amount: boolean;
|
|
184
|
+
tribute_skipped: boolean;
|
|
185
|
+
tribute_type: string;
|
|
186
|
+
useOnBillingAddress: boolean;
|
|
187
|
+
embed_referer: string;
|
|
188
|
+
converted_to_recurring: boolean;
|
|
189
|
+
customer_meta: Record<string, string>;
|
|
190
|
+
recaptcha_token: string;
|
|
191
|
+
recaptcha_type: string;
|
|
192
|
+
designations: {
|
|
193
|
+
id: string;
|
|
194
|
+
amount: number;
|
|
195
|
+
}[];
|
|
196
|
+
country: string;
|
|
197
|
+
address1: string;
|
|
198
|
+
address2: string | undefined;
|
|
199
|
+
city: string;
|
|
200
|
+
state: string;
|
|
201
|
+
zip_code: string;
|
|
202
|
+
title?: string;
|
|
203
|
+
first_name: string;
|
|
204
|
+
middle_name?: string | undefined;
|
|
205
|
+
last_name: string;
|
|
206
|
+
company_name: string;
|
|
207
|
+
email?: string;
|
|
208
|
+
home_phone: string;
|
|
209
|
+
timezone: string;
|
|
210
|
+
payment_method_id: string;
|
|
211
|
+
gateway_id: string;
|
|
212
|
+
amount: number;
|
|
213
|
+
type: 'cash';
|
|
214
|
+
frequency: RecurringFrequency;
|
|
215
|
+
start_date: Date | undefined;
|
|
216
|
+
end_date: Date | undefined;
|
|
217
|
+
retain_on_success: boolean | undefined;
|
|
218
|
+
} & UtmFields;
|
|
219
|
+
export type ClientErrorDetails = {
|
|
220
|
+
field?: string;
|
|
221
|
+
code?: string;
|
|
222
|
+
suggestion?: string;
|
|
223
|
+
_rawPayload?: any;
|
|
224
|
+
};
|
|
225
|
+
export declare class ClientError extends Error {
|
|
226
|
+
message: string;
|
|
227
|
+
details?: ClientErrorDetails | undefined;
|
|
228
|
+
constructor(message: string, details?: ClientErrorDetails | undefined);
|
|
229
|
+
}
|
|
230
|
+
export type ClientResponse = {
|
|
231
|
+
errors: ClientError[];
|
|
232
|
+
_raw_response?: any;
|
|
233
|
+
};
|
|
234
|
+
export type CreateDonationResult = ClientResponse & {
|
|
235
|
+
transaction?: Transaction;
|
|
236
|
+
schedule?: Schedule;
|
|
237
|
+
donor?: Donor;
|
|
238
|
+
designation?: Designation;
|
|
239
|
+
campaign?: Campaign;
|
|
240
|
+
};
|
|
241
|
+
export type CreatePaymentMethodRequest = RecaptchaSecuredRequest & {
|
|
242
|
+
paymentMethodType: PaymentMethodType;
|
|
243
|
+
paymentMethodToken: string;
|
|
244
|
+
donorId?: string;
|
|
245
|
+
paymentGatewayId?: string;
|
|
246
|
+
backendName?: BackendName;
|
|
247
|
+
embedId?: string;
|
|
248
|
+
contact: Contact;
|
|
249
|
+
address: Address;
|
|
250
|
+
};
|
|
251
|
+
export type CreatePaymentMethodResult = ClientResponse & {
|
|
252
|
+
paymentMethodId: string;
|
|
253
|
+
};
|
|
254
|
+
export type Campaign = {
|
|
255
|
+
title: string;
|
|
256
|
+
};
|
|
257
|
+
export type Designation = {
|
|
258
|
+
id: string;
|
|
259
|
+
title: string;
|
|
260
|
+
};
|
|
261
|
+
export type Donor = {
|
|
262
|
+
id: string;
|
|
263
|
+
created: string;
|
|
264
|
+
contact: {
|
|
265
|
+
created: string;
|
|
266
|
+
updated: string;
|
|
267
|
+
title: string;
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
export type TokenizeCardConnectResult = {
|
|
271
|
+
token: string;
|
|
272
|
+
message: string;
|
|
273
|
+
errorcode: number;
|
|
274
|
+
};
|
|
275
|
+
export type BackendName = 'spreedly' | 'card_connect' | 'iats';
|
|
276
|
+
export type PaymentGateway = {
|
|
277
|
+
id: string;
|
|
278
|
+
backendName: BackendName;
|
|
279
|
+
};
|
|
280
|
+
export type PaymentMethod = {
|
|
281
|
+
id: string;
|
|
282
|
+
type: PaymentMethodType;
|
|
283
|
+
};
|
|
284
|
+
export type Schedule = {
|
|
285
|
+
id: string;
|
|
286
|
+
recurringFrequency: RecurringFrequency;
|
|
287
|
+
};
|
|
288
|
+
export type Transaction = {
|
|
289
|
+
id: string;
|
|
290
|
+
};
|
|
291
|
+
export type Donation = {
|
|
292
|
+
id: string;
|
|
293
|
+
transaction?: Transaction;
|
|
294
|
+
schedule?: Schedule;
|
|
295
|
+
};
|
|
296
|
+
export type TokenizeCardConnectBankAccountResult = TokenizeCardConnectResult;
|
|
297
|
+
export type TokenizeCardConnectApplePayResult = TokenizeCardConnectResult;
|
|
298
|
+
export type TokenizeCardConnectGooglePayResult = TokenizeCardConnectResult;
|
|
299
|
+
export type ApplePayContact = ApplePayJS.ApplePayPaymentContact & {
|
|
300
|
+
email?: string;
|
|
301
|
+
phone?: string;
|
|
302
|
+
};
|
|
303
|
+
export type TokenizeApplePayResult = {
|
|
304
|
+
applePaySession: ApplePaySession;
|
|
305
|
+
cardConnectResponse: TokenizeCardConnectApplePayResult;
|
|
306
|
+
billingContact?: ApplePayContact;
|
|
307
|
+
merchantSessionId?: string;
|
|
308
|
+
};
|
|
309
|
+
export type MerchantSession = any;
|
|
310
|
+
export type ApplePayMerchantValidationPayload = {
|
|
311
|
+
apple_pay_url: string;
|
|
312
|
+
organization_id: string;
|
|
313
|
+
};
|
|
314
|
+
export type GooglePayBaseCardPaymentMethodType = {
|
|
315
|
+
type: google.payments.api.PaymentMethodType;
|
|
316
|
+
parameters: google.payments.api.CardParameters;
|
|
317
|
+
};
|
|
318
|
+
export type GooglePayConfig = {
|
|
319
|
+
paymentDataRequest: Partial<Omit<google.payments.api.PaymentDataRequest, 'transactionInfo'>> & {
|
|
320
|
+
transactionInfo: Partial<google.payments.api.PaymentDataRequest['transactionInfo']>;
|
|
321
|
+
};
|
|
322
|
+
paymentOptions: google.payments.api.PaymentOptions;
|
|
323
|
+
cardConnectMerchantId: string;
|
|
324
|
+
baseCardPaymentMethodParameters?: Partial<GooglePayBaseCardPaymentMethodType['parameters']>;
|
|
325
|
+
};
|
|
326
|
+
export interface SpreedlyPaymentMethodPayload {
|
|
327
|
+
retained?: boolean;
|
|
328
|
+
metadata?: Record<string, string>;
|
|
329
|
+
}
|
|
330
|
+
export interface SpreedlyPaymentMethodBankAccountPayload extends SpreedlyPaymentMethodPayload {
|
|
331
|
+
payment_method: {
|
|
332
|
+
bank_account: ({
|
|
333
|
+
first_name: string;
|
|
334
|
+
last_name: string;
|
|
335
|
+
} | {
|
|
336
|
+
full_name: string;
|
|
337
|
+
}) & {
|
|
338
|
+
bank_routing_number: string;
|
|
339
|
+
bank_account_number: string;
|
|
340
|
+
bank_name?: string;
|
|
341
|
+
bank_account_type?: 'checking' | 'savings';
|
|
342
|
+
bank_account_holder_type?: 'business' | 'personal';
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
export interface SpreedlyInstance {
|
|
347
|
+
init(key: string, opts: {
|
|
348
|
+
numberEl: string;
|
|
349
|
+
cvvEl: string;
|
|
350
|
+
}): void;
|
|
351
|
+
on(key: string, func: (param1: any | null, param2: any | null, param3: any | null, param4: any | null) => void): void;
|
|
352
|
+
validate(): void;
|
|
353
|
+
setPlaceholder(fields: string, placeholder: string): void;
|
|
354
|
+
setFieldType(fields: string, placeholder: string): void;
|
|
355
|
+
setStyle(fields: string, placeholder: string): void;
|
|
356
|
+
setNumberFormat(fields: string): void;
|
|
357
|
+
reload(): void;
|
|
358
|
+
tokenizeCreditCard(fields: {
|
|
359
|
+
first_name: string;
|
|
360
|
+
last_name: string;
|
|
361
|
+
month: string;
|
|
362
|
+
year: string;
|
|
363
|
+
email?: string;
|
|
364
|
+
zip?: string;
|
|
365
|
+
}): void;
|
|
366
|
+
removeHandlers(): void;
|
|
367
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export const ApplePaySessionStatus = {
|
|
2
|
+
STATUS_SUCCESS: typeof ApplePaySession !== 'undefined' ? ApplePaySession.STATUS_SUCCESS : 1,
|
|
3
|
+
STATUS_FAILURE: typeof ApplePaySession !== 'undefined' ? ApplePaySession.STATUS_FAILURE : 0,
|
|
4
|
+
};
|
|
5
|
+
export class ClientError extends Error {
|
|
6
|
+
constructor(message, details) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.message = message;
|
|
9
|
+
this.details = details;
|
|
10
|
+
if (Error.captureStackTrace) {
|
|
11
|
+
Error.captureStackTrace(this, ClientError);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ClientResponse } from './types';
|
|
2
|
+
export declare function receiveEmbedData(): Promise<any>;
|
|
3
|
+
export declare function sanitizeString(value: string): string;
|
|
4
|
+
type SanitizeableObject = {
|
|
5
|
+
[key: string]: SanitizeableObject;
|
|
6
|
+
} | string | boolean | number | SanitizeableObject[];
|
|
7
|
+
export declare function sanitizeArray(array: SanitizeableObject[]): SanitizeableObject[];
|
|
8
|
+
export declare function sanitizeObject(object: SanitizeableObject): SanitizeableObject;
|
|
9
|
+
type Name = {
|
|
10
|
+
firstName: string;
|
|
11
|
+
lastName: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function splitName(fullname: string): Name;
|
|
14
|
+
export declare function parseResponse(response: Response, opts?: {
|
|
15
|
+
throwErrors?: boolean;
|
|
16
|
+
}): Promise<ClientResponse>;
|
|
17
|
+
export {};
|
package/dist/esm/util.js
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { ClientError } from './types';
|
|
2
|
+
import { collapseClientErrors } from './typeAdapters';
|
|
3
|
+
export function receiveEmbedData() {
|
|
4
|
+
let handler;
|
|
5
|
+
return new Promise((resolve, reject) => {
|
|
6
|
+
if (!window.parent) {
|
|
7
|
+
reject('Cannot receive data without parent');
|
|
8
|
+
}
|
|
9
|
+
handler = (evt) => {
|
|
10
|
+
let data;
|
|
11
|
+
try {
|
|
12
|
+
data = JSON.parse(evt.data);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (data.embedData) {
|
|
18
|
+
resolve(data.embedData);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
window.addEventListener('message', handler);
|
|
22
|
+
}).then((data) => {
|
|
23
|
+
window.removeEventListener('message', handler);
|
|
24
|
+
return data;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
export function sanitizeString(value) {
|
|
28
|
+
if (!value) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
const tmp = document.createElement('div');
|
|
32
|
+
tmp.innerHTML = value;
|
|
33
|
+
const scripts = Array.from(tmp.getElementsByTagName('script'));
|
|
34
|
+
for (const script of scripts) {
|
|
35
|
+
if (script.parentNode) {
|
|
36
|
+
script.parentNode.removeChild(script);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return tmp.innerHTML;
|
|
40
|
+
}
|
|
41
|
+
export function sanitizeArray(array) {
|
|
42
|
+
return array.map(sanitizeObject);
|
|
43
|
+
}
|
|
44
|
+
export function sanitizeObject(object) {
|
|
45
|
+
if (object === null || object === undefined) {
|
|
46
|
+
return object;
|
|
47
|
+
}
|
|
48
|
+
else if (Array.isArray(object)) {
|
|
49
|
+
return sanitizeArray(object);
|
|
50
|
+
}
|
|
51
|
+
else if (typeof object === 'string') {
|
|
52
|
+
return sanitizeString(object);
|
|
53
|
+
}
|
|
54
|
+
else if (typeof object === 'object') {
|
|
55
|
+
const newObject = {};
|
|
56
|
+
for (const [key, value] of Object.entries(object)) {
|
|
57
|
+
if (Array.isArray(value)) {
|
|
58
|
+
newObject[key] = sanitizeArray(value);
|
|
59
|
+
}
|
|
60
|
+
else if (typeof value === 'string') {
|
|
61
|
+
newObject[key] = sanitizeString(value);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
newObject[key] = sanitizeObject(value);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return newObject;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
return object;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
export function splitName(fullname) {
|
|
74
|
+
const nameParts = fullname.split(' ');
|
|
75
|
+
const firstName = nameParts.slice(0, -1).join(' ') || 'NOT GIVEN';
|
|
76
|
+
const lastName = nameParts.slice(-1).join(' ');
|
|
77
|
+
const nameObj = {
|
|
78
|
+
firstName,
|
|
79
|
+
lastName,
|
|
80
|
+
};
|
|
81
|
+
return nameObj;
|
|
82
|
+
}
|
|
83
|
+
export function parseResponse(response, opts) {
|
|
84
|
+
return response.json().then((json) => {
|
|
85
|
+
const errors = [];
|
|
86
|
+
if (response.status !== 200) {
|
|
87
|
+
if (json.result !== undefined) {
|
|
88
|
+
Object.keys(json.result).forEach((key) => {
|
|
89
|
+
errors.push(new ClientError(key + ': ' + json.result[key].join('\n '), {
|
|
90
|
+
field: key,
|
|
91
|
+
}));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (json.messages !== undefined) {
|
|
95
|
+
json.messages.forEach((msg) => {
|
|
96
|
+
if (msg.category === 'error') {
|
|
97
|
+
errors.push(new ClientError(msg.message));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
errors.push(new ClientError(json.message));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (opts && opts.throwErrors && errors.length) {
|
|
106
|
+
throw collapseClientErrors(errors);
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
errors,
|
|
110
|
+
_raw_response: json,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idonatedev/idonate-sdk",
|
|
3
3
|
"author": "iDonate",
|
|
4
|
-
"version": "1.1.0-
|
|
4
|
+
"version": "1.1.0-dev15",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "iDonate Web SDK",
|
|
7
7
|
"engines": {
|
|
8
8
|
"node": ">=18.0.0"
|
|
9
9
|
},
|
|
10
10
|
"main": "dist/index.js",
|
|
11
|
+
"module": "dist/esm/index.js",
|
|
11
12
|
"unpkg": "umd/idonate-sdk.js",
|
|
12
13
|
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/esm/index.js",
|
|
17
|
+
"require": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
13
21
|
"files": [
|
|
14
22
|
"/dist",
|
|
15
23
|
"/umd"
|
|
@@ -22,7 +30,10 @@
|
|
|
22
30
|
"lint": "npx eslint 'src/**/*.ts'",
|
|
23
31
|
"lint:fix": "npx eslint --fix 'src/**/*.ts'",
|
|
24
32
|
"format": "npx prettier --write 'src/**/*.ts'",
|
|
25
|
-
"build": "
|
|
33
|
+
"build": "npm run build:cjs && npm run build:esm && npm run inject:version && webpack",
|
|
34
|
+
"build:cjs": "npx tsc",
|
|
35
|
+
"build:esm": "npx tsc -p tsconfig.esm.json",
|
|
36
|
+
"inject:version": "node scripts/inject-version.js",
|
|
26
37
|
"watch": "npx tsc -w & webpack --watch",
|
|
27
38
|
"dev:server": "http-server -p 8000 -c-1 -o /e2e/donation-flow-enhanced.html",
|
|
28
39
|
"dev": "concurrently \"npm run dev:server\" \"npm run watch\" --names \"server,build\" --prefix-colors \"blue,green\"",
|