@synnaxlabs/client 0.47.0 → 0.49.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 (311) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/dist/client.cjs +35 -35
  3. package/dist/client.js +6264 -5984
  4. package/dist/eslint.config.d.ts +3 -2
  5. package/dist/eslint.config.d.ts.map +1 -1
  6. package/dist/src/access/client.d.ts +3 -1
  7. package/dist/src/access/client.d.ts.map +1 -1
  8. package/dist/src/access/enforce.d.ts +35 -0
  9. package/dist/src/access/enforce.d.ts.map +1 -0
  10. package/dist/src/access/enforce.spec.d.ts +2 -0
  11. package/dist/src/access/enforce.spec.d.ts.map +1 -0
  12. package/dist/src/access/external.d.ts +3 -0
  13. package/dist/src/access/external.d.ts.map +1 -1
  14. package/dist/src/access/payload.d.ts +0 -6
  15. package/dist/src/access/payload.d.ts.map +1 -1
  16. package/dist/src/access/policy/access.spec.d.ts +2 -0
  17. package/dist/src/access/policy/access.spec.d.ts.map +1 -0
  18. package/dist/src/access/policy/client.d.ts +485 -31
  19. package/dist/src/access/policy/client.d.ts.map +1 -1
  20. package/dist/src/access/policy/payload.d.ts +36 -113
  21. package/dist/src/access/policy/payload.d.ts.map +1 -1
  22. package/dist/src/access/role/client.d.ts +135 -0
  23. package/dist/src/access/role/client.d.ts.map +1 -0
  24. package/dist/src/access/role/external.d.ts.map +1 -0
  25. package/dist/src/access/role/index.d.ts +2 -0
  26. package/dist/src/access/role/index.d.ts.map +1 -0
  27. package/dist/src/access/role/payload.d.ts +27 -0
  28. package/dist/src/access/role/payload.d.ts.map +1 -0
  29. package/dist/src/access/role/role.spec.d.ts +2 -0
  30. package/dist/src/access/role/role.spec.d.ts.map +1 -0
  31. package/dist/src/arc/access.spec.d.ts +2 -0
  32. package/dist/src/arc/access.spec.d.ts.map +1 -0
  33. package/dist/src/arc/client.d.ts +5 -14
  34. package/dist/src/arc/client.d.ts.map +1 -1
  35. package/dist/src/arc/payload.d.ts +11 -2
  36. package/dist/src/arc/payload.d.ts.map +1 -1
  37. package/dist/src/auth/auth.d.ts +5 -3
  38. package/dist/src/auth/auth.d.ts.map +1 -1
  39. package/dist/src/channel/access.spec.d.ts +2 -0
  40. package/dist/src/channel/access.spec.d.ts.map +1 -0
  41. package/dist/src/channel/client.d.ts +0 -1
  42. package/dist/src/channel/client.d.ts.map +1 -1
  43. package/dist/src/channel/payload.d.ts +19 -8
  44. package/dist/src/channel/payload.d.ts.map +1 -1
  45. package/dist/src/channel/payload.spec.d.ts +2 -0
  46. package/dist/src/channel/payload.spec.d.ts.map +1 -0
  47. package/dist/src/channel/retriever.d.ts +4 -6
  48. package/dist/src/channel/retriever.d.ts.map +1 -1
  49. package/dist/src/channel/writer.d.ts.map +1 -1
  50. package/dist/src/client.d.ts +18 -10
  51. package/dist/src/client.d.ts.map +1 -1
  52. package/dist/src/connection/checker.d.ts +2 -3
  53. package/dist/src/connection/checker.d.ts.map +1 -1
  54. package/dist/src/connection.spec.d.ts +2 -0
  55. package/dist/src/connection.spec.d.ts.map +1 -0
  56. package/dist/src/device/access.spec.d.ts +2 -0
  57. package/dist/src/device/access.spec.d.ts.map +1 -0
  58. package/dist/src/{hardware/device → device}/client.d.ts +14 -7
  59. package/dist/src/device/client.d.ts.map +1 -0
  60. package/dist/src/device/device.spec.d.ts.map +1 -0
  61. package/dist/src/device/external.d.ts.map +1 -0
  62. package/dist/src/device/index.d.ts.map +1 -0
  63. package/dist/src/{hardware/device → device}/payload.d.ts +1 -1
  64. package/dist/src/device/payload.d.ts.map +1 -0
  65. package/dist/src/errors.d.ts +3 -0
  66. package/dist/src/errors.d.ts.map +1 -1
  67. package/dist/src/framer/adapter.d.ts +2 -2
  68. package/dist/src/framer/adapter.d.ts.map +1 -1
  69. package/dist/src/framer/client.d.ts +8 -1
  70. package/dist/src/framer/client.d.ts.map +1 -1
  71. package/dist/src/framer/frame.d.ts +11 -5
  72. package/dist/src/framer/frame.d.ts.map +1 -1
  73. package/dist/src/framer/iterator.d.ts +3 -3
  74. package/dist/src/framer/streamer.d.ts +24 -21
  75. package/dist/src/framer/streamer.d.ts.map +1 -1
  76. package/dist/src/framer/writer.d.ts +13 -13
  77. package/dist/src/index.d.ts +6 -7
  78. package/dist/src/index.d.ts.map +1 -1
  79. package/dist/src/label/access.spec.d.ts +2 -0
  80. package/dist/src/label/access.spec.d.ts.map +1 -0
  81. package/dist/src/label/client.d.ts +20 -11
  82. package/dist/src/label/client.d.ts.map +1 -1
  83. package/dist/src/ontology/client.d.ts +6 -6
  84. package/dist/src/ontology/client.d.ts.map +1 -1
  85. package/dist/src/ontology/group/access.spec.d.ts +2 -0
  86. package/dist/src/ontology/group/access.spec.d.ts.map +1 -0
  87. package/dist/src/ontology/group/client.d.ts +2 -2
  88. package/dist/src/ontology/group/client.d.ts.map +1 -1
  89. package/dist/src/ontology/group/payload.d.ts +1 -2
  90. package/dist/src/ontology/group/payload.d.ts.map +1 -1
  91. package/dist/src/ontology/payload.d.ts +23 -17
  92. package/dist/src/ontology/payload.d.ts.map +1 -1
  93. package/dist/src/ontology/writer.d.ts +10 -10
  94. package/dist/src/ontology/writer.d.ts.map +1 -1
  95. package/dist/src/rack/access.spec.d.ts +2 -0
  96. package/dist/src/rack/access.spec.d.ts.map +1 -0
  97. package/dist/src/{hardware/rack → rack}/client.d.ts +15 -8
  98. package/dist/src/rack/client.d.ts.map +1 -0
  99. package/dist/src/rack/external.d.ts.map +1 -0
  100. package/dist/src/rack/index.d.ts.map +1 -0
  101. package/dist/src/{hardware/rack → rack}/payload.d.ts +1 -1
  102. package/dist/src/rack/payload.d.ts.map +1 -0
  103. package/dist/src/rack/rack.spec.d.ts.map +1 -0
  104. package/dist/src/ranger/access.spec.d.ts +2 -0
  105. package/dist/src/ranger/access.spec.d.ts.map +1 -0
  106. package/dist/src/ranger/alias.d.ts +1 -8
  107. package/dist/src/ranger/alias.d.ts.map +1 -1
  108. package/dist/src/ranger/client.d.ts +12 -5
  109. package/dist/src/ranger/client.d.ts.map +1 -1
  110. package/dist/src/ranger/kv.d.ts +0 -3
  111. package/dist/src/ranger/kv.d.ts.map +1 -1
  112. package/dist/src/ranger/writer.d.ts +2 -2
  113. package/dist/src/ranger/writer.d.ts.map +1 -1
  114. package/dist/src/status/access.spec.d.ts +2 -0
  115. package/dist/src/status/access.spec.d.ts.map +1 -0
  116. package/dist/src/status/client.d.ts +4 -4
  117. package/dist/src/status/client.d.ts.map +1 -1
  118. package/dist/src/status/payload.d.ts +9 -2
  119. package/dist/src/status/payload.d.ts.map +1 -1
  120. package/dist/src/task/access.spec.d.ts +2 -0
  121. package/dist/src/task/access.spec.d.ts.map +1 -0
  122. package/dist/src/{hardware/task → task}/client.d.ts +26 -15
  123. package/dist/src/task/client.d.ts.map +1 -0
  124. package/dist/src/task/external.d.ts +3 -0
  125. package/dist/src/task/external.d.ts.map +1 -0
  126. package/dist/src/task/index.d.ts.map +1 -0
  127. package/dist/src/{hardware/task → task}/payload.d.ts +45 -6
  128. package/dist/src/task/payload.d.ts.map +1 -0
  129. package/dist/src/task/task.spec.d.ts.map +1 -0
  130. package/dist/src/testutil/access.d.ts +4 -0
  131. package/dist/src/testutil/access.d.ts.map +1 -0
  132. package/dist/src/testutil/client.d.ts +3 -3
  133. package/dist/src/testutil/client.d.ts.map +1 -1
  134. package/dist/src/transport.d.ts.map +1 -1
  135. package/dist/src/user/access.spec.d.ts +2 -0
  136. package/dist/src/user/access.spec.d.ts.map +1 -0
  137. package/dist/src/user/client.d.ts +10 -1
  138. package/dist/src/user/client.d.ts.map +1 -1
  139. package/dist/src/user/external.d.ts +1 -1
  140. package/dist/src/user/external.d.ts.map +1 -1
  141. package/dist/src/user/payload.d.ts.map +1 -1
  142. package/dist/src/workspace/access.spec.d.ts +2 -0
  143. package/dist/src/workspace/access.spec.d.ts.map +1 -0
  144. package/dist/src/workspace/client.d.ts +10 -5
  145. package/dist/src/workspace/client.d.ts.map +1 -1
  146. package/dist/src/workspace/lineplot/access.spec.d.ts +2 -0
  147. package/dist/src/workspace/lineplot/access.spec.d.ts.map +1 -0
  148. package/dist/src/workspace/lineplot/client.d.ts +8 -1
  149. package/dist/src/workspace/lineplot/client.d.ts.map +1 -1
  150. package/dist/src/workspace/log/access.spec.d.ts +2 -0
  151. package/dist/src/workspace/log/access.spec.d.ts.map +1 -0
  152. package/dist/src/workspace/log/client.d.ts +8 -1
  153. package/dist/src/workspace/log/client.d.ts.map +1 -1
  154. package/dist/src/workspace/schematic/access.spec.d.ts +2 -0
  155. package/dist/src/workspace/schematic/access.spec.d.ts.map +1 -0
  156. package/dist/src/workspace/schematic/client.d.ts +8 -1
  157. package/dist/src/workspace/schematic/client.d.ts.map +1 -1
  158. package/dist/src/workspace/schematic/symbol/access.spec.d.ts +2 -0
  159. package/dist/src/workspace/schematic/symbol/access.spec.d.ts.map +1 -0
  160. package/dist/src/workspace/schematic/symbol/client.d.ts +1 -5
  161. package/dist/src/workspace/schematic/symbol/client.d.ts.map +1 -1
  162. package/dist/src/workspace/schematic/symbol/payload.d.ts +2 -2
  163. package/dist/src/workspace/table/access.spec.d.ts +2 -0
  164. package/dist/src/workspace/table/access.spec.d.ts.map +1 -0
  165. package/dist/src/workspace/table/client.d.ts +8 -1
  166. package/dist/src/workspace/table/client.d.ts.map +1 -1
  167. package/eslint.config.ts +3 -1
  168. package/package.json +8 -8
  169. package/src/access/client.ts +5 -2
  170. package/src/access/enforce.spec.ts +189 -0
  171. package/src/access/enforce.ts +84 -0
  172. package/src/access/external.ts +3 -0
  173. package/src/access/payload.ts +1 -13
  174. package/src/access/policy/access.spec.ts +147 -0
  175. package/src/access/policy/client.ts +21 -25
  176. package/src/access/policy/payload.ts +9 -5
  177. package/src/access/role/client.ts +135 -0
  178. package/src/access/role/external.ts +11 -0
  179. package/src/{hardware → access/role}/index.ts +1 -1
  180. package/src/access/role/payload.ts +32 -0
  181. package/src/access/role/role.spec.ts +95 -0
  182. package/src/arc/access.spec.ts +143 -0
  183. package/src/arc/client.ts +7 -31
  184. package/src/arc/payload.ts +4 -0
  185. package/src/auth/auth.spec.ts +13 -13
  186. package/src/auth/auth.ts +33 -11
  187. package/src/channel/access.spec.ts +116 -0
  188. package/src/channel/channel.spec.ts +63 -73
  189. package/src/channel/client.ts +2 -8
  190. package/src/channel/payload.spec.ts +171 -0
  191. package/src/channel/payload.ts +37 -8
  192. package/src/channel/retriever.ts +10 -11
  193. package/src/channel/writer.ts +3 -7
  194. package/src/client.ts +38 -28
  195. package/src/connection/checker.ts +10 -10
  196. package/src/connection/connection.spec.ts +13 -13
  197. package/src/connection.spec.ts +145 -0
  198. package/src/device/access.spec.ts +159 -0
  199. package/src/{hardware/device → device}/client.ts +12 -21
  200. package/src/{hardware/device → device}/device.spec.ts +70 -34
  201. package/src/device/external.ts +11 -0
  202. package/src/{hardware/rack → device}/index.ts +1 -1
  203. package/src/{hardware/device → device}/payload.ts +3 -3
  204. package/src/errors.ts +2 -0
  205. package/src/framer/adapter.spec.ts +351 -13
  206. package/src/framer/adapter.ts +23 -13
  207. package/src/framer/client.spec.ts +14 -20
  208. package/src/framer/client.ts +3 -5
  209. package/src/framer/deleter.spec.ts +1 -1
  210. package/src/framer/frame.spec.ts +427 -0
  211. package/src/framer/frame.ts +30 -3
  212. package/src/framer/iterator.ts +4 -4
  213. package/src/framer/streamer.spec.ts +155 -10
  214. package/src/framer/streamer.ts +35 -12
  215. package/src/framer/writer.spec.ts +5 -5
  216. package/src/index.ts +13 -7
  217. package/src/label/access.spec.ts +109 -0
  218. package/src/label/client.ts +10 -14
  219. package/src/ontology/client.ts +4 -6
  220. package/src/ontology/group/access.spec.ts +77 -0
  221. package/src/ontology/group/client.ts +3 -7
  222. package/src/ontology/group/group.spec.ts +18 -0
  223. package/src/ontology/group/payload.ts +2 -2
  224. package/src/ontology/ontology.spec.ts +2 -0
  225. package/src/ontology/payload.ts +18 -2
  226. package/src/ontology/writer.ts +3 -7
  227. package/src/rack/access.spec.ts +102 -0
  228. package/src/{hardware/rack → rack}/client.ts +14 -19
  229. package/src/{hardware/device/index.ts → rack/external.ts} +2 -1
  230. package/src/{hardware/external.ts → rack/index.ts} +1 -1
  231. package/src/{hardware/rack → rack}/payload.ts +2 -2
  232. package/src/{hardware/rack → rack}/rack.spec.ts +43 -17
  233. package/src/ranger/access.spec.ts +115 -0
  234. package/src/ranger/alias.ts +6 -14
  235. package/src/ranger/client.ts +13 -14
  236. package/src/ranger/kv.ts +7 -9
  237. package/src/ranger/ranger.spec.ts +4 -4
  238. package/src/ranger/writer.ts +3 -7
  239. package/src/status/access.spec.ts +129 -0
  240. package/src/status/client.ts +5 -9
  241. package/src/status/payload.ts +3 -2
  242. package/src/task/access.spec.ts +131 -0
  243. package/src/{hardware/task → task}/client.ts +50 -25
  244. package/src/task/external.ts +11 -0
  245. package/src/{hardware/task → task}/index.ts +1 -1
  246. package/src/{hardware/task → task}/payload.ts +22 -3
  247. package/src/{hardware/task → task}/task.spec.ts +197 -34
  248. package/src/testutil/access.ts +34 -0
  249. package/src/testutil/channels.ts +3 -3
  250. package/src/testutil/client.ts +4 -4
  251. package/src/transport.ts +1 -3
  252. package/src/user/access.spec.ts +107 -0
  253. package/src/user/client.ts +10 -12
  254. package/src/user/external.ts +12 -1
  255. package/src/user/payload.ts +3 -5
  256. package/src/workspace/access.spec.ts +108 -0
  257. package/src/workspace/client.ts +11 -27
  258. package/src/workspace/lineplot/access.spec.ts +134 -0
  259. package/src/workspace/lineplot/client.ts +8 -13
  260. package/src/workspace/log/access.spec.ts +134 -0
  261. package/src/workspace/log/client.ts +8 -13
  262. package/src/workspace/schematic/access.spec.ts +134 -0
  263. package/src/workspace/schematic/client.ts +9 -18
  264. package/src/workspace/schematic/symbol/access.spec.ts +172 -0
  265. package/src/workspace/schematic/symbol/client.ts +6 -17
  266. package/src/workspace/schematic/symbol/payload.ts +1 -1
  267. package/src/workspace/table/access.spec.ts +134 -0
  268. package/src/workspace/table/client.ts +8 -13
  269. package/dist/src/access/policy/policy.spec.d.ts +0 -2
  270. package/dist/src/access/policy/policy.spec.d.ts.map +0 -1
  271. package/dist/src/hardware/client.d.ts +0 -10
  272. package/dist/src/hardware/client.d.ts.map +0 -1
  273. package/dist/src/hardware/device/client.d.ts.map +0 -1
  274. package/dist/src/hardware/device/device.spec.d.ts.map +0 -1
  275. package/dist/src/hardware/device/external.d.ts.map +0 -1
  276. package/dist/src/hardware/device/index.d.ts.map +0 -1
  277. package/dist/src/hardware/device/payload.d.ts.map +0 -1
  278. package/dist/src/hardware/external.d.ts +0 -2
  279. package/dist/src/hardware/external.d.ts.map +0 -1
  280. package/dist/src/hardware/index.d.ts +0 -2
  281. package/dist/src/hardware/index.d.ts.map +0 -1
  282. package/dist/src/hardware/rack/client.d.ts.map +0 -1
  283. package/dist/src/hardware/rack/external.d.ts.map +0 -1
  284. package/dist/src/hardware/rack/index.d.ts.map +0 -1
  285. package/dist/src/hardware/rack/payload.d.ts.map +0 -1
  286. package/dist/src/hardware/rack/rack.spec.d.ts.map +0 -1
  287. package/dist/src/hardware/task/client.d.ts.map +0 -1
  288. package/dist/src/hardware/task/external.d.ts.map +0 -1
  289. package/dist/src/hardware/task/index.d.ts.map +0 -1
  290. package/dist/src/hardware/task/payload.d.ts.map +0 -1
  291. package/dist/src/hardware/task/task.spec.d.ts.map +0 -1
  292. package/dist/src/user/retriever.d.ts +0 -16
  293. package/dist/src/user/retriever.d.ts.map +0 -1
  294. package/dist/src/user/writer.d.ts +0 -11
  295. package/dist/src/user/writer.d.ts.map +0 -1
  296. package/src/access/policy/policy.spec.ts +0 -329
  297. package/src/hardware/client.ts +0 -24
  298. package/src/hardware/device/external.ts +0 -11
  299. package/src/hardware/rack/external.ts +0 -11
  300. package/src/hardware/task/external.ts +0 -11
  301. package/src/user/retriever.ts +0 -41
  302. package/src/user/writer.ts +0 -84
  303. /package/dist/src/{hardware/device → access/role}/external.d.ts +0 -0
  304. /package/dist/src/{hardware/device → device}/device.spec.d.ts +0 -0
  305. /package/dist/src/{hardware/rack → device}/external.d.ts +0 -0
  306. /package/dist/src/{hardware/device → device}/index.d.ts +0 -0
  307. /package/dist/src/{hardware/task → rack}/external.d.ts +0 -0
  308. /package/dist/src/{hardware/rack → rack}/index.d.ts +0 -0
  309. /package/dist/src/{hardware/rack → rack}/rack.spec.d.ts +0 -0
  310. /package/dist/src/{hardware/task → task}/index.d.ts +0 -0
  311. /package/dist/src/{hardware/task → task}/task.spec.d.ts +0 -0
