postex-auth-sdk-stage 2.3.0 → 3.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/README.md CHANGED
@@ -101,7 +101,7 @@ Accepts either a direct email string or an identifier object.
101
101
 
102
102
  ```typescript
103
103
  async getStatus(
104
- identifier: string | { email?: string; mobileNumber?: string }
104
+ identifier: string | { email?: string; mobileNumber?: string; username?: string }
105
105
  ): Promise<AuthStatusResponse>
106
106
  ```
107
107
 
@@ -110,6 +110,7 @@ async getStatus(
110
110
  - `auth.getStatus('user@example.com')`
111
111
  - `auth.getStatus({ email: 'user@example.com' })`
112
112
  - `auth.getStatus({ mobileNumber: '03011266254' })`
113
+ - `auth.getStatus({ username: 'user123' })`
113
114
 
114
115
  **Returns:**
115
116
 
@@ -126,13 +127,22 @@ Start the authentication process. Returns either a WebAuthn challenge or confirm
126
127
 
127
128
  ```typescript
128
129
  async initiateAuth(
129
- identifier: string | { email?: string; mobileNumber?: string }
130
+ identifier: string | { email?: string; mobileNumber?: string; username?: string }
130
131
  ): Promise<InitiateAuthResponse>
131
132
  ```
132
133
 
134
+ **Supported input forms:**
135
+
136
+ - `auth.initiateAuth('user@example.com')`
137
+ - `auth.initiateAuth({ email: 'user@example.com' })`
138
+ - `auth.initiateAuth({ mobileNumber: '03011266254' })`
139
+ - `auth.initiateAuth({ username: 'user123' })`
140
+
133
141
  **Returns:**
134
142
 
135
143
  - `status`: `'webauthn_challenge'` | `'otp_sent'`
144
+ - `message`: Backend initiation message
145
+ - `delivery`: OTP delivery metadata when status is `'otp_sent'`
136
146
  - `challenge`, `credentialIds`, `rp`: WebAuthn data if status is `'webauthn_challenge'`
137
147
 
138
148
  ---
@@ -140,24 +150,34 @@ async initiateAuth(
140
150
  #### initiateOTP()
141
151
 
142
152
  Start OTP authentication directly via `/otp/initiate`.
143
- Requires at least one identifier: `email` or `mobileNumber`.
153
+ Requires at least one identifier: `email`, `mobileNumber`, or `username`.
144
154
 
145
155
  ```typescript
146
156
  async initiateOTP(
147
- identifier: string | { email?: string; mobileNumber?: string }
157
+ identifier: string | { email?: string; mobileNumber?: string; username?: string }
148
158
  ): Promise<{
159
+ statusText?: string;
149
160
  message?: string;
161
+ statusCode?: number;
162
+ success?: boolean;
163
+ data?: {
164
+ delivery?: {
165
+ channel: 'email' | 'sms';
166
+ target: string;
167
+ };
168
+ };
150
169
  }>
151
170
  ```
152
171
 
153
172
  **Supported input forms:**
154
173
  - `auth.initiateOTP({ email: 'user@example.com' })`
155
174
  - `auth.initiateOTP({ mobileNumber: '03011266254' })`
156
- - `auth.initiateOTP({ email: 'user@example.com' })`
175
+ - `auth.initiateOTP({ username: 'user123' })`
157
176
 
158
177
  **Validation:**
159
178
 
160
- - Throws an error when both `email` and `mobileNumber` are missing/empty.
179
+ - Throws an error when `email`, `mobileNumber`, and `username` are all missing/empty.
180
+ - `username` is trimmed, must be 64 characters or fewer, and must not contain control characters.
161
181
 
162
182
  ---
163
183
 
@@ -184,13 +204,23 @@ async verifyOTP(otp: string): Promise<OTPVerifyResponse>
184
204
  Resend OTP code for the standard login OTP flow.
185
205
 
186
206
  ```typescript
187
- async resendOTP(): Promise<{ success: boolean; message?: string }>
207
+ async resendOTP(): Promise<{
208
+ message?: string;
209
+ success?: boolean;
210
+ data?: {
211
+ delivery?: {
212
+ channel: 'email' | 'sms';
213
+ target: string;
214
+ };
215
+ };
216
+ }>
188
217
  ```
189
218
 
190
219
  **Returns:**
191
220
 
192
- - `success`: Whether resend request was accepted
193
- - `message`: Optional backend message
221
+ - `message`: Backend resend message
222
+ - `success`: Whether resend request was accepted, when provided by the backend
223
+ - `data.delivery`: OTP delivery channel and masked target
194
224
 
195
225
  ---
196
226
 
package/dist/auth.d.ts CHANGED
@@ -2,6 +2,7 @@ type AuthEntity = "xstak" | "postex" | "callcourier" | "postexglobal" | "postexs
2
2
  type AuthIdentifierInput = string | {
3
3
  email?: string;
4
4
  mobileNumber?: string;
5
+ username?: string;
5
6
  realm?: string;
6
7
  };
7
8
  interface RealmOptions {
@@ -25,8 +26,15 @@ interface AuthStatusResponse {
25
26
  }
26
27
  /** Response from POST /auth/initiate */
27
28
  type InitiateAuthStatusType = "webauthn_challenge" | "otp_sent";
29
+ type OTPDeliveryChannel = "email" | "sms";
30
+ interface OTPDeliveryMetadata {
31
+ channel: OTPDeliveryChannel;
32
+ target: string;
33
+ }
28
34
  interface InitiateAuthResponse {
29
35
  status: InitiateAuthStatusType;
36
+ message?: string;
37
+ delivery?: OTPDeliveryMetadata;
30
38
  challenge?: string;
31
39
  credentialIds?: string[];
32
40
  rp?: {
@@ -49,7 +57,16 @@ interface OTPInitiateResponse {
49
57
  success?: boolean;
50
58
  message?: string;
51
59
  data?: {
52
- message?: string;
60
+ delivery?: OTPDeliveryMetadata;
61
+ [key: string]: any;
62
+ };
63
+ [key: string]: any;
64
+ }
65
+ interface OTPResendResponse {
66
+ message?: string;
67
+ success?: boolean;
68
+ data?: {
69
+ delivery?: OTPDeliveryMetadata;
53
70
  [key: string]: any;
54
71
  };
55
72
  [key: string]: any;
@@ -126,6 +143,7 @@ export declare class AuthSDK {
126
143
  private assertNoControlChars;
127
144
  private validateEmail;
128
145
  private validateMobileNumber;
146
+ private validateUsername;
129
147
  private validateOTP;
130
148
  private validateMagicLinkToken;
131
149
  private validateRealm;
@@ -149,12 +167,12 @@ export declare class AuthSDK {
149
167
  getStatus(identifier: AuthIdentifierInput, options?: RealmOptions): Promise<AuthStatusResponse>;
150
168
  /**
151
169
  * POST /auth/initiate - Unified entry: returns webauthn_challenge or otp_sent.
152
- * Sets auth_session cookie when otp_sent.
170
+ * Sets auth_session cookie and includes delivery metadata when otp_sent.
153
171
  */
154
172
  initiateAuth(identifier: AuthIdentifierInput, options?: RealmOptions): Promise<InitiateAuthResponse>;
155
173
  /**
156
- * POST /otp/initiate - Direct OTP initiation using email or mobile number.
157
- * Requires at least one identifier: email or mobileNumber.
174
+ * POST /otp/initiate - Direct OTP initiation using email, mobile number, or username.
175
+ * Requires at least one identifier: email, mobileNumber, or username.
158
176
  */
159
177
  initiateOTP(identifier: AuthIdentifierInput, options?: RealmOptions): Promise<OTPInitiateResponse>;
160
178
  /**
@@ -163,13 +181,10 @@ export declare class AuthSDK {
163
181
  */
164
182
  verifyOTP(otp: string): Promise<OTPVerifyResponse>;
165
183
  /**
166
- * POST /resend - Resend OTP code to the user's email.
184
+ * POST /otp/resend - Resend OTP code to the user's email or mobile number.
167
185
  * No payload required, relies on auth_session cookie.
168
186
  */
169
- resendOTP(): Promise<{
170
- success: boolean;
171
- message?: string;
172
- }>;
187
+ resendOTP(): Promise<OTPResendResponse>;
173
188
  /**
174
189
  * POST /otp/signup/verify - Verify OTP for signup flow.
175
190
  * Stores tokens from the response when provided by backend.