@weaveprotocol/core 0.1.2 → 0.2.1

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 (199) hide show
  1. package/README.md +322 -45
  2. package/dist/doors/doors.d.ts +139 -0
  3. package/dist/doors/doors.d.ts.map +1 -0
  4. package/dist/doors/doors.js +210 -0
  5. package/dist/doors/doors.js.map +1 -0
  6. package/dist/doors/index.d.ts +9 -0
  7. package/dist/doors/index.d.ts.map +1 -0
  8. package/dist/doors/index.js +7 -0
  9. package/dist/doors/index.js.map +1 -0
  10. package/dist/identity/contact-key.d.ts +68 -0
  11. package/dist/identity/contact-key.d.ts.map +1 -0
  12. package/dist/identity/contact-key.js +185 -0
  13. package/dist/identity/contact-key.js.map +1 -0
  14. package/dist/index.d.ts +16 -7
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +10 -5
  17. package/dist/index.js.map +1 -1
  18. package/dist/network/index.d.ts +2 -0
  19. package/dist/network/index.d.ts.map +1 -1
  20. package/dist/network/index.js +1 -0
  21. package/dist/network/index.js.map +1 -1
  22. package/dist/network/mailbox.d.ts +49 -0
  23. package/dist/network/mailbox.d.ts.map +1 -0
  24. package/dist/network/mailbox.js +125 -0
  25. package/dist/network/mailbox.js.map +1 -0
  26. package/dist/network/mesh.d.ts +6 -0
  27. package/dist/network/mesh.d.ts.map +1 -1
  28. package/dist/network/mesh.js +11 -1
  29. package/dist/network/mesh.js.map +1 -1
  30. package/dist/network/multi-signaling.d.ts +12 -2
  31. package/dist/network/multi-signaling.d.ts.map +1 -1
  32. package/dist/network/multi-signaling.js +86 -14
  33. package/dist/network/multi-signaling.js.map +1 -1
  34. package/dist/network/peer-auth.d.ts +50 -16
  35. package/dist/network/peer-auth.d.ts.map +1 -1
  36. package/dist/network/peer-auth.js +52 -15
  37. package/dist/network/peer-auth.js.map +1 -1
  38. package/dist/node/carrier.d.ts +87 -0
  39. package/dist/node/carrier.d.ts.map +1 -1
  40. package/dist/node/carrier.js +180 -59
  41. package/dist/node/carrier.js.map +1 -1
  42. package/dist/node/copy.d.ts.map +1 -1
  43. package/dist/node/copy.js +6 -3
  44. package/dist/node/copy.js.map +1 -1
  45. package/dist/node/host.d.ts +117 -0
  46. package/dist/node/host.d.ts.map +1 -0
  47. package/dist/node/host.js +192 -0
  48. package/dist/node/host.js.map +1 -0
  49. package/dist/node/index.d.ts +6 -2
  50. package/dist/node/index.d.ts.map +1 -1
  51. package/dist/node/index.js +1 -0
  52. package/dist/node/index.js.map +1 -1
  53. package/dist/node/node.d.ts.map +1 -1
  54. package/dist/node/node.js +958 -25
  55. package/dist/node/node.js.map +1 -1
  56. package/dist/node/space-runtime.d.ts +42 -25
  57. package/dist/node/space-runtime.d.ts.map +1 -1
  58. package/dist/node/space-runtime.js +734 -35
  59. package/dist/node/space-runtime.js.map +1 -1
  60. package/dist/node/types.d.ts +375 -3
  61. package/dist/node/types.d.ts.map +1 -1
  62. package/dist/privacy/space-encryption.d.ts +16 -0
  63. package/dist/privacy/space-encryption.d.ts.map +1 -1
  64. package/dist/privacy/space-encryption.js +40 -0
  65. package/dist/privacy/space-encryption.js.map +1 -1
  66. package/dist/query/engine.js +1 -1
  67. package/dist/query/engine.js.map +1 -1
  68. package/dist/query/types.d.ts +7 -0
  69. package/dist/query/types.d.ts.map +1 -1
  70. package/dist/query/types.js.map +1 -1
  71. package/dist/react/use-query.d.ts +1 -1
  72. package/dist/react/use-query.d.ts.map +1 -1
  73. package/dist/records/topics.d.ts +21 -0
  74. package/dist/records/topics.d.ts.map +1 -0
  75. package/dist/records/topics.js +86 -0
  76. package/dist/records/topics.js.map +1 -0
  77. package/dist/schema/collection-def.d.ts +7 -0
  78. package/dist/schema/collection-def.d.ts.map +1 -1
  79. package/dist/schema/collection-def.js +4 -0
  80. package/dist/schema/collection-def.js.map +1 -1
  81. package/dist/schema/expression.d.ts +2 -0
  82. package/dist/schema/expression.d.ts.map +1 -1
  83. package/dist/schema/expression.js +1 -0
  84. package/dist/schema/expression.js.map +1 -1
  85. package/dist/schemas/contacts.d.ts +214 -0
  86. package/dist/schemas/contacts.d.ts.map +1 -0
  87. package/dist/schemas/contacts.js +98 -0
  88. package/dist/schemas/contacts.js.map +1 -0
  89. package/dist/schemas/index.d.ts +2 -0
  90. package/dist/schemas/index.d.ts.map +1 -1
  91. package/dist/schemas/index.js +1 -0
  92. package/dist/schemas/index.js.map +1 -1
  93. package/dist/session/auth.d.ts.map +1 -1
  94. package/dist/session/auth.js +15 -3
  95. package/dist/session/auth.js.map +1 -1
  96. package/dist/session/connect.d.ts +25 -1
  97. package/dist/session/connect.d.ts.map +1 -1
  98. package/dist/session/connect.js +9 -2
  99. package/dist/session/connect.js.map +1 -1
  100. package/dist/session/hosting.d.ts +155 -0
  101. package/dist/session/hosting.d.ts.map +1 -0
  102. package/dist/session/hosting.js +160 -0
  103. package/dist/session/hosting.js.map +1 -0
  104. package/dist/space/account-registry.d.ts +6 -0
  105. package/dist/space/account-registry.d.ts.map +1 -1
  106. package/dist/space/account-registry.js +16 -4
  107. package/dist/space/account-registry.js.map +1 -1
  108. package/dist/space/notify.d.ts +88 -0
  109. package/dist/space/notify.d.ts.map +1 -0
  110. package/dist/space/notify.js +127 -0
  111. package/dist/space/notify.js.map +1 -0
  112. package/dist/space/pass.d.ts +6 -0
  113. package/dist/space/pass.d.ts.map +1 -1
  114. package/dist/space/pass.js +5 -2
  115. package/dist/space/pass.js.map +1 -1
  116. package/dist/space/roles.d.ts +71 -0
  117. package/dist/space/roles.d.ts.map +1 -1
  118. package/dist/space/roles.js +114 -0
  119. package/dist/space/roles.js.map +1 -1
  120. package/dist/space/space-access.d.ts +24 -0
  121. package/dist/space/space-access.d.ts.map +1 -1
  122. package/dist/space/space-access.js +24 -0
  123. package/dist/space/space-access.js.map +1 -1
  124. package/dist/space/space-manager.d.ts +35 -1
  125. package/dist/space/space-manager.d.ts.map +1 -1
  126. package/dist/space/space-manager.js +72 -25
  127. package/dist/space/space-manager.js.map +1 -1
  128. package/dist/storage/blob/memory.d.ts +9 -0
  129. package/dist/storage/blob/memory.d.ts.map +1 -0
  130. package/dist/storage/blob/memory.js +20 -0
  131. package/dist/storage/blob/memory.js.map +1 -0
  132. package/dist/storage/blob/s3.d.ts +16 -0
  133. package/dist/storage/blob/s3.d.ts.map +1 -0
  134. package/dist/storage/blob/s3.js +86 -0
  135. package/dist/storage/blob/s3.js.map +1 -0
  136. package/dist/storage/blob-store.d.ts +26 -0
  137. package/dist/storage/blob-store.d.ts.map +1 -0
  138. package/dist/storage/blob-store.js +2 -0
  139. package/dist/storage/blob-store.js.map +1 -0
  140. package/dist/storage/encrypted-adapter.d.ts +3 -3
  141. package/dist/storage/encrypted-adapter.js +3 -3
  142. package/dist/storage/folder-adapter.d.ts +8 -8
  143. package/dist/storage/folder-adapter.d.ts.map +1 -1
  144. package/dist/storage/folder-adapter.js +7 -7
  145. package/dist/storage/folder-reconcile.d.ts +12 -14
  146. package/dist/storage/folder-reconcile.d.ts.map +1 -1
  147. package/dist/storage/folder-reconcile.js +20 -14
  148. package/dist/storage/folder-reconcile.js.map +1 -1
  149. package/dist/storage/index.d.ts +0 -1
  150. package/dist/storage/index.d.ts.map +1 -1
  151. package/dist/storage/index.js +0 -1
  152. package/dist/storage/index.js.map +1 -1
  153. package/dist/storage/indexeddb-adapter.d.ts.map +1 -1
  154. package/dist/storage/indexeddb-adapter.js +8 -9
  155. package/dist/storage/indexeddb-adapter.js.map +1 -1
  156. package/dist/storage/mirror.d.ts +68 -0
  157. package/dist/storage/mirror.d.ts.map +1 -0
  158. package/dist/storage/mirror.js +174 -0
  159. package/dist/storage/mirror.js.map +1 -0
  160. package/dist/storage/segment.d.ts +20 -0
  161. package/dist/storage/segment.d.ts.map +1 -0
  162. package/dist/storage/segment.js +27 -0
  163. package/dist/storage/segment.js.map +1 -0
  164. package/dist/storage/storage-provider.d.ts +36 -40
  165. package/dist/storage/storage-provider.d.ts.map +1 -1
  166. package/dist/storage/storage-provider.js +208 -117
  167. package/dist/storage/storage-provider.js.map +1 -1
  168. package/dist/sync/index.d.ts +1 -1
  169. package/dist/sync/index.d.ts.map +1 -1
  170. package/dist/sync/index.js +1 -1
  171. package/dist/sync/index.js.map +1 -1
  172. package/dist/sync/negentropy.d.ts +68 -0
  173. package/dist/sync/negentropy.d.ts.map +1 -0
  174. package/dist/sync/negentropy.js +379 -0
  175. package/dist/sync/negentropy.js.map +1 -0
  176. package/dist/sync/sync-engine.d.ts +45 -13
  177. package/dist/sync/sync-engine.d.ts.map +1 -1
  178. package/dist/sync/sync-engine.js +290 -207
  179. package/dist/sync/sync-engine.js.map +1 -1
  180. package/dist/sync/sync-messages.d.ts +42 -32
  181. package/dist/sync/sync-messages.d.ts.map +1 -1
  182. package/dist/sync/sync-messages.js +1 -1
  183. package/dist/sync/sync-messages.js.map +1 -1
  184. package/dist/types.d.ts +9 -0
  185. package/dist/types.d.ts.map +1 -1
  186. package/dist/types.js.map +1 -1
  187. package/dist/utils/hash.d.ts +9 -0
  188. package/dist/utils/hash.d.ts.map +1 -1
  189. package/dist/utils/hash.js +33 -0
  190. package/dist/utils/hash.js.map +1 -1
  191. package/package.json +8 -3
  192. package/dist/storage/mst.d.ts +0 -121
  193. package/dist/storage/mst.d.ts.map +0 -1
  194. package/dist/storage/mst.js +0 -402
  195. package/dist/storage/mst.js.map +0 -1
  196. package/dist/sync/anti-entropy.d.ts +0 -49
  197. package/dist/sync/anti-entropy.d.ts.map +0 -1
  198. package/dist/sync/anti-entropy.js +0 -62
  199. package/dist/sync/anti-entropy.js.map +0 -1
