@koolbase/core 12.43.0 → 12.44.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.
@@ -71,6 +71,19 @@ export declare class KoolbaseAuth {
71
71
  * the caller's own request would have failed first.
72
72
  */
73
73
  private updateUserAndPersist;
74
+ /**
75
+ * Remember me: the choice of the sign-in under way, held until its session
76
+ * is saved -- through a second step (MFA) too. Null: none under way.
77
+ */
78
+ private pendingRemember;
79
+ /** A sign-in starts: its Remember me, omitted meaning remembered. */
80
+ private beginSignIn;
81
+ /**
82
+ * A sign-in's session: told to the storage where it lives first (Remember
83
+ * me), then saved. A refresh or a profile change is not a sign-in and
84
+ * keeps the place the session already has.
85
+ */
86
+ private setSignedInSession;
74
87
  private setSessionInternal;
75
88
  /**
76
89
  * Discards the stored session without contacting the server.
@@ -378,6 +391,7 @@ export declare class KoolbaseAuth {
378
391
  signInWithEmailCode(params: {
379
392
  email: string;
380
393
  code: string;
394
+ remember?: boolean;
381
395
  }): Promise<KoolbaseSession>;
382
396
  private mfaRequired;
383
397
  /** Finishes sign-in with a code from the person's authenticator app. */
package/dist/cjs/auth.js CHANGED
@@ -26,6 +26,11 @@ class KoolbaseAuth {
26
26
  this.signOutReason = null;
27
27
  /** The last renewal failed for want of a connection, not because the server refused it (#96). */
28
28
  this.renewalUnavailable = false;
29
+ /**
30
+ * Remember me: the choice of the sign-in under way, held until its session
31
+ * is saved -- through a second step (MFA) too. Null: none under way.
32
+ */
33
+ this.pendingRemember = null;
29
34
  this.config = config;
30
35
  this.metadata = new device_metadata_js_1.DeviceMetadata(config.appVersion);
31
36
  this.fetchFn = config.fetch ?? ((url, init) => (0, network_js_1.koolbaseFetch)(url, init));
@@ -165,6 +170,29 @@ class KoolbaseAuth {
165
170
  return;
166
171
  await this.setSessionInternal({ ...this.session, user });
167
172
  }
173
+ /** A sign-in starts: its Remember me, omitted meaning remembered. */
174
+ beginSignIn(remember) {
175
+ this.pendingRemember = remember ?? true;
176
+ }
177
+ /**
178
+ * A sign-in's session: told to the storage where it lives first (Remember
179
+ * me), then saved. A refresh or a profile change is not a sign-in and
180
+ * keeps the place the session already has.
181
+ */
182
+ async setSignedInSession(session) {
183
+ const remember = this.pendingRemember ?? true;
184
+ this.pendingRemember = null;
185
+ if (this.storage?.setRemember) {
186
+ try {
187
+ await this.storage.setRemember(remember);
188
+ }
189
+ catch (err) {
190
+ // eslint-disable-next-line no-console
191
+ console.warn('[Koolbase] Could not apply Remember me:', err);
192
+ }
193
+ }
194
+ await this.setSessionInternal(session);
195
+ }
168
196
  async setSessionInternal(session) {
169
197
  this.session = session;
170
198
  this.signOutReason = null;
@@ -348,16 +376,20 @@ class KoolbaseAuth {
348
376
  };
349
377
  }
350
378
  const session = this.sessionFromBody(data);
351
- await this.setSessionInternal(session);
379
+ this.beginSignIn(undefined);
380
+ await this.setSignedInSession(session);
352
381
  return { status: 'authenticated', user: session.user, session };
353
382
  }
354
383
  async login(params) {
384
+ // Remember me is this device's, never the server's.
385
+ const { remember, ...body } = params;
386
+ this.beginSignIn(remember);
355
387
  const res = await this.authRequest('/v1/sdk/auth/login', {
356
388
  method: 'POST',
357
- body: params,
389
+ body,
358
390
  });
359
391
  const session = await this.parseSessionResponse(res, false);
360
- await this.setSessionInternal(session);
392
+ await this.setSignedInSession(session);
361
393
  return session;
362
394
  }
363
395
  /**
@@ -386,6 +418,7 @@ class KoolbaseAuth {
386
418
  * but auto-link rule blocked (409).
387
419
  */
388
420
  async signInWithApple(params) {
421
+ this.beginSignIn(params.remember);
389
422
  const body = {
390
423
  identity_token: params.identityToken,
391
424
  };
@@ -415,7 +448,7 @@ class KoolbaseAuth {
415
448
  body,
416
449
  });
417
450
  const session = await this.parseAppleSessionResponse(res);
418
- await this.setSessionInternal(session);
451
+ await this.setSignedInSession(session);
419
452
  return session;
420
453
  }
