@boltic/sdk 0.1.1 → 0.1.3
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 +192 -154
- package/dist/databases/index.d.ts +214 -93
- package/dist/databases/index.js +1 -1
- package/dist/databases/index.js.map +1 -1
- package/dist/databases/index.mjs +1 -1
- package/dist/databases/index.mjs.map +1 -1
- package/dist/databases/test-client-BEAX5vfC.mjs +2 -0
- package/dist/databases/test-client-BEAX5vfC.mjs.map +1 -0
- package/dist/databases/test-client-BgkvBtst.js +2 -0
- package/dist/databases/test-client-BgkvBtst.js.map +1 -0
- package/dist/databases/testing.d.ts +204 -94
- package/dist/databases/testing.js +1 -1
- package/dist/databases/testing.mjs +1 -1
- package/dist/sdk.js +915 -711
- package/dist/sdk.js.map +1 -1
- package/dist/sdk.mjs +916 -712
- package/dist/sdk.mjs.map +1 -1
- package/dist/types/index.d.ts +464 -83
- package/package.json +2 -1
- package/dist/databases/test-client-Bo_BCApL.js +0 -2
- package/dist/databases/test-client-Bo_BCApL.js.map +0 -1
- package/dist/databases/test-client-C9T839dW.mjs +0 -2
- package/dist/databases/test-client-C9T839dW.mjs.map +0 -1
package/dist/sdk.mjs
CHANGED
|
@@ -109,6 +109,73 @@ let AuthManager$1 = class AuthManager {
|
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
};
|
|
112
|
+
const REGION_CONFIGS = {
|
|
113
|
+
"asia-south1": {
|
|
114
|
+
local: {
|
|
115
|
+
baseURL: "http://localhost:8000",
|
|
116
|
+
timeout: 3e4,
|
|
117
|
+
debug: true
|
|
118
|
+
},
|
|
119
|
+
sit: {
|
|
120
|
+
baseURL: "https://asia-south1.api.fcz0.de/service/sdk/boltic-tables",
|
|
121
|
+
timeout: 15e3
|
|
122
|
+
},
|
|
123
|
+
uat: {
|
|
124
|
+
baseURL: "https://asia-south1.api.uat.fcz0.de/service/sdk/boltic-tables",
|
|
125
|
+
timeout: 15e3
|
|
126
|
+
},
|
|
127
|
+
prod: {
|
|
128
|
+
baseURL: "https://asia-south1.api.boltic.io/service/sdk/boltic-tables",
|
|
129
|
+
timeout: 1e4
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
"us-central1": {
|
|
133
|
+
local: {
|
|
134
|
+
baseURL: "http://localhost:8000",
|
|
135
|
+
timeout: 3e4,
|
|
136
|
+
debug: true
|
|
137
|
+
},
|
|
138
|
+
sit: {
|
|
139
|
+
baseURL: "https://us-central1.api.fcz0.de/service/sdk/boltic-tables",
|
|
140
|
+
timeout: 15e3
|
|
141
|
+
},
|
|
142
|
+
uat: {
|
|
143
|
+
baseURL: "https://us-central1.api.uat.fcz0.de/service/sdk/boltic-tables",
|
|
144
|
+
timeout: 15e3
|
|
145
|
+
},
|
|
146
|
+
prod: {
|
|
147
|
+
baseURL: "https://us-central1.api.boltic.io/service/sdk/boltic-tables",
|
|
148
|
+
timeout: 1e4
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
const REGION_BASE_HOSTS = {
|
|
153
|
+
"asia-south1": {
|
|
154
|
+
local: { host: "http://localhost:8000", timeout: 3e4, debug: true },
|
|
155
|
+
sit: { host: "https://asia-south1.api.fcz0.de", timeout: 15e3 },
|
|
156
|
+
uat: { host: "https://asia-south1.api.uat.fcz0.de", timeout: 15e3 },
|
|
157
|
+
prod: { host: "https://asia-south1.api.boltic.io", timeout: 1e4 }
|
|
158
|
+
},
|
|
159
|
+
"us-central1": {
|
|
160
|
+
local: { host: "http://localhost:8000", timeout: 3e4, debug: true },
|
|
161
|
+
sit: { host: "https://us-central1.api.fcz0.de", timeout: 15e3 },
|
|
162
|
+
uat: { host: "https://us-central1.api.uat.fcz0.de", timeout: 15e3 },
|
|
163
|
+
prod: { host: "https://us-central1.api.boltic.io", timeout: 1e4 }
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
function resolveServiceURL(region, environment, servicePath) {
|
|
167
|
+
const regionConfig = REGION_BASE_HOSTS[region];
|
|
168
|
+
if (!regionConfig) {
|
|
169
|
+
throw new Error(`Unsupported region: ${region}`);
|
|
170
|
+
}
|
|
171
|
+
const envConfig = regionConfig[environment];
|
|
172
|
+
if (!envConfig) {
|
|
173
|
+
throw new Error(
|
|
174
|
+
`Unsupported environment: ${environment} for region: ${region}`
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
return `${envConfig.host}${servicePath}`;
|
|
178
|
+
}
|
|
112
179
|
function isErrorResponse(response) {
|
|
113
180
|
return "error" in response && response.error !== void 0;
|
|
114
181
|
}
|
|
@@ -167,77 +234,6 @@ Context: ${JSON.stringify(context, null, 2)}`;
|
|
|
167
234
|
}
|
|
168
235
|
return String(error);
|
|
169
236
|
}
|
|
170
|
-
class AuthManager2 {
|
|
171
|
-
constructor(config) {
|
|
172
|
-
this.tokenInfo = null;
|
|
173
|
-
this.config = {
|
|
174
|
-
maxRetries: 3,
|
|
175
|
-
...config
|
|
176
|
-
};
|
|
177
|
-
this.validateApiKey(config.apiKey);
|
|
178
|
-
}
|
|
179
|
-
validateApiKey(apiKey) {
|
|
180
|
-
if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) {
|
|
181
|
-
throw createErrorWithContext(
|
|
182
|
-
"API key is required and must be a non-empty string",
|
|
183
|
-
{
|
|
184
|
-
name: "AuthenticationError",
|
|
185
|
-
code: "INVALID_API_KEY"
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
if (apiKey.length < 10) {
|
|
190
|
-
throw createErrorWithContext(
|
|
191
|
-
"API key appears to be invalid (too short)",
|
|
192
|
-
{
|
|
193
|
-
name: "AuthenticationError",
|
|
194
|
-
code: "INVALID_API_KEY_FORMAT"
|
|
195
|
-
}
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
getAuthHeaders() {
|
|
200
|
-
return {
|
|
201
|
-
"x-boltic-token": this.config.apiKey
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
updateApiKey(newApiKey) {
|
|
205
|
-
this.validateApiKey(newApiKey);
|
|
206
|
-
this.config.apiKey = newApiKey;
|
|
207
|
-
this.tokenInfo = null;
|
|
208
|
-
}
|
|
209
|
-
isAuthenticated() {
|
|
210
|
-
return !!this.config.apiKey;
|
|
211
|
-
}
|
|
212
|
-
async validateApiKeyAsync() {
|
|
213
|
-
try {
|
|
214
|
-
this.validateApiKey(this.config.apiKey);
|
|
215
|
-
return true;
|
|
216
|
-
} catch {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
getTokenInfo() {
|
|
221
|
-
return this.tokenInfo ? { ...this.tokenInfo } : null;
|
|
222
|
-
}
|
|
223
|
-
getMaxRetries() {
|
|
224
|
-
return this.config.maxRetries || 3;
|
|
225
|
-
}
|
|
226
|
-
// Security methods to prevent API key exposure
|
|
227
|
-
toString() {
|
|
228
|
-
return `AuthManager { authenticated: ${this.isAuthenticated()}, maxRetries: ${this.getMaxRetries()} }`;
|
|
229
|
-
}
|
|
230
|
-
toJSON() {
|
|
231
|
-
return {
|
|
232
|
-
authenticated: this.isAuthenticated(),
|
|
233
|
-
maxRetries: this.getMaxRetries()
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
// Custom inspect method for Node.js console logging
|
|
237
|
-
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
238
|
-
return this.toString();
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
237
|
class AxiosAdapter {
|
|
242
238
|
constructor() {
|
|
243
239
|
try {
|
|
@@ -260,7 +256,6 @@ class AxiosAdapter {
|
|
|
260
256
|
timeout: config.timeout,
|
|
261
257
|
signal: config.signal,
|
|
262
258
|
validateStatus: () => true
|
|
263
|
-
// Don't throw on non-2xx status codes
|
|
264
259
|
};
|
|
265
260
|
const response = await this.axios(axiosConfig);
|
|
266
261
|
if (response.status < 200 || response.status >= 300) {
|
|
@@ -480,6 +475,156 @@ function createHttpAdapter() {
|
|
|
480
475
|
);
|
|
481
476
|
}
|
|
482
477
|
}
|
|
478
|
+
class AuthManager2 {
|
|
479
|
+
constructor(config) {
|
|
480
|
+
this.tokenInfo = null;
|
|
481
|
+
this.config = {
|
|
482
|
+
maxRetries: 3,
|
|
483
|
+
...config
|
|
484
|
+
};
|
|
485
|
+
this.validateApiKey(config.apiKey);
|
|
486
|
+
}
|
|
487
|
+
validateApiKey(apiKey) {
|
|
488
|
+
if (!apiKey || typeof apiKey !== "string" || apiKey.trim().length === 0) {
|
|
489
|
+
throw createErrorWithContext(
|
|
490
|
+
"API key is required and must be a non-empty string",
|
|
491
|
+
{
|
|
492
|
+
name: "AuthenticationError",
|
|
493
|
+
code: "INVALID_API_KEY"
|
|
494
|
+
}
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
if (apiKey.length < 10) {
|
|
498
|
+
throw createErrorWithContext(
|
|
499
|
+
"API key appears to be invalid (too short)",
|
|
500
|
+
{
|
|
501
|
+
name: "AuthenticationError",
|
|
502
|
+
code: "INVALID_API_KEY_FORMAT"
|
|
503
|
+
}
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
getAuthHeaders() {
|
|
508
|
+
return {
|
|
509
|
+
"x-boltic-token": this.config.apiKey
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
updateApiKey(newApiKey) {
|
|
513
|
+
this.validateApiKey(newApiKey);
|
|
514
|
+
this.config.apiKey = newApiKey;
|
|
515
|
+
this.tokenInfo = null;
|
|
516
|
+
}
|
|
517
|
+
isAuthenticated() {
|
|
518
|
+
return !!this.config.apiKey;
|
|
519
|
+
}
|
|
520
|
+
async validateApiKeyAsync() {
|
|
521
|
+
try {
|
|
522
|
+
this.validateApiKey(this.config.apiKey);
|
|
523
|
+
return true;
|
|
524
|
+
} catch {
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
getTokenInfo() {
|
|
529
|
+
return this.tokenInfo ? { ...this.tokenInfo } : null;
|
|
530
|
+
}
|
|
531
|
+
getMaxRetries() {
|
|
532
|
+
return this.config.maxRetries || 3;
|
|
533
|
+
}
|
|
534
|
+
toString() {
|
|
535
|
+
return `AuthManager { authenticated: ${this.isAuthenticated()}, maxRetries: ${this.getMaxRetries()} }`;
|
|
536
|
+
}
|
|
537
|
+
toJSON() {
|
|
538
|
+
return {
|
|
539
|
+
authenticated: this.isAuthenticated(),
|
|
540
|
+
maxRetries: this.getMaxRetries()
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
544
|
+
return this.toString();
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
const SERVICE_PATHS = {
|
|
548
|
+
DATABASES: "/service/sdk/boltic-tables/v1",
|
|
549
|
+
WORKFLOW_TEMPORAL: "/service/panel/temporal/v1.0",
|
|
550
|
+
INTEGRATION: "/service/panel/integration/v1"
|
|
551
|
+
};
|
|
552
|
+
class BaseApiClient {
|
|
553
|
+
constructor(apiKey, config = {}, servicePath = SERVICE_PATHS.DATABASES) {
|
|
554
|
+
this.config = { apiKey, ...config };
|
|
555
|
+
this.httpAdapter = createHttpAdapter();
|
|
556
|
+
this.environment = config.environment || "prod";
|
|
557
|
+
this.region = config.region || "asia-south1";
|
|
558
|
+
this.baseURL = resolveServiceURL(
|
|
559
|
+
this.region,
|
|
560
|
+
this.environment,
|
|
561
|
+
servicePath
|
|
562
|
+
);
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Resolve a secondary service URL using the same region/environment
|
|
566
|
+
* but a different service path.
|
|
567
|
+
*/
|
|
568
|
+
resolveAdditionalServiceURL(servicePath) {
|
|
569
|
+
return resolveServiceURL(this.region, this.environment, servicePath);
|
|
570
|
+
}
|
|
571
|
+
buildHeaders() {
|
|
572
|
+
return {
|
|
573
|
+
"Content-Type": "application/json",
|
|
574
|
+
Accept: "application/json",
|
|
575
|
+
"x-boltic-token": this.config.apiKey,
|
|
576
|
+
...this.config.headers
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
formatErrorResponse(error, prefix = "API") {
|
|
580
|
+
if (this.config.debug) {
|
|
581
|
+
console.error(`[${this.constructor.name}] ${prefix} Error:`, error);
|
|
582
|
+
}
|
|
583
|
+
if (error && typeof error === "object" && "response" in error) {
|
|
584
|
+
const apiError = error;
|
|
585
|
+
if (apiError.response?.data?.error) {
|
|
586
|
+
return apiError.response.data;
|
|
587
|
+
}
|
|
588
|
+
return {
|
|
589
|
+
error: {
|
|
590
|
+
code: `${prefix}_ERROR`,
|
|
591
|
+
message: error instanceof Error ? error.message : `Unknown ${prefix} error`,
|
|
592
|
+
meta: [`Status: ${apiError.response?.status || "unknown"}`]
|
|
593
|
+
}
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
if (error instanceof Error) {
|
|
597
|
+
return {
|
|
598
|
+
error: {
|
|
599
|
+
code: `${prefix}_CLIENT_ERROR`,
|
|
600
|
+
message: error.message,
|
|
601
|
+
meta: []
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
return {
|
|
606
|
+
error: {
|
|
607
|
+
code: `${prefix}_UNKNOWN_ERROR`,
|
|
608
|
+
message: `An unexpected ${prefix} error occurred`,
|
|
609
|
+
meta: []
|
|
610
|
+
}
|
|
611
|
+
};
|
|
612
|
+
}
|
|
613
|
+
toString() {
|
|
614
|
+
return `${this.constructor.name} { environment: "${this.config.environment || "prod"}", debug: ${this.config.debug || false} }`;
|
|
615
|
+
}
|
|
616
|
+
toJSON() {
|
|
617
|
+
const safeConfig = { ...this.config };
|
|
618
|
+
delete safeConfig.apiKey;
|
|
619
|
+
return {
|
|
620
|
+
client: this.constructor.name,
|
|
621
|
+
config: safeConfig
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
625
|
+
return this.toString();
|
|
626
|
+
}
|
|
627
|
+
}
|
|
483
628
|
class InterceptorManagerImpl {
|
|
484
629
|
constructor() {
|
|
485
630
|
this.requestInterceptors = /* @__PURE__ */ new Map();
|
|
@@ -635,75 +780,117 @@ class BaseClient {
|
|
|
635
780
|
const delay = this.config.retryDelay * Math.pow(2, attempt);
|
|
636
781
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
637
782
|
}
|
|
638
|
-
}
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
throw await this.interceptors.executeErrorInterceptors(lastError);
|
|
786
|
+
}
|
|
787
|
+
get(url, config) {
|
|
788
|
+
return this.request({ ...config, method: "GET", url });
|
|
789
|
+
}
|
|
790
|
+
post(url, data, config) {
|
|
791
|
+
return this.request({ ...config, method: "POST", url, data });
|
|
792
|
+
}
|
|
793
|
+
put(url, data, config) {
|
|
794
|
+
return this.request({ ...config, method: "PUT", url, data });
|
|
795
|
+
}
|
|
796
|
+
patch(url, data, config) {
|
|
797
|
+
return this.request({ ...config, method: "PATCH", url, data });
|
|
798
|
+
}
|
|
799
|
+
delete(url, config) {
|
|
800
|
+
return this.request({ ...config, method: "DELETE", url });
|
|
801
|
+
}
|
|
802
|
+
getInterceptors() {
|
|
803
|
+
return this.interceptors;
|
|
804
|
+
}
|
|
805
|
+
updateConfig(updates) {
|
|
806
|
+
this.config = { ...this.config, ...updates };
|
|
807
|
+
}
|
|
808
|
+
getConfig() {
|
|
809
|
+
return { ...this.config };
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
class BaseResource {
|
|
813
|
+
constructor(client, basePath) {
|
|
814
|
+
this.client = client;
|
|
815
|
+
this.basePath = basePath;
|
|
816
|
+
}
|
|
817
|
+
getBasePath() {
|
|
818
|
+
return this.basePath;
|
|
819
|
+
}
|
|
820
|
+
async makeRequest(method, path, data, options) {
|
|
821
|
+
const url = `${this.basePath}${path}`;
|
|
822
|
+
try {
|
|
823
|
+
let response;
|
|
824
|
+
switch (method) {
|
|
825
|
+
case "GET":
|
|
826
|
+
response = await this.client.get(url, {
|
|
827
|
+
params: options?.params
|
|
828
|
+
});
|
|
829
|
+
break;
|
|
830
|
+
case "POST":
|
|
831
|
+
response = await this.client.post(url, data, {
|
|
832
|
+
params: options?.params
|
|
833
|
+
});
|
|
834
|
+
break;
|
|
835
|
+
case "PUT":
|
|
836
|
+
response = await this.client.put(url, data, {
|
|
837
|
+
params: options?.params
|
|
838
|
+
});
|
|
839
|
+
break;
|
|
840
|
+
case "PATCH":
|
|
841
|
+
response = await this.client.patch(url, data, {
|
|
842
|
+
params: options?.params
|
|
843
|
+
});
|
|
844
|
+
break;
|
|
845
|
+
case "DELETE":
|
|
846
|
+
response = await this.client.delete(url, {
|
|
847
|
+
params: options?.params
|
|
848
|
+
});
|
|
849
|
+
break;
|
|
850
|
+
}
|
|
851
|
+
return response.data;
|
|
852
|
+
} catch (error) {
|
|
853
|
+
return {
|
|
854
|
+
error: {
|
|
855
|
+
code: "CLIENT_ERROR",
|
|
856
|
+
message: formatError(error),
|
|
857
|
+
meta: ["Request failed"]
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
buildQueryParams(options = {}) {
|
|
863
|
+
const params = {};
|
|
864
|
+
if (options.fields?.length) {
|
|
865
|
+
params.fields = options.fields.join(",");
|
|
866
|
+
}
|
|
867
|
+
if (options.sort?.length) {
|
|
868
|
+
params.sort = options.sort.map((s) => `${s.field}:${s.order}`).join(",");
|
|
869
|
+
}
|
|
870
|
+
if (options.limit !== void 0) {
|
|
871
|
+
params.limit = options.limit;
|
|
872
|
+
}
|
|
873
|
+
if (options.offset !== void 0) {
|
|
874
|
+
params.offset = options.offset;
|
|
875
|
+
}
|
|
876
|
+
if (options.where) {
|
|
877
|
+
Object.entries(options.where).forEach(([key, value]) => {
|
|
878
|
+
if (value !== void 0 && value !== null) {
|
|
879
|
+
params[`where[${key}]`] = typeof value === "object" ? JSON.stringify(value) : value;
|
|
880
|
+
}
|
|
881
|
+
});
|
|
639
882
|
}
|
|
640
|
-
|
|
641
|
-
}
|
|
642
|
-
get(url, config) {
|
|
643
|
-
return this.request({ ...config, method: "GET", url });
|
|
644
|
-
}
|
|
645
|
-
post(url, data, config) {
|
|
646
|
-
return this.request({ ...config, method: "POST", url, data });
|
|
647
|
-
}
|
|
648
|
-
put(url, data, config) {
|
|
649
|
-
return this.request({ ...config, method: "PUT", url, data });
|
|
650
|
-
}
|
|
651
|
-
patch(url, data, config) {
|
|
652
|
-
return this.request({ ...config, method: "PATCH", url, data });
|
|
653
|
-
}
|
|
654
|
-
delete(url, config) {
|
|
655
|
-
return this.request({ ...config, method: "DELETE", url });
|
|
656
|
-
}
|
|
657
|
-
getInterceptors() {
|
|
658
|
-
return this.interceptors;
|
|
659
|
-
}
|
|
660
|
-
updateConfig(updates) {
|
|
661
|
-
this.config = { ...this.config, ...updates };
|
|
662
|
-
}
|
|
663
|
-
getConfig() {
|
|
664
|
-
return { ...this.config };
|
|
883
|
+
return params;
|
|
665
884
|
}
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
timeout: 3e4,
|
|
672
|
-
debug: true
|
|
673
|
-
},
|
|
674
|
-
sit: {
|
|
675
|
-
baseURL: "https://asia-south1.api.fcz0.de/service/sdk/boltic-tables",
|
|
676
|
-
timeout: 15e3
|
|
677
|
-
},
|
|
678
|
-
uat: {
|
|
679
|
-
baseURL: "https://asia-south1.api.uat.fcz0.de/service/sdk/boltic-tables",
|
|
680
|
-
timeout: 15e3
|
|
681
|
-
},
|
|
682
|
-
prod: {
|
|
683
|
-
baseURL: "https://asia-south1.api.boltic.io/service/sdk/boltic-tables",
|
|
684
|
-
timeout: 1e4
|
|
685
|
-
}
|
|
686
|
-
},
|
|
687
|
-
"us-central1": {
|
|
688
|
-
local: {
|
|
689
|
-
baseURL: "http://localhost:8000",
|
|
690
|
-
timeout: 3e4,
|
|
691
|
-
debug: true
|
|
692
|
-
},
|
|
693
|
-
sit: {
|
|
694
|
-
baseURL: "https://us-central1.api.fcz0.de/service/sdk/boltic-tables",
|
|
695
|
-
timeout: 15e3
|
|
696
|
-
},
|
|
697
|
-
uat: {
|
|
698
|
-
baseURL: "https://us-central1.api.uat.fcz0.de/service/sdk/boltic-tables",
|
|
699
|
-
timeout: 15e3
|
|
700
|
-
},
|
|
701
|
-
prod: {
|
|
702
|
-
baseURL: "https://us-central1.api.boltic.io/service/sdk/boltic-tables",
|
|
703
|
-
timeout: 1e4
|
|
885
|
+
handleResponse(response) {
|
|
886
|
+
if ("error" in response) {
|
|
887
|
+
if (this.client.getConfig().debug) {
|
|
888
|
+
console.error("API Error:", response.error);
|
|
889
|
+
}
|
|
704
890
|
}
|
|
891
|
+
return response;
|
|
705
892
|
}
|
|
706
|
-
}
|
|
893
|
+
}
|
|
707
894
|
class ConfigManager {
|
|
708
895
|
constructor(apiKey, environment = "prod", region = "asia-south1", overrides) {
|
|
709
896
|
const envConfig = REGION_CONFIGS[region][environment];
|
|
@@ -726,7 +913,6 @@ class ConfigManager {
|
|
|
726
913
|
updateConfig(updates) {
|
|
727
914
|
this.config = { ...this.config, ...updates };
|
|
728
915
|
}
|
|
729
|
-
// Security methods to prevent API key exposure
|
|
730
916
|
toString() {
|
|
731
917
|
return `ConfigManager { environment: "${this.config.environment}", region: "${this.config.region}", debug: ${this.config.debug} }`;
|
|
732
918
|
}
|
|
@@ -735,7 +921,6 @@ class ConfigManager {
|
|
|
735
921
|
delete safeConfig.apiKey;
|
|
736
922
|
return safeConfig;
|
|
737
923
|
}
|
|
738
|
-
// Custom inspect method for Node.js console logging
|
|
739
924
|
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
740
925
|
return this.toString();
|
|
741
926
|
}
|
|
@@ -922,26 +1107,9 @@ function transformDateFormat(dateFormat) {
|
|
|
922
1107
|
function transformTimeFormat(timeFormat) {
|
|
923
1108
|
return TimeFormatEnum[timeFormat] || timeFormat;
|
|
924
1109
|
}
|
|
925
|
-
class ColumnsApiClient {
|
|
1110
|
+
class ColumnsApiClient extends BaseApiClient {
|
|
926
1111
|
constructor(apiKey, config = {}) {
|
|
927
|
-
|
|
928
|
-
this.httpAdapter = createHttpAdapter();
|
|
929
|
-
const environment = config.environment || "prod";
|
|
930
|
-
const region = config.region || "asia-south1";
|
|
931
|
-
this.baseURL = this.getBaseURL(environment, region);
|
|
932
|
-
}
|
|
933
|
-
getBaseURL(environment, region) {
|
|
934
|
-
const regionConfig = REGION_CONFIGS[region];
|
|
935
|
-
if (!regionConfig) {
|
|
936
|
-
throw new Error(`Unsupported region: ${region}`);
|
|
937
|
-
}
|
|
938
|
-
const envConfig = regionConfig[environment];
|
|
939
|
-
if (!envConfig) {
|
|
940
|
-
throw new Error(
|
|
941
|
-
`Unsupported environment: ${environment} for region: ${region}`
|
|
942
|
-
);
|
|
943
|
-
}
|
|
944
|
-
return `${envConfig.baseURL}/v1`;
|
|
1112
|
+
super(apiKey, config);
|
|
945
1113
|
}
|
|
946
1114
|
/**
|
|
947
1115
|
* Create a single column in a table
|
|
@@ -978,7 +1146,7 @@ class ColumnsApiClient {
|
|
|
978
1146
|
const createdColumns = [];
|
|
979
1147
|
for (const column of columns) {
|
|
980
1148
|
const result = await this.createColumn(tableId, column);
|
|
981
|
-
if (
|
|
1149
|
+
if (isErrorResponse(result)) {
|
|
982
1150
|
return result;
|
|
983
1151
|
}
|
|
984
1152
|
createdColumns.push(result.data);
|
|
@@ -1130,7 +1298,7 @@ class ColumnsApiClient {
|
|
|
1130
1298
|
tableId,
|
|
1131
1299
|
apiRequest
|
|
1132
1300
|
);
|
|
1133
|
-
if (
|
|
1301
|
+
if (isErrorResponse(listResult)) {
|
|
1134
1302
|
return listResult;
|
|
1135
1303
|
}
|
|
1136
1304
|
const column = listResult.data[0] || null;
|
|
@@ -1177,7 +1345,7 @@ class ColumnsApiClient {
|
|
|
1177
1345
|
async updateColumnByName(tableId, columnName, updates) {
|
|
1178
1346
|
try {
|
|
1179
1347
|
const findResult = await this.findColumnByName(tableId, columnName);
|
|
1180
|
-
if (
|
|
1348
|
+
if (isErrorResponse(findResult)) {
|
|
1181
1349
|
return findResult;
|
|
1182
1350
|
}
|
|
1183
1351
|
if (!findResult.data) {
|
|
@@ -1211,7 +1379,7 @@ class ColumnsApiClient {
|
|
|
1211
1379
|
async deleteColumnByName(tableId, columnName) {
|
|
1212
1380
|
try {
|
|
1213
1381
|
const findResult = await this.findColumnByName(tableId, columnName);
|
|
1214
|
-
if (
|
|
1382
|
+
if (isErrorResponse(findResult)) {
|
|
1215
1383
|
return findResult;
|
|
1216
1384
|
}
|
|
1217
1385
|
if (!findResult.data) {
|
|
@@ -1228,47 +1396,6 @@ class ColumnsApiClient {
|
|
|
1228
1396
|
return this.formatErrorResponse(error);
|
|
1229
1397
|
}
|
|
1230
1398
|
}
|
|
1231
|
-
buildHeaders() {
|
|
1232
|
-
return {
|
|
1233
|
-
"Content-Type": "application/json",
|
|
1234
|
-
Accept: "application/json",
|
|
1235
|
-
"x-boltic-token": this.config.apiKey
|
|
1236
|
-
};
|
|
1237
|
-
}
|
|
1238
|
-
formatErrorResponse(error) {
|
|
1239
|
-
if (this.config.debug) {
|
|
1240
|
-
console.error("Columns API Error:", error);
|
|
1241
|
-
}
|
|
1242
|
-
if (error && typeof error === "object" && "response" in error) {
|
|
1243
|
-
const apiError = error;
|
|
1244
|
-
if (apiError.response?.data?.error) {
|
|
1245
|
-
return apiError.response.data;
|
|
1246
|
-
}
|
|
1247
|
-
return {
|
|
1248
|
-
error: {
|
|
1249
|
-
code: "API_ERROR",
|
|
1250
|
-
message: error.message || "Unknown API error",
|
|
1251
|
-
meta: [`Status: ${apiError.response?.status || "unknown"}`]
|
|
1252
|
-
}
|
|
1253
|
-
};
|
|
1254
|
-
}
|
|
1255
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
1256
|
-
return {
|
|
1257
|
-
error: {
|
|
1258
|
-
code: "CLIENT_ERROR",
|
|
1259
|
-
message: error.message,
|
|
1260
|
-
meta: ["Client-side error occurred"]
|
|
1261
|
-
}
|
|
1262
|
-
};
|
|
1263
|
-
}
|
|
1264
|
-
return {
|
|
1265
|
-
error: {
|
|
1266
|
-
code: "UNKNOWN_ERROR",
|
|
1267
|
-
message: "An unexpected error occurred",
|
|
1268
|
-
meta: ["Unknown error type"]
|
|
1269
|
-
}
|
|
1270
|
-
};
|
|
1271
|
-
}
|
|
1272
1399
|
}
|
|
1273
1400
|
const TABLE_ENDPOINTS = {
|
|
1274
1401
|
list: {
|
|
@@ -1447,26 +1574,9 @@ function transformFieldDefinition(field) {
|
|
|
1447
1574
|
default_value: field.default_value
|
|
1448
1575
|
};
|
|
1449
1576
|
}
|
|
1450
|
-
class TablesApiClient {
|
|
1577
|
+
class TablesApiClient extends BaseApiClient {
|
|
1451
1578
|
constructor(apiKey, config = {}) {
|
|
1452
|
-
|
|
1453
|
-
this.httpAdapter = createHttpAdapter();
|
|
1454
|
-
const environment = config.environment || "prod";
|
|
1455
|
-
const region = config.region || "asia-south1";
|
|
1456
|
-
this.baseURL = this.getBaseURL(environment, region);
|
|
1457
|
-
}
|
|
1458
|
-
getBaseURL(environment, region) {
|
|
1459
|
-
const regionConfig = REGION_CONFIGS[region];
|
|
1460
|
-
if (!regionConfig) {
|
|
1461
|
-
throw new Error(`Unsupported region: ${region}`);
|
|
1462
|
-
}
|
|
1463
|
-
const envConfig = regionConfig[environment];
|
|
1464
|
-
if (!envConfig) {
|
|
1465
|
-
throw new Error(
|
|
1466
|
-
`Unsupported environment: ${environment} for region: ${region}`
|
|
1467
|
-
);
|
|
1468
|
-
}
|
|
1469
|
-
return `${envConfig.baseURL}/v1`;
|
|
1579
|
+
super(apiKey, config);
|
|
1470
1580
|
}
|
|
1471
1581
|
/**
|
|
1472
1582
|
* Create a new table
|
|
@@ -1564,155 +1674,30 @@ class TablesApiClient {
|
|
|
1564
1674
|
responseData.data,
|
|
1565
1675
|
fields
|
|
1566
1676
|
);
|
|
1567
|
-
}
|
|
1568
|
-
return responseData;
|
|
1569
|
-
} catch (error) {
|
|
1570
|
-
return this.formatErrorResponse(error);
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
/**
|
|
1574
|
-
* Delete a table
|
|
1575
|
-
*/
|
|
1576
|
-
async deleteTable(tableId, options = {}) {
|
|
1577
|
-
try {
|
|
1578
|
-
const endpoint = TABLE_ENDPOINTS.delete;
|
|
1579
|
-
let url = `${this.baseURL}${buildEndpointPath(endpoint, { table_id: tableId })}`;
|
|
1580
|
-
url = addDbIdToUrl(url, options.db_id);
|
|
1581
|
-
const response = await this.httpAdapter.request({
|
|
1582
|
-
url,
|
|
1583
|
-
method: endpoint.method,
|
|
1584
|
-
headers: this.buildHeaders(),
|
|
1585
|
-
timeout: this.config.timeout
|
|
1586
|
-
});
|
|
1587
|
-
return response.data;
|
|
1588
|
-
} catch (error) {
|
|
1589
|
-
return this.formatErrorResponse(error);
|
|
1590
|
-
}
|
|
1591
|
-
}
|
|
1592
|
-
// Private helper methods
|
|
1593
|
-
buildHeaders() {
|
|
1594
|
-
return {
|
|
1595
|
-
"Content-Type": "application/json",
|
|
1596
|
-
Accept: "application/json",
|
|
1597
|
-
"x-boltic-token": this.config.apiKey
|
|
1598
|
-
};
|
|
1599
|
-
}
|
|
1600
|
-
formatErrorResponse(error) {
|
|
1601
|
-
if (this.config.debug) {
|
|
1602
|
-
console.error("Tables API Error:", error);
|
|
1603
|
-
}
|
|
1604
|
-
if (error && typeof error === "object" && "response" in error) {
|
|
1605
|
-
const apiError = error;
|
|
1606
|
-
if (apiError.response?.data?.error) {
|
|
1607
|
-
return apiError.response.data;
|
|
1608
|
-
}
|
|
1609
|
-
return {
|
|
1610
|
-
error: {
|
|
1611
|
-
code: "API_ERROR",
|
|
1612
|
-
message: error.message || "Unknown API error",
|
|
1613
|
-
meta: [`Status: ${apiError.response?.status || "unknown"}`]
|
|
1614
|
-
}
|
|
1615
|
-
};
|
|
1616
|
-
}
|
|
1617
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
1618
|
-
return {
|
|
1619
|
-
error: {
|
|
1620
|
-
code: "CLIENT_ERROR",
|
|
1621
|
-
message: error.message,
|
|
1622
|
-
meta: ["Client-side error occurred"]
|
|
1623
|
-
}
|
|
1624
|
-
};
|
|
1625
|
-
}
|
|
1626
|
-
return {
|
|
1627
|
-
error: {
|
|
1628
|
-
code: "UNKNOWN_ERROR",
|
|
1629
|
-
message: "An unexpected error occurred",
|
|
1630
|
-
meta: ["Unknown error type"]
|
|
1631
|
-
}
|
|
1632
|
-
};
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
class BaseResource {
|
|
1636
|
-
constructor(client, basePath) {
|
|
1637
|
-
this.client = client;
|
|
1638
|
-
this.basePath = basePath;
|
|
1639
|
-
}
|
|
1640
|
-
// Public getter for basePath
|
|
1641
|
-
getBasePath() {
|
|
1642
|
-
return this.basePath;
|
|
1643
|
-
}
|
|
1644
|
-
async makeRequest(method, path, data, options) {
|
|
1645
|
-
const url = `${this.basePath}${path}`;
|
|
1646
|
-
try {
|
|
1647
|
-
let response;
|
|
1648
|
-
switch (method) {
|
|
1649
|
-
case "GET":
|
|
1650
|
-
response = await this.client.get(url, {
|
|
1651
|
-
params: options?.params
|
|
1652
|
-
});
|
|
1653
|
-
break;
|
|
1654
|
-
case "POST":
|
|
1655
|
-
response = await this.client.post(url, data, {
|
|
1656
|
-
params: options?.params
|
|
1657
|
-
});
|
|
1658
|
-
break;
|
|
1659
|
-
case "PUT":
|
|
1660
|
-
response = await this.client.put(url, data, {
|
|
1661
|
-
params: options?.params
|
|
1662
|
-
});
|
|
1663
|
-
break;
|
|
1664
|
-
case "PATCH":
|
|
1665
|
-
response = await this.client.patch(url, data, {
|
|
1666
|
-
params: options?.params
|
|
1667
|
-
});
|
|
1668
|
-
break;
|
|
1669
|
-
case "DELETE":
|
|
1670
|
-
response = await this.client.delete(url, {
|
|
1671
|
-
params: options?.params
|
|
1672
|
-
});
|
|
1673
|
-
break;
|
|
1674
|
-
}
|
|
1675
|
-
return response.data;
|
|
1676
|
-
} catch (error) {
|
|
1677
|
-
return {
|
|
1678
|
-
error: {
|
|
1679
|
-
code: "CLIENT_ERROR",
|
|
1680
|
-
message: formatError(error),
|
|
1681
|
-
meta: ["Request failed"]
|
|
1682
|
-
}
|
|
1683
|
-
};
|
|
1684
|
-
}
|
|
1685
|
-
}
|
|
1686
|
-
buildQueryParams(options = {}) {
|
|
1687
|
-
const params = {};
|
|
1688
|
-
if (options.fields?.length) {
|
|
1689
|
-
params.fields = options.fields.join(",");
|
|
1690
|
-
}
|
|
1691
|
-
if (options.sort?.length) {
|
|
1692
|
-
params.sort = options.sort.map((s) => `${s.field}:${s.order}`).join(",");
|
|
1693
|
-
}
|
|
1694
|
-
if (options.limit !== void 0) {
|
|
1695
|
-
params.limit = options.limit;
|
|
1696
|
-
}
|
|
1697
|
-
if (options.offset !== void 0) {
|
|
1698
|
-
params.offset = options.offset;
|
|
1699
|
-
}
|
|
1700
|
-
if (options.where) {
|
|
1701
|
-
Object.entries(options.where).forEach(([key, value]) => {
|
|
1702
|
-
if (value !== void 0 && value !== null) {
|
|
1703
|
-
params[`where[${key}]`] = typeof value === "object" ? JSON.stringify(value) : value;
|
|
1704
|
-
}
|
|
1705
|
-
});
|
|
1677
|
+
}
|
|
1678
|
+
return responseData;
|
|
1679
|
+
} catch (error) {
|
|
1680
|
+
return this.formatErrorResponse(error);
|
|
1706
1681
|
}
|
|
1707
|
-
return params;
|
|
1708
1682
|
}
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1683
|
+
/**
|
|
1684
|
+
* Delete a table
|
|
1685
|
+
*/
|
|
1686
|
+
async deleteTable(tableId, options = {}) {
|
|
1687
|
+
try {
|
|
1688
|
+
const endpoint = TABLE_ENDPOINTS.delete;
|
|
1689
|
+
let url = `${this.baseURL}${buildEndpointPath(endpoint, { table_id: tableId })}`;
|
|
1690
|
+
url = addDbIdToUrl(url, options.db_id);
|
|
1691
|
+
const response = await this.httpAdapter.request({
|
|
1692
|
+
url,
|
|
1693
|
+
method: endpoint.method,
|
|
1694
|
+
headers: this.buildHeaders(),
|
|
1695
|
+
timeout: this.config.timeout
|
|
1696
|
+
});
|
|
1697
|
+
return response.data;
|
|
1698
|
+
} catch (error) {
|
|
1699
|
+
return this.formatErrorResponse(error);
|
|
1714
1700
|
}
|
|
1715
|
-
return response;
|
|
1716
1701
|
}
|
|
1717
1702
|
}
|
|
1718
1703
|
class TableResource extends BaseResource {
|
|
@@ -2023,30 +2008,7 @@ class TableResource extends BaseResource {
|
|
|
2023
2008
|
*/
|
|
2024
2009
|
async rename(oldName, newName, dbId) {
|
|
2025
2010
|
try {
|
|
2026
|
-
const result = await this.update(
|
|
2027
|
-
oldName,
|
|
2028
|
-
{
|
|
2029
|
-
name: newName
|
|
2030
|
-
},
|
|
2031
|
-
dbId
|
|
2032
|
-
);
|
|
2033
|
-
return result;
|
|
2034
|
-
} catch (error) {
|
|
2035
|
-
throw error instanceof ApiError ? error : new ApiError(this.formatError(error), 500);
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
/**
|
|
2039
|
-
* Set table access permissions
|
|
2040
|
-
*/
|
|
2041
|
-
async setAccess(request, dbId) {
|
|
2042
|
-
try {
|
|
2043
|
-
const result = await this.update(
|
|
2044
|
-
request.table_name,
|
|
2045
|
-
{
|
|
2046
|
-
is_shared: request.is_shared
|
|
2047
|
-
},
|
|
2048
|
-
dbId
|
|
2049
|
-
);
|
|
2011
|
+
const result = await this.update(oldName, { name: newName }, dbId);
|
|
2050
2012
|
return result;
|
|
2051
2013
|
} catch (error) {
|
|
2052
2014
|
throw error instanceof ApiError ? error : new ApiError(this.formatError(error), 500);
|
|
@@ -2487,26 +2449,9 @@ const buildDatabaseEndpointPath = (endpoint, params = {}) => {
|
|
|
2487
2449
|
});
|
|
2488
2450
|
return path;
|
|
2489
2451
|
};
|
|
2490
|
-
class DatabasesApiClient {
|
|
2452
|
+
class DatabasesApiClient extends BaseApiClient {
|
|
2491
2453
|
constructor(apiKey, config = {}) {
|
|
2492
|
-
|
|
2493
|
-
this.httpAdapter = createHttpAdapter();
|
|
2494
|
-
const environment = config.environment || "prod";
|
|
2495
|
-
const region = config.region || "asia-south1";
|
|
2496
|
-
this.baseURL = this.getBaseURL(environment, region);
|
|
2497
|
-
}
|
|
2498
|
-
getBaseURL(environment, region) {
|
|
2499
|
-
const regionConfig = REGION_CONFIGS[region];
|
|
2500
|
-
if (!regionConfig) {
|
|
2501
|
-
throw new Error(`Unsupported region: ${region}`);
|
|
2502
|
-
}
|
|
2503
|
-
const envConfig = regionConfig[environment];
|
|
2504
|
-
if (!envConfig) {
|
|
2505
|
-
throw new Error(
|
|
2506
|
-
`Unsupported environment: ${environment} for region: ${region}`
|
|
2507
|
-
);
|
|
2508
|
-
}
|
|
2509
|
-
return `${envConfig.baseURL}/v1`;
|
|
2454
|
+
super(apiKey, config);
|
|
2510
2455
|
}
|
|
2511
2456
|
/**
|
|
2512
2457
|
* Create a new database
|
|
@@ -2518,16 +2463,13 @@ class DatabasesApiClient {
|
|
|
2518
2463
|
const response = await this.httpAdapter.request({
|
|
2519
2464
|
url,
|
|
2520
2465
|
method: endpoint.method,
|
|
2521
|
-
headers:
|
|
2522
|
-
"Content-Type": "application/json",
|
|
2523
|
-
"x-boltic-token": this.config.apiKey
|
|
2524
|
-
},
|
|
2466
|
+
headers: this.buildHeaders(),
|
|
2525
2467
|
data: request,
|
|
2526
2468
|
timeout: this.config.timeout
|
|
2527
2469
|
});
|
|
2528
2470
|
return response.data;
|
|
2529
2471
|
} catch (error) {
|
|
2530
|
-
return this.
|
|
2472
|
+
return this.formatErrorResponse(error);
|
|
2531
2473
|
}
|
|
2532
2474
|
}
|
|
2533
2475
|
/**
|
|
@@ -2553,10 +2495,7 @@ class DatabasesApiClient {
|
|
|
2553
2495
|
const response = await this.httpAdapter.request({
|
|
2554
2496
|
url,
|
|
2555
2497
|
method: endpoint.method,
|
|
2556
|
-
headers:
|
|
2557
|
-
"Content-Type": "application/json",
|
|
2558
|
-
"x-boltic-token": this.config.apiKey
|
|
2559
|
-
},
|
|
2498
|
+
headers: this.buildHeaders(),
|
|
2560
2499
|
data: request,
|
|
2561
2500
|
timeout: this.config.timeout
|
|
2562
2501
|
});
|
|
@@ -2572,7 +2511,7 @@ class DatabasesApiClient {
|
|
|
2572
2511
|
}
|
|
2573
2512
|
return result;
|
|
2574
2513
|
} catch (error) {
|
|
2575
|
-
return this.
|
|
2514
|
+
return this.formatErrorResponse(error);
|
|
2576
2515
|
}
|
|
2577
2516
|
}
|
|
2578
2517
|
/**
|
|
@@ -2586,16 +2525,13 @@ class DatabasesApiClient {
|
|
|
2586
2525
|
const response = await this.httpAdapter.request({
|
|
2587
2526
|
url,
|
|
2588
2527
|
method: endpoint.method,
|
|
2589
|
-
headers:
|
|
2590
|
-
"Content-Type": "application/json",
|
|
2591
|
-
"x-boltic-token": this.config.apiKey
|
|
2592
|
-
},
|
|
2528
|
+
headers: this.buildHeaders(),
|
|
2593
2529
|
data: request,
|
|
2594
2530
|
timeout: this.config.timeout
|
|
2595
2531
|
});
|
|
2596
2532
|
return response.data;
|
|
2597
2533
|
} catch (error) {
|
|
2598
|
-
return this.
|
|
2534
|
+
return this.formatErrorResponse(error);
|
|
2599
2535
|
}
|
|
2600
2536
|
}
|
|
2601
2537
|
/**
|
|
@@ -2609,15 +2545,12 @@ class DatabasesApiClient {
|
|
|
2609
2545
|
const response = await this.httpAdapter.request({
|
|
2610
2546
|
url,
|
|
2611
2547
|
method: endpoint.method,
|
|
2612
|
-
headers:
|
|
2613
|
-
"Content-Type": "application/json",
|
|
2614
|
-
"x-boltic-token": this.config.apiKey
|
|
2615
|
-
},
|
|
2548
|
+
headers: this.buildHeaders(),
|
|
2616
2549
|
timeout: this.config.timeout
|
|
2617
2550
|
});
|
|
2618
2551
|
return response.data;
|
|
2619
2552
|
} catch (error) {
|
|
2620
|
-
return this.
|
|
2553
|
+
return this.formatErrorResponse(error);
|
|
2621
2554
|
}
|
|
2622
2555
|
}
|
|
2623
2556
|
/**
|
|
@@ -2630,10 +2563,7 @@ class DatabasesApiClient {
|
|
|
2630
2563
|
const response = await this.httpAdapter.request({
|
|
2631
2564
|
url,
|
|
2632
2565
|
method: endpoint.method,
|
|
2633
|
-
headers:
|
|
2634
|
-
"Content-Type": "application/json",
|
|
2635
|
-
"x-boltic-token": this.config.apiKey
|
|
2636
|
-
},
|
|
2566
|
+
headers: this.buildHeaders(),
|
|
2637
2567
|
data: request,
|
|
2638
2568
|
timeout: this.config.timeout
|
|
2639
2569
|
});
|
|
@@ -2649,7 +2579,7 @@ class DatabasesApiClient {
|
|
|
2649
2579
|
}
|
|
2650
2580
|
return result;
|
|
2651
2581
|
} catch (error) {
|
|
2652
|
-
return this.
|
|
2582
|
+
return this.formatErrorResponse(error);
|
|
2653
2583
|
}
|
|
2654
2584
|
}
|
|
2655
2585
|
/**
|
|
@@ -2663,70 +2593,13 @@ class DatabasesApiClient {
|
|
|
2663
2593
|
const response = await this.httpAdapter.request({
|
|
2664
2594
|
url,
|
|
2665
2595
|
method: endpoint.method,
|
|
2666
|
-
headers:
|
|
2667
|
-
"Content-Type": "application/json",
|
|
2668
|
-
"x-boltic-token": this.config.apiKey
|
|
2669
|
-
},
|
|
2596
|
+
headers: this.buildHeaders(),
|
|
2670
2597
|
timeout: this.config.timeout
|
|
2671
2598
|
});
|
|
2672
2599
|
return response.data;
|
|
2673
2600
|
} catch (error) {
|
|
2674
|
-
return this.
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
/**
|
|
2678
|
-
* Handle API errors and convert to standard error format
|
|
2679
|
-
*/
|
|
2680
|
-
handleError(error) {
|
|
2681
|
-
if (this.config.debug) {
|
|
2682
|
-
console.error("[DatabasesApiClient] Error:", error);
|
|
2683
|
-
}
|
|
2684
|
-
const hasErrorProperty = (err) => {
|
|
2685
|
-
return typeof err === "object" && err !== null && "error" in err && typeof err.error === "object" && err.error !== null;
|
|
2686
|
-
};
|
|
2687
|
-
const hasResponseError = (err) => {
|
|
2688
|
-
return typeof err === "object" && err !== null && "response" in err && typeof err.response === "object" && err.response !== null && "data" in err.response && typeof err.response.data === "object" && err.response.data !== null && "error" in err.response.data;
|
|
2689
|
-
};
|
|
2690
|
-
const isStandardError = (err) => {
|
|
2691
|
-
return err instanceof Error;
|
|
2692
|
-
};
|
|
2693
|
-
if (hasErrorProperty(error)) {
|
|
2694
|
-
const errorWithError = error;
|
|
2695
|
-
return {
|
|
2696
|
-
error: {
|
|
2697
|
-
code: typeof errorWithError.error.code === "number" ? String(errorWithError.error.code) : errorWithError.error.code || "UNKNOWN_ERROR",
|
|
2698
|
-
message: errorWithError.error.message || "An error occurred",
|
|
2699
|
-
meta: errorWithError.error.meta || []
|
|
2700
|
-
}
|
|
2701
|
-
};
|
|
2702
|
-
}
|
|
2703
|
-
if (hasResponseError(error)) {
|
|
2704
|
-
const errorWithResponse = error;
|
|
2705
|
-
return {
|
|
2706
|
-
error: {
|
|
2707
|
-
code: typeof errorWithResponse.response.data.error.code === "number" ? String(errorWithResponse.response.data.error.code) : errorWithResponse.response.data.error.code || "UNKNOWN_ERROR",
|
|
2708
|
-
message: errorWithResponse.response.data.error.message || "An error occurred",
|
|
2709
|
-
meta: errorWithResponse.response.data.error.meta || []
|
|
2710
|
-
}
|
|
2711
|
-
};
|
|
2712
|
-
}
|
|
2713
|
-
if (isStandardError(error)) {
|
|
2714
|
-
const standardError = error;
|
|
2715
|
-
return {
|
|
2716
|
-
error: {
|
|
2717
|
-
code: standardError.code || "UNKNOWN_ERROR",
|
|
2718
|
-
message: standardError.message || "An unexpected error occurred",
|
|
2719
|
-
meta: []
|
|
2720
|
-
}
|
|
2721
|
-
};
|
|
2601
|
+
return this.formatErrorResponse(error);
|
|
2722
2602
|
}
|
|
2723
|
-
return {
|
|
2724
|
-
error: {
|
|
2725
|
-
code: "UNKNOWN_ERROR",
|
|
2726
|
-
message: "An unexpected error occurred",
|
|
2727
|
-
meta: []
|
|
2728
|
-
}
|
|
2729
|
-
};
|
|
2730
2603
|
}
|
|
2731
2604
|
}
|
|
2732
2605
|
class DatabaseResource extends BaseResource {
|
|
@@ -2756,7 +2629,7 @@ class DatabaseResource extends BaseResource {
|
|
|
2756
2629
|
*/
|
|
2757
2630
|
async create(request) {
|
|
2758
2631
|
const result = await this.apiClient.createDatabase(request);
|
|
2759
|
-
if (
|
|
2632
|
+
if (isErrorResponse(result)) {
|
|
2760
2633
|
return {
|
|
2761
2634
|
error: {
|
|
2762
2635
|
code: typeof result.error.code === "number" ? String(result.error.code) : result.error.code,
|
|
@@ -2823,7 +2696,7 @@ class DatabaseResource extends BaseResource {
|
|
|
2823
2696
|
queryParams,
|
|
2824
2697
|
options
|
|
2825
2698
|
);
|
|
2826
|
-
if (
|
|
2699
|
+
if (isErrorResponse(result)) {
|
|
2827
2700
|
return {
|
|
2828
2701
|
error: {
|
|
2829
2702
|
code: typeof result.error.code === "number" ? String(result.error.code) : result.error.code,
|
|
@@ -2951,7 +2824,7 @@ class DatabaseResource extends BaseResource {
|
|
|
2951
2824
|
db_name: request.db_name
|
|
2952
2825
|
};
|
|
2953
2826
|
const result = await this.apiClient.updateDatabase(dbId, updateRequest);
|
|
2954
|
-
if (
|
|
2827
|
+
if (isErrorResponse(result)) {
|
|
2955
2828
|
return {
|
|
2956
2829
|
error: {
|
|
2957
2830
|
code: typeof result.error.code === "number" ? String(result.error.code) : result.error.code,
|
|
@@ -3000,7 +2873,7 @@ class DatabaseResource extends BaseResource {
|
|
|
3000
2873
|
}
|
|
3001
2874
|
const dbId = dbInfo.data.id;
|
|
3002
2875
|
const result = await this.apiClient.deleteDatabase(dbId);
|
|
3003
|
-
if (
|
|
2876
|
+
if (isErrorResponse(result)) {
|
|
3004
2877
|
return {
|
|
3005
2878
|
error: {
|
|
3006
2879
|
code: typeof result.error.code === "number" ? String(result.error.code) : result.error.code,
|
|
@@ -3043,7 +2916,7 @@ class DatabaseResource extends BaseResource {
|
|
|
3043
2916
|
request.filters = options.filters;
|
|
3044
2917
|
}
|
|
3045
2918
|
const result = await this.apiClient.listDatabaseJobs(request, options);
|
|
3046
|
-
if (
|
|
2919
|
+
if (isErrorResponse(result)) {
|
|
3047
2920
|
return {
|
|
3048
2921
|
error: {
|
|
3049
2922
|
code: typeof result.error.code === "number" ? String(result.error.code) : result.error.code,
|
|
@@ -3088,7 +2961,7 @@ class DatabaseResource extends BaseResource {
|
|
|
3088
2961
|
*/
|
|
3089
2962
|
async pollDeleteStatus(jobId) {
|
|
3090
2963
|
const result = await this.apiClient.pollDeleteStatus(jobId);
|
|
3091
|
-
if (
|
|
2964
|
+
if (isErrorResponse(result)) {
|
|
3092
2965
|
return {
|
|
3093
2966
|
error: {
|
|
3094
2967
|
code: typeof result.error.code === "number" ? String(result.error.code) : result.error.code,
|
|
@@ -3128,26 +3001,9 @@ const buildIndexEndpointPath = (endpoint, params = {}) => {
|
|
|
3128
3001
|
}
|
|
3129
3002
|
return path;
|
|
3130
3003
|
};
|
|
3131
|
-
class IndexesApiClient {
|
|
3004
|
+
class IndexesApiClient extends BaseApiClient {
|
|
3132
3005
|
constructor(apiKey, config = {}) {
|
|
3133
|
-
|
|
3134
|
-
this.httpAdapter = createHttpAdapter();
|
|
3135
|
-
const environment = config.environment || "prod";
|
|
3136
|
-
const region = config.region || "asia-south1";
|
|
3137
|
-
this.baseURL = this.getBaseURL(environment, region);
|
|
3138
|
-
}
|
|
3139
|
-
getBaseURL(environment, region) {
|
|
3140
|
-
const regionConfig = REGION_CONFIGS[region];
|
|
3141
|
-
if (!regionConfig) {
|
|
3142
|
-
throw new Error(`Unsupported region: ${region}`);
|
|
3143
|
-
}
|
|
3144
|
-
const envConfig = regionConfig[environment];
|
|
3145
|
-
if (!envConfig) {
|
|
3146
|
-
throw new Error(
|
|
3147
|
-
`Unsupported environment: ${environment} for region: ${region}`
|
|
3148
|
-
);
|
|
3149
|
-
}
|
|
3150
|
-
return `${envConfig.baseURL}/v1`;
|
|
3006
|
+
super(apiKey, config);
|
|
3151
3007
|
}
|
|
3152
3008
|
async addIndex(tableId, request, dbId) {
|
|
3153
3009
|
try {
|
|
@@ -3200,47 +3056,6 @@ class IndexesApiClient {
|
|
|
3200
3056
|
return this.formatErrorResponse(error);
|
|
3201
3057
|
}
|
|
3202
3058
|
}
|
|
3203
|
-
buildHeaders() {
|
|
3204
|
-
return {
|
|
3205
|
-
"Content-Type": "application/json",
|
|
3206
|
-
Accept: "application/json",
|
|
3207
|
-
"x-boltic-token": this.config.apiKey
|
|
3208
|
-
};
|
|
3209
|
-
}
|
|
3210
|
-
formatErrorResponse(error) {
|
|
3211
|
-
if (this.config.debug) {
|
|
3212
|
-
console.error("Indexes API Error:", error);
|
|
3213
|
-
}
|
|
3214
|
-
if (error && typeof error === "object" && "response" in error) {
|
|
3215
|
-
const apiError = error;
|
|
3216
|
-
if (apiError.response?.data?.error) {
|
|
3217
|
-
return apiError.response.data;
|
|
3218
|
-
}
|
|
3219
|
-
return {
|
|
3220
|
-
error: {
|
|
3221
|
-
code: "API_ERROR",
|
|
3222
|
-
message: error.message || "Unknown API error",
|
|
3223
|
-
meta: [`Status: ${apiError.response?.status || "unknown"}`]
|
|
3224
|
-
}
|
|
3225
|
-
};
|
|
3226
|
-
}
|
|
3227
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
3228
|
-
return {
|
|
3229
|
-
error: {
|
|
3230
|
-
code: "CLIENT_ERROR",
|
|
3231
|
-
message: error.message,
|
|
3232
|
-
meta: ["Client-side error occurred"]
|
|
3233
|
-
}
|
|
3234
|
-
};
|
|
3235
|
-
}
|
|
3236
|
-
return {
|
|
3237
|
-
error: {
|
|
3238
|
-
code: "UNKNOWN_ERROR",
|
|
3239
|
-
message: "An unexpected error occurred",
|
|
3240
|
-
meta: ["Unknown error type"]
|
|
3241
|
-
}
|
|
3242
|
-
};
|
|
3243
|
-
}
|
|
3244
3059
|
}
|
|
3245
3060
|
class IndexResource {
|
|
3246
3061
|
constructor(client) {
|
|
@@ -3377,26 +3192,9 @@ function transformDeleteRequest(sdkRequest) {
|
|
|
3377
3192
|
}
|
|
3378
3193
|
return result;
|
|
3379
3194
|
}
|
|
3380
|
-
class RecordsApiClient {
|
|
3195
|
+
class RecordsApiClient extends BaseApiClient {
|
|
3381
3196
|
constructor(apiKey, config = {}) {
|
|
3382
|
-
|
|
3383
|
-
this.httpAdapter = createHttpAdapter();
|
|
3384
|
-
const environment = config.environment || "prod";
|
|
3385
|
-
const region = config.region || "asia-south1";
|
|
3386
|
-
this.baseURL = this.getBaseURL(environment, region);
|
|
3387
|
-
}
|
|
3388
|
-
getBaseURL(environment, region) {
|
|
3389
|
-
const regionConfig = REGION_CONFIGS[region];
|
|
3390
|
-
if (!regionConfig) {
|
|
3391
|
-
throw new Error(`Unsupported region: ${region}`);
|
|
3392
|
-
}
|
|
3393
|
-
const envConfig = regionConfig[environment];
|
|
3394
|
-
if (!envConfig) {
|
|
3395
|
-
throw new Error(
|
|
3396
|
-
`Unsupported environment: ${environment} for region: ${region}`
|
|
3397
|
-
);
|
|
3398
|
-
}
|
|
3399
|
-
return `${envConfig.baseURL}/v1`;
|
|
3197
|
+
super(apiKey, config);
|
|
3400
3198
|
}
|
|
3401
3199
|
/**
|
|
3402
3200
|
* Insert a single record
|
|
@@ -3672,47 +3470,6 @@ class RecordsApiClient {
|
|
|
3672
3470
|
dbId
|
|
3673
3471
|
);
|
|
3674
3472
|
}
|
|
3675
|
-
buildHeaders() {
|
|
3676
|
-
return {
|
|
3677
|
-
"Content-Type": "application/json",
|
|
3678
|
-
Accept: "application/json",
|
|
3679
|
-
"x-boltic-token": this.config.apiKey
|
|
3680
|
-
};
|
|
3681
|
-
}
|
|
3682
|
-
formatErrorResponse(error) {
|
|
3683
|
-
if (this.config.debug) {
|
|
3684
|
-
console.error("Records API Error:", error);
|
|
3685
|
-
}
|
|
3686
|
-
if (error && typeof error === "object" && "response" in error) {
|
|
3687
|
-
const apiError = error;
|
|
3688
|
-
if (apiError.response?.data?.error) {
|
|
3689
|
-
return apiError.response.data;
|
|
3690
|
-
}
|
|
3691
|
-
return {
|
|
3692
|
-
error: {
|
|
3693
|
-
code: "API_ERROR",
|
|
3694
|
-
message: error.message || "Unknown API error",
|
|
3695
|
-
meta: [`Status: ${apiError.response?.status || "unknown"}`]
|
|
3696
|
-
}
|
|
3697
|
-
};
|
|
3698
|
-
}
|
|
3699
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
3700
|
-
return {
|
|
3701
|
-
error: {
|
|
3702
|
-
code: "CLIENT_ERROR",
|
|
3703
|
-
message: error.message,
|
|
3704
|
-
meta: ["Client-side error occurred"]
|
|
3705
|
-
}
|
|
3706
|
-
};
|
|
3707
|
-
}
|
|
3708
|
-
return {
|
|
3709
|
-
error: {
|
|
3710
|
-
code: "UNKNOWN_ERROR",
|
|
3711
|
-
message: "An unexpected error occurred",
|
|
3712
|
-
meta: ["Unknown error type"]
|
|
3713
|
-
}
|
|
3714
|
-
};
|
|
3715
|
-
}
|
|
3716
3473
|
}
|
|
3717
3474
|
class RecordResource {
|
|
3718
3475
|
constructor(client) {
|
|
@@ -4300,86 +4057,6 @@ const buildSqlEndpointPath = (endpoint, params = {}) => {
|
|
|
4300
4057
|
});
|
|
4301
4058
|
return path;
|
|
4302
4059
|
};
|
|
4303
|
-
class BaseApiClient {
|
|
4304
|
-
constructor(apiKey, config = {}) {
|
|
4305
|
-
this.config = { apiKey, ...config };
|
|
4306
|
-
this.httpAdapter = createHttpAdapter();
|
|
4307
|
-
const environment = config.environment || "prod";
|
|
4308
|
-
const region = config.region || "asia-south1";
|
|
4309
|
-
this.baseURL = this.getBaseURL(environment, region);
|
|
4310
|
-
}
|
|
4311
|
-
getBaseURL(environment, region) {
|
|
4312
|
-
const regionConfig = REGION_CONFIGS[region];
|
|
4313
|
-
if (!regionConfig) {
|
|
4314
|
-
throw new Error(`Unsupported region: ${region}`);
|
|
4315
|
-
}
|
|
4316
|
-
const envConfig = regionConfig[environment];
|
|
4317
|
-
if (!envConfig) {
|
|
4318
|
-
throw new Error(
|
|
4319
|
-
`Unsupported environment: ${environment} for region: ${region}`
|
|
4320
|
-
);
|
|
4321
|
-
}
|
|
4322
|
-
return `${envConfig.baseURL}/v1`;
|
|
4323
|
-
}
|
|
4324
|
-
buildHeaders() {
|
|
4325
|
-
return {
|
|
4326
|
-
"Content-Type": "application/json",
|
|
4327
|
-
Accept: "application/json",
|
|
4328
|
-
"x-boltic-token": this.config.apiKey,
|
|
4329
|
-
...this.config.headers
|
|
4330
|
-
};
|
|
4331
|
-
}
|
|
4332
|
-
formatErrorResponse(error, prefix = "API") {
|
|
4333
|
-
if (this.config.debug) {
|
|
4334
|
-
console.error(`${prefix} Error:`, error);
|
|
4335
|
-
}
|
|
4336
|
-
if (error && typeof error === "object" && "response" in error) {
|
|
4337
|
-
const apiError = error;
|
|
4338
|
-
if (apiError.response?.data?.error) {
|
|
4339
|
-
return apiError.response.data;
|
|
4340
|
-
}
|
|
4341
|
-
return {
|
|
4342
|
-
error: {
|
|
4343
|
-
code: `${prefix}_ERROR`,
|
|
4344
|
-
message: error.message || `Unknown ${prefix} error`,
|
|
4345
|
-
meta: [`Status: ${apiError.response?.status || "unknown"}`]
|
|
4346
|
-
}
|
|
4347
|
-
};
|
|
4348
|
-
}
|
|
4349
|
-
if (error && typeof error === "object" && "message" in error) {
|
|
4350
|
-
return {
|
|
4351
|
-
error: {
|
|
4352
|
-
code: `${prefix}_CLIENT_ERROR`,
|
|
4353
|
-
message: error.message,
|
|
4354
|
-
meta: [`${prefix} client-side error occurred`]
|
|
4355
|
-
}
|
|
4356
|
-
};
|
|
4357
|
-
}
|
|
4358
|
-
return {
|
|
4359
|
-
error: {
|
|
4360
|
-
code: `${prefix}_UNKNOWN_ERROR`,
|
|
4361
|
-
message: `An unexpected ${prefix} error occurred`,
|
|
4362
|
-
meta: [`Unknown ${prefix} error type`]
|
|
4363
|
-
}
|
|
4364
|
-
};
|
|
4365
|
-
}
|
|
4366
|
-
// Security methods to prevent API key exposure
|
|
4367
|
-
toString() {
|
|
4368
|
-
return `${this.constructor.name} { environment: "${this.config.environment || "prod"}", debug: ${this.config.debug || false} }`;
|
|
4369
|
-
}
|
|
4370
|
-
toJSON() {
|
|
4371
|
-
const safeConfig = { ...this.config };
|
|
4372
|
-
delete safeConfig.apiKey;
|
|
4373
|
-
return {
|
|
4374
|
-
client: this.constructor.name,
|
|
4375
|
-
config: safeConfig
|
|
4376
|
-
};
|
|
4377
|
-
}
|
|
4378
|
-
// Custom inspect method for Node.js console logging
|
|
4379
|
-
[/* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom")]() {
|
|
4380
|
-
return this.toString();
|
|
4381
|
-
}
|
|
4382
|
-
}
|
|
4383
4060
|
class SqlApiClient extends BaseApiClient {
|
|
4384
4061
|
constructor(apiKey, config = {}) {
|
|
4385
4062
|
super(apiKey, config);
|
|
@@ -4506,7 +4183,6 @@ class SqlResource {
|
|
|
4506
4183
|
}
|
|
4507
4184
|
class TableBuilder {
|
|
4508
4185
|
constructor(options, tablesApiClient) {
|
|
4509
|
-
this.isPublic = false;
|
|
4510
4186
|
this.fields = [];
|
|
4511
4187
|
this.tableName = options.name;
|
|
4512
4188
|
this.description = options.description;
|
|
@@ -4526,13 +4202,6 @@ class TableBuilder {
|
|
|
4526
4202
|
this.description = description;
|
|
4527
4203
|
return this;
|
|
4528
4204
|
}
|
|
4529
|
-
/**
|
|
4530
|
-
* Set if table is public
|
|
4531
|
-
*/
|
|
4532
|
-
public(isPublic = true) {
|
|
4533
|
-
this.isPublic = isPublic;
|
|
4534
|
-
return this;
|
|
4535
|
-
}
|
|
4536
4205
|
/**
|
|
4537
4206
|
* Add a text field
|
|
4538
4207
|
*/
|
|
@@ -4825,6 +4494,508 @@ class TableBuilder {
|
|
|
4825
4494
|
function createTableBuilder(options, tablesApiClient) {
|
|
4826
4495
|
return new TableBuilder(options, tablesApiClient);
|
|
4827
4496
|
}
|
|
4497
|
+
const POLLING_INTERVAL_MS = 1e3;
|
|
4498
|
+
const MAX_POLLING_ATTEMPTS = 30;
|
|
4499
|
+
const SCHEMA_TYPE_MAPPING = {
|
|
4500
|
+
string: { type: "string", fallback_value: "" },
|
|
4501
|
+
number: { type: "number", fallback_value: "" },
|
|
4502
|
+
boolean: { type: "boolean", secondary_type: "string", fallback_value: "" },
|
|
4503
|
+
int: { type: "number", fallback_value: "" },
|
|
4504
|
+
integer: { type: "number", fallback_value: "" },
|
|
4505
|
+
"date-time": { type: "date-time", secondary_type: "string", fallback_value: "" },
|
|
4506
|
+
date: { type: "date", secondary_type: "string", fallback_value: "" },
|
|
4507
|
+
json: { type: "object", fallback_value: {} },
|
|
4508
|
+
text: { type: "string", fallback_value: "" },
|
|
4509
|
+
email: { type: "string", fallback_value: "" },
|
|
4510
|
+
password: { type: "string", fallback_value: "" },
|
|
4511
|
+
url: { type: "string", fallback_value: "" },
|
|
4512
|
+
textarea: { type: "string", fallback_value: "" },
|
|
4513
|
+
select: { type: "string", fallback_value: "" },
|
|
4514
|
+
multiselect: { type: "string", fallback_value: "" },
|
|
4515
|
+
autocomplete: { type: "array", fallback_value: [] },
|
|
4516
|
+
radio: { type: "string", fallback_value: "" },
|
|
4517
|
+
radiobuttons: { type: "string", fallback_value: "" },
|
|
4518
|
+
checkbox: { type: "array", fallback_value: [] },
|
|
4519
|
+
toggle: { type: "boolean", fallback_value: "" },
|
|
4520
|
+
hidden: { type: "string", fallback_value: "" },
|
|
4521
|
+
slider: { type: "number", fallback_value: "" },
|
|
4522
|
+
datepicker: { type: "string", fallback_value: "" },
|
|
4523
|
+
phoneinput: { type: "string", fallback_value: "" },
|
|
4524
|
+
time: { type: "string", fallback_value: "" },
|
|
4525
|
+
datetime: { type: "string", fallback_value: "" },
|
|
4526
|
+
code: { type: "string", fallback_value: "" },
|
|
4527
|
+
multitext: { type: "array", fallback_value: [] },
|
|
4528
|
+
array: { type: "array", fallback_value: [] },
|
|
4529
|
+
keyvalue: { type: "object", fallback_value: {} },
|
|
4530
|
+
object: { type: "object", fallback_value: {} },
|
|
4531
|
+
phone: { type: "string", fallback_value: "" },
|
|
4532
|
+
"number[]": { type: "string", fallback_value: "" },
|
|
4533
|
+
"number []": { type: "string", fallback_value: "" },
|
|
4534
|
+
"object | any": { type: "string", fallback_value: "" }
|
|
4535
|
+
};
|
|
4536
|
+
const WORKFLOW_ENDPOINTS = {
|
|
4537
|
+
executeActivity: {
|
|
4538
|
+
path: "/workflows/execute/activity",
|
|
4539
|
+
method: "POST",
|
|
4540
|
+
authenticated: true
|
|
4541
|
+
},
|
|
4542
|
+
getExecutionById: {
|
|
4543
|
+
path: "/workflows/run/{run_id}",
|
|
4544
|
+
method: "GET",
|
|
4545
|
+
authenticated: true
|
|
4546
|
+
},
|
|
4547
|
+
getIntegrations: {
|
|
4548
|
+
path: "/integrations",
|
|
4549
|
+
method: "GET",
|
|
4550
|
+
authenticated: true
|
|
4551
|
+
},
|
|
4552
|
+
getCredentials: {
|
|
4553
|
+
path: "/integrations/entity/{entity}",
|
|
4554
|
+
method: "GET",
|
|
4555
|
+
authenticated: true
|
|
4556
|
+
},
|
|
4557
|
+
getIntegrationResource: {
|
|
4558
|
+
path: "/integrations/{integration_slug}/schema",
|
|
4559
|
+
method: "GET",
|
|
4560
|
+
authenticated: true
|
|
4561
|
+
},
|
|
4562
|
+
getIntegrationForm: {
|
|
4563
|
+
path: "/integrations/{integration_slug}/fields",
|
|
4564
|
+
method: "GET",
|
|
4565
|
+
authenticated: true
|
|
4566
|
+
}
|
|
4567
|
+
};
|
|
4568
|
+
function buildWorkflowEndpointPath(endpoint, params = {}) {
|
|
4569
|
+
let path = endpoint.path;
|
|
4570
|
+
for (const [key, value] of Object.entries(params)) {
|
|
4571
|
+
path = path.replace(`{${key}}`, value);
|
|
4572
|
+
}
|
|
4573
|
+
return path;
|
|
4574
|
+
}
|
|
4575
|
+
class WorkflowApiClient extends BaseApiClient {
|
|
4576
|
+
constructor(apiKey, config = {}) {
|
|
4577
|
+
super(apiKey, config, SERVICE_PATHS.WORKFLOW_TEMPORAL);
|
|
4578
|
+
this.integrationBaseURL = this.resolveAdditionalServiceURL(
|
|
4579
|
+
SERVICE_PATHS.INTEGRATION
|
|
4580
|
+
);
|
|
4581
|
+
}
|
|
4582
|
+
/**
|
|
4583
|
+
* Execute a workflow activity.
|
|
4584
|
+
*
|
|
4585
|
+
* @param body - The execute-activity request body
|
|
4586
|
+
*/
|
|
4587
|
+
async executeActivity(body) {
|
|
4588
|
+
try {
|
|
4589
|
+
const endpoint = WORKFLOW_ENDPOINTS.executeActivity;
|
|
4590
|
+
const url = `${this.baseURL}${endpoint.path}`;
|
|
4591
|
+
const response = await this.httpAdapter.request({
|
|
4592
|
+
url,
|
|
4593
|
+
method: endpoint.method,
|
|
4594
|
+
headers: this.buildHeaders(),
|
|
4595
|
+
data: body,
|
|
4596
|
+
timeout: this.config.timeout
|
|
4597
|
+
});
|
|
4598
|
+
return response.data;
|
|
4599
|
+
} catch (error) {
|
|
4600
|
+
return this.formatErrorResponse(error, "WORKFLOW");
|
|
4601
|
+
}
|
|
4602
|
+
}
|
|
4603
|
+
/**
|
|
4604
|
+
* Fetch the result of a workflow execution by its run ID.
|
|
4605
|
+
*
|
|
4606
|
+
* @param runId - The execution run ID returned by `executeActivity`
|
|
4607
|
+
*/
|
|
4608
|
+
async getExecutionById(runId) {
|
|
4609
|
+
try {
|
|
4610
|
+
const endpoint = WORKFLOW_ENDPOINTS.getExecutionById;
|
|
4611
|
+
const path = buildWorkflowEndpointPath(endpoint, { run_id: runId });
|
|
4612
|
+
const url = `${this.baseURL}${path}`;
|
|
4613
|
+
const response = await this.httpAdapter.request({
|
|
4614
|
+
url,
|
|
4615
|
+
method: endpoint.method,
|
|
4616
|
+
headers: this.buildHeaders(),
|
|
4617
|
+
timeout: this.config.timeout
|
|
4618
|
+
});
|
|
4619
|
+
return response.data;
|
|
4620
|
+
} catch (error) {
|
|
4621
|
+
return this.formatErrorResponse(error, "WORKFLOW");
|
|
4622
|
+
}
|
|
4623
|
+
}
|
|
4624
|
+
/**
|
|
4625
|
+
* Fetch the list of available integrations.
|
|
4626
|
+
*
|
|
4627
|
+
* @param params - Optional pagination parameters
|
|
4628
|
+
*/
|
|
4629
|
+
async getIntegrations(params = {}) {
|
|
4630
|
+
try {
|
|
4631
|
+
const endpoint = WORKFLOW_ENDPOINTS.getIntegrations;
|
|
4632
|
+
const query = new URLSearchParams({
|
|
4633
|
+
page: String(params.page ?? 1),
|
|
4634
|
+
per_page: String(params.per_page ?? 999)
|
|
4635
|
+
});
|
|
4636
|
+
const url = `${this.baseURL}${endpoint.path}?${query.toString()}`;
|
|
4637
|
+
const response = await this.httpAdapter.request({
|
|
4638
|
+
url,
|
|
4639
|
+
method: endpoint.method,
|
|
4640
|
+
headers: this.buildHeaders(),
|
|
4641
|
+
timeout: this.config.timeout
|
|
4642
|
+
});
|
|
4643
|
+
return response.data;
|
|
4644
|
+
} catch (error) {
|
|
4645
|
+
return this.formatErrorResponse(error, "WORKFLOW");
|
|
4646
|
+
}
|
|
4647
|
+
}
|
|
4648
|
+
/**
|
|
4649
|
+
* Fetch credentials for a given integration entity.
|
|
4650
|
+
*
|
|
4651
|
+
* @param params - Entity name (required) and optional pagination
|
|
4652
|
+
*/
|
|
4653
|
+
async getCredentials(params) {
|
|
4654
|
+
try {
|
|
4655
|
+
const endpoint = WORKFLOW_ENDPOINTS.getCredentials;
|
|
4656
|
+
const path = buildWorkflowEndpointPath(endpoint, {
|
|
4657
|
+
entity: params.entity.toUpperCase()
|
|
4658
|
+
});
|
|
4659
|
+
const query = new URLSearchParams({
|
|
4660
|
+
current_page: String(params.current_page ?? 1),
|
|
4661
|
+
page_size: String(params.page_size ?? 999)
|
|
4662
|
+
});
|
|
4663
|
+
const url = `${this.integrationBaseURL}${path}?${query.toString()}`;
|
|
4664
|
+
const response = await this.httpAdapter.request({
|
|
4665
|
+
url,
|
|
4666
|
+
method: endpoint.method,
|
|
4667
|
+
headers: this.buildHeaders(),
|
|
4668
|
+
timeout: this.config.timeout
|
|
4669
|
+
});
|
|
4670
|
+
return response.data;
|
|
4671
|
+
} catch (error) {
|
|
4672
|
+
return this.formatErrorResponse(error, "INTEGRATION");
|
|
4673
|
+
}
|
|
4674
|
+
}
|
|
4675
|
+
/**
|
|
4676
|
+
* Fetch the resource/operation schema for an integration.
|
|
4677
|
+
*
|
|
4678
|
+
* @param params - Integration slug identifier
|
|
4679
|
+
*/
|
|
4680
|
+
async getIntegrationResource(params) {
|
|
4681
|
+
try {
|
|
4682
|
+
const endpoint = WORKFLOW_ENDPOINTS.getIntegrationResource;
|
|
4683
|
+
const path = buildWorkflowEndpointPath(endpoint, {
|
|
4684
|
+
integration_slug: params.integration_slug
|
|
4685
|
+
});
|
|
4686
|
+
const url = `${this.baseURL}${path}`;
|
|
4687
|
+
const response = await this.httpAdapter.request({
|
|
4688
|
+
url,
|
|
4689
|
+
method: endpoint.method,
|
|
4690
|
+
headers: this.buildHeaders(),
|
|
4691
|
+
timeout: this.config.timeout
|
|
4692
|
+
});
|
|
4693
|
+
return response.data;
|
|
4694
|
+
} catch (error) {
|
|
4695
|
+
return this.formatErrorResponse(error, "WORKFLOW");
|
|
4696
|
+
}
|
|
4697
|
+
}
|
|
4698
|
+
/**
|
|
4699
|
+
* Fetch the form schema (fields) for a specific integration resource + operation.
|
|
4700
|
+
*
|
|
4701
|
+
* @param params - Integration slug, resource, operation, and credential secret
|
|
4702
|
+
*/
|
|
4703
|
+
async getIntegrationForm(params) {
|
|
4704
|
+
try {
|
|
4705
|
+
const endpoint = WORKFLOW_ENDPOINTS.getIntegrationForm;
|
|
4706
|
+
const path = buildWorkflowEndpointPath(endpoint, {
|
|
4707
|
+
integration_slug: params.integration_slug
|
|
4708
|
+
});
|
|
4709
|
+
const query = new URLSearchParams({
|
|
4710
|
+
resource: params.resource,
|
|
4711
|
+
operation: params.operation,
|
|
4712
|
+
// getFormOnly: String(params.getFormOnly ?? true),
|
|
4713
|
+
secret: params.secret
|
|
4714
|
+
});
|
|
4715
|
+
const url = `${this.baseURL}${path}?${query.toString()}`;
|
|
4716
|
+
const response = await this.httpAdapter.request({
|
|
4717
|
+
url,
|
|
4718
|
+
method: endpoint.method,
|
|
4719
|
+
headers: this.buildHeaders(),
|
|
4720
|
+
timeout: this.config.timeout
|
|
4721
|
+
});
|
|
4722
|
+
return response.data;
|
|
4723
|
+
} catch (error) {
|
|
4724
|
+
return this.formatErrorResponse(error, "WORKFLOW");
|
|
4725
|
+
}
|
|
4726
|
+
}
|
|
4727
|
+
}
|
|
4728
|
+
const FORM_META_FIELDS = /* @__PURE__ */ new Set(["resource", "operation"]);
|
|
4729
|
+
function getSchemaMapping(displayType) {
|
|
4730
|
+
return SCHEMA_TYPE_MAPPING[displayType] ?? {
|
|
4731
|
+
type: "string",
|
|
4732
|
+
fallback_value: ""
|
|
4733
|
+
};
|
|
4734
|
+
}
|
|
4735
|
+
function transformFormToDefaults(fields, skipFields = FORM_META_FIELDS) {
|
|
4736
|
+
const result = {};
|
|
4737
|
+
for (const field of fields) {
|
|
4738
|
+
if (skipFields.has(field.name)) continue;
|
|
4739
|
+
const displayType = field.meta?.displayType || "text";
|
|
4740
|
+
const mapping = getSchemaMapping(displayType);
|
|
4741
|
+
result[field.name] = field.meta?.value !== void 0 ? field.meta.value : mapping.fallback_value;
|
|
4742
|
+
}
|
|
4743
|
+
return result;
|
|
4744
|
+
}
|
|
4745
|
+
function transformFormToJsonSchema(fields, skipFields = FORM_META_FIELDS) {
|
|
4746
|
+
const properties = {};
|
|
4747
|
+
for (const field of fields) {
|
|
4748
|
+
if (skipFields.has(field.name)) continue;
|
|
4749
|
+
const displayType = field.meta?.displayType || "text";
|
|
4750
|
+
const mapping = getSchemaMapping(displayType);
|
|
4751
|
+
const isRequired = field.meta?.validation?.required ?? false;
|
|
4752
|
+
const defaultValue = field.meta?.value !== void 0 ? field.meta.value : mapping.fallback_value;
|
|
4753
|
+
const prop = {
|
|
4754
|
+
type: mapping.type,
|
|
4755
|
+
required: isRequired,
|
|
4756
|
+
default: defaultValue
|
|
4757
|
+
};
|
|
4758
|
+
if (field.meta?.description) {
|
|
4759
|
+
prop.description = field.meta.description;
|
|
4760
|
+
}
|
|
4761
|
+
if (field.meta?.options && Array.isArray(field.meta.options) && field.meta.options.length > 0) {
|
|
4762
|
+
prop.enum = field.meta.options.map((opt) => opt.value);
|
|
4763
|
+
}
|
|
4764
|
+
properties[field.name] = prop;
|
|
4765
|
+
}
|
|
4766
|
+
return { type: "object", properties };
|
|
4767
|
+
}
|
|
4768
|
+
function buildDefaultResultPayload() {
|
|
4769
|
+
return {
|
|
4770
|
+
payload: {},
|
|
4771
|
+
global_variables: {}
|
|
4772
|
+
};
|
|
4773
|
+
}
|
|
4774
|
+
function buildExecuteActivityBody(params) {
|
|
4775
|
+
const node = {
|
|
4776
|
+
data: {
|
|
4777
|
+
type: params.data.type,
|
|
4778
|
+
name: params.data.name,
|
|
4779
|
+
properties: params.data.properties
|
|
4780
|
+
}
|
|
4781
|
+
};
|
|
4782
|
+
return {
|
|
4783
|
+
nodes: [node],
|
|
4784
|
+
result: params.result ?? buildDefaultResultPayload()
|
|
4785
|
+
};
|
|
4786
|
+
}
|
|
4787
|
+
function sleep(ms) {
|
|
4788
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4789
|
+
}
|
|
4790
|
+
class WorkflowResource extends BaseResource {
|
|
4791
|
+
constructor(client) {
|
|
4792
|
+
super(client, "/workflows");
|
|
4793
|
+
const config = client.getConfig();
|
|
4794
|
+
this.apiClient = new WorkflowApiClient(config.apiKey, {
|
|
4795
|
+
environment: config.environment,
|
|
4796
|
+
region: config.region,
|
|
4797
|
+
timeout: config.timeout,
|
|
4798
|
+
debug: config.debug
|
|
4799
|
+
});
|
|
4800
|
+
}
|
|
4801
|
+
/**
|
|
4802
|
+
* Execute a workflow integration activity.
|
|
4803
|
+
*
|
|
4804
|
+
* When `executeOnly` is `true`, returns the immediate API response.
|
|
4805
|
+
* When `executeOnly` is `false` (default), polls until a terminal state
|
|
4806
|
+
* is reached and returns the final execution result.
|
|
4807
|
+
*
|
|
4808
|
+
* @param params - Execution parameters
|
|
4809
|
+
* @returns The execute response or the final polled result
|
|
4810
|
+
*
|
|
4811
|
+
* @example
|
|
4812
|
+
* ```typescript
|
|
4813
|
+
* const result = await client.workflow.executeIntegration({
|
|
4814
|
+
* data: { type: 'apiActivity', name: 'api1', properties: { method: 'get', endpoint: '...' } },
|
|
4815
|
+
* });
|
|
4816
|
+
*
|
|
4817
|
+
* const fire = await client.workflow.executeIntegration({
|
|
4818
|
+
* data: { type: 'apiActivity', name: 'api1', properties: { method: 'get', endpoint: '...' } },
|
|
4819
|
+
* executeOnly: true,
|
|
4820
|
+
* });
|
|
4821
|
+
* ```
|
|
4822
|
+
*/
|
|
4823
|
+
async executeIntegration(params) {
|
|
4824
|
+
const body = buildExecuteActivityBody(params);
|
|
4825
|
+
const executeResult = await this.apiClient.executeActivity(body);
|
|
4826
|
+
if (isErrorResponse(executeResult)) {
|
|
4827
|
+
return executeResult;
|
|
4828
|
+
}
|
|
4829
|
+
if (params.executeOnly) {
|
|
4830
|
+
return executeResult;
|
|
4831
|
+
}
|
|
4832
|
+
const executionId = executeResult.data?.execution_id;
|
|
4833
|
+
if (!executionId) {
|
|
4834
|
+
return {
|
|
4835
|
+
error: {
|
|
4836
|
+
code: "MISSING_EXECUTION_ID",
|
|
4837
|
+
message: "Execute API response did not contain an execution_id",
|
|
4838
|
+
meta: []
|
|
4839
|
+
}
|
|
4840
|
+
};
|
|
4841
|
+
}
|
|
4842
|
+
return this.pollExecution(executionId);
|
|
4843
|
+
}
|
|
4844
|
+
/**
|
|
4845
|
+
* Retrieve the result of a workflow execution by its run/execution ID.
|
|
4846
|
+
*
|
|
4847
|
+
* @param executionId - The execution run ID
|
|
4848
|
+
* @returns The execution data or an error response
|
|
4849
|
+
*
|
|
4850
|
+
* @example
|
|
4851
|
+
* ```typescript
|
|
4852
|
+
* const result = await client.workflow.getIntegrationExecuteById('run-uuid');
|
|
4853
|
+
* ```
|
|
4854
|
+
*/
|
|
4855
|
+
async getIntegrationExecuteById(executionId) {
|
|
4856
|
+
return this.apiClient.getExecutionById(executionId);
|
|
4857
|
+
}
|
|
4858
|
+
/**
|
|
4859
|
+
* Fetch the list of available integrations.
|
|
4860
|
+
*
|
|
4861
|
+
* @param params - Optional pagination parameters (`page`, `per_page`)
|
|
4862
|
+
* @returns The integrations list or an error response
|
|
4863
|
+
*
|
|
4864
|
+
* @example
|
|
4865
|
+
* ```typescript
|
|
4866
|
+
* const list = await client.workflow.getIntegrations();
|
|
4867
|
+
* ```
|
|
4868
|
+
*/
|
|
4869
|
+
async getIntegrations(params = {}) {
|
|
4870
|
+
return this.apiClient.getIntegrations(params);
|
|
4871
|
+
}
|
|
4872
|
+
/**
|
|
4873
|
+
* Fetch credentials for a given integration entity.
|
|
4874
|
+
*
|
|
4875
|
+
* @param params - Entity name (required), optional `current_page` and `page_size`
|
|
4876
|
+
* @returns The credentials list or an error response
|
|
4877
|
+
*
|
|
4878
|
+
* @example
|
|
4879
|
+
* ```typescript
|
|
4880
|
+
* const creds = await client.workflow.getCredentials({ entity: 'freshsales' });
|
|
4881
|
+
* ```
|
|
4882
|
+
*/
|
|
4883
|
+
async getCredentials(params) {
|
|
4884
|
+
return this.apiClient.getCredentials(params);
|
|
4885
|
+
}
|
|
4886
|
+
/**
|
|
4887
|
+
* Fetch the resource/operation schema for an integration.
|
|
4888
|
+
*
|
|
4889
|
+
* Returns the available resources and operations supported by the
|
|
4890
|
+
* specified integration (e.g. which resources like "task", "project"
|
|
4891
|
+
* are available and what operations can be performed on them).
|
|
4892
|
+
*
|
|
4893
|
+
* @param params - Integration slug identifier
|
|
4894
|
+
* @returns The integration resource schema or an error response
|
|
4895
|
+
*
|
|
4896
|
+
* @example
|
|
4897
|
+
* ```typescript
|
|
4898
|
+
* const schema = await client.workflow.getIntegrationResource({
|
|
4899
|
+
* integration_slug: 'blt-int.asana',
|
|
4900
|
+
* });
|
|
4901
|
+
* ```
|
|
4902
|
+
*/
|
|
4903
|
+
async getIntegrationResource(params) {
|
|
4904
|
+
return this.apiClient.getIntegrationResource(params);
|
|
4905
|
+
}
|
|
4906
|
+
/**
|
|
4907
|
+
* Fetch the form schema (fields) for a specific integration resource + operation.
|
|
4908
|
+
*
|
|
4909
|
+
* By default, returns a flat JSON object with default/fallback values
|
|
4910
|
+
* for each input field. Set `asJsonSchema: true` to get a JSON Schema
|
|
4911
|
+
* object describing the expected input shape instead.
|
|
4912
|
+
*
|
|
4913
|
+
* Fields like `resource` and `operation` are automatically excluded
|
|
4914
|
+
* since they are already handled by the SDK parameters. The `secret`
|
|
4915
|
+
* field is included and populated with the value from `params.secret`.
|
|
4916
|
+
*
|
|
4917
|
+
* @param params - Integration slug, resource, operation, credential secret, and format flag
|
|
4918
|
+
* @returns Transformed form data or an error response
|
|
4919
|
+
*
|
|
4920
|
+
* @example
|
|
4921
|
+
* ```typescript
|
|
4922
|
+
* // Get flat defaults: { name: '', workspace: [], team: '', ... }
|
|
4923
|
+
* const defaults = await client.workflow.getIntegrationForm({
|
|
4924
|
+
* integration_slug: 'blt-int.asana',
|
|
4925
|
+
* resource: 'project',
|
|
4926
|
+
* operation: 'create',
|
|
4927
|
+
* secret: 'credential-secret-here',
|
|
4928
|
+
* });
|
|
4929
|
+
*
|
|
4930
|
+
* // Get JSON Schema: { type: 'object', properties: { name: { type: 'string', ... } } }
|
|
4931
|
+
* const schema = await client.workflow.getIntegrationForm({
|
|
4932
|
+
* integration_slug: 'blt-int.asana',
|
|
4933
|
+
* resource: 'project',
|
|
4934
|
+
* operation: 'create',
|
|
4935
|
+
* secret: 'credential-secret-here',
|
|
4936
|
+
* asJsonSchema: true,
|
|
4937
|
+
* });
|
|
4938
|
+
* ```
|
|
4939
|
+
*/
|
|
4940
|
+
async getIntegrationForm(params) {
|
|
4941
|
+
const rawResult = await this.apiClient.getIntegrationForm(params);
|
|
4942
|
+
console.log("rawResult", JSON.stringify(rawResult, null, 2));
|
|
4943
|
+
if (isErrorResponse(rawResult)) {
|
|
4944
|
+
return rawResult;
|
|
4945
|
+
}
|
|
4946
|
+
const configuration = rawResult.data?.parameters || rawResult.data;
|
|
4947
|
+
const fields = configuration ?? [];
|
|
4948
|
+
const transformed = params.asJsonSchema ? transformFormToJsonSchema(fields) : transformFormToDefaults(fields);
|
|
4949
|
+
if (params.asJsonSchema) {
|
|
4950
|
+
const schema = transformed;
|
|
4951
|
+
if (schema.properties.secret) {
|
|
4952
|
+
schema.properties.secret.default = params.secret;
|
|
4953
|
+
}
|
|
4954
|
+
} else {
|
|
4955
|
+
const defaults = transformed;
|
|
4956
|
+
if ("secret" in defaults) {
|
|
4957
|
+
defaults.secret = params.secret;
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4960
|
+
return {
|
|
4961
|
+
data: transformed,
|
|
4962
|
+
message: rawResult.message
|
|
4963
|
+
};
|
|
4964
|
+
}
|
|
4965
|
+
/**
|
|
4966
|
+
* Internal polling loop.
|
|
4967
|
+
* Repeatedly calls `getExecutionById` until the response `data` object is
|
|
4968
|
+
* non-empty (execution finished) or max attempts are exhausted.
|
|
4969
|
+
*/
|
|
4970
|
+
async pollExecution(executionId) {
|
|
4971
|
+
const debug = this.client.getConfig().debug;
|
|
4972
|
+
for (let attempt = 0; attempt < MAX_POLLING_ATTEMPTS; attempt++) {
|
|
4973
|
+
const result = await this.apiClient.getExecutionById(executionId);
|
|
4974
|
+
if (isErrorResponse(result)) {
|
|
4975
|
+
return result;
|
|
4976
|
+
}
|
|
4977
|
+
if (result.data && Object.keys(result.data).length > 0) {
|
|
4978
|
+
if (debug) {
|
|
4979
|
+
console.log(
|
|
4980
|
+
`[WorkflowResource] Execution ${executionId} completed after ${attempt + 1} poll(s)`
|
|
4981
|
+
);
|
|
4982
|
+
}
|
|
4983
|
+
return result;
|
|
4984
|
+
}
|
|
4985
|
+
await sleep(POLLING_INTERVAL_MS);
|
|
4986
|
+
}
|
|
4987
|
+
return {
|
|
4988
|
+
error: {
|
|
4989
|
+
code: "EXECUTION_TIMEOUT",
|
|
4990
|
+
message: `Execution ${executionId} did not complete within ${MAX_POLLING_ATTEMPTS} polling attempts`,
|
|
4991
|
+
meta: [
|
|
4992
|
+
`execution_id: ${executionId}`,
|
|
4993
|
+
`max_attempts: ${MAX_POLLING_ATTEMPTS}`
|
|
4994
|
+
]
|
|
4995
|
+
}
|
|
4996
|
+
};
|
|
4997
|
+
}
|
|
4998
|
+
}
|
|
4828
4999
|
class BolticClient {
|
|
4829
5000
|
constructor(apiKey, options = {}) {
|
|
4830
5001
|
this.currentDatabase = null;
|
|
@@ -4847,6 +5018,7 @@ class BolticClient {
|
|
|
4847
5018
|
this.sqlResource = new SqlResource(this.baseClient);
|
|
4848
5019
|
this.indexResource = new IndexResource(this.baseClient);
|
|
4849
5020
|
this.databaseResource = new DatabaseResource(this.baseClient);
|
|
5021
|
+
this.workflowResource = new WorkflowResource(this.baseClient);
|
|
4850
5022
|
this.currentDatabase = null;
|
|
4851
5023
|
}
|
|
4852
5024
|
/**
|
|
@@ -4916,8 +5088,7 @@ class BolticClient {
|
|
|
4916
5088
|
findOne: (options) => this.tableResource.findOne(options, dbId),
|
|
4917
5089
|
update: (name, data) => this.tableResource.update(name, data, dbId),
|
|
4918
5090
|
delete: (name) => this.tableResource.delete(name, dbId),
|
|
4919
|
-
rename: (oldName, newName) => this.tableResource.rename(oldName, newName, dbId)
|
|
4920
|
-
setAccess: (request) => this.tableResource.setAccess(request, dbId)
|
|
5091
|
+
rename: (oldName, newName) => this.tableResource.rename(oldName, newName, dbId)
|
|
4921
5092
|
};
|
|
4922
5093
|
}
|
|
4923
5094
|
// Direct column operations
|
|
@@ -5002,6 +5173,33 @@ class BolticClient {
|
|
|
5002
5173
|
executeSQL: (query) => this.sqlResource.executeSQL(query, dbId)
|
|
5003
5174
|
};
|
|
5004
5175
|
}
|
|
5176
|
+
/**
|
|
5177
|
+
* Workflow integration operations.
|
|
5178
|
+
*
|
|
5179
|
+
* @example
|
|
5180
|
+
* ```typescript
|
|
5181
|
+
* // Execute and poll for result
|
|
5182
|
+
* const result = await client.workflow.executeIntegration({
|
|
5183
|
+
* nodes: [{ id: 'api1', data: { ... }, activity_data: { ... } }],
|
|
5184
|
+
* });
|
|
5185
|
+
*
|
|
5186
|
+
* // Get execution result by ID
|
|
5187
|
+
* const exec = await client.workflow.getIntegrationExecuteById('run-uuid');
|
|
5188
|
+
*
|
|
5189
|
+
* // List integrations
|
|
5190
|
+
* const integrations = await client.workflow.getIntegrations();
|
|
5191
|
+
* ```
|
|
5192
|
+
*/
|
|
5193
|
+
get workflow() {
|
|
5194
|
+
return {
|
|
5195
|
+
executeIntegration: (params) => this.workflowResource.executeIntegration(params),
|
|
5196
|
+
getIntegrationExecuteById: (executionId) => this.workflowResource.getIntegrationExecuteById(executionId),
|
|
5197
|
+
getIntegrations: (params) => this.workflowResource.getIntegrations(params),
|
|
5198
|
+
getCredentials: (params) => this.workflowResource.getCredentials(params),
|
|
5199
|
+
getIntegrationResource: (params) => this.workflowResource.getIntegrationResource(params),
|
|
5200
|
+
getIntegrationForm: (params) => this.workflowResource.getIntegrationForm(params)
|
|
5201
|
+
};
|
|
5202
|
+
}
|
|
5005
5203
|
// SQL resource access for testing
|
|
5006
5204
|
getSqlResource() {
|
|
5007
5205
|
return this.sqlResource;
|
|
@@ -5084,6 +5282,7 @@ class BolticClient {
|
|
|
5084
5282
|
this.sqlResource = new SqlResource(this.baseClient);
|
|
5085
5283
|
this.indexResource = new IndexResource(this.baseClient);
|
|
5086
5284
|
this.databaseResource = new DatabaseResource(this.baseClient);
|
|
5285
|
+
this.workflowResource = new WorkflowResource(this.baseClient);
|
|
5087
5286
|
}
|
|
5088
5287
|
// Security methods to prevent API key exposure
|
|
5089
5288
|
toString() {
|
|
@@ -5112,13 +5311,18 @@ const VERSION = "1.0.0";
|
|
|
5112
5311
|
export {
|
|
5113
5312
|
AuthManager$1 as AuthManager,
|
|
5114
5313
|
BolticClient,
|
|
5314
|
+
SERVICE_PATHS,
|
|
5115
5315
|
VERSION,
|
|
5316
|
+
WorkflowResource,
|
|
5116
5317
|
createClient,
|
|
5117
5318
|
createErrorWithContext$1 as createErrorWithContext,
|
|
5118
5319
|
formatError$1 as formatError,
|
|
5119
5320
|
getHttpStatusCode$1 as getHttpStatusCode,
|
|
5120
5321
|
isErrorResponse,
|
|
5121
5322
|
isListResponse,
|
|
5122
|
-
isNetworkError
|
|
5323
|
+
isNetworkError,
|
|
5324
|
+
resolveServiceURL,
|
|
5325
|
+
transformFormToDefaults,
|
|
5326
|
+
transformFormToJsonSchema
|
|
5123
5327
|
};
|
|
5124
5328
|
//# sourceMappingURL=sdk.mjs.map
|