jazz-tools 0.10.14 → 0.11.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.
Files changed (150) hide show
  1. package/.turbo/turbo-build.log +11 -7
  2. package/CHANGELOG.md +31 -0
  3. package/dist/auth/AuthSecretStorage.d.ts +25 -0
  4. package/dist/auth/AuthSecretStorage.d.ts.map +1 -0
  5. package/dist/auth/DemoAuth.d.ts +27 -0
  6. package/dist/auth/DemoAuth.d.ts.map +1 -0
  7. package/dist/auth/InMemoryKVStore.d.ts +9 -0
  8. package/dist/auth/InMemoryKVStore.d.ts.map +1 -0
  9. package/dist/auth/KvStoreContext.d.ts +17 -0
  10. package/dist/auth/KvStoreContext.d.ts.map +1 -0
  11. package/dist/auth/PassphraseAuth.d.ts +35 -0
  12. package/dist/auth/PassphraseAuth.d.ts.map +1 -0
  13. package/dist/{chunk-5YDDEUNX.js → chunk-RTRX7HIO.js} +193 -81
  14. package/dist/chunk-RTRX7HIO.js.map +1 -0
  15. package/dist/coValues/account.d.ts +120 -0
  16. package/dist/coValues/account.d.ts.map +1 -0
  17. package/dist/coValues/coFeed.d.ts +361 -0
  18. package/dist/coValues/coFeed.d.ts.map +1 -0
  19. package/dist/coValues/coList.d.ts +221 -0
  20. package/dist/coValues/coList.d.ts.map +1 -0
  21. package/dist/coValues/coMap.d.ts +500 -0
  22. package/dist/coValues/coMap.d.ts.map +1 -0
  23. package/dist/coValues/coPlainText.d.ts +69 -0
  24. package/dist/coValues/coPlainText.d.ts.map +1 -0
  25. package/dist/coValues/coRichText.d.ts +259 -0
  26. package/dist/coValues/coRichText.d.ts.map +1 -0
  27. package/dist/coValues/deepLoading.d.ts +81 -0
  28. package/dist/coValues/deepLoading.d.ts.map +1 -0
  29. package/dist/coValues/extensions/imageDef.d.ts +17 -0
  30. package/dist/coValues/extensions/imageDef.d.ts.map +1 -0
  31. package/dist/coValues/group.d.ts +67 -0
  32. package/dist/coValues/group.d.ts.map +1 -0
  33. package/dist/coValues/inbox.d.ts +52 -0
  34. package/dist/coValues/inbox.d.ts.map +1 -0
  35. package/dist/coValues/interfaces.d.ts +97 -0
  36. package/dist/coValues/interfaces.d.ts.map +1 -0
  37. package/dist/coValues/profile.d.ts +28 -0
  38. package/dist/coValues/profile.d.ts.map +1 -0
  39. package/dist/coValues/registeredSchemas.d.ts +12 -0
  40. package/dist/coValues/registeredSchemas.d.ts.map +1 -0
  41. package/dist/coValues/schemaUnion.d.ts +79 -0
  42. package/dist/coValues/schemaUnion.d.ts.map +1 -0
  43. package/dist/exports.d.ts +27 -0
  44. package/dist/exports.d.ts.map +1 -0
  45. package/dist/implementation/ContextManager.d.ts +65 -0
  46. package/dist/implementation/ContextManager.d.ts.map +1 -0
  47. package/dist/implementation/activeAccountContext.d.ts +12 -0
  48. package/dist/implementation/activeAccountContext.d.ts.map +1 -0
  49. package/dist/implementation/anonymousJazzAgent.d.ts +7 -0
  50. package/dist/implementation/anonymousJazzAgent.d.ts.map +1 -0
  51. package/dist/implementation/createContext.d.ts +91 -0
  52. package/dist/implementation/createContext.d.ts.map +1 -0
  53. package/dist/implementation/devtoolsFormatters.d.ts +2 -0
  54. package/dist/implementation/devtoolsFormatters.d.ts.map +1 -0
  55. package/dist/implementation/errors.d.ts +2 -0
  56. package/dist/implementation/errors.d.ts.map +1 -0
  57. package/dist/implementation/inspect.d.ts +3 -0
  58. package/dist/implementation/inspect.d.ts.map +1 -0
  59. package/dist/implementation/invites.d.ts +23 -0
  60. package/dist/implementation/invites.d.ts.map +1 -0
  61. package/dist/implementation/refs.d.ts +21 -0
  62. package/dist/implementation/refs.d.ts.map +1 -0
  63. package/dist/implementation/schema.d.ts +72 -0
  64. package/dist/implementation/schema.d.ts.map +1 -0
  65. package/dist/implementation/subscriptionScope.d.ts +33 -0
  66. package/dist/implementation/subscriptionScope.d.ts.map +1 -0
  67. package/dist/implementation/symbols.d.ts +8 -0
  68. package/dist/implementation/symbols.d.ts.map +1 -0
  69. package/dist/index.d.ts +3 -0
  70. package/dist/index.d.ts.map +1 -0
  71. package/dist/index.js +1 -1
  72. package/dist/internal.d.ts +12 -0
  73. package/dist/internal.d.ts.map +1 -0
  74. package/dist/lib/cache.d.ts +6 -0
  75. package/dist/lib/cache.d.ts.map +1 -0
  76. package/dist/lib/cache.test.d.ts +2 -0
  77. package/dist/lib/cache.test.d.ts.map +1 -0
  78. package/dist/testing.d.ts +41 -0
  79. package/dist/testing.d.ts.map +1 -0
  80. package/dist/testing.js +11 -16
  81. package/dist/testing.js.map +1 -1
  82. package/dist/tests/AuthSecretStorage.test.d.ts +2 -0
  83. package/dist/tests/AuthSecretStorage.test.d.ts.map +1 -0
  84. package/dist/tests/ContextManager.test.d.ts +2 -0
  85. package/dist/tests/ContextManager.test.d.ts.map +1 -0
  86. package/dist/tests/DemoAuth.test.d.ts +2 -0
  87. package/dist/tests/DemoAuth.test.d.ts.map +1 -0
  88. package/dist/tests/PassphraseAuth.test.d.ts +2 -0
  89. package/dist/tests/PassphraseAuth.test.d.ts.map +1 -0
  90. package/dist/tests/account.test.d.ts +2 -0
  91. package/dist/tests/account.test.d.ts.map +1 -0
  92. package/dist/tests/coFeed.test.d.ts +2 -0
  93. package/dist/tests/coFeed.test.d.ts.map +1 -0
  94. package/dist/tests/coList.test.d.ts +2 -0
  95. package/dist/tests/coList.test.d.ts.map +1 -0
  96. package/dist/tests/coMap.test.d.ts +2 -0
  97. package/dist/tests/coMap.test.d.ts.map +1 -0
  98. package/dist/tests/coPlainText.test.d.ts +2 -0
  99. package/dist/tests/coPlainText.test.d.ts.map +1 -0
  100. package/dist/tests/coRichText.test.d.ts +2 -0
  101. package/dist/tests/coRichText.test.d.ts.map +1 -0
  102. package/dist/tests/createContext.test.d.ts +2 -0
  103. package/dist/tests/createContext.test.d.ts.map +1 -0
  104. package/dist/tests/deepLoading.test.d.ts +2 -0
  105. package/dist/tests/deepLoading.test.d.ts.map +1 -0
  106. package/dist/tests/fixtures.d.ts +2 -0
  107. package/dist/tests/fixtures.d.ts.map +1 -0
  108. package/dist/tests/groupsAndAccounts.test.d.ts +2 -0
  109. package/dist/tests/groupsAndAccounts.test.d.ts.map +1 -0
  110. package/dist/tests/inbox.test.d.ts +2 -0
  111. package/dist/tests/inbox.test.d.ts.map +1 -0
  112. package/dist/tests/interfaces.test.d.ts +2 -0
  113. package/dist/tests/interfaces.test.d.ts.map +1 -0
  114. package/dist/tests/invites.test.d.ts +2 -0
  115. package/dist/tests/invites.test.d.ts.map +1 -0
  116. package/dist/tests/schema.test.d.ts +2 -0
  117. package/dist/tests/schema.test.d.ts.map +1 -0
  118. package/dist/tests/schemaUnion.test.d.ts +2 -0
  119. package/dist/tests/schemaUnion.test.d.ts.map +1 -0
  120. package/dist/tests/subscribe.test.d.ts +2 -0
  121. package/dist/tests/subscribe.test.d.ts.map +1 -0
  122. package/dist/tests/testing.test.d.ts +2 -0
  123. package/dist/tests/testing.test.d.ts.map +1 -0
  124. package/dist/tests/utils.d.ts +21 -0
  125. package/dist/tests/utils.d.ts.map +1 -0
  126. package/dist/types.d.ts +52 -0
  127. package/dist/types.d.ts.map +1 -0
  128. package/package.json +8 -7
  129. package/src/coValues/account.ts +69 -11
  130. package/src/coValues/coMap.ts +2 -2
  131. package/src/coValues/coRichText.ts +42 -17
  132. package/src/coValues/group.ts +76 -31
  133. package/src/coValues/inbox.ts +10 -0
  134. package/src/coValues/interfaces.ts +1 -1
  135. package/src/coValues/profile.ts +35 -2
  136. package/src/implementation/ContextManager.ts +63 -15
  137. package/src/implementation/schema.ts +1 -3
  138. package/src/testing.ts +10 -16
  139. package/src/tests/AuthSecretStorage.test.ts +1 -2
  140. package/src/tests/ContextManager.test.ts +27 -14
  141. package/src/tests/PassphraseAuth.test.ts +7 -3
  142. package/src/tests/coMap.test.ts +20 -21
  143. package/src/tests/deepLoading.test.ts +8 -17
  144. package/src/tests/groupsAndAccounts.test.ts +429 -89
  145. package/src/tests/inbox.test.ts +24 -0
  146. package/src/tests/schema.test.ts +45 -5
  147. package/src/tests/utils.ts +7 -3
  148. package/src/types.ts +6 -0
  149. package/tsconfig.json +4 -1
  150. package/dist/chunk-5YDDEUNX.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
 
