@synnaxlabs/client 0.30.0 → 0.31.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.
Files changed (115) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/api/client.api.md +615 -261
  3. package/dist/access/client.d.ts +2 -7
  4. package/dist/access/client.d.ts.map +1 -1
  5. package/dist/access/payload.d.ts +7 -102
  6. package/dist/access/payload.d.ts.map +1 -1
  7. package/dist/access/policy/client.d.ts +17 -0
  8. package/dist/access/policy/client.d.ts.map +1 -0
  9. package/dist/access/policy/external.d.ts +3 -0
  10. package/dist/access/policy/external.d.ts.map +1 -0
  11. package/dist/access/policy/index.d.ts +2 -0
  12. package/dist/access/policy/index.d.ts.map +1 -0
  13. package/dist/access/policy/payload.d.ts +163 -0
  14. package/dist/access/policy/payload.d.ts.map +1 -0
  15. package/dist/access/policy/policy.spec.d.ts +2 -0
  16. package/dist/access/policy/policy.spec.d.ts.map +1 -0
  17. package/dist/access/policy/retriever.d.ts +36 -0
  18. package/dist/access/policy/retriever.d.ts.map +1 -0
  19. package/dist/access/policy/writer.d.ts +9 -0
  20. package/dist/access/policy/writer.d.ts.map +1 -0
  21. package/dist/auth/auth.d.ts +6 -30
  22. package/dist/auth/auth.d.ts.map +1 -1
  23. package/dist/channel/payload.d.ts +17 -17
  24. package/dist/channel/payload.d.ts.map +1 -1
  25. package/dist/channel/retriever.d.ts +8 -8
  26. package/dist/client.cjs +31 -21
  27. package/dist/client.js +2962 -2233
  28. package/dist/framer/client.d.ts +4 -1
  29. package/dist/framer/client.d.ts.map +1 -1
  30. package/dist/framer/frame.d.ts +27 -80
  31. package/dist/framer/frame.d.ts.map +1 -1
  32. package/dist/framer/streamer.d.ts +3 -1
  33. package/dist/framer/streamer.d.ts.map +1 -1
  34. package/dist/framer/writer.d.ts +24 -16
  35. package/dist/framer/writer.d.ts.map +1 -1
  36. package/dist/hardware/device/client.d.ts +2 -2
  37. package/dist/hardware/device/payload.d.ts +1 -1
  38. package/dist/hardware/device/payload.d.ts.map +1 -1
  39. package/dist/hardware/rack/payload.d.ts +1 -1
  40. package/dist/hardware/rack/payload.d.ts.map +1 -1
  41. package/dist/hardware/task/client.d.ts +2 -2
  42. package/dist/hardware/task/ni/types.d.ts +16 -16
  43. package/dist/hardware/task/payload.d.ts +13 -13
  44. package/dist/hardware/task/payload.d.ts.map +1 -1
  45. package/dist/index.d.ts +6 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/label/payload.d.ts +1 -1
  48. package/dist/label/payload.d.ts.map +1 -1
  49. package/dist/label/writer.d.ts +5 -5
  50. package/dist/ontology/client.d.ts +32 -30
  51. package/dist/ontology/client.d.ts.map +1 -1
  52. package/dist/ontology/payload.d.ts +62 -63
  53. package/dist/ontology/payload.d.ts.map +1 -1
  54. package/dist/ranger/payload.d.ts +2 -2
  55. package/dist/ranger/payload.d.ts.map +1 -1
  56. package/dist/ranger/writer.d.ts +5 -5
  57. package/dist/user/client.d.ts +13 -3
  58. package/dist/user/client.d.ts.map +1 -1
  59. package/dist/user/payload.d.ts +34 -3
  60. package/dist/user/payload.d.ts.map +1 -1
  61. package/dist/user/retriever.d.ts +21 -0
  62. package/dist/user/retriever.d.ts.map +1 -0
  63. package/dist/user/user.spec.d.ts +2 -0
  64. package/dist/user/user.spec.d.ts.map +1 -0
  65. package/dist/user/writer.d.ts +11 -0
  66. package/dist/user/writer.d.ts.map +1 -0
  67. package/dist/workspace/lineplot/payload.d.ts +1 -1
  68. package/dist/workspace/lineplot/payload.d.ts.map +1 -1
  69. package/dist/workspace/payload.d.ts +1 -1
  70. package/dist/workspace/payload.d.ts.map +1 -1
  71. package/dist/workspace/schematic/client.d.ts.map +1 -1
  72. package/dist/workspace/schematic/payload.d.ts +1 -1
  73. package/dist/workspace/schematic/payload.d.ts.map +1 -1
  74. package/examples/node/package-lock.json +963 -134
  75. package/examples/node/package.json +1 -1
  76. package/package.json +3 -3
  77. package/src/access/client.ts +4 -70
  78. package/src/access/payload.ts +14 -24
  79. package/src/access/policy/client.ts +65 -0
  80. package/src/access/policy/external.ts +11 -0
  81. package/src/access/policy/index.ts +10 -0
  82. package/src/access/policy/payload.ts +45 -0
  83. package/src/access/policy/policy.spec.ts +331 -0
  84. package/src/access/policy/retriever.ts +43 -0
  85. package/src/access/policy/writer.ts +65 -0
  86. package/src/auth/auth.ts +32 -10
  87. package/src/channel/payload.ts +2 -2
  88. package/src/framer/client.ts +7 -1
  89. package/src/framer/frame.spec.ts +21 -12
  90. package/src/framer/frame.ts +9 -24
  91. package/src/framer/streamer.spec.ts +48 -0
  92. package/src/framer/streamer.ts +7 -4
  93. package/src/framer/writer.ts +0 -2
  94. package/src/hardware/device/payload.ts +2 -2
  95. package/src/hardware/rack/payload.ts +2 -2
  96. package/src/hardware/task/payload.ts +2 -2
  97. package/src/index.ts +16 -13
  98. package/src/label/payload.ts +2 -2
  99. package/src/ontology/client.ts +35 -34
  100. package/src/ontology/payload.ts +28 -35
  101. package/src/ranger/payload.ts +5 -7
  102. package/src/setupspecs.ts +2 -2
  103. package/src/user/client.ts +63 -19
  104. package/src/user/payload.ts +14 -7
  105. package/src/user/retriever.ts +41 -0
  106. package/src/user/user.spec.ts +289 -0
  107. package/src/user/writer.ts +91 -0
  108. package/src/workspace/lineplot/payload.ts +2 -2
  109. package/src/workspace/payload.ts +2 -2
  110. package/src/workspace/schematic/client.ts +1 -1
  111. package/src/workspace/schematic/payload.ts +2 -2
  112. package/src/workspace/workspace.spec.ts +1 -1
  113. package/dist/access/access.spec.d.ts +0 -2
  114. package/dist/access/access.spec.d.ts.map +0 -1
  115. package/src/access/access.spec.ts +0 -276