@@ -0,0 +1,117 @@
1
+ /**
2
+ * @module node/host
3
+ * A carrier that never sleeps, for many accounts: what a hosting service runs.
4
+ *
5
+ * It is the extension's carrier (`node/carrier.ts`) with more than one carry
6
+ * space. Each **subscription** — someone paying for hosting — is a key the
7
+ * account made, a date it is paid until, and once a device hands it over,
8
+ * the account's carry space. The spaces every carry space's passes name are
9
+ * held once, whoever asks for them, so a space shared by two paying members
10
+ * is one space here, online for all its members.
11
+ *
12
+ * Blind, like any carrier: it holds no seed, no space key and no note, signs
13
+ * nothing, and takes in only what passes the same gates as at any member's
14
+ * node. What it learns: which spaces exist, their size, when they change, and
15
+ * — through the carry spaces — which account asked for which.
16
+ *
17
+ * Subscriptions live in the host's own store, next to the carried spaces. The
18
+ * payment side (`cli/src/host/…`) only ever moves a subscription's date.
19
+ */
20
+ import type { CryptoProvider } from '../types.js';
21
+ import { type ServerAuth } from '../network/peer-auth.js';
22
+ import { type CarriedSpace, type CarrierEvent } from './carrier.js';
23
+ import type { StoreFactory } from './stores.js';
24
+ import type { NodeNetworkConfig } from './types.js';
25
+ import type { BlobStore } from '../storage/blob-store.js';
26
+ /** Someone paying for hosting, as the host knows them */
27
+ export interface Subscription {
28
+ /** The subscription key's DID — what every call about it is signed with */
29
+ readonly id: string;
30
+ /** Unix seconds. Past it, the grace period; past that, it is dropped. */
31
+ readonly paidUntil: number;
32
+ /** When it was made, unix seconds */
33
+ readonly since: number;
34
+ /** The account and its carry space, once a device has handed them over */
35
+ readonly carry?: {
36
+ readonly account: string;
37
+ readonly space: string;
38
+ readonly invite: string;
39
+ };
40
+ /** The payment provider's reference for whoever pays — nothing else about them is kept */
41
+ readonly customer?: string;
42
+ /** A wallet payment asked for and not yet seen (`cli/src/wallet.ts`) */
43
+ readonly invoice?: Invoice;
44
+ }
45
+ /** A payment a host asked a wallet for: an exact amount, so the transfer that arrives says whose it is */
46
+ export interface Invoice {
47
+ readonly plan: string;
48
+ /** In the token's smallest unit, as a decimal string */
49
+ readonly amount: string;
50
+ /** When it was asked for, unix seconds — a transfer made before it pays nothing */
51
+ readonly at: number;
52
+ }
53
+ export type SubscriptionState = 'active' | 'grace' | 'lapsed';
54
+ export interface HostConfig {
55
+ /** The host's own key — who it is to peers */
56
+ readonly key: CryptoKeyPair;
57
+ readonly stores: StoreFactory;
58
+ readonly network?: NodeNetworkConfig;
59
+ readonly provider?: CryptoProvider;
60
+ /** Days a lapsed subscription is kept, carried, before it is dropped. Default 30. */
61
+ readonly graceDays?: number;
62
+ /** Every subscription counts as paid — for someone hosting only themselves, and for trying it out */
63
+ readonly free?: boolean;
64
+ /**
65
+ * The accounts this host carries for, and no others — someone hosting only
66
+ * themselves and their family. Absent: any account whose subscription is paid.
67
+ */
68
+ readonly allow?: ReadonlyArray<string>;
69
+ /** Unix seconds now; for tests */
70
+ readonly now?: () => number;
71
+ /**
72
+ * The host's bucket (`storage/blob/s3.ts`): every carried space is kept
73
+ * there too, in the mirror layout, and so is the list of subscriptions. The
74
+ * host's disk is then only a cache — lose it, and everything comes back.
75
+ * A space nobody pays for any more is deleted from it.
76
+ */
77
+ readonly mirror?: BlobStore;
78
+ readonly watchIntervalMs?: number;
79
+ }
80
+ export interface HostNode {
81
+ readonly did: string;
82
+ /** Makes a subscription if there is none by this id, and returns it */
83
+ subscribe(id: string): Promise<Subscription>;
84
+ get(id: string): Promise<Subscription | null>;
85
+ list(): Promise<ReadonlyArray<Subscription>>;
86
+ /** Whether a subscription is paid, in its grace period, or lapsed */
87
+ state(subscription: Subscription): SubscriptionState;
88
+ /** Moves a subscription's paid-until date — the one thing payments do */
89
+ extend(id: string, until: number, customer?: string): Promise<Subscription>;
90
+ /** Keeps a wallet payment asked for, or drops it (null) once it arrived */
91
+ setInvoice(id: string, invoice: Invoice | null): Promise<Subscription>;
92
+ /**
93
+ * Starts carrying an account's spaces for a subscription: its carry space,
94
+ * and every space its passes name. Replaces what the subscription carried.
95
+ * @throws When the subscription is lapsed, or the invite is not a carry space's
96
+ */
97
+ attach(id: string, account: string, invite: string): Promise<Subscription>;
98
+ /** Stops carrying for a subscription; the subscription stays */
99
+ detach(id: string): Promise<void>;
100
+ /** Drops what lapsed past its grace period. Run now and then. */
101
+ sweep(): Promise<ReadonlyArray<string>>;
102
+ /** Every space carried, for every subscription */
103
+ spaces(): Promise<ReadonlyArray<CarriedSpace>>;
104
+ /** How many spaces a subscription's account asks the host to carry */
105
+ carriedFor(id: string): Promise<number>;
106
+ /** For a server taking sockets: checks a connecting peer against the space's history. Null for a space not carried. */
107
+ authenticator(spaceId: string): Promise<ServerAuth | null>;
108
+ subscribeEvents(listener: (event: CarrierEvent) => void): () => void;
109
+ close(): Promise<void>;
110
+ }
111
+ /** An account this host was not told to carry for */
112
+ export declare class NotAllowedError extends Error {
113
+ constructor();
114
+ }
115
+ /** Starts a host */
116
+ export declare function createHostNode(config: HostConfig): Promise<HostNode>;
117
+ //# sourceMappingURL=host.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/node/host.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,cAAc,EAAkB,MAAM,aAAa,CAAC;AAElE,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE5E,OAAO,EAAmB,KAAK,YAAY,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAG1D,yDAAyD;AACzD,MAAM,WAAW,YAAY;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,yEAAyE;IACzE,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,qCAAqC;IACrC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/F,0FAA0F;IAC1F,QAAQ,CAAC,QAAQ,CAAC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EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAoL1E"}
@@ -0,0 +1,192 @@
1
+ import { createP256Provider } from '../identity/crypto-p256.js';
2
+ import { createServerAuth } from '../network/peer-auth.js';
3
+ import { utf8Decode, utf8Encode } from '../utils/encoding.js';
4
+ import { createCarryCore } from './carrier.js';
5
+ import { deleteMirrored } from '../storage/mirror.js';
6
+ const SUBSCRIPTION_PREFIX = 'subscription:';
7
+ /** An account this host was not told to carry for */
8
+ export class NotAllowedError extends Error {
9
+ constructor() {
10
+ super('This host only carries spaces for the accounts its owner named');
11
+ }
12
+ }
13
+ /** Where the subscriptions are kept in the bucket */
14
+ const BUCKET_PREFIX = 'host/subscriptions/';
15
+ const DAY = 24 * 3600;
16
+ /** Starts a host */
17
+ export async function createHostNode(config) {
18
+ const provider = config.provider ?? createP256Provider();
19
+ const now = config.now ?? (() => Math.floor(Date.now() / 1000));
20
+ const graceSeconds = (config.graceDays ?? 30) * DAY;
21
+ const allowed = (account) => !config.allow || config.allow.includes(account);
22
+ const store = await config.stores('host');
23
+ const listeners = new Set();
24
+ const emit = (event) => {
25
+ for (const listener of listeners) {
26
+ try {
27
+ listener(event);
28
+ }
29
+ catch (error) {
30
+ console.error('Error in host listener:', error);
31
+ }
32
+ }
33
+ };
34
+ const read = async (id) => {
35
+ const bytes = await store.get(`${SUBSCRIPTION_PREFIX}${id}`);
36
+ return bytes ? JSON.parse(utf8Decode(bytes)) : null;
37
+ };
38
+ const bucketKey = (id) => `${BUCKET_PREFIX}${encodeURIComponent(id)}.json`;
39
+ const write = async (subscription) => {
40
+ const bytes = utf8Encode(JSON.stringify(subscription));
41
+ await store.put(`${SUBSCRIPTION_PREFIX}${subscription.id}`, bytes);
42
+ // The bucket's copy is what a host with a new disk starts from.
43
+ await config.mirror?.put(bucketKey(subscription.id), bytes);
44
+ return subscription;
45
+ };
46
+ const forget = async (id) => {
47
+ await store.delete(`${SUBSCRIPTION_PREFIX}${id}`);
48
+ await config.mirror?.delete(bucketKey(id));
49
+ };
50
+ const list = async () => {
51
+ const keys = await store.list(SUBSCRIPTION_PREFIX);
52
+ return (await Promise.all(keys.map((key) => read(key.slice(SUBSCRIPTION_PREFIX.length))))).filter((s) => s !== null);
53
+ };
54
+ const state = (subscription) => {
55
+ if (config.free || subscription.paidUntil >= now())
56
+ return 'active';
57
+ return subscription.paidUntil + graceSeconds >= now() ? 'grace' : 'lapsed';
58
+ };
59
+ // A fresh disk: the subscriptions come back from the bucket, and the spaces with them.
60
+ if (config.mirror && (await store.list(SUBSCRIPTION_PREFIX)).length === 0) {
61
+ for (const key of await config.mirror.list(BUCKET_PREFIX)) {
62
+ const bytes = await config.mirror.get(key);
63
+ if (!bytes)
64
+ continue;
65
+ const subscription = JSON.parse(utf8Decode(bytes));
66
+ if (typeof subscription.id === 'string')
67
+ await store.put(`${SUBSCRIPTION_PREFIX}${subscription.id}`, bytes);
68
+ }
69
+ }
70
+ /** The subscription an account's carry space belongs to, when it wrote `carry:closed` */
71
+ let closing = Promise.resolve();
72
+ const core = await createCarryCore({
73
+ key: config.key,
74
+ stores: config.stores,
75
+ ...(config.network ? { network: config.network } : {}),
76
+ provider,
77
+ ...(config.watchIntervalMs !== undefined ? { watchIntervalMs: config.watchIntervalMs } : {}),
78
+ emit,
79
+ ...(config.mirror ? { mirror: config.mirror, onRelease: (spaceId) => deleteMirrored(config.mirror, spaceId) } : {}),
80
+ onClosed: (carrySpace) => {
81
+ // The account stopped using this host: forget its carry space; the subscription stays paid.
82
+ closing = closing.then(async () => {
83
+ for (const subscription of await list()) {
84
+ if (subscription.carry?.space !== carrySpace)
85
+ continue;
86
+ const { carry: _gone, ...rest } = subscription;
87
+ await write(rest);
88
+ }
89
+ await core.removeCarry(carrySpace);
90
+ });
91
+ },
92
+ });
93
+ // Carry again what was carried before a restart — the store is only a cache of the spaces, but the list is ours.
94
+ for (const subscription of await list()) {
95
+ // An account taken off the list since is not carried again.
96
+ if (!subscription.carry || state(subscription) === 'lapsed' || !allowed(subscription.carry.account))
97
+ continue;
98
+ await core.addCarry(subscription.carry.account, subscription.carry.invite).catch((error) => {
99
+ console.error(`Could not carry for subscription ${subscription.id}:`, error);
100
+ });
101
+ }
102
+ /** Whether another subscription still carries this carry space */
103
+ const carriedByOther = async (carrySpace, except) => (await list()).some((other) => other.id !== except && other.carry?.space === carrySpace);
104
+ const host = {
105
+ did: core.did,
106
+ async subscribe(id) {
107
+ if (!id.startsWith('did:key:'))
108
+ throw new Error('A subscription is named by its key');
109
+ return (await read(id)) ?? write({ id, paidUntil: 0, since: now() });
110
+ },
111
+ get: read,
112
+ list,
113
+ state,
114
+ async extend(id, until, customer) {
115
+ const subscription = await host.subscribe(id);
116
+ const extended = { ...subscription, paidUntil: Math.max(subscription.paidUntil, until), ...(customer ? { customer } : {}) };
117
+ await write(extended);
118
+ // Paid again in time: carry again what the grace period had kept.
119
+ if (extended.carry && !core.carries.has(extended.carry.space)) {
120
+ await core.addCarry(extended.carry.account, extended.carry.invite);
121
+ }
122
+ return extended;
123
+ },
124
+ async setInvoice(id, invoice) {
125
+ const { invoice: _before, ...subscription } = await host.subscribe(id);
126
+ return write(invoice ? { ...subscription, invoice } : subscription);
127
+ },
128
+ async attach(id, account, invite) {
129
+ const subscription = await read(id);
130
+ if (!subscription || state(subscription) === 'lapsed')
131
+ throw new Error('That subscription is not paid for');
132
+ if (!account.startsWith('did:key:'))
133
+ throw new Error('An account is named by its DID');
134
+ if (!allowed(account))
135
+ throw new NotAllowedError();
136
+ const space = await core.addCarry(account, invite);
137
+ const before = subscription.carry;
138
+ const attached = await write({ ...subscription, carry: { account, space, invite } });
139
+ if (before && before.space !== space && !(await carriedByOther(before.space, id)))
140
+ await core.removeCarry(before.space);
141
+ return attached;
142
+ },
143
+ async detach(id) {
144
+ const subscription = await read(id);
145
+ if (!subscription?.carry)
146
+ return;
147
+ const { carry, ...rest } = subscription;
148
+ await write(rest);
149
+ if (!(await carriedByOther(carry.space, id)))
150
+ await core.removeCarry(carry.space);
151
+ },
152
+ async sweep() {
153
+ const dropped = [];
154
+ for (const subscription of await list()) {
155
+ if (state(subscription) !== 'lapsed')
156
+ continue;
157
+ await forget(subscription.id);
158
+ if (subscription.carry && !(await carriedByOther(subscription.carry.space, subscription.id))) {
159
+ await core.removeCarry(subscription.carry.space);
160
+ }
161
+ dropped.push(subscription.id);
162
+ }
163
+ return dropped;
164
+ },
165
+ spaces: core.spaces,
166
+ async carriedFor(id) {
167
+ const space = (await read(id))?.carry?.space;
168
+ return space ? (core.carries.get(space)?.wants.size ?? 0) : 0;
169
+ },
170
+ async authenticator(spaceId) {
171
+ const entry = core.carried.get(spaceId);
172
+ if (!entry)
173
+ return null;
174
+ const read = entry.record.space.visibility === 'private' ? entry.runtime.readAccess() : null;
175
+ return createServerAuth(spaceId, read, config.key.privateKey, provider);
176
+ },
177
+ subscribeEvents(listener) {
178
+ listeners.add(listener);
179
+ return () => {
180
+ listeners.delete(listener);
181
+ };
182
+ },
183
+ async close() {
184
+ await closing;
185
+ await core.close();
186
+ await store.close();
187
+ listeners.clear();
188
+ },
189
+ };
190
+ return Object.freeze(host);
191
+ }
192
+ //# sourceMappingURL=host.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/node/host.ts"],"names":[],"mappings":"AAoBA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,gBAAgB,EAAmB,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAC9D,OAAO,EAAE,eAAe,EAAwC,MAAM,cAAc,CAAC;AAIrF,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAwFtD,MAAM,mBAAmB,GAAG,eAAe,CAAC;AAE5C,qDAAqD;AACrD,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACxC;QACE,KAAK,CAAC,gEAAgE,CAAC,CAAC;IAC1E,CAAC;CACF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,EAAE,CAAC;QACpB,CAAC;KACF,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AAC7B,CAAC"}
@@ -7,10 +7,14 @@ export { writeCapability, relayRoom } from './space-runtime.js';
7
7
  export { indexedDBStores, folderStores } from './stores.js';
