@ledewire/browser 0.3.0 → 0.5.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 +32 -9
- package/dist/index.d.ts +227 -6
- package/dist/index.js +143 -18
- package/dist/index.js.map +1 -1
- package/dist/ledewire.min.js +1 -1
- package/dist/ledewire.min.js.map +1 -1
- package/llms.txt +290 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/@ledewire/browser)
|
|
4
4
|
[](../../LICENSE)
|
|
5
5
|
|
|
6
|
-
Browser SDK for the [LedeWire](https://api.ledewire.com/api-docs/index.html) content marketplace — embed buyer authentication, wallet funding, and content
|
|
6
|
+
Browser SDK for the [LedeWire](https://api.ledewire.com/api-docs/index.html) content marketplace — embed buyer authentication, wallet funding, content purchases, and seller content discovery on any website with a single script tag.
|
|
7
7
|
|
|
8
8
|
## CDN — No Install Required
|
|
9
9
|
|
|
@@ -40,14 +40,15 @@ const lw = init({
|
|
|
40
40
|
|
|
41
41
|
## Client Namespaces
|
|
42
42
|
|
|
43
|
-
| Namespace
|
|
44
|
-
|
|
|
45
|
-
| `lw.config`
|
|
46
|
-
| `lw.auth`
|
|
47
|
-
| `lw.wallet`
|
|
48
|
-
| `lw.purchases`
|
|
49
|
-
| `lw.content`
|
|
50
|
-
| `lw.checkout`
|
|
43
|
+
| Namespace | Description |
|
|
44
|
+
| ------------------- | ------------------------------------------------------------------------------- |
|
|
45
|
+
| `lw.config` | Platform public config (no auth required) |
|
|
46
|
+
| `lw.auth` | Buyer signup, email/password login, Google OAuth, API key login, password reset |
|
|
47
|
+
| `lw.wallet` | Wallet balance, fund wallet via payment session |
|
|
48
|
+
| `lw.purchases` | List and create content purchases |
|
|
49
|
+
| `lw.content` | Fetch content with buyer access info |
|
|
50
|
+
| `lw.checkout` | Checkout state — what action is required next |
|
|
51
|
+
| `lw.seller.content` | List, search, and get store content (API key auth) |
|
|
51
52
|
|
|
52
53
|
## Example: Fetch Google OAuth Client ID Before Sign-In
|
|
53
54
|
|
|
@@ -92,6 +93,28 @@ switch (checkout_state.next_required_action) {
|
|
|
92
93
|
}
|
|
93
94
|
```
|
|
94
95
|
|
|
96
|
+
## Example: Seller Content Discovery
|
|
97
|
+
|
|
98
|
+
Use `lw.auth.loginWithApiKey` with only the `key` to obtain a read-only token,
|
|
99
|
+
then browse your store's content catalogue directly from the browser:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
const lw = Ledewire.init({ apiKey: 'your_api_key' })
|
|
103
|
+
|
|
104
|
+
// Obtain a view-only seller token (key only — no secret needed)
|
|
105
|
+
await lw.auth.loginWithApiKey({ key: 'your_api_key' })
|
|
106
|
+
|
|
107
|
+
// List all content
|
|
108
|
+
const items = await lw.seller.content.list()
|
|
109
|
+
|
|
110
|
+
// Search by title, URI, or metadata
|
|
111
|
+
const results = await lw.seller.content.search({ title: 'intro' })
|
|
112
|
+
const byMeta = await lw.seller.content.search({ metadata: { author: 'Alice' } })
|
|
113
|
+
|
|
114
|
+
// Fetch a single item
|
|
115
|
+
const item = await lw.seller.content.get('content-id')
|
|
116
|
+
```
|
|
117
|
+
|
|
95
118
|
## Token Storage
|
|
96
119
|
|
|
97
120
|
By default tokens are stored **in memory** (most secure — cleared on page unload).
|
package/dist/index.d.ts
CHANGED
|
@@ -47,12 +47,47 @@ export declare class AuthError extends LedewireError {
|
|
|
47
47
|
constructor(message: string, code?: number);
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
/** Request body for API key authentication (seller). */
|
|
51
|
+
declare type AuthLoginApiKeyRequest = components['schemas']['AuthLoginApiKeyRequest'];
|
|
52
|
+
|
|
50
53
|
/** Request body for buyer email/password login. */
|
|
51
54
|
declare type AuthLoginEmailRequest = components['schemas']['AuthLoginEmailRequest'];
|
|
52
55
|
|
|
53
56
|
/** Request body for buyer Google OAuth login. */
|
|
54
57
|
declare type AuthLoginOAuthRequest = components['schemas']['AuthLoginOAuthRequest'];
|
|
55
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Request body for completing a buyer password reset.
|
|
61
|
+
* Sent to `POST /v1/auth/password/reset`.
|
|
62
|
+
*/
|
|
63
|
+
export declare interface AuthPasswordResetBody {
|
|
64
|
+
/** The buyer's registered email address. */
|
|
65
|
+
email: string;
|
|
66
|
+
/** 6-digit numeric code delivered to the buyer's email. */
|
|
67
|
+
reset_code: string;
|
|
68
|
+
/** New password (minimum 6 characters). */
|
|
69
|
+
password: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Request body for initiating a buyer password reset.
|
|
74
|
+
* Sent to `POST /v1/auth/password/reset-request`.
|
|
75
|
+
*/
|
|
76
|
+
export declare interface AuthPasswordResetRequestBody {
|
|
77
|
+
/** The buyer's registered email address. */
|
|
78
|
+
email: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Response returned by both password reset endpoints.
|
|
83
|
+
* Contains a human-readable confirmation message.
|
|
84
|
+
*/
|
|
85
|
+
export declare interface AuthPasswordResetResponse {
|
|
86
|
+
data?: {
|
|
87
|
+
message?: string;
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
56
91
|
/** Request body for buyer email/password signup. */
|
|
57
92
|
declare type AuthSignupRequest = components['schemas']['AuthSignupRequest'];
|
|
58
93
|
|
|
@@ -95,6 +130,61 @@ declare class BrowserAuthNamespace {
|
|
|
95
130
|
* @returns The authentication token response.
|
|
96
131
|
*/
|
|
97
132
|
loginWithGoogle(body: AuthLoginOAuthRequest): Promise<AuthenticationResponse>;
|
|
133
|
+
/**
|
|
134
|
+
* Log in using an API key to obtain a seller token.
|
|
135
|
+
* Provide only `key` for read-only (`view`) access.
|
|
136
|
+
* Provide both `key` and `secret` for read/write (`full`) access.
|
|
137
|
+
* Tokens are stored automatically after successful authentication.
|
|
138
|
+
*
|
|
139
|
+
* Use this before calling `lw.seller.content.*` methods.
|
|
140
|
+
*
|
|
141
|
+
* @param body - API key credentials.
|
|
142
|
+
* @returns The authentication token response.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```ts
|
|
146
|
+
* // View access (read-only) — sufficient for seller.content.list/search/get
|
|
147
|
+
* await lw.auth.loginWithApiKey({ key: 'your_api_key' })
|
|
148
|
+
*
|
|
149
|
+
* // Full access (read/write)
|
|
150
|
+
* await lw.auth.loginWithApiKey({ key: 'your_api_key', secret: 'your_secret' })
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
loginWithApiKey(body: AuthLoginApiKeyRequest): Promise<AuthenticationResponse>;
|
|
154
|
+
/**
|
|
155
|
+
* Request a password reset code to be sent to the buyer's email address.
|
|
156
|
+
*
|
|
157
|
+
* The response is intentionally ambiguous — if the email does not exist,
|
|
158
|
+
* the API returns the same success message to prevent account enumeration.
|
|
159
|
+
*
|
|
160
|
+
* @param body - The buyer's email address.
|
|
161
|
+
* @returns A response with a confirmation message.
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* ```ts
|
|
165
|
+
* await lw.auth.requestPasswordReset({ email: 'buyer@example.com' })
|
|
166
|
+
* // → { data: { message: 'If an account with this email exists, a reset code has been sent.' } }
|
|
167
|
+
* ```
|
|
168
|
+
*/
|
|
169
|
+
requestPasswordReset(body: AuthPasswordResetRequestBody): Promise<AuthPasswordResetResponse>;
|
|
170
|
+
/**
|
|
171
|
+
* Reset a buyer's password using the code delivered to their email.
|
|
172
|
+
*
|
|
173
|
+
* Obtain the reset code first by calling `requestPasswordReset()`.
|
|
174
|
+
*
|
|
175
|
+
* @param body - Email address, 6-digit reset code, and the new password.
|
|
176
|
+
* @returns A response with a confirmation message.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```ts
|
|
180
|
+
* await lw.auth.resetPassword({
|
|
181
|
+
* email: 'buyer@example.com',
|
|
182
|
+
* reset_code: '123456',
|
|
183
|
+
* password: 'new-secure-password',
|
|
184
|
+
* })
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
resetPassword(body: AuthPasswordResetBody): Promise<AuthPasswordResetResponse>;
|
|
98
188
|
private storeTokens;
|
|
99
189
|
}
|
|
100
190
|
|
|
@@ -121,6 +211,8 @@ declare class BrowserClient {
|
|
|
121
211
|
readonly purchases: BrowserPurchasesNamespace;
|
|
122
212
|
/** Public content with per-user access information */
|
|
123
213
|
readonly content: BrowserContentNamespace;
|
|
214
|
+
/** Seller content: list, search, and get (requires API key view token) */
|
|
215
|
+
readonly seller: BrowserSellerNamespace;
|
|
124
216
|
/* Excluded from this release type: __constructor */
|
|
125
217
|
}
|
|
126
218
|
|
|
@@ -248,6 +340,85 @@ declare class BrowserPurchasesNamespace {
|
|
|
248
340
|
get(id: string): Promise<PurchaseResponse>;
|
|
249
341
|
}
|
|
250
342
|
|
|
343
|
+
/**
|
|
344
|
+
* Seller content namespace — list, search, and fetch store content by API key.
|
|
345
|
+
*
|
|
346
|
+
* Obtain via `lw.seller.content` — do not construct directly.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* ```ts
|
|
350
|
+
* const lw = Ledewire.init({ apiKey: 'your_api_key' })
|
|
351
|
+
* await lw.auth.loginWithApiKey({ key: 'your_api_key' })
|
|
352
|
+
*
|
|
353
|
+
* const items = await lw.seller.content.list()
|
|
354
|
+
* const results = await lw.seller.content.search({ title: 'intro' })
|
|
355
|
+
* const item = await lw.seller.content.get('content-id')
|
|
356
|
+
* ```
|
|
357
|
+
*/
|
|
358
|
+
declare class BrowserSellerContentNamespace {
|
|
359
|
+
private readonly http;
|
|
360
|
+
/* Excluded from this release type: __constructor */
|
|
361
|
+
/**
|
|
362
|
+
* List all content for the authenticated seller's store.
|
|
363
|
+
* Requires a token with at least `view` permission.
|
|
364
|
+
*
|
|
365
|
+
* @returns Array of content items.
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```ts
|
|
369
|
+
* const items = await lw.seller.content.list()
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
list(): Promise<ContentResponse[]>;
|
|
373
|
+
/**
|
|
374
|
+
* Search content by title, URI, and/or metadata (AND logic).
|
|
375
|
+
* At least one criterion must be supplied.
|
|
376
|
+
* Requires a token with at least `view` permission.
|
|
377
|
+
*
|
|
378
|
+
* @param body - Search criteria (title, uri, and/or metadata).
|
|
379
|
+
* @returns Array of matching content items.
|
|
380
|
+
*
|
|
381
|
+
* @example
|
|
382
|
+
* ```ts
|
|
383
|
+
* const results = await lw.seller.content.search({ title: 'intro' })
|
|
384
|
+
* const byUri = await lw.seller.content.search({ uri: 'vimeo.com' })
|
|
385
|
+
* const byMeta = await lw.seller.content.search({ metadata: { author: 'Alice' } })
|
|
386
|
+
* ```
|
|
387
|
+
*/
|
|
388
|
+
search(body: SellerContentSearchRequest): Promise<ContentResponse[]>;
|
|
389
|
+
/**
|
|
390
|
+
* Get a single content item by ID.
|
|
391
|
+
* Requires a token with at least `view` permission.
|
|
392
|
+
*
|
|
393
|
+
* @param id - The content ID.
|
|
394
|
+
* @returns The content item.
|
|
395
|
+
*
|
|
396
|
+
* @example
|
|
397
|
+
* ```ts
|
|
398
|
+
* const item = await lw.seller.content.get('content-id')
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
get(id: string): Promise<ContentResponse>;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Seller operations accessible with a view-permission API key token.
|
|
406
|
+
*
|
|
407
|
+
* Obtain via `lw.seller` — do not construct directly.
|
|
408
|
+
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* const lw = Ledewire.init({ apiKey: 'your_api_key' })
|
|
412
|
+
* await lw.auth.loginWithApiKey({ key: 'your_api_key' })
|
|
413
|
+
* const items = await lw.seller.content.list()
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
416
|
+
declare class BrowserSellerNamespace {
|
|
417
|
+
/** Seller content: list, search, and get by API key. */
|
|
418
|
+
readonly content: BrowserSellerContentNamespace;
|
|
419
|
+
/* Excluded from this release type: __constructor */
|
|
420
|
+
}
|
|
421
|
+
|
|
251
422
|
/**
|
|
252
423
|
* Buyer wallet namespace — balance, transactions, and payment session management.
|
|
253
424
|
*
|
|
@@ -455,8 +626,8 @@ declare interface components {
|
|
|
455
626
|
refresh_token?: string;
|
|
456
627
|
};
|
|
457
628
|
ManageableStore: {
|
|
458
|
-
|
|
459
|
-
|
|
629
|
+
id: string;
|
|
630
|
+
name: string;
|
|
460
631
|
store_key: string;
|
|
461
632
|
/**
|
|
462
633
|
* @description Derived role. `owner` if the user owns this store; `author` if they have author permissions only.
|
|
@@ -986,7 +1157,7 @@ declare interface components {
|
|
|
986
1157
|
data: components['schemas']['MerchantUser'][];
|
|
987
1158
|
pagination: components['schemas']['PaginationMeta'];
|
|
988
1159
|
};
|
|
989
|
-
/** @description Lightweight content representation returned by list and search endpoints. Omits
|
|
1160
|
+
/** @description Lightweight content representation returned by list and search endpoints. Omits `content_body` to keep list payloads small. Use the detail endpoint (`GET /v1/merchant/:store_id/content/:id`) to retrieve the full body. */
|
|
990
1161
|
ContentListItem: {
|
|
991
1162
|
id: string;
|
|
992
1163
|
/** @enum {string} */
|
|
@@ -1002,6 +1173,8 @@ declare interface components {
|
|
|
1002
1173
|
visibility: 'public' | 'unlisted' | 'private';
|
|
1003
1174
|
/** Format: date-time */
|
|
1004
1175
|
created_at: string;
|
|
1176
|
+
/** @description External URI for `external_ref` content; optional supplementary link for `markdown` content. Null when not set. */
|
|
1177
|
+
content_uri: string | null;
|
|
1005
1178
|
/** @description Namespaced platform ID for `external_ref` content. Null for other types. */
|
|
1006
1179
|
external_identifier?: string | null;
|
|
1007
1180
|
};
|
|
@@ -1139,12 +1312,42 @@ declare interface components {
|
|
|
1139
1312
|
/** Checkout state for a specific piece of content and user. */
|
|
1140
1313
|
export declare type ContentAccessInfo = components['schemas']['ContentAccessInfo'];
|
|
1141
1314
|
|
|
1315
|
+
/** Full content item returned by all seller content endpoints. */
|
|
1316
|
+
declare type ContentResponse = components['schemas']['ContentResponse'];
|
|
1317
|
+
|
|
1142
1318
|
/** A piece of content with buyer access information. */
|
|
1143
1319
|
export declare type ContentWithAccessResponse = components['schemas']['ContentWithAccessResponse'];
|
|
1144
1320
|
|
|
1145
1321
|
/**
|
|
1146
1322
|
* Thrown when the authenticated user does not have permission
|
|
1147
1323
|
* to perform the requested operation.
|
|
1324
|
+
*
|
|
1325
|
+
* **Common cause — merchant login with the wrong account role:**
|
|
1326
|
+
* `POST /v1/auth/merchant/login/email` and `POST /v1/auth/merchant/login/google`
|
|
1327
|
+
* return `403 Forbidden` (not `401`) when the credentials are valid but the
|
|
1328
|
+
* account has no merchant store associations (e.g. a buyer account used on the
|
|
1329
|
+
* merchant endpoint). The `err.message` will be:
|
|
1330
|
+
* `"This account does not have merchant access. Use a merchant or owner account."`
|
|
1331
|
+
*
|
|
1332
|
+
* Use a different account or ask a store owner to add your account as a member.
|
|
1333
|
+
*
|
|
1334
|
+
* @example
|
|
1335
|
+
* ```ts
|
|
1336
|
+
* import { ForbiddenError, AuthError } from '@ledewire/node'
|
|
1337
|
+
*
|
|
1338
|
+
* try {
|
|
1339
|
+
* await client.merchant.auth.loginWithGoogle({ id_token })
|
|
1340
|
+
* } catch (err) {
|
|
1341
|
+
* if (err instanceof ForbiddenError) {
|
|
1342
|
+
* // Credentials were valid but account has no merchant store access.
|
|
1343
|
+
* // err.message → "This account does not have merchant access. Use a merchant or owner account."
|
|
1344
|
+
* console.error('Wrong account role:', err.message)
|
|
1345
|
+
* } else if (err instanceof AuthError) {
|
|
1346
|
+
* // Bad credentials or expired token — re-authenticate.
|
|
1347
|
+
* console.error('Authentication failed:', err.message)
|
|
1348
|
+
* }
|
|
1349
|
+
* }
|
|
1350
|
+
* ```
|
|
1148
1351
|
*/
|
|
1149
1352
|
export declare class ForbiddenError extends LedewireError {
|
|
1150
1353
|
constructor(message: string, code?: number);
|
|
@@ -1342,6 +1545,19 @@ export declare class PurchaseError extends LedewireError {
|
|
|
1342
1545
|
/** A purchase record. */
|
|
1343
1546
|
export declare type PurchaseResponse = components['schemas']['PurchaseResponse'];
|
|
1344
1547
|
|
|
1548
|
+
/**
|
|
1549
|
+
* Search criteria for seller content search.
|
|
1550
|
+
* At least one field must be supplied. All supplied fields must match (AND logic).
|
|
1551
|
+
*/
|
|
1552
|
+
export declare interface SellerContentSearchRequest {
|
|
1553
|
+
/** Case-insensitive partial match against the content title. */
|
|
1554
|
+
title?: string;
|
|
1555
|
+
/** Case-insensitive partial match against the content URI (`external_ref` content only). */
|
|
1556
|
+
uri?: string;
|
|
1557
|
+
/** Exact key/value pairs to AND-match against content metadata. */
|
|
1558
|
+
metadata?: Record<string, unknown>;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1345
1561
|
/** Internal representation of stored authentication tokens. */
|
|
1346
1562
|
export declare interface StoredTokens {
|
|
1347
1563
|
accessToken: string;
|
|
@@ -1396,13 +1612,18 @@ declare interface TokenManagerOptions {
|
|
|
1396
1612
|
*/
|
|
1397
1613
|
refreshFn: (refreshToken: string) => Promise<StoredTokens>;
|
|
1398
1614
|
/**
|
|
1399
|
-
* Called after a successful token refresh.
|
|
1400
|
-
* Use
|
|
1615
|
+
* Called after a successful background token refresh (not on initial login).
|
|
1616
|
+
* Use for side-effects only — e.g. audit logging, cache invalidation, or
|
|
1617
|
+
* notifying a secondary system when tokens rotate.
|
|
1618
|
+
*
|
|
1619
|
+
* **Do not use this for token persistence.** The `storage` adapter's
|
|
1620
|
+
* `setTokens` is the canonical persistence hook and is already called on
|
|
1621
|
+
* every refresh. Providing both will result in double-writes.
|
|
1401
1622
|
*
|
|
1402
1623
|
* @example
|
|
1403
1624
|
* ```ts
|
|
1404
1625
|
* onTokenRefreshed: async (tokens) => {
|
|
1405
|
-
* await
|
|
1626
|
+
* await auditLog.record('token_refreshed', { expiresAt: tokens.expiresAt })
|
|
1406
1627
|
* }
|
|
1407
1628
|
* ```
|
|
1408
1629
|
*/
|
package/dist/index.js
CHANGED
|
@@ -21,23 +21,23 @@ class d extends c {
|
|
|
21
21
|
super(e, 403, t), this.name = "ForbiddenError";
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
|
-
class
|
|
24
|
+
class g extends c {
|
|
25
25
|
constructor(e, t) {
|
|
26
26
|
super(e, 404, t), this.name = "NotFoundError";
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
class
|
|
29
|
+
class $ extends c {
|
|
30
30
|
constructor(e, t, r) {
|
|
31
31
|
super(e, t, r), this.name = "PurchaseError";
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
const
|
|
34
|
+
const k = "https://api.ledewire.com";
|
|
35
35
|
class f {
|
|
36
36
|
constructor(e = {}) {
|
|
37
37
|
n(this, "baseUrl");
|
|
38
38
|
n(this, "getAccessToken");
|
|
39
39
|
n(this, "onUnauthorized");
|
|
40
|
-
this.baseUrl = (e.baseUrl ??
|
|
40
|
+
this.baseUrl = (e.baseUrl ?? k).replace(/\/$/, ""), this.getAccessToken = e.getAccessToken ?? (() => null), this.onUnauthorized = e.onUnauthorized ?? (() => null);
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* GET request with optional query parameters.
|
|
@@ -117,7 +117,7 @@ class f {
|
|
|
117
117
|
case 403:
|
|
118
118
|
throw new d(r, o);
|
|
119
119
|
case 404:
|
|
120
|
-
throw new
|
|
120
|
+
throw new g(r, o);
|
|
121
121
|
default:
|
|
122
122
|
throw new c(r, e.status, o);
|
|
123
123
|
}
|
|
@@ -226,6 +226,68 @@ class E {
|
|
|
226
226
|
const t = await this.http.post("/v1/auth/login/google", e);
|
|
227
227
|
return await this.storeTokens(t), t;
|
|
228
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Log in using an API key to obtain a seller token.
|
|
231
|
+
* Provide only `key` for read-only (`view`) access.
|
|
232
|
+
* Provide both `key` and `secret` for read/write (`full`) access.
|
|
233
|
+
* Tokens are stored automatically after successful authentication.
|
|
234
|
+
*
|
|
235
|
+
* Use this before calling `lw.seller.content.*` methods.
|
|
236
|
+
*
|
|
237
|
+
* @param body - API key credentials.
|
|
238
|
+
* @returns The authentication token response.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```ts
|
|
242
|
+
* // View access (read-only) — sufficient for seller.content.list/search/get
|
|
243
|
+
* await lw.auth.loginWithApiKey({ key: 'your_api_key' })
|
|
244
|
+
*
|
|
245
|
+
* // Full access (read/write)
|
|
246
|
+
* await lw.auth.loginWithApiKey({ key: 'your_api_key', secret: 'your_secret' })
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
async loginWithApiKey(e) {
|
|
250
|
+
const t = await this.http.post("/v1/auth/login/api-key", e);
|
|
251
|
+
return await this.storeTokens(t), t;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Request a password reset code to be sent to the buyer's email address.
|
|
255
|
+
*
|
|
256
|
+
* The response is intentionally ambiguous — if the email does not exist,
|
|
257
|
+
* the API returns the same success message to prevent account enumeration.
|
|
258
|
+
*
|
|
259
|
+
* @param body - The buyer's email address.
|
|
260
|
+
* @returns A response with a confirmation message.
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* ```ts
|
|
264
|
+
* await lw.auth.requestPasswordReset({ email: 'buyer@example.com' })
|
|
265
|
+
* // → { data: { message: 'If an account with this email exists, a reset code has been sent.' } }
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
async requestPasswordReset(e) {
|
|
269
|
+
return this.http.post("/v1/auth/password/reset-request", e);
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Reset a buyer's password using the code delivered to their email.
|
|
273
|
+
*
|
|
274
|
+
* Obtain the reset code first by calling `requestPasswordReset()`.
|
|
275
|
+
*
|
|
276
|
+
* @param body - Email address, 6-digit reset code, and the new password.
|
|
277
|
+
* @returns A response with a confirmation message.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```ts
|
|
281
|
+
* await lw.auth.resetPassword({
|
|
282
|
+
* email: 'buyer@example.com',
|
|
283
|
+
* reset_code: '123456',
|
|
284
|
+
* password: 'new-secure-password',
|
|
285
|
+
* })
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
async resetPassword(e) {
|
|
289
|
+
return this.http.post("/v1/auth/password/reset", e);
|
|
290
|
+
}
|
|
229
291
|
async storeTokens(e) {
|
|
230
292
|
await this.tokenManager.setTokens({
|
|
231
293
|
accessToken: e.access_token,
|
|
@@ -257,7 +319,7 @@ class A {
|
|
|
257
319
|
return this.http.get("/v1/config/public");
|
|
258
320
|
}
|
|
259
321
|
}
|
|
260
|
-
class
|
|
322
|
+
class v {
|
|
261
323
|
constructor(e) {
|
|
262
324
|
this.http = e;
|
|
263
325
|
}
|
|
@@ -277,7 +339,7 @@ class x {
|
|
|
277
339
|
);
|
|
278
340
|
}
|
|
279
341
|
}
|
|
280
|
-
class
|
|
342
|
+
class x {
|
|
281
343
|
constructor(e) {
|
|
282
344
|
this.http = e;
|
|
283
345
|
}
|
|
@@ -308,6 +370,67 @@ class U {
|
|
|
308
370
|
return this.http.get(`/v1/purchases/${e}`);
|
|
309
371
|
}
|
|
310
372
|
}
|
|
373
|
+
class U {
|
|
374
|
+
/** @internal */
|
|
375
|
+
constructor(e) {
|
|
376
|
+
this.http = e;
|
|
377
|
+
}
|
|
378
|
+
/**
|
|
379
|
+
* List all content for the authenticated seller's store.
|
|
380
|
+
* Requires a token with at least `view` permission.
|
|
381
|
+
*
|
|
382
|
+
* @returns Array of content items.
|
|
383
|
+
*
|
|
384
|
+
* @example
|
|
385
|
+
* ```ts
|
|
386
|
+
* const items = await lw.seller.content.list()
|
|
387
|
+
* ```
|
|
388
|
+
*/
|
|
389
|
+
async list() {
|
|
390
|
+
return this.http.get("/v1/seller/content");
|
|
391
|
+
}
|
|
392
|
+
/**
|
|
393
|
+
* Search content by title, URI, and/or metadata (AND logic).
|
|
394
|
+
* At least one criterion must be supplied.
|
|
395
|
+
* Requires a token with at least `view` permission.
|
|
396
|
+
*
|
|
397
|
+
* @param body - Search criteria (title, uri, and/or metadata).
|
|
398
|
+
* @returns Array of matching content items.
|
|
399
|
+
*
|
|
400
|
+
* @example
|
|
401
|
+
* ```ts
|
|
402
|
+
* const results = await lw.seller.content.search({ title: 'intro' })
|
|
403
|
+
* const byUri = await lw.seller.content.search({ uri: 'vimeo.com' })
|
|
404
|
+
* const byMeta = await lw.seller.content.search({ metadata: { author: 'Alice' } })
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
async search(e) {
|
|
408
|
+
return this.http.post("/v1/seller/content/search", e);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* Get a single content item by ID.
|
|
412
|
+
* Requires a token with at least `view` permission.
|
|
413
|
+
*
|
|
414
|
+
* @param id - The content ID.
|
|
415
|
+
* @returns The content item.
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```ts
|
|
419
|
+
* const item = await lw.seller.content.get('content-id')
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
async get(e) {
|
|
423
|
+
return this.http.get(`/v1/seller/content/${e}`);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
class S {
|
|
427
|
+
/** @internal */
|
|
428
|
+
constructor(e) {
|
|
429
|
+
/** Seller content: list, search, and get by API key. */
|
|
430
|
+
n(this, "content");
|
|
431
|
+
this.content = new U(e);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
311
434
|
class b {
|
|
312
435
|
constructor(e) {
|
|
313
436
|
this.http = e;
|
|
@@ -347,7 +470,7 @@ class b {
|
|
|
347
470
|
return this.http.get(`/v1/wallet/payment-status/${e}`);
|
|
348
471
|
}
|
|
349
472
|
}
|
|
350
|
-
class
|
|
473
|
+
class P {
|
|
351
474
|
constructor(e) {
|
|
352
475
|
this.http = e;
|
|
353
476
|
}
|
|
@@ -366,7 +489,7 @@ class v {
|
|
|
366
489
|
return this.http.get(`/v1/checkout/state/${e}`);
|
|
367
490
|
}
|
|
368
491
|
}
|
|
369
|
-
function
|
|
492
|
+
function C(s) {
|
|
370
493
|
const e = s.baseUrl ?? "https://api.ledewire.com", t = s.storage ?? new m(), r = new y({
|
|
371
494
|
storage: t,
|
|
372
495
|
refreshFn: async (h) => {
|
|
@@ -389,9 +512,9 @@ function O(s) {
|
|
|
389
512
|
getAccessToken: () => r.getAccessToken(),
|
|
390
513
|
onUnauthorized: () => r.handleUnauthorized()
|
|
391
514
|
});
|
|
392
|
-
return new
|
|
515
|
+
return new N(o, r, s);
|
|
393
516
|
}
|
|
394
|
-
class
|
|
517
|
+
class N {
|
|
395
518
|
/** @internal */
|
|
396
519
|
constructor(e, t, r) {
|
|
397
520
|
/** Platform-level public configuration (no auth required) */
|
|
@@ -406,11 +529,13 @@ class S {
|
|
|
406
529
|
n(this, "purchases");
|
|
407
530
|
/** Public content with per-user access information */
|
|
408
531
|
n(this, "content");
|
|
409
|
-
|
|
532
|
+
/** Seller content: list, search, and get (requires API key view token) */
|
|
533
|
+
n(this, "seller");
|
|
534
|
+
this._http = e, this._tokenManager = t, this._config = r, this.config = new A(e), this.auth = new E(e, t), this.checkout = new P(e), this.wallet = new b(e), this.purchases = new x(e), this.content = new v(e), this.seller = new S(e);
|
|
410
535
|
}
|
|
411
536
|
}
|
|
412
|
-
const
|
|
413
|
-
function
|
|
537
|
+
const R = "lw:tokens";
|
|
538
|
+
function B(s = R) {
|
|
414
539
|
return {
|
|
415
540
|
getTokens() {
|
|
416
541
|
const e = localStorage.getItem(s);
|
|
@@ -434,10 +559,10 @@ export {
|
|
|
434
559
|
d as ForbiddenError,
|
|
435
560
|
c as LedewireError,
|
|
436
561
|
m as MemoryTokenStorage,
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
562
|
+
g as NotFoundError,
|
|
563
|
+
$ as PurchaseError,
|
|
564
|
+
C as init,
|
|
565
|
+
B as localStorageAdapter,
|
|
441
566
|
l as parseExpiresAt
|
|
442
567
|
};
|
|
443
568
|
//# sourceMappingURL=index.js.map
|