attlaz-client 1.48.1 → 1.48.2

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.
@@ -9,9 +9,14 @@ export class LoadAllHelper {
9
9
  firstPagination.limit = limit;
10
10
  firstPagination.startingAfter = lastRef;
11
11
  const data = await call(firstPagination);
12
- for (const record of data.getData()) {
13
- totalResult.push(record);
14
- lastRef = record.id.toString();
12
+ const records = data.getData();
13
+ // Spread is faster than a per-element loop but can exceed the call stack for very large collections (50k+)
14
+ if (totalResult.length + records.length > 50_000) {
15
+ throw new Error('loadAll exceeded 50,000 records (' + (totalResult.length + records.length) + '). This method is not intended for large datasets.');
16
+ }
17
+ totalResult.push(...records);
18
+ if (records.length > 0) {
19
+ lastRef = records[records.length - 1].id.toString();
15
20
  }
16
21
  hasMore = data.hasMore;
17
22
  }
@@ -8,13 +8,18 @@ export interface DirectTransportRoute {
8
8
  * Transport for internal service-to-service calls that bypasses Gateway OAuth.
9
9
  * Authenticates via HMAC-signed session headers instead of an OAuth token.
10
10
  *
11
+ * The caller is responsible for computing the HMAC signature (since this requires
12
+ * node:crypto which is not available in browser environments).
13
+ *
11
14
  * Usage:
12
- * const transport = new DirectTransport('http://core-api:5728', process.env.api_secret);
15
+ * import {createHmac} from 'node:crypto';
16
+ * const sessionPayload = DirectTransport.createSessionPayload();
17
+ * const sessionSignature = createHmac('sha256', apiSecret).update(sessionPayload).digest('hex');
18
+ * const transport = new DirectTransport('http://core-api:5728', sessionPayload, sessionSignature);
13
19
  * const client = Client.withTransport(transport);
14
- * client.getFlowEndpoint().getById(id);
15
20
  *
16
21
  * With multiple backends:
17
- * const transport = new DirectTransport('http://core-api:5728', secret, [
22
+ * const transport = new DirectTransport('http://core-api:5728', sessionPayload, sessionSignature, [
18
23
  * { prefix: '/products', baseUrl: 'http://products-api:5730' },
19
24
  * { prefix: '/services', baseUrl: 'http://services-api:5731' },
20
25
  * ]);
@@ -22,7 +27,11 @@ export interface DirectTransportRoute {
22
27
  export declare class DirectTransport implements ITransport {
23
28
  private readonly clients;
24
29
  private readonly sortedRoutes;
25
- constructor(defaultBaseUrl: string, apiSecret: string, routes?: DirectTransportRoute[]);
30
+ /**
31
+ * Creates the default session payload for internal service-to-service calls.
32
+ */
33
+ static createSessionPayload(): string;
34
+ constructor(defaultBaseUrl: string, sessionPayload: string, sessionSignature: string, routes?: DirectTransportRoute[]);
26
35
  request<T>(action: string, parameters?: Parameters, method?: string, _signWithOauthToken?: boolean): Promise<T>;
27
36
  private resolveClient;
28
37
  isDebugEnabled(): boolean;
@@ -1,17 +1,21 @@
1
- import { createHmac } from 'node:crypto';
2
1
  import { OAuthClientOptions } from '../OAuthClientOptions.js';
3
2
  import { OAuthClient } from './OAuthClient.js';
4
3
  /**
5
4
  * Transport for internal service-to-service calls that bypasses Gateway OAuth.
6
5
  * Authenticates via HMAC-signed session headers instead of an OAuth token.
7
6
  *
7
+ * The caller is responsible for computing the HMAC signature (since this requires
8
+ * node:crypto which is not available in browser environments).
9
+ *
8
10
  * Usage:
9
- * const transport = new DirectTransport('http://core-api:5728', process.env.api_secret);
11
+ * import {createHmac} from 'node:crypto';
12
+ * const sessionPayload = DirectTransport.createSessionPayload();
13
+ * const sessionSignature = createHmac('sha256', apiSecret).update(sessionPayload).digest('hex');
14
+ * const transport = new DirectTransport('http://core-api:5728', sessionPayload, sessionSignature);
10
15
  * const client = Client.withTransport(transport);
11
- * client.getFlowEndpoint().getById(id);
12
16
  *
13
17
  * With multiple backends:
14
- * const transport = new DirectTransport('http://core-api:5728', secret, [
18
+ * const transport = new DirectTransport('http://core-api:5728', sessionPayload, sessionSignature, [
15
19
  * { prefix: '/products', baseUrl: 'http://products-api:5730' },
16
20
  * { prefix: '/services', baseUrl: 'http://services-api:5731' },
17
21
  * ]);
@@ -19,9 +23,11 @@ import { OAuthClient } from './OAuthClient.js';
19
23
  export class DirectTransport {
20
24
  clients = new Map();
21
25
  sortedRoutes;
22
- constructor(defaultBaseUrl, apiSecret, routes = []) {
23
- // TODO: do we need to define user, client and ip?
24
- const sessionPayload = JSON.stringify({
26
+ /**
27
+ * Creates the default session payload for internal service-to-service calls.
28
+ */
29
+ static createSessionPayload() {
30
+ return JSON.stringify({
25
31
  api_version: 'latest',
26
32
  user: null,
27
33
  client: null,
@@ -30,7 +36,8 @@ export class DirectTransport {
30
36
  scopes: [],
31
37
  access_token: null,
32
38
  });
33
- const sessionSignature = createHmac('sha256', apiSecret).update(sessionPayload).digest('hex');
39
+ }
40
+ constructor(defaultBaseUrl, sessionPayload, sessionSignature, routes = []) {
34
41
  // All routes plus the catch-all default, sorted by prefix length descending (most specific first)
35
42
  this.sortedRoutes = [...routes, { prefix: '', baseUrl: defaultBaseUrl }]
36
43
  .sort((a, b) => b.prefix.length - a.prefix.length);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "attlaz-client",
3
- "version": "1.48.1",
3
+ "version": "1.48.2",
4
4
  "description": "Javascript Client to access Attlaz API",
5
5
  "types": "./dist/index.d.ts",
6
6
  "main": "./dist/index.js",