@payez/next-mvp 4.13.0 → 4.13.1
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/CHANGELOG.md +12 -0
- package/dist/api-handlers/account/profile.d.ts +2 -39
- package/dist/api-handlers/account/profile.js +5 -2
- package/dist/api-handlers/anon/preferences.d.ts +1 -14
- package/dist/api-handlers/anon/preferences.js +5 -5
- package/dist/api-handlers/health.d.ts +5 -0
- package/dist/api-handlers/health.js +48 -0
- package/dist/api-handlers/session/refresh-viability.d.ts +3 -15
- package/dist/api-handlers/session/refresh-viability.js +5 -2
- package/dist/api-handlers/session/viability.d.ts +3 -8
- package/dist/api-handlers/session/viability.js +5 -2
- package/dist/auth/better-auth-exposure.d.ts +11 -0
- package/dist/auth/better-auth-exposure.js +73 -0
- package/dist/auth/better-auth.js +13 -1
- package/dist/auth/route-config.js +9 -0
- package/dist/lib/no-store.d.ts +13 -0
- package/dist/lib/no-store.js +35 -0
- package/dist/routes/auth/session.d.ts +2 -9
- package/dist/routes/auth/session.js +5 -2
- package/dist/routes/auth/viability.d.ts +3 -54
- package/dist/routes/auth/viability.js +5 -2
- package/dist/routes/health.d.ts +1 -0
- package/dist/routes/health.js +16 -0
- package/dist/routes/mfa/methods.d.ts +2 -2
- package/dist/routes/mfa/methods.js +3 -1
- package/dist/routes/passkeys/list.d.ts +2 -10
- package/dist/routes/passkeys/list.js +4 -2
- package/dist/routes/session/refresh-viability.d.ts +2 -1
- package/dist/routes/session/refresh-viability.js +4 -2
- package/dist/utils/api.d.ts +33 -6
- package/dist/utils/api.js +35 -2
- package/package.json +11 -1
- package/src/api-handlers/account/profile.ts +5 -1
- package/src/api-handlers/anon/preferences.ts +5 -4
- package/src/api-handlers/health.ts +53 -0
- package/src/api-handlers/session/refresh-viability.ts +5 -1
- package/src/api-handlers/session/viability.ts +6 -2
- package/src/auth/better-auth-exposure.ts +69 -0
- package/src/auth/better-auth.ts +15 -1
- package/src/auth/route-config.ts +9 -0
- package/src/lib/no-store.ts +30 -0
- package/src/routes/auth/session.ts +5 -1
- package/src/routes/auth/viability.ts +6 -2
- package/src/routes/health.ts +14 -0
- package/src/routes/mfa/methods.ts +3 -1
- package/src/routes/passkeys/list.ts +5 -1
- package/src/routes/session/refresh-viability.ts +5 -1
- package/src/utils/api.ts +50 -8
|
@@ -14,4 +14,8 @@
|
|
|
14
14
|
* @since auth-ready-v2
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
import { GET as refreshViability } from '../../api-handlers/session/refresh-viability';
|
|
18
|
+
import { noStore } from '../../lib/no-store';
|
|
19
|
+
|
|
20
|
+
/** PAY-2994: refresh-token viability of this session; never cached (noStore). */
|
|
21
|
+
export const GET = noStore(refreshViability);
|
package/src/utils/api.ts
CHANGED
|
@@ -133,6 +133,45 @@ export function resetFailureText(status: number, rules: string[] = [], policy =
|
|
|
133
133
|
return "We couldn't reset your password just now. Please try again.";
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* SMS-first sign-up (door 3b): when the phone code is right but the email is still unconfirmed, the server answers 200 success with
|
|
138
|
+
* `next_step = EMAIL_CONFIRMATION_REQUIRED` and NO reset token. `verifyOnboardingSmsCode` surfaces that as `nextStep`;
|
|
139
|
+
* `interpretSmsVerification` turns a result into ONE outcome, testing `nextStep` BEFORE `success`, so a consumer that uses it can
|
|
140
|
+
* never reach "verified" without a reset token or with an unfinished step. The sentences are the package's own, never the server's text.
|
|
141
|
+
*/
|
|
142
|
+
export const SMS_NEXT_STEP_EMAIL_CONFIRMATION_REQUIRED = 'EMAIL_CONFIRMATION_REQUIRED';
|
|
143
|
+
export const SMS_EMAIL_CONFIRMATION_TEXT = 'Your phone is verified. Confirm your email to finish signing up.';
|
|
144
|
+
export const SMS_MORE_STEPS_TEXT = 'One more step is needed to finish signing up.';
|
|
145
|
+
|
|
146
|
+
export interface SmsCodeVerification {
|
|
147
|
+
success: boolean;
|
|
148
|
+
resetToken: string;
|
|
149
|
+
email: string;
|
|
150
|
+
clientKey: string;
|
|
151
|
+
/** Present when the server says more steps remain (an UNRECOGNISED value is kept as a non-empty string, never dropped). */
|
|
152
|
+
nextStep?: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export type SmsVerificationOutcome =
|
|
156
|
+
| { kind: 'verified'; resetToken: string; email: string; clientKey: string }
|
|
157
|
+
| { kind: 'email_confirmation_required'; message: string }
|
|
158
|
+
| { kind: 'more_steps'; message: string }
|
|
159
|
+
| { kind: 'not_verified' };
|
|
160
|
+
|
|
161
|
+
export function interpretSmsVerification(result: SmsCodeVerification): SmsVerificationOutcome {
|
|
162
|
+
// success:false WINS over any step (BAPert 88508): a failed answer must never say "Your phone is verified".
|
|
163
|
+
if (!result.success) return { kind: 'not_verified' };
|
|
164
|
+
// For every answer that is not a failure, nextStep comes BEFORE the token test: a step that is not finished is never "verified".
|
|
165
|
+
if (result.nextStep) {
|
|
166
|
+
return result.nextStep === SMS_NEXT_STEP_EMAIL_CONFIRMATION_REQUIRED
|
|
167
|
+
? { kind: 'email_confirmation_required', message: SMS_EMAIL_CONFIRMATION_TEXT }
|
|
168
|
+
: { kind: 'more_steps', message: SMS_MORE_STEPS_TEXT };
|
|
169
|
+
}
|
|
170
|
+
// success with an EMPTY reset token is the shape that is dangerous (set-password would be called with ''): not verified.
|
|
171
|
+
if (!result.resetToken) return { kind: 'more_steps', message: SMS_MORE_STEPS_TEXT };
|
|
172
|
+
return { kind: 'verified', resetToken: result.resetToken, email: result.email, clientKey: result.clientKey };
|
|
173
|
+
}
|
|
174
|
+
|
|
136
175
|
export class AccountApi {
|
|
137
176
|
/**
|
|
138
177
|
* Get masked user info (email, phone, authenticator status)
|
|
@@ -338,17 +377,12 @@ export class AccountApi {
|
|
|
338
377
|
};
|
|
339
378
|
}
|
|
340
379
|
|
|
341
|
-
async verifyOnboardingSmsCode(onboardToken: string, code: string, clientKey?: string): Promise<{
|
|
342
|
-
success: boolean;
|
|
343
|
-
resetToken: string;
|
|
344
|
-
email: string;
|
|
345
|
-
clientKey: string;
|
|
346
|
-
}> {
|
|
380
|
+
async verifyOnboardingSmsCode(onboardToken: string, code: string, clientKey?: string): Promise<SmsCodeVerification> {
|
|
347
381
|
const qs = clientKey ? `?clientId=${encodeURIComponent(clientKey)}` : '';
|
|
348
382
|
const res = await fetch(`/api/onboarding/verify-sms-code${qs}`, {
|
|
349
383
|
method: 'POST',
|
|
350
384
|
headers: { 'Content-Type': 'application/json' },
|
|
351
|
-
body: JSON.stringify({
|
|
385
|
+
body: JSON.stringify({
|
|
352
386
|
onboard_token: onboardToken,
|
|
353
387
|
code: code
|
|
354
388
|
})
|
|
@@ -360,11 +394,19 @@ export class AccountApi {
|
|
|
360
394
|
}
|
|
361
395
|
// Extract from nested data structure
|
|
362
396
|
const data = result.data?.data || result.data || {};
|
|
397
|
+
// next_step (door 3b): read from the nested shapes AND a flat body. Absent / null / '' = no step; a non-string value is an
|
|
398
|
+
// UNRECOGNISED step and is kept as a non-empty string (never dropped, never mistaken for the known one). That includes false and 0:
|
|
399
|
+
// a server that means "no step" must send nothing or null (or '').
|
|
400
|
+
const rawStep = data.next_step ?? result.next_step;
|
|
401
|
+
const nextStep = rawStep === undefined || rawStep === null || rawStep === ''
|
|
402
|
+
? undefined
|
|
403
|
+
: typeof rawStep === 'string' ? rawStep : 'UNRECOGNISED_NEXT_STEP';
|
|
363
404
|
return {
|
|
364
405
|
success: data.success !== false,
|
|
365
406
|
resetToken: data.reset_token || '',
|
|
366
407
|
email: data.email || '',
|
|
367
|
-
clientKey: data.client_key || ''
|
|
408
|
+
clientKey: data.client_key || '',
|
|
409
|
+
...(nextStep !== undefined ? { nextStep } : {})
|
|
368
410
|
};
|
|
369
411
|
}
|
|
370
412
|
|