@lacagnottedesproches/lcdp-js-lite 1.7.0 → 1.9.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.
package/dist/types.d.ts CHANGED
@@ -62,6 +62,7 @@ export interface Pot {
62
62
  visual_secondary_url: string | null;
63
63
  with_tax_receipt: boolean;
64
64
  tags?: string[];
65
+ metadata?: Record<string, unknown>;
65
66
  }
66
67
  export interface PotsPagination extends Pagination {
67
68
  items: Pot[];
@@ -89,6 +90,7 @@ interface PayloadPotBase {
89
90
  description?: string | undefined;
90
91
  assoid?: string | undefined;
91
92
  tags?: string[] | undefined;
93
+ metadata?: Record<string, unknown>;
92
94
  }
93
95
  export interface PayloadPot extends PayloadPotBase {
94
96
  acct_id: string;
@@ -103,6 +105,7 @@ export interface PayloadPotUpdate {
103
105
  amount_collected_hidden?: boolean | undefined;
104
106
  description?: string | undefined;
105
107
  tags?: string[] | undefined;
108
+ metadata?: Record<string, unknown>;
106
109
  }
107
110
  export interface PayloadAccountAndPot extends PayloadAccount, PayloadPotBase {
108
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lacagnottedesproches/lcdp-js-lite",
3
- "version": "1.7.0",
3
+ "version": "1.9.0",
4
4
  "description": "LCDP JS Lite",
5
5
  "scripts": {
6
6
  "build": "rm -rf dist/ && rollup -c",
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 {
@@ -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;
@@ -70,6 +76,8 @@ export interface Pot {
70
76
  visual_secondary_url: string | null;
71
77
  with_tax_receipt: boolean;
72
78
  tags?: string[];
79
+ metadata?: Record<string, unknown>;
80
+ account_id: string;
73
81
  }
74
82
 
75
83
  export interface PotsPagination extends Pagination {
@@ -90,6 +98,17 @@ export interface PayloadAccount {
90
98
  tags?: string[] | undefined;
91
99
  }
92
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
+
93
112
  interface PayloadPotBase {
94
113
  name: string;
95
114
  category_id: string;
@@ -100,6 +119,7 @@ interface PayloadPotBase {
100
119
  description?: string | undefined;
101
120
  assoid?: string | undefined;
102
121
  tags?: string[] | undefined;
122
+ metadata?: Record<string, unknown>;
103
123
  }
104
124
 
105
125
  export interface PayloadPot extends PayloadPotBase {
@@ -116,6 +136,7 @@ export interface PayloadPotUpdate {
116
136
  amount_collected_hidden?: boolean | undefined;
117
137
  description?: string | undefined;
118
138
  tags?: string[] | undefined;
139
+ metadata?: Record<string, unknown>;
119
140
  }
120
141
 
121
142
  export interface PayloadAccountAndPot extends PayloadAccount, PayloadPotBase {}
@@ -262,6 +283,15 @@ export interface LCDP {
262
283
  payload: PayloadAccountAndPot,
263
284
  ) => Promise<TokenObject>;
264
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>;
265
295
  createDonation: (payload: PayloadDonation) => Promise<DonationResult>;
266
296
  getAvailableCountries: () => Promise<Country[]>;
267
297
  getCategories: () => Promise<Category[]>;
@@ -289,6 +319,19 @@ export interface LCDPApi {
289
319
  createPot: (payload: TokenObject) => Promise<PotCreated>;
290
320
  createAccountAndPot: (payload: TokenObject) => Promise<AccountAndPotCreated>;
291
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>;
292
335
  }
293
336
 
294
337
  export type LCDPOpts = {
@@ -308,6 +351,82 @@ export interface ParamsPagination {
308
351
  per_page?: number;
309
352
  }
310
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
+
311
430
  declare global {
312
431
  interface Window {
313
432
  lcdp?: {
@@ -320,4 +439,18 @@ export interface DataAccount extends Omit<PayloadAccount, "birth_date"> {
320
439
  birth_date: number;
321
440
  }
322
441
 
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
+ }
323
456
  export {};