@backstage/plugin-permission-common 0.5.0 → 0.5.1

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 CHANGED
@@ -1,5 +1,14 @@
1
1
  # @backstage/plugin-permission-common
2
2
 
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix for the previous release with missing type declarations.
8
+ - Updated dependencies
9
+ - @backstage/config@0.1.15
10
+ - @backstage/errors@0.2.2
11
+
3
12
  ## 0.5.0
4
13
 
5
14
  ### Minor Changes
@@ -0,0 +1,206 @@
1
+ import { Config } from '@backstage/config';
2
+
3
+ /**
4
+ * The attributes related to a given permission; these should be generic and widely applicable to
5
+ * all permissions in the system.
6
+ * @public
7
+ */
8
+ declare type PermissionAttributes = {
9
+ action?: 'create' | 'read' | 'update' | 'delete';
10
+ };
11
+ /**
12
+ * A permission that can be checked through authorization.
13
+ *
14
+ * Permissions are the "what" part of authorization, the action to be performed. This may be reading
15
+ * an entity from the catalog, executing a software template, or any other action a plugin author
16
+ * may wish to protect.
17
+ *
18
+ * To evaluate authorization, a permission is paired with a Backstage identity (the "who") and
19
+ * evaluated using an authorization policy.
20
+ * @public
21
+ */
22
+ declare type Permission = {
23
+ name: string;
24
+ attributes: PermissionAttributes;
25
+ resourceType?: string;
26
+ };
27
+ /**
28
+ * A client interacting with the permission backend can implement this authorizer interface.
29
+ * @public
30
+ */
31
+ interface PermissionAuthorizer {
32
+ authorize(queries: AuthorizeQuery[], options?: AuthorizeRequestOptions): Promise<AuthorizeDecision[]>;
33
+ }
34
+ /**
35
+ * Options for authorization requests.
36
+ * @public
37
+ */
38
+ declare type AuthorizeRequestOptions = {
39
+ token?: string;
40
+ };
41
+
42
+ /**
43
+ * A request with a UUID identifier, so that batched responses can be matched up with the original
44
+ * requests.
45
+ * @public
46
+ */
47
+ declare type Identified<T> = T & {
48
+ id: string;
49
+ };
50
+ /**
51
+ * The result of an authorization request.
52
+ * @public
53
+ */
54
+ declare enum AuthorizeResult {
55
+ /**
56
+ * The authorization request is denied.
57
+ */
58
+ DENY = "DENY",
59
+ /**
60
+ * The authorization request is allowed.
61
+ */
62
+ ALLOW = "ALLOW",
63
+ /**
64
+ * The authorization request is allowed if the provided conditions are met.
65
+ */
66
+ CONDITIONAL = "CONDITIONAL"
67
+ }
68
+ /**
69
+ * An individual authorization request for {@link PermissionClient#authorize}.
70
+ * @public
71
+ */
72
+ declare type AuthorizeQuery = {
73
+ permission: Permission;
74
+ resourceRef?: string;
75
+ };
76
+ /**
77
+ * A batch of authorization requests from {@link PermissionClient#authorize}.
78
+ * @public
79
+ */
80
+ declare type AuthorizeRequest = {
81
+ items: Identified<AuthorizeQuery>[];
82
+ };
83
+ /**
84
+ * A condition returned with a CONDITIONAL authorization response.
85
+ *
86
+ * Conditions are a reference to a rule defined by a plugin, and parameters to apply the rule. For
87
+ * example, a rule might be `isOwner` from the catalog-backend, and params may be a list of entity
88
+ * claims from a identity token.
89
+ * @public
90
+ */
91
+ declare type PermissionCondition<TParams extends unknown[] = unknown[]> = {
92
+ rule: string;
93
+ params: TParams;
94
+ };
95
+ /**
96
+ * Utility type to represent an array with 1 or more elements.
97
+ * @ignore
98
+ */
99
+ declare type NonEmptyArray<T> = [T, ...T[]];
100
+ /**
101
+ * Represnts a logical AND for the provided criteria.
102
+ * @public
103
+ */
104
+ declare type AllOfCriteria<TQuery> = {
105
+ allOf: NonEmptyArray<PermissionCriteria<TQuery>>;
106
+ };
107
+ /**
108
+ * Represnts a logical OR for the provided criteria.
109
+ * @public
110
+ */
111
+ declare type AnyOfCriteria<TQuery> = {
112
+ anyOf: NonEmptyArray<PermissionCriteria<TQuery>>;
113
+ };
114
+ /**
115
+ * Represents a negation of the provided criteria.
116
+ * @public
117
+ */
118
+ declare type NotCriteria<TQuery> = {
119
+ not: PermissionCriteria<TQuery>;
120
+ };
121
+ /**
122
+ * Composes several {@link PermissionCondition}s as criteria with a nested AND/OR structure.
123
+ * @public
124
+ */
125
+ declare type PermissionCriteria<TQuery> = AllOfCriteria<TQuery> | AnyOfCriteria<TQuery> | NotCriteria<TQuery> | TQuery;
126
+ /**
127
+ * An individual authorization response from {@link PermissionClient#authorize}.
128
+ * @public
129
+ */
130
+ declare type AuthorizeDecision = {
131
+ result: AuthorizeResult.ALLOW | AuthorizeResult.DENY;
132
+ } | {
133
+ result: AuthorizeResult.CONDITIONAL;
134
+ conditions: PermissionCriteria<PermissionCondition>;
135
+ };
136
+ /**
137
+ * A batch of authorization responses from {@link PermissionClient#authorize}.
138
+ * @public
139
+ */
140
+ declare type AuthorizeResponse = {
141
+ items: Identified<AuthorizeDecision>[];
142
+ };
143
+
144
+ /**
145
+ * This is a copy of the core DiscoveryApi, to avoid importing core.
146
+ *
147
+ * @public
148
+ */
149
+ declare type DiscoveryApi = {
150
+ getBaseUrl(pluginId: string): Promise<string>;
151
+ };
152
+
153
+ /**
154
+ * Check if a given permission is related to a create action.
155
+ * @public
156
+ */
157
+ declare function isCreatePermission(permission: Permission): boolean;
158
+ /**
159
+ * Check if a given permission is related to a read action.
160
+ * @public
161
+ */
162
+ declare function isReadPermission(permission: Permission): boolean;
163
+ /**
164
+ * Check if a given permission is related to an update action.
165
+ * @public
166
+ */
167
+ declare function isUpdatePermission(permission: Permission): boolean;
168
+ /**
169
+ * Check if a given permission is related to a delete action.
170
+ * @public
171
+ */
172
+ declare function isDeletePermission(permission: Permission): boolean;
173
+
174
+ /**
175
+ * An isomorphic client for requesting authorization for Backstage permissions.
176
+ * @public
177
+ */
178
+ declare class PermissionClient implements PermissionAuthorizer {
179
+ private readonly enabled;
180
+ private readonly discovery;
181
+ constructor(options: {
182
+ discovery: DiscoveryApi;
183
+ config: Config;
184
+ });
185
+ /**
186
+ * Request authorization from the permission-backend for the given set of permissions.
187
+ *
188
+ * Authorization requests check that a given Backstage user can perform a protected operation,
189
+ * potentially for a specific resource (such as a catalog entity). The Backstage identity token
190
+ * should be included in the `options` if available.
191
+ *
192
+ * Permissions can be imported from plugins exposing them, such as `catalogEntityReadPermission`.
193
+ *
194
+ * The response will be either ALLOW or DENY when either the permission has no resourceType, or a
195
+ * resourceRef is provided in the request. For permissions with a resourceType, CONDITIONAL may be
196
+ * returned if no resourceRef is provided in the request. Conditional responses are intended only
197
+ * for backends which have access to the data source for permissioned resources, so that filters
198
+ * can be applied when loading collections of resources.
199
+ * @public
200
+ */
201
+ authorize(queries: AuthorizeQuery[], options?: AuthorizeRequestOptions): Promise<AuthorizeDecision[]>;
202
+ private getAuthorizationHeader;
203
+ private assertValidResponse;
204
+ }
205
+
206
+ export { AllOfCriteria, AnyOfCriteria, AuthorizeDecision, AuthorizeQuery, AuthorizeRequest, AuthorizeRequestOptions, AuthorizeResponse, AuthorizeResult, DiscoveryApi, Identified, NotCriteria, Permission, PermissionAttributes, PermissionAuthorizer, PermissionClient, PermissionCondition, PermissionCriteria, isCreatePermission, isDeletePermission, isReadPermission, isUpdatePermission };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@backstage/plugin-permission-common",
3
3
  "description": "Isomorphic types and client for Backstage permissions and authorization",
4
- "version": "0.5.0",
4
+ "version": "0.5.1",
5
5
  "main": "dist/index.cjs.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "publishConfig": {
@@ -41,8 +41,8 @@
41
41
  "url": "https://github.com/backstage/backstage/issues"
42
42
  },
43
43
  "dependencies": {
44
- "@backstage/config": "^0.1.14",
45
- "@backstage/errors": "^0.2.1",
44
+ "@backstage/config": "^0.1.15",
45
+ "@backstage/errors": "^0.2.2",
46
46
  "cross-fetch": "^3.1.5",
47
47
  "uuid": "^8.0.0",
48
48
  "zod": "^3.11.6"
@@ -52,6 +52,6 @@
52
52
  "@types/jest": "^26.0.7",
53
53
  "msw": "^0.35.0"
54
54
  },
55
- "gitHead": "4805c3d13ce9bfc369e53c271b1b95e722b3b4dc",
55
+ "gitHead": "e244b348c473700e7d5e5fbcef38bd9f9fd1d0ba",
56
56
  "module": "dist/index.esm.js"
57
57
  }