@@ -80,7 +80,7 @@ export interface Spec extends z.infer<typeof specZ> {
80
80
  }
81
81
  export declare const symbolZ: z.ZodObject<{
82
82
  key: z.ZodUUID;
83
- version: z.ZodDefault<z.ZodOptional<z.ZodLiteral<1>>>;
83
+ version: z.ZodDefault<z.ZodLiteral<1>>;
84
84
  name: z.ZodString;
85
85
  data: z.ZodObject<{
86
86
  svg: z.ZodString;
@@ -122,7 +122,7 @@ export declare const symbolZ: z.ZodObject<{
122
122
  }, z.core.$strip>;
123
123
  export declare const newZ: z.ZodObject<{
124
124
  key: z.ZodOptional<z.ZodUUID>;
125
- version: z.ZodDefault<z.ZodOptional<z.ZodLiteral<1>>>;
125
+ version: z.ZodDefault<z.ZodLiteral<1>>;
126
126
  name: z.ZodString;
127
127
  data: z.ZodObject<{
128
128
  svg: z.ZodString;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=access.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"access.spec.d.ts","sourceRoot":"","sources":["../../../../src/workspace/table/access.spec.ts"],"names":[],"mappings":""}
@@ -37,6 +37,13 @@ export declare class Client {
37
37
  retrieve(args: RetrieveMultipleParams): Promise<Table[]>;
38
38
  delete(keys: Params): Promise<void>;
39
39
  }
40
- export declare const ontologyID: (key: Key) => ontology.ID;
40
+ export declare const ontologyID: ontology.CreateID<string>;
41
+ export declare const TYPE_ONTOLOGY_ID: {
42
+ type: "status" | "label" | "log" | "builtin" | "cluster" | "channel" | "node" | "group" | "range" | "framer" | "range-alias" | "user" | "workspace" | "schematic" | "lineplot" | "rack" | "device" | "task" | "policy" | "role" | "table" | "arc" | "schematic_symbol";
43
+ key: string;
44
+ } | {
45
+ type: "status" | "label" | "log" | "builtin" | "cluster" | "channel" | "node" | "group" | "range" | "framer" | "range-alias" | "user" | "workspace" | "schematic" | "lineplot" | "rack" | "device" | "task" | "policy" | "role" | "table" | "arc" | "schematic_symbol";
46
+ key: string;
47
+ };
41
48
  export {};
42
49
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/workspace/table/client.ts"],"names":[],"mappings":"AASA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,KAAK,GAAG,IAAI,YAAY,EAAyB,MAAM,qBAAqB,CAAC;AACtF,OAAO,EACL,KAAK,GAAG,EAER,KAAK,GAAG,EAER,KAAK,MAAM,EAEX,KAAK,KAAK,EACX,MAAM,2BAA2B,CAAC;AAanC,QAAA,MAAM,YAAY;;iBAAmC,CAAC;AACtD,QAAA,MAAM,mBAAmB;;;;;;GAEmB,CAAC;AAE7C,eAAO,MAAM,aAAa;;;;;;;;mBAA+C,CAAC;AAC1E,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACzD,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACvE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AASlE,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,MAAM,EAAE,WAAW;IAIzB,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;IAC3D,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAahE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU7C,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtD,QAAQ,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,KAAK,CAAC;IACpD,QAAQ,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAgBxD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS1C;AAED,eAAO,MAAM,UAAU,GAAI,KAAK,GAAG,KAAG,QAAQ,CAAC,EAA8B,CAAC"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/workspace/table/client.ts"],"names":[],"mappings":"AASA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAS,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,KAAK,GAAG,IAAI,YAAY,EAAyB,MAAM,qBAAqB,CAAC;AACtF,OAAO,EACL,KAAK,GAAG,EAER,KAAK,GAAG,EAER,KAAK,MAAM,EAEX,KAAK,KAAK,EACX,MAAM,2BAA2B,CAAC;AAOnC,QAAA,MAAM,YAAY;;iBAAmC,CAAC;AACtD,QAAA,MAAM,mBAAmB;;;;;;GAEmB,CAAC;AAE7C,eAAO,MAAM,aAAa;;;;;;;;mBAA+C,CAAC;AAC1E,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACzD,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AACvE,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AASlE,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,MAAM,EAAE,WAAW;IAIzB,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC;IAC3D,MAAM,CAAC,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAahE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU7C,OAAO,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtD,QAAQ,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,KAAK,CAAC;IACpD,QAAQ,CAAC,IAAI,EAAE,sBAAsB,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAgBxD,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAS1C;AAED,eAAO,MAAM,UAAU,2BAAyC,CAAC;AACjE,eAAO,MAAM,gBAAgB;;;;;;CAAiB,CAAC"}
package/eslint.config.ts CHANGED
@@ -7,6 +7,8 @@
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 type { Linter } from "eslint";
10
11
  import synnaxConfig from "eslint-config-synnaxlabs";
11
12
 
12
- export default [...synnaxConfig, { ignores: ["examples"] }];
13
+ const cfg: Linter.Config[] = [...synnaxConfig, { ignores: ["examples"] }];
14
+ export default cfg;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synnaxlabs/client",
3
- "version": "0.47.0",
3
+ "version": "0.49.0",
4
4
  "description": "The Synnax Client Library",
5
5
  "keywords": [
6
6
  "synnax",
@@ -25,17 +25,17 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "async-mutex": "^0.5.0",
28
- "zod": "^4.1.8",
29
- "@synnaxlabs/freighter": "^0.47.0",
30
- "@synnaxlabs/x": "^0.47.0"
28
+ "zod": "^4.1.12",
29
+ "@synnaxlabs/freighter": "^0.49.0",
30
+ "@synnaxlabs/x": "^0.49.0"
31
31
  },
32
32
  "devDependencies": {
33
33
  "@vitest/coverage-v8": "^3.2.4",
34
- "@types/node": "^24.4.0",
35
- "eslint": "^9.37.0",
34
+ "@types/node": "^24.10.0",
35
+ "eslint": "^9.39.1",
36
36
  "madge": "^8.0.0",
37
- "typescript": "^5.9.2",
38
- "vite": "^7.1.5",
37
+ "typescript": "^5.9.3",
38
+ "vite": "^7.1.12",
39
39
  "vitest": "^3.2.4",
40
40
  "@synnaxlabs/tsconfig": "^0.43.0",
41
41
  "@synnaxlabs/vite-plugin": "^0.43.0",
@@ -10,11 +10,14 @@
10
10
  import { type UnaryClient } from "@synnaxlabs/freighter";
11
11
 
12
12
  import { policy } from "@/access/policy";
13
+ import { role } from "@/access/role";
13
14
 
14
15
  export class Client {
15
- readonly policy: policy.Client;
16
+ readonly policies: policy.Client;
17
+ readonly roles: role.Client;
16
18
 
17
19
  constructor(client: UnaryClient) {
18
- this.policy = new policy.Client(client);
20
+ this.policies = new policy.Client(client);
21
+ this.roles = new role.Client(client);
19
22
  }
20
23
  }
@@ -0,0 +1,189 @@
1
+ // Copyright 2025 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 { describe, expect, it } from "vitest";
11
+
12
+ import { access } from "@/access";
13
+ import { type Policy } from "@/access/policy/payload";
14
+ import { type ontology } from "@/ontology";
15
+
16
+ const id = (type: ontology.ResourceType, key: string): ontology.ID => ({ type, key });
17
+
18
+ const policy = (
19
+ objects: ontology.ID[],
20
+ actions: access.Action[],
21
+ key = crypto.randomUUID(),
22
+ ): Policy => ({ key, name: "test", objects, actions, internal: false });
23
+
24
+ describe("allowRequest", () => {
25
+ describe("single object", () => {
26
+ it("should allow when policy has exact match", () => {
27
+ const policies = [policy([id("channel", "1")], ["retrieve"])];
28
+ const allowed = access.allowRequest(
29
+ {
30
+ subject: id("user", "u1"),
31
+ action: "retrieve",
32
+ objects: id("channel", "1"),
33
+ },
34
+ policies,
35
+ );
36
+ expect(allowed).toBe(true);
37
+ });
38
+
39
+ it("should allow when policy has type-level match (empty key)", () => {
40
+ const policies = [policy([id("channel", "")], ["retrieve"])];
41
+ const allowed = access.allowRequest(
42
+ {
43
+ subject: id("user", "u1"),
44
+ action: "retrieve",
45
+ objects: id("channel", "42"),
46
+ },
47
+ policies,
48
+ );
49
+ expect(allowed).toBe(true);
50
+ });
51
+
52
+ it("should deny when no policy matches", () => {
53
+ const policies = [policy([id("channel", "1")], ["retrieve"])];
54
+ const allowed = access.allowRequest(
55
+ {
56
+ subject: id("user", "u1"),
57
+ action: "retrieve",
58
+ objects: id("channel", "2"),
59
+ },
60
+ policies,
61
+ );
62
+ expect(allowed).toBe(false);
63
+ });
64
+
65
+ it("should deny when action not allowed", () => {
66
+ const policies = [policy([id("channel", "1")], ["retrieve"])];
67
+ const allowed = access.allowRequest(
68
+ {
69
+ subject: id("user", "u1"),
70
+ action: "delete",
71
+ objects: id("channel", "1"),
72
+ },
73
+ policies,
74
+ );
75
+ expect(allowed).toBe(false);
76
+ });
77
+
78
+ it("should deny when type does not match", () => {
79
+ const policies = [policy([id("channel", "1")], ["retrieve"])];
80
+ const allowed = access.allowRequest(
81
+ {
82
+ subject: id("user", "u1"),
83
+ action: "retrieve",
84
+ objects: id("device", "1"),
85
+ },
86
+ policies,
87
+ );
88
+ expect(allowed).toBe(false);
89
+ });
90
+ });
91
+
92
+ describe("multiple objects", () => {
93
+ it("should allow when all objects are covered", () => {
94
+ const policies = [policy([id("channel", "1"), id("channel", "2")], ["retrieve"])];
95
+ const allowed = access.allowRequest(
96
+ {
97
+ subject: id("user", "u1"),
98
+ action: "retrieve",
99
+ objects: [id("channel", "1"), id("channel", "2")],
100
+ },
101
+ policies,
102
+ );
103
+ expect(allowed).toBe(true);
104
+ });
105
+
106
+ it("should deny when some objects are not covered", () => {
107
+ const policies = [policy([id("channel", "1")], ["retrieve"])];
108
+ const allowed = access.allowRequest(
109
+ {
110
+ subject: id("user", "u1"),
111
+ action: "retrieve",
112
+ objects: [id("channel", "1"), id("channel", "2")],
113
+ },
114
+ policies,
115
+ );
116
+ expect(allowed).toBe(false);
117
+ });
118
+
119
+ it("should allow all objects with type-level policy", () => {
120
+ const policies = [policy([id("channel", "")], ["retrieve"])];
121
+ const allowed = access.allowRequest(
122
+ {
123
+ subject: id("user", "u1"),
124
+ action: "retrieve",
125
+ objects: [id("channel", "1"), id("channel", "2"), id("channel", "99")],
126
+ },
127
+ policies,
128
+ );
129
+ expect(allowed).toBe(true);
130
+ });
131
+ });
132
+
133
+ describe("multiple policies", () => {
134
+ it("should allow when different policies cover different objects", () => {
135
+ const policies = [
136
+ policy([id("channel", "1")], ["retrieve"]),
137
+ policy([id("channel", "2")], ["retrieve"]),
138
+ ];
139
+ const allowed = access.allowRequest(
140
+ {
141
+ subject: id("user", "u1"),
142
+ action: "retrieve",
143
+ objects: [id("channel", "1"), id("channel", "2")],
144
+ },
145
+ policies,
146
+ );
147
+ expect(allowed).toBe(true);
148
+ });
149
+
150
+ it("should allow when one policy covers object and another has different action", () => {
151
+ const policies = [
152
+ policy([id("channel", "1")], ["delete"]),
153
+ policy([id("channel", "1")], ["retrieve"]),
154
+ ];
155
+ const allowed = access.allowRequest(
156
+ {
157
+ subject: id("user", "u1"),
158
+ action: "retrieve",
159
+ objects: id("channel", "1"),
160
+ },
161
+ policies,
162
+ );
163
+ expect(allowed).toBe(true);
164
+ });
165
+ });
166
+
167
+ describe("edge cases", () => {
168
+ it("should deny with empty policies", () => {
169
+ const allowed = access.allowRequest(
170
+ {
171
+ subject: id("user", "u1"),
172
+ action: "retrieve",
173
+ objects: id("channel", "1"),
174
+ },
175
+ [],
176
+ );
177
+ expect(allowed).toBe(false);
178
+ });
179
+
180
+ it("should allow with empty objects", () => {
181
+ const policies = [policy([id("channel", "1")], ["retrieve"])];
182
+ const allowed = access.allowRequest(
183
+ { subject: id("user", "u1"), action: "retrieve", objects: [] },
184
+ policies,
185
+ );
186
+ expect(allowed).toBe(true);
187
+ });
188
+ });
189
+ });
@@ -0,0 +1,84 @@
1
+ // Copyright 2025 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 { array } from "@synnaxlabs/x";
11
+
12
+ import { type Action } from "@/access/payload";
13
+ import { type Policy } from "@/access/policy/payload";
14
+ import { type ontology } from "@/ontology";
15
+
16
+ /**
17
+ * Request represents an access control request to check if a subject
18
+ * can perform an action on one or more objects.
19
+ */
20
+ export interface Request {
21
+ /** The subject making the request (typically a user) */
22
+ subject: ontology.ID;
23
+ /** The action being requested */
24
+ action: Action;
25
+ /** The objects being accessed */
26
+ objects: ontology.ID | ontology.ID[];
27
+ }
28
+
29
+ /**
30
+ * Checks if a request is allowed based on the provided policies.
31
+ * This is the client-side equivalent of the Go allowRequest function.
32
+ *
33
+ * @param req - The access request to check
34
+ * @param policies - The policies to check against
35
+ * @returns true if the request is allowed, false otherwise
36
+ *
37
+ * @remarks
38
+ * This function implements the following logic:
39
+ * - For each requested object, check if any policy allows the action
40
+ * - A policy allows an action if:
41
+ * 1. The policy's actions include the requested action or "all"
42
+ * 2. The policy's objects include the requested object, either:
43
+ * - Type-level match: policy object has empty key and matching type
44
+ * - Instance-level match: policy object has matching type and key
45
+ * - ALL requested objects must be allowed for the request to succeed
46
+ */
47
+ export const allowRequest = (req: Request, policies: Policy[]): boolean => {
48
+ const objs = array.toArray(req.objects);
49
+ const { action } = req;
50
+ for (const requestedObj of objs) {
51
+ let allowed = false;
52
+
53
+ for (const policy of policies) {
54
+ // Check if every requested action is allowed by this policy
55
+ const actionAllowed = policy.actions.includes(action);
56
+ if (!actionAllowed) continue;
57
+
58
+ // Check if any object in the policy matches the requested object
59
+ // Type-level match: empty key means the policy applies to all instances of this type
60
+ for (const policyObj of policy.objects)
61
+ if (policyObj.key === "") {
62
+ if (policyObj.type === requestedObj.type) {
63
+ allowed = true;
64
+ break;
65
+ }
66
+ } else if (
67
+ policyObj.type === requestedObj.type &&
68
+ policyObj.key === requestedObj.key
69
+ ) {
70
+ // Instance-level match: both type and key must match
71
+ allowed = true;
72
+ break;
73
+ }
74
+
75
+ if (allowed) break;
76
+ }
77
+
78
+ // If any object is not allowed, the entire request fails
79
+ if (!allowed) return false;
80
+ }
81
+
82
+ // All objects are allowed
83
+ return true;
84
+ };
@@ -8,4 +8,7 @@
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
10
  export * from "@/access/client";
11
+ export * from "@/access/enforce";
11
12
  export * from "@/access/payload";
13
+ export * from "@/access/policy";
14
+ export * from "@/access/role";
@@ -9,17 +9,5 @@
9
9
 
10
10
  import { z } from "zod";
11
11
 
12
- export const ALL_ACTION = "all";
13
- export const CREATE_ACTION = "create";
14
- export const DELETE_ACTION = "delete";
15
- export const RETRIEVE_ACTION = "retrieve";
16
- export const UPDATE_ACTION = "update";
17
-
18
- export const actionZ = z.enum([
19
- ALL_ACTION,
20
- CREATE_ACTION,
21
- DELETE_ACTION,
22
- RETRIEVE_ACTION,
23
- UPDATE_ACTION,
24
- ]);
12
+ export const actionZ = z.enum(["create", "delete", "retrieve", "update"]);
25
13
  export type Action = z.infer<typeof actionZ>;
@@ -0,0 +1,147 @@
1
+ // Copyright 2025 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 { describe, expect, it } from "vitest";
11
+
12
+ import { policy } from "@/access/policy";
13
+ import { AuthError, NotFoundError } from "@/errors";
14
+ import { createTestClientWithPolicy } from "@/testutil/access";
15
+ import { createTestClient } from "@/testutil/client";
16
+
17
+ const client = createTestClient();
18
+
19
+ describe("policy", () => {
20
+ describe("retrieve", () => {
21
+ it("should filter by internal flag when retrieving policies", async () => {
22
+ // Create a non-internal policy
23
+ const created = await client.access.policies.create({
24
+ name: "test-non-internal",
25
+ objects: [],
26
+ actions: ["retrieve"],
27
+ });
28
+
29
+ // Retrieve only internal policies (built-in system policies)
30
+ const internalPolicies = await client.access.policies.retrieve({
31
+ internal: true,
32
+ });
33
+ expect(internalPolicies.length).toBeGreaterThan(0);
34
+ expect(internalPolicies.every((p) => p.internal === true)).toBe(true);
35
+ expect(internalPolicies.find((p) => p.key === created.key)).toBeUndefined();
36
+
37
+ // Retrieve only non-internal policies
38
+ const nonInternalPolicies = await client.access.policies.retrieve({
39
+ internal: false,
40
+ });
41
+ expect(nonInternalPolicies.every((p) => p.internal !== true)).toBe(true);
42
+ expect(nonInternalPolicies.find((p) => p.key === created.key)).toBeDefined();
43
+ });
44
+ });
45
+
46
+ describe("access control", () => {
47
+ it("should deny access when no matching policy exists", async () => {
48
+ // Create a user with no policy for retrieving policies
49
+ const userClient = await createTestClientWithPolicy(client, {
50
+ name: "test",
51
+ objects: [],
52
+ actions: [],
53
+ });
54
+ const randomPolicy = await client.access.policies.create({
55
+ name: "test",
56
+ objects: [],
57
+ actions: ["retrieve"],
58
+ });
59
+ await expect(
60
+ userClient.access.policies.retrieve({ key: randomPolicy.key }),
61
+ ).rejects.toThrow(AuthError);
62
+ });
63
+
64
+ it("should allow the caller to retrieve policies with the correct policy", async () => {
65
+ const userClient = await createTestClientWithPolicy(client, {
66
+ name: "test",
67
+ objects: [policy.ontologyID("")],
68
+ actions: ["retrieve"],
69
+ });
70
+ const randomPolicy = await client.access.policies.create({
71
+ name: "test",
72
+ objects: [],
73
+ actions: ["retrieve"],
74
+ });
75
+ const retrieved = await userClient.access.policies.retrieve({
76
+ key: randomPolicy.key,
77
+ });
78
+ expect(retrieved.key).toBe(randomPolicy.key);
79
+ expect(retrieved.name).toBe(randomPolicy.name);
80
+ expect(retrieved.objects).toEqual(randomPolicy.objects);
81
+ expect(retrieved.actions).toEqual(randomPolicy.actions);
82
+ });
83
+
84
+ it("should allow the caller to create policies with the correct policy", async () => {
85
+ const userClient = await createTestClientWithPolicy(client, {
86
+ name: "test",
87
+ objects: [policy.ontologyID("")],
88
+ actions: ["create"],
89
+ });
90
+ await userClient.access.policies.create({
91
+ name: "test",
92
+ objects: [],
93
+ actions: ["retrieve"],
94
+ });
95
+ });
96
+
97
+ it("should deny access when no create policy exists", async () => {
98
+ // Create a user with no create policy for policies
99
+ const userClient = await createTestClientWithPolicy(client, {
100
+ name: "test",
101
+ objects: [policy.ontologyID("")],
102
+ actions: ["retrieve"],
103
+ });
104
+ await expect(
105
+ userClient.access.policies.create({
106
+ name: "test",
107
+ objects: [],
108
+ actions: ["retrieve"],
109
+ }),
110
+ ).rejects.toThrow(AuthError);
111
+ });
112
+
113
+ it("should allow the caller to delete policies with the correct policy", async () => {
114
+ const userClient = await createTestClientWithPolicy(client, {
115
+ name: "test",
116
+ objects: [policy.ontologyID("")],
117
+ actions: ["delete"],
118
+ });
119
+ const randomPolicy = await client.access.policies.create({
120
+ name: "test",
121
+ objects: [],
122
+ actions: ["retrieve"],
123
+ });
124
+ await userClient.access.policies.delete(randomPolicy.key);
125
+ await expect(
126
+ userClient.access.policies.retrieve({ key: randomPolicy.key }),
127
+ ).rejects.toThrow(NotFoundError);
128
+ });
129
+
130
+ it("should deny access when no delete policy exists", async () => {
131
+ // Create a user with no delete policy for policies
132
+ const userClient = await createTestClientWithPolicy(client, {
133
+ name: "test",
134
+ objects: [policy.ontologyID("")],
135
+ actions: ["retrieve"],
136
+ });
137
+ const randomPolicy = await client.access.policies.create({
138
+ name: "test",
139
+ objects: [],
140
+ actions: ["retrieve"],
141
+ });
142
+ await expect(userClient.access.policies.delete(randomPolicy.key)).rejects.toThrow(
143
+ AuthError,
144
+ );
145
+ });
146
+ });
147
+ });
@@ -21,9 +21,15 @@ import {
21
21
  } from "@/access/policy/payload";
22
22
  import { ontology } from "@/ontology";
23
23
 
24
+ export const SET_CHANNEL_NAME = "sy_policy_set";
25
+ export const DELETE_CHANNEL_NAME = "sy_policy_delete";
26
+
24
27
  const retrieveRequestZ = z.object({
25
28
  keys: keyZ.array().optional(),
26
29
  subjects: ontology.idZ.array().optional(),
30
+ limit: z.number().optional(),
31
+ offset: z.number().optional(),
32
+ internal: z.boolean().optional(),
27
33
  });
28
34
 
29
35
  const keyRetrieveRequestZ = z
@@ -49,15 +55,18 @@ export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
49
55
 
50
56
  const retrieveResZ = z.object({ policies: array.nullableZ(policyZ) });
51
57
 
52
- const createReqZ = z.object({ policies: policyZ.partial({ key: true }).array() });
58
+ const singleCreateArgsZ = newZ.transform((p) => ({ policies: [p] }));
59
+ export type SingleCreateArgs = z.input<typeof singleCreateArgsZ>;
60
+
61
+ export const multipleCreateArgsZ = newZ.array().transform((policies) => ({ policies }));
62
+
63
+ export const createArgsZ = z.union([singleCreateArgsZ, multipleCreateArgsZ]);
64
+ export type CreateArgs = z.input<typeof createArgsZ>;
65
+
53
66
  const createResZ = z.object({ policies: policyZ.array() });
54
67
  const deleteReqZ = z.object({ keys: keyZ.array() });
55
68
  const deleteResZ = z.object({});
56
69
 
57
- const RETRIEVE_ENDPOINT = "/access/policy/retrieve";
58
- const CREATE_ENDPOINT = "/access/policy/create";
59
- const DELETE_ENDPOINT = "/access/policy/delete";
60
-
61
70
  export class Client {
62
71
  private readonly client: UnaryClient;
63
72
 
@@ -67,19 +76,13 @@ export class Client {
67
76
 
68
77
  async create(policy: New): Promise<Policy>;
69
78
  async create(policies: New[]): Promise<Policy[]>;
70
- async create(policies: New | New[]): Promise<Policy | Policy[]> {
79
+ async create(policies: CreateArgs): Promise<Policy | Policy[]> {
71
80
  const isMany = Array.isArray(policies);
72
- const parsedPolicies = newZ.array().parse(array.toArray(policies));
73
- const req = parsedPolicies.map((policy) => ({
74
- objects: array.toArray(policy.objects),
75
- actions: array.toArray(policy.actions),
76
- subjects: array.toArray(policy.subjects),
77
- }));
78
- const res = await sendRequired<typeof createReqZ, typeof createResZ>(
81
+ const res = await sendRequired<typeof createArgsZ, typeof createResZ>(
79
82
  this.client,
80
- CREATE_ENDPOINT,
81
- { policies: req },
82
- createReqZ,
83
+ "/access/policy/create",
84
+ policies,
85
+ createArgsZ,
83
86
  createResZ,
84
87
  );
85
88
  return isMany ? res.policies : res.policies[0];
@@ -91,7 +94,7 @@ export class Client {
91
94
  const isSingle = "key" in args;
92
95
  const res = await sendRequired<typeof retrieveArgsZ, typeof retrieveResZ>(
93
96
  this.client,
94
- RETRIEVE_ENDPOINT,
97
+ "/access/policy/retrieve",
95
98
  args,
96
99
  retrieveArgsZ,
97
100
  retrieveResZ,
@@ -104,17 +107,10 @@ export class Client {
104
107
  async delete(keys: Key | Key[]): Promise<void> {
105
108
  await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
106
109
  this.client,
107
- DELETE_ENDPOINT,
110
+ "/access/policy/delete",
108
111
  { keys: array.toArray(keys) },
109
112
  deleteReqZ,
110
113
  deleteResZ,
111
114
  );
112
115
  }
113
116
  }
114
-
115
- export const ontologyID = (key: Key): ontology.ID => ({ type: "policy", key });
116
-
117
- export const ALLOW_ALL_ONTOLOGY_ID: ontology.ID = {
118
- type: "allow_all",
119
- key: "",
120
- };