@lacagnottedesproches/lcdp-js-lite 1.12.0 โ 1.13.0-beta.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/README.md +64 -4
- package/dist/types.d.ts +51 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,9 +1,69 @@
|
|
|
1
1
|
[](https://github.com/lacagnottedesproches/afina-js-lite/actions/workflows/test.js.yml)
|
|
2
|
-
|
|
3
|
-
[](https://github.com/lacagnottedesproches/afina-js-lite/actions/workflows/node.js.yml)
|
|
2
|
+
[](https://www.npmjs.com/package/@lacagnottedesproches/lcdp-js-lite)
|
|
4
3
|
|
|
5
4
|
<div align="center">
|
|
6
|
-
<h1>La Cagnotte des Proches
|
|
5
|
+
<h1>La Cagnotte des Proches โ JS SDK</h1>
|
|
6
|
+
<p>Typed loader for the La Cagnotte des Proches SDK, in the browser and on the server.</p>
|
|
7
|
+
<p>
|
|
8
|
+
<a href="https://docs.lacagnottedesproches.fr/lcdpjs/"><strong>Documentation</strong></a> ยท
|
|
9
|
+
<a href="https://docs.lacagnottedesproches.fr/">API reference</a>
|
|
10
|
+
</p>
|
|
7
11
|
</div>
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @lacagnottedesproches/lcdp-js-lite @stripe/stripe-js
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
`@stripe/stripe-js` (>= 3) is a peer dependency.
|
|
20
|
+
|
|
21
|
+
## Browser: `loadLCDP`
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { loadLCDP } from "@lacagnottedesproches/lcdp-js-lite";
|
|
25
|
+
|
|
26
|
+
const lcdp = await loadLCDP("pk_your_public_key");
|
|
27
|
+
// lcdp is null during server-side rendering
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Options:
|
|
31
|
+
|
|
32
|
+
| Option | Default | Description |
|
|
33
|
+
| ------------- | ------------------------------------- | -------------------------------------------------------------- |
|
|
34
|
+
| `api_url` | `https://api.lacagnottedesproches.fr` | API base URL. Never take it from user input. |
|
|
35
|
+
| `sdk_version` | โ | Pin a specific SDK bundle version. |
|
|
36
|
+
| `stripe` | `true` | Set `false` on read-only pages to skip loading Stripe.js. |
|
|
37
|
+
|
|
38
|
+
The SDK is loaded once. Calling `loadLCDP` again returns the same instance.
|
|
39
|
+
|
|
40
|
+
## Server: `requestLCDP`
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { requestLCDP } from "@lacagnottedesproches/lcdp-js-lite";
|
|
44
|
+
|
|
45
|
+
const api = requestLCDP(process.env.LCDP_SECRET_KEY!);
|
|
46
|
+
const account = await api.getAccount(accountId);
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- **Server only.** It throws if `window` exists, so your secret key never reaches the browser.
|
|
50
|
+
- Every request has a 30 s timeout.
|
|
51
|
+
- On HTTP errors, the promise rejects with the API error `detail`.
|
|
52
|
+
|
|
53
|
+
Available methods: `createAccount`, `createPot`, `createAccountAndPot`, `updatePot`, `createPayout`, `getAccount`, `updateAccount`, `updateAccountIdentity`, `updateAccountBank`.
|
|
54
|
+
|
|
55
|
+
## TypeScript
|
|
56
|
+
|
|
57
|
+
All types are exported from the package:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import type { LCDP, LCDPApi } from "@lacagnottedesproches/lcdp-js-lite";
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Documentation
|
|
64
|
+
|
|
65
|
+
Full guides and the API reference: **https://docs.lacagnottedesproches.fr/lcdpjs/**
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
[GPL-3.0-only](./LICENSE)
|
package/dist/types.d.ts
CHANGED
|
@@ -177,6 +177,34 @@ export interface PayloadDonation extends DataDonation {
|
|
|
177
177
|
amount_donation: number;
|
|
178
178
|
amount_tip: number;
|
|
179
179
|
}
|
|
180
|
+
/**
|
|
181
|
+
* Donor edit of a donation, sent to `updateDonation`. `token` is the edit
|
|
182
|
+
* token from the link v4 puts in the donation email. Only the fields you set
|
|
183
|
+
* are changed; `message: null` clears the message.
|
|
184
|
+
*/
|
|
185
|
+
export interface PayloadDonationUpdate {
|
|
186
|
+
token: string;
|
|
187
|
+
first_name?: string | undefined;
|
|
188
|
+
message?: string | null | undefined;
|
|
189
|
+
stay_anonymous_checked?: boolean | undefined;
|
|
190
|
+
hide_amount_donation_checked?: boolean | undefined;
|
|
191
|
+
private_message_checked?: boolean | undefined;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Current values of a donation for the donor edit form, from `getDonationForEdit`.
|
|
195
|
+
* `first_name` and `message` are the real values, even for an anonymous
|
|
196
|
+
* donation or a private message.
|
|
197
|
+
*/
|
|
198
|
+
export interface DonationForEdit {
|
|
199
|
+
id: UUID;
|
|
200
|
+
first_name: string | null;
|
|
201
|
+
message: string | null;
|
|
202
|
+
stay_anonymous_checked: boolean;
|
|
203
|
+
hide_amount_donation_checked: boolean;
|
|
204
|
+
private_message_checked: boolean;
|
|
205
|
+
pot_id: UUID;
|
|
206
|
+
pot_name: string;
|
|
207
|
+
}
|
|
180
208
|
export interface DonationResult {
|
|
181
209
|
error?: string;
|
|
182
210
|
status: string | "requires_action";
|
|
@@ -246,6 +274,25 @@ export interface StatsPot {
|
|
|
246
274
|
amount_tips?: number;
|
|
247
275
|
amount_real_tips?: number;
|
|
248
276
|
}
|
|
277
|
+
/**
|
|
278
|
+
* Public view of a donation in a pot donations list. The API already hides
|
|
279
|
+
* what the donor chose to hide: names are null when anonymous, the amount
|
|
280
|
+
* is null when hidden, the message is null when private.
|
|
281
|
+
*/
|
|
282
|
+
export interface PotDonation {
|
|
283
|
+
id: UUID;
|
|
284
|
+
date_created_ts: number;
|
|
285
|
+
amount_donation: number | null;
|
|
286
|
+
stay_anonymous_checked: boolean;
|
|
287
|
+
hide_amount_donation_checked: boolean;
|
|
288
|
+
private_message_checked: boolean;
|
|
289
|
+
message: string | null;
|
|
290
|
+
first_name: string | null;
|
|
291
|
+
last_name: string | null;
|
|
292
|
+
}
|
|
293
|
+
export interface PotDonationsPagination extends Pagination {
|
|
294
|
+
items: PotDonation[];
|
|
295
|
+
}
|
|
249
296
|
export interface StatsPotsPagination extends Pagination {
|
|
250
297
|
items: StatsPot[];
|
|
251
298
|
}
|
|
@@ -303,10 +350,14 @@ export interface LCDP {
|
|
|
303
350
|
createTokenPersonVerification: (payload: PayloadVerification) => Promise<ExternalTokenObject>;
|
|
304
351
|
createTokenAccountBank(payload: PayloadAccountBank): Promise<ExternalTokenObject>;
|
|
305
352
|
createDonation: (payload: PayloadDonation) => Promise<DonationResult>;
|
|
353
|
+
/** `getDonationForEdit` and `updateDonation` need SDK 1.7.0 or later. */
|
|
354
|
+
getDonationForEdit: (token: string) => Promise<DonationForEdit>;
|
|
355
|
+
updateDonation: (donationId: string, payload: PayloadDonationUpdate) => Promise<void>;
|
|
306
356
|
getAvailableCountries: () => Promise<Country[]>;
|
|
307
357
|
getCategories: () => Promise<Category[]>;
|
|
308
358
|
getPots: (params?: ParamsPagination) => Promise<PotsPagination>;
|
|
309
359
|
getPot: (potId: string) => Promise<Pot>;
|
|
360
|
+
getPotDonations: (potId: string, params?: ParamsPagination) => Promise<PotDonationsPagination>;
|
|
310
361
|
getStatsDashboard: (ts_start?: number, ts_end?: number) => Promise<StatDashboard>;
|
|
311
362
|
getStatsPots: (ts_start?: number, ts_end?: number, page?: number, per_page?: number) => Promise<StatsPotsPagination>;
|
|
312
363
|
retrieveAssociations: (payload?: PayloadQueryAssociations) => Promise<Associations>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lacagnottedesproches/lcdp-js-lite",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.0-beta.0",
|
|
4
4
|
"description": "LCDP JS Lite",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "rm -rf dist/ && rollup -c",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"test:types": "tsd --files __tests__/types.test-d.ts",
|
|
16
16
|
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
|
|
17
17
|
"test:update-snapshots": "jest --updateSnapshot",
|
|
18
|
-
"test:clear-cache": "jest --clearCache"
|
|
18
|
+
"test:clear-cache": "jest --clearCache",
|
|
19
|
+
"docs": "typedoc"
|
|
19
20
|
},
|
|
20
21
|
"main": "dist/index.js",
|
|
21
22
|
"module": "dist/index.mjs",
|