@seaverse/dataservice 1.7.0 → 1.8.0

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/README.md CHANGED
@@ -24,6 +24,7 @@ This package uses a **factory pattern** for client creation. Here's what it expo
24
24
  **Functions:**
25
25
  - `createClient(config)` - Factory function to create a client instance (async)
26
26
  - `debugSetToken(token)` - Set debug token for testing (call before createClient)
27
+ - `setAppId(appId)` - **[Deprecated]** Set application ID manually (not recommended)
27
28
 
28
29
  **Types (TypeScript):**
29
30
  - `DataServiceClient` - Type of the client instance (**not a constructor**)
@@ -137,6 +138,27 @@ Access the extracted ID:
137
138
  console.log(client.appId); // "app_8e5e867e-user_f4ed2364"
138
139
  ```
139
140
 
141
+ **Manual Override (Not Recommended):**
142
+
143
+ For special cases where auto-extraction doesn't work, you can manually set the appId using `setAppId()`:
144
+
145
+ ```typescript
146
+ import { setAppId, createClient } from '@seaverse/dataservice';
147
+
148
+ // Set manual appId before creating client (highest priority)
149
+ setAppId('my-custom-app-id');
150
+
151
+ // Client will use manual appId instead of auto-extraction
152
+ const client = await createClient({});
153
+ console.log(client.appId); // "my-custom-app-id"
154
+ ```
155
+
156
+ ⚠️ **Note:** `setAppId()` is deprecated and not recommended for normal use. The SDK automatically extracts appId from the URL, which is the recommended approach. Only use this for special cases where auto-extraction doesn't work.
157
+
158
+ **AppId Priority (from highest to lowest):**
159
+ 1. `setAppId()` - Manual override (not recommended)
160
+ 2. URL extraction (browser) / Environment variable (Node.js) - Automatic and recommended
161
+
140
162
  ### Data Tables
141
163
 
142
164
  The SDK provides access to different data tables with different permission scopes:
@@ -335,6 +357,13 @@ The SDK uses the following priority order for obtaining authentication tokens:
335
357
  2. **Parent Page Token** - Auto-fetched via PostMessage when in iframe
336
358
  3. **No Token** - Client created without authentication (API calls will fail with 401)
337
359
 
360
+ **AppId Configuration Priority:**
361
+
362
+ The SDK uses the following priority order for determining the application ID:
363
+
364
+ 1. **Manual AppId (Highest Priority)** - Set via `setAppId()` (not recommended, deprecated)
365
+ 2. **Auto-extraction** - Extracted from URL (browser) or environment variable (Node.js)
366
+
338
367
  **Production Usage (Auto-fetch from parent):**
339
368
 
340
369
  The SDK automatically fetches the authentication token and service host from the parent page via PostMessage when running in an iframe:
@@ -369,6 +398,34 @@ debugSetToken('your-test-token');
369
398
  const client = await createClient({});
370
399
  ```
371
400
 
401
+ **Manual AppId Override (Not Recommended):**
402
+
403
+ For special cases, you can force a specific appId using `setAppId()`, which will override auto-extraction:
404
+
405
+ ```typescript
406
+ import { setAppId, createClient } from '@seaverse/dataservice';
407
+
408
+ // Current URL: https://app_auto_extracted.app.seaverse.ai
409
+ // Without setAppId, client.appId would be "app_auto_extracted"
410
+
411
+ // Force specific appId (overrides auto-extraction)
412
+ setAppId('my-custom-app-id');
413
+
414
+ const client = await createClient({});
415
+ console.log(client.appId); // "my-custom-app-id" (not "app_auto_extracted")
416
+
417
+ // All operations will use the manual appId
418
+ await client.userData.collection('test').insert({ foo: 'bar' });
419
+ // ↑ This record will be stored with app_id = "my-custom-app-id"
420
+ ```
421
+
422
+ ⚠️ **Warning:** `setAppId()` is deprecated. Only use it when:
423
+ - Testing in environments where URL-based extraction doesn't work
424
+ - Debugging issues with specific appIds
425
+ - Working around temporary limitations
426
+
427
+ In production, always rely on automatic appId extraction from the URL.
428
+
372
429
  **Graceful Degradation:**
373
430
 
374
431
  If token or serviceHost fetching fails, the SDK gracefully handles the failure:
package/dist/index.d.mts CHANGED
@@ -278,6 +278,30 @@ interface DataServiceClient {
278
278
  * ```
279
279
  */
280
280
  declare function debugSetToken(token: string): void;
281
+ /**
282
+ * Set application ID manually (not recommended)
283
+ *
284
+ * @deprecated This function is not recommended for normal use.
285
+ * The SDK automatically extracts appId from the URL, which is the recommended approach.
286
+ * Only use this for special cases where auto-extraction doesn't work.
287
+ *
288
+ * When set, this appId will take highest priority over auto-extracted appId.
289
+ *
290
+ * @param appId The application ID to use
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * import { setAppId, createClient } from '@seaverse/dataservice';
295
+ *
296
+ * // Set manual appId before creating client (highest priority)
297
+ * setAppId('my-custom-app-id');
298
+ *
299
+ * // Client will use manual appId instead of auto-extraction
300
+ * const client = await createClient({});
301
+ * console.log(client.appId); // "my-custom-app-id"
302
+ * ```
303
+ */
304
+ declare function setAppId(appId: string): void;
281
305
  /**
282
306
  * Create a new Data Service client
283
307
  *
@@ -353,6 +377,6 @@ declare function createClient(config?: ClientConfig): Promise<DataServiceClient>
353
377
  * ```
354
378
  */
355
379
 
356
- declare const VERSION = "1.6.2";
380
+ declare const VERSION = "1.8.0";
357
381
 
358
- export { type APIError, type ClientConfig, type Collection, type DataRecord, type DataServiceClient, DataServiceError, type DataTable, type OrderOptions, type QueryBuilder, type QueryFilter, type UserDataStats, VERSION, createClient, debugSetToken };
382
+ export { type APIError, type ClientConfig, type Collection, type DataRecord, type DataServiceClient, DataServiceError, type DataTable, type OrderOptions, type QueryBuilder, type QueryFilter, type UserDataStats, VERSION, createClient, debugSetToken, setAppId };
package/dist/index.d.ts CHANGED
@@ -278,6 +278,30 @@ interface DataServiceClient {
278
278
  * ```
279
279
  */
280
280
  declare function debugSetToken(token: string): void;
281
+ /**
282
+ * Set application ID manually (not recommended)
283
+ *
284
+ * @deprecated This function is not recommended for normal use.
285
+ * The SDK automatically extracts appId from the URL, which is the recommended approach.
286
+ * Only use this for special cases where auto-extraction doesn't work.
287
+ *
288
+ * When set, this appId will take highest priority over auto-extracted appId.
289
+ *
290
+ * @param appId The application ID to use
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * import { setAppId, createClient } from '@seaverse/dataservice';
295
+ *
296
+ * // Set manual appId before creating client (highest priority)
297
+ * setAppId('my-custom-app-id');
298
+ *
299
+ * // Client will use manual appId instead of auto-extraction
300
+ * const client = await createClient({});
301
+ * console.log(client.appId); // "my-custom-app-id"
302
+ * ```
303
+ */
304
+ declare function setAppId(appId: string): void;
281
305
  /**
282
306
  * Create a new Data Service client
283
307
  *
@@ -353,6 +377,6 @@ declare function createClient(config?: ClientConfig): Promise<DataServiceClient>
353
377
  * ```
354
378
  */
355
379
 
356
- declare const VERSION = "1.6.2";
380
+ declare const VERSION = "1.8.0";
357
381
 
358
- export { type APIError, type ClientConfig, type Collection, type DataRecord, type DataServiceClient, DataServiceError, type DataTable, type OrderOptions, type QueryBuilder, type QueryFilter, type UserDataStats, VERSION, createClient, debugSetToken };
382
+ export { type APIError, type ClientConfig, type Collection, type DataRecord, type DataServiceClient, DataServiceError, type DataTable, type OrderOptions, type QueryBuilder, type QueryFilter, type UserDataStats, VERSION, createClient, debugSetToken, setAppId };
package/dist/index.js CHANGED
@@ -23,7 +23,8 @@ __export(src_exports, {
23
23
  DataServiceError: () => DataServiceError,
24
24
  VERSION: () => VERSION,
25
25
  createClient: () => createClient,
26
- debugSetToken: () => debugSetToken
26
+ debugSetToken: () => debugSetToken,
27
+ setAppId: () => setAppId
27
28
  });
28
29
  module.exports = __toCommonJS(src_exports);
29
30
 
@@ -41,9 +42,13 @@ var DataServiceError = class extends Error {
41
42
 
42
43
  // src/client.ts
43
44
  var debugToken = null;
45
+ var manualAppId = null;
44
46
  function debugSetToken(token) {
45
47
  debugToken = token;
46
48
  }
49
+ function setAppId(appId) {
50
+ manualAppId = appId;
51
+ }
47
52
  function isInIframe() {
48
53
  try {
49
54
  return typeof globalThis !== "undefined" && "window" in globalThis && globalThis.window.self !== globalThis.window.top;
@@ -465,16 +470,17 @@ async function createClient(config = {}) {
465
470
  serviceHost = null;
466
471
  }
467
472
  const httpClient = new HTTPClient(config, token || void 0, serviceHost || void 0);
468
- const appId = extractAppId();
473
+ const appId = manualAppId || extractAppId();
469
474
  return new DataServiceClientImpl(httpClient, appId);
470
475
  }
471
476
 
472
477
  // src/index.ts
473
- var VERSION = "1.6.2";
478
+ var VERSION = "1.8.0";
474
479
  // Annotate the CommonJS export names for ESM import in node:
475
480
  0 && (module.exports = {
476
481
  DataServiceError,
477
482
  VERSION,
478
483
  createClient,
479
- debugSetToken
484
+ debugSetToken,
485
+ setAppId
480
486
  });
package/dist/index.mjs CHANGED
@@ -12,9 +12,13 @@ var DataServiceError = class extends Error {
12
12
 
13
13
  // src/client.ts
14
14
  var debugToken = null;
15
+ var manualAppId = null;
15
16
  function debugSetToken(token) {
16
17
  debugToken = token;
17
18
  }
19
+ function setAppId(appId) {
20
+ manualAppId = appId;
21
+ }
18
22
  function isInIframe() {
19
23
  try {
20
24
  return typeof globalThis !== "undefined" && "window" in globalThis && globalThis.window.self !== globalThis.window.top;
@@ -436,15 +440,16 @@ async function createClient(config = {}) {
436
440
  serviceHost = null;
437
441
  }
438
442
  const httpClient = new HTTPClient(config, token || void 0, serviceHost || void 0);
439
- const appId = extractAppId();
443
+ const appId = manualAppId || extractAppId();
440
444
  return new DataServiceClientImpl(httpClient, appId);
441
445
  }
442
446
 
443
447
  // src/index.ts
444
- var VERSION = "1.6.2";
448
+ var VERSION = "1.8.0";
445
449
  export {
446
450
  DataServiceError,
447
451
  VERSION,
448
452
  createClient,
449
- debugSetToken
453
+ debugSetToken,
454
+ setAppId
450
455
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seaverse/dataservice",
3
- "version": "1.7.0",
3
+ "version": "1.8.0",
4
4
  "description": "AI-Friendly Universal Data Storage SDK for TypeScript/JavaScript",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",