@seaverse/dataservice 1.8.0 → 1.8.1

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.js CHANGED
@@ -18,15 +18,15 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  DataServiceError: () => DataServiceError,
24
24
  VERSION: () => VERSION,
25
25
  createClient: () => createClient,
26
26
  debugSetToken: () => debugSetToken,
27
27
  setAppId: () => setAppId
28
28
  });
29
- module.exports = __toCommonJS(src_exports);
29
+ module.exports = __toCommonJS(index_exports);
30
30
 
31
31
  // src/types.ts
32
32
  var DataServiceError = class extends Error {
@@ -130,6 +130,42 @@ async function getServiceHostFromParent(timeout = 500, serviceName = "dataservic
130
130
  }
131
131
  });
132
132
  }
133
+ async function getAppIdFromParent(timeout = 500) {
134
+ if (!isInIframe()) {
135
+ return null;
136
+ }
137
+ return new Promise((resolve) => {
138
+ const messageHandler = (event) => {
139
+ if (event.data && event.data.type === "seaverse:appId") {
140
+ cleanup();
141
+ const appId = event.data.payload?.appId;
142
+ resolve(appId || null);
143
+ } else if (event.data && event.data.type === "seaverse:error") {
144
+ cleanup();
145
+ console.warn("[SeaVerse DataService SDK] Error getting appId from parent:", event.data.error);
146
+ resolve(null);
147
+ }
148
+ };
149
+ const timeoutId = setTimeout(() => {
150
+ cleanup();
151
+ resolve(null);
152
+ }, timeout);
153
+ const cleanup = () => {
154
+ clearTimeout(timeoutId);
155
+ globalThis.window.removeEventListener("message", messageHandler);
156
+ };
157
+ globalThis.window.addEventListener("message", messageHandler);
158
+ try {
159
+ globalThis.window.parent.postMessage(
160
+ { type: "seaverse:get_appId" },
161
+ "*"
162
+ );
163
+ } catch (e) {
164
+ cleanup();
165
+ resolve(null);
166
+ }
167
+ });
168
+ }
133
169
  function extractAppId() {
134
170
  if (typeof globalThis !== "undefined" && "location" in globalThis) {
135
171
  const location = globalThis.location;
@@ -288,8 +324,7 @@ var QueryBuilderImpl = class {
288
324
  }
289
325
  order(field, options = {}) {
290
326
  let orderStr = field;
291
- if (options.descending)
292
- orderStr += ".desc";
327
+ if (options.descending) orderStr += ".desc";
293
328
  if (options.nullsFirst !== void 0) {
294
329
  orderStr += options.nullsFirst ? ".nullsfirst" : ".nullslast";
295
330
  }
@@ -310,12 +345,9 @@ var QueryBuilderImpl = class {
310
345
  collection_name: `eq.${this.collectionName}`,
311
346
  ...Object.fromEntries(this.filters.map((f, i) => [`filter${i}`, f]))
312
347
  };
313
- if (this.ordering)
314
- params.order = this.ordering;
315
- if (this.limitValue !== null)
316
- params.limit = String(this.limitValue);
317
- if (this.offsetValue !== null)
318
- params.offset = String(this.offsetValue);
348
+ if (this.ordering) params.order = this.ordering;
349
+ if (this.limitValue !== null) params.limit = String(this.limitValue);
350
+ if (this.offsetValue !== null) params.offset = String(this.offsetValue);
319
351
  return this.client.get(this.tablePath, params);
320
352
  }
321
353
  async count() {
@@ -470,7 +502,16 @@ async function createClient(config = {}) {
470
502
  serviceHost = null;
471
503
  }
472
504
  const httpClient = new HTTPClient(config, token || void 0, serviceHost || void 0);
473
- const appId = manualAppId || extractAppId();
505
+ let parentAppId = null;
506
+ if (!manualAppId) {
507
+ try {
508
+ parentAppId = await getAppIdFromParent(500);
509
+ } catch (error) {
510
+ console.warn("[SeaVerse DataService SDK] Failed to fetch appId:", error);
511
+ parentAppId = null;
512
+ }
513
+ }
514
+ const appId = manualAppId || parentAppId || extractAppId();
474
515
  return new DataServiceClientImpl(httpClient, appId);
475
516
  }
476
517
 
package/dist/index.mjs CHANGED
@@ -100,6 +100,42 @@ async function getServiceHostFromParent(timeout = 500, serviceName = "dataservic
100
100
  }
101
101
  });
