@turinhub/tale-js-sdk 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth/index.js +2 -2
- package/dist/common/http.js +6 -0
- package/dist/dashboard/index.d.ts +9 -0
- package/dist/dashboard/index.js +30 -0
- package/dist/dashboard/types.d.ts +18 -0
- package/dist/dashboard/types.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
package/dist/auth/index.js
CHANGED
|
@@ -65,12 +65,12 @@ export async function login(credentials, options) {
|
|
|
65
65
|
}
|
|
66
66
|
// Determine base URL
|
|
67
67
|
const env = globalThis?.process?.env ?? import.meta?.env ?? undefined;
|
|
68
|
-
const base = options?.baseUrl ?? env?.TALE_BASE_URL ??
|
|
68
|
+
const base = options?.baseUrl ?? env?.TALE_BASE_URL ?? env?.NEXT_PUBLIC_TALE_BASE_URL;
|
|
69
69
|
if (!base) {
|
|
70
70
|
throw new ConfigurationError("Missing required environment variable: TALE_BASE_URL");
|
|
71
71
|
}
|
|
72
72
|
// Get app key from environment variable
|
|
73
|
-
const appKey = env?.TALE_APP_KEY;
|
|
73
|
+
const appKey = env?.TALE_APP_KEY ?? env?.NEXT_PUBLIC_TALE_APP_KEY;
|
|
74
74
|
if (!appKey) {
|
|
75
75
|
throw new ConfigurationError("Missing required environment variable: TALE_APP_KEY");
|
|
76
76
|
}
|
package/dist/common/http.js
CHANGED
|
@@ -101,6 +101,12 @@ export async function requestJson(path, options, config) {
|
|
|
101
101
|
catch (error) {
|
|
102
102
|
throw new ApiError(`Failed to parse response: ${error instanceof Error ? error.message : "Invalid JSON"}`, response.status);
|
|
103
103
|
}
|
|
104
|
+
if (response.ok === false || response.status >= 400) {
|
|
105
|
+
const errorResponse = toRecord(json);
|
|
106
|
+
const errorMessage = pickString(errorResponse.msg, errorResponse.message) ||
|
|
107
|
+
config.errorMessage;
|
|
108
|
+
throw new ApiError(errorMessage, response.status);
|
|
109
|
+
}
|
|
104
110
|
return unwrapApiResponse(json, config.errorMessage, response.status);
|
|
105
111
|
}
|
|
106
112
|
export function normalizePageResponse(value, normalizeItem) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PageResponse } from "../common/types.js";
|
|
2
|
+
import type { DashboardOptions, DashboardViewQueryRequest, DashboardViewQueryResponse, DashboardViewRow } from "./types.js";
|
|
3
|
+
export declare function getDashboardView(viewName: string, options?: DashboardOptions & {
|
|
4
|
+
page?: number;
|
|
5
|
+
size?: number;
|
|
6
|
+
sort?: string;
|
|
7
|
+
}): Promise<PageResponse<DashboardViewRow>>;
|
|
8
|
+
export declare function queryDashboardView(request: DashboardViewQueryRequest, options?: DashboardOptions): Promise<DashboardViewQueryResponse>;
|
|
9
|
+
export type { DashboardFilterOperator, DashboardOptions, DashboardViewFilter, DashboardViewQueryRequest, DashboardViewQueryResponse, DashboardViewRow, } from "./types.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { assertRequiredString, normalizePageResponse, requestJson, toRecord, } from "../common/http.js";
|
|
2
|
+
function normalizeDashboardRow(value) {
|
|
3
|
+
return toRecord(value);
|
|
4
|
+
}
|
|
5
|
+
function toPageQuery(request) {
|
|
6
|
+
return {
|
|
7
|
+
page: request.page,
|
|
8
|
+
size: request.size,
|
|
9
|
+
sort: request.sort,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
export async function getDashboardView(viewName, options) {
|
|
13
|
+
assertRequiredString(viewName, "viewName");
|
|
14
|
+
const { page, size, sort, ...requestOptions } = options ?? {};
|
|
15
|
+
const data = await requestJson(`/dashboard/v2/view/${encodeURIComponent(viewName)}/page`, requestOptions, {
|
|
16
|
+
query: toPageQuery({ page, size, sort }),
|
|
17
|
+
errorMessage: "Failed to get dashboard view",
|
|
18
|
+
});
|
|
19
|
+
return normalizePageResponse(data, normalizeDashboardRow);
|
|
20
|
+
}
|
|
21
|
+
export async function queryDashboardView(request, options) {
|
|
22
|
+
assertRequiredString(request?.viewName, "viewName");
|
|
23
|
+
const data = await requestJson(`/dashboard/v2/view/${encodeURIComponent(request.viewName)}/query`, options, {
|
|
24
|
+
method: "POST",
|
|
25
|
+
query: toPageQuery(request),
|
|
26
|
+
body: { filters: request.filters ?? [] },
|
|
27
|
+
errorMessage: "Failed to query dashboard view",
|
|
28
|
+
});
|
|
29
|
+
return normalizePageResponse(data, normalizeDashboardRow);
|
|
30
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { CommonOptions, PageResponse } from "../common/types.js";
|
|
2
|
+
export type DashboardFilterOperator = "eq" | "ne" | "gt" | "lt" | "gte" | "lte" | "like" | "in";
|
|
3
|
+
export interface DashboardViewFilter {
|
|
4
|
+
field: string;
|
|
5
|
+
operator?: DashboardFilterOperator;
|
|
6
|
+
value: unknown;
|
|
7
|
+
}
|
|
8
|
+
export type DashboardViewRow = Record<string, unknown>;
|
|
9
|
+
export interface DashboardViewQueryRequest {
|
|
10
|
+
viewName: string;
|
|
11
|
+
page?: number;
|
|
12
|
+
size?: number;
|
|
13
|
+
sort?: string;
|
|
14
|
+
filters?: DashboardViewFilter[];
|
|
15
|
+
}
|
|
16
|
+
export type DashboardViewQueryResponse = PageResponse<DashboardViewRow>;
|
|
17
|
+
export interface DashboardOptions extends CommonOptions {
|
|
18
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export * from "./attachment/index.js";
|
|
|
13
13
|
export * from "./attachment-type/index.js";
|
|
14
14
|
export * from "./app/index.js";
|
|
15
15
|
export * from "./app-token/index.js";
|
|
16
|
+
export * from "./dashboard/index.js";
|
|
16
17
|
export * from "./errors.js";
|
|
17
18
|
export type { CommonOptions, PageResponse, UserGroup, Role, Privilege, AppInfo, User, } from "./common/types.js";
|
|
18
19
|
export type { Attachment, AttachmentRefType, ListAttachmentsByRefRequest, UploadAttachmentRequest, UploadAuthorizationRequest, CompleteUploadRequest, DeleteAttachmentRequest, DownloadAttachmentUrlRequest, DownloadUrlResponse, AttachmentOptions, } from "./attachment/types.js";
|
package/dist/index.js
CHANGED