@koolbase/core 12.38.2 → 12.41.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/cjs/auth.js CHANGED
@@ -504,6 +504,9 @@ class KoolbaseAuth {
504
504
  }
505
505
  if (code === 'invalid_public_key')
506
506
  throw new errors_1.KoolbaseInvalidPublicKeyError(errorMessage || undefined);
507
+ const preview = (0, errors_1.previewErrorFor)(code);
508
+ if (preview)
509
+ throw preview;
507
510
  if (res.status === 401)
508
511
  throw new auth_errors_js_1.InvalidGoogleTokenError();
509
512
  if (res.status === 403)
@@ -562,6 +565,9 @@ class KoolbaseAuth {
562
565
  }
563
566
  if (code === 'invalid_public_key')
564
567
  throw new errors_1.KoolbaseInvalidPublicKeyError(errorMessage || undefined);
568
+ const preview = (0, errors_1.previewErrorFor)(code);
569
+ if (preview)
570
+ throw preview;
565
571
  if (res.status === 401)
566
572
  throw new auth_errors_js_1.InvalidAppleTokenError();
567
573
  if (res.status === 403)
@@ -1327,6 +1333,9 @@ class KoolbaseAuth {
1327
1333
  throw new auth_errors_js_1.MfaNotEnabledError();
1328
1334
  case 'invalid_public_key':
1329
1335
  throw new errors_1.KoolbaseInvalidPublicKeyError(msg || undefined);
1336
+ case 'preview_not_live':
1337
+ case 'preview_origin_mismatch':
1338
+ throw (0, errors_1.previewErrorFor)(code);
1330
1339
  case 'invalid_credentials':
1331
1340
  throw new auth_errors_js_1.InvalidCredentialsError();
1332
1341
  case 'email_in_use':
@@ -528,6 +528,10 @@ function koolbaseDataError(status, body, fallbackMessage = 'Request failed') {
528
528
  // of the key, not a body's claim about a session.
529
529
  if (code === 'invalid_public_key')
530
530
  return attach(new errors_1.KoolbaseInvalidPublicKeyError(message));
531
+ // A Run preview the API would not serve: setup too, never a sign-out.
532
+ const preview = (0, errors_1.previewErrorFor)(code);
533
+ if (preview)
534
+ return preview;
531
535
  if (status === 401) {
532
536
  return new errors_js_1.KoolbaseUnauthenticatedError(message);
533
537
  }
@@ -89,6 +89,25 @@ export declare class KoolbaseServiceUnavailableError extends KoolbaseError {
89
89
  export declare class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
90
90
  constructor(message: string);
91
91
  }
92
+ /** What an ended Run preview says. */
93
+ export declare const PREVIEW_ENDED_MESSAGE = "This preview has ended. Press Run in the Koolbase Designer for a new one.";
94
+ /** What a Run preview says when a request carried another project's key. */
95
+ export declare const PREVIEW_OTHER_PROJECT_MESSAGE = "This preview can only use its own project's Koolbase key.";
96
+ /**
97
+ * A request from a Run preview the API would not serve: the preview has ended
98
+ * (`preview_not_live`: replaced by a newer Run, or past its 7 days), or it
99
+ * carried a key or session from another project (`preview_origin_mismatch`).
100
+ * Only Run previews meet it, never a published app. Like a refused key it is
101
+ * setup, not the user's session: it never signs anyone out.
102
+ */
103
+ export declare class KoolbasePreviewError extends KoolbaseError {
104
+ constructor(message: string, code: 'preview_not_live' | 'preview_origin_mismatch');
105
+ }
106
+ /** The refusal for a server code, or null when the code is not one. */
107
+ export declare function previewErrorFor(code: unknown): KoolbasePreviewError | null;
108
+ /** The refusal in a failed response's body, when a Run preview's request was
109
+ * refused; null otherwise. For paths that read a status before a code. */
110
+ export declare function previewRefusalIn(body: string): KoolbasePreviewError | null;
92
111
  /** What the server says for a refused app key, word for word. */
93
112
  export declare const INVALID_PUBLIC_KEY_MESSAGE = "This app's Koolbase key isn't valid for this project.";
94
113
  /**
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KoolbaseInvalidPublicKeyError = exports.INVALID_PUBLIC_KEY_MESSAGE = exports.KoolbaseOfflineBaselineUnavailableError = exports.KoolbaseServiceUnavailableError = exports.KoolbasePlanLimitError = exports.KoolbaseUnauthenticatedError = exports.KoolbaseError = void 0;
3
+ exports.KoolbaseInvalidPublicKeyError = exports.INVALID_PUBLIC_KEY_MESSAGE = exports.KoolbasePreviewError = exports.PREVIEW_OTHER_PROJECT_MESSAGE = exports.PREVIEW_ENDED_MESSAGE = exports.KoolbaseOfflineBaselineUnavailableError = exports.KoolbaseServiceUnavailableError = exports.KoolbasePlanLimitError = exports.KoolbaseUnauthenticatedError = exports.KoolbaseError = void 0;
4
+ exports.previewErrorFor = previewErrorFor;
5
+ exports.previewRefusalIn = previewRefusalIn;
4
6
  exports.invalidPublicKeyIn = invalidPublicKeyIn;
5
7
  /**
6
8
  * The root of every error the SDK raises.
@@ -121,6 +123,44 @@ class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
121
123
  }
122
124
  }
123
125
  exports.KoolbaseOfflineBaselineUnavailableError = KoolbaseOfflineBaselineUnavailableError;
126
+ /** What an ended Run preview says. */
127
+ exports.PREVIEW_ENDED_MESSAGE = 'This preview has ended. Press Run in the Koolbase Designer for a new one.';
128
+ /** What a Run preview says when a request carried another project's key. */
129
+ exports.PREVIEW_OTHER_PROJECT_MESSAGE = "This preview can only use its own project's Koolbase key.";
130
+ /**
131
+ * A request from a Run preview the API would not serve: the preview has ended
132
+ * (`preview_not_live`: replaced by a newer Run, or past its 7 days), or it
133
+ * carried a key or session from another project (`preview_origin_mismatch`).
134
+ * Only Run previews meet it, never a published app. Like a refused key it is
135
+ * setup, not the user's session: it never signs anyone out.
136
+ */
137
+ class KoolbasePreviewError extends KoolbaseError {
138
+ constructor(message, code) {
139
+ super(message, code);
140
+ this.name = 'KoolbasePreviewError';
141
+ Object.setPrototypeOf(this, new.target.prototype);
142
+ }
143
+ }
144
+ exports.KoolbasePreviewError = KoolbasePreviewError;
145
+ /** The refusal for a server code, or null when the code is not one. */
146
+ function previewErrorFor(code) {
147
+ if (code === 'preview_not_live')
148
+ return new KoolbasePreviewError(exports.PREVIEW_ENDED_MESSAGE, code);
149
+ if (code === 'preview_origin_mismatch')
150
+ return new KoolbasePreviewError(exports.PREVIEW_OTHER_PROJECT_MESSAGE, code);
151
+ return null;
152
+ }
153
+ /** The refusal in a failed response's body, when a Run preview's request was
154
+ * refused; null otherwise. For paths that read a status before a code. */
155
+ function previewRefusalIn(body) {
156
+ try {
157
+ const j = JSON.parse(body);
158
+ return j && typeof j === 'object' ? previewErrorFor(j.code) : null;
159
+ }
160
+ catch {
161
+ return null;
162
+ }
163
+ }
124
164
  /** What the server says for a refused app key, word for word. */
125
165
  exports.INVALID_PUBLIC_KEY_MESSAGE = "This app's Koolbase key isn't valid for this project.";
126
166
  /**
@@ -94,6 +94,10 @@ class KoolbaseFiscal {
94
94
  const badKey = (0, errors_1.invalidPublicKeyIn)(text);
95
95
  if (badKey)
96
96
  throw badKey;
97
+ // A Run preview the API would not serve: a 403, but not a sign-out.
98
+ const preview = (0, errors_1.previewRefusalIn)(text);
99
+ if (preview)
100
+ throw preview;
97
101
  if (res.status === 401 || res.status === 403) {
98
102
  await this.onSessionExpired?.();
99
103
  throw new errors_js_1.KoolbaseUnauthenticatedError(`fiscal: unauthenticated (${res.status})`);
package/dist/cjs/flags.js CHANGED
@@ -75,6 +75,7 @@ class KoolbaseFlags {
75
75
  status: 'force_update',
76
76
  message: policy.update_message,
77
77
  latestVersion: policy.latest_version,
78
+ ...(policy.store_url ? { storeUrl: policy.store_url } : {}),
78
79
  };
79
80
  }
80
81
  if (policy.latest_version && current < latest) {
@@ -82,6 +83,7 @@ class KoolbaseFlags {
82
83
  status: policy.force_update ? 'force_update' : 'soft_update',
83
84
  message: policy.update_message,
84
85
  latestVersion: policy.latest_version,
86
+ ...(policy.store_url ? { storeUrl: policy.store_url } : {}),
85
87
  };
86
88
  }
87
89
  return { status: 'up_to_date', message: '', latestVersion: policy.latest_version };
@@ -113,6 +113,10 @@ class FunctionRateLimitError extends FunctionInvokeError {
113
113
  exports.FunctionRateLimitError = FunctionRateLimitError;
114
114
  /** Builds the right error for a failed invocation. */
115
115
  function functionInvokeError(status, message, code) {
116
+ // A Run preview the API would not serve: setup, never a sign-out.
117
+ const preview = (0, errors_1.previewErrorFor)(code);
118
+ if (preview)
119
+ return preview;
116
120
  switch (status) {
117
121
  case 401:
118
122
  // A refused app key is setup, not a session (#169): never signs out.
@@ -34,7 +34,7 @@ export { KoolbaseAnalytics, disabledAnalytics } from './analytics.js';
34
34
  export { KoolbaseFiscal, KoolbaseFiscalError, decodeFiscalResponse, isFiscalized, isPending } from './fiscal.js';
35
35
  export type { FiscalIntentResult, FiscalStatus } from './fiscal.js';
36
36
  export { KoolbaseMessaging } from './messaging.js';
37
- export type { RegisterTokenOptions } from './messaging.js';
37
+ export type { RegisterTokenOptions, KoolbaseMessagingPlatform } from './messaging.js';
38
38
  export { getOrCreateDeviceId } from './device-id.js';
39
39
  export { koolbaseSdkVersion } from './device-metadata.js';
40
40
  export { RestoreResult } from './types.js';
@@ -1,13 +1,30 @@
1
1
  import { KoolbaseConfig } from './types.js';
2
+ /** The platforms a token registers as: a phone's FCM token, or a browser's (R138). */
3
+ export type KoolbaseMessagingPlatform = 'android' | 'ios' | 'web';
2
4
  export interface RegisterTokenOptions {
3
5
  token: string;
4
- platform: 'android' | 'ios';
6
+ platform: KoolbaseMessagingPlatform;
7
+ /** Ignored by the API (the owner comes from the session); kept for compatibility. */
5
8
  userId?: string;
6
9
  }
7
10
  export declare class KoolbaseMessaging {
8
11
  private config;
9
12
  private deviceId;
10
- constructor(config: KoolbaseConfig);
13
+ private accessToken;
14
+ /** The last token registered, and its platform: registered again when
15
+ * someone signs in or out, so the device follows who is signed in. */
16
+ private last;
17
+ /** [accessToken]: the signed-in person's, or null -- the device is theirs
18
+ * only while they are signed in (the API takes the owner from it, never
19
+ * from the request body). */
20
+ constructor(config: KoolbaseConfig, accessToken?: () => Promise<string | null>);
11
21
  setDeviceId(deviceId: string): void;
22
+ /** Registers an FCM token with Koolbase -- tied to the signed-in person, if
23
+ * someone is signed in (R138). Call it after getting the token, and again
24
+ * when it changes; signing in or out registers it again by itself. */
12
25
  registerToken(options: RegisterTokenOptions): Promise<boolean>;
26
+ /** Someone signed in or out (Koolbase wires it): the last token is
27
+ * registered again. Nothing before a token is registered. */
28
+ sessionChanged(): Promise<void>;
29
+ private send;
13
30
  }
@@ -2,30 +2,51 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KoolbaseMessaging = void 0;
4
4
  const network_js_1 = require("./network.js");
5
+ const PLATFORMS = new Set(['android', 'ios', 'web']);
5
6
  // ─── KoolbaseMessaging ────────────────────────────────────────────────────────
6
7
  class KoolbaseMessaging {
7
- constructor(config) {
8
+ /** [accessToken]: the signed-in person's, or null -- the device is theirs
9
+ * only while they are signed in (the API takes the owner from it, never
10
+ * from the request body). */
11
+ constructor(config, accessToken = () => Promise.resolve(null)) {
8
12
  this.deviceId = '';
13
+ /** The last token registered, and its platform: registered again when
14
+ * someone signs in or out, so the device follows who is signed in. */
15
+ this.last = null;
9
16
  this.config = config;
17
+ this.accessToken = accessToken;
10
18
  }
11
19
  setDeviceId(deviceId) {
12
20
  this.deviceId = deviceId;
13
21
  }
14
22
  // ─── Register token ───────────────────────────────────────────────────────
23
+ /** Registers an FCM token with Koolbase -- tied to the signed-in person, if
24
+ * someone is signed in (R138). Call it after getting the token, and again
25
+ * when it changes; signing in or out registers it again by itself. */
15
26
  async registerToken(options) {
27
+ if (!PLATFORMS.has(options.platform))
28
+ return false;
29
+ this.last = { token: options.token, platform: options.platform };
30
+ return this.send(options.token, options.platform);
31
+ }
32
+ /** Someone signed in or out (Koolbase wires it): the last token is
33
+ * registered again. Nothing before a token is registered. */
34
+ async sessionChanged() {
35
+ if (this.last === null)
36
+ return;
37
+ await this.send(this.last.token, this.last.platform);
38
+ }
39
+ async send(token, platform) {
16
40
  try {
41
+ const access = await this.accessToken().catch(() => null);
17
42
  const response = await (0, network_js_1.koolbaseFetch)(`${this.config.baseUrl}/v1/messaging/register`, {
18
43
  method: 'POST',
19
44
  headers: {
20
45
  'Content-Type': 'application/json',
21
46
  'x-api-key': this.config.publicKey,
47
+ ...(access ? { Authorization: `Bearer ${access}` } : {}),
22
48
  },
23
- body: JSON.stringify({
24
- device_id: this.deviceId,
25
- token: options.token,
26
- platform: options.platform,
27
- ...(options.userId && { user_id: options.userId }),
28
- }),
49
+ body: JSON.stringify({ device_id: this.deviceId, token, platform }),
29
50
  });
30
51
  return response.ok;
31
52
  }
@@ -410,6 +410,10 @@ exports.KoolbaseStorageQuarantinedError = KoolbaseStorageQuarantinedError;
410
410
  function koolbaseStorageError(status, body, fallbackMessage = 'Storage request failed') {
411
411
  const code = body?.code;
412
412
  const message = body?.error ?? fallbackMessage;
413
+ // A Run preview the API would not serve: setup, never a sign-out.
414
+ const preview = (0, errors_1.previewErrorFor)(code);
415
+ if (preview)
416
+ return preview;
413
417
  // ─── code-first ───
414
418
  switch (code) {
415
419
  case 'path_conflict':
@@ -548,6 +548,8 @@ export interface BootstrapPayload {
548
548
  latest_version: string;
549
549
  force_update: boolean;
550
550
  update_message: string;
551
+ /** The store page set in the dashboard for this app's platform (API, Nov 2026). */
552
+ store_url?: string;
551
553
  };
552
554
  }
553
555
  export type VersionStatus = 'up_to_date' | 'soft_update' | 'force_update';
@@ -555,6 +557,12 @@ export interface VersionCheckResult {
555
557
  status: VersionStatus;
556
558
  message: string;
557
559
  latestVersion: string;
560
+ /**
561
+ * Where to send the person to update: the store page set in the dashboard's
562
+ * version policy for this platform. Absent when up to date, or when no
563
+ * store page was set.
564
+ */
565
+ storeUrl?: string;
558
566
  }
559
567
  export declare enum FunctionRuntime {
560
568
  Deno = "deno",
package/dist/esm/auth.js CHANGED
@@ -1,4 +1,4 @@
1
- import { KoolbaseInvalidPublicKeyError } from './errors';
1
+ import { KoolbaseInvalidPublicKeyError, previewErrorFor } from './errors';
2
2
  import { koolbaseFetch } from './network.js';
3
3
  import { RestoreResult, } from './types.js';
4
4
  import { AccountLockedError, EmailAlreadyInUseError, InvalidCredentialsError, InvalidPhoneNumberError, KoolbaseAuthError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, IdentityNotFoundError, InsufficientScopeError, MalformedSessionResponseError, ProviderIdentityAlreadyLinkedError, AccountExistsError, ContactNotVerifiedError, CurrentPasswordIncorrectError, HideRequiresVerificationError, InsufficientAuthorityError, LastCredentialError, OAuthOnlyAccountError, SessionRequiredError, SignupsDisabledError, TokenAlreadyUsedError, TokenExpiredError, UnsupportedOAuthProviderError, RateLimitError, retryAfterOf, VerificationResendCooldownError, VerificationResendDailyCapError, SessionExpiredError, SmsConfigMissingError, TokenRevokedError, UnlockTokenInvalidError, UserDisabledError, WeakPasswordError, AppleEmailRequiredError, AppleSignInNotConfiguredError, InvalidAppleTokenError, OAuthEmailConflictError, GoogleEmailRequiredError, GoogleSignInNotConfiguredError, InvalidGoogleTokenError, EmailCodeDisabledError, MfaRequiredError, RecentAuthRequiredError, RecentMfaRequiredError, MfaAlreadyEnabledError, MfaEnrollmentNotFoundError, MfaNotEnabledError, } from './auth-errors.js';
@@ -501,6 +501,9 @@ export class KoolbaseAuth {
501
501
  }
502
502
  if (code === 'invalid_public_key')
503
503
  throw new KoolbaseInvalidPublicKeyError(errorMessage || undefined);
504
+ const preview = previewErrorFor(code);
505
+ if (preview)
506
+ throw preview;
504
507
  if (res.status === 401)
505
508
  throw new InvalidGoogleTokenError();
506
509
  if (res.status === 403)
@@ -559,6 +562,9 @@ export class KoolbaseAuth {
559
562
  }
560
563
  if (code === 'invalid_public_key')
561
564
  throw new KoolbaseInvalidPublicKeyError(errorMessage || undefined);
565
+ const preview = previewErrorFor(code);
566
+ if (preview)
567
+ throw preview;
562
568
  if (res.status === 401)
563
569
  throw new InvalidAppleTokenError();
564
570
  if (res.status === 403)
@@ -1324,6 +1330,9 @@ export class KoolbaseAuth {
1324
1330
  throw new MfaNotEnabledError();
1325
1331
  case 'invalid_public_key':
1326
1332
  throw new KoolbaseInvalidPublicKeyError(msg || undefined);
1333
+ case 'preview_not_live':
1334
+ case 'preview_origin_mismatch':
1335
+ throw previewErrorFor(code);
1327
1336
  case 'invalid_credentials':
1328
1337
  throw new InvalidCredentialsError();
1329
1338
  case 'email_in_use':
@@ -1,4 +1,4 @@
1
- import { KoolbaseInvalidPublicKeyError } from './errors';
1
+ import { KoolbaseInvalidPublicKeyError, previewErrorFor } from './errors';
2
2
  import { KoolbaseError, KoolbasePlanLimitError, KoolbaseServiceUnavailableError, KoolbaseUnauthenticatedError } from './errors.js';
3
3
  /**
4
4
  * Base class for errors surfaced by the Koolbase data layer (database reads
@@ -490,6 +490,10 @@ export function koolbaseDataError(status, body, fallbackMessage = 'Request faile
490
490
  // of the key, not a body's claim about a session.
491
491
  if (code === 'invalid_public_key')
492
492
  return attach(new KoolbaseInvalidPublicKeyError(message));
493
+ // A Run preview the API would not serve: setup too, never a sign-out.
494
+ const preview = previewErrorFor(code);
495
+ if (preview)
496
+ return preview;
493
497
  if (status === 401) {
494
498
  return new KoolbaseUnauthenticatedError(message);
495
499
  }
@@ -89,6 +89,25 @@ export declare class KoolbaseServiceUnavailableError extends KoolbaseError {
89
89
  export declare class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
90
90
  constructor(message: string);
91
91
  }
92
+ /** What an ended Run preview says. */
93
+ export declare const PREVIEW_ENDED_MESSAGE = "This preview has ended. Press Run in the Koolbase Designer for a new one.";
94
+ /** What a Run preview says when a request carried another project's key. */
95
+ export declare const PREVIEW_OTHER_PROJECT_MESSAGE = "This preview can only use its own project's Koolbase key.";
96
+ /**
97
+ * A request from a Run preview the API would not serve: the preview has ended
98
+ * (`preview_not_live`: replaced by a newer Run, or past its 7 days), or it
99
+ * carried a key or session from another project (`preview_origin_mismatch`).
100
+ * Only Run previews meet it, never a published app. Like a refused key it is
101
+ * setup, not the user's session: it never signs anyone out.
102
+ */
103
+ export declare class KoolbasePreviewError extends KoolbaseError {
104
+ constructor(message: string, code: 'preview_not_live' | 'preview_origin_mismatch');
105
+ }
106
+ /** The refusal for a server code, or null when the code is not one. */
107
+ export declare function previewErrorFor(code: unknown): KoolbasePreviewError | null;
108
+ /** The refusal in a failed response's body, when a Run preview's request was
109
+ * refused; null otherwise. For paths that read a status before a code. */
110
+ export declare function previewRefusalIn(body: string): KoolbasePreviewError | null;
92
111
  /** What the server says for a refused app key, word for word. */
93
112
  export declare const INVALID_PUBLIC_KEY_MESSAGE = "This app's Koolbase key isn't valid for this project.";
94
113
  /**
@@ -112,6 +112,43 @@ export class KoolbaseOfflineBaselineUnavailableError extends KoolbaseError {
112
112
  Object.setPrototypeOf(this, new.target.prototype);
113
113
  }
114
114
  }
115
+ /** What an ended Run preview says. */
116
+ export const PREVIEW_ENDED_MESSAGE = 'This preview has ended. Press Run in the Koolbase Designer for a new one.';
117
+ /** What a Run preview says when a request carried another project's key. */
118
+ export const PREVIEW_OTHER_PROJECT_MESSAGE = "This preview can only use its own project's Koolbase key.";
119
+ /**
120
+ * A request from a Run preview the API would not serve: the preview has ended
121
+ * (`preview_not_live`: replaced by a newer Run, or past its 7 days), or it
122
+ * carried a key or session from another project (`preview_origin_mismatch`).
123
+ * Only Run previews meet it, never a published app. Like a refused key it is
124
+ * setup, not the user's session: it never signs anyone out.
125
+ */
126
+ export class KoolbasePreviewError extends KoolbaseError {
127
+ constructor(message, code) {
128
+ super(message, code);
129
+ this.name = 'KoolbasePreviewError';
130
+ Object.setPrototypeOf(this, new.target.prototype);
131
+ }
132
+ }
133
+ /** The refusal for a server code, or null when the code is not one. */
134
+ export function previewErrorFor(code) {
135
+ if (code === 'preview_not_live')
136
+ return new KoolbasePreviewError(PREVIEW_ENDED_MESSAGE, code);
137
+ if (code === 'preview_origin_mismatch')
138
+ return new KoolbasePreviewError(PREVIEW_OTHER_PROJECT_MESSAGE, code);
139
+ return null;
140
+ }
141
+ /** The refusal in a failed response's body, when a Run preview's request was
142
+ * refused; null otherwise. For paths that read a status before a code. */
143
+ export function previewRefusalIn(body) {
144
+ try {
145
+ const j = JSON.parse(body);
146
+ return j && typeof j === 'object' ? previewErrorFor(j.code) : null;
147
+ }
148
+ catch {
149
+ return null;
150
+ }
151
+ }
115
152
  /** What the server says for a refused app key, word for word. */
116
153
  export const INVALID_PUBLIC_KEY_MESSAGE = "This app's Koolbase key isn't valid for this project.";
117
154
  /**
@@ -1,4 +1,4 @@
1
- import { invalidPublicKeyIn } from './errors';
1
+ import { invalidPublicKeyIn, previewRefusalIn } from './errors';
2
2
  import { sessionFetch } from './network.js';
3
3
  import { KoolbaseError, KoolbaseUnauthenticatedError } from './errors.js';
4
4
  const KNOWN_STATUSES = [
@@ -87,6 +87,10 @@ export class KoolbaseFiscal {
87
87
  const badKey = invalidPublicKeyIn(text);
88
88
  if (badKey)
89
89
  throw badKey;
90
+ // A Run preview the API would not serve: a 403, but not a sign-out.
91
+ const preview = previewRefusalIn(text);
92
+ if (preview)
93
+ throw preview;
90
94
  if (res.status === 401 || res.status === 403) {
91
95
  await this.onSessionExpired?.();
92
96
  throw new KoolbaseUnauthenticatedError(`fiscal: unauthenticated (${res.status})`);
package/dist/esm/flags.js CHANGED
@@ -72,6 +72,7 @@ export class KoolbaseFlags {
72
72
  status: 'force_update',
73
73
  message: policy.update_message,
74
74
  latestVersion: policy.latest_version,
75
+ ...(policy.store_url ? { storeUrl: policy.store_url } : {}),
75
76
  };
76
77
  }
77
78
  if (policy.latest_version && current < latest) {
@@ -79,6 +80,7 @@ export class KoolbaseFlags {
79
80
  status: policy.force_update ? 'force_update' : 'soft_update',
80
81
  message: policy.update_message,
81
82
  latestVersion: policy.latest_version,
83
+ ...(policy.store_url ? { storeUrl: policy.store_url } : {}),
82
84
  };
83
85
  }
84
86
  return { status: 'up_to_date', message: '', latestVersion: policy.latest_version };
@@ -1,4 +1,4 @@
1
- import { KoolbaseInvalidPublicKeyError, INVALID_PUBLIC_KEY_MESSAGE } from './errors';
1
+ import { KoolbaseInvalidPublicKeyError, INVALID_PUBLIC_KEY_MESSAGE, previewErrorFor } from './errors';
2
2
  import { KoolbaseError, KoolbaseUnauthenticatedError } from './errors.js';
3
3
  /**
4
4
  * A Function call did not succeed.
@@ -101,6 +101,10 @@ export class FunctionRateLimitError extends FunctionInvokeError {
101
101
  }
102
102
  /** Builds the right error for a failed invocation. */
103
103
  export function functionInvokeError(status, message, code) {
104
+ // A Run preview the API would not serve: setup, never a sign-out.
105
+ const preview = previewErrorFor(code);
106
+ if (preview)
107
+ return preview;
104
108
  switch (status) {
105
109
  case 401:
106
110
  // A refused app key is setup, not a session (#169): never signs out.
@@ -34,7 +34,7 @@ export { KoolbaseAnalytics, disabledAnalytics } from './analytics.js';
34
34
  export { KoolbaseFiscal, KoolbaseFiscalError, decodeFiscalResponse, isFiscalized, isPending } from './fiscal.js';
35
35
  export type { FiscalIntentResult, FiscalStatus } from './fiscal.js';
36
36
  export { KoolbaseMessaging } from './messaging.js';
37
- export type { RegisterTokenOptions } from './messaging.js';
37
+ export type { RegisterTokenOptions, KoolbaseMessagingPlatform } from './messaging.js';
38
38
  export { getOrCreateDeviceId } from './device-id.js';
39
39
  export { koolbaseSdkVersion } from './device-metadata.js';
40
40
  export { RestoreResult } from './types.js';
@@ -1,13 +1,30 @@
1
1
  import { KoolbaseConfig } from './types.js';
2
+ /** The platforms a token registers as: a phone's FCM token, or a browser's (R138). */
3
+ export type KoolbaseMessagingPlatform = 'android' | 'ios' | 'web';
2
4
  export interface RegisterTokenOptions {
3
5
  token: string;
4
- platform: 'android' | 'ios';
6
+ platform: KoolbaseMessagingPlatform;
7
+ /** Ignored by the API (the owner comes from the session); kept for compatibility. */
5
8
  userId?: string;
6
9
  }
7
10
  export declare class KoolbaseMessaging {
8
11
  private config;
9
12
  private deviceId;
10
- constructor(config: KoolbaseConfig);
13
+ private accessToken;
14
+ /** The last token registered, and its platform: registered again when
15
+ * someone signs in or out, so the device follows who is signed in. */
16
+ private last;
17
+ /** [accessToken]: the signed-in person's, or null -- the device is theirs
18
+ * only while they are signed in (the API takes the owner from it, never
19
+ * from the request body). */
20
+ constructor(config: KoolbaseConfig, accessToken?: () => Promise<string | null>);
11
21
  setDeviceId(deviceId: string): void;
22
+ /** Registers an FCM token with Koolbase -- tied to the signed-in person, if
23
+ * someone is signed in (R138). Call it after getting the token, and again
24
+ * when it changes; signing in or out registers it again by itself. */
12
25
  registerToken(options: RegisterTokenOptions): Promise<boolean>;
26
+ /** Someone signed in or out (Koolbase wires it): the last token is
27
+ * registered again. Nothing before a token is registered. */
28
+ sessionChanged(): Promise<void>;
29
+ private send;
13
30
  }
@@ -1,28 +1,49 @@
1
1
  import { koolbaseFetch } from './network.js';
2
+ const PLATFORMS = new Set(['android', 'ios', 'web']);
2
3
  // ─── KoolbaseMessaging ────────────────────────────────────────────────────────
3
4
  export class KoolbaseMessaging {
4
- constructor(config) {
5
+ /** [accessToken]: the signed-in person's, or null -- the device is theirs
6
+ * only while they are signed in (the API takes the owner from it, never
7
+ * from the request body). */
8
+ constructor(config, accessToken = () => Promise.resolve(null)) {
5
9
  this.deviceId = '';
10
+ /** The last token registered, and its platform: registered again when
11
+ * someone signs in or out, so the device follows who is signed in. */
12
+ this.last = null;
6
13
  this.config = config;
14
+ this.accessToken = accessToken;
7
15
  }
8
16
  setDeviceId(deviceId) {
9
17
  this.deviceId = deviceId;
10
18
  }
11
19
  // ─── Register token ───────────────────────────────────────────────────────
20
+ /** Registers an FCM token with Koolbase -- tied to the signed-in person, if
21
+ * someone is signed in (R138). Call it after getting the token, and again
22
+ * when it changes; signing in or out registers it again by itself. */
12
23
  async registerToken(options) {
24
+ if (!PLATFORMS.has(options.platform))
25
+ return false;
26
+ this.last = { token: options.token, platform: options.platform };
27
+ return this.send(options.token, options.platform);
28
+ }
29
+ /** Someone signed in or out (Koolbase wires it): the last token is
30
+ * registered again. Nothing before a token is registered. */
31
+ async sessionChanged() {
32
+ if (this.last === null)
33
+ return;
34
+ await this.send(this.last.token, this.last.platform);
35
+ }
36
+ async send(token, platform) {
13
37
  try {
38
+ const access = await this.accessToken().catch(() => null);
14
39
  const response = await koolbaseFetch(`${this.config.baseUrl}/v1/messaging/register`, {
15
40
  method: 'POST',
16
41
  headers: {
17
42
  'Content-Type': 'application/json',
18
43
  'x-api-key': this.config.publicKey,
44
+ ...(access ? { Authorization: `Bearer ${access}` } : {}),
19
45
  },
20
- body: JSON.stringify({
21
- device_id: this.deviceId,
22
- token: options.token,
23
- platform: options.platform,
24
- ...(options.userId && { user_id: options.userId }),
25
- }),
46
+ body: JSON.stringify({ device_id: this.deviceId, token, platform }),
26
47
  });
27
48
  return response.ok;
28
49
  }
@@ -1,4 +1,4 @@
1
- import { KoolbaseInvalidPublicKeyError } from './errors';
1
+ import { KoolbaseInvalidPublicKeyError, previewErrorFor } from './errors';
2
2
  import { KoolbaseError, KoolbasePlanLimitError, KoolbaseServiceUnavailableError, KoolbaseUnauthenticatedError } from './errors.js';
3
3
  /**
4
4
  * Base error type for all Koolbase storage errors. Catchable via
@@ -381,6 +381,10 @@ export class KoolbaseStorageQuarantinedError extends KoolbaseStorageError {
381
381
  export function koolbaseStorageError(status, body, fallbackMessage = 'Storage request failed') {
382
382
  const code = body?.code;
383
383
  const message = body?.error ?? fallbackMessage;
384
+ // A Run preview the API would not serve: setup, never a sign-out.
385
+ const preview = previewErrorFor(code);
386
+ if (preview)
387
+ return preview;
384
388
  // ─── code-first ───
385
389
  switch (code) {
386
390
  case 'path_conflict':
@@ -548,6 +548,8 @@ export interface BootstrapPayload {
548
548
  latest_version: string;
549
549
  force_update: boolean;
550
550
  update_message: string;
551
+ /** The store page set in the dashboard for this app's platform (API, Nov 2026). */
552
+ store_url?: string;
551
553
  };
552
554
  }
553
555
  export type VersionStatus = 'up_to_date' | 'soft_update' | 'force_update';
@@ -555,6 +557,12 @@ export interface VersionCheckResult {
555
557
  status: VersionStatus;
556
558
  message: string;
557
559
  latestVersion: string;
560
+ /**
561
+ * Where to send the person to update: the store page set in the dashboard's
562
+ * version policy for this platform. Absent when up to date, or when no
563
+ * store page was set.
564
+ */
565
+ storeUrl?: string;
558
566
  }
559
567
  export declare enum FunctionRuntime {
560
568
  Deno = "deno",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koolbase/core",
3
- "version": "12.38.2",
3
+ "version": "12.41.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",