@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/cli/index.js CHANGED
@@ -21583,6 +21583,164 @@ async function invokeRegisteredEffect(effectMap, request) {
21583
21583
  return resolved.handler(request.input, context);
21584
21584
  }
21585
21585
 
21586
+ // src/client-normalizers.ts
21587
+ function createEmptyHeapSnapshot(now = Date.now()) {
21588
+ return {
21589
+ entriesByPath: {},
21590
+ listsByName: {},
21591
+ variablesByName: {},
21592
+ updatedAt: now
21593
+ };
21594
+ }
21595
+ function normalizeHeapSnapshot(raw) {
21596
+ if (!raw || typeof raw !== "object") {
21597
+ return createEmptyHeapSnapshot();
21598
+ }
21599
+ const heap = raw;
21600
+ return {
21601
+ entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
21602
+ listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
21603
+ variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
21604
+ updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
21605
+ };
21606
+ }
21607
+ function normalizeGraphPathSegment(value) {
21608
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
21609
+ }
21610
+ function extractRecordIdFromGraphPath(path7, className) {
21611
+ const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
21612
+ if (path7.startsWith(normalizedPrefix)) {
21613
+ return path7.slice(normalizedPrefix.length);
21614
+ }
21615
+ const legacyPrefix = `${className}_`;
21616
+ if (path7.startsWith(legacyPrefix)) {
21617
+ return path7.slice(legacyPrefix.length);
21618
+ }
21619
+ return path7;
21620
+ }
21621
+ function toRecordSearchResult(className, node) {
21622
+ const path7 = typeof node.path === "string" ? node.path : "";
21623
+ if (!path7) return null;
21624
+ const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
21625
+ (submodel) => {
21626
+ const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
21627
+ if (!name) return [];
21628
+ if (typeof submodel.string_value === "string") {
21629
+ return [{ name, type: "string", value: submodel.string_value }];
21630
+ }
21631
+ if (typeof submodel.number_value === "number") {
21632
+ return [{ name, type: "number", value: submodel.number_value }];
21633
+ }
21634
+ if (typeof submodel.boolean_value === "boolean") {
21635
+ return [
21636
+ {
21637
+ name,
21638
+ type: "boolean",
21639
+ value: submodel.boolean_value
21640
+ }
21641
+ ];
21642
+ }
21643
+ return [];
21644
+ }
21645
+ ) : [];
21646
+ return {
21647
+ path: path7,
21648
+ className,
21649
+ id: extractRecordIdFromGraphPath(path7, className),
21650
+ label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path7, className),
21651
+ description: typeof node.description === "string" && node.description.trim() ? node.description : null,
21652
+ fields
21653
+ };
21654
+ }
21655
+ function normalizeRecordSearchText(value) {
21656
+ return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
21657
+ }
21658
+ function rankRecordSearchResult(result, query, index) {
21659
+ const normalizedQuery = normalizeRecordSearchText(query);
21660
+ if (!normalizedQuery) {
21661
+ return index;
21662
+ }
21663
+ const label = normalizeRecordSearchText(result.label || "");
21664
+ const id = normalizeRecordSearchText(result.id || "");
21665
+ const path7 = normalizeRecordSearchText(result.path || "");
21666
+ const className = normalizeRecordSearchText(result.className || "");
21667
+ const searchable = [label, id, path7, className].filter(Boolean);
21668
+ if (label === normalizedQuery) return index;
21669
+ if (id === normalizedQuery || path7 === normalizedQuery) return 100 + index;
21670
+ if (label.startsWith(normalizedQuery)) return 200 + index;
21671
+ if (searchable.some((value) => value.startsWith(normalizedQuery))) {
21672
+ return 300 + index;
21673
+ }
21674
+ if (label.includes(normalizedQuery)) return 400 + index;
21675
+ if (searchable.some((value) => value.includes(normalizedQuery))) {
21676
+ return 500 + index;
21677
+ }
21678
+ return 900 + index;
21679
+ }
21680
+ function deriveRuntimeBaseUrl(apiEndpoint) {
21681
+ try {
21682
+ const endpoint = new URL(apiEndpoint);
21683
+ const graphqlSuffix = "/orchestrator/graphql";
21684
+ if (endpoint.pathname.endsWith(graphqlSuffix)) {
21685
+ endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
21686
+ } else if (endpoint.pathname.endsWith("/graphql")) {
21687
+ endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
21688
+ }
21689
+ endpoint.search = "";
21690
+ endpoint.hash = "";
21691
+ return endpoint.toString().replace(/\/$/, "");
21692
+ } catch {
21693
+ return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
21694
+ }
21695
+ }
21696
+
21697
+ // src/client-transport.ts
21698
+ function sleep(ms) {
21699
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
21700
+ }
21701
+ function withTimeout(promise, timeoutMs, label) {
21702
+ let timer = null;
21703
+ const timeout = new Promise((_, reject) => {
21704
+ timer = setTimeout(() => {
21705
+ reject(new Error(`${label} timed out after ${timeoutMs}ms`));
21706
+ }, timeoutMs);
21707
+ });
21708
+ return Promise.race([promise, timeout]).finally(() => {
21709
+ if (timer) {
21710
+ clearTimeout(timer);
21711
+ }
21712
+ });
21713
+ }
21714
+ function isLocalControlUrl(url) {
21715
+ try {
21716
+ const parsed = new URL(url);
21717
+ return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
21718
+ } catch {
21719
+ return false;
21720
+ }
21721
+ }
21722
+ function isRetryableLocalWorkerRestart(status, body, url) {
21723
+ return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
21724
+ }
21725
+ function isRetryableRecordObjectsError(error2) {
21726
+ const message = error2 instanceof Error ? error2.message : String(error2);
21727
+ 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(
21728
+ message
21729
+ );
21730
+ }
21731
+ function isRetryableEffectRegistrationError(error2) {
21732
+ const message = error2 instanceof Error ? error2.message : String(error2);
21733
+ 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(
21734
+ message
21735
+ );
21736
+ }
21737
+ function isRetryableSessionDataError(error2) {
21738
+ const message = error2 instanceof Error ? error2.message : String(error2);
21739
+ 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(
21740
+ message
21741
+ );
21742
+ }
21743
+
21586
21744
  // src/spend.ts