421
454
  /**
@@ -441,6 +474,7 @@ class KoolbaseAuth {
441
474
  * but auto-link rule blocked (409).
442
475
  */
443
476
  async signInWithGoogle(params) {
477
+ this.beginSignIn(params.remember);
444
478
  const body = {
445
479
  identity_token: params.idToken,
446
480
  };
@@ -452,7 +486,7 @@ class KoolbaseAuth {
452
486
  body,
453
487
  });
454
488
  const session = await this.parseGoogleSessionResponse(res);
455
- await this.setSessionInternal(session);
489
+ await this.setSignedInSession(session);
456
490
  return session;
457
491
  }
458
492
  /**
@@ -1045,12 +1079,13 @@ class KoolbaseAuth {
1045
1079
  * @throws EmailCodeDisabledError if the project has switched this off
1046
1080
  */
1047
1081
  async signInWithEmailCode(params) {
1082
+ this.beginSignIn(params.remember);
1048
1083
  const res = await this.authRequest('/v1/sdk/auth/email/code/verify', {
1049
1084
  method: 'POST',
1050
1085
  body: { email: params.email, code: params.code },
1051
1086
  });
1052
1087
  const session = await this.parseSessionResponse(res, false);
1053
- await this.setSessionInternal(session);
1088
+ await this.setSignedInSession(session);
1054
1089
  return session;
1055
1090
  }
1056
1091
  // ─── Two-step sign-in (MFA) ─────────────────────────────────────────────
@@ -1070,7 +1105,8 @@ class KoolbaseAuth {
1070
1105
  body: { challenge_token: params.challengeToken, code: params.code },
1071
1106
  });
1072
1107
  const session = await this.parseSessionResponse(res, false);
1073
- await this.setSessionInternal(session);
1108
+ // The second step of the sign-in that asked for it: its Remember me.
1109
+ await this.setSignedInSession(session);
1074
1110
  return session;
1075
1111
  }
1076
1112
  /**
@@ -1096,7 +1132,7 @@ class KoolbaseAuth {
1096
1132
  expiresAt: data.expires_at,
1097
1133
  user: this.mapUser(data.user),
1098
1134
  };
1099
- await this.setSessionInternal(session);
1135
+ await this.setSignedInSession(session);
1100
1136
  return { session, recoveryCodesRemaining: Number(data.recovery_codes_remaining ?? 0) };
1101
1137
  }
1102
1138
  /**
@@ -1161,6 +1197,7 @@ class KoolbaseAuth {
1161
1197
  }
1162
1198
  async verifyOtp(params) {
1163
1199
  this.validatePhone(params.phoneNumber);
1200
+ this.beginSignIn(params.remember);
1164
1201
  const res = await this.authRequest('/v1/sdk/auth/phone/verify-otp', {
1165
1202
  method: 'POST',
1166
1203
  body: {
@@ -1175,7 +1212,7 @@ class KoolbaseAuth {
1175
1212
  expiresAt: data.expires_at,
1176
1213
  user: this.mapUser(data.user),
1177
1214
  };
1178
- await this.setSessionInternal(session);
1215
+ await this.setSignedInSession(session);
1179
1216
  return { session, isNewUser: data.is_new_user ?? false };
1180
1217
  }
1181
1218
  async linkPhone(params) {
@@ -181,6 +181,13 @@ export interface KoolbaseAuthStorage {
181
181
  saveSession(session: KoolbaseSession): Promise<void>;
182
182
  readSession(): Promise<KoolbaseSession | null>;
183
183
  clear(): Promise<void>;
184
+ /**
185
+ * Remember me: where the next sign-in's session lives, told before it is
186
+ * saved. `true`: as long as the storage keeps anything; `false`: until the
187
+ * tab or browser closes. Optional -- a storage without it (a keychain, the
188
+ * memory one, an app's own) keeps every session as it always has.
189
+ */
190
+ setRemember?(remember: boolean): Promise<void>;
184
191
  }
185
192
  /**
186
193
  * Result of KoolbaseAuth.restoreSession(). Apps should branch on this:
@@ -225,6 +232,13 @@ export interface RegisterParams {
225
232
  export interface LoginParams {
226
233
  email: string;
227
234
  password: string;
235
+ /**
236
+ * Whether this sign-in outlasts the browser (Remember me). Omitted: it
237
+ * does, as always. `false`: the session is kept for this tab only, and
238
+ * ends when it closes -- where the storage can tell the two apart (the
239
+ * browser's, in @koolbase/js; a keychain always keeps it).
240
+ */
241
+ remember?: boolean;
228
242
  }