8
8
  export { copyAccountData } from './copy.js';
9
9
  export { createCarrierNode } from './carrier.js';
10
- export type { CarrierConfig, CarrierNode, CarriedSpace, CarrierEvent } from './carrier.js';
10
+ export type { CarrierConfig, CarrierNode, CarriedSpace, CarrierEvent, CarriedSubscriptionView } from './carrier.js';
11
+ export type { NotifyWhen, CarriedSubscription } from '../space/notify.js';
12
+ export { createHostNode, NotAllowedError } from './host.js';
13
+ export type { HostConfig, HostNode, Invoice, Subscription, SubscriptionState } from './host.js';
11
14
  export type { CopyAccountParams, CopyResult } from './copy.js';
12
15
  export type { StoreFactory, StoreOptions } from './stores.js';
16
+ export type { Keeper } from '../space/roles.js';
13
17
  export { NODE_ACTIONS, runAction, checkActionInput } from './actions.js';
14
18
  export type { NodeAction, ActionSchema } from './actions.js';
15
- export type { P2PNode, NodeConfig, NodeNetworkConfig, NodeSpaces, NodeRecords, NodeRecord, NodeEvent, SpaceSummary, SpaceStatus, SpaceProfile, NewSpace, InvitePreview, ListOptions, ConnectionState, DelegateParams, Delegated, NodeCollection, NodeCollections, DefineCollection, NodeAccount, NodeCarriers, CarrierSummary, AccountProfileView, } from './types.js';
19
+ export type { P2PNode, NodeConfig, NodeNetworkConfig, CacheConfig, NodeSpaces, NodeRecords, NodeRecord, NodeEvent, SpaceSummary, SpaceStatus, SpaceProfile, NewSpace, InvitePreview, ListOptions, ConnectionState, DelegateParams, Delegated, NodeCollection, NodeCollections, DefineCollection, NodeAccount, NodeCarriers, NodeNotifications, NotifyView, NodeHosting, HostingView, CarrierSummary, AccountProfileView, NodeContacts, ContactView, ContactRequest, } from './types.js';
16
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC3F,YAAY,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAC/D,YAAY,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACzE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC7D,YAAY,EACV,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,UAAU,EACV,WAAW,EACX,UAAU,EACV,SAAS,EACT,YAAY,EACZ,WAAW,EACX,YAAY,EACZ,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,cAAc,EACd,SAAS,EACT,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,YAAY,EACZ,cAAc,EACd,kBAAkB,GACnB,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,e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exedDBStores, folderStores } from './stores.js';
8
8
  export { copyAccountData } from './copy.js';
