jazz-tools 0.9.9 → 0.9.10

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.
@@ -1,5 +1,5 @@
1
1
 
2
- > jazz-tools@0.9.9 build /home/runner/work/jazz/jazz/packages/jazz-tools
2
+ > jazz-tools@0.9.10 build /home/runner/work/jazz/jazz/packages/jazz-tools
3
3
  > tsup
4
4
 
5
5
  CLI Building entry: {"index.web":"src/index.web.ts","index.native":"src/index.native.ts","testing":"src/testing.ts"}
@@ -9,12 +9,12 @@
9
9
  CLI Target: es2021
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
+ ESM dist/index.web.js 1.15 KB
12
13
  ESM dist/index.native.js 1.14 KB
13
14
  ESM dist/testing.js 2.30 KB
14
- ESM dist/chunk-VQZOWIPU.js 96.39 KB
15
- ESM dist/testing.js.map 4.89 KB
16
- ESM dist/index.web.js 1.15 KB
17
- ESM dist/index.native.js.map 283.00 B
18
- ESM dist/chunk-VQZOWIPU.js.map 238.27 KB
15
+ ESM dist/chunk-ICWP2U63.js 94.94 KB
19
16
  ESM dist/index.web.js.map 273.00 B
20
- ESM ⚡️ Build success in 83ms
17
+ ESM dist/index.native.js.map 283.00 B
18
+ ESM dist/testing.js.map 4.89 KB
19
+ ESM dist/chunk-ICWP2U63.js.map 235.54 KB
20
+ ESM ⚡️ Build success in 88ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.9.10
4
+
5
+ ### Patch Changes
6
+
7
+ - 5e83864: Improve error management on initial auth, fixed an infinite loop when migration fails
8
+ - Updated dependencies [4aa377d]
9
+ - cojson@0.9.10
10
+
3
11
  ## 0.9.9
4
12
 
5
13
  ### Patch Changes
@@ -454,110 +454,88 @@ async function randomSessionProvider(accountID, crypto) {
454
454
  };
455
455
  }