21587
21745
  function toGranularHttpBase(apiUrl) {
21588
21746
  const url = new URL(apiUrl);
@@ -21784,51 +21942,6 @@ function planRecordObjectsChunks(records, batchSize) {
21784
21942
  }
21785
21943
  return plans;
21786
21944
  }
21787
- function sleep(ms) {
21788
- return new Promise((resolve2) => setTimeout(resolve2, ms));
21789
- }
21790
- function withTimeout(promise, timeoutMs, label) {
21791
- let timer = null;
21792
- const timeout = new Promise((_, reject) => {
21793
- timer = setTimeout(() => {
21794
- reject(new Error(`${label} timed out after ${timeoutMs}ms`));
21795
- }, timeoutMs);
21796
- });
21797
- return Promise.race([promise, timeout]).finally(() => {
21798
- if (timer) {
21799
- clearTimeout(timer);
21800
- }
21801
- });
21802
- }
21803
- function isLocalControlUrl(url) {
21804
- try {
21805
- const parsed = new URL(url);
21806
- return parsed.hostname === "127.0.0.1" || parsed.hostname === "localhost" || parsed.hostname === "::1";
21807
- } catch {
21808
- return false;
21809
- }
21810
- }
21811
- function isRetryableLocalWorkerRestart(status, body, url) {
21812
- return isLocalControlUrl(url) && (status === 503 && body.includes("Your worker restarted mid-request") || status === 500 && body.includes("Network connection lost"));
21813
- }
21814
- function isRetryableRecordObjectsError(error2) {
21815
- const message = error2 instanceof Error ? error2.message : String(error2);
21816
- 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(
21817
- message
21818
- );
21819
- }
21820
- function isRetryableEffectRegistrationError(error2) {
21821
- const message = error2 instanceof Error ? error2.message : String(error2);
21822
- 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(
21823
- message
21824
- );
21825
- }
21826
- function isRetryableSessionDataError(error2) {
21827
- const message = error2 instanceof Error ? error2.message : String(error2);
21828
- 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(
21829
- message
21830
- );
21831
- }
21832
21945
  function computeEffectKey2(effect) {
21833
21946
  const attachedClass = effect.className?.trim();
21834
21947
  if (!attachedClass) {
@@ -21883,115 +21996,6 @@ function buildEffectHostUrl(apiUrl, sandboxId, effectClientId, clientId, effectH
21883
21996
  url.searchParams.set("clientId", clientId);
21884
21997
  return url.toString();
21885
21998
  }
21886
- function createEmptyHeapSnapshot(now = Date.now()) {
21887
- return {
21888
- entriesByPath: {},
21889
- listsByName: {},
21890
- variablesByName: {},
21891
- updatedAt: now
21892
- };
21893
- }
21894
- function normalizeHeapSnapshot(raw) {
21895
- if (!raw || typeof raw !== "object") {
21896
- return createEmptyHeapSnapshot();
21897
- }
21898
- const heap = raw;
21899
- return {
21900
- entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
21901
- listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
21902
- variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
21903
- updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
21904
- };
21905
- }
21906
- function normalizeGraphPathSegment(value) {
21907
- return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, "_").replace(/^_+|_+$/g, "");
21908
- }
21909
- function extractRecordIdFromGraphPath(path7, className) {
21910
- const normalizedPrefix = `${normalizeGraphPathSegment(className)}_`;
21911
- if (path7.startsWith(normalizedPrefix)) {
21912
- return path7.slice(normalizedPrefix.length);
21913
- }
21914
- const legacyPrefix = `${className}_`;
21915
- if (path7.startsWith(legacyPrefix)) {
21916
- return path7.slice(legacyPrefix.length);
21917
- }
21918
- return path7;
21919
- }
21920
- function toRecordSearchResult(className, node) {
21921
- const path7 = typeof node.path === "string" ? node.path : "";
21922
- if (!path7) return null;
21923
- const fields = Array.isArray(node.submodels) ? node.submodels.flatMap(
21924
- (submodel) => {
21925
- const name = typeof submodel?.label === "string" && submodel.label.trim() ? submodel.label : typeof submodel?.path === "string" ? submodel.path.split(":").pop() || submodel.path : "";
21926
- if (!name) return [];
21927
- if (typeof submodel.string_value === "string") {
21928
- return [{ name, type: "string", value: submodel.string_value }];
21929
- }
21930
- if (typeof submodel.number_value === "number") {
21931
- return [{ name, type: "number", value: submodel.number_value }];
21932
- }
21933
- if (typeof submodel.boolean_value === "boolean") {
21934
- return [
21935
- {
21936
- name,
21937
- type: "boolean",
21938
- value: submodel.boolean_value
21939
- }
21940
- ];
21941
- }
21942
- return [];
21943
- }
21944
- ) : [];
21945
- return {
21946
- path: path7,
21947
- className,
21948
- id: extractRecordIdFromGraphPath(path7, className),
21949
- label: typeof node.label === "string" && node.label.trim() ? node.label : extractRecordIdFromGraphPath(path7, className),
21950
- description: typeof node.description === "string" && node.description.trim() ? node.description : null,
21951
- fields
21952
- };
21953
- }
21954
- function normalizeRecordSearchText(value) {
21955
- return value.trim().toLowerCase().replace(/[^a-z0-9]+/g, " ").replace(/\s+/g, " ").trim();
21956
- }
21957
- function rankRecordSearchResult(result, query, index) {
21958
- const normalizedQuery = normalizeRecordSearchText(query);
21959
- if (!normalizedQuery) {
21960
- return index;
21961
- }
21962
- const label = normalizeRecordSearchText(result.label || "");
21963
- const id = normalizeRecordSearchText(result.id || "");
21964
- const path7 = normalizeRecordSearchText(result.path || "");
21965
- const className = normalizeRecordSearchText(result.className || "");
21966
- const searchable = [label, id, path7, className].filter(Boolean);
21967
- if (label === normalizedQuery) return index;
21968
- if (id === normalizedQuery || path7 === normalizedQuery) return 100 + index;
21969
- if (label.startsWith(normalizedQuery)) return 200 + index;
21970
- if (searchable.some((value) => value.startsWith(normalizedQuery))) {
21971
- return 300 + index;
21972
- }
21973
- if (label.includes(normalizedQuery)) return 400 + index;
21974
- if (searchable.some((value) => value.includes(normalizedQuery))) {
21975
- return 500 + index;
21976
- }
21977
- return 900 + index;
21978
- }
21979
- function deriveRuntimeBaseUrl(apiEndpoint) {
21980
- try {
21981
- const endpoint = new URL(apiEndpoint);
21982
- const graphqlSuffix = "/orchestrator/graphql";
21983
- if (endpoint.pathname.endsWith(graphqlSuffix)) {
21984
- endpoint.pathname = endpoint.pathname.slice(0, -graphqlSuffix.length);
21985
- } else if (endpoint.pathname.endsWith("/graphql")) {
21986
- endpoint.pathname = endpoint.pathname.slice(0, -"/graphql".length);
21987
- }
21988
- endpoint.search = "";
21989
- endpoint.hash = "";
21990
- return endpoint.toString().replace(/\/$/, "");
21991
- } catch {
21992
- return apiEndpoint.replace(/\/orchestrator\/graphql$/, "").replace(/\/$/, "");
21993
- }
21994
- }
21995
21999
  function normalizeSubject(subject) {
21996
22000
  const granularId = subject.granularId || subject.subjectId;
21997
22001
  const userId = subject.userId || subject.identityId || granularId;