@synnaxlabs/client 0.48.0 → 0.49.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 +6 -6
- package/dist/client.cjs +33 -31
- package/dist/client.js +6522 -6167
- package/dist/src/access/client.d.ts +3 -1
- package/dist/src/access/client.d.ts.map +1 -1
- package/dist/src/access/enforce.d.ts +35 -0
- package/dist/src/access/enforce.d.ts.map +1 -0
- package/dist/src/access/enforce.spec.d.ts +2 -0
- package/dist/src/access/enforce.spec.d.ts.map +1 -0
- package/dist/src/access/external.d.ts +3 -0
- package/dist/src/access/external.d.ts.map +1 -1
- package/dist/src/access/payload.d.ts +0 -6
- package/dist/src/access/payload.d.ts.map +1 -1
- package/dist/src/access/policy/access.spec.d.ts +2 -0
- package/dist/src/access/policy/access.spec.d.ts.map +1 -0
- package/dist/src/access/policy/client.d.ts +485 -31
- package/dist/src/access/policy/client.d.ts.map +1 -1
- package/dist/src/access/policy/payload.d.ts +36 -113
- package/dist/src/access/policy/payload.d.ts.map +1 -1
- package/dist/src/access/role/client.d.ts +135 -0
- package/dist/src/access/role/client.d.ts.map +1 -0
- package/dist/src/access/role/external.d.ts.map +1 -0
- package/dist/src/access/role/index.d.ts +2 -0
- package/dist/src/access/role/index.d.ts.map +1 -0
- package/dist/src/access/role/payload.d.ts +27 -0
- package/dist/src/access/role/payload.d.ts.map +1 -0
- package/dist/src/access/role/role.spec.d.ts +2 -0
- package/dist/src/access/role/role.spec.d.ts.map +1 -0
- package/dist/src/arc/access.spec.d.ts +2 -0
- package/dist/src/arc/access.spec.d.ts.map +1 -0
- package/dist/src/arc/client.d.ts +5 -14
- package/dist/src/arc/client.d.ts.map +1 -1
- package/dist/src/arc/payload.d.ts +11 -2
- package/dist/src/arc/payload.d.ts.map +1 -1
- package/dist/src/auth/auth.d.ts +5 -3
- package/dist/src/auth/auth.d.ts.map +1 -1
- package/dist/src/channel/access.spec.d.ts +2 -0
- package/dist/src/channel/access.spec.d.ts.map +1 -0
- package/dist/src/channel/client.d.ts +0 -1
- package/dist/src/channel/client.d.ts.map +1 -1
- package/dist/src/channel/payload.d.ts +18 -8
- package/dist/src/channel/payload.d.ts.map +1 -1
- package/dist/src/channel/payload.spec.d.ts +2 -0
- package/dist/src/channel/payload.spec.d.ts.map +1 -0
- package/dist/src/channel/retriever.d.ts +4 -6
- package/dist/src/channel/retriever.d.ts.map +1 -1
- package/dist/src/channel/writer.d.ts.map +1 -1
- package/dist/src/client.d.ts +9 -5
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/device/access.spec.d.ts +2 -0
- package/dist/src/device/access.spec.d.ts.map +1 -0
- package/dist/src/{hardware/device → device}/client.d.ts +14 -7
- package/dist/src/device/client.d.ts.map +1 -0
- package/dist/src/device/device.spec.d.ts.map +1 -0
- package/dist/src/device/external.d.ts.map +1 -0
- package/dist/src/device/index.d.ts.map +1 -0
- package/dist/src/{hardware/device → device}/payload.d.ts +1 -1
- package/dist/src/device/payload.d.ts.map +1 -0
- package/dist/src/errors.d.ts +3 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/framer/client.d.ts +11 -1
- package/dist/src/framer/client.d.ts.map +1 -1
- package/dist/src/framer/frame.d.ts +10 -5
- package/dist/src/framer/frame.d.ts.map +1 -1
- package/dist/src/framer/iterator.d.ts +3 -3
- package/dist/src/framer/reader.d.ts +16 -0
- package/dist/src/framer/reader.d.ts.map +1 -0
- package/dist/src/framer/reader.spec.d.ts +2 -0
- package/dist/src/framer/reader.spec.d.ts.map +1 -0
- package/dist/src/framer/streamer.d.ts +24 -21
- package/dist/src/framer/streamer.d.ts.map +1 -1
- package/dist/src/framer/writer.d.ts +13 -13
- package/dist/src/index.d.ts +4 -5
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/label/access.spec.d.ts +2 -0
- package/dist/src/label/access.spec.d.ts.map +1 -0
- package/dist/src/label/client.d.ts +20 -11
- package/dist/src/label/client.d.ts.map +1 -1
- package/dist/src/ontology/client.d.ts +6 -6
- package/dist/src/ontology/client.d.ts.map +1 -1
- package/dist/src/ontology/group/access.spec.d.ts +2 -0
- package/dist/src/ontology/group/access.spec.d.ts.map +1 -0
- package/dist/src/ontology/group/client.d.ts +2 -2
- package/dist/src/ontology/group/client.d.ts.map +1 -1
- package/dist/src/ontology/group/payload.d.ts +1 -2
- package/dist/src/ontology/group/payload.d.ts.map +1 -1
- package/dist/src/ontology/payload.d.ts +23 -17
- package/dist/src/ontology/payload.d.ts.map +1 -1
- package/dist/src/ontology/writer.d.ts +10 -10
- package/dist/src/ontology/writer.d.ts.map +1 -1
- package/dist/src/rack/access.spec.d.ts +2 -0
- package/dist/src/rack/access.spec.d.ts.map +1 -0
- package/dist/src/{hardware/rack → rack}/client.d.ts +15 -8
- package/dist/src/rack/client.d.ts.map +1 -0
- package/dist/src/rack/external.d.ts.map +1 -0
- package/dist/src/rack/index.d.ts.map +1 -0
- package/dist/src/{hardware/rack → rack}/payload.d.ts +1 -1
- package/dist/src/rack/payload.d.ts.map +1 -0
- package/dist/src/rack/rack.spec.d.ts.map +1 -0
- package/dist/src/ranger/access.spec.d.ts +2 -0
- package/dist/src/ranger/access.spec.d.ts.map +1 -0
- package/dist/src/ranger/alias.d.ts +1 -8
- package/dist/src/ranger/alias.d.ts.map +1 -1
- package/dist/src/ranger/client.d.ts +12 -5
- package/dist/src/ranger/client.d.ts.map +1 -1
- package/dist/src/ranger/kv.d.ts +0 -3
- package/dist/src/ranger/kv.d.ts.map +1 -1
- package/dist/src/ranger/writer.d.ts +2 -2
- package/dist/src/ranger/writer.d.ts.map +1 -1
- package/dist/src/status/access.spec.d.ts +2 -0
- package/dist/src/status/access.spec.d.ts.map +1 -0
- package/dist/src/status/client.d.ts +4 -4
- package/dist/src/status/client.d.ts.map +1 -1
- package/dist/src/status/payload.d.ts +9 -2
- package/dist/src/status/payload.d.ts.map +1 -1
- package/dist/src/task/access.spec.d.ts +2 -0
- package/dist/src/task/access.spec.d.ts.map +1 -0
- package/dist/src/{hardware/task → task}/client.d.ts +26 -15
- package/dist/src/task/client.d.ts.map +1 -0
- package/dist/src/task/external.d.ts +3 -0
- package/dist/src/task/external.d.ts.map +1 -0
- package/dist/src/task/index.d.ts.map +1 -0
- package/dist/src/{hardware/task → task}/payload.d.ts +45 -6
- package/dist/src/task/payload.d.ts.map +1 -0
- package/dist/src/task/task.spec.d.ts.map +1 -0
- package/dist/src/testutil/access.d.ts +4 -0
- package/dist/src/testutil/access.d.ts.map +1 -0
- package/dist/src/transport.d.ts.map +1 -1
- package/dist/src/user/access.spec.d.ts +2 -0
- package/dist/src/user/access.spec.d.ts.map +1 -0
- package/dist/src/user/client.d.ts +10 -1
- package/dist/src/user/client.d.ts.map +1 -1
- package/dist/src/user/external.d.ts +1 -1
- package/dist/src/user/external.d.ts.map +1 -1
- package/dist/src/user/payload.d.ts.map +1 -1
- package/dist/src/workspace/access.spec.d.ts +2 -0
- package/dist/src/workspace/access.spec.d.ts.map +1 -0
- package/dist/src/workspace/client.d.ts +10 -5
- package/dist/src/workspace/client.d.ts.map +1 -1
- package/dist/src/workspace/lineplot/access.spec.d.ts +2 -0
- package/dist/src/workspace/lineplot/access.spec.d.ts.map +1 -0
- package/dist/src/workspace/lineplot/client.d.ts +8 -1
- package/dist/src/workspace/lineplot/client.d.ts.map +1 -1
- package/dist/src/workspace/log/access.spec.d.ts +2 -0
- package/dist/src/workspace/log/access.spec.d.ts.map +1 -0
- package/dist/src/workspace/log/client.d.ts +8 -1
- package/dist/src/workspace/log/client.d.ts.map +1 -1
- package/dist/src/workspace/schematic/access.spec.d.ts +2 -0
- package/dist/src/workspace/schematic/access.spec.d.ts.map +1 -0
- package/dist/src/workspace/schematic/client.d.ts +8 -1
- package/dist/src/workspace/schematic/client.d.ts.map +1 -1
- package/dist/src/workspace/schematic/symbol/access.spec.d.ts +2 -0
- package/dist/src/workspace/schematic/symbol/access.spec.d.ts.map +1 -0
- package/dist/src/workspace/schematic/symbol/client.d.ts +1 -5
- package/dist/src/workspace/schematic/symbol/client.d.ts.map +1 -1
- package/dist/src/workspace/schematic/symbol/payload.d.ts +2 -2
- package/dist/src/workspace/table/access.spec.d.ts +2 -0
- package/dist/src/workspace/table/access.spec.d.ts.map +1 -0
- package/dist/src/workspace/table/client.d.ts +8 -1
- package/dist/src/workspace/table/client.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/access/client.ts +5 -2
- package/src/access/enforce.spec.ts +189 -0
- package/src/access/enforce.ts +84 -0
- package/src/access/external.ts +3 -0
- package/src/access/payload.ts +1 -13
- package/src/access/policy/access.spec.ts +147 -0
- package/src/access/policy/client.ts +21 -25
- package/src/access/policy/payload.ts +9 -5
- package/src/access/role/client.ts +135 -0
- package/src/access/role/external.ts +11 -0
- package/src/{hardware → access/role}/index.ts +1 -1
- package/src/access/role/payload.ts +32 -0
- package/src/access/role/role.spec.ts +95 -0
- package/src/arc/access.spec.ts +143 -0
- package/src/arc/client.ts +7 -31
- package/src/arc/payload.ts +4 -0
- package/src/auth/auth.ts +33 -11
- package/src/channel/access.spec.ts +116 -0
- package/src/channel/channel.spec.ts +63 -73
- package/src/channel/client.ts +2 -8
- package/src/channel/payload.spec.ts +171 -0
- package/src/channel/payload.ts +35 -7
- package/src/channel/retriever.ts +10 -11
- package/src/channel/writer.ts +3 -7
- package/src/client.ts +14 -18
- package/src/device/access.spec.ts +159 -0
- package/src/{hardware/device → device}/client.ts +12 -21
- package/src/{hardware/device → device}/device.spec.ts +70 -34
- package/src/device/external.ts +11 -0
- package/src/{hardware/rack → device}/index.ts +1 -1
- package/src/{hardware/device → device}/payload.ts +3 -3
- package/src/errors.ts +2 -0
- package/src/framer/adapter.spec.ts +14 -14
- package/src/framer/client.spec.ts +14 -20
- package/src/framer/client.ts +15 -20
- package/src/framer/deleter.spec.ts +1 -1
- package/src/framer/frame.spec.ts +131 -0
- package/src/framer/frame.ts +10 -2
- package/src/framer/iterator.ts +3 -3
- package/src/framer/reader.spec.ts +736 -0
- package/src/framer/reader.ts +265 -0
- package/src/framer/streamer.spec.ts +100 -12
- package/src/framer/streamer.ts +29 -9
- package/src/framer/writer.spec.ts +5 -5
- package/src/index.ts +4 -5
- package/src/label/access.spec.ts +109 -0
- package/src/label/client.ts +10 -14
- package/src/ontology/client.ts +4 -6
- package/src/ontology/group/access.spec.ts +77 -0
- package/src/ontology/group/client.ts +3 -7
- package/src/ontology/group/group.spec.ts +18 -0
- package/src/ontology/group/payload.ts +2 -2
- package/src/ontology/ontology.spec.ts +2 -0
- package/src/ontology/payload.ts +18 -2
- package/src/ontology/writer.ts +3 -7
- package/src/rack/access.spec.ts +102 -0
- package/src/{hardware/rack → rack}/client.ts +14 -19
- package/src/{hardware/device/index.ts → rack/external.ts} +2 -1
- package/src/{hardware/external.ts → rack/index.ts} +1 -1
- package/src/{hardware/rack → rack}/payload.ts +2 -2
- package/src/{hardware/rack → rack}/rack.spec.ts +43 -17
- package/src/ranger/access.spec.ts +115 -0
- package/src/ranger/alias.ts +6 -14
- package/src/ranger/client.ts +13 -14
- package/src/ranger/kv.ts +7 -9
- package/src/ranger/ranger.spec.ts +4 -4
- package/src/ranger/writer.ts +3 -7
- package/src/status/access.spec.ts +129 -0
- package/src/status/client.ts +5 -9
- package/src/status/payload.ts +3 -2
- package/src/task/access.spec.ts +131 -0
- package/src/{hardware/task → task}/client.ts +50 -25
- package/src/task/external.ts +11 -0
- package/src/{hardware/task → task}/index.ts +1 -1
- package/src/{hardware/task → task}/payload.ts +22 -3
- package/src/{hardware/task → task}/task.spec.ts +197 -34
- package/src/testutil/access.ts +34 -0
- package/src/testutil/channels.ts +3 -3
- package/src/transport.ts +1 -3
- package/src/user/access.spec.ts +107 -0
- package/src/user/client.ts +10 -12
- package/src/user/external.ts +12 -1
- package/src/user/payload.ts +3 -5
- package/src/workspace/access.spec.ts +108 -0
- package/src/workspace/client.ts +11 -27
- package/src/workspace/lineplot/access.spec.ts +134 -0
- package/src/workspace/lineplot/client.ts +8 -13
- package/src/workspace/log/access.spec.ts +134 -0
- package/src/workspace/log/client.ts +8 -13
- package/src/workspace/schematic/access.spec.ts +134 -0
- package/src/workspace/schematic/client.ts +9 -18
- package/src/workspace/schematic/symbol/access.spec.ts +172 -0
- package/src/workspace/schematic/symbol/client.ts +6 -17
- package/src/workspace/schematic/symbol/payload.ts +1 -1
- package/src/workspace/table/access.spec.ts +134 -0
- package/src/workspace/table/client.ts +8 -13
- package/dist/src/access/policy/policy.spec.d.ts +0 -2
- package/dist/src/access/policy/policy.spec.d.ts.map +0 -1
- package/dist/src/hardware/client.d.ts +0 -10
- package/dist/src/hardware/client.d.ts.map +0 -1
- package/dist/src/hardware/device/client.d.ts.map +0 -1
- package/dist/src/hardware/device/device.spec.d.ts.map +0 -1
- package/dist/src/hardware/device/external.d.ts.map +0 -1
- package/dist/src/hardware/device/index.d.ts.map +0 -1
- package/dist/src/hardware/device/payload.d.ts.map +0 -1
- package/dist/src/hardware/external.d.ts +0 -2
- package/dist/src/hardware/external.d.ts.map +0 -1
- package/dist/src/hardware/index.d.ts +0 -2
- package/dist/src/hardware/index.d.ts.map +0 -1
- package/dist/src/hardware/rack/client.d.ts.map +0 -1
- package/dist/src/hardware/rack/external.d.ts.map +0 -1
- package/dist/src/hardware/rack/index.d.ts.map +0 -1
- package/dist/src/hardware/rack/payload.d.ts.map +0 -1
- package/dist/src/hardware/rack/rack.spec.d.ts.map +0 -1
- package/dist/src/hardware/task/client.d.ts.map +0 -1
- package/dist/src/hardware/task/external.d.ts.map +0 -1
- package/dist/src/hardware/task/index.d.ts.map +0 -1
- package/dist/src/hardware/task/payload.d.ts.map +0 -1
- package/dist/src/hardware/task/task.spec.d.ts.map +0 -1
- package/dist/src/user/retriever.d.ts +0 -16
- package/dist/src/user/retriever.d.ts.map +0 -1
- package/dist/src/user/writer.d.ts +0 -11
- package/dist/src/user/writer.d.ts.map +0 -1
- package/src/access/policy/policy.spec.ts +0 -329
- package/src/hardware/client.ts +0 -24
- package/src/hardware/device/external.ts +0 -11
- package/src/hardware/rack/external.ts +0 -11
- package/src/hardware/task/external.ts +0 -11
- package/src/user/retriever.ts +0 -41
- package/src/user/writer.ts +0 -84
- /package/dist/src/{hardware/device → access/role}/external.d.ts +0 -0
- /package/dist/src/{hardware/device → device}/device.spec.d.ts +0 -0
- /package/dist/src/{hardware/rack → device}/external.d.ts +0 -0
- /package/dist/src/{hardware/device → device}/index.d.ts +0 -0
- /package/dist/src/{hardware/task → rack}/external.d.ts +0 -0
- /package/dist/src/{hardware/rack → rack}/index.d.ts +0 -0
- /package/dist/src/{hardware/rack → rack}/rack.spec.d.ts +0 -0
- /package/dist/src/{hardware/task → task}/index.d.ts +0 -0
- /package/dist/src/{hardware/task → task}/task.spec.d.ts +0 -0
|
@@ -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:
|
|
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,
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.49.2",
|
|
4
4
|
"description": "The Synnax Client Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"synnax",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"async-mutex": "^0.5.0",
|
|
28
28
|
"zod": "^4.1.12",
|
|
29
|
-
"@synnaxlabs/freighter": "^0.
|
|
30
|
-
"@synnaxlabs/x": "^0.
|
|
29
|
+
"@synnaxlabs/freighter": "^0.49.0",
|
|
30
|
+
"@synnaxlabs/x": "^0.49.2"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@vitest/coverage-v8": "^3.2.4",
|
package/src/access/client.ts
CHANGED
|
@@ -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
|
|
16
|
+
readonly policies: policy.Client;
|
|
17
|
+
readonly roles: role.Client;
|
|
16
18
|
|
|
17
19
|
constructor(client: UnaryClient) {
|
|
18
|
-
this.
|
|
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
|
+
};
|
package/src/access/external.ts
CHANGED
package/src/access/payload.ts
CHANGED
|
@@ -9,17 +9,5 @@
|
|
|
9
9
|
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
|
|
12
|
-
export const
|
|
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
|
|
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:
|
|
79
|
+
async create(policies: CreateArgs): Promise<Policy | Policy[]> {
|
|
71
80
|
const isMany = Array.isArray(policies);
|
|
72
|
-
const
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
};
|
|
@@ -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 { array } from "@synnaxlabs/x";
|
|
10
|
+
import { array, zod } from "@synnaxlabs/x";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
import { actionZ } from "@/access/payload";
|
|
@@ -18,16 +18,20 @@ export type Key = z.infer<typeof keyZ>;
|
|
|
18
18
|
|
|
19
19
|
export const policyZ = z.object({
|
|
20
20
|
key: keyZ,
|
|
21
|
-
|
|
21
|
+
name: z.string(),
|
|
22
22
|
objects: array.nullableZ(ontology.idZ),
|
|
23
23
|
actions: array.nullableZ(actionZ),
|
|
24
|
+
internal: z.boolean(),
|
|
24
25
|
});
|
|
25
26
|
export interface Policy extends z.infer<typeof policyZ> {}
|
|
26
27
|
|
|
27
28
|
export const newZ = z.object({
|
|
28
29
|
key: keyZ.optional(),
|
|
29
|
-
|
|
30
|
-
objects:
|
|
31
|
-
actions:
|
|
30
|
+
name: z.string(),
|
|
31
|
+
objects: zod.toArray(ontology.idZ),
|
|
32
|
+
actions: zod.toArray(actionZ),
|
|
32
33
|
});
|
|
33
34
|
export interface New extends z.input<typeof newZ> {}
|
|
35
|
+
|
|
36
|
+
export const ontologyID = ontology.createIDFactory<Key>("policy");
|
|
37
|
+
export const TYPE_ONTOLOGY_ID = ontologyID("");
|