456
456
  async function createJazzContext(options) {
457
- while (true) {
458
- if (!("auth" in options)) {
459
- return createAnonymousJazzContext({
460
- peersToLoadFrom: options.peersToLoadFrom,
461
- crypto: options.crypto
457
+ if (!("auth" in options)) {
458
+ return createAnonymousJazzContext({
459
+ peersToLoadFrom: options.peersToLoadFrom,
460
+ crypto: options.crypto
461
+ });
462
+ }
463
+ const { auth, sessionProvider, peersToLoadFrom, crypto } = options;
464
+ const AccountSchema = options.AccountSchema ?? RegisteredSchemas["Account"];
465
+ const authResult = await auth.start(crypto);
466
+ if (authResult.type === "existing") {
467
+ const { sessionID, sessionDone } = await sessionProvider(
468
+ authResult.credentials.accountID,
469
+ crypto
470
+ );
471
+ const node = await LocalNode.withLoadedAccount({
472
+ accountID: authResult.credentials.accountID,
473
+ accountSecret: authResult.credentials.secret,
474
+ sessionID,
475
+ peersToLoadFrom,
476
+ crypto,
477
+ migration: async (rawAccount, _node, creationProps) => {
478
+ const account2 = new AccountSchema({
479
+ fromRaw: rawAccount
480
+ });
481
+ activeAccountContext.set(account2);
482
+ await account2.applyMigration(creationProps);
483
+ }
484
+ });
485
+ const account = AccountSchema.fromNode(node);
486
+ activeAccountContext.set(account);
487
+ if (authResult.saveCredentials) {
488
+ await authResult.saveCredentials({
489
+ accountID: node.account.id,
490
+ secret: node.account.agentSecret
462
491
  });
463
492
  }
464
- const { auth, sessionProvider, peersToLoadFrom, crypto } = options;
465
- const AccountSchema = options.AccountSchema ?? RegisteredSchemas["Account"];
466
- let authResult;
467
- try {
468
- authResult = await auth.start(crypto);
469
- } catch (e) {
470
- console.error("error", e);
471
- throw e;
472
- }
473
- if (authResult.type === "existing") {
474
- try {
475
- const { sessionID, sessionDone } = await sessionProvider(
476
- authResult.credentials.accountID,
477
- crypto
478
- );
479
- try {
480
- const node = await LocalNode.withLoadedAccount({
481
- accountID: authResult.credentials.accountID,
482
- accountSecret: authResult.credentials.secret,
483
- sessionID,
484
- peersToLoadFrom,
485
- crypto,
486
- migration: async (rawAccount, _node, creationProps) => {
487
- const account2 = new AccountSchema({
488
- fromRaw: rawAccount
489
- });
490
- activeAccountContext.set(account2);
491
- await account2.applyMigration(creationProps);
492
- }
493
- });
494
- const account = AccountSchema.fromNode(node);
495
- activeAccountContext.set(account);
496
- if (authResult.saveCredentials) {
497
- await authResult.saveCredentials({
498
- accountID: node.account.id,
499
- secret: node.account.agentSecret
500
- });
501
- }
502
- authResult.onSuccess();
503
- return {
504
- account,
505
- done: () => {
506
- node.gracefulShutdown();
507
- sessionDone();
508
- },
509
- logOut: () => {
510
- node.gracefulShutdown();
511
- sessionDone();
512
- authResult.logOut();
513
- }
514
- };
515
- } catch (e) {
516
- authResult.onError(new Error("Error loading account", { cause: e }));
517
- sessionDone();
518
- }
519
- } catch (e) {
520
- authResult.onError(
521
- new Error("Error acquiring sessionID", { cause: e })
522
- );
493
+ authResult.onSuccess();
494
+ return {
495
+ account,
496
+ done: () => {
497
+ node.gracefulShutdown();
498
+ sessionDone();
499
+ },
500
+ logOut: () => {
501
+ node.gracefulShutdown();
502
+ sessionDone();
503
+ authResult.logOut();
523
504
  }
524
- } else if (authResult.type === "new") {
525
- try {
526
- const { node } = await LocalNode.withNewlyCreatedAccount({
527
- creationProps: authResult.creationProps,
528
- peersToLoadFrom,
529
- crypto,
530
- initialAgentSecret: authResult.initialSecret,
531
- migration: async (rawAccount, _node, creationProps) => {
532
- const account2 = new AccountSchema({
533
- fromRaw: rawAccount
534
- });
535
- activeAccountContext.set(account2);
536
- await account2.applyMigration(creationProps);
537
- }
538
- });
539
- const account = AccountSchema.fromNode(node);
540
- activeAccountContext.set(account);
541
- await authResult.saveCredentials({
542
- accountID: node.account.id,
543
- secret: node.account.agentSecret
505
+ };
506
+ } else if (authResult.type === "new") {
507
+ const { node } = await LocalNode.withNewlyCreatedAccount({
508
+ creationProps: authResult.creationProps,
509
+ peersToLoadFrom,
510
+ crypto,
511
+ initialAgentSecret: authResult.initialSecret,
512
+ migration: async (rawAccount, _node, creationProps) => {
513
+ const account2 = new AccountSchema({
514
+ fromRaw: rawAccount
544
515
  });
545
- authResult.onSuccess();
546
- return {
547
- account,
548
- done: () => {
549
- node.gracefulShutdown();
550
- },
551
- logOut: () => {
552
- node.gracefulShutdown();
553
- authResult.logOut();
554
- }
555
- };
556
- } catch (e) {
557
- authResult.onError(new Error("Error creating account", { cause: e }));
516
+ activeAccountContext.set(account2);
517
+ await account2.applyMigration(creationProps);
558
518
  }
559
- }
519
+ });
520
+ const account = AccountSchema.fromNode(node);
521
+ activeAccountContext.set(account);
522
+ await authResult.saveCredentials({
523
+ accountID: node.account.id,
524
+ secret: node.account.agentSecret
525
+ });
526
+ authResult.onSuccess();
527
+ return {
528
+ account,
529
+ done: () => {
530
+ node.gracefulShutdown();
531
+ },
532
+ logOut: () => {
533
+ node.gracefulShutdown();
534
+ authResult.logOut();
535
+ }
536
+ };
560
537
  }
538
+ throw new Error("Invalid auth result");
561
539
  }
562
540
  async function createAnonymousJazzContext({
563
541
  peersToLoadFrom,
@@ -2837,22 +2815,6 @@ var CoPlainText = class extends String {
2837
2815
  /**
2838
2816
  * Load a `CoPlainText` with a given ID, as a given account.
2839
2817
  *
2840
- * `depth` specifies which (if any) fields that reference other CoValues to load as well before resolving.
2841
- * The `DeeplyLoaded` return type guarantees that corresponding referenced CoValues are loaded to the specified depth.
2842
- *
2843
- * You can pass `[]` or `{}` for shallowly loading only this CoPlainText, or `{ fieldA: depthA, fieldB: depthB }` for recursively loading referenced CoValues.
2844
- *
2845
- * Check out the `load` methods on `CoMap`/`CoList`/`CoStream`/`Group`/`Account` to see which depth structures are valid to nest.
2846
- *
2847
- * @example
2848
- * ```ts
2849
- * const person = await Person.load(
2850
- * "co_zdsMhHtfG6VNKt7RqPUPvUtN2Ax",
2851
- * me,
2852
- * { pet: {} }
2853
- * );
2854
- * ```
2855
- *
2856
2818
  * @category Subscription & Loading
2857
2819
  */
2858
2820
  static load(id, as) {
@@ -3092,6 +3054,7 @@ var CoRichText = class extends CoMap {
3092
3054
  end + 1,
3093
3055
  mark.endBefore,
3094
3056
  RangeClass,
3057
+ // @ts-ignore Some Typescript versions flag this as an error
3095
3058
  {},
3096
3059
  {
3097
3060
  markOwner: mark.sourceMark._owner || this._owner
@@ -3417,4 +3380,4 @@ export {
3417
3380
  SchemaUnion
3418
3381
  };
3419
3382
  /* istanbul ignore file -- @preserve */
3420
- //# sourceMappingURL=chunk-VQZOWIPU.js.map
3383
+ //# sourceMappingURL=chunk-ICWP2U63.js.map