@persistica/flux-agent 0.0.2 → 0.0.11
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 +22 -0
- package/{index.cjs → index.js} +35 -31
- package/package.json +21 -25
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Flux Agent
|
|
2
|
+
|
|
3
|
+
```TypeScript
|
|
4
|
+
import { FluxAgent, FluxAgentNetworkConnection } from '@persistica/flux-agent';
|
|
5
|
+
|
|
6
|
+
const NETWORK_ID = 'network-id-to-connect-to';
|
|
7
|
+
|
|
8
|
+
const fluxAgent = new FluxAgent(NETWORK_ID);
|
|
9
|
+
|
|
10
|
+
// * Connect to network
|
|
11
|
+
const fluxNetworkConnection: FluxAgentNetworkConnection = await fluxAgent
|
|
12
|
+
.connect(
|
|
13
|
+
'CODE_TO_ACCESS_NETWORK',
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
console.log(`✅ Agent connected to network ID: '${NETWORK_ID}'`);
|
|
17
|
+
|
|
18
|
+
// * Join network channel
|
|
19
|
+
const fluxConnectedAgentNetworkChannel: FluxNetworkChannel = await fluxNetworkConnection
|
|
20
|
+
.joinChannel('connected-agents');
|
|
21
|
+
|
|
22
|
+
```
|
package/{index.cjs → index.js}
RENAMED
|
@@ -1,29 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// packages/flux/agent/src/index.ts
|
|
21
|
-
var index_exports = {};
|
|
22
|
-
__export(index_exports, {
|
|
23
|
-
FluxAgent: () => FluxAgent
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
26
|
-
|
|
27
1
|
// libs/flux/shared/types/src/lib/channel.type.ts
|
|
28
2
|
var validateChannelNameOrThrow = (channelName) => {
|
|
29
3
|
if (channelName.includes(":")) {
|
|
@@ -57,6 +31,7 @@ var SUBSCRIBED_NETWORK_CHANNEL_NAME = "subscribed-to-nc-name";
|
|
|
57
31
|
var UNSUBSCRIBE_NETWORK_CHANNEL_NAME = "unsubscribe-nc-name";
|
|
58
32
|
var AUTHORITY_CHANNEL_SUBSCRIBE = "acs";
|
|
59
33
|
var AUTHORITY_DISCONNECT_AGENT = "ada";
|
|
34
|
+
var ERROR = "e";
|
|
60
35
|
|
|
61
36
|
// libs/flux/shared/types/src/lib/client.type.ts
|
|
62
37
|
var validateAgentUIDOrThrow = (clientOwnUID) => {
|
|
@@ -72,6 +47,32 @@ var validateAgentUIDOrThrow = (clientOwnUID) => {
|
|
|
72
47
|
return true;
|
|
73
48
|
};
|
|
74
49
|
|
|
50
|
+
// libs/flux/shared/types/src/lib/network.type.ts
|
|
51
|
+
var validateNetworkIdOrThrow = (networkId) => {
|
|
52
|
+
if (typeof networkId !== "string") {
|
|
53
|
+
throw new Error("Network ID must be a string");
|
|
54
|
+
}
|
|
55
|
+
if (networkId === "") {
|
|
56
|
+
throw new Error("Network ID cannot be empty");
|
|
57
|
+
}
|
|
58
|
+
if (networkId === "undefined" || networkId === "null") {
|
|
59
|
+
throw new Error('Network ID cannot be "null" or "undefined"');
|
|
60
|
+
}
|
|
61
|
+
if (networkId.includes(":")) {
|
|
62
|
+
throw new Error("Network ID cannot contain :");
|
|
63
|
+
}
|
|
64
|
+
if (networkId.includes("/")) {
|
|
65
|
+
throw new Error("Network ID cannot contain /");
|
|
66
|
+
}
|
|
67
|
+
if (!/^[A-Za-z0-9-]+$/.test(networkId)) {
|
|
68
|
+
throw new Error("Network ID can only contain letters, numbers and dashes ('-')");
|
|
69
|
+
}
|
|
70
|
+
if (networkId.length > 100) {
|
|
71
|
+
throw new Error("Network ID cannot be longer than 100 characters");
|
|
72
|
+
}
|
|
73
|
+
return true;
|
|
74
|
+
};
|
|
75
|
+
|
|
75
76
|
// libs/flux/shared/ws/src/lib/rpc/rpc-server.class.ts
|
|
76
77
|
var RPCServer = class {
|
|
77
78
|
methods = /* @__PURE__ */ new Map();
|
|
@@ -811,6 +812,9 @@ var FluxWebSocketConnection = class {
|
|
|
811
812
|
break;
|
|
812
813
|
}
|
|
813
814
|
default:
|
|
815
|
+
if (message_.startsWith(`${ERROR}:`)) {
|
|
816
|
+
throw new Error(message_.substring(message_.indexOf(":") + 1) ?? "Unknown error");
|
|
817
|
+
}
|
|
814
818
|
PicoLogger.log(`\u{1F50C} Unhandled type: "${message_}"`, "ws-client");
|
|
815
819
|
break;
|
|
816
820
|
}
|
|
@@ -818,7 +822,7 @@ var FluxWebSocketConnection = class {
|
|
|
818
822
|
};
|
|
819
823
|
|
|
820
824
|
// packages/flux/agent/src/lib/flux-agent.class.ts
|
|
821
|
-
|
|
825
|
+
import { nanoid } from "nanoid";
|
|
822
826
|
|
|
823
827
|
// packages/flux/agent/src/lib/utils/obscuring/shared.utils.ts
|
|
824
828
|
var ALGORITHM = { name: "AES-GCM", length: 256 };
|
|
@@ -1029,8 +1033,9 @@ var FluxAgent = class {
|
|
|
1029
1033
|
constructor(networkId, options) {
|
|
1030
1034
|
this.networkId = networkId;
|
|
1031
1035
|
this.options = options;
|
|
1036
|
+
validateNetworkIdOrThrow(this.networkId);
|
|
1032
1037
|
}
|
|
1033
|
-
id =
|
|
1038
|
+
id = nanoid();
|
|
1034
1039
|
fluxWebSocketConnection;
|
|
1035
1040
|
fluxClientData = new FluxClientData();
|
|
1036
1041
|
stateManager = new StateManager();
|
|
@@ -1093,7 +1098,6 @@ var FluxAgent = class {
|
|
|
1093
1098
|
this.fluxClientData.onMessage(cb);
|
|
1094
1099
|
}
|
|
1095
1100
|
};
|
|
1096
|
-
|
|
1097
|
-
0 && (module.exports = {
|
|
1101
|
+
export {
|
|
1098
1102
|
FluxAgent
|
|
1099
|
-
}
|
|
1103
|
+
};
|
package/package.json
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"nanoid": "5.1.5"
|
|
24
|
-
},
|
|
25
|
-
"packageManager": "bun@1.2.20",
|
|
26
|
-
"module": "./index.js"
|
|
2
|
+
"name": "@persistica/flux-agent",
|
|
3
|
+
"version": "0.0.11",
|
|
4
|
+
"description": "Persistica Flux Agent",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"keywords": [],
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"access": "public"
|
|
9
|
+
},
|
|
10
|
+
"exports": "./index.js",
|
|
11
|
+
"main": "./index.js",
|
|
12
|
+
"types": "./src/index.d.ts",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/rujorgensen/persistica.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "pixl.prophet",
|
|
18
|
+
"license": "ISC",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/rujorgensen/persistica/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/rujorgensen/persistica#readme"
|
|
27
23
|
}
|