@dxos/edge-client 0.6.12-staging.e11e696 → 0.6.13-main.548ca8d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/index.mjs +47 -40
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +5 -2
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/index.cjs +44 -39
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +5 -2
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/index.mjs +47 -40
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +5 -2
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/edge-client.d.ts +2 -0
- package/dist/types/src/edge-client.d.ts.map +1 -1
- package/dist/types/src/edge-http-client.d.ts +2 -1
- package/dist/types/src/edge-http-client.d.ts.map +1 -1
- package/dist/types/src/testing/test-utils.d.ts +1 -0
- package/dist/types/src/testing/test-utils.d.ts.map +1 -1
- package/dist/types/src/utils.d.ts +2 -0
- package/dist/types/src/utils.d.ts.map +1 -0
- package/package.json +14 -14
- package/src/edge-client.ts +11 -4
- package/src/edge-http-client.ts +20 -22
- package/src/testing/test-utils.ts +3 -0
- package/src/utils.ts +10 -0
|
@@ -20,6 +20,7 @@ export type MessengerConfig = {
|
|
|
20
20
|
socketEndpoint: string;
|
|
21
21
|
timeout?: number;
|
|
22
22
|
protocol?: Protocol;
|
|
23
|
+
disableAuth?: boolean;
|
|
23
24
|
};
|
|
24
25
|
export interface EdgeIdentity {
|
|
25
26
|
peerKey: string;
|
|
@@ -47,6 +48,7 @@ export declare class EdgeClient extends Resource implements EdgeConnection {
|
|
|
47
48
|
private _ws?;
|
|
48
49
|
private _keepaliveCtx?;
|
|
49
50
|
private _heartBeatContext?;
|
|
51
|
+
private _baseUrl;
|
|
50
52
|
constructor(_identity: EdgeIdentity, _config: MessengerConfig);
|
|
51
53
|
get info(): {
|
|
52
54
|
open: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-client.d.ts","sourceRoot":"","sources":["../../../src/edge-client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,EAAoD,MAAM,aAAa,CAAC;AAC/F,OAAO,EAA2B,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAIlF,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,4CAA4C,CAAC;AAEzF,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAKhF,OAAO,EAAE,KAAK,QAAQ,EAAgB,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"edge-client.d.ts","sourceRoot":"","sources":["../../../src/edge-client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAW,KAAK,EAAoD,MAAM,aAAa,CAAC;AAC/F,OAAO,EAA2B,QAAQ,EAAE,KAAK,SAAS,EAAE,MAAM,eAAe,CAAC;AAIlF,OAAO,EAAE,KAAK,OAAO,EAAiB,MAAM,4CAA4C,CAAC;AAEzF,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAKhF,OAAO,EAAE,KAAK,QAAQ,EAAgB,MAAM,YAAY,CAAC;AAMzD,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzE,MAAM,WAAW,cAAe,SAAQ,QAAQ,CAAC,SAAS,CAAC;IACzD,SAAS,EAAE,KAAK,CAAC;IACjB,SAAS,EAAE,KAAK,CAAC;IAEjB,IAAI,IAAI,IAAI,GAAG,CAAC;IAChB,IAAI,WAAW,IAAI,MAAM,CAAC;IAC1B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IAAI,WAAW,YAEd;IAED,IAAI,WAAW,WAEd;IAED,IAAI,OAAO,WAEV;IAED,WAAW,CAAC,QAAQ,EAAE,YAAY;IAK3B,WAAW,CAAC,QAAQ,EAAE,eAAe,GAAG,MAAM,IAAI;IAKzD;;OAEG;cACsB,KAAK;IAO9B;;OAEG;cACsB,MAAM;YAKjB,cAAc;YAuEd,eAAe;IA0B7B;;;OAGG;IACU,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBlD,OAAO,CAAC,YAAY;CAcrB"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Context } from '@dxos/context';
|
|
2
2
|
import { type SpaceId } from '@dxos/keys';
|
|
3
|
-
import { type GetNotarizationResponseBody, type PostNotarizationRequestBody } from '@dxos/protocols';
|
|
3
|
+
import { type GetNotarizationResponseBody, type PostNotarizationRequestBody, type JoinSpaceRequest, type JoinSpaceResponseBody } from '@dxos/protocols';
|
|
4
4
|
export declare class EdgeHttpClient {
|
|
5
5
|
private readonly _baseUrl;
|
|
6
6
|
constructor(baseUrl: string);
|
|
7
7
|
getCredentialsForNotarization(spaceId: SpaceId, args?: EdgeHttpGetArgs): Promise<GetNotarizationResponseBody>;
|
|
8
8
|
notarizeCredentials(spaceId: SpaceId, body: PostNotarizationRequestBody, args?: EdgeHttpGetArgs): Promise<void>;
|
|
9
|
+
joinSpaceByInvitation(spaceId: SpaceId, body: JoinSpaceRequest, args?: EdgeHttpGetArgs): Promise<JoinSpaceResponseBody>;
|
|
9
10
|
private _call;
|
|
10
11
|
}
|
|
11
12
|
export type RetryConfig = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-http-client.d.ts","sourceRoot":"","sources":["../../../src/edge-http-client.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,YAAY,CAAC;AAE1C,OAAO,E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K,CAAC,EAAE,WAAW,CAAA;CAAE,CAAC"}
|
|
@@ -14,6 +14,7 @@ export declare const createTestEdgeWsServer: (port?: number, params?: TestEdgeWs
|
|
|
14
14
|
cleanup: () => void;
|
|
15
15
|
currentConnection: () => WebSocket | undefined;
|
|
16
16
|
sendResponseMessage: (request: Message, responsePayload: Uint8Array) => void;
|
|
17
|
+
sendMessage: (msg: Message) => void;
|
|
17
18
|
closeConnection: () => Promise<void>;
|
|
18
19
|
}>;
|
|
19
20
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-utils.ts"],"names":[],"mappings":"AAIA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAoC,KAAK,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAK5G,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,KAAK,sBAAsB,GAAG;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,GAAG,CAAC;IAC9C,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CACpE,CAAC;AAEF,eAAO,MAAM,sBAAsB,2BAAwC,sBAAsB;;;;;;
|
|
1
|
+
{"version":3,"file":"test-utils.d.ts","sourceRoot":"","sources":["../../../../src/testing/test-utils.ts"],"names":[],"mappings":"AAIA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAGtC,OAAO,EAAoC,KAAK,OAAO,EAAE,MAAM,4CAA4C,CAAC;AAK5G,eAAO,MAAM,YAAY,OAAO,CAAC;AAEjC,KAAK,sBAAsB,GAAG;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,UAAU,KAAK,GAAG,CAAC;IAC9C,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAAC;CACpE,CAAC;AAEF,eAAO,MAAM,sBAAsB,2BAAwC,sBAAsB;;;;;;mCAmE9E,OAAO,mBAAmB,UAAU;uBA1BhC,OAAO;;EAS7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,YAAa,MAAM,YAAY,MAAM,GAAG,IAAI,WAK9E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/edge-client",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.13-main.548ca8d",
|
|
4
4
|
"description": "EDGE Client",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -40,21 +40,21 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"isomorphic-ws": "^5.0.0",
|
|
42
42
|
"ws": "^8.14.2",
|
|
43
|
-
"@dxos/async": "0.6.
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/invariant": "0.6.
|
|
49
|
-
"@dxos/keyring": "0.6.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/log": "0.6.
|
|
52
|
-
"@dxos/
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
43
|
+
"@dxos/async": "0.6.13-main.548ca8d",
|
|
44
|
+
"@dxos/debug": "0.6.13-main.548ca8d",
|
|
45
|
+
"@dxos/context": "0.6.13-main.548ca8d",
|
|
46
|
+
"@dxos/credentials": "0.6.13-main.548ca8d",
|
|
47
|
+
"@dxos/keys": "0.6.13-main.548ca8d",
|
|
48
|
+
"@dxos/invariant": "0.6.13-main.548ca8d",
|
|
49
|
+
"@dxos/keyring": "0.6.13-main.548ca8d",
|
|
50
|
+
"@dxos/crypto": "0.6.13-main.548ca8d",
|
|
51
|
+
"@dxos/log": "0.6.13-main.548ca8d",
|
|
52
|
+
"@dxos/protocols": "0.6.13-main.548ca8d",
|
|
53
|
+
"@dxos/util": "0.6.13-main.548ca8d",
|
|
54
|
+
"@dxos/node-std": "0.6.13-main.548ca8d"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@dxos/test-utils": "0.6.
|
|
57
|
+
"@dxos/test-utils": "0.6.13-main.548ca8d"
|
|
58
58
|
},
|
|
59
59
|
"publishConfig": {
|
|
60
60
|
"access": "public"
|
package/src/edge-client.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { protocol } from './defs';
|
|
|
17
17
|
import { EdgeConnectionClosedError, EdgeIdentityChangedError } from './errors';
|
|
18
18
|
import { PersistentLifecycle } from './persistent-lifecycle';
|
|
19
19
|
import { type Protocol, toUint8Array } from './protocol';
|
|
20
|
+
import { getEdgeUrlWithProtocol } from './utils';
|
|
20
21
|
|
|
21
22
|
const DEFAULT_TIMEOUT = 10_000;
|
|
22
23
|
const SIGNAL_KEEPALIVE_INTERVAL = 5_000;
|
|
@@ -41,6 +42,7 @@ export type MessengerConfig = {
|
|
|
41
42
|
socketEndpoint: string;
|
|
42
43
|
timeout?: number;
|
|
43
44
|
protocol?: Protocol;
|
|
45
|
+
disableAuth?: boolean;
|
|
44
46
|
};
|
|
45
47
|
|
|
46
48
|
export interface EdgeIdentity {
|
|
@@ -54,8 +56,6 @@ export interface EdgeIdentity {
|
|
|
54
56
|
presentCredentials({ challenge }: { challenge: Uint8Array }): Promise<Presentation>;
|
|
55
57
|
}
|
|
56
58
|
|
|
57
|
-
const DISABLE_AUTH = true;
|
|
58
|
-
|
|
59
59
|
/**
|
|
60
60
|
* Messenger client.
|
|
61
61
|
*/
|
|
@@ -74,11 +74,14 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
74
74
|
private _keepaliveCtx?: Context = undefined;
|
|
75
75
|
private _heartBeatContext?: Context = undefined;
|
|
76
76
|
|
|
77
|
+
private _baseUrl: string;
|
|
78
|
+
|
|
77
79
|
constructor(
|
|
78
80
|
private _identity: EdgeIdentity,
|
|
79
81
|
private readonly _config: MessengerConfig,
|
|
80
82
|
) {
|
|
81
83
|
super();
|
|
84
|
+
this._baseUrl = getEdgeUrlWithProtocol(_config.socketEndpoint, 'ws');
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
// TODO(burdon): Attach logging.
|
|
@@ -133,14 +136,18 @@ export class EdgeClient extends Resource implements EdgeConnection {
|
|
|
133
136
|
private async _openWebSocket() {
|
|
134
137
|
let protocolHeader: string | undefined;
|
|
135
138
|
|
|
136
|
-
if (!
|
|
139
|
+
if (!this._config.disableAuth) {
|
|
137
140
|
// TODO(dmaretskyi): Get challenge from the WWW-Authenticate header returned by the endpoint.
|
|
138
141
|
const challenge = randomBytes(32);
|
|
139
142
|
const credential = await this._identity.presentCredentials({ challenge });
|
|
140
143
|
protocolHeader = encodePresentationIntoAuthHeader(credential);
|
|
141
144
|
}
|
|
142
145
|
|
|
143
|
-
|
|
146
|
+
if (this._ctx.disposed) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const url = new URL(`/ws/${this._identity.identityKey}/${this._identity.peerKey}`, this._baseUrl);
|
|
144
151
|
log('Opening websocket', { url: url.toString(), protocolHeader });
|
|
145
152
|
this._ws = new WebSocket(url, protocolHeader ? [protocolHeader] : []);
|
|
146
153
|
|
package/src/edge-http-client.ts
CHANGED
|
@@ -11,8 +11,13 @@ import {
|
|
|
11
11
|
type EdgeHttpResponse,
|
|
12
12
|
type GetNotarizationResponseBody,
|
|
13
13
|
type PostNotarizationRequestBody,
|
|
14
|
+
type JoinSpaceRequest,
|
|
15
|
+
type JoinSpaceResponseBody,
|
|
16
|
+
EdgeAuthChallengeError,
|
|
14
17
|
} from '@dxos/protocols';
|
|
15
18
|
|
|
19
|
+
import { getEdgeUrlWithProtocol } from './utils';
|
|
20
|
+
|
|
16
21
|
const DEFAULT_RETRY_TIMEOUT = 1500;
|
|
17
22
|
const DEFAULT_RETRY_JITTER = 500;
|
|
18
23
|
const DEFAULT_MAX_RETRIES_COUNT = 3;
|
|
@@ -21,9 +26,7 @@ export class EdgeHttpClient {
|
|
|
21
26
|
private readonly _baseUrl: string;
|
|
22
27
|
|
|
23
28
|
constructor(baseUrl: string) {
|
|
24
|
-
|
|
25
|
-
url.protocol = 'https';
|
|
26
|
-
this._baseUrl = url.toString();
|
|
29
|
+
this._baseUrl = getEdgeUrlWithProtocol(baseUrl, 'http');
|
|
27
30
|
log('created', { url: this._baseUrl });
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -39,6 +42,14 @@ export class EdgeHttpClient {
|
|
|
39
42
|
await this._call(`/spaces/${spaceId}/notarization`, { ...args, body, method: 'POST' });
|
|
40
43
|
}
|
|
41
44
|
|
|
45
|
+
public async joinSpaceByInvitation(
|
|
46
|
+
spaceId: SpaceId,
|
|
47
|
+
body: JoinSpaceRequest,
|
|
48
|
+
args?: EdgeHttpGetArgs,
|
|
49
|
+
): Promise<JoinSpaceResponseBody> {
|
|
50
|
+
return this._call(`/spaces/${spaceId}/join`, { ...args, body, method: 'POST' });
|
|
51
|
+
}
|
|
52
|
+
|
|
42
53
|
private async _call<T>(path: string, args: EdgeHttpCallArgs): Promise<T> {
|
|
43
54
|
const requestContext = args.context ?? new Context();
|
|
44
55
|
const shouldRetry = createRetryHandler(args);
|
|
@@ -61,23 +72,19 @@ export class EdgeHttpClient {
|
|
|
61
72
|
return body.data;
|
|
62
73
|
}
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
75
|
+
if (body.errorData?.type === 'auth_challenge' && typeof body.errorData?.challenge === 'string') {
|
|
76
|
+
processingError = new EdgeAuthChallengeError(body.errorData.challenge, body.errorData);
|
|
77
|
+
} else {
|
|
78
|
+
processingError = EdgeCallFailedError.fromUnsuccessfulResponse(response, body);
|
|
67
79
|
}
|
|
68
|
-
|
|
69
|
-
processingError = new EdgeCallFailedError(body.reason);
|
|
70
80
|
} else {
|
|
71
|
-
processingError = EdgeCallFailedError.
|
|
72
|
-
if (!isRetryable(response.status)) {
|
|
73
|
-
throw processingError;
|
|
74
|
-
}
|
|
81
|
+
processingError = EdgeCallFailedError.fromHttpFailure(response);
|
|
75
82
|
}
|
|
76
83
|
} catch (error: any) {
|
|
77
84
|
processingError = EdgeCallFailedError.fromProcessingFailureCause(error);
|
|
78
85
|
}
|
|
79
86
|
|
|
80
|
-
if (await shouldRetry(requestContext, retryAfterHeaderValue)) {
|
|
87
|
+
if (processingError.isRetryable && (await shouldRetry(requestContext, retryAfterHeaderValue))) {
|
|
81
88
|
log.info('retrying edge request', { path, processingError });
|
|
82
89
|
} else {
|
|
83
90
|
throw processingError;
|
|
@@ -93,15 +100,6 @@ const createRequest = (args: EdgeHttpCallArgs): RequestInit => {
|
|
|
93
100
|
};
|
|
94
101
|
};
|
|
95
102
|
|
|
96
|
-
const isRetryable = (status: number) => {
|
|
97
|
-
if (status === 501) {
|
|
98
|
-
// Not Implemented
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
// TODO: handle 401 Not Authorized
|
|
102
|
-
return !(status >= 400 && status < 500);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
103
|
const createRetryHandler = (args: EdgeHttpCallArgs) => {
|
|
106
104
|
if (!args.retry || args.retry.count < 1) {
|
|
107
105
|
return async () => false;
|
|
@@ -61,6 +61,9 @@ export const createTestEdgeWsServer = async (port = DEFAULT_PORT, params?: TestE
|
|
|
61
61
|
cleanup: () => server.close(),
|
|
62
62
|
currentConnection: () => connection,
|
|
63
63
|
sendResponseMessage,
|
|
64
|
+
sendMessage: (msg: Message) => {
|
|
65
|
+
connection!.send(buf.toBinary(MessageSchema, msg));
|
|
66
|
+
},
|
|
64
67
|
closeConnection: () => {
|
|
65
68
|
closeTrigger.reset();
|
|
66
69
|
connection!.close(1011);
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
export const getEdgeUrlWithProtocol = (baseUrl: string, protocol: 'http' | 'ws') => {
|
|
6
|
+
const isSecure = baseUrl.startsWith('https') || baseUrl.startsWith('wss');
|
|
7
|
+
const url = new URL(baseUrl);
|
|
8
|
+
url.protocol = protocol + (isSecure ? 's' : '');
|
|
9
|
+
return url.toString();
|
|
10
|
+
};
|