@mitumba/sdk 5.4.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 +243 -1
- package/dist/index.d.ts +243 -1
- package/dist/index.js +147 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -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" },
|
|
@@ -2599,6 +2614,132 @@ var WholesaleModule = class {
|
|
|
2599
2614
|
}
|
|
2600
2615
|
};
|
|
2601
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
|
+
|
|
2602
2743
|
// src/types/auth.ts
|
|
2603
2744
|
var TWO_FACTOR_METHOD_TYPES = ["totp", "sms", "email", "passkey"];
|
|
2604
2745
|
|
|
@@ -2692,6 +2833,7 @@ var MitumbaClient = class {
|
|
|
2692
2833
|
uploads;
|
|
2693
2834
|
reports;
|
|
2694
2835
|
wholesale;
|
|
2836
|
+
iam;
|
|
2695
2837
|
constructor(config) {
|
|
2696
2838
|
this.api = new APIClient(config);
|
|
2697
2839
|
this.auth = new AuthModule(this.api);
|
|
@@ -2715,6 +2857,7 @@ var MitumbaClient = class {
|
|
|
2715
2857
|
this.uploads = new UploadsModule(this.api);
|
|
2716
2858
|
this.reports = new ReportsModule(this.api);
|
|
2717
2859
|
this.wholesale = new WholesaleModule(this.api);
|
|
2860
|
+
this.iam = new IamModule(this.api);
|
|
2718
2861
|
}
|
|
2719
2862
|
/**
|
|
2720
2863
|
* Set the access token for authenticated requests.
|
|
@@ -2755,6 +2898,6 @@ var MitumbaClient = class {
|
|
|
2755
2898
|
}
|
|
2756
2899
|
};
|
|
2757
2900
|
|
|
2758
|
-
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 };
|
|
2759
2902
|
//# sourceMappingURL=index.mjs.map
|
|
2760
2903
|
//# sourceMappingURL=index.mjs.map
|