@granular-software/sdk 0.4.4 → 0.4.5

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
@@ -5067,7 +5067,7 @@ var JobImplementation = class {
5067
5067
 
5068
5068
  // src/endpoints.ts
5069
5069
  var LOCAL_API_URL = "ws://localhost:8787/granular";
5070
- var PRODUCTION_API_URL = "wss://api.granular.dev/v2/ws";
5070
+ var PRODUCTION_API_URL = "wss://cf-api-gateway.arthur6084.workers.dev/granular";
5071
5071
  function readEnv(name) {
5072
5072
  if (typeof process === "undefined" || !process.env) return void 0;
5073
5073
  return process.env[name];
@@ -5154,6 +5154,26 @@ function buildEffectHostUrl(apiUrl, sandboxId, effectClientId, clientId) {
5154
5154
  url.searchParams.set("clientId", clientId);
5155
5155
  return url.toString();
5156
5156
  }
5157
+ function createEmptyHeapSnapshot(now = Date.now()) {
5158
+ return {
5159
+ entriesByPath: {},
5160
+ listsByName: {},
5161
+ variablesByName: {},
5162
+ updatedAt: now
5163
+ };
5164
+ }
5165
+ function normalizeHeapSnapshot(raw) {
5166
+ if (!raw || typeof raw !== "object") {
5167
+ return createEmptyHeapSnapshot();
5168
+ }
5169
+ const heap = raw;
5170
+ return {
5171
+ entriesByPath: heap.entriesByPath && typeof heap.entriesByPath === "object" ? JSON.parse(JSON.stringify(heap.entriesByPath)) : {},
5172
+ listsByName: heap.listsByName && typeof heap.listsByName === "object" ? JSON.parse(JSON.stringify(heap.listsByName)) : {},
5173
+ variablesByName: heap.variablesByName && typeof heap.variablesByName === "object" ? JSON.parse(JSON.stringify(heap.variablesByName)) : {},
5174
+ updatedAt: typeof heap.updatedAt === "number" ? heap.updatedAt : Date.now()
5175
+ };
5176
+ }
5157
5177
  var Environment = class _Environment extends Session {
5158
5178
  envData;
5159
5179
  _apiKey;
@@ -5184,6 +5204,16 @@ var Environment = class _Environment extends Session {
5184
5204
  get apiEndpoint() {
5185
5205
  return this._apiEndpoint;
5186
5206
  }
5207
+ /**
5208
+ * Return a plain JS snapshot of the synced session heap.
5209
+ *
5210
+ * The heap lives in the Automerge document, so this method does not perform
5211
+ * any extra network roundtrip.
5212
+ */
5213
+ getHeap() {
5214
+ const doc = this.document;
5215
+ return normalizeHeapSnapshot(doc?.heap);
5216
+ }
5187
5217
  getRuntimeBaseUrl() {
5188
5218
  try {
5189
5219
  const endpoint = new URL(this._apiEndpoint);
@@ -6045,7 +6075,8 @@ var Granular = class {
6045
6075
  method: "POST",
6046
6076
  body: JSON.stringify({
6047
6077
  environmentId: envData.environmentId,
6048
- clientId
6078
+ clientId,
6079
+ initialHeap: options.initialHeap
6049
6080
  })
6050
6081
  });
6051
6082
  const client = new WSClient({