@mitumba/sdk 5.10.0 → 5.12.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 +49 -13
- package/dist/index.d.ts +49 -13
- package/dist/index.js +24 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1278,7 +1278,9 @@ interface BecomeSellerInput {
|
|
|
1278
1278
|
business_name?: string;
|
|
1279
1279
|
id_number?: string;
|
|
1280
1280
|
kra_pin?: string;
|
|
1281
|
+
/** Contact / payout phone in any common local form; stored on the business in E.164. Invalid is a 400. */
|
|
1281
1282
|
phone?: string;
|
|
1283
|
+
/** A region name from `sdk.markets.regions()`; stored canonically. Invalid is a 400. */
|
|
1282
1284
|
county?: string;
|
|
1283
1285
|
town?: string;
|
|
1284
1286
|
categories?: string[];
|
|
@@ -1292,7 +1294,9 @@ interface BecomeBaleSellerInput {
|
|
|
1292
1294
|
business_name?: string;
|
|
1293
1295
|
kra_pin?: string;
|
|
1294
1296
|
id_number?: string;
|
|
1297
|
+
/** Contact / payout phone in any common local form; stored on the business in E.164. Invalid is a 400. */
|
|
1295
1298
|
phone?: string;
|
|
1299
|
+
/** A region name from `sdk.markets.regions()`; stored canonically. Invalid is a 400. */
|
|
1296
1300
|
county?: string;
|
|
1297
1301
|
}
|
|
1298
1302
|
interface UserProfile {
|
|
@@ -1438,13 +1442,24 @@ interface OAuthTokenExchangeInput {
|
|
|
1438
1442
|
client_secret?: string;
|
|
1439
1443
|
}
|
|
1440
1444
|
/**
|
|
1441
|
-
* Result of a successful token exchange
|
|
1445
|
+
* Result of a successful token exchange.
|
|
1446
|
+
*
|
|
1447
|
+
* What a client receives depends on its registration:
|
|
1448
|
+
*
|
|
1449
|
+
* - **The Mitumba marketplace** receives a Mitumba session: `access_token` plus `refresh_token`.
|
|
1450
|
+
* - **Every other relying party** receives an access token addressed only to itself (its `aud` is the
|
|
1451
|
+
* client's `client_id`), limited to the consented `scope`, plus an `id_token`. There is **no**
|
|
1452
|
+
* `refresh_token`: renew by repeating the authorization flow (silently with `prompt=none` where the
|
|
1453
|
+
* client is permitted). Verify both tokens against the published JWKS (`getJwks()`). The access
|
|
1454
|
+
* token is not accepted by Mitumba's APIs, only by `userinfo()` and the relying party's own API.
|
|
1442
1455
|
*/
|
|
1443
1456
|
interface OAuthTokenResult {
|
|
1444
1457
|
/** The access token (JWT) for authenticated requests. */
|
|
1445
1458
|
access_token: string;
|
|
1446
|
-
/** The refresh token used to rotate the access token. */
|
|
1447
|
-
refresh_token
|
|
1459
|
+
/** The refresh token used to rotate the access token. Present only for a Mitumba session. */
|
|
1460
|
+
refresh_token?: string;
|
|
1461
|
+
/** The OpenID Connect ID token (ES256). Always present for a relying party. */
|
|
1462
|
+
id_token?: string;
|
|
1448
1463
|
/** Lifetime of the access token in seconds. */
|
|
1449
1464
|
expires_in: number;
|
|
1450
1465
|
/** Always `'Bearer'`. */
|
|
@@ -2552,8 +2567,11 @@ interface Business {
|
|
|
2552
2567
|
seller_type: 'individual' | 'business';
|
|
2553
2568
|
kra_pin: string | null;
|
|
2554
2569
|
id_number: string | null;
|
|
2570
|
+
/** Canonical region name (e.g. `Trans-Nzoia`), from `sdk.markets.regions()`. */
|
|
2555
2571
|
county: string | null;
|
|
2556
2572
|
town: string | null;
|
|
2573
|
+
/** Contact / payout phone in E.164, e.g. `+254712345678`. */
|
|
2574
|
+
phone: string | null;
|
|
2557
2575
|
categories: string | null;
|
|
2558
2576
|
condition_grades: string | null;
|
|
2559
2577
|
delivery_method: 'self' | 'mitumba-logistics';
|
|
@@ -2568,8 +2586,17 @@ interface UpdateBusinessInput {
|
|
|
2568
2586
|
name?: string;
|
|
2569
2587
|
kra_pin?: string;
|
|
2570
2588
|
id_number?: string;
|
|
2571
|
-
|
|
2589
|
+
/**
|
|
2590
|
+
* A region name from `sdk.markets.regions()`; known alternative spellings are accepted and stored
|
|
2591
|
+
* canonically. Anything else is a 400 `invalid_county`. `null` or blank clears it.
|
|
2592
|
+
*/
|
|
2593
|
+
county?: string | null;
|
|
2572
2594
|
town?: string;
|
|
2595
|
+
/**
|
|
2596
|
+
* Contact / payout phone in any common local form (`0712 345 678`, `+254 712 345 678`); stored in
|
|
2597
|
+
* E.164. An invalid number is a 400 `invalid_phone`. `null` or blank clears it.
|
|
2598
|
+
*/
|
|
2599
|
+
phone?: string | null;
|
|
2573
2600
|
categories?: string[];
|
|
2574
2601
|
condition_grades?: string[];
|
|
2575
2602
|
delivery_method?: 'self' | 'mitumba-logistics';
|
|
@@ -3153,18 +3180,23 @@ declare class OAuthModule {
|
|
|
3153
3180
|
*/
|
|
3154
3181
|
authorize(input: OAuthAuthorizeInput, options?: RequestOptions): Promise<OAuthAuthorizeResult | OAuthConsentRequired>;
|
|
3155
3182
|
/**
|
|
3156
|
-
* Exchange a one-time authorization code for
|
|
3183
|
+
* Exchange a one-time authorization code for tokens.
|
|
3157
3184
|
*
|
|
3158
3185
|
* The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
|
|
3159
3186
|
* that matches the earlier challenge. The authorization code is single-use — a reused, expired,
|
|
3160
|
-
* or tampered code is rejected with `400 invalid_grant`.
|
|
3161
|
-
*
|
|
3162
|
-
*
|
|
3187
|
+
* or tampered code is rejected with `400 invalid_grant`. `grant_type` is set to
|
|
3188
|
+
* `'authorization_code'` by the SDK.
|
|
3189
|
+
*
|
|
3190
|
+
* When the result is a Mitumba session (it carries a `refresh_token`, as for the Mitumba
|
|
3191
|
+
* marketplace), the tokens are persisted into the client session via `setSession`, so the caller
|
|
3192
|
+
* is signed in immediately. Any other relying party receives an access token addressed only to
|
|
3193
|
+
* itself and no refresh token; that result is returned untouched and the client session is left
|
|
3194
|
+
* as it was, because such a token cannot call Mitumba's APIs or be refreshed.
|
|
3163
3195
|
*
|
|
3164
3196
|
* @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
|
|
3165
3197
|
* @param options - Optional per-request options (abort signal, extra headers)
|
|
3166
|
-
* @returns The access
|
|
3167
|
-
* @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code
|
|
3198
|
+
* @returns The access token, granted scope, and either a refresh token (Mitumba session) or an id_token (relying party)
|
|
3199
|
+
* @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code or withdrawn consent), `401 invalid_client` (wrong secret), or `503 temporarily_unavailable` (token signing unavailable)
|
|
3168
3200
|
*
|
|
3169
3201
|
* @example
|
|
3170
3202
|
* ```typescript
|
|
@@ -3200,13 +3232,17 @@ declare class OAuthModule {
|
|
|
3200
3232
|
*/
|
|
3201
3233
|
getJwks(options?: RequestOptions): Promise<Jwks>;
|
|
3202
3234
|
/**
|
|
3203
|
-
* Fetch the userinfo claim set
|
|
3235
|
+
* Fetch the userinfo claim set.
|
|
3204
3236
|
*
|
|
3205
|
-
* Returns `sub` plus the identity claims the
|
|
3206
|
-
*
|
|
3237
|
+
* Returns `sub` plus the identity claims the token's granted scopes allow. With a Mitumba session
|
|
3238
|
+
* the SDK attaches the session's bearer token automatically. A relying party, whose client holds no
|
|
3239
|
+
* Mitumba session (`exchangeCode()` does not set one for it), passes its own access token explicitly:
|
|
3240
|
+
* `sdk.oauth.userinfo({ headers: { Authorization: `Bearer ${tokens.access_token}` } })`. A custom
|
|
3241
|
+
* `Authorization` header never replaces an active session's token.
|
|
3207
3242
|
*
|
|
3208
3243
|
* @param options - Optional per-request options (abort signal, extra headers)
|
|
3209
3244
|
* @returns The userinfo claims
|
|
3245
|
+
* @throws {APIError} On `401` with no token, or `401 invalid_token` for a token that is expired, revoked, or no longer consented
|
|
3210
3246
|
*/
|
|
3211
3247
|
userinfo(options?: RequestOptions): Promise<UserInfo>;
|
|
3212
3248
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -1278,7 +1278,9 @@ interface BecomeSellerInput {
|
|
|
1278
1278
|
business_name?: string;
|
|
1279
1279
|
id_number?: string;
|
|
1280
1280
|
kra_pin?: string;
|
|
1281
|
+
/** Contact / payout phone in any common local form; stored on the business in E.164. Invalid is a 400. */
|
|
1281
1282
|
phone?: string;
|
|
1283
|
+
/** A region name from `sdk.markets.regions()`; stored canonically. Invalid is a 400. */
|
|
1282
1284
|
county?: string;
|
|
1283
1285
|
town?: string;
|
|
1284
1286
|
categories?: string[];
|
|
@@ -1292,7 +1294,9 @@ interface BecomeBaleSellerInput {
|
|
|
1292
1294
|
business_name?: string;
|
|
1293
1295
|
kra_pin?: string;
|
|
1294
1296
|
id_number?: string;
|
|
1297
|
+
/** Contact / payout phone in any common local form; stored on the business in E.164. Invalid is a 400. */
|
|
1295
1298
|
phone?: string;
|
|
1299
|
+
/** A region name from `sdk.markets.regions()`; stored canonically. Invalid is a 400. */
|
|
1296
1300
|
county?: string;
|
|
1297
1301
|
}
|
|
1298
1302
|
interface UserProfile {
|
|
@@ -1438,13 +1442,24 @@ interface OAuthTokenExchangeInput {
|
|
|
1438
1442
|
client_secret?: string;
|
|
1439
1443
|
}
|
|
1440
1444
|
/**
|
|
1441
|
-
* Result of a successful token exchange
|
|
1445
|
+
* Result of a successful token exchange.
|
|
1446
|
+
*
|
|
1447
|
+
* What a client receives depends on its registration:
|
|
1448
|
+
*
|
|
1449
|
+
* - **The Mitumba marketplace** receives a Mitumba session: `access_token` plus `refresh_token`.
|
|
1450
|
+
* - **Every other relying party** receives an access token addressed only to itself (its `aud` is the
|
|
1451
|
+
* client's `client_id`), limited to the consented `scope`, plus an `id_token`. There is **no**
|
|
1452
|
+
* `refresh_token`: renew by repeating the authorization flow (silently with `prompt=none` where the
|
|
1453
|
+
* client is permitted). Verify both tokens against the published JWKS (`getJwks()`). The access
|
|
1454
|
+
* token is not accepted by Mitumba's APIs, only by `userinfo()` and the relying party's own API.
|
|
1442
1455
|
*/
|
|
1443
1456
|
interface OAuthTokenResult {
|
|
1444
1457
|
/** The access token (JWT) for authenticated requests. */
|
|
1445
1458
|
access_token: string;
|
|
1446
|
-
/** The refresh token used to rotate the access token. */
|
|
1447
|
-
refresh_token
|
|
1459
|
+
/** The refresh token used to rotate the access token. Present only for a Mitumba session. */
|
|
1460
|
+
refresh_token?: string;
|
|
1461
|
+
/** The OpenID Connect ID token (ES256). Always present for a relying party. */
|
|
1462
|
+
id_token?: string;
|
|
1448
1463
|
/** Lifetime of the access token in seconds. */
|
|
1449
1464
|
expires_in: number;
|
|
1450
1465
|
/** Always `'Bearer'`. */
|
|
@@ -2552,8 +2567,11 @@ interface Business {
|
|
|
2552
2567
|
seller_type: 'individual' | 'business';
|
|
2553
2568
|
kra_pin: string | null;
|
|
2554
2569
|
id_number: string | null;
|
|
2570
|
+
/** Canonical region name (e.g. `Trans-Nzoia`), from `sdk.markets.regions()`. */
|
|
2555
2571
|
county: string | null;
|
|
2556
2572
|
town: string | null;
|
|
2573
|
+
/** Contact / payout phone in E.164, e.g. `+254712345678`. */
|
|
2574
|
+
phone: string | null;
|
|
2557
2575
|
categories: string | null;
|
|
2558
2576
|
condition_grades: string | null;
|
|
2559
2577
|
delivery_method: 'self' | 'mitumba-logistics';
|
|
@@ -2568,8 +2586,17 @@ interface UpdateBusinessInput {
|
|
|
2568
2586
|
name?: string;
|
|
2569
2587
|
kra_pin?: string;
|
|
2570
2588
|
id_number?: string;
|
|
2571
|
-
|
|
2589
|
+
/**
|
|
2590
|
+
* A region name from `sdk.markets.regions()`; known alternative spellings are accepted and stored
|
|
2591
|
+
* canonically. Anything else is a 400 `invalid_county`. `null` or blank clears it.
|
|
2592
|
+
*/
|
|
2593
|
+
county?: string | null;
|
|
2572
2594
|
town?: string;
|
|
2595
|
+
/**
|
|
2596
|
+
* Contact / payout phone in any common local form (`0712 345 678`, `+254 712 345 678`); stored in
|
|
2597
|
+
* E.164. An invalid number is a 400 `invalid_phone`. `null` or blank clears it.
|
|
2598
|
+
*/
|
|
2599
|
+
phone?: string | null;
|
|
2573
2600
|
categories?: string[];
|
|
2574
2601
|
condition_grades?: string[];
|
|
2575
2602
|
delivery_method?: 'self' | 'mitumba-logistics';
|
|
@@ -3153,18 +3180,23 @@ declare class OAuthModule {
|
|
|
3153
3180
|
*/
|
|
3154
3181
|
authorize(input: OAuthAuthorizeInput, options?: RequestOptions): Promise<OAuthAuthorizeResult | OAuthConsentRequired>;
|
|
3155
3182
|
/**
|
|
3156
|
-
* Exchange a one-time authorization code for
|
|
3183
|
+
* Exchange a one-time authorization code for tokens.
|
|
3157
3184
|
*
|
|
3158
3185
|
* The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
|
|
3159
3186
|
* that matches the earlier challenge. The authorization code is single-use — a reused, expired,
|
|
3160
|
-
* or tampered code is rejected with `400 invalid_grant`.
|
|
3161
|
-
*
|
|
3162
|
-
*
|
|
3187
|
+
* or tampered code is rejected with `400 invalid_grant`. `grant_type` is set to
|
|
3188
|
+
* `'authorization_code'` by the SDK.
|
|
3189
|
+
*
|
|
3190
|
+
* When the result is a Mitumba session (it carries a `refresh_token`, as for the Mitumba
|
|
3191
|
+
* marketplace), the tokens are persisted into the client session via `setSession`, so the caller
|
|
3192
|
+
* is signed in immediately. Any other relying party receives an access token addressed only to
|
|
3193
|
+
* itself and no refresh token; that result is returned untouched and the client session is left
|
|
3194
|
+
* as it was, because such a token cannot call Mitumba's APIs or be refreshed.
|
|
3163
3195
|
*
|
|
3164
3196
|
* @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
|
|
3165
3197
|
* @param options - Optional per-request options (abort signal, extra headers)
|
|
3166
|
-
* @returns The access
|
|
3167
|
-
* @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code
|
|
3198
|
+
* @returns The access token, granted scope, and either a refresh token (Mitumba session) or an id_token (relying party)
|
|
3199
|
+
* @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code or withdrawn consent), `401 invalid_client` (wrong secret), or `503 temporarily_unavailable` (token signing unavailable)
|
|
3168
3200
|
*
|
|
3169
3201
|
* @example
|
|
3170
3202
|
* ```typescript
|
|
@@ -3200,13 +3232,17 @@ declare class OAuthModule {
|
|
|
3200
3232
|
*/
|
|
3201
3233
|
getJwks(options?: RequestOptions): Promise<Jwks>;
|
|
3202
3234
|
/**
|
|
3203
|
-
* Fetch the userinfo claim set
|
|
3235
|
+
* Fetch the userinfo claim set.
|
|
3204
3236
|
*
|
|
3205
|
-
* Returns `sub` plus the identity claims the
|
|
3206
|
-
*
|
|
3237
|
+
* Returns `sub` plus the identity claims the token's granted scopes allow. With a Mitumba session
|
|
3238
|
+
* the SDK attaches the session's bearer token automatically. A relying party, whose client holds no
|
|
3239
|
+
* Mitumba session (`exchangeCode()` does not set one for it), passes its own access token explicitly:
|
|
3240
|
+
* `sdk.oauth.userinfo({ headers: { Authorization: `Bearer ${tokens.access_token}` } })`. A custom
|
|
3241
|
+
* `Authorization` header never replaces an active session's token.
|
|
3207
3242
|
*
|
|
3208
3243
|
* @param options - Optional per-request options (abort signal, extra headers)
|
|
3209
3244
|
* @returns The userinfo claims
|
|
3245
|
+
* @throws {APIError} On `401` with no token, or `401 invalid_token` for a token that is expired, revoked, or no longer consented
|
|
3210
3246
|
*/
|
|
3211
3247
|
userinfo(options?: RequestOptions): Promise<UserInfo>;
|
|
3212
3248
|
/**
|
package/dist/index.js
CHANGED
|
@@ -735,18 +735,23 @@ var OAuthModule = class {
|
|
|
735
735
|
);
|
|
736
736
|
}
|
|
737
737
|
/**
|
|
738
|
-
* Exchange a one-time authorization code for
|
|
738
|
+
* Exchange a one-time authorization code for tokens.
|
|
739
739
|
*
|
|
740
740
|
* The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
|
|
741
741
|
* that matches the earlier challenge. The authorization code is single-use — a reused, expired,
|
|
742
|
-
* or tampered code is rejected with `400 invalid_grant`.
|
|
743
|
-
*
|
|
744
|
-
*
|
|
742
|
+
* or tampered code is rejected with `400 invalid_grant`. `grant_type` is set to
|
|
743
|
+
* `'authorization_code'` by the SDK.
|
|
744
|
+
*
|
|
745
|
+
* When the result is a Mitumba session (it carries a `refresh_token`, as for the Mitumba
|
|
746
|
+
* marketplace), the tokens are persisted into the client session via `setSession`, so the caller
|
|
747
|
+
* is signed in immediately. Any other relying party receives an access token addressed only to
|
|
748
|
+
* itself and no refresh token; that result is returned untouched and the client session is left
|
|
749
|
+
* as it was, because such a token cannot call Mitumba's APIs or be refreshed.
|
|
745
750
|
*
|
|
746
751
|
* @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
|
|
747
752
|
* @param options - Optional per-request options (abort signal, extra headers)
|
|
748
|
-
* @returns The access
|
|
749
|
-
* @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code
|
|
753
|
+
* @returns The access token, granted scope, and either a refresh token (Mitumba session) or an id_token (relying party)
|
|
754
|
+
* @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code or withdrawn consent), `401 invalid_client` (wrong secret), or `503 temporarily_unavailable` (token signing unavailable)
|
|
750
755
|
*
|
|
751
756
|
* @example
|
|
752
757
|
* ```typescript
|
|
@@ -765,10 +770,12 @@ var OAuthModule = class {
|
|
|
765
770
|
{ ...input, grant_type: "authorization_code" },
|
|
766
771
|
options
|
|
767
772
|
);
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
773
|
+
if (result.refresh_token) {
|
|
774
|
+
await this.client.setSession({
|
|
775
|
+
access_token: result.access_token,
|
|
776
|
+
refresh_token: result.refresh_token
|
|
777
|
+
});
|
|
778
|
+
}
|
|
772
779
|
return result;
|
|
773
780
|
}
|
|
774
781
|
/**
|
|
@@ -797,13 +804,17 @@ var OAuthModule = class {
|
|
|
797
804
|
return this.client.get("/auth/oauth/jwks.json", void 0, options);
|
|
798
805
|
}
|
|
799
806
|
/**
|
|
800
|
-
* Fetch the userinfo claim set
|
|
807
|
+
* Fetch the userinfo claim set.
|
|
801
808
|
*
|
|
802
|
-
* Returns `sub` plus the identity claims the
|
|
803
|
-
*
|
|
809
|
+
* Returns `sub` plus the identity claims the token's granted scopes allow. With a Mitumba session
|
|
810
|
+
* the SDK attaches the session's bearer token automatically. A relying party, whose client holds no
|
|
811
|
+
* Mitumba session (`exchangeCode()` does not set one for it), passes its own access token explicitly:
|
|
812
|
+
* `sdk.oauth.userinfo({ headers: { Authorization: `Bearer ${tokens.access_token}` } })`. A custom
|
|
813
|
+
* `Authorization` header never replaces an active session's token.
|
|
804
814
|
*
|
|
805
815
|
* @param options - Optional per-request options (abort signal, extra headers)
|
|
806
816
|
* @returns The userinfo claims
|
|
817
|
+
* @throws {APIError} On `401` with no token, or `401 invalid_token` for a token that is expired, revoked, or no longer consented
|
|
807
818
|
*/
|
|
808
819
|
async userinfo(options) {
|
|
809
820
|
return this.client.get("/auth/oauth/userinfo", void 0, options);
|