102
102
  }
103
+ async function getAppIdFromParent(timeout = 500) {
104
+ if (!isInIframe()) {
105
+ return null;
106
+ }
107
+ return new Promise((resolve) => {
108
+ const messageHandler = (event) => {
109
+ if (event.data && event.data.type === "seaverse:appId") {
110
+ cleanup();
111
+ const appId = event.data.payload?.appId;
112
+ resolve(appId || null);
113
+ } else if (event.data && event.data.type === "seaverse:error") {
114
+ cleanup();
115
+ console.warn("[SeaVerse DataService SDK] Error getting appId from parent:", event.data.error);
116
+ resolve(null);
117
+ }
118
+ };
119
+ const timeoutId = setTimeout(() => {
120
+ cleanup();
121
+ resolve(null);
122
+ }, timeout);
123
+ const cleanup = () => {
124
+ clearTimeout(timeoutId);
125
+ globalThis.window.removeEventListener("message", messageHandler);
126
+ };
127
+ globalThis.window.addEventListener("message", messageHandler);
128
+ try {
129
+ globalThis.window.parent.postMessage(
130
+ { type: "seaverse:get_appId" },
131
+ "*"
132
+ );
133
+ } catch (e) {
134
+ cleanup();
135
+ resolve(null);
136
+ }
137
+ });
138
+ }
103
139
  function extractAppId() {
104
140
  if (typeof globalThis !== "undefined" && "location" in globalThis) {
105
141
  const location = globalThis.location;
@@ -258,8 +294,7 @@ var QueryBuilderImpl = class {
258
294
  }
259
295
  order(field, options = {}) {
260
296
  let orderStr = field;
261
- if (options.descending)
262
- orderStr += ".desc";
297
+ if (options.descending) orderStr += ".desc";
263
298
  if (options.nullsFirst !== void 0) {
264
299
  orderStr += options.nullsFirst ? ".nullsfirst" : ".nullslast";
265
300
  }
@@ -280,12 +315,9 @@ var QueryBuilderImpl = class {
280
315
  collection_name: `eq.${this.collectionName}`,
281
316
  ...Object.fromEntries(this.filters.map((f, i) => [`filter${i}`, f]))
282
317
  };
283
- if (this.ordering)
284
- params.order = this.ordering;
285
- if (this.limitValue !== null)
286
- params.limit = String(this.limitValue);
287
- if (this.offsetValue !== null)
288
- params.offset = String(this.offsetValue);
318
+ if (this.ordering) params.order = this.ordering;
319
+ if (this.limitValue !== null) params.limit = String(this.limitValue);
320
+ if (this.offsetValue !== null) params.offset = String(this.offsetValue);
289
321
  return this.client.get(this.tablePath, params);
290
322
  }
291
323
  async count() {
@@ -440,7 +472,16 @@ async function createClient(config = {}) {
440
472
  serviceHost = null;
441
473
  }
442
474
  const httpClient = new HTTPClient(config, token || void 0, serviceHost || void 0);
443
- const appId = manualAppId || extractAppId();
475
+ let parentAppId = null;
476
+ if (!manualAppId) {
477
+ try {
478
+ parentAppId = await getAppIdFromParent(500);
479
+ } catch (error) {
480
+ console.warn("[SeaVerse DataService SDK] Failed to fetch appId:", error);
481
+ parentAppId = null;
482
+ }
483
+ }
484
+ const appId = manualAppId || parentAppId || extractAppId();
444
485
  return new DataServiceClientImpl(httpClient, appId);
445
486
  }
446
487
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seaverse/dataservice",
3
- "version": "1.8.0",
3
+ "version": "1.8.1",
4
4
  "description": "AI-Friendly Universal Data Storage SDK for TypeScript/JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",