@mitumba/sdk 4.0.0 → 5.1.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 +148 -5
- package/dist/index.d.ts +148 -5
- package/dist/index.js +108 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +108 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -227,6 +227,13 @@ var APIClient = class {
|
|
|
227
227
|
this.config.refreshToken = void 0;
|
|
228
228
|
await this.tokenStore.clear();
|
|
229
229
|
}
|
|
230
|
+
/**
|
|
231
|
+
* The current stored refresh token, or null if none. Exposed so logout can revoke the exact
|
|
232
|
+
* token the SDK holds rather than relying on the caller to supply (or guess) it.
|
|
233
|
+
*/
|
|
234
|
+
async getStoredRefreshToken() {
|
|
235
|
+
return this.config.refreshToken ?? await this.tokenStore.getRefreshToken();
|
|
236
|
+
}
|
|
230
237
|
/**
|
|
231
238
|
* Check if user has a stored session (access or refresh token available).
|
|
232
239
|
*/
|
|
@@ -471,12 +478,28 @@ var AuthModule = class {
|
|
|
471
478
|
return result;
|
|
472
479
|
}
|
|
473
480
|
/**
|
|
474
|
-
*
|
|
481
|
+
* Log out: revoke the current server session and clear the stored tokens.
|
|
482
|
+
*
|
|
483
|
+
* Reads the refresh token the SDK holds and revokes exactly that session server-side, then
|
|
484
|
+
* always clears local tokens — even if the network call fails or there was no token — so the
|
|
485
|
+
* device is signed out regardless. Idempotent: a second call is a no-op that still resolves.
|
|
486
|
+
*
|
|
487
|
+
* @returns `{ ok, revoked }` where `revoked` is true only when the server confirmed revocation.
|
|
488
|
+
* `revoked: false` means local credentials were cleared but the server session may persist
|
|
489
|
+
* until expiry (offline, or already revoked) — callers should not claim remote sign-out then.
|
|
475
490
|
*/
|
|
476
|
-
async logout(
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
491
|
+
async logout(options) {
|
|
492
|
+
const refreshToken = await this.client.getStoredRefreshToken();
|
|
493
|
+
let revoked = false;
|
|
494
|
+
try {
|
|
495
|
+
if (refreshToken) {
|
|
496
|
+
await this.client.post("/auth/logout", { refresh_token: refreshToken }, options);
|
|
497
|
+
revoked = true;
|
|
498
|
+
}
|
|
499
|
+
} finally {
|
|
500
|
+
await this.client.clearToken();
|
|
501
|
+
}
|
|
502
|
+
return { ok: true, revoked };
|
|
480
503
|
}
|
|
481
504
|
/**
|
|
482
505
|
* Request a password reset email.
|
|
@@ -653,6 +676,83 @@ var AuthModule = class {
|
|
|
653
676
|
}
|
|
654
677
|
};
|
|
655
678
|
|
|
679
|
+
// src/modules/oauth.ts
|
|
680
|
+
var OAuthModule = class {
|
|
681
|
+
constructor(client) {
|
|
682
|
+
this.client = client;
|
|
683
|
+
}
|
|
684
|
+
client;
|
|
685
|
+
/**
|
|
686
|
+
* Mint a one-time authorization code for the relying party.
|
|
687
|
+
*
|
|
688
|
+
* This is the authenticated mint step the accounts app calls after the user is signed in. It
|
|
689
|
+
* returns a one-time code (plus the echoed `state`) that the app then redirects back to the
|
|
690
|
+
* relying party's `redirect_uri`. The PKCE method is fixed to `'S256'` by the SDK, so callers
|
|
691
|
+
* cannot supply a weaker value. The returned code is not a session — this method does not
|
|
692
|
+
* persist anything.
|
|
693
|
+
*
|
|
694
|
+
* @param input - The authorize request (client, redirect URI, state, PKCE challenge, scope)
|
|
695
|
+
* @param options - Optional per-request options (abort signal, extra headers)
|
|
696
|
+
* @returns The one-time authorization code and the echoed `state`
|
|
697
|
+
* @throws {APIError} On `400` (`invalid_redirect_uri`, `invalid_client`, `invalid_scope`) or other errors
|
|
698
|
+
*
|
|
699
|
+
* @example
|
|
700
|
+
* ```typescript
|
|
701
|
+
* const { code, state } = await sdk.oauth.authorize({
|
|
702
|
+
* client_id: 'rp_abc',
|
|
703
|
+
* redirect_uri: 'https://app.example.com/callback',
|
|
704
|
+
* scope: 'profile email',
|
|
705
|
+
* state: csrfState,
|
|
706
|
+
* code_challenge: challenge,
|
|
707
|
+
* })
|
|
708
|
+
* ```
|
|
709
|
+
*/
|
|
710
|
+
async authorize(input, options) {
|
|
711
|
+
return this.client.post(
|
|
712
|
+
"/auth/oauth/authorize",
|
|
713
|
+
{ ...input, code_challenge_method: "S256" },
|
|
714
|
+
options
|
|
715
|
+
);
|
|
716
|
+
}
|
|
717
|
+
/**
|
|
718
|
+
* Exchange a one-time authorization code for a token pair.
|
|
719
|
+
*
|
|
720
|
+
* The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
|
|
721
|
+
* that matches the earlier challenge. The authorization code is single-use — a reused, expired,
|
|
722
|
+
* or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
|
|
723
|
+
* persisted into the client session via `setSession`, so the relying party is logged in
|
|
724
|
+
* immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
|
|
725
|
+
*
|
|
726
|
+
* @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
|
|
727
|
+
* @param options - Optional per-request options (abort signal, extra headers)
|
|
728
|
+
* @returns The access/refresh token pair and granted scope
|
|
729
|
+
* @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
|
|
730
|
+
*
|
|
731
|
+
* @example
|
|
732
|
+
* ```typescript
|
|
733
|
+
* const tokens = await sdk.oauth.exchangeCode({
|
|
734
|
+
* code,
|
|
735
|
+
* redirect_uri: 'https://app.example.com/callback',
|
|
736
|
+
* client_id: 'rp_abc',
|
|
737
|
+
* code_verifier: verifier,
|
|
738
|
+
* })
|
|
739
|
+
* // sdk is now authenticated as the exchanged session
|
|
740
|
+
* ```
|
|
741
|
+
*/
|
|
742
|
+
async exchangeCode(input, options) {
|
|
743
|
+
const result = await this.client.post(
|
|
744
|
+
"/auth/oauth/token",
|
|
745
|
+
{ ...input, grant_type: "authorization_code" },
|
|
746
|
+
options
|
|
747
|
+
);
|
|
748
|
+
await this.client.setSession({
|
|
749
|
+
access_token: result.access_token,
|
|
750
|
+
refresh_token: result.refresh_token
|
|
751
|
+
});
|
|
752
|
+
return result;
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
|
|
656
756
|
// src/modules/listings.ts
|
|
657
757
|
var ListingsModule = class {
|
|
658
758
|
constructor(client) {
|
|
@@ -2448,6 +2548,7 @@ function baleShareUrl(baleId, options = {}) {
|
|
|
2448
2548
|
var MitumbaClient = class {
|
|
2449
2549
|
api;
|
|
2450
2550
|
auth;
|
|
2551
|
+
oauth;
|
|
2451
2552
|
listings;
|
|
2452
2553
|
search;
|
|
2453
2554
|
orders;
|
|
@@ -2470,6 +2571,7 @@ var MitumbaClient = class {
|
|
|
2470
2571
|
constructor(config) {
|
|
2471
2572
|
this.api = new APIClient(config);
|
|
2472
2573
|
this.auth = new AuthModule(this.api);
|
|
2574
|
+
this.oauth = new OAuthModule(this.api);
|
|
2473
2575
|
this.listings = new ListingsModule(this.api);
|
|
2474
2576
|
this.search = new SearchModule(this.api);
|
|
2475
2577
|
this.orders = new OrdersModule(this.api);
|
|
@@ -2529,6 +2631,6 @@ var MitumbaClient = class {
|
|
|
2529
2631
|
}
|
|
2530
2632
|
};
|
|
2531
2633
|
|
|
2532
|
-
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, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, RealtimeProtocolError, RealtimeUnavailableError, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, baleShareUrl, createTokenStore, isMessagingAPIError, listingShareUrl, storeShareUrl };
|
|
2634
|
+
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, isMessagingAPIError, listingShareUrl, storeShareUrl };
|
|
2533
2635
|
//# sourceMappingURL=index.mjs.map
|
|
2534
2636
|
//# sourceMappingURL=index.mjs.map
|