@ledewire/browser 0.7.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -13
- package/dist/index.d.ts +1267 -50
- package/dist/index.js +465 -691
- package/dist/index.js.map +1 -1
- package/dist/ledewire.min.js +2 -2
- package/dist/ledewire.min.js.map +1 -1
- package/llms.txt +116 -22
- package/package.json +9 -4
package/dist/index.js
CHANGED
|
@@ -1,705 +1,479 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function w(s) {
|
|
5
|
-
return atob(s);
|
|
1
|
+
//#region ../core/src/base64.ts
|
|
2
|
+
function e(e) {
|
|
3
|
+
return atob(e);
|
|
6
4
|
}
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
...typeof s.teaser == "string" && { teaser: w(s.teaser) }
|
|
14
|
-
};
|
|
5
|
+
function t(t) {
|
|
6
|
+
return {
|
|
7
|
+
...t,
|
|
8
|
+
...typeof t.content_body == "string" && { content_body: e(t.content_body) },
|
|
9
|
+
...typeof t.teaser == "string" && { teaser: e(t.teaser) }
|
|
10
|
+
};
|
|
15
11
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/typeof.js
|
|
14
|
+
function n(e) {
|
|
15
|
+
"@babel/helpers - typeof";
|
|
16
|
+
return n = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
17
|
+
return typeof e;
|
|
18
|
+
} : function(e) {
|
|
19
|
+
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
20
|
+
}, n(e);
|
|
25
21
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPrimitive.js
|
|
24
|
+
function r(e, t) {
|
|
25
|
+
if (n(e) != "object" || !e) return e;
|
|
26
|
+
var r = e[Symbol.toPrimitive];
|
|
27
|
+
if (r !== void 0) {
|
|
28
|
+
var i = r.call(e, t || "default");
|
|
29
|
+
if (n(i) != "object") return i;
|
|
30
|
+
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
31
|
+
}
|
|
32
|
+
return (t === "string" ? String : Number)(e);
|
|
30
33
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/toPropertyKey.js
|
|
36
|
+
function i(e) {
|
|
37
|
+
var t = r(e, "string");
|
|
38
|
+
return n(t) == "symbol" ? t : t + "";
|
|
35
39
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region \0@oxc-project+runtime@0.137.0/helpers/esm/defineProperty.js
|
|
42
|
+
function a(e, t, n) {
|
|
43
|
+
return (t = i(t)) in e ? Object.defineProperty(e, t, {
|
|
44
|
+
value: n,
|
|
45
|
+
enumerable: !0,
|
|
46
|
+
configurable: !0,
|
|
47
|
+
writable: !0
|
|
48
|
+
}) : e[t] = n, e;
|
|
40
49
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
headers: i,
|
|
116
|
-
...r !== void 0 && { body: JSON.stringify(r) }
|
|
117
|
-
});
|
|
118
|
-
if (a.status === 401 && !o) {
|
|
119
|
-
if (await this.onUnauthorized())
|
|
120
|
-
return this.request(e, t, r, !0);
|
|
121
|
-
throw new l("Session expired. Please re-authenticate.");
|
|
122
|
-
}
|
|
123
|
-
if (a.ok || await this.throwApiError(a), a.status !== 204)
|
|
124
|
-
return a.json();
|
|
125
|
-
}
|
|
126
|
-
async throwApiError(e) {
|
|
127
|
-
let t;
|
|
128
|
-
try {
|
|
129
|
-
t = await e.json();
|
|
130
|
-
} catch {
|
|
131
|
-
}
|
|
132
|
-
const r = t?.error.message ?? e.statusText, o = t?.error.code;
|
|
133
|
-
switch (e.status) {
|
|
134
|
-
case 401:
|
|
135
|
-
throw new l(r, o);
|
|
136
|
-
case 403:
|
|
137
|
-
throw new y(r, o);
|
|
138
|
-
case 404:
|
|
139
|
-
throw new T(r, o);
|
|
140
|
-
default:
|
|
141
|
-
throw new c(r, e.status, o);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
const A = 6e4;
|
|
146
|
-
class E {
|
|
147
|
-
constructor(e) {
|
|
148
|
-
n(this, "storage");
|
|
149
|
-
n(this, "refreshFn");
|
|
150
|
-
n(this, "onTokenRefreshed");
|
|
151
|
-
n(this, "onAuthExpired");
|
|
152
|
-
n(this, "refreshPromise", null);
|
|
153
|
-
this.storage = e.storage, this.refreshFn = e.refreshFn, this.onTokenRefreshed = e.onTokenRefreshed, this.onAuthExpired = e.onAuthExpired;
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Returns a valid access token, refreshing proactively if needed.
|
|
157
|
-
* Returns `null` if no tokens are stored (user not authenticated).
|
|
158
|
-
*/
|
|
159
|
-
async getAccessToken() {
|
|
160
|
-
const e = await this.storage.getTokens();
|
|
161
|
-
return e ? e.expiresAt - Date.now() < A ? (await this.performRefresh(e.refreshToken))?.accessToken ?? null : e.accessToken : null;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Called by `HttpClient` when a 401 is received.
|
|
165
|
-
* Attempts one refresh; returns the new access token or null.
|
|
166
|
-
*/
|
|
167
|
-
async handleUnauthorized() {
|
|
168
|
-
const e = await this.storage.getTokens();
|
|
169
|
-
if (!e)
|
|
170
|
-
return await this.onAuthExpired?.(), null;
|
|
171
|
-
const t = await this.performRefresh(e.refreshToken);
|
|
172
|
-
return t || await this.onAuthExpired?.(), t?.accessToken ?? null;
|
|
173
|
-
}
|
|
174
|
-
/** Store new tokens after a successful login or signup. */
|
|
175
|
-
async setTokens(e) {
|
|
176
|
-
await this.storage.setTokens(e);
|
|
177
|
-
}
|
|
178
|
-
/** Clear all stored tokens (call on logout). */
|
|
179
|
-
async clearTokens() {
|
|
180
|
-
await this.storage.clearTokens();
|
|
181
|
-
}
|
|
182
|
-
// ---------------------------------------------------------------------------
|
|
183
|
-
// Private
|
|
184
|
-
// ---------------------------------------------------------------------------
|
|
185
|
-
performRefresh(e) {
|
|
186
|
-
return this.refreshPromise ? this.refreshPromise : (this.refreshPromise = this.refreshFn(e).then(async (t) => (await this.storage.setTokens(t), await this.onTokenRefreshed?.(t), t)).catch((t) => {
|
|
187
|
-
throw this.storage.clearTokens(), new l("Token refresh failed. Please re-authenticate.");
|
|
188
|
-
}).finally(() => {
|
|
189
|
-
this.refreshPromise = null;
|
|
190
|
-
}), this.refreshPromise);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
class U {
|
|
194
|
-
constructor() {
|
|
195
|
-
n(this, "tokens", null);
|
|
196
|
-
}
|
|
197
|
-
getTokens() {
|
|
198
|
-
return this.tokens;
|
|
199
|
-
}
|
|
200
|
-
setTokens(e) {
|
|
201
|
-
this.tokens = e;
|
|
202
|
-
}
|
|
203
|
-
clearTokens() {
|
|
204
|
-
this.tokens = null;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
function p(s) {
|
|
208
|
-
return new Date(s).getTime();
|
|
209
|
-
}
|
|
210
|
-
function v(s) {
|
|
211
|
-
return async (e) => {
|
|
212
|
-
const t = await fetch(`${s}/v1/auth/token/refresh`, {
|
|
213
|
-
method: "POST",
|
|
214
|
-
headers: { "Content-Type": "application/json" },
|
|
215
|
-
body: JSON.stringify({ refresh_token: e })
|
|
216
|
-
});
|
|
217
|
-
if (!t.ok) throw new Error("Token refresh failed");
|
|
218
|
-
const r = await t.json();
|
|
219
|
-
return {
|
|
220
|
-
accessToken: r.access_token,
|
|
221
|
-
refreshToken: r.refresh_token,
|
|
222
|
-
expiresAt: p(r.expires_at)
|
|
223
|
-
};
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
class x {
|
|
227
|
-
/** @internal */
|
|
228
|
-
constructor(e, t) {
|
|
229
|
-
this.http = e, this.tokenManager = t;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* Register a new buyer account with email and password.
|
|
233
|
-
* Tokens are stored automatically after successful signup.
|
|
234
|
-
*
|
|
235
|
-
* @param body - Signup credentials and display name.
|
|
236
|
-
* @returns The authentication token response.
|
|
237
|
-
*/
|
|
238
|
-
async signup(e) {
|
|
239
|
-
const t = await this.http.post("/v1/auth/signup", e);
|
|
240
|
-
return await this.storeTokens(t), t;
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Log in with email and password.
|
|
244
|
-
* Tokens are stored automatically after successful login.
|
|
245
|
-
*
|
|
246
|
-
* @param body - Email and password credentials.
|
|
247
|
-
* @returns The authentication token response.
|
|
248
|
-
*/
|
|
249
|
-
async loginWithEmail(e) {
|
|
250
|
-
const t = await this.http.post("/v1/auth/login/email", e);
|
|
251
|
-
return await this.storeTokens(t), t;
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Log in with a Google ID token obtained from the Google OAuth flow.
|
|
255
|
-
* Tokens are stored automatically after successful login.
|
|
256
|
-
*
|
|
257
|
-
* @param body - The Google ID token.
|
|
258
|
-
* @returns The authentication token response.
|
|
259
|
-
*/
|
|
260
|
-
async loginWithGoogle(e) {
|
|
261
|
-
const t = await this.http.post("/v1/auth/login/google", e);
|
|
262
|
-
return await this.storeTokens(t), t;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Log in using a buyer API key and secret.
|
|
266
|
-
* Returns a buyer-scoped JWT, stored automatically after successful authentication.
|
|
267
|
-
*
|
|
268
|
-
* Primarily useful when building buyer-facing dashboards where the user
|
|
269
|
-
* has created a named API key and wishes to authenticate with it programmatically,
|
|
270
|
-
* or for agent workflows running inside a browser context.
|
|
271
|
-
*
|
|
272
|
-
* @param body - The buyer API key and secret.
|
|
273
|
-
* @returns The authentication token response.
|
|
274
|
-
*
|
|
275
|
-
* @example
|
|
276
|
-
* ```ts
|
|
277
|
-
* await lw.auth.loginWithBuyerApiKey({
|
|
278
|
-
* key: 'bktst_abc123',
|
|
279
|
-
* secret: 'deadbeef...',
|
|
280
|
-
* })
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
async loginWithBuyerApiKey(e) {
|
|
284
|
-
const t = await this.http.post("/v1/auth/login/buyer-api-key", e);
|
|
285
|
-
return await this.storeTokens(t), t;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Request a password reset code to be sent to the buyer's email address.
|
|
289
|
-
*
|
|
290
|
-
* The response is intentionally ambiguous — if the email does not exist,
|
|
291
|
-
* the API returns the same success message to prevent account enumeration.
|
|
292
|
-
*
|
|
293
|
-
* @param body - The buyer's email address.
|
|
294
|
-
* @returns A response with a confirmation message.
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```ts
|
|
298
|
-
* await lw.auth.requestPasswordReset({ email: 'buyer@example.com' })
|
|
299
|
-
* // → { data: { message: 'If an account with this email exists, a reset code has been sent.' } }
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
async requestPasswordReset(e) {
|
|
303
|
-
return this.http.post("/v1/auth/password/reset-request", e);
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* Reset a buyer's password using the code delivered to their email.
|
|
307
|
-
*
|
|
308
|
-
* Obtain the reset code first by calling `requestPasswordReset()`.
|
|
309
|
-
*
|
|
310
|
-
* @param body - Email address, 6-digit reset code, and the new password.
|
|
311
|
-
* @returns A response with a confirmation message.
|
|
312
|
-
*
|
|
313
|
-
* @example
|
|
314
|
-
* ```ts
|
|
315
|
-
* await lw.auth.resetPassword({
|
|
316
|
-
* email: 'buyer@example.com',
|
|
317
|
-
* reset_code: '123456',
|
|
318
|
-
* password: 'new-secure-password',
|
|
319
|
-
* })
|
|
320
|
-
* ```
|
|
321
|
-
*/
|
|
322
|
-
async resetPassword(e) {
|
|
323
|
-
return this.http.post("/v1/auth/password/reset", e);
|
|
324
|
-
}
|
|
325
|
-
async storeTokens(e) {
|
|
326
|
-
await this.tokenManager.setTokens({
|
|
327
|
-
accessToken: e.access_token,
|
|
328
|
-
refreshToken: e.refresh_token,
|
|
329
|
-
expiresAt: p(e.expires_at)
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
class b {
|
|
334
|
-
/** @internal */
|
|
335
|
-
constructor(e) {
|
|
336
|
-
this.http = e;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* Returns platform-level public configuration.
|
|
340
|
-
* No authentication required — safe to call before the user has signed in.
|
|
341
|
-
*
|
|
342
|
-
* Use `google_client_id` to initialise the Google Identity Services library
|
|
343
|
-
* on the storefront login page without requiring a prior authenticated call.
|
|
344
|
-
*
|
|
345
|
-
* @example
|
|
346
|
-
* ```ts
|
|
347
|
-
* const lw = init({ apiKey: 'your_api_key' })
|
|
348
|
-
* const { google_client_id } = await lw.config.getPublic()
|
|
349
|
-
* google.accounts.id.initialize({ client_id: google_client_id, callback })
|
|
350
|
-
* ```
|
|
351
|
-
*/
|
|
352
|
-
async getPublic() {
|
|
353
|
-
return this.http.get("/v1/config/public");
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
class S {
|
|
357
|
-
constructor(e) {
|
|
358
|
-
this.http = e;
|
|
359
|
-
}
|
|
360
|
-
/**
|
|
361
|
-
* Returns a content item together with access information for the
|
|
362
|
-
* authenticated buyer (or a generic access response when unauthenticated).
|
|
363
|
-
*
|
|
364
|
-
* @param id - The content ID.
|
|
365
|
-
* @returns The content item with access information. `content_body` and
|
|
366
|
-
* `teaser` are returned as plain UTF-8 text — the SDK decodes base64
|
|
367
|
-
* transparently so you can render them directly.
|
|
368
|
-
*
|
|
369
|
-
* @example
|
|
370
|
-
* ```ts
|
|
371
|
-
* const result = await lw.content.getWithAccess('article-123')
|
|
372
|
-
* if (result.access_info.next_required_action === 'view_content') {
|
|
373
|
-
* renderMarkdown(result.content_body ?? '')
|
|
374
|
-
* }
|
|
375
|
-
* ```
|
|
376
|
-
*/
|
|
377
|
-
async getWithAccess(e) {
|
|
378
|
-
const t = await this.http.get(
|
|
379
|
-
`/v1/content/${encodeURIComponent(e)}/with-access`
|
|
380
|
-
);
|
|
381
|
-
return u(t);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
class P {
|
|
385
|
-
constructor(e) {
|
|
386
|
-
this.http = e;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Completes a content purchase using the buyer's wallet balance.
|
|
390
|
-
*
|
|
391
|
-
* @param body - The content ID and expected price in cents.
|
|
392
|
-
* @returns The completed purchase record.
|
|
393
|
-
*/
|
|
394
|
-
async create(e) {
|
|
395
|
-
return this.http.post("/v1/purchases", e);
|
|
396
|
-
}
|
|
397
|
-
/**
|
|
398
|
-
* Returns all purchases made by the authenticated buyer.
|
|
399
|
-
*
|
|
400
|
-
* @returns A list of purchase records, newest first.
|
|
401
|
-
*/
|
|
402
|
-
async list() {
|
|
403
|
-
return this.http.get("/v1/purchases");
|
|
404
|
-
}
|
|
405
|
-
/**
|
|
406
|
-
* Returns a single purchase by ID.
|
|
407
|
-
*
|
|
408
|
-
* @param id - The purchase ID.
|
|
409
|
-
* @returns The purchase record.
|
|
410
|
-
*/
|
|
411
|
-
async get(e) {
|
|
412
|
-
return this.http.get(`/v1/purchases/${encodeURIComponent(e)}`);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
class R {
|
|
416
|
-
/** @internal */
|
|
417
|
-
constructor(e) {
|
|
418
|
-
this.http = e;
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* List all content for the authenticated seller's store.
|
|
422
|
-
* Requires a token with at least `view` permission.
|
|
423
|
-
*
|
|
424
|
-
* @returns Array of content items. `teaser` is returned as plain text —
|
|
425
|
-
* the SDK decodes base64 automatically.
|
|
426
|
-
*
|
|
427
|
-
* @example
|
|
428
|
-
* ```ts
|
|
429
|
-
* const items = await lw.seller.content.list()
|
|
430
|
-
* ```
|
|
431
|
-
*/
|
|
432
|
-
async list() {
|
|
433
|
-
return (await this.http.get("/v1/seller/content")).map(u);
|
|
434
|
-
}
|
|
435
|
-
/**
|
|
436
|
-
* Search content by title, URI, and/or metadata (AND logic).
|
|
437
|
-
* At least one criterion must be supplied.
|
|
438
|
-
* Requires a token with at least `view` permission.
|
|
439
|
-
*
|
|
440
|
-
* @param body - Search criteria (title, uri, and/or metadata).
|
|
441
|
-
* @returns Array of matching content items. `teaser` is returned as plain
|
|
442
|
-
* text — the SDK decodes base64 automatically.
|
|
443
|
-
*
|
|
444
|
-
* @example
|
|
445
|
-
* ```ts
|
|
446
|
-
* const results = await lw.seller.content.search({ title: 'intro' })
|
|
447
|
-
* const byUri = await lw.seller.content.search({ uri: 'vimeo.com' })
|
|
448
|
-
* const byId = await lw.seller.content.search({ external_identifier: 'vimeo:123456789' })
|
|
449
|
-
* const byMeta = await lw.seller.content.search({ metadata: { author: 'Alice' } })
|
|
450
|
-
* ```
|
|
451
|
-
*/
|
|
452
|
-
async search(e) {
|
|
453
|
-
return (await this.http.post("/v1/seller/content/search", e)).map(u);
|
|
454
|
-
}
|
|
455
|
-
/**
|
|
456
|
-
* Get a single content item by ID.
|
|
457
|
-
* Requires a token with at least `view` permission.
|
|
458
|
-
*
|
|
459
|
-
* @param id - The content ID.
|
|
460
|
-
* @returns The content item. `content_body` and `teaser` are returned as
|
|
461
|
-
* plain UTF-8 text — the SDK decodes base64 automatically so you can render
|
|
462
|
-
* them directly without calling `atob()`.
|
|
463
|
-
*
|
|
464
|
-
* @example
|
|
465
|
-
* ```ts
|
|
466
|
-
* const item = await lw.seller.content.get('content-id')
|
|
467
|
-
* // item.content_body is plain markdown — no atob() needed
|
|
468
|
-
* ```
|
|
469
|
-
*/
|
|
470
|
-
async get(e) {
|
|
471
|
-
const t = await this.http.get(`/v1/seller/content/${encodeURIComponent(e)}`);
|
|
472
|
-
return u(t);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
class C {
|
|
476
|
-
/** @internal */
|
|
477
|
-
constructor(e, t) {
|
|
478
|
-
/** Seller content: list, search, and get by API key. */
|
|
479
|
-
n(this, "content");
|
|
480
|
-
this.http = e, this.tokenManager = t, this.content = new R(e);
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* Log in using an API key to obtain a seller token.
|
|
484
|
-
* Provide only `key` for read-only (`view`) access.
|
|
485
|
-
* Provide both `key` and `secret` for read/write (`full`) access.
|
|
486
|
-
* Tokens are stored automatically after successful authentication.
|
|
487
|
-
*
|
|
488
|
-
* Use this before calling `lw.seller.content.*` methods.
|
|
489
|
-
*
|
|
490
|
-
* @param body - API key credentials.
|
|
491
|
-
* @returns The authentication token response.
|
|
492
|
-
*
|
|
493
|
-
* @example
|
|
494
|
-
* ```ts
|
|
495
|
-
* // View access (read-only) — sufficient for seller.content.list/search/get
|
|
496
|
-
* await lw.seller.loginWithApiKey({ key: 'your_api_key' })
|
|
497
|
-
*
|
|
498
|
-
* // Full access (read/write)
|
|
499
|
-
* await lw.seller.loginWithApiKey({ key: 'your_api_key', secret: 'your_secret' })
|
|
500
|
-
* ```
|
|
501
|
-
*/
|
|
502
|
-
async loginWithApiKey(e) {
|
|
503
|
-
const t = await this.http.post("/v1/auth/login/api-key", e);
|
|
504
|
-
return await this.tokenManager.setTokens({
|
|
505
|
-
accessToken: t.access_token,
|
|
506
|
-
refreshToken: t.refresh_token,
|
|
507
|
-
expiresAt: p(t.expires_at)
|
|
508
|
-
}), t;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
class N {
|
|
512
|
-
constructor(e) {
|
|
513
|
-
this.http = e;
|
|
514
|
-
}
|
|
515
|
-
/**
|
|
516
|
-
* Returns the authenticated buyer's current wallet balance.
|
|
517
|
-
*
|
|
518
|
-
* @returns The current wallet balance in cents.
|
|
519
|
-
*/
|
|
520
|
-
async balance() {
|
|
521
|
-
return this.http.get("/v1/wallet/balance");
|
|
522
|
-
}
|
|
523
|
-
/**
|
|
524
|
-
* Returns the authenticated buyer's wallet transaction history, newest first.
|
|
525
|
-
*
|
|
526
|
-
* @returns A list of completed wallet transaction entries.
|
|
527
|
-
*/
|
|
528
|
-
async transactions() {
|
|
529
|
-
return this.http.get("/v1/wallet/transactions");
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
* Creates a payment session for funding the buyer's wallet.
|
|
533
|
-
*
|
|
534
|
-
* @param body - The amount and currency to fund.
|
|
535
|
-
* @returns Payment session details for use with the payment provider widget.
|
|
536
|
-
*/
|
|
537
|
-
async createPaymentSession(e) {
|
|
538
|
-
return this.http.post("/v1/wallet/payment-session", e);
|
|
539
|
-
}
|
|
540
|
-
/**
|
|
541
|
-
* Polls the status of a wallet funding payment session.
|
|
542
|
-
*
|
|
543
|
-
* @param sessionId - The session ID returned by `createPaymentSession`.
|
|
544
|
-
* @returns The current payment status.
|
|
545
|
-
*/
|
|
546
|
-
async getPaymentStatus(e) {
|
|
547
|
-
return this.http.get(
|
|
548
|
-
`/v1/wallet/payment-status/${encodeURIComponent(e)}`
|
|
549
|
-
);
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
class F {
|
|
553
|
-
constructor(e) {
|
|
554
|
-
this.http = e;
|
|
555
|
-
}
|
|
556
|
-
/**
|
|
557
|
-
* Returns the authenticated buyer's checkout readiness for a given piece of
|
|
558
|
-
* content. Indicates whether the buyer needs to authenticate, fund their
|
|
559
|
-
* wallet, or purchase before accessing the content.
|
|
560
|
-
*
|
|
561
|
-
* Works without authentication — returns anonymous checkout state when the
|
|
562
|
-
* buyer is not logged in.
|
|
563
|
-
*
|
|
564
|
-
* @param contentId - The content item ID.
|
|
565
|
-
* @returns The checkout state, including what action is required next.
|
|
566
|
-
*/
|
|
567
|
-
async state(e) {
|
|
568
|
-
return this.http.get(
|
|
569
|
-
`/v1/checkout/state/${encodeURIComponent(e)}`
|
|
570
|
-
);
|
|
571
|
-
}
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region ../core/src/errors.ts
|
|
52
|
+
var o, s = Symbol.for("@ledewire/error-brands");
|
|
53
|
+
o = Symbol.hasInstance;
|
|
54
|
+
var c = class extends Error {
|
|
55
|
+
constructor(e, t, n, r, i) {
|
|
56
|
+
super(e), a(this, "statusCode", void 0), a(this, "code", void 0), a(this, "type", void 0), a(this, "details", void 0), this.name = "LedewireError", this.statusCode = t, this.code = n, this.type = r, this.details = i, Object.setPrototypeOf(this, new.target.prototype);
|
|
57
|
+
let o = [], c = new.target;
|
|
58
|
+
for (; typeof c == "function";) {
|
|
59
|
+
let e = c.brand;
|
|
60
|
+
typeof e == "string" && Object.prototype.hasOwnProperty.call(c, "brand") && o.push(e), c = Object.getPrototypeOf(c);
|
|
61
|
+
}
|
|
62
|
+
Object.defineProperty(this, s, {
|
|
63
|
+
value: o,
|
|
64
|
+
enumerable: !1,
|
|
65
|
+
configurable: !0
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
static [o](e) {
|
|
69
|
+
if (Function.prototype[Symbol.hasInstance].call(this, e)) return !0;
|
|
70
|
+
if (!e || typeof e != "object" && typeof e != "function") return !1;
|
|
71
|
+
let t = e[s];
|
|
72
|
+
return Array.isArray(t) && t.includes(this.brand);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
a(c, "brand", "LedewireError");
|
|
76
|
+
var l = class extends c {
|
|
77
|
+
constructor(e, t, n, r) {
|
|
78
|
+
super(e, 401, t, n, r), this.name = "AuthError";
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
a(l, "brand", "AuthError");
|
|
82
|
+
var u = class extends c {
|
|
83
|
+
constructor(e, t, n, r) {
|
|
84
|
+
super(e, 403, t, n, r), this.name = "ForbiddenError";
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
a(u, "brand", "ForbiddenError");
|
|
88
|
+
var d = class extends c {
|
|
89
|
+
constructor(e, t, n, r) {
|
|
90
|
+
super(e, 404, t, n, r), this.name = "NotFoundError";
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
a(d, "brand", "NotFoundError");
|
|
94
|
+
var f = class extends c {
|
|
95
|
+
constructor(e, t, n, r, i) {
|
|
96
|
+
super(e, t, n, r, i), this.name = "PurchaseError";
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
a(f, "brand", "PurchaseError");
|
|
100
|
+
var p = class extends c {
|
|
101
|
+
constructor(e, t, n) {
|
|
102
|
+
super(e, 402, n, "daily_spend_cap_reached"), a(this, "capCents", void 0), a(this, "spentCents", void 0), a(this, "remainingCents", void 0), a(this, "resetsAt", void 0), a(this, "bulkExempt", void 0), this.name = "SpendCapReachedError", this.capCents = t.capCents, this.spentCents = t.spentCents, this.remainingCents = t.remainingCents, this.resetsAt = t.resetsAt, this.bulkExempt = t.bulkExempt, Object.setPrototypeOf(this, new.target.prototype);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
a(p, "brand", "SpendCapReachedError");
|
|
106
|
+
//#endregion
|
|
107
|
+
//#region ../core/src/spend-cap.ts
|
|
108
|
+
function m(e) {
|
|
109
|
+
if (!e || typeof e != "object") return null;
|
|
110
|
+
let t = e, n = t.error;
|
|
111
|
+
if (!n || typeof n != "object") return null;
|
|
112
|
+
let r = n;
|
|
113
|
+
if (r.type !== "daily_spend_cap_reached") return null;
|
|
114
|
+
let i = t.cap_cents, a = t.spent_cents, o = t.remaining_cents, s = t.resets_at, c = t.bulk_exempt;
|
|
115
|
+
if (typeof i != "number" || typeof a != "number" || typeof o != "number" || typeof s != "string" || typeof c != "boolean") return null;
|
|
116
|
+
let l = typeof r.message == "string" ? r.message : "Daily spend cap reached.", u = typeof r.code == "number" ? r.code : void 0;
|
|
117
|
+
return new p(l, {
|
|
118
|
+
capCents: i,
|
|
119
|
+
spentCents: a,
|
|
120
|
+
remainingCents: o,
|
|
121
|
+
resetsAt: s,
|
|
122
|
+
bulkExempt: c
|
|
123
|
+
}, u);
|
|
572
124
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
* name: 'production-agent',
|
|
601
|
-
* spending_limit_cents: 5000, // $50 cap
|
|
602
|
-
* })
|
|
603
|
-
* // ⚠️ Store secret NOW — it is shown once only
|
|
604
|
-
* process.env.LEDEWIRE_BUYER_SECRET = secret
|
|
605
|
-
* ```
|
|
606
|
-
*/
|
|
607
|
-
async create(e) {
|
|
608
|
-
return this.http.post("/v1/user/api-keys", e);
|
|
609
|
-
}
|
|
610
|
-
/**
|
|
611
|
-
* Revokes (permanently deletes) a buyer API key by ID.
|
|
612
|
-
*
|
|
613
|
-
* Any agent currently using this key will receive `401` on its next
|
|
614
|
-
* token refresh. Revocation takes effect immediately.
|
|
615
|
-
*
|
|
616
|
-
* @param id - UUID of the API key to revoke.
|
|
617
|
-
*/
|
|
618
|
-
async revoke(e) {
|
|
619
|
-
return this.http.delete(`/v1/user/api-keys/${encodeURIComponent(e)}`);
|
|
620
|
-
}
|
|
125
|
+
function h(e, t) {
|
|
126
|
+
if (!e || typeof e != "object" || Array.isArray(e)) return {
|
|
127
|
+
message: t,
|
|
128
|
+
code: void 0,
|
|
129
|
+
type: void 0,
|
|
130
|
+
details: void 0
|
|
131
|
+
};
|
|
132
|
+
let { error: n, ...r } = e, i = Object.keys(r).length > 0 ? r : void 0;
|
|
133
|
+
if (typeof n == "string") return {
|
|
134
|
+
message: n,
|
|
135
|
+
code: void 0,
|
|
136
|
+
type: void 0,
|
|
137
|
+
details: i
|
|
138
|
+
};
|
|
139
|
+
if (!n || typeof n != "object" || Array.isArray(n)) return {
|
|
140
|
+
message: t,
|
|
141
|
+
code: void 0,
|
|
142
|
+
type: void 0,
|
|
143
|
+
details: i
|
|
144
|
+
};
|
|
145
|
+
let a = n;
|
|
146
|
+
return {
|
|
147
|
+
message: typeof a.message == "string" ? a.message : t,
|
|
148
|
+
code: typeof a.code == "number" ? a.code : void 0,
|
|
149
|
+
type: typeof a.type == "string" ? a.type : void 0,
|
|
150
|
+
details: i
|
|
151
|
+
};
|
|
621
152
|
}
|
|
622
|
-
class
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
153
|
+
var g = class {
|
|
154
|
+
constructor(e = {}) {
|
|
155
|
+
a(this, "baseUrl", void 0), a(this, "getAccessToken", void 0), a(this, "onUnauthorized", void 0), this.baseUrl = (e.baseUrl ?? "https://api.ledewire.com").replace(/\/$/, ""), this.getAccessToken = e.getAccessToken ?? (() => null), this.onUnauthorized = e.onUnauthorized ?? (() => null);
|
|
156
|
+
}
|
|
157
|
+
async get(e, t, n) {
|
|
158
|
+
return this.request("GET", this.buildUrl(e, t), void 0, n);
|
|
159
|
+
}
|
|
160
|
+
async post(e, t, n) {
|
|
161
|
+
return this.request("POST", this.buildUrl(e, n), t);
|
|
162
|
+
}
|
|
163
|
+
async put(e, t) {
|
|
164
|
+
return this.request("PUT", this.buildUrl(e), t);
|
|
165
|
+
}
|
|
166
|
+
async patch(e, t) {
|
|
167
|
+
return this.request("PATCH", this.buildUrl(e), t);
|
|
168
|
+
}
|
|
169
|
+
async delete(e) {
|
|
170
|
+
return this.request("DELETE", this.buildUrl(e));
|
|
171
|
+
}
|
|
172
|
+
async getRaw(e) {
|
|
173
|
+
return this.performRequest("GET", this.buildUrl(e), { Accept: "application/gzip, application/json" });
|
|
174
|
+
}
|
|
175
|
+
buildUrl(e, t) {
|
|
176
|
+
let n = `${this.baseUrl}${e}`;
|
|
177
|
+
if (!t) return n;
|
|
178
|
+
let r = Object.entries(t).filter((e) => e[1] !== void 0);
|
|
179
|
+
return r.length === 0 ? n : `${n}?${new URLSearchParams(r.map(([e, t]) => [e, String(t)])).toString()}`;
|
|
180
|
+
}
|
|
181
|
+
async request(e, t, n, r) {
|
|
182
|
+
let i = await this.performRequest(e, t, {
|
|
183
|
+
"Content-Type": "application/json",
|
|
184
|
+
Accept: "application/json"
|
|
185
|
+
}, n, !1, r);
|
|
186
|
+
if (i.status !== 204) return i.json();
|
|
187
|
+
}
|
|
188
|
+
async performRequest(e, t, n, r, i = !1, a) {
|
|
189
|
+
let o = a?.auth !== !1, s = o ? await this.getAccessToken() : null, c = { ...n };
|
|
190
|
+
s && (c.Authorization = `Bearer ${s}`);
|
|
191
|
+
let u = await fetch(t, {
|
|
192
|
+
method: e,
|
|
193
|
+
headers: c,
|
|
194
|
+
...r !== void 0 && { body: JSON.stringify(r) }
|
|
195
|
+
});
|
|
196
|
+
if (u.status === 401 && !i) {
|
|
197
|
+
if (o && await this.onUnauthorized()) return this.performRequest(e, t, n, r, !0, a);
|
|
198
|
+
throw new l("Session expired. Please re-authenticate.");
|
|
199
|
+
}
|
|
200
|
+
return u.ok || await this.throwApiError(u), u;
|
|
201
|
+
}
|
|
202
|
+
async throwApiError(e) {
|
|
203
|
+
let t;
|
|
204
|
+
try {
|
|
205
|
+
t = await e.json();
|
|
206
|
+
} catch {}
|
|
207
|
+
let n = m(t);
|
|
208
|
+
if (n) throw n;
|
|
209
|
+
let { message: r, code: i, type: a, details: o } = h(t, e.statusText);
|
|
210
|
+
switch (e.status) {
|
|
211
|
+
case 401: throw new l(r, i, a, o);
|
|
212
|
+
case 403: throw new u(r, i, a, o);
|
|
213
|
+
case 404: throw new d(r, i, a, o);
|
|
214
|
+
default: throw new c(r, e.status, i, a, o);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}, _ = 6e4, v = class {
|
|
218
|
+
constructor(e) {
|
|
219
|
+
a(this, "storage", void 0), a(this, "refreshFn", void 0), a(this, "onTokenRefreshed", void 0), a(this, "onAuthExpired", void 0), a(this, "refreshPromise", null), this.storage = e.storage, this.refreshFn = e.refreshFn, this.onTokenRefreshed = e.onTokenRefreshed, this.onAuthExpired = e.onAuthExpired;
|
|
220
|
+
}
|
|
221
|
+
async getAccessToken() {
|
|
222
|
+
let e = await this.storage.getTokens();
|
|
223
|
+
return e ? e.expiresAt - Date.now() < _ ? (await this.performRefresh(e.refreshToken))?.accessToken ?? null : e.accessToken : null;
|
|
224
|
+
}
|
|
225
|
+
async handleUnauthorized() {
|
|
226
|
+
let e = await this.storage.getTokens();
|
|
227
|
+
if (!e) return await this.onAuthExpired?.(), null;
|
|
228
|
+
let t = await this.performRefresh(e.refreshToken);
|
|
229
|
+
return t || await this.onAuthExpired?.(), t?.accessToken ?? null;
|
|
230
|
+
}
|
|
231
|
+
async setTokens(e) {
|
|
232
|
+
await this.storage.setTokens(e);
|
|
233
|
+
}
|
|
234
|
+
async clearTokens() {
|
|
235
|
+
await this.storage.clearTokens();
|
|
236
|
+
}
|
|
237
|
+
performRefresh(e) {
|
|
238
|
+
return this.refreshPromise || (this.refreshPromise = this.refreshFn(e).then(async (e) => (await this.storage.setTokens(e), await this.onTokenRefreshed?.(e), e)).catch((e) => {
|
|
239
|
+
throw this.storage.clearTokens(), new l("Token refresh failed. Please re-authenticate.");
|
|
240
|
+
}).finally(() => {
|
|
241
|
+
this.refreshPromise = null;
|
|
242
|
+
})), this.refreshPromise;
|
|
243
|
+
}
|
|
244
|
+
}, y = class {
|
|
245
|
+
constructor() {
|
|
246
|
+
a(this, "tokens", null);
|
|
247
|
+
}
|
|
248
|
+
getTokens() {
|
|
249
|
+
return this.tokens;
|
|
250
|
+
}
|
|
251
|
+
setTokens(e) {
|
|
252
|
+
this.tokens = e;
|
|
253
|
+
}
|
|
254
|
+
clearTokens() {
|
|
255
|
+
this.tokens = null;
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
function b(e) {
|
|
259
|
+
return new Date(e).getTime();
|
|
632
260
|
}
|
|
633
|
-
function
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
261
|
+
function x(e) {
|
|
262
|
+
return async (t) => {
|
|
263
|
+
let n = await fetch(`${e}/v1/auth/token/refresh`, {
|
|
264
|
+
method: "POST",
|
|
265
|
+
headers: { "Content-Type": "application/json" },
|
|
266
|
+
body: JSON.stringify({ refresh_token: t })
|
|
267
|
+
});
|
|
268
|
+
if (!n.ok) throw Error("Token refresh failed");
|
|
269
|
+
let r = await n.json();
|
|
270
|
+
return {
|
|
271
|
+
accessToken: r.access_token,
|
|
272
|
+
refreshToken: r.refresh_token,
|
|
273
|
+
expiresAt: b(r.expires_at)
|
|
274
|
+
};
|
|
275
|
+
};
|
|
644
276
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
277
|
+
//#endregion
|
|
278
|
+
//#region src/resources/auth.ts
|
|
279
|
+
var S = class {
|
|
280
|
+
constructor(e, t) {
|
|
281
|
+
a(this, "http", void 0), a(this, "tokenManager", void 0), this.http = e, this.tokenManager = t;
|
|
282
|
+
}
|
|
283
|
+
async signup(e) {
|
|
284
|
+
let t = await this.http.post("/v1/auth/signup", e);
|
|
285
|
+
return await this.storeTokens(t), t;
|
|
286
|
+
}
|
|
287
|
+
async loginWithEmail(e) {
|
|
288
|
+
let t = await this.http.post("/v1/auth/login/email", e);
|
|
289
|
+
return await this.storeTokens(t), t;
|
|
290
|
+
}
|
|
291
|
+
async loginWithGoogle(e) {
|
|
292
|
+
let t = await this.http.post("/v1/auth/login/google", e);
|
|
293
|
+
return await this.storeTokens(t), t;
|
|
294
|
+
}
|
|
295
|
+
async loginWithBuyerApiKey(e) {
|
|
296
|
+
let t = await this.http.post("/v1/auth/login/buyer-api-key", e);
|
|
297
|
+
return await this.storeTokens(t), t;
|
|
298
|
+
}
|
|
299
|
+
async requestPasswordReset(e) {
|
|
300
|
+
return this.http.post("/v1/auth/password/reset-request", e);
|
|
301
|
+
}
|
|
302
|
+
async resetPassword(e) {
|
|
303
|
+
return this.http.post("/v1/auth/password/reset", e);
|
|
304
|
+
}
|
|
305
|
+
async storeTokens(e) {
|
|
306
|
+
await this.tokenManager.setTokens({
|
|
307
|
+
accessToken: e.access_token,
|
|
308
|
+
refreshToken: e.refresh_token,
|
|
309
|
+
expiresAt: b(e.expires_at)
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}, C = class {
|
|
313
|
+
constructor(e) {
|
|
314
|
+
a(this, "http", void 0), this.http = e;
|
|
315
|
+
}
|
|
316
|
+
async getPublic() {
|
|
317
|
+
return this.http.get("/v1/config/public");
|
|
318
|
+
}
|
|
319
|
+
}, w = class {
|
|
320
|
+
constructor(e) {
|
|
321
|
+
a(this, "http", void 0), this.http = e;
|
|
322
|
+
}
|
|
323
|
+
async getWithAccess(e) {
|
|
324
|
+
return t(await this.http.get(`/v1/content/${encodeURIComponent(e)}/with-access`));
|
|
325
|
+
}
|
|
326
|
+
}, T = class {
|
|
327
|
+
constructor(e) {
|
|
328
|
+
a(this, "http", void 0), this.http = e;
|
|
329
|
+
}
|
|
330
|
+
async create(e) {
|
|
331
|
+
return this.http.post("/v1/purchases", e);
|
|
332
|
+
}
|
|
333
|
+
async list() {
|
|
334
|
+
return this.http.get("/v1/purchases");
|
|
335
|
+
}
|
|
336
|
+
async get(e) {
|
|
337
|
+
return this.http.get(`/v1/purchases/${encodeURIComponent(e)}`);
|
|
338
|
+
}
|
|
339
|
+
}, E = class {
|
|
340
|
+
constructor(e) {
|
|
341
|
+
a(this, "http", void 0), this.http = e;
|
|
342
|
+
}
|
|
343
|
+
async list() {
|
|
344
|
+
return (await this.http.get("/v1/seller/content")).map(t);
|
|
345
|
+
}
|
|
346
|
+
async search(e) {
|
|
347
|
+
return (await this.http.post("/v1/seller/content/search", e)).map(t);
|
|
348
|
+
}
|
|
349
|
+
async get(e) {
|
|
350
|
+
return t(await this.http.get(`/v1/seller/content/${encodeURIComponent(e)}`));
|
|
351
|
+
}
|
|
352
|
+
}, D = class {
|
|
353
|
+
constructor(e, t) {
|
|
354
|
+
a(this, "http", void 0), a(this, "tokenManager", void 0), a(this, "content", void 0), this.http = e, this.tokenManager = t, this.content = new E(e);
|
|
355
|
+
}
|
|
356
|
+
async loginWithApiKey(e) {
|
|
357
|
+
let t = await this.http.post("/v1/auth/login/api-key", e);
|
|
358
|
+
return await this.tokenManager.setTokens({
|
|
359
|
+
accessToken: t.access_token,
|
|
360
|
+
refreshToken: t.refresh_token,
|
|
361
|
+
expiresAt: b(t.expires_at)
|
|
362
|
+
}), t;
|
|
363
|
+
}
|
|
364
|
+
}, O = class {
|
|
365
|
+
constructor(e) {
|
|
366
|
+
a(this, "http", void 0), this.http = e;
|
|
367
|
+
}
|
|
368
|
+
async balance() {
|
|
369
|
+
return this.http.get("/v1/wallet/balance");
|
|
370
|
+
}
|
|
371
|
+
async transactions() {
|
|
372
|
+
return this.http.get("/v1/wallet/transactions");
|
|
373
|
+
}
|
|
374
|
+
async createPaymentSession(e) {
|
|
375
|
+
return this.http.post("/v1/wallet/payment-session", e);
|
|
376
|
+
}
|
|
377
|
+
async getPaymentStatus(e) {
|
|
378
|
+
return this.http.get(`/v1/wallet/payment-status/${encodeURIComponent(e)}`);
|
|
379
|
+
}
|
|
380
|
+
}, k = class {
|
|
381
|
+
constructor(e) {
|
|
382
|
+
a(this, "http", void 0), this.http = e;
|
|
383
|
+
}
|
|
384
|
+
async state(e) {
|
|
385
|
+
return this.http.get(`/v1/checkout/state/${encodeURIComponent(e)}`);
|
|
386
|
+
}
|
|
387
|
+
}, A = class {
|
|
388
|
+
constructor(e) {
|
|
389
|
+
a(this, "http", void 0), this.http = e;
|
|
390
|
+
}
|
|
391
|
+
async list() {
|
|
392
|
+
return this.http.get("/v1/user/api-keys");
|
|
393
|
+
}
|
|
394
|
+
async create(e) {
|
|
395
|
+
return this.http.post("/v1/user/api-keys", e);
|
|
396
|
+
}
|
|
397
|
+
async revoke(e) {
|
|
398
|
+
return this.http.delete(`/v1/user/api-keys/${encodeURIComponent(e)}`);
|
|
399
|
+
}
|
|
400
|
+
}, j = class {
|
|
401
|
+
constructor(e) {
|
|
402
|
+
a(this, "http", void 0), this.http = e;
|
|
403
|
+
}
|
|
404
|
+
async get() {
|
|
405
|
+
return this.http.get("/v1/user/spend-cap");
|
|
406
|
+
}
|
|
407
|
+
async update(e) {
|
|
408
|
+
return this.http.patch("/v1/user/spend-cap", e);
|
|
409
|
+
}
|
|
410
|
+
}, M = class {
|
|
411
|
+
constructor(e) {
|
|
412
|
+
a(this, "http", void 0), this.http = e;
|
|
413
|
+
}
|
|
414
|
+
async list() {
|
|
415
|
+
return this.http.get("/v1/mcp/keys");
|
|
416
|
+
}
|
|
417
|
+
async create(e) {
|
|
418
|
+
return this.http.post("/v1/mcp/keys", e);
|
|
419
|
+
}
|
|
420
|
+
async revoke(e) {
|
|
421
|
+
return this.http.delete(`/v1/mcp/keys/${encodeURIComponent(e)}`);
|
|
422
|
+
}
|
|
423
|
+
}, N = class {
|
|
424
|
+
constructor(e) {
|
|
425
|
+
a(this, "apiKeys", void 0), a(this, "spendCap", void 0), a(this, "mcpKeys", void 0), this.apiKeys = new A(e), this.spendCap = new j(e), this.mcpKeys = new M(e);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/client.ts
|
|
430
|
+
function P(e) {
|
|
431
|
+
let t = e.baseUrl ?? "https://api.ledewire.com", n = new v({
|
|
432
|
+
storage: e.storage ?? new y(),
|
|
433
|
+
refreshFn: x(t),
|
|
434
|
+
...e.onAuthExpired !== void 0 && { onAuthExpired: e.onAuthExpired }
|
|
435
|
+
});
|
|
436
|
+
return new F(new g({
|
|
437
|
+
baseUrl: t,
|
|
438
|
+
getAccessToken: () => n.getAccessToken(),
|
|
439
|
+
onUnauthorized: () => n.handleUnauthorized()
|
|
440
|
+
}), n, e);
|
|
666
441
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
442
|
+
var F = class {
|
|
443
|
+
constructor(e, t, n) {
|
|
444
|
+
a(this, "_http", void 0), a(this, "_tokenManager", void 0), a(this, "_config", void 0), a(this, "config", void 0), a(this, "auth", void 0), a(this, "checkout", void 0), a(this, "wallet", void 0), a(this, "purchases", void 0), a(this, "content", void 0), a(this, "seller", void 0), a(this, "user", void 0), this._http = e, this._tokenManager = t, this._config = n, this.config = new C(e), this.auth = new S(e, t), this.checkout = new k(e), this.wallet = new O(e), this.purchases = new T(e), this.content = new w(e), this.seller = new D(e, t), this.user = new N(e);
|
|
445
|
+
}
|
|
446
|
+
}, I = "lw:tokens";
|
|
447
|
+
function L(e, t = I) {
|
|
448
|
+
return {
|
|
449
|
+
getTokens() {
|
|
450
|
+
let n = e.getItem(t);
|
|
451
|
+
if (!n) return null;
|
|
452
|
+
try {
|
|
453
|
+
return JSON.parse(n);
|
|
454
|
+
} catch {
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
},
|
|
458
|
+
setTokens(n) {
|
|
459
|
+
e.setItem(t, JSON.stringify(n));
|
|
460
|
+
},
|
|
461
|
+
clearTokens() {
|
|
462
|
+
e.removeItem(t);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
686
465
|
}
|
|
687
|
-
|
|
688
|
-
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/local-storage-adapter.ts
|
|
468
|
+
function R(e) {
|
|
469
|
+
return L(localStorage, e);
|
|
689
470
|
}
|
|
690
|
-
|
|
691
|
-
|
|
471
|
+
//#endregion
|
|
472
|
+
//#region src/session-storage-adapter.ts
|
|
473
|
+
function z(e) {
|
|
474
|
+
return L(sessionStorage, e);
|
|
692
475
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
U as MemoryTokenStorage,
|
|
698
|
-
T as NotFoundError,
|
|
699
|
-
M as PurchaseError,
|
|
700
|
-
j as init,
|
|
701
|
-
z as localStorageAdapter,
|
|
702
|
-
p as parseExpiresAt,
|
|
703
|
-
L as sessionStorageAdapter
|
|
704
|
-
};
|
|
705
|
-
//# sourceMappingURL=index.js.map
|
|
476
|
+
//#endregion
|
|
477
|
+
export { l as AuthError, u as ForbiddenError, c as LedewireError, y as MemoryTokenStorage, d as NotFoundError, f as PurchaseError, p as SpendCapReachedError, P as init, R as localStorageAdapter, b as parseExpiresAt, z as sessionStorageAdapter };
|
|
478
|
+
|
|
479
|
+
//# sourceMappingURL=index.js.map
|