@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.
@@ -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 ?? undefined;
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
  }
@@ -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
@@ -13,4 +13,5 @@ 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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@turinhub/tale-js-sdk",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Official TypeScript SDK for Tale backend services",
5
5
  "keywords": [
6
6
  "tale",