@metamask/permission-controller 13.1.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -1
- package/LICENSE +1 -0
- package/dist/{Caveat.d.mts → Caveat.d.ts} +3 -3
- package/dist/Caveat.d.ts.map +1 -0
- package/dist/{Caveat.mjs → Caveat.js} +4 -4
- package/dist/Caveat.js.map +1 -0
- package/dist/{Permission.d.mts → Permission.d.ts} +7 -7
- package/dist/Permission.d.ts.map +1 -0
- package/dist/{Permission.mjs → Permission.js} +2 -2
- package/dist/Permission.js.map +1 -0
- package/dist/{PermissionController-method-action-types.d.cts → PermissionController-method-action-types.d.ts} +2 -2
- package/dist/PermissionController-method-action-types.d.ts.map +1 -0
- package/dist/{PermissionController-method-action-types.mjs → PermissionController-method-action-types.js} +1 -1
- package/dist/PermissionController-method-action-types.js.map +1 -0
- package/dist/{PermissionController.d.cts → PermissionController.d.ts} +11 -11
- package/dist/PermissionController.d.ts.map +1 -0
- package/dist/PermissionController.js +1533 -0
- package/dist/PermissionController.js.map +1 -0
- package/dist/{SubjectMetadataController-method-action-types.d.cts → SubjectMetadataController-method-action-types.d.ts} +2 -2
- package/dist/SubjectMetadataController-method-action-types.d.ts.map +1 -0
- package/dist/{SubjectMetadataController-method-action-types.mjs → SubjectMetadataController-method-action-types.js} +1 -1
- package/dist/SubjectMetadataController-method-action-types.js.map +1 -0
- package/dist/{SubjectMetadataController.d.cts → SubjectMetadataController.d.ts} +8 -8
- package/dist/SubjectMetadataController.d.ts.map +1 -0
- package/dist/SubjectMetadataController.js +157 -0
- package/dist/SubjectMetadataController.js.map +1 -0
- package/dist/{createRestrictedMethodMessenger.d.cts → createRestrictedMethodMessenger.d.ts} +3 -3
- package/dist/createRestrictedMethodMessenger.d.ts.map +1 -0
- package/dist/{createRestrictedMethodMessenger.mjs → createRestrictedMethodMessenger.js} +2 -2
- package/dist/createRestrictedMethodMessenger.js.map +1 -0
- package/dist/{errors.d.mts → errors.d.ts} +6 -6
- package/dist/errors.d.ts.map +1 -0
- package/dist/{errors.mjs → errors.js} +17 -3
- package/dist/errors.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +12 -12
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/{permission-middleware.d.cts → permission-middleware.d.ts} +7 -7
- package/dist/permission-middleware.d.ts.map +1 -0
- package/dist/{permission-middleware.mjs → permission-middleware.js} +2 -2
- package/dist/permission-middleware.js.map +1 -0
- package/dist/{utils.d.cts → utils.d.ts} +3 -3
- package/dist/utils.d.ts.map +1 -0
- package/dist/{utils.mjs → utils.js} +1 -1
- package/dist/utils.js.map +1 -0
- package/package.json +25 -27
- package/dist/Caveat.cjs +0 -48
- package/dist/Caveat.cjs.map +0 -1
- package/dist/Caveat.d.cts +0 -211
- package/dist/Caveat.d.cts.map +0 -1
- package/dist/Caveat.d.mts.map +0 -1
- package/dist/Caveat.mjs.map +0 -1
- package/dist/Permission.cjs +0 -65
- package/dist/Permission.cjs.map +0 -1
- package/dist/Permission.d.cts +0 -415
- package/dist/Permission.d.cts.map +0 -1
- package/dist/Permission.d.mts.map +0 -1
- package/dist/Permission.mjs.map +0 -1
- package/dist/PermissionController-method-action-types.cjs +0 -7
- package/dist/PermissionController-method-action-types.cjs.map +0 -1
- package/dist/PermissionController-method-action-types.d.cts.map +0 -1
- package/dist/PermissionController-method-action-types.d.mts +0 -374
- package/dist/PermissionController-method-action-types.d.mts.map +0 -1
- package/dist/PermissionController-method-action-types.mjs.map +0 -1
- package/dist/PermissionController.cjs +0 -1257
- package/dist/PermissionController.cjs.map +0 -1
- package/dist/PermissionController.d.cts.map +0 -1
- package/dist/PermissionController.d.mts +0 -753
- package/dist/PermissionController.d.mts.map +0 -1
- package/dist/PermissionController.mjs +0 -1257
- package/dist/PermissionController.mjs.map +0 -1
- package/dist/SubjectMetadataController-method-action-types.cjs +0 -7
- package/dist/SubjectMetadataController-method-action-types.cjs.map +0 -1
- package/dist/SubjectMetadataController-method-action-types.d.cts.map +0 -1
- package/dist/SubjectMetadataController-method-action-types.d.mts +0 -51
- package/dist/SubjectMetadataController-method-action-types.d.mts.map +0 -1
- package/dist/SubjectMetadataController-method-action-types.mjs.map +0 -1
- package/dist/SubjectMetadataController.cjs +0 -158
- package/dist/SubjectMetadataController.cjs.map +0 -1
- package/dist/SubjectMetadataController.d.cts.map +0 -1
- package/dist/SubjectMetadataController.d.mts +0 -104
- package/dist/SubjectMetadataController.d.mts.map +0 -1
- package/dist/SubjectMetadataController.mjs +0 -154
- package/dist/SubjectMetadataController.mjs.map +0 -1
- package/dist/createRestrictedMethodMessenger.cjs +0 -20
- package/dist/createRestrictedMethodMessenger.cjs.map +0 -1
- package/dist/createRestrictedMethodMessenger.d.cts.map +0 -1
- package/dist/createRestrictedMethodMessenger.d.mts +0 -42
- package/dist/createRestrictedMethodMessenger.d.mts.map +0 -1
- package/dist/createRestrictedMethodMessenger.mjs.map +0 -1
- package/dist/errors.cjs +0 -226
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -183
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.mts.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/index.cjs +0 -30
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -12
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -9
- package/dist/index.mjs.map +0 -1
- package/dist/permission-middleware.cjs +0 -59
- package/dist/permission-middleware.cjs.map +0 -1
- package/dist/permission-middleware.d.cts.map +0 -1
- package/dist/permission-middleware.d.mts +0 -49
- package/dist/permission-middleware.d.mts.map +0 -1
- package/dist/permission-middleware.mjs.map +0 -1
- package/dist/utils.cjs +0 -44
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.mts +0 -34
- package/dist/utils.d.mts.map +0 -1
- package/dist/utils.mjs.map +0 -1
|
@@ -1,753 +0,0 @@
|
|
|
1
|
-
import type { ApprovalControllerAcceptRequestAction, ApprovalControllerAddRequestAction, ApprovalControllerHasRequestAction, ApprovalControllerRejectRequestAction } from "@metamask/approval-controller";
|
|
2
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
|
|
3
|
-
import { BaseController } from "@metamask/base-controller";
|
|
4
|
-
import type { NonEmptyArray } from "@metamask/controller-utils";
|
|
5
|
-
import type { Messenger, ActionConstraint, EventConstraint } from "@metamask/messenger";
|
|
6
|
-
import type { Json } from "@metamask/utils";
|
|
7
|
-
import type { CaveatConstraint, CaveatDiffMap, CaveatSpecificationConstraint, CaveatSpecificationMap, ExtractCaveat, ExtractCaveats, ExtractCaveatValue } from "./Caveat.mjs";
|
|
8
|
-
import type { EndowmentSpecificationConstraint, ExtractAllowedCaveatTypes, OriginString, PermissionConstraint, PermissionSpecificationConstraint, PermissionSpecificationMap, RequestedPermissions, RestrictedMethodParameters, RestrictedMethodSpecificationConstraint, SideEffectHandler, ValidPermission, ValidPermissionSpecification } from "./Permission.mjs";
|
|
9
|
-
import type { PermissionControllerMethodActions } from "./PermissionController-method-action-types.mjs";
|
|
10
|
-
import type { SubjectMetadataControllerGetSubjectMetadataAction } from "./SubjectMetadataController-method-action-types.mjs";
|
|
11
|
-
/**
|
|
12
|
-
* Metadata associated with {@link PermissionController} subjects.
|
|
13
|
-
*/
|
|
14
|
-
export type PermissionSubjectMetadata = {
|
|
15
|
-
origin: OriginString;
|
|
16
|
-
};
|
|
17
|
-
/**
|
|
18
|
-
* Metadata associated with permission requests.
|
|
19
|
-
*/
|
|
20
|
-
export type PermissionsRequestMetadata = PermissionSubjectMetadata & {
|
|
21
|
-
id: string;
|
|
22
|
-
[key: string]: Json;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* A diff produced by an incremental permissions request.
|
|
26
|
-
*/
|
|
27
|
-
export type PermissionDiffMap<TargetName extends string, AllowedCaveats extends CaveatConstraint> = Record<TargetName, CaveatDiffMap<AllowedCaveats>>;
|
|
28
|
-
/**
|
|
29
|
-
* Used for prompting the user about a proposed new permission.
|
|
30
|
-
* Includes information about the grantee subject, requested permissions, the
|
|
31
|
-
* diff relative to the previously granted permissions (if relevant), and any
|
|
32
|
-
* additional information added by the consumer.
|
|
33
|
-
*
|
|
34
|
-
* All properties except `diff` and `permissions` are passed to any factories
|
|
35
|
-
* for the requested permissions.
|
|
36
|
-
*/
|
|
37
|
-
export type PermissionsRequest = {
|
|
38
|
-
metadata: PermissionsRequestMetadata;
|
|
39
|
-
permissions: RequestedPermissions;
|
|
40
|
-
[key: string]: Json;
|
|
41
|
-
} & {
|
|
42
|
-
diff?: {
|
|
43
|
-
currentPermissions: SubjectPermissions<PermissionConstraint>;
|
|
44
|
-
permissionDiffMap: PermissionDiffMap<string, CaveatConstraint>;
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Metadata associated with an approved permission request.
|
|
49
|
-
*/
|
|
50
|
-
type ApprovedPermissionsMetadata = {
|
|
51
|
-
data?: Record<string, unknown>;
|
|
52
|
-
id: string;
|
|
53
|
-
origin: OriginString;
|
|
54
|
-
};
|
|
55
|
-
export type SideEffects = {
|
|
56
|
-
permittedHandlers: Record<string, SideEffectHandler<ActionConstraint, EventConstraint>>;
|
|
57
|
-
failureHandlers: Record<string, SideEffectHandler<ActionConstraint, EventConstraint>>;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* The name of the {@link PermissionController}.
|
|
61
|
-
*/
|
|
62
|
-
declare const controllerName = "PermissionController";
|
|
63
|
-
/**
|
|
64
|
-
* Permissions associated with a {@link PermissionController} subject.
|
|
65
|
-
*/
|
|
66
|
-
export type SubjectPermissions<Permission extends PermissionConstraint> = Record<Permission['parentCapability'], Permission>;
|
|
67
|
-
/**
|
|
68
|
-
* Permissions and metadata associated with a {@link PermissionController}
|
|
69
|
-
* subject.
|
|
70
|
-
*/
|
|
71
|
-
export type PermissionSubjectEntry<SubjectPermission extends PermissionConstraint> = {
|
|
72
|
-
origin: SubjectPermission['invoker'];
|
|
73
|
-
permissions: SubjectPermissions<SubjectPermission>;
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* All subjects of a {@link PermissionController}.
|
|
77
|
-
*
|
|
78
|
-
* @template SubjectPermission - The permissions of the subject.
|
|
79
|
-
*/
|
|
80
|
-
export type PermissionControllerSubjects<SubjectPermission extends PermissionConstraint> = Record<SubjectPermission['invoker'], PermissionSubjectEntry<SubjectPermission>>;
|
|
81
|
-
/**
|
|
82
|
-
* The state of a {@link PermissionController}.
|
|
83
|
-
*
|
|
84
|
-
* @template Permission - The controller's permission type union.
|
|
85
|
-
*/
|
|
86
|
-
export type PermissionControllerState<Permission> = Permission extends PermissionConstraint ? {
|
|
87
|
-
subjects: PermissionControllerSubjects<Permission>;
|
|
88
|
-
} : never;
|
|
89
|
-
/**
|
|
90
|
-
* Gets the state of the {@link PermissionController}.
|
|
91
|
-
*/
|
|
92
|
-
export type PermissionControllerGetStateAction = ControllerGetStateAction<typeof controllerName, PermissionControllerState<PermissionConstraint>>;
|
|
93
|
-
/**
|
|
94
|
-
* Gets the state of the {@link PermissionController}.
|
|
95
|
-
*
|
|
96
|
-
* @deprecated Use `PermissionControllerGetStateAction` instead.
|
|
97
|
-
*/
|
|
98
|
-
export type GetPermissionControllerState = PermissionControllerGetStateAction;
|
|
99
|
-
/**
|
|
100
|
-
* Gets the names of all subjects from the {@link PermissionController}.
|
|
101
|
-
*
|
|
102
|
-
* @deprecated Use `PermissionControllerGetSubjectNamesAction` instead.
|
|
103
|
-
*/
|
|
104
|
-
export type GetSubjects = {
|
|
105
|
-
type: `${typeof controllerName}:getSubjectNames`;
|
|
106
|
-
handler: () => (keyof PermissionControllerSubjects<PermissionConstraint>)[];
|
|
107
|
-
};
|
|
108
|
-
/**
|
|
109
|
-
* Gets the permissions for specified subject.
|
|
110
|
-
*
|
|
111
|
-
* @deprecated Use `PermissionControllerGetPermissionsAction` instead.
|
|
112
|
-
*/
|
|
113
|
-
export type GetPermissions = {
|
|
114
|
-
type: `${typeof controllerName}:getPermissions`;
|
|
115
|
-
handler: GenericPermissionController['getPermissions'];
|
|
116
|
-
};
|
|
117
|
-
/**
|
|
118
|
-
* Checks whether the specified subject has any permissions.
|
|
119
|
-
*
|
|
120
|
-
* @deprecated Use `PermissionControllerHasPermissionAction` instead.
|
|
121
|
-
*/
|
|
122
|
-
export type HasPermissions = {
|
|
123
|
-
type: `${typeof controllerName}:hasPermissions`;
|
|
124
|
-
handler: GenericPermissionController['hasPermissions'];
|
|
125
|
-
};
|
|
126
|
-
/**
|
|
127
|
-
* Checks whether the specified subject has a specific permission.
|
|
128
|
-
*
|
|
129
|
-
* @deprecated Use `PermissionControllerHasPermissionAction` instead.
|
|
130
|
-
*/
|
|
131
|
-
export type HasPermission = {
|
|
132
|
-
type: `${typeof controllerName}:hasPermission`;
|
|
133
|
-
handler: GenericPermissionController['hasPermission'];
|
|
134
|
-
};
|
|
135
|
-
/**
|
|
136
|
-
* Directly grants given permissions for a specified origin without requesting user approval.
|
|
137
|
-
*
|
|
138
|
-
* @deprecated Use `PermissionControllerGrantPermissionsAction` instead.
|
|
139
|
-
*/
|
|
140
|
-
export type GrantPermissions = {
|
|
141
|
-
type: `${typeof controllerName}:grantPermissions`;
|
|
142
|
-
handler: GenericPermissionController['grantPermissions'];
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Directly grants given permissions for a specified origin without requesting user approval.
|
|
146
|
-
*
|
|
147
|
-
* @deprecated Use `PermissionControllerGrantPermissionsIncrementalAction`
|
|
148
|
-
* instead.
|
|
149
|
-
*/
|
|
150
|
-
export type GrantPermissionsIncremental = {
|
|
151
|
-
type: `${typeof controllerName}:grantPermissionsIncremental`;
|
|
152
|
-
handler: GenericPermissionController['grantPermissionsIncremental'];
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* Requests given permissions for a specified origin.
|
|
156
|
-
*
|
|
157
|
-
* @deprecated Use `PermissionControllerRequestPermissionsAction` instead.
|
|
158
|
-
*/
|
|
159
|
-
export type RequestPermissions = {
|
|
160
|
-
type: `${typeof controllerName}:requestPermissions`;
|
|
161
|
-
handler: GenericPermissionController['requestPermissions'];
|
|
162
|
-
};
|
|
163
|
-
/**
|
|
164
|
-
* Requests given permissions for a specified origin.
|
|
165
|
-
*
|
|
166
|
-
* @deprecated Use `PermissionControllerRequestPermissionsAction` instead.
|
|
167
|
-
*/
|
|
168
|
-
export type RequestPermissionsIncremental = {
|
|
169
|
-
type: `${typeof controllerName}:requestPermissionsIncremental`;
|
|
170
|
-
handler: GenericPermissionController['requestPermissionsIncremental'];
|
|
171
|
-
};
|
|
172
|
-
/**
|
|
173
|
-
* Removes the specified permissions for each origin.
|
|
174
|
-
*
|
|
175
|
-
* @deprecated Use `PermissionControllerRevokePermissionsAction` instead.
|
|
176
|
-
*/
|
|
177
|
-
export type RevokePermissions = {
|
|
178
|
-
type: `${typeof controllerName}:revokePermissions`;
|
|
179
|
-
handler: GenericPermissionController['revokePermissions'];
|
|
180
|
-
};
|
|
181
|
-
/**
|
|
182
|
-
* Removes all permissions for a given origin.
|
|
183
|
-
*
|
|
184
|
-
* @deprecated Use `PermissionControllerRevokeAllPermissionAction` instead.
|
|
185
|
-
*/
|
|
186
|
-
export type RevokeAllPermissions = {
|
|
187
|
-
type: `${typeof controllerName}:revokeAllPermissions`;
|
|
188
|
-
handler: GenericPermissionController['revokeAllPermissions'];
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* Revokes all permissions corresponding to the specified target for all subjects.
|
|
192
|
-
* Does nothing if no subjects or no such permission exists.
|
|
193
|
-
*
|
|
194
|
-
* @deprecated Use `PermissionControllerRevokePermissionForAllSubjectsAction`
|
|
195
|
-
* instead.
|
|
196
|
-
*/
|
|
197
|
-
export type RevokePermissionForAllSubjects = {
|
|
198
|
-
type: `${typeof controllerName}:revokePermissionForAllSubjects`;
|
|
199
|
-
handler: GenericPermissionController['revokePermissionForAllSubjects'];
|
|
200
|
-
};
|
|
201
|
-
/**
|
|
202
|
-
* Updates a caveat value for a specified caveat type belonging to a specific target and origin.
|
|
203
|
-
*
|
|
204
|
-
* @deprecated Use `PermissionControllerUpdateCaveatAction` instead.
|
|
205
|
-
*/
|
|
206
|
-
export type UpdateCaveat = {
|
|
207
|
-
type: `${typeof controllerName}:updateCaveat`;
|
|
208
|
-
handler: GenericPermissionController['updateCaveat'];
|
|
209
|
-
};
|
|
210
|
-
/**
|
|
211
|
-
* Get a caveat value for a specified caveat type belonging to a specific target and origin.
|
|
212
|
-
*
|
|
213
|
-
* @deprecated Use `PermissionControllerGetCaveatAction` instead.
|
|
214
|
-
*/
|
|
215
|
-
export type GetCaveat = {
|
|
216
|
-
type: `${typeof controllerName}:getCaveat`;
|
|
217
|
-
handler: GenericPermissionController['getCaveat'];
|
|
218
|
-
};
|
|
219
|
-
/**
|
|
220
|
-
* Clears all permissions from the {@link PermissionController}.
|
|
221
|
-
*
|
|
222
|
-
* @deprecated Use `PermissionControllerClearStateAction` instead.
|
|
223
|
-
*/
|
|
224
|
-
export type ClearPermissions = {
|
|
225
|
-
type: `${typeof controllerName}:clearPermissions`;
|
|
226
|
-
handler: () => void;
|
|
227
|
-
};
|
|
228
|
-
/**
|
|
229
|
-
* Gets the endowments for the given subject and permission.
|
|
230
|
-
*
|
|
231
|
-
* @deprecated Use `PermissionControllerGetEndowmentsAction` instead.
|
|
232
|
-
*/
|
|
233
|
-
export type GetEndowments = {
|
|
234
|
-
type: `${typeof controllerName}:getEndowments`;
|
|
235
|
-
handler: GenericPermissionController['getEndowments'];
|
|
236
|
-
};
|
|
237
|
-
/**
|
|
238
|
-
* The {@link Messenger} actions of the {@link PermissionController}.
|
|
239
|
-
*/
|
|
240
|
-
export type PermissionControllerActions = PermissionControllerGetStateAction | PermissionControllerMethodActions;
|
|
241
|
-
/**
|
|
242
|
-
* The generic state change event of the {@link PermissionController}.
|
|
243
|
-
*/
|
|
244
|
-
export type PermissionControllerStateChange = ControllerStateChangeEvent<typeof controllerName, PermissionControllerState<PermissionConstraint>>;
|
|
245
|
-
/**
|
|
246
|
-
* The {@link Messenger} events of the {@link PermissionController}.
|
|
247
|
-
*
|
|
248
|
-
* The permission controller only emits its generic state change events.
|
|
249
|
-
* Consumers should use selector subscriptions to subscribe to relevant
|
|
250
|
-
* substate.
|
|
251
|
-
*/
|
|
252
|
-
export type PermissionControllerEvents = PermissionControllerStateChange;
|
|
253
|
-
/**
|
|
254
|
-
* The external {@link Messenger} actions available to the
|
|
255
|
-
* {@link PermissionController}.
|
|
256
|
-
*/
|
|
257
|
-
type AllowedActions = ApprovalControllerAddRequestAction | ApprovalControllerHasRequestAction | ApprovalControllerAcceptRequestAction | ApprovalControllerRejectRequestAction | SubjectMetadataControllerGetSubjectMetadataAction;
|
|
258
|
-
/**
|
|
259
|
-
* The messenger of the {@link PermissionController}.
|
|
260
|
-
*/
|
|
261
|
-
export type PermissionControllerMessenger = Messenger<typeof controllerName, PermissionControllerActions | AllowedActions, PermissionControllerEvents>;
|
|
262
|
-
export type SideEffectMessenger<Actions extends ActionConstraint, Events extends EventConstraint> = Messenger<typeof controllerName, Actions | AllowedActions, Events>;
|
|
263
|
-
/**
|
|
264
|
-
* A generic {@link PermissionController}.
|
|
265
|
-
*/
|
|
266
|
-
export type GenericPermissionController = PermissionController<PermissionSpecificationConstraint, CaveatSpecificationConstraint>;
|
|
267
|
-
/**
|
|
268
|
-
* Describes the possible results of a {@link CaveatMutator} function.
|
|
269
|
-
*/
|
|
270
|
-
export declare enum CaveatMutatorOperation {
|
|
271
|
-
Noop = 0,
|
|
272
|
-
UpdateValue = 1,
|
|
273
|
-
DeleteCaveat = 2,
|
|
274
|
-
RevokePermission = 3
|
|
275
|
-
}
|
|
276
|
-
/**
|
|
277
|
-
* Given a caveat value, returns a {@link CaveatMutatorOperation} and, optionally,
|
|
278
|
-
* a new caveat value.
|
|
279
|
-
*
|
|
280
|
-
* @see {@link PermissionController.updatePermissionsByCaveat} for more details.
|
|
281
|
-
* @template Caveat - The caveat type for which this mutator is intended.
|
|
282
|
-
* @param caveatValue - The existing value of the caveat being mutated.
|
|
283
|
-
* @returns A tuple of the mutation result and, optionally, the new caveat
|
|
284
|
-
* value.
|
|
285
|
-
*/
|
|
286
|
-
export type CaveatMutator<TargetCaveat extends CaveatConstraint> = (caveatValue: TargetCaveat['value']) => CaveatMutatorResult;
|
|
287
|
-
type CaveatMutatorResult = Readonly<{
|
|
288
|
-
operation: CaveatMutatorOperation.UpdateValue;
|
|
289
|
-
value: CaveatConstraint['value'];
|
|
290
|
-
}> | Readonly<{
|
|
291
|
-
operation: Exclude<CaveatMutatorOperation, CaveatMutatorOperation.UpdateValue>;
|
|
292
|
-
}>;
|
|
293
|
-
/**
|
|
294
|
-
* Extracts the permission(s) specified by the given permission and caveat
|
|
295
|
-
* specifications.
|
|
296
|
-
*
|
|
297
|
-
* @template ControllerPermissionSpecification - The permission specification(s)
|
|
298
|
-
* to extract from.
|
|
299
|
-
* @template ControllerCaveatSpecification - The caveat specification(s) to
|
|
300
|
-
* extract from. Necessary because {@link Permission} has a generic parameter
|
|
301
|
-
* that describes the allowed caveats for the permission.
|
|
302
|
-
*/
|
|
303
|
-
export type ExtractPermission<ControllerPermissionSpecification extends PermissionSpecificationConstraint, ControllerCaveatSpecification extends CaveatSpecificationConstraint> = ControllerPermissionSpecification extends ValidPermissionSpecification<ControllerPermissionSpecification> ? ValidPermission<ControllerPermissionSpecification['targetName'], ExtractCaveats<ControllerCaveatSpecification>> : never;
|
|
304
|
-
/**
|
|
305
|
-
* Extracts the restricted method permission(s) specified by the given
|
|
306
|
-
* permission and caveat specifications.
|
|
307
|
-
*
|
|
308
|
-
* @template ControllerPermissionSpecification - The permission specification(s)
|
|
309
|
-
* to extract from.
|
|
310
|
-
* @template ControllerCaveatSpecification - The caveat specification(s) to
|
|
311
|
-
* extract from. Necessary because {@link Permission} has a generic parameter
|
|
312
|
-
* that describes the allowed caveats for the permission.
|
|
313
|
-
*/
|
|
314
|
-
export type ExtractRestrictedMethodPermission<ControllerPermissionSpecification extends PermissionSpecificationConstraint, ControllerCaveatSpecification extends CaveatSpecificationConstraint> = ExtractPermission<Extract<ControllerPermissionSpecification, RestrictedMethodSpecificationConstraint>, ControllerCaveatSpecification>;
|
|
315
|
-
/**
|
|
316
|
-
* Extracts the endowment permission(s) specified by the given permission and
|
|
317
|
-
* caveat specifications.
|
|
318
|
-
*
|
|
319
|
-
* @template ControllerPermissionSpecification - The permission specification(s)
|
|
320
|
-
* to extract from.
|
|
321
|
-
* @template ControllerCaveatSpecification - The caveat specification(s) to
|
|
322
|
-
* extract from. Necessary because {@link Permission} has a generic parameter
|
|
323
|
-
* that describes the allowed caveats for the permission.
|
|
324
|
-
*/
|
|
325
|
-
export type ExtractEndowmentPermission<ControllerPermissionSpecification extends PermissionSpecificationConstraint, ControllerCaveatSpecification extends CaveatSpecificationConstraint> = ExtractPermission<Extract<ControllerPermissionSpecification, EndowmentSpecificationConstraint>, ControllerCaveatSpecification>;
|
|
326
|
-
/**
|
|
327
|
-
* Options for the {@link PermissionController} constructor.
|
|
328
|
-
*
|
|
329
|
-
* @template ControllerPermissionSpecification - A union of the types of all
|
|
330
|
-
* permission specifications available to the controller. Any referenced caveats
|
|
331
|
-
* must be included in the controller's caveat specifications.
|
|
332
|
-
* @template ControllerCaveatSpecification - A union of the types of all
|
|
333
|
-
* caveat specifications available to the controller.
|
|
334
|
-
*/
|
|
335
|
-
export type PermissionControllerOptions<ControllerPermissionSpecification extends PermissionSpecificationConstraint, ControllerCaveatSpecification extends CaveatSpecificationConstraint> = {
|
|
336
|
-
messenger: PermissionControllerMessenger;
|
|
337
|
-
caveatSpecifications: CaveatSpecificationMap<ControllerCaveatSpecification>;
|
|
338
|
-
permissionSpecifications: PermissionSpecificationMap<ControllerPermissionSpecification>;
|
|
339
|
-
unrestrictedMethods: readonly string[];
|
|
340
|
-
state?: Partial<PermissionControllerState<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>;
|
|
341
|
-
};
|
|
342
|
-
/**
|
|
343
|
-
* The permission controller. See the [Architecture](../ARCHITECTURE.md)
|
|
344
|
-
* document for details.
|
|
345
|
-
*
|
|
346
|
-
* Assumes the existence of an {@link ApprovalController} reachable via the
|
|
347
|
-
* {@link Messenger}.
|
|
348
|
-
*
|
|
349
|
-
* @template ControllerPermissionSpecification - A union of the types of all
|
|
350
|
-
* permission specifications available to the controller. Any referenced caveats
|
|
351
|
-
* must be included in the controller's caveat specifications.
|
|
352
|
-
* @template ControllerCaveatSpecification - A union of the types of all
|
|
353
|
-
* caveat specifications available to the controller.
|
|
354
|
-
*/
|
|
355
|
-
export declare class PermissionController<ControllerPermissionSpecification extends PermissionSpecificationConstraint = PermissionSpecificationConstraint, ControllerCaveatSpecification extends CaveatSpecificationConstraint = CaveatSpecificationConstraint> extends BaseController<typeof controllerName, PermissionControllerState<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>, PermissionControllerMessenger> {
|
|
356
|
-
#private;
|
|
357
|
-
/**
|
|
358
|
-
* The names of all JSON-RPC methods that will be ignored by the controller.
|
|
359
|
-
*
|
|
360
|
-
* @returns The names of all unrestricted JSON-RPC methods
|
|
361
|
-
*/
|
|
362
|
-
get unrestrictedMethods(): ReadonlySet<string>;
|
|
363
|
-
/**
|
|
364
|
-
* Checks whether the given method was declared as unrestricted at
|
|
365
|
-
* construction time. Methods unknown to the controller return `false` and
|
|
366
|
-
* would be treated as restricted by callers such as the permission
|
|
367
|
-
* middleware.
|
|
368
|
-
*
|
|
369
|
-
* @param method - The name of the method to check.
|
|
370
|
-
* @returns Whether the method is unrestricted.
|
|
371
|
-
*/
|
|
372
|
-
hasUnrestrictedMethod(method: string): boolean;
|
|
373
|
-
/**
|
|
374
|
-
* Constructs the PermissionController.
|
|
375
|
-
*
|
|
376
|
-
* @param options - Permission controller options.
|
|
377
|
-
* @param options.caveatSpecifications - The specifications of all caveats
|
|
378
|
-
* available to the controller. See {@link CaveatSpecificationMap} and the
|
|
379
|
-
* documentation for more details.
|
|
380
|
-
* @param options.permissionSpecifications - The specifications of all
|
|
381
|
-
* permissions available to the controller. See
|
|
382
|
-
* {@link PermissionSpecificationMap} and the README for more details.
|
|
383
|
-
* @param options.unrestrictedMethods - The callable names of all JSON-RPC
|
|
384
|
-
* methods ignored by the new controller.
|
|
385
|
-
* @param options.messenger - The messenger. See
|
|
386
|
-
* {@link BaseController} for more information.
|
|
387
|
-
* @param options.state - Existing state to hydrate the controller with at
|
|
388
|
-
* initialization.
|
|
389
|
-
*/
|
|
390
|
-
constructor(options: PermissionControllerOptions<ControllerPermissionSpecification, ControllerCaveatSpecification>);
|
|
391
|
-
/**
|
|
392
|
-
* Clears the state of the controller.
|
|
393
|
-
*/
|
|
394
|
-
clearState(): void;
|
|
395
|
-
/**
|
|
396
|
-
* Gets a list of all origins of subjects.
|
|
397
|
-
*
|
|
398
|
-
* @returns The origins (i.e. IDs) of all subjects.
|
|
399
|
-
*/
|
|
400
|
-
getSubjectNames(): OriginString[];
|
|
401
|
-
/**
|
|
402
|
-
* Gets the permission for the specified target of the subject corresponding
|
|
403
|
-
* to the specified origin.
|
|
404
|
-
*
|
|
405
|
-
* @param origin - The origin of the subject.
|
|
406
|
-
* @param targetName - The method name as invoked by a third party (i.e., not
|
|
407
|
-
* a method key).
|
|
408
|
-
* @returns The permission if it exists, or undefined otherwise.
|
|
409
|
-
*/
|
|
410
|
-
getPermission<SubjectPermission extends ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>(origin: OriginString, targetName: SubjectPermission['parentCapability']): SubjectPermission | undefined;
|
|
411
|
-
/**
|
|
412
|
-
* Gets all permissions for the specified subject, if any.
|
|
413
|
-
*
|
|
414
|
-
* @param origin - The origin of the subject.
|
|
415
|
-
* @returns The permissions of the subject, if any.
|
|
416
|
-
*/
|
|
417
|
-
getPermissions(origin: OriginString): SubjectPermissions<ValidPermission<string, ExtractCaveats<ControllerCaveatSpecification>>> | undefined;
|
|
418
|
-
/**
|
|
419
|
-
* Checks whether the subject with the specified origin has the specified
|
|
420
|
-
* permission.
|
|
421
|
-
*
|
|
422
|
-
* @param origin - The origin of the subject.
|
|
423
|
-
* @param target - The target name of the permission.
|
|
424
|
-
* @returns Whether the subject has the permission.
|
|
425
|
-
*/
|
|
426
|
-
hasPermission(origin: OriginString, target: ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability']): boolean;
|
|
427
|
-
/**
|
|
428
|
-
* Checks whether the subject with the specified origin has any permissions.
|
|
429
|
-
* Use this if you want to know if a subject "exists".
|
|
430
|
-
*
|
|
431
|
-
* @param origin - The origin of the subject to check.
|
|
432
|
-
* @returns Whether the subject has any permissions.
|
|
433
|
-
*/
|
|
434
|
-
hasPermissions(origin: OriginString): boolean;
|
|
435
|
-
/**
|
|
436
|
-
* Revokes all permissions from the specified origin.
|
|
437
|
-
*
|
|
438
|
-
* Throws an error if the origin has no permissions.
|
|
439
|
-
*
|
|
440
|
-
* @param origin - The origin whose permissions to revoke.
|
|
441
|
-
*/
|
|
442
|
-
revokeAllPermissions(origin: OriginString): void;
|
|
443
|
-
/**
|
|
444
|
-
* Revokes the specified permission from the subject with the specified
|
|
445
|
-
* origin.
|
|
446
|
-
*
|
|
447
|
-
* Throws an error if the subject or the permission does not exist.
|
|
448
|
-
*
|
|
449
|
-
* @param origin - The origin of the subject whose permission to revoke.
|
|
450
|
-
* @param target - The target name of the permission to revoke.
|
|
451
|
-
*/
|
|
452
|
-
revokePermission(origin: OriginString, target: ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability']): void;
|
|
453
|
-
/**
|
|
454
|
-
* Revokes the specified permissions from the specified subjects.
|
|
455
|
-
*
|
|
456
|
-
* Throws an error if any of the subjects or permissions do not exist.
|
|
457
|
-
*
|
|
458
|
-
* @param subjectsAndPermissions - An object mapping subject origins
|
|
459
|
-
* to arrays of permission target names to revoke.
|
|
460
|
-
*/
|
|
461
|
-
revokePermissions(subjectsAndPermissions: Record<OriginString, NonEmptyArray<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability']>>): void;
|
|
462
|
-
/**
|
|
463
|
-
* Revokes all permissions corresponding to the specified target for all subjects.
|
|
464
|
-
* Does nothing if no subjects or no such permission exists.
|
|
465
|
-
*
|
|
466
|
-
* @param target - The name of the target to revoke all permissions for.
|
|
467
|
-
*/
|
|
468
|
-
revokePermissionForAllSubjects(target: ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability']): void;
|
|
469
|
-
/**
|
|
470
|
-
* Checks whether the permission of the subject corresponding to the given
|
|
471
|
-
* origin has a caveat of the specified type.
|
|
472
|
-
*
|
|
473
|
-
* Throws an error if the subject does not have a permission with the
|
|
474
|
-
* specified target name.
|
|
475
|
-
*
|
|
476
|
-
* @template TargetName - The permission target name. Should be inferred.
|
|
477
|
-
* @template CaveatType - The valid caveat types for the permission. Should
|
|
478
|
-
* be inferred.
|
|
479
|
-
* @param origin - The origin of the subject.
|
|
480
|
-
* @param target - The target name of the permission.
|
|
481
|
-
* @param caveatType - The type of the caveat to check for.
|
|
482
|
-
* @returns Whether the permission has the specified caveat.
|
|
483
|
-
*/
|
|
484
|
-
hasCaveat<TargetName extends ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability'], CaveatType extends ExtractAllowedCaveatTypes<ControllerPermissionSpecification>>(origin: OriginString, target: TargetName, caveatType: CaveatType): boolean;
|
|
485
|
-
/**
|
|
486
|
-
* Gets the caveat of the specified type, if any, for the permission of
|
|
487
|
-
* the subject corresponding to the given origin.
|
|
488
|
-
*
|
|
489
|
-
* Throws an error if the subject does not have a permission with the
|
|
490
|
-
* specified target name.
|
|
491
|
-
*
|
|
492
|
-
* @template TargetName - The permission target name. Should be inferred.
|
|
493
|
-
* @template CaveatType - The valid caveat types for the permission. Should
|
|
494
|
-
* be inferred.
|
|
495
|
-
* @param origin - The origin of the subject.
|
|
496
|
-
* @param target - The target name of the permission.
|
|
497
|
-
* @param caveatType - The type of the caveat to get.
|
|
498
|
-
* @returns The caveat, or `undefined` if no such caveat exists.
|
|
499
|
-
*/
|
|
500
|
-
getCaveat<TargetName extends ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability'], CaveatType extends ExtractAllowedCaveatTypes<ControllerPermissionSpecification>>(origin: OriginString, target: TargetName, caveatType: CaveatType): ExtractCaveat<ControllerCaveatSpecification, CaveatType> | undefined;
|
|
501
|
-
/**
|
|
502
|
-
* Adds a caveat of the specified type, with the specified caveat value, to
|
|
503
|
-
* the permission corresponding to the given subject origin and permission
|
|
504
|
-
* target.
|
|
505
|
-
*
|
|
506
|
-
* For modifying existing caveats, use
|
|
507
|
-
* {@link PermissionController.updateCaveat}.
|
|
508
|
-
*
|
|
509
|
-
* Throws an error if no such permission exists, or if the caveat already
|
|
510
|
-
* exists.
|
|
511
|
-
*
|
|
512
|
-
* @template TargetName - The permission target name. Should be inferred.
|
|
513
|
-
* @template CaveatType - The valid caveat types for the permission. Should
|
|
514
|
-
* be inferred.
|
|
515
|
-
* @param origin - The origin of the subject.
|
|
516
|
-
* @param target - The target name of the permission.
|
|
517
|
-
* @param caveatType - The type of the caveat to add.
|
|
518
|
-
* @param caveatValue - The value of the caveat to add.
|
|
519
|
-
*/
|
|
520
|
-
addCaveat<TargetName extends ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability'], CaveatType extends ExtractAllowedCaveatTypes<ControllerPermissionSpecification>>(origin: OriginString, target: TargetName, caveatType: CaveatType, caveatValue: ExtractCaveatValue<ControllerCaveatSpecification, CaveatType>): void;
|
|
521
|
-
/**
|
|
522
|
-
* Updates the value of the caveat of the specified type belonging to the
|
|
523
|
-
* permission corresponding to the given subject origin and permission
|
|
524
|
-
* target.
|
|
525
|
-
*
|
|
526
|
-
* For adding new caveats, use
|
|
527
|
-
* {@link PermissionController.addCaveat}.
|
|
528
|
-
*
|
|
529
|
-
* Throws an error if no such permission or caveat exists.
|
|
530
|
-
*
|
|
531
|
-
* @template TargetName - The permission target name. Should be inferred.
|
|
532
|
-
* @template CaveatType - The valid caveat types for the permission. Should
|
|
533
|
-
* be inferred.
|
|
534
|
-
* @param origin - The origin of the subject.
|
|
535
|
-
* @param target - The target name of the permission.
|
|
536
|
-
* @param caveatType - The type of the caveat to update.
|
|
537
|
-
* @param caveatValue - The new value of the caveat.
|
|
538
|
-
*/
|
|
539
|
-
updateCaveat<TargetName extends ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability'], CaveatType extends ExtractAllowedCaveatTypes<ControllerPermissionSpecification>, CaveatValue extends ExtractCaveatValue<ControllerCaveatSpecification, CaveatType>>(origin: OriginString, target: TargetName, caveatType: CaveatType, caveatValue: CaveatValue): void;
|
|
540
|
-
/**
|
|
541
|
-
* Updates all caveats with the specified type for all subjects and
|
|
542
|
-
* permissions by applying the specified mutator function to them.
|
|
543
|
-
*
|
|
544
|
-
* ATTN: Permissions can be revoked entirely by the action of this method,
|
|
545
|
-
* read on for details.
|
|
546
|
-
*
|
|
547
|
-
* Caveat mutators are functions that receive a caveat value and return a
|
|
548
|
-
* tuple consisting of a {@link CaveatMutatorOperation} and, optionally, a new
|
|
549
|
-
* value to update the existing caveat with.
|
|
550
|
-
*
|
|
551
|
-
* For each caveat, depending on the mutator result, this method will:
|
|
552
|
-
* - Do nothing ({@link CaveatMutatorOperation.Noop})
|
|
553
|
-
* - Update the value of the caveat ({@link CaveatMutatorOperation.UpdateValue}). The caveat specification validator, if any, will be called after updating the value.
|
|
554
|
-
* - Delete the caveat ({@link CaveatMutatorOperation.DeleteCaveat}). The permission specification validator, if any, will be called after deleting the caveat.
|
|
555
|
-
* - Revoke the parent permission ({@link CaveatMutatorOperation.RevokePermission})
|
|
556
|
-
*
|
|
557
|
-
* This method throws if the validation of any caveat or permission fails.
|
|
558
|
-
*
|
|
559
|
-
* @param targetCaveatType - The type of the caveats to update.
|
|
560
|
-
* @param mutator - The mutator function which will be applied to all caveat
|
|
561
|
-
* values.
|
|
562
|
-
*/
|
|
563
|
-
updatePermissionsByCaveat<CaveatType extends ExtractCaveats<ControllerCaveatSpecification>['type'], TargetCaveat extends ExtractCaveat<ControllerCaveatSpecification, CaveatType>>(targetCaveatType: CaveatType, mutator: CaveatMutator<TargetCaveat>): void;
|
|
564
|
-
/**
|
|
565
|
-
* Removes the caveat of the specified type from the permission corresponding
|
|
566
|
-
* to the given subject origin and target name.
|
|
567
|
-
*
|
|
568
|
-
* Throws an error if no such permission or caveat exists.
|
|
569
|
-
*
|
|
570
|
-
* @template TargetName - The permission target name. Should be inferred.
|
|
571
|
-
* @template CaveatType - The valid caveat types for the permission. Should
|
|
572
|
-
* be inferred.
|
|
573
|
-
* @param origin - The origin of the subject.
|
|
574
|
-
* @param target - The target name of the permission.
|
|
575
|
-
* @param caveatType - The type of the caveat to remove.
|
|
576
|
-
*/
|
|
577
|
-
removeCaveat<TargetName extends ControllerPermissionSpecification['targetName'], CaveatType extends ExtractAllowedCaveatTypes<ControllerPermissionSpecification>>(origin: OriginString, target: TargetName, caveatType: CaveatType): void;
|
|
578
|
-
/**
|
|
579
|
-
* Grants _approved_ permissions to the specified subject. Every permission and
|
|
580
|
-
* caveat is stringently validated—including by calling their specification
|
|
581
|
-
* validators—and an error is thrown if validation fails.
|
|
582
|
-
*
|
|
583
|
-
* ATTN: This method does **not** prompt the user for approval. User consent must
|
|
584
|
-
* first be obtained through some other means.
|
|
585
|
-
*
|
|
586
|
-
* @see {@link PermissionController.requestPermissions} For initiating a
|
|
587
|
-
* permissions request requiring user approval.
|
|
588
|
-
* @param options - Options bag.
|
|
589
|
-
* @param options.approvedPermissions - The requested permissions approved by
|
|
590
|
-
* the user.
|
|
591
|
-
* @param options.requestData - Permission request data. Passed to permission
|
|
592
|
-
* factory functions.
|
|
593
|
-
* @param options.preserveExistingPermissions - Whether to preserve the
|
|
594
|
-
* subject's existing permissions.
|
|
595
|
-
* @param options.subject - The subject to grant permissions to.
|
|
596
|
-
* @returns The subject's new permission state. It may or may not have changed.
|
|
597
|
-
*/
|
|
598
|
-
grantPermissions({ approvedPermissions, requestData, preserveExistingPermissions, subject, }: {
|
|
599
|
-
approvedPermissions: RequestedPermissions;
|
|
600
|
-
subject: PermissionSubjectMetadata;
|
|
601
|
-
preserveExistingPermissions?: boolean;
|
|
602
|
-
requestData?: Record<string, unknown>;
|
|
603
|
-
}): Partial<SubjectPermissions<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>;
|
|
604
|
-
/**
|
|
605
|
-
* Incrementally grants _approved_ permissions to the specified subject. Every
|
|
606
|
-
* permission and caveat is stringently validated—including by calling their
|
|
607
|
-
* specification validators—and an error is thrown if validation fails.
|
|
608
|
-
*
|
|
609
|
-
* ATTN: This method does **not** prompt the user for approval. User consent must
|
|
610
|
-
* first be obtained through some other means.
|
|
611
|
-
*
|
|
612
|
-
* @see {@link PermissionController.requestPermissionsIncremental} For initiating
|
|
613
|
-
* an incremental permissions request requiring user approval.
|
|
614
|
-
* @param options - Options bag.
|
|
615
|
-
* @param options.approvedPermissions - The requested permissions approved by
|
|
616
|
-
* the user.
|
|
617
|
-
* @param options.requestData - Permission request data. Passed to permission
|
|
618
|
-
* factory functions.
|
|
619
|
-
* @param options.subject - The subject to grant permissions to.
|
|
620
|
-
* @returns The subject's new permission state. It may or may not have changed.
|
|
621
|
-
*/
|
|
622
|
-
grantPermissionsIncremental({ approvedPermissions, requestData, subject, }: {
|
|
623
|
-
approvedPermissions: RequestedPermissions;
|
|
624
|
-
subject: PermissionSubjectMetadata;
|
|
625
|
-
requestData?: Record<string, unknown>;
|
|
626
|
-
}): Partial<SubjectPermissions<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>;
|
|
627
|
-
/**
|
|
628
|
-
* Initiates a permission request that requires user approval.
|
|
629
|
-
*
|
|
630
|
-
* Either this or {@link PermissionController.requestPermissionsIncremental}
|
|
631
|
-
* should always be used to grant additional permissions to a subject,
|
|
632
|
-
* unless user approval has been obtained through some other means.
|
|
633
|
-
*
|
|
634
|
-
* Permissions are validated at every step of the approval process, and this
|
|
635
|
-
* method will reject if validation fails.
|
|
636
|
-
*
|
|
637
|
-
* @see {@link ApprovalController} For the user approval logic.
|
|
638
|
-
* @see {@link PermissionController.acceptPermissionsRequest} For the method
|
|
639
|
-
* that _accepts_ the request and resolves the user approval promise.
|
|
640
|
-
* @see {@link PermissionController.rejectPermissionsRequest} For the method
|
|
641
|
-
* that _rejects_ the request and the user approval promise.
|
|
642
|
-
* @param subject - The grantee subject.
|
|
643
|
-
* @param requestedPermissions - The requested permissions.
|
|
644
|
-
* @param options - Additional options.
|
|
645
|
-
* @param options.id - The id of the permissions request. Defaults to a unique
|
|
646
|
-
* id.
|
|
647
|
-
* @param options.preserveExistingPermissions - Whether to preserve the
|
|
648
|
-
* subject's existing permissions. Defaults to `true`.
|
|
649
|
-
* @param options.metadata - Additional metadata about the permission request.
|
|
650
|
-
* @returns The granted permissions and request metadata.
|
|
651
|
-
*/
|
|
652
|
-
requestPermissions(subject: PermissionSubjectMetadata, requestedPermissions: RequestedPermissions, options?: {
|
|
653
|
-
id?: string;
|
|
654
|
-
preserveExistingPermissions?: boolean;
|
|
655
|
-
metadata?: Record<string, Json>;
|
|
656
|
-
}): Promise<[
|
|
657
|
-
Partial<SubjectPermissions<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>,
|
|
658
|
-
ApprovedPermissionsMetadata
|
|
659
|
-
]>;
|
|
660
|
-
/**
|
|
661
|
-
* Initiates an incremental permission request that prompts for user approval.
|
|
662
|
-
* Incremental permission requests allow the caller to replace existing and/or
|
|
663
|
-
* add brand new permissions and caveats for the specified subject.
|
|
664
|
-
*
|
|
665
|
-
* Incremental permission request are merged with the subject's existing permissions
|
|
666
|
-
* through a right-biased union, where the incremental permission are the right-hand
|
|
667
|
-
* side of the merger. If both sides of the merger specify the same caveats for a
|
|
668
|
-
* given permission, the caveats are merged using their specification's caveat value
|
|
669
|
-
* merger property.
|
|
670
|
-
*
|
|
671
|
-
* Either this or {@link PermissionController.requestPermissions} should
|
|
672
|
-
* always be used to grant additional permissions to a subject, unless user
|
|
673
|
-
* approval has been obtained through some other means.
|
|
674
|
-
*
|
|
675
|
-
* Permissions are validated at every step of the approval process, and this
|
|
676
|
-
* method will reject if validation fails.
|
|
677
|
-
*
|
|
678
|
-
* @see {@link ApprovalController} For the user approval logic.
|
|
679
|
-
* @see {@link PermissionController.acceptPermissionsRequest} For the method
|
|
680
|
-
* that _accepts_ the request and resolves the user approval promise.
|
|
681
|
-
* @see {@link PermissionController.rejectPermissionsRequest} For the method
|
|
682
|
-
* that _rejects_ the request and the user approval promise.
|
|
683
|
-
* @param subject - The grantee subject.
|
|
684
|
-
* @param requestedPermissions - The requested permissions.
|
|
685
|
-
* @param options - Additional options.
|
|
686
|
-
* @param options.id - The id of the permissions request. Defaults to a unique
|
|
687
|
-
* id.
|
|
688
|
-
* @param options.metadata - Additional metadata about the permission request.
|
|
689
|
-
* @returns The granted permissions and request metadata.
|
|
690
|
-
*/
|
|
691
|
-
requestPermissionsIncremental(subject: PermissionSubjectMetadata, requestedPermissions: RequestedPermissions, options?: {
|
|
692
|
-
id?: string;
|
|
693
|
-
metadata?: Record<string, Json>;
|
|
694
|
-
}): Promise<[
|
|
695
|
-
Partial<SubjectPermissions<ExtractPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>>>,
|
|
696
|
-
ApprovedPermissionsMetadata
|
|
697
|
-
] | []>;
|
|
698
|
-
/**
|
|
699
|
-
* Accepts a permissions request created by
|
|
700
|
-
* {@link PermissionController.requestPermissions}.
|
|
701
|
-
*
|
|
702
|
-
* @param request - The permissions request.
|
|
703
|
-
*/
|
|
704
|
-
acceptPermissionsRequest(request: PermissionsRequest): Promise<void>;
|
|
705
|
-
/**
|
|
706
|
-
* Rejects a permissions request created by
|
|
707
|
-
* {@link PermissionController.requestPermissions}.
|
|
708
|
-
*
|
|
709
|
-
* @param id - The id of the request to be rejected.
|
|
710
|
-
*/
|
|
711
|
-
rejectPermissionsRequest(id: string): Promise<void>;
|
|
712
|
-
/**
|
|
713
|
-
* Gets the subject's endowments per the specified endowment permission.
|
|
714
|
-
* Throws if the subject does not have the required permission or if the
|
|
715
|
-
* permission is not an endowment permission.
|
|
716
|
-
*
|
|
717
|
-
* @param origin - The origin of the subject whose endowments to retrieve.
|
|
718
|
-
* @param targetName - The name of the endowment permission. This must be a
|
|
719
|
-
* valid permission target name.
|
|
720
|
-
* @param requestData - Additional data associated with the request, if any.
|
|
721
|
-
* Forwarded to the endowment getter function for the permission.
|
|
722
|
-
* @returns The endowments, if any.
|
|
723
|
-
*/
|
|
724
|
-
getEndowments(origin: string, targetName: ExtractEndowmentPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability'], requestData?: unknown): Promise<Json>;
|
|
725
|
-
/**
|
|
726
|
-
* Executes a restricted method as the subject with the given origin.
|
|
727
|
-
* The specified params, if any, will be passed to the method implementation.
|
|
728
|
-
*
|
|
729
|
-
* ATTN: Great caution should be exercised in the use of this method.
|
|
730
|
-
* Methods that cause side effects or affect application state should
|
|
731
|
-
* be avoided.
|
|
732
|
-
*
|
|
733
|
-
* This method will first attempt to retrieve the requested restricted method
|
|
734
|
-
* implementation, throwing if it does not exist. The method will then be
|
|
735
|
-
* invoked as though the subject with the specified origin had invoked it with
|
|
736
|
-
* the specified parameters. This means that any existing caveats will be
|
|
737
|
-
* applied to the restricted method, and this method will throw if the
|
|
738
|
-
* restricted method or its caveat decorators throw.
|
|
739
|
-
*
|
|
740
|
-
* In addition, this method will throw if the subject does not have a
|
|
741
|
-
* permission for the specified restricted method.
|
|
742
|
-
*
|
|
743
|
-
* @param origin - The origin of the subject to execute the method on behalf
|
|
744
|
-
* of.
|
|
745
|
-
* @param targetName - The name of the method to execute. This must be a valid
|
|
746
|
-
* permission target name.
|
|
747
|
-
* @param params - The parameters to pass to the method implementation.
|
|
748
|
-
* @returns The result of the executed method.
|
|
749
|
-
*/
|
|
750
|
-
executeRestrictedMethod(origin: OriginString, targetName: ExtractRestrictedMethodPermission<ControllerPermissionSpecification, ControllerCaveatSpecification>['parentCapability'], params?: RestrictedMethodParameters): Promise<Json>;
|
|
751
|
-
}
|
|
752
|
-
export {};
|
|
753
|
-
//# sourceMappingURL=PermissionController.d.mts.map
|