@mitumba/sdk 5.13.0 → 5.15.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 +1 -1
- package/dist/index.d.mts +120 -2
- package/dist/index.d.ts +120 -2
- package/dist/index.js +92 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -279,6 +279,17 @@ var APIClient = class {
|
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
281
|
async request(method, path, body, params, options) {
|
|
282
|
+
const response = await this.send(method, path, body, params, options);
|
|
283
|
+
if (response.status === 204) {
|
|
284
|
+
return void 0;
|
|
285
|
+
}
|
|
286
|
+
return response.json();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* One request with authentication, proactive and reactive token refresh, retries and error decoding.
|
|
290
|
+
* Resolves with the successful response, unread, so the caller chooses how to read its body.
|
|
291
|
+
*/
|
|
292
|
+
async send(method, path, body, params, options) {
|
|
282
293
|
if (!isSessionEndpoint(path)) {
|
|
283
294
|
await this.ensureFreshToken(options);
|
|
284
295
|
}
|
|
@@ -368,10 +379,7 @@ var APIClient = class {
|
|
|
368
379
|
}
|
|
369
380
|
throw new APIError(response.status, normalizeAPIErrorResponse(decoded, response.statusText));
|
|
370
381
|
}
|
|
371
|
-
|
|
372
|
-
return void 0;
|
|
373
|
-
}
|
|
374
|
-
return response.json();
|
|
382
|
+
return response;
|
|
375
383
|
}
|
|
376
384
|
async handleTokenRefresh(signal) {
|
|
377
385
|
if (this.isRefreshing && this.refreshPromise) {
|
|
@@ -423,6 +431,18 @@ var APIClient = class {
|
|
|
423
431
|
get(path, params, options) {
|
|
424
432
|
return this.request("GET", path, void 0, params, options);
|
|
425
433
|
}
|
|
434
|
+
/**
|
|
435
|
+
* A GET whose response is a file (a PDF, an image) rather than JSON. Authentication, refresh,
|
|
436
|
+
* retries and errors are exactly those of {@link get}; an error response still decodes its JSON body.
|
|
437
|
+
*/
|
|
438
|
+
async getFile(path, params, options) {
|
|
439
|
+
const response = await this.send("GET", path, void 0, params, options);
|
|
440
|
+
return {
|
|
441
|
+
blob: await response.blob(),
|
|
442
|
+
contentType: response.headers.get("Content-Type") ?? "application/octet-stream",
|
|
443
|
+
headers: response.headers
|
|
444
|
+
};
|
|
445
|
+
}
|
|
426
446
|
post(path, body, options) {
|
|
427
447
|
return this.request("POST", path, body, void 0, options);
|
|
428
448
|
}
|
|
@@ -1089,6 +1109,18 @@ var SearchModule = class {
|
|
|
1089
1109
|
};
|
|
1090
1110
|
|
|
1091
1111
|
// src/modules/orders.ts
|
|
1112
|
+
function dispositionFilename(header) {
|
|
1113
|
+
if (!header) return null;
|
|
1114
|
+
const extended = /filename\*\s*=\s*(?:UTF-8|utf-8)''([^;]+)/.exec(header);
|
|
1115
|
+
if (extended?.[1]) {
|
|
1116
|
+
try {
|
|
1117
|
+
return decodeURIComponent(extended[1].trim());
|
|
1118
|
+
} catch {
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
const plain = /filename\s*=\s*"?([^";]+)"?/.exec(header);
|
|
1122
|
+
return plain?.[1]?.trim() || null;
|
|
1123
|
+
}
|
|
1092
1124
|
var OrdersModule = class {
|
|
1093
1125
|
constructor(client) {
|
|
1094
1126
|
this.client = client;
|
|
@@ -1111,6 +1143,21 @@ var OrdersModule = class {
|
|
|
1111
1143
|
async transition(id, input, options) {
|
|
1112
1144
|
return this.client.post(`/orders/${id}/transition`, input, options);
|
|
1113
1145
|
}
|
|
1146
|
+
/**
|
|
1147
|
+
* Get an order's invoice or receipt as a PDF: its receipt once it is paid, its invoice while it awaits
|
|
1148
|
+
* payment. Buyer only. Every order of one checkout returns the same document.
|
|
1149
|
+
*
|
|
1150
|
+
* Errors: 404 document_not_found when the order has no document to show.
|
|
1151
|
+
*/
|
|
1152
|
+
async getDocument(id, options) {
|
|
1153
|
+
const file = await this.client.getFile(`/orders/${encodeURIComponent(id)}/document`, void 0, options);
|
|
1154
|
+
const kind = file.headers.get("X-Mitumba-Document") === "receipt" ? "receipt" : "invoice";
|
|
1155
|
+
return {
|
|
1156
|
+
kind,
|
|
1157
|
+
filename: dispositionFilename(file.headers.get("Content-Disposition")) ?? `Mitumba-${id}.pdf`,
|
|
1158
|
+
blob: file.blob
|
|
1159
|
+
};
|
|
1160
|
+
}
|
|
1114
1161
|
/**
|
|
1115
1162
|
* Get the order history for the current authenticated user.
|
|
1116
1163
|
*/
|
|
@@ -2381,6 +2428,47 @@ var AdminModule = class {
|
|
|
2381
2428
|
async listAuditLog(query2 = {}, options) {
|
|
2382
2429
|
return this.client.get("/admin/audit", query2, options);
|
|
2383
2430
|
}
|
|
2431
|
+
// ── Identity provider: sign-in clients (requires clients:manage) ──
|
|
2432
|
+
/** Every registered sign-in client, oldest first. Secrets are never included. */
|
|
2433
|
+
async listOAuthClients(options) {
|
|
2434
|
+
return this.client.get("/admin/clients", void 0, options);
|
|
2435
|
+
}
|
|
2436
|
+
/** One client with its redirect-URI allow-list and permitted scopes. */
|
|
2437
|
+
async getOAuthClient(clientId, options) {
|
|
2438
|
+
return this.client.get(`/admin/clients/${encodeURIComponent(clientId)}`, void 0, options);
|
|
2439
|
+
}
|
|
2440
|
+
/**
|
|
2441
|
+
* Register a client. A confidential client's `client_secret` is in this response only — it is
|
|
2442
|
+
* stored hashed and cannot be retrieved again, so hand it to the client's owner immediately.
|
|
2443
|
+
*/
|
|
2444
|
+
async registerOAuthClient(input, options) {
|
|
2445
|
+
return this.client.post("/admin/clients", input, options);
|
|
2446
|
+
}
|
|
2447
|
+
/** Stop a client authorising. Clients are deactivated, never deleted, so their history stays auditable. */
|
|
2448
|
+
async deactivateOAuthClient(clientId, options) {
|
|
2449
|
+
return this.client.post(`/admin/clients/${encodeURIComponent(clientId)}/deactivate`, void 0, options);
|
|
2450
|
+
}
|
|
2451
|
+
/** Replace a client's whole redirect-URI allow-list. URIs match exactly: no wildcards or prefixes. */
|
|
2452
|
+
async setOAuthClientRedirectUris(clientId, redirectUris, options) {
|
|
2453
|
+
return this.client.put(`/admin/clients/${encodeURIComponent(clientId)}/redirect-uris`, { redirect_uris: redirectUris }, options);
|
|
2454
|
+
}
|
|
2455
|
+
/** Replace the set of scopes a client may request. */
|
|
2456
|
+
async setOAuthClientScopes(clientId, scopes, options) {
|
|
2457
|
+
return this.client.put(`/admin/clients/${encodeURIComponent(clientId)}/scopes`, { scopes }, options);
|
|
2458
|
+
}
|
|
2459
|
+
// ── Identity provider: signing keys (requires oidc:rotate_keys) ──
|
|
2460
|
+
/** The signing-key window — current, previous, retired — as metadata only. */
|
|
2461
|
+
async listOidcSigningKeys(options) {
|
|
2462
|
+
return this.client.get("/auth/oidc/keys", void 0, options);
|
|
2463
|
+
}
|
|
2464
|
+
/**
|
|
2465
|
+
* Run the rotation ceremony: a new key becomes current, the current key becomes previous (still
|
|
2466
|
+
* verifying), and the old previous is retired. Do not rotate twice within an id_token lifetime
|
|
2467
|
+
* (one hour), or tokens signed by the retired key stop verifying.
|
|
2468
|
+
*/
|
|
2469
|
+
async rotateOidcSigningKey(options) {
|
|
2470
|
+
return this.client.post("/auth/oidc/keys/rotate", void 0, options);
|
|
2471
|
+
}
|
|
2384
2472
|
// ── Payout approval ──
|
|
2385
2473
|
async listPayoutsAwaitingApproval(options) {
|
|
2386
2474
|
return this.client.get("/admin/payouts/pending-approval", void 0, options);
|