@koolbase/react-native 9.1.0 → 10.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/CHANGELOG.md +1342 -0
- package/README.md +462 -511
- package/dist/{auth-storage.d.ts → cjs/auth-storage.d.ts} +1 -1
- package/dist/cjs/index.d.ts +19 -0
- package/dist/cjs/index.js +125 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/platform.d.ts +2 -0
- package/dist/cjs/platform.js +43 -0
- package/dist/esm/auth-storage.d.ts +26 -0
- package/dist/esm/auth-storage.js +100 -0
- package/dist/esm/index.d.ts +19 -0
- package/dist/esm/index.js +106 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/platform.d.ts +2 -0
- package/dist/esm/platform.js +37 -0
- package/package.json +30 -24
- package/dist/analytics.d.ts +0 -24
- package/dist/analytics.js +0 -114
- package/dist/apple-auth.d.ts +0 -22
- package/dist/apple-auth.js +0 -74
- package/dist/auth-errors.d.ts +0 -117
- package/dist/auth-errors.js +0 -250
- package/dist/auth.d.ts +0 -199
- package/dist/auth.js +0 -794
- package/dist/cache-store.d.ts +0 -11
- package/dist/cache-store.js +0 -136
- package/dist/code-push.d.ts +0 -59
- package/dist/code-push.js +0 -255
- package/dist/database-errors.d.ts +0 -95
- package/dist/database-errors.js +0 -173
- package/dist/database.d.ts +0 -208
- package/dist/database.js +0 -508
- package/dist/device-id.d.ts +0 -1
- package/dist/device-id.js +0 -60
- package/dist/device-metadata.d.ts +0 -36
- package/dist/device-metadata.js +0 -102
- package/dist/flags.d.ts +0 -15
- package/dist/flags.js +0 -76
- package/dist/functions.d.ts +0 -8
- package/dist/functions.js +0 -70
- package/dist/index.d.ts +0 -45
- package/dist/index.js +0 -193
- package/dist/logic-engine.d.ts +0 -17
- package/dist/logic-engine.js +0 -193
- package/dist/messaging.d.ts +0 -13
- package/dist/messaging.js +0 -36
- package/dist/realtime.d.ts +0 -19
- package/dist/realtime.js +0 -148
- package/dist/record.d.ts +0 -2
- package/dist/record.js +0 -20
- package/dist/storage-errors.d.ts +0 -163
- package/dist/storage-errors.js +0 -249
- package/dist/storage.d.ts +0 -184
- package/dist/storage.js +0 -438
- package/dist/sync-engine.d.ts +0 -16
- package/dist/sync-engine.js +0 -86
- package/dist/types.d.ts +0 -470
- package/dist/types.js +0 -40
- /package/dist/{auth-storage.js → cjs/auth-storage.js} +0 -0
package/dist/analytics.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseAnalytics = void 0;
|
|
4
|
-
const react_native_1 = require("react-native");
|
|
5
|
-
const device_id_1 = require("./device-id");
|
|
6
|
-
// ─── KoolbaseAnalytics ───────────────────────────────────────────────────────
|
|
7
|
-
const SDK_VERSION = '1.3.0';
|
|
8
|
-
const DEVICE_ID_KEY = 'koolbase:device_id';
|
|
9
|
-
const FLUSH_INTERVAL_MS = 30000;
|
|
10
|
-
const MAX_BATCH_SIZE = 20;
|
|
11
|
-
class KoolbaseAnalytics {
|
|
12
|
-
constructor(config) {
|
|
13
|
-
this.queue = [];
|
|
14
|
-
this.deviceId = '';
|
|
15
|
-
this.userProperties = {};
|
|
16
|
-
this.sessionId = '';
|
|
17
|
-
this.appVersion = '1.0.0';
|
|
18
|
-
this.initialized = false;
|
|
19
|
-
this.config = config;
|
|
20
|
-
}
|
|
21
|
-
// ─── Init ─────────────────────────────────────────────────────────────────
|
|
22
|
-
async init(appVersion) {
|
|
23
|
-
if (this.initialized)
|
|
24
|
-
return;
|
|
25
|
-
this.deviceId = await (0, device_id_1.getOrCreateDeviceId)();
|
|
26
|
-
this.sessionId = `${this.deviceId}-${Date.now()}`;
|
|
27
|
-
this.appVersion = appVersion ?? '1.0.0';
|
|
28
|
-
// Auto flush on app background
|
|
29
|
-
react_native_1.AppState.addEventListener('change', (state) => {
|
|
30
|
-
if (state === 'background' || state === 'inactive') {
|
|
31
|
-
this.flush();
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
// Periodic flush
|
|
35
|
-
this.flushTimer = setInterval(() => this.flush(), FLUSH_INTERVAL_MS);
|
|
36
|
-
// Auto track app_open
|
|
37
|
-
this.track('app_open');
|
|
38
|
-
this.initialized = true;
|
|
39
|
-
}
|
|
40
|
-
// ─── Public API ───────────────────────────────────────────────────────────
|
|
41
|
-
track(eventName, properties) {
|
|
42
|
-
const event = {
|
|
43
|
-
device_id: this.deviceId,
|
|
44
|
-
user_id: this.userId,
|
|
45
|
-
environment_id: this.environmentId,
|
|
46
|
-
event_name: eventName,
|
|
47
|
-
properties: properties ?? {},
|
|
48
|
-
user_properties: { ...this.userProperties },
|
|
49
|
-
platform: react_native_1.Platform.OS,
|
|
50
|
-
app_version: this.appVersion,
|
|
51
|
-
sdk_version: SDK_VERSION,
|
|
52
|
-
session_id: this.sessionId,
|
|
53
|
-
occurred_at: new Date().toISOString(),
|
|
54
|
-
};
|
|
55
|
-
this.queue.push(event);
|
|
56
|
-
if (this.queue.length >= MAX_BATCH_SIZE) {
|
|
57
|
-
this.flush();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
screenView(screenName, properties) {
|
|
61
|
-
this.track('screen_view', {
|
|
62
|
-
screen_name: screenName,
|
|
63
|
-
...properties,
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
identify(userId) {
|
|
67
|
-
this.userId = userId;
|
|
68
|
-
}
|
|
69
|
-
setUserProperty(key, value) {
|
|
70
|
-
this.userProperties[key] = value;
|
|
71
|
-
}
|
|
72
|
-
setUserProperties(properties) {
|
|
73
|
-
Object.assign(this.userProperties, properties);
|
|
74
|
-
}
|
|
75
|
-
setEnvironment(environmentId) {
|
|
76
|
-
this.environmentId = environmentId;
|
|
77
|
-
}
|
|
78
|
-
reset() {
|
|
79
|
-
this.userId = undefined;
|
|
80
|
-
this.userProperties = {};
|
|
81
|
-
}
|
|
82
|
-
// ─── Flush ────────────────────────────────────────────────────────────────
|
|
83
|
-
async flush() {
|
|
84
|
-
if (this.queue.length === 0)
|
|
85
|
-
return;
|
|
86
|
-
const batch = [...this.queue];
|
|
87
|
-
this.queue = [];
|
|
88
|
-
try {
|
|
89
|
-
const response = await fetch(`${this.config.baseUrl}/v1/analytics/events`, {
|
|
90
|
-
method: 'POST',
|
|
91
|
-
headers: {
|
|
92
|
-
'Content-Type': 'application/json',
|
|
93
|
-
'x-api-key': this.config.publicKey,
|
|
94
|
-
},
|
|
95
|
-
body: JSON.stringify({ events: batch }),
|
|
96
|
-
});
|
|
97
|
-
if (!response.ok) {
|
|
98
|
-
// Re-queue on failure
|
|
99
|
-
this.queue.unshift(...batch.slice(0, MAX_BATCH_SIZE - this.queue.length));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
catch {
|
|
103
|
-
// Re-queue on network error
|
|
104
|
-
this.queue.unshift(...batch.slice(0, MAX_BATCH_SIZE - this.queue.length));
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
async dispose() {
|
|
108
|
-
if (this.flushTimer)
|
|
109
|
-
clearInterval(this.flushTimer);
|
|
110
|
-
this.track('session_end');
|
|
111
|
-
await this.flush();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
exports.KoolbaseAnalytics = KoolbaseAnalytics;
|
package/dist/apple-auth.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* KoolbaseAppleAuth — Sign in with Apple for React Native
|
|
3
|
-
*
|
|
4
|
-
* Requires @invertase/react-native-apple-authentication
|
|
5
|
-
* Install: npm install @invertase/react-native-apple-authentication
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* ```typescript
|
|
9
|
-
* import { KoolbaseAppleAuth } from 'koolbase-react-native';
|
|
10
|
-
* const session = await KoolbaseAppleAuth.signIn();
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export declare class KoolbaseAppleAuth {
|
|
14
|
-
static signIn(getAppleCredential: () => Promise<{
|
|
15
|
-
identityToken: string | null;
|
|
16
|
-
email: string | null;
|
|
17
|
-
fullName?: {
|
|
18
|
-
givenName?: string | null;
|
|
19
|
-
familyName?: string | null;
|
|
20
|
-
} | null;
|
|
21
|
-
}>): Promise<Record<string, unknown> | null>;
|
|
22
|
-
}
|
package/dist/apple-auth.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.KoolbaseAppleAuth = void 0;
|
|
37
|
-
/**
|
|
38
|
-
* KoolbaseAppleAuth — Sign in with Apple for React Native
|
|
39
|
-
*
|
|
40
|
-
* Requires @invertase/react-native-apple-authentication
|
|
41
|
-
* Install: npm install @invertase/react-native-apple-authentication
|
|
42
|
-
*
|
|
43
|
-
* Usage:
|
|
44
|
-
* ```typescript
|
|
45
|
-
* import { KoolbaseAppleAuth } from 'koolbase-react-native';
|
|
46
|
-
* const session = await KoolbaseAppleAuth.signIn();
|
|
47
|
-
* ```
|
|
48
|
-
*/
|
|
49
|
-
class KoolbaseAppleAuth {
|
|
50
|
-
static async signIn(getAppleCredential) {
|
|
51
|
-
try {
|
|
52
|
-
const { Koolbase } = await Promise.resolve().then(() => __importStar(require('./index')));
|
|
53
|
-
const credential = await getAppleCredential();
|
|
54
|
-
if (!credential.identityToken) {
|
|
55
|
-
console.warn('[KoolbaseAppleAuth] No identity token returned');
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
const name = [credential.fullName?.givenName, credential.fullName?.familyName]
|
|
59
|
-
.filter(Boolean)
|
|
60
|
-
.join(' ');
|
|
61
|
-
return await Koolbase.auth.oauthLogin({
|
|
62
|
-
provider: 'apple',
|
|
63
|
-
token: credential.identityToken,
|
|
64
|
-
email: credential.email ?? '',
|
|
65
|
-
name,
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
catch (error) {
|
|
69
|
-
console.error('[KoolbaseAppleAuth] Sign in failed:', error);
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.KoolbaseAppleAuth = KoolbaseAppleAuth;
|
package/dist/auth-errors.d.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Base error type for all Koolbase auth errors. Catchable via
|
|
3
|
-
* `instanceof KoolbaseAuthError` to handle any auth-related failure
|
|
4
|
-
* generically; subclasses let you handle specific cases.
|
|
5
|
-
*/
|
|
6
|
-
export declare class KoolbaseAuthError extends Error {
|
|
7
|
-
code?: string;
|
|
8
|
-
constructor(message: string, code?: string);
|
|
9
|
-
}
|
|
10
|
-
export declare class InvalidCredentialsError extends KoolbaseAuthError {
|
|
11
|
-
constructor();
|
|
12
|
-
}
|
|
13
|
-
export declare class EmailAlreadyInUseError extends KoolbaseAuthError {
|
|
14
|
-
constructor();
|
|
15
|
-
}
|
|
16
|
-
export declare class UserDisabledError extends KoolbaseAuthError {
|
|
17
|
-
constructor();
|
|
18
|
-
}
|
|
19
|
-
export declare class WeakPasswordError extends KoolbaseAuthError {
|
|
20
|
-
constructor();
|
|
21
|
-
}
|
|
22
|
-
export declare class SessionExpiredError extends KoolbaseAuthError {
|
|
23
|
-
constructor();
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Thrown when the access token references a session that has been revoked
|
|
27
|
-
* centrally — either by the user (sessions endpoint) or an administrator.
|
|
28
|
-
* Distinct from {@link SessionExpiredError} which indicates the access
|
|
29
|
-
* token TTL elapsed without a successful refresh.
|
|
30
|
-
*
|
|
31
|
-
* Forward-compatible: matches multiple server message patterns so it stays
|
|
32
|
-
* accurate as the server's revocation signaling evolves.
|
|
33
|
-
*/
|
|
34
|
-
export declare class TokenRevokedError extends KoolbaseAuthError {
|
|
35
|
-
constructor();
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Thrown when the account is temporarily locked due to too many failed
|
|
39
|
-
* login attempts. The server uses progressive 5/10/20-attempt lockouts;
|
|
40
|
-
* if an unlock email was issued (level 2+), the user can clear the lock
|
|
41
|
-
* by passing that token to {@link KoolbaseAuth.unlock}.
|
|
42
|
-
*
|
|
43
|
-
* [lockedUntil] is currently null — the server returns a generic 429 but
|
|
44
|
-
* does not yet include the unlock timestamp in the response body. Field
|
|
45
|
-
* is forward-compatible for when the server adds it.
|
|
46
|
-
*/
|
|
47
|
-
export declare class AccountLockedError extends KoolbaseAuthError {
|
|
48
|
-
lockedUntil?: Date;
|
|
49
|
-
constructor(lockedUntil?: Date);
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Thrown when the unlock token from a brute-force unlock email is
|
|
53
|
-
* invalid, expired, or already consumed. Unlock tokens are one-shot.
|
|
54
|
-
*/
|
|
55
|
-
export declare class UnlockTokenInvalidError extends KoolbaseAuthError {
|
|
56
|
-
constructor();
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Thrown when the server rate-limits a non-phone authentication endpoint
|
|
60
|
-
* (HTTP 429 without the "account temporarily locked" marker). Phone OTP
|
|
61
|
-
* endpoints throw {@link OtpRateLimitError} instead — they hit a
|
|
62
|
-
* separate server-side rate-limiter.
|
|
63
|
-
*/
|
|
64
|
-
export declare class RateLimitError extends KoolbaseAuthError {
|
|
65
|
-
constructor(message?: string);
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Generic network error. The SDK does NOT throw this directly — fetch
|
|
69
|
-
* failures (DNS, no connection, timeout) propagate as native TypeErrors.
|
|
70
|
-
* This class exists for consumer code that wants to construct or
|
|
71
|
-
* `instanceof`-check a typed network error from their own retry logic.
|
|
72
|
-
*/
|
|
73
|
-
export declare class NetworkError extends KoolbaseAuthError {
|
|
74
|
-
constructor();
|
|
75
|
-
}
|
|
76
|
-
export declare class InvalidPhoneNumberError extends KoolbaseAuthError {
|
|
77
|
-
constructor();
|
|
78
|
-
}
|
|
79
|
-
export declare class OtpExpiredError extends KoolbaseAuthError {
|
|
80
|
-
constructor();
|
|
81
|
-
}
|
|
82
|
-
export declare class OtpInvalidError extends KoolbaseAuthError {
|
|
83
|
-
constructor();
|
|
84
|
-
}
|
|
85
|
-
export declare class OtpMaxAttemptsError extends KoolbaseAuthError {
|
|
86
|
-
constructor();
|
|
87
|
-
}
|
|
88
|
-
export declare class OtpRateLimitError extends KoolbaseAuthError {
|
|
89
|
-
constructor();
|
|
90
|
-
}
|
|
91
|
-
export declare class PhoneAlreadyLinkedError extends KoolbaseAuthError {
|
|
92
|
-
constructor();
|
|
93
|
-
}
|
|
94
|
-
export declare class SmsConfigMissingError extends KoolbaseAuthError {
|
|
95
|
-
constructor();
|
|
96
|
-
}
|
|
97
|
-
export declare class AppleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
98
|
-
constructor();
|
|
99
|
-
}
|
|
100
|
-
export declare class InvalidAppleTokenError extends KoolbaseAuthError {
|
|
101
|
-
constructor();
|
|
102
|
-
}
|
|
103
|
-
export declare class AppleEmailRequiredError extends KoolbaseAuthError {
|
|
104
|
-
constructor();
|
|
105
|
-
}
|
|
106
|
-
export declare class OAuthEmailConflictError extends KoolbaseAuthError {
|
|
107
|
-
constructor();
|
|
108
|
-
}
|
|
109
|
-
export declare class GoogleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
110
|
-
constructor();
|
|
111
|
-
}
|
|
112
|
-
export declare class InvalidGoogleTokenError extends KoolbaseAuthError {
|
|
113
|
-
constructor();
|
|
114
|
-
}
|
|
115
|
-
export declare class GoogleEmailRequiredError extends KoolbaseAuthError {
|
|
116
|
-
constructor();
|
|
117
|
-
}
|
package/dist/auth-errors.js
DELETED
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GoogleEmailRequiredError = exports.InvalidGoogleTokenError = exports.GoogleSignInNotConfiguredError = exports.OAuthEmailConflictError = exports.AppleEmailRequiredError = exports.InvalidAppleTokenError = exports.AppleSignInNotConfiguredError = exports.SmsConfigMissingError = exports.PhoneAlreadyLinkedError = exports.OtpRateLimitError = exports.OtpMaxAttemptsError = exports.OtpInvalidError = exports.OtpExpiredError = exports.InvalidPhoneNumberError = exports.NetworkError = exports.RateLimitError = exports.UnlockTokenInvalidError = exports.AccountLockedError = exports.TokenRevokedError = exports.SessionExpiredError = exports.WeakPasswordError = exports.UserDisabledError = exports.EmailAlreadyInUseError = exports.InvalidCredentialsError = exports.KoolbaseAuthError = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Base error type for all Koolbase auth errors. Catchable via
|
|
6
|
-
* `instanceof KoolbaseAuthError` to handle any auth-related failure
|
|
7
|
-
* generically; subclasses let you handle specific cases.
|
|
8
|
-
*/
|
|
9
|
-
class KoolbaseAuthError extends Error {
|
|
10
|
-
constructor(message, code) {
|
|
11
|
-
super(message);
|
|
12
|
-
this.code = code;
|
|
13
|
-
this.name = 'KoolbaseAuthError';
|
|
14
|
-
Object.setPrototypeOf(this, KoolbaseAuthError.prototype);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
exports.KoolbaseAuthError = KoolbaseAuthError;
|
|
18
|
-
// ─── Credentials / Registration ────────────────────────────────────────────
|
|
19
|
-
class InvalidCredentialsError extends KoolbaseAuthError {
|
|
20
|
-
constructor() {
|
|
21
|
-
super('Invalid email or password', 'invalid_credentials');
|
|
22
|
-
this.name = 'InvalidCredentialsError';
|
|
23
|
-
Object.setPrototypeOf(this, InvalidCredentialsError.prototype);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.InvalidCredentialsError = InvalidCredentialsError;
|
|
27
|
-
class EmailAlreadyInUseError extends KoolbaseAuthError {
|
|
28
|
-
constructor() {
|
|
29
|
-
super('Email is already in use', 'email_taken');
|
|
30
|
-
this.name = 'EmailAlreadyInUseError';
|
|
31
|
-
Object.setPrototypeOf(this, EmailAlreadyInUseError.prototype);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
exports.EmailAlreadyInUseError = EmailAlreadyInUseError;
|
|
35
|
-
class UserDisabledError extends KoolbaseAuthError {
|
|
36
|
-
constructor() {
|
|
37
|
-
super('This account has been disabled', 'user_disabled');
|
|
38
|
-
this.name = 'UserDisabledError';
|
|
39
|
-
Object.setPrototypeOf(this, UserDisabledError.prototype);
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
exports.UserDisabledError = UserDisabledError;
|
|
43
|
-
class WeakPasswordError extends KoolbaseAuthError {
|
|
44
|
-
constructor() {
|
|
45
|
-
super('Password must be at least 8 characters', 'weak_password');
|
|
46
|
-
this.name = 'WeakPasswordError';
|
|
47
|
-
Object.setPrototypeOf(this, WeakPasswordError.prototype);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.WeakPasswordError = WeakPasswordError;
|
|
51
|
-
// ─── Session lifecycle ─────────────────────────────────────────────────────
|
|
52
|
-
class SessionExpiredError extends KoolbaseAuthError {
|
|
53
|
-
constructor() {
|
|
54
|
-
super('Session expired, please log in again', 'session_expired');
|
|
55
|
-
this.name = 'SessionExpiredError';
|
|
56
|
-
Object.setPrototypeOf(this, SessionExpiredError.prototype);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
exports.SessionExpiredError = SessionExpiredError;
|
|
60
|
-
/**
|
|
61
|
-
* Thrown when the access token references a session that has been revoked
|
|
62
|
-
* centrally — either by the user (sessions endpoint) or an administrator.
|
|
63
|
-
* Distinct from {@link SessionExpiredError} which indicates the access
|
|
64
|
-
* token TTL elapsed without a successful refresh.
|
|
65
|
-
*
|
|
66
|
-
* Forward-compatible: matches multiple server message patterns so it stays
|
|
67
|
-
* accurate as the server's revocation signaling evolves.
|
|
68
|
-
*/
|
|
69
|
-
class TokenRevokedError extends KoolbaseAuthError {
|
|
70
|
-
constructor() {
|
|
71
|
-
super('Session has been revoked, please log in again', 'token_revoked');
|
|
72
|
-
this.name = 'TokenRevokedError';
|
|
73
|
-
Object.setPrototypeOf(this, TokenRevokedError.prototype);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.TokenRevokedError = TokenRevokedError;
|
|
77
|
-
// ─── Brute-force protection ────────────────────────────────────────────────
|
|
78
|
-
/**
|
|
79
|
-
* Thrown when the account is temporarily locked due to too many failed
|
|
80
|
-
* login attempts. The server uses progressive 5/10/20-attempt lockouts;
|
|
81
|
-
* if an unlock email was issued (level 2+), the user can clear the lock
|
|
82
|
-
* by passing that token to {@link KoolbaseAuth.unlock}.
|
|
83
|
-
*
|
|
84
|
-
* [lockedUntil] is currently null — the server returns a generic 429 but
|
|
85
|
-
* does not yet include the unlock timestamp in the response body. Field
|
|
86
|
-
* is forward-compatible for when the server adds it.
|
|
87
|
-
*/
|
|
88
|
-
class AccountLockedError extends KoolbaseAuthError {
|
|
89
|
-
constructor(lockedUntil) {
|
|
90
|
-
super('Account temporarily locked due to too many failed attempts', 'account_locked');
|
|
91
|
-
this.lockedUntil = lockedUntil;
|
|
92
|
-
this.name = 'AccountLockedError';
|
|
93
|
-
Object.setPrototypeOf(this, AccountLockedError.prototype);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
exports.AccountLockedError = AccountLockedError;
|
|
97
|
-
/**
|
|
98
|
-
* Thrown when the unlock token from a brute-force unlock email is
|
|
99
|
-
* invalid, expired, or already consumed. Unlock tokens are one-shot.
|
|
100
|
-
*/
|
|
101
|
-
class UnlockTokenInvalidError extends KoolbaseAuthError {
|
|
102
|
-
constructor() {
|
|
103
|
-
super('Unlock link is invalid or has expired', 'unlock_token_invalid');
|
|
104
|
-
this.name = 'UnlockTokenInvalidError';
|
|
105
|
-
Object.setPrototypeOf(this, UnlockTokenInvalidError.prototype);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
exports.UnlockTokenInvalidError = UnlockTokenInvalidError;
|
|
109
|
-
/**
|
|
110
|
-
* Thrown when the server rate-limits a non-phone authentication endpoint
|
|
111
|
-
* (HTTP 429 without the "account temporarily locked" marker). Phone OTP
|
|
112
|
-
* endpoints throw {@link OtpRateLimitError} instead — they hit a
|
|
113
|
-
* separate server-side rate-limiter.
|
|
114
|
-
*/
|
|
115
|
-
class RateLimitError extends KoolbaseAuthError {
|
|
116
|
-
constructor(message) {
|
|
117
|
-
super(message ?? 'Too many requests, please wait before trying again', 'rate_limit');
|
|
118
|
-
this.name = 'RateLimitError';
|
|
119
|
-
Object.setPrototypeOf(this, RateLimitError.prototype);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
exports.RateLimitError = RateLimitError;
|
|
123
|
-
// ─── Network ───────────────────────────────────────────────────────────────
|
|
124
|
-
/**
|
|
125
|
-
* Generic network error. The SDK does NOT throw this directly — fetch
|
|
126
|
-
* failures (DNS, no connection, timeout) propagate as native TypeErrors.
|
|
127
|
-
* This class exists for consumer code that wants to construct or
|
|
128
|
-
* `instanceof`-check a typed network error from their own retry logic.
|
|
129
|
-
*/
|
|
130
|
-
class NetworkError extends KoolbaseAuthError {
|
|
131
|
-
constructor() {
|
|
132
|
-
super('Network error, please check your connection', 'network_error');
|
|
133
|
-
this.name = 'NetworkError';
|
|
134
|
-
Object.setPrototypeOf(this, NetworkError.prototype);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
exports.NetworkError = NetworkError;
|
|
138
|
-
// ─── Phone OTP (unchanged from earlier releases) ───────────────────────────
|
|
139
|
-
class InvalidPhoneNumberError extends KoolbaseAuthError {
|
|
140
|
-
constructor() {
|
|
141
|
-
super('Phone number must be in E.164 format (e.g. +233XXXXXXXXX)', 'invalid_phone');
|
|
142
|
-
this.name = 'InvalidPhoneNumberError';
|
|
143
|
-
Object.setPrototypeOf(this, InvalidPhoneNumberError.prototype);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
exports.InvalidPhoneNumberError = InvalidPhoneNumberError;
|
|
147
|
-
class OtpExpiredError extends KoolbaseAuthError {
|
|
148
|
-
constructor() {
|
|
149
|
-
super('OTP has expired, please request a new code', 'otp_expired');
|
|
150
|
-
this.name = 'OtpExpiredError';
|
|
151
|
-
Object.setPrototypeOf(this, OtpExpiredError.prototype);
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
exports.OtpExpiredError = OtpExpiredError;
|
|
155
|
-
class OtpInvalidError extends KoolbaseAuthError {
|
|
156
|
-
constructor() {
|
|
157
|
-
super('Invalid OTP code', 'otp_invalid');
|
|
158
|
-
this.name = 'OtpInvalidError';
|
|
159
|
-
Object.setPrototypeOf(this, OtpInvalidError.prototype);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
exports.OtpInvalidError = OtpInvalidError;
|
|
163
|
-
class OtpMaxAttemptsError extends KoolbaseAuthError {
|
|
164
|
-
constructor() {
|
|
165
|
-
super('Too many incorrect attempts, please request a new code', 'otp_max_attempts');
|
|
166
|
-
this.name = 'OtpMaxAttemptsError';
|
|
167
|
-
Object.setPrototypeOf(this, OtpMaxAttemptsError.prototype);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
exports.OtpMaxAttemptsError = OtpMaxAttemptsError;
|
|
171
|
-
class OtpRateLimitError extends KoolbaseAuthError {
|
|
172
|
-
constructor() {
|
|
173
|
-
super('Too many OTP requests, please wait before trying again', 'otp_rate_limit');
|
|
174
|
-
this.name = 'OtpRateLimitError';
|
|
175
|
-
Object.setPrototypeOf(this, OtpRateLimitError.prototype);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
exports.OtpRateLimitError = OtpRateLimitError;
|
|
179
|
-
class PhoneAlreadyLinkedError extends KoolbaseAuthError {
|
|
180
|
-
constructor() {
|
|
181
|
-
super('Phone number is already associated with another account', 'phone_taken');
|
|
182
|
-
this.name = 'PhoneAlreadyLinkedError';
|
|
183
|
-
Object.setPrototypeOf(this, PhoneAlreadyLinkedError.prototype);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
exports.PhoneAlreadyLinkedError = PhoneAlreadyLinkedError;
|
|
187
|
-
class SmsConfigMissingError extends KoolbaseAuthError {
|
|
188
|
-
constructor() {
|
|
189
|
-
super('SMS provider not configured for this project', 'sms_config_missing');
|
|
190
|
-
this.name = 'SmsConfigMissingError';
|
|
191
|
-
Object.setPrototypeOf(this, SmsConfigMissingError.prototype);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
exports.SmsConfigMissingError = SmsConfigMissingError;
|
|
195
|
-
class AppleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
196
|
-
constructor() {
|
|
197
|
-
super('Apple Sign-In is not configured for this environment', 'apple_not_configured');
|
|
198
|
-
this.name = 'AppleSignInNotConfiguredError';
|
|
199
|
-
Object.setPrototypeOf(this, AppleSignInNotConfiguredError.prototype);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.AppleSignInNotConfiguredError = AppleSignInNotConfiguredError;
|
|
203
|
-
class InvalidAppleTokenError extends KoolbaseAuthError {
|
|
204
|
-
constructor() {
|
|
205
|
-
super('Invalid Apple identity token', 'invalid_apple_token');
|
|
206
|
-
this.name = 'InvalidAppleTokenError';
|
|
207
|
-
Object.setPrototypeOf(this, InvalidAppleTokenError.prototype);
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
exports.InvalidAppleTokenError = InvalidAppleTokenError;
|
|
211
|
-
class AppleEmailRequiredError extends KoolbaseAuthError {
|
|
212
|
-
constructor() {
|
|
213
|
-
super('Apple did not return email for this sign-in. Revoke this app in iOS Settings → Apple ID and retry.', 'apple_email_required');
|
|
214
|
-
this.name = 'AppleEmailRequiredError';
|
|
215
|
-
Object.setPrototypeOf(this, AppleEmailRequiredError.prototype);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
exports.AppleEmailRequiredError = AppleEmailRequiredError;
|
|
219
|
-
class OAuthEmailConflictError extends KoolbaseAuthError {
|
|
220
|
-
constructor() {
|
|
221
|
-
super('Email is already in use by another account. Sign in with your existing method and link Apple from settings.', 'oauth_email_conflict');
|
|
222
|
-
this.name = 'OAuthEmailConflictError';
|
|
223
|
-
Object.setPrototypeOf(this, OAuthEmailConflictError.prototype);
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
exports.OAuthEmailConflictError = OAuthEmailConflictError;
|
|
227
|
-
class GoogleSignInNotConfiguredError extends KoolbaseAuthError {
|
|
228
|
-
constructor() {
|
|
229
|
-
super('Google Sign-In is not configured for this environment', 'google_not_configured');
|
|
230
|
-
this.name = 'GoogleSignInNotConfiguredError';
|
|
231
|
-
Object.setPrototypeOf(this, GoogleSignInNotConfiguredError.prototype);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
exports.GoogleSignInNotConfiguredError = GoogleSignInNotConfiguredError;
|
|
235
|
-
class InvalidGoogleTokenError extends KoolbaseAuthError {
|
|
236
|
-
constructor() {
|
|
237
|
-
super('Invalid Google identity token', 'invalid_google_token');
|
|
238
|
-
this.name = 'InvalidGoogleTokenError';
|
|
239
|
-
Object.setPrototypeOf(this, InvalidGoogleTokenError.prototype);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
exports.InvalidGoogleTokenError = InvalidGoogleTokenError;
|
|
243
|
-
class GoogleEmailRequiredError extends KoolbaseAuthError {
|
|
244
|
-
constructor() {
|
|
245
|
-
super('Google did not return email for this sign-in. Ensure the email scope is requested in the native flow.', 'google_email_required');
|
|
246
|
-
this.name = 'GoogleEmailRequiredError';
|
|
247
|
-
Object.setPrototypeOf(this, GoogleEmailRequiredError.prototype);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
exports.GoogleEmailRequiredError = GoogleEmailRequiredError;
|