9
9
  export { createCarrierNode } from './carrier.js';
10
+ export { createHostNode, NotAllowedError } from './host.js';
10
11
  export { NODE_ACTIONS, runAction, checkActionInput } from './actions.js';
11
12
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAIjD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAK5D,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/node/node.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA+C,KAAK,UAAU,EAAkB,MAAM,qBAAqB,CAAC;AAqBnH,OAAO,KAAK,EAOV,UAAU,EAQV,OAAO,EAER,MAAM,YAAY,CAAC;AAEpB,yEAAyE;AACzE,eAAO,MAAM,kBAAkB,EAAE,UAA+C,CAAC;AAgCjF;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAo1BrE"}
1
+ {"version":3,"file":"node.d.ts","sourceRoot":"","sources":["../../src/node/node.ts"],"names":[],"mappings":"AAqBA,OAAO,EAA+C,KAAK,UAAU,EAAkB,MAAM,qBAAqB,CAAC;AA6EnH,OAAO,KAAK,EAYV,UAAU,EAaV,OAAO,EAER,MAAM,YAAY,CAAC;AAEpB,yEAAyE;AACzE,eAAO,MAAM,kBAAkB,EAAE,UAA+C,CAAC;AA+CjF;;;;;GAKG;AACH,wBAAsB,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CA+sDrE"}