jazz-tools 0.10.13 → 0.10.14

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
@@ -35,7 +35,7 @@ import {
35
35
  parseInviteLink,
36
36
  randomSessionProvider,
37
37
  subscribeToCoValue
38
- } from "./chunk-GSIV52ZH.js";
38
+ } from "./chunk-5YDDEUNX.js";
39
39
 
40
40
  // src/index.ts
41
41
  import { MAX_RECOMMENDED_TX_SIZE, cojsonInternals } from "cojson";
package/dist/testing.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  createAnonymousJazzContext,
6
6
  createJazzContext,
7
7
  randomSessionProvider
8
- } from "./chunk-GSIV52ZH.js";
8
+ } from "./chunk-5YDDEUNX.js";
9
9
 
10
10
  // src/testing.ts
11
11
  import { LocalNode } from "cojson";
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  },
18
18
  "type": "module",
19
19
  "license": "MIT",
20
- "version": "0.10.13",
20
+ "version": "0.10.14",
21
21
  "dependencies": {
22
22
  "@scure/bip39": "^1.3.0",
23
23
  "cojson": "0.10.8"
@@ -16,7 +16,6 @@ export type AuthSetPayload = {
16
16
  export class AuthSecretStorage {
17
17
  private listeners: Set<(isAuthenticated: boolean) => void>;
18
18
  public isAuthenticated: boolean;
19
- notify = false;
20
19
 
21
20
  constructor() {
22
21
  this.listeners = new Set();
@@ -97,7 +96,7 @@ export class AuthSecretStorage {
97
96
  };
98
97
  }
99
98
 
100
- async set(payload: AuthSetPayload) {
99
+ async setWithoutNotify(payload: AuthSetPayload) {
101
100
  const kvStore = KvStoreContext.getInstance().getStorage();
102
101
  await kvStore.set(
103
102
  STORAGE_KEY,
@@ -110,10 +109,11 @@ export class AuthSecretStorage {
110
109
  provider: payload.provider,
111
110
  }),
112
111
  );
112
+ }
113
113
 
114
- if (this.notify) {
115
- this.emitUpdate(payload);
116
- }
114
+ async set(payload: AuthSetPayload) {
115
+ this.setWithoutNotify(payload);
116
+ this.emitUpdate(payload);
117
117
  }
118
118
 
119
119
  getIsAuthenticated(data: AuthCredentials | null): boolean {
@@ -139,12 +139,13 @@ export class AuthSecretStorage {
139
139
  }
140
140
  }
141
141
 
142
- async clear() {
142
+ async clearWithoutNotify() {
143
143
  const kvStore = KvStoreContext.getInstance().getStorage();
144
144
  await kvStore.delete(STORAGE_KEY);
145
+ }
145
146
 
146
- if (this.notify) {
147
- this.emitUpdate(null);
148
- }
147
+ async clear() {
148
+ await this.clearWithoutNotify();
149
+ this.emitUpdate(null);
149
150
  }
150
151
  }
@@ -43,10 +43,6 @@ export class JazzContextManager<
43
43
  protected context: PlatformSpecificContext<Acc> | undefined;
44
44
  protected props: P | undefined;
45
45
  protected authSecretStorage = new AuthSecretStorage();
46
- protected authSecretStorageWithNotify = Object.assign(
47
- Object.create(this.authSecretStorage),
48
- { notify: true },
49
- );
50
46
  protected authenticating = false;
51
47
 
52
48
  constructor() {
@@ -103,9 +99,7 @@ export class JazzContextManager<
103
99
  }
104
100
 
105
101
  getAuthSecretStorage() {
106
- // External updates of the auth secret storage are notified by default (e.g. when registering a new Auth provider)
107
- // We skip internal notify to ensure that the isAuthenticated changes are notified along with the context updates
108
- return this.authSecretStorageWithNotify;
102
+ return this.authSecretStorage;
109
103
  }
110
104
 
111
105
  logOut = async () => {
@@ -219,7 +219,7 @@ export async function createJazzContext<Acc extends Account>(options: {
219
219
  AccountSchema: options.AccountSchema,
220
220
  sessionProvider: options.sessionProvider,
221
221
  onLogOut: () => {
222
- authSecretStorage.clear();
222
+ authSecretStorage.clearWithoutNotify();
223
223
  },
224
224
  });
225
225
  } else {
@@ -240,12 +240,12 @@ export async function createJazzContext<Acc extends Account>(options: {
240
240
  crypto,
241
241
  AccountSchema: options.AccountSchema,
242
242
  onLogOut: async () => {
243
- await authSecretStorage.clear();
243
+ await authSecretStorage.clearWithoutNotify();
244
244
  },
245
245
  });
246
246
 
247
247
  if (!options.newAccountProps) {
248
- await authSecretStorage.set({
248
+ await authSecretStorage.setWithoutNotify({
249
249
  accountID: context.account.id,
250
250
  secretSeed,
251
251
  accountSecret: context.node.account.agentSecret,
@@ -257,11 +257,10 @@ describe("AuthSecretStorage", () => {
257
257
  });
258
258
  });
259
259
 
260
- describe("notify=true", () => {
260
+ describe("notify", () => {
261
261
  beforeEach(() => {
262
262
  kvStore.clearAll();
263
263
  authSecretStorage = new AuthSecretStorage();
264
- authSecretStorage.notify = true;
265
264
  });
266
265
 
267
266
  describe("set", () => {
@@ -337,7 +336,7 @@ describe("AuthSecretStorage", () => {
337
336
  });
338
337
  });
339
338
 
340
- describe("notify=false", () => {
339
+ describe("without notify", () => {
341
340
  beforeEach(() => {
342
341
  kvStore.clearAll();
343
342
  authSecretStorage = new AuthSecretStorage();
@@ -348,7 +347,7 @@ describe("AuthSecretStorage", () => {
348
347
  const handler = vi.fn();
349
348
  authSecretStorage.onUpdate(handler);
350
349
 
351
- await authSecretStorage.set({
350
+ await authSecretStorage.setWithoutNotify({
352
351
  accountID: "test123" as ID<Account>,
353
352
  accountSecret:
354
353
  "secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
@@ -365,7 +364,7 @@ describe("AuthSecretStorage", () => {
365
364
  });
366
365
 
367
366
  it("should return false for anonymous credentials", async () => {
368
- await authSecretStorage.set({
367
+ await authSecretStorage.setWithoutNotify({
369
368
  accountID: "test123" as ID<Account>,
370
369
  accountSecret:
371
370
  "secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
@@ -376,7 +375,7 @@ describe("AuthSecretStorage", () => {
376
375
  });
377
376
 
378
377
  it("should return true for non-anonymous credentials", async () => {
379
- await authSecretStorage.set({
378
+ await authSecretStorage.setWithoutNotify({
380
379
  accountID: "test123" as ID<Account>,
381
380
  accountSecret:
382
381
  "secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
@@ -395,7 +394,7 @@ describe("AuthSecretStorage", () => {
395
394
  });
396
395
 
397
396
  it("should return true when the provider is missing", async () => {
398
- await authSecretStorage.set({
397
+ await authSecretStorage.setWithoutNotify({
399
398
  accountID: "test123" as ID<Account>,
400
399
  accountSecret:
401
400
  "secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
@@ -414,7 +413,7 @@ describe("AuthSecretStorage", () => {
414
413
 
415
414
  describe("clear", () => {
416
415
  it("should not emit update event when clearing", async () => {
417
- await authSecretStorage.set({
416
+ await authSecretStorage.setWithoutNotify({
418
417
  accountID: "test123" as ID<Account>,
419
418
  accountSecret:
420
419
  "secret123" as `sealerSecret_z${string}/signerSecret_z${string}`,
@@ -424,7 +423,7 @@ describe("AuthSecretStorage", () => {
424
423
  const handler = vi.fn();
425
424
  authSecretStorage.onUpdate(handler);
426
425
 
427
- await authSecretStorage.clear();
426
+ await authSecretStorage.clearWithoutNotify();
428
427
 
429
428
  expect(handler).not.toHaveBeenCalled();
430
429
  });
@@ -1,8 +1,7 @@
1
1
  // @vitest-environment happy-dom
2
2
 
3
- import { mnemonicToEntropy } from "@scure/bip39";
4
3
  import { AgentSecret } from "cojson";
5
- import { PureJSCrypto } from "cojson/src/crypto/PureJSCrypto";
4
+ import { PureJSCrypto } from "cojson/crypto/PureJSCrypto";
6
5
  import {
7
6
  Account,
8
7
  AuthSecretStorage,
package/tsconfig.json CHANGED
@@ -12,5 +12,5 @@
12
12
  "esModuleInterop": true
13
13
  },
14
14
  "include": ["./src/**/*.ts"],
15
- "exclude": ["./node_modules", "./src/tests"]
15
+ "exclude": ["./node_modules"]
16
16
  }