@coreiam/auth 1.0.392-beta.8 → 1.0.392-beta.9

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.
@@ -41,6 +41,7 @@ export interface RefreshSessionResult {
41
41
  }
42
42
  /** Maps gateway token claims → CoreIAMIdentity (same shape the Next.js middleware injects). */
43
43
  export declare function toIdentity(payload: JWTPayload): CoreIAMIdentity;
44
+ export declare function retryAfterSeconds(body: unknown): number | undefined;
44
45
  /**
45
46
  export class CoreIAM {
46
47
  private apiKey: string = '';
@@ -143,6 +144,8 @@ export declare class CoreIAM {
143
144
  requestOtp(body: RequestOtpBody, incomingHeaders: Headers): Promise<Response>;
144
145
  verifyOtp(body: VerifyOtpBody, incomingHeaders: Headers): Promise<Response>;
145
146
  forgotPassword(email: string, incomingHeaders: Headers): Promise<Response>;
147
+ verifyEmail(body: VerifyEmailBody, incomingHeaders: Headers): Promise<Response>;
148
+ resendVerification(email: string, incomingHeaders: Headers): Promise<Response>;
146
149
  resetPassword(email: string, otp: string, newPassword: string, incomingHeaders: Headers): Promise<Response>;
147
150
  listSessions(incomingHeaders: Headers): Promise<Response>;
148
151
  revokeSession(sessionId: string, incomingHeaders: Headers): Promise<Response>;
@@ -157,6 +160,10 @@ export interface VerifyOtpBody {
157
160
  email: string;
158
161
  otp: string;
159
162
  }
163
+ export interface VerifyEmailBody {
164
+ email: string;
165
+ otp: string;
166
+ }
160
167
  export interface RequestResetBody {
161
168
  email: string;
162
169
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OAUTH_PROVIDERS = exports.CSRF_PROTECTED_PATHS = exports.CoreIAM = void 0;
4
4
  exports.toIdentity = toIdentity;
5
+ exports.retryAfterSeconds = retryAfterSeconds;
5
6
  // src/core/index.ts
6
7
  const jose_1 = require("jose");
7
8
  /** Maps gateway token claims → CoreIAMIdentity (same shape the Next.js middleware injects). */
@@ -13,6 +14,17 @@ function toIdentity(payload) {
13
14
  roles: Array.isArray(payload.roles) ? payload.roles : [],
14
15
  };
15
16
  }
