@mitumba/sdk 5.3.0 → 5.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/dist/index.d.mts +292 -1
- package/dist/index.d.ts +292 -1
- package/dist/index.js +191 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +191 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -149,6 +149,21 @@ function isExpiringSoon(token, thresholdSeconds) {
|
|
|
149
149
|
return false;
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
|
+
function refreshPathForToken(token) {
|
|
153
|
+
if (!token) return "/auth/refresh";
|
|
154
|
+
try {
|
|
155
|
+
const encoded = token.split(".")[1];
|
|
156
|
+
if (!encoded) return "/auth/refresh";
|
|
157
|
+
const normalized = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
158
|
+
const payload = JSON.parse(atob(normalized));
|
|
159
|
+
return payload.ptype === "iam" ? "/auth/iam/refresh" : "/auth/refresh";
|
|
160
|
+
} catch {
|
|
161
|
+
return "/auth/refresh";
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
function isSessionEndpoint(path) {
|
|
165
|
+
return path === "/auth/login" || path === "/auth/register" || path === "/auth/refresh" || path === "/auth/iam/login" || path === "/auth/iam/login/2fa" || path === "/auth/iam/login/passkey/start" || path === "/auth/iam/login/passkey/finish" || path === "/auth/iam/activate" || path === "/auth/iam/refresh" || path === "/auth/iam/logout";
|
|
166
|
+
}
|
|
152
167
|
function isErrorRecord(value) {
|
|
153
168
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
154
169
|
}
|
|
@@ -264,7 +279,7 @@ var APIClient = class {
|
|
|
264
279
|
}
|
|
265
280
|
}
|
|
266
281
|
async request(method, path, body, params, options) {
|
|
267
|
-
if (!
|
|
282
|
+
if (!isSessionEndpoint(path)) {
|
|
268
283
|
await this.ensureFreshToken(options);
|
|
269
284
|
}
|
|
270
285
|
const url = new URL(path, this.config.baseUrl);
|
|
@@ -325,7 +340,7 @@ var APIClient = class {
|
|
|
325
340
|
}
|
|
326
341
|
break;
|
|
327
342
|
}
|
|
328
|
-
if (response.status === 401 && !
|
|
343
|
+
if (response.status === 401 && !isSessionEndpoint(path)) {
|
|
329
344
|
const hasRefreshToken = this.config.refreshToken && this.config.refreshToken.length > 0;
|
|
330
345
|
if (hasRefreshToken) {
|
|
331
346
|
try {
|
|
@@ -365,7 +380,7 @@ var APIClient = class {
|
|
|
365
380
|
this.isRefreshing = true;
|
|
366
381
|
this.refreshPromise = (async () => {
|
|
367
382
|
try {
|
|
368
|
-
const url = new URL(
|
|
383
|
+
const url = new URL(refreshPathForToken(this.config.token), this.config.baseUrl);
|
|
369
384
|
const response = await fetch(url.toString(), {
|
|
370
385
|
method: "POST",
|
|
371
386
|
headers: { "Content-Type": "application/json" },
|
|
@@ -831,6 +846,50 @@ var OAuthModule = class {
|
|
|
831
846
|
async listConsents(options) {
|
|
832
847
|
return this.client.get("/auth/oauth/consents", void 0, options);
|
|
833
848
|
}
|
|
849
|
+
/**
|
|
850
|
+
* Attempt a silent (`prompt=none`) authorization — the "sign in once, every app knows you" path.
|
|
851
|
+
*
|
|
852
|
+
* Sends the authorize request with `prompt=none`, meaning: mint a code only if it can be done with
|
|
853
|
+
* no interaction, otherwise tell me why so I can fall back. Unlike {@link OAuthModule.authorize},
|
|
854
|
+
* the expected non-success outcomes are RETURNED (discriminated on `ok`), not thrown, so a caller
|
|
855
|
+
* can branch cleanly without a try/catch:
|
|
856
|
+
*
|
|
857
|
+
* - `{ ok: true, code, state }` — redirect to `redirect_uri?code=..&state=..` as usual.
|
|
858
|
+
* - `{ ok: false, reason: 'login_required' }` — no usable session, or this client is not
|
|
859
|
+
* authorized for silent auth. Fall back to a visible sign-in (or stay logged out).
|
|
860
|
+
* - `{ ok: false, reason: 'interaction_required' }` — consent needed; fall back to a visible flow.
|
|
861
|
+
* - `{ ok: false, reason: 'unauthenticated' }` — no session reached the server (HTTP 401).
|
|
862
|
+
*
|
|
863
|
+
* Only genuinely unexpected errors (network failure, 5xx, an unrecognised error code) throw.
|
|
864
|
+
* `code_challenge_method` is fixed to `'S256'` and `prompt` to `'none'` by the SDK. This is a
|
|
865
|
+
* top-level/first-party call carrying the session the SDK holds; the server never mints for a
|
|
866
|
+
* client that lacks the silent-auth privilege (it returns `login_required`).
|
|
867
|
+
*
|
|
868
|
+
* @param input - The authorize request (client, redirect URI, state, PKCE challenge, scope)
|
|
869
|
+
* @param options - Optional per-request options (abort signal, extra headers)
|
|
870
|
+
* @returns A discriminated success-or-fallback result
|
|
871
|
+
* @throws {APIError} Only on unexpected failures (network, 5xx, unknown error code)
|
|
872
|
+
*/
|
|
873
|
+
async silentAuthorize(input, options) {
|
|
874
|
+
try {
|
|
875
|
+
const result = await this.client.post(
|
|
876
|
+
"/auth/oauth/authorize",
|
|
877
|
+
{ ...input, code_challenge_method: "S256", prompt: "none" },
|
|
878
|
+
options
|
|
879
|
+
);
|
|
880
|
+
if (isConsentRequired(result)) return { ok: false, reason: "interaction_required" };
|
|
881
|
+
return { ok: true, code: result.code, state: result.state };
|
|
882
|
+
} catch (err) {
|
|
883
|
+
if (err instanceof APIError) {
|
|
884
|
+
if (err.status === 401) return { ok: false, reason: "unauthenticated" };
|
|
885
|
+
if (err.code === "login_required") return { ok: false, reason: "login_required" };
|
|
886
|
+
if (err.code === "interaction_required" || err.code === "consent_required") {
|
|
887
|
+
return { ok: false, reason: "interaction_required" };
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
throw err;
|
|
891
|
+
}
|
|
892
|
+
}
|
|
834
893
|
};
|
|
835
894
|
|
|
836
895
|
// src/modules/listings.ts
|
|
@@ -2555,6 +2614,132 @@ var WholesaleModule = class {
|
|
|
2555
2614
|
}
|
|
2556
2615
|
};
|
|
2557
2616
|
|
|
2617
|
+
// src/modules/iam.ts
|
|
2618
|
+
function isIamTokens(result) {
|
|
2619
|
+
return "access_token" in result;
|
|
2620
|
+
}
|
|
2621
|
+
var IamModule = class {
|
|
2622
|
+
constructor(client) {
|
|
2623
|
+
this.client = client;
|
|
2624
|
+
}
|
|
2625
|
+
client;
|
|
2626
|
+
/** Start IAM sign-in with an organization ID or alias, email and password. */
|
|
2627
|
+
async login(input, options) {
|
|
2628
|
+
const result = await this.client.post("/auth/iam/login", input, options);
|
|
2629
|
+
if (isIamTokens(result)) await this.client.setSession(result);
|
|
2630
|
+
return result;
|
|
2631
|
+
}
|
|
2632
|
+
/** Finish IAM sign-in with a TOTP or one-time backup code. */
|
|
2633
|
+
async verifyTwoFactor(input, options) {
|
|
2634
|
+
const result = await this.client.post("/auth/iam/login/2fa", input, options);
|
|
2635
|
+
await this.client.setSession(result);
|
|
2636
|
+
return result;
|
|
2637
|
+
}
|
|
2638
|
+
/** Get WebAuthn assertion options for a pending IAM sign-in. */
|
|
2639
|
+
async startPasskeyLogin(tempToken, options) {
|
|
2640
|
+
return this.client.post("/auth/iam/login/passkey/start", { temp_token: tempToken }, options);
|
|
2641
|
+
}
|
|
2642
|
+
/** Finish IAM passkey sign-in and persist the returned IAM session. */
|
|
2643
|
+
async finishPasskeyLogin(input, options) {
|
|
2644
|
+
const result = await this.client.post("/auth/iam/login/passkey/finish", input, options);
|
|
2645
|
+
await this.client.setSession(result);
|
|
2646
|
+
return result;
|
|
2647
|
+
}
|
|
2648
|
+
/** Activate an invited IAM user and choose its password. */
|
|
2649
|
+
async activate(input, options) {
|
|
2650
|
+
return this.client.post("/auth/iam/activate", input, options);
|
|
2651
|
+
}
|
|
2652
|
+
/** Rotate an IAM refresh token and persist the returned session. */
|
|
2653
|
+
async refresh(refreshToken, options) {
|
|
2654
|
+
const result = await this.client.post("/auth/iam/refresh", { refresh_token: refreshToken }, options);
|
|
2655
|
+
await this.client.setSession(result);
|
|
2656
|
+
return result;
|
|
2657
|
+
}
|
|
2658
|
+
/** End the current IAM session and clear locally stored credentials. */
|
|
2659
|
+
async logout(options) {
|
|
2660
|
+
const refreshToken = await this.client.getStoredRefreshToken();
|
|
2661
|
+
if (!refreshToken) {
|
|
2662
|
+
await this.client.clearToken();
|
|
2663
|
+
return { ok: true };
|
|
2664
|
+
}
|
|
2665
|
+
const result = await this.client.post("/auth/iam/logout", { refresh_token: refreshToken }, options);
|
|
2666
|
+
await this.client.clearToken();
|
|
2667
|
+
return result;
|
|
2668
|
+
}
|
|
2669
|
+
/** Get the current IAM principal, organization and effective access state. */
|
|
2670
|
+
async me(options) {
|
|
2671
|
+
return this.client.get("/auth/iam/me", void 0, options);
|
|
2672
|
+
}
|
|
2673
|
+
/** List this IAM principal's enrolled second-factor methods. */
|
|
2674
|
+
async listMethods(options) {
|
|
2675
|
+
return this.client.get("/auth/iam/2fa/methods", void 0, options);
|
|
2676
|
+
}
|
|
2677
|
+
/** Begin adding an authenticator app or passkey. */
|
|
2678
|
+
async addMethod(input, options) {
|
|
2679
|
+
return this.client.post("/auth/iam/2fa/methods", input, options);
|
|
2680
|
+
}
|
|
2681
|
+
/** Verify and enable a pending IAM authenticator method. */
|
|
2682
|
+
async verifyMethod(methodId, code, options) {
|
|
2683
|
+
return this.client.post(`/auth/iam/2fa/methods/${encodeURIComponent(methodId)}/verify`, { code }, options);
|
|
2684
|
+
}
|
|
2685
|
+
/** Finish and enable a pending IAM passkey method. */
|
|
2686
|
+
async finishPasskeyEnrollment(methodId, credential, options) {
|
|
2687
|
+
return this.client.post(`/auth/iam/2fa/methods/${encodeURIComponent(methodId)}/passkey/finish`, credential, options);
|
|
2688
|
+
}
|
|
2689
|
+
/** List organizations the current root/global operator may administer. */
|
|
2690
|
+
async listOrganizations(options) {
|
|
2691
|
+
return this.client.get("/auth/orgs", void 0, options);
|
|
2692
|
+
}
|
|
2693
|
+
/** Create an organization. */
|
|
2694
|
+
async createOrganization(input, options) {
|
|
2695
|
+
return this.client.post("/auth/orgs", input, options);
|
|
2696
|
+
}
|
|
2697
|
+
/** Update an organization's name or lifecycle state. */
|
|
2698
|
+
async updateOrganization(orgId, input, options) {
|
|
2699
|
+
return this.client.patch(`/auth/orgs/${encodeURIComponent(orgId)}`, input, options);
|
|
2700
|
+
}
|
|
2701
|
+
/** List IAM users and grantable permissions in one organization. */
|
|
2702
|
+
async listUsers(orgId, options) {
|
|
2703
|
+
return this.client.get(`/auth/orgs/${encodeURIComponent(orgId)}/iam-users`, void 0, options);
|
|
2704
|
+
}
|
|
2705
|
+
/** Provision an IAM user. The activation code is returned once. */
|
|
2706
|
+
async createUser(orgId, input, options) {
|
|
2707
|
+
return this.client.post(`/auth/orgs/${encodeURIComponent(orgId)}/iam-users`, input, options);
|
|
2708
|
+
}
|
|
2709
|
+
/** Grant one organization-scoped permission to an IAM user. */
|
|
2710
|
+
async grantPermission(orgId, iamUserId, permission, options) {
|
|
2711
|
+
return this.client.post(
|
|
2712
|
+
`/auth/orgs/${encodeURIComponent(orgId)}/iam-users/${encodeURIComponent(iamUserId)}/permissions`,
|
|
2713
|
+
{ permission },
|
|
2714
|
+
options
|
|
2715
|
+
);
|
|
2716
|
+
}
|
|
2717
|
+
/** Revoke one permission and immediately end the IAM user's sessions. */
|
|
2718
|
+
async revokePermission(orgId, iamUserId, permission, options) {
|
|
2719
|
+
return this.client.delete(
|
|
2720
|
+
`/auth/orgs/${encodeURIComponent(orgId)}/iam-users/${encodeURIComponent(iamUserId)}/permissions/${encodeURIComponent(permission)}`,
|
|
2721
|
+
void 0,
|
|
2722
|
+
options
|
|
2723
|
+
);
|
|
2724
|
+
}
|
|
2725
|
+
/** Enable or disable an IAM user. Disabling immediately ends its sessions. */
|
|
2726
|
+
async setUserStatus(orgId, iamUserId, status, options) {
|
|
2727
|
+
return this.client.post(
|
|
2728
|
+
`/auth/orgs/${encodeURIComponent(orgId)}/iam-users/${encodeURIComponent(iamUserId)}/status`,
|
|
2729
|
+
{ status },
|
|
2730
|
+
options
|
|
2731
|
+
);
|
|
2732
|
+
}
|
|
2733
|
+
/** Reissue the one-time activation credential for an unactivated IAM user. */
|
|
2734
|
+
async reissueActivation(orgId, iamUserId, options) {
|
|
2735
|
+
return this.client.post(
|
|
2736
|
+
`/auth/orgs/${encodeURIComponent(orgId)}/iam-users/${encodeURIComponent(iamUserId)}/activation`,
|
|
2737
|
+
void 0,
|
|
2738
|
+
options
|
|
2739
|
+
);
|
|
2740
|
+
}
|
|
2741
|
+
};
|
|
2742
|
+
|
|
2558
2743
|
// src/types/auth.ts
|
|
2559
2744
|
var TWO_FACTOR_METHOD_TYPES = ["totp", "sms", "email", "passkey"];
|
|
2560
2745
|
|
|
@@ -2648,6 +2833,7 @@ var MitumbaClient = class {
|
|
|
2648
2833
|
uploads;
|
|
2649
2834
|
reports;
|
|
2650
2835
|
wholesale;
|
|
2836
|
+
iam;
|
|
2651
2837
|
constructor(config) {
|
|
2652
2838
|
this.api = new APIClient(config);
|
|
2653
2839
|
this.auth = new AuthModule(this.api);
|
|
@@ -2671,6 +2857,7 @@ var MitumbaClient = class {
|
|
|
2671
2857
|
this.uploads = new UploadsModule(this.api);
|
|
2672
2858
|
this.reports = new ReportsModule(this.api);
|
|
2673
2859
|
this.wholesale = new WholesaleModule(this.api);
|
|
2860
|
+
this.iam = new IamModule(this.api);
|
|
2674
2861
|
}
|
|
2675
2862
|
/**
|
|
2676
2863
|
* Set the access token for authenticated requests.
|
|
@@ -2711,6 +2898,6 @@ var MitumbaClient = class {
|
|
|
2711
2898
|
}
|
|
2712
2899
|
};
|
|
2713
2900
|
|
|
2714
|
-
export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, DisputesModule, IDBTokenStore, LISTING_STATUSES, ListingsModule, MailerModule, MemoryTokenStore, MessagesModule, MitumbaClient, NotificationsModule, OAuthModule, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, RealtimeProtocolError, RealtimeUnavailableError, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, baleShareUrl, createTokenStore, isConsentRequired, isMessagingAPIError, listingShareUrl, storeShareUrl };
|
|
2901
|
+
export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, DisputesModule, IDBTokenStore, IamModule, LISTING_STATUSES, ListingsModule, MailerModule, MemoryTokenStore, MessagesModule, MitumbaClient, NotificationsModule, OAuthModule, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, RealtimeProtocolError, RealtimeUnavailableError, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, baleShareUrl, createTokenStore, isConsentRequired, isMessagingAPIError, listingShareUrl, storeShareUrl };
|
|
2715
2902
|
//# sourceMappingURL=index.mjs.map
|
|
2716
2903
|
//# sourceMappingURL=index.mjs.map
|