2
- > jazz-tools@0.10.14 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
- > tsup
2
+ > jazz-tools@0.11.0 build /home/runner/_work/jazz/jazz/packages/jazz-tools
3
+ > tsup && pnpm types
4
4
 
5
5
  CLI Building entry: {"index":"src/index.ts","testing":"src/testing.ts"}
6
6
  CLI Using tsconfig: tsconfig.json
@@ -10,9 +10,13 @@
10
10
  CLI Cleaning output folder
11
11
  ESM Build start
12
12
  ESM dist/index.js 1.50 KB
13
- ESM dist/testing.js 6.28 KB
14
- ESM dist/chunk-5YDDEUNX.js 115.67 KB
13
+ ESM dist/testing.js 6.18 KB
14
+ ESM dist/chunk-RTRX7HIO.js 119.14 KB
15
15
  ESM dist/index.js.map 259.00 B
16
- ESM dist/testing.js.map 12.41 KB
17
- ESM dist/chunk-5YDDEUNX.js.map 275.90 KB
18
- ESM ⚡️ Build success in 38ms
16
+ ESM dist/testing.js.map 12.24 KB
17
+ ESM dist/chunk-RTRX7HIO.js.map 283.79 KB
18
+ ESM ⚡️ Build success in 46ms
19
+
20
+ > jazz-tools@0.11.0 types /home/runner/_work/jazz/jazz/packages/jazz-tools
21
+ > tsc --outDir dist
22
+
package/CHANGELOG.md CHANGED
@@ -1,5 +1,36 @@
1
1
  # jazz-tools
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b9d194a: Make members return inherited members
8
+ Added getRoleOf method to Account and Group
9
+ Added canRead, canWrite, canAdmin methods to Account so simplify permissions checks
10
+ - 34cbdc3: Added revokeExtend method to Group
11
+ - f039e8f: Remove co.members and use RegisteredAccount and the configured AccountSchema to setup the members Account class. Remove everyone from Group.members results
12
+ - e22de9f: Fix profile migrations
13
+
14
+ ### Patch Changes
15
+
16
+ - 6a96d8b: Add getParentGroups API to Group
17
+ - a35249a: Fix CoMap.toJSON() with encoded fields
18
+ - a4713df: Moving to the d.ts files for the exported type definitions
19
+ - Updated dependencies [b9d194a]
20
+ - Updated dependencies [a4713df]
21
+ - Updated dependencies [e22de9f]
22
+ - Updated dependencies [34cbdc3]
23
+ - Updated dependencies [0f67e0a]
24
+ - cojson@0.11.0
25
+
26
+ ## 0.10.15
27
+
28
+ ### Patch Changes
29
+
30
+ - 2f99de0: Avoid race conditions on context creation and run the anonymous migration only when the hook is provided
31
+ - Updated dependencies [f86e278]
32
+ - cojson@0.10.15
33
+
3
34
  ## 0.10.14
