@synnaxlabs/client 0.43.1 → 0.44.2
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/.turbo/turbo-build.log +7 -7
- package/dist/access/payload.d.ts +1 -1
- package/dist/access/payload.d.ts.map +1 -1
- package/dist/access/policy/client.d.ts +263 -6
- package/dist/access/policy/client.d.ts.map +1 -1
- package/dist/access/policy/external.d.ts +0 -1
- package/dist/access/policy/external.d.ts.map +1 -1
- package/dist/access/policy/payload.d.ts +105 -93
- package/dist/access/policy/payload.d.ts.map +1 -1
- package/dist/auth/auth.d.ts +1 -1
- package/dist/auth/auth.d.ts.map +1 -1
- package/dist/channel/client.d.ts +23 -17
- package/dist/channel/client.d.ts.map +1 -1
- package/dist/channel/payload.d.ts +151 -21
- package/dist/channel/payload.d.ts.map +1 -1
- package/dist/channel/retriever.d.ts +9 -16
- package/dist/channel/retriever.d.ts.map +1 -1
- package/dist/channel/writer.d.ts +1 -1
- package/dist/channel/writer.d.ts.map +1 -1
- package/dist/client.cjs +27 -135
- package/dist/client.d.ts +3 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8657 -28963
- package/dist/connection/checker.d.ts +1 -1
- package/dist/connection/checker.d.ts.map +1 -1
- package/dist/control/client.d.ts +1 -0
- package/dist/control/client.d.ts.map +1 -1
- package/dist/control/state.d.ts +6 -6
- package/dist/control/state.d.ts.map +1 -1
- package/dist/errors.d.ts +18 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/framer/adapter.d.ts +3 -3
- package/dist/framer/adapter.d.ts.map +1 -1
- package/dist/framer/client.d.ts +4 -13
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/framer/codec.d.ts +1 -1
- package/dist/framer/codec.d.ts.map +1 -1
- package/dist/framer/deleter.d.ts +5 -5
- package/dist/framer/deleter.d.ts.map +1 -1
- package/dist/framer/frame.d.ts +5 -7
- package/dist/framer/frame.d.ts.map +1 -1
- package/dist/framer/streamProxy.d.ts +1 -1
- package/dist/framer/streamProxy.d.ts.map +1 -1
- package/dist/framer/streamer.d.ts +235 -20
- package/dist/framer/streamer.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +302 -33
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/client.d.ts +49 -28
- package/dist/hardware/device/client.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts +126 -46
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/rack/client.d.ts +78 -22
- package/dist/hardware/rack/client.d.ts.map +1 -1
- package/dist/hardware/rack/payload.d.ts +99 -56
- package/dist/hardware/rack/payload.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +100 -41
- package/dist/hardware/task/client.d.ts.map +1 -1
- package/dist/hardware/task/payload.d.ts +83 -61
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/label/client.d.ts +138 -20
- package/dist/label/client.d.ts.map +1 -1
- package/dist/label/external.d.ts +0 -2
- package/dist/label/external.d.ts.map +1 -1
- package/dist/label/payload.d.ts +4 -5
- package/dist/label/payload.d.ts.map +1 -1
- package/dist/ontology/client.d.ts +45 -135
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/group/group.d.ts +3 -3
- package/dist/ontology/group/group.d.ts.map +1 -1
- package/dist/ontology/group/payload.d.ts +3 -27
- package/dist/ontology/group/payload.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +114 -243
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ontology/writer.d.ts +4 -4
- package/dist/ontology/writer.d.ts.map +1 -1
- package/dist/ranger/alias.d.ts +15 -5
- package/dist/ranger/alias.d.ts.map +1 -1
- package/dist/ranger/client.d.ts +91 -30
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/external.d.ts +1 -1
- package/dist/ranger/external.d.ts.map +1 -1
- package/dist/ranger/kv.d.ts +11 -12
- package/dist/ranger/kv.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts +19 -44
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +22 -19
- package/dist/ranger/writer.d.ts.map +1 -1
- package/dist/testutil/client.d.ts +4 -0
- package/dist/testutil/client.d.ts.map +1 -0
- package/dist/user/client.d.ts +59 -6
- package/dist/user/client.d.ts.map +1 -1
- package/dist/user/payload.d.ts +4 -6
- package/dist/user/payload.d.ts.map +1 -1
- package/dist/user/retriever.d.ts +2 -2
- package/dist/user/retriever.d.ts.map +1 -1
- package/dist/util/decodeJSONString.d.ts +2 -2
- package/dist/util/decodeJSONString.d.ts.map +1 -1
- package/dist/util/parseWithoutKeyConversion.d.ts +2 -2
- package/dist/util/parseWithoutKeyConversion.d.ts.map +1 -1
- package/dist/util/retrieve.d.ts +1 -1
- package/dist/util/retrieve.d.ts.map +1 -1
- package/dist/util/zod.d.ts +1 -1
- package/dist/util/zod.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +17 -6
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/client.d.ts +2 -2
- package/dist/workspace/lineplot/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/payload.d.ts +8 -9
- package/dist/workspace/lineplot/payload.d.ts.map +1 -1
- package/dist/workspace/log/client.d.ts +2 -2
- package/dist/workspace/log/client.d.ts.map +1 -1
- package/dist/workspace/log/payload.d.ts +8 -9
- package/dist/workspace/log/payload.d.ts.map +1 -1
- package/dist/workspace/payload.d.ts +10 -11
- package/dist/workspace/payload.d.ts.map +1 -1
- package/dist/workspace/schematic/client.d.ts +2 -2
- package/dist/workspace/schematic/client.d.ts.map +1 -1
- package/dist/workspace/schematic/payload.d.ts +10 -11
- package/dist/workspace/schematic/payload.d.ts.map +1 -1
- package/dist/workspace/table/client.d.ts +2 -2
- package/dist/workspace/table/client.d.ts.map +1 -1
- package/dist/workspace/table/payload.d.ts +10 -11
- package/dist/workspace/table/payload.d.ts.map +1 -1
- package/examples/node/package-lock.json +47 -39
- package/examples/node/package.json +2 -1
- package/examples/node/streamWrite.js +5 -11
- package/package.json +14 -13
- package/src/access/payload.ts +1 -1
- package/src/access/policy/client.ts +87 -32
- package/src/access/policy/external.ts +0 -1
- package/src/access/policy/payload.ts +4 -4
- package/src/access/policy/policy.spec.ts +86 -83
- package/src/auth/auth.spec.ts +29 -18
- package/src/auth/auth.ts +1 -1
- package/src/channel/batchRetriever.spec.ts +4 -9
- package/src/channel/channel.spec.ts +24 -6
- package/src/channel/client.ts +52 -51
- package/src/channel/payload.ts +15 -16
- package/src/channel/retriever.ts +26 -41
- package/src/channel/writer.ts +7 -4
- package/src/client.ts +4 -4
- package/src/connection/checker.ts +1 -1
- package/src/connection/connection.spec.ts +31 -23
- package/src/control/client.ts +2 -2
- package/src/control/state.spec.ts +3 -3
- package/src/control/state.ts +1 -1
- package/src/errors.spec.ts +9 -5
- package/src/errors.ts +28 -15
- package/src/framer/adapter.spec.ts +118 -9
- package/src/framer/adapter.ts +24 -11
- package/src/framer/client.spec.ts +125 -2
- package/src/framer/client.ts +41 -47
- package/src/framer/codec.ts +1 -1
- package/src/framer/deleter.spec.ts +2 -2
- package/src/framer/deleter.ts +1 -1
- package/src/framer/frame.ts +1 -4
- package/src/framer/iterator.spec.ts +8 -8
- package/src/framer/iterator.ts +1 -1
- package/src/framer/streamProxy.ts +1 -1
- package/src/framer/streamer.spec.ts +185 -36
- package/src/framer/streamer.ts +28 -36
- package/src/framer/writer.spec.ts +7 -6
- package/src/framer/writer.ts +97 -111
- package/src/hardware/device/client.ts +45 -131
- package/src/hardware/device/device.spec.ts +163 -52
- package/src/hardware/device/payload.ts +10 -21
- package/src/hardware/rack/client.ts +87 -105
- package/src/hardware/rack/payload.ts +4 -13
- package/src/hardware/rack/rack.spec.ts +28 -35
- package/src/hardware/task/client.ts +335 -291
- package/src/hardware/task/payload.ts +86 -62
- package/src/hardware/task/task.spec.ts +208 -32
- package/src/index.ts +2 -1
- package/src/label/client.ts +100 -95
- package/src/label/external.ts +0 -2
- package/src/label/label.spec.ts +8 -6
- package/src/label/payload.ts +3 -4
- package/src/ontology/client.ts +41 -324
- package/src/ontology/group/group.spec.ts +2 -2
- package/src/ontology/group/group.ts +4 -5
- package/src/ontology/group/payload.ts +2 -25
- package/src/ontology/group/writer.ts +1 -1
- package/src/ontology/ontology.spec.ts +355 -41
- package/src/ontology/payload.ts +77 -112
- package/src/ontology/writer.ts +8 -17
- package/src/ranger/alias.ts +45 -37
- package/src/ranger/client.ts +144 -149
- package/src/ranger/external.ts +1 -1
- package/src/ranger/kv.ts +9 -27
- package/src/ranger/payload.ts +23 -37
- package/src/ranger/ranger.spec.ts +37 -56
- package/src/ranger/writer.ts +1 -1
- package/src/{signals/index.ts → testutil/client.ts} +11 -1
- package/src/user/client.ts +122 -47
- package/src/user/payload.ts +2 -5
- package/src/user/retriever.ts +1 -1
- package/src/user/user.spec.ts +31 -31
- package/src/user/writer.ts +1 -1
- package/src/util/decodeJSONString.ts +3 -3
- package/src/util/parseWithoutKeyConversion.ts +2 -2
- package/src/util/retrieve.ts +1 -1
- package/src/util/zod.ts +1 -1
- package/src/workspace/client.ts +20 -36
- package/src/workspace/lineplot/client.ts +5 -7
- package/src/workspace/lineplot/lineplot.spec.ts +2 -2
- package/src/workspace/lineplot/payload.ts +4 -7
- package/src/workspace/log/client.ts +5 -7
- package/src/workspace/log/log.spec.ts +2 -2
- package/src/workspace/log/payload.ts +4 -7
- package/src/workspace/payload.ts +4 -7
- package/src/workspace/schematic/client.ts +5 -7
- package/src/workspace/schematic/payload.ts +4 -7
- package/src/workspace/schematic/schematic.spec.ts +2 -2
- package/src/workspace/table/client.ts +5 -7
- package/src/workspace/table/payload.ts +4 -7
- package/src/workspace/table/table.spec.ts +2 -2
- package/src/workspace/workspace.spec.ts +2 -2
- package/dist/access/policy/ontology.d.ts +0 -5
- package/dist/access/policy/ontology.d.ts.map +0 -1
- package/dist/access/policy/retriever.d.ts +0 -40
- package/dist/access/policy/retriever.d.ts.map +0 -1
- package/dist/access/policy/writer.d.ts +0 -9
- package/dist/access/policy/writer.d.ts.map +0 -1
- package/dist/label/retriever.d.ts +0 -14
- package/dist/label/retriever.d.ts.map +0 -1
- package/dist/label/writer.d.ts +0 -54
- package/dist/label/writer.d.ts.map +0 -1
- package/dist/setupspecs.d.ts +0 -5
- package/dist/setupspecs.d.ts.map +0 -1
- package/dist/signals/external.d.ts +0 -2
- package/dist/signals/external.d.ts.map +0 -1
- package/dist/signals/index.d.ts +0 -2
- package/dist/signals/index.d.ts.map +0 -1
- package/dist/signals/observable.d.ts +0 -12
- package/dist/signals/observable.d.ts.map +0 -1
- package/src/access/policy/ontology.ts +0 -17
- package/src/access/policy/retriever.ts +0 -44
- package/src/access/policy/writer.ts +0 -65
- package/src/label/retriever.ts +0 -63
- package/src/label/writer.ts +0 -95
- package/src/setupspecs.ts +0 -27
- package/src/signals/external.ts +0 -10
- package/src/signals/observable.ts +0 -42
|
@@ -11,37 +11,34 @@ import { id } from "@synnaxlabs/x";
|
|
|
11
11
|
import { describe, expect, test } from "vitest";
|
|
12
12
|
|
|
13
13
|
import { type policy } from "@/access/policy";
|
|
14
|
-
import { channel } from "@/channel";
|
|
15
|
-
import Synnax from "@/client";
|
|
16
14
|
import { AuthError } from "@/errors";
|
|
17
|
-
import {
|
|
18
|
-
import { HOST, newClient, PORT } from "@/setupspecs";
|
|
15
|
+
import { createTestClient } from "@/testutil/client";
|
|
19
16
|
import { user } from "@/user";
|
|
20
|
-
import { schematic } from "@/workspace/schematic";
|
|
21
17
|
|
|
22
|
-
const client =
|
|
18
|
+
const client = createTestClient();
|
|
23
19
|
|
|
24
20
|
describe("Policy", () => {
|
|
25
21
|
describe("create", () => {
|
|
26
22
|
describe("one", () => {
|
|
27
23
|
test("without key", async () => {
|
|
28
24
|
const policy = await client.access.policy.create({
|
|
29
|
-
subjects: user
|
|
30
|
-
objects: [user
|
|
25
|
+
subjects: "user",
|
|
26
|
+
objects: ["user", "channel"],
|
|
31
27
|
actions: "delete",
|
|
32
28
|
});
|
|
33
29
|
expect(policy.key).toBeDefined();
|
|
34
30
|
expect(policy.subjects.length).toEqual(1);
|
|
35
31
|
expect(policy.subjects[0].key).toEqual("");
|
|
36
|
-
expect(policy.subjects[0].type).toEqual(user
|
|
32
|
+
expect(policy.subjects[0].type).toEqual("user");
|
|
37
33
|
expect(policy.objects.length).toEqual(2);
|
|
38
34
|
expect(policy.objects[0].key).toEqual("");
|
|
39
35
|
expect(policy.objects[1].key).toEqual("");
|
|
40
|
-
expect(policy.objects[0].type).toEqual(user
|
|
41
|
-
expect(policy.objects[1].type).toEqual(channel
|
|
36
|
+
expect(policy.objects[0].type).toEqual("user");
|
|
37
|
+
expect(policy.objects[1].type).toEqual("channel");
|
|
42
38
|
expect(policy.actions).toEqual(["delete"]);
|
|
43
39
|
await client.access.policy.delete(policy.key);
|
|
44
40
|
});
|
|
41
|
+
|
|
45
42
|
test("missing subjects", async () => {
|
|
46
43
|
const policy = await client.access.policy.create({
|
|
47
44
|
subjects: [],
|
|
@@ -52,42 +49,46 @@ describe("Policy", () => {
|
|
|
52
49
|
expect(policy.subjects).toHaveLength(0);
|
|
53
50
|
expect(policy.objects).toHaveLength(0);
|
|
54
51
|
expect(policy.actions).toHaveLength(0);
|
|
55
|
-
const retrievedPolicy = await client.access.policy.retrieve(
|
|
52
|
+
const retrievedPolicy = await client.access.policy.retrieve({
|
|
53
|
+
key: policy.key,
|
|
54
|
+
});
|
|
56
55
|
expect(retrievedPolicy).toMatchObject(policy);
|
|
57
56
|
});
|
|
58
57
|
test("missing objects", async () => {
|
|
59
58
|
const policy = await client.access.policy.create({
|
|
60
|
-
subjects: user
|
|
59
|
+
subjects: "user",
|
|
61
60
|
objects: [],
|
|
62
61
|
actions: [],
|
|
63
62
|
});
|
|
64
63
|
expect(policy.key).toBeDefined();
|
|
65
64
|
expect(policy.subjects.length).toEqual(1);
|
|
66
|
-
expect(policy.subjects[0].key).toEqual("
|
|
67
|
-
expect(policy.subjects[0].type).toEqual(user
|
|
65
|
+
expect(policy.subjects[0].key).toEqual("");
|
|
66
|
+
expect(policy.subjects[0].type).toEqual("user");
|
|
68
67
|
expect(policy.objects).toHaveLength(0);
|
|
69
68
|
expect(policy.actions).toHaveLength(0);
|
|
70
|
-
const retrievedPolicy = await client.access.policy.retrieve(
|
|
69
|
+
const retrievedPolicy = await client.access.policy.retrieve({
|
|
70
|
+
key: policy.key,
|
|
71
|
+
});
|
|
71
72
|
expect(retrievedPolicy).toMatchObject(policy);
|
|
72
73
|
});
|
|
73
74
|
test("with key", async () => {
|
|
74
75
|
const policy = await client.access.policy.create({
|
|
75
76
|
subjects: [
|
|
76
|
-
{ type: user
|
|
77
|
-
{ type: channel
|
|
77
|
+
{ type: "user", key: "1" },
|
|
78
|
+
{ type: "channel", key: "2" },
|
|
78
79
|
],
|
|
79
|
-
objects: { type: channel
|
|
80
|
+
objects: { type: "channel", key: "3" },
|
|
80
81
|
actions: ["delete", "retrieve"],
|
|
81
82
|
});
|
|
82
83
|
expect(policy.key).toBeDefined();
|
|
83
84
|
expect(policy.subjects.length).toEqual(2);
|
|
84
85
|
expect(policy.subjects[0].key).toEqual("1");
|
|
85
|
-
expect(policy.subjects[0].type).toEqual(user
|
|
86
|
+
expect(policy.subjects[0].type).toEqual("user");
|
|
86
87
|
expect(policy.subjects[1].key).toEqual("2");
|
|
87
|
-
expect(policy.subjects[1].type).toEqual(channel
|
|
88
|
+
expect(policy.subjects[1].type).toEqual("channel");
|
|
88
89
|
expect(policy.objects.length).toEqual(1);
|
|
89
90
|
expect(policy.objects[0].key).toEqual("3");
|
|
90
|
-
expect(policy.objects[0].type).toEqual(channel
|
|
91
|
+
expect(policy.objects[0].type).toEqual("channel");
|
|
91
92
|
expect(policy.actions).toEqual(["delete", "retrieve"]);
|
|
92
93
|
await client.access.policy.delete(policy.key);
|
|
93
94
|
});
|
|
@@ -96,21 +97,21 @@ describe("Policy", () => {
|
|
|
96
97
|
test("with keys", async () => {
|
|
97
98
|
const policiesToCreate: policy.New[] = [
|
|
98
99
|
{
|
|
99
|
-
subjects: [{ type: user
|
|
100
|
+
subjects: [{ type: "user", key: "10" }],
|
|
100
101
|
objects: [
|
|
101
|
-
{ type: user
|
|
102
|
-
{ type: schematic
|
|
102
|
+
{ type: "user", key: "20" },
|
|
103
|
+
{ type: "schematic", key: "21" },
|
|
103
104
|
],
|
|
104
105
|
actions: ["retrieve"],
|
|
105
106
|
},
|
|
106
107
|
{
|
|
107
108
|
subjects: [
|
|
108
|
-
{ type: user
|
|
109
|
-
{ type: schematic
|
|
109
|
+
{ type: "user", key: "20" },
|
|
110
|
+
{ type: "schematic", key: "21" },
|
|
110
111
|
],
|
|
111
112
|
objects: [
|
|
112
|
-
{ type: user
|
|
113
|
-
{ type: schematic
|
|
113
|
+
{ type: "user", key: "20" },
|
|
114
|
+
{ type: "schematic", key: "30" },
|
|
114
115
|
],
|
|
115
116
|
actions: ["delete"],
|
|
116
117
|
},
|
|
@@ -123,13 +124,13 @@ describe("Policy", () => {
|
|
|
123
124
|
test("without keys", async () => {
|
|
124
125
|
const policies = await client.access.policy.create([
|
|
125
126
|
{
|
|
126
|
-
subjects: user
|
|
127
|
-
objects: [user
|
|
127
|
+
subjects: "user",
|
|
128
|
+
objects: ["user", "schematic"],
|
|
128
129
|
actions: ["retrieve"],
|
|
129
130
|
},
|
|
130
131
|
{
|
|
131
|
-
subjects: [user
|
|
132
|
-
objects: [channel
|
|
132
|
+
subjects: ["user", "schematic"],
|
|
133
|
+
objects: ["channel"],
|
|
133
134
|
actions: "retrieve",
|
|
134
135
|
},
|
|
135
136
|
]);
|
|
@@ -137,22 +138,22 @@ describe("Policy", () => {
|
|
|
137
138
|
expect(policies[0].key).toBeDefined();
|
|
138
139
|
expect(policies[0].subjects.length).toEqual(1);
|
|
139
140
|
expect(policies[0].subjects[0].key).toEqual("");
|
|
140
|
-
expect(policies[0].subjects[0].type).toEqual(user
|
|
141
|
+
expect(policies[0].subjects[0].type).toEqual("user");
|
|
141
142
|
expect(policies[0].objects.length).toEqual(2);
|
|
142
143
|
expect(policies[0].objects[0].key).toEqual("");
|
|
143
144
|
expect(policies[0].objects[1].key).toEqual("");
|
|
144
|
-
expect(policies[0].objects[0].type).toEqual(user
|
|
145
|
-
expect(policies[0].objects[1].type).toEqual(schematic
|
|
145
|
+
expect(policies[0].objects[0].type).toEqual("user");
|
|
146
|
+
expect(policies[0].objects[1].type).toEqual("schematic");
|
|
146
147
|
expect(policies[0].actions).toEqual(["retrieve"]);
|
|
147
148
|
expect(policies[1].key).toBeDefined();
|
|
148
149
|
expect(policies[1].subjects.length).toEqual(2);
|
|
149
150
|
expect(policies[1].subjects[0].key).toEqual("");
|
|
150
151
|
expect(policies[1].subjects[1].key).toEqual("");
|
|
151
|
-
expect(policies[1].subjects[0].type).toEqual(user
|
|
152
|
-
expect(policies[1].subjects[1].type).toEqual(schematic
|
|
152
|
+
expect(policies[1].subjects[0].type).toEqual("user");
|
|
153
|
+
expect(policies[1].subjects[1].type).toEqual("schematic");
|
|
153
154
|
expect(policies[1].objects.length).toEqual(1);
|
|
154
155
|
expect(policies[1].objects[0].key).toEqual("");
|
|
155
|
-
expect(policies[1].objects[0].type).toEqual(channel
|
|
156
|
+
expect(policies[1].objects[0].type).toEqual("channel");
|
|
156
157
|
expect(policies[1].actions).toEqual(["retrieve"]);
|
|
157
158
|
await client.access.policy.delete([policies[0].key, policies[1].key]);
|
|
158
159
|
});
|
|
@@ -162,22 +163,21 @@ describe("Policy", () => {
|
|
|
162
163
|
test("by key", async () => {
|
|
163
164
|
const policies = await client.access.policy.create([
|
|
164
165
|
{
|
|
165
|
-
subjects: user
|
|
166
|
-
objects: [user
|
|
166
|
+
subjects: "user",
|
|
167
|
+
objects: ["user", "channel"],
|
|
167
168
|
actions: "delete",
|
|
168
169
|
},
|
|
169
170
|
{
|
|
170
|
-
subjects: user
|
|
171
|
-
objects: [schematic
|
|
171
|
+
subjects: "user",
|
|
172
|
+
objects: ["schematic", "channel"],
|
|
172
173
|
actions: "retrieve",
|
|
173
174
|
},
|
|
174
175
|
]);
|
|
175
|
-
const result = await client.access.policy.retrieve(policies[0].key);
|
|
176
|
+
const result = await client.access.policy.retrieve({ key: policies[0].key });
|
|
176
177
|
expect(result).toMatchObject(policies[0]);
|
|
177
|
-
const results = await client.access.policy.retrieve(
|
|
178
|
-
policies[0].key,
|
|
179
|
-
|
|
180
|
-
]);
|
|
178
|
+
const results = await client.access.policy.retrieve({
|
|
179
|
+
keys: [policies[0].key, policies[1].key],
|
|
180
|
+
});
|
|
181
181
|
expect(results).toHaveLength(2);
|
|
182
182
|
expect(results[0]).toMatchObject(policies[0]);
|
|
183
183
|
expect(results[1]).toMatchObject(policies[1]);
|
|
@@ -190,25 +190,27 @@ describe("Policy", () => {
|
|
|
190
190
|
const created = await client.access.policy.create([
|
|
191
191
|
{
|
|
192
192
|
subjects: [
|
|
193
|
-
{ type: user
|
|
194
|
-
{ type: user
|
|
193
|
+
{ type: "user", key: key1 },
|
|
194
|
+
{ type: "user", key: key2 },
|
|
195
195
|
],
|
|
196
196
|
objects: [
|
|
197
|
-
{ type: user
|
|
198
|
-
{ type: channel
|
|
197
|
+
{ type: "user", key: "234" },
|
|
198
|
+
{ type: "channel", key: "30" },
|
|
199
199
|
],
|
|
200
200
|
actions: ["retrieve"],
|
|
201
201
|
},
|
|
202
202
|
{
|
|
203
|
-
subjects: { type: user
|
|
203
|
+
subjects: { type: "user", key: key1 },
|
|
204
204
|
objects: [
|
|
205
|
-
{ type: label
|
|
206
|
-
{ type: channel
|
|
205
|
+
{ type: "label", key: "23123" },
|
|
206
|
+
{ type: "channel", key: "30" },
|
|
207
207
|
],
|
|
208
208
|
actions: "delete",
|
|
209
209
|
},
|
|
210
210
|
]);
|
|
211
|
-
const received = await client.access.policy.
|
|
211
|
+
const received = await client.access.policy.retrieve({
|
|
212
|
+
for: user.ontologyID(key2),
|
|
213
|
+
});
|
|
212
214
|
const newReceived = received.filter((p) => created.some((c) => c.key === p.key));
|
|
213
215
|
expect(created[0]).toMatchObject(newReceived[0]);
|
|
214
216
|
await client.access.policy.delete([created[0].key, created[1].key]);
|
|
@@ -222,23 +224,23 @@ describe("Policy", () => {
|
|
|
222
224
|
const policies: policy.New[] = [
|
|
223
225
|
{
|
|
224
226
|
subjects: [
|
|
225
|
-
{ type: user
|
|
226
|
-
{ type: user
|
|
227
|
+
{ type: "user", key: id1 },
|
|
228
|
+
{ type: "user", key: id2 },
|
|
227
229
|
],
|
|
228
230
|
objects: [
|
|
229
|
-
{ type: user
|
|
230
|
-
{ type: channel
|
|
231
|
+
{ type: "user", key: "20" },
|
|
232
|
+
{ type: "channel", key: "30" },
|
|
231
233
|
],
|
|
232
234
|
actions: ["retrieve"],
|
|
233
235
|
},
|
|
234
236
|
{
|
|
235
237
|
subjects: [
|
|
236
|
-
{ type: user
|
|
237
|
-
{ type: user
|
|
238
|
+
{ type: "user", key: id1 },
|
|
239
|
+
{ type: "user", key: id3 },
|
|
238
240
|
],
|
|
239
241
|
objects: [
|
|
240
|
-
{ type: label
|
|
241
|
-
{ type: channel
|
|
242
|
+
{ type: "label", key: "20" },
|
|
243
|
+
{ type: "channel", key: "30" },
|
|
242
244
|
],
|
|
243
245
|
actions: ["delete"],
|
|
244
246
|
},
|
|
@@ -246,7 +248,9 @@ describe("Policy", () => {
|
|
|
246
248
|
|
|
247
249
|
const created = await client.access.policy.create(policies);
|
|
248
250
|
await client.access.policy.delete(created[0].key);
|
|
249
|
-
await expect(
|
|
251
|
+
await expect(
|
|
252
|
+
client.access.policy.retrieve({ key: created[0].key }),
|
|
253
|
+
).rejects.toThrow();
|
|
250
254
|
await client.access.policy.delete(created[1].key);
|
|
251
255
|
});
|
|
252
256
|
test("many", async () => {
|
|
@@ -256,23 +260,23 @@ describe("Policy", () => {
|
|
|
256
260
|
const policies: policy.New[] = [
|
|
257
261
|
{
|
|
258
262
|
subjects: [
|
|
259
|
-
{ type: user
|
|
260
|
-
{ type: user
|
|
263
|
+
{ type: "user", key: id1 },
|
|
264
|
+
{ type: "user", key: id2 },
|
|
261
265
|
],
|
|
262
266
|
objects: [
|
|
263
|
-
{ type: user
|
|
264
|
-
{ type: channel
|
|
267
|
+
{ type: "user", key: "20" },
|
|
268
|
+
{ type: "channel", key: "30" },
|
|
265
269
|
],
|
|
266
270
|
actions: ["retrieve"],
|
|
267
271
|
},
|
|
268
272
|
{
|
|
269
273
|
subjects: [
|
|
270
|
-
{ type: user
|
|
271
|
-
{ type: user
|
|
274
|
+
{ type: "user", key: id1 },
|
|
275
|
+
{ type: "user", key: id3 },
|
|
272
276
|
],
|
|
273
277
|
objects: [
|
|
274
|
-
{ type: label
|
|
275
|
-
{ type: channel
|
|
278
|
+
{ type: "label", key: "20" },
|
|
279
|
+
{ type: "channel", key: "30" },
|
|
276
280
|
],
|
|
277
281
|
actions: ["delete"],
|
|
278
282
|
},
|
|
@@ -280,8 +284,12 @@ describe("Policy", () => {
|
|
|
280
284
|
|
|
281
285
|
const created = await client.access.policy.create(policies);
|
|
282
286
|
await client.access.policy.delete([created[0].key, created[1].key]);
|
|
283
|
-
await expect(
|
|
284
|
-
|
|
287
|
+
await expect(
|
|
288
|
+
client.access.policy.retrieve({ key: created[0].key }),
|
|
289
|
+
).rejects.toThrow();
|
|
290
|
+
await expect(
|
|
291
|
+
client.access.policy.retrieve({ key: created[1].key }),
|
|
292
|
+
).rejects.toThrow();
|
|
285
293
|
});
|
|
286
294
|
});
|
|
287
295
|
});
|
|
@@ -291,19 +299,14 @@ describe("privilege", async () => {
|
|
|
291
299
|
const username = id.create();
|
|
292
300
|
const user2 = await client.user.create({ username, password: "pwd1" });
|
|
293
301
|
expect(user2).toBeDefined();
|
|
294
|
-
const client2 =
|
|
295
|
-
host: HOST,
|
|
296
|
-
port: PORT,
|
|
297
|
-
username: user2.username,
|
|
298
|
-
password: "pwd1",
|
|
299
|
-
});
|
|
302
|
+
const client2 = createTestClient({ username: user2.username, password: "pwd1" });
|
|
300
303
|
await expect(
|
|
301
304
|
client2.user.create({ username: id.create(), password: id.create() }),
|
|
302
305
|
).rejects.toThrow(AuthError);
|
|
303
306
|
|
|
304
307
|
const policy = await client.access.policy.create({
|
|
305
|
-
subjects: user
|
|
306
|
-
objects: user
|
|
308
|
+
subjects: "user",
|
|
309
|
+
objects: "user",
|
|
307
310
|
actions: ["create"],
|
|
308
311
|
});
|
|
309
312
|
|
package/src/auth/auth.spec.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { describe, expect, it, test } from "vitest";
|
|
|
13
13
|
|
|
14
14
|
import { auth } from "@/auth";
|
|
15
15
|
import { AuthError, ExpiredTokenError, InvalidTokenError } from "@/errors";
|
|
16
|
-
import {
|
|
16
|
+
import { TEST_CLIENT_PROPS } from "@/testutil/client";
|
|
17
17
|
import { Transport } from "@/transport";
|
|
18
18
|
|
|
19
19
|
const DUMMY_CTX: Context = {
|
|
@@ -25,20 +25,27 @@ const DUMMY_CTX: Context = {
|
|
|
25
25
|
|
|
26
26
|
describe("auth", () => {
|
|
27
27
|
test("valid credentials", async () => {
|
|
28
|
-
const transport = new Transport(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
const transport = new Transport(
|
|
29
|
+
new URL({
|
|
30
|
+
host: TEST_CLIENT_PROPS.host,
|
|
31
|
+
port: Number(TEST_CLIENT_PROPS.port),
|
|
32
|
+
}),
|
|
33
|
+
);
|
|
34
|
+
const client = new auth.Client(transport.unary, TEST_CLIENT_PROPS);
|
|
33
35
|
const mw = client.middleware();
|
|
34
36
|
const res = await mw(DUMMY_CTX, async () => [DUMMY_CTX, null]);
|
|
35
37
|
expect(res).toEqual([DUMMY_CTX, null]);
|
|
36
38
|
});
|
|
37
39
|
|
|
38
40
|
test("invalid credentials", async () => {
|
|
39
|
-
const transport = new Transport(
|
|
41
|
+
const transport = new Transport(
|
|
42
|
+
new URL({
|
|
43
|
+
host: TEST_CLIENT_PROPS.host,
|
|
44
|
+
port: Number(TEST_CLIENT_PROPS.port),
|
|
45
|
+
}),
|
|
46
|
+
);
|
|
40
47
|
const client = new auth.Client(transport.unary, {
|
|
41
|
-
|
|
48
|
+
...TEST_CLIENT_PROPS,
|
|
42
49
|
password: "wrong",
|
|
43
50
|
});
|
|
44
51
|
const mw = client.middleware();
|
|
@@ -50,11 +57,13 @@ describe("auth", () => {
|
|
|
50
57
|
const ERROR_TYPES = [InvalidTokenError, ExpiredTokenError];
|
|
51
58
|
ERROR_TYPES.forEach((ErrorType) => {
|
|
52
59
|
it(`should re-authenticate and retry the request for ${ErrorType.name}`, async () => {
|
|
53
|
-
const transport = new Transport(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
const transport = new Transport(
|
|
61
|
+
new URL({
|
|
62
|
+
host: TEST_CLIENT_PROPS.host,
|
|
63
|
+
port: Number(TEST_CLIENT_PROPS.port),
|
|
64
|
+
}),
|
|
65
|
+
);
|
|
66
|
+
const client = new auth.Client(transport.unary, TEST_CLIENT_PROPS);
|
|
58
67
|
const mw = client.middleware();
|
|
59
68
|
let isFirst = true;
|
|
60
69
|
let tkOne: string | undefined;
|
|
@@ -75,11 +84,13 @@ describe("auth", () => {
|
|
|
75
84
|
});
|
|
76
85
|
|
|
77
86
|
it("should fail after MAX_RETRIES", async () => {
|
|
78
|
-
const transport = new Transport(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
87
|
+
const transport = new Transport(
|
|
88
|
+
new URL({
|
|
89
|
+
host: TEST_CLIENT_PROPS.host,
|
|
90
|
+
port: Number(TEST_CLIENT_PROPS.port),
|
|
91
|
+
}),
|
|
92
|
+
);
|
|
93
|
+
const client = new auth.Client(transport.unary, TEST_CLIENT_PROPS);
|
|
83
94
|
const mw = client.middleware();
|
|
84
95
|
const [, err] = await mw(DUMMY_CTX, async () => [
|
|
85
96
|
DUMMY_CTX,
|
package/src/auth/auth.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
10
|
import { type Middleware, sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
-
import { z } from "zod
|
|
11
|
+
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
import { ExpiredTokenError, InvalidTokenError } from "@/errors";
|
|
14
14
|
import { user } from "@/user";
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
|
+
import { errors } from "@synnaxlabs/x";
|
|
10
11
|
import { DataType, Rate } from "@synnaxlabs/x/telem";
|
|
11
12
|
import { describe, expect, it, vi } from "vitest";
|
|
12
13
|
|
|
@@ -27,18 +28,12 @@ class MockRetriever implements channel.Retriever {
|
|
|
27
28
|
this.func = func;
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
async search(): Promise<channel.Payload[]> {
|
|
31
|
-
throw new Error("Method not implemented.");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async page(): Promise<channel.Payload[]> {
|
|
35
|
-
throw new Error("Method not implemented.");
|
|
36
|
-
}
|
|
37
|
-
|
|
38
31
|
async retrieve(
|
|
39
|
-
channels: channel.Params,
|
|
32
|
+
channels: channel.Params | channel.RetrieveRequest,
|
|
40
33
|
options?: channel.RetrieveOptions,
|
|
41
34
|
): Promise<channel.Payload[]> {
|
|
35
|
+
if (typeof channels === "object" && !Array.isArray(channels))
|
|
36
|
+
throw new errors.NotImplemented();
|
|
42
37
|
return await this.func(channels, options);
|
|
43
38
|
}
|
|
44
39
|
}
|
|
@@ -11,10 +11,10 @@ import { DataType, TimeStamp } from "@synnaxlabs/x/telem";
|
|
|
11
11
|
import { beforeAll, describe, expect, it, test } from "vitest";
|
|
12
12
|
|
|
13
13
|
import { Channel } from "@/channel/client";
|
|
14
|
-
import { NotFoundError } from "@/errors";
|
|
15
|
-
import {
|
|
14
|
+
import { NotFoundError, PathError } from "@/errors";
|
|
15
|
+
import { createTestClient } from "@/testutil/client";
|
|
16
16
|
|
|
17
|
-
const client =
|
|
17
|
+
const client = createTestClient();
|
|
18
18
|
|
|
19
19
|
describe("Channel", () => {
|
|
20
20
|
describe("create", () => {
|
|
@@ -26,7 +26,7 @@ describe("Channel", () => {
|
|
|
26
26
|
});
|
|
27
27
|
expect(channel.name, "test").toEqual("test");
|
|
28
28
|
expect(channel.leaseholder).toEqual(1);
|
|
29
|
-
expect(channel.virtual).
|
|
29
|
+
expect(channel.virtual).toBe(true);
|
|
30
30
|
expect(channel.dataType).toEqual(DataType.FLOAT32);
|
|
31
31
|
}, 80000);
|
|
32
32
|
|
|
@@ -51,6 +51,24 @@ describe("Channel", () => {
|
|
|
51
51
|
expect(calculatedCH.requires).toEqual([chOne.key]);
|
|
52
52
|
});
|
|
53
53
|
|
|
54
|
+
test("create calculated, missing required channel", async () => {
|
|
55
|
+
try {
|
|
56
|
+
await client.channels.create({
|
|
57
|
+
name: "test",
|
|
58
|
+
virtual: true,
|
|
59
|
+
dataType: DataType.FLOAT32,
|
|
60
|
+
expression: "test * 2",
|
|
61
|
+
requires: [],
|
|
62
|
+
});
|
|
63
|
+
} catch (e) {
|
|
64
|
+
expect(PathError.matches(e)).toBe(true);
|
|
65
|
+
expect((e as PathError).path).toEqual(["requires"]);
|
|
66
|
+
expect((e as PathError).error.message).contain(
|
|
67
|
+
"calculated channels must require at least one channel",
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
|
|
54
72
|
test("create index and indexed pair", async () => {
|
|
55
73
|
const one = await client.channels.create({
|
|
56
74
|
name: "Time",
|
|
@@ -112,7 +130,7 @@ describe("Channel", () => {
|
|
|
112
130
|
});
|
|
113
131
|
expect(channel.virtual).toEqual(true);
|
|
114
132
|
const retrieved = await client.channels.retrieve(channel.key);
|
|
115
|
-
expect(retrieved.virtual).
|
|
133
|
+
expect(retrieved.virtual).toBe(true);
|
|
116
134
|
});
|
|
117
135
|
});
|
|
118
136
|
|
|
@@ -270,7 +288,7 @@ describe("Channel", () => {
|
|
|
270
288
|
});
|
|
271
289
|
});
|
|
272
290
|
|
|
273
|
-
describe("update", () => {
|
|
291
|
+
describe("update calculations", () => {
|
|
274
292
|
let idxCH: Channel;
|
|
275
293
|
beforeAll(async () => {
|
|
276
294
|
idxCH = await client.channels.create({
|