@seaverse/dataservice 1.8.0 → 1.8.2
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 +100 -24
- package/dist/index.mjs +97 -21
- package/package.json +1 -1
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
|
|
22
|
-
__export(
|
|
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(
|
|
29
|
+
module.exports = __toCommonJS(index_exports);
|
|
30
30
|
|
|
31
31
|
// src/types.ts
|
|
32
32
|
var DataServiceError = class extends Error {
|
|
@@ -56,16 +56,27 @@ function isInIframe() {
|
|
|
56
56
|
return false;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
+
function isInSeaVerseApp() {
|
|
60
|
+
try {
|
|
61
|
+
return typeof globalThis !== "undefined" && "window" in globalThis && typeof globalThis.window.ReactNativeWebView !== "undefined";
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
59
66
|
async function getTokenFromParent(timeout = 5e3) {
|
|
60
|
-
if (!isInIframe()) {
|
|
67
|
+
if (!isInIframe() && !isInSeaVerseApp()) {
|
|
61
68
|
return null;
|
|
62
69
|
}
|
|
63
70
|
return new Promise((resolve) => {
|
|
71
|
+
const callId = `token_${Date.now()}_${Math.random()}`;
|
|
64
72
|
const messageHandler = (event) => {
|
|
65
73
|
if (event.data && event.data.type === "seaverse:token") {
|
|
66
74
|
cleanup();
|
|
67
75
|
const token = event.data.payload?.accessToken;
|
|
68
76
|
resolve(token || null);
|
|
77
|
+
} else if (event.data && event.data.type === "seaverse:token_response" && event.data.callId === callId) {
|
|
78
|
+
cleanup();
|
|
79
|
+
resolve(event.data.token || null);
|
|
69
80
|
} else if (event.data && event.data.type === "seaverse:error") {
|
|
70
81
|
cleanup();
|
|
71
82
|
console.warn("[SeaVerse DataService SDK] Error getting token from parent:", event.data.error);
|
|
@@ -82,11 +93,16 @@ async function getTokenFromParent(timeout = 5e3) {
|
|
|
82
93
|
};
|
|
83
94
|
globalThis.window.addEventListener("message", messageHandler);
|
|
84
95
|
try {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
96
|
+
if (isInSeaVerseApp()) {
|
|
97
|
+
globalThis.window.ReactNativeWebView.postMessage(
|
|
98
|
+
JSON.stringify({ type: "seaverse:get_token", callId })
|
|
99
|
+
);
|
|
100
|
+
} else {
|
|
101
|
+
globalThis.window.parent.postMessage(
|
|
102
|
+
{ type: "seaverse:get_token" },
|
|
103
|
+
"*"
|
|
104
|
+
);
|
|
105
|
+
}
|
|
90
106
|
} catch (e) {
|
|
91
107
|
cleanup();
|
|
92
108
|
resolve(null);
|
|
@@ -94,15 +110,19 @@ async function getTokenFromParent(timeout = 5e3) {
|
|
|
94
110
|
});
|
|
95
111
|
}
|
|
96
112
|
async function getServiceHostFromParent(timeout = 500, serviceName = "dataservice") {
|
|
97
|
-
if (!isInIframe()) {
|
|
113
|
+
if (!isInIframe() && !isInSeaVerseApp()) {
|
|
98
114
|
return null;
|
|
99
115
|
}
|
|
100
116
|
return new Promise((resolve) => {
|
|
117
|
+
const callId = `host_${Date.now()}_${Math.random()}`;
|
|
101
118
|
const messageHandler = (event) => {
|
|
102
119
|
if (event.data && event.data.type === "seaverse:service_host") {
|
|
103
120
|
cleanup();
|
|
104
121
|
const serviceHost = event.data.payload?.serviceHost;
|
|
105
122
|
resolve(serviceHost || null);
|
|
123
|
+
} else if (event.data && event.data.type === "seaverse:service_host_response" && event.data.callId === callId) {
|
|
124
|
+
cleanup();
|
|
125
|
+
resolve(event.data.serviceHost || null);
|
|
106
126
|
} else if (event.data && event.data.type === "seaverse:error") {
|
|
107
127
|
cleanup();
|
|
108
128
|
console.warn("[SeaVerse DataService SDK] Error getting serviceHost from parent:", event.data.error);
|
|
@@ -119,11 +139,62 @@ async function getServiceHostFromParent(timeout = 500, serviceName = "dataservic
|
|
|
119
139
|
};
|
|
120
140
|
globalThis.window.addEventListener("message", messageHandler);
|
|
121
141
|
try {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
142
|
+
if (isInSeaVerseApp()) {
|
|
143
|
+
globalThis.window.ReactNativeWebView.postMessage(
|
|
144
|
+
JSON.stringify({ type: "seaverse:get_service_host", callId, serviceName })
|
|
145
|
+
);
|
|
146
|
+
} else {
|
|
147
|
+
globalThis.window.parent.postMessage(
|
|
148
|
+
{ type: "seaverse:get_service_host", payload: { serviceName } },
|
|
149
|
+
"*"
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
} catch (e) {
|
|
153
|
+
cleanup();
|
|
154
|
+
resolve(null);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
async function getAppIdFromParent(timeout = 500) {
|
|
159
|
+
if (!isInIframe() && !isInSeaVerseApp()) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return new Promise((resolve) => {
|
|
163
|
+
const callId = `appid_${Date.now()}_${Math.random()}`;
|
|
164
|
+
const messageHandler = (event) => {
|
|
165
|
+
if (event.data && event.data.type === "seaverse:appId") {
|
|
166
|
+
cleanup();
|
|
167
|
+
const appId = event.data.payload?.appId;
|
|
168
|
+
resolve(appId || null);
|
|
169
|
+
} else if (event.data && event.data.type === "seaverse:appId_response" && event.data.callId === callId) {
|
|
170
|
+
cleanup();
|
|
171
|
+
resolve(event.data.appId || null);
|
|
172
|
+
} else if (event.data && event.data.type === "seaverse:error") {
|
|
173
|
+
cleanup();
|
|
174
|
+
console.warn("[SeaVerse DataService SDK] Error getting appId from parent:", event.data.error);
|
|
175
|
+
resolve(null);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
178
|
+
const timeoutId = setTimeout(() => {
|
|
179
|
+
cleanup();
|
|
180
|
+
resolve(null);
|
|
181
|
+
}, timeout);
|
|
182
|
+
const cleanup = () => {
|
|
183
|
+
clearTimeout(timeoutId);
|
|
184
|
+
globalThis.window.removeEventListener("message", messageHandler);
|
|
185
|
+
};
|
|
186
|
+
globalThis.window.addEventListener("message", messageHandler);
|
|
187
|
+
try {
|
|
188
|
+
if (isInSeaVerseApp()) {
|
|
189
|
+
globalThis.window.ReactNativeWebView.postMessage(
|
|
190
|
+
JSON.stringify({ type: "seaverse:get_appId", callId })
|
|
191
|
+
);
|
|
192
|
+
} else {
|
|
193
|
+
globalThis.window.parent.postMessage(
|
|
194
|
+
{ type: "seaverse:get_appId" },
|
|
195
|
+
"*"
|
|
196
|
+
);
|
|
197
|
+
}
|
|
127
198
|
} catch (e) {
|
|
128
199
|
cleanup();
|
|
129
200
|
resolve(null);
|
|
@@ -288,8 +359,7 @@ var QueryBuilderImpl = class {
|
|
|
288
359
|
}
|
|
289
360
|
order(field, options = {}) {
|
|
290
361
|
let orderStr = field;
|
|
291
|
-
if (options.descending)
|
|
292
|
-
orderStr += ".desc";
|
|
362
|
+
if (options.descending) orderStr += ".desc";
|
|
293
363
|
if (options.nullsFirst !== void 0) {
|
|
294
364
|
orderStr += options.nullsFirst ? ".nullsfirst" : ".nullslast";
|
|
295
365
|
}
|
|
@@ -310,12 +380,9 @@ var QueryBuilderImpl = class {
|
|
|
310
380
|
collection_name: `eq.${this.collectionName}`,
|
|
311
381
|
...Object.fromEntries(this.filters.map((f, i) => [`filter${i}`, f]))
|
|
312
382
|
};
|
|
313
|
-
if (this.ordering)
|
|
314
|
-
|
|
315
|
-
if (this.
|
|
316
|
-
params.limit = String(this.limitValue);
|
|
317
|
-
if (this.offsetValue !== null)
|
|
318
|
-
params.offset = String(this.offsetValue);
|
|
383
|
+
if (this.ordering) params.order = this.ordering;
|
|
384
|
+
if (this.limitValue !== null) params.limit = String(this.limitValue);
|
|
385
|
+
if (this.offsetValue !== null) params.offset = String(this.offsetValue);
|
|
319
386
|
return this.client.get(this.tablePath, params);
|
|
320
387
|
}
|
|
321
388
|
async count() {
|
|
@@ -470,7 +537,16 @@ async function createClient(config = {}) {
|
|
|
470
537
|
serviceHost = null;
|
|
471
538
|
}
|
|
472
539
|
const httpClient = new HTTPClient(config, token || void 0, serviceHost || void 0);
|
|
473
|
-
|
|
540
|
+
let parentAppId = null;
|
|
541
|
+
if (!manualAppId) {
|
|
542
|
+
try {
|
|
543
|
+
parentAppId = await getAppIdFromParent(500);
|
|
544
|
+
} catch (error) {
|
|
545
|
+
console.warn("[SeaVerse DataService SDK] Failed to fetch appId:", error);
|
|
546
|
+
parentAppId = null;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const appId = manualAppId || parentAppId || extractAppId();
|
|
474
550
|
return new DataServiceClientImpl(httpClient, appId);
|
|
475
551
|
}
|
|
476
552
|
|
package/dist/index.mjs
CHANGED
|
@@ -26,16 +26,27 @@ function isInIframe() {
|
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
function isInSeaVerseApp() {
|
|
30
|
+
try {
|
|
31
|
+
return typeof globalThis !== "undefined" && "window" in globalThis && typeof globalThis.window.ReactNativeWebView !== "undefined";
|
|
32
|
+
} catch {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
29
36
|
async function getTokenFromParent(timeout = 5e3) {
|
|
30
|
-
if (!isInIframe()) {
|
|
37
|
+
if (!isInIframe() && !isInSeaVerseApp()) {
|
|
31
38
|
return null;
|
|
32
39
|
}
|
|
33
40
|
return new Promise((resolve) => {
|
|
41
|
+
const callId = `token_${Date.now()}_${Math.random()}`;
|
|
34
42
|
const messageHandler = (event) => {
|
|
35
43
|
if (event.data && event.data.type === "seaverse:token") {
|
|
36
44
|
cleanup();
|
|
37
45
|
const token = event.data.payload?.accessToken;
|
|
38
46
|
resolve(token || null);
|
|
47
|
+
} else if (event.data && event.data.type === "seaverse:token_response" && event.data.callId === callId) {
|
|
48
|
+
cleanup();
|
|
49
|
+
resolve(event.data.token || null);
|
|
39
50
|
} else if (event.data && event.data.type === "seaverse:error") {
|
|
40
51
|
cleanup();
|
|
41
52
|
console.warn("[SeaVerse DataService SDK] Error getting token from parent:", event.data.error);
|
|
@@ -52,11 +63,16 @@ async function getTokenFromParent(timeout = 5e3) {
|
|
|
52
63
|
};
|
|
53
64
|
globalThis.window.addEventListener("message", messageHandler);
|
|
54
65
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
66
|
+
if (isInSeaVerseApp()) {
|
|
67
|
+
globalThis.window.ReactNativeWebView.postMessage(
|
|
68
|
+
JSON.stringify({ type: "seaverse:get_token", callId })
|
|
69
|
+
);
|
|
70
|
+
} else {
|
|
71
|
+
globalThis.window.parent.postMessage(
|
|
72
|
+
{ type: "seaverse:get_token" },
|
|
73
|
+
"*"
|
|
74
|
+
);
|
|
75
|
+
}
|
|
60
76
|
} catch (e) {
|
|
61
77
|
cleanup();
|
|
62
78
|
resolve(null);
|
|
@@ -64,15 +80,19 @@ async function getTokenFromParent(timeout = 5e3) {
|
|
|
64
80
|
});
|
|
65
81
|
}
|
|
66
82
|
async function getServiceHostFromParent(timeout = 500, serviceName = "dataservice") {
|
|
67
|
-
if (!isInIframe()) {
|
|
83
|
+
if (!isInIframe() && !isInSeaVerseApp()) {
|
|
68
84
|
return null;
|
|
69
85
|
}
|
|
70
86
|
return new Promise((resolve) => {
|
|
87
|
+
const callId = `host_${Date.now()}_${Math.random()}`;
|
|
71
88
|
const messageHandler = (event) => {
|
|
72
89
|
if (event.data && event.data.type === "seaverse:service_host") {
|
|
73
90
|
cleanup();
|
|
74
91
|
const serviceHost = event.data.payload?.serviceHost;
|
|
75
92
|
resolve(serviceHost || null);
|
|
93
|
+
} else if (event.data && event.data.type === "seaverse:service_host_response" && event.data.callId === callId) {
|
|
94
|
+
cleanup();
|
|
95
|
+
resolve(event.data.serviceHost || null);
|
|
76
96
|
} else if (event.data && event.data.type === "seaverse:error") {
|
|
77
97
|
cleanup();
|
|
78
98
|
console.warn("[SeaVerse DataService SDK] Error getting serviceHost from parent:", event.data.error);
|
|
@@ -89,11 +109,62 @@ async function getServiceHostFromParent(timeout = 500, serviceName = "dataservic
|
|
|
89
109
|
};
|
|
90
110
|
globalThis.window.addEventListener("message", messageHandler);
|
|
91
111
|
try {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
112
|
+
if (isInSeaVerseApp()) {
|
|
113
|
+
globalThis.window.ReactNativeWebView.postMessage(
|
|
114
|
+
JSON.stringify({ type: "seaverse:get_service_host", callId, serviceName })
|
|
115
|
+
);
|
|
116
|
+
} else {
|
|
117
|
+
globalThis.window.parent.postMessage(
|
|
118
|
+
{ type: "seaverse:get_service_host", payload: { serviceName } },
|
|
119
|
+
"*"
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
} catch (e) {
|
|
123
|
+
cleanup();
|
|
124
|
+
resolve(null);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
async function getAppIdFromParent(timeout = 500) {
|
|
129
|
+
if (!isInIframe() && !isInSeaVerseApp()) {
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
return new Promise((resolve) => {
|
|
133
|
+
const callId = `appid_${Date.now()}_${Math.random()}`;
|
|
134
|
+
const messageHandler = (event) => {
|
|
135
|
+
if (event.data && event.data.type === "seaverse:appId") {
|
|
136
|
+
cleanup();
|
|
137
|
+
const appId = event.data.payload?.appId;
|
|
138
|
+
resolve(appId || null);
|
|
139
|
+
} else if (event.data && event.data.type === "seaverse:appId_response" && event.data.callId === callId) {
|
|
140
|
+
cleanup();
|
|
141
|
+
resolve(event.data.appId || null);
|
|
142
|
+
} else if (event.data && event.data.type === "seaverse:error") {
|
|
143
|
+
cleanup();
|
|
144
|
+
console.warn("[SeaVerse DataService SDK] Error getting appId from parent:", event.data.error);
|
|
145
|
+
resolve(null);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
const timeoutId = setTimeout(() => {
|
|
149
|
+
cleanup();
|
|
150
|
+
resolve(null);
|
|
151
|
+
}, timeout);
|
|
152
|
+
const cleanup = () => {
|
|
153
|
+
clearTimeout(timeoutId);
|
|
154
|
+
globalThis.window.removeEventListener("message", messageHandler);
|
|
155
|
+
};
|
|
156
|
+
globalThis.window.addEventListener("message", messageHandler);
|
|
157
|
+
try {
|
|
158
|
+
if (isInSeaVerseApp()) {
|
|
159
|
+
globalThis.window.ReactNativeWebView.postMessage(
|
|
160
|
+
JSON.stringify({ type: "seaverse:get_appId", callId })
|
|
161
|
+
);
|
|
162
|
+
} else {
|
|
163
|
+
globalThis.window.parent.postMessage(
|
|
164
|
+
{ type: "seaverse:get_appId" },
|
|
165
|
+
"*"
|
|
166
|
+
);
|
|
167
|
+
}
|
|
97
168
|
} catch (e) {
|
|
98
169
|
cleanup();
|
|
99
170
|
resolve(null);
|
|
@@ -258,8 +329,7 @@ var QueryBuilderImpl = class {
|
|
|
258
329
|
}
|
|
259
330
|
order(field, options = {}) {
|
|
260
331
|
let orderStr = field;
|
|
261
|
-
if (options.descending)
|
|
262
|
-
orderStr += ".desc";
|
|
332
|
+
if (options.descending) orderStr += ".desc";
|
|
263
333
|
if (options.nullsFirst !== void 0) {
|
|
264
334
|
orderStr += options.nullsFirst ? ".nullsfirst" : ".nullslast";
|
|
265
335
|
}
|
|
@@ -280,12 +350,9 @@ var QueryBuilderImpl = class {
|
|
|
280
350
|
collection_name: `eq.${this.collectionName}`,
|
|
281
351
|
...Object.fromEntries(this.filters.map((f, i) => [`filter${i}`, f]))
|
|
282
352
|
};
|
|
283
|
-
if (this.ordering)
|
|
284
|
-
|
|
285
|
-
if (this.
|
|
286
|
-
params.limit = String(this.limitValue);
|
|
287
|
-
if (this.offsetValue !== null)
|
|
288
|
-
params.offset = String(this.offsetValue);
|
|
353
|
+
if (this.ordering) params.order = this.ordering;
|
|
354
|
+
if (this.limitValue !== null) params.limit = String(this.limitValue);
|
|
355
|
+
if (this.offsetValue !== null) params.offset = String(this.offsetValue);
|
|
289
356
|
return this.client.get(this.tablePath, params);
|
|
290
357
|
}
|
|
291
358
|
async count() {
|
|
@@ -440,7 +507,16 @@ async function createClient(config = {}) {
|
|
|
440
507
|
serviceHost = null;
|
|
441
508
|
}
|
|
442
509
|
const httpClient = new HTTPClient(config, token || void 0, serviceHost || void 0);
|
|
443
|
-
|
|
510
|
+
let parentAppId = null;
|
|
511
|
+
if (!manualAppId) {
|
|
512
|
+
try {
|
|
513
|
+
parentAppId = await getAppIdFromParent(500);
|
|
514
|
+
} catch (error) {
|
|
515
|
+
console.warn("[SeaVerse DataService SDK] Failed to fetch appId:", error);
|
|
516
|
+
parentAppId = null;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
const appId = manualAppId || parentAppId || extractAppId();
|
|
444
520
|
return new DataServiceClientImpl(httpClient, appId);
|
|
445
521
|
}
|
|
446
522
|
|