@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/device-metadata.js
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DeviceMetadata = exports.koolbaseSdkVersion = void 0;
|
|
4
|
-
const react_native_1 = require("react-native");
|
|
5
|
-
const auth_storage_1 = require("./auth-storage");
|
|
6
|
-
/**
|
|
7
|
-
* Koolbase React Native SDK version. Sent in the `x-koolbase-sdk-version`
|
|
8
|
-
* header on every authenticated request so the server can route
|
|
9
|
-
* version-conditional logic (deprecation warnings, schema migrations,
|
|
10
|
-
* feature flags). Must match the `version` field in package.json.
|
|
11
|
-
*/
|
|
12
|
-
exports.koolbaseSdkVersion = '1.11.0';
|
|
13
|
-
/**
|
|
14
|
-
* Generate a UUIDv4-shaped string for use as a stable per-install
|
|
15
|
-
* device label. Not cryptographically secure — this is a label, not a
|
|
16
|
-
* security primitive. Avoids pulling in a crypto-grade UUID dependency.
|
|
17
|
-
*/
|
|
18
|
-
function generateDeviceLabel() {
|
|
19
|
-
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
|
20
|
-
const r = (Math.random() * 16) | 0;
|
|
21
|
-
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
22
|
-
return v.toString(16);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Builds device-identifying headers attached to every Koolbase auth
|
|
27
|
-
* request. Mirrors the Flutter SDK's `DeviceMetadata` for parity. Apps
|
|
28
|
-
* with privacy concerns can swap in a custom storage adapter to avoid
|
|
29
|
-
* persisting the device label.
|
|
30
|
-
*
|
|
31
|
-
* Headers emitted:
|
|
32
|
-
* - User-Agent: koolbase-react-native/<sdk> (<platform> <version>)
|
|
33
|
-
* - x-koolbase-sdk: react-native
|
|
34
|
-
* - x-koolbase-sdk-version: <koolbaseSdkVersion>
|
|
35
|
-
* - x-koolbase-platform: ios | android | web | etc.
|
|
36
|
-
* - x-koolbase-platform-version: numeric SDK level or OS version string
|
|
37
|
-
* - x-koolbase-app-version: from KoolbaseConfig.appVersion or 'unknown'
|
|
38
|
-
* - x-koolbase-device-label: persistent UUID per install
|
|
39
|
-
*/
|
|
40
|
-
class DeviceMetadata {
|
|
41
|
-
constructor(appVersion) {
|
|
42
|
-
this.cached = null;
|
|
43
|
-
this.ephemeralLabel = null;
|
|
44
|
-
this.appVersion = appVersion ?? 'unknown';
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Build (or return cached) device headers. The first call may perform
|
|
48
|
-
* an async keychain read to look up the persisted device label;
|
|
49
|
-
* subsequent calls return the in-memory cache synchronously via the
|
|
50
|
-
* returned Promise.
|
|
51
|
-
*/
|
|
52
|
-
async build() {
|
|
53
|
-
if (this.cached)
|
|
54
|
-
return this.cached;
|
|
55
|
-
const platform = String(react_native_1.Platform.OS);
|
|
56
|
-
const platformVersion = String(react_native_1.Platform.Version);
|
|
57
|
-
const deviceLabel = await this.getOrCreateDeviceLabel();
|
|
58
|
-
const userAgent = `koolbase-react-native/${exports.koolbaseSdkVersion} (${platform} ${platformVersion})`;
|
|
59
|
-
this.cached = {
|
|
60
|
-
'User-Agent': userAgent,
|
|
61
|
-
'x-koolbase-sdk': 'react-native',
|
|
62
|
-
'x-koolbase-sdk-version': exports.koolbaseSdkVersion,
|
|
63
|
-
'x-koolbase-platform': platform,
|
|
64
|
-
'x-koolbase-platform-version': platformVersion,
|
|
65
|
-
'x-koolbase-app-version': this.appVersion,
|
|
66
|
-
'x-koolbase-device-label': deviceLabel,
|
|
67
|
-
};
|
|
68
|
-
return this.cached;
|
|
69
|
-
}
|
|
70
|
-
async getOrCreateDeviceLabel() {
|
|
71
|
-
// No keychain available → ephemeral per-session label.
|
|
72
|
-
// (Better than no label — still useful for in-session debugging.)
|
|
73
|
-
if (!(0, auth_storage_1.isKeychainAvailable)()) {
|
|
74
|
-
if (!this.ephemeralLabel) {
|
|
75
|
-
this.ephemeralLabel = generateDeviceLabel();
|
|
76
|
-
}
|
|
77
|
-
return this.ephemeralLabel;
|
|
78
|
-
}
|
|
79
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
80
|
-
const Keychain = require('react-native-keychain');
|
|
81
|
-
const service = 'koolbase_device_label_v1';
|
|
82
|
-
try {
|
|
83
|
-
const existing = await Keychain.getGenericPassword({ service });
|
|
84
|
-
if (existing && existing.password) {
|
|
85
|
-
return existing.password;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
// fall through to create
|
|
90
|
-
}
|
|
91
|
-
const newLabel = generateDeviceLabel();
|
|
92
|
-
try {
|
|
93
|
-
await Keychain.setGenericPassword('device', newLabel, { service });
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
// Persistence failed — return the generated label anyway, but
|
|
97
|
-
// don't cache it as ephemeral since future requests may persist.
|
|
98
|
-
}
|
|
99
|
-
return newLabel;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
exports.DeviceMetadata = DeviceMetadata;
|
package/dist/flags.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { KoolbaseConfig, VersionCheckResult } from './types';
|
|
2
|
-
export declare class KoolbaseFlags {
|
|
3
|
-
private config;
|
|
4
|
-
private payload;
|
|
5
|
-
private deviceId;
|
|
6
|
-
constructor(config: KoolbaseConfig, deviceId: string);
|
|
7
|
-
fetch(appVersion: string, platform: string): Promise<void>;
|
|
8
|
-
isEnabled(key: string): boolean;
|
|
9
|
-
getString(key: string, fallback?: string): string;
|
|
10
|
-
getNumber(key: string, fallback?: number): number;
|
|
11
|
-
getBool(key: string, fallback?: boolean): boolean;
|
|
12
|
-
checkVersion(currentVersion: string): VersionCheckResult;
|
|
13
|
-
private parseVersion;
|
|
14
|
-
private stableHash;
|
|
15
|
-
}
|
package/dist/flags.js
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseFlags = void 0;
|
|
4
|
-
class KoolbaseFlags {
|
|
5
|
-
constructor(config, deviceId) {
|
|
6
|
-
this.payload = null;
|
|
7
|
-
this.config = config;
|
|
8
|
-
this.deviceId = deviceId;
|
|
9
|
-
}
|
|
10
|
-
async fetch(appVersion, platform) {
|
|
11
|
-
try {
|
|
12
|
-
const res = await fetch(`${this.config.baseUrl}/v1/bootstrap?public_key=${this.config.publicKey}&device_id=${this.deviceId}&app_version=${appVersion}&platform=${platform}`);
|
|
13
|
-
if (res.ok) {
|
|
14
|
-
this.payload = await res.json();
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
catch (_) { }
|
|
18
|
-
}
|
|
19
|
-
isEnabled(key) {
|
|
20
|
-
const flag = this.payload?.flags[key];
|
|
21
|
-
if (!flag || !flag.enabled || flag.kill_switch)
|
|
22
|
-
return false;
|
|
23
|
-
const bucket = this.stableHash(`${this.deviceId}:${key}`) % 100;
|
|
24
|
-
return bucket < flag.rollout_percentage;
|
|
25
|
-
}
|
|
26
|
-
getString(key, fallback = '') {
|
|
27
|
-
const val = this.payload?.config[key];
|
|
28
|
-
return val !== undefined ? String(val) : fallback;
|
|
29
|
-
}
|
|
30
|
-
getNumber(key, fallback = 0) {
|
|
31
|
-
const val = this.payload?.config[key];
|
|
32
|
-
return typeof val === 'number' ? val : Number(val) || fallback;
|
|
33
|
-
}
|
|
34
|
-
getBool(key, fallback = false) {
|
|
35
|
-
const val = this.payload?.config[key];
|
|
36
|
-
if (typeof val === 'boolean')
|
|
37
|
-
return val;
|
|
38
|
-
return val === 'true' ? true : fallback;
|
|
39
|
-
}
|
|
40
|
-
checkVersion(currentVersion) {
|
|
41
|
-
const policy = this.payload?.version;
|
|
42
|
-
if (!policy?.min_version) {
|
|
43
|
-
return { status: 'up_to_date', message: '', latestVersion: '' };
|
|
44
|
-
}
|
|
45
|
-
const current = this.parseVersion(currentVersion);
|
|
46
|
-
const min = this.parseVersion(policy.min_version);
|
|
47
|
-
const latest = this.parseVersion(policy.latest_version);
|
|
48
|
-
if (current < min) {
|
|
49
|
-
return {
|
|
50
|
-
status: 'force_update',
|
|
51
|
-
message: policy.update_message,
|
|
52
|
-
latestVersion: policy.latest_version,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if (policy.latest_version && current < latest) {
|
|
56
|
-
return {
|
|
57
|
-
status: policy.force_update ? 'force_update' : 'soft_update',
|
|
58
|
-
message: policy.update_message,
|
|
59
|
-
latestVersion: policy.latest_version,
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
return { status: 'up_to_date', message: '', latestVersion: policy.latest_version };
|
|
63
|
-
}
|
|
64
|
-
parseVersion(v) {
|
|
65
|
-
const parts = v.split('.').map(Number);
|
|
66
|
-
return (parts[0] ?? 0) * 10000 + (parts[1] ?? 0) * 100 + (parts[2] ?? 0);
|
|
67
|
-
}
|
|
68
|
-
stableHash(s) {
|
|
69
|
-
let hash = 0;
|
|
70
|
-
for (let i = 0; i < s.length; i++) {
|
|
71
|
-
hash = (Math.imul(31, hash) + s.charCodeAt(i)) | 0;
|
|
72
|
-
}
|
|
73
|
-
return Math.abs(hash);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
exports.KoolbaseFlags = KoolbaseFlags;
|
package/dist/functions.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { KoolbaseConfig, FunctionInvokeResult, DeployOptions, DeployResult } from './types';
|
|
2
|
-
export declare class KoolbaseFunctions {
|
|
3
|
-
private config;
|
|
4
|
-
private getUserAccessToken?;
|
|
5
|
-
constructor(config: KoolbaseConfig, getUserAccessToken?: () => Promise<string | null>);
|
|
6
|
-
deploy(options: DeployOptions): Promise<DeployResult>;
|
|
7
|
-
invoke(name: string, body?: Record<string, unknown>): Promise<FunctionInvokeResult>;
|
|
8
|
-
}
|
package/dist/functions.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.KoolbaseFunctions = void 0;
|
|
4
|
-
const types_1 = require("./types");
|
|
5
|
-
class KoolbaseFunctions {
|
|
6
|
-
constructor(config, getUserAccessToken) {
|
|
7
|
-
this.config = config;
|
|
8
|
-
this.getUserAccessToken = getUserAccessToken;
|
|
9
|
-
}
|
|
10
|
-
// ─── Deploy ────────────────────────────────────────────────────────────────
|
|
11
|
-
async deploy(options) {
|
|
12
|
-
const runtime = options.runtime ?? types_1.FunctionRuntime.Deno;
|
|
13
|
-
const res = await fetch(`${this.config.baseUrl}/v1/sdk/functions/deploy`, {
|
|
14
|
-
method: 'POST',
|
|
15
|
-
headers: {
|
|
16
|
-
'Content-Type': 'application/json',
|
|
17
|
-
'x-api-key': this.config.publicKey,
|
|
18
|
-
},
|
|
19
|
-
body: JSON.stringify({
|
|
20
|
-
name: options.name,
|
|
21
|
-
code: options.code,
|
|
22
|
-
runtime,
|
|
23
|
-
timeout_ms: options.timeoutMs ?? 10000,
|
|
24
|
-
}),
|
|
25
|
-
});
|
|
26
|
-
const data = await res.json().catch(() => null);
|
|
27
|
-
if (!res.ok) {
|
|
28
|
-
throw new Error(data?.error ??
|
|
29
|
-
'Function deploy failed');
|
|
30
|
-
}
|
|
31
|
-
const d = data;
|
|
32
|
-
return {
|
|
33
|
-
id: d.id,
|
|
34
|
-
name: d.name,
|
|
35
|
-
runtime: d.runtime,
|
|
36
|
-
version: d.version,
|
|
37
|
-
isActive: d.is_active,
|
|
38
|
-
timeoutMs: d.timeout_ms,
|
|
39
|
-
lastDeployedAt: d.last_deployed_at,
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
// ─── Invoke ────────────────────────────────────────────────────────────────
|
|
43
|
-
async invoke(name, body) {
|
|
44
|
-
const headers = {
|
|
45
|
-
'Content-Type': 'application/json',
|
|
46
|
-
'x-api-key': this.config.publicKey,
|
|
47
|
-
};
|
|
48
|
-
const userToken = await this.getUserAccessToken?.();
|
|
49
|
-
if (userToken) {
|
|
50
|
-
headers['Authorization'] = `Bearer ${userToken}`;
|
|
51
|
-
}
|
|
52
|
-
const res = await fetch(`${this.config.baseUrl}/v1/sdk/functions/${name}`, {
|
|
53
|
-
method: 'POST',
|
|
54
|
-
headers,
|
|
55
|
-
body: JSON.stringify({ body: body ?? {} }),
|
|
56
|
-
});
|
|
57
|
-
const data = await res.json().catch(() => null);
|
|
58
|
-
const success = res.status >= 200 && res.status < 300;
|
|
59
|
-
if (!success) {
|
|
60
|
-
throw new Error(data?.error ??
|
|
61
|
-
'Function invocation failed');
|
|
62
|
-
}
|
|
63
|
-
return {
|
|
64
|
-
statusCode: res.status,
|
|
65
|
-
data: data,
|
|
66
|
-
success,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.KoolbaseFunctions = KoolbaseFunctions;
|
package/dist/index.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { KoolbaseAuth } from './auth';
|
|
2
|
-
import { KoolbaseCodePush } from './code-push';
|
|
3
|
-
import { KoolbaseAnalytics } from './analytics';
|
|
4
|
-
import { KoolbaseMessaging } from './messaging';
|
|
5
|
-
export { KoolbaseMessaging } from './messaging';
|
|
6
|
-
export { KoolbaseAppleAuth } from './apple-auth';
|
|
7
|
-
export type { RegisterTokenOptions } from './messaging';
|
|
8
|
-
import { FlowResult } from './logic-engine';
|
|
9
|
-
export { KoolbaseAnalytics } from './analytics';
|
|
10
|
-
export type { FlowResult } from './logic-engine';
|
|
11
|
-
export { KoolbaseCodePush } from './code-push';
|
|
12
|
-
export type { BundleManifest, BundlePayload } from './code-push';
|
|
13
|
-
import { KoolbaseDatabase } from './database';
|
|
14
|
-
import { KoolbaseFlags } from './flags';
|
|
15
|
-
import { KoolbaseFunctions } from './functions';
|
|
16
|
-
import { KoolbaseRealtime } from './realtime';
|
|
17
|
-
import { KoolbaseStorage } from './storage';
|
|
18
|
-
import { KoolbaseConfig, VersionCheckResult } from './types';
|
|
19
|
-
export * from './types';
|
|
20
|
-
export * from './auth-errors';
|
|
21
|
-
export * from './database-errors';
|
|
22
|
-
export * from './storage-errors';
|
|
23
|
-
export { KoolbaseAuth, KoolbaseDatabase, KoolbaseFlags, KoolbaseFunctions, KoolbaseRealtime, KoolbaseStorage };
|
|
24
|
-
export declare const Koolbase: {
|
|
25
|
-
initialize(config: KoolbaseConfig): Promise<void>;
|
|
26
|
-
readonly auth: KoolbaseAuth;
|
|
27
|
-
readonly db: KoolbaseDatabase;
|
|
28
|
-
readonly storage: KoolbaseStorage;
|
|
29
|
-
readonly realtime: KoolbaseRealtime;
|
|
30
|
-
readonly functions: KoolbaseFunctions;
|
|
31
|
-
isEnabled(key: string): boolean;
|
|
32
|
-
configString(key: string, fallback?: string): string;
|
|
33
|
-
configNumber(key: string, fallback?: number): number;
|
|
34
|
-
configBool(key: string, fallback?: boolean): boolean;
|
|
35
|
-
readonly codePush: KoolbaseCodePush;
|
|
36
|
-
readonly analytics: KoolbaseAnalytics;
|
|
37
|
-
executeFlow(flowId: string, context?: Record<string, unknown>): FlowResult;
|
|
38
|
-
readonly messaging: KoolbaseMessaging;
|
|
39
|
-
checkVersion(currentVersion: string): VersionCheckResult;
|
|
40
|
-
};
|
|
41
|
-
export { koolbaseSdkVersion } from './device-metadata';
|
|
42
|
-
export { RestoreResult } from './types';
|
|
43
|
-
export type { AuthStateListener, FetchLike, KoolbaseAuthStorage } from './types';
|
|
44
|
-
export { SecureAuthStorage } from './auth-storage';
|
|
45
|
-
export { KoolbaseAuthError, InvalidCredentialsError, EmailAlreadyInUseError, UserDisabledError, WeakPasswordError, SessionExpiredError, TokenRevokedError, AccountLockedError, UnlockTokenInvalidError, RateLimitError, NetworkError, InvalidPhoneNumberError, OtpExpiredError, OtpInvalidError, OtpMaxAttemptsError, OtpRateLimitError, PhoneAlreadyLinkedError, SmsConfigMissingError, } from './auth-errors';
|
package/dist/index.js
DELETED
|
@@ -1,193 +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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
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 = exports.SecureAuthStorage = exports.RestoreResult = exports.koolbaseSdkVersion = exports.Koolbase = exports.KoolbaseStorage = exports.KoolbaseRealtime = exports.KoolbaseFunctions = exports.KoolbaseFlags = exports.KoolbaseDatabase = exports.KoolbaseAuth = exports.KoolbaseCodePush = exports.KoolbaseAnalytics = exports.KoolbaseAppleAuth = exports.KoolbaseMessaging = void 0;
|
|
18
|
-
const auth_1 = require("./auth");
|
|
19
|
-
Object.defineProperty(exports, "KoolbaseAuth", { enumerable: true, get: function () { return auth_1.KoolbaseAuth; } });
|
|
20
|
-
const code_push_1 = require("./code-push");
|
|
21
|
-
const analytics_1 = require("./analytics");
|
|
22
|
-
const messaging_1 = require("./messaging");
|
|
23
|
-
var messaging_2 = require("./messaging");
|
|
24
|
-
Object.defineProperty(exports, "KoolbaseMessaging", { enumerable: true, get: function () { return messaging_2.KoolbaseMessaging; } });
|
|
25
|
-
var apple_auth_1 = require("./apple-auth");
|
|
26
|
-
Object.defineProperty(exports, "KoolbaseAppleAuth", { enumerable: true, get: function () { return apple_auth_1.KoolbaseAppleAuth; } });
|
|
27
|
-
const logic_engine_1 = require("./logic-engine");
|
|
28
|
-
var analytics_2 = require("./analytics");
|
|
29
|
-
Object.defineProperty(exports, "KoolbaseAnalytics", { enumerable: true, get: function () { return analytics_2.KoolbaseAnalytics; } });
|
|
30
|
-
var code_push_2 = require("./code-push");
|
|
31
|
-
Object.defineProperty(exports, "KoolbaseCodePush", { enumerable: true, get: function () { return code_push_2.KoolbaseCodePush; } });
|
|
32
|
-
const database_1 = require("./database");
|
|
33
|
-
Object.defineProperty(exports, "KoolbaseDatabase", { enumerable: true, get: function () { return database_1.KoolbaseDatabase; } });
|
|
34
|
-
const flags_1 = require("./flags");
|
|
35
|
-
Object.defineProperty(exports, "KoolbaseFlags", { enumerable: true, get: function () { return flags_1.KoolbaseFlags; } });
|
|
36
|
-
const functions_1 = require("./functions");
|
|
37
|
-
Object.defineProperty(exports, "KoolbaseFunctions", { enumerable: true, get: function () { return functions_1.KoolbaseFunctions; } });
|
|
38
|
-
const realtime_1 = require("./realtime");
|
|
39
|
-
Object.defineProperty(exports, "KoolbaseRealtime", { enumerable: true, get: function () { return realtime_1.KoolbaseRealtime; } });
|
|
40
|
-
const storage_1 = require("./storage");
|
|
41
|
-
Object.defineProperty(exports, "KoolbaseStorage", { enumerable: true, get: function () { return storage_1.KoolbaseStorage; } });
|
|
42
|
-
const device_id_1 = require("./device-id");
|
|
43
|
-
__exportStar(require("./types"), exports);
|
|
44
|
-
__exportStar(require("./auth-errors"), exports);
|
|
45
|
-
__exportStar(require("./database-errors"), exports);
|
|
46
|
-
__exportStar(require("./storage-errors"), exports);
|
|
47
|
-
let _auth = null;
|
|
48
|
-
let _db = null;
|
|
49
|
-
let _storage = null;
|
|
50
|
-
let _realtime = null;
|
|
51
|
-
let _functions = null;
|
|
52
|
-
let _flags = null;
|
|
53
|
-
let _codePush = null;
|
|
54
|
-
let _analytics = null;
|
|
55
|
-
let _messaging = null;
|
|
56
|
-
const _logicEngine = new logic_engine_1.KoolbaseLogicEngine();
|
|
57
|
-
let _initialized = false;
|
|
58
|
-
function ensureInitialized() {
|
|
59
|
-
if (!_initialized) {
|
|
60
|
-
throw new Error('Koolbase not initialized. Call Koolbase.initialize() first.');
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
exports.Koolbase = {
|
|
64
|
-
async initialize(config) {
|
|
65
|
-
if (_initialized)
|
|
66
|
-
return;
|
|
67
|
-
_auth = new auth_1.KoolbaseAuth(config);
|
|
68
|
-
_db = new database_1.KoolbaseDatabase(config, () => _auth?.currentUser?.id ?? null, () => _auth?.validAccessToken() ?? Promise.resolve(null));
|
|
69
|
-
_storage = new storage_1.KoolbaseStorage(config, () => _auth?.validAccessToken() ?? Promise.resolve(null));
|
|
70
|
-
_realtime = new realtime_1.KoolbaseRealtime(config, () => _auth?.validAccessToken() ?? Promise.resolve(null));
|
|
71
|
-
_functions = new functions_1.KoolbaseFunctions(config, () => _auth?.validAccessToken() ?? Promise.resolve(null));
|
|
72
|
-
// One anonymous device id for the whole SDK — bucketing (flags), targeting
|
|
73
|
-
// (code push), and registration keying (messaging) must all agree on it.
|
|
74
|
-
const deviceId = await (0, device_id_1.getOrCreateDeviceId)();
|
|
75
|
-
_flags = new flags_1.KoolbaseFlags(config, deviceId);
|
|
76
|
-
_codePush = new code_push_1.KoolbaseCodePush(config, config.codePushChannel ?? 'stable');
|
|
77
|
-
// Initialize code push — loads cached bundle then checks in background
|
|
78
|
-
await _codePush.init({
|
|
79
|
-
appVersion: '1.0.0', // override with your app version
|
|
80
|
-
platform: 'react-native',
|
|
81
|
-
deviceId,
|
|
82
|
-
});
|
|
83
|
-
// Initialize analytics
|
|
84
|
-
if (config.analyticsEnabled !== false) {
|
|
85
|
-
_analytics = new analytics_1.KoolbaseAnalytics(config);
|
|
86
|
-
await _analytics.init(config.appVersion);
|
|
87
|
-
}
|
|
88
|
-
// Initialize messaging
|
|
89
|
-
if (config.messagingEnabled !== false) {
|
|
90
|
-
_messaging = new messaging_1.KoolbaseMessaging(config);
|
|
91
|
-
_messaging.setDeviceId(deviceId);
|
|
92
|
-
}
|
|
93
|
-
_initialized = true;
|
|
94
|
-
},
|
|
95
|
-
get auth() {
|
|
96
|
-
ensureInitialized();
|
|
97
|
-
return _auth;
|
|
98
|
-
},
|
|
99
|
-
get db() {
|
|
100
|
-
ensureInitialized();
|
|
101
|
-
return _db;
|
|
102
|
-
},
|
|
103
|
-
get storage() {
|
|
104
|
-
ensureInitialized();
|
|
105
|
-
return _storage;
|
|
106
|
-
},
|
|
107
|
-
get realtime() {
|
|
108
|
-
ensureInitialized();
|
|
109
|
-
return _realtime;
|
|
110
|
-
},
|
|
111
|
-
get functions() {
|
|
112
|
-
ensureInitialized();
|
|
113
|
-
return _functions;
|
|
114
|
-
},
|
|
115
|
-
isEnabled(key) {
|
|
116
|
-
ensureInitialized();
|
|
117
|
-
// Bundle flag wins over remote flag
|
|
118
|
-
const bundleFlag = _codePush?.getBundleFlag(key);
|
|
119
|
-
if (bundleFlag !== undefined)
|
|
120
|
-
return bundleFlag;
|
|
121
|
-
return _flags.isEnabled(key);
|
|
122
|
-
},
|
|
123
|
-
configString(key, fallback = '') {
|
|
124
|
-
ensureInitialized();
|
|
125
|
-
const bundleVal = _codePush?.getBundleConfig(key);
|
|
126
|
-
if (bundleVal !== undefined)
|
|
127
|
-
return String(bundleVal);
|
|
128
|
-
return _flags.getString(key, fallback);
|
|
129
|
-
},
|
|
130
|
-
configNumber(key, fallback = 0) {
|
|
131
|
-
ensureInitialized();
|
|
132
|
-
const bundleVal = _codePush?.getBundleConfig(key);
|
|
133
|
-
if (bundleVal !== undefined)
|
|
134
|
-
return typeof bundleVal === 'number' ? bundleVal : Number(bundleVal) || fallback;
|
|
135
|
-
return _flags.getNumber(key, fallback);
|
|
136
|
-
},
|
|
137
|
-
configBool(key, fallback = false) {
|
|
138
|
-
ensureInitialized();
|
|
139
|
-
const bundleVal = _codePush?.getBundleConfig(key);
|
|
140
|
-
if (bundleVal !== undefined)
|
|
141
|
-
return typeof bundleVal === 'boolean' ? bundleVal : bundleVal === 'true';
|
|
142
|
-
return _flags.getBool(key, fallback);
|
|
143
|
-
},
|
|
144
|
-
get codePush() {
|
|
145
|
-
ensureInitialized();
|
|
146
|
-
return _codePush;
|
|
147
|
-
},
|
|
148
|
-
get analytics() {
|
|
149
|
-
ensureInitialized();
|
|
150
|
-
return _analytics;
|
|
151
|
-
},
|
|
152
|
-
executeFlow(flowId, context) {
|
|
153
|
-
ensureInitialized();
|
|
154
|
-
const manifest = _codePush?.manifest;
|
|
155
|
-
if (!manifest)
|
|
156
|
-
return { hasEvent: false, args: {}, completed: true };
|
|
157
|
-
return _logicEngine.execute(flowId, manifest.payload.flows ?? {}, context ?? {}, manifest.payload.config ?? {}, manifest.payload.flags ?? {});
|
|
158
|
-
},
|
|
159
|
-
get messaging() {
|
|
160
|
-
ensureInitialized();
|
|
161
|
-
return _messaging;
|
|
162
|
-
},
|
|
163
|
-
checkVersion(currentVersion) {
|
|
164
|
-
ensureInitialized();
|
|
165
|
-
return _flags.checkVersion(currentVersion);
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
// v1.9.0 additions
|
|
169
|
-
var device_metadata_1 = require("./device-metadata");
|
|
170
|
-
Object.defineProperty(exports, "koolbaseSdkVersion", { enumerable: true, get: function () { return device_metadata_1.koolbaseSdkVersion; } });
|
|
171
|
-
var types_1 = require("./types");
|
|
172
|
-
Object.defineProperty(exports, "RestoreResult", { enumerable: true, get: function () { return types_1.RestoreResult; } });
|
|
173
|
-
var auth_storage_1 = require("./auth-storage");
|
|
174
|
-
Object.defineProperty(exports, "SecureAuthStorage", { enumerable: true, get: function () { return auth_storage_1.SecureAuthStorage; } });
|
|
175
|
-
var auth_errors_1 = require("./auth-errors");
|
|
176
|
-
Object.defineProperty(exports, "KoolbaseAuthError", { enumerable: true, get: function () { return auth_errors_1.KoolbaseAuthError; } });
|
|
177
|
-
Object.defineProperty(exports, "InvalidCredentialsError", { enumerable: true, get: function () { return auth_errors_1.InvalidCredentialsError; } });
|
|
178
|
-
Object.defineProperty(exports, "EmailAlreadyInUseError", { enumerable: true, get: function () { return auth_errors_1.EmailAlreadyInUseError; } });
|
|
179
|
-
Object.defineProperty(exports, "UserDisabledError", { enumerable: true, get: function () { return auth_errors_1.UserDisabledError; } });
|
|
180
|
-
Object.defineProperty(exports, "WeakPasswordError", { enumerable: true, get: function () { return auth_errors_1.WeakPasswordError; } });
|
|
181
|
-
Object.defineProperty(exports, "SessionExpiredError", { enumerable: true, get: function () { return auth_errors_1.SessionExpiredError; } });
|
|
182
|
-
Object.defineProperty(exports, "TokenRevokedError", { enumerable: true, get: function () { return auth_errors_1.TokenRevokedError; } });
|
|
183
|
-
Object.defineProperty(exports, "AccountLockedError", { enumerable: true, get: function () { return auth_errors_1.AccountLockedError; } });
|
|
184
|
-
Object.defineProperty(exports, "UnlockTokenInvalidError", { enumerable: true, get: function () { return auth_errors_1.UnlockTokenInvalidError; } });
|
|
185
|
-
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return auth_errors_1.RateLimitError; } });
|
|
186
|
-
Object.defineProperty(exports, "NetworkError", { enumerable: true, get: function () { return auth_errors_1.NetworkError; } });
|
|
187
|
-
Object.defineProperty(exports, "InvalidPhoneNumberError", { enumerable: true, get: function () { return auth_errors_1.InvalidPhoneNumberError; } });
|
|
188
|
-
Object.defineProperty(exports, "OtpExpiredError", { enumerable: true, get: function () { return auth_errors_1.OtpExpiredError; } });
|
|
189
|
-
Object.defineProperty(exports, "OtpInvalidError", { enumerable: true, get: function () { return auth_errors_1.OtpInvalidError; } });
|
|
190
|
-
Object.defineProperty(exports, "OtpMaxAttemptsError", { enumerable: true, get: function () { return auth_errors_1.OtpMaxAttemptsError; } });
|
|
191
|
-
Object.defineProperty(exports, "OtpRateLimitError", { enumerable: true, get: function () { return auth_errors_1.OtpRateLimitError; } });
|
|
192
|
-
Object.defineProperty(exports, "PhoneAlreadyLinkedError", { enumerable: true, get: function () { return auth_errors_1.PhoneAlreadyLinkedError; } });
|
|
193
|
-
Object.defineProperty(exports, "SmsConfigMissingError", { enumerable: true, get: function () { return auth_errors_1.SmsConfigMissingError; } });
|
package/dist/logic-engine.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export interface FlowResult {
|
|
2
|
-
hasEvent: boolean;
|
|
3
|
-
eventName?: string;
|
|
4
|
-
args: Record<string, unknown>;
|
|
5
|
-
completed: boolean;
|
|
6
|
-
error?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class KoolbaseLogicEngine {
|
|
9
|
-
execute(flowId: string, flows: Record<string, unknown>, context: Record<string, unknown>, config: Record<string, unknown>, flags: Record<string, boolean>): FlowResult;
|
|
10
|
-
private evalNode;
|
|
11
|
-
private evalIf;
|
|
12
|
-
private evalSequence;
|
|
13
|
-
private evalCondition;
|
|
14
|
-
private resolve;
|
|
15
|
-
private getNested;
|
|
16
|
-
private setNested;
|
|
17
|
-
}
|