@lacagnottedesproches/lcdp-js-lite 1.9.0 → 1.10.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/.claude/settings.local.json +7 -0
- package/CLAUDE.md +56 -0
- package/__tests__/index.test.ts +34 -0
- package/dist/api.d.ts +7 -2
- package/dist/index.js +268 -58
- package/dist/index.min.js +2 -2
- package/dist/index.mjs +268 -58
- package/dist/index.umd.js +268 -58
- package/dist/index.umd.min.js +1 -1
- package/dist/types.d.ts +108 -1
- package/package.json +1 -1
- package/src/api.ts +1 -1
- package/src/index.ts +4 -1
- package/src/types.ts +17 -1
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project
|
|
6
|
+
|
|
7
|
+
`@lacagnottedesproches/lcdp-js-lite` — a thin TypeScript SDK published to npm. It is a wrapper around the upstream **afina-sdk** (which lives behind `https://api.lacagnottedesproches.fr` and is served as a script bundle at `${api_url}/js`). This repo does not implement the SDK logic itself; it only loads it and exposes typed entry points.
|
|
8
|
+
|
|
9
|
+
Peer dependency: `@stripe/stripe-js` (the loaded `LCDP` instance exposes a `stripe` field).
|
|
10
|
+
|
|
11
|
+
## Commands
|
|
12
|
+
|
|
13
|
+
- `npm run build` — clean `dist/` and bundle via rollup. Outputs CJS, ESM, IIFE, UMD, and minified UMD (see `rollup.config.cjs`).
|
|
14
|
+
- `npm run dev` — rollup watch mode.
|
|
15
|
+
- `npm test` — Jest in verbose mode.
|
|
16
|
+
- `npm run test:unit` / `npm run test:integration` — filter by path pattern.
|
|
17
|
+
- `npm run test:types` — `tsd` type-level tests against `__tests__/types.test-d.ts` (these files are excluded from Jest via `testPathIgnorePatterns`, so `npm test` won't run them).
|
|
18
|
+
- `npm run test:coverage` — coverage report. CI (`.github/workflows/test.js.yml`, `node.js.yml`) runs this across Node 18/20/22.
|
|
19
|
+
- Run a single test: `npx jest __tests__/api.test.ts -t "createAccount"`.
|
|
20
|
+
|
|
21
|
+
There is no lint script. Prettier (`.prettierrc.json`) and a minimal ESLint config (`extends: ["prettier"]`) are present but not wired into npm scripts.
|
|
22
|
+
|
|
23
|
+
## Architecture
|
|
24
|
+
|
|
25
|
+
The public surface is two functions exported from `src/index.ts`, intended for two opposite runtimes:
|
|
26
|
+
|
|
27
|
+
### `loadLCDP(pubKey, opts?)` — browser only
|
|
28
|
+
Defined in `src/index.ts`. Lazily injects a `<script src="${api_url}/js">` tag, waits for `window.lcdp.Afina` (the upstream constructor) to appear, then `new`s it with the user's args and awaits `init()`. Behavior notes that are easy to miss:
|
|
29
|
+
- The promise (`lcdpPromise`) and `loadCalled` flag are **module-level singletons** — repeated calls reuse the in-flight/resolved promise. Tests must `jest.resetModules()` to reset this.
|
|
30
|
+
- If `window`/`document` are undefined (SSR), it resolves `null` rather than throwing.
|
|
31
|
+
- If a matching script tag already exists in the DOM, it is reused (with a `console.warn`) rather than re-injected.
|
|
32
|
+
- Also injects a `<div id="lcdp-modal-root">` into the body — the upstream SDK renders its modal there.
|
|
33
|
+
- `opts.api_url` overrides the default `https://api.lacagnottedesproches.fr`.
|
|
34
|
+
- `opts.stripe: false` skips the Stripe.js load inside `init()` (origin verification / CSRF bootstrap still runs). For read-only pages: avoids the Stripe.js network/parse cost, the TBT hit, and the need for Stripe domains in the partner's CSP. Token-creating methods will fail in this mode because `lcdp.stripe` stays `null`. The actual skip happens in `afina-sdk` (`src/core.ts:init`).
|
|
35
|
+
|
|
36
|
+
### `requestLCDP(secret, apiUrl?)` — server only
|
|
37
|
+
Returns a `LCDPRequest` (from `src/api.ts`). The constructor and every method throw `"Must be used server side"` if `typeof window !== "undefined"`. This is a hard guard to keep the API token off the client. Methods (`createAccount`, `createPot`, `createAccountAndPot`, `updatePot`, `getAccount`, `updateAccount`, `updateAccountIdentity`, `updateAccountBank`) wrap `fetch` with `Authorization: Bearer ${secret}`. Error contract: HTTP ≥ 400 rejects with the response body's `detail` string; 204 resolves `undefined`; otherwise resolves the JSON body. The promise wrappers around each method are slightly redundant (the inner `requestLCDPApi` already returns a promise) — preserve this shape when editing unless intentionally refactoring.
|
|
38
|
+
|
|
39
|
+
### Types (`src/types.ts`)
|
|
40
|
+
All public types are re-exported via `export * from "./types"` in `index.ts`. Notable shapes:
|
|
41
|
+
- `LCDP` — the browser-side instance interface (token creation, donations, pots, stats, associations).
|
|
42
|
+
- `LCDPApi` — the server-side `LCDPRequest` interface.
|
|
43
|
+
- `LCDPConstructor` / `LoadLCDP` — entry-point signatures.
|
|
44
|
+
- `window.lcdp.Afina` is declared via `declare global` augmentation.
|
|
45
|
+
|
|
46
|
+
When changing public types, update both `__tests__/types.test-d.ts` (compile-time `tsd` assertions) and `__tests__/types.runtime.test.ts` (runtime smoke).
|
|
47
|
+
|
|
48
|
+
## Testing setup
|
|
49
|
+
|
|
50
|
+
- `jest.setup.ts` enables `jest-fetch-mock` and stubs `window`/`document` globally. Individual tests in `__tests__/index.test.ts` rebuild these mocks per case and call `jest.resetModules()` to reset the module-level `lcdpPromise` singleton.
|
|
51
|
+
- `api.test.ts` tests delete `global.window` before constructing `LCDPRequest` (since its constructor throws when `window` is defined).
|
|
52
|
+
- `testEnvironment` is `"node"`, not `"jsdom"` — the DOM is mocked manually.
|
|
53
|
+
|
|
54
|
+
## Publishing
|
|
55
|
+
|
|
56
|
+
`package.json` defines `main`/`module`/`browser`/`browser:min`/`types` pointing into `dist/`. `docs/` is generated by TypeDoc and gitignored. Version bumps live in commit messages (`chore(version): Bump to X.Y.Z`) and `package.json`; there's no automated release script in this repo.
|
package/__tests__/index.test.ts
CHANGED
|
@@ -44,6 +44,40 @@ describe("index.ts in node env", () => {
|
|
|
44
44
|
expect(result).toEqual({ ready: true });
|
|
45
45
|
});
|
|
46
46
|
|
|
47
|
+
it("forwards { stripe: false } from opts to init", async () => {
|
|
48
|
+
jest.resetModules();
|
|
49
|
+
|
|
50
|
+
const initMock = jest.fn().mockResolvedValue({ ready: true });
|
|
51
|
+
|
|
52
|
+
(globalThis as any).window.lcdp = {
|
|
53
|
+
Afina: function () {
|
|
54
|
+
(this as any).init = initMock;
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const { loadLCDP } = await import("../src");
|
|
59
|
+
await loadLCDP("key", { stripe: false });
|
|
60
|
+
|
|
61
|
+
expect(initMock).toHaveBeenCalledWith({ stripe: false });
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("calls init with no args when stripe opt is omitted", async () => {
|
|
65
|
+
jest.resetModules();
|
|
66
|
+
|
|
67
|
+
const initMock = jest.fn().mockResolvedValue({ ready: true });
|
|
68
|
+
|
|
69
|
+
(globalThis as any).window.lcdp = {
|
|
70
|
+
Afina: function () {
|
|
71
|
+
(this as any).init = initMock;
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const { loadLCDP } = await import("../src");
|
|
76
|
+
await loadLCDP("key");
|
|
77
|
+
|
|
78
|
+
expect(initMock).toHaveBeenCalledWith(undefined);
|
|
79
|
+
});
|
|
80
|
+
|
|
47
81
|
it("injects script if not present", async () => {
|
|
48
82
|
jest.resetModules(); // reset module-level state
|
|
49
83
|
|
package/dist/api.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AccountCreated, LCDPApi, PotCreated, TokenObject
|
|
1
|
+
import { Account, AccountAndPotCreated, AccountCreated, ExternalTokenObject, LCDPApi, PotCreated, TokenObject } from "./types";
|
|
2
2
|
interface LCDPApiResponse {
|
|
3
3
|
[key: string]: string | LCDPApiResponse;
|
|
4
4
|
}
|
|
@@ -6,10 +6,15 @@ export declare class LCDPRequest implements LCDPApi {
|
|
|
6
6
|
_apiToken: string;
|
|
7
7
|
_apiUrl: string;
|
|
8
8
|
constructor(secret: string, apiUrl: string);
|
|
9
|
-
requestLCDPApi: (endpoint: string, payload: TokenObject, authToken: string, customMethod?: "POST" | "PATCH") => Promise<LCDPApiResponse | void>;
|
|
9
|
+
requestLCDPApi: (endpoint: string, payload: TokenObject | ExternalTokenObject, authToken: string, customMethod?: "POST" | "PATCH") => Promise<LCDPApiResponse | void>;
|
|
10
|
+
requestGetLCDPApi: (endpoint: string, authToken: string) => Promise<LCDPApiResponse | void>;
|
|
10
11
|
createAccount: (payload: TokenObject) => Promise<AccountCreated>;
|
|
11
12
|
createPot: (payload: TokenObject) => Promise<PotCreated>;
|
|
12
13
|
createAccountAndPot: (payload: TokenObject) => Promise<AccountAndPotCreated>;
|
|
13
14
|
updatePot: (payload: TokenObject) => Promise<void>;
|
|
15
|
+
getAccount: (accountId: string) => Promise<Account>;
|
|
16
|
+
updateAccount: (accountId: string, payload: ExternalTokenObject) => Promise<void>;
|
|
17
|
+
updateAccountIdentity: (accountId: string, payload: ExternalTokenObject) => Promise<void>;
|
|
18
|
+
updateAccountBank: (accountId: string, payload: ExternalTokenObject) => Promise<void>;
|
|
14
19
|
}
|
|
15
20
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -277,19 +277,86 @@ var LCDPRequest = /*#__PURE__*/_createClass(function LCDPRequest(secret, apiUrl)
|
|
|
277
277
|
};
|
|
278
278
|
}());
|
|
279
279
|
});
|
|
280
|
+
_defineProperty(this, "requestGetLCDPApi", function (endpoint, authToken) {
|
|
281
|
+
if (typeof window !== "undefined") {
|
|
282
|
+
throw new Error("Must be used server side");
|
|
283
|
+
}
|
|
284
|
+
return new Promise(/*#__PURE__*/function () {
|
|
285
|
+
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(resolve, reject) {
|
|
286
|
+
var url, response, status, _yield$response$json2, detail, data, _t2;
|
|
287
|
+
return _regenerator().w(function (_context2) {
|
|
288
|
+
while (1) switch (_context2.p = _context2.n) {
|
|
289
|
+
case 0:
|
|
290
|
+
url = "".concat(_this._apiUrl, "/").concat(endpoint);
|
|
291
|
+
_context2.p = 1;
|
|
292
|
+
_context2.n = 2;
|
|
293
|
+
return fetch(url, {
|
|
294
|
+
method: "GET",
|
|
295
|
+
headers: {
|
|
296
|
+
"Content-Type": "application/json",
|
|
297
|
+
"User-Agent": "lcdp/v1",
|
|
298
|
+
Authorization: "Bearer ".concat(authToken)
|
|
299
|
+
}
|
|
300
|
+
});
|
|
301
|
+
case 2:
|
|
302
|
+
response = _context2.v;
|
|
303
|
+
status = response.status;
|
|
304
|
+
if (!(status >= 400)) {
|
|
305
|
+
_context2.n = 4;
|
|
306
|
+
break;
|
|
307
|
+
}
|
|
308
|
+
_context2.n = 3;
|
|
309
|
+
return response.json();
|
|
310
|
+
case 3:
|
|
311
|
+
_yield$response$json2 = _context2.v;
|
|
312
|
+
detail = _yield$response$json2.detail;
|
|
313
|
+
reject(detail);
|
|
314
|
+
_context2.n = 7;
|
|
315
|
+
break;
|
|
316
|
+
case 4:
|
|
317
|
+
if (!(status === 204)) {
|
|
318
|
+
_context2.n = 5;
|
|
319
|
+
break;
|
|
320
|
+
}
|
|
321
|
+
resolve();
|
|
322
|
+
_context2.n = 7;
|
|
323
|
+
break;
|
|
324
|
+
case 5:
|
|
325
|
+
_context2.n = 6;
|
|
326
|
+
return response.json();
|
|
327
|
+
case 6:
|
|
328
|
+
data = _context2.v;
|
|
329
|
+
resolve(data);
|
|
330
|
+
case 7:
|
|
331
|
+
_context2.n = 9;
|
|
332
|
+
break;
|
|
333
|
+
case 8:
|
|
334
|
+
_context2.p = 8;
|
|
335
|
+
_t2 = _context2.v;
|
|
336
|
+
reject(_t2);
|
|
337
|
+
case 9:
|
|
338
|
+
return _context2.a(2);
|
|
339
|
+
}
|
|
340
|
+
}, _callee2, null, [[1, 8]]);
|
|
341
|
+
}));
|
|
342
|
+
return function (_x3, _x4) {
|
|
343
|
+
return _ref2.apply(this, arguments);
|
|
344
|
+
};
|
|
345
|
+
}());
|
|
346
|
+
});
|
|
280
347
|
_defineProperty(this, "createAccount", /*#__PURE__*/function () {
|
|
281
|
-
var
|
|
282
|
-
return _regenerator().w(function (
|
|
283
|
-
while (1) switch (
|
|
348
|
+
var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(payload) {
|
|
349
|
+
return _regenerator().w(function (_context4) {
|
|
350
|
+
while (1) switch (_context4.n) {
|
|
284
351
|
case 0:
|
|
285
|
-
return
|
|
286
|
-
var
|
|
352
|
+
return _context4.a(2, new Promise(/*#__PURE__*/function () {
|
|
353
|
+
var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(resolve, reject) {
|
|
287
354
|
var responsePromise;
|
|
288
|
-
return _regenerator().w(function (
|
|
289
|
-
while (1) switch (
|
|
355
|
+
return _regenerator().w(function (_context3) {
|
|
356
|
+
while (1) switch (_context3.n) {
|
|
290
357
|
case 0:
|
|
291
358
|
responsePromise = _this.requestLCDPApi("accounts", payload, _this._apiToken);
|
|
292
|
-
return
|
|
359
|
+
return _context3.a(2, responsePromise.then(function (data) {
|
|
293
360
|
try {
|
|
294
361
|
// TODO: may be improved
|
|
295
362
|
resolve(data);
|
|
@@ -300,32 +367,32 @@ var LCDPRequest = /*#__PURE__*/_createClass(function LCDPRequest(secret, apiUrl)
|
|
|
300
367
|
return reject(reason);
|
|
301
368
|
}));
|
|
302
369
|
}
|
|
303
|
-
},
|
|
370
|
+
}, _callee3);
|
|
304
371
|
}));
|
|
305
|
-
return function (
|
|
306
|
-
return
|
|
372
|
+
return function (_x6, _x7) {
|
|
373
|
+
return _ref4.apply(this, arguments);
|
|
307
374
|
};
|
|
308
375
|
}()));
|
|
309
376
|
}
|
|
310
|
-
},
|
|
377
|
+
}, _callee4);
|
|
311
378
|
}));
|
|
312
|
-
return function (
|
|
313
|
-
return
|
|
379
|
+
return function (_x5) {
|
|
380
|
+
return _ref3.apply(this, arguments);
|
|
314
381
|
};
|
|
315
382
|
}());
|
|
316
383
|
_defineProperty(this, "createPot", /*#__PURE__*/function () {
|
|
317
|
-
var
|
|
318
|
-
return _regenerator().w(function (
|
|
319
|
-
while (1) switch (
|
|
384
|
+
var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(payload) {
|
|
385
|
+
return _regenerator().w(function (_context6) {
|
|
386
|
+
while (1) switch (_context6.n) {
|
|
320
387
|
case 0:
|
|
321
|
-
return
|
|
322
|
-
var
|
|
388
|
+
return _context6.a(2, new Promise(/*#__PURE__*/function () {
|
|
389
|
+
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(resolve, reject) {
|
|
323
390
|
var responsePromise;
|
|
324
|
-
return _regenerator().w(function (
|
|
325
|
-
while (1) switch (
|
|
391
|
+
return _regenerator().w(function (_context5) {
|
|
392
|
+
while (1) switch (_context5.n) {
|
|
326
393
|
case 0:
|
|
327
394
|
responsePromise = _this.requestLCDPApi("pots", payload, _this._apiToken);
|
|
328
|
-
return
|
|
395
|
+
return _context5.a(2, responsePromise.then(function (data) {
|
|
329
396
|
try {
|
|
330
397
|
// TODO: may be improved
|
|
331
398
|
resolve(data);
|
|
@@ -336,32 +403,32 @@ var LCDPRequest = /*#__PURE__*/_createClass(function LCDPRequest(secret, apiUrl)
|
|
|
336
403
|
return reject(reason);
|
|
337
404
|
}));
|
|
338
405
|
}
|
|
339
|
-
},
|
|
406
|
+
}, _callee5);
|
|
340
407
|
}));
|
|
341
|
-
return function (
|
|
342
|
-
return
|
|
408
|
+
return function (_x9, _x0) {
|
|
409
|
+
return _ref6.apply(this, arguments);
|
|
343
410
|
};
|
|
344
411
|
}()));
|
|
345
412
|
}
|
|
346
|
-
},
|
|
413
|
+
}, _callee6);
|
|
347
414
|
}));
|
|
348
|
-
return function (
|
|
349
|
-
return
|
|
415
|
+
return function (_x8) {
|
|
416
|
+
return _ref5.apply(this, arguments);
|
|
350
417
|
};
|
|
351
418
|
}());
|
|
352
419
|
_defineProperty(this, "createAccountAndPot", /*#__PURE__*/function () {
|
|
353
|
-
var
|
|
354
|
-
return _regenerator().w(function (
|
|
355
|
-
while (1) switch (
|
|
420
|
+
var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee8(payload) {
|
|
421
|
+
return _regenerator().w(function (_context8) {
|
|
422
|
+
while (1) switch (_context8.n) {
|
|
356
423
|
case 0:
|
|
357
|
-
return
|
|
358
|
-
var
|
|
424
|
+
return _context8.a(2, new Promise(/*#__PURE__*/function () {
|
|
425
|
+
var _ref8 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(resolve, reject) {
|
|
359
426
|
var responsePromise;
|
|
360
|
-
return _regenerator().w(function (
|
|
361
|
-
while (1) switch (
|
|
427
|
+
return _regenerator().w(function (_context7) {
|
|
428
|
+
while (1) switch (_context7.n) {
|
|
362
429
|
case 0:
|
|
363
430
|
responsePromise = _this.requestLCDPApi("wizards", payload, _this._apiToken);
|
|
364
|
-
return
|
|
431
|
+
return _context7.a(2, responsePromise.then(function (data) {
|
|
365
432
|
try {
|
|
366
433
|
// TODO: may be improved
|
|
367
434
|
resolve(data);
|
|
@@ -372,32 +439,172 @@ var LCDPRequest = /*#__PURE__*/_createClass(function LCDPRequest(secret, apiUrl)
|
|
|
372
439
|
return reject(reason);
|
|
373
440
|
}));
|
|
374
441
|
}
|
|
375
|
-
},
|
|
442
|
+
}, _callee7);
|
|
376
443
|
}));
|
|
377
|
-
return function (
|
|
378
|
-
return
|
|
444
|
+
return function (_x10, _x11) {
|
|
445
|
+
return _ref8.apply(this, arguments);
|
|
379
446
|
};
|
|
380
447
|
}()));
|
|
381
448
|
}
|
|
382
|
-
},
|
|
449
|
+
}, _callee8);
|
|
383
450
|
}));
|
|
384
|
-
return function (
|
|
385
|
-
return
|
|
451
|
+
return function (_x1) {
|
|
452
|
+
return _ref7.apply(this, arguments);
|
|
386
453
|
};
|
|
387
454
|
}());
|
|
388
455
|
_defineProperty(this, "updatePot", /*#__PURE__*/function () {
|
|
389
|
-
var
|
|
390
|
-
return _regenerator().w(function (
|
|
391
|
-
while (1) switch (
|
|
456
|
+
var _ref9 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee0(payload) {
|
|
457
|
+
return _regenerator().w(function (_context0) {
|
|
458
|
+
while (1) switch (_context0.n) {
|
|
392
459
|
case 0:
|
|
393
|
-
return
|
|
394
|
-
var
|
|
460
|
+
return _context0.a(2, new Promise(/*#__PURE__*/function () {
|
|
461
|
+
var _ref0 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee9(resolve, reject) {
|
|
395
462
|
var responsePromise;
|
|
396
|
-
return _regenerator().w(function (
|
|
397
|
-
while (1) switch (
|
|
463
|
+
return _regenerator().w(function (_context9) {
|
|
464
|
+
while (1) switch (_context9.n) {
|
|
398
465
|
case 0:
|
|
399
466
|
responsePromise = _this.requestLCDPApi("pots", payload, _this._apiToken, "PATCH");
|
|
400
|
-
return
|
|
467
|
+
return _context9.a(2, responsePromise.then(function (_) {
|
|
468
|
+
try {
|
|
469
|
+
resolve();
|
|
470
|
+
} catch (error) {
|
|
471
|
+
reject(error);
|
|
472
|
+
}
|
|
473
|
+
})["catch"](function (reason) {
|
|
474
|
+
return reject(reason);
|
|
475
|
+
}));
|
|
476
|
+
}
|
|
477
|
+
}, _callee9);
|
|
478
|
+
}));
|
|
479
|
+
return function (_x13, _x14) {
|
|
480
|
+
return _ref0.apply(this, arguments);
|
|
481
|
+
};
|
|
482
|
+
}()));
|
|
483
|
+
}
|
|
484
|
+
}, _callee0);
|
|
485
|
+
}));
|
|
486
|
+
return function (_x12) {
|
|
487
|
+
return _ref9.apply(this, arguments);
|
|
488
|
+
};
|
|
489
|
+
}());
|
|
490
|
+
_defineProperty(this, "getAccount", /*#__PURE__*/function () {
|
|
491
|
+
var _ref1 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee10(accountId) {
|
|
492
|
+
return _regenerator().w(function (_context10) {
|
|
493
|
+
while (1) switch (_context10.n) {
|
|
494
|
+
case 0:
|
|
495
|
+
return _context10.a(2, new Promise(/*#__PURE__*/function () {
|
|
496
|
+
var _ref10 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee1(resolve, reject) {
|
|
497
|
+
var responsePromise;
|
|
498
|
+
return _regenerator().w(function (_context1) {
|
|
499
|
+
while (1) switch (_context1.n) {
|
|
500
|
+
case 0:
|
|
501
|
+
responsePromise = _this.requestGetLCDPApi("accounts/".concat(accountId), _this._apiToken);
|
|
502
|
+
return _context1.a(2, responsePromise.then(function (data) {
|
|
503
|
+
try {
|
|
504
|
+
resolve(data);
|
|
505
|
+
} catch (error) {
|
|
506
|
+
reject(error);
|
|
507
|
+
}
|
|
508
|
+
})["catch"](function (reason) {
|
|
509
|
+
return reject(reason);
|
|
510
|
+
}));
|
|
511
|
+
}
|
|
512
|
+
}, _callee1);
|
|
513
|
+
}));
|
|
514
|
+
return function (_x16, _x17) {
|
|
515
|
+
return _ref10.apply(this, arguments);
|
|
516
|
+
};
|
|
517
|
+
}()));
|
|
518
|
+
}
|
|
519
|
+
}, _callee10);
|
|
520
|
+
}));
|
|
521
|
+
return function (_x15) {
|
|
522
|
+
return _ref1.apply(this, arguments);
|
|
523
|
+
};
|
|
524
|
+
}());
|
|
525
|
+
_defineProperty(this, "updateAccount", /*#__PURE__*/function () {
|
|
526
|
+
var _ref11 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee12(accountId, payload) {
|
|
527
|
+
return _regenerator().w(function (_context12) {
|
|
528
|
+
while (1) switch (_context12.n) {
|
|
529
|
+
case 0:
|
|
530
|
+
return _context12.a(2, new Promise(/*#__PURE__*/function () {
|
|
531
|
+
var _ref12 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee11(resolve, reject) {
|
|
532
|
+
var responsePromise;
|
|
533
|
+
return _regenerator().w(function (_context11) {
|
|
534
|
+
while (1) switch (_context11.n) {
|
|
535
|
+
case 0:
|
|
536
|
+
responsePromise = _this.requestLCDPApi("accounts/".concat(accountId), payload, _this._apiToken, "PATCH");
|
|
537
|
+
return _context11.a(2, responsePromise.then(function (_) {
|
|
538
|
+
try {
|
|
539
|
+
resolve();
|
|
540
|
+
} catch (error) {
|
|
541
|
+
reject(error);
|
|
542
|
+
}
|
|
543
|
+
})["catch"](function (reason) {
|
|
544
|
+
return reject(reason);
|
|
545
|
+
}));
|
|
546
|
+
}
|
|
547
|
+
}, _callee11);
|
|
548
|
+
}));
|
|
549
|
+
return function (_x20, _x21) {
|
|
550
|
+
return _ref12.apply(this, arguments);
|
|
551
|
+
};
|
|
552
|
+
}()));
|
|
553
|
+
}
|
|
554
|
+
}, _callee12);
|
|
555
|
+
}));
|
|
556
|
+
return function (_x18, _x19) {
|
|
557
|
+
return _ref11.apply(this, arguments);
|
|
558
|
+
};
|
|
559
|
+
}());
|
|
560
|
+
_defineProperty(this, "updateAccountIdentity", /*#__PURE__*/function () {
|
|
561
|
+
var _ref13 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee14(accountId, payload) {
|
|
562
|
+
return _regenerator().w(function (_context14) {
|
|
563
|
+
while (1) switch (_context14.n) {
|
|
564
|
+
case 0:
|
|
565
|
+
return _context14.a(2, new Promise(/*#__PURE__*/function () {
|
|
566
|
+
var _ref14 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee13(resolve, reject) {
|
|
567
|
+
var responsePromise;
|
|
568
|
+
return _regenerator().w(function (_context13) {
|
|
569
|
+
while (1) switch (_context13.n) {
|
|
570
|
+
case 0:
|
|
571
|
+
responsePromise = _this.requestLCDPApi("accounts/".concat(accountId, "/identity"), payload, _this._apiToken, "POST");
|
|
572
|
+
return _context13.a(2, responsePromise.then(function (_) {
|
|
573
|
+
try {
|
|
574
|
+
resolve();
|
|
575
|
+
} catch (error) {
|
|
576
|
+
reject(error);
|
|
577
|
+
}
|
|
578
|
+
})["catch"](function (reason) {
|
|
579
|
+
return reject(reason);
|
|
580
|
+
}));
|
|
581
|
+
}
|
|
582
|
+
}, _callee13);
|
|
583
|
+
}));
|
|
584
|
+
return function (_x24, _x25) {
|
|
585
|
+
return _ref14.apply(this, arguments);
|
|
586
|
+
};
|
|
587
|
+
}()));
|
|
588
|
+
}
|
|
589
|
+
}, _callee14);
|
|
590
|
+
}));
|
|
591
|
+
return function (_x22, _x23) {
|
|
592
|
+
return _ref13.apply(this, arguments);
|
|
593
|
+
};
|
|
594
|
+
}());
|
|
595
|
+
_defineProperty(this, "updateAccountBank", /*#__PURE__*/function () {
|
|
596
|
+
var _ref15 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee16(accountId, payload) {
|
|
597
|
+
return _regenerator().w(function (_context16) {
|
|
598
|
+
while (1) switch (_context16.n) {
|
|
599
|
+
case 0:
|
|
600
|
+
return _context16.a(2, new Promise(/*#__PURE__*/function () {
|
|
601
|
+
var _ref16 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee15(resolve, reject) {
|
|
602
|
+
var responsePromise;
|
|
603
|
+
return _regenerator().w(function (_context15) {
|
|
604
|
+
while (1) switch (_context15.n) {
|
|
605
|
+
case 0:
|
|
606
|
+
responsePromise = _this.requestLCDPApi("accounts/".concat(accountId, "/bank"), payload, _this._apiToken, "POST");
|
|
607
|
+
return _context15.a(2, responsePromise.then(function (_) {
|
|
401
608
|
try {
|
|
402
609
|
resolve();
|
|
403
610
|
} catch (error) {
|
|
@@ -407,17 +614,17 @@ var LCDPRequest = /*#__PURE__*/_createClass(function LCDPRequest(secret, apiUrl)
|
|
|
407
614
|
return reject(reason);
|
|
408
615
|
}));
|
|
409
616
|
}
|
|
410
|
-
},
|
|
617
|
+
}, _callee15);
|
|
411
618
|
}));
|
|
412
|
-
return function (
|
|
413
|
-
return
|
|
619
|
+
return function (_x28, _x29) {
|
|
620
|
+
return _ref16.apply(this, arguments);
|
|
414
621
|
};
|
|
415
622
|
}()));
|
|
416
623
|
}
|
|
417
|
-
},
|
|
624
|
+
}, _callee16);
|
|
418
625
|
}));
|
|
419
|
-
return function (
|
|
420
|
-
return
|
|
626
|
+
return function (_x26, _x27) {
|
|
627
|
+
return _ref15.apply(this, arguments);
|
|
421
628
|
};
|
|
422
629
|
}());
|
|
423
630
|
if (typeof window !== "undefined") {
|
|
@@ -539,7 +746,7 @@ var getLCDPPromise = function getLCDPPromise(args) {
|
|
|
539
746
|
};
|
|
540
747
|
var initLCDP = /*#__PURE__*/function () {
|
|
541
748
|
var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(maybeLCDP, args) {
|
|
542
|
-
var lcdp;
|
|
749
|
+
var lcdp, opts;
|
|
543
750
|
return _regenerator().w(function (_context) {
|
|
544
751
|
while (1) switch (_context.n) {
|
|
545
752
|
case 0:
|
|
@@ -550,7 +757,10 @@ var initLCDP = /*#__PURE__*/function () {
|
|
|
550
757
|
return _context.a(2, Promise.resolve(null));
|
|
551
758
|
case 1:
|
|
552
759
|
lcdp = _construct(maybeLCDP, _toConsumableArray(args));
|
|
553
|
-
|
|
760
|
+
opts = args[1];
|
|
761
|
+
return _context.a(2, lcdp.init((opts === null || opts === void 0 ? void 0 : opts.stripe) === false ? {
|
|
762
|
+
stripe: false
|
|
763
|
+
} : undefined).then(function (lcdpReady) {
|
|
554
764
|
return lcdpReady;
|
|
555
765
|
}));
|
|
556
766
|
}
|
package/dist/index.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
var lcdpjs=function(n){"use strict";function t(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=Array(t);r<t;r++)e[r]=n[r];return e}function r(n,t,r,e,o,i,u){try{var
|
|
1
|
+
var lcdpjs=function(n){"use strict";function t(n,t){(null==t||t>n.length)&&(t=n.length);for(var r=0,e=Array(t);r<t;r++)e[r]=n[r];return e}function r(n,t,r,e,o,i,u){try{var c=n[i](u),a=c.value}catch(n){return void r(n)}c.done?t(a):Promise.resolve(a).then(e,o)}function e(n){return function(){var t=this,e=arguments;return new Promise(function(o,i){var u=n.apply(t,e);function c(n){r(u,o,i,c,a,"next",n)}function a(n){r(u,o,i,c,a,"throw",n)}c(void 0)})}}function o(n,t,r){if(c())return Reflect.construct.apply(null,arguments);var e=[null];return e.push.apply(e,t),new(n.bind.apply(n,e))}function i(n,t,r){return Object.defineProperty(n,"prototype",{writable:!1}),n}function u(n,t,r){return(t=function(n){var t=function(n,t){if("object"!=typeof n||!n)return n;var r=n[Symbol.toPrimitive];if(void 0!==r){var e=r.call(n,t);if("object"!=typeof e)return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(n)}(n,"string");return"symbol"==typeof t?t:t+""}(t))in n?Object.defineProperty(n,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):n[t]=r,n}function c(){try{var n=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(n){}return(c=function(){return!!n})()}function a(){
|
|
2
2
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
|
|
3
|
-
var n,t,r="function"==typeof Symbol?Symbol:{},e=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,e,o,i){var c=e&&e.prototype instanceof a?e:a,l=Object.create(c.prototype);return f(l,"_invoke",function(r,e,o){var i,a,c,f=0,l=o||[],s=!1,p={p:0,n:0,v:n,a:d,f:d.bind(n,4),d:function(t,r){return i=t,a=0,c=n,p.n=r,u}};function d(r,e){for(a=r,c=e,t=0;!s&&f&&!o&&t<l.length;t++){var o,i=l[t],d=p.p,v=i[2];r>3?(o=v===e)&&(c=i[(a=i[4])?5:(a=3,3)],i[4]=i[5]=n):i[0]<=d&&((o=r<2&&d<i[1])?(a=0,p.v=e,p.n=i[1]):d<v&&(o=r<3||i[0]>e||e>v)&&(i[4]=r,i[5]=e,p.n=v,a=0))}if(o||r>1)return u;throw s=!0,e}return function(o,l,v){if(f>1)throw TypeError("Generator is already running");for(s&&1===l&&d(l,v),a=l,c=v;(t=a<2?n:c)||!s;){i||(a?a<3?(a>1&&(p.n=-1),d(a,c)):p.n=c:p.v=c);try{if(f=2,i){if(a||(o="next"),t=i[o]){if(!(t=t.call(i,c)))throw TypeError("iterator result is not an object");if(!t.done)return t;c=t.value,a<2&&(a=0)}else 1===a&&(t=i.return)&&t.call(i),a<2&&(c=TypeError("The iterator does not provide a '"+o+"' method"),a=1);i=n}else if((t=(s=p.n<0)?c:r.call(e,p))!==u)break}catch(t){i=n,a=1,c=t}finally{f=1}}return{value:t,done:s}}}(r,o,i),!0),l}var u={};function a(){}function l(){}function s(){}t=Object.getPrototypeOf;var p=[][e]?t(t([][e]())):(f(t={},e,function(){return this}),t),d=s.prototype=a.prototype=Object.create(p);function v(n){return Object.setPrototypeOf?Object.setPrototypeOf(n,s):(n.__proto__=s,f(n,o,"GeneratorFunction")),n.prototype=Object.create(d),n}return l.prototype=s,f(d,"constructor",s),f(s,"constructor",l),l.displayName="GeneratorFunction",f(s,o,"GeneratorFunction"),f(d),f(d,o,"Generator"),f(d,e,function(){return this}),f(d,"toString",function(){return"[object Generator]"}),(c=function(){return{w:i,m:v}})()}function f(n,t,r,e){var o=Object.defineProperty;try{o({},"",{})}catch(n){o=0}f=function(n,t,r,e){function i(t,r){f(n,t,function(n){return this._invoke(t,r,n)})}t?o?o(n,t,{value:r,enumerable:!e,configurable:!e,writable:!e}):n[t]=r:(i("next",0),i("throw",1),i("return",2))},f(n,t,r,e)}function l(n){return function(n){if(Array.isArray(n))return t(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||function(n,r){if(n){if("string"==typeof n)return t(n,r);var e={}.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?t(n,r):void 0}}(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var s,p,d=i(function n(t,r){var o=this;if(function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),u(this,"_apiToken",void 0),u(this,"_apiUrl",void 0),u(this,"requestLCDPApi",function(n,t,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"POST";if("undefined"!=typeof window)throw new Error("Must be used server side");return new Promise(function(){var u=e(c().m(function e(u,a){var f,l,s,p,d,v,y;return c().w(function(e){for(;;)switch(e.p=e.n){case 0:return f="".concat(o._apiUrl,"/").concat(n),e.p=1,e.n=2,fetch(f,{method:i,headers:{"Content-Type":"application/json","User-Agent":"lcdp/v1",Authorization:"Bearer ".concat(r)},body:JSON.stringify(t)});case 2:if(l=e.v,!((s=l.status)>=400)){e.n=4;break}return e.n=3,l.json();case 3:p=e.v,d=p.detail,a(d),e.n=7;break;case 4:if(204!==s){e.n=5;break}u(),e.n=7;break;case 5:return e.n=6,l.json();case 6:v=e.v,u(v);case 7:e.n=9;break;case 8:e.p=8,y=e.v,a(y);case 9:return e.a(2)}},e,null,[[1,8]])}));return function(n,t){return u.apply(this,arguments)}}())}),u(this,"createAccount",function(){var n=e(c().m(function n(t){return c().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(c().m(function n(r,e){var i;return c().w(function(n){for(;;)if(0===n.n)return i=o.requestLCDPApi("accounts",t,o._apiToken),n.a(2,i.then(function(n){try{r(n)}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),u(this,"createPot",function(){var n=e(c().m(function n(t){return c().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(c().m(function n(r,e){var i;return c().w(function(n){for(;;)if(0===n.n)return i=o.requestLCDPApi("pots",t,o._apiToken),n.a(2,i.then(function(n){try{r(n)}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),u(this,"createAccountAndPot",function(){var n=e(c().m(function n(t){return c().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(c().m(function n(r,e){var i;return c().w(function(n){for(;;)if(0===n.n)return i=o.requestLCDPApi("wizards",t,o._apiToken),n.a(2,i.then(function(n){try{r(n)}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),u(this,"updatePot",function(){var n=e(c().m(function n(t){return c().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(c().m(function n(r,e){var i;return c().w(function(n){for(;;)if(0===n.n)return i=o.requestLCDPApi("pots",t,o._apiToken,"PATCH"),n.a(2,i.then(function(n){try{r()}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),"undefined"!=typeof window)throw new Error("Must be used server side");this._apiToken=t,this._apiUrl=r});n.AfinaError=void 0,(s=n.AfinaError||(n.AfinaError={})).Verify="Fail to verify origin request",s.Stripe="Stripe is not available",s.ClientSide="Should be on Client Side",s.Key="A publishable key is mandatory",n.TokenObjectType=void 0,(p=n.TokenObjectType||(n.TokenObjectType={})).Account="account",p.Pot="pot",p.Wizard="wizard";var v=null,y="https://api.lacagnottedesproches.fr",h=function(n){return new RegExp("/^".concat(n,"?(.*)$/"))},w=null,m=null,b=function(n){var t=document.createElement("script");t.src="".concat(n,"/js");var r=document.head||document.body;if(!r)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");r.appendChild(t);var e=document.createElement("div");return e.id="lcdp-modal-root",document.body.appendChild(e),t},P=function(n){return v||(v=new Promise(function(t,r){var e;if("undefined"!=typeof window&&"undefined"!=typeof document)if(null!==(e=window.lcdp)&&void 0!==e&&e.Afina)t(window.lcdp.Afina);else{var o=y,i=h(o);if(n&&n.length>=2){var u=n[1];null!=u&&u.api_url&&(o=u.api_url,i=h(o))}try{var a=function(n,t){for(var r=document.querySelectorAll('script[src^="'.concat(n,'"]')),e=0;e<r.length;e++){var o=r[e];if(t.test(o.src))return o}return null}(o,i);if(a)console.warn("it seems a lcdp script already exists.");else if(a){if(a&&null!==m&&null!==w){var c;a.removeEventListener("load",m),a.removeEventListener("error",w),null===(c=a.parentNode)||void 0===c||c.removeChild(a),a=b(o)}}else a=b(o);m=function(n,t){return function(){var r;null!==(r=window.lcdp)&&void 0!==r&&r.Afina?n(window.lcdp.Afina):t(new Error("lcdp.js not available"))}}(t,r),w=function(n){return function(){n(new Error("Failed to load lcdp.js"))}}(r),a.addEventListener("load",m),a.addEventListener("error",w)}catch(n){return void r(n)}}else t(null)}))},A=function(){var n=e(c().m(function n(t,r){var e;return c().w(function(n){for(;;)switch(n.n){case 0:if(null!==t){n.n=1;break}return n.a(2,Promise.resolve(null));case 1:return e=o(t,l(r)),n.a(2,e.init().then(function(n){return n}))}},n)}));return function(t,r){return n.apply(this,arguments)}}(),g=function(){var n=e(c().m(function n(){var t,r,e,o=arguments;return c().w(function(n){for(;;)if(0===n.n){for(t=o.length,r=new Array(t),e=0;e<t;e++)r[e]=o[e];return n.a(2,P(r).then(function(n){return A(n,r)}))}},n)}));return function(){return n.apply(this,arguments)}}();return n.loadLCDP=g,n.requestLCDP=function(n){return new d(n,arguments.length>1&&void 0!==arguments[1]?arguments[1]:y)},n}({});
|
|
3
|
+
var n,t,r="function"==typeof Symbol?Symbol:{},e=r.iterator||"@@iterator",o=r.toStringTag||"@@toStringTag";function i(r,e,o,i){var a=e&&e.prototype instanceof c?e:c,s=Object.create(a.prototype);return f(s,"_invoke",function(r,e,o){var i,c,a,f=0,s=o||[],l=!1,p={p:0,n:0,v:n,a:d,f:d.bind(n,4),d:function(t,r){return i=t,c=0,a=n,p.n=r,u}};function d(r,e){for(c=r,a=e,t=0;!l&&f&&!o&&t<s.length;t++){var o,i=s[t],d=p.p,v=i[2];r>3?(o=v===e)&&(a=i[(c=i[4])?5:(c=3,3)],i[4]=i[5]=n):i[0]<=d&&((o=r<2&&d<i[1])?(c=0,p.v=e,p.n=i[1]):d<v&&(o=r<3||i[0]>e||e>v)&&(i[4]=r,i[5]=e,p.n=v,c=0))}if(o||r>1)return u;throw l=!0,e}return function(o,s,v){if(f>1)throw TypeError("Generator is already running");for(l&&1===s&&d(s,v),c=s,a=v;(t=c<2?n:a)||!l;){i||(c?c<3?(c>1&&(p.n=-1),d(c,a)):p.n=a:p.v=a);try{if(f=2,i){if(c||(o="next"),t=i[o]){if(!(t=t.call(i,a)))throw TypeError("iterator result is not an object");if(!t.done)return t;a=t.value,c<2&&(c=0)}else 1===c&&(t=i.return)&&t.call(i),c<2&&(a=TypeError("The iterator does not provide a '"+o+"' method"),c=1);i=n}else if((t=(l=p.n<0)?a:r.call(e,p))!==u)break}catch(t){i=n,c=1,a=t}finally{f=1}}return{value:t,done:l}}}(r,o,i),!0),s}var u={};function c(){}function s(){}function l(){}t=Object.getPrototypeOf;var p=[][e]?t(t([][e]())):(f(t={},e,function(){return this}),t),d=l.prototype=c.prototype=Object.create(p);function v(n){return Object.setPrototypeOf?Object.setPrototypeOf(n,l):(n.__proto__=l,f(n,o,"GeneratorFunction")),n.prototype=Object.create(d),n}return s.prototype=l,f(d,"constructor",l),f(l,"constructor",s),s.displayName="GeneratorFunction",f(l,o,"GeneratorFunction"),f(d),f(d,o,"Generator"),f(d,e,function(){return this}),f(d,"toString",function(){return"[object Generator]"}),(a=function(){return{w:i,m:v}})()}function f(n,t,r,e){var o=Object.defineProperty;try{o({},"",{})}catch(n){o=0}f=function(n,t,r,e){function i(t,r){f(n,t,function(n){return this._invoke(t,r,n)})}t?o?o(n,t,{value:r,enumerable:!e,configurable:!e,writable:!e}):n[t]=r:(i("next",0),i("throw",1),i("return",2))},f(n,t,r,e)}function s(n){return function(n){if(Array.isArray(n))return t(n)}(n)||function(n){if("undefined"!=typeof Symbol&&null!=n[Symbol.iterator]||null!=n["@@iterator"])return Array.from(n)}(n)||function(n,r){if(n){if("string"==typeof n)return t(n,r);var e={}.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?t(n,r):void 0}}(n)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var l,p,d=i(function n(t,r){var o=this;if(function(n,t){if(!(n instanceof t))throw new TypeError("Cannot call a class as a function")}(this,n),u(this,"_apiToken",void 0),u(this,"_apiUrl",void 0),u(this,"requestLCDPApi",function(n,t,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"POST";if("undefined"!=typeof window)throw new Error("Must be used server side");return new Promise(function(){var u=e(a().m(function e(u,c){var f,s,l,p,d,v,h;return a().w(function(e){for(;;)switch(e.p=e.n){case 0:return f="".concat(o._apiUrl,"/").concat(n),e.p=1,e.n=2,fetch(f,{method:i,headers:{"Content-Type":"application/json","User-Agent":"lcdp/v1",Authorization:"Bearer ".concat(r)},body:JSON.stringify(t)});case 2:if(s=e.v,!((l=s.status)>=400)){e.n=4;break}return e.n=3,s.json();case 3:p=e.v,d=p.detail,c(d),e.n=7;break;case 4:if(204!==l){e.n=5;break}u(),e.n=7;break;case 5:return e.n=6,s.json();case 6:v=e.v,u(v);case 7:e.n=9;break;case 8:e.p=8,h=e.v,c(h);case 9:return e.a(2)}},e,null,[[1,8]])}));return function(n,t){return u.apply(this,arguments)}}())}),u(this,"requestGetLCDPApi",function(n,t){if("undefined"!=typeof window)throw new Error("Must be used server side");return new Promise(function(){var r=e(a().m(function r(e,i){var u,c,f,s,l,p,d;return a().w(function(r){for(;;)switch(r.p=r.n){case 0:return u="".concat(o._apiUrl,"/").concat(n),r.p=1,r.n=2,fetch(u,{method:"GET",headers:{"Content-Type":"application/json","User-Agent":"lcdp/v1",Authorization:"Bearer ".concat(t)}});case 2:if(c=r.v,!((f=c.status)>=400)){r.n=4;break}return r.n=3,c.json();case 3:s=r.v,l=s.detail,i(l),r.n=7;break;case 4:if(204!==f){r.n=5;break}e(),r.n=7;break;case 5:return r.n=6,c.json();case 6:p=r.v,e(p);case 7:r.n=9;break;case 8:r.p=8,d=r.v,i(d);case 9:return r.a(2)}},r,null,[[1,8]])}));return function(n,t){return r.apply(this,arguments)}}())}),u(this,"createAccount",function(){var n=e(a().m(function n(t){return a().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(a().m(function n(r,e){var i;return a().w(function(n){for(;;)if(0===n.n)return i=o.requestLCDPApi("accounts",t,o._apiToken),n.a(2,i.then(function(n){try{r(n)}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),u(this,"createPot",function(){var n=e(a().m(function n(t){return a().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(a().m(function n(r,e){var i;return a().w(function(n){for(;;)if(0===n.n)return i=o.requestLCDPApi("pots",t,o._apiToken),n.a(2,i.then(function(n){try{r(n)}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),u(this,"createAccountAndPot",function(){var n=e(a().m(function n(t){return a().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(a().m(function n(r,e){var i;return a().w(function(n){for(;;)if(0===n.n)return i=o.requestLCDPApi("wizards",t,o._apiToken),n.a(2,i.then(function(n){try{r(n)}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),u(this,"updatePot",function(){var n=e(a().m(function n(t){return a().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(a().m(function n(r,e){var i;return a().w(function(n){for(;;)if(0===n.n)return i=o.requestLCDPApi("pots",t,o._apiToken,"PATCH"),n.a(2,i.then(function(n){try{r()}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),u(this,"getAccount",function(){var n=e(a().m(function n(t){return a().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(a().m(function n(r,e){var i;return a().w(function(n){for(;;)if(0===n.n)return i=o.requestGetLCDPApi("accounts/".concat(t),o._apiToken),n.a(2,i.then(function(n){try{r(n)}catch(n){e(n)}}).catch(function(n){return e(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t){return n.apply(this,arguments)}}()),u(this,"updateAccount",function(){var n=e(a().m(function n(t,r){return a().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(a().m(function n(e,i){var u;return a().w(function(n){for(;;)if(0===n.n)return u=o.requestLCDPApi("accounts/".concat(t),r,o._apiToken,"PATCH"),n.a(2,u.then(function(n){try{e()}catch(n){i(n)}}).catch(function(n){return i(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t,r){return n.apply(this,arguments)}}()),u(this,"updateAccountIdentity",function(){var n=e(a().m(function n(t,r){return a().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(a().m(function n(e,i){var u;return a().w(function(n){for(;;)if(0===n.n)return u=o.requestLCDPApi("accounts/".concat(t,"/identity"),r,o._apiToken,"POST"),n.a(2,u.then(function(n){try{e()}catch(n){i(n)}}).catch(function(n){return i(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t,r){return n.apply(this,arguments)}}()),u(this,"updateAccountBank",function(){var n=e(a().m(function n(t,r){return a().w(function(n){for(;;)if(0===n.n)return n.a(2,new Promise(function(){var n=e(a().m(function n(e,i){var u;return a().w(function(n){for(;;)if(0===n.n)return u=o.requestLCDPApi("accounts/".concat(t,"/bank"),r,o._apiToken,"POST"),n.a(2,u.then(function(n){try{e()}catch(n){i(n)}}).catch(function(n){return i(n)}))},n)}));return function(t,r){return n.apply(this,arguments)}}()))},n)}));return function(t,r){return n.apply(this,arguments)}}()),"undefined"!=typeof window)throw new Error("Must be used server side");this._apiToken=t,this._apiUrl=r});n.AfinaError=void 0,(l=n.AfinaError||(n.AfinaError={})).Verify="Fail to verify origin request",l.Stripe="Stripe is not available",l.ClientSide="Should be on Client Side",l.Key="A publishable key is mandatory",n.TokenObjectType=void 0,(p=n.TokenObjectType||(n.TokenObjectType={})).Account="account",p.Pot="pot",p.Wizard="wizard";var v=null,h="https://api.lacagnottedesproches.fr",y=function(n){return new RegExp("/^".concat(n,"?(.*)$/"))},w=null,m=null,b=function(n){var t=document.createElement("script");t.src="".concat(n,"/js");var r=document.head||document.body;if(!r)throw new Error("Expected document.body not to be null. Stripe.js requires a <body> element.");r.appendChild(t);var e=document.createElement("div");return e.id="lcdp-modal-root",document.body.appendChild(e),t},P=function(n){return v||(v=new Promise(function(t,r){var e;if("undefined"!=typeof window&&"undefined"!=typeof document)if(null!==(e=window.lcdp)&&void 0!==e&&e.Afina)t(window.lcdp.Afina);else{var o=h,i=y(o);if(n&&n.length>=2){var u=n[1];null!=u&&u.api_url&&(o=u.api_url,i=y(o))}try{var c=function(n,t){for(var r=document.querySelectorAll('script[src^="'.concat(n,'"]')),e=0;e<r.length;e++){var o=r[e];if(t.test(o.src))return o}return null}(o,i);if(c)console.warn("it seems a lcdp script already exists.");else if(c){if(c&&null!==m&&null!==w){var a;c.removeEventListener("load",m),c.removeEventListener("error",w),null===(a=c.parentNode)||void 0===a||a.removeChild(c),c=b(o)}}else c=b(o);m=function(n,t){return function(){var r;null!==(r=window.lcdp)&&void 0!==r&&r.Afina?n(window.lcdp.Afina):t(new Error("lcdp.js not available"))}}(t,r),w=function(n){return function(){n(new Error("Failed to load lcdp.js"))}}(r),c.addEventListener("load",m),c.addEventListener("error",w)}catch(n){return void r(n)}}else t(null)}))},A=function(){var n=e(a().m(function n(t,r){var e,i;return a().w(function(n){for(;;)switch(n.n){case 0:if(null!==t){n.n=1;break}return n.a(2,Promise.resolve(null));case 1:return e=o(t,s(r)),i=r[1],n.a(2,e.init(!1===(null==i?void 0:i.stripe)?{stripe:!1}:void 0).then(function(n){return n}))}},n)}));return function(t,r){return n.apply(this,arguments)}}(),T=function(){var n=e(a().m(function n(){var t,r,e,o=arguments;return a().w(function(n){for(;;)if(0===n.n){for(t=o.length,r=new Array(t),e=0;e<t;e++)r[e]=o[e];return n.a(2,P(r).then(function(n){return A(n,r)}))}},n)}));return function(){return n.apply(this,arguments)}}();return n.loadLCDP=T,n.requestLCDP=function(n){return new d(n,arguments.length>1&&void 0!==arguments[1]?arguments[1]:h)},n}({});
|