4
35
 
5
36
  ### Patch Changes
@@ -0,0 +1,25 @@
1
+ import { AgentSecret } from "cojson";
2
+ import type { Account } from "../coValues/account.js";
3
+ import type { ID } from "../internal.js";
4
+ import { AuthCredentials } from "../types.js";
5
+ export type AuthSetPayload = {
6
+ accountID: ID<Account>;
7
+ secretSeed?: Uint8Array;
8
+ accountSecret: AgentSecret;
9
+ provider: "anonymous" | "clerk" | "demo" | "passkey" | "passphrase" | string;
10
+ };
11
+ export declare class AuthSecretStorage {
12
+ private listeners;
13
+ isAuthenticated: boolean;
14
+ constructor();
15
+ migrate(): Promise<void>;
16
+ get(): Promise<AuthCredentials | null>;
17
+ setWithoutNotify(payload: AuthSetPayload): Promise<void>;
18
+ set(payload: AuthSetPayload): Promise<void>;
19
+ getIsAuthenticated(data: AuthCredentials | null): boolean;
20
+ onUpdate(handler: (isAuthenticated: boolean) => void): () => void;
21
+ emitUpdate(data: AuthCredentials | null): void;
22
+ clearWithoutNotify(): Promise<void>;
23
+ clear(): Promise<void>;
24
+ }
25
+ //# sourceMappingURL=AuthSecretStorage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuthSecretStorage.d.ts","sourceRoot":"","sources":["../../src/auth/AuthSecretStorage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAK9C,MAAM,MAAM,cAAc,GAAG;IAC3B,SAAS,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,aAAa,EAAE,WAAW,CAAC;IAC3B,QAAQ,EAAE,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;CAC9E,CAAC;AAEF,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,SAAS,CAA0C;IACpD,eAAe,EAAE,OAAO,CAAC;;IAO1B,OAAO;IAoDP,GAAG,IAAI,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;IAsBtC,gBAAgB,CAAC,OAAO,EAAE,cAAc;IAexC,GAAG,CAAC,OAAO,EAAE,cAAc;IAKjC,kBAAkB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,GAAG,OAAO;IAKzD,QAAQ,CAAC,OAAO,EAAE,CAAC,eAAe,EAAE,OAAO,KAAK,IAAI;IAOpD,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;IAWjC,kBAAkB;IAKlB,KAAK;CAIZ"}
@@ -0,0 +1,27 @@
1
+ import { AuthenticateAccountFunction } from "../types.js";
2
+ import { AuthSecretStorage } from "./AuthSecretStorage.js";
3
+ /**
4
+ * `DemoAuth` provides a `JazzAuth` object for demo authentication.
5
+ *
6
+ * Demo authentication is useful for quickly testing your app, as it allows you to create new accounts and log in as existing ones.
7
+ *
8
+ * ```
9
+ * import { DemoAuth } from "jazz-tools";
10
+ *
11
+ * const auth = new DemoAuth(jazzContext.authenticate, new AuthSecretStorage());
12
+ * ```
13
+ *
14
+ * @category Auth Providers
15
+ */
16
+ export declare class DemoAuth {
17
+ private authenticate;
18
+ private authSecretStorage;
19
+ constructor(authenticate: AuthenticateAccountFunction, authSecretStorage: AuthSecretStorage);
20
+ logIn: (username: string) => Promise<void>;
21
+ signUp: (username: string) => Promise<void>;
22
+ private addToExistingUsers;
23
+ private getExisitingUsersWithData;
24
+ getExistingUsers: () => Promise<string[]>;
25
+ }
26
+ export declare function encodeUsername(username: string): string;
27
+ //# sourceMappingURL=DemoAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DemoAuth.d.ts","sourceRoot":"","sources":["../../src/auth/DemoAuth.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAS3D;;;;;;;;;;;;GAYG;AACH,qBAAa,QAAQ;IAEjB,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,iBAAiB;gBADjB,YAAY,EAAE,2BAA2B,EACzC,iBAAiB,EAAE,iBAAiB;IAG9C,KAAK,aAAoB,MAAM,mBAqB7B;IAEF,MAAM,aAAoB,MAAM,mBAkC9B;YAEY,kBAAkB;YAalB,yBAAyB;IAQvC,gBAAgB,0BAEd;CACH;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,UAK9C"}
@@ -0,0 +1,9 @@
1
+ import { KvStore } from "./KvStoreContext.js";
2
+ export declare class InMemoryKVStore implements KvStore {
3
+ private store;
4
+ get(key: string): Promise<string | null>;
5
+ set(key: string, value: string): Promise<void>;
6
+ delete(key: string): Promise<void>;
7
+ clearAll(): Promise<void>;
8
+ }
9
+ //# sourceMappingURL=InMemoryKVStore.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"InMemoryKVStore.d.ts","sourceRoot":"","sources":["../../src/auth/InMemoryKVStore.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAE9C,qBAAa,eAAgB,YAAW,OAAO;IAC7C,OAAO,CAAC,KAAK,CAA8B;IAErC,GAAG,CAAC,GAAG,EAAE,MAAM;IAQf,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAI9B,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB,QAAQ;CAGf"}
@@ -0,0 +1,17 @@
1
+ export interface KvStore {
2
+ get(key: string): Promise<string | null>;
3
+ set(key: string, value: string): Promise<void>;
4
+ delete(key: string): Promise<void>;
5
+ clearAll(): Promise<void>;
6
+ }
7
+ export declare class KvStoreContext {
8
+ private static instance;
9
+ private storageInstance;
10
+ private constructor();
11
+ static getInstance(): KvStoreContext;
12
+ isInitialized(): boolean;
13
+ initialize(store: KvStore): void;
14
+ getStorage(): KvStore;
15
+ }
16
+ export default KvStoreContext;
17
+ //# sourceMappingURL=KvStoreContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KvStoreContext.d.ts","sourceRoot":"","sources":["../../src/auth/KvStoreContext.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IACzC,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/C,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAiB;IACxC,OAAO,CAAC,eAAe,CAAwB;IAE/C,OAAO;WAEO,WAAW,IAAI,cAAc;IAOpC,aAAa,IAAI,OAAO;IAIxB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAMhC,UAAU,IAAI,OAAO;CAM7B;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { CryptoProvider } from "cojson";
2
+ import { Account } from "../coValues/account.js";
3
+ import type { ID } from "../internal.js";
4
+ import type { AuthenticateAccountFunction, RegisterAccountFunction } from "../types.js";
5
+ import { AuthSecretStorage } from "./AuthSecretStorage.js";
6
+ /**
7
+ * `PassphraseAuth` provides a `JazzAuth` object for passphrase authentication.
8
+ *
9
+ * ```ts
10
+ * import { PassphraseAuth } from "jazz-tools";
11
+ *
12
+ * const auth = new PassphraseAuth(crypto, jazzContext.authenticate, new AuthSecretStorage(), wordlist);
13
+ * ```
14
+ *
15
+ * @category Auth Providers
16
+ */
17
+ export declare class PassphraseAuth {
18
+ private crypto;
19
+ private authenticate;
20
+ private register;
21
+ private authSecretStorage;
22
+ wordlist: string[];
23
+ passphrase: string;
24
+ constructor(crypto: CryptoProvider, authenticate: AuthenticateAccountFunction, register: RegisterAccountFunction, authSecretStorage: AuthSecretStorage, wordlist: string[]);
25
+ logIn: (passphrase: string) => Promise<void>;
26
+ signUp: (name?: string) => Promise<string>;
27
+ registerNewAccount: (passphrase: string, name: string) => Promise<ID<Account>>;
28
+ getCurrentAccountPassphrase: () => Promise<string>;
29
+ generateRandomPassphrase: () => string;
30
+ loadCurrentAccountPassphrase: () => Promise<void>;
31
+ listeners: Set<() => void>;
32
+ subscribe: (callback: () => void) => () => void;
33
+ notify(): void;
34
+ }
35
+ //# sourceMappingURL=PassphraseAuth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PassphraseAuth.d.ts","sourceRoot":"","sources":["../../src/auth/PassphraseAuth.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAmB,MAAM,QAAQ,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AACjD,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,gBAAgB,CAAC;AACzC,OAAO,KAAK,EACV,2BAA2B,EAC3B,uBAAuB,EACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,qBAAa,cAAc;IAIvB,OAAO,CAAC,MAAM;IACd,OAAO,CAAC,YAAY;IACpB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,iBAAiB;IAClB,QAAQ,EAAE,MAAM,EAAE;IAP3B,UAAU,EAAE,MAAM,CAAM;gBAGd,MAAM,EAAE,cAAc,EACtB,YAAY,EAAE,2BAA2B,EACzC,QAAQ,EAAE,uBAAuB,EACjC,iBAAiB,EAAE,iBAAiB,EACrC,QAAQ,EAAE,MAAM,EAAE;IAG3B,KAAK,eAAsB,MAAM,mBAgC/B;IAEF,MAAM,UAAiB,MAAM,qBAyB3B;IAEF,kBAAkB,eAAsB,MAAM,QAAQ,MAAM,0BAa1D;IAEF,2BAA2B,wBAQzB;IAEF,wBAAwB,eAEtB;IAEF,4BAA4B,sBAI1B;IAEF,SAAS,YAAiB,IAAI,EAAI;IAClC,SAAS,aAAc,MAAM,IAAI,gBAM/B;IAEF,MAAM;CAKP"}
@@ -46,7 +46,6 @@ var inspect = Symbol.for("nodejs.util.inspect.custom");
46
46
  // src/implementation/symbols.ts
