@granular-software/sdk 0.4.42 → 0.4.44

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/index.mjs CHANGED
@@ -159,9 +159,9 @@ var require_node_gyp_build = __commonJS({
159
159
  }
160
160
  function parseTags(file) {
161
161
  var arr = file.split(".");
162
- var extension = arr.pop();
162
+ var extension2 = arr.pop();
163
163
  var tags = { file, specificity: 0 };
164
- if (extension !== "node") return;
164
+ if (extension2 !== "node") return;
165
165
  for (var i = 0; i < arr.length; i++) {
166
166
  var tag = arr[i];
167
167
  if (tag === "node" || tag === "electron" || tag === "node-webkit") {
@@ -409,7 +409,7 @@ var require_permessage_deflate = __commonJS({
409
409
  var kBuffers = Symbol("buffers");
410
410
  var kError = Symbol("error");
411
411
  var zlibLimiter;
412
- var PerMessageDeflate = class {
412
+ var PerMessageDeflate2 = class {
413
413
  /**
414
414
  * Creates a PerMessageDeflate instance.
415
415
  *
@@ -420,6 +420,9 @@ var require_permessage_deflate = __commonJS({
420
420
  * acknowledge disabling of client context takeover
421
421
  * @param {Number} [options.concurrencyLimit=10] The number of concurrent
422
422
  * calls to zlib
423
+ * @param {Boolean} [options.isServer=false] Create the instance in either
424
+ * server or client mode
425
+ * @param {Number} [options.maxPayload=0] The maximum allowed message length
423
426
  * @param {(Boolean|Number)} [options.serverMaxWindowBits] Request/confirm the
424
427
  * use of a custom server window size
425
428
  * @param {Boolean} [options.serverNoContextTakeover=false] Request/accept
@@ -430,15 +433,12 @@ var require_permessage_deflate = __commonJS({
430
433
  * deflate
431
434
  * @param {Object} [options.zlibInflateOptions] Options to pass to zlib on
432
435
  * inflate
433
- * @param {Boolean} [isServer=false] Create the instance in either server or
434
- * client mode
435
- * @param {Number} [maxPayload=0] The maximum allowed message length
436
436
  */
437
- constructor(options, isServer, maxPayload) {
438
- this._maxPayload = maxPayload | 0;
437
+ constructor(options) {
439
438
  this._options = options || {};
440
439
  this._threshold = this._options.threshold !== void 0 ? this._options.threshold : 1024;
441
- this._isServer = !!isServer;
440
+ this._maxPayload = this._options.maxPayload | 0;
441
+ this._isServer = !!this._options.isServer;
442
442
  this._deflate = null;
443
443
  this._inflate = null;
444
444
  this.params = null;
@@ -747,7 +747,7 @@ var require_permessage_deflate = __commonJS({
747
747
  });
748
748
  }
749
749
  };
750
- module.exports = PerMessageDeflate;
750
+ module.exports = PerMessageDeflate2;
751
751
  function deflateOnData(chunk) {
752
752
  this[kBuffers].push(chunk);
753
753
  this[kTotalLength] += chunk.length;
@@ -1027,7 +1027,7 @@ var require_validation = __commonJS({
1027
1027
  var require_receiver = __commonJS({
1028
1028
  "../../node_modules/ws/lib/receiver.js"(exports, module) {
1029
1029
  var { Writable } = __require("stream");
1030
- var PerMessageDeflate = require_permessage_deflate();
1030
+ var PerMessageDeflate2 = require_permessage_deflate();
1031
1031
  var {
1032
1032
  BINARY_TYPES,
1033
1033
  EMPTY_BUFFER,
@@ -1057,6 +1057,10 @@ var require_receiver = __commonJS({
1057
1057
  * extensions
1058
1058
  * @param {Boolean} [options.isServer=false] Specifies whether to operate in
1059
1059
  * client or server mode
1060
+ * @param {Number} [options.maxBufferedChunks=0] The maximum number of
1061
+ * buffered data chunks
1062
+ * @param {Number} [options.maxFragments=0] The maximum number of message
1063
+ * fragments
1060
1064
  * @param {Number} [options.maxPayload=0] The maximum allowed message length
1061
1065
  * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
1062
1066
  * not to skip UTF-8 validation for text and close messages
@@ -1067,6 +1071,8 @@ var require_receiver = __commonJS({
1067
1071
  this._binaryType = options.binaryType || BINARY_TYPES[0];
1068
1072
  this._extensions = options.extensions || {};
1069
1073
  this._isServer = !!options.isServer;
1074
+ this._maxBufferedChunks = options.maxBufferedChunks | 0;
1075
+ this._maxFragments = options.maxFragments | 0;
1070
1076
  this._maxPayload = options.maxPayload | 0;
1071
1077
  this._skipUTF8Validation = !!options.skipUTF8Validation;
1072
1078
  this[kWebSocket] = void 0;
@@ -1096,6 +1102,18 @@ var require_receiver = __commonJS({
1096
1102
  */
1097
1103
  _write(chunk, encoding, cb) {
1098
1104
  if (this._opcode === 8 && this._state == GET_INFO) return cb();
1105
+ if (this._maxBufferedChunks > 0 && this._buffers.length >= this._maxBufferedChunks) {
1106
+ cb(
1107
+ this.createError(
1108
+ RangeError,
1109
+ "Too many buffered chunks",
1110
+ false,
1111
+ 1008,
1112
+ "WS_ERR_TOO_MANY_BUFFERED_PARTS"
1113
+ )
1114
+ );
1115
+ return;
1116
+ }
1099
1117
  this._bufferedBytes += chunk.length;
1100
1118
  this._buffers.push(chunk);
1101
1119
  this.startLoop(cb);
@@ -1194,7 +1212,7 @@ var require_receiver = __commonJS({
1194
1212
  return;
1195
1213
  }
1196
1214
  const compressed = (buf[0] & 64) === 64;
1197
- if (compressed && !this._extensions[PerMessageDeflate.extensionName]) {
1215
+ if (compressed && !this._extensions[PerMessageDeflate2.extensionName]) {
1198
1216
  const error = this.createError(
1199
1217
  RangeError,
1200
1218
  "RSV1 must be clear",
@@ -1425,6 +1443,17 @@ var require_receiver = __commonJS({
1425
1443
  return;
1426
1444
  }
1427
1445
  if (data.length) {
1446
+ if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
1447
+ const error = this.createError(
1448
+ RangeError,
1449
+ "Too many message fragments",
1450
+ false,
1451
+ 1008,
1452
+ "WS_ERR_TOO_MANY_BUFFERED_PARTS"
1453
+ );
1454
+ cb(error);
1455
+ return;
1456
+ }
1428
1457
  this._messageLength = this._totalPayloadLength;
1429
1458
  this._fragments.push(data);
1430
1459
  }
@@ -1438,7 +1467,7 @@ var require_receiver = __commonJS({
1438
1467
  * @private
1439
1468
  */
1440
1469
  decompress(data, cb) {
1441
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1470
+ const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
1442
1471
  perMessageDeflate.decompress(data, this._fin, (err, buf) => {
1443
1472
  if (err) return cb(err);
1444
1473
  if (buf.length) {
@@ -1454,6 +1483,17 @@ var require_receiver = __commonJS({
1454
1483
  cb(error);
1455
1484
  return;
1456
1485
  }
1486
+ if (this._maxFragments > 0 && this._fragments.length >= this._maxFragments) {
1487
+ const error = this.createError(
1488
+ RangeError,
1489
+ "Too many message fragments",
1490
+ false,
1491
+ 1008,
1492
+ "WS_ERR_TOO_MANY_BUFFERED_PARTS"
1493
+ );
1494
+ cb(error);
1495
+ return;
1496
+ }
1457
1497
  this._fragments.push(buf);
1458
1498
  }
1459
1499
  this.dataMessage(cb);
@@ -1619,7 +1659,10 @@ var require_sender = __commonJS({
1619
1659
  "../../node_modules/ws/lib/sender.js"(exports, module) {
1620
1660
  var { Duplex } = __require("stream");
1621
1661
  var { randomFillSync } = __require("crypto");
1622
- var PerMessageDeflate = require_permessage_deflate();
1662
+ var {
1663
+ types: { isUint8Array }
1664
+ } = __require("util");
1665
+ var PerMessageDeflate2 = require_permessage_deflate();
1623
1666
  var { EMPTY_BUFFER, kWebSocket, NOOP } = require_constants();
1624
1667
  var { isBlob, isValidStatusCode } = require_validation();
1625
1668
  var { mask: applyMask, toBuffer } = require_buffer_util();
@@ -1772,8 +1815,10 @@ var require_sender = __commonJS({
1772
1815
  buf.writeUInt16BE(code, 0);
1773
1816
  if (typeof data === "string") {
1774
1817
  buf.write(data, 2);
1775
- } else {
1818
+ } else if (isUint8Array(data)) {
1776
1819
  buf.set(data, 2);
1820
+ } else {
1821
+ throw new TypeError("Second argument must be a string or a Uint8Array");
1777
1822
  }
1778
1823
  }
1779
1824
  const options = {
@@ -1903,7 +1948,7 @@ var require_sender = __commonJS({
1903
1948
  * @public
1904
1949
  */
1905
1950
  send(data, options, cb) {
1906
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
1951
+ const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
1907
1952
  let opcode = options.binary ? 2 : 1;
1908
1953
  let rsv1 = options.compress;
1909
1954
  let byteLength;
@@ -2027,7 +2072,7 @@ var require_sender = __commonJS({
2027
2072
  this.sendFrame(_Sender.frame(data, options), cb);
2028
2073
  return;
2029
2074
  }
2030
- const perMessageDeflate = this._extensions[PerMessageDeflate.extensionName];
2075
+ const perMessageDeflate = this._extensions[PerMessageDeflate2.extensionName];
2031
2076
  this._bufferedBytes += options[kByteLength];
2032
2077
  this._state = DEFLATING;
2033
2078
  perMessageDeflate.compress(data, options.fin, (_, buf) => {
@@ -2463,11 +2508,11 @@ var require_extension = __commonJS({
2463
2508
  return offers;
2464
2509
  }
2465
2510
  function format(extensions) {
2466
- return Object.keys(extensions).map((extension) => {
2467
- let configurations = extensions[extension];
2511
+ return Object.keys(extensions).map((extension2) => {
2512
+ let configurations = extensions[extension2];
2468
2513
  if (!Array.isArray(configurations)) configurations = [configurations];
2469
2514
  return configurations.map((params) => {
2470
- return [extension].concat(
2515
+ return [extension2].concat(
2471
2516
  Object.keys(params).map((k) => {
2472
2517
  let values = params[k];
2473
2518
  if (!Array.isArray(values)) values = [values];
@@ -2492,7 +2537,7 @@ var require_websocket = __commonJS({
2492
2537
  var { randomBytes, createHash } = __require("crypto");
2493
2538
  var { Duplex, Readable } = __require("stream");
2494
2539
  var { URL: URL2 } = __require("url");
2495
- var PerMessageDeflate = require_permessage_deflate();
2540
+ var PerMessageDeflate2 = require_permessage_deflate();
2496
2541
  var Receiver2 = require_receiver();
2497
2542
  var Sender2 = require_sender();
2498
2543
  var { isBlob } = require_validation();
@@ -2651,6 +2696,10 @@ var require_websocket = __commonJS({
2651
2696
  * multiple times in the same tick
2652
2697
  * @param {Function} [options.generateMask] The function used to generate the
2653
2698
  * masking key
2699
+ * @param {Number} [options.maxBufferedChunks=0] The maximum number of
2700
+ * buffered data chunks
2701
+ * @param {Number} [options.maxFragments=0] The maximum number of message
2702
+ * fragments
2654
2703
  * @param {Number} [options.maxPayload=0] The maximum allowed message size
2655
2704
  * @param {Boolean} [options.skipUTF8Validation=false] Specifies whether or
2656
2705
  * not to skip UTF-8 validation for text and close messages
@@ -2662,6 +2711,8 @@ var require_websocket = __commonJS({
2662
2711
  binaryType: this.binaryType,
2663
2712
  extensions: this._extensions,
2664
2713
  isServer: this._isServer,
2714
+ maxBufferedChunks: options.maxBufferedChunks,
2715
+ maxFragments: options.maxFragments,
2665
2716
  maxPayload: options.maxPayload,
2666
2717
  skipUTF8Validation: options.skipUTF8Validation
2667
2718
  });
@@ -2700,8 +2751,8 @@ var require_websocket = __commonJS({
2700
2751
  this.emit("close", this._closeCode, this._closeMessage);
2701
2752
  return;
2702
2753
  }
2703
- if (this._extensions[PerMessageDeflate.extensionName]) {
2704
- this._extensions[PerMessageDeflate.extensionName].cleanup();
2754
+ if (this._extensions[PerMessageDeflate2.extensionName]) {
2755
+ this._extensions[PerMessageDeflate2.extensionName].cleanup();
2705
2756
  }
2706
2757
  this._receiver.removeAllListeners();
2707
2758
  this._readyState = _WebSocket.CLOSED;
@@ -2863,7 +2914,7 @@ var require_websocket = __commonJS({
2863
2914
  fin: true,
2864
2915
  ...options
2865
2916
  };
2866
- if (!this._extensions[PerMessageDeflate.extensionName]) {
2917
+ if (!this._extensions[PerMessageDeflate2.extensionName]) {
2867
2918
  opts.compress = false;
2868
2919
  }
2869
2920
  this._sender.send(data || EMPTY_BUFFER, opts, cb);
@@ -2961,6 +3012,8 @@ var require_websocket = __commonJS({
2961
3012
  autoPong: true,
2962
3013
  closeTimeout: CLOSE_TIMEOUT,
2963
3014
  protocolVersion: protocolVersions[1],
3015
+ maxBufferedChunks: 1024 * 1024,
3016
+ maxFragments: 128 * 1024,
2964
3017
  maxPayload: 100 * 1024 * 1024,
2965
3018
  skipUTF8Validation: false,
2966
3019
  perMessageDeflate: true,
@@ -2989,7 +3042,7 @@ var require_websocket = __commonJS({
2989
3042
  } else {
2990
3043
  try {
2991
3044
  parsedUrl = new URL2(address);
2992
- } catch (e) {
3045
+ } catch {
2993
3046
  throw new SyntaxError(`Invalid URL: ${address}`);
2994
3047
  }
2995
3048
  }
@@ -3037,13 +3090,13 @@ var require_websocket = __commonJS({
3037
3090
  opts.path = parsedUrl.pathname + parsedUrl.search;
3038
3091
  opts.timeout = opts.handshakeTimeout;
3039
3092
  if (opts.perMessageDeflate) {
3040
- perMessageDeflate = new PerMessageDeflate(
3041
- opts.perMessageDeflate !== true ? opts.perMessageDeflate : {},
3042
- false,
3043
- opts.maxPayload
3044
- );
3093
+ perMessageDeflate = new PerMessageDeflate2({
3094
+ ...opts.perMessageDeflate,
3095
+ isServer: false,
3096
+ maxPayload: opts.maxPayload
3097
+ });
3045
3098
  opts.headers["Sec-WebSocket-Extensions"] = format({
3046
- [PerMessageDeflate.extensionName]: perMessageDeflate.offer()
3099
+ [PerMessageDeflate2.extensionName]: perMessageDeflate.offer()
3047
3100
  });
3048
3101
  }
3049
3102
  if (protocols.length) {
@@ -3186,23 +3239,25 @@ var require_websocket = __commonJS({
3186
3239
  return;
3187
3240
  }
3188
3241
  const extensionNames = Object.keys(extensions);
3189
- if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate.extensionName) {
3242
+ if (extensionNames.length !== 1 || extensionNames[0] !== PerMessageDeflate2.extensionName) {
3190
3243
  const message = "Server indicated an extension that was not requested";
3191
3244
  abortHandshake(websocket, socket, message);
3192
3245
  return;
3193
3246
  }
3194
3247
  try {
3195
- perMessageDeflate.accept(extensions[PerMessageDeflate.extensionName]);
3248
+ perMessageDeflate.accept(extensions[PerMessageDeflate2.extensionName]);
3196
3249
  } catch (err) {
3197
3250
  const message = "Invalid Sec-WebSocket-Extensions header";
3198
3251
  abortHandshake(websocket, socket, message);
3199
3252
  return;
3200
3253
  }
3201
- websocket._extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3254
+ websocket._extensions[PerMessageDeflate2.extensionName] = perMessageDeflate;
3202
3255
  }
3203
3256
  websocket.setSocket(socket, head, {
3204
3257
  allowSynchronousEvents: opts.allowSynchronousEvents,
3205
3258
  generateMask: opts.generateMask,
3259
+ maxBufferedChunks: opts.maxBufferedChunks,
3260
+ maxFragments: opts.maxFragments,
3206
3261
  maxPayload: opts.maxPayload,
3207
3262
  skipUTF8Validation: opts.skipUTF8Validation
3208
3263
  });
@@ -3514,9 +3569,9 @@ var require_websocket_server = __commonJS({
3514
3569
  var http = __require("http");
3515
3570
  var { Duplex } = __require("stream");
3516
3571
  var { createHash } = __require("crypto");
3517
- var extension = require_extension();
3518
- var PerMessageDeflate = require_permessage_deflate();
3519
- var subprotocol = require_subprotocol();
3572
+ var extension2 = require_extension();
3573
+ var PerMessageDeflate2 = require_permessage_deflate();
3574
+ var subprotocol2 = require_subprotocol();
3520
3575
  var WebSocket2 = require_websocket();
3521
3576
  var { CLOSE_TIMEOUT, GUID, kWebSocket } = require_constants();
3522
3577
  var keyRegex = /^[+/0-9A-Za-z]{22}==$/;
@@ -3542,6 +3597,10 @@ var require_websocket_server = __commonJS({
3542
3597
  * called
3543
3598
  * @param {Function} [options.handleProtocols] A hook to handle protocols
3544
3599
  * @param {String} [options.host] The hostname where to bind the server
3600
+ * @param {Number} [options.maxBufferedChunks=1048576] The maximum number of
3601
+ * buffered data chunks
3602
+ * @param {Number} [options.maxFragments=131072] The maximum number of message
3603
+ * fragments
3545
3604
  * @param {Number} [options.maxPayload=104857600] The maximum allowed message
3546
3605
  * size
3547
3606
  * @param {Boolean} [options.noServer=false] Enable no server mode
@@ -3563,6 +3622,8 @@ var require_websocket_server = __commonJS({
3563
3622
  options = {
3564
3623
  allowSynchronousEvents: true,
3565
3624
  autoPong: true,
3625
+ maxBufferedChunks: 1024 * 1024,
3626
+ maxFragments: 128 * 1024,
3566
3627
  maxPayload: 100 * 1024 * 1024,
3567
3628
  skipUTF8Validation: false,
3568
3629
  perMessageDeflate: false,
@@ -3739,7 +3800,7 @@ var require_websocket_server = __commonJS({
3739
3800
  let protocols = /* @__PURE__ */ new Set();
3740
3801
  if (secWebSocketProtocol !== void 0) {
3741
3802
  try {
3742
- protocols = subprotocol.parse(secWebSocketProtocol);
3803
+ protocols = subprotocol2.parse(secWebSocketProtocol);
3743
3804
  } catch (err) {
3744
3805
  const message = "Invalid Sec-WebSocket-Protocol header";
3745
3806
  abortHandshakeOrEmitwsClientError(this, req, socket, 400, message);
@@ -3749,16 +3810,16 @@ var require_websocket_server = __commonJS({
3749
3810
  const secWebSocketExtensions = req.headers["sec-websocket-extensions"];
3750
3811
  const extensions = {};
3751
3812
  if (this.options.perMessageDeflate && secWebSocketExtensions !== void 0) {
3752
- const perMessageDeflate = new PerMessageDeflate(
3753
- this.options.perMessageDeflate,
3754
- true,
3755
- this.options.maxPayload
3756
- );
3813
+ const perMessageDeflate = new PerMessageDeflate2({
3814
+ ...this.options.perMessageDeflate,
3815
+ isServer: true,
3816
+ maxPayload: this.options.maxPayload
3817
+ });
3757
3818
  try {
3758
- const offers = extension.parse(secWebSocketExtensions);
3759
- if (offers[PerMessageDeflate.extensionName]) {
3760
- perMessageDeflate.accept(offers[PerMessageDeflate.extensionName]);
3761
- extensions[PerMessageDeflate.extensionName] = perMessageDeflate;
3819
+ const offers = extension2.parse(secWebSocketExtensions);
3820
+ if (offers[PerMessageDeflate2.extensionName]) {
3821
+ perMessageDeflate.accept(offers[PerMessageDeflate2.extensionName]);
3822
+ extensions[PerMessageDeflate2.extensionName] = perMessageDeflate;
3762
3823
  }
3763
3824
  } catch (err) {
3764
3825
  const message = "Invalid or unacceptable Sec-WebSocket-Extensions header";
@@ -3829,10 +3890,10 @@ var require_websocket_server = __commonJS({
3829
3890
  ws._protocol = protocol;
3830
3891
  }
3831
3892
  }
3832
- if (extensions[PerMessageDeflate.extensionName]) {
3833
- const params = extensions[PerMessageDeflate.extensionName].params;
3834
- const value = extension.format({
3835
- [PerMessageDeflate.extensionName]: [params]
3893
+ if (extensions[PerMessageDeflate2.extensionName]) {
3894
+ const params = extensions[PerMessageDeflate2.extensionName].params;
3895
+ const value = extension2.format({
3896
+ [PerMessageDeflate2.extensionName]: [params]
3836
3897
  });
3837
3898
  headers.push(`Sec-WebSocket-Extensions: ${value}`);
3838
3899
  ws._extensions = extensions;
@@ -3842,6 +3903,8 @@ var require_websocket_server = __commonJS({
3842
3903
  socket.removeListener("error", socketOnError);
3843
3904
  ws.setSocket(socket, head, {
3844
3905
  allowSynchronousEvents: this.options.allowSynchronousEvents,
3906
+ maxBufferedChunks: this.options.maxBufferedChunks,
3907
+ maxFragments: this.options.maxFragments,
3845
3908
  maxPayload: this.options.maxPayload,
3846
3909
  skipUTF8Validation: this.options.skipUTF8Validation
3847
3910
  });
@@ -3902,19 +3965,25 @@ var require_websocket_server = __commonJS({
3902
3965
  // ../../node_modules/ws/wrapper.mjs
3903
3966
  var wrapper_exports = {};
3904
3967
  __export(wrapper_exports, {
3968
+ PerMessageDeflate: () => import_permessage_deflate.default,
3905
3969
  Receiver: () => import_receiver.default,
3906
3970
  Sender: () => import_sender.default,
3907
3971
  WebSocket: () => import_websocket.default,
3908
3972
  WebSocketServer: () => import_websocket_server.default,
3909
3973
  createWebSocketStream: () => import_stream.default,
3910
- default: () => wrapper_default
3974
+ default: () => wrapper_default,
3975
+ extension: () => import_extension.default,
3976
+ subprotocol: () => import_subprotocol.default
3911
3977
  });
3912
- var import_stream, import_receiver, import_sender, import_websocket, import_websocket_server, wrapper_default;
3978
+ var import_stream, import_extension, import_permessage_deflate, import_receiver, import_sender, import_subprotocol, import_websocket, import_websocket_server, wrapper_default;
3913
3979
  var init_wrapper = __esm({
3914
3980
  "../../node_modules/ws/wrapper.mjs"() {
3915
3981
  import_stream = __toESM(require_stream());
3982
+ import_extension = __toESM(require_extension());
3983
+ import_permessage_deflate = __toESM(require_permessage_deflate());
3916
3984
  import_receiver = __toESM(require_receiver());
3917
3985
  import_sender = __toESM(require_sender());
3986
+ import_subprotocol = __toESM(require_subprotocol());
3918
3987
  import_websocket = __toESM(require_websocket());
3919
3988
  import_websocket_server = __toESM(require_websocket_server());
3920
3989
  wrapper_default = import_websocket.default;
@@ -11373,6 +11442,164 @@ async function invokeRegisteredEffect(effectMap, request) {
11373
11442
  return resolved.handler(request.input, context);
11374
11443
  }
11375
11444
 
11445
+ // src/client-normalizers.ts
11446
+ function createEmptyHeapSnapshot(now = Date.now()) {
11447
+ return {
11448
+ entriesByPath: {},
11449
+ listsByName: {},
11450
+ variablesByName: {},
11451
+ updatedAt: now
11452
+ };
11453
+ }
11454
+ function normalizeHeapSnapshot(raw) {
11455
+ if (!raw || typeof raw !== "object") {
11456
+ return createEmptyHeapSnapshot();
11457
+ }
11458
+ const heap = raw;
11459
+ return {
11460
+ entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
11461
+ listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
11462
+ variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
11463
+ updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
11464
+ };
11465
+ }
11466
+ function normalizeGraphPathSegment(value) {
11467
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
11468
+ }
11469
+ function extractRecordIdFromGraphPath(path, className) {
11470
+ const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
11471
+ if (path.startsWith(normalizedPrefix)) {
11472
+ return path.slice(normalizedPrefix.length);
11473
+ }
11474
+ const legacyPrefix = `${className}_`;
11475
+ if (path.startsWith(legacyPrefix)) {
11476
+ return path.slice(legacyPrefix.length);
11477
+ }
11478
+ return path;
11479
+ }
11480
+ function toRecordSearchResult(className, node) {
11481
+ const path = typeof node.path === "string" ? node.path : "";
11482
+ if (!path) return null;
11483
+ const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
11484
+ (submodel) => {
11485
+ const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
11486
+ if (!name) return [];
11487
+ if (typeof submodel.string_value === "string") {
11488
+ return [{ name, type: "string", value: submodel.string_value }];
11489
+ }
11490
+ if (typeof submodel.number_value === "number") {
11491
+ return [{ name, type: "number", value: submodel.number_value }];
11492
+ }
11493
+ if (typeof submodel.boolean_value === "boolean") {
11494
+ return [
11495
+ {
11496
+ name,
11497
+ type: "boolean",
11498
+ value: submodel.boolean_value
11499
+ }
11500
+ ];
11501
+ }
11502
+ return [];
11503
+ }
11504
+ ) : [];
11505
+ return {
11506
+ path,
11507
+ className,
11508
+ id: extractRecordIdFromGraphPath(path, className),
11509
+ label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path, className),
11510
+ description: typeof node.description === "string" && node.description.trim() ? node.description : null,
11511
+ fields
11512
+ };
11513
+ }
11514
+ function normalizeRecordSearchText(value) {
11515
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
11516
+ }
11517
+ function rankRecordSearchResult(result, query, index) {
11518
+ const normalizedQuery = normalizeRecordSearchText(query);
11519
+ if (!normalizedQuery) {
11520
+ return index;
11521
+ }
11522
+ const label = normalizeRecordSearchText(result.label || "");
11523
+ const id = normalizeRecordSearchText(result.id || "");
11524
+ const path = normalizeRecordSearchText(result.path || "");
11525
+ const className = normalizeRecordSearchText(result.className || "");
11526
+ const searchable = [label, id, path, className].filter(Boolean);
11527
+ if (label === normalizedQuery) return index;
11528
+ if (id === normalizedQuery || path === normalizedQuery) return 100 + index;
11529
+ if (label.startsWith(normalizedQuery)) return 200 + index;
11530
+ if (searchable.some((value) => value.startsWith(normalizedQuery))) {
11531
+ return 300 + index;
11532
+ }
11533
+ if (label.includes(normalizedQuery)) return 400 + index;
11534
+ if (searchable.some((value) => value.includes(normalizedQuery))) {
11535
+ return 500 + index;
11536
+ }
11537
+ return 900 + index;
11538
+ }
11539
+ function deriveRuntimeBaseUrl(apiEndpoint) {
11540
+ try {
11541
+ const endpoint = new URL(apiEndpoint);
11542
+ const graphqlSuffix = "/orchestrator/graphql";
11543
+ if (endpoint.pathname.endsWith(graphqlSuffix)) {
11544
+ endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
11545
+ } else if (endpoint.pathname.endsWith("/graphql")) {
11546
+ endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
11547
+ }
11548
+ endpoint.search = "";
11549
+ endpoint.hash = "";
11550
+ return endpoint.toString().replace(/\/$/, "");
11551
+ } catch {
11552
+ return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
11553
+ }
11554
+ }
11555
+
11556
+ // src/client-transport.ts
11557
+ function sleep(ms) {
11558
+ return new Promise((resolve) => setTimeout(resolve, ms));
11559
+ }
11560
+ function withTimeout(promise, timeoutMs, label) {
11561
+ let timer = null;
11562
+ const timeout = new Promise((_, reject) => {
11563
+ timer = setTimeout(() => {
11564
+ reject(new Error(`${label} timed out after ${timeoutMs}ms`));
11565
+ }, timeoutMs);
11566
+ });
11567
+ return Promise.race([promise, timeout]).finally(() => {
11568
+ if (timer) {
11569
+ clearTimeout(timer);
11570
+ }
11571
+ });
11572
+ }
11573
+ function isLocalControlUrl(url) {
11574
+ try {
11575
+ const parsed = new URL(url);
11576
+ return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
11577
+ } catch {
11578
+ return false;
11579
+ }
11580
+ }
11581
+ function isRetryableLocalWorkerRestart(status, body, url) {
11582
+ return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
11583
+ }
11584
+ function isRetryableRecordObjectsError(error) {
11585
+ const message = error instanceof Error ? error.message : String(error);
11586
+ return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out|bad gateway|too many requests|gateway timeout|control plane api error \((?:429|500|502|503|504)\)|graphql api error \((?:429|500|502|503|504)\)|failed to record batch/i.test(
11587
+ message
11588
+ );
11589
+ }
11590
+ function isRetryableEffectRegistrationError(error) {
11591
+ const message = error instanceof Error ? error.message : String(error);
11592
+ return /timed out|websocket disconnected|websocket not connected|rpc timeout|worker restarted mid-request|network connection lost|bad gateway|gateway timeout|too many requests|(?:control plane|granular|graphql) api error \((?:429|500|502|503|504)\)/i.test(
11593
+ message
11594
+ );
11595
+ }
11596
+ function isRetryableSessionDataError(error) {
11597
+ const message = error instanceof Error ? error.message : String(error);
11598
+ return /network connection lost|worker restarted mid-request|econnreset|socket connection was closed unexpectedly|bad gateway|gateway timeout|service unavailable|session data api error \((?:429|500|502|503|504)\)/i.test(
11599
+ message
11600
+ );
11601
+ }
11602
+
11376
11603
  // src/spend.ts
11377
11604
  function toGranularHttpBase(apiUrl) {
11378
11605
  const url = new URL(apiUrl);
@@ -12858,51 +13085,6 @@ function planRecordObjectsChunks(records, batchSize) {
12858
13085
  }
12859
13086
  return plans;
12860
13087
  }
12861
- function sleep(ms) {
12862
- return new Promise((resolve) => setTimeout(resolve, ms));
12863
- }
12864
- function withTimeout(promise, timeoutMs, label) {
12865
- let timer = null;
12866
- const timeout = new Promise((_, reject) => {
12867
- timer = setTimeout(() => {
12868
- reject(new Error(`${label} timed out after ${timeoutMs}ms`));
12869
- }, timeoutMs);
12870
- });
12871
- return Promise.race([promise, timeout]).finally(() => {
12872
- if (timer) {
12873
- clearTimeout(timer);
12874
- }
12875
- });
12876
- }
12877
- function isLocalControlUrl(url) {
12878
- try {
12879
- const parsed = new URL(url);
12880
- return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
12881
- } catch {
12882
- return false;
12883
- }
12884
- }
12885
- function isRetryableLocalWorkerRestart(status, body, url) {
12886
- return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
12887
- }
12888
- function isRetryableRecordObjectsError(error) {
12889
- const message = error instanceof Error ? error.message : String(error);
12890
- return /worker restarted mid-request|econnreset|network|socket connection was closed unexpectedly|timed out|bad gateway|too many requests|gateway timeout|control plane api error \((?:429|500|502|503|504)\)|graphql api error \((?:429|500|502|503|504)\)|failed to record batch/i.test(
12891
- message
12892
- );
12893
- }
12894
- function isRetryableEffectRegistrationError(error) {
12895
- const message = error instanceof Error ? error.message : String(error);
12896
- return /timed out|websocket disconnected|websocket not connected|rpc timeout|worker restarted mid-request|network connection lost|bad gateway|gateway timeout|too many requests|(?:control plane|granular|graphql) api error \((?:429|500|502|503|504)\)/i.test(
12897
- message
12898
- );
12899
- }
12900
- function isRetryableSessionDataError(error) {
12901
- const message = error instanceof Error ? error.message : String(error);
12902
- return /network connection lost|worker restarted mid-request|econnreset|socket connection was closed unexpectedly|bad gateway|gateway timeout|service unavailable|session data api error \((?:429|500|502|503|504)\)/i.test(
12903
- message
12904
- );
12905
- }
12906
13088
  function computeEffectKey2(effect) {
12907
13089
  const attachedClass = effect.className?.trim();
12908
13090
  if (!attachedClass) {
@@ -12957,115 +13139,6 @@ function buildEffectHostUrl(apiUrl, sandboxId, effectClientId, clientId, effectH
12957
13139
  url.searchParams.set("clientId", clientId);
12958
13140
  return url.toString();
12959
13141
  }
12960
- function createEmptyHeapSnapshot(now = Date.now()) {
12961
- return {
12962
- entriesByPath: {},
12963
- listsByName: {},
12964
- variablesByName: {},
12965
- updatedAt: now
12966
- };
12967
- }
12968
- function normalizeHeapSnapshot(raw) {
12969
- if (!raw || typeof raw !== "object") {
12970
- return createEmptyHeapSnapshot();
12971
- }
12972
- const heap = raw;
12973
- return {
12974
- entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
12975
- listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
12976
- variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
12977
- updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
12978
- };
12979
- }
12980
- function normalizeGraphPathSegment(value) {
12981
- return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
12982
- }
12983
- function extractRecordIdFromGraphPath(path, className) {
12984
- const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
12985
- if (path.startsWith(normalizedPrefix)) {
12986
- return path.slice(normalizedPrefix.length);
12987
- }
12988
- const legacyPrefix = `${className}_`;
12989
- if (path.startsWith(legacyPrefix)) {
12990
- return path.slice(legacyPrefix.length);
12991
- }
12992
- return path;
12993
- }
12994
- function toRecordSearchResult(className, node) {
12995
- const path = typeof node.path === "string" ? node.path : "";
12996
- if (!path) return null;
12997
- const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
12998
- (submodel) => {
12999
- const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
13000
- if (!name) return [];
13001
- if (typeof submodel.string_value === "string") {
13002
- return [{ name, type: "string", value: submodel.string_value }];
13003
- }
13004
- if (typeof submodel.number_value === "number") {
13005
- return [{ name, type: "number", value: submodel.number_value }];
13006
- }
13007
- if (typeof submodel.boolean_value === "boolean") {
13008
- return [
13009
- {
13010
- name,
13011
- type: "boolean",
13012
- value: submodel.boolean_value
13013
- }
13014
- ];
13015
- }
13016
- return [];
13017
- }
13018
- ) : [];
13019
- return {
13020
- path,
13021
- className,
13022
- id: extractRecordIdFromGraphPath(path, className),
13023
- label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path, className),
13024
- description: typeof node.description === "string" && node.description.trim() ? node.description : null,
13025
- fields
13026
- };
13027
- }
13028
- function normalizeRecordSearchText(value) {
13029
- return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
13030
- }
13031
- function rankRecordSearchResult(result, query, index) {
13032
- const normalizedQuery = normalizeRecordSearchText(query);
13033
- if (!normalizedQuery) {
13034
- return index;
13035
- }
13036
- const label = normalizeRecordSearchText(result.label || "");
13037
- const id = normalizeRecordSearchText(result.id || "");
13038
- const path = normalizeRecordSearchText(result.path || "");
13039
- const className = normalizeRecordSearchText(result.className || "");
13040
- const searchable = [label, id, path, className].filter(Boolean);
13041
- if (label === normalizedQuery) return index;
13042
- if (id === normalizedQuery || path === normalizedQuery) return 100 + index;
13043
- if (label.startsWith(normalizedQuery)) return 200 + index;
13044
- if (searchable.some((value) => value.startsWith(normalizedQuery))) {
13045
- return 300 + index;
13046
- }
13047
- if (label.includes(normalizedQuery)) return 400 + index;
13048
- if (searchable.some((value) => value.includes(normalizedQuery))) {
13049
- return 500 + index;
13050
- }
13051
- return 900 + index;
13052
- }
13053
- function deriveRuntimeBaseUrl(apiEndpoint) {
13054
- try {
13055
- const endpoint = new URL(apiEndpoint);
13056
- const graphqlSuffix = "/orchestrator/graphql";
13057
- if (endpoint.pathname.endsWith(graphqlSuffix)) {
13058
- endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
13059
- } else if (endpoint.pathname.endsWith("/graphql")) {
13060
- endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
13061
- }
13062
- endpoint.search = "";
13063
- endpoint.hash = "";
13064
- return endpoint.toString().replace(/\/$/, "");
13065
- } catch {
13066
- return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
13067
- }
13068
- }
13069
13142
  function normalizeSubject(subject) {
13070
13143
  const granularId = subject.granularId || subject.subjectId;
13071
13144
  const userId = subject.userId || subject.identityId || granularId;