17
+ function retryAfterSeconds(body) {
18
+ const msg = body?.message;
19
+ for (const m of Array.isArray(msg) ? msg : [msg]) {
20
+ if (typeof m === 'string') {
21
+ const match = m.match(/Try again in (\d+) seconds?/);
22
+ if (match)
23
+ return Number(match[1]);
24
+ }
25
+ }
26
+ return undefined;
27
+ }
16
28
  /**
17
29
  export class CoreIAM {
18
30
  private apiKey: string = '';
@@ -424,6 +436,20 @@ class CoreIAM {
424
436
  body: JSON.stringify({ email }),
425
437
  }, incomingHeaders);
426
438
  }
439
+ async verifyEmail(body, incomingHeaders) {
440
+ return this.proxyWithCsrfProtection('/auth/verify-email', {
441
+ method: 'POST',
442
+ headers: { 'Content-Type': 'application/json' },
443
+ body: JSON.stringify(body),
444
+ }, incomingHeaders);
445
+ }
446
+ async resendVerification(email, incomingHeaders) {
447
+ return this.proxyWithCsrfProtection('/auth/resend-verification', {
448
+ method: 'POST',
449
+ headers: { 'Content-Type': 'application/json' },
450
+ body: JSON.stringify({ email }),
451
+ }, incomingHeaders);
452
+ }
427
453
  async resetPassword(email, otp, newPassword, incomingHeaders) {
428
454
  return this.proxyWithCsrfProtection('/auth/reset-password', {
429
455
  method: 'POST',
@@ -456,7 +482,7 @@ class CoreIAM {
456
482
  exports.CoreIAM = CoreIAM;
457
483
  exports.CSRF_PROTECTED_PATHS = new Set([
458
484
  '/auth/login', '/auth/register', '/auth/discover-tenants',
459
- '/auth/request-otp', '/auth/verify-otp', '/auth/mfa/login',
485
+ '/auth/request-otp', '/auth/verify-otp', '/auth/mfa/login', '/auth/verify-email', '/auth/resend-verification',
460
486
  '/auth/profile', '/auth/mfa/setup', '/auth/mfa/verify', '/auth/mfa/disable',
461
487
  '/auth/password',
462
488
  '/auth/request-reset', '/auth/reset-password',
@@ -1,7 +1,8 @@
1
- import { CoreIAMIdentity, RequestOtpBody, VerifyOtpBody } from '../core';
1
+ import { CoreIAMIdentity, RequestOtpBody, VerifyOtpBody, VerifyEmailBody } from '../core';
2
2
  export interface AuthResult {
3
3
  ok: boolean;
4
4
  status: number;
5
+ retryAfter?: number;
5
6
  data: any;
6
7
  }
7
8
  export declare function getSession(): Promise<CoreIAMIdentity | null>;
@@ -15,6 +16,8 @@ export declare function verifyMfaActionSdk(token: string): Promise<AuthResult>;
15
16
  export declare function disableMfaActionSdk(): Promise<AuthResult>;
16
17
  export declare function requestOtpActionSdk(body: RequestOtpBody): Promise<AuthResult>;
17
18
  export declare function verifyOtpActionSdk(body: VerifyOtpBody): Promise<AuthResult>;
19
+ export declare function verifyEmailActionSdk(body: VerifyEmailBody): Promise<AuthResult>;
20
+ export declare function resendVerificationActionSdk(email: string): Promise<AuthResult>;
18
21
  export declare function forgotPasswordActionSdk(email: string): Promise<AuthResult>;
19
22
  export declare function resetPasswordActionSdk(email: string, otp: string, newPassword: string): Promise<AuthResult>;
20
23
  export declare function listSessionsActionSdk(): Promise<AuthResult>;
@@ -105,6 +105,8 @@ exports.verifyMfaActionSdk = verifyMfaActionSdk;
105
105
  exports.disableMfaActionSdk = disableMfaActionSdk;
106
106
  exports.requestOtpActionSdk = requestOtpActionSdk;
107
107
  exports.verifyOtpActionSdk = verifyOtpActionSdk;
108
+ exports.verifyEmailActionSdk = verifyEmailActionSdk;
109
+ exports.resendVerificationActionSdk = resendVerificationActionSdk;
108
110
  exports.forgotPasswordActionSdk = forgotPasswordActionSdk;
109
111
  exports.resetPasswordActionSdk = resetPasswordActionSdk;
110
112
  exports.listSessionsActionSdk = listSessionsActionSdk;
@@ -324,7 +326,8 @@ async function requestOtpActionSdk(body) {
324
326
  // any Set-Cookie through the same sync as every other auth action keeps the
325
327
  // invariant above true if the backend ever starts setting one.
326
328
  await syncCookiesToNext(response);
327
- return { ok: response.ok, status: response.status, data: await response.json().catch(() => ({})) };
329
+ const data = await response.json().catch(() => ({}));
330
+ return { ok: response.ok, status: response.status, data, retryAfter: (0, core_1.retryAfterSeconds)(data) };
328
331
  }
329
332
  catch (error) {
330
333
  return { ok: false, status: 500, data: { error: 'OTP request failed' } };
@@ -341,12 +344,40 @@ async function verifyOtpActionSdk(body) {
341
344
  // server action never established a browser session. Mirrors the
342
345
  // loginActionSdk / registerActionSdk pattern exactly.
343
346
  await syncCookiesToNext(response);
344
- return { ok: response.ok, status: response.status, data: await response.json().catch(() => ({})) };
347
+ const data = await response.json().catch(() => ({}));
348
+ return { ok: response.ok, status: response.status, data, retryAfter: (0, core_1.retryAfterSeconds)(data) };
345
349
  }
346
350
  catch (error) {
347
351
  return { ok: false, status: 500, data: { error: 'OTP verification failed' } };
348
352
  }
349
353
  }
354
+ // W5 (beta.9): signup email verification — register fires the verification
355
+ // email (emailVerificationRequired: true); these close the loop so the SDK
356
+ // surface matches the server's /auth/verify-email + resend-verification pair.
357
+ async function verifyEmailActionSdk(body) {
358
+ const reqHeaders = await (0, headers_1.headers)();
359
+ try {
360
+ const response = await getIam().verifyEmail(body, reqHeaders);
361
+ await syncCookiesToNext(response);
362
+ const data = await response.json().catch(() => ({}));
363
+ return { ok: response.ok, status: response.status, data, retryAfter: (0, core_1.retryAfterSeconds)(data) };
364
+ }
365
+ catch (error) {
366
+ return { ok: false, status: 500, data: { error: 'Email verification failed' } };
367
+ }
368
+ }
369
+ async function resendVerificationActionSdk(email) {
370
+ const reqHeaders = await (0, headers_1.headers)();
371
+ try {
372
+ const response = await getIam().resendVerification(email, reqHeaders);
373
+ await syncCookiesToNext(response);
374
+ const data = await response.json().catch(() => ({}));
375
+ return { ok: response.ok, status: response.status, data, retryAfter: (0, core_1.retryAfterSeconds)(data) };
376
+ }
377
+ catch (error) {
378
+ return { ok: false, status: 500, data: { error: 'Verification resend failed' } };
379
+ }
380
+ }
350
381
  async function forgotPasswordActionSdk(email) {
351
382
  const reqHeaders = await (0, headers_1.headers)();
352
383
  try {
@@ -51,7 +51,7 @@
51
51
  // export function useAuth() {
52
52
  // return useContext(AuthContext);
53
53
  // }
54
- // src/nextjs/provider.tsx
54
+ // sdk/javascript/src/nextjs/provider.tsx
55
55
  'use client';
56
56
  Object.defineProperty(exports, "__esModule", { value: true });
57
57
  exports.CoreIAMProvider = CoreIAMProvider;
@@ -44,6 +44,7 @@ export function useAuth() {
44
44
  }
45
45
 
46
46
  */
47
+ //sdk/javascript/src/react/provider.tsx
47
48
  'use client';
48
49
  Object.defineProperty(exports, "__esModule", { value: true });
49
50
  exports.CoreIAMProvider = CoreIAMProvider;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coreiam/auth",
3
- "version": "1.0.392-beta.8",
3
+ "version": "1.0.392-beta.9",
4
4
  "main": "./dist/core/index.js",
5
5
  "types": "./dist/core/index.d.ts",
6
6
  "exports": {
@@ -56,7 +56,8 @@
56
56
  "author": "coreiam",
57
57
  "license": "MIT",
58
58
  "publishConfig": {
59
- "access": "public"
59
+ "access": "public",
60
+ "tag": "beta"
60
61
  },
61
62
  "peerDependencies": {
62
63
  "express": "^4.0.0 || ^5.0.0",