229
243
  export interface SendOtpParams {
230
244
  phoneNumber: string;
@@ -232,6 +246,13 @@ export interface SendOtpParams {
232
246
  export interface VerifyOtpParams {
233
247
  phoneNumber: string;
234
248
  code: string;
249
+ /**
250
+ * Whether this sign-in outlasts the browser (Remember me). Omitted: it
251
+ * does, as always. `false`: the session is kept for this tab only, and
252
+ * ends when it closes -- where the storage can tell the two apart (the
253
+ * browser's, in @koolbase/js; a keychain always keeps it).
254
+ */
255
+ remember?: boolean;
235
256
  }
236
257
  export interface LinkPhoneParams {
237
258
  phoneNumber: string;
@@ -609,6 +630,13 @@ export interface AppleFullName {
609
630
  export interface SignInWithAppleParams {
610
631
  identityToken: string;
611
632
  nonce?: string;
633
+ /**
634
+ * Whether this sign-in outlasts the browser (Remember me). Omitted: it
635
+ * does, as always. `false`: the session is kept for this tab only, and
636
+ * ends when it closes -- where the storage can tell the two apart (the
637
+ * browser's, in @koolbase/js; a keychain always keeps it).
638
+ */
639
+ remember?: boolean;
612
640
  fullName?: AppleFullName;
613
641
  /** The credential's authorization code: the server exchanges it for the
614
642
  * token it revokes when the account is deleted, as Apple asks. */
@@ -627,6 +655,13 @@ export interface SignInWithAppleParams {
627
655
  export interface SignInWithGoogleParams {
628
656
  idToken: string;
629
657
  nonce?: string;
658
+ /**
659
+ * Whether this sign-in outlasts the browser (Remember me). Omitted: it
660
+ * does, as always. `false`: the session is kept for this tab only, and
661
+ * ends when it closes -- where the storage can tell the two apart (the
662
+ * browser's, in @koolbase/js; a keychain always keeps it).
663
+ */
664
+ remember?: boolean;
630
665
  }
631
666
  export type BatchOp = {
632
667
  type: 'insert';
@@ -71,6 +71,19 @@ export declare class KoolbaseAuth {
71
71
  * the caller's own request would have failed first.
72
72
  */
73
73
  private updateUserAndPersist;
74
+ /**
75
+ * Remember me: the choice of the sign-in under way, held until its session
76
+ * is saved -- through a second step (MFA) too. Null: none under way.
77
+ */
78
+ private pendingRemember;
79
+ /** A sign-in starts: its Remember me, omitted meaning remembered. */
80
+ private beginSignIn;
81
+ /**
82
+ * A sign-in's session: told to the storage where it lives first (Remember
83
+ * me), then saved. A refresh or a profile change is not a sign-in and
84
+ * keeps the place the session already has.
85
+ */
86
+ private setSignedInSession;
74
87
  private setSessionInternal;
75
88
  /**
76
89
  * Discards the stored session without contacting the server.
@@ -378,6 +391,7 @@ export declare class KoolbaseAuth {
378
391
  signInWithEmailCode(params: {
379
392
  email: string;
380
393
  code: string;
394
+ remember?: boolean;
381
395
  }): Promise<KoolbaseSession>;
382
396
  private mfaRequired;
383
397
  /** Finishes sign-in with a code from the person's authenticator app. */
package/dist/esm/auth.js CHANGED
@@ -23,6 +23,11 @@ export class KoolbaseAuth {
23
23
  this.signOutReason = null;
24
24
  /** The last renewal failed for want of a connection, not because the server refused it (#96). */
25
25
  this.renewalUnavailable = false;
26
+ /**
27
+ * Remember me: the choice of the sign-in under way, held until its session
28
+ * is saved -- through a second step (MFA) too. Null: none under way.
29
+ */
30
+ this.pendingRemember = null;
26
31
  this.config = config;
27
32
  this.metadata = new DeviceMetadata(config.appVersion);
28
33
  this.fetchFn = config.fetch ?? ((url, init) => koolbaseFetch(url, init));
@@ -162,6 +167,29 @@ export class KoolbaseAuth {
162
167
  return;
163
168
  await this.setSessionInternal({ ...this.session, user });
164
169
  }
170
+ /** A sign-in starts: its Remember me, omitted meaning remembered. */
171
+ beginSignIn(remember) {
172
+ this.pendingRemember = remember ?? true;
173
+ }
174
+ /**
175
+ * A sign-in's session: told to the storage where it lives first (Remember
176
+ * me), then saved. A refresh or a profile change is not a sign-in and
177
+ * keeps the place the session already has.
178
+ */
179
+ async setSignedInSession(session) {
180
+ const remember = this.pendingRemember ?? true;
181
+ this.pendingRemember = null;
182
+ if (this.storage?.setRemember) {
183
+ try {
184
+ await this.storage.setRemember(remember);
185
+ }
186
+ catch (err) {
187
+ // eslint-disable-next-line no-console
188
+ console.warn('[Koolbase] Could not apply Remember me:', err);
189
+ }
190
+ }
191
+ await this.setSessionInternal(session);
192
+ }
165
193
  async setSessionInternal(session) {
166
194
  this.session = session;
167
195
  this.signOutReason = null;
@@ -345,16 +373,20 @@ export class KoolbaseAuth {
345
373
  };
346
374
  }
347
375
  const session = this.sessionFromBody(data);
348
- await this.setSessionInternal(session);
376
+ this.beginSignIn(undefined);
377
+ await this.setSignedInSession(session);
349
378
  return { status: 'authenticated', user: session.user, session };
350
379
  }
351
380
  async login(params) {
381
+ // Remember me is this device's, never the server's.
382
+ const { remember, ...body } = params;
383
+ this.beginSignIn(remember);
352
384
  const res = await this.authRequest('/v1/sdk/auth/login', {
353
385
  method: 'POST',
354
- body: params,
386
+ body,
355
387
  });
356
388
  const session = await this.parseSessionResponse(res, false);
357
- await this.setSessionInternal(session);
389
+ await this.setSignedInSession(session);
358
390
  return session;
359
391
  }
360
392
  /**
@@ -383,6 +415,7 @@ export class KoolbaseAuth {
383
415
  * but auto-link rule blocked (409).
384
416
  */
385
417
  async signInWithApple(params) {
418
+ this.beginSignIn(params.remember);
386
419
  const body = {
387
420
  identity_token: params.identityToken,
388
421
  };
@@ -412,7 +445,7 @@ export class KoolbaseAuth {
412
445
  body,
413
446
  });
414
447
  const session = await this.parseAppleSessionResponse(res);
415
- await this.setSessionInternal(session);
448
+ await this.setSignedInSession(session);
416
449
  return session;
417
450
  }
418
451
  /**
@@ -438,6 +471,7 @@ export class KoolbaseAuth {
438
471
  * but auto-link rule blocked (409).
439
472
  */
440
473
  async signInWithGoogle(params) {
474
+ this.beginSignIn(params.remember);
441
475
  const body = {
442
476
  identity_token: params.idToken,
443
477
  };
@@ -449,7 +483,7 @@ export class KoolbaseAuth {
449
483
  body,
450
484
  });
451
485
  const session = await this.parseGoogleSessionResponse(res);
452
- await this.setSessionInternal(session);
486
+ await this.setSignedInSession(session);
453
487
  return session;
454
488
  }
455
489
  /**
@@ -1042,12 +1076,13 @@ export class KoolbaseAuth {
1042
1076
  * @throws EmailCodeDisabledError if the project has switched this off
1043
1077
  */
1044
1078
  async signInWithEmailCode(params) {
1079
+ this.beginSignIn(params.remember);
1045
1080
  const res = await this.authRequest('/v1/sdk/auth/email/code/verify', {
1046
1081
  method: 'POST',
1047
1082
  body: { email: params.email, code: params.code },
1048
1083
  });
1049
1084
  const session = await this.parseSessionResponse(res, false);
1050
- await this.setSessionInternal(session);
1085
+ await this.setSignedInSession(session);
1051
1086
  return session;
1052
1087
  }
1053
1088
  // ─── Two-step sign-in (MFA) ─────────────────────────────────────────────
@@ -1067,7 +1102,8 @@ export class KoolbaseAuth {
1067
1102
  body: { challenge_token: params.challengeToken, code: params.code },
1068
1103
  });
1069
1104
  const session = await this.parseSessionResponse(res, false);
1070
- await this.setSessionInternal(session);
1105
+ // The second step of the sign-in that asked for it: its Remember me.
1106
+ await this.setSignedInSession(session);
1071
1107
  return session;
1072
1108
  }
1073
1109
  /**
@@ -1093,7 +1129,7 @@ export class KoolbaseAuth {
1093
1129
  expiresAt: data.expires_at,
1094
1130
  user: this.mapUser(data.user),
1095
1131
  };
1096
- await this.setSessionInternal(session);
1132
+ await this.setSignedInSession(session);
1097
1133
  return { session, recoveryCodesRemaining: Number(data.recovery_codes_remaining ?? 0) };
1098
1134
  }
1099
1135
  /**
@@ -1158,6 +1194,7 @@ export class KoolbaseAuth {
1158
1194
  }
1159
1195
  async verifyOtp(params) {
1160
1196
  this.validatePhone(params.phoneNumber);
1197
+ this.beginSignIn(params.remember);
1161
1198
  const res = await this.authRequest('/v1/sdk/auth/phone/verify-otp', {
1162
1199
  method: 'POST',
1163
1200
  body: {
@@ -1172,7 +1209,7 @@ export class KoolbaseAuth {
1172
1209
  expiresAt: data.expires_at,
1173
1210
  user: this.mapUser(data.user),
1174
1211
  };
1175
- await this.setSessionInternal(session);
1212
+ await this.setSignedInSession(session);
1176
1213
  return { session, isNewUser: data.is_new_user ?? false };
1177
1214
  }
1178
1215
  async linkPhone(params) {
@@ -181,6 +181,13 @@ export interface KoolbaseAuthStorage {
181
181
  saveSession(session: KoolbaseSession): Promise<void>;
182
182
  readSession(): Promise<KoolbaseSession | null>;
183
183
  clear(): Promise<void>;
184
+ /**
185
+ * Remember me: where the next sign-in's session lives, told before it is
186
+ * saved. `true`: as long as the storage keeps anything; `false`: until the
187
+ * tab or browser closes. Optional -- a storage without it (a keychain, the
188
+ * memory one, an app's own) keeps every session as it always has.
189
+ */
190
+ setRemember?(remember: boolean): Promise<void>;
184
191
  }
185
192
  /**
186
193
  * Result of KoolbaseAuth.restoreSession(). Apps should branch on this:
@@ -225,6 +232,13 @@ export interface RegisterParams {
225
232
  export interface LoginParams {
226
233
  email: string;
227
234
  password: string;
235
+ /**
236
+ * Whether this sign-in outlasts the browser (Remember me). Omitted: it
237
+ * does, as always. `false`: the session is kept for this tab only, and
238
+ * ends when it closes -- where the storage can tell the two apart (the
239
+ * browser's, in @koolbase/js; a keychain always keeps it).
240
+ */
241
+ remember?: boolean;
228
242
  }
229
243
  export interface SendOtpParams {
230
244
  phoneNumber: string;
@@ -232,6 +246,13 @@ export interface SendOtpParams {
232
246
  export interface VerifyOtpParams {
233
247
  phoneNumber: string;
234
248
  code: string;
249
+ /**
250
+ * Whether this sign-in outlasts the browser (Remember me). Omitted: it
251
+ * does, as always. `false`: the session is kept for this tab only, and
252
+ * ends when it closes -- where the storage can tell the two apart (the
253
+ * browser's, in @koolbase/js; a keychain always keeps it).
254
+ */
255
+ remember?: boolean;
235
256
  }
236
257
  export interface LinkPhoneParams {
237
258
  phoneNumber: string;
@@ -609,6 +630,13 @@ export interface AppleFullName {
609
630
  export interface SignInWithAppleParams {
610
631
  identityToken: string;
611
632
  nonce?: string;
633
+ /**
634
+ * Whether this sign-in outlasts the browser (Remember me). Omitted: it
635
+ * does, as always. `false`: the session is kept for this tab only, and
636
+ * ends when it closes -- where the storage can tell the two apart (the
637
+ * browser's, in @koolbase/js; a keychain always keeps it).
638
+ */
639
+ remember?: boolean;
612
640
  fullName?: AppleFullName;
613
641
  /** The credential's authorization code: the server exchanges it for the
614
642
  * token it revokes when the account is deleted, as Apple asks. */
@@ -627,6 +655,13 @@ export interface SignInWithAppleParams {
627
655
  export interface SignInWithGoogleParams {
628
656
  idToken: string;
629
657
  nonce?: string;
658
+ /**
659
+ * Whether this sign-in outlasts the browser (Remember me). Omitted: it
660
+ * does, as always. `false`: the session is kept for this tab only, and
661
+ * ends when it closes -- where the storage can tell the two apart (the
662
+ * browser's, in @koolbase/js; a keychain always keeps it).
663
+ */
664
+ remember?: boolean;
630
665
  }
631
666
  export type BatchOp = {
632
667
  type: 'insert';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "12.43.0",
3
+ "version": "12.44.0",
4
4
  "description": "Koolbase SDK core \u2014 shared behaviour behind @koolbase/react-native and @koolbase/js. Install one of those, not this.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/esm/index.d.ts",