@mitumba/sdk 1.17.0 → 1.19.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 +46 -10
- package/dist/index.d.ts +46 -10
- package/dist/index.js +74 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +74 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -423,6 +423,21 @@ interface Store {
|
|
|
423
423
|
follower_count?: number;
|
|
424
424
|
is_following?: boolean;
|
|
425
425
|
}
|
|
426
|
+
interface FollowedStore {
|
|
427
|
+
id: string;
|
|
428
|
+
name: string;
|
|
429
|
+
slug: string;
|
|
430
|
+
logo_url: string | null;
|
|
431
|
+
banner_url: string | null;
|
|
432
|
+
category: string | null;
|
|
433
|
+
is_verified: boolean;
|
|
434
|
+
sti_score: number | null;
|
|
435
|
+
city_name: string | null;
|
|
436
|
+
follower_count: number;
|
|
437
|
+
listing_count: number;
|
|
438
|
+
followed_at: string;
|
|
439
|
+
is_following: true;
|
|
440
|
+
}
|
|
426
441
|
interface CreateStoreInput {
|
|
427
442
|
name: string;
|
|
428
443
|
slug: string;
|
|
@@ -957,6 +972,14 @@ declare class APIClient {
|
|
|
957
972
|
private refreshPromise;
|
|
958
973
|
constructor(config: MitumbaClientConfig);
|
|
959
974
|
setToken(token: string, refreshToken?: string): Promise<void>;
|
|
975
|
+
/**
|
|
976
|
+
* Set both tokens explicitly. Requires a valid refresh token.
|
|
977
|
+
* Preferred over setToken() to avoid dropping the refresh token.
|
|
978
|
+
*/
|
|
979
|
+
setSession(tokens: {
|
|
980
|
+
access_token: string;
|
|
981
|
+
refresh_token: string;
|
|
982
|
+
}): Promise<void>;
|
|
960
983
|
getToken(): string | undefined;
|
|
961
984
|
getBaseUrl(): string;
|
|
962
985
|
clearToken(): Promise<void>;
|
|
@@ -983,13 +1006,13 @@ declare class AuthModule {
|
|
|
983
1006
|
constructor(client: APIClient);
|
|
984
1007
|
/**
|
|
985
1008
|
* Register a new account.
|
|
986
|
-
* If using EmailRegisterInput, returns AuthTokens.
|
|
1009
|
+
* If using EmailRegisterInput, returns AuthTokens (auto-persisted).
|
|
987
1010
|
* If using PhoneRegisterInput, returns MessageResponse (OTP sent).
|
|
988
1011
|
*/
|
|
989
1012
|
register(input: RegisterInput, options?: RequestOptions): Promise<AuthTokens | MessageResponse>;
|
|
990
1013
|
/**
|
|
991
1014
|
* Log in to an existing account.
|
|
992
|
-
* If using EmailLoginInput, returns AuthTokens (or TwoFactorRequired
|
|
1015
|
+
* If using EmailLoginInput, returns AuthTokens (auto-persisted) or TwoFactorRequired.
|
|
993
1016
|
* If using PhoneLoginInput, returns MessageResponse (OTP sent).
|
|
994
1017
|
*/
|
|
995
1018
|
login(input: LoginInput, options?: RequestOptions): Promise<AuthTokens | MessageResponse | TwoFactorRequired>;
|
|
@@ -998,7 +1021,7 @@ declare class AuthModule {
|
|
|
998
1021
|
*/
|
|
999
1022
|
sendOtp(input: SendOtpInput, options?: RequestOptions): Promise<MessageResponse>;
|
|
1000
1023
|
/**
|
|
1001
|
-
* Verify an OTP code.
|
|
1024
|
+
* Verify an OTP code. Tokens are auto-persisted.
|
|
1002
1025
|
*/
|
|
1003
1026
|
verifyOtp(input: VerifyOtpInput, options?: RequestOptions): Promise<AuthTokens>;
|
|
1004
1027
|
/**
|
|
@@ -1008,7 +1031,7 @@ declare class AuthModule {
|
|
|
1008
1031
|
refresh_token: string;
|
|
1009
1032
|
}, options?: RequestOptions): Promise<AuthTokens>;
|
|
1010
1033
|
/**
|
|
1011
|
-
* Revoke the refresh token and log out.
|
|
1034
|
+
* Revoke the refresh token and log out. Clears stored session.
|
|
1012
1035
|
*/
|
|
1013
1036
|
logout(input: {
|
|
1014
1037
|
refresh_token: string;
|
|
@@ -1017,7 +1040,6 @@ declare class AuthModule {
|
|
|
1017
1040
|
}>;
|
|
1018
1041
|
/**
|
|
1019
1042
|
* Request a password reset email.
|
|
1020
|
-
* Sends a reset link to the provided email address.
|
|
1021
1043
|
*/
|
|
1022
1044
|
forgotPassword(input: ForgotPasswordInput, options?: RequestOptions): Promise<MessageResponse>;
|
|
1023
1045
|
/**
|
|
@@ -1035,26 +1057,23 @@ declare class AuthModule {
|
|
|
1035
1057
|
ok: true;
|
|
1036
1058
|
}>;
|
|
1037
1059
|
/**
|
|
1038
|
-
* Verify 2FA code during login
|
|
1060
|
+
* Verify 2FA code during login. Tokens are auto-persisted.
|
|
1039
1061
|
*/
|
|
1040
1062
|
verify2FA(input: Verify2FAInput, options?: RequestOptions): Promise<AuthTokens>;
|
|
1041
1063
|
/**
|
|
1042
1064
|
* Send a verification code to the user's email.
|
|
1043
|
-
* If unauthenticated, pass the email address.
|
|
1044
1065
|
*/
|
|
1045
1066
|
sendVerificationCode(email?: string, options?: RequestOptions): Promise<{
|
|
1046
1067
|
ok: true;
|
|
1047
1068
|
}>;
|
|
1048
1069
|
/**
|
|
1049
1070
|
* Verify the email with the 6-digit code.
|
|
1050
|
-
* If unauthenticated, pass the email address.
|
|
1051
1071
|
*/
|
|
1052
1072
|
verifyEmail(code: string, email?: string, options?: RequestOptions): Promise<{
|
|
1053
1073
|
ok: true;
|
|
1054
1074
|
}>;
|
|
1055
1075
|
/**
|
|
1056
1076
|
* Upgrade the current user to a seller role.
|
|
1057
|
-
* Idempotent — returns success if already a seller.
|
|
1058
1077
|
*/
|
|
1059
1078
|
becomeSeller(input: BecomeSellerInput, options?: RequestOptions): Promise<{
|
|
1060
1079
|
ok: true;
|
|
@@ -1372,6 +1391,16 @@ declare class StoresModule {
|
|
|
1372
1391
|
getMyStores(options?: RequestOptions): Promise<{
|
|
1373
1392
|
data: Store[];
|
|
1374
1393
|
}>;
|
|
1394
|
+
/**
|
|
1395
|
+
* Get stores the authenticated user follows.
|
|
1396
|
+
*/
|
|
1397
|
+
getFollowing(params?: {
|
|
1398
|
+
page?: number;
|
|
1399
|
+
}, options?: RequestOptions): Promise<{
|
|
1400
|
+
data: FollowedStore[];
|
|
1401
|
+
page: number;
|
|
1402
|
+
page_size: number;
|
|
1403
|
+
}>;
|
|
1375
1404
|
/**
|
|
1376
1405
|
* Create a new store.
|
|
1377
1406
|
*/
|
|
@@ -1902,6 +1931,13 @@ declare class MitumbaClient {
|
|
|
1902
1931
|
* Optionally pass a refresh token to enable automatic token rotation.
|
|
1903
1932
|
*/
|
|
1904
1933
|
setToken(token: string, refreshToken?: string): void;
|
|
1934
|
+
/**
|
|
1935
|
+
* Set both tokens explicitly. Preferred — prevents dropping the refresh token.
|
|
1936
|
+
*/
|
|
1937
|
+
setSession(tokens: {
|
|
1938
|
+
access_token: string;
|
|
1939
|
+
refresh_token: string;
|
|
1940
|
+
}): Promise<void>;
|
|
1905
1941
|
/**
|
|
1906
1942
|
* Get the current access token.
|
|
1907
1943
|
*/
|
|
@@ -1920,4 +1956,4 @@ declare class MitumbaClient {
|
|
|
1920
1956
|
isAuthenticated(): Promise<boolean>;
|
|
1921
1957
|
}
|
|
1922
1958
|
|
|
1923
|
-
export { APIClient, APIError, type APIErrorResponse, type AddAddressInput, type AddPaymentMethodInput, type Address, type AdminListingItem, AdminModule, type AdminOrderDetail, type AdminOrderListItem, type AdminPayoutItem, type AdminReport, type AdminStoreDetail, type AdminStoreListItem, type AdminUserDetail, type AdminUserListItem, type AdminVaziOutfit, type AdminVerificationItem, AuthModule, type AuthTokens, type BecomeSellerInput, type BlockedIp, type Business, BusinessesModule, CONDITIONS, type CartItem, CartModule, type Category, type ChangePasswordInput, type City, type CompleteOnboardingInput, type Condition, type Conversation, type CreateListingInput, type CreateOrderInput, type CreateReportInput, type CreateReviewInput, type CreateStoreInput, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, type DeliveryAddress, type DesiredResolution, type Dispute, type DisputeEvent, type DisputeEvidence, type DisputeListParams, type DisputeReason, type DisputeStatus, DisputesModule, type EmailLoginInput, type EmailRegisterInput, type ForgotPasswordInput, IDBTokenStore, LISTING_STATUSES, type LinkedAccount, type LinkedAccountProvider, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, MemoryTokenStore, type Message, type MessageResponse, MessagesModule, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, ORDER_STATUSES, type Order, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, PAYMENT_STATUSES, type PaginatedResponse, PayModule, type PaymentMethod, type PaymentMethodType, type PaymentStatus, type PaymentStatusResponse, type PaystackInitResponse, type PaystackInput, type PhoneLoginInput, type PhoneRegisterInput, type PresignImageResponse, type RaiseDisputeInput, type RegisterInput, ReportsModule, type RequestOptions, type ResetPasswordInput, type ResolveDisputeInput, type RespondDisputeInput, type Review, type ReviewableOrder, ReviewsModule, type SaveSearchInput, type SearchHistoryItem, SearchModule, type SearchParams, type SearchResult, type SellerProfile, type SellerStorefront, type SendEmailInput, type SendMessageInput, type SendOtpInput, type Session, SettingsModule, type SimilarListing, type StiEvent, type StkPushInput, type StkPushResponse, type Store, type StoreAnalytics, type StoreSettings, type StoreStats, StoresModule, type SubscriptionTier, type SystemStats, type TokenStore, type TransitionOrderInput, type TrendingTerm, type TwoFactorRequired, type UpdateBusinessInput, type UpdateListingInput, type UpdateProfileInput, type UpdateStoreInput, UploadsModule, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyOtpInput, type WishlistListing, WishlistsModule, createTokenStore };
|
|
1959
|
+
export { APIClient, APIError, type APIErrorResponse, type AddAddressInput, type AddPaymentMethodInput, type Address, type AdminListingItem, AdminModule, type AdminOrderDetail, type AdminOrderListItem, type AdminPayoutItem, type AdminReport, type AdminStoreDetail, type AdminStoreListItem, type AdminUserDetail, type AdminUserListItem, type AdminVaziOutfit, type AdminVerificationItem, AuthModule, type AuthTokens, type BecomeSellerInput, type BlockedIp, type Business, BusinessesModule, CONDITIONS, type CartItem, CartModule, type Category, type ChangePasswordInput, type City, type CompleteOnboardingInput, type Condition, type Conversation, type CreateListingInput, type CreateOrderInput, type CreateReportInput, type CreateReviewInput, type CreateStoreInput, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, type DeliveryAddress, type DesiredResolution, type Dispute, type DisputeEvent, type DisputeEvidence, type DisputeListParams, type DisputeReason, type DisputeStatus, DisputesModule, type EmailLoginInput, type EmailRegisterInput, type FollowedStore, type ForgotPasswordInput, IDBTokenStore, LISTING_STATUSES, type LinkedAccount, type LinkedAccountProvider, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, MemoryTokenStore, type Message, type MessageResponse, MessagesModule, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, ORDER_STATUSES, type Order, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, PAYMENT_STATUSES, type PaginatedResponse, PayModule, type PaymentMethod, type PaymentMethodType, type PaymentStatus, type PaymentStatusResponse, type PaystackInitResponse, type PaystackInput, type PhoneLoginInput, type PhoneRegisterInput, type PresignImageResponse, type RaiseDisputeInput, type RegisterInput, ReportsModule, type RequestOptions, type ResetPasswordInput, type ResolveDisputeInput, type RespondDisputeInput, type Review, type ReviewableOrder, ReviewsModule, type SaveSearchInput, type SearchHistoryItem, SearchModule, type SearchParams, type SearchResult, type SellerProfile, type SellerStorefront, type SendEmailInput, type SendMessageInput, type SendOtpInput, type Session, SettingsModule, type SimilarListing, type StiEvent, type StkPushInput, type StkPushResponse, type Store, type StoreAnalytics, type StoreSettings, type StoreStats, StoresModule, type SubscriptionTier, type SystemStats, type TokenStore, type TransitionOrderInput, type TrendingTerm, type TwoFactorRequired, type UpdateBusinessInput, type UpdateListingInput, type UpdateProfileInput, type UpdateStoreInput, UploadsModule, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyOtpInput, type WishlistListing, WishlistsModule, createTokenStore };
|
package/dist/index.d.ts
CHANGED
|
@@ -423,6 +423,21 @@ interface Store {
|
|
|
423
423
|
follower_count?: number;
|
|
424
424
|
is_following?: boolean;
|
|
425
425
|
}
|
|
426
|
+
interface FollowedStore {
|
|
427
|
+
id: string;
|
|
428
|
+
name: string;
|
|
429
|
+
slug: string;
|
|
430
|
+
logo_url: string | null;
|
|
431
|
+
banner_url: string | null;
|
|
432
|
+
category: string | null;
|
|
433
|
+
is_verified: boolean;
|
|
434
|
+
sti_score: number | null;
|
|
435
|
+
city_name: string | null;
|
|
436
|
+
follower_count: number;
|
|
437
|
+
listing_count: number;
|
|
438
|
+
followed_at: string;
|
|
439
|
+
is_following: true;
|
|
440
|
+
}
|
|
426
441
|
interface CreateStoreInput {
|
|
427
442
|
name: string;
|
|
428
443
|
slug: string;
|
|
@@ -957,6 +972,14 @@ declare class APIClient {
|
|
|
957
972
|
private refreshPromise;
|
|
958
973
|
constructor(config: MitumbaClientConfig);
|
|
959
974
|
setToken(token: string, refreshToken?: string): Promise<void>;
|
|
975
|
+
/**
|
|
976
|
+
* Set both tokens explicitly. Requires a valid refresh token.
|
|
977
|
+
* Preferred over setToken() to avoid dropping the refresh token.
|
|
978
|
+
*/
|
|
979
|
+
setSession(tokens: {
|
|
980
|
+
access_token: string;
|
|
981
|
+
refresh_token: string;
|
|
982
|
+
}): Promise<void>;
|
|
960
983
|
getToken(): string | undefined;
|
|
961
984
|
getBaseUrl(): string;
|
|
962
985
|
clearToken(): Promise<void>;
|
|
@@ -983,13 +1006,13 @@ declare class AuthModule {
|
|
|
983
1006
|
constructor(client: APIClient);
|
|
984
1007
|
/**
|
|
985
1008
|
* Register a new account.
|
|
986
|
-
* If using EmailRegisterInput, returns AuthTokens.
|
|
1009
|
+
* If using EmailRegisterInput, returns AuthTokens (auto-persisted).
|
|
987
1010
|
* If using PhoneRegisterInput, returns MessageResponse (OTP sent).
|
|
988
1011
|
*/
|
|
989
1012
|
register(input: RegisterInput, options?: RequestOptions): Promise<AuthTokens | MessageResponse>;
|
|
990
1013
|
/**
|
|
991
1014
|
* Log in to an existing account.
|
|
992
|
-
* If using EmailLoginInput, returns AuthTokens (or TwoFactorRequired
|
|
1015
|
+
* If using EmailLoginInput, returns AuthTokens (auto-persisted) or TwoFactorRequired.
|
|
993
1016
|
* If using PhoneLoginInput, returns MessageResponse (OTP sent).
|
|
994
1017
|
*/
|
|
995
1018
|
login(input: LoginInput, options?: RequestOptions): Promise<AuthTokens | MessageResponse | TwoFactorRequired>;
|
|
@@ -998,7 +1021,7 @@ declare class AuthModule {
|
|
|
998
1021
|
*/
|
|
999
1022
|
sendOtp(input: SendOtpInput, options?: RequestOptions): Promise<MessageResponse>;
|
|
1000
1023
|
/**
|
|
1001
|
-
* Verify an OTP code.
|
|
1024
|
+
* Verify an OTP code. Tokens are auto-persisted.
|
|
1002
1025
|
*/
|
|
1003
1026
|
verifyOtp(input: VerifyOtpInput, options?: RequestOptions): Promise<AuthTokens>;
|
|
1004
1027
|
/**
|
|
@@ -1008,7 +1031,7 @@ declare class AuthModule {
|
|
|
1008
1031
|
refresh_token: string;
|
|
1009
1032
|
}, options?: RequestOptions): Promise<AuthTokens>;
|
|
1010
1033
|
/**
|
|
1011
|
-
* Revoke the refresh token and log out.
|
|
1034
|
+
* Revoke the refresh token and log out. Clears stored session.
|
|
1012
1035
|
*/
|
|
1013
1036
|
logout(input: {
|
|
1014
1037
|
refresh_token: string;
|
|
@@ -1017,7 +1040,6 @@ declare class AuthModule {
|
|
|
1017
1040
|
}>;
|
|
1018
1041
|
/**
|
|
1019
1042
|
* Request a password reset email.
|
|
1020
|
-
* Sends a reset link to the provided email address.
|
|
1021
1043
|
*/
|
|
1022
1044
|
forgotPassword(input: ForgotPasswordInput, options?: RequestOptions): Promise<MessageResponse>;
|
|
1023
1045
|
/**
|
|
@@ -1035,26 +1057,23 @@ declare class AuthModule {
|
|
|
1035
1057
|
ok: true;
|
|
1036
1058
|
}>;
|
|
1037
1059
|
/**
|
|
1038
|
-
* Verify 2FA code during login
|
|
1060
|
+
* Verify 2FA code during login. Tokens are auto-persisted.
|
|
1039
1061
|
*/
|
|
1040
1062
|
verify2FA(input: Verify2FAInput, options?: RequestOptions): Promise<AuthTokens>;
|
|
1041
1063
|
/**
|
|
1042
1064
|
* Send a verification code to the user's email.
|
|
1043
|
-
* If unauthenticated, pass the email address.
|
|
1044
1065
|
*/
|
|
1045
1066
|
sendVerificationCode(email?: string, options?: RequestOptions): Promise<{
|
|
1046
1067
|
ok: true;
|
|
1047
1068
|
}>;
|
|
1048
1069
|
/**
|
|
1049
1070
|
* Verify the email with the 6-digit code.
|
|
1050
|
-
* If unauthenticated, pass the email address.
|
|
1051
1071
|
*/
|
|
1052
1072
|
verifyEmail(code: string, email?: string, options?: RequestOptions): Promise<{
|
|
1053
1073
|
ok: true;
|
|
1054
1074
|
}>;
|
|
1055
1075
|
/**
|
|
1056
1076
|
* Upgrade the current user to a seller role.
|
|
1057
|
-
* Idempotent — returns success if already a seller.
|
|
1058
1077
|
*/
|
|
1059
1078
|
becomeSeller(input: BecomeSellerInput, options?: RequestOptions): Promise<{
|
|
1060
1079
|
ok: true;
|
|
@@ -1372,6 +1391,16 @@ declare class StoresModule {
|
|
|
1372
1391
|
getMyStores(options?: RequestOptions): Promise<{
|
|
1373
1392
|
data: Store[];
|
|
1374
1393
|
}>;
|
|
1394
|
+
/**
|
|
1395
|
+
* Get stores the authenticated user follows.
|
|
1396
|
+
*/
|
|
1397
|
+
getFollowing(params?: {
|
|
1398
|
+
page?: number;
|
|
1399
|
+
}, options?: RequestOptions): Promise<{
|
|
1400
|
+
data: FollowedStore[];
|
|
1401
|
+
page: number;
|
|
1402
|
+
page_size: number;
|
|
1403
|
+
}>;
|
|
1375
1404
|
/**
|
|
1376
1405
|
* Create a new store.
|
|
1377
1406
|
*/
|
|
@@ -1902,6 +1931,13 @@ declare class MitumbaClient {
|
|
|
1902
1931
|
* Optionally pass a refresh token to enable automatic token rotation.
|
|
1903
1932
|
*/
|
|
1904
1933
|
setToken(token: string, refreshToken?: string): void;
|
|
1934
|
+
/**
|
|
1935
|
+
* Set both tokens explicitly. Preferred — prevents dropping the refresh token.
|
|
1936
|
+
*/
|
|
1937
|
+
setSession(tokens: {
|
|
1938
|
+
access_token: string;
|
|
1939
|
+
refresh_token: string;
|
|
1940
|
+
}): Promise<void>;
|
|
1905
1941
|
/**
|
|
1906
1942
|
* Get the current access token.
|
|
1907
1943
|
*/
|
|
@@ -1920,4 +1956,4 @@ declare class MitumbaClient {
|
|
|
1920
1956
|
isAuthenticated(): Promise<boolean>;
|
|
1921
1957
|
}
|
|
1922
1958
|
|
|
1923
|
-
export { APIClient, APIError, type APIErrorResponse, type AddAddressInput, type AddPaymentMethodInput, type Address, type AdminListingItem, AdminModule, type AdminOrderDetail, type AdminOrderListItem, type AdminPayoutItem, type AdminReport, type AdminStoreDetail, type AdminStoreListItem, type AdminUserDetail, type AdminUserListItem, type AdminVaziOutfit, type AdminVerificationItem, AuthModule, type AuthTokens, type BecomeSellerInput, type BlockedIp, type Business, BusinessesModule, CONDITIONS, type CartItem, CartModule, type Category, type ChangePasswordInput, type City, type CompleteOnboardingInput, type Condition, type Conversation, type CreateListingInput, type CreateOrderInput, type CreateReportInput, type CreateReviewInput, type CreateStoreInput, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, type DeliveryAddress, type DesiredResolution, type Dispute, type DisputeEvent, type DisputeEvidence, type DisputeListParams, type DisputeReason, type DisputeStatus, DisputesModule, type EmailLoginInput, type EmailRegisterInput, type ForgotPasswordInput, IDBTokenStore, LISTING_STATUSES, type LinkedAccount, type LinkedAccountProvider, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, MemoryTokenStore, type Message, type MessageResponse, MessagesModule, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, ORDER_STATUSES, type Order, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, PAYMENT_STATUSES, type PaginatedResponse, PayModule, type PaymentMethod, type PaymentMethodType, type PaymentStatus, type PaymentStatusResponse, type PaystackInitResponse, type PaystackInput, type PhoneLoginInput, type PhoneRegisterInput, type PresignImageResponse, type RaiseDisputeInput, type RegisterInput, ReportsModule, type RequestOptions, type ResetPasswordInput, type ResolveDisputeInput, type RespondDisputeInput, type Review, type ReviewableOrder, ReviewsModule, type SaveSearchInput, type SearchHistoryItem, SearchModule, type SearchParams, type SearchResult, type SellerProfile, type SellerStorefront, type SendEmailInput, type SendMessageInput, type SendOtpInput, type Session, SettingsModule, type SimilarListing, type StiEvent, type StkPushInput, type StkPushResponse, type Store, type StoreAnalytics, type StoreSettings, type StoreStats, StoresModule, type SubscriptionTier, type SystemStats, type TokenStore, type TransitionOrderInput, type TrendingTerm, type TwoFactorRequired, type UpdateBusinessInput, type UpdateListingInput, type UpdateProfileInput, type UpdateStoreInput, UploadsModule, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyOtpInput, type WishlistListing, WishlistsModule, createTokenStore };
|
|
1959
|
+
export { APIClient, APIError, type APIErrorResponse, type AddAddressInput, type AddPaymentMethodInput, type Address, type AdminListingItem, AdminModule, type AdminOrderDetail, type AdminOrderListItem, type AdminPayoutItem, type AdminReport, type AdminStoreDetail, type AdminStoreListItem, type AdminUserDetail, type AdminUserListItem, type AdminVaziOutfit, type AdminVerificationItem, AuthModule, type AuthTokens, type BecomeSellerInput, type BlockedIp, type Business, BusinessesModule, CONDITIONS, type CartItem, CartModule, type Category, type ChangePasswordInput, type City, type CompleteOnboardingInput, type Condition, type Conversation, type CreateListingInput, type CreateOrderInput, type CreateReportInput, type CreateReviewInput, type CreateStoreInput, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, type DeliveryAddress, type DesiredResolution, type Dispute, type DisputeEvent, type DisputeEvidence, type DisputeListParams, type DisputeReason, type DisputeStatus, DisputesModule, type EmailLoginInput, type EmailRegisterInput, type FollowedStore, type ForgotPasswordInput, IDBTokenStore, LISTING_STATUSES, type LinkedAccount, type LinkedAccountProvider, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, MemoryTokenStore, type Message, type MessageResponse, MessagesModule, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, ORDER_STATUSES, type Order, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, PAYMENT_STATUSES, type PaginatedResponse, PayModule, type PaymentMethod, type PaymentMethodType, type PaymentStatus, type PaymentStatusResponse, type PaystackInitResponse, type PaystackInput, type PhoneLoginInput, type PhoneRegisterInput, type PresignImageResponse, type RaiseDisputeInput, type RegisterInput, ReportsModule, type RequestOptions, type ResetPasswordInput, type ResolveDisputeInput, type RespondDisputeInput, type Review, type ReviewableOrder, ReviewsModule, type SaveSearchInput, type SearchHistoryItem, SearchModule, type SearchParams, type SearchResult, type SellerProfile, type SellerStorefront, type SendEmailInput, type SendMessageInput, type SendOtpInput, type Session, SettingsModule, type SimilarListing, type StiEvent, type StkPushInput, type StkPushResponse, type Store, type StoreAnalytics, type StoreSettings, type StoreStats, StoresModule, type SubscriptionTier, type SystemStats, type TokenStore, type TransitionOrderInput, type TrendingTerm, type TwoFactorRequired, type UpdateBusinessInput, type UpdateListingInput, type UpdateProfileInput, type UpdateStoreInput, UploadsModule, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyOtpInput, type WishlistListing, WishlistsModule, createTokenStore };
|
package/dist/index.js
CHANGED
|
@@ -110,15 +110,25 @@ var APIClient = class {
|
|
|
110
110
|
this.config = config;
|
|
111
111
|
this.tokenStore = config.tokenStore ?? createTokenStore();
|
|
112
112
|
if (config.token) {
|
|
113
|
-
this.tokenStore.setTokens(config.token, config.refreshToken
|
|
113
|
+
this.tokenStore.setTokens(config.token, config.refreshToken || "");
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
async setToken(token, refreshToken) {
|
|
117
117
|
this.config.token = token;
|
|
118
|
-
if (refreshToken) {
|
|
118
|
+
if (refreshToken && refreshToken.length > 0) {
|
|
119
119
|
this.config.refreshToken = refreshToken;
|
|
120
120
|
}
|
|
121
|
-
|
|
121
|
+
const effectiveRefresh = refreshToken && refreshToken.length > 0 ? refreshToken : this.config.refreshToken && this.config.refreshToken.length > 0 ? this.config.refreshToken : "";
|
|
122
|
+
await this.tokenStore.setTokens(token, effectiveRefresh);
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Set both tokens explicitly. Requires a valid refresh token.
|
|
126
|
+
* Preferred over setToken() to avoid dropping the refresh token.
|
|
127
|
+
*/
|
|
128
|
+
async setSession(tokens) {
|
|
129
|
+
this.config.token = tokens.access_token;
|
|
130
|
+
this.config.refreshToken = tokens.refresh_token;
|
|
131
|
+
await this.tokenStore.setTokens(tokens.access_token, tokens.refresh_token);
|
|
122
132
|
}
|
|
123
133
|
getToken() {
|
|
124
134
|
return this.config.token;
|
|
@@ -156,7 +166,7 @@ var APIClient = class {
|
|
|
156
166
|
const refresh = await this.tokenStore.getRefreshToken();
|
|
157
167
|
if (refresh) this.config.refreshToken = refresh;
|
|
158
168
|
}
|
|
159
|
-
if (this.config.token && isExpiringSoon(this.config.token, 60) && this.config.refreshToken) {
|
|
169
|
+
if (this.config.token && isExpiringSoon(this.config.token, 60) && this.config.refreshToken && this.config.refreshToken.length > 0) {
|
|
160
170
|
await this.handleTokenRefresh();
|
|
161
171
|
}
|
|
162
172
|
}
|
|
@@ -222,12 +232,20 @@ var APIClient = class {
|
|
|
222
232
|
}
|
|
223
233
|
break;
|
|
224
234
|
}
|
|
225
|
-
if (response.status === 401 &&
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
235
|
+
if (response.status === 401 && !path.includes("/auth/refresh") && !path.includes("/auth/login") && !path.includes("/auth/register")) {
|
|
236
|
+
const hasRefreshToken = this.config.refreshToken && this.config.refreshToken.length > 0;
|
|
237
|
+
if (hasRefreshToken) {
|
|
238
|
+
try {
|
|
239
|
+
await this.handleTokenRefresh();
|
|
240
|
+
headers.set("Authorization", `Bearer ${this.config.token}`);
|
|
241
|
+
response = await fetch(url.toString(), { ...init, headers });
|
|
242
|
+
} catch {
|
|
243
|
+
if (this.config.onAuthExpired) {
|
|
244
|
+
this.config.onAuthExpired();
|
|
245
|
+
}
|
|
246
|
+
throw new APIError(401, { error: "session_expired", message: "Session expired. Please log in again." });
|
|
247
|
+
}
|
|
248
|
+
} else {
|
|
231
249
|
if (this.config.onAuthExpired) {
|
|
232
250
|
this.config.onAuthExpired();
|
|
233
251
|
}
|
|
@@ -299,6 +317,9 @@ var APIClient = class {
|
|
|
299
317
|
};
|
|
300
318
|
|
|
301
319
|
// src/modules/auth.ts
|
|
320
|
+
function isAuthTokens(result) {
|
|
321
|
+
return typeof result === "object" && result !== null && "access_token" in result && "refresh_token" in result;
|
|
322
|
+
}
|
|
302
323
|
var AuthModule = class {
|
|
303
324
|
constructor(client) {
|
|
304
325
|
this.client = client;
|
|
@@ -306,19 +327,27 @@ var AuthModule = class {
|
|
|
306
327
|
client;
|
|
307
328
|
/**
|
|
308
329
|
* Register a new account.
|
|
309
|
-
* If using EmailRegisterInput, returns AuthTokens.
|
|
330
|
+
* If using EmailRegisterInput, returns AuthTokens (auto-persisted).
|
|
310
331
|
* If using PhoneRegisterInput, returns MessageResponse (OTP sent).
|
|
311
332
|
*/
|
|
312
333
|
async register(input, options) {
|
|
313
|
-
|
|
334
|
+
const result = await this.client.post("/auth/register", input, options);
|
|
335
|
+
if (isAuthTokens(result)) {
|
|
336
|
+
await this.client.setSession(result);
|
|
337
|
+
}
|
|
338
|
+
return result;
|
|
314
339
|
}
|
|
315
340
|
/**
|
|
316
341
|
* Log in to an existing account.
|
|
317
|
-
* If using EmailLoginInput, returns AuthTokens (or TwoFactorRequired
|
|
342
|
+
* If using EmailLoginInput, returns AuthTokens (auto-persisted) or TwoFactorRequired.
|
|
318
343
|
* If using PhoneLoginInput, returns MessageResponse (OTP sent).
|
|
319
344
|
*/
|
|
320
345
|
async login(input, options) {
|
|
321
|
-
|
|
346
|
+
const result = await this.client.post("/auth/login", input, options);
|
|
347
|
+
if (isAuthTokens(result)) {
|
|
348
|
+
await this.client.setSession(result);
|
|
349
|
+
}
|
|
350
|
+
return result;
|
|
322
351
|
}
|
|
323
352
|
/**
|
|
324
353
|
* Send an OTP code to a phone number.
|
|
@@ -327,26 +356,31 @@ var AuthModule = class {
|
|
|
327
356
|
return this.client.post("/auth/otp/send", input, options);
|
|
328
357
|
}
|
|
329
358
|
/**
|
|
330
|
-
* Verify an OTP code.
|
|
359
|
+
* Verify an OTP code. Tokens are auto-persisted.
|
|
331
360
|
*/
|
|
332
361
|
async verifyOtp(input, options) {
|
|
333
|
-
|
|
362
|
+
const result = await this.client.post("/auth/otp/verify", input, options);
|
|
363
|
+
await this.client.setSession(result);
|
|
364
|
+
return result;
|
|
334
365
|
}
|
|
335
366
|
/**
|
|
336
367
|
* Refresh the access token using a refresh token.
|
|
337
368
|
*/
|
|
338
369
|
async refresh(input, options) {
|
|
339
|
-
|
|
370
|
+
const result = await this.client.post("/auth/refresh", input, options);
|
|
371
|
+
await this.client.setSession(result);
|
|
372
|
+
return result;
|
|
340
373
|
}
|
|
341
374
|
/**
|
|
342
|
-
* Revoke the refresh token and log out.
|
|
375
|
+
* Revoke the refresh token and log out. Clears stored session.
|
|
343
376
|
*/
|
|
344
377
|
async logout(input, options) {
|
|
345
|
-
|
|
378
|
+
const result = await this.client.post("/auth/logout", input, options);
|
|
379
|
+
await this.client.clearToken();
|
|
380
|
+
return result;
|
|
346
381
|
}
|
|
347
382
|
/**
|
|
348
383
|
* Request a password reset email.
|
|
349
|
-
* Sends a reset link to the provided email address.
|
|
350
384
|
*/
|
|
351
385
|
async forgotPassword(input, options) {
|
|
352
386
|
return this.client.post("/auth/forgot-password", input, options);
|
|
@@ -370,28 +404,27 @@ var AuthModule = class {
|
|
|
370
404
|
return this.client.post("/auth/onboarding/complete", input, options);
|
|
371
405
|
}
|
|
372
406
|
/**
|
|
373
|
-
* Verify 2FA code during login
|
|
407
|
+
* Verify 2FA code during login. Tokens are auto-persisted.
|
|
374
408
|
*/
|
|
375
409
|
async verify2FA(input, options) {
|
|
376
|
-
|
|
410
|
+
const result = await this.client.post("/auth/2fa/login", input, options);
|
|
411
|
+
await this.client.setSession(result);
|
|
412
|
+
return result;
|
|
377
413
|
}
|
|
378
414
|
/**
|
|
379
415
|
* Send a verification code to the user's email.
|
|
380
|
-
* If unauthenticated, pass the email address.
|
|
381
416
|
*/
|
|
382
417
|
async sendVerificationCode(email, options) {
|
|
383
418
|
return this.client.post("/auth/verify-email/send", email ? { email } : void 0, options);
|
|
384
419
|
}
|
|
385
420
|
/**
|
|
386
421
|
* Verify the email with the 6-digit code.
|
|
387
|
-
* If unauthenticated, pass the email address.
|
|
388
422
|
*/
|
|
389
423
|
async verifyEmail(code, email, options) {
|
|
390
424
|
return this.client.post("/auth/verify-email/confirm", email ? { code, email } : { code }, options);
|
|
391
425
|
}
|
|
392
426
|
/**
|
|
393
427
|
* Upgrade the current user to a seller role.
|
|
394
|
-
* Idempotent — returns success if already a seller.
|
|
395
428
|
*/
|
|
396
429
|
async becomeSeller(input, options) {
|
|
397
430
|
return this.client.post("/auth/become-seller", input, options);
|
|
@@ -795,6 +828,16 @@ var StoresModule = class {
|
|
|
795
828
|
async getMyStores(options) {
|
|
796
829
|
return this.client.get("/listings/stores/mine", void 0, options);
|
|
797
830
|
}
|
|
831
|
+
/**
|
|
832
|
+
* Get stores the authenticated user follows.
|
|
833
|
+
*/
|
|
834
|
+
async getFollowing(params, options) {
|
|
835
|
+
return this.client.get(
|
|
836
|
+
"/listings/stores/following",
|
|
837
|
+
params,
|
|
838
|
+
options
|
|
839
|
+
);
|
|
840
|
+
}
|
|
798
841
|
/**
|
|
799
842
|
* Create a new store.
|
|
800
843
|
*/
|
|
@@ -1354,6 +1397,12 @@ var MitumbaClient = class {
|
|
|
1354
1397
|
setToken(token, refreshToken) {
|
|
1355
1398
|
this.api.setToken(token, refreshToken);
|
|
1356
1399
|
}
|
|
1400
|
+
/**
|
|
1401
|
+
* Set both tokens explicitly. Preferred — prevents dropping the refresh token.
|
|
1402
|
+
*/
|
|
1403
|
+
setSession(tokens) {
|
|
1404
|
+
return this.api.setSession(tokens);
|
|
1405
|
+
}
|
|
1357
1406
|
/**
|
|
1358
1407
|
* Get the current access token.
|
|
1359
1408
|
*/
|