@mitumba/sdk 3.1.0 → 5.0.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 CHANGED
@@ -1518,7 +1518,25 @@ interface Order {
1518
1518
  listing_condition: string | null;
1519
1519
  listing_size: string | null;
1520
1520
  buyer_name: string | null;
1521
+ /**
1522
+ * The buyer's county. Not sensitive — always returned to both parties, including to the seller
1523
+ * before payment (with `buyer_name`) while `buyer_phone`/`delivery_address` are withheld.
1524
+ * (Mitumba-Ltd/mitumba#321)
1525
+ */
1526
+ buyer_county: string | null;
1527
+ /**
1528
+ * The buyer's phone. Visible to the buyer at any status. Visible to the seller **only** while
1529
+ * they are handing the parcel over — statuses `paid`, `seller_confirmed`, `shipped`,
1530
+ * `delivered` — and `null` for the seller otherwise (before payment, and on `completed`,
1531
+ * `cancelled`, or `disputed`). Before payment a seller sees only `buyer_name` and the delivery
1532
+ * `county`. (Mitumba-Ltd/mitumba#321)
1533
+ */
1521
1534
  buyer_phone: string | null;
1535
+ /**
1536
+ * The buyer's delivery address. Same visibility rule as `buyer_phone`: always visible to the
1537
+ * buyer; visible to the seller only during the `paid`→`delivered` handover window, `null`
1538
+ * otherwise. (Mitumba-Ltd/mitumba#321)
1539
+ */
1522
1540
  delivery_address: DeliveryAddress | null;
1523
1541
  events?: OrderEvent[];
1524
1542
  }
@@ -2134,6 +2152,19 @@ interface CartItem {
2134
2152
  delivery_fee: number;
2135
2153
  }
2136
2154
 
