@valon-technologies/gestalt 0.0.1-alpha.18 → 0.0.1-alpha.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -12
- package/package.json +5 -3
- package/src/agent-conversions.ts +201 -0
- package/src/agent-manager.ts +272 -83
- package/src/agent.ts +1023 -224
- package/src/api.ts +42 -0
- package/src/auth.ts +3 -3
- package/src/authorization.ts +1700 -51
- package/src/cache.ts +3 -3
- package/src/catalog.ts +22 -0
- package/src/http-subject.ts +9 -2
- package/src/index.ts +191 -17
- package/src/indexeddb.ts +3 -15
- package/src/internal/gen/v1/agent_pb.ts +137 -51
- package/src/internal/gen/v1/authorization_pb.ts +505 -27
- package/src/internal/gen/v1/plugin_pb.ts +67 -21
- package/src/internal/gen/v1/pluginruntime_pb.ts +95 -6
- package/src/internal/gen/v1/workflow_pb.ts +344 -62
- package/src/invoker.ts +6 -35
- package/src/plugin.ts +12 -12
- package/src/pluginruntime.ts +337 -49
- package/src/protocol/v1.ts +19 -0
- package/src/protocol-internal.ts +19 -0
- package/src/protocol.ts +183 -0
- package/src/provider-kind.ts +7 -3
- package/src/provider.ts +21 -13
- package/src/runtime-log-host.ts +80 -52
- package/src/runtime.ts +67 -0
- package/src/s3.ts +13 -28
- package/src/secrets.ts +3 -3
- package/src/workflow-manager.ts +350 -121
- package/src/workflow.ts +2598 -389
package/src/authorization.ts
CHANGED
|
@@ -1,60 +1,391 @@
|
|
|
1
1
|
import { connect } from "node:net";
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import { create } from "@bufbuild/protobuf";
|
|
4
|
+
import { EmptySchema } from "@bufbuild/protobuf/wkt";
|
|
4
5
|
import {
|
|
6
|
+
Code,
|
|
7
|
+
ConnectError,
|
|
5
8
|
createClient,
|
|
6
9
|
type Client,
|
|
7
10
|
type Interceptor,
|
|
11
|
+
type ServiceImpl,
|
|
8
12
|
} from "@connectrpc/connect";
|
|
9
13
|
import { createGrpcTransport } from "@connectrpc/connect-node";
|
|
10
14
|
|
|
11
15
|
import {
|
|
12
|
-
|
|
13
|
-
type ActionSearchResponse,
|
|
14
|
-
type AuthorizationMetadata,
|
|
15
|
-
AuthorizationProvider as AuthorizationProviderService,
|
|
16
|
-
type ReadRelationshipsResponse,
|
|
17
|
-
type ResourceSearchResponse,
|
|
18
|
-
type SubjectSearchResponse,
|
|
16
|
+
AccessDecisionSchema,
|
|
19
17
|
AccessEvaluationRequestSchema,
|
|
18
|
+
AccessEvaluationsRequestSchema,
|
|
19
|
+
AccessEvaluationsResponseSchema,
|
|
20
20
|
ActionSearchRequestSchema,
|
|
21
|
+
ActionSearchResponseSchema,
|
|
22
|
+
ActionSchema,
|
|
23
|
+
AuthorizationMetadataSchema,
|
|
24
|
+
AuthorizationModelRefSchema,
|
|
25
|
+
AuthorizationProvider as AuthorizationProviderService,
|
|
26
|
+
EffectiveSubjectSearchRequestSchema,
|
|
27
|
+
EffectiveSubjectSearchResponseSchema,
|
|
28
|
+
ExpandNodeSchema,
|
|
29
|
+
ExpandRequestSchema,
|
|
30
|
+
ExpandResponseSchema,
|
|
31
|
+
GetActiveModelResponseSchema,
|
|
32
|
+
ListModelsRequestSchema,
|
|
33
|
+
ListModelsResponseSchema,
|
|
21
34
|
ReadRelationshipsRequestSchema,
|
|
35
|
+
ReadRelationshipsResponseSchema,
|
|
36
|
+
RelationshipKeySchema,
|
|
37
|
+
RelationshipSchema,
|
|
38
|
+
RelationshipTargetSchema,
|
|
39
|
+
ResourceSchema,
|
|
22
40
|
ResourceSearchRequestSchema,
|
|
41
|
+
ResourceSearchResponseSchema,
|
|
42
|
+
SubjectSchema,
|
|
23
43
|
SubjectSearchRequestSchema,
|
|
44
|
+
SubjectSearchResponseSchema,
|
|
45
|
+
SubjectSetSchema,
|
|
46
|
+
WriteModelRequestSchema,
|
|
47
|
+
WriteRelationshipsRequestSchema,
|
|
48
|
+
type AccessDecision as ProtoAccessDecision,
|
|
49
|
+
type AccessEvaluationRequest as ProtoAccessEvaluationRequest,
|
|
50
|
+
type AccessEvaluationsRequest as ProtoAccessEvaluationsRequest,
|
|
51
|
+
type AccessEvaluationsResponse as ProtoAccessEvaluationsResponse,
|
|
52
|
+
type Action as ProtoAction,
|
|
53
|
+
type ActionSearchRequest as ProtoActionSearchRequest,
|
|
54
|
+
type ActionSearchResponse as ProtoActionSearchResponse,
|
|
55
|
+
type AuthorizationMetadata as ProtoAuthorizationMetadata,
|
|
56
|
+
type AuthorizationModel as ProtoAuthorizationModel,
|
|
57
|
+
type AuthorizationModelAction as ProtoAuthorizationModelAction,
|
|
58
|
+
type AuthorizationModelAllowedTarget as ProtoAuthorizationModelAllowedTarget,
|
|
59
|
+
type AuthorizationModelComputedUserset as ProtoAuthorizationModelComputedUserset,
|
|
60
|
+
type AuthorizationModelRef as ProtoAuthorizationModelRef,
|
|
61
|
+
type AuthorizationModelRelation as ProtoAuthorizationModelRelation,
|
|
62
|
+
type AuthorizationModelResourceType as ProtoAuthorizationModelResourceType,
|
|
63
|
+
type AuthorizationModelRewrite as ProtoAuthorizationModelRewrite,
|
|
64
|
+
type AuthorizationModelRewriteUnion as ProtoAuthorizationModelRewriteUnion,
|
|
65
|
+
type AuthorizationModelSubjectSetTarget as ProtoAuthorizationModelSubjectSetTarget,
|
|
66
|
+
type AuthorizationModelTupleToUserset as ProtoAuthorizationModelTupleToUserset,
|
|
67
|
+
type EffectiveSubjectSearchRequest as ProtoEffectiveSubjectSearchRequest,
|
|
68
|
+
type EffectiveSubjectSearchResponse as ProtoEffectiveSubjectSearchResponse,
|
|
69
|
+
type ExpandNode as ProtoExpandNode,
|
|
70
|
+
type ExpandRequest as ProtoExpandRequest,
|
|
71
|
+
type ExpandResponse as ProtoExpandResponse,
|
|
72
|
+
type GetActiveModelResponse as ProtoGetActiveModelResponse,
|
|
73
|
+
type ListModelsRequest as ProtoListModelsRequest,
|
|
74
|
+
type ListModelsResponse as ProtoListModelsResponse,
|
|
75
|
+
type ReadRelationshipsRequest as ProtoReadRelationshipsRequest,
|
|
76
|
+
type ReadRelationshipsResponse as ProtoReadRelationshipsResponse,
|
|
77
|
+
type Relationship as ProtoRelationship,
|
|
78
|
+
type RelationshipKey as ProtoRelationshipKey,
|
|
79
|
+
type RelationshipTarget as ProtoRelationshipTarget,
|
|
80
|
+
type Resource as ProtoResource,
|
|
81
|
+
type ResourceSearchRequest as ProtoResourceSearchRequest,
|
|
82
|
+
type ResourceSearchResponse as ProtoResourceSearchResponse,
|
|
83
|
+
type Subject as ProtoSubject,
|
|
84
|
+
type SubjectSearchRequest as ProtoSubjectSearchRequest,
|
|
85
|
+
type SubjectSearchResponse as ProtoSubjectSearchResponse,
|
|
86
|
+
type SubjectSet as ProtoSubjectSet,
|
|
87
|
+
type WriteModelRequest as ProtoWriteModelRequest,
|
|
88
|
+
type WriteRelationshipsRequest as ProtoWriteRelationshipsRequest,
|
|
24
89
|
} from "./internal/gen/v1/authorization_pb.ts";
|
|
90
|
+
import {
|
|
91
|
+
dateFromTimestamp,
|
|
92
|
+
timestampFromDate,
|
|
93
|
+
type JsonObjectInput,
|
|
94
|
+
} from "./protocol.ts";
|
|
95
|
+
import {
|
|
96
|
+
optionalObjectFromStruct,
|
|
97
|
+
optionalStruct,
|
|
98
|
+
} from "./protocol-internal.ts";
|
|
99
|
+
import type { MaybePromise } from "./api.ts";
|
|
100
|
+
import { ProviderBase, type ProviderBaseOptions } from "./provider.ts";
|
|
101
|
+
|
|
102
|
+
type AuthorizationProviderServiceImpl = Partial<
|
|
103
|
+
ServiceImpl<typeof AuthorizationProviderService>
|
|
104
|
+
>;
|
|
25
105
|
|
|
26
106
|
/**
|
|
27
107
|
* Environment variable containing the Unix socket path or relay target for the
|
|
28
|
-
*
|
|
108
|
+
* host authorization client exposed to plugins.
|
|
29
109
|
*/
|
|
30
110
|
export const ENV_AUTHORIZATION_SOCKET = "GESTALT_AUTHORIZATION_SOCKET";
|
|
31
|
-
export const ENV_AUTHORIZATION_SOCKET_TOKEN =
|
|
32
|
-
|
|
33
|
-
const AUTHORIZATION_RELAY_TOKEN_HEADER =
|
|
34
|
-
"x-gestalt-host-service-relay-token";
|
|
111
|
+
export const ENV_AUTHORIZATION_SOCKET_TOKEN = `${ENV_AUTHORIZATION_SOCKET}_TOKEN`;
|
|
112
|
+
const AUTHORIZATION_RELAY_TOKEN_HEADER = "x-gestalt-host-service-relay-token";
|
|
35
113
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
114
|
+
/** Subject type used for canonical Gestalt subject ids in managed grants. */
|
|
115
|
+
export const AUTHORIZATION_SUBJECT_TYPE_SUBJECT = "subject";
|
|
116
|
+
/** Managed authorization resource type for agent sessions. */
|
|
117
|
+
export const AGENT_SESSION_RESOURCE_TYPE = "agent_session";
|
|
118
|
+
/** Relation that grants view and edit access to an agent session. */
|
|
119
|
+
export const AGENT_SESSION_RELATION_EDITOR = "editor";
|
|
120
|
+
/** Action checked when reading a shared agent session. */
|
|
121
|
+
export const AGENT_SESSION_ACTION_VIEW = "view";
|
|
122
|
+
/** Action checked when creating turns or resolving interactions in a session. */
|
|
123
|
+
export const AGENT_SESSION_ACTION_EDIT = "edit";
|
|
124
|
+
|
|
125
|
+
export interface AuthorizationSubject {
|
|
126
|
+
type: string;
|
|
127
|
+
id: string;
|
|
128
|
+
properties?: JsonObjectInput | undefined;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export interface AuthorizationResource {
|
|
132
|
+
type: string;
|
|
133
|
+
id: string;
|
|
134
|
+
properties?: JsonObjectInput | undefined;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export interface AuthorizationSubjectSet {
|
|
138
|
+
resource?: AuthorizationResource | undefined;
|
|
139
|
+
relation: string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export type AuthorizationRelationshipTargetKind =
|
|
143
|
+
| { case: "subject"; value: AuthorizationSubject }
|
|
144
|
+
| { case: "resource"; value: AuthorizationResource }
|
|
145
|
+
| { case: "subjectSet"; value: AuthorizationSubjectSet }
|
|
146
|
+
| { case: undefined; value?: undefined };
|
|
147
|
+
|
|
148
|
+
export interface AuthorizationRelationshipTarget {
|
|
149
|
+
kind: AuthorizationRelationshipTargetKind;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export interface AuthorizationAction {
|
|
153
|
+
name: string;
|
|
154
|
+
properties?: JsonObjectInput | undefined;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface AuthorizationEvaluateInput {
|
|
158
|
+
subject?: AuthorizationSubject | undefined;
|
|
159
|
+
action?: AuthorizationAction | undefined;
|
|
160
|
+
resource?: AuthorizationResource | undefined;
|
|
161
|
+
context?: JsonObjectInput | undefined;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export interface AuthorizationDecision {
|
|
165
|
+
allowed?: boolean | undefined;
|
|
166
|
+
context?: JsonObjectInput | undefined;
|
|
167
|
+
modelId?: string | undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export interface AuthorizationEvaluateManyInput {
|
|
171
|
+
requests: readonly AuthorizationEvaluateInput[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export interface AuthorizationEvaluationsResponse {
|
|
175
|
+
decisions: readonly AuthorizationDecision[];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
export interface AuthorizationSearchResourcesInput {
|
|
179
|
+
subject?: AuthorizationSubject | undefined;
|
|
180
|
+
action?: AuthorizationAction | undefined;
|
|
181
|
+
resourceType?: string | undefined;
|
|
182
|
+
context?: JsonObjectInput | undefined;
|
|
183
|
+
pageSize?: number | undefined;
|
|
184
|
+
pageToken?: string | undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export interface AuthorizationResourceSearch {
|
|
188
|
+
resources: readonly AuthorizationResource[];
|
|
189
|
+
nextPageToken?: string | undefined;
|
|
190
|
+
modelId?: string | undefined;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export interface AuthorizationSearchSubjectsInput {
|
|
194
|
+
resource?: AuthorizationResource | undefined;
|
|
195
|
+
action?: AuthorizationAction | undefined;
|
|
196
|
+
subjectType?: string | undefined;
|
|
197
|
+
context?: JsonObjectInput | undefined;
|
|
198
|
+
pageSize?: number | undefined;
|
|
199
|
+
pageToken?: string | undefined;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface AuthorizationSubjectSearch {
|
|
203
|
+
subjects: readonly AuthorizationSubject[];
|
|
204
|
+
nextPageToken?: string | undefined;
|
|
205
|
+
modelId?: string | undefined;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface AuthorizationEffectiveSearchSubjectsInput {
|
|
209
|
+
resource?: AuthorizationResource | undefined;
|
|
210
|
+
action?: AuthorizationAction | undefined;
|
|
211
|
+
context?: JsonObjectInput | undefined;
|
|
212
|
+
pageSize?: number | undefined;
|
|
213
|
+
pageToken?: string | undefined;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
export interface AuthorizationEffectiveSubjectSearch {
|
|
217
|
+
targets: readonly AuthorizationRelationshipTarget[];
|
|
218
|
+
nextPageToken?: string | undefined;
|
|
219
|
+
modelId?: string | undefined;
|
|
220
|
+
truncated?: boolean | undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export interface AuthorizationSearchActionsInput {
|
|
224
|
+
subject?: AuthorizationSubject | undefined;
|
|
225
|
+
resource?: AuthorizationResource | undefined;
|
|
226
|
+
context?: JsonObjectInput | undefined;
|
|
227
|
+
pageSize?: number | undefined;
|
|
228
|
+
pageToken?: string | undefined;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
export interface AuthorizationActionSearch {
|
|
232
|
+
actions: readonly AuthorizationAction[];
|
|
233
|
+
nextPageToken?: string | undefined;
|
|
234
|
+
modelId?: string | undefined;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface AuthorizationMetadata {
|
|
238
|
+
capabilities?: readonly string[] | undefined;
|
|
239
|
+
activeModelId?: string | undefined;
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export interface AuthorizationRelationship {
|
|
243
|
+
subject?: AuthorizationSubject | undefined;
|
|
244
|
+
relation: string;
|
|
245
|
+
resource?: AuthorizationResource | undefined;
|
|
246
|
+
properties?: JsonObjectInput | undefined;
|
|
247
|
+
target?: AuthorizationRelationshipTarget | undefined;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
export interface AuthorizationRelationshipKey {
|
|
251
|
+
subject?: AuthorizationSubject | undefined;
|
|
252
|
+
relation: string;
|
|
253
|
+
resource?: AuthorizationResource | undefined;
|
|
254
|
+
target?: AuthorizationRelationshipTarget | undefined;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface AuthorizationReadRelationshipsInput {
|
|
258
|
+
subject?: AuthorizationSubject | undefined;
|
|
259
|
+
relation?: string | undefined;
|
|
260
|
+
resource?: AuthorizationResource | undefined;
|
|
261
|
+
pageSize?: number | undefined;
|
|
262
|
+
pageToken?: string | undefined;
|
|
263
|
+
modelId?: string | undefined;
|
|
264
|
+
target?: AuthorizationRelationshipTarget | undefined;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export interface AuthorizationReadRelationships {
|
|
268
|
+
relationships: readonly AuthorizationRelationship[];
|
|
269
|
+
nextPageToken?: string | undefined;
|
|
270
|
+
modelId?: string | undefined;
|
|
271
|
+
}
|
|
51
272
|
|
|
52
|
-
export
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
273
|
+
export interface AuthorizationWriteRelationshipsInput {
|
|
274
|
+
writes?: readonly AuthorizationRelationship[] | undefined;
|
|
275
|
+
deletes?: readonly AuthorizationRelationshipKey[] | undefined;
|
|
276
|
+
modelId?: string | undefined;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
export interface AuthorizationModel {
|
|
280
|
+
version?: number | undefined;
|
|
281
|
+
resourceTypes?: readonly AuthorizationModelResourceType[] | undefined;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export interface AuthorizationModelResourceType {
|
|
285
|
+
name: string;
|
|
286
|
+
relations?: readonly AuthorizationModelRelation[] | undefined;
|
|
287
|
+
actions?: readonly AuthorizationModelAction[] | undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
export interface AuthorizationModelRelation {
|
|
291
|
+
name: string;
|
|
292
|
+
subjectTypes?: readonly string[] | undefined;
|
|
293
|
+
allowedTargets?: readonly AuthorizationModelAllowedTarget[] | undefined;
|
|
294
|
+
rewrite?: AuthorizationModelRewrite | undefined;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
export interface AuthorizationModelAction {
|
|
298
|
+
name: string;
|
|
299
|
+
relations?: readonly string[] | undefined;
|
|
300
|
+
rewrite?: AuthorizationModelRewrite | undefined;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export type AuthorizationModelAllowedTargetKind =
|
|
304
|
+
| { case: "subjectType"; value: string }
|
|
305
|
+
| { case: "resourceType"; value: string }
|
|
306
|
+
| { case: "subjectSet"; value: AuthorizationModelSubjectSetTarget }
|
|
307
|
+
| { case: undefined; value?: undefined };
|
|
308
|
+
|
|
309
|
+
export interface AuthorizationModelAllowedTarget {
|
|
310
|
+
kind: AuthorizationModelAllowedTargetKind;
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
export interface AuthorizationModelSubjectSetTarget {
|
|
314
|
+
resourceType: string;
|
|
315
|
+
relation: string;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export type AuthorizationModelRewriteKind =
|
|
319
|
+
| { case: "this"; value: AuthorizationModelRewriteThis }
|
|
320
|
+
| { case: "computedUserset"; value: AuthorizationModelComputedUserset }
|
|
321
|
+
| { case: "tupleToUserset"; value: AuthorizationModelTupleToUserset }
|
|
322
|
+
| { case: "union"; value: AuthorizationModelRewriteUnion }
|
|
323
|
+
| { case: undefined; value?: undefined };
|
|
324
|
+
|
|
325
|
+
export interface AuthorizationModelRewrite {
|
|
326
|
+
kind: AuthorizationModelRewriteKind;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
export interface AuthorizationModelRewriteThis {}
|
|
330
|
+
|
|
331
|
+
export interface AuthorizationModelComputedUserset {
|
|
332
|
+
relation: string;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
export interface AuthorizationModelTupleToUserset {
|
|
336
|
+
tuplesetRelation: string;
|
|
337
|
+
computedRelation: string;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
export interface AuthorizationModelRewriteUnion {
|
|
341
|
+
children?: readonly AuthorizationModelRewrite[] | undefined;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export interface AuthorizationModelRef {
|
|
345
|
+
id: string;
|
|
346
|
+
version: string;
|
|
347
|
+
createdAt?: Date | undefined;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
export interface AuthorizationExpandInput {
|
|
351
|
+
resource?: AuthorizationResource | undefined;
|
|
352
|
+
relation?: string | undefined;
|
|
353
|
+
context?: JsonObjectInput | undefined;
|
|
354
|
+
maxDepth?: number | undefined;
|
|
355
|
+
modelId?: string | undefined;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
export interface AuthorizationExpandNode {
|
|
359
|
+
target?: AuthorizationRelationshipTarget | undefined;
|
|
360
|
+
relation?: string | undefined;
|
|
361
|
+
children?: readonly AuthorizationExpandNode[] | undefined;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export interface AuthorizationExpand {
|
|
365
|
+
root?: AuthorizationExpandNode | undefined;
|
|
366
|
+
truncated?: boolean | undefined;
|
|
367
|
+
cycleDetected?: boolean | undefined;
|
|
368
|
+
maxDepthReached?: boolean | undefined;
|
|
369
|
+
modelId?: string | undefined;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export interface AuthorizationGetActiveModel {
|
|
373
|
+
model?: AuthorizationModelRef | undefined;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export interface AuthorizationListModelsInput {
|
|
377
|
+
pageSize?: number | undefined;
|
|
378
|
+
pageToken?: string | undefined;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
export interface AuthorizationListModels {
|
|
382
|
+
models?: readonly AuthorizationModelRef[] | undefined;
|
|
383
|
+
nextPageToken?: string | undefined;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
export interface AuthorizationWriteModelInput {
|
|
387
|
+
model?: AuthorizationModel | undefined;
|
|
388
|
+
}
|
|
58
389
|
|
|
59
390
|
const sharedAuthorizationTransport: {
|
|
60
391
|
target: string;
|
|
@@ -67,12 +398,18 @@ const sharedAuthorizationTransport: {
|
|
|
67
398
|
};
|
|
68
399
|
|
|
69
400
|
/**
|
|
70
|
-
*
|
|
401
|
+
* Client for the host-configured authorization provider.
|
|
402
|
+
*
|
|
403
|
+
* The client accepts plain SDK request objects and keeps transport message
|
|
404
|
+
* construction inside the SDK.
|
|
71
405
|
*/
|
|
72
406
|
export class AuthorizationClient {
|
|
73
407
|
private readonly client: Client<typeof AuthorizationProviderService>;
|
|
74
408
|
|
|
75
|
-
constructor(
|
|
409
|
+
constructor(
|
|
410
|
+
socketTarget?: string,
|
|
411
|
+
relayToken = process.env[ENV_AUTHORIZATION_SOCKET_TOKEN]?.trim() ?? "",
|
|
412
|
+
) {
|
|
76
413
|
const resolvedTarget = resolveAuthorizationSocketTarget(socketTarget);
|
|
77
414
|
const transportOptions = authorizationTransportOptions(resolvedTarget);
|
|
78
415
|
const transport = createGrpcTransport({
|
|
@@ -94,42 +431,423 @@ export class AuthorizationClient {
|
|
|
94
431
|
|
|
95
432
|
async evaluate(
|
|
96
433
|
request: AuthorizationEvaluateInput,
|
|
97
|
-
): Promise<
|
|
98
|
-
return
|
|
434
|
+
): Promise<AuthorizationDecision> {
|
|
435
|
+
return authorizationDecisionFromProto(
|
|
436
|
+
await this.client.evaluate(authorizationEvaluateInputToProto(request)),
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
async evaluateMany(
|
|
441
|
+
request: AuthorizationEvaluateManyInput,
|
|
442
|
+
): Promise<AuthorizationEvaluationsResponse> {
|
|
443
|
+
return authorizationEvaluationsResponseFromProto(
|
|
444
|
+
await this.client.evaluateMany(authorizationEvaluateManyInputToProto(request)),
|
|
445
|
+
);
|
|
99
446
|
}
|
|
100
447
|
|
|
101
448
|
async searchResources(
|
|
102
449
|
request: AuthorizationSearchResourcesInput,
|
|
103
|
-
): Promise<
|
|
104
|
-
return
|
|
450
|
+
): Promise<AuthorizationResourceSearch> {
|
|
451
|
+
return authorizationResourceSearchFromProto(
|
|
452
|
+
await this.client.searchResources(authorizationSearchResourcesInputToProto(request)),
|
|
453
|
+
);
|
|
105
454
|
}
|
|
106
455
|
|
|
107
456
|
async searchSubjects(
|
|
108
457
|
request: AuthorizationSearchSubjectsInput,
|
|
109
|
-
): Promise<
|
|
110
|
-
return
|
|
458
|
+
): Promise<AuthorizationSubjectSearch> {
|
|
459
|
+
return authorizationSubjectSearchFromProto(
|
|
460
|
+
await this.client.searchSubjects(authorizationSearchSubjectsInputToProto(request)),
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
async effectiveSearchResources(
|
|
465
|
+
request: AuthorizationSearchResourcesInput,
|
|
466
|
+
): Promise<AuthorizationResourceSearch> {
|
|
467
|
+
return authorizationResourceSearchFromProto(
|
|
468
|
+
await this.client.effectiveSearchResources(authorizationSearchResourcesInputToProto(request)),
|
|
469
|
+
);
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
async effectiveSearchSubjects(
|
|
473
|
+
request: AuthorizationEffectiveSearchSubjectsInput,
|
|
474
|
+
): Promise<AuthorizationEffectiveSubjectSearch> {
|
|
475
|
+
return authorizationEffectiveSubjectSearchFromProto(
|
|
476
|
+
await this.client.effectiveSearchSubjects(authorizationEffectiveSearchSubjectsInputToProto(request)),
|
|
477
|
+
);
|
|
111
478
|
}
|
|
112
479
|
|
|
113
480
|
async searchActions(
|
|
114
481
|
request: AuthorizationSearchActionsInput,
|
|
115
|
-
): Promise<
|
|
116
|
-
return
|
|
482
|
+
): Promise<AuthorizationActionSearch> {
|
|
483
|
+
return authorizationActionSearchFromProto(
|
|
484
|
+
await this.client.searchActions(authorizationSearchActionsInputToProto(request)),
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
async expand(
|
|
489
|
+
request: AuthorizationExpandInput,
|
|
490
|
+
): Promise<AuthorizationExpand> {
|
|
491
|
+
return authorizationExpandFromProto(
|
|
492
|
+
await this.client.expand(authorizationExpandInputToProto(request)),
|
|
493
|
+
);
|
|
117
494
|
}
|
|
118
495
|
|
|
119
496
|
async readRelationships(
|
|
120
497
|
request: AuthorizationReadRelationshipsInput,
|
|
121
|
-
): Promise<
|
|
122
|
-
return
|
|
498
|
+
): Promise<AuthorizationReadRelationships> {
|
|
499
|
+
return authorizationReadRelationshipsFromProto(
|
|
500
|
+
await this.client.readRelationships(authorizationReadRelationshipsInputToProto(request)),
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
/** Writes and deletes authorization relationships. */
|
|
505
|
+
async writeRelationships(
|
|
506
|
+
request: AuthorizationWriteRelationshipsInput,
|
|
507
|
+
): Promise<void> {
|
|
508
|
+
await this.client.writeRelationships(authorizationWriteRelationshipsInputToProto(request));
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Grants a canonical Gestalt subject id editor access to an agent session.
|
|
513
|
+
*
|
|
514
|
+
* This writes the host-managed `agent_session` relationship through the SDK.
|
|
515
|
+
*/
|
|
516
|
+
async grantAgentSessionEditor(
|
|
517
|
+
subjectId: string,
|
|
518
|
+
sessionId: string,
|
|
519
|
+
): Promise<void> {
|
|
520
|
+
await this.writeRelationships(
|
|
521
|
+
agentSessionEditorWriteRequest(subjectId, sessionId),
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
async getMetadata(): Promise<AuthorizationMetadata> {
|
|
526
|
+
return authorizationMetadataFromProto(await this.client.getMetadata({}));
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
async getActiveModel(): Promise<AuthorizationGetActiveModel> {
|
|
530
|
+
return authorizationGetActiveModelFromProto(await this.client.getActiveModel({}));
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
async listModels(
|
|
534
|
+
request: AuthorizationListModelsInput = {},
|
|
535
|
+
): Promise<AuthorizationListModels> {
|
|
536
|
+
return authorizationListModelsFromProto(
|
|
537
|
+
await this.client.listModels(authorizationListModelsInputToProto(request)),
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
async writeModel(
|
|
542
|
+
request: AuthorizationWriteModelInput,
|
|
543
|
+
): Promise<AuthorizationModelRef> {
|
|
544
|
+
return authorizationModelRefFromProtoRequired(
|
|
545
|
+
await this.client.writeModel(authorizationWriteModelInputToProto(request)),
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
export interface AuthorizationProviderOptions extends ProviderBaseOptions {
|
|
551
|
+
evaluate: (
|
|
552
|
+
request: AuthorizationEvaluateInput,
|
|
553
|
+
) => MaybePromise<AuthorizationDecision>;
|
|
554
|
+
evaluateMany: (
|
|
555
|
+
request: AuthorizationEvaluateManyInput,
|
|
556
|
+
) => MaybePromise<AuthorizationEvaluationsResponse>;
|
|
557
|
+
searchResources: (
|
|
558
|
+
request: AuthorizationSearchResourcesInput,
|
|
559
|
+
) => MaybePromise<AuthorizationResourceSearch>;
|
|
560
|
+
searchSubjects: (
|
|
561
|
+
request: AuthorizationSearchSubjectsInput,
|
|
562
|
+
) => MaybePromise<AuthorizationSubjectSearch>;
|
|
563
|
+
effectiveSearchResources?: (
|
|
564
|
+
request: AuthorizationSearchResourcesInput,
|
|
565
|
+
) => MaybePromise<AuthorizationResourceSearch>;
|
|
566
|
+
effectiveSearchSubjects?: (
|
|
567
|
+
request: AuthorizationEffectiveSearchSubjectsInput,
|
|
568
|
+
) => MaybePromise<AuthorizationEffectiveSubjectSearch>;
|
|
569
|
+
searchActions: (
|
|
570
|
+
request: AuthorizationSearchActionsInput,
|
|
571
|
+
) => MaybePromise<AuthorizationActionSearch>;
|
|
572
|
+
expand?: (
|
|
573
|
+
request: AuthorizationExpandInput,
|
|
574
|
+
) => MaybePromise<AuthorizationExpand>;
|
|
575
|
+
getMetadata: () => MaybePromise<AuthorizationMetadata>;
|
|
576
|
+
readRelationships: (
|
|
577
|
+
request: AuthorizationReadRelationshipsInput,
|
|
578
|
+
) => MaybePromise<AuthorizationReadRelationships>;
|
|
579
|
+
writeRelationships: (
|
|
580
|
+
request: AuthorizationWriteRelationshipsInput,
|
|
581
|
+
) => MaybePromise<void>;
|
|
582
|
+
getActiveModel: () => MaybePromise<AuthorizationGetActiveModel>;
|
|
583
|
+
listModels: (
|
|
584
|
+
request: AuthorizationListModelsInput,
|
|
585
|
+
) => MaybePromise<AuthorizationListModels>;
|
|
586
|
+
writeModel: (
|
|
587
|
+
request: AuthorizationWriteModelInput,
|
|
588
|
+
) => MaybePromise<AuthorizationModelRef>;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
export class AuthorizationProvider extends ProviderBase {
|
|
592
|
+
readonly kind = "authorization" as const;
|
|
593
|
+
|
|
594
|
+
private readonly options: AuthorizationProviderOptions;
|
|
595
|
+
|
|
596
|
+
constructor(options: AuthorizationProviderOptions) {
|
|
597
|
+
super(options);
|
|
598
|
+
this.options = options;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
async evaluate(request: AuthorizationEvaluateInput) {
|
|
602
|
+
return await this.options.evaluate(request);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
async evaluateMany(request: AuthorizationEvaluateManyInput) {
|
|
606
|
+
return await this.options.evaluateMany(request);
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
async searchResources(request: AuthorizationSearchResourcesInput) {
|
|
610
|
+
return await this.options.searchResources(request);
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
async searchSubjects(request: AuthorizationSearchSubjectsInput) {
|
|
614
|
+
return await this.options.searchSubjects(request);
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
supportsEffectiveSearch(): boolean {
|
|
618
|
+
return (
|
|
619
|
+
this.options.effectiveSearchResources !== undefined &&
|
|
620
|
+
this.options.effectiveSearchSubjects !== undefined
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
async effectiveSearchResources(request: AuthorizationSearchResourcesInput) {
|
|
625
|
+
return await this.options.effectiveSearchResources?.(request);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
async effectiveSearchSubjects(request: AuthorizationEffectiveSearchSubjectsInput) {
|
|
629
|
+
return await this.options.effectiveSearchSubjects?.(request);
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
async searchActions(request: AuthorizationSearchActionsInput) {
|
|
633
|
+
return await this.options.searchActions(request);
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
supportsExpand(): boolean {
|
|
637
|
+
return this.options.expand !== undefined;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
async expand(request: AuthorizationExpandInput) {
|
|
641
|
+
return await this.options.expand?.(request);
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
async getMetadata() {
|
|
645
|
+
return await this.options.getMetadata();
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
async readRelationships(request: AuthorizationReadRelationshipsInput) {
|
|
649
|
+
return await this.options.readRelationships(request);
|
|
123
650
|
}
|
|
124
651
|
|
|
125
|
-
async
|
|
126
|
-
|
|
652
|
+
async writeRelationships(request: AuthorizationWriteRelationshipsInput): Promise<void> {
|
|
653
|
+
await this.options.writeRelationships(request);
|
|
127
654
|
}
|
|
655
|
+
|
|
656
|
+
async getActiveModel() {
|
|
657
|
+
return await this.options.getActiveModel();
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
async listModels(request: AuthorizationListModelsInput) {
|
|
661
|
+
return await this.options.listModels(request);
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
async writeModel(request: AuthorizationWriteModelInput) {
|
|
665
|
+
return await this.options.writeModel(request);
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
export function defineAuthorizationProvider(
|
|
670
|
+
options: AuthorizationProviderOptions,
|
|
671
|
+
): AuthorizationProvider {
|
|
672
|
+
return new AuthorizationProvider(options);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
export function isAuthorizationProvider(
|
|
676
|
+
value: unknown,
|
|
677
|
+
): value is AuthorizationProvider {
|
|
678
|
+
return (
|
|
679
|
+
value instanceof AuthorizationProvider ||
|
|
680
|
+
(typeof value === "object" &&
|
|
681
|
+
value !== null &&
|
|
682
|
+
"kind" in value &&
|
|
683
|
+
String((value as { kind?: unknown }).kind ?? "") === "authorization" &&
|
|
684
|
+
"evaluate" in value &&
|
|
685
|
+
"evaluateMany" in value &&
|
|
686
|
+
"searchResources" in value &&
|
|
687
|
+
"searchSubjects" in value &&
|
|
688
|
+
"searchActions" in value &&
|
|
689
|
+
"getMetadata" in value &&
|
|
690
|
+
"readRelationships" in value &&
|
|
691
|
+
"writeRelationships" in value &&
|
|
692
|
+
"getActiveModel" in value &&
|
|
693
|
+
"listModels" in value &&
|
|
694
|
+
"writeModel" in value)
|
|
695
|
+
);
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
export function createAuthorizationProviderService(
|
|
699
|
+
provider: AuthorizationProvider,
|
|
700
|
+
): AuthorizationProviderServiceImpl {
|
|
701
|
+
return {
|
|
702
|
+
async evaluate(request) {
|
|
703
|
+
return authorizationDecisionToProto(
|
|
704
|
+
requiredAuthorizationResponse(
|
|
705
|
+
await provider.evaluate(authorizationEvaluateInputFromProto(request)),
|
|
706
|
+
"evaluate",
|
|
707
|
+
),
|
|
708
|
+
);
|
|
709
|
+
},
|
|
710
|
+
async evaluateMany(request) {
|
|
711
|
+
return authorizationEvaluationsResponseToProto(
|
|
712
|
+
requiredAuthorizationResponse(
|
|
713
|
+
await provider.evaluateMany(authorizationEvaluateManyInputFromProto(request)),
|
|
714
|
+
"evaluate many",
|
|
715
|
+
),
|
|
716
|
+
);
|
|
717
|
+
},
|
|
718
|
+
async searchResources(request) {
|
|
719
|
+
return authorizationResourceSearchToProto(
|
|
720
|
+
requiredAuthorizationResponse(
|
|
721
|
+
await provider.searchResources(authorizationSearchResourcesInputFromProto(request)),
|
|
722
|
+
"search resources",
|
|
723
|
+
),
|
|
724
|
+
);
|
|
725
|
+
},
|
|
726
|
+
async searchSubjects(request) {
|
|
727
|
+
return authorizationSubjectSearchToProto(
|
|
728
|
+
requiredAuthorizationResponse(
|
|
729
|
+
await provider.searchSubjects(authorizationSearchSubjectsInputFromProto(request)),
|
|
730
|
+
"search subjects",
|
|
731
|
+
),
|
|
732
|
+
);
|
|
733
|
+
},
|
|
734
|
+
async effectiveSearchResources(request) {
|
|
735
|
+
if (!provider.supportsEffectiveSearch()) {
|
|
736
|
+
throw new ConnectError(
|
|
737
|
+
"authorization provider does not support effective search",
|
|
738
|
+
Code.Unimplemented,
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
return authorizationResourceSearchToProto(
|
|
742
|
+
requiredAuthorizationResponse(
|
|
743
|
+
await provider.effectiveSearchResources(authorizationSearchResourcesInputFromProto(request)),
|
|
744
|
+
"effective search resources",
|
|
745
|
+
),
|
|
746
|
+
);
|
|
747
|
+
},
|
|
748
|
+
async effectiveSearchSubjects(request) {
|
|
749
|
+
if (!provider.supportsEffectiveSearch()) {
|
|
750
|
+
throw new ConnectError(
|
|
751
|
+
"authorization provider does not support effective search",
|
|
752
|
+
Code.Unimplemented,
|
|
753
|
+
);
|
|
754
|
+
}
|
|
755
|
+
return authorizationEffectiveSubjectSearchToProto(
|
|
756
|
+
requiredAuthorizationResponse(
|
|
757
|
+
await provider.effectiveSearchSubjects(authorizationEffectiveSearchSubjectsInputFromProto(request)),
|
|
758
|
+
"effective search subjects",
|
|
759
|
+
),
|
|
760
|
+
);
|
|
761
|
+
},
|
|
762
|
+
async searchActions(request) {
|
|
763
|
+
return authorizationActionSearchToProto(
|
|
764
|
+
requiredAuthorizationResponse(
|
|
765
|
+
await provider.searchActions(authorizationSearchActionsInputFromProto(request)),
|
|
766
|
+
"search actions",
|
|
767
|
+
),
|
|
768
|
+
);
|
|
769
|
+
},
|
|
770
|
+
async expand(request) {
|
|
771
|
+
if (!provider.supportsExpand()) {
|
|
772
|
+
throw new ConnectError(
|
|
773
|
+
"authorization provider does not support expansion",
|
|
774
|
+
Code.Unimplemented,
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
return authorizationExpandToProto(
|
|
778
|
+
requiredAuthorizationResponse(
|
|
779
|
+
await provider.expand(authorizationExpandInputFromProto(request)),
|
|
780
|
+
"expand",
|
|
781
|
+
),
|
|
782
|
+
);
|
|
783
|
+
},
|
|
784
|
+
async getMetadata() {
|
|
785
|
+
const metadata = authorizationMetadataToProto(
|
|
786
|
+
requiredAuthorizationResponse(await provider.getMetadata(), "metadata"),
|
|
787
|
+
);
|
|
788
|
+
if (provider.supportsEffectiveSearch()) {
|
|
789
|
+
pushCapability(metadata.capabilities, "effective_search_resources");
|
|
790
|
+
pushCapability(metadata.capabilities, "effective_search_subjects");
|
|
791
|
+
}
|
|
792
|
+
if (provider.supportsExpand()) {
|
|
793
|
+
pushCapability(metadata.capabilities, "expand");
|
|
794
|
+
}
|
|
795
|
+
return metadata;
|
|
796
|
+
},
|
|
797
|
+
async readRelationships(request) {
|
|
798
|
+
return authorizationReadRelationshipsToProto(
|
|
799
|
+
requiredAuthorizationResponse(
|
|
800
|
+
await provider.readRelationships(authorizationReadRelationshipsInputFromProto(request)),
|
|
801
|
+
"read relationships",
|
|
802
|
+
),
|
|
803
|
+
);
|
|
804
|
+
},
|
|
805
|
+
async writeRelationships(request) {
|
|
806
|
+
await provider.writeRelationships(authorizationWriteRelationshipsInputFromProto(request));
|
|
807
|
+
return create(EmptySchema, {});
|
|
808
|
+
},
|
|
809
|
+
async getActiveModel() {
|
|
810
|
+
return authorizationGetActiveModelToProto(
|
|
811
|
+
requiredAuthorizationResponse(
|
|
812
|
+
await provider.getActiveModel(),
|
|
813
|
+
"get active model",
|
|
814
|
+
),
|
|
815
|
+
);
|
|
816
|
+
},
|
|
817
|
+
async listModels(request) {
|
|
818
|
+
return authorizationListModelsToProto(
|
|
819
|
+
requiredAuthorizationResponse(
|
|
820
|
+
await provider.listModels(authorizationListModelsInputFromProto(request)),
|
|
821
|
+
"list models",
|
|
822
|
+
),
|
|
823
|
+
);
|
|
824
|
+
},
|
|
825
|
+
async writeModel(request) {
|
|
826
|
+
return authorizationModelRefToProto(
|
|
827
|
+
requiredAuthorizationResponse(
|
|
828
|
+
await provider.writeModel(authorizationWriteModelInputFromProto(request)),
|
|
829
|
+
"write model",
|
|
830
|
+
),
|
|
831
|
+
);
|
|
832
|
+
},
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
function requiredAuthorizationResponse<T>(
|
|
837
|
+
value: T | null | undefined,
|
|
838
|
+
label: string,
|
|
839
|
+
): T {
|
|
840
|
+
if (value === null || value === undefined) {
|
|
841
|
+
throw new ConnectError(
|
|
842
|
+
`authorization provider returned nil ${label} response`,
|
|
843
|
+
Code.Internal,
|
|
844
|
+
);
|
|
845
|
+
}
|
|
846
|
+
return value;
|
|
128
847
|
}
|
|
129
848
|
|
|
130
849
|
/**
|
|
131
|
-
*
|
|
132
|
-
* client inside authored providers.
|
|
850
|
+
* Returns a shared host authorization client for authored providers.
|
|
133
851
|
*/
|
|
134
852
|
export function Authorization(): AuthorizationClient {
|
|
135
853
|
const target = resolveAuthorizationSocketTarget();
|
|
@@ -149,7 +867,932 @@ export function Authorization(): AuthorizationClient {
|
|
|
149
867
|
return client;
|
|
150
868
|
}
|
|
151
869
|
|
|
152
|
-
|
|
870
|
+
/** Creates an authorization subject reference. */
|
|
871
|
+
export function authorizationSubject(
|
|
872
|
+
type: string,
|
|
873
|
+
id: string,
|
|
874
|
+
properties?: JsonObjectInput,
|
|
875
|
+
): AuthorizationSubject {
|
|
876
|
+
return properties === undefined ? { type, id } : { type, id, properties };
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
/** Creates an authorization resource reference. */
|
|
880
|
+
export function authorizationResource(
|
|
881
|
+
type: string,
|
|
882
|
+
id: string,
|
|
883
|
+
properties?: JsonObjectInput,
|
|
884
|
+
): AuthorizationResource {
|
|
885
|
+
return properties === undefined ? { type, id } : { type, id, properties };
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
/** Creates an authorization subject-set reference. */
|
|
889
|
+
export function authorizationSubjectSet(
|
|
890
|
+
resource: AuthorizationResource,
|
|
891
|
+
relation: string,
|
|
892
|
+
): AuthorizationSubjectSet {
|
|
893
|
+
return { resource, relation };
|
|
894
|
+
}
|
|
895
|
+
|
|
896
|
+
/** Creates a relationship target from a subject. */
|
|
897
|
+
export function authorizationSubjectTarget(
|
|
898
|
+
subject: AuthorizationSubject,
|
|
899
|
+
): AuthorizationRelationshipTarget {
|
|
900
|
+
return { kind: { case: "subject", value: subject } };
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
/** Creates a relationship target from a resource. */
|
|
904
|
+
export function authorizationResourceTarget(
|
|
905
|
+
resource: AuthorizationResource,
|
|
906
|
+
): AuthorizationRelationshipTarget {
|
|
907
|
+
return { kind: { case: "resource", value: resource } };
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
/** Creates a relationship target from a subject set. */
|
|
911
|
+
export function authorizationSubjectSetTarget(
|
|
912
|
+
resource: AuthorizationResource,
|
|
913
|
+
relation: string,
|
|
914
|
+
): AuthorizationRelationshipTarget {
|
|
915
|
+
return {
|
|
916
|
+
kind: {
|
|
917
|
+
case: "subjectSet",
|
|
918
|
+
value: authorizationSubjectSet(resource, relation),
|
|
919
|
+
},
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/** Creates the managed authorization resource for an agent session. */
|
|
924
|
+
export function agentSessionAuthorizationResource(
|
|
925
|
+
sessionId: string,
|
|
926
|
+
): AuthorizationResource {
|
|
927
|
+
return authorizationResource(AGENT_SESSION_RESOURCE_TYPE, sessionId);
|
|
928
|
+
}
|
|
929
|
+
|
|
930
|
+
/** Creates an authorization action reference. */
|
|
931
|
+
export function authorizationAction(
|
|
932
|
+
name: string,
|
|
933
|
+
properties?: JsonObjectInput,
|
|
934
|
+
): AuthorizationAction {
|
|
935
|
+
return properties === undefined ? { name } : { name, properties };
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
/** Creates a relationship tuple for authorization writes. */
|
|
939
|
+
export function authorizationRelationship(
|
|
940
|
+
subject: AuthorizationSubject,
|
|
941
|
+
relation: string,
|
|
942
|
+
resource: AuthorizationResource,
|
|
943
|
+
properties?: JsonObjectInput,
|
|
944
|
+
): AuthorizationRelationship {
|
|
945
|
+
return properties === undefined
|
|
946
|
+
? { subject, relation, resource }
|
|
947
|
+
: { subject, relation, resource, properties };
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
/** Creates a generalized relationship tuple for authorization writes. */
|
|
951
|
+
export function authorizationRelationshipWithTarget(
|
|
952
|
+
target: AuthorizationRelationshipTarget,
|
|
953
|
+
relation: string,
|
|
954
|
+
resource: AuthorizationResource,
|
|
955
|
+
properties?: JsonObjectInput,
|
|
956
|
+
): AuthorizationRelationship {
|
|
957
|
+
return properties === undefined
|
|
958
|
+
? { target, relation, resource }
|
|
959
|
+
: { target, relation, resource, properties };
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* Creates the relationship that shares an agent session with a canonical
|
|
964
|
+
* Gestalt subject id such as `user:123`.
|
|
965
|
+
*
|
|
966
|
+
* The returned relationship mirrors the subject into both the legacy `subject`
|
|
967
|
+
* field and the generalized `target.subject` field so it remains compatible
|
|
968
|
+
* with mixed host/provider versions.
|
|
969
|
+
*/
|
|
970
|
+
export function agentSessionEditorRelationship(
|
|
971
|
+
subjectId: string,
|
|
972
|
+
sessionId: string,
|
|
973
|
+
): AuthorizationRelationship {
|
|
974
|
+
const subject = authorizationSubject(
|
|
975
|
+
AUTHORIZATION_SUBJECT_TYPE_SUBJECT,
|
|
976
|
+
subjectId,
|
|
977
|
+
);
|
|
978
|
+
return {
|
|
979
|
+
subject,
|
|
980
|
+
target: authorizationSubjectTarget(subject),
|
|
981
|
+
relation: AGENT_SESSION_RELATION_EDITOR,
|
|
982
|
+
resource: agentSessionAuthorizationResource(sessionId),
|
|
983
|
+
};
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
/** Creates a relationship-write request that shares an agent session. */
|
|
987
|
+
export function agentSessionEditorWriteRequest(
|
|
988
|
+
subjectId: string,
|
|
989
|
+
sessionId: string,
|
|
990
|
+
): AuthorizationWriteRelationshipsInput {
|
|
991
|
+
return {
|
|
992
|
+
writes: [agentSessionEditorRelationship(subjectId, sessionId)],
|
|
993
|
+
};
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
/** Creates a relationship key for authorization deletes. */
|
|
997
|
+
export function authorizationRelationshipKey(
|
|
998
|
+
subject: AuthorizationSubject,
|
|
999
|
+
relation: string,
|
|
1000
|
+
resource: AuthorizationResource,
|
|
1001
|
+
): AuthorizationRelationshipKey {
|
|
1002
|
+
return { subject, relation, resource };
|
|
1003
|
+
}
|
|
1004
|
+
|
|
1005
|
+
/** Creates a generalized relationship key for authorization deletes. */
|
|
1006
|
+
export function authorizationRelationshipKeyWithTarget(
|
|
1007
|
+
target: AuthorizationRelationshipTarget,
|
|
1008
|
+
relation: string,
|
|
1009
|
+
resource: AuthorizationResource,
|
|
1010
|
+
): AuthorizationRelationshipKey {
|
|
1011
|
+
return { target, relation, resource };
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
function authorizationEvaluateInputToProto(input: AuthorizationEvaluateInput) {
|
|
1015
|
+
return create(AccessEvaluationRequestSchema, {
|
|
1016
|
+
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1017
|
+
action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
|
|
1018
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1019
|
+
context: optionalStruct(input.context),
|
|
1020
|
+
});
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
function authorizationEvaluateInputFromProto(
|
|
1024
|
+
input: ProtoAccessEvaluationRequest,
|
|
1025
|
+
): AuthorizationEvaluateInput {
|
|
1026
|
+
return {
|
|
1027
|
+
subject: authorizationSubjectFromProto(input.subject),
|
|
1028
|
+
action: authorizationActionFromProto(input.action),
|
|
1029
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1030
|
+
context: optionalObjectFromStruct(input.context),
|
|
1031
|
+
};
|
|
1032
|
+
}
|
|
1033
|
+
|
|
1034
|
+
function authorizationEvaluateManyInputToProto(input: AuthorizationEvaluateManyInput) {
|
|
1035
|
+
return create(AccessEvaluationsRequestSchema, {
|
|
1036
|
+
requests: input.requests?.map(authorizationEvaluateInputToProto) ?? [],
|
|
1037
|
+
});
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
function authorizationEvaluateManyInputFromProto(
|
|
1041
|
+
input: ProtoAccessEvaluationsRequest,
|
|
1042
|
+
): AuthorizationEvaluateManyInput {
|
|
1043
|
+
return { requests: input.requests.map(authorizationEvaluateInputFromProto) };
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
function authorizationSearchResourcesInputToProto(input: AuthorizationSearchResourcesInput) {
|
|
1047
|
+
return create(ResourceSearchRequestSchema, {
|
|
1048
|
+
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1049
|
+
action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
|
|
1050
|
+
resourceType: input.resourceType ?? "",
|
|
1051
|
+
context: optionalStruct(input.context),
|
|
1052
|
+
pageSize: input.pageSize ?? 0,
|
|
1053
|
+
pageToken: input.pageToken ?? "",
|
|
1054
|
+
});
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
function authorizationSearchResourcesInputFromProto(
|
|
1058
|
+
input: ProtoResourceSearchRequest,
|
|
1059
|
+
): AuthorizationSearchResourcesInput {
|
|
1060
|
+
return {
|
|
1061
|
+
subject: authorizationSubjectFromProto(input.subject),
|
|
1062
|
+
action: authorizationActionFromProto(input.action),
|
|
1063
|
+
resourceType: input.resourceType,
|
|
1064
|
+
context: optionalObjectFromStruct(input.context),
|
|
1065
|
+
pageSize: input.pageSize,
|
|
1066
|
+
pageToken: input.pageToken,
|
|
1067
|
+
};
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
function authorizationSearchSubjectsInputToProto(input: AuthorizationSearchSubjectsInput) {
|
|
1071
|
+
return create(SubjectSearchRequestSchema, {
|
|
1072
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1073
|
+
action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
|
|
1074
|
+
subjectType: input.subjectType ?? "",
|
|
1075
|
+
context: optionalStruct(input.context),
|
|
1076
|
+
pageSize: input.pageSize ?? 0,
|
|
1077
|
+
pageToken: input.pageToken ?? "",
|
|
1078
|
+
});
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
function authorizationSearchSubjectsInputFromProto(
|
|
1082
|
+
input: ProtoSubjectSearchRequest,
|
|
1083
|
+
): AuthorizationSearchSubjectsInput {
|
|
1084
|
+
return {
|
|
1085
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1086
|
+
action: authorizationActionFromProto(input.action),
|
|
1087
|
+
subjectType: input.subjectType,
|
|
1088
|
+
context: optionalObjectFromStruct(input.context),
|
|
1089
|
+
pageSize: input.pageSize,
|
|
1090
|
+
pageToken: input.pageToken,
|
|
1091
|
+
};
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
function authorizationEffectiveSearchSubjectsInputToProto(
|
|
1095
|
+
input: AuthorizationEffectiveSearchSubjectsInput,
|
|
1096
|
+
) {
|
|
1097
|
+
return create(EffectiveSubjectSearchRequestSchema, {
|
|
1098
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1099
|
+
action: input.action === undefined ? undefined : authorizationActionToProto(input.action),
|
|
1100
|
+
context: optionalStruct(input.context),
|
|
1101
|
+
pageSize: input.pageSize ?? 0,
|
|
1102
|
+
pageToken: input.pageToken ?? "",
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
function authorizationEffectiveSearchSubjectsInputFromProto(
|
|
1107
|
+
input: ProtoEffectiveSubjectSearchRequest,
|
|
1108
|
+
): AuthorizationEffectiveSearchSubjectsInput {
|
|
1109
|
+
return {
|
|
1110
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1111
|
+
action: authorizationActionFromProto(input.action),
|
|
1112
|
+
context: optionalObjectFromStruct(input.context),
|
|
1113
|
+
pageSize: input.pageSize,
|
|
1114
|
+
pageToken: input.pageToken,
|
|
1115
|
+
};
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
function authorizationSearchActionsInputToProto(input: AuthorizationSearchActionsInput) {
|
|
1119
|
+
return create(ActionSearchRequestSchema, {
|
|
1120
|
+
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1121
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1122
|
+
context: optionalStruct(input.context),
|
|
1123
|
+
pageSize: input.pageSize ?? 0,
|
|
1124
|
+
pageToken: input.pageToken ?? "",
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
|
|
1128
|
+
function authorizationSearchActionsInputFromProto(
|
|
1129
|
+
input: ProtoActionSearchRequest,
|
|
1130
|
+
): AuthorizationSearchActionsInput {
|
|
1131
|
+
return {
|
|
1132
|
+
subject: authorizationSubjectFromProto(input.subject),
|
|
1133
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1134
|
+
context: optionalObjectFromStruct(input.context),
|
|
1135
|
+
pageSize: input.pageSize,
|
|
1136
|
+
pageToken: input.pageToken,
|
|
1137
|
+
};
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
function authorizationExpandInputToProto(input: AuthorizationExpandInput) {
|
|
1141
|
+
return create(ExpandRequestSchema, {
|
|
1142
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1143
|
+
relation: input.relation ?? "",
|
|
1144
|
+
context: optionalStruct(input.context),
|
|
1145
|
+
maxDepth: input.maxDepth ?? 0,
|
|
1146
|
+
modelId: input.modelId ?? "",
|
|
1147
|
+
});
|
|
1148
|
+
}
|
|
1149
|
+
|
|
1150
|
+
function authorizationExpandInputFromProto(input: ProtoExpandRequest): AuthorizationExpandInput {
|
|
1151
|
+
return {
|
|
1152
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1153
|
+
relation: input.relation,
|
|
1154
|
+
context: optionalObjectFromStruct(input.context),
|
|
1155
|
+
maxDepth: input.maxDepth,
|
|
1156
|
+
modelId: input.modelId,
|
|
1157
|
+
};
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
function authorizationReadRelationshipsInputToProto(input: AuthorizationReadRelationshipsInput) {
|
|
1161
|
+
return create(ReadRelationshipsRequestSchema, {
|
|
1162
|
+
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1163
|
+
relation: input.relation ?? "",
|
|
1164
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1165
|
+
pageSize: input.pageSize ?? 0,
|
|
1166
|
+
pageToken: input.pageToken ?? "",
|
|
1167
|
+
modelId: input.modelId ?? "",
|
|
1168
|
+
target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
|
|
1169
|
+
});
|
|
1170
|
+
}
|
|
1171
|
+
|
|
1172
|
+
function authorizationReadRelationshipsInputFromProto(
|
|
1173
|
+
input: ProtoReadRelationshipsRequest,
|
|
1174
|
+
): AuthorizationReadRelationshipsInput {
|
|
1175
|
+
return {
|
|
1176
|
+
subject: authorizationSubjectFromProto(input.subject),
|
|
1177
|
+
relation: input.relation,
|
|
1178
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1179
|
+
pageSize: input.pageSize,
|
|
1180
|
+
pageToken: input.pageToken,
|
|
1181
|
+
modelId: input.modelId,
|
|
1182
|
+
target: authorizationRelationshipTargetFromProto(input.target),
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
function authorizationWriteRelationshipsInputToProto(input: AuthorizationWriteRelationshipsInput) {
|
|
1187
|
+
return create(WriteRelationshipsRequestSchema, {
|
|
1188
|
+
writes: input.writes?.map(authorizationRelationshipToProto) ?? [],
|
|
1189
|
+
deletes: input.deletes?.map(authorizationRelationshipKeyToProto) ?? [],
|
|
1190
|
+
modelId: input.modelId ?? "",
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
|
|
1194
|
+
function authorizationWriteRelationshipsInputFromProto(
|
|
1195
|
+
input: ProtoWriteRelationshipsRequest,
|
|
1196
|
+
): AuthorizationWriteRelationshipsInput {
|
|
1197
|
+
return {
|
|
1198
|
+
writes: input.writes.map(authorizationRelationshipFromProto),
|
|
1199
|
+
deletes: input.deletes.map(authorizationRelationshipKeyFromProto),
|
|
1200
|
+
modelId: input.modelId,
|
|
1201
|
+
};
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
function authorizationListModelsInputToProto(input: AuthorizationListModelsInput) {
|
|
1205
|
+
return create(ListModelsRequestSchema, {
|
|
1206
|
+
pageSize: input.pageSize ?? 0,
|
|
1207
|
+
pageToken: input.pageToken ?? "",
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
function authorizationListModelsInputFromProto(input: ProtoListModelsRequest): AuthorizationListModelsInput {
|
|
1212
|
+
return {
|
|
1213
|
+
pageSize: input.pageSize,
|
|
1214
|
+
pageToken: input.pageToken,
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
function authorizationWriteModelInputToProto(input: AuthorizationWriteModelInput) {
|
|
1219
|
+
return create(WriteModelRequestSchema, {
|
|
1220
|
+
model: input.model === undefined ? undefined : authorizationModelToProto(input.model),
|
|
1221
|
+
});
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
function authorizationWriteModelInputFromProto(input: ProtoWriteModelRequest): AuthorizationWriteModelInput {
|
|
1225
|
+
return {
|
|
1226
|
+
model: authorizationModelFromProto(input.model),
|
|
1227
|
+
};
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
function authorizationDecisionToProto(input: AuthorizationDecision) {
|
|
1231
|
+
return create(AccessDecisionSchema, {
|
|
1232
|
+
allowed: input.allowed ?? false,
|
|
1233
|
+
context: optionalStruct(input.context),
|
|
1234
|
+
modelId: input.modelId ?? "",
|
|
1235
|
+
});
|
|
1236
|
+
}
|
|
1237
|
+
|
|
1238
|
+
function authorizationDecisionFromProto(input: ProtoAccessDecision): AuthorizationDecision {
|
|
1239
|
+
return {
|
|
1240
|
+
allowed: input.allowed,
|
|
1241
|
+
context: optionalObjectFromStruct(input.context),
|
|
1242
|
+
modelId: input.modelId,
|
|
1243
|
+
};
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
function authorizationEvaluationsResponseToProto(input: AuthorizationEvaluationsResponse) {
|
|
1247
|
+
return create(AccessEvaluationsResponseSchema, {
|
|
1248
|
+
decisions: input.decisions?.map(authorizationDecisionToProto) ?? [],
|
|
1249
|
+
});
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
function authorizationEvaluationsResponseFromProto(
|
|
1253
|
+
input: ProtoAccessEvaluationsResponse,
|
|
1254
|
+
): AuthorizationEvaluationsResponse {
|
|
1255
|
+
return { decisions: input.decisions.map(authorizationDecisionFromProto) };
|
|
1256
|
+
}
|
|
1257
|
+
|
|
1258
|
+
function authorizationResourceSearchToProto(input: AuthorizationResourceSearch) {
|
|
1259
|
+
return create(ResourceSearchResponseSchema, {
|
|
1260
|
+
resources: input.resources?.map(authorizationResourceToProto) ?? [],
|
|
1261
|
+
nextPageToken: input.nextPageToken ?? "",
|
|
1262
|
+
modelId: input.modelId ?? "",
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
function authorizationResourceSearchFromProto(input: ProtoResourceSearchResponse): AuthorizationResourceSearch {
|
|
1267
|
+
return {
|
|
1268
|
+
resources: input.resources.map(authorizationResourceFromProtoRequired),
|
|
1269
|
+
nextPageToken: input.nextPageToken,
|
|
1270
|
+
modelId: input.modelId,
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
|
|
1274
|
+
function authorizationSubjectSearchToProto(input: AuthorizationSubjectSearch) {
|
|
1275
|
+
return create(SubjectSearchResponseSchema, {
|
|
1276
|
+
subjects: input.subjects?.map(authorizationSubjectToProto) ?? [],
|
|
1277
|
+
nextPageToken: input.nextPageToken ?? "",
|
|
1278
|
+
modelId: input.modelId ?? "",
|
|
1279
|
+
});
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
function authorizationSubjectSearchFromProto(input: ProtoSubjectSearchResponse): AuthorizationSubjectSearch {
|
|
1283
|
+
return {
|
|
1284
|
+
subjects: input.subjects.map(authorizationSubjectFromProtoRequired),
|
|
1285
|
+
nextPageToken: input.nextPageToken,
|
|
1286
|
+
modelId: input.modelId,
|
|
1287
|
+
};
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
function authorizationEffectiveSubjectSearchToProto(input: AuthorizationEffectiveSubjectSearch) {
|
|
1291
|
+
return create(EffectiveSubjectSearchResponseSchema, {
|
|
1292
|
+
targets: input.targets?.map(authorizationRelationshipTargetToProto) ?? [],
|
|
1293
|
+
nextPageToken: input.nextPageToken ?? "",
|
|
1294
|
+
modelId: input.modelId ?? "",
|
|
1295
|
+
truncated: input.truncated ?? false,
|
|
1296
|
+
});
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
function authorizationEffectiveSubjectSearchFromProto(
|
|
1300
|
+
input: ProtoEffectiveSubjectSearchResponse,
|
|
1301
|
+
): AuthorizationEffectiveSubjectSearch {
|
|
1302
|
+
return {
|
|
1303
|
+
targets: input.targets.map(authorizationRelationshipTargetFromProtoRequired),
|
|
1304
|
+
nextPageToken: input.nextPageToken,
|
|
1305
|
+
modelId: input.modelId,
|
|
1306
|
+
truncated: input.truncated,
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
function authorizationActionSearchToProto(input: AuthorizationActionSearch) {
|
|
1311
|
+
return create(ActionSearchResponseSchema, {
|
|
1312
|
+
actions: input.actions?.map(authorizationActionToProto) ?? [],
|
|
1313
|
+
nextPageToken: input.nextPageToken ?? "",
|
|
1314
|
+
modelId: input.modelId ?? "",
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
|
|
1318
|
+
function authorizationActionSearchFromProto(input: ProtoActionSearchResponse): AuthorizationActionSearch {
|
|
1319
|
+
return {
|
|
1320
|
+
actions: input.actions.map(authorizationActionFromProtoRequired),
|
|
1321
|
+
nextPageToken: input.nextPageToken,
|
|
1322
|
+
modelId: input.modelId,
|
|
1323
|
+
};
|
|
1324
|
+
}
|
|
1325
|
+
|
|
1326
|
+
function authorizationMetadataToProto(input: AuthorizationMetadata) {
|
|
1327
|
+
return create(AuthorizationMetadataSchema, {
|
|
1328
|
+
capabilities: [...(input.capabilities ?? [])],
|
|
1329
|
+
activeModelId: input.activeModelId ?? "",
|
|
1330
|
+
});
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
function authorizationMetadataFromProto(input: ProtoAuthorizationMetadata): AuthorizationMetadata {
|
|
1334
|
+
return {
|
|
1335
|
+
capabilities: [...input.capabilities],
|
|
1336
|
+
activeModelId: input.activeModelId,
|
|
1337
|
+
};
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
function authorizationReadRelationshipsToProto(input: AuthorizationReadRelationships) {
|
|
1341
|
+
return create(ReadRelationshipsResponseSchema, {
|
|
1342
|
+
relationships: input.relationships?.map(authorizationRelationshipToProto) ?? [],
|
|
1343
|
+
nextPageToken: input.nextPageToken ?? "",
|
|
1344
|
+
modelId: input.modelId ?? "",
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
function authorizationReadRelationshipsFromProto(
|
|
1349
|
+
input: ProtoReadRelationshipsResponse,
|
|
1350
|
+
): AuthorizationReadRelationships {
|
|
1351
|
+
return {
|
|
1352
|
+
relationships: input.relationships.map(authorizationRelationshipFromProto),
|
|
1353
|
+
nextPageToken: input.nextPageToken,
|
|
1354
|
+
modelId: input.modelId,
|
|
1355
|
+
};
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
function authorizationGetActiveModelToProto(input: AuthorizationGetActiveModel) {
|
|
1359
|
+
return create(GetActiveModelResponseSchema, {
|
|
1360
|
+
model: input.model === undefined ? undefined : authorizationModelRefToProto(input.model),
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
function authorizationGetActiveModelFromProto(input: ProtoGetActiveModelResponse): AuthorizationGetActiveModel {
|
|
1365
|
+
return {
|
|
1366
|
+
model: authorizationModelRefFromProto(input.model),
|
|
1367
|
+
};
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
function authorizationListModelsToProto(input: AuthorizationListModels) {
|
|
1371
|
+
return create(ListModelsResponseSchema, {
|
|
1372
|
+
models: input.models?.map(authorizationModelRefToProto) ?? [],
|
|
1373
|
+
nextPageToken: input.nextPageToken ?? "",
|
|
1374
|
+
});
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
function authorizationListModelsFromProto(input: ProtoListModelsResponse): AuthorizationListModels {
|
|
1378
|
+
return {
|
|
1379
|
+
models: input.models.map(authorizationModelRefFromProtoRequired),
|
|
1380
|
+
nextPageToken: input.nextPageToken,
|
|
1381
|
+
};
|
|
1382
|
+
}
|
|
1383
|
+
|
|
1384
|
+
function authorizationSubjectToProto(input: AuthorizationSubject) {
|
|
1385
|
+
return create(SubjectSchema, {
|
|
1386
|
+
type: input.type,
|
|
1387
|
+
id: input.id,
|
|
1388
|
+
properties: optionalStruct(input.properties),
|
|
1389
|
+
});
|
|
1390
|
+
}
|
|
1391
|
+
|
|
1392
|
+
function authorizationSubjectFromProto(input?: ProtoSubject | undefined): AuthorizationSubject | undefined {
|
|
1393
|
+
return input === undefined ? undefined : authorizationSubjectFromProtoRequired(input);
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
function authorizationSubjectFromProtoRequired(input: ProtoSubject): AuthorizationSubject {
|
|
1397
|
+
return {
|
|
1398
|
+
type: input.type,
|
|
1399
|
+
id: input.id,
|
|
1400
|
+
properties: optionalObjectFromStruct(input.properties),
|
|
1401
|
+
};
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
function authorizationResourceToProto(input: AuthorizationResource) {
|
|
1405
|
+
return create(ResourceSchema, {
|
|
1406
|
+
type: input.type,
|
|
1407
|
+
id: input.id,
|
|
1408
|
+
properties: optionalStruct(input.properties),
|
|
1409
|
+
});
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
function authorizationResourceFromProto(input?: ProtoResource | undefined): AuthorizationResource | undefined {
|
|
1413
|
+
return input === undefined ? undefined : authorizationResourceFromProtoRequired(input);
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
function authorizationResourceFromProtoRequired(input: ProtoResource): AuthorizationResource {
|
|
1417
|
+
return {
|
|
1418
|
+
type: input.type,
|
|
1419
|
+
id: input.id,
|
|
1420
|
+
properties: optionalObjectFromStruct(input.properties),
|
|
1421
|
+
};
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
function authorizationSubjectSetToProto(input: AuthorizationSubjectSet) {
|
|
1425
|
+
return create(SubjectSetSchema, {
|
|
1426
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1427
|
+
relation: input.relation,
|
|
1428
|
+
});
|
|
1429
|
+
}
|
|
1430
|
+
|
|
1431
|
+
function authorizationSubjectSetFromProto(input?: ProtoSubjectSet | undefined): AuthorizationSubjectSet | undefined {
|
|
1432
|
+
if (input === undefined) {
|
|
1433
|
+
return undefined;
|
|
1434
|
+
}
|
|
1435
|
+
return {
|
|
1436
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1437
|
+
relation: input.relation,
|
|
1438
|
+
};
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
function authorizationRelationshipTargetToProto(input: AuthorizationRelationshipTarget) {
|
|
1442
|
+
switch (input.kind.case) {
|
|
1443
|
+
case "subject":
|
|
1444
|
+
return create(RelationshipTargetSchema, {
|
|
1445
|
+
kind: { case: "subject", value: authorizationSubjectToProto(input.kind.value) },
|
|
1446
|
+
});
|
|
1447
|
+
case "resource":
|
|
1448
|
+
return create(RelationshipTargetSchema, {
|
|
1449
|
+
kind: { case: "resource", value: authorizationResourceToProto(input.kind.value) },
|
|
1450
|
+
});
|
|
1451
|
+
case "subjectSet":
|
|
1452
|
+
return create(RelationshipTargetSchema, {
|
|
1453
|
+
kind: { case: "subjectSet", value: authorizationSubjectSetToProto(input.kind.value) },
|
|
1454
|
+
});
|
|
1455
|
+
default:
|
|
1456
|
+
return create(RelationshipTargetSchema);
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
function authorizationRelationshipTargetFromProto(
|
|
1461
|
+
input?: ProtoRelationshipTarget | undefined,
|
|
1462
|
+
): AuthorizationRelationshipTarget | undefined {
|
|
1463
|
+
return input === undefined ? undefined : authorizationRelationshipTargetFromProtoRequired(input);
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
function authorizationRelationshipTargetFromProtoRequired(
|
|
1467
|
+
input: ProtoRelationshipTarget,
|
|
1468
|
+
): AuthorizationRelationshipTarget {
|
|
1469
|
+
switch (input.kind.case) {
|
|
1470
|
+
case "subject":
|
|
1471
|
+
return { kind: { case: "subject", value: authorizationSubjectFromProtoRequired(input.kind.value) } };
|
|
1472
|
+
case "resource":
|
|
1473
|
+
return { kind: { case: "resource", value: authorizationResourceFromProtoRequired(input.kind.value) } };
|
|
1474
|
+
case "subjectSet":
|
|
1475
|
+
return { kind: { case: "subjectSet", value: authorizationSubjectSetFromProto(input.kind.value)! } };
|
|
1476
|
+
default:
|
|
1477
|
+
return { kind: { case: undefined } };
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
|
|
1481
|
+
function authorizationActionToProto(input: AuthorizationAction) {
|
|
1482
|
+
return create(ActionSchema, {
|
|
1483
|
+
name: input.name,
|
|
1484
|
+
properties: optionalStruct(input.properties),
|
|
1485
|
+
});
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
function authorizationActionFromProto(input?: ProtoAction | undefined): AuthorizationAction | undefined {
|
|
1489
|
+
return input === undefined ? undefined : authorizationActionFromProtoRequired(input);
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
function authorizationActionFromProtoRequired(input: ProtoAction): AuthorizationAction {
|
|
1493
|
+
return {
|
|
1494
|
+
name: input.name,
|
|
1495
|
+
properties: optionalObjectFromStruct(input.properties),
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
function authorizationRelationshipToProto(input: AuthorizationRelationship) {
|
|
1500
|
+
return create(RelationshipSchema, {
|
|
1501
|
+
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1502
|
+
relation: input.relation,
|
|
1503
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1504
|
+
properties: optionalStruct(input.properties),
|
|
1505
|
+
target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
|
|
1509
|
+
function authorizationRelationshipFromProto(input: ProtoRelationship): AuthorizationRelationship {
|
|
1510
|
+
return {
|
|
1511
|
+
subject: authorizationSubjectFromProto(input.subject),
|
|
1512
|
+
relation: input.relation,
|
|
1513
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1514
|
+
properties: optionalObjectFromStruct(input.properties),
|
|
1515
|
+
target: authorizationRelationshipTargetFromProto(input.target),
|
|
1516
|
+
};
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
function authorizationRelationshipKeyToProto(input: AuthorizationRelationshipKey) {
|
|
1520
|
+
return create(RelationshipKeySchema, {
|
|
1521
|
+
subject: input.subject === undefined ? undefined : authorizationSubjectToProto(input.subject),
|
|
1522
|
+
relation: input.relation,
|
|
1523
|
+
resource: input.resource === undefined ? undefined : authorizationResourceToProto(input.resource),
|
|
1524
|
+
target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
|
|
1525
|
+
});
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1528
|
+
function authorizationRelationshipKeyFromProto(input: ProtoRelationshipKey): AuthorizationRelationshipKey {
|
|
1529
|
+
return {
|
|
1530
|
+
subject: authorizationSubjectFromProto(input.subject),
|
|
1531
|
+
relation: input.relation,
|
|
1532
|
+
resource: authorizationResourceFromProto(input.resource),
|
|
1533
|
+
target: authorizationRelationshipTargetFromProto(input.target),
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
function authorizationModelToProto(input: AuthorizationModel) {
|
|
1538
|
+
return {
|
|
1539
|
+
version: input.version ?? 0,
|
|
1540
|
+
resourceTypes: input.resourceTypes?.map(authorizationModelResourceTypeToProto) ?? [],
|
|
1541
|
+
};
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
function authorizationModelFromProto(input?: ProtoAuthorizationModel | undefined): AuthorizationModel | undefined {
|
|
1545
|
+
if (input === undefined) {
|
|
1546
|
+
return undefined;
|
|
1547
|
+
}
|
|
1548
|
+
return {
|
|
1549
|
+
version: input.version,
|
|
1550
|
+
resourceTypes: input.resourceTypes.map(authorizationModelResourceTypeFromProto),
|
|
1551
|
+
};
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
function authorizationModelResourceTypeToProto(input: AuthorizationModelResourceType) {
|
|
1555
|
+
return {
|
|
1556
|
+
name: input.name,
|
|
1557
|
+
relations: input.relations?.map(authorizationModelRelationToProto) ?? [],
|
|
1558
|
+
actions: input.actions?.map(authorizationModelActionToProto) ?? [],
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
function authorizationModelResourceTypeFromProto(
|
|
1563
|
+
input: ProtoAuthorizationModelResourceType,
|
|
1564
|
+
): AuthorizationModelResourceType {
|
|
1565
|
+
return {
|
|
1566
|
+
name: input.name,
|
|
1567
|
+
relations: input.relations.map(authorizationModelRelationFromProto),
|
|
1568
|
+
actions: input.actions.map(authorizationModelActionFromProto),
|
|
1569
|
+
};
|
|
1570
|
+
}
|
|
1571
|
+
|
|
1572
|
+
function authorizationModelRelationToProto(input: AuthorizationModelRelation) {
|
|
1573
|
+
return {
|
|
1574
|
+
name: input.name,
|
|
1575
|
+
subjectTypes: [...(input.subjectTypes ?? [])],
|
|
1576
|
+
allowedTargets: input.allowedTargets?.map(authorizationModelAllowedTargetToProto) ?? [],
|
|
1577
|
+
rewrite: input.rewrite === undefined ? undefined : authorizationModelRewriteToProto(input.rewrite),
|
|
1578
|
+
};
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
function authorizationModelRelationFromProto(
|
|
1582
|
+
input: ProtoAuthorizationModelRelation,
|
|
1583
|
+
): AuthorizationModelRelation {
|
|
1584
|
+
return {
|
|
1585
|
+
name: input.name,
|
|
1586
|
+
subjectTypes: [...input.subjectTypes],
|
|
1587
|
+
allowedTargets: input.allowedTargets.map(authorizationModelAllowedTargetFromProto),
|
|
1588
|
+
rewrite: authorizationModelRewriteFromProto(input.rewrite),
|
|
1589
|
+
};
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
function authorizationModelActionToProto(input: AuthorizationModelAction) {
|
|
1593
|
+
return {
|
|
1594
|
+
name: input.name,
|
|
1595
|
+
relations: [...(input.relations ?? [])],
|
|
1596
|
+
rewrite: input.rewrite === undefined ? undefined : authorizationModelRewriteToProto(input.rewrite),
|
|
1597
|
+
};
|
|
1598
|
+
}
|
|
1599
|
+
|
|
1600
|
+
function authorizationModelActionFromProto(input: ProtoAuthorizationModelAction): AuthorizationModelAction {
|
|
1601
|
+
return {
|
|
1602
|
+
name: input.name,
|
|
1603
|
+
relations: [...input.relations],
|
|
1604
|
+
rewrite: authorizationModelRewriteFromProto(input.rewrite),
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
function authorizationModelAllowedTargetToProto(input: AuthorizationModelAllowedTarget) {
|
|
1609
|
+
switch (input.kind.case) {
|
|
1610
|
+
case "subjectType":
|
|
1611
|
+
return { kind: { case: "subjectType" as const, value: input.kind.value } };
|
|
1612
|
+
case "resourceType":
|
|
1613
|
+
return { kind: { case: "resourceType" as const, value: input.kind.value } };
|
|
1614
|
+
case "subjectSet":
|
|
1615
|
+
return {
|
|
1616
|
+
kind: {
|
|
1617
|
+
case: "subjectSet" as const,
|
|
1618
|
+
value: {
|
|
1619
|
+
resourceType: input.kind.value.resourceType,
|
|
1620
|
+
relation: input.kind.value.relation,
|
|
1621
|
+
},
|
|
1622
|
+
},
|
|
1623
|
+
};
|
|
1624
|
+
default:
|
|
1625
|
+
return { kind: { case: undefined } };
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
function authorizationModelAllowedTargetFromProto(
|
|
1630
|
+
input: ProtoAuthorizationModelAllowedTarget,
|
|
1631
|
+
): AuthorizationModelAllowedTarget {
|
|
1632
|
+
switch (input.kind.case) {
|
|
1633
|
+
case "subjectType":
|
|
1634
|
+
return { kind: { case: "subjectType", value: input.kind.value } };
|
|
1635
|
+
case "resourceType":
|
|
1636
|
+
return { kind: { case: "resourceType", value: input.kind.value } };
|
|
1637
|
+
case "subjectSet":
|
|
1638
|
+
return {
|
|
1639
|
+
kind: {
|
|
1640
|
+
case: "subjectSet",
|
|
1641
|
+
value: authorizationModelSubjectSetTargetFromProto(input.kind.value),
|
|
1642
|
+
},
|
|
1643
|
+
};
|
|
1644
|
+
default:
|
|
1645
|
+
return { kind: { case: undefined } };
|
|
1646
|
+
}
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
function authorizationModelSubjectSetTargetFromProto(
|
|
1650
|
+
input: ProtoAuthorizationModelSubjectSetTarget,
|
|
1651
|
+
): AuthorizationModelSubjectSetTarget {
|
|
1652
|
+
return {
|
|
1653
|
+
resourceType: input.resourceType,
|
|
1654
|
+
relation: input.relation,
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
function authorizationModelRewriteToProto(input: AuthorizationModelRewrite): ProtoAuthorizationModelRewrite {
|
|
1659
|
+
switch (input.kind.case) {
|
|
1660
|
+
case "this":
|
|
1661
|
+
return { kind: { case: "this", value: {} } } as ProtoAuthorizationModelRewrite;
|
|
1662
|
+
case "computedUserset":
|
|
1663
|
+
return {
|
|
1664
|
+
kind: {
|
|
1665
|
+
case: "computedUserset",
|
|
1666
|
+
value: { relation: input.kind.value.relation },
|
|
1667
|
+
},
|
|
1668
|
+
} as ProtoAuthorizationModelRewrite;
|
|
1669
|
+
case "tupleToUserset":
|
|
1670
|
+
return {
|
|
1671
|
+
kind: {
|
|
1672
|
+
case: "tupleToUserset",
|
|
1673
|
+
value: {
|
|
1674
|
+
tuplesetRelation: input.kind.value.tuplesetRelation,
|
|
1675
|
+
computedRelation: input.kind.value.computedRelation,
|
|
1676
|
+
},
|
|
1677
|
+
},
|
|
1678
|
+
} as ProtoAuthorizationModelRewrite;
|
|
1679
|
+
case "union":
|
|
1680
|
+
return {
|
|
1681
|
+
kind: {
|
|
1682
|
+
case: "union",
|
|
1683
|
+
value: {
|
|
1684
|
+
children: input.kind.value.children?.map(authorizationModelRewriteToProto) ?? [],
|
|
1685
|
+
},
|
|
1686
|
+
},
|
|
1687
|
+
} as ProtoAuthorizationModelRewrite;
|
|
1688
|
+
default:
|
|
1689
|
+
return { kind: { case: undefined } } as ProtoAuthorizationModelRewrite;
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
function authorizationModelRewriteFromProto(
|
|
1694
|
+
input?: ProtoAuthorizationModelRewrite | undefined,
|
|
1695
|
+
): AuthorizationModelRewrite | undefined {
|
|
1696
|
+
if (input === undefined) {
|
|
1697
|
+
return undefined;
|
|
1698
|
+
}
|
|
1699
|
+
switch (input.kind.case) {
|
|
1700
|
+
case "this":
|
|
1701
|
+
return { kind: { case: "this", value: {} } };
|
|
1702
|
+
case "computedUserset":
|
|
1703
|
+
return { kind: { case: "computedUserset", value: authorizationComputedUsersetFromProto(input.kind.value) } };
|
|
1704
|
+
case "tupleToUserset":
|
|
1705
|
+
return { kind: { case: "tupleToUserset", value: authorizationTupleToUsersetFromProto(input.kind.value) } };
|
|
1706
|
+
case "union":
|
|
1707
|
+
return { kind: { case: "union", value: authorizationRewriteUnionFromProto(input.kind.value) } };
|
|
1708
|
+
default:
|
|
1709
|
+
return { kind: { case: undefined } };
|
|
1710
|
+
}
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
function authorizationComputedUsersetFromProto(
|
|
1714
|
+
input: ProtoAuthorizationModelComputedUserset,
|
|
1715
|
+
): AuthorizationModelComputedUserset {
|
|
1716
|
+
return { relation: input.relation };
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
function authorizationTupleToUsersetFromProto(
|
|
1720
|
+
input: ProtoAuthorizationModelTupleToUserset,
|
|
1721
|
+
): AuthorizationModelTupleToUserset {
|
|
1722
|
+
return {
|
|
1723
|
+
tuplesetRelation: input.tuplesetRelation,
|
|
1724
|
+
computedRelation: input.computedRelation,
|
|
1725
|
+
};
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
function authorizationRewriteUnionFromProto(
|
|
1729
|
+
input: ProtoAuthorizationModelRewriteUnion,
|
|
1730
|
+
): AuthorizationModelRewriteUnion {
|
|
1731
|
+
return { children: input.children.map((child) => authorizationModelRewriteFromProto(child)!) };
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
function authorizationModelRefToProto(input: AuthorizationModelRef) {
|
|
1735
|
+
return create(AuthorizationModelRefSchema, {
|
|
1736
|
+
id: input.id,
|
|
1737
|
+
version: input.version,
|
|
1738
|
+
createdAt: input.createdAt === undefined ? undefined : timestampFromDate(input.createdAt),
|
|
1739
|
+
});
|
|
1740
|
+
}
|
|
1741
|
+
|
|
1742
|
+
function authorizationModelRefFromProto(input?: ProtoAuthorizationModelRef | undefined): AuthorizationModelRef | undefined {
|
|
1743
|
+
return input === undefined ? undefined : authorizationModelRefFromProtoRequired(input);
|
|
1744
|
+
}
|
|
1745
|
+
|
|
1746
|
+
function authorizationModelRefFromProtoRequired(input: ProtoAuthorizationModelRef): AuthorizationModelRef {
|
|
1747
|
+
return {
|
|
1748
|
+
id: input.id,
|
|
1749
|
+
version: input.version,
|
|
1750
|
+
createdAt: input.createdAt === undefined ? undefined : dateFromTimestamp(input.createdAt),
|
|
1751
|
+
};
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
function authorizationExpandToProto(input: AuthorizationExpand) {
|
|
1755
|
+
return create(ExpandResponseSchema, {
|
|
1756
|
+
root: input.root === undefined ? undefined : authorizationExpandNodeToProto(input.root),
|
|
1757
|
+
truncated: input.truncated ?? false,
|
|
1758
|
+
cycleDetected: input.cycleDetected ?? false,
|
|
1759
|
+
maxDepthReached: input.maxDepthReached ?? false,
|
|
1760
|
+
modelId: input.modelId ?? "",
|
|
1761
|
+
});
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
function authorizationExpandFromProto(input: ProtoExpandResponse): AuthorizationExpand {
|
|
1765
|
+
return {
|
|
1766
|
+
root: authorizationExpandNodeFromProto(input.root),
|
|
1767
|
+
truncated: input.truncated,
|
|
1768
|
+
cycleDetected: input.cycleDetected,
|
|
1769
|
+
maxDepthReached: input.maxDepthReached,
|
|
1770
|
+
modelId: input.modelId,
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1773
|
+
|
|
1774
|
+
function authorizationExpandNodeToProto(input: AuthorizationExpandNode): ProtoExpandNode {
|
|
1775
|
+
return create(ExpandNodeSchema, {
|
|
1776
|
+
target: input.target === undefined ? undefined : authorizationRelationshipTargetToProto(input.target),
|
|
1777
|
+
relation: input.relation ?? "",
|
|
1778
|
+
children: input.children?.map(authorizationExpandNodeToProto) ?? [],
|
|
1779
|
+
});
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
function authorizationExpandNodeFromProto(input?: ProtoExpandNode | undefined): AuthorizationExpandNode | undefined {
|
|
1783
|
+
if (input === undefined) {
|
|
1784
|
+
return undefined;
|
|
1785
|
+
}
|
|
1786
|
+
return {
|
|
1787
|
+
target: authorizationRelationshipTargetFromProto(input.target),
|
|
1788
|
+
relation: input.relation,
|
|
1789
|
+
children: input.children.map((child) => authorizationExpandNodeFromProto(child)!),
|
|
1790
|
+
};
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
function resolveAuthorizationSocketTarget(
|
|
1794
|
+
socketPath = process.env[ENV_AUTHORIZATION_SOCKET],
|
|
1795
|
+
): string {
|
|
153
1796
|
const trimmed = socketPath?.trim() ?? "";
|
|
154
1797
|
if (!trimmed) {
|
|
155
1798
|
throw new Error(`authorization: ${ENV_AUTHORIZATION_SOCKET} is not set`);
|
|
@@ -207,3 +1850,9 @@ function authorizationRelayTokenInterceptor(token: string): Interceptor {
|
|
|
207
1850
|
return next(req);
|
|
208
1851
|
};
|
|
209
1852
|
}
|
|
1853
|
+
|
|
1854
|
+
function pushCapability(capabilities: string[], capability: string): void {
|
|
1855
|
+
if (!capabilities.includes(capability)) {
|
|
1856
|
+
capabilities.push(capability);
|
|
1857
|
+
}
|
|
1858
|
+
}
|