@datalayer/core 1.0.16 → 1.0.18

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.
@@ -12,11 +12,8 @@ export interface HealthzPingResponse {
12
12
  success: boolean;
13
13
  /** Response message from the server */
14
14
  message: string;
15
- /** Service status information */
16
- status?: {
17
- /** Status indicator (e.g., "OK") */
18
- status: string;
19
- };
15
+ /** Service status indicator (e.g., "OK") */
16
+ status?: string;
20
17
  /** API version */
21
18
  version?: string;
22
19
  }
@@ -74,17 +74,17 @@ export interface UserMeResponse {
74
74
  /** Unique identifier (UID) for the user */
75
75
  uid: string;
76
76
  /** User handle (username) */
77
- handle: string;
77
+ handle_s: string;
78
78
  /** Email address of the user (may be empty string) */
79
- email: string;
79
+ email_s: string;
80
80
  /** First name of the user (may be empty string) */
81
- firstName: string;
81
+ first_name_t: string;
82
82
  /** Last name of the user (may be empty string) */
83
- lastName: string;
83
+ last_name_t: string;
84
84
  /** Avatar URL for the user (may be empty string) */
85
- avatarUrl: string;
85
+ avatar_url_s: string;
86
86
  /** Array of roles assigned to the user */
87
- roles: string[];
87
+ roles_ss: string[];
88
88
  /** Allow additional fields that may come from the server */
89
89
  [key: string]: any;
90
90
  };
package/lib/otel/auth.js CHANGED
@@ -1,3 +1,7 @@
1
+ /*
2
+ * Copyright (c) 2023-2025 Datalayer, Inc.
3
+ * Distributed under the terms of the Modified BSD License.
4
+ */
1
5
  /*
2
6
  * Copyright (c) 2023-2026 Datalayer, Inc.
3
7
  * Distributed under the terms of the Modified BSD License.
@@ -7,7 +11,16 @@ function normalizeBaseUrl(baseUrl) {
7
11
  const normalized = baseUrl.startsWith('ws://') || baseUrl.startsWith('wss://')
8
12
  ? baseUrl.replace(/^ws/, 'http')
9
13
  : baseUrl;
10
- return new URL(normalized);
14
+ const isAbsoluteUrl = /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(normalized);
15
+ if (isAbsoluteUrl) {
16
+ return new URL(normalized);
17
+ }
18
+ if (typeof window !== 'undefined' &&
19
+ typeof window.location !== 'undefined' &&
20
+ typeof window.location.origin === 'string') {
21
+ return new URL(normalized || '/', window.location.origin);
22
+ }
23
+ throw new Error('OTEL baseUrl must be an absolute URL when window.location is unavailable.');
11
24
  }
12
25
  export function resolveOtelUserUid(token, userUid) {
13
26
  if (typeof userUid === 'string' && userUid.trim().length > 0) {
@@ -31,12 +44,13 @@ export function resolveOtelAuth(token, userUid) {
31
44
  if (!token || token.trim().length === 0) {
32
45
  throw new Error('OTEL requires an authenticated token.');
33
46
  }
34
- const resolvedUserUid = resolveOtelUserUid(token, userUid);
47
+ const trimmedToken = token.trim();
48
+ const resolvedUserUid = resolveOtelUserUid(trimmedToken, userUid);
35
49
  if (!resolvedUserUid) {
36
50
  throw new Error('OTEL requires datalayer.user_uid. Provide a JWT with user.uid/sub or pass userUid explicitly.');
37
51
  }
38
52
  return {
39
- token,
53
+ token: trimmedToken,
40
54
  userUid: resolvedUserUid,
41
55
  };
42
56
  }
@@ -8,7 +8,7 @@ export interface OtelClientOptions {
8
8
  */
9
9
  baseUrl?: string;
10
10
  /** JWT bearer token or API key for authentication. */
11
- token?: string;
11
+ token: string;
12
12
  /** Explicit user UID; optional when token contains user.uid/sub. */
13
13
  userUid?: string;
14
14
  }
@@ -41,7 +41,7 @@ export declare class OtelClient {
41
41
  private readonly baseUrl;
42
42
  private readonly token;
43
43
  private readonly userUid;
44
- constructor(options?: OtelClientOptions);
44
+ constructor(options: OtelClientOptions);
45
45
  /** List recent spans / traces. */
46
46
  fetchTraces(options?: FetchTracesOptions): Promise<{
47
47
  data: OtelSpan[];
@@ -92,5 +92,5 @@ export declare class OtelClient {
92
92
  * const services = await client.fetchServices();
93
93
  * ```
94
94
  */
95
- export declare function createOtelClient(options?: OtelClientOptions): OtelClient;
95
+ export declare function createOtelClient(options: OtelClientOptions): OtelClient;
96
96
  export type { OtelSystemData, OtelSystemProcess, OtelSystemDisk, OtelSystemTable, };
@@ -80,13 +80,13 @@ function normalizeMetric(raw) {
80
80
  // Preserve the raw nanosecond timestamp for time-series charts.
81
81
  let timestampUnixNano;
82
82
  const rawNano = raw.timestamp_unix_nano;
83
- if (typeof rawNano === 'number' && rawNano > 0) {
84
- timestampUnixNano = rawNano;
83
+ if (typeof rawNano === 'number' && Number.isFinite(rawNano) && rawNano > 0) {
84
+ timestampUnixNano = String(Math.trunc(rawNano));
85
85
  }
86
86
  else if (typeof rawNano === 'string') {
87
- const parsed = Number(rawNano);
88
- if (Number.isFinite(parsed) && parsed > 0) {
89
- timestampUnixNano = parsed;
87
+ const trimmed = rawNano.trim();
88
+ if (/^\d+$/.test(trimmed) && trimmed !== '0') {
89
+ timestampUnixNano = trimmed;
90
90
  }
91
91
  }
92
92
  return {
@@ -124,7 +124,7 @@ export class OtelClient {
124
124
  baseUrl;
125
125
  token;
126
126
  userUid;
127
- constructor(options = {}) {
127
+ constructor(options) {
128
128
  this.baseUrl =
129
129
  options.baseUrl ?? coreStore.getState().configuration.otelRunUrl;
130
130
  const auth = resolveOtelAuth(options.token, options.userUid);
@@ -244,6 +244,6 @@ export class OtelClient {
244
244
  * const services = await client.fetchServices();
245
245
  * ```
246
246
  */
247
- export function createOtelClient(options = {}) {
247
+ export function createOtelClient(options) {
248
248
  return new OtelClient(options);
249
249
  }
@@ -56,7 +56,7 @@ export interface OtelMetric {
56
56
  unit?: string;
57
57
  timestamp: string;
58
58
  /** Raw nanosecond timestamp preserved from the backend. */
59
- timestamp_unix_nano?: number;
59
+ timestamp_unix_nano?: string;
60
60
  attributes?: Record<string, unknown>;
61
61
  metric_type?: string;
62
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datalayer/core",
3
- "version": "1.0.16",
3
+ "version": "1.0.18",
4
4
  "type": "module",
5
5
  "workspaces": [
6
6
  ".",