47
47
  var SchemaInit = "$SchemaInit$";
48
48
  var ItemsSym = "$items$";
49
- var MembersSym = "$members$";
50
49
 
51
50
  // src/coValues/deepLoading.ts
52
51
  function fulfillsDepth(depth, value) {
@@ -319,7 +318,6 @@ var co = {
319
318
  },
320
319
  ref,
321
320
  items: ItemsSym,
322
- members: MembersSym,
323
321
  optional
324
322
  };
325
323
  function optionalRef(arg) {
@@ -1112,6 +1110,11 @@ var InboxSender = class _InboxSender {
1112
1110
  if (inboxOwnerProfileRaw === "unavailable") {
1113
1111
  throw new Error("Failed to load the inbox owner profile");
1114
1112
  }
1113
+ if (inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "reader" && inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "writer" && inboxOwnerProfileRaw.group.roleOf(currentAccount._raw.id) !== "admin") {
1114
+ throw new Error(
1115
+ "Insufficient permissions to access the inbox, make sure its user profile is publicly readable."
1116
+ );
1117
+ }
1115
1118
  const inboxInvite = inboxOwnerProfileRaw.get("inboxInvite");
1116
1119
  if (!inboxInvite) {
1117
1120
  throw new Error("The user has not set up their inbox");
@@ -1294,7 +1297,7 @@ var _CoMap = class _CoMap extends CoValueBase {
1294
1297
  const jsonedFields = this._raw.keys().map((key) => {
1295
1298
  const tKey = key;
1296
1299
  const descriptor = this._schema[tKey] || this._schema[ItemsSym];
1297
- if (descriptor == "json" || "encode" in descriptor) {
1300
+ if (descriptor == "json" || "encoded" in descriptor) {
1298
1301
  return [key, this._raw.get(key)];
1299
1302
  } else if (isRefEncoded(descriptor)) {
1300
1303
  if (seenAbove?.includes(this[tKey]?.id)) {
@@ -1578,6 +1581,23 @@ var Profile = class extends CoMap {
1578
1581
  this.inbox = co.optional.json();
1579
1582
  this.inboxInvite = co.optional.json();
1580
1583
  }
1584
+ get _owner() {
1585
+ return super._owner;
1586
+ }
1587
+ /**
1588
+ * Creates a new profile with the given initial values and owner.
1589
+ *
1590
+ * The owner (a Group) determines access rights to the Profile.
1591
+ *
1592
+ * @category Creation
1593
+ */
1594
+ static create(init, options) {
1595
+ const owner = options !== void 0 && "owner" in options ? options.owner : options;
1596
+ if (owner?._type === "Account") {
1597
+ throw new Error("Profiles should be owned by a group");
1598
+ }
1599
+ return super.create(init, options);
1600
+ }
1581
1601
  };
1582
1602
 
1583
1603
  // src/coValues/account.ts
@@ -1649,6 +1669,36 @@ var _Account = class _Account extends CoValueBase {
1649
1669
  return "admin";
1650
1670
  }
1651
1671
  }
1672
+ getRoleOf(member) {
1673
+ if (member === "me") {
1674
+ return this.isMe ? "admin" : void 0;
1675
+ }
1676
+ if (member === this.id) {
1677
+ return "admin";
1678
+ }
1679
+ return void 0;
1680
+ }
1681
+ getParentGroups() {
1682
+ return [];
1683
+ }
1684
+ get members() {
1685
+ const ref2 = new Ref(this.id, this._loadedAs, {
1686
+ ref: () => this.constructor,
1687
+ optional: false
1688
+ });
1689
+ return [{ id: this.id, role: "admin", ref: ref2, account: this }];
1690
+ }
1691
+ canRead(value) {
1692
+ const role = value._owner.getRoleOf(this.id);
1693
+ return role === "admin" || role === "writer" || role === "reader" || role === "writeOnly";
1694
+ }
1695
+ canWrite(value) {
1696
+ const role = value._owner.getRoleOf(this.id);
1697
+ return role === "admin" || role === "writer" || role === "writeOnly";
1698
+ }
1699
+ canAdmin(value) {
1700
+ return value._owner.getRoleOf(this.id) === "admin";
1701
+ }
1652
1702
  async acceptInvite(valueID, inviteSecret, coValueClass) {
1653
1703
  if (!this.isLocalNodeOwner) {
1654
1704
  throw new Error("Only a controlled account can accept invites");
@@ -1704,13 +1754,17 @@ var _Account = class _Account extends CoValueBase {
1704
1754
  return this.toJSON();
1705
1755
  }
1706
1756
  async applyMigration(creationProps) {
1707
- if (creationProps) {
1757
+ await this.migrate(creationProps);
1758
+ if (this.profile === void 0 && creationProps) {
1708
1759
  const profileGroup = RegisteredSchemas["Group"].create({ owner: this });
1709
- profileGroup.addMember("everyone", "reader");
1710
- this.profile = Profile.create(
1711
- { name: creationProps.name },
1712
- { owner: profileGroup }
1713
- );
1760
+ this.profile = Profile.create({ name: creationProps.name }, profileGroup);
1761
+ this.profile._owner.addMember("everyone", "reader");
1762
+ } else if (this.profile && creationProps) {
1763
+ if (this.profile._owner._type !== "Group") {
1764
+ throw new Error("Profile must be owned by a Group", {
1765
+ cause: `The profile of the account "${this.id}" was created with an Account as owner, which is not allowed.`
1766
+ });
1767
+ }
1714
1768
  }
1715
1769
  const node = this._raw.core.node;
1716
1770
  const profile = node.expectCoValueLoaded(this._raw.get("profile")).getCurrentContent();
@@ -1719,7 +1773,6 @@ var _Account = class _Account extends CoValueBase {
1719
1773
  profile.set("inbox", inboxRoot.id);
1720
1774
  profile.set("inboxInvite", inboxRoot.inviteLink);
1721
1775
  }
1722
- await this.migrate(creationProps);
1723
1776
  }
1724
1777
  // Placeholder method for subclasses to override
1725
1778
  migrate(creationProps) {
@@ -1791,7 +1844,7 @@ var AccountAndGroupProxyHandler = {
1791
1844
  }
1792
1845
  },
1793
1846
  set(target, key, value, receiver) {
1794
- if ((key === "profile" || key === "root" || key === MembersSym) && typeof value === "object" && SchemaInit in value) {
1847
+ if ((key === "profile" || key === "root") && typeof value === "object" && SchemaInit in value) {
1795
1848
  target.constructor._schema ||= {};
1796
1849
  target.constructor._schema[key] = value[SchemaInit];
1797
1850
  return true;
@@ -1816,7 +1869,7 @@ var AccountAndGroupProxyHandler = {
1816
1869
  }
1817
1870
  },
1818
1871
  defineProperty(target, key, descriptor) {
1819
- if ((key === "profile" || key === "root" || key === MembersSym) && typeof descriptor.value === "object" && SchemaInit in descriptor.value) {
1872
+ if ((key === "profile" || key === "root") && typeof descriptor.value === "object" && SchemaInit in descriptor.value) {
1820
1873
  target.constructor._schema ||= {};
1821
1874
  target.constructor._schema[key] = descriptor.value[SchemaInit];
1822
1875
  return true;
@@ -2753,31 +2806,58 @@ var _Group = class _Group extends CoValueBase {
2753
2806
  return this._raw.removeMember(member === "everyone" ? member : member._raw);
2754
2807
  }
2755
2808
  get members() {
2756
- return this._raw.keys().filter((key) => {
2757
- return key === "everyone" || key.startsWith("co_");
2758
- }).map((id) => {
2759
- const role = this._raw.get(id);
2760
- const accountID = id === "everyone" ? void 0 : id;
2761
- const ref2 = accountID && new Ref(
2762
- accountID,
2763
- this._loadedAs,
2764
- this._schema[MembersSym]
2765
- );
2766
- const accessRef = () => ref2?.accessFrom(this, "members." + id);
2767
- return {
2768
- id,
2769
- role,
2770
- ref: ref2,
2771
- get account() {
2772
- return accessRef();
2809
+ const members = [];
2810
+ const BaseAccountSchema = activeAccountContext.maybeGet()?.constructor || RegisteredSchemas["Account"];
2811
+ const refEncodedAccountSchema = {
2812
+ ref: () => BaseAccountSchema,
2813
+ optional: false
2814
+ };
2815
+ for (const accountID of this._raw.getAllMemberKeysSet()) {
2816
+ if (!isAccountID(accountID)) continue;
2817
+ const role = this._raw.roleOf(accountID);
2818
+ if (role === "admin" || role === "writer" || role === "reader" || role === "writeOnly") {
2819
+ const ref2 = new Ref(
2820
+ accountID,
2821
+ this._loadedAs,
2822
+ refEncodedAccountSchema
2823
+ );
2824
+ const accessRef = () => ref2.accessFrom(this, "members." + accountID);
2825
+ if (!ref2.syncLoad()) {
2826
+ console.warn("Account not loaded", accountID);
2773
2827
  }
2774
- };
2775
- });
2828
+ members.push({
2829
+ id: accountID,
2830
+ role,
2831
+ ref: ref2,
2832
+ get account() {
2833
+ return accessRef();
2834
+ }
2835
+ });
2836
+ }
2837
+ }
2838
+ return members;
2839
+ }
2840
+ getRoleOf(member) {
2841
+ if (member === "me") {
2842
+ return this._raw.roleOf(
2843
+ activeAccountContext.get().id
2844
+ );
2845
+ }
2846
+ return this._raw.roleOf(
2847
+ member === "everyone" ? member : member
2848
+ );
2849
+ }
2850
+ getParentGroups() {
2851
+ return this._raw.getParentGroups().map(({ group }) => _Group.fromRaw(group));
2776
2852
  }
2777
2853
  extend(parent, roleMapping) {
2778
2854
  this._raw.extend(parent._raw, roleMapping);
2779
2855
  return this;
2780
2856
  }
2857
+ async revokeExtend(parent) {
2858
+ await this._raw.revokeExtend(parent._raw);
2859
+ return this;
2860
+ }
2781
2861
  static load(id, asOrDepth, depth) {
2782
2862
  return loadCoValueWithoutMe(this, id, asOrDepth, depth);
2783
2863
  }
@@ -2810,11 +2890,7 @@ var _Group = class _Group extends CoValueBase {
2810
2890
  _Group.prototype._type = "Group";
2811
2891
  _Group._schema = {
2812
2892
  profile: "json",
2813
- root: "json",
2814
- [MembersSym]: {
2815
- ref: () => RegisteredSchemas["Account"],
2816
- optional: false
2817
- }
2893
+ root: "json"
2818
2894
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
2819
2895
  };
2820
2896
  Object.defineProperty(_Group.prototype, "_schema", {
@@ -2822,6 +2898,9 @@ Object.defineProperty(_Group.prototype, "_schema", {
2822
2898
  });
2823
2899
  var Group = _Group;
2824
2900
  RegisteredSchemas["Group"] = Group;
2901
+ function isAccountID(id) {
2902
+ return id.startsWith("co_");
2903
+ }
2825
2904
 
2826
2905
  // src/coValues/coPlainText.ts
2827
2906
  import {
@@ -3293,40 +3372,45 @@ function splitNode(node, at) {
3293
3372
  ];
3294
3373
  }
3295
3374
  }
3296
- var Marks = {
3297
- Heading: class Heading extends Mark {
3298
- constructor() {
3299
- super(...arguments);
3300
- this.tag = co.literal("heading");
3301
- this.level = co.number;
3302
- }
3303
- },
3304
- Paragraph: class Paragraph extends Mark {
3305
- constructor() {
3306
- super(...arguments);
3307
- this.tag = co.literal("paragraph");
3308
- }
3309
- },
3310
- Link: class Link extends Mark {
3311
- constructor() {
3312
- super(...arguments);
3313
- this.tag = co.literal("link");
3314
- this.url = co.string;
3315
- }
3316
- },
3317
- Strong: class Strong extends Mark {
3318
- constructor() {
3319
- super(...arguments);
3320
- this.tag = co.literal("strong");
3321
- }
3322
- },
3323
- Em: class Italic extends Mark {
3324
- constructor() {
3325
- super(...arguments);
3326
- this.tag = co.literal("em");
3327
- }
3375
+ var Heading = class extends Mark {
3376
+ constructor() {
3377
+ super(...arguments);
3378
+ this.tag = co.literal("heading");
3379
+ this.level = co.number;
3380
+ }
3381
+ };
3382
+ var Paragraph = class extends Mark {
3383
+ constructor() {
3384
+ super(...arguments);
3385
+ this.tag = co.literal("paragraph");
3386
+ }
3387
+ };
3388
+ var Link = class extends Mark {
3389
+ constructor() {
3390
+ super(...arguments);
3391
+ this.tag = co.literal("link");
3392
+ this.url = co.string;
3393
+ }
3394
+ };
3395
+ var Strong = class extends Mark {
3396
+ constructor() {
3397
+ super(...arguments);
3398
+ this.tag = co.literal("strong");
3399
+ }
3400
+ };
3401
+ var Em = class extends Mark {
3402
+ constructor() {
3403
+ super(...arguments);
3404
+ this.tag = co.literal("em");
3328
3405
  }
3329
3406
  };
3407
+ var Marks = {
3408
+ Heading,
3409
+ Paragraph,
3410
+ Link,
3411
+ Strong,
3412
+ Em
3413
+ };
3330
3414
 
3331
3415
  // src/coValues/extensions/imageDef.ts
3332
3416
  var _a, _b;
@@ -3591,7 +3675,7 @@ import { cojsonInternals as cojsonInternals4 } from "cojson";
3591
3675
  var JazzContextManager = class {
3592
3676
  constructor() {
3593
3677
  this.authSecretStorage = new AuthSecretStorage();
3594
- this.authenticating = false;
3678
+ this.keepContextOpen = false;
3595
3679
  this.logOut = async () => {
3596
3680
  if (!this.context || !this.props) {
3597
3681
  return;
@@ -3606,6 +3690,14 @@ var JazzContextManager = class {
3606
3690
  }
3607
3691
  this.context.done();
3608
3692
  };
3693
+ this.shouldMigrateAnonymousAccount = async () => {
3694
+ if (!this.props?.onAnonymousAccountDiscarded) {
3695
+ return false;
3696
+ }
3697
+ const prevCredentials = await this.authSecretStorage.get();
3698
+ const wasAnonymous = this.authSecretStorage.getIsAuthenticated(prevCredentials) === false;
3699
+ return wasAnonymous;
3700
+ };
3609
3701
  /**
3610
3702
  * Authenticates the user with the given credentials
3611
3703
  */
@@ -3614,13 +3706,12 @@ var JazzContextManager = class {
3614
3706
  throw new Error("Props required");
3615
3707
  }
3616
3708
  const prevContext = this.context;
3617
- const prevCredentials = await this.authSecretStorage.get();
3618
- const wasAnonymous = this.authSecretStorage.getIsAuthenticated(prevCredentials) === false;
3619
- this.authenticating = true;
3709
+ const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
3710
+ this.keepContextOpen = migratingAnonymousAccount;
3620
3711
  await this.createContext(this.props, { credentials }).finally(() => {
3621
- this.authenticating = false;
3712
+ this.keepContextOpen = false;
3622
3713
  });
3623
- if (wasAnonymous) {
3714
+ if (migratingAnonymousAccount) {
3624
3715
  await this.handleAnonymousAccountMigration(prevContext);
3625
3716
  }
3626
3717
  };
@@ -3629,18 +3720,17 @@ var JazzContextManager = class {
3629
3720
  throw new Error("Props required");
3630
3721
  }
3631
3722
  const prevContext = this.context;
3632
- const prevCredentials = await this.authSecretStorage.get();
3633
- const wasAnonymous = this.authSecretStorage.getIsAuthenticated(prevCredentials) === false;
3634
- this.authenticating = true;
3723
+ const migratingAnonymousAccount = await this.shouldMigrateAnonymousAccount();
3724
+ this.keepContextOpen = migratingAnonymousAccount;
3635
3725
  await this.createContext(this.props, {
3636
3726
  newAccountProps: {
3637
3727
  secret: accountSecret,
3638
3728
  creationProps
3639
3729
  }
3640
3730
  }).finally(() => {
3641
- this.authenticating = false;
3731
+ this.keepContextOpen = false;
3642
3732
  });
3643
- if (wasAnonymous) {
3733
+ if (migratingAnonymousAccount) {
3644
3734
  await this.handleAnonymousAccountMigration(prevContext);
3645
3735
  }
3646
3736
  if (this.context && "me" in this.context) {
@@ -3661,12 +3751,27 @@ var JazzContextManager = class {
3661
3751
  return new InMemoryKVStore();
3662
3752
  }
3663
3753
  async createContext(props, authProps) {
3754
+ this.props = props;
3755
+ const { promise, resolve } = createResolvablePromise();
3756
+ const prevPromise = this.contextPromise;
3757
+ this.contextPromise = promise;
3758
+ await prevPromise;
3759
+ try {
3760
+ const result = await this.getNewContext(props, authProps);
3761
+ await this.updateContext(props, result, authProps);
3762
+ resolve();
3763
+ } catch (error) {
3764
+ resolve();
3765
+ throw error;
3766
+ }
3767
+ }
3768
+ async getNewContext(props, authProps) {
3664
3769
  props;
3665
3770
  authProps;
3666
3771
  throw new Error("Not implemented");
3667
3772
  }
3668
3773
  async updateContext(props, context, authProps) {
3669
- if (!this.authenticating) {
3774
+ if (!this.keepContextOpen) {
3670
3775
  this.context?.done();
3671
3776
  }
3672
3777
  this.context = context;
@@ -3728,6 +3833,13 @@ var JazzContextManager = class {
3728
3833
  }
3729
3834
  }
3730
3835
  };
3836
+ function createResolvablePromise() {
3837
+ let resolve;
3838
+ const promise = new Promise((res) => {
3839
+ resolve = res;
3840
+ });
3841
+ return { promise, resolve };
3842
+ }
3731
3843
 
3732
3844
  // src/auth/DemoAuth.ts
3733
3845
  var DemoAuth = class {
@@ -4045,4 +4157,4 @@ export {
4045
4157
  consumeInviteLink
4046
4158
  };
4047
4159
  /* istanbul ignore file -- @preserve */
4048
- //# sourceMappingURL=chunk-5YDDEUNX.js.map
4160
+ //# sourceMappingURL=chunk-RTRX7HIO.js.map