@dxos/client-services 0.1.30-next.7c60cd3 → 0.1.30

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 (161) hide show
  1. package/dist/lib/browser/{chunk-JLLUQQXD.mjs → chunk-DFO3FW2W.mjs} +949 -1150
  2. package/dist/lib/browser/chunk-DFO3FW2W.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +5 -41
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +221 -50
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +4 -4
  7. package/dist/lib/node/index.cjs +837 -1062
  8. package/dist/lib/node/index.cjs.map +4 -4
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +2937 -2719
  11. package/dist/lib/node/packlets/testing/index.cjs.map +4 -4
  12. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts +1 -2
  13. package/dist/types/src/packlets/invitations/device-invitations-handler.d.ts.map +1 -1
  14. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts +1 -1
  15. package/dist/types/src/packlets/invitations/device-invitations-service.d.ts.map +1 -1
  16. package/dist/types/src/packlets/invitations/index.d.ts +0 -6
  17. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  18. package/dist/types/src/packlets/invitations/invitations-service.d.ts +2 -3
  19. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  20. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts +2 -4
  21. package/dist/types/src/packlets/invitations/space-invitations-handler.d.ts.map +1 -1
  22. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts +2 -3
  23. package/dist/types/src/packlets/invitations/space-invitations-service.d.ts.map +1 -1
  24. package/dist/types/src/packlets/services/client-rpc-server.d.ts +22 -0
  25. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -0
  26. package/dist/types/src/packlets/services/index.d.ts +2 -3
  27. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  28. package/dist/types/src/packlets/services/local-client-services.d.ts +3 -2
  29. package/dist/types/src/packlets/services/local-client-services.d.ts.map +1 -1
  30. package/dist/types/src/packlets/services/service-context.d.ts +1 -1
  31. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  32. package/dist/types/src/packlets/services/service-host.d.ts +22 -8
  33. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  34. package/dist/types/src/packlets/services/service-registry.d.ts +3 -1
  35. package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
  36. package/dist/types/src/packlets/services/utils.d.ts +7 -0
  37. package/dist/types/src/packlets/services/utils.d.ts.map +1 -0
  38. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  39. package/dist/types/src/packlets/spaces/data-space.d.ts +8 -1
  40. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  41. package/dist/types/src/packlets/spaces/index.d.ts +2 -0
  42. package/dist/types/src/packlets/spaces/index.d.ts.map +1 -1
  43. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  44. package/dist/types/src/packlets/spaces/spaces-service.d.ts +4 -1
  45. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  46. package/dist/types/src/packlets/system/system-service.d.ts +2 -2
  47. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  48. package/dist/types/src/packlets/testing/host-test-builder.d.ts +43 -0
  49. package/dist/types/src/packlets/testing/host-test-builder.d.ts.map +1 -0
  50. package/dist/types/src/packlets/testing/index.d.ts +1 -0
  51. package/dist/types/src/packlets/testing/index.d.ts.map +1 -1
  52. package/dist/types/src/packlets/testing/invitation-utils.d.ts +1 -1
  53. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  54. package/dist/types/src/packlets/testing/test-builder.d.ts +32 -34
  55. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  56. package/dist/types/src/packlets/tests/client-services.test.d.ts +2 -0
  57. package/dist/types/src/packlets/tests/client-services.test.d.ts.map +1 -0
  58. package/dist/types/src/packlets/tests/client.test.d.ts +2 -0
  59. package/dist/types/src/packlets/tests/client.test.d.ts.map +1 -0
  60. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts +2 -0
  61. package/dist/types/src/packlets/tests/halo-credentials.test.d.ts.map +1 -0
  62. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts +2 -0
  63. package/dist/types/src/packlets/tests/halo-persistent.test.d.ts.map +1 -0
  64. package/dist/types/src/packlets/tests/halo-profile.test.d.ts +2 -0
  65. package/dist/types/src/packlets/tests/halo-profile.test.d.ts.map +1 -0
  66. package/dist/types/src/packlets/tests/shared-worker.test.d.ts +2 -0
  67. package/dist/types/src/packlets/tests/shared-worker.test.d.ts.map +1 -0
  68. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts +2 -0
  69. package/dist/types/src/packlets/tests/spaces-invitations.test.d.ts.map +1 -0
  70. package/dist/types/src/packlets/tests/spaces.test.d.ts +2 -0
  71. package/dist/types/src/packlets/tests/spaces.test.d.ts.map +1 -0
  72. package/dist/types/src/packlets/tests/text.test.d.ts +2 -0
  73. package/dist/types/src/packlets/tests/text.test.d.ts.map +1 -0
  74. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts +0 -1
  75. package/dist/types/src/packlets/vault/iframe-host-runtime.d.ts.map +1 -1
  76. package/dist/types/src/packlets/vault/iframe-proxy-runtime.d.ts.map +1 -1
  77. package/dist/types/src/packlets/vault/index.d.ts +0 -2
  78. package/dist/types/src/packlets/vault/index.d.ts.map +1 -1
  79. package/dist/types/src/packlets/vault/shell-runtime.d.ts.map +1 -1
  80. package/dist/types/src/packlets/vault/worker-runtime.d.ts.map +1 -1
  81. package/dist/types/src/packlets/vault/worker-session.d.ts +4 -4
  82. package/dist/types/src/packlets/vault/worker-session.d.ts.map +1 -1
  83. package/package.json +31 -30
  84. package/src/packlets/invitations/device-invitations-handler.ts +10 -9
  85. package/src/packlets/invitations/device-invitations-service.test.ts +1 -1
  86. package/src/packlets/invitations/device-invitations-service.ts +1 -1
  87. package/src/packlets/invitations/index.ts +0 -6
  88. package/src/packlets/invitations/invitations-service.ts +7 -2
  89. package/src/packlets/invitations/space-invitations-handler.test.ts +3 -3
  90. package/src/packlets/invitations/space-invitations-handler.ts +11 -11
  91. package/src/packlets/invitations/space-invitations-service.test.ts +1 -1
  92. package/src/packlets/invitations/space-invitations-service.ts +2 -3
  93. package/src/packlets/services/client-rpc-server.ts +91 -0
  94. package/src/packlets/services/index.ts +2 -3
  95. package/src/packlets/services/local-client-services.ts +5 -1
  96. package/src/packlets/services/service-context.test.ts +4 -4
  97. package/src/packlets/services/service-context.ts +1 -1
  98. package/src/packlets/services/service-host.ts +52 -19
  99. package/src/packlets/services/service-registry.test.ts +2 -2
  100. package/src/packlets/services/service-registry.ts +9 -1
  101. package/src/packlets/services/utils.ts +53 -0
  102. package/src/packlets/spaces/data-space-manager.test.ts +64 -4
  103. package/src/packlets/spaces/data-space-manager.ts +11 -7
  104. package/src/packlets/spaces/data-space.ts +13 -1
  105. package/src/packlets/spaces/index.ts +2 -0
  106. package/src/packlets/spaces/notarization-plugin.ts +9 -2
  107. package/src/packlets/spaces/spaces-service.ts +25 -0
  108. package/src/packlets/system/system-service.ts +3 -3
  109. package/src/packlets/testing/host-test-builder.ts +163 -0
  110. package/src/packlets/testing/index.ts +1 -0
  111. package/src/packlets/testing/invitation-utils.ts +1 -2
  112. package/src/packlets/testing/test-builder.ts +156 -138
  113. package/src/packlets/tests/client-services.test.ts +252 -0
  114. package/src/packlets/tests/client.test.ts +143 -0
  115. package/src/packlets/tests/halo-credentials.test.ts +94 -0
  116. package/src/packlets/tests/halo-persistent.test.ts +53 -0
  117. package/src/packlets/tests/halo-profile.test.ts +74 -0
  118. package/src/packlets/tests/shared-worker.test.ts +93 -0
  119. package/src/packlets/tests/spaces-invitations.test.ts +64 -0
  120. package/src/packlets/tests/spaces.test.ts +136 -0
  121. package/src/packlets/tests/text.test.ts +206 -0
  122. package/src/packlets/vault/iframe-host-runtime.ts +26 -34
  123. package/src/packlets/vault/iframe-proxy-runtime.ts +1 -1
  124. package/src/packlets/vault/index.ts +0 -2
  125. package/src/packlets/vault/shell-runtime.ts +1 -2
  126. package/src/packlets/vault/worker-runtime.ts +5 -15
  127. package/src/packlets/vault/worker-session.ts +39 -23
  128. package/dist/lib/browser/chunk-JLLUQQXD.mjs.map +0 -7
  129. package/dist/types/src/packlets/invitations/device-invitations-proxy.d.ts +0 -8
  130. package/dist/types/src/packlets/invitations/device-invitations-proxy.d.ts.map +0 -1
  131. package/dist/types/src/packlets/invitations/encoder.d.ts +0 -9
  132. package/dist/types/src/packlets/invitations/encoder.d.ts.map +0 -1
  133. package/dist/types/src/packlets/invitations/encoder.test.d.ts +0 -2
  134. package/dist/types/src/packlets/invitations/encoder.test.d.ts.map +0 -1
  135. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +0 -56
  136. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +0 -1
  137. package/dist/types/src/packlets/invitations/invitations-proxy.d.ts +0 -18
  138. package/dist/types/src/packlets/invitations/invitations-proxy.d.ts.map +0 -1
  139. package/dist/types/src/packlets/invitations/invitations.d.ts +0 -55
  140. package/dist/types/src/packlets/invitations/invitations.d.ts.map +0 -1
  141. package/dist/types/src/packlets/invitations/space-invitations-proxy.d.ts +0 -11
  142. package/dist/types/src/packlets/invitations/space-invitations-proxy.d.ts.map +0 -1
  143. package/dist/types/src/packlets/services/service-definitions.d.ts +0 -30
  144. package/dist/types/src/packlets/services/service-definitions.d.ts.map +0 -1
  145. package/dist/types/src/packlets/services/service-proxy.d.ts +0 -17
  146. package/dist/types/src/packlets/services/service-proxy.d.ts.map +0 -1
  147. package/dist/types/src/packlets/vault/services.d.ts +0 -21
  148. package/dist/types/src/packlets/vault/services.d.ts.map +0 -1
  149. package/dist/types/src/packlets/vault/shell-controller.d.ts +0 -18
  150. package/dist/types/src/packlets/vault/shell-controller.d.ts.map +0 -1
  151. package/src/packlets/invitations/device-invitations-proxy.ts +0 -14
  152. package/src/packlets/invitations/encoder.test.ts +0 -23
  153. package/src/packlets/invitations/encoder.ts +0 -26
  154. package/src/packlets/invitations/invitations-handler.ts +0 -68
  155. package/src/packlets/invitations/invitations-proxy.ts +0 -159
  156. package/src/packlets/invitations/invitations.ts +0 -113
  157. package/src/packlets/invitations/space-invitations-proxy.ts +0 -16
  158. package/src/packlets/services/service-definitions.ts +0 -68
  159. package/src/packlets/services/service-proxy.ts +0 -54
  160. package/src/packlets/vault/services.ts +0 -42
  161. package/src/packlets/vault/shell-controller.ts +0 -56
@@ -1,8 +0,0 @@
1
- import { AbstractInvitationsProxy } from './invitations-proxy';
2
- /**
3
- * Adapts invitation service observable to client/service stream.
4
- */
5
- export declare class DeviceInvitationsProxy extends AbstractInvitationsProxy {
6
- getInvitationOptions(): {};
7
- }
8
- //# sourceMappingURL=device-invitations-proxy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"device-invitations-proxy.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/invitations/device-invitations-proxy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,wBAAwB;IAClE,oBAAoB;CAGrB"}
@@ -1,9 +0,0 @@
1
- import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
2
- /**
3
- * Encodes and decodes an invitation proto into/from alphanumeric chars.
4
- */
5
- export declare class InvitationEncoder {
6
- static decode(text: string): Invitation;
7
- static encode(invitation: Invitation): string;
8
- }
9
- //# sourceMappingURL=encoder.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/invitations/encoder.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAOxE;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU;IAIvC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM;CAG9C"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=encoder.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encoder.test.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/invitations/encoder.test.ts"],"names":[],"mappings":""}
@@ -1,56 +0,0 @@
1
- import { PublicKey } from '@dxos/keys';
2
- import { NetworkManager } from '@dxos/network-manager';
3
- import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
4
- import { AuthMethod } from '@dxos/protocols/proto/dxos/halo/invitations';
5
- import { AuthenticatingInvitationObservable, CancellableInvitationObservable } from './invitations';
6
- export declare type InvitationsOptions = {
7
- type?: Invitation.Type;
8
- timeout?: number;
9
- swarmKey?: PublicKey;
10
- /**
11
- * Authentication method.
12
- * @default AuthMethod.SHARED_SECRET
13
- */
14
- authMethod?: AuthMethod;
15
- };
16
- /**
17
- * Common interface for Halo and Space invitation proxies and handlers.
18
- * Handles the life-cycle of Space invitations between peers.
19
- *
20
- * Host
21
- * - Creates an invitation containing a swarm topic (which can be shared via a URL, QR code, or direct message).
22
- * - Joins the swarm with the topic and waits for guest's admission request.
23
- * - Wait for guest to authenticate with OTP.
24
- * - Waits for guest to present credentials (containing local device and feed keys).
25
- * - Writes credentials to control feed then exits.
26
- *
27
- * Guest
28
- * - Joins the swarm with the topic.
29
- * - Sends an admission request.
30
- * - Sends authentication OTP.
31
- * - If Space handler then creates a local cloned space (with genesis block).
32
- * - Sends admission credentials.
33
- *
34
- * TODO(burdon): Show proxy/service relationship and reference design doc/diagram.
35
- *
36
- * ```
37
- * [Guest] [Host]
38
- * |-----------------------------RequestAdmission-->|
39
- * |-------------------------------[Authenticate]-->|
40
- * |------------------PresentAdmissionCredentials-->|
41
- * ```
42
- */
43
- export interface InvitationsHandler<T = void> {
44
- createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable;
45
- acceptInvitation(invitation: Invitation, options?: InvitationsOptions): AuthenticatingInvitationObservable;
46
- }
47
- /**
48
- * Base class for Halo/Space invitations handlers.
49
- */
50
- export declare abstract class AbstractInvitationsHandler<T = void> implements InvitationsHandler<T> {
51
- protected readonly _networkManager: NetworkManager;
52
- protected constructor(_networkManager: NetworkManager);
53
- abstract createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable;
54
- abstract acceptInvitation(invitation: Invitation, options?: InvitationsOptions): AuthenticatingInvitationObservable;
55
- }
56
- //# sourceMappingURL=invitations-handler.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invitations-handler.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/invitations/invitations-handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AACxE,OAAO,EAAE,UAAU,EAAE,MAAM,6CAA6C,CAAC;AAEzE,OAAO,EAAE,kCAAkC,EAAE,+BAA+B,EAAE,MAAM,eAAe,CAAC;AAEpG,oBAAY,kBAAkB,GAAG;IAC/B,IAAI,CAAC,EAAE,UAAU,CAAC,IAAI,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB;;;OAGG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,IAAI;IAC1C,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,+BAA+B,CAAC;IAC5F,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,kCAAkC,CAAC;CAC5G;AAED;;GAEG;AAEH,8BAAsB,0BAA0B,CAAC,CAAC,GAAG,IAAI,CAAE,YAAW,kBAAkB,CAAC,CAAC,CAAC;IAGvF,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,cAAc;IADpD,SAAS,aACY,eAAe,EAAE,cAAc;IAGpD,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,+BAA+B;IACpG,QAAQ,CAAC,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,kCAAkC;CACpH"}
@@ -1,18 +0,0 @@
1
- import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
2
- import { AuthenticatingInvitationObservable, CancellableInvitationObservable, InvitationsService } from './invitations';
3
- import { InvitationsOptions, InvitationsHandler } from './invitations-handler';
4
- /**
5
- * Adapts invitations service observable to client/service stream.
6
- * Common base class for HALO and Spaces implementations.
7
- */
8
- export interface InvitationsProxy<T = void> extends InvitationsHandler<T> {
9
- getInvitationOptions(context: T): Invitation;
10
- }
11
- export declare abstract class AbstractInvitationsProxy<T = void> implements InvitationsProxy<T> {
12
- private readonly _invitationsService;
13
- constructor(_invitationsService: InvitationsService);
14
- abstract getInvitationOptions(context: T): Invitation;
15
- createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable;
16
- acceptInvitation(invitation: Invitation, options?: InvitationsOptions): AuthenticatingInvitationObservable;
17
- }
18
- //# sourceMappingURL=invitations-proxy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invitations-proxy.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/invitations/invitations-proxy.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAExE,OAAO,EACL,kCAAkC,EAElC,+BAA+B,EAE/B,kBAAkB,EACnB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE/E;;;GAGG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,IAAI,CAAE,SAAQ,kBAAkB,CAAC,CAAC,CAAC;IACvE,oBAAoB,CAAC,OAAO,EAAE,CAAC,GAAG,UAAU,CAAC;CAC9C;AAED,8BAAsB,wBAAwB,CAAC,CAAC,GAAG,IAAI,CAAE,YAAW,gBAAgB,CAAC,CAAC,CAAC;IAGnF,OAAO,CAAC,QAAQ,CAAC,mBAAmB;gBAAnB,mBAAmB,EAAE,kBAAkB;IAG1D,QAAQ,CAAC,oBAAoB,CAAC,OAAO,EAAE,CAAC,GAAG,UAAU;IAErD,gBAAgB,CAAC,OAAO,EAAE,CAAC,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,+BAA+B;IA0D3F,gBAAgB,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,kCAAkC;CAgE3G"}
@@ -1,55 +0,0 @@
1
- import { AsyncEvents, CancellableObservable, CancellableObservableEvents, CancellableObservableProvider } from '@dxos/async';
2
- import type { Stream } from '@dxos/codec-protobuf';
3
- import { AuthenticationRequest, CancelInvitationRequest, Invitation } from '@dxos/protocols/proto/dxos/client/services';
4
- export declare const AUTHENTICATION_CODE_LENGTH = 6;
5
- export declare const INVITATION_TIMEOUT: number;
6
- export declare const ON_CLOSE_DELAY = 1000;
7
- export interface InvitationsService {
8
- createInvitation(invitation: Invitation): Stream<Invitation>;
9
- authenticate(request: AuthenticationRequest): Promise<void>;
10
- acceptInvitation(invitation: Invitation): Stream<Invitation>;
11
- cancelInvitation(request: CancelInvitationRequest): Promise<void>;
12
- }
13
- /**
14
- * Common invitation events (callbacks) for creating and accepting invitations.
15
- */
16
- export interface InvitationEvents extends AsyncEvents, CancellableObservableEvents {
17
- onConnecting?(invitation: Invitation): void;
18
- onConnected?(invitation: Invitation): void;
19
- onAuthenticating?(invitation: Invitation): void;
20
- onSuccess(invitation: Invitation): void;
21
- }
22
- /**
23
- * Base class for all invitation observables and providers.
24
- * Observable that supports inspection of the current value.
25
- */
26
- export interface CancellableInvitationObservable extends CancellableObservable<InvitationEvents> {
27
- get invitation(): Invitation | undefined;
28
- }
29
- export declare class InvitationObservableProvider extends CancellableObservableProvider<InvitationEvents> implements CancellableInvitationObservable {
30
- private _invitation?;
31
- get invitation(): Invitation | undefined;
32
- setInvitation(invitation: Invitation): void;
33
- }
34
- /**
35
- * Cancelable observer that relays authentication requests.
36
- */
37
- export interface AuthenticatingInvitationObservable extends CancellableInvitationObservable {
38
- authenticate(code: string): Promise<void>;
39
- }
40
- export interface AuthenticatingInvitationProviderActions {
41
- onCancel(): Promise<void>;
42
- onAuthenticate(code: string): Promise<void>;
43
- }
44
- export declare class AuthenticatingInvitationProvider extends InvitationObservableProvider implements AuthenticatingInvitationObservable {
45
- private readonly _actions;
46
- constructor(_actions: AuthenticatingInvitationProviderActions);
47
- authenticate(authenticationCode: string): Promise<void>;
48
- }
49
- /**
50
- * Testing util to wrap non-authenticating observable with promise.
51
- * Don't use this in production code.
52
- * @deprecated
53
- */
54
- export declare const wrapObservable: (observable: CancellableInvitationObservable) => Promise<Invitation>;
55
- //# sourceMappingURL=invitations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"invitations.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/invitations/invitations.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,WAAW,EACX,qBAAqB,EACrB,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AAExH,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,eAAO,MAAM,kBAAkB,QAAa,CAAC;AAG7C,eAAO,MAAM,cAAc,OAAO,CAAC;AAEnC,MAAM,WAAW,kBAAkB;IACjC,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7D,YAAY,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5D,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAC7D,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACnE;AAED;;GAEG;AAEH,MAAM,WAAW,gBAAiB,SAAQ,WAAW,EAAE,2BAA2B;IAChF,YAAY,CAAC,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC5C,WAAW,CAAC,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAC3C,gBAAgB,CAAC,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;IAChD,SAAS,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAAC;CACzC;AAED;;;GAGG;AACH,MAAM,WAAW,+BAAgC,SAAQ,qBAAqB,CAAC,gBAAgB,CAAC;IAC9F,IAAI,UAAU,IAAI,UAAU,GAAG,SAAS,CAAC;CAC1C;AAGD,qBAAa,4BACX,SAAQ,6BAA6B,CAAC,gBAAgB,CACtD,YAAW,+BAA+B;IAE1C,OAAO,CAAC,WAAW,CAAC,CAAa;IAEjC,IAAI,UAAU,IAAI,UAAU,GAAG,SAAS,CAEvC;IAED,aAAa,CAAC,UAAU,EAAE,UAAU;CAGrC;AAED;;GAEG;AACH,MAAM,WAAW,kCAAmC,SAAQ,+BAA+B;IACzF,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C;AAED,MAAM,WAAW,uCAAuC;IACtD,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC1B,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC7C;AAED,qBAAa,gCACX,SAAQ,4BACR,YAAW,kCAAkC;IAI3C,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBAAR,QAAQ,EAAE,uCAAuC;IAK9D,YAAY,CAAC,kBAAkB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9D;AAED;;;;GAIG;AAEH,eAAO,MAAM,cAAc,eAAsB,+BAA+B,KAAG,QAAQ,UAAU,CAcpG,CAAC"}
@@ -1,11 +0,0 @@
1
- import { PublicKey } from '@dxos/keys';
2
- import { AbstractInvitationsProxy } from './invitations-proxy';
3
- /**
4
- * Adapts invitation service observable to client/service stream.
5
- */
6
- export declare class SpaceInvitationsProxy extends AbstractInvitationsProxy<PublicKey> {
7
- getInvitationOptions(context: PublicKey): {
8
- spaceKey: PublicKey;
9
- };
10
- }
11
- //# sourceMappingURL=space-invitations-proxy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"space-invitations-proxy.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/invitations/space-invitations-proxy.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,wBAAwB,CAAC,SAAS,CAAC;IAC5E,oBAAoB,CAAC,OAAO,EAAE,SAAS;;;CAGxC"}
@@ -1,30 +0,0 @@
1
- import { DevicesService, DeviceInvitationsService, IdentityService, NetworkService, SpaceInvitationsService, SpacesService, SystemService } from '@dxos/protocols/proto/dxos/client/services';
2
- import { DevtoolsHost, TracingService } from '@dxos/protocols/proto/dxos/devtools/host';
3
- import { DataService } from '@dxos/protocols/proto/dxos/echo/service';
4
- import { ServiceBundle } from '@dxos/rpc';
5
- export declare type ClientServices = {
6
- SystemService: SystemService;
7
- IdentityService: IdentityService;
8
- DeviceInvitationsService: DeviceInvitationsService;
9
- DevicesService: DevicesService;
10
- SpaceInvitationsService: SpaceInvitationsService;
11
- SpacesService: SpacesService;
12
- DataService: DataService;
13
- NetworkService: NetworkService;
14
- DevtoolsHost: DevtoolsHost;
15
- TracingService: TracingService;
16
- };
17
- /**
18
- * Provide access to client services definitions and service handler.
19
- */
20
- export interface ClientServicesProvider {
21
- descriptors: ServiceBundle<ClientServices>;
22
- services: Partial<ClientServices>;
23
- open(): Promise<void>;
24
- close(): Promise<void>;
25
- }
26
- /**
27
- * Services supported by host.
28
- */
29
- export declare const clientServiceBundle: ServiceBundle<ClientServices>;
30
- //# sourceMappingURL=service-definitions.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service-definitions.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/services/service-definitions.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,cAAc,EACd,wBAAwB,EACxB,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,aAAa,EACb,aAAa,EACd,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,yCAAyC,CAAC;AACtE,OAAO,EAAuB,aAAa,EAAE,MAAM,WAAW,CAAC;AAM/D,oBAAY,cAAc,GAAG;IAC3B,aAAa,EAAE,aAAa,CAAC;IAE7B,eAAe,EAAE,eAAe,CAAC;IACjC,wBAAwB,EAAE,wBAAwB,CAAC;IACnD,cAAc,EAAE,cAAc,CAAC;IAE/B,uBAAuB,EAAE,uBAAuB,CAAC;IACjD,aAAa,EAAE,aAAa,CAAC;IAC7B,WAAW,EAAE,WAAW,CAAC;IAEzB,cAAc,EAAE,cAAc,CAAC;IAG/B,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,EAAE,cAAc,CAAC;CAChC,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,WAAW,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC3C,QAAQ,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAElC,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED;;GAEG;AACH,eAAO,MAAM,mBAAmB,+BAa9B,CAAC"}
@@ -1,17 +0,0 @@
1
- import { ProtoRpcPeer, RpcPort } from '@dxos/rpc';
2
- import { ClientServicesProvider, ClientServices } from './service-definitions';
3
- /**
4
- * Implements services that are not local to the app.
5
- * For example, the services can be located in Wallet Extension.
6
- */
7
- export declare class ClientServicesProxy implements ClientServicesProvider {
8
- private readonly _timeout;
9
- private readonly _proxy;
10
- constructor(port: RpcPort, _timeout?: number);
11
- get proxy(): ProtoRpcPeer<ClientServices>;
12
- get descriptors(): import("@dxos/rpc").ServiceBundle<ClientServices>;
13
- get services(): ClientServices;
14
- open(): Promise<void>;
15
- close(): Promise<void>;
16
- }
17
- //# sourceMappingURL=service-proxy.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"service-proxy.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/services/service-proxy.ts"],"names":[],"mappings":"AAMA,OAAO,EAAsB,YAAY,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEtE,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAuB,MAAM,uBAAuB,CAAC;AAEpG;;;GAGG;AAGH,qBAAa,mBAAoB,YAAW,sBAAsB;IAQ9D,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAP3B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;gBAIpD,IAAI,EAAE,OAAO,EAGI,QAAQ,SAAS;IAUpC,IAAI,KAAK,iCAER;IAED,IAAI,WAAW,sDAEd;IAED,IAAI,QAAQ,mBAEX;IAEK,IAAI;IAIJ,KAAK;CAGZ"}
@@ -1,21 +0,0 @@
1
- import type { IframeService, AppService, ShellService, WorkerService } from '@dxos/protocols/proto/dxos/iframe';
2
- import type { BridgeService } from '@dxos/protocols/proto/dxos/mesh/bridge';
3
- import { ServiceBundle } from '@dxos/rpc';
4
- export declare type IframeServiceBundle = {
5
- IframeService: IframeService;
6
- BridgeService: BridgeService;
7
- };
8
- export declare const iframeServiceBundle: ServiceBundle<IframeServiceBundle>;
9
- export declare type WorkerServiceBundle = {
10
- WorkerService: WorkerService;
11
- };
12
- export declare const workerServiceBundle: ServiceBundle<WorkerServiceBundle>;
13
- export declare type AppServiceBundle = {
14
- AppService: AppService;
15
- };
16
- export declare const appServiceBundle: ServiceBundle<AppServiceBundle>;
17
- export declare type ShellServiceBundle = {
18
- ShellService: ShellService;
19
- };
20
- export declare const shellServiceBundle: ServiceBundle<ShellServiceBundle>;
21
- //# sourceMappingURL=services.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"services.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/vault/services.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAChH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,oBAAY,mBAAmB,GAAG;IAChC,aAAa,EAAE,aAAa,CAAC;IAC7B,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,aAAa,CAAC,mBAAmB,CAGlE,CAAC;AAEF,oBAAY,mBAAmB,GAAG;IAChC,aAAa,EAAE,aAAa,CAAC;CAC9B,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,aAAa,CAAC,mBAAmB,CAElE,CAAC;AAEF,oBAAY,gBAAgB,GAAG;IAC7B,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,aAAa,CAAC,gBAAgB,CAE5D,CAAC;AAEF,oBAAY,kBAAkB,GAAG;IAC/B,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,aAAa,CAAC,kBAAkB,CAEhE,CAAC"}
@@ -1,18 +0,0 @@
1
- import { Event } from '@dxos/async';
2
- import { AppContextRequest, LayoutRequest, ShellDisplay, ShellLayout } from '@dxos/protocols/proto/dxos/iframe';
3
- import { RpcPort } from '@dxos/rpc';
4
- /**
5
- * Provide access to the shell via RPC connection.
6
- */
7
- export declare class ShellController {
8
- private readonly _port;
9
- readonly contextUpdate: Event<AppContextRequest>;
10
- private _shellRpc?;
11
- private _display;
12
- constructor(_port: RpcPort);
13
- get display(): ShellDisplay;
14
- setLayout(layout: ShellLayout, options?: Omit<LayoutRequest, 'layout'>): Promise<void>;
15
- open(): Promise<void>;
16
- close(): Promise<void>;
17
- }
18
- //# sourceMappingURL=shell-controller.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"shell-controller.d.ts","sourceRoot":"","sources":["../../../../../src/packlets/vault/shell-controller.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEpC,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAChH,OAAO,EAAoC,OAAO,EAAE,MAAM,WAAW,CAAC;AAItE;;GAEG;AACH,qBAAa,eAAe;IAKd,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJlC,QAAQ,CAAC,aAAa,2BAAkC;IACxD,OAAO,CAAC,SAAS,CAAC,CAAmC;IACrD,OAAO,CAAC,QAAQ,CAAqB;gBAER,KAAK,EAAE,OAAO;IAE3C,IAAI,OAAO,iBAEV;IAEK,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,GAAE,IAAI,CAAC,aAAa,EAAE,QAAQ,CAAM;IAO1E,IAAI;IAmBJ,KAAK;CAIZ"}
@@ -1,14 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import { AbstractInvitationsProxy } from './invitations-proxy';
6
-
7
- /**
8
- * Adapts invitation service observable to client/service stream.
9
- */
10
- export class DeviceInvitationsProxy extends AbstractInvitationsProxy {
11
- getInvitationOptions() {
12
- return {};
13
- }
14
- }
@@ -1,23 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import { expect } from 'chai';
6
-
7
- import { PublicKey } from '@dxos/keys';
8
- import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
9
- import { describe, test } from '@dxos/test';
10
-
11
- import { InvitationEncoder } from './encoder';
12
-
13
- describe('Invitation utils', () => {
14
- test('encodes and decodes an invitation', () => {
15
- const invitation: Invitation = {
16
- swarmKey: PublicKey.random()
17
- };
18
-
19
- const encoded = InvitationEncoder.encode(invitation);
20
- const decoded = InvitationEncoder.decode(encoded);
21
- expect(decoded.swarmKey).to.deep.eq(invitation.swarmKey);
22
- });
23
- });
@@ -1,26 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import base from 'base-x';
6
-
7
- import { schema } from '@dxos/protocols';
8
- import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
9
-
10
- // Encode with URL-safe alpha-numeric characters.
11
- const base62 = base('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
12
-
13
- const codec = schema.getCodecForType('dxos.client.services.Invitation');
14
-
15
- /**
16
- * Encodes and decodes an invitation proto into/from alphanumeric chars.
17
- */
18
- export class InvitationEncoder {
19
- static decode(text: string): Invitation {
20
- return codec.decode(base62.decode(text));
21
- }
22
-
23
- static encode(invitation: Invitation): string {
24
- return base62.encode(codec.encode(invitation));
25
- }
26
- }
@@ -1,68 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import { PublicKey } from '@dxos/keys';
6
- import { NetworkManager } from '@dxos/network-manager';
7
- import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
8
- import { AuthMethod } from '@dxos/protocols/proto/dxos/halo/invitations';
9
-
10
- import { AuthenticatingInvitationObservable, CancellableInvitationObservable } from './invitations';
11
-
12
- export type InvitationsOptions = {
13
- type?: Invitation.Type;
14
- timeout?: number;
15
- // Used for debugging.
16
- swarmKey?: PublicKey;
17
- /**
18
- * Authentication method.
19
- * @default AuthMethod.SHARED_SECRET
20
- */
21
- authMethod?: AuthMethod;
22
- };
23
-
24
- /**
25
- * Common interface for Halo and Space invitation proxies and handlers.
26
- * Handles the life-cycle of Space invitations between peers.
27
- *
28
- * Host
29
- * - Creates an invitation containing a swarm topic (which can be shared via a URL, QR code, or direct message).
30
- * - Joins the swarm with the topic and waits for guest's admission request.
31
- * - Wait for guest to authenticate with OTP.
32
- * - Waits for guest to present credentials (containing local device and feed keys).
33
- * - Writes credentials to control feed then exits.
34
- *
35
- * Guest
36
- * - Joins the swarm with the topic.
37
- * - Sends an admission request.
38
- * - Sends authentication OTP.
39
- * - If Space handler then creates a local cloned space (with genesis block).
40
- * - Sends admission credentials.
41
- *
42
- * TODO(burdon): Show proxy/service relationship and reference design doc/diagram.
43
- *
44
- * ```
45
- * [Guest] [Host]
46
- * |-----------------------------RequestAdmission-->|
47
- * |-------------------------------[Authenticate]-->|
48
- * |------------------PresentAdmissionCredentials-->|
49
- * ```
50
- */
51
- export interface InvitationsHandler<T = void> {
52
- createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable;
53
- acceptInvitation(invitation: Invitation, options?: InvitationsOptions): AuthenticatingInvitationObservable;
54
- }
55
-
56
- /**
57
- * Base class for Halo/Space invitations handlers.
58
- */
59
- // TODO(burdon): Extract common functionality.
60
- export abstract class AbstractInvitationsHandler<T = void> implements InvitationsHandler<T> {
61
- // prettier-ignore
62
- protected constructor(
63
- protected readonly _networkManager: NetworkManager
64
- ) {}
65
-
66
- abstract createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable;
67
- abstract acceptInvitation(invitation: Invitation, options?: InvitationsOptions): AuthenticatingInvitationObservable;
68
- }
@@ -1,159 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import assert from 'node:assert';
6
-
7
- import { observableError } from '@dxos/async';
8
- import { Stream } from '@dxos/codec-protobuf';
9
- import { log } from '@dxos/log';
10
- import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
11
-
12
- import {
13
- AuthenticatingInvitationObservable,
14
- AuthenticatingInvitationProvider,
15
- CancellableInvitationObservable,
16
- InvitationObservableProvider,
17
- InvitationsService
18
- } from './invitations';
19
- import { InvitationsOptions, InvitationsHandler } from './invitations-handler';
20
-
21
- /**
22
- * Adapts invitations service observable to client/service stream.
23
- * Common base class for HALO and Spaces implementations.
24
- */
25
- export interface InvitationsProxy<T = void> extends InvitationsHandler<T> {
26
- getInvitationOptions(context: T): Invitation;
27
- }
28
-
29
- export abstract class AbstractInvitationsProxy<T = void> implements InvitationsProxy<T> {
30
- // prettier-ignore
31
- constructor(
32
- private readonly _invitationsService: InvitationsService
33
- ) {}
34
-
35
- abstract getInvitationOptions(context: T): Invitation;
36
-
37
- createInvitation(context: T, options?: InvitationsOptions): CancellableInvitationObservable {
38
- let invitationId: string;
39
- const observable = new InvitationObservableProvider(async () => {
40
- if (invitationId) {
41
- await this._invitationsService.cancelInvitation({ invitationId });
42
- }
43
- });
44
-
45
- const invitation: Invitation = { ...this.getInvitationOptions(context), ...options };
46
- const stream: Stream<Invitation> = this._invitationsService.createInvitation(invitation);
47
-
48
- stream.subscribe(
49
- (invitation: Invitation) => {
50
- observable.setInvitation(invitation);
51
-
52
- switch (invitation.state) {
53
- case Invitation.State.CONNECTING: {
54
- assert(invitation.invitationId);
55
- invitationId = invitation.invitationId;
56
- observable.callback.onConnecting?.(invitation);
57
- break;
58
- }
59
-
60
- case Invitation.State.CONNECTED: {
61
- observable.callback.onConnected?.(invitation);
62
- break;
63
- }
64
-
65
- case Invitation.State.AUTHENTICATING: {
66
- observable.callback.onAuthenticating?.(invitation);
67
- break;
68
- }
69
-
70
- case Invitation.State.SUCCESS: {
71
- observable.callback.onSuccess?.(invitation);
72
- break;
73
- }
74
-
75
- case Invitation.State.CANCELLED: {
76
- observable.callback.onCancelled?.();
77
- break;
78
- }
79
-
80
- default: {
81
- log.error(`Invalid state: ${invitation.state}`);
82
- }
83
- }
84
- },
85
- (err) => {
86
- if (err) {
87
- observableError(observable, err);
88
- }
89
- }
90
- );
91
-
92
- return observable;
93
- }
94
-
95
- acceptInvitation(invitation: Invitation, options?: InvitationsOptions): AuthenticatingInvitationObservable {
96
- assert(invitation && invitation.swarmKey);
97
-
98
- const observable = new AuthenticatingInvitationProvider({
99
- onCancel: async () => {
100
- const invitationId = observable.invitation?.invitationId;
101
- assert(invitationId);
102
- await this._invitationsService.cancelInvitation({ invitationId });
103
- },
104
-
105
- onAuthenticate: async (authenticationCode: string) => {
106
- const invitationId = observable.invitation?.invitationId;
107
- assert(invitationId);
108
- await this._invitationsService.authenticate({ invitationId, authenticationCode });
109
- }
110
- });
111
-
112
- const stream: Stream<Invitation> = this._invitationsService.acceptInvitation({ ...invitation, ...options });
113
-
114
- stream.subscribe(
115
- (invitation: Invitation) => {
116
- assert(invitation.invitationId);
117
- observable.setInvitation(invitation);
118
-
119
- switch (invitation.state) {
120
- case Invitation.State.CONNECTING: {
121
- observable.callback.onConnecting?.(invitation);
122
- break;
123
- }
124
-
125
- case Invitation.State.CONNECTED: {
126
- observable.callback.onConnected?.(invitation);
127
- break;
128
- }
129
-
130
- case Invitation.State.AUTHENTICATING: {
131
- observable.callback.onAuthenticating?.(invitation);
132
- break;
133
- }
134
-
135
- case Invitation.State.SUCCESS: {
136
- observable.callback.onSuccess?.(invitation);
137
- break;
138
- }
139
-
140
- case Invitation.State.CANCELLED: {
141
- observable.callback.onCancelled?.();
142
- break;
143
- }
144
-
145
- default: {
146
- log.error(`Invalid state: ${invitation.state}`);
147
- }
148
- }
149
- },
150
- (err) => {
151
- if (err) {
152
- observableError(observable, err);
153
- }
154
- }
155
- );
156
-
157
- return observable;
158
- }
159
- }