@fusebase/fusebase-gate-sdk 1.0.2-sdk.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/README.md +52 -0
- package/dist/apis/CustomDashboardRowsApi.d.ts +113 -0
- package/dist/apis/CustomDashboardRowsApi.js +122 -0
- package/dist/apis/DashboardDataApi.d.ts +98 -0
- package/dist/apis/DashboardDataApi.js +91 -0
- package/dist/apis/DashboardRelationsApi.d.ts +92 -0
- package/dist/apis/DashboardRelationsApi.js +117 -0
- package/dist/apis/DashboardsApi.d.ts +405 -0
- package/dist/apis/DashboardsApi.js +507 -0
- package/dist/apis/DatabasesApi.d.ts +134 -0
- package/dist/apis/DatabasesApi.js +162 -0
- package/dist/apis/HealthApi.d.ts +19 -0
- package/dist/apis/HealthApi.js +28 -0
- package/dist/apis/OrgUsersApi.d.ts +22 -0
- package/dist/apis/OrgUsersApi.js +29 -0
- package/dist/apis/ResolveApi.d.ts +20 -0
- package/dist/apis/ResolveApi.js +29 -0
- package/dist/apis/TemplatesApi.d.ts +100 -0
- package/dist/apis/TemplatesApi.js +124 -0
- package/dist/apis/TokensApi.d.ts +71 -0
- package/dist/apis/TokensApi.js +95 -0
- package/dist/extras/fetchWithRetry.d.ts +30 -0
- package/dist/extras/fetchWithRetry.js +53 -0
- package/dist/extras/messaging.d.ts +81 -0
- package/dist/extras/messaging.js +16 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +31 -0
- package/dist/runtime/index.d.ts +5 -0
- package/dist/runtime/index.js +21 -0
- package/dist/runtime/transport.d.ts +28 -0
- package/dist/runtime/transport.js +237 -0
- package/dist/runtime/types.d.ts +52 -0
- package/dist/runtime/types.js +23 -0
- package/dist/types/common/portal-form.d.ts +14 -0
- package/dist/types/common/portal-form.js +8 -0
- package/dist/types/dashboard/custom-item.d.ts +53 -0
- package/dist/types/dashboard/custom-item.js +22 -0
- package/dist/types/dashboard/dashboard.d.ts +421 -0
- package/dist/types/dashboard/dashboard.js +8 -0
- package/dist/types/dashboard/dashboards.d.ts +19 -0
- package/dist/types/dashboard/dashboards.js +8 -0
- package/dist/types/dashboard/data.d.ts +10 -0
- package/dist/types/dashboard/data.js +8 -0
- package/dist/types/dashboard/export.d.ts +11 -0
- package/dist/types/dashboard/export.js +8 -0
- package/dist/types/dashboard/index.d.ts +215 -0
- package/dist/types/dashboard/index.js +34 -0
- package/dist/types/dashboard/intent.d.ts +243 -0
- package/dist/types/dashboard/intent.js +8 -0
- package/dist/types/dashboard/items.d.ts +14 -0
- package/dist/types/dashboard/items.js +8 -0
- package/dist/types/dashboard/metadata.d.ts +12 -0
- package/dist/types/dashboard/metadata.js +8 -0
- package/dist/types/dashboard/render.d.ts +188 -0
- package/dist/types/dashboard/render.js +51 -0
- package/dist/types/dashboard/rows.d.ts +77 -0
- package/dist/types/dashboard/rows.js +14 -0
- package/dist/types/dashboard/schema.d.ts +172 -0
- package/dist/types/dashboard/schema.js +17 -0
- package/dist/types/dashboard/values.d.ts +187 -0
- package/dist/types/dashboard/values.js +8 -0
- package/dist/types/dashboard/view.d.ts +249 -0
- package/dist/types/dashboard/view.js +8 -0
- package/dist/types/database/database.d.ts +203 -0
- package/dist/types/database/database.js +8 -0
- package/dist/types/database/export.d.ts +11 -0
- package/dist/types/database/export.js +8 -0
- package/dist/types/index.d.ts +31 -0
- package/dist/types/index.js +30 -0
- package/dist/types/org-user/org-user.d.ts +19 -0
- package/dist/types/org-user/org-user.js +6 -0
- package/dist/types/relations/relations.d.ts +138 -0
- package/dist/types/relations/relations.js +14 -0
- package/dist/types/resolve/resolve.d.ts +86 -0
- package/dist/types/resolve/resolve.js +20 -0
- package/dist/types/shared/common.d.ts +122 -0
- package/dist/types/shared/common.js +24 -0
- package/dist/types/shared/enums.d.ts +64 -0
- package/dist/types/shared/enums.js +52 -0
- package/dist/types/shared/health.d.ts +12 -0
- package/dist/types/shared/health.js +8 -0
- package/dist/types/shared/parameters.d.ts +95 -0
- package/dist/types/shared/parameters.js +2 -0
- package/dist/types/template/template.d.ts +74 -0
- package/dist/types/template/template.js +8 -0
- package/dist/types/token/token.d.ts +184 -0
- package/dist/types/token/token.js +8 -0
- package/package.json +16 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Tokens API
|
|
4
|
+
*
|
|
5
|
+
* Generated from contract introspection
|
|
6
|
+
* Domain: tokens
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.TokensApi = void 0;
|
|
10
|
+
class TokensApi {
|
|
11
|
+
constructor(client) {
|
|
12
|
+
this.client = client;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Create a new API token
|
|
16
|
+
* Create a new API token with specified scopes and permissions.
|
|
17
|
+
* The token value is only returned once on creation - store it securely.
|
|
18
|
+
* At least one org scope is required in the scopes array.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
21
|
+
async createToken(params) {
|
|
22
|
+
return this.client.request({
|
|
23
|
+
method: "POST",
|
|
24
|
+
path: "/tokens",
|
|
25
|
+
headers: params.headers,
|
|
26
|
+
body: params.body,
|
|
27
|
+
opId: "createToken",
|
|
28
|
+
expectedContentType: "application/json",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get token by ID
|
|
33
|
+
* Retrieve details of a specific API token by its global ID
|
|
34
|
+
*/
|
|
35
|
+
async getToken(params) {
|
|
36
|
+
return this.client.request({
|
|
37
|
+
method: "GET",
|
|
38
|
+
path: "/tokens/:tokenId",
|
|
39
|
+
pathParams: params.path,
|
|
40
|
+
headers: params.headers,
|
|
41
|
+
opId: "getToken",
|
|
42
|
+
expectedContentType: "application/json",
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* List user's API tokens
|
|
47
|
+
* Retrieve a list of all API tokens for the authenticated user.
|
|
48
|
+
* Optionally filter by scope type and scope ID (both must be provided together).
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
async listTokens(params) {
|
|
52
|
+
return this.client.request({
|
|
53
|
+
method: "GET",
|
|
54
|
+
path: "/tokens",
|
|
55
|
+
query: params.query,
|
|
56
|
+
headers: params.headers,
|
|
57
|
+
opId: "listTokens",
|
|
58
|
+
expectedContentType: "application/json",
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Revoke token
|
|
63
|
+
* Permanently revoke (soft delete) an API token.
|
|
64
|
+
* Once revoked, the token can no longer be used for authentication.
|
|
65
|
+
*
|
|
66
|
+
*/
|
|
67
|
+
async revokeToken(params) {
|
|
68
|
+
return this.client.request({
|
|
69
|
+
method: "DELETE",
|
|
70
|
+
path: "/tokens/:tokenId",
|
|
71
|
+
pathParams: params.path,
|
|
72
|
+
headers: params.headers,
|
|
73
|
+
opId: "revokeToken",
|
|
74
|
+
expectedContentType: "application/json",
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Update token
|
|
79
|
+
* Update token properties (name, permissions, expiration).
|
|
80
|
+
* Note: The token value itself cannot be changed.
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
async updateToken(params) {
|
|
84
|
+
return this.client.request({
|
|
85
|
+
method: "PUT",
|
|
86
|
+
path: "/tokens/:tokenId",
|
|
87
|
+
pathParams: params.path,
|
|
88
|
+
headers: params.headers,
|
|
89
|
+
body: params.body,
|
|
90
|
+
opId: "updateToken",
|
|
91
|
+
expectedContentType: "application/json",
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.TokensApi = TokensApi;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export type FetchLike = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
2
|
+
type BackoffValue = number | ((attempt: number, response?: Response | undefined, error?: unknown) => number);
|
|
3
|
+
export interface RetryOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Number of retry attempts after the initial request.
|
|
6
|
+
* A value of 0 disables retries.
|
|
7
|
+
* @default 3
|
|
8
|
+
*/
|
|
9
|
+
retries?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Static or dynamic backoff duration (ms) between retries.
|
|
12
|
+
* When a function is provided, it receives the current attempt index (starting at 1),
|
|
13
|
+
* the last failing response (if any), and the last thrown error (if any).
|
|
14
|
+
* @default attempt => Math.min(1000 * 2 ** attempt, 30000)
|
|
15
|
+
*/
|
|
16
|
+
backoffMs?: BackoffValue;
|
|
17
|
+
/**
|
|
18
|
+
* Predicate that determines whether a response should be retried.
|
|
19
|
+
* Throwing inside this function will abort the retry loop.
|
|
20
|
+
* @default status >= 500 && status < 600
|
|
21
|
+
*/
|
|
22
|
+
shouldRetry?: (response: Response) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Optional guard to abort retrying on specific errors (network, abort, etc.).
|
|
25
|
+
* Return true to continue retrying, false to rethrow immediately.
|
|
26
|
+
*/
|
|
27
|
+
shouldRetryError?: (error: unknown) => boolean;
|
|
28
|
+
}
|
|
29
|
+
export declare function createFetchWithRetry(baseFetch: FetchLike, { retries, backoffMs, shouldRetry, shouldRetryError, }?: RetryOptions): FetchLike;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createFetchWithRetry = createFetchWithRetry;
|
|
4
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
5
|
+
const defaultShouldRetry = (response) => response.status >= 500 && response.status < 600;
|
|
6
|
+
const defaultBackoff = (attempt) => Math.min(1000 * 2 ** attempt, 30000);
|
|
7
|
+
const shouldRetryNetworkError = (error) => {
|
|
8
|
+
if (error == null) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
if (typeof error !== "object") {
|
|
12
|
+
return true;
|
|
13
|
+
}
|
|
14
|
+
if (error.name === "AbortError") {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
function createFetchWithRetry(baseFetch, { retries = 3, backoffMs = defaultBackoff, shouldRetry = defaultShouldRetry, shouldRetryError = shouldRetryNetworkError, } = {}) {
|
|
20
|
+
return async (input, init) => {
|
|
21
|
+
const originalRequest = input instanceof Request ? input : new Request(input, init);
|
|
22
|
+
let lastError;
|
|
23
|
+
let lastResponse;
|
|
24
|
+
for (let attempt = 0; attempt <= retries; attempt++) {
|
|
25
|
+
if (attempt > 0) {
|
|
26
|
+
const wait = typeof backoffMs === "function"
|
|
27
|
+
? backoffMs(attempt, lastResponse, lastError)
|
|
28
|
+
: backoffMs;
|
|
29
|
+
if (wait > 0) {
|
|
30
|
+
console.log(`Waiting ${wait}ms before next attempt #${attempt}, ${lastError instanceof Error ? lastError.message : "unknown error"}`);
|
|
31
|
+
await sleep(wait);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
try {
|
|
35
|
+
const response = await baseFetch(originalRequest.clone());
|
|
36
|
+
if (!shouldRetry(response) || attempt === retries) {
|
|
37
|
+
return response;
|
|
38
|
+
}
|
|
39
|
+
lastResponse = response;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
lastError = error;
|
|
43
|
+
if (!shouldRetryError(error) || attempt === retries) {
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
// Should never reach here, but TypeScript needs a final throw.
|
|
49
|
+
throw lastError instanceof Error
|
|
50
|
+
? lastError
|
|
51
|
+
: new Error("createFetchWithRetry exhausted all retries without a terminal condition");
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base event interface
|
|
3
|
+
* All events must extend this interface
|
|
4
|
+
*/
|
|
5
|
+
export interface EventBase<T extends string = string, P = unknown> {
|
|
6
|
+
type: T;
|
|
7
|
+
payload: P;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Dashboard event types
|
|
11
|
+
*/
|
|
12
|
+
export declare const EVENTS: {
|
|
13
|
+
readonly DATABASE_CREATED: "database:created";
|
|
14
|
+
readonly DASHBOARD_CREATED: "dashboard:created";
|
|
15
|
+
readonly DASHBOARD_DELETED: "dashboard:deleted";
|
|
16
|
+
readonly DASHBOARD_ROW_CREATED: "dashboard:row_created";
|
|
17
|
+
readonly DASHBOARD_ROW_COLUMN_UPDATED: "dashboard:row_column_updated";
|
|
18
|
+
readonly DASHBOARD_RELATION_UPDATED: "dashboard:relation_updated";
|
|
19
|
+
readonly DASHBOARD_RELATION_DELETED: "dashboard:relation_deleted";
|
|
20
|
+
};
|
|
21
|
+
export type DashboardEventType = (typeof EVENTS)[keyof typeof EVENTS];
|
|
22
|
+
/**
|
|
23
|
+
* Event payload interfaces
|
|
24
|
+
*/
|
|
25
|
+
export interface DatabaseCreatedPayload {
|
|
26
|
+
orgId: string;
|
|
27
|
+
databaseId: string;
|
|
28
|
+
}
|
|
29
|
+
export interface DashboardCreatedPayload {
|
|
30
|
+
orgId: string;
|
|
31
|
+
dashboardId: string;
|
|
32
|
+
databaseId?: string;
|
|
33
|
+
}
|
|
34
|
+
export interface DashboardRowCreatedPayload {
|
|
35
|
+
orgId: string;
|
|
36
|
+
dashboardId: string;
|
|
37
|
+
rowUuids: string[];
|
|
38
|
+
}
|
|
39
|
+
export interface DashboardRowColumnUpdatedPayload {
|
|
40
|
+
orgId: string;
|
|
41
|
+
dashboardId: string;
|
|
42
|
+
viewId: string;
|
|
43
|
+
rootIndexValue: string;
|
|
44
|
+
itemKey: string;
|
|
45
|
+
valueBefore: null | string | number | boolean | object | Date;
|
|
46
|
+
alias: null | string;
|
|
47
|
+
render: {
|
|
48
|
+
type: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface DashboardRelationPayload {
|
|
52
|
+
globalId: string;
|
|
53
|
+
sourceDashboardId: string;
|
|
54
|
+
targetDashboardId: string;
|
|
55
|
+
beforeRows: object[];
|
|
56
|
+
afterRows: object[];
|
|
57
|
+
}
|
|
58
|
+
export interface DashboardDeletedPayload {
|
|
59
|
+
dashboardId: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Event interfaces
|
|
63
|
+
*/
|
|
64
|
+
export type DatabaseCreatedEvent = EventBase<typeof EVENTS.DATABASE_CREATED, DatabaseCreatedPayload>;
|
|
65
|
+
export type DashboardCreatedEvent = EventBase<typeof EVENTS.DASHBOARD_CREATED, DashboardCreatedPayload>;
|
|
66
|
+
export type DashboardRowCreatedEvent = EventBase<typeof EVENTS.DASHBOARD_ROW_CREATED, DashboardRowCreatedPayload>;
|
|
67
|
+
export type DashboardRowColumnUpdatedEvent = EventBase<typeof EVENTS.DASHBOARD_RELATION_UPDATED, DashboardRowColumnUpdatedPayload>;
|
|
68
|
+
export type DashboardRelationUpdatedEvent = EventBase<typeof EVENTS.DASHBOARD_RELATION_DELETED, DashboardRelationPayload>;
|
|
69
|
+
export type DashboardRelationDeletedEvent = EventBase<typeof EVENTS.DASHBOARD_ROW_COLUMN_UPDATED, DashboardRelationPayload>;
|
|
70
|
+
export type DashboardDeletedEvent = EventBase<typeof EVENTS.DASHBOARD_DELETED, DashboardDeletedPayload>;
|
|
71
|
+
/**
|
|
72
|
+
* Union type of all dashboard events
|
|
73
|
+
* Will be extended when more events are added
|
|
74
|
+
*/
|
|
75
|
+
export type DashboardEvent = DatabaseCreatedEvent | DashboardCreatedEvent | DashboardRowCreatedEvent | DashboardRowColumnUpdatedEvent | DashboardDeletedEvent | DashboardRelationUpdatedEvent | DashboardRelationDeletedEvent;
|
|
76
|
+
/**
|
|
77
|
+
* Helper: Extract payload type by event type string
|
|
78
|
+
*/
|
|
79
|
+
export type DashboardEventPayload<T extends DashboardEvent["type"]> = Extract<DashboardEvent, {
|
|
80
|
+
type: T;
|
|
81
|
+
}>["payload"];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Do not import anything in this file, messaging.ts copy in sdk-client
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.EVENTS = void 0;
|
|
5
|
+
/**
|
|
6
|
+
* Dashboard event types
|
|
7
|
+
*/
|
|
8
|
+
exports.EVENTS = {
|
|
9
|
+
DATABASE_CREATED: "database:created",
|
|
10
|
+
DASHBOARD_CREATED: "dashboard:created",
|
|
11
|
+
DASHBOARD_DELETED: "dashboard:deleted",
|
|
12
|
+
DASHBOARD_ROW_CREATED: "dashboard:row_created",
|
|
13
|
+
DASHBOARD_ROW_COLUMN_UPDATED: "dashboard:row_column_updated",
|
|
14
|
+
DASHBOARD_RELATION_UPDATED: "dashboard:relation_updated",
|
|
15
|
+
DASHBOARD_RELATION_DELETED: "dashboard:relation_deleted",
|
|
16
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SDK Client
|
|
3
|
+
*
|
|
4
|
+
* Generated from contract introspection
|
|
5
|
+
*/
|
|
6
|
+
export * from "./runtime";
|
|
7
|
+
export * from "./types";
|
|
8
|
+
export { HealthApi } from "./apis/HealthApi";
|
|
9
|
+
export { OrgUsersApi } from "./apis/OrgUsersApi";
|
|
10
|
+
export { TokensApi } from "./apis/TokensApi";
|
|
11
|
+
export * from "./extras/fetchWithRetry";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* SDK Client
|
|
4
|
+
*
|
|
5
|
+
* Generated from contract introspection
|
|
6
|
+
*/
|
|
7
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
8
|
+
if (k2 === undefined) k2 = k;
|
|
9
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
10
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
11
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
12
|
+
}
|
|
13
|
+
Object.defineProperty(o, k2, desc);
|
|
14
|
+
}) : (function(o, m, k, k2) {
|
|
15
|
+
if (k2 === undefined) k2 = k;
|
|
16
|
+
o[k2] = m[k];
|
|
17
|
+
}));
|
|
18
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.TokensApi = exports.OrgUsersApi = exports.HealthApi = void 0;
|
|
23
|
+
__exportStar(require("./runtime"), exports);
|
|
24
|
+
__exportStar(require("./types"), exports);
|
|
25
|
+
var HealthApi_1 = require("./apis/HealthApi");
|
|
26
|
+
Object.defineProperty(exports, "HealthApi", { enumerable: true, get: function () { return HealthApi_1.HealthApi; } });
|
|
27
|
+
var OrgUsersApi_1 = require("./apis/OrgUsersApi");
|
|
28
|
+
Object.defineProperty(exports, "OrgUsersApi", { enumerable: true, get: function () { return OrgUsersApi_1.OrgUsersApi; } });
|
|
29
|
+
var TokensApi_1 = require("./apis/TokensApi");
|
|
30
|
+
Object.defineProperty(exports, "TokensApi", { enumerable: true, get: function () { return TokensApi_1.TokensApi; } });
|
|
31
|
+
__exportStar(require("./extras/fetchWithRetry"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
/**
|
|
18
|
+
* Runtime exports
|
|
19
|
+
*/
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./transport"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime transport for SDK
|
|
3
|
+
* Generated by SDK codegen
|
|
4
|
+
*/
|
|
5
|
+
import { type ClientConfig } from "./types";
|
|
6
|
+
/**
|
|
7
|
+
* Request options for transport layer
|
|
8
|
+
*/
|
|
9
|
+
export interface RequestOptions {
|
|
10
|
+
method: string;
|
|
11
|
+
path: string;
|
|
12
|
+
pathParams?: Record<string, string | number>;
|
|
13
|
+
query?: Record<string, unknown>;
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
body?: unknown;
|
|
16
|
+
opId?: string;
|
|
17
|
+
expectedContentType?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Client instance returned by createClient
|
|
21
|
+
*/
|
|
22
|
+
export interface Client {
|
|
23
|
+
request<T = unknown>(options: RequestOptions): Promise<T>;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create SDK client
|
|
27
|
+
*/
|
|
28
|
+
export declare function createClient(config: ClientConfig): Client;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Runtime transport for SDK
|
|
4
|
+
* Generated by SDK codegen
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createClient = createClient;
|
|
8
|
+
// @ts-ignore - Import path valid in generated SDK (src/runtime -> src/extras), not in generator source
|
|
9
|
+
const fetchWithRetry_1 = require("../extras/fetchWithRetry");
|
|
10
|
+
const types_1 = require("./types");
|
|
11
|
+
function isPrimitive(v) {
|
|
12
|
+
return (typeof v === "string" || typeof v === "number" || typeof v === "boolean");
|
|
13
|
+
}
|
|
14
|
+
/** True if value is a plain object with only numeric keys 0,1,2,... (array-like). */
|
|
15
|
+
function isArrayLikeObject(v) {
|
|
16
|
+
if (v === null || typeof v !== "object" || Array.isArray(v))
|
|
17
|
+
return false;
|
|
18
|
+
const keys = Object.keys(v);
|
|
19
|
+
if (keys.length === 0)
|
|
20
|
+
return false;
|
|
21
|
+
return keys.every((k, i) => k === String(i));
|
|
22
|
+
}
|
|
23
|
+
/** Get values from array-like object in index order. */
|
|
24
|
+
function getArrayLikeValues(obj) {
|
|
25
|
+
const keys = Object.keys(obj).sort((a, b) => Number(a) - Number(b));
|
|
26
|
+
return keys.map((k) => obj[k]);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Serialize query object. Uses form-style for top-level arrays of primitives
|
|
30
|
+
* (key=val1&key=val2) so servers get a normal repeated key. Array-like objects
|
|
31
|
+
* (plain objects with keys "0","1",...) are serialized the same way. Uses deepObject
|
|
32
|
+
* for nested structures (e.g. mapping[columns][0][index]=0).
|
|
33
|
+
*/
|
|
34
|
+
function buildQueryString(query) {
|
|
35
|
+
const parts = [];
|
|
36
|
+
function encodeKey(prefix, key) {
|
|
37
|
+
return prefix ? `${prefix}[${key}]` : key;
|
|
38
|
+
}
|
|
39
|
+
function append(keyPrefix, value) {
|
|
40
|
+
if (value === undefined || value === null)
|
|
41
|
+
return;
|
|
42
|
+
if (isPrimitive(value)) {
|
|
43
|
+
parts.push(`${encodeURIComponent(keyPrefix)}=${encodeURIComponent(String(value))}`);
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(value)) {
|
|
47
|
+
const allPrimitive = value.every(isPrimitive);
|
|
48
|
+
if (allPrimitive) {
|
|
49
|
+
for (const item of value) {
|
|
50
|
+
parts.push(`${encodeURIComponent(keyPrefix)}=${encodeURIComponent(String(item))}`);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
value.forEach((item, i) => append(`${keyPrefix}[${i}]`, item));
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
if (typeof value === "object" && value !== null) {
|
|
58
|
+
// Array-like object (e.g. { 0: "a", 1: "b" }) → form-style repeated key, not root_entities[0]=a
|
|
59
|
+
if (isArrayLikeObject(value)) {
|
|
60
|
+
const arr = getArrayLikeValues(value);
|
|
61
|
+
const allPrimitive = arr.every(isPrimitive);
|
|
62
|
+
if (allPrimitive) {
|
|
63
|
+
for (const item of arr) {
|
|
64
|
+
parts.push(`${encodeURIComponent(keyPrefix)}=${encodeURIComponent(String(item))}`);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
arr.forEach((item, i) => append(`${keyPrefix}[${i}]`, item));
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
for (const [k, v] of Object.entries(value)) {
|
|
72
|
+
append(encodeKey(keyPrefix, k), v);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
for (const [key, value] of Object.entries(query)) {
|
|
77
|
+
if (value !== undefined && value !== null) {
|
|
78
|
+
append(key, value);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return parts.join("&");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Create SDK client
|
|
85
|
+
*/
|
|
86
|
+
function createClient(config) {
|
|
87
|
+
const { baseUrl, auth, defaultHeaders = {}, timeout = 30000 } = config;
|
|
88
|
+
// Build authorization header
|
|
89
|
+
const authHeader = {};
|
|
90
|
+
if (auth === null || auth === void 0 ? void 0 : auth.authorization) {
|
|
91
|
+
authHeader["Authorization"] = auth.authorization;
|
|
92
|
+
}
|
|
93
|
+
else if (auth === null || auth === void 0 ? void 0 : auth.token) {
|
|
94
|
+
authHeader["Authorization"] = `Bearer ${auth.token}`;
|
|
95
|
+
}
|
|
96
|
+
// Merge default headers with auth
|
|
97
|
+
const clientHeaders = {
|
|
98
|
+
...defaultHeaders,
|
|
99
|
+
...authHeader,
|
|
100
|
+
};
|
|
101
|
+
// Create fetch with retry logic for network errors and 5xx responses
|
|
102
|
+
// Retries up to 3 times with exponential backoff for transient failures
|
|
103
|
+
const fetchWithRetry = (0, fetchWithRetry_1.createFetchWithRetry)(fetch, {
|
|
104
|
+
retries: 3,
|
|
105
|
+
backoffMs: (attempt) => Math.min(1000 * 2 ** attempt, 5000), // Max 5s backoff
|
|
106
|
+
shouldRetry: (response) => {
|
|
107
|
+
// Retry on 5xx server errors
|
|
108
|
+
return response.status >= 500 && response.status < 600;
|
|
109
|
+
},
|
|
110
|
+
shouldRetryError: (error) => {
|
|
111
|
+
// Retry on network errors (status 0, connection refused, etc.)
|
|
112
|
+
// Don't retry on abort errors (timeouts)
|
|
113
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
return true;
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
async request(options) {
|
|
121
|
+
const { method, path, pathParams = {}, query, headers = {}, body, opId = "unknown", expectedContentType, } = options;
|
|
122
|
+
// Replace path parameters (e.g., "/tokens/:id" with { id: "123" } -> "/tokens/123")
|
|
123
|
+
// Extract required path params from path template
|
|
124
|
+
const pathParamNames = new Set();
|
|
125
|
+
const pathParamRegex = /:(\w+)/g;
|
|
126
|
+
let match;
|
|
127
|
+
while ((match = pathParamRegex.exec(path)) !== null) {
|
|
128
|
+
pathParamNames.add(match[1]);
|
|
129
|
+
}
|
|
130
|
+
// Validate required path params are provided
|
|
131
|
+
for (const paramName of pathParamNames) {
|
|
132
|
+
if (!(paramName in pathParams)) {
|
|
133
|
+
throw new types_1.ApiError(400, opId, path, { message: `Missing required path parameter: ${paramName}` }, undefined);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
// Replace path parameters with URL-encoded values
|
|
137
|
+
let resolvedPath = path;
|
|
138
|
+
for (const [key, value] of Object.entries(pathParams)) {
|
|
139
|
+
const encodedValue = encodeURIComponent(String(value));
|
|
140
|
+
resolvedPath = resolvedPath.replace(new RegExp(`:${key}(?=/|$)`), encodedValue);
|
|
141
|
+
}
|
|
142
|
+
// Build query string (form-style for arrays of primitives; deepObject for nested)
|
|
143
|
+
const queryString = query && Object.keys(query).length > 0 ? buildQueryString(query) : "";
|
|
144
|
+
const url = `${baseUrl}${resolvedPath}${queryString ? `?${queryString}` : ""}`;
|
|
145
|
+
// Merge headers: client defaults + per-call headers (per-call overrides)
|
|
146
|
+
const requestHeaders = {
|
|
147
|
+
...clientHeaders,
|
|
148
|
+
...headers,
|
|
149
|
+
};
|
|
150
|
+
// Body and Content-Type: FormData/Blob must be sent as-is (multipart/binary); do not set Content-Type so browser sets boundary
|
|
151
|
+
const isFormData = typeof FormData !== "undefined" && body instanceof FormData;
|
|
152
|
+
const isBlob = typeof Blob !== "undefined" && body instanceof Blob;
|
|
153
|
+
if (isFormData || isBlob) {
|
|
154
|
+
delete requestHeaders["Content-Type"];
|
|
155
|
+
}
|
|
156
|
+
else if (body !== undefined && body !== null) {
|
|
157
|
+
if (!requestHeaders["Content-Type"]) {
|
|
158
|
+
requestHeaders["Content-Type"] = "application/json";
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Create AbortController for timeout
|
|
162
|
+
const controller = new AbortController();
|
|
163
|
+
const timeoutId = setTimeout(() => controller.abort(), timeout);
|
|
164
|
+
let requestBody;
|
|
165
|
+
if (body !== undefined && body !== null) {
|
|
166
|
+
requestBody =
|
|
167
|
+
isFormData || isBlob
|
|
168
|
+
? body
|
|
169
|
+
: JSON.stringify(body);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
requestBody = undefined;
|
|
173
|
+
}
|
|
174
|
+
try {
|
|
175
|
+
const response = await fetchWithRetry(url, {
|
|
176
|
+
method,
|
|
177
|
+
headers: requestHeaders,
|
|
178
|
+
body: requestBody,
|
|
179
|
+
signal: controller.signal,
|
|
180
|
+
});
|
|
181
|
+
clearTimeout(timeoutId);
|
|
182
|
+
// Handle 204 No Content
|
|
183
|
+
if (response.status === 204) {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
// Determine content type: use actual response header first, fallback to expectedContentType
|
|
187
|
+
let contentType = response.headers.get("content-type") || "";
|
|
188
|
+
// Strip charset and other parameters (e.g., "text/csv; charset=utf-8" -> "text/csv")
|
|
189
|
+
if (contentType) {
|
|
190
|
+
contentType = contentType.split(";")[0].trim();
|
|
191
|
+
}
|
|
192
|
+
if (!contentType && expectedContentType) {
|
|
193
|
+
contentType = expectedContentType;
|
|
194
|
+
}
|
|
195
|
+
let data;
|
|
196
|
+
// Parse response based on actual content type
|
|
197
|
+
if (contentType.includes("application/json")) {
|
|
198
|
+
data = (await response.json());
|
|
199
|
+
}
|
|
200
|
+
else if (contentType.includes("text/csv")) {
|
|
201
|
+
data = (await response.text());
|
|
202
|
+
}
|
|
203
|
+
else if (contentType.includes("application/pdf")) {
|
|
204
|
+
data = (await response.arrayBuffer());
|
|
205
|
+
}
|
|
206
|
+
else {
|
|
207
|
+
// Fallback: try to parse as text, then attempt JSON
|
|
208
|
+
const text = await response.text();
|
|
209
|
+
try {
|
|
210
|
+
data = JSON.parse(text);
|
|
211
|
+
}
|
|
212
|
+
catch {
|
|
213
|
+
data = text;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Check for error status (after parsing to get error body)
|
|
217
|
+
if (!response.ok) {
|
|
218
|
+
const requestId = response.headers.get("x-request-id") || undefined;
|
|
219
|
+
throw new types_1.ApiError(response.status, opId, url, data, requestId);
|
|
220
|
+
}
|
|
221
|
+
return data;
|
|
222
|
+
}
|
|
223
|
+
catch (error) {
|
|
224
|
+
clearTimeout(timeoutId);
|
|
225
|
+
if (error instanceof types_1.ApiError) {
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
// Handle fetch errors (network, timeout, etc.)
|
|
229
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
230
|
+
throw new types_1.ApiError(408, opId, url, undefined, undefined);
|
|
231
|
+
}
|
|
232
|
+
// Re-throw as ApiError with minimal info
|
|
233
|
+
throw new types_1.ApiError(0, opId, url, error, undefined);
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime types for SDK
|
|
3
|
+
* Generated by SDK codegen
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Client configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface ClientConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Base URL for API requests (e.g., "https://api.example.com")
|
|
11
|
+
*/
|
|
12
|
+
baseUrl: string;
|
|
13
|
+
/**
|
|
14
|
+
* Authentication configuration
|
|
15
|
+
*/
|
|
16
|
+
auth?: AuthConfig;
|
|
17
|
+
/**
|
|
18
|
+
* Default headers to include in all requests
|
|
19
|
+
*/
|
|
20
|
+
defaultHeaders?: Record<string, string>;
|
|
21
|
+
/**
|
|
22
|
+
* Request timeout in milliseconds (default: 30000)
|
|
23
|
+
*/
|
|
24
|
+
timeout?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Authentication configuration
|
|
28
|
+
*/
|
|
29
|
+
export interface AuthConfig {
|
|
30
|
+
/**
|
|
31
|
+
* API token for authentication
|
|
32
|
+
* Will be sent as "Authorization: Bearer <token>"
|
|
33
|
+
*/
|
|
34
|
+
token?: string;
|
|
35
|
+
/**
|
|
36
|
+
* Custom authorization header value
|
|
37
|
+
* If provided, will be used instead of "Bearer <token>"
|
|
38
|
+
*/
|
|
39
|
+
authorization?: string;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* API Error
|
|
43
|
+
* Thrown when a request fails (non-2xx response)
|
|
44
|
+
*/
|
|
45
|
+
export declare class ApiError extends Error {
|
|
46
|
+
readonly status: number;
|
|
47
|
+
readonly opId: string;
|
|
48
|
+
readonly url: string;
|
|
49
|
+
readonly body?: unknown | undefined;
|
|
50
|
+
readonly requestId?: string | undefined;
|
|
51
|
+
constructor(status: number, opId: string, url: string, body?: unknown | undefined, requestId?: string | undefined);
|
|
52
|
+
}
|