@@ -0,0 +1,91 @@
1
+ // Copyright 2024 Synnax Labs, Inc.
2
+ //
3
+ // Use of this software is governed by the Business Source License included in the file
4
+ // licenses/BSL.txt.
5
+ //
6
+ // As of the Change Date specified in that file, in accordance with the Business Source
7
+ // License, use of this software will be governed by the Apache License, Version 2.0,
8
+ // included in the file licenses/APL.txt.
9
+
10
+ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
+ import { toArray } from "@synnaxlabs/x/toArray";
12
+ import { z } from "zod";
13
+
14
+ import {
15
+ type Key,
16
+ keyZ,
17
+ type NewUser,
18
+ newUserZ,
19
+ type User,
20
+ userZ,
21
+ } from "@/user/payload";
22
+
23
+ const createReqZ = z.object({ users: newUserZ.array() });
24
+ const createResZ = z.object({ users: userZ.array() });
25
+
26
+ const changeUsernameReqZ = z.object({ key: keyZ, username: z.string().min(1) });
27
+ const changeUsernameResZ = z.object({});
28
+
29
+ const renameReqZ = z.object({
30
+ key: keyZ,
31
+ firstName: z.string().optional(),
32
+ lastName: z.string().optional(),
33
+ });
34
+ const renameResZ = z.object({});
35
+
36
+ const deleteReqZ = z.object({ keys: keyZ.array() });
37
+ const deleteResZ = z.object({});
38
+
39
+ const CREATE_ENDPOINT = "/user/create";
40
+ const CHANGE_USERNAME_ENDPOINT = "/user/change-username";
41
+ const RENAME_ENDPOINT = "/user/rename";
42
+ const DELETE_ENDPOINT = "/user/delete";
43
+
44
+ export class Writer {
45
+ private readonly client: UnaryClient;
46
+
47
+ constructor(client: UnaryClient) {
48
+ this.client = client;
49
+ }
50
+
51
+ async create(users: NewUser | NewUser[]): Promise<User[]> {
52
+ const res = await sendRequired<typeof createReqZ, typeof createResZ>(
53
+ this.client,
54
+ CREATE_ENDPOINT,
55
+ { users: toArray(users) },
56
+ createReqZ,
57
+ createResZ,
58
+ );
59
+ return res.users;
60
+ }
61
+
62
+ async changeUsername(key: Key, newUsername: string): Promise<void> {
63
+ await sendRequired<typeof changeUsernameReqZ, typeof changeUsernameResZ>(
64
+ this.client,
65
+ CHANGE_USERNAME_ENDPOINT,
66
+ { key, username: newUsername },
67
+ changeUsernameReqZ,
68
+ changeUsernameResZ,
69
+ );
70
+ }
71
+
72
+ async rename(key: Key, firstName?: string, lastName?: string): Promise<void> {
73
+ await sendRequired<typeof renameReqZ, typeof renameResZ>(
74
+ this.client,
75
+ RENAME_ENDPOINT,
76
+ { key, firstName, lastName },
77
+ renameReqZ,
78
+ renameResZ,
79
+ );
80
+ }
81
+
82
+ async delete(keys: Key | Key[]): Promise<void> {
83
+ await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
84
+ this.client,
85
+ DELETE_ENDPOINT,
86
+ { keys: toArray(keys) },
87
+ deleteReqZ,
88
+ deleteResZ,
89
+ );
90
+ }
91
+ }
@@ -24,7 +24,7 @@ export const linePlotZ = z.object({
24
24
 
25
25
  export type LinePlot = z.infer<typeof linePlotZ>;
26
26
 
27
- export const LineplotOntologyType = "lineplot" as ontology.ResourceType;
27
+ export const ONTOLOGY_TYPE: ontology.ResourceType = "lineplot";
28
28
 
29
29
  export const ontologyID = (key: Key): ontology.ID =>
30
- new ontology.ID({ type: LineplotOntologyType, key: key });
30
+ new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
@@ -38,7 +38,7 @@ export const workspaceRemoteZ = workspaceZ.omit({ layout: true }).extend({
38
38
 
39
39
  export type Workspace = z.infer<typeof workspaceZ>;
40
40
 
41
- export const WorkspaceOntologyType = "workspace" as ontology.ResourceType;
41
+ export const ONTOLOGY_TYPE: ontology.ResourceType = "workspace";
42
42
 
43
43
  export const ontologyID = (key: Key): ontology.ID =>
44
- new ontology.ID({ type: WorkspaceOntologyType, key: key });
44
+ new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
@@ -12,7 +12,7 @@ import { type UnknownRecord } from "@synnaxlabs/x/record";
12
12
 
13
13
  import { type Key, type Params, type Schematic } from "@/workspace/schematic/payload";
14
14
  import { Retriever } from "@/workspace/schematic/retriever";
15
- import { type NewSchematic,Writer } from "@/workspace/schematic/writer";
15
+ import { type NewSchematic, Writer } from "@/workspace/schematic/writer";
16
16
 
17
17
  export class Client {
18
18
  private readonly writer: Writer;
@@ -32,7 +32,7 @@ export const schematicRemoteZ = z.object({
32
32
 
33
33
  export type Schematic = z.infer<typeof schematicZ>;
34
34
 
35
- export const SchematicOntologyType = "schematic" as ontology.ResourceType;
35
+ export const ONTOLOGY_TYPE: ontology.ResourceType = "schematic";
36
36
 
37
37
  export const ontologyID = (key: Key): ontology.ID =>
38
- new ontology.ID({ type: SchematicOntologyType, key: key });
38
+ new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
@@ -7,7 +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 { describe, expect,test } from "vitest";
10
+ import { describe, expect, test } from "vitest";
11
11
 
12
12
  import { newClient } from "@/setupspecs";
13
13
 
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=access.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"access.spec.d.ts","sourceRoot":"","sources":["../../src/access/access.spec.ts"],"names":[],"mappings":""}
@@ -1,276 +0,0 @@
1
- // Copyright 2024 Synnax Labs, Inc.
2
- //
3
- // Use of this software is governed by the Business Source License included in the file
4
- // licenses/BSL.txt.
5
- //
6
- // As of the Change Date specified in that file, in accordance with the Business Source
7
- // License, use of this software will be governed by the Apache License, Version 2.0,
8
- // included in the file licenses/APL.txt.
9
-
10
- import { DataType, id, Rate } from "@synnaxlabs/x";
11
- import { describe, expect, test } from "vitest";
12
-
13
- import { Policy } from "@/access/payload";
14
- import { Channel } from "@/channel/client";
15
- import { ChannelOntologyType } from "@/channel/payload";
16
- import Synnax from "@/client";
17
- import { AuthError } from "@/errors";
18
- import { LabelOntologyType } from "@/label/payload";
19
- import { HOST, newClient, PORT } from "@/setupspecs";
20
- import { UserOntologyType } from "@/user/payload";
21
-
22
- const client = newClient();
23
-
24
- describe("Policy", () => {
25
- describe("create", () => {
26
- test.skip("create one", async () => {
27
- const policy = await client.access.create({
28
- subjects: [{ type: UserOntologyType, key: "1" }],
29
- objects: [
30
- { type: UserOntologyType, key: "2" },
31
- { type: ChannelOntologyType, key: "3" },
32
- ],
33
- actions: ["update"],
34
- });
35
- expect(policy.key).not.toEqual("");
36
- expect(policy.subjects).toEqual([{ type: UserOntologyType, key: "1" }]);
37
- expect(policy.objects).toEqual([
38
- { type: UserOntologyType, key: "2" },
39
- { type: ChannelOntologyType, key: "3" },
40
- ]);
41
- expect(policy.actions).toEqual(["update"]);
42
- });
43
- test.skip("create many", async () => {
44
- const policies = await client.access.create([
45
- {
46
- subjects: [{ type: UserOntologyType, key: "10" }],
47
- objects: [
48
- { type: UserOntologyType, key: "20" },
49
- { type: UserOntologyType, key: "21" },
50
- ],
51
- actions: ["update"],
52
- },
53
- {
54
- subjects: [
55
- { type: UserOntologyType, key: "20" },
56
- { type: UserOntologyType, key: "21" },
57
- ],
58
- objects: [
59
- { type: UserOntologyType, key: "20" },
60
- { type: ChannelOntologyType, key: "30" },
61
- ],
62
- actions: ["update"],
63
- },
64
- ]);
65
- expect(policies.length).toEqual(3);
66
- expect(policies[0].subjects[0].key).toEqual("10");
67
- expect(policies[1].subjects[1].key).toEqual("21");
68
- });
69
- test.skip("create instances of policies", async () => {
70
- const policy = {
71
- key: undefined,
72
- subjects: [
73
- { type: UserOntologyType, key: "20" },
74
- { type: UserOntologyType, key: "21" },
75
- ],
76
- objects: [
77
- { type: UserOntologyType, key: "20" },
78
- { type: ChannelOntologyType, key: "30" },
79
- ],
80
- actions: ["update"],
81
- };
82
-
83
- const p = await client.access.create(policy);
84
- expect(p.subjects).toEqual(policy.subjects);
85
- expect(p.key).not.toEqual(policy.key);
86
- });
87
- });
88
- test.skip("retrieve by subject", async () => {
89
- const key1 = id.id();
90
- const policies = [
91
- {
92
- key: undefined,
93
- subjects: [
94
- { type: UserOntologyType, key: key1 },
95
- { type: UserOntologyType, key: "21" },
96
- ],
97
- objects: [
98
- { type: UserOntologyType, key: "234" },
99
- { type: ChannelOntologyType, key: "30" },
100
- ],
101
- actions: ["update"],
102
- },
103
- {
104
- key: undefined,
105
- subjects: [
106
- { type: UserOntologyType, key: key1 },
107
- { type: UserOntologyType, key: "22" },
108
- ],
109
- objects: [
110
- { type: LabelOntologyType, key: "23123" },
111
- { type: ChannelOntologyType, key: "30" },
112
- ],
113
- actions: ["delete"],
114
- },
115
- ];
116
-
117
- await client.access.create(policies);
118
-
119
- const p = (await client.access.retrieve(policies[0].subjects[0])) as Policy[];
120
- expect(p).toHaveLength(2);
121
- expect([p[0].actions, p[1].actions].sort()).toEqual([["delete"], ["update"]]);
122
- });
123
- test.skip("retrieve by subject - not found", async () => {
124
- const res = await client.access.retrieve({ type: UserOntologyType, key: "999" });
125
- expect(res).toHaveLength(0);
126
- });
127
-
128
- describe("delete", async () => {
129
- test.skip("delete one", async () => {
130
- const id1 = id.id();
131
- const id2 = id.id();
132
- const id3 = id.id();
133
- const policies = [
134
- {
135
- key: undefined,
136
- subjects: [
137
- { type: UserOntologyType, key: id1 },
138
- { type: UserOntologyType, key: id2 },
139
- ],
140
- objects: [
141
- { type: UserOntologyType, key: "20" },
142
- { type: ChannelOntologyType, key: "30" },
143
- ],
144
- actions: ["update"],
145
- },
146
- {
147
- key: undefined,
148
- subjects: [
149
- { type: UserOntologyType, key: id1 },
150
- { type: UserOntologyType, key: id3 },
151
- ],
152
- objects: [
153
- { type: LabelOntologyType, key: "20" },
154
- { type: ChannelOntologyType, key: "30" },
155
- ],
156
- actions: ["delete"],
157
- },
158
- ];
159
-
160
- const created = await client.access.create(policies);
161
- await client.access.delete(created[0].key);
162
- const res = await client.access.retrieve(created[0].subjects[0]);
163
- expect(res).toHaveLength(1);
164
- expect(res[0].actions).toEqual(["delete"]);
165
- });
166
- test.skip("delete many", async () => {
167
- const id1 = id.id();
168
- const id2 = id.id();
169
- const id3 = id.id();
170
- const policies = [
171
- {
172
- subjects: [
173
- { type: UserOntologyType, key: id1 },
174
- { type: UserOntologyType, key: id2 },
175
- ],
176
- objects: [
177
- { type: UserOntologyType, key: "20" },
178
- { type: ChannelOntologyType, key: "30" },
179
- ],
180
- actions: ["update"],
181
- },
182
- {
183
- subjects: [
184
- { type: UserOntologyType, key: id1 },
185
- { type: UserOntologyType, key: id3 },
186
- ],
187
- objects: [
188
- { type: LabelOntologyType, key: "20" },
189
- { type: ChannelOntologyType, key: "30" },
190
- ],
191
- actions: ["delete"],
192
- },
193
- ];
194
-
195
- const created = await client.access.create(policies);
196
- await client.access.delete([created[0].key, created[1].key]);
197
- let res = await client.access.retrieve({ type: UserOntologyType, key: id1 });
198
- expect(res).toHaveLength(0);
199
- res = await client.access.retrieve({ type: UserOntologyType, key: id2 });
200
- expect(res).toHaveLength(0);
201
- res = await client.access.retrieve({ type: UserOntologyType, key: id3 });
202
- expect(res).toHaveLength(0);
203
- });
204
- });
205
- describe("registration", async () => {
206
- test.skip("register a user", async () => {
207
- const username = id.id();
208
- await client.user.register(username, "pwd1");
209
- new Synnax({
210
- host: HOST,
211
- port: PORT,
212
- username: username,
213
- password: "pwd1",
214
- });
215
- });
216
- test.skip("duplicate username", async () => {
217
- const username = id.id();
218
- await client.user.register(username, "pwd1");
219
- await expect(client.user.register(username, "pwd1")).rejects.toThrow(AuthError);
220
- });
221
- });
222
- describe("privilege", async () => {
223
- test.skip("new user", async () => {
224
- const username = id.id();
225
- const user2 = await client.user.register(username, "pwd1");
226
- expect(user2).toBeDefined();
227
- const client2 = new Synnax({
228
- host: HOST,
229
- port: PORT,
230
- username: username,
231
- password: "pwd1",
232
- });
233
-
234
- await expect(
235
- client2.user.register(id.id(), "pwd3")
236
- ).rejects.toThrow(AuthError);
237
-
238
- await expect(
239
- client2.channels.create(
240
- new Channel({
241
- dataType: DataType.FLOAT64,
242
- rate: Rate.hz(1),
243
- name: "my_channel",
244
- }),
245
- ),
246
- ).rejects.toThrow(AuthError);
247
-
248
- const p = await client.access.create({
249
- subjects: [{ type: UserOntologyType, key: user2.key }],
250
- objects: [{ type: ChannelOntologyType, key: "" }],
251
- actions: ["create"],
252
- });
253
-
254
- await client2.channels.create(
255
- new Channel({
256
- dataType: DataType.FLOAT64,
257
- rate: Rate.hz(1),
258
- name: "my_channel",
259
- }),
260
- );
261
-
262
- // Remove privileges
263
- await client.access.delete(p.key);
264
-
265
- await expect(
266
- client2.channels.create(
267
- new Channel({
268
- dataType: DataType.FLOAT64,
269
- rate: Rate.hz(1),
270
- name: "my_channel",
271
- }),
272
- ),
273
- ).rejects.toThrow(AuthError);
274
- });
275
- });
276
- });