@kumiai/hub-tunnel 0.1.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.
- package/README.md +3 -0
- package/lib/encrypted-transport.d.ts +8 -0
- package/lib/encrypted-transport.js +147 -0
- package/lib/encryptor.d.ts +4 -0
- package/lib/encryptor.js +1 -0
- package/lib/envelope.d.ts +26 -0
- package/lib/envelope.js +58 -0
- package/lib/errors.d.ts +21 -0
- package/lib/errors.js +21 -0
- package/lib/events.d.ts +13 -0
- package/lib/events.js +1 -0
- package/lib/frame.d.ts +107 -0
- package/lib/frame.js +141 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.js +6 -0
- package/lib/transport.d.ts +81 -0
- package/lib/transport.js +281 -0
- package/package.json +50 -0
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TransportType } from '@enkaku/transport';
|
|
2
|
+
import type { Encryptor } from './encryptor.js';
|
|
3
|
+
import { type HubTunnelTransportParams } from './transport.js';
|
|
4
|
+
export type EncryptedHubTunnelTransportParams = HubTunnelTransportParams & {
|
|
5
|
+
encryptor: Encryptor;
|
|
6
|
+
groupID: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function createEncryptedHubTunnelTransport<R, W>(params: EncryptedHubTunnelTransportParams): TransportType<R, W>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { fromB64, toB64 } from '@sozai/codec';
|
|
2
|
+
import { decodeEnvelope, encodeEnvelope } from './envelope.js';
|
|
3
|
+
import { DecryptError, EncryptError, EnvelopeDecodeError } from './errors.js';
|
|
4
|
+
import { createHubTunnelTransport } from './transport.js';
|
|
5
|
+
function wrapHub({ hub, encryptor, groupID, onEvent, onEncryptError }) {
|
|
6
|
+
const wrapped = {
|
|
7
|
+
async publish (params) {
|
|
8
|
+
let ciphertextBytes;
|
|
9
|
+
try {
|
|
10
|
+
ciphertextBytes = await encryptor.encrypt(params.payload);
|
|
11
|
+
} catch (cause) {
|
|
12
|
+
const err = new EncryptError('encrypt failed', {
|
|
13
|
+
cause
|
|
14
|
+
});
|
|
15
|
+
onEncryptError(err);
|
|
16
|
+
throw err;
|
|
17
|
+
}
|
|
18
|
+
const envelope = {
|
|
19
|
+
v: 1,
|
|
20
|
+
groupID,
|
|
21
|
+
ciphertext: toB64(ciphertextBytes)
|
|
22
|
+
};
|
|
23
|
+
return await hub.publish({
|
|
24
|
+
senderDID: params.senderDID,
|
|
25
|
+
topicID: params.topicID,
|
|
26
|
+
payload: encodeEnvelope(envelope)
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
subscribe (subscriberDID, topicID) {
|
|
30
|
+
return hub.subscribe(subscriberDID, topicID);
|
|
31
|
+
},
|
|
32
|
+
unsubscribe (subscriberDID, topicID) {
|
|
33
|
+
return hub.unsubscribe?.(subscriberDID, topicID);
|
|
34
|
+
},
|
|
35
|
+
receive (subscriberDID) {
|
|
36
|
+
const inner = hub.receive(subscriberDID);
|
|
37
|
+
const innerIterator = inner[Symbol.asyncIterator]();
|
|
38
|
+
const iterator = {
|
|
39
|
+
async next () {
|
|
40
|
+
while(true){
|
|
41
|
+
const result = await innerIterator.next();
|
|
42
|
+
if (result.done) {
|
|
43
|
+
return {
|
|
44
|
+
value: undefined,
|
|
45
|
+
done: true
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const message = result.value;
|
|
49
|
+
let envelope;
|
|
50
|
+
try {
|
|
51
|
+
envelope = decodeEnvelope(message.payload);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error instanceof EnvelopeDecodeError) {
|
|
54
|
+
onEvent?.({
|
|
55
|
+
type: 'envelope-decode-failed',
|
|
56
|
+
error
|
|
57
|
+
});
|
|
58
|
+
onEvent?.({
|
|
59
|
+
type: 'frame-dropped',
|
|
60
|
+
reason: 'envelope-decode'
|
|
61
|
+
});
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
let plaintext;
|
|
67
|
+
try {
|
|
68
|
+
plaintext = await encryptor.decrypt(fromB64(envelope.ciphertext));
|
|
69
|
+
} catch (cause) {
|
|
70
|
+
const err = new DecryptError('decrypt failed', {
|
|
71
|
+
cause
|
|
72
|
+
});
|
|
73
|
+
onEvent?.({
|
|
74
|
+
type: 'decrypt-failed',
|
|
75
|
+
error: err
|
|
76
|
+
});
|
|
77
|
+
onEvent?.({
|
|
78
|
+
type: 'frame-dropped',
|
|
79
|
+
reason: 'decrypt'
|
|
80
|
+
});
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
const decrypted = {
|
|
84
|
+
sequenceID: message.sequenceID,
|
|
85
|
+
senderDID: message.senderDID,
|
|
86
|
+
topicID: message.topicID,
|
|
87
|
+
payload: plaintext
|
|
88
|
+
};
|
|
89
|
+
return {
|
|
90
|
+
value: decrypted,
|
|
91
|
+
done: false
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
return () {
|
|
96
|
+
innerIterator.return?.();
|
|
97
|
+
return Promise.resolve({
|
|
98
|
+
value: undefined,
|
|
99
|
+
done: true
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
[Symbol.asyncIterator] () {
|
|
105
|
+
return iterator;
|
|
106
|
+
},
|
|
107
|
+
return () {
|
|
108
|
+
inner.return?.();
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
if (hub.events != null) {
|
|
114
|
+
wrapped.events = hub.events;
|
|
115
|
+
}
|
|
116
|
+
return wrapped;
|
|
117
|
+
}
|
|
118
|
+
export function createEncryptedHubTunnelTransport(params) {
|
|
119
|
+
const { hub, encryptor, groupID, onEvent, signal: externalSignal, ...rest } = params;
|
|
120
|
+
const internalController = new AbortController();
|
|
121
|
+
if (externalSignal != null) {
|
|
122
|
+
if (externalSignal.aborted) {
|
|
123
|
+
internalController.abort(externalSignal.reason);
|
|
124
|
+
} else {
|
|
125
|
+
externalSignal.addEventListener('abort', ()=>{
|
|
126
|
+
internalController.abort(externalSignal.reason);
|
|
127
|
+
}, {
|
|
128
|
+
once: true
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
const wrappedHub = wrapHub({
|
|
133
|
+
hub,
|
|
134
|
+
encryptor,
|
|
135
|
+
groupID,
|
|
136
|
+
onEvent,
|
|
137
|
+
onEncryptError: (err)=>{
|
|
138
|
+
internalController.abort(err);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
return createHubTunnelTransport({
|
|
142
|
+
...rest,
|
|
143
|
+
hub: wrappedHub,
|
|
144
|
+
signal: internalController.signal,
|
|
145
|
+
onEvent
|
|
146
|
+
});
|
|
147
|
+
}
|
package/lib/encryptor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const TUNNEL_ENVELOPE_VERSION = 1;
|
|
2
|
+
export type TunnelEnvelope = {
|
|
3
|
+
v: 1;
|
|
4
|
+
groupID: string;
|
|
5
|
+
ciphertext: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const tunnelEnvelopeSchema: {
|
|
8
|
+
readonly $id: "urn:enkaku:hub-tunnel:envelope";
|
|
9
|
+
readonly type: "object";
|
|
10
|
+
readonly properties: {
|
|
11
|
+
readonly v: {
|
|
12
|
+
readonly type: "integer";
|
|
13
|
+
readonly const: 1;
|
|
14
|
+
};
|
|
15
|
+
readonly groupID: {
|
|
16
|
+
readonly type: "string";
|
|
17
|
+
};
|
|
18
|
+
readonly ciphertext: {
|
|
19
|
+
readonly type: "string";
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
readonly required: readonly ["v", "groupID", "ciphertext"];
|
|
23
|
+
readonly additionalProperties: false;
|
|
24
|
+
};
|
|
25
|
+
export declare function encodeEnvelope(envelope: TunnelEnvelope): Uint8Array;
|
|
26
|
+
export declare function decodeEnvelope(bytes: Uint8Array): TunnelEnvelope;
|
package/lib/envelope.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createValidator } from '@sozai/schema';
|
|
2
|
+
import { EnvelopeDecodeError } from './errors.js';
|
|
3
|
+
export const TUNNEL_ENVELOPE_VERSION = 1;
|
|
4
|
+
export const tunnelEnvelopeSchema = {
|
|
5
|
+
$id: 'urn:enkaku:hub-tunnel:envelope',
|
|
6
|
+
type: 'object',
|
|
7
|
+
properties: {
|
|
8
|
+
v: {
|
|
9
|
+
type: 'integer',
|
|
10
|
+
const: TUNNEL_ENVELOPE_VERSION
|
|
11
|
+
},
|
|
12
|
+
groupID: {
|
|
13
|
+
type: 'string'
|
|
14
|
+
},
|
|
15
|
+
ciphertext: {
|
|
16
|
+
type: 'string'
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
required: [
|
|
20
|
+
'v',
|
|
21
|
+
'groupID',
|
|
22
|
+
'ciphertext'
|
|
23
|
+
],
|
|
24
|
+
additionalProperties: false
|
|
25
|
+
};
|
|
26
|
+
const validateTunnelEnvelope = createValidator(tunnelEnvelopeSchema);
|
|
27
|
+
const textEncoder = new TextEncoder();
|
|
28
|
+
const textDecoder = new TextDecoder('utf-8', {
|
|
29
|
+
fatal: true
|
|
30
|
+
});
|
|
31
|
+
export function encodeEnvelope(envelope) {
|
|
32
|
+
return textEncoder.encode(JSON.stringify(envelope));
|
|
33
|
+
}
|
|
34
|
+
export function decodeEnvelope(bytes) {
|
|
35
|
+
let text;
|
|
36
|
+
try {
|
|
37
|
+
text = textDecoder.decode(bytes);
|
|
38
|
+
} catch (cause) {
|
|
39
|
+
throw new EnvelopeDecodeError('Envelope bytes are not valid UTF-8', {
|
|
40
|
+
cause
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
let parsed;
|
|
44
|
+
try {
|
|
45
|
+
parsed = JSON.parse(text);
|
|
46
|
+
} catch (cause) {
|
|
47
|
+
throw new EnvelopeDecodeError('Envelope is not valid JSON', {
|
|
48
|
+
cause
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
const result = validateTunnelEnvelope(parsed);
|
|
52
|
+
if ('issues' in result) {
|
|
53
|
+
throw new EnvelopeDecodeError('Envelope failed schema validation', {
|
|
54
|
+
cause: result
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return result.value;
|
|
58
|
+
}
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class FrameDecodeError extends Error {
|
|
2
|
+
name: string;
|
|
3
|
+
}
|
|
4
|
+
export declare class EnvelopeDecodeError extends Error {
|
|
5
|
+
name: string;
|
|
6
|
+
}
|
|
7
|
+
export declare class DecryptError extends Error {
|
|
8
|
+
name: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class EncryptError extends Error {
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class BackpressureError extends Error {
|
|
14
|
+
name: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class HubReconnectingError extends Error {
|
|
17
|
+
name: string;
|
|
18
|
+
}
|
|
19
|
+
export declare class SessionNotEstablishedError extends Error {
|
|
20
|
+
name: string;
|
|
21
|
+
}
|
package/lib/errors.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export class FrameDecodeError extends Error {
|
|
2
|
+
name = 'FrameDecodeError';
|
|
3
|
+
}
|
|
4
|
+
export class EnvelopeDecodeError extends Error {
|
|
5
|
+
name = 'EnvelopeDecodeError';
|
|
6
|
+
}
|
|
7
|
+
export class DecryptError extends Error {
|
|
8
|
+
name = 'DecryptError';
|
|
9
|
+
}
|
|
10
|
+
export class EncryptError extends Error {
|
|
11
|
+
name = 'EncryptError';
|
|
12
|
+
}
|
|
13
|
+
export class BackpressureError extends Error {
|
|
14
|
+
name = 'BackpressureError';
|
|
15
|
+
}
|
|
16
|
+
export class HubReconnectingError extends Error {
|
|
17
|
+
name = 'HubReconnectingError';
|
|
18
|
+
}
|
|
19
|
+
export class SessionNotEstablishedError extends Error {
|
|
20
|
+
name = 'SessionNotEstablishedError';
|
|
21
|
+
}
|
package/lib/events.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { DecryptError, EnvelopeDecodeError } from './errors.js';
|
|
2
|
+
export type FrameDroppedReason = 'envelope-decode' | 'decrypt' | 'topic-mismatch' | 'session-mismatch' | 'dedup';
|
|
3
|
+
export type ObservabilityEvent = {
|
|
4
|
+
type: 'decrypt-failed';
|
|
5
|
+
error: DecryptError;
|
|
6
|
+
} | {
|
|
7
|
+
type: 'envelope-decode-failed';
|
|
8
|
+
error: EnvelopeDecodeError;
|
|
9
|
+
} | {
|
|
10
|
+
type: 'frame-dropped';
|
|
11
|
+
reason: FrameDroppedReason;
|
|
12
|
+
};
|
|
13
|
+
export type ObservabilityEventListener = (event: ObservabilityEvent) => void;
|
package/lib/events.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/lib/frame.d.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export declare const HUB_FRAME_VERSION = 1;
|
|
2
|
+
export declare const hubFrameSchema: {
|
|
3
|
+
readonly $id: "urn:enkaku:hub-tunnel:frame";
|
|
4
|
+
readonly oneOf: readonly [{
|
|
5
|
+
readonly type: "object";
|
|
6
|
+
readonly properties: {
|
|
7
|
+
readonly v: {
|
|
8
|
+
readonly type: "integer";
|
|
9
|
+
readonly const: 1;
|
|
10
|
+
};
|
|
11
|
+
readonly sessionID: {
|
|
12
|
+
readonly type: "string";
|
|
13
|
+
};
|
|
14
|
+
readonly seq: {
|
|
15
|
+
readonly type: "integer";
|
|
16
|
+
};
|
|
17
|
+
readonly correlationID: {
|
|
18
|
+
readonly type: "string";
|
|
19
|
+
};
|
|
20
|
+
readonly kind: {
|
|
21
|
+
readonly type: "string";
|
|
22
|
+
readonly const: "message";
|
|
23
|
+
};
|
|
24
|
+
readonly body: {
|
|
25
|
+
readonly type: "object";
|
|
26
|
+
readonly properties: {
|
|
27
|
+
readonly header: {
|
|
28
|
+
readonly type: "object";
|
|
29
|
+
readonly additionalProperties: true;
|
|
30
|
+
};
|
|
31
|
+
readonly payload: {
|
|
32
|
+
readonly type: "object";
|
|
33
|
+
readonly properties: {
|
|
34
|
+
readonly typ: {
|
|
35
|
+
readonly type: "string";
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
readonly required: readonly ["typ"];
|
|
39
|
+
readonly additionalProperties: true;
|
|
40
|
+
};
|
|
41
|
+
readonly signature: {
|
|
42
|
+
readonly type: "string";
|
|
43
|
+
};
|
|
44
|
+
readonly data: {
|
|
45
|
+
readonly type: "string";
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
readonly required: readonly ["header", "payload"];
|
|
49
|
+
readonly additionalProperties: false;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
readonly required: readonly ["v", "sessionID", "seq", "kind", "body"];
|
|
53
|
+
readonly additionalProperties: false;
|
|
54
|
+
}, {
|
|
55
|
+
readonly type: "object";
|
|
56
|
+
readonly properties: {
|
|
57
|
+
readonly v: {
|
|
58
|
+
readonly type: "integer";
|
|
59
|
+
readonly const: 1;
|
|
60
|
+
};
|
|
61
|
+
readonly sessionID: {
|
|
62
|
+
readonly type: "string";
|
|
63
|
+
};
|
|
64
|
+
readonly seq: {
|
|
65
|
+
readonly type: "integer";
|
|
66
|
+
};
|
|
67
|
+
readonly correlationID: {
|
|
68
|
+
readonly type: "string";
|
|
69
|
+
};
|
|
70
|
+
readonly kind: {
|
|
71
|
+
readonly type: "string";
|
|
72
|
+
readonly const: "session-end";
|
|
73
|
+
};
|
|
74
|
+
readonly reason: {
|
|
75
|
+
readonly type: "string";
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
readonly required: readonly ["v", "sessionID", "seq", "kind"];
|
|
79
|
+
readonly additionalProperties: false;
|
|
80
|
+
}];
|
|
81
|
+
};
|
|
82
|
+
export type HubFrameMessageBody = {
|
|
83
|
+
header: Record<string, unknown>;
|
|
84
|
+
payload: {
|
|
85
|
+
typ: string;
|
|
86
|
+
[key: string]: unknown;
|
|
87
|
+
};
|
|
88
|
+
signature?: string;
|
|
89
|
+
data?: string;
|
|
90
|
+
};
|
|
91
|
+
export type HubFrame = {
|
|
92
|
+
v: 1;
|
|
93
|
+
sessionID: string;
|
|
94
|
+
seq: number;
|
|
95
|
+
correlationID?: string;
|
|
96
|
+
kind: 'message';
|
|
97
|
+
body: HubFrameMessageBody;
|
|
98
|
+
} | {
|
|
99
|
+
v: 1;
|
|
100
|
+
sessionID: string;
|
|
101
|
+
seq: number;
|
|
102
|
+
correlationID?: string;
|
|
103
|
+
kind: 'session-end';
|
|
104
|
+
reason?: string;
|
|
105
|
+
};
|
|
106
|
+
export declare function encodeFrame(frame: HubFrame): Uint8Array;
|
|
107
|
+
export declare function decodeFrame(bytes: Uint8Array): HubFrame;
|
package/lib/frame.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { createValidator } from '@sozai/schema';
|
|
2
|
+
import { FrameDecodeError } from './errors.js';
|
|
3
|
+
export const HUB_FRAME_VERSION = 1;
|
|
4
|
+
// Permissive envelope schema: validates {header: object, payload: {typ: string}}
|
|
5
|
+
// without enforcing JWT-specific header constraints (e.g. typ:'JWT').
|
|
6
|
+
// Payload-shape validation is left to the consumer's own protocol schema.
|
|
7
|
+
const enkakuMessageSchema = {
|
|
8
|
+
type: 'object',
|
|
9
|
+
properties: {
|
|
10
|
+
header: {
|
|
11
|
+
type: 'object',
|
|
12
|
+
additionalProperties: true
|
|
13
|
+
},
|
|
14
|
+
payload: {
|
|
15
|
+
type: 'object',
|
|
16
|
+
properties: {
|
|
17
|
+
typ: {
|
|
18
|
+
type: 'string'
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
required: [
|
|
22
|
+
'typ'
|
|
23
|
+
],
|
|
24
|
+
additionalProperties: true
|
|
25
|
+
},
|
|
26
|
+
signature: {
|
|
27
|
+
type: 'string'
|
|
28
|
+
},
|
|
29
|
+
data: {
|
|
30
|
+
type: 'string'
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
required: [
|
|
34
|
+
'header',
|
|
35
|
+
'payload'
|
|
36
|
+
],
|
|
37
|
+
additionalProperties: false
|
|
38
|
+
};
|
|
39
|
+
const messageFrameSchema = {
|
|
40
|
+
type: 'object',
|
|
41
|
+
properties: {
|
|
42
|
+
v: {
|
|
43
|
+
type: 'integer',
|
|
44
|
+
const: HUB_FRAME_VERSION
|
|
45
|
+
},
|
|
46
|
+
sessionID: {
|
|
47
|
+
type: 'string'
|
|
48
|
+
},
|
|
49
|
+
seq: {
|
|
50
|
+
type: 'integer'
|
|
51
|
+
},
|
|
52
|
+
correlationID: {
|
|
53
|
+
type: 'string'
|
|
54
|
+
},
|
|
55
|
+
kind: {
|
|
56
|
+
type: 'string',
|
|
57
|
+
const: 'message'
|
|
58
|
+
},
|
|
59
|
+
body: enkakuMessageSchema
|
|
60
|
+
},
|
|
61
|
+
required: [
|
|
62
|
+
'v',
|
|
63
|
+
'sessionID',
|
|
64
|
+
'seq',
|
|
65
|
+
'kind',
|
|
66
|
+
'body'
|
|
67
|
+
],
|
|
68
|
+
additionalProperties: false
|
|
69
|
+
};
|
|
70
|
+
const sessionEndFrameSchema = {
|
|
71
|
+
type: 'object',
|
|
72
|
+
properties: {
|
|
73
|
+
v: {
|
|
74
|
+
type: 'integer',
|
|
75
|
+
const: HUB_FRAME_VERSION
|
|
76
|
+
},
|
|
77
|
+
sessionID: {
|
|
78
|
+
type: 'string'
|
|
79
|
+
},
|
|
80
|
+
seq: {
|
|
81
|
+
type: 'integer'
|
|
82
|
+
},
|
|
83
|
+
correlationID: {
|
|
84
|
+
type: 'string'
|
|
85
|
+
},
|
|
86
|
+
kind: {
|
|
87
|
+
type: 'string',
|
|
88
|
+
const: 'session-end'
|
|
89
|
+
},
|
|
90
|
+
reason: {
|
|
91
|
+
type: 'string'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
required: [
|
|
95
|
+
'v',
|
|
96
|
+
'sessionID',
|
|
97
|
+
'seq',
|
|
98
|
+
'kind'
|
|
99
|
+
],
|
|
100
|
+
additionalProperties: false
|
|
101
|
+
};
|
|
102
|
+
export const hubFrameSchema = {
|
|
103
|
+
$id: 'urn:enkaku:hub-tunnel:frame',
|
|
104
|
+
oneOf: [
|
|
105
|
+
messageFrameSchema,
|
|
106
|
+
sessionEndFrameSchema
|
|
107
|
+
]
|
|
108
|
+
};
|
|
109
|
+
const validateHubFrame = createValidator(hubFrameSchema);
|
|
110
|
+
const textEncoder = new TextEncoder();
|
|
111
|
+
const textDecoder = new TextDecoder('utf-8', {
|
|
112
|
+
fatal: true
|
|
113
|
+
});
|
|
114
|
+
export function encodeFrame(frame) {
|
|
115
|
+
return textEncoder.encode(JSON.stringify(frame));
|
|
116
|
+
}
|
|
117
|
+
export function decodeFrame(bytes) {
|
|
118
|
+
let text;
|
|
119
|
+
try {
|
|
120
|
+
text = textDecoder.decode(bytes);
|
|
121
|
+
} catch (cause) {
|
|
122
|
+
throw new FrameDecodeError('Frame bytes are not valid UTF-8', {
|
|
123
|
+
cause
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
let parsed;
|
|
127
|
+
try {
|
|
128
|
+
parsed = JSON.parse(text);
|
|
129
|
+
} catch (cause) {
|
|
130
|
+
throw new FrameDecodeError('Frame is not valid JSON', {
|
|
131
|
+
cause
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const result = validateHubFrame(parsed);
|
|
135
|
+
if ('issues' in result) {
|
|
136
|
+
throw new FrameDecodeError('Frame failed schema validation', {
|
|
137
|
+
cause: result
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
return result.value;
|
|
141
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createEncryptedHubTunnelTransport, type EncryptedHubTunnelTransportParams, } from './encrypted-transport.js';
|
|
2
|
+
export type { Encryptor } from './encryptor.js';
|
|
3
|
+
export { decodeEnvelope, encodeEnvelope, TUNNEL_ENVELOPE_VERSION, type TunnelEnvelope, tunnelEnvelopeSchema, } from './envelope.js';
|
|
4
|
+
export { BackpressureError, DecryptError, EncryptError, EnvelopeDecodeError, FrameDecodeError, HubReconnectingError, SessionNotEstablishedError, } from './errors.js';
|
|
5
|
+
export type { FrameDroppedReason, ObservabilityEvent, ObservabilityEventListener, } from './events.js';
|
|
6
|
+
export { decodeFrame, encodeFrame, HUB_FRAME_VERSION, type HubFrame, type HubFrameMessageBody, hubFrameSchema, } from './frame.js';
|
|
7
|
+
export { createHubTunnelTransport, type HubLike, type HubLikeEvent, type HubLikeEventListener, type HubLikeEvents, type HubPublishParams, type HubReceiveSubscription, type HubTunnelSessionID, type HubTunnelTransportParams, } from './transport.js';
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// @kumiai/hub-tunnel — peer-to-peer Enkaku transport over the hub relay
|
|
2
|
+
export { createEncryptedHubTunnelTransport } from './encrypted-transport.js';
|
|
3
|
+
export { decodeEnvelope, encodeEnvelope, TUNNEL_ENVELOPE_VERSION, tunnelEnvelopeSchema } from './envelope.js';
|
|
4
|
+
export { BackpressureError, DecryptError, EncryptError, EnvelopeDecodeError, FrameDecodeError, HubReconnectingError, SessionNotEstablishedError } from './errors.js';
|
|
5
|
+
export { decodeFrame, encodeFrame, HUB_FRAME_VERSION, hubFrameSchema } from './frame.js';
|
|
6
|
+
export { createHubTunnelTransport } from './transport.js';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type TransportType } from '@enkaku/transport';
|
|
2
|
+
import type { StoredMessage } from '@kumiai/hub-protocol';
|
|
3
|
+
import type { ObservabilityEventListener } from './events.js';
|
|
4
|
+
export type HubReceiveSubscription = AsyncIterable<StoredMessage> & {
|
|
5
|
+
return?: () => void;
|
|
6
|
+
/**
|
|
7
|
+
* Acknowledge a delivered message as durably handled, so the hub stops
|
|
8
|
+
* redelivering it on reconnect. Optional: a live/in-memory transport that
|
|
9
|
+
* never redelivers can omit it. A durable transport coalesces acks (batching)
|
|
10
|
+
* below this contract.
|
|
11
|
+
*/
|
|
12
|
+
ack?: (sequenceID: string) => void | Promise<void>;
|
|
13
|
+
};
|
|
14
|
+
export type HubLikeEvent = {
|
|
15
|
+
type: 'reconnecting';
|
|
16
|
+
} | {
|
|
17
|
+
type: 'connected';
|
|
18
|
+
} | {
|
|
19
|
+
type: 'disconnected';
|
|
20
|
+
};
|
|
21
|
+
export type HubLikeEventListener = (event: HubLikeEvent) => void;
|
|
22
|
+
export type HubLikeEvents = {
|
|
23
|
+
subscribe: (listener: HubLikeEventListener) => () => void;
|
|
24
|
+
};
|
|
25
|
+
export type HubPublishParams = {
|
|
26
|
+
senderDID: string;
|
|
27
|
+
topicID: string;
|
|
28
|
+
payload: Uint8Array;
|
|
29
|
+
};
|
|
30
|
+
export type HubLike = {
|
|
31
|
+
publish: (params: HubPublishParams) => Promise<{
|
|
32
|
+
sequenceID: string;
|
|
33
|
+
}>;
|
|
34
|
+
subscribe: (subscriberDID: string, topicID: string) => Promise<void> | void;
|
|
35
|
+
unsubscribe?: (subscriberDID: string, topicID: string) => Promise<void> | void;
|
|
36
|
+
receive: (subscriberDID: string) => HubReceiveSubscription;
|
|
37
|
+
events?: HubLikeEvents;
|
|
38
|
+
};
|
|
39
|
+
export type HubTunnelSessionID = string | {
|
|
40
|
+
auto: true;
|
|
41
|
+
};
|
|
42
|
+
export type HubTunnelTransportParams = {
|
|
43
|
+
hub: HubLike;
|
|
44
|
+
sessionID: HubTunnelSessionID;
|
|
45
|
+
/**
|
|
46
|
+
* The authenticated DID used to drain the receive stream (`hub.receive`) and
|
|
47
|
+
* stamp published frames (`senderDID`). NOT a routing key — routing is by
|
|
48
|
+
* `sendTopicID` / `receiveTopicID`.
|
|
49
|
+
*/
|
|
50
|
+
localDID: string;
|
|
51
|
+
/** Topic this transport publishes its outbound frames to. */
|
|
52
|
+
sendTopicID: string;
|
|
53
|
+
/** Topic this transport subscribes to and accepts inbound frames from. */
|
|
54
|
+
receiveTopicID: string;
|
|
55
|
+
inboxCapacity?: number;
|
|
56
|
+
idleTimeoutMs?: number;
|
|
57
|
+
reconnectTimeoutMs?: number;
|
|
58
|
+
signal?: AbortSignal;
|
|
59
|
+
onEvent?: ObservabilityEventListener;
|
|
60
|
+
/**
|
|
61
|
+
* Fired exactly once when the peer signals graceful end-of-session via the
|
|
62
|
+
* `session-end` frame kind. Non-error path — `teardown(error)` paths emit
|
|
63
|
+
* through `onEvent` instead.
|
|
64
|
+
*/
|
|
65
|
+
onSessionEnd?: () => void;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Build a hub-tunnel transport over the pub/sub hub API. The returned
|
|
69
|
+
* `TransportType` subscribes to `receiveTopicID`, reads from a single inbox
|
|
70
|
+
* subscription (filtering to that topic), and writes to the hub via
|
|
71
|
+
* `hub.publish` on `sendTopicID`.
|
|
72
|
+
*
|
|
73
|
+
* **Contract notes (relied on by callers):**
|
|
74
|
+
* - `hub.subscribe(localDID, receiveTopicID)` and `hub.receive(localDID)` are
|
|
75
|
+
* each called **exactly once** during construction.
|
|
76
|
+
* - On any teardown path (signal abort, idle timeout, encrypt failure,
|
|
77
|
+
* peer-side `session-end`, manual `transport.dispose()`), this transport
|
|
78
|
+
* publishes a best-effort `session-end` frame to `sendTopicID` and
|
|
79
|
+
* best-effort `hub.unsubscribe?.(localDID, receiveTopicID)`.
|
|
80
|
+
*/
|
|
81
|
+
export declare function createHubTunnelTransport<R, W>(params: HubTunnelTransportParams): TransportType<R, W>;
|
package/lib/transport.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { Transport } from '@enkaku/transport';
|
|
2
|
+
import { AbortInterruption, TimeoutInterruption } from '@sozai/async';
|
|
3
|
+
import { BackpressureError, FrameDecodeError, HubReconnectingError, SessionNotEstablishedError } from './errors.js';
|
|
4
|
+
import { decodeFrame, encodeFrame } from './frame.js';
|
|
5
|
+
const DEFAULT_INBOX_CAPACITY = 1024;
|
|
6
|
+
/**
|
|
7
|
+
* Build a hub-tunnel transport over the pub/sub hub API. The returned
|
|
8
|
+
* `TransportType` subscribes to `receiveTopicID`, reads from a single inbox
|
|
9
|
+
* subscription (filtering to that topic), and writes to the hub via
|
|
10
|
+
* `hub.publish` on `sendTopicID`.
|
|
11
|
+
*
|
|
12
|
+
* **Contract notes (relied on by callers):**
|
|
13
|
+
* - `hub.subscribe(localDID, receiveTopicID)` and `hub.receive(localDID)` are
|
|
14
|
+
* each called **exactly once** during construction.
|
|
15
|
+
* - On any teardown path (signal abort, idle timeout, encrypt failure,
|
|
16
|
+
* peer-side `session-end`, manual `transport.dispose()`), this transport
|
|
17
|
+
* publishes a best-effort `session-end` frame to `sendTopicID` and
|
|
18
|
+
* best-effort `hub.unsubscribe?.(localDID, receiveTopicID)`.
|
|
19
|
+
*/ export function createHubTunnelTransport(params) {
|
|
20
|
+
const { hub, sessionID, localDID, sendTopicID, receiveTopicID, signal, idleTimeoutMs, reconnectTimeoutMs, onEvent, onSessionEnd } = params;
|
|
21
|
+
const inboxCapacity = params.inboxCapacity ?? DEFAULT_INBOX_CAPACITY;
|
|
22
|
+
let lockedSessionID = typeof sessionID === 'string' ? sessionID : null;
|
|
23
|
+
let outboundSeq = 0;
|
|
24
|
+
let expectedSeq = 0;
|
|
25
|
+
// Best-effort subscribe; rejection is swallowed (the receive stream still
|
|
26
|
+
// attaches, and a missing subscription simply yields no inbound frames).
|
|
27
|
+
void Promise.resolve(hub.subscribe(localDID, receiveTopicID)).catch(()=>{});
|
|
28
|
+
const subscription = hub.receive(localDID);
|
|
29
|
+
const iterator = subscription[Symbol.asyncIterator]();
|
|
30
|
+
let abortHandler;
|
|
31
|
+
let torndown = false;
|
|
32
|
+
let readableController;
|
|
33
|
+
let lastActivity = Date.now();
|
|
34
|
+
let idleTimer;
|
|
35
|
+
let reconnectTimer;
|
|
36
|
+
let unsubscribeEvents;
|
|
37
|
+
const clearIdleTimer = ()=>{
|
|
38
|
+
if (idleTimer != null) {
|
|
39
|
+
clearTimeout(idleTimer);
|
|
40
|
+
idleTimer = undefined;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const clearReconnectTimer = ()=>{
|
|
44
|
+
if (reconnectTimer != null) {
|
|
45
|
+
clearTimeout(reconnectTimer);
|
|
46
|
+
reconnectTimer = undefined;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const sendSessionEnd = ()=>{
|
|
50
|
+
if (lockedSessionID == null) return;
|
|
51
|
+
const frame = {
|
|
52
|
+
v: 1,
|
|
53
|
+
sessionID: lockedSessionID,
|
|
54
|
+
kind: 'session-end',
|
|
55
|
+
seq: outboundSeq
|
|
56
|
+
};
|
|
57
|
+
void hub.publish({
|
|
58
|
+
senderDID: localDID,
|
|
59
|
+
topicID: sendTopicID,
|
|
60
|
+
payload: encodeFrame(frame)
|
|
61
|
+
}).catch(()=>{
|
|
62
|
+
// ignore
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
const teardown = (error)=>{
|
|
66
|
+
if (torndown) return;
|
|
67
|
+
torndown = true;
|
|
68
|
+
clearIdleTimer();
|
|
69
|
+
clearReconnectTimer();
|
|
70
|
+
if (unsubscribeEvents != null) {
|
|
71
|
+
unsubscribeEvents();
|
|
72
|
+
unsubscribeEvents = undefined;
|
|
73
|
+
}
|
|
74
|
+
if (abortHandler != null && signal != null) {
|
|
75
|
+
signal.removeEventListener('abort', abortHandler);
|
|
76
|
+
abortHandler = undefined;
|
|
77
|
+
}
|
|
78
|
+
sendSessionEnd();
|
|
79
|
+
try {
|
|
80
|
+
void Promise.resolve(hub.unsubscribe?.(localDID, receiveTopicID)).catch(()=>{});
|
|
81
|
+
} catch {
|
|
82
|
+
// ignore
|
|
83
|
+
}
|
|
84
|
+
if (error !== undefined && readableController != null) {
|
|
85
|
+
try {
|
|
86
|
+
readableController.error(error);
|
|
87
|
+
} catch {
|
|
88
|
+
// controller may already be closed
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
iterator.return?.();
|
|
92
|
+
};
|
|
93
|
+
const scheduleIdleTimer = ()=>{
|
|
94
|
+
if (idleTimeoutMs == null || torndown) return;
|
|
95
|
+
clearIdleTimer();
|
|
96
|
+
const elapsed = Date.now() - lastActivity;
|
|
97
|
+
const remaining = idleTimeoutMs - elapsed;
|
|
98
|
+
const delay = remaining > 0 ? remaining : 0;
|
|
99
|
+
idleTimer = setTimeout(()=>{
|
|
100
|
+
idleTimer = undefined;
|
|
101
|
+
if (torndown) return;
|
|
102
|
+
const sinceActivity = Date.now() - lastActivity;
|
|
103
|
+
if (sinceActivity >= idleTimeoutMs) {
|
|
104
|
+
teardown(new TimeoutInterruption({
|
|
105
|
+
message: 'idle timeout'
|
|
106
|
+
}));
|
|
107
|
+
} else {
|
|
108
|
+
scheduleIdleTimer();
|
|
109
|
+
}
|
|
110
|
+
}, delay);
|
|
111
|
+
};
|
|
112
|
+
const markActivity = ()=>{
|
|
113
|
+
lastActivity = Date.now();
|
|
114
|
+
};
|
|
115
|
+
const readable = new ReadableStream({
|
|
116
|
+
start (controller) {
|
|
117
|
+
readableController = controller;
|
|
118
|
+
if (signal?.aborted === true) {
|
|
119
|
+
teardown(new AbortInterruption({
|
|
120
|
+
cause: signal.reason
|
|
121
|
+
}));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
scheduleIdleTimer();
|
|
125
|
+
void (async ()=>{
|
|
126
|
+
while(true){
|
|
127
|
+
let result;
|
|
128
|
+
try {
|
|
129
|
+
result = await iterator.next();
|
|
130
|
+
} catch (error) {
|
|
131
|
+
if (!torndown) {
|
|
132
|
+
torndown = true;
|
|
133
|
+
clearIdleTimer();
|
|
134
|
+
controller.error(error);
|
|
135
|
+
}
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
if (torndown) return;
|
|
139
|
+
if (result.done) {
|
|
140
|
+
torndown = true;
|
|
141
|
+
clearIdleTimer();
|
|
142
|
+
controller.close();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const message = result.value;
|
|
146
|
+
if (message.topicID !== receiveTopicID) {
|
|
147
|
+
onEvent?.({
|
|
148
|
+
type: 'frame-dropped',
|
|
149
|
+
reason: 'topic-mismatch'
|
|
150
|
+
});
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
153
|
+
let frame;
|
|
154
|
+
try {
|
|
155
|
+
frame = decodeFrame(message.payload);
|
|
156
|
+
} catch (error) {
|
|
157
|
+
if (error instanceof FrameDecodeError) continue;
|
|
158
|
+
teardown(error);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (lockedSessionID == null) {
|
|
162
|
+
lockedSessionID = frame.sessionID;
|
|
163
|
+
} else if (frame.sessionID !== lockedSessionID) {
|
|
164
|
+
onEvent?.({
|
|
165
|
+
type: 'frame-dropped',
|
|
166
|
+
reason: 'session-mismatch'
|
|
167
|
+
});
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (frame.kind === 'session-end') {
|
|
171
|
+
torndown = true;
|
|
172
|
+
clearIdleTimer();
|
|
173
|
+
try {
|
|
174
|
+
controller.close();
|
|
175
|
+
} catch {
|
|
176
|
+
// already closed
|
|
177
|
+
}
|
|
178
|
+
iterator.return?.();
|
|
179
|
+
onSessionEnd?.();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (frame.kind !== 'message') {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (frame.seq < expectedSeq) {
|
|
186
|
+
onEvent?.({
|
|
187
|
+
type: 'frame-dropped',
|
|
188
|
+
reason: 'dedup'
|
|
189
|
+
});
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
const desired = controller.desiredSize;
|
|
193
|
+
if (desired != null && desired <= 0) {
|
|
194
|
+
const err = new BackpressureError(`Hub tunnel inbox overflow: capacity=${inboxCapacity} session=${lockedSessionID}`);
|
|
195
|
+
teardown(err);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
expectedSeq = frame.seq + 1;
|
|
199
|
+
markActivity();
|
|
200
|
+
controller.enqueue(frame.body);
|
|
201
|
+
}
|
|
202
|
+
})();
|
|
203
|
+
},
|
|
204
|
+
cancel () {
|
|
205
|
+
teardown();
|
|
206
|
+
}
|
|
207
|
+
}, new CountQueuingStrategy({
|
|
208
|
+
highWaterMark: inboxCapacity
|
|
209
|
+
}));
|
|
210
|
+
const writable = new WritableStream({
|
|
211
|
+
async write (value) {
|
|
212
|
+
if (torndown) {
|
|
213
|
+
throw new Error('Hub tunnel transport torn down');
|
|
214
|
+
}
|
|
215
|
+
if (lockedSessionID == null) {
|
|
216
|
+
throw new SessionNotEstablishedError('hub-tunnel: cannot send before session is established');
|
|
217
|
+
}
|
|
218
|
+
const frame = {
|
|
219
|
+
v: 1,
|
|
220
|
+
sessionID: lockedSessionID,
|
|
221
|
+
kind: 'message',
|
|
222
|
+
seq: outboundSeq++,
|
|
223
|
+
body: value
|
|
224
|
+
};
|
|
225
|
+
await hub.publish({
|
|
226
|
+
senderDID: localDID,
|
|
227
|
+
topicID: sendTopicID,
|
|
228
|
+
payload: encodeFrame(frame)
|
|
229
|
+
});
|
|
230
|
+
markActivity();
|
|
231
|
+
},
|
|
232
|
+
close () {
|
|
233
|
+
teardown();
|
|
234
|
+
},
|
|
235
|
+
abort () {
|
|
236
|
+
teardown();
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
const transport = new Transport({
|
|
240
|
+
stream: {
|
|
241
|
+
readable,
|
|
242
|
+
writable
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
if (signal != null && signal.aborted !== true) {
|
|
246
|
+
abortHandler = ()=>{
|
|
247
|
+
teardown(new AbortInterruption({
|
|
248
|
+
cause: signal.reason
|
|
249
|
+
}));
|
|
250
|
+
};
|
|
251
|
+
signal.addEventListener('abort', abortHandler, {
|
|
252
|
+
once: true
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
transport.events.on('disposed', ()=>{
|
|
256
|
+
teardown();
|
|
257
|
+
});
|
|
258
|
+
if (reconnectTimeoutMs != null && hub.events != null) {
|
|
259
|
+
const armReconnectTimer = ()=>{
|
|
260
|
+
if (torndown || reconnectTimer != null) return;
|
|
261
|
+
reconnectTimer = setTimeout(()=>{
|
|
262
|
+
reconnectTimer = undefined;
|
|
263
|
+
if (torndown) return;
|
|
264
|
+
teardown(new HubReconnectingError('reconnect timeout exceeded'));
|
|
265
|
+
}, reconnectTimeoutMs);
|
|
266
|
+
};
|
|
267
|
+
unsubscribeEvents = hub.events.subscribe((event)=>{
|
|
268
|
+
if (torndown) return;
|
|
269
|
+
switch(event.type){
|
|
270
|
+
case 'reconnecting':
|
|
271
|
+
case 'disconnected':
|
|
272
|
+
armReconnectTimer();
|
|
273
|
+
return;
|
|
274
|
+
case 'connected':
|
|
275
|
+
clearReconnectTimer();
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
return transport;
|
|
281
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kumiai/hub-tunnel",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "Peer-to-peer Enkaku transport tunneled through a hub relay",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"enkaku",
|
|
8
|
+
"hub",
|
|
9
|
+
"tunnel",
|
|
10
|
+
"transport",
|
|
11
|
+
"p2p"
|
|
12
|
+
],
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/TairuFramework/kumiai",
|
|
16
|
+
"directory": "packages/hub-tunnel"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"main": "lib/index.js",
|
|
20
|
+
"types": "lib/index.d.ts",
|
|
21
|
+
"exports": {
|
|
22
|
+
".": "./lib/index.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"lib/*"
|
|
26
|
+
],
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@sozai/async": "^0.1.0",
|
|
30
|
+
"@sozai/codec": "^0.1.0",
|
|
31
|
+
"@sozai/schema": "^0.1.0",
|
|
32
|
+
"@enkaku/transport": "^0.18.0",
|
|
33
|
+
"@kumiai/hub-protocol": "^0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@enkaku/client": "^0.18.0",
|
|
37
|
+
"@enkaku/protocol": "^0.18.0",
|
|
38
|
+
"@enkaku/server": "^0.18.0",
|
|
39
|
+
"@kokuin/token": "^0.1.0"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build:clean": "del lib",
|
|
43
|
+
"build:js": "swc src -d ./lib --config-file ../../node_modules/@kigu/dev/swc.json --strip-leading-paths",
|
|
44
|
+
"build:types": "tsc --emitDeclarationOnly --skipLibCheck",
|
|
45
|
+
"build": "pnpm run build:clean && pnpm run build:js && pnpm run build:types",
|
|
46
|
+
"test:types": "tsc --noEmit -p tsconfig.test.json",
|
|
47
|
+
"test:unit": "vitest run",
|
|
48
|
+
"test": "pnpm run test:types && pnpm run test:unit"
|
|
49
|
+
}
|
|
50
|
+
}
|