2155
+ /**
2156
+ * Fields a user may change on their own profile via `PUT /auth/me`. Every field is optional;
2157
+ * only the ones provided are updated. The server enforces the profile contract:
2158
+ *
2159
+ * - `display_name`: non-empty, at most 80 characters.
2160
+ * - `phone`: canonical Kenyan E.164, `+254` followed by 9 digits. Must be unique — a number
2161
+ * already used by another account is rejected with `phone_taken` (409).
2162
+ * - `county`: one of Kenya's 47 canonical county names.
2163
+ * - `bio`: at most 500 characters.
2164
+ * - `avatar_url`: an absolute URL on a trusted Mitumba CDN origin (no arbitrary remote hosts).
2165
+ *
2166
+ * Invalid input is rejected with `invalid_input` (400). The updated `UserProfile` is returned.
2167
+ */
2137
2168
  interface UpdateProfileInput {
2138
2169
  display_name?: string;
2139
2170
  phone?: string;
@@ -2378,6 +2409,11 @@ declare class APIClient {
2378
2409
  /** Create an isomorphic WebSocket using the configured or global transport. */
2379
2410
  createWebSocket(url: string, protocols: string | string[]): WebSocketLike;
2380
2411
  clearToken(): Promise<void>;
2412
+ /**
2413
+ * The current stored refresh token, or null if none. Exposed so logout can revoke the exact
2414
+ * token the SDK holds rather than relying on the caller to supply (or guess) it.
2415
+ */
2416
+ getStoredRefreshToken(): Promise<string | null>;
2381
2417
  /**
2382
2418
  * Check if user has a stored session (access or refresh token available).
2383
2419
  */
@@ -2426,12 +2462,19 @@ declare class AuthModule {
2426
2462
  refresh_token: string;
2427
2463
  }, options?: RequestOptions): Promise<AuthTokens>;
2428
2464
  /**
2429
- * Revoke the refresh token and log out. Clears stored session.
2465
+ * Log out: revoke the current server session and clear the stored tokens.
2466
+ *
2467
+ * Reads the refresh token the SDK holds and revokes exactly that session server-side, then
2468
+ * always clears local tokens — even if the network call fails or there was no token — so the
2469
+ * device is signed out regardless. Idempotent: a second call is a no-op that still resolves.
2470
+ *
2471
+ * @returns `{ ok, revoked }` where `revoked` is true only when the server confirmed revocation.
2472
+ * `revoked: false` means local credentials were cleared but the server session may persist
2473
+ * until expiry (offline, or already revoked) — callers should not claim remote sign-out then.
2430
2474
  */
2431
- logout(input: {
2432
- refresh_token: string;
2433
- }, options?: RequestOptions): Promise<{
2475
+ logout(options?: RequestOptions): Promise<{
2434
2476
  ok: boolean;
2477
+ revoked: boolean;
2435
2478
  }>;
2436
2479
  /**
2437
2480
  * Request a password reset email.
@@ -3095,9 +3138,14 @@ declare class SettingsModule {
3095
3138
  private readonly client;
3096
3139
  constructor(client: APIClient);
3097
3140
  getProfile(options?: RequestOptions): Promise<UserProfile>;
3098
- updateProfile(input: UpdateProfileInput, options?: RequestOptions): Promise<{
3099
- ok: true;
3100
- }>;
3141
+ /**
3142
+ * Update the current user's profile. Only the provided fields change. Returns the updated
3143
+ * {@link UserProfile}. See {@link UpdateProfileInput} for the server-enforced contract.
3144
+ *
3145
+ * @throws {APIError} `invalid_input` (400) when a field violates the contract, and
3146
+ * `phone_taken` (409) when the phone number already belongs to another account.
3147
+ */
3148
+ updateProfile(input: UpdateProfileInput, options?: RequestOptions): Promise<UserProfile>;
3101
3149
  changePassword(input: ChangePasswordInput, options?: RequestOptions): Promise<{
3102
3150
  ok: true;
3103
3151
  }>;
package/dist/index.d.ts CHANGED
@@ -1518,7 +1518,25 @@ interface Order {
1518
1518
  listing_condition: string | null;
1519
1519
  listing_size: string | null;
1520
1520
  buyer_name: string | null;
1521
+ /**
1522
+ * The buyer's county. Not sensitive — always returned to both parties, including to the seller
1523
+ * before payment (with `buyer_name`) while `buyer_phone`/`delivery_address` are withheld.
1524
+ * (Mitumba-Ltd/mitumba#321)
1525
+ */
1526
+ buyer_county: string | null;
1527
+ /**
1528
+ * The buyer's phone. Visible to the buyer at any status. Visible to the seller **only** while
1529
+ * they are handing the parcel over — statuses `paid`, `seller_confirmed`, `shipped`,
1530
+ * `delivered` — and `null` for the seller otherwise (before payment, and on `completed`,
1531
+ * `cancelled`, or `disputed`). Before payment a seller sees only `buyer_name` and the delivery
1532
+ * `county`. (Mitumba-Ltd/mitumba#321)
1533
+ */
1521
1534
  buyer_phone: string | null;
1535
+ /**
1536
+ * The buyer's delivery address. Same visibility rule as `buyer_phone`: always visible to the
1537
+ * buyer; visible to the seller only during the `paid`→`delivered` handover window, `null`
1538
+ * otherwise. (Mitumba-Ltd/mitumba#321)
1539
+ */
1522
1540
  delivery_address: DeliveryAddress | null;
1523
1541
  events?: OrderEvent[];
1524
1542
  }
@@ -2134,6 +2152,19 @@ interface CartItem {
2134
2152
  delivery_fee: number;
2135
2153
  }
2136
2154
 
2155
+ /**
2156
+ * Fields a user may change on their own profile via `PUT /auth/me`. Every field is optional;
2157
+ * only the ones provided are updated. The server enforces the profile contract:
2158
+ *
2159
+ * - `display_name`: non-empty, at most 80 characters.
2160
+ * - `phone`: canonical Kenyan E.164, `+254` followed by 9 digits. Must be unique — a number
2161
+ * already used by another account is rejected with `phone_taken` (409).
2162
+ * - `county`: one of Kenya's 47 canonical county names.
2163
+ * - `bio`: at most 500 characters.
2164
+ * - `avatar_url`: an absolute URL on a trusted Mitumba CDN origin (no arbitrary remote hosts).
2165
+ *
2166
+ * Invalid input is rejected with `invalid_input` (400). The updated `UserProfile` is returned.
2167
+ */
2137
2168
  interface UpdateProfileInput {
2138
2169
  display_name?: string;
2139
2170
  phone?: string;
@@ -2378,6 +2409,11 @@ declare class APIClient {
2378
2409
  /** Create an isomorphic WebSocket using the configured or global transport. */
2379
2410
  createWebSocket(url: string, protocols: string | string[]): WebSocketLike;
2380
2411
  clearToken(): Promise<void>;
2412
+ /**
2413
+ * The current stored refresh token, or null if none. Exposed so logout can revoke the exact
2414
+ * token the SDK holds rather than relying on the caller to supply (or guess) it.
2415
+ */
2416
+ getStoredRefreshToken(): Promise<string | null>;
2381
2417
  /**
2382
2418
  * Check if user has a stored session (access or refresh token available).
2383
2419
  */
@@ -2426,12 +2462,19 @@ declare class AuthModule {
2426
2462
  refresh_token: string;
2427
2463
  }, options?: RequestOptions): Promise<AuthTokens>;
2428
2464
  /**
2429
- * Revoke the refresh token and log out. Clears stored session.
2465
+ * Log out: revoke the current server session and clear the stored tokens.
2466
+ *
2467
+ * Reads the refresh token the SDK holds and revokes exactly that session server-side, then
2468
+ * always clears local tokens — even if the network call fails or there was no token — so the
2469
+ * device is signed out regardless. Idempotent: a second call is a no-op that still resolves.
2470
+ *
2471
+ * @returns `{ ok, revoked }` where `revoked` is true only when the server confirmed revocation.
2472
+ * `revoked: false` means local credentials were cleared but the server session may persist
2473
+ * until expiry (offline, or already revoked) — callers should not claim remote sign-out then.
2430
2474
  */
2431
- logout(input: {
2432
- refresh_token: string;
2433
- }, options?: RequestOptions): Promise<{
2475
+ logout(options?: RequestOptions): Promise<{
2434
2476
  ok: boolean;
2477
+ revoked: boolean;
2435
2478
  }>;
2436
2479
  /**
2437
2480
  * Request a password reset email.
@@ -3095,9 +3138,14 @@ declare class SettingsModule {
3095
3138
  private readonly client;
3096
3139
  constructor(client: APIClient);
3097
3140
  getProfile(options?: RequestOptions): Promise<UserProfile>;
3098
- updateProfile(input: UpdateProfileInput, options?: RequestOptions): Promise<{
3099
- ok: true;
3100
- }>;
3141
+ /**
3142
+ * Update the current user's profile. Only the provided fields change. Returns the updated
3143
+ * {@link UserProfile}. See {@link UpdateProfileInput} for the server-enforced contract.
3144
+ *
3145
+ * @throws {APIError} `invalid_input` (400) when a field violates the contract, and
3146
+ * `phone_taken` (409) when the phone number already belongs to another account.
3147
+ */
3148
+ updateProfile(input: UpdateProfileInput, options?: RequestOptions): Promise<UserProfile>;
3101
3149
  changePassword(input: ChangePasswordInput, options?: RequestOptions): Promise<{
3102
3150
  ok: true;
3103
3151
  }>;
package/dist/index.js CHANGED
@@ -229,6 +229,13 @@ var APIClient = class {
229
229
  this.config.refreshToken = void 0;
230
230
  await this.tokenStore.clear();
231
231
  }
232
+ /**
233
+ * The current stored refresh token, or null if none. Exposed so logout can revoke the exact
234
+ * token the SDK holds rather than relying on the caller to supply (or guess) it.
235
+ */
236
+ async getStoredRefreshToken() {
237
+ return this.config.refreshToken ?? await this.tokenStore.getRefreshToken();
238
+ }
232
239
  /**
233
240
  * Check if user has a stored session (access or refresh token available).
234
241
  */
@@ -473,12 +480,28 @@ var AuthModule = class {
473
480
  return result;
474
481
  }
475
482
  /**
476
- * Revoke the refresh token and log out. Clears stored session.
483
+ * Log out: revoke the current server session and clear the stored tokens.
484
+ *
485
+ * Reads the refresh token the SDK holds and revokes exactly that session server-side, then
486
+ * always clears local tokens — even if the network call fails or there was no token — so the
487
+ * device is signed out regardless. Idempotent: a second call is a no-op that still resolves.
488
+ *
489
+ * @returns `{ ok, revoked }` where `revoked` is true only when the server confirmed revocation.
490
+ * `revoked: false` means local credentials were cleared but the server session may persist
491
+ * until expiry (offline, or already revoked) — callers should not claim remote sign-out then.
477
492
  */
478
- async logout(input, options) {
479
- const result = await this.client.post("/auth/logout", input, options);
480
- await this.client.clearToken();
481
- return result;
493
+ async logout(options) {
494
+ const refreshToken = await this.client.getStoredRefreshToken();
495
+ let revoked = false;
496
+ try {
497
+ if (refreshToken) {
498
+ await this.client.post("/auth/logout", { refresh_token: refreshToken }, options);
499
+ revoked = true;
500
+ }
501
+ } finally {
502
+ await this.client.clearToken();
503
+ }
504
+ return { ok: true, revoked };
482
505
  }
483
506
  /**
484
507
  * Request a password reset email.
@@ -1828,6 +1851,13 @@ var SettingsModule = class {
1828
1851
  async getProfile(options) {
1829
1852
  return this.client.get("/auth/me", void 0, options);
1830
1853
  }
1854
+ /**
1855
+ * Update the current user's profile. Only the provided fields change. Returns the updated
1856
+ * {@link UserProfile}. See {@link UpdateProfileInput} for the server-enforced contract.
1857
+ *
1858
+ * @throws {APIError} `invalid_input` (400) when a field violates the contract, and
1859
+ * `phone_taken` (409) when the phone number already belongs to another account.
1860
+ */
1831
1861
  async updateProfile(input, options) {
1832
1862
  return this.client.put("/auth/me", input, options);
1833
1863
  }