@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.js
CHANGED
|
@@ -151,6 +151,21 @@ function isExpiringSoon(token, thresholdSeconds) {
|
|
|
151
151
|
return false;
|
|
152
152
|
}
|
|
153
153
|
}
|
|
154
|
+
function refreshPathForToken(token) {
|
|
155
|
+
if (!token) return "/auth/refresh";
|
|
156
|
+
try {
|
|
157
|
+
const encoded = token.split(".")[1];
|
|
158
|
+
if (!encoded) return "/auth/refresh";
|
|
159
|
+
const normalized = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
160
|
+
const payload = JSON.parse(atob(normalized));
|
|
161
|
+
return payload.ptype === "iam" ? "/auth/iam/refresh" : "/auth/refresh";
|
|
162
|
+
} catch {
|
|
163
|
+
return "/auth/refresh";
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function isSessionEndpoint(path) {
|
|
167
|
+
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";
|
|
168
|
+
}
|
|
154
169
|
function isErrorRecord(value) {
|
|
155
170
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
156
171
|
}
|
|
@@ -266,7 +281,7 @@ var APIClient = class {
|
|
|
266
281
|
}
|
|
267
282
|
}
|
|
268
283
|
async request(method, path, body, params, options) {
|
|
269
|
-
if (!
|
|
284
|
+
if (!isSessionEndpoint(path)) {
|
|
270
285
|
await this.ensureFreshToken(options);
|
|
271
286
|
}
|
|
272
287
|
const url = new URL(path, this.config.baseUrl);
|
|
@@ -327,7 +342,7 @@ var APIClient = class {
|
|
|
327
342
|
}
|
|
328
343
|
break;
|
|
329
344
|
}
|
|
330
|
-
if (response.status === 401 && !
|
|
345
|
+
if (response.status === 401 && !isSessionEndpoint(path)) {
|
|
331
346
|
const hasRefreshToken = this.config.refreshToken && this.config.refreshToken.length > 0;
|
|
332
347
|
if (hasRefreshToken) {
|
|
333
348
|
try {
|
|
@@ -367,7 +382,7 @@ var APIClient = class {
|
|
|
367
382
|
this.isRefreshing = true;
|
|
368
383
|
this.refreshPromise = (async () => {
|
|
369
384
|
try {
|
|
370
|
-
const url = new URL(
|
|
385
|
+
const url = new URL(refreshPathForToken(this.config.token), this.config.baseUrl);
|
|
371
386
|
const response = await fetch(url.toString(), {
|
|
372
387
|
method: "POST",
|
|
373
388
|
headers: { "Content-Type": "application/json" },
|
|
@@ -2601,6 +2616,132 @@ var WholesaleModule = class {
|
|
|
2601
2616
|
}
|
|
2602
2617
|
};
|
|
2603
2618
|
|
|
2619
|
+
// src/modules/iam.ts
|
|
2620
|
+
function isIamTokens(result) {
|
|
2621
|
+
return "access_token" in result;
|
|
2622
|
+
}
|
|
2623
|
+
var IamModule = class {
|
|
2624
|
+
constructor(client) {
|
|
2625
|
+
this.client = client;
|
|
2626
|
+
}
|
|
2627
|
+
client;
|
|
2628
|
+
/** Start IAM sign-in with an organization ID or alias, email and password. */
|
|
2629
|
+
async login(input, options) {
|
|
2630
|
+
const result = await this.client.post("/auth/iam/login", input, options);
|
|
2631
|
+
if (isIamTokens(result)) await this.client.setSession(result);
|
|
2632
|
+
return result;
|
|
2633
|
+
}
|
|
2634
|
+
/** Finish IAM sign-in with a TOTP or one-time backup code. */
|
|
2635
|
+
async verifyTwoFactor(input, options) {
|
|
2636
|
+
const result = await this.client.post("/auth/iam/login/2fa", input, options);
|
|
2637
|
+
await this.client.setSession(result);
|
|
2638
|
+
return result;
|
|
2639
|
+
}
|
|
2640
|
+
/** Get WebAuthn assertion options for a pending IAM sign-in. */
|
|
2641
|
+
async startPasskeyLogin(tempToken, options) {
|
|
2642
|
+
return this.client.post("/auth/iam/login/passkey/start", { temp_token: tempToken }, options);
|
|
2643
|
+
}
|
|
2644
|
+
/** Finish IAM passkey sign-in and persist the returned IAM session. */
|
|
2645
|
+
async finishPasskeyLogin(input, options) {
|
|
2646
|
+
const result = await this.client.post("/auth/iam/login/passkey/finish", input, options);
|
|
2647
|
+
await this.client.setSession(result);
|
|
2648
|
+
return result;
|
|
2649
|
+
}
|
|
2650
|
+
/** Activate an invited IAM user and choose its password. */
|
|
2651
|
+
async activate(input, options) {
|
|
2652
|
+
return this.client.post("/auth/iam/activate", input, options);
|
|
2653
|
+
}
|
|
2654
|
+
/** Rotate an IAM refresh token and persist the returned session. */
|
|
2655
|
+
async refresh(refreshToken, options) {
|
|
2656
|
+
const result = await this.client.post("/auth/iam/refresh", { refresh_token: refreshToken }, options);
|
|
2657
|
+
await this.client.setSession(result);
|
|
2658
|
+
return result;
|
|
2659
|
+
}
|
|
2660
|
+
/** End the current IAM session and clear locally stored credentials. */
|
|
2661
|
+
async logout(options) {
|
|
2662
|
+
const refreshToken = await this.client.getStoredRefreshToken();
|
|
2663
|
+
if (!refreshToken) {
|
|
2664
|
+
await this.client.clearToken();
|
|
2665
|
+
return { ok: true };
|
|
2666
|
+
}
|
|
2667
|
+
const result = await this.client.post("/auth/iam/logout", { refresh_token: refreshToken }, options);
|
|
2668
|
+
await this.client.clearToken();
|
|
2669
|
+
return result;
|
|
2670
|
+
}
|
|
2671
|
+
/** Get the current IAM principal, organization and effective access state. */
|
|
2672
|
+
async me(options) {
|
|
2673
|
+
return this.client.get("/auth/iam/me", void 0, options);
|
|
2674
|
+
}
|
|
2675
|
+
/** List this IAM principal's enrolled second-factor methods. */
|
|
2676
|
+
async listMethods(options) {
|
|
2677
|
+
return this.client.get("/auth/iam/2fa/methods", void 0, options);
|
|
2678
|
+
}
|
|
2679
|
+
/** Begin adding an authenticator app or passkey. */
|
|
2680
|
+
async addMethod(input, options) {
|
|
2681
|
+
return this.client.post("/auth/iam/2fa/methods", input, options);
|
|
2682
|
+
}
|
|
2683
|
+
/** Verify and enable a pending IAM authenticator method. */
|
|
2684
|
+
async verifyMethod(methodId, code, options) {
|
|
2685
|
+
return this.client.post(`/auth/iam/2fa/methods/${encodeURIComponent(methodId)}/verify`, { code }, options);
|
|
2686
|
+
}
|
|
2687
|
+
/** Finish and enable a pending IAM passkey method. */
|
|
2688
|
+
async finishPasskeyEnrollment(methodId, credential, options) {
|
|
2689
|
+
return this.client.post(`/auth/iam/2fa/methods/${encodeURIComponent(methodId)}/passkey/finish`, credential, options);
|
|
2690
|
+
}
|
|
2691
|
+
/** List organizations the current root/global operator may administer. */
|
|
2692
|
+
async listOrganizations(options) {
|
|
2693
|
+
return this.client.get("/auth/orgs", void 0, options);
|
|
2694
|
+
}
|
|
2695
|
+
/** Create an organization. */
|
|
2696
|
+
async createOrganization(input, options) {
|
|
2697
|
+
return this.client.post("/auth/orgs", input, options);
|
|
2698
|
+
}
|
|
2699
|
+
/** Update an organization's name or lifecycle state. */
|
|
2700
|
+
async updateOrganization(orgId, input, options) {
|
|
2701
|
+
return this.client.patch(`/auth/orgs/${encodeURIComponent(orgId)}`, input, options);
|
|
2702
|
+
}
|
|
2703
|
+
/** List IAM users and grantable permissions in one organization. */
|
|
2704
|
+
async listUsers(orgId, options) {
|
|
2705
|
+
return this.client.get(`/auth/orgs/${encodeURIComponent(orgId)}/iam-users`, void 0, options);
|
|
2706
|
+
}
|
|
2707
|
+
/** Provision an IAM user. The activation code is returned once. */
|
|
2708
|
+
async createUser(orgId, input, options) {
|
|
2709
|
+
return this.client.post(`/auth/orgs/${encodeURIComponent(orgId)}/iam-users`, input, options);
|
|
2710
|
+
}
|
|
2711
|
+
/** Grant one organization-scoped permission to an IAM user. */
|
|
2712
|
+
async grantPermission(orgId, iamUserId, permission, options) {
|
|
2713
|
+
return this.client.post(
|
|
2714
|
+
`/auth/orgs/${encodeURIComponent(orgId)}/iam-users/${encodeURIComponent(iamUserId)}/permissions`,
|
|
2715
|
+
{ permission },
|
|
2716
|
+
options
|
|
2717
|
+
);
|
|
2718
|
+
}
|
|
2719
|
+
/** Revoke one permission and immediately end the IAM user's sessions. */
|
|
2720
|
+
async revokePermission(orgId, iamUserId, permission, options) {
|
|
2721
|
+
return this.client.delete(
|
|
2722
|
+
`/auth/orgs/${encodeURIComponent(orgId)}/iam-users/${encodeURIComponent(iamUserId)}/permissions/${encodeURIComponent(permission)}`,
|
|
2723
|
+
void 0,
|
|
2724
|
+
options
|
|
2725
|
+
);
|
|
2726
|
+
}
|
|
2727
|
+
/** Enable or disable an IAM user. Disabling immediately ends its sessions. */
|
|
2728
|
+
async setUserStatus(orgId, iamUserId, status, options) {
|
|
2729
|
+
return this.client.post(
|
|
2730
|
+
`/auth/orgs/${encodeURIComponent(orgId)}/iam-users/${encodeURIComponent(iamUserId)}/status`,
|
|
2731
|
+
{ status },
|
|
2732
|
+
options
|
|
2733
|
+
);
|
|
2734
|
+
}
|
|
2735
|
+
/** Reissue the one-time activation credential for an unactivated IAM user. */
|
|
2736
|
+
async reissueActivation(orgId, iamUserId, options) {
|
|
2737
|
+
return this.client.post(
|
|
2738
|
+
`/auth/orgs/${encodeURIComponent(orgId)}/iam-users/${encodeURIComponent(iamUserId)}/activation`,
|
|
2739
|
+
void 0,
|
|
2740
|
+
options
|
|
2741
|
+
);
|
|
2742
|
+
}
|
|
2743
|
+
};
|
|
2744
|
+
|
|
2604
2745
|
// src/types/auth.ts
|
|
2605
2746
|
var TWO_FACTOR_METHOD_TYPES = ["totp", "sms", "email", "passkey"];
|
|
2606
2747
|
|
|
@@ -2694,6 +2835,7 @@ var MitumbaClient = class {
|
|
|
2694
2835
|
uploads;
|
|
2695
2836
|
reports;
|
|
2696
2837
|
wholesale;
|
|
2838
|
+
iam;
|
|
2697
2839
|
constructor(config) {
|
|
2698
2840
|
this.api = new APIClient(config);
|
|
2699
2841
|
this.auth = new AuthModule(this.api);
|
|
@@ -2717,6 +2859,7 @@ var MitumbaClient = class {
|
|
|
2717
2859
|
this.uploads = new UploadsModule(this.api);
|
|
2718
2860
|
this.reports = new ReportsModule(this.api);
|
|
2719
2861
|
this.wholesale = new WholesaleModule(this.api);
|
|
2862
|
+
this.iam = new IamModule(this.api);
|
|
2720
2863
|
}
|
|
2721
2864
|
/**
|
|
2722
2865
|
* Set the access token for authenticated requests.
|
|
@@ -2771,6 +2914,7 @@ exports.DISPUTE_REASONS = DISPUTE_REASONS;
|
|
|
2771
2914
|
exports.DISPUTE_STATUSES = DISPUTE_STATUSES;
|
|
2772
2915
|
exports.DisputesModule = DisputesModule;
|
|
2773
2916
|
exports.IDBTokenStore = IDBTokenStore;
|
|
2917
|
+
exports.IamModule = IamModule;
|
|
2774
2918
|
exports.LISTING_STATUSES = LISTING_STATUSES;
|
|
2775
2919
|
exports.ListingsModule = ListingsModule;
|
|
2776
2920
|
exports.MailerModule = MailerModule;
|