@giaeulate/baas-sdk 1.0.9 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +103 -6
- package/dist/index.d.cts +79 -3
- package/dist/index.d.ts +79 -3
- package/dist/index.js +103 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,12 +32,32 @@ var HttpClient = class {
|
|
|
32
32
|
apiKey = "";
|
|
33
33
|
token = null;
|
|
34
34
|
environment = "prod";
|
|
35
|
+
_onForceLogout = null;
|
|
35
36
|
constructor(url, apiKey) {
|
|
36
37
|
let baseUrl = url || (typeof window !== "undefined" ? window.location.origin : "http://localhost:8080");
|
|
37
38
|
this.url = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
38
39
|
if (apiKey) this.apiKey = apiKey;
|
|
39
40
|
this.token = this.cleanValue(localStorage.getItem("baas_token"));
|
|
40
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Set the auth token manually (e.g. restoring from SecureStore in React Native).
|
|
44
|
+
* Persists to both the in-memory property and localStorage so getDynamicToken() works.
|
|
45
|
+
*/
|
|
46
|
+
setToken(token) {
|
|
47
|
+
this.token = token;
|
|
48
|
+
if (token) {
|
|
49
|
+
localStorage.setItem("baas_token", token);
|
|
50
|
+
} else {
|
|
51
|
+
localStorage.removeItem("baas_token");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Register a callback invoked on forced logout (401).
|
|
56
|
+
* Use this in React Native instead of the default window.location redirect.
|
|
57
|
+
*/
|
|
58
|
+
onForceLogout(callback) {
|
|
59
|
+
this._onForceLogout = callback;
|
|
60
|
+
}
|
|
41
61
|
cleanValue(val) {
|
|
42
62
|
if (!val || val === "null" || val === "undefined") return null;
|
|
43
63
|
return val.trim();
|
|
@@ -120,9 +140,13 @@ var HttpClient = class {
|
|
|
120
140
|
}
|
|
121
141
|
forceLogout() {
|
|
122
142
|
this.logout();
|
|
123
|
-
if (
|
|
143
|
+
if (this._onForceLogout) {
|
|
144
|
+
this._onForceLogout();
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (typeof window !== "undefined" && window.location && window.location.search !== void 0) {
|
|
124
148
|
if (!window.location.search.includes("expired")) {
|
|
125
|
-
window.location.href = "/
|
|
149
|
+
window.location.href = "/authentication/login?reason=expired";
|
|
126
150
|
}
|
|
127
151
|
}
|
|
128
152
|
}
|
|
@@ -406,6 +430,9 @@ function createDatabaseModule(client) {
|
|
|
406
430
|
async getSchema(name) {
|
|
407
431
|
return get(`/api/schemas/${name}`);
|
|
408
432
|
},
|
|
433
|
+
async saveSchemas(data) {
|
|
434
|
+
return post("/api/schemas", data);
|
|
435
|
+
},
|
|
409
436
|
// Tables
|
|
410
437
|
async createTable(tableName, definition) {
|
|
411
438
|
return post("/api/schemas/tables", { table_name: tableName, definition });
|
|
@@ -633,17 +660,23 @@ function createFunctionsModule(client) {
|
|
|
633
660
|
async invoke(id, data = {}) {
|
|
634
661
|
return post(`/api/functions/${id}/execute`, data);
|
|
635
662
|
},
|
|
663
|
+
async get(id) {
|
|
664
|
+
return get(`/api/functions/${id}`);
|
|
665
|
+
},
|
|
636
666
|
async list() {
|
|
637
667
|
return get("/api/functions");
|
|
638
668
|
},
|
|
639
|
-
async create(name, code) {
|
|
640
|
-
return post("/api/functions", { name, code });
|
|
669
|
+
async create(name, code, options) {
|
|
670
|
+
return post("/api/functions", { name, code, ...options });
|
|
641
671
|
},
|
|
642
672
|
async delete(id) {
|
|
643
673
|
return del(`/api/functions/${id}`);
|
|
644
674
|
},
|
|
645
|
-
async update(id, code) {
|
|
646
|
-
return put(`/api/functions/${id}`, { code });
|
|
675
|
+
async update(id, code, options) {
|
|
676
|
+
return put(`/api/functions/${id}`, { code, ...options });
|
|
677
|
+
},
|
|
678
|
+
async executeCode(code, options) {
|
|
679
|
+
return post("/api/functions/execute", { code, ...options });
|
|
647
680
|
},
|
|
648
681
|
async listHooks() {
|
|
649
682
|
return get("/api/hooks");
|
|
@@ -779,11 +812,15 @@ function createSearchModule(client) {
|
|
|
779
812
|
|
|
780
813
|
// src/modules/graphql.ts
|
|
781
814
|
function createGraphQLModule(client) {
|
|
815
|
+
const get = (endpoint) => client.get(endpoint);
|
|
782
816
|
const post = (endpoint, body) => client.post(endpoint, body);
|
|
783
817
|
return {
|
|
784
818
|
async query(query, variables) {
|
|
785
819
|
return post("/api/graphql", { query, variables });
|
|
786
820
|
},
|
|
821
|
+
async getSchema() {
|
|
822
|
+
return get("/api/graphql/schema");
|
|
823
|
+
},
|
|
787
824
|
getPlaygroundUrl() {
|
|
788
825
|
return `${client.url}/api/graphql/playground`;
|
|
789
826
|
}
|
|
@@ -1147,6 +1184,42 @@ function createCorsOriginsModule(client) {
|
|
|
1147
1184
|
};
|
|
1148
1185
|
}
|
|
1149
1186
|
|
|
1187
|
+
// src/modules/policies.ts
|
|
1188
|
+
function createPoliciesModule(client) {
|
|
1189
|
+
const get = (endpoint) => client.get(endpoint);
|
|
1190
|
+
const post = (endpoint, body) => client.post(endpoint, body);
|
|
1191
|
+
const del = (endpoint) => client.delete(endpoint);
|
|
1192
|
+
return {
|
|
1193
|
+
async create(input) {
|
|
1194
|
+
return post("/api/policies", input);
|
|
1195
|
+
},
|
|
1196
|
+
async list() {
|
|
1197
|
+
return get("/api/policies");
|
|
1198
|
+
},
|
|
1199
|
+
async delete(id) {
|
|
1200
|
+
return del(`/api/policies/${id}`);
|
|
1201
|
+
}
|
|
1202
|
+
};
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
// src/modules/ip-whitelist.ts
|
|
1206
|
+
function createIPWhitelistModule(client) {
|
|
1207
|
+
const get = (endpoint) => client.get(endpoint);
|
|
1208
|
+
const post = (endpoint, body) => client.post(endpoint, body);
|
|
1209
|
+
const del = (endpoint) => client.delete(endpoint);
|
|
1210
|
+
return {
|
|
1211
|
+
async list() {
|
|
1212
|
+
return get("/api/ip-whitelist");
|
|
1213
|
+
},
|
|
1214
|
+
async create(ipAddress, description) {
|
|
1215
|
+
return post("/api/ip-whitelist", { ip_address: ipAddress, description: description || "" });
|
|
1216
|
+
},
|
|
1217
|
+
async delete(id) {
|
|
1218
|
+
return del(`/api/ip-whitelist/${id}`);
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1150
1223
|
// src/client.ts
|
|
1151
1224
|
var BaasClient = class extends HttpClient {
|
|
1152
1225
|
// Feature modules
|
|
@@ -1171,6 +1244,8 @@ var BaasClient = class extends HttpClient {
|
|
|
1171
1244
|
apiKeys;
|
|
1172
1245
|
environments;
|
|
1173
1246
|
corsOrigins;
|
|
1247
|
+
policies;
|
|
1248
|
+
ipWhitelist;
|
|
1174
1249
|
constructor(url, apiKey) {
|
|
1175
1250
|
super(url, apiKey);
|
|
1176
1251
|
this.auth = createAuthModule(this);
|
|
@@ -1194,6 +1269,8 @@ var BaasClient = class extends HttpClient {
|
|
|
1194
1269
|
this.apiKeys = createApiKeysModule(this);
|
|
1195
1270
|
this.environments = createEnvironmentsModule(this);
|
|
1196
1271
|
this.corsOrigins = createCorsOriginsModule(this);
|
|
1272
|
+
this.policies = createPoliciesModule(this);
|
|
1273
|
+
this.ipWhitelist = createIPWhitelistModule(this);
|
|
1197
1274
|
}
|
|
1198
1275
|
/**
|
|
1199
1276
|
* Create a query builder for fluent data queries
|
|
@@ -1595,6 +1672,26 @@ var BaasClient = class extends HttpClient {
|
|
|
1595
1672
|
async deleteCorsOrigin(id) {
|
|
1596
1673
|
return this.corsOrigins.delete(id);
|
|
1597
1674
|
}
|
|
1675
|
+
// Policies shortcuts
|
|
1676
|
+
async listPolicies() {
|
|
1677
|
+
return this.policies.list();
|
|
1678
|
+
}
|
|
1679
|
+
async createPolicy(input) {
|
|
1680
|
+
return this.policies.create(input);
|
|
1681
|
+
}
|
|
1682
|
+
async deletePolicy(id) {
|
|
1683
|
+
return this.policies.delete(id);
|
|
1684
|
+
}
|
|
1685
|
+
// IP Whitelist shortcuts
|
|
1686
|
+
async listIPWhitelist() {
|
|
1687
|
+
return this.ipWhitelist.list();
|
|
1688
|
+
}
|
|
1689
|
+
async addIPWhitelistEntry(ipAddress, description) {
|
|
1690
|
+
return this.ipWhitelist.create(ipAddress, description);
|
|
1691
|
+
}
|
|
1692
|
+
async deleteIPWhitelistEntry(id) {
|
|
1693
|
+
return this.ipWhitelist.delete(id);
|
|
1694
|
+
}
|
|
1598
1695
|
};
|
|
1599
1696
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1600
1697
|
0 && (module.exports = {
|
package/dist/index.d.cts
CHANGED
|
@@ -50,7 +50,18 @@ declare class HttpClient {
|
|
|
50
50
|
apiKey: string;
|
|
51
51
|
token: string | null;
|
|
52
52
|
private environment;
|
|
53
|
+
private _onForceLogout;
|
|
53
54
|
constructor(url?: string, apiKey?: string);
|
|
55
|
+
/**
|
|
56
|
+
* Set the auth token manually (e.g. restoring from SecureStore in React Native).
|
|
57
|
+
* Persists to both the in-memory property and localStorage so getDynamicToken() works.
|
|
58
|
+
*/
|
|
59
|
+
setToken(token: string | null): void;
|
|
60
|
+
/**
|
|
61
|
+
* Register a callback invoked on forced logout (401).
|
|
62
|
+
* Use this in React Native instead of the default window.location redirect.
|
|
63
|
+
*/
|
|
64
|
+
onForceLogout(callback: () => void): void;
|
|
54
65
|
protected cleanValue(val: string | null): string | null;
|
|
55
66
|
/**
|
|
56
67
|
* Public header generator for adapters
|
|
@@ -223,6 +234,10 @@ interface DatabaseModule {
|
|
|
223
234
|
offset?: number;
|
|
224
235
|
}): Promise<any>;
|
|
225
236
|
getSchema(name: string): Promise<any>;
|
|
237
|
+
saveSchemas(data: {
|
|
238
|
+
table_name: string;
|
|
239
|
+
definition: any;
|
|
240
|
+
}): Promise<any>;
|
|
226
241
|
createTable(tableName: string, definition: Record<string, string | {
|
|
227
242
|
type: string;
|
|
228
243
|
nullable?: boolean;
|
|
@@ -355,10 +370,22 @@ interface MigrationsModule {
|
|
|
355
370
|
|
|
356
371
|
interface FunctionsModule {
|
|
357
372
|
invoke(id: string, data?: any): Promise<any>;
|
|
373
|
+
get(id: string): Promise<any>;
|
|
358
374
|
list(): Promise<any>;
|
|
359
|
-
create(name: string, code: string
|
|
375
|
+
create(name: string, code: string, options?: {
|
|
376
|
+
runtime?: 'wazero' | 'deno';
|
|
377
|
+
timeout_ms?: number;
|
|
378
|
+
}): Promise<any>;
|
|
360
379
|
delete(id: string): Promise<any>;
|
|
361
|
-
update(id: string, code: string
|
|
380
|
+
update(id: string, code: string, options?: {
|
|
381
|
+
runtime?: 'wazero' | 'deno';
|
|
382
|
+
timeout_ms?: number;
|
|
383
|
+
}): Promise<any>;
|
|
384
|
+
executeCode(code: string, options?: {
|
|
385
|
+
data?: any;
|
|
386
|
+
runtime?: 'wazero' | 'deno';
|
|
387
|
+
timeout_ms?: number;
|
|
388
|
+
}): Promise<any>;
|
|
362
389
|
listHooks(): Promise<any>;
|
|
363
390
|
createHook(data: {
|
|
364
391
|
event_type: string;
|
|
@@ -482,6 +509,7 @@ interface SearchModule {
|
|
|
482
509
|
|
|
483
510
|
interface GraphQLModule {
|
|
484
511
|
query(query: string, variables?: Record<string, any>): Promise<any>;
|
|
512
|
+
getSchema(): Promise<any>;
|
|
485
513
|
getPlaygroundUrl(): string;
|
|
486
514
|
}
|
|
487
515
|
|
|
@@ -643,6 +671,46 @@ interface CorsOriginsModule {
|
|
|
643
671
|
delete(id: string): Promise<any>;
|
|
644
672
|
}
|
|
645
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Policies Module - Row-Level Security policy management
|
|
676
|
+
*/
|
|
677
|
+
|
|
678
|
+
interface Policy {
|
|
679
|
+
id: string;
|
|
680
|
+
table_name: string;
|
|
681
|
+
action: 'select' | 'insert' | 'update' | 'delete';
|
|
682
|
+
role: string;
|
|
683
|
+
condition: string;
|
|
684
|
+
created_at?: string;
|
|
685
|
+
}
|
|
686
|
+
interface CreatePolicyInput {
|
|
687
|
+
table_name: string;
|
|
688
|
+
action: 'select' | 'insert' | 'update' | 'delete';
|
|
689
|
+
role: string;
|
|
690
|
+
condition: string;
|
|
691
|
+
}
|
|
692
|
+
interface PoliciesModule {
|
|
693
|
+
create(input: CreatePolicyInput): Promise<Policy>;
|
|
694
|
+
list(): Promise<Policy[]>;
|
|
695
|
+
delete(id: string): Promise<any>;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* IP Whitelist Module - IP-based access control
|
|
700
|
+
*/
|
|
701
|
+
|
|
702
|
+
interface IPWhitelistEntry {
|
|
703
|
+
id: string;
|
|
704
|
+
ip_address: string;
|
|
705
|
+
description: string;
|
|
706
|
+
created_at?: string;
|
|
707
|
+
}
|
|
708
|
+
interface IPWhitelistModule {
|
|
709
|
+
list(): Promise<IPWhitelistEntry[]>;
|
|
710
|
+
create(ipAddress: string, description?: string): Promise<IPWhitelistEntry>;
|
|
711
|
+
delete(id: string): Promise<any>;
|
|
712
|
+
}
|
|
713
|
+
|
|
646
714
|
/**
|
|
647
715
|
* Main BaaS Client - Composes all feature modules
|
|
648
716
|
*
|
|
@@ -682,6 +750,8 @@ declare class BaasClient extends HttpClient {
|
|
|
682
750
|
readonly apiKeys: ApiKeysModule;
|
|
683
751
|
readonly environments: EnvironmentsModule;
|
|
684
752
|
readonly corsOrigins: CorsOriginsModule;
|
|
753
|
+
readonly policies: PoliciesModule;
|
|
754
|
+
readonly ipWhitelist: IPWhitelistModule;
|
|
685
755
|
constructor(url?: string, apiKey?: string);
|
|
686
756
|
/**
|
|
687
757
|
* Create a query builder for fluent data queries
|
|
@@ -810,6 +880,12 @@ declare class BaasClient extends HttpClient {
|
|
|
810
880
|
listCorsOrigins(): Promise<any>;
|
|
811
881
|
addCorsOrigin(origin: string, description?: string): Promise<any>;
|
|
812
882
|
deleteCorsOrigin(id: string): Promise<any>;
|
|
883
|
+
listPolicies(): Promise<Policy[]>;
|
|
884
|
+
createPolicy(input: any): Promise<Policy>;
|
|
885
|
+
deletePolicy(id: string): Promise<any>;
|
|
886
|
+
listIPWhitelist(): Promise<IPWhitelistEntry[]>;
|
|
887
|
+
addIPWhitelistEntry(ipAddress: string, description?: string): Promise<IPWhitelistEntry>;
|
|
888
|
+
deleteIPWhitelistEntry(id: string): Promise<any>;
|
|
813
889
|
}
|
|
814
890
|
|
|
815
|
-
export { type ApiKeysModule, type ApiResponse, type ApplicationLogsOptions, type AuditLogsOptions, type AuditModule, type AuthModule, BaasClient, type BackupsModule, type BranchesModule, type CorsOriginsModule, type DatabaseModule, type EmailConfig, type EmailModule, type EmailTemplate, type EnvVarsModule, type FunctionsModule, type GraphQLModule, HttpClient, type HttpMethod, type JobInput, type JobUpdateInput, type JobsModule, type LogDrainInput, type LogDrainUpdateInput, type LogDrainsModule, type MetricsModule, type MigrationsModule, type PaginationOptions, QueryBuilder, type QueryFilter, type RealtimeModule, type RequestLogsOptions, type RequestOptions, type SearchModule, type SearchOptions, type SendEmailInput, type StorageBucket, type StorageFile, type StorageFileWithUrl, type StorageModule, type Subscription, type TimeseriesOptions, type UsersModule, type WebhookInput, type WebhookUpdateInput, type WebhooksModule };
|
|
891
|
+
export { type ApiKeysModule, type ApiResponse, type ApplicationLogsOptions, type AuditLogsOptions, type AuditModule, type AuthModule, BaasClient, type BackupsModule, type BranchesModule, type CorsOriginsModule, type CreatePolicyInput, type DatabaseModule, type EmailConfig, type EmailModule, type EmailTemplate, type EnvVarsModule, type EnvironmentsModule, type FunctionsModule, type GraphQLModule, HttpClient, type HttpMethod, type IPWhitelistEntry, type IPWhitelistModule, type JobInput, type JobUpdateInput, type JobsModule, type LogDrainInput, type LogDrainUpdateInput, type LogDrainsModule, type MetricsModule, type MigrationsModule, type PaginationOptions, type PoliciesModule, type Policy, QueryBuilder, type QueryFilter, type RealtimeModule, type RequestLogsOptions, type RequestOptions, type SearchModule, type SearchOptions, type SendEmailInput, type StorageBucket, type StorageFile, type StorageFileWithUrl, type StorageModule, type Subscription, type TimeseriesOptions, type UsersModule, type WebhookInput, type WebhookUpdateInput, type WebhooksModule };
|
package/dist/index.d.ts
CHANGED
|
@@ -50,7 +50,18 @@ declare class HttpClient {
|
|
|
50
50
|
apiKey: string;
|
|
51
51
|
token: string | null;
|
|
52
52
|
private environment;
|
|
53
|
+
private _onForceLogout;
|
|
53
54
|
constructor(url?: string, apiKey?: string);
|
|
55
|
+
/**
|
|
56
|
+
* Set the auth token manually (e.g. restoring from SecureStore in React Native).
|
|
57
|
+
* Persists to both the in-memory property and localStorage so getDynamicToken() works.
|
|
58
|
+
*/
|
|
59
|
+
setToken(token: string | null): void;
|
|
60
|
+
/**
|
|
61
|
+
* Register a callback invoked on forced logout (401).
|
|
62
|
+
* Use this in React Native instead of the default window.location redirect.
|
|
63
|
+
*/
|
|
64
|
+
onForceLogout(callback: () => void): void;
|
|
54
65
|
protected cleanValue(val: string | null): string | null;
|
|
55
66
|
/**
|
|
56
67
|
* Public header generator for adapters
|
|
@@ -223,6 +234,10 @@ interface DatabaseModule {
|
|
|
223
234
|
offset?: number;
|
|
224
235
|
}): Promise<any>;
|
|
225
236
|
getSchema(name: string): Promise<any>;
|
|
237
|
+
saveSchemas(data: {
|
|
238
|
+
table_name: string;
|
|
239
|
+
definition: any;
|
|
240
|
+
}): Promise<any>;
|
|
226
241
|
createTable(tableName: string, definition: Record<string, string | {
|
|
227
242
|
type: string;
|
|
228
243
|
nullable?: boolean;
|
|
@@ -355,10 +370,22 @@ interface MigrationsModule {
|
|
|
355
370
|
|
|
356
371
|
interface FunctionsModule {
|
|
357
372
|
invoke(id: string, data?: any): Promise<any>;
|
|
373
|
+
get(id: string): Promise<any>;
|
|
358
374
|
list(): Promise<any>;
|
|
359
|
-
create(name: string, code: string
|
|
375
|
+
create(name: string, code: string, options?: {
|
|
376
|
+
runtime?: 'wazero' | 'deno';
|
|
377
|
+
timeout_ms?: number;
|
|
378
|
+
}): Promise<any>;
|
|
360
379
|
delete(id: string): Promise<any>;
|
|
361
|
-
update(id: string, code: string
|
|
380
|
+
update(id: string, code: string, options?: {
|
|
381
|
+
runtime?: 'wazero' | 'deno';
|
|
382
|
+
timeout_ms?: number;
|
|
383
|
+
}): Promise<any>;
|
|
384
|
+
executeCode(code: string, options?: {
|
|
385
|
+
data?: any;
|
|
386
|
+
runtime?: 'wazero' | 'deno';
|
|
387
|
+
timeout_ms?: number;
|
|
388
|
+
}): Promise<any>;
|
|
362
389
|
listHooks(): Promise<any>;
|
|
363
390
|
createHook(data: {
|
|
364
391
|
event_type: string;
|
|
@@ -482,6 +509,7 @@ interface SearchModule {
|
|
|
482
509
|
|
|
483
510
|
interface GraphQLModule {
|
|
484
511
|
query(query: string, variables?: Record<string, any>): Promise<any>;
|
|
512
|
+
getSchema(): Promise<any>;
|
|
485
513
|
getPlaygroundUrl(): string;
|
|
486
514
|
}
|
|
487
515
|
|
|
@@ -643,6 +671,46 @@ interface CorsOriginsModule {
|
|
|
643
671
|
delete(id: string): Promise<any>;
|
|
644
672
|
}
|
|
645
673
|
|
|
674
|
+
/**
|
|
675
|
+
* Policies Module - Row-Level Security policy management
|
|
676
|
+
*/
|
|
677
|
+
|
|
678
|
+
interface Policy {
|
|
679
|
+
id: string;
|
|
680
|
+
table_name: string;
|
|
681
|
+
action: 'select' | 'insert' | 'update' | 'delete';
|
|
682
|
+
role: string;
|
|
683
|
+
condition: string;
|
|
684
|
+
created_at?: string;
|
|
685
|
+
}
|
|
686
|
+
interface CreatePolicyInput {
|
|
687
|
+
table_name: string;
|
|
688
|
+
action: 'select' | 'insert' | 'update' | 'delete';
|
|
689
|
+
role: string;
|
|
690
|
+
condition: string;
|
|
691
|
+
}
|
|
692
|
+
interface PoliciesModule {
|
|
693
|
+
create(input: CreatePolicyInput): Promise<Policy>;
|
|
694
|
+
list(): Promise<Policy[]>;
|
|
695
|
+
delete(id: string): Promise<any>;
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* IP Whitelist Module - IP-based access control
|
|
700
|
+
*/
|
|
701
|
+
|
|
702
|
+
interface IPWhitelistEntry {
|
|
703
|
+
id: string;
|
|
704
|
+
ip_address: string;
|
|
705
|
+
description: string;
|
|
706
|
+
created_at?: string;
|
|
707
|
+
}
|
|
708
|
+
interface IPWhitelistModule {
|
|
709
|
+
list(): Promise<IPWhitelistEntry[]>;
|
|
710
|
+
create(ipAddress: string, description?: string): Promise<IPWhitelistEntry>;
|
|
711
|
+
delete(id: string): Promise<any>;
|
|
712
|
+
}
|
|
713
|
+
|
|
646
714
|
/**
|
|
647
715
|
* Main BaaS Client - Composes all feature modules
|
|
648
716
|
*
|
|
@@ -682,6 +750,8 @@ declare class BaasClient extends HttpClient {
|
|
|
682
750
|
readonly apiKeys: ApiKeysModule;
|
|
683
751
|
readonly environments: EnvironmentsModule;
|
|
684
752
|
readonly corsOrigins: CorsOriginsModule;
|
|
753
|
+
readonly policies: PoliciesModule;
|
|
754
|
+
readonly ipWhitelist: IPWhitelistModule;
|
|
685
755
|
constructor(url?: string, apiKey?: string);
|
|
686
756
|
/**
|
|
687
757
|
* Create a query builder for fluent data queries
|
|
@@ -810,6 +880,12 @@ declare class BaasClient extends HttpClient {
|
|
|
810
880
|
listCorsOrigins(): Promise<any>;
|
|
811
881
|
addCorsOrigin(origin: string, description?: string): Promise<any>;
|
|
812
882
|
deleteCorsOrigin(id: string): Promise<any>;
|
|
883
|
+
listPolicies(): Promise<Policy[]>;
|
|
884
|
+
createPolicy(input: any): Promise<Policy>;
|
|
885
|
+
deletePolicy(id: string): Promise<any>;
|
|
886
|
+
listIPWhitelist(): Promise<IPWhitelistEntry[]>;
|
|
887
|
+
addIPWhitelistEntry(ipAddress: string, description?: string): Promise<IPWhitelistEntry>;
|
|
888
|
+
deleteIPWhitelistEntry(id: string): Promise<any>;
|
|
813
889
|
}
|
|
814
890
|
|
|
815
|
-
export { type ApiKeysModule, type ApiResponse, type ApplicationLogsOptions, type AuditLogsOptions, type AuditModule, type AuthModule, BaasClient, type BackupsModule, type BranchesModule, type CorsOriginsModule, type DatabaseModule, type EmailConfig, type EmailModule, type EmailTemplate, type EnvVarsModule, type FunctionsModule, type GraphQLModule, HttpClient, type HttpMethod, type JobInput, type JobUpdateInput, type JobsModule, type LogDrainInput, type LogDrainUpdateInput, type LogDrainsModule, type MetricsModule, type MigrationsModule, type PaginationOptions, QueryBuilder, type QueryFilter, type RealtimeModule, type RequestLogsOptions, type RequestOptions, type SearchModule, type SearchOptions, type SendEmailInput, type StorageBucket, type StorageFile, type StorageFileWithUrl, type StorageModule, type Subscription, type TimeseriesOptions, type UsersModule, type WebhookInput, type WebhookUpdateInput, type WebhooksModule };
|
|
891
|
+
export { type ApiKeysModule, type ApiResponse, type ApplicationLogsOptions, type AuditLogsOptions, type AuditModule, type AuthModule, BaasClient, type BackupsModule, type BranchesModule, type CorsOriginsModule, type CreatePolicyInput, type DatabaseModule, type EmailConfig, type EmailModule, type EmailTemplate, type EnvVarsModule, type EnvironmentsModule, type FunctionsModule, type GraphQLModule, HttpClient, type HttpMethod, type IPWhitelistEntry, type IPWhitelistModule, type JobInput, type JobUpdateInput, type JobsModule, type LogDrainInput, type LogDrainUpdateInput, type LogDrainsModule, type MetricsModule, type MigrationsModule, type PaginationOptions, type PoliciesModule, type Policy, QueryBuilder, type QueryFilter, type RealtimeModule, type RequestLogsOptions, type RequestOptions, type SearchModule, type SearchOptions, type SendEmailInput, type StorageBucket, type StorageFile, type StorageFileWithUrl, type StorageModule, type Subscription, type TimeseriesOptions, type UsersModule, type WebhookInput, type WebhookUpdateInput, type WebhooksModule };
|
package/dist/index.js
CHANGED
|
@@ -4,12 +4,32 @@ var HttpClient = class {
|
|
|
4
4
|
apiKey = "";
|
|
5
5
|
token = null;
|
|
6
6
|
environment = "prod";
|
|
7
|
+
_onForceLogout = null;
|
|
7
8
|
constructor(url, apiKey) {
|
|
8
9
|
let baseUrl = url || (typeof window !== "undefined" ? window.location.origin : "http://localhost:8080");
|
|
9
10
|
this.url = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
|
|
10
11
|
if (apiKey) this.apiKey = apiKey;
|
|
11
12
|
this.token = this.cleanValue(localStorage.getItem("baas_token"));
|
|
12
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Set the auth token manually (e.g. restoring from SecureStore in React Native).
|
|
16
|
+
* Persists to both the in-memory property and localStorage so getDynamicToken() works.
|
|
17
|
+
*/
|
|
18
|
+
setToken(token) {
|
|
19
|
+
this.token = token;
|
|
20
|
+
if (token) {
|
|
21
|
+
localStorage.setItem("baas_token", token);
|
|
22
|
+
} else {
|
|
23
|
+
localStorage.removeItem("baas_token");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Register a callback invoked on forced logout (401).
|
|
28
|
+
* Use this in React Native instead of the default window.location redirect.
|
|
29
|
+
*/
|
|
30
|
+
onForceLogout(callback) {
|
|
31
|
+
this._onForceLogout = callback;
|
|
32
|
+
}
|
|
13
33
|
cleanValue(val) {
|
|
14
34
|
if (!val || val === "null" || val === "undefined") return null;
|
|
15
35
|
return val.trim();
|
|
@@ -92,9 +112,13 @@ var HttpClient = class {
|
|
|
92
112
|
}
|
|
93
113
|
forceLogout() {
|
|
94
114
|
this.logout();
|
|
95
|
-
if (
|
|
115
|
+
if (this._onForceLogout) {
|
|
116
|
+
this._onForceLogout();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (typeof window !== "undefined" && window.location && window.location.search !== void 0) {
|
|
96
120
|
if (!window.location.search.includes("expired")) {
|
|
97
|
-
window.location.href = "/
|
|
121
|
+
window.location.href = "/authentication/login?reason=expired";
|
|
98
122
|
}
|
|
99
123
|
}
|
|
100
124
|
}
|
|
@@ -378,6 +402,9 @@ function createDatabaseModule(client) {
|
|
|
378
402
|
async getSchema(name) {
|
|
379
403
|
return get(`/api/schemas/${name}`);
|
|
380
404
|
},
|
|
405
|
+
async saveSchemas(data) {
|
|
406
|
+
return post("/api/schemas", data);
|
|
407
|
+
},
|
|
381
408
|
// Tables
|
|
382
409
|
async createTable(tableName, definition) {
|
|
383
410
|
return post("/api/schemas/tables", { table_name: tableName, definition });
|
|
@@ -605,17 +632,23 @@ function createFunctionsModule(client) {
|
|
|
605
632
|
async invoke(id, data = {}) {
|
|
606
633
|
return post(`/api/functions/${id}/execute`, data);
|
|
607
634
|
},
|
|
635
|
+
async get(id) {
|
|
636
|
+
return get(`/api/functions/${id}`);
|
|
637
|
+
},
|
|
608
638
|
async list() {
|
|
609
639
|
return get("/api/functions");
|
|
610
640
|
},
|
|
611
|
-
async create(name, code) {
|
|
612
|
-
return post("/api/functions", { name, code });
|
|
641
|
+
async create(name, code, options) {
|
|
642
|
+
return post("/api/functions", { name, code, ...options });
|
|
613
643
|
},
|
|
614
644
|
async delete(id) {
|
|
615
645
|
return del(`/api/functions/${id}`);
|
|
616
646
|
},
|
|
617
|
-
async update(id, code) {
|
|
618
|
-
return put(`/api/functions/${id}`, { code });
|
|
647
|
+
async update(id, code, options) {
|
|
648
|
+
return put(`/api/functions/${id}`, { code, ...options });
|
|
649
|
+
},
|
|
650
|
+
async executeCode(code, options) {
|
|
651
|
+
return post("/api/functions/execute", { code, ...options });
|
|
619
652
|
},
|
|
620
653
|
async listHooks() {
|
|
621
654
|
return get("/api/hooks");
|
|
@@ -751,11 +784,15 @@ function createSearchModule(client) {
|
|
|
751
784
|
|
|
752
785
|
// src/modules/graphql.ts
|
|
753
786
|
function createGraphQLModule(client) {
|
|
787
|
+
const get = (endpoint) => client.get(endpoint);
|
|
754
788
|
const post = (endpoint, body) => client.post(endpoint, body);
|
|
755
789
|
return {
|
|
756
790
|
async query(query, variables) {
|
|
757
791
|
return post("/api/graphql", { query, variables });
|
|
758
792
|
},
|
|
793
|
+
async getSchema() {
|
|
794
|
+
return get("/api/graphql/schema");
|
|
795
|
+
},
|
|
759
796
|
getPlaygroundUrl() {
|
|
760
797
|
return `${client.url}/api/graphql/playground`;
|
|
761
798
|
}
|
|
@@ -1119,6 +1156,42 @@ function createCorsOriginsModule(client) {
|
|
|
1119
1156
|
};
|
|
1120
1157
|
}
|
|
1121
1158
|
|
|
1159
|
+
// src/modules/policies.ts
|
|
1160
|
+
function createPoliciesModule(client) {
|
|
1161
|
+
const get = (endpoint) => client.get(endpoint);
|
|
1162
|
+
const post = (endpoint, body) => client.post(endpoint, body);
|
|
1163
|
+
const del = (endpoint) => client.delete(endpoint);
|
|
1164
|
+
return {
|
|
1165
|
+
async create(input) {
|
|
1166
|
+
return post("/api/policies", input);
|
|
1167
|
+
},
|
|
1168
|
+
async list() {
|
|
1169
|
+
return get("/api/policies");
|
|
1170
|
+
},
|
|
1171
|
+
async delete(id) {
|
|
1172
|
+
return del(`/api/policies/${id}`);
|
|
1173
|
+
}
|
|
1174
|
+
};
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// src/modules/ip-whitelist.ts
|
|
1178
|
+
function createIPWhitelistModule(client) {
|
|
1179
|
+
const get = (endpoint) => client.get(endpoint);
|
|
1180
|
+
const post = (endpoint, body) => client.post(endpoint, body);
|
|
1181
|
+
const del = (endpoint) => client.delete(endpoint);
|
|
1182
|
+
return {
|
|
1183
|
+
async list() {
|
|
1184
|
+
return get("/api/ip-whitelist");
|
|
1185
|
+
},
|
|
1186
|
+
async create(ipAddress, description) {
|
|
1187
|
+
return post("/api/ip-whitelist", { ip_address: ipAddress, description: description || "" });
|
|
1188
|
+
},
|
|
1189
|
+
async delete(id) {
|
|
1190
|
+
return del(`/api/ip-whitelist/${id}`);
|
|
1191
|
+
}
|
|
1192
|
+
};
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1122
1195
|
// src/client.ts
|
|
1123
1196
|
var BaasClient = class extends HttpClient {
|
|
1124
1197
|
// Feature modules
|
|
@@ -1143,6 +1216,8 @@ var BaasClient = class extends HttpClient {
|
|
|
1143
1216
|
apiKeys;
|
|
1144
1217
|
environments;
|
|
1145
1218
|
corsOrigins;
|
|
1219
|
+
policies;
|
|
1220
|
+
ipWhitelist;
|
|
1146
1221
|
constructor(url, apiKey) {
|
|
1147
1222
|
super(url, apiKey);
|
|
1148
1223
|
this.auth = createAuthModule(this);
|
|
@@ -1166,6 +1241,8 @@ var BaasClient = class extends HttpClient {
|
|
|
1166
1241
|
this.apiKeys = createApiKeysModule(this);
|
|
1167
1242
|
this.environments = createEnvironmentsModule(this);
|
|
1168
1243
|
this.corsOrigins = createCorsOriginsModule(this);
|
|
1244
|
+
this.policies = createPoliciesModule(this);
|
|
1245
|
+
this.ipWhitelist = createIPWhitelistModule(this);
|
|
1169
1246
|
}
|
|
1170
1247
|
/**
|
|
1171
1248
|
* Create a query builder for fluent data queries
|
|
@@ -1567,6 +1644,26 @@ var BaasClient = class extends HttpClient {
|
|
|
1567
1644
|
async deleteCorsOrigin(id) {
|
|
1568
1645
|
return this.corsOrigins.delete(id);
|
|
1569
1646
|
}
|
|
1647
|
+
// Policies shortcuts
|
|
1648
|
+
async listPolicies() {
|
|
1649
|
+
return this.policies.list();
|
|
1650
|
+
}
|
|
1651
|
+
async createPolicy(input) {
|
|
1652
|
+
return this.policies.create(input);
|
|
1653
|
+
}
|
|
1654
|
+
async deletePolicy(id) {
|
|
1655
|
+
return this.policies.delete(id);
|
|
1656
|
+
}
|
|
1657
|
+
// IP Whitelist shortcuts
|
|
1658
|
+
async listIPWhitelist() {
|
|
1659
|
+
return this.ipWhitelist.list();
|
|
1660
|
+
}
|
|
1661
|
+
async addIPWhitelistEntry(ipAddress, description) {
|
|
1662
|
+
return this.ipWhitelist.create(ipAddress, description);
|
|
1663
|
+
}
|
|
1664
|
+
async deleteIPWhitelistEntry(id) {
|
|
1665
|
+
return this.ipWhitelist.delete(id);
|
|
1666
|
+
}
|
|
1570
1667
|
};
|
|
1571
1668
|
export {
|
|
1572
1669
|
BaasClient,
|