@tinycloud/node-sdk 2.1.0-beta.3 → 2.1.0-beta.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/core.cjs CHANGED
@@ -414,14 +414,17 @@ var NodeUserAuthorization = class {
414
414
  * - resources are appended to the default resources
415
415
  * - uri triggers a warning (overwriting delegation target)
416
416
  * - all other fields override directly
417
+ * - per-call nonce overrides siweConfig.nonce when provided
417
418
  */
418
- buildSiweOverrides() {
419
+ buildSiweOverrides(options) {
419
420
  const base = { uri: this.uri };
420
421
  if (this.nonce !== void 0) {
421
422
  base.nonce = this.nonce;
422
423
  }
423
- if (!this.siweConfig) return base;
424
- const { statement, resources, uri, ...rest } = this.siweConfig;
424
+ if (!this.siweConfig && !options?.nonce) {
425
+ return base;
426
+ }
427
+ const { statement, resources, uri, ...rest } = this.siweConfig ?? {};
425
428
  const overrides = { ...base, ...rest };
426
429
  if (statement) {
427
430
  overrides.statement = this.statement ? `${statement} ${this.statement}` : statement;
@@ -435,6 +438,9 @@ var NodeUserAuthorization = class {
435
438
  );
436
439
  overrides.uri = uri;
437
440
  }
441
+ if (options?.nonce) {
442
+ overrides.nonce = options.nonce;
443
+ }
438
444
  return overrides;
439
445
  }
440
446
  /**
@@ -593,8 +599,10 @@ var NodeUserAuthorization = class {
593
599
  * 2. Call prepareSession() which generates the SIWE with ReCap capabilities
594
600
  * 3. Sign the SIWE string from prepareSession
595
601
  * 4. Call completeSessionSetup() with the prepared session + signature
602
+ *
603
+ * @param options - Optional per-call SIWE overrides for this sign-in only
596
604
  */
597
- async signIn() {
605
+ async signIn(options) {
598
606
  this._address = await this.signer.getAddress();
599
607
  this._chainId = await this.signer.getChainId();
600
608
  const address = this.wasm.ensureEip55(this._address);
@@ -618,7 +626,7 @@ var NodeUserAuthorization = class {
618
626
  expirationTime: expirationTime.toISOString(),
619
627
  spaceId,
620
628
  jwk,
621
- ...this.buildSiweOverrides()
629
+ ...this.buildSiweOverrides(options)
622
630
  });
623
631
  const signature = await this.requestSignature({
624
632
  address,
@@ -1345,8 +1353,10 @@ var _TinyCloudNode = class _TinyCloudNode {
1345
1353
  * Sign in and create a new session.
1346
1354
  * This creates the user's space if it doesn't exist.
1347
1355
  * Requires wallet mode (privateKey in config).
1356
+ *
1357
+ * @param options - Optional per-call SIWE overrides for this sign-in only
1348
1358
  */
1349
- async signIn() {
1359
+ async signIn(options) {
1350
1360
  if (!this.signer || !this.tc) {
1351
1361
  throw new Error(
1352
1362
  "Cannot signIn() in session-only mode. Provide a privateKey in config to create your own space."
@@ -1360,7 +1370,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1360
1370
  this._duckdb = void 0;
1361
1371
  this._hooks = void 0;
1362
1372
  this._serviceContext = void 0;
1363
- await this.tc.signIn();
1373
+ await this.tc.signIn(options);
1364
1374
  this.initializeServices();
1365
1375
  this.notificationHandler.success("Successfully signed in");
1366
1376
  }
@@ -2476,9 +2486,19 @@ var _TinyCloudNode = class _TinyCloudNode {
2476
2486
  expirationSecs
2477
2487
  });
2478
2488
  const primary = result.resources[0];
2489
+ const delegationHeader = { Authorization: `Bearer ${result.delegation}` };
2490
+ const activateResult = await (0, import_sdk_core5.activateSessionWithHost)(
2491
+ this.config.host,
2492
+ delegationHeader
2493
+ );
2494
+ if (!activateResult.success) {
2495
+ throw new Error(
2496
+ `Failed to activate delegation with host: ${activateResult.error}`
2497
+ );
2498
+ }
2479
2499
  return {
2480
2500
  cid: result.cid,
2481
- delegationHeader: { Authorization: `Bearer ${result.delegation}` },
2501
+ delegationHeader,
2482
2502
  spaceId,
2483
2503
  path: primary.path,
2484
2504
  actions: primary.actions,