@lacagnottedesproches/lcdp-js-lite 1.8.0 → 1.9.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/package.json +1 -1
- package/src/api.ts +125 -2
- package/src/types.ts +131 -1
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Account,
|
|
3
|
+
AccountAndPotCreated,
|
|
2
4
|
AccountCreated,
|
|
5
|
+
ExternalTokenObject,
|
|
3
6
|
LCDPApi,
|
|
4
7
|
PotCreated,
|
|
5
8
|
TokenObject,
|
|
6
|
-
AccountAndPotCreated,
|
|
7
9
|
} from "./types";
|
|
8
10
|
|
|
9
11
|
interface LCDPApiResponse {
|
|
@@ -24,7 +26,7 @@ export class LCDPRequest implements LCDPApi {
|
|
|
24
26
|
|
|
25
27
|
requestLCDPApi = (
|
|
26
28
|
endpoint: string,
|
|
27
|
-
payload: TokenObject,
|
|
29
|
+
payload: TokenObject | ExternalTokenObject,
|
|
28
30
|
authToken: string,
|
|
29
31
|
customMethod: "POST" | "PATCH" = "POST",
|
|
30
32
|
): Promise<LCDPApiResponse | void> => {
|
|
@@ -59,6 +61,40 @@ export class LCDPRequest implements LCDPApi {
|
|
|
59
61
|
});
|
|
60
62
|
};
|
|
61
63
|
|
|
64
|
+
requestGetLCDPApi = (
|
|
65
|
+
endpoint: string,
|
|
66
|
+
authToken: string,
|
|
67
|
+
): Promise<LCDPApiResponse | void> => {
|
|
68
|
+
if (typeof window !== "undefined") {
|
|
69
|
+
throw new Error("Must be used server side");
|
|
70
|
+
}
|
|
71
|
+
return new Promise(async (resolve, reject) => {
|
|
72
|
+
const url = `${this._apiUrl}/${endpoint}`;
|
|
73
|
+
try {
|
|
74
|
+
const response = await fetch(url, {
|
|
75
|
+
method: "GET",
|
|
76
|
+
headers: {
|
|
77
|
+
"Content-Type": "application/json",
|
|
78
|
+
"User-Agent": "lcdp/v1",
|
|
79
|
+
Authorization: `Bearer ${authToken}`,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
const status = response.status;
|
|
83
|
+
if (status >= 400) {
|
|
84
|
+
const { detail } = await response.json();
|
|
85
|
+
reject(detail);
|
|
86
|
+
} else if (status === 204) {
|
|
87
|
+
resolve();
|
|
88
|
+
} else {
|
|
89
|
+
const data = await response.json();
|
|
90
|
+
resolve(data);
|
|
91
|
+
}
|
|
92
|
+
} catch (error) {
|
|
93
|
+
reject(error);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
62
98
|
createAccount = async (payload: TokenObject): Promise<AccountCreated> => {
|
|
63
99
|
return new Promise(async (resolve, reject) => {
|
|
64
100
|
const responsePromise = this.requestLCDPApi(
|
|
@@ -140,4 +176,91 @@ export class LCDPRequest implements LCDPApi {
|
|
|
140
176
|
.catch((reason) => reject(reason));
|
|
141
177
|
});
|
|
142
178
|
};
|
|
179
|
+
|
|
180
|
+
getAccount = async (accountId: string): Promise<Account> => {
|
|
181
|
+
return new Promise(async (resolve, reject) => {
|
|
182
|
+
const responsePromise = this.requestGetLCDPApi(
|
|
183
|
+
`accounts/${accountId}`,
|
|
184
|
+
this._apiToken,
|
|
185
|
+
);
|
|
186
|
+
return responsePromise
|
|
187
|
+
.then((data) => {
|
|
188
|
+
try {
|
|
189
|
+
resolve(data as unknown as Account);
|
|
190
|
+
} catch (error) {
|
|
191
|
+
reject(error);
|
|
192
|
+
}
|
|
193
|
+
})
|
|
194
|
+
.catch((reason) => reject(reason));
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
updateAccount = async (
|
|
199
|
+
accountId: string,
|
|
200
|
+
payload: ExternalTokenObject,
|
|
201
|
+
): Promise<void> => {
|
|
202
|
+
return new Promise(async (resolve, reject) => {
|
|
203
|
+
const responsePromise = this.requestLCDPApi(
|
|
204
|
+
`accounts/${accountId}`,
|
|
205
|
+
payload,
|
|
206
|
+
this._apiToken,
|
|
207
|
+
"PATCH",
|
|
208
|
+
);
|
|
209
|
+
return responsePromise
|
|
210
|
+
.then((_) => {
|
|
211
|
+
try {
|
|
212
|
+
resolve();
|
|
213
|
+
} catch (error) {
|
|
214
|
+
reject(error);
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
.catch((reason) => reject(reason));
|
|
218
|
+
});
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
updateAccountIdentity = async (
|
|
222
|
+
accountId: string,
|
|
223
|
+
payload: ExternalTokenObject,
|
|
224
|
+
): Promise<void> => {
|
|
225
|
+
return new Promise(async (resolve, reject) => {
|
|
226
|
+
const responsePromise = this.requestLCDPApi(
|
|
227
|
+
`accounts/${accountId}/identity`,
|
|
228
|
+
payload,
|
|
229
|
+
this._apiToken,
|
|
230
|
+
"POST",
|
|
231
|
+
);
|
|
232
|
+
return responsePromise
|
|
233
|
+
.then((_) => {
|
|
234
|
+
try {
|
|
235
|
+
resolve();
|
|
236
|
+
} catch (error) {
|
|
237
|
+
reject(error);
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
.catch((reason) => reject(reason));
|
|
241
|
+
});
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
updateAccountBank = async (
|
|
245
|
+
accountId: string,
|
|
246
|
+
payload: ExternalTokenObject,
|
|
247
|
+
): Promise<void> => {
|
|
248
|
+
return new Promise(async (resolve, reject) => {
|
|
249
|
+
const responsePromise = this.requestLCDPApi(
|
|
250
|
+
`accounts/${accountId}/bank`,
|
|
251
|
+
payload,
|
|
252
|
+
this._apiToken,
|
|
253
|
+
"POST",
|
|
254
|
+
);
|
|
255
|
+
return responsePromise
|
|
256
|
+
.then((_) => {
|
|
257
|
+
try {
|
|
258
|
+
resolve();
|
|
259
|
+
} catch (error) {
|
|
260
|
+
reject(error);
|
|
261
|
+
}
|
|
262
|
+
})
|
|
263
|
+
.catch((reason) => reject(reason));
|
|
264
|
+
});
|
|
265
|
+
};
|
|
143
266
|
}
|
package/src/types.ts
CHANGED
|
@@ -33,6 +33,12 @@ export interface TokenObject {
|
|
|
33
33
|
client_ip: string;
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
+
export interface ExternalTokenObject {
|
|
37
|
+
id: string;
|
|
38
|
+
type: string;
|
|
39
|
+
client_ip: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
interface Pagination {
|
|
37
43
|
has_next: boolean;
|
|
38
44
|
has_prev: boolean;
|
|
@@ -71,6 +77,7 @@ export interface Pot {
|
|
|
71
77
|
with_tax_receipt: boolean;
|
|
72
78
|
tags?: string[];
|
|
73
79
|
metadata?: Record<string, unknown>;
|
|
80
|
+
account_id: string;
|
|
74
81
|
}
|
|
75
82
|
|
|
76
83
|
export interface PotsPagination extends Pagination {
|
|
@@ -91,6 +98,17 @@ export interface PayloadAccount {
|
|
|
91
98
|
tags?: string[] | undefined;
|
|
92
99
|
}
|
|
93
100
|
|
|
101
|
+
export interface PayloadAccountUpdate {
|
|
102
|
+
first_name?: string | null;
|
|
103
|
+
last_name?: string | null;
|
|
104
|
+
birth_date?: Date | null;
|
|
105
|
+
address?: string | null;
|
|
106
|
+
postcode?: string | null;
|
|
107
|
+
city?: string | null;
|
|
108
|
+
phone_number?: string | null;
|
|
109
|
+
country_code?: string | null;
|
|
110
|
+
}
|
|
111
|
+
|
|
94
112
|
interface PayloadPotBase {
|
|
95
113
|
name: string;
|
|
96
114
|
category_id: string;
|
|
@@ -265,6 +283,15 @@ export interface LCDP {
|
|
|
265
283
|
payload: PayloadAccountAndPot,
|
|
266
284
|
) => Promise<TokenObject>;
|
|
267
285
|
createTokenPotUpdate: (payload: PayloadPotUpdate) => Promise<TokenObject>;
|
|
286
|
+
createExternalTokenAccount: (
|
|
287
|
+
payload: PayloadAccountUpdate,
|
|
288
|
+
) => Promise<ExternalTokenObject>;
|
|
289
|
+
createTokenPersonVerification: (
|
|
290
|
+
payload: PayloadVerification,
|
|
291
|
+
) => Promise<ExternalTokenObject>;
|
|
292
|
+
createTokenAccountBank(
|
|
293
|
+
payload: PayloadAccountBank,
|
|
294
|
+
): Promise<ExternalTokenObject>;
|
|
268
295
|
createDonation: (payload: PayloadDonation) => Promise<DonationResult>;
|
|
269
296
|
getAvailableCountries: () => Promise<Country[]>;
|
|
270
297
|
getCategories: () => Promise<Category[]>;
|
|
@@ -292,6 +319,19 @@ export interface LCDPApi {
|
|
|
292
319
|
createPot: (payload: TokenObject) => Promise<PotCreated>;
|
|
293
320
|
createAccountAndPot: (payload: TokenObject) => Promise<AccountAndPotCreated>;
|
|
294
321
|
updatePot: (payload: TokenObject) => Promise<void>;
|
|
322
|
+
getAccount: (accountId: string) => Promise<Account>;
|
|
323
|
+
updateAccount: (
|
|
324
|
+
accountId: string,
|
|
325
|
+
payload: ExternalTokenObject,
|
|
326
|
+
) => Promise<void>;
|
|
327
|
+
updateAccountIdentity: (
|
|
328
|
+
accountId: string,
|
|
329
|
+
payload: ExternalTokenObject,
|
|
330
|
+
) => Promise<void>;
|
|
331
|
+
updateAccountBank: (
|
|
332
|
+
accountId: string,
|
|
333
|
+
payload: ExternalTokenObject,
|
|
334
|
+
) => Promise<void>;
|
|
295
335
|
}
|
|
296
336
|
|
|
297
337
|
export type LCDPOpts = {
|
|
@@ -311,6 +351,82 @@ export interface ParamsPagination {
|
|
|
311
351
|
per_page?: number;
|
|
312
352
|
}
|
|
313
353
|
|
|
354
|
+
export interface AccountEntity {
|
|
355
|
+
rna?: string | null;
|
|
356
|
+
siren?: string | null;
|
|
357
|
+
address?: string | null;
|
|
358
|
+
postcode?: string | null;
|
|
359
|
+
city?: string | null;
|
|
360
|
+
country?: string | null;
|
|
361
|
+
|
|
362
|
+
phoneNumber?: string | null;
|
|
363
|
+
name?: string | null;
|
|
364
|
+
|
|
365
|
+
website?: string | null;
|
|
366
|
+
pageLcdp?: string | null;
|
|
367
|
+
|
|
368
|
+
logo?: string | null;
|
|
369
|
+
logoBackground?: string | null;
|
|
370
|
+
logoUrl?: string | null;
|
|
371
|
+
logoBackgroundUrl?: string | null;
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
export interface AssoCat {
|
|
375
|
+
id: string;
|
|
376
|
+
name: string;
|
|
377
|
+
picto?: string | null;
|
|
378
|
+
enable: boolean;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export interface AccountAssoSettings {
|
|
382
|
+
withTaxReceipts?: boolean | null;
|
|
383
|
+
isPublished?: boolean | null;
|
|
384
|
+
isHighlighted?: boolean | null;
|
|
385
|
+
|
|
386
|
+
assocat: AssoCat[];
|
|
387
|
+
position?: number | null;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export interface AccountPerson {
|
|
391
|
+
firstName?: string | null;
|
|
392
|
+
lastName?: string | null;
|
|
393
|
+
birthDateTimestamp?: number | null;
|
|
394
|
+
|
|
395
|
+
address?: string | null;
|
|
396
|
+
postcode?: string | null;
|
|
397
|
+
city?: string | null;
|
|
398
|
+
country?: string | null;
|
|
399
|
+
|
|
400
|
+
phoneNumber?: string | null;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
export interface AccountCapabilities {
|
|
404
|
+
collect: boolean;
|
|
405
|
+
payout: boolean;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
export type UserType = "individual" | "association" | "business";
|
|
409
|
+
|
|
410
|
+
export interface Account {
|
|
411
|
+
type?: UserType | null;
|
|
412
|
+
|
|
413
|
+
capabilities: AccountCapabilities;
|
|
414
|
+
|
|
415
|
+
email: string;
|
|
416
|
+
|
|
417
|
+
entity?: AccountEntity | null;
|
|
418
|
+
|
|
419
|
+
entityPresident?: AccountPerson | null;
|
|
420
|
+
entityOtherThanPresident?: AccountPerson | null;
|
|
421
|
+
|
|
422
|
+
assoSettings?: AccountAssoSettings | null;
|
|
423
|
+
|
|
424
|
+
person?: AccountPerson | null;
|
|
425
|
+
|
|
426
|
+
descriptionShort?: string | null;
|
|
427
|
+
descriptionLong?: string | null;
|
|
428
|
+
}
|
|
429
|
+
|
|
314
430
|
declare global {
|
|
315
431
|
interface Window {
|
|
316
432
|
lcdp?: {
|
|
@@ -323,4 +439,18 @@ export interface DataAccount extends Omit<PayloadAccount, "birth_date"> {
|
|
|
323
439
|
birth_date: number;
|
|
324
440
|
}
|
|
325
441
|
|
|
326
|
-
export {
|
|
442
|
+
export interface PayloadDocument {
|
|
443
|
+
front?: string;
|
|
444
|
+
back?: string;
|
|
445
|
+
}
|
|
446
|
+
export interface PayloadVerification {
|
|
447
|
+
document?: PayloadDocument;
|
|
448
|
+
additional_document?: PayloadDocument;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export interface PayloadAccountBank {
|
|
452
|
+
country: string;
|
|
453
|
+
account_number: string;
|
|
454
|
+
account_holder_name: string;
|
|
455
|
+
}
|
|
456
|
+
export {};
|