@techfinityedge/koolbase-react-native 1.6.1
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/README.md +282 -0
- package/dist/analytics.d.ts +26 -0
- package/dist/analytics.js +138 -0
- package/dist/apple-auth.d.ts +22 -0
- package/dist/apple-auth.js +74 -0
- package/dist/auth.d.ts +24 -0
- package/dist/auth.js +85 -0
- package/dist/cache-store.d.ts +11 -0
- package/dist/cache-store.js +136 -0
- package/dist/code-push.d.ts +51 -0
- package/dist/code-push.js +234 -0
- package/dist/database.d.ts +15 -0
- package/dist/database.js +161 -0
- package/dist/flags.d.ts +15 -0
- package/dist/flags.js +76 -0
- package/dist/functions.d.ts +7 -0
- package/dist/functions.js +64 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +165 -0
- package/dist/logic-engine.d.ts +17 -0
- package/dist/logic-engine.js +193 -0
- package/dist/messaging.d.ts +20 -0
- package/dist/messaging.js +58 -0
- package/dist/realtime.d.ts +11 -0
- package/dist/realtime.js +52 -0
- package/dist/storage.d.ts +12 -0
- package/dist/storage.js +62 -0
- package/dist/sync-engine.d.ts +15 -0
- package/dist/sync-engine.js +83 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.js +9 -0
- package/package.json +43 -0
package/dist/realtime.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KoolbaseRealtime = void 0;
|
|
4
|
+
class KoolbaseRealtime {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.ws = null;
|
|
7
|
+
this.listeners = new Map();
|
|
8
|
+
this.reconnectTimer = null;
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
subscribe(collection, callback) {
|
|
12
|
+
if (!this.listeners.has(collection)) {
|
|
13
|
+
this.listeners.set(collection, []);
|
|
14
|
+
}
|
|
15
|
+
this.listeners.get(collection).push(callback);
|
|
16
|
+
if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
|
|
17
|
+
this.connect();
|
|
18
|
+
}
|
|
19
|
+
// Return unsubscribe function
|
|
20
|
+
return () => {
|
|
21
|
+
const callbacks = this.listeners.get(collection) ?? [];
|
|
22
|
+
const index = callbacks.indexOf(callback);
|
|
23
|
+
if (index > -1)
|
|
24
|
+
callbacks.splice(index, 1);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
connect() {
|
|
28
|
+
const wsUrl = this.config.baseUrl
|
|
29
|
+
.replace('https://', 'wss://')
|
|
30
|
+
.replace('http://', 'ws://');
|
|
31
|
+
this.ws = new WebSocket(`${wsUrl}/v1/sdk/realtime?key=${this.config.publicKey}`);
|
|
32
|
+
this.ws.onmessage = (event) => {
|
|
33
|
+
try {
|
|
34
|
+
const msg = JSON.parse(event.data);
|
|
35
|
+
const callbacks = this.listeners.get(msg.collection) ?? [];
|
|
36
|
+
callbacks.forEach((cb) => cb(msg));
|
|
37
|
+
}
|
|
38
|
+
catch (_) { }
|
|
39
|
+
};
|
|
40
|
+
this.ws.onclose = () => {
|
|
41
|
+
this.reconnectTimer = setTimeout(() => this.connect(), 3000);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
disconnect() {
|
|
45
|
+
if (this.reconnectTimer)
|
|
46
|
+
clearTimeout(this.reconnectTimer);
|
|
47
|
+
this.ws?.close();
|
|
48
|
+
this.ws = null;
|
|
49
|
+
this.listeners.clear();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.KoolbaseRealtime = KoolbaseRealtime;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { KoolbaseConfig, UploadOptions } from './types';
|
|
2
|
+
export declare class KoolbaseStorage {
|
|
3
|
+
private config;
|
|
4
|
+
private getToken;
|
|
5
|
+
constructor(config: KoolbaseConfig, getToken: () => string | null);
|
|
6
|
+
private get headers();
|
|
7
|
+
upload(options: UploadOptions): Promise<{
|
|
8
|
+
url: string;
|
|
9
|
+
}>;
|
|
10
|
+
getDownloadUrl(bucket: string, path: string): Promise<string>;
|
|
11
|
+
delete(bucket: string, path: string): Promise<void>;
|
|
12
|
+
}
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KoolbaseStorage = void 0;
|
|
4
|
+
class KoolbaseStorage {
|
|
5
|
+
constructor(config, getToken) {
|
|
6
|
+
this.config = config;
|
|
7
|
+
this.getToken = getToken;
|
|
8
|
+
}
|
|
9
|
+
get headers() {
|
|
10
|
+
const token = this.getToken();
|
|
11
|
+
return {
|
|
12
|
+
'x-api-key': this.config.publicKey,
|
|
13
|
+
...(token ? { Authorization: `Bearer ${token}` } : {}),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
async upload(options) {
|
|
17
|
+
// Get presigned upload URL
|
|
18
|
+
const res = await fetch(`${this.config.baseUrl}/v1/sdk/storage/${options.bucket}/upload`, {
|
|
19
|
+
method: 'POST',
|
|
20
|
+
headers: { ...this.headers, 'Content-Type': 'application/json' },
|
|
21
|
+
body: JSON.stringify({
|
|
22
|
+
path: options.path,
|
|
23
|
+
content_type: options.file.type,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
if (!res.ok) {
|
|
27
|
+
const data = await res.json();
|
|
28
|
+
throw new Error(data.error ?? 'Failed to get upload URL');
|
|
29
|
+
}
|
|
30
|
+
const { upload_url, public_url } = await res.json();
|
|
31
|
+
// Upload to presigned URL
|
|
32
|
+
const formData = new FormData();
|
|
33
|
+
formData.append('file', {
|
|
34
|
+
uri: options.file.uri,
|
|
35
|
+
name: options.file.name,
|
|
36
|
+
type: options.file.type,
|
|
37
|
+
});
|
|
38
|
+
await fetch(upload_url, { method: 'PUT', body: formData });
|
|
39
|
+
return { url: public_url };
|
|
40
|
+
}
|
|
41
|
+
async getDownloadUrl(bucket, path) {
|
|
42
|
+
const res = await fetch(`${this.config.baseUrl}/v1/sdk/storage/${bucket}/download?path=${encodeURIComponent(path)}`, { headers: this.headers });
|
|
43
|
+
if (!res.ok) {
|
|
44
|
+
const data = await res.json();
|
|
45
|
+
throw new Error(data.error ?? 'Failed to get download URL');
|
|
46
|
+
}
|
|
47
|
+
const { url } = await res.json();
|
|
48
|
+
return url;
|
|
49
|
+
}
|
|
50
|
+
async delete(bucket, path) {
|
|
51
|
+
const res = await fetch(`${this.config.baseUrl}/v1/sdk/storage/${bucket}/delete`, {
|
|
52
|
+
method: 'DELETE',
|
|
53
|
+
headers: { ...this.headers, 'Content-Type': 'application/json' },
|
|
54
|
+
body: JSON.stringify({ path }),
|
|
55
|
+
});
|
|
56
|
+
if (!res.ok && res.status !== 204) {
|
|
57
|
+
const data = await res.json();
|
|
58
|
+
throw new Error(data.error ?? 'Delete failed');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.KoolbaseStorage = KoolbaseStorage;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { KoolbaseConfig } from './types';
|
|
2
|
+
type SyncCallback = () => void;
|
|
3
|
+
export declare class SyncEngine {
|
|
4
|
+
private config;
|
|
5
|
+
private getUserId;
|
|
6
|
+
private onSyncComplete?;
|
|
7
|
+
private unsubscribe?;
|
|
8
|
+
private isSyncing;
|
|
9
|
+
constructor(config: KoolbaseConfig, getUserId: () => string | null, onSyncComplete?: SyncCallback);
|
|
10
|
+
start(): void;
|
|
11
|
+
stop(): void;
|
|
12
|
+
flush(): Promise<void>;
|
|
13
|
+
private executeWrite;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SyncEngine = void 0;
|
|
7
|
+
const netinfo_1 = __importDefault(require("@react-native-community/netinfo"));
|
|
8
|
+
const cache_store_1 = require("./cache-store");
|
|
9
|
+
class SyncEngine {
|
|
10
|
+
constructor(config, getUserId, onSyncComplete) {
|
|
11
|
+
this.isSyncing = false;
|
|
12
|
+
this.config = config;
|
|
13
|
+
this.getUserId = getUserId;
|
|
14
|
+
this.onSyncComplete = onSyncComplete;
|
|
15
|
+
}
|
|
16
|
+
start() {
|
|
17
|
+
this.unsubscribe = netinfo_1.default.addEventListener(state => {
|
|
18
|
+
if (state.isConnected && state.isInternetReachable !== false) {
|
|
19
|
+
this.flush();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
stop() {
|
|
24
|
+
this.unsubscribe?.();
|
|
25
|
+
}
|
|
26
|
+
async flush() {
|
|
27
|
+
if (this.isSyncing)
|
|
28
|
+
return;
|
|
29
|
+
const userId = this.getUserId();
|
|
30
|
+
if (!userId)
|
|
31
|
+
return;
|
|
32
|
+
this.isSyncing = true;
|
|
33
|
+
try {
|
|
34
|
+
const queue = await (0, cache_store_1.getWriteQueue)(userId);
|
|
35
|
+
if (queue.length === 0)
|
|
36
|
+
return;
|
|
37
|
+
for (const write of queue) {
|
|
38
|
+
try {
|
|
39
|
+
await this.executeWrite(write);
|
|
40
|
+
await (0, cache_store_1.removeFromWriteQueue)(userId, write.id);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
await (0, cache_store_1.incrementWriteRetry)(userId, write.id);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
this.onSyncComplete?.();
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
this.isSyncing = false;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async executeWrite(write) {
|
|
53
|
+
const headers = {
|
|
54
|
+
'Content-Type': 'application/json',
|
|
55
|
+
'x-api-key': this.config.publicKey,
|
|
56
|
+
};
|
|
57
|
+
if (write.type === 'insert') {
|
|
58
|
+
const res = await fetch(`${this.config.baseUrl}/v1/sdk/db/insert`, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers,
|
|
61
|
+
body: JSON.stringify({ collection: write.collection, data: write.data }),
|
|
62
|
+
});
|
|
63
|
+
if (!res.ok)
|
|
64
|
+
throw new Error(`Insert failed: ${res.status}`);
|
|
65
|
+
}
|
|
66
|
+
else if (write.type === 'update') {
|
|
67
|
+
const res = await fetch(`${this.config.baseUrl}/v1/sdk/db/records/${write.recordId}`, {
|
|
68
|
+
method: 'PATCH',
|
|
69
|
+
headers,
|
|
70
|
+
body: JSON.stringify({ data: write.data }),
|
|
71
|
+
});
|
|
72
|
+
if (!res.ok)
|
|
73
|
+
throw new Error(`Update failed: ${res.status}`);
|
|
74
|
+
}
|
|
75
|
+
else if (write.type === 'delete') {
|
|
76
|
+
const res = await fetch(`${this.config.baseUrl}/v1/sdk/db/records/${write.recordId}`, { method: 'DELETE', headers });
|
|
77
|
+
if (!res.ok && res.status !== 204) {
|
|
78
|
+
throw new Error(`Delete failed: ${res.status}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
exports.SyncEngine = SyncEngine;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
export interface KoolbaseConfig {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
codePushChannel?: string;
|
|
5
|
+
analyticsEnabled?: boolean;
|
|
6
|
+
appVersion?: string;
|
|
7
|
+
messagingEnabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface KoolbaseUser {
|
|
10
|
+
id: string;
|
|
11
|
+
email: string;
|
|
12
|
+
fullName?: string;
|
|
13
|
+
avatarUrl?: string;
|
|
14
|
+
verified: boolean;
|
|
15
|
+
createdAt: string;
|
|
16
|
+
}
|
|
17
|
+
export interface KoolbaseSession {
|
|
18
|
+
accessToken: string;
|
|
19
|
+
refreshToken: string;
|
|
20
|
+
user: KoolbaseUser;
|
|
21
|
+
}
|
|
22
|
+
export interface RegisterParams {
|
|
23
|
+
email: string;
|
|
24
|
+
password: string;
|
|
25
|
+
fullName?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface LoginParams {
|
|
28
|
+
email: string;
|
|
29
|
+
password: string;
|
|
30
|
+
}
|
|
31
|
+
export interface KoolbaseRecord {
|
|
32
|
+
id: string;
|
|
33
|
+
projectId: string;
|
|
34
|
+
collectionId: string;
|
|
35
|
+
createdBy?: string;
|
|
36
|
+
data: Record<string, unknown>;
|
|
37
|
+
createdAt: string;
|
|
38
|
+
updatedAt: string;
|
|
39
|
+
}
|
|
40
|
+
export interface QueryOptions {
|
|
41
|
+
filters?: Record<string, unknown>;
|
|
42
|
+
limit?: number;
|
|
43
|
+
offset?: number;
|
|
44
|
+
orderBy?: string;
|
|
45
|
+
orderDesc?: boolean;
|
|
46
|
+
populate?: string[];
|
|
47
|
+
}
|
|
48
|
+
export interface QueryResult {
|
|
49
|
+
records: KoolbaseRecord[];
|
|
50
|
+
total: number;
|
|
51
|
+
isFromCache?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface PendingWrite {
|
|
54
|
+
id: string;
|
|
55
|
+
type: 'insert' | 'update' | 'delete';
|
|
56
|
+
collection?: string;
|
|
57
|
+
recordId?: string;
|
|
58
|
+
data?: Record<string, unknown>;
|
|
59
|
+
retries: number;
|
|
60
|
+
createdAt: string;
|
|
61
|
+
}
|
|
62
|
+
export interface UploadOptions {
|
|
63
|
+
bucket: string;
|
|
64
|
+
path: string;
|
|
65
|
+
file: {
|
|
66
|
+
uri: string;
|
|
67
|
+
name: string;
|
|
68
|
+
type: string;
|
|
69
|
+
};
|
|
70
|
+
onProgress?: (percent: number) => void;
|
|
71
|
+
}
|
|
72
|
+
export interface RealtimeEvent {
|
|
73
|
+
type: 'created' | 'updated' | 'deleted';
|
|
74
|
+
collection: string;
|
|
75
|
+
record: KoolbaseRecord;
|
|
76
|
+
}
|
|
77
|
+
export type RealtimeCallback = (event: RealtimeEvent) => void;
|
|
78
|
+
export interface BootstrapPayload {
|
|
79
|
+
payload_version: string;
|
|
80
|
+
flags: Record<string, {
|
|
81
|
+
enabled: boolean;
|
|
82
|
+
rollout_percentage: number;
|
|
83
|
+
kill_switch: boolean;
|
|
84
|
+
}>;
|
|
85
|
+
config: Record<string, unknown>;
|
|
86
|
+
version: {
|
|
87
|
+
min_version: string;
|
|
88
|
+
latest_version: string;
|
|
89
|
+
force_update: boolean;
|
|
90
|
+
update_message: string;
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
export type VersionStatus = 'up_to_date' | 'soft_update' | 'force_update';
|
|
94
|
+
export interface VersionCheckResult {
|
|
95
|
+
status: VersionStatus;
|
|
96
|
+
message: string;
|
|
97
|
+
latestVersion: string;
|
|
98
|
+
}
|
|
99
|
+
export declare enum FunctionRuntime {
|
|
100
|
+
Deno = "deno",
|
|
101
|
+
Dart = "dart"
|
|
102
|
+
}
|
|
103
|
+
export interface DeployOptions {
|
|
104
|
+
name: string;
|
|
105
|
+
code: string;
|
|
106
|
+
runtime?: FunctionRuntime;
|
|
107
|
+
timeoutMs?: number;
|
|
108
|
+
}
|
|
109
|
+
export interface DeployResult {
|
|
110
|
+
id: string;
|
|
111
|
+
name: string;
|
|
112
|
+
runtime: string;
|
|
113
|
+
version: number;
|
|
114
|
+
isActive: boolean;
|
|
115
|
+
timeoutMs: number;
|
|
116
|
+
lastDeployedAt: string | null;
|
|
117
|
+
}
|
|
118
|
+
export interface FunctionInvokeResult {
|
|
119
|
+
statusCode: number;
|
|
120
|
+
data: Record<string, unknown> | null;
|
|
121
|
+
success: boolean;
|
|
122
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.FunctionRuntime = void 0;
|
|
4
|
+
// ─── Functions ─────────────────────────────────────────────────────────────
|
|
5
|
+
var FunctionRuntime;
|
|
6
|
+
(function (FunctionRuntime) {
|
|
7
|
+
FunctionRuntime["Deno"] = "deno";
|
|
8
|
+
FunctionRuntime["Dart"] = "dart";
|
|
9
|
+
})(FunctionRuntime || (exports.FunctionRuntime = FunctionRuntime = {}));
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@techfinityedge/koolbase-react-native",
|
|
3
|
+
"version": "1.6.1",
|
|
4
|
+
"description": "React Native SDK for Koolbase — auth, database, storage, realtime, feature flags, and functions in one package.",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"prepare": "npm run build"
|
|
13
|
+
},
|
|
14
|
+
"keywords": [
|
|
15
|
+
"koolbase",
|
|
16
|
+
"react-native",
|
|
17
|
+
"baas",
|
|
18
|
+
"firebase-alternative",
|
|
19
|
+
"flutter"
|
|
20
|
+
],
|
|
21
|
+
"author": "Kennedy Owusu",
|
|
22
|
+
"license": "MIT",
|
|
23
|
+
"homepage": "https://koolbase.com",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/kennedyowusu/koolbase-react-native"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/jszip": "^3.4.0",
|
|
30
|
+
"typescript": "^5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependencies": {
|
|
33
|
+
"react-native": ">=0.70.0"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@react-native-async-storage/async-storage": "^3.0.2",
|
|
37
|
+
"@react-native-community/netinfo": "^12.0.1",
|
|
38
|
+
"jszip": "^3.10.1"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
|
+
}
|
|
43
|
+
}
|