nexabase-console 2.0.0 → 2.0.2
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 +96 -23
- package/dist/app/NexaApp.d.ts +6 -5
- package/dist/app/NexaApp.js +2 -2
- package/dist/app/initializeApp.d.ts +6 -0
- package/dist/app/initializeApp.js +14 -1
- package/dist/auth/Auth.d.ts +38 -6
- package/dist/auth/Auth.js +341 -28
- package/dist/auth/NexaAuthError.d.ts +5 -0
- package/dist/auth/NexaAuthError.js +15 -0
- package/dist/auth/authTypes.d.ts +38 -1
- package/dist/auth/persistence.d.ts +7 -5
- package/dist/auth/persistence.js +42 -13
- package/dist/facade/nexaSDK.d.ts +93 -0
- package/dist/facade/nexaSDK.js +129 -0
- package/dist/firestore/Query.js +14 -10
- package/dist/firestore/batch.js +4 -0
- package/dist/firestore/writes.js +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/storage/Storage.d.ts +5 -0
- package/dist/storage/Storage.js +17 -1
- package/dist/storage/StorageReference.d.ts +18 -0
- package/dist/storage/StorageReference.js +33 -1
- package/dist/types/index.d.ts +1 -8
- package/package.json +1 -1
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.nexaSDK = exports.NexaSDKFacade = void 0;
|
|
4
|
+
exports.createNexaSDK = createNexaSDK;
|
|
5
|
+
const initializeApp_1 = require("../app/initializeApp");
|
|
6
|
+
/**
|
|
7
|
+
* Universal NexaBase Client SDK Facade (Domain & Server-Authoritative Logic)
|
|
8
|
+
* Decouples client components & stores from raw primitives like getDocs/runTransaction.
|
|
9
|
+
*/
|
|
10
|
+
class NexaSDKFacade {
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.appInstance = null;
|
|
13
|
+
this.customBaseURL = '';
|
|
14
|
+
/* =========================================================================
|
|
15
|
+
* 1. PRODUCTS & INVENTORY DOMAIN
|
|
16
|
+
* ========================================================================= */
|
|
17
|
+
this.products = {
|
|
18
|
+
/**
|
|
19
|
+
* Atomically adjust product stock in server with audit log trail
|
|
20
|
+
*/
|
|
21
|
+
adjustStock: async (params) => {
|
|
22
|
+
return this.call('adjustProductStock', params);
|
|
23
|
+
},
|
|
24
|
+
/**
|
|
25
|
+
* Quick stock deduction helper
|
|
26
|
+
*/
|
|
27
|
+
deductStock: async (productId, qty, reason = 'sale') => {
|
|
28
|
+
return this.call('adjustProductStock', { productId, delta: -Math.abs(qty), reason });
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Quick stock addition helper
|
|
32
|
+
*/
|
|
33
|
+
addStock: async (productId, qty, reason = 'restock') => {
|
|
34
|
+
return this.call('adjustProductStock', { productId, delta: Math.abs(qty), reason });
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/* =========================================================================
|
|
38
|
+
* 2. ORDERS & WAREHOUSE DOMAIN
|
|
39
|
+
* ========================================================================= */
|
|
40
|
+
this.orders = {
|
|
41
|
+
/**
|
|
42
|
+
* Scan tracking number (resi), update shipping status & auto-deduct stock atomically
|
|
43
|
+
*/
|
|
44
|
+
scanResi: async (params) => {
|
|
45
|
+
return this.call('scanResiOrder', params);
|
|
46
|
+
},
|
|
47
|
+
/**
|
|
48
|
+
* Cancel an order & automatically return deducted stock to inventory
|
|
49
|
+
*/
|
|
50
|
+
cancelOrder: async (params) => {
|
|
51
|
+
return this.call('cancelOrder', params);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/* =========================================================================
|
|
55
|
+
* 3. FINANCIAL & TRANSACTION DOMAIN
|
|
56
|
+
* ========================================================================= */
|
|
57
|
+
this.finance = {
|
|
58
|
+
/**
|
|
59
|
+
* Atomic balance transfer between users with ledger record
|
|
60
|
+
*/
|
|
61
|
+
transferBalance: async (params) => {
|
|
62
|
+
return this.call('transferBalance', params);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
/* =========================================================================
|
|
66
|
+
* 4. GENERAL PURPOSE UTILITIES
|
|
67
|
+
* ========================================================================= */
|
|
68
|
+
this.utils = {
|
|
69
|
+
/**
|
|
70
|
+
* Atomic field incrementer on any Firestore document
|
|
71
|
+
*/
|
|
72
|
+
increment: async (params) => {
|
|
73
|
+
return this.call('incrementCounter', params);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
if (options?.app)
|
|
77
|
+
this.appInstance = options.app;
|
|
78
|
+
if (options?.baseURL)
|
|
79
|
+
this.customBaseURL = options.baseURL;
|
|
80
|
+
}
|
|
81
|
+
getApp() {
|
|
82
|
+
if (this.appInstance)
|
|
83
|
+
return this.appInstance;
|
|
84
|
+
return (0, initializeApp_1.getApp)();
|
|
85
|
+
}
|
|
86
|
+
getBaseURL() {
|
|
87
|
+
if (this.customBaseURL)
|
|
88
|
+
return this.customBaseURL;
|
|
89
|
+
if (typeof window !== 'undefined')
|
|
90
|
+
return window.location.origin;
|
|
91
|
+
return 'http://localhost:3000';
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Universal Server-Authoritative Cloud Function Caller
|
|
95
|
+
*/
|
|
96
|
+
async call(functionName, data = {}) {
|
|
97
|
+
const app = this.getApp();
|
|
98
|
+
const projectId = app.options.projectId;
|
|
99
|
+
const apiKey = app.options.apiKey;
|
|
100
|
+
const url = `${this.getBaseURL()}/api/functions/${projectId}/${functionName}`;
|
|
101
|
+
const headers = {
|
|
102
|
+
'Content-Type': 'application/json'
|
|
103
|
+
};
|
|
104
|
+
if (apiKey) {
|
|
105
|
+
headers['Authorization'] = `Bearer ${apiKey}`;
|
|
106
|
+
}
|
|
107
|
+
const response = await fetch(url, {
|
|
108
|
+
method: 'POST',
|
|
109
|
+
headers,
|
|
110
|
+
body: JSON.stringify(data)
|
|
111
|
+
});
|
|
112
|
+
const result = await response.json();
|
|
113
|
+
if (!response.ok || result.success === false) {
|
|
114
|
+
throw new Error(result.error || result.message || `Failed to execute function "${functionName}"`);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
exports.NexaSDKFacade = NexaSDKFacade;
|
|
120
|
+
/**
|
|
121
|
+
* Singleton Default Facade Export
|
|
122
|
+
*/
|
|
123
|
+
exports.nexaSDK = new NexaSDKFacade();
|
|
124
|
+
/**
|
|
125
|
+
* Factory function to create custom facade instance with specific NexaApp
|
|
126
|
+
*/
|
|
127
|
+
function createNexaSDK(app, options) {
|
|
128
|
+
return new NexaSDKFacade({ app, baseURL: options?.baseURL });
|
|
129
|
+
}
|
package/dist/firestore/Query.js
CHANGED
|
@@ -120,11 +120,13 @@ const getDocs = async (queryOrCollection) => {
|
|
|
120
120
|
for (const d of docs) {
|
|
121
121
|
await db._setCache(`${collectionPath}/${d.id}`, d.fields);
|
|
122
122
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
123
|
+
if (constraints.length === 0) {
|
|
124
|
+
for (const cachePath of Object.keys(db._firestoreCache)) {
|
|
125
|
+
if (cachePath.startsWith(collectionPath + '/')) {
|
|
126
|
+
const docId = cachePath.split('/').pop();
|
|
127
|
+
if (docId && !serverIds.has(docId)) {
|
|
128
|
+
await db._deleteCache(cachePath);
|
|
129
|
+
}
|
|
128
130
|
}
|
|
129
131
|
}
|
|
130
132
|
}
|
|
@@ -141,11 +143,13 @@ const getDocs = async (queryOrCollection) => {
|
|
|
141
143
|
for (const d of docs) {
|
|
142
144
|
await db._setCache(`${collectionPath}/${d.id}`, d.fields);
|
|
143
145
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
if (constraints.length === 0) {
|
|
147
|
+
for (const cachePath of Object.keys(db._firestoreCache)) {
|
|
148
|
+
if (cachePath.startsWith(collectionPath + '/')) {
|
|
149
|
+
const docId = cachePath.split('/').pop();
|
|
150
|
+
if (docId && !serverIds.has(docId)) {
|
|
151
|
+
await db._deleteCache(cachePath);
|
|
152
|
+
}
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
155
|
}
|
package/dist/firestore/batch.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.writeBatch = void 0;
|
|
4
4
|
const helpers_1 = require("../utils/helpers");
|
|
5
|
+
const NexaError_1 = require("../errors/NexaError");
|
|
5
6
|
const writeBatch = (db) => {
|
|
6
7
|
const operations = [];
|
|
7
8
|
const batchObj = {
|
|
@@ -59,6 +60,9 @@ const writeBatch = (db) => {
|
|
|
59
60
|
return (await db.client.post(`/api/firestore/${db.projectId}/batch`, { operations, idempotencyKey }, { headers: { 'X-Idempotency-Key': idempotencyKey } })).data;
|
|
60
61
|
}
|
|
61
62
|
catch (error) {
|
|
63
|
+
if (error && error.response && error.response.status >= 400 && error.response.status < 500) {
|
|
64
|
+
throw (0, NexaError_1.toNexaError)(error);
|
|
65
|
+
}
|
|
62
66
|
for (const op of operations) {
|
|
63
67
|
await db._addOfflineJob({
|
|
64
68
|
id: Math.random().toString(36).substring(2, 9),
|
package/dist/firestore/writes.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteDoc = exports.updateDoc = exports.patchDoc = exports.setDoc = exports.FieldValue = void 0;
|
|
4
4
|
const helpers_1 = require("../utils/helpers");
|
|
5
|
+
const NexaError_1 = require("../errors/NexaError");
|
|
5
6
|
var FieldValue_1 = require("./FieldValue");
|
|
6
7
|
Object.defineProperty(exports, "FieldValue", { enumerable: true, get: function () { return FieldValue_1.FieldValue; } });
|
|
7
8
|
const setDoc = async (docRef, data, options) => {
|
|
@@ -35,6 +36,9 @@ const setDoc = async (docRef, data, options) => {
|
|
|
35
36
|
return res;
|
|
36
37
|
}
|
|
37
38
|
catch (error) {
|
|
39
|
+
if (error && error.response && error.response.status >= 400 && error.response.status < 500) {
|
|
40
|
+
throw (0, NexaError_1.toNexaError)(error);
|
|
41
|
+
}
|
|
38
42
|
await db._addOfflineJob({
|
|
39
43
|
id: jobId,
|
|
40
44
|
type: 'set',
|
|
@@ -82,6 +86,9 @@ const patchDoc = async (docRef, data, options) => {
|
|
|
82
86
|
return res;
|
|
83
87
|
}
|
|
84
88
|
catch (error) {
|
|
89
|
+
if (error && error.response && error.response.status >= 400 && error.response.status < 500) {
|
|
90
|
+
throw (0, NexaError_1.toNexaError)(error);
|
|
91
|
+
}
|
|
85
92
|
await db._addOfflineJob({
|
|
86
93
|
id: jobId,
|
|
87
94
|
type: 'patch',
|
|
@@ -129,6 +136,9 @@ const deleteDoc = async (docRef, options) => {
|
|
|
129
136
|
return res;
|
|
130
137
|
}
|
|
131
138
|
catch (error) {
|
|
139
|
+
if (error && error.response && error.response.status >= 400 && error.response.status < 500) {
|
|
140
|
+
throw (0, NexaError_1.toNexaError)(error);
|
|
141
|
+
}
|
|
132
142
|
await db._addOfflineJob({
|
|
133
143
|
id: jobId,
|
|
134
144
|
type: 'delete',
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export * from './app/NexaApp';
|
|
|
3
3
|
export * from './auth/Auth';
|
|
4
4
|
export * from './auth/authTypes';
|
|
5
5
|
export * from './auth/persistence';
|
|
6
|
+
export * from './auth/NexaAuthError';
|
|
6
7
|
export * from './firestore/Firestore';
|
|
7
8
|
export * from './firestore/DocumentReference';
|
|
8
9
|
export * from './firestore/CollectionReference';
|
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ __exportStar(require("./app/NexaApp"), exports);
|
|
|
21
21
|
__exportStar(require("./auth/Auth"), exports);
|
|
22
22
|
__exportStar(require("./auth/authTypes"), exports);
|
|
23
23
|
__exportStar(require("./auth/persistence"), exports);
|
|
24
|
+
__exportStar(require("./auth/NexaAuthError"), exports);
|
|
24
25
|
// Firestore
|
|
25
26
|
__exportStar(require("./firestore/Firestore"), exports);
|
|
26
27
|
__exportStar(require("./firestore/DocumentReference"), exports);
|
package/dist/storage/Storage.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Storage = void 0;
|
|
3
|
+
exports.getStorage = exports.Storage = void 0;
|
|
4
4
|
const UploadTask_1 = require("./UploadTask");
|
|
5
5
|
const NexaError_1 = require("../errors/NexaError");
|
|
6
6
|
class Storage {
|
|
@@ -37,5 +37,21 @@ class Storage {
|
|
|
37
37
|
throw (0, NexaError_1.toNexaError)(err);
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
+
async deleteFile(path) {
|
|
41
|
+
try {
|
|
42
|
+
const res = await this.client.delete(`/api/project/${this.projectId}/storage/file?path=${encodeURIComponent(path)}`);
|
|
43
|
+
return res.data;
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
throw (0, NexaError_1.toNexaError)(err);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
40
49
|
}
|
|
41
50
|
exports.Storage = Storage;
|
|
51
|
+
const getStorage = (app) => {
|
|
52
|
+
if (app && typeof app.storage === 'function') {
|
|
53
|
+
return app.storage();
|
|
54
|
+
}
|
|
55
|
+
throw new Error('Invalid NexaApp instance provided to getStorage()');
|
|
56
|
+
};
|
|
57
|
+
exports.getStorage = getStorage;
|
|
@@ -9,5 +9,23 @@ export declare class StorageReferenceImpl implements IStorageReference {
|
|
|
9
9
|
path: string;
|
|
10
10
|
}>;
|
|
11
11
|
getDownloadURL(): Promise<string>;
|
|
12
|
+
delete(): Promise<{
|
|
13
|
+
success: boolean;
|
|
14
|
+
message?: string;
|
|
15
|
+
}>;
|
|
12
16
|
}
|
|
13
17
|
export declare const storageRef: (storage: Storage, path: string) => IStorageReference;
|
|
18
|
+
export declare const ref: (storage: Storage, path: string) => IStorageReference;
|
|
19
|
+
export declare const uploadBytes: (storageRef: IStorageReference, file: File | Blob, options?: UploadOptions) => Promise<{
|
|
20
|
+
url: string;
|
|
21
|
+
path: string;
|
|
22
|
+
}>;
|
|
23
|
+
export declare const uploadBytesResumable: (storageRef: IStorageReference, file: File | Blob, options?: UploadOptions) => Promise<{
|
|
24
|
+
url: string;
|
|
25
|
+
path: string;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const getDownloadURL: (storageRef: IStorageReference) => Promise<string>;
|
|
28
|
+
export declare const deleteObject: (storageRef: IStorageReference) => Promise<{
|
|
29
|
+
success: boolean;
|
|
30
|
+
message?: string;
|
|
31
|
+
}>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.storageRef = exports.StorageReferenceImpl = void 0;
|
|
3
|
+
exports.deleteObject = exports.getDownloadURL = exports.uploadBytesResumable = exports.uploadBytes = exports.ref = exports.storageRef = exports.StorageReferenceImpl = void 0;
|
|
4
4
|
class StorageReferenceImpl {
|
|
5
5
|
constructor(path, storage) {
|
|
6
6
|
this.path = path;
|
|
@@ -12,9 +12,41 @@ class StorageReferenceImpl {
|
|
|
12
12
|
async getDownloadURL() {
|
|
13
13
|
return this.storage.getDownloadURL(this.path);
|
|
14
14
|
}
|
|
15
|
+
async delete() {
|
|
16
|
+
return this.storage.deleteFile(this.path);
|
|
17
|
+
}
|
|
15
18
|
}
|
|
16
19
|
exports.StorageReferenceImpl = StorageReferenceImpl;
|
|
17
20
|
const storageRef = (storage, path) => {
|
|
18
21
|
return new StorageReferenceImpl(path, storage);
|
|
19
22
|
};
|
|
20
23
|
exports.storageRef = storageRef;
|
|
24
|
+
const ref = (storage, path) => {
|
|
25
|
+
return new StorageReferenceImpl(path, storage);
|
|
26
|
+
};
|
|
27
|
+
exports.ref = ref;
|
|
28
|
+
const uploadBytes = async (storageRef, file, options) => {
|
|
29
|
+
if (storageRef.upload) {
|
|
30
|
+
return storageRef.upload(file, options);
|
|
31
|
+
}
|
|
32
|
+
throw new Error('Invalid storage reference');
|
|
33
|
+
};
|
|
34
|
+
exports.uploadBytes = uploadBytes;
|
|
35
|
+
const uploadBytesResumable = (storageRef, file, options) => {
|
|
36
|
+
return (0, exports.uploadBytes)(storageRef, file, options);
|
|
37
|
+
};
|
|
38
|
+
exports.uploadBytesResumable = uploadBytesResumable;
|
|
39
|
+
const getDownloadURL = async (storageRef) => {
|
|
40
|
+
if (storageRef.getDownloadURL) {
|
|
41
|
+
return storageRef.getDownloadURL();
|
|
42
|
+
}
|
|
43
|
+
throw new Error('Invalid storage reference');
|
|
44
|
+
};
|
|
45
|
+
exports.getDownloadURL = getDownloadURL;
|
|
46
|
+
const deleteObject = async (storageRef) => {
|
|
47
|
+
if (storageRef.delete) {
|
|
48
|
+
return storageRef.delete();
|
|
49
|
+
}
|
|
50
|
+
throw new Error('Invalid storage reference');
|
|
51
|
+
};
|
|
52
|
+
exports.deleteObject = deleteObject;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { NexaApp } from '../app/NexaApp';
|
|
2
2
|
import type { FieldPath } from '../firestore/FieldPath';
|
|
3
|
+
import type { User } from '../auth/authTypes';
|
|
3
4
|
export interface NexaConfig {
|
|
4
5
|
projectId: string;
|
|
5
6
|
apiKey?: string;
|
|
@@ -7,14 +8,6 @@ export interface NexaConfig {
|
|
|
7
8
|
enablePersistence?: boolean;
|
|
8
9
|
cacheStrategy?: 'network-first' | 'cache-first';
|
|
9
10
|
}
|
|
10
|
-
export interface User {
|
|
11
|
-
id: string;
|
|
12
|
-
email: string;
|
|
13
|
-
name?: string;
|
|
14
|
-
role?: string;
|
|
15
|
-
createdAt?: string;
|
|
16
|
-
[key: string]: any;
|
|
17
|
-
}
|
|
18
11
|
export interface AuthResponse {
|
|
19
12
|
token: string;
|
|
20
13
|
user: User;
|
package/package.json
CHANGED