@evomap/evolver-adapter-public 2.0.37 → 2.0.38

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.
@@ -172,6 +172,8 @@ export class PublicHubCapability {
172
172
  ...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
173
173
  };
174
174
  }
175
+ if (isNodeMergedResponse(body, payload))
176
+ return helloResultFromBody(200, body);
175
177
  if (payload['error'])
176
178
  return { ok: false, error: String(payload['error']), ...(retryAfterMs !== undefined ? { retryAfterMs } : {}), ...(rateLimitUntilMs !== undefined ? { rateLimitUntilMs } : {}) };
177
179
  const nodeId = stringField(payload, 'your_node_id')
@@ -203,8 +205,12 @@ export class PublicHubCapability {
203
205
  };
204
206
  }
205
207
  catch (err) {
206
- if (err instanceof AuthError)
207
- return { ok: false, authError: true, error: `hub auth error ${err.status}`, httpStatus: err.status };
208
+ if (err instanceof AuthError) {
209
+ const result = helloResultFromBody(err.status, asRecord(err.body) ?? {});
210
+ return result.error === 'node_merged'
211
+ ? result
212
+ : { ok: false, authError: true, error: `hub auth error ${err.status}`, httpStatus: err.status };
213
+ }
208
214
  if (err instanceof HubClientError)
209
215
  return helloResultFromBody(err.status, asRecord(err.body) ?? {});
210
216
  if (isHubUnreachableError(err))
@@ -229,8 +235,12 @@ export class PublicHubCapability {
229
235
  return heartbeatResultFromBody(200, body);
230
236
  }
231
237
  catch (err) {
232
- if (err instanceof AuthError)
233
- return { ok: false, authError: true, error: `hub auth error ${err.status}` };
238
+ if (err instanceof AuthError) {
239
+ const result = heartbeatResultFromBody(err.status, asRecord(err.body) ?? {});
240
+ return result.error === 'node_merged'
241
+ ? result
242
+ : { ok: false, authError: true, error: `hub auth error ${err.status}` };
243
+ }
234
244
  if (err instanceof HubClientError)
235
245
  return heartbeatResultFromBody(err.status, asRecord(err.body) ?? {});
236
246
  if (isHubUnreachableError(err))
@@ -1568,9 +1578,12 @@ function helloResultFromBody(httpStatus, body) {
1568
1578
  const payload = asRecord(body['payload']) ?? body;
1569
1579
  const retryAfterMs = numberField(payload, 'retry_after_ms') ?? numberField(payload, 'retryAfterMs');
1570
1580
  const rateLimitUntilMs = numberField(payload, 'rate_limit_until_ms') ?? numberField(payload, 'rateLimitUntilMs');
1571
- const status = stringField(payload, 'status');
1572
- const error = stringField(payload, 'error') ?? stringField(payload, 'reason') ?? (httpStatus >= 400 ? `http_${httpStatus}` : undefined);
1573
- const details = payload['details'] ?? body['details'];
1581
+ const nodeMerged = isNodeMergedResponse(body, payload);
1582
+ const status = nodeMerged ? 'node_merged' : stringField(payload, 'status');
1583
+ const error = nodeMerged
1584
+ ? 'node_merged'
1585
+ : stringField(payload, 'error') ?? stringField(payload, 'reason') ?? (httpStatus >= 400 ? `http_${httpStatus}` : undefined);
1586
+ const details = nodeMerged ? undefined : payload['details'] ?? body['details'];
1574
1587
  const authError = httpStatus === 401 || httpStatus === 403 || status === 'auth_failed' || status === 'invalid_secret';
1575
1588
  return {
1576
1589
  ok: false,
@@ -1591,9 +1604,13 @@ function hubUnreachableRetryAfterMs(err) {
1591
1604
  function heartbeatResultFromBody(httpStatus, body) {
1592
1605
  const payload = asRecord(body['payload']) ?? body;
1593
1606
  const retryAfterMs = numberField(payload, 'retry_after_ms') ?? numberField(payload, 'retryAfterMs');
1594
- const status = stringField(payload, 'status');
1595
- const error = stringField(payload, 'error') ?? (httpStatus >= 400 ? `http_${httpStatus}` : undefined);
1596
- const details = payload['details'] ?? body['details'];
1607
+ const nodeMerged = isNodeMergedResponse(body, payload);
1608
+ const status = nodeMerged ? 'node_merged' : stringField(payload, 'status');
1609
+ const error = nodeMerged
1610
+ ? 'node_merged'
1611
+ : stringField(payload, 'error') ?? (httpStatus >= 400 ? `http_${httpStatus}` : undefined);
1612
+ const details = nodeMerged ? undefined : payload['details'] ?? body['details'];
1613
+ const authError = httpStatus === 401 || httpStatus === 403;
1597
1614
  const ack = asRecord(payload['last_update_ack']);
1598
1615
  const forceUpdate = forceUpdateFromRecord(asRecord(payload['force_update']));
1599
1616
  const rawCapabilityGaps = payload['capability_gaps'] ?? payload['capabilityGaps'];
@@ -1607,6 +1624,7 @@ function heartbeatResultFromBody(httpStatus, body) {
1607
1624
  && !error;
1608
1625
  return {
1609
1626
  ok,
1627
+ ...(authError ? { authError: true } : {}),
1610
1628
  ...(httpStatus >= 400 ? { httpStatus } : {}),
1611
1629
  ...(error ? { error } : {}),
1612
1630
  ...(details !== undefined ? { details } : {}),
@@ -1620,6 +1638,21 @@ function heartbeatResultFromBody(httpStatus, body) {
1620
1638
  ...(capabilityGaps !== undefined ? { capabilityGaps } : {}),
1621
1639
  };
1622
1640
  }
1641
+ function isNodeMergedResponse(body, payload) {
1642
+ return [
1643
+ payload['error'],
1644
+ payload['reason'],
1645
+ payload['status'],
1646
+ body['error'],
1647
+ body['reason'],
1648
+ body['status'],
1649
+ ].some((value) => {
1650
+ if (typeof value !== 'string')
1651
+ return false;
1652
+ const code = value.trim();
1653
+ return code === 'node_merged' || code.startsWith('node_merged:');
1654
+ });
1655
+ }
1623
1656
  function forceUpdateFromRecord(value) {
1624
1657
  if (!value)
1625
1658
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evomap/evolver-adapter-public",
3
- "version": "2.0.37",
3
+ "version": "2.0.38",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -17,8 +17,8 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@evomap/atp-sdk": "^0.1.0",
20
- "@evomap/evolver-core": "2.0.37",
21
- "undici": "^6.27.0"
20
+ "@evomap/evolver-core": "2.0.38",
21
+ "undici": "^6.28.0"
22
22
  },
23
23
  "optionalDependencies": {
24
24
  "@napi-rs/keyring": "^1.1.6"