Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@backstage/plugin-permission-common

Package Overview
Dependencies
Maintainers
3
Versions
485
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@backstage/plugin-permission-common - npm Package Compare versions

Comparing version 0.0.0-nightly-20240319021037 to 0.0.0-nightly-20240612021718

dist/PermissionClient.esm.js

26

CHANGELOG.md
# @backstage/plugin-permission-common
## 0.0.0-nightly-20240319021037
## 0.0.0-nightly-20240612021718
### Patch Changes
- d44a20a: Added additional plugin metadata to `package.json`.
- Updated dependencies
- @backstage/config@1.2.0
- @backstage/errors@1.2.4
- @backstage/types@1.1.1
## 0.7.14-next.0
### Patch Changes
- d44a20a: Added additional plugin metadata to `package.json`.
- Updated dependencies
- @backstage/config@1.2.0
- @backstage/errors@1.2.4
- @backstage/types@1.1.1
## 0.7.13
### Patch Changes
- 0502d82: The `token` option of the `PermissionEvaluator` methods is now deprecated. The options that only apply to backend implementations have been moved to `PermissionsService` from `@backstage/backend-plugin-api` instead.

@@ -11,4 +31,4 @@ - 0fb419b: Updated dependency `uuid` to `^9.0.0`.

- Updated dependencies
- @backstage/config@0.0.0-nightly-20240319021037
- @backstage/errors@0.0.0-nightly-20240319021037
- @backstage/config@1.2.0
- @backstage/errors@1.2.4
- @backstage/types@1.1.1

@@ -15,0 +35,0 @@

31

dist/index.cjs.js
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
var errors = require('@backstage/errors');

@@ -10,6 +8,6 @@ var fetch = require('cross-fetch');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
function _interopNamespace(e) {
if (e && e.__esModule) return e;
function _interopNamespaceCompat(e) {
if (e && typeof e === 'object' && 'default' in e) return e;
var n = Object.create(null);

@@ -27,8 +25,8 @@ if (e) {

}
n["default"] = e;
n.default = e;
return Object.freeze(n);
}
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
var uuid__namespace = /*#__PURE__*/_interopNamespace(uuid);
var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
var uuid__namespace = /*#__PURE__*/_interopNamespaceCompat(uuid);

@@ -96,8 +94,2 @@ var AuthorizeResult = /* @__PURE__ */ ((AuthorizeResult2) => {

var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
const permissionCriteriaSchema = zod.z.lazy(

@@ -140,8 +132,7 @@ () => zod.z.object({

class PermissionClient {
enabled;
discovery;
constructor(options) {
__publicField(this, "enabled");
__publicField(this, "discovery");
var _a;
this.discovery = options.discovery;
this.enabled = (_a = options.config.getOptionalBoolean("permission.enabled")) != null ? _a : false;
this.enabled = options.config.getOptionalBoolean("permission.enabled") ?? false;
}

@@ -175,7 +166,7 @@ /**

const permissionApi = await this.discovery.getBaseUrl("permission");
const response = await fetch__default["default"](`${permissionApi}/authorize`, {
const response = await fetch__default.default(`${permissionApi}/authorize`, {
method: "POST",
body: JSON.stringify(request),
headers: {
...this.getAuthorizationHeader(options == null ? void 0 : options.token),
...this.getAuthorizationHeader(options?.token),
"content-type": "application/json"

@@ -182,0 +173,0 @@ }

@@ -395,2 +395,2 @@ import { JsonPrimitive } from '@backstage/types';

export { AllOfCriteria, AnyOfCriteria, AuthorizePermissionRequest, AuthorizePermissionResponse, AuthorizeRequestOptions, AuthorizeResult, BasicPermission, ConditionalPolicyDecision, DefinitivePolicyDecision, DiscoveryApi, EvaluatePermissionRequest, EvaluatePermissionRequestBatch, EvaluatePermissionResponse, EvaluatePermissionResponseBatch, EvaluatorRequestOptions, IdentifiedPermissionMessage, NotCriteria, Permission, PermissionAttributes, PermissionAuthorizer, PermissionBase, PermissionClient, PermissionCondition, PermissionCriteria, PermissionEvaluator, PermissionMessageBatch, PermissionRuleParam, PermissionRuleParams, PolicyDecision, QueryPermissionRequest, QueryPermissionResponse, ResourcePermission, createPermission, isCreatePermission, isDeletePermission, isPermission, isReadPermission, isResourcePermission, isUpdatePermission, toPermissionEvaluator };
export { type AllOfCriteria, type AnyOfCriteria, type AuthorizePermissionRequest, type AuthorizePermissionResponse, type AuthorizeRequestOptions, AuthorizeResult, type BasicPermission, type ConditionalPolicyDecision, type DefinitivePolicyDecision, type DiscoveryApi, type EvaluatePermissionRequest, type EvaluatePermissionRequestBatch, type EvaluatePermissionResponse, type EvaluatePermissionResponseBatch, type EvaluatorRequestOptions, type IdentifiedPermissionMessage, type NotCriteria, type Permission, type PermissionAttributes, type PermissionAuthorizer, type PermissionBase, PermissionClient, type PermissionCondition, type PermissionCriteria, type PermissionEvaluator, type PermissionMessageBatch, type PermissionRuleParam, type PermissionRuleParams, type PolicyDecision, type QueryPermissionRequest, type QueryPermissionResponse, type ResourcePermission, createPermission, isCreatePermission, isDeletePermission, isPermission, isReadPermission, isResourcePermission, isUpdatePermission, toPermissionEvaluator };

@@ -1,172 +0,5 @@

import { ResponseError } from '@backstage/errors';
import fetch from 'cross-fetch';
import * as uuid from 'uuid';
import { z } from 'zod';
var AuthorizeResult = /* @__PURE__ */ ((AuthorizeResult2) => {
AuthorizeResult2["DENY"] = "DENY";
AuthorizeResult2["ALLOW"] = "ALLOW";
AuthorizeResult2["CONDITIONAL"] = "CONDITIONAL";
return AuthorizeResult2;
})(AuthorizeResult || {});
function isPermission(permission, comparedPermission) {
return permission.name === comparedPermission.name;
}
function isResourcePermission(permission, resourceType) {
if (!("resourceType" in permission)) {
return false;
}
return !resourceType || permission.resourceType === resourceType;
}
function isCreatePermission(permission) {
return permission.attributes.action === "create";
}
function isReadPermission(permission) {
return permission.attributes.action === "read";
}
function isUpdatePermission(permission) {
return permission.attributes.action === "update";
}
function isDeletePermission(permission) {
return permission.attributes.action === "delete";
}
function toPermissionEvaluator(permissionAuthorizer) {
return {
authorize: async (requests, options) => {
const response = await permissionAuthorizer.authorize(requests, options);
return response;
},
authorizeConditional(requests, options) {
const parsedRequests = requests;
return permissionAuthorizer.authorize(parsedRequests, options);
}
};
}
function createPermission({
name,
attributes,
resourceType
}) {
if (resourceType) {
return {
type: "resource",
name,
attributes,
resourceType
};
}
return {
type: "basic",
name,
attributes
};
}
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
const permissionCriteriaSchema = z.lazy(
() => z.object({
rule: z.string(),
resourceType: z.string(),
params: z.record(z.any()).optional()
}).or(z.object({ anyOf: z.array(permissionCriteriaSchema).nonempty() })).or(z.object({ allOf: z.array(permissionCriteriaSchema).nonempty() })).or(z.object({ not: permissionCriteriaSchema }))
);
const authorizePermissionResponseSchema = z.object({
result: z.literal(AuthorizeResult.ALLOW).or(z.literal(AuthorizeResult.DENY))
});
const queryPermissionResponseSchema = z.union([
z.object({
result: z.literal(AuthorizeResult.ALLOW).or(z.literal(AuthorizeResult.DENY))
}),
z.object({
result: z.literal(AuthorizeResult.CONDITIONAL),
pluginId: z.string(),
resourceType: z.string(),
conditions: permissionCriteriaSchema
})
]);
const responseSchema = (itemSchema, ids) => z.object({
items: z.array(
z.intersection(
z.object({
id: z.string()
}),
itemSchema
)
).refine(
(items) => items.length === ids.size && items.every(({ id }) => ids.has(id)),
{
message: "Items in response do not match request"
}
)
});
class PermissionClient {
constructor(options) {
__publicField(this, "enabled");
__publicField(this, "discovery");
var _a;
this.discovery = options.discovery;
this.enabled = (_a = options.config.getOptionalBoolean("permission.enabled")) != null ? _a : false;
}
/**
* {@inheritdoc PermissionEvaluator.authorize}
*/
async authorize(requests, options) {
return this.makeRequest(
requests,
authorizePermissionResponseSchema,
options
);
}
/**
* {@inheritdoc PermissionEvaluator.authorizeConditional}
*/
async authorizeConditional(queries, options) {
return this.makeRequest(queries, queryPermissionResponseSchema, options);
}
async makeRequest(queries, itemSchema, options) {
if (!this.enabled) {
return queries.map((_) => ({ result: AuthorizeResult.ALLOW }));
}
const request = {
items: queries.map((query) => ({
id: uuid.v4(),
...query
}))
};
const permissionApi = await this.discovery.getBaseUrl("permission");
const response = await fetch(`${permissionApi}/authorize`, {
method: "POST",
body: JSON.stringify(request),
headers: {
...this.getAuthorizationHeader(options == null ? void 0 : options.token),
"content-type": "application/json"
}
});
if (!response.ok) {
throw await ResponseError.fromResponse(response);
}
const responseBody = await response.json();
const parsedResponse = responseSchema(
itemSchema,
new Set(request.items.map(({ id }) => id))
).parse(responseBody);
const responsesById = parsedResponse.items.reduce((acc, r) => {
acc[r.id] = r;
return acc;
}, {});
return request.items.map((query) => responsesById[query.id]);
}
getAuthorizationHeader(token) {
return token ? { Authorization: `Bearer ${token}` } : {};
}
}
export { AuthorizeResult, PermissionClient, createPermission, isCreatePermission, isDeletePermission, isPermission, isReadPermission, isResourcePermission, isUpdatePermission, toPermissionEvaluator };
export { AuthorizeResult } from './types/api.esm.js';
export { isCreatePermission, isDeletePermission, isPermission, isReadPermission, isResourcePermission, isUpdatePermission, toPermissionEvaluator } from './permissions/util.esm.js';
export { createPermission } from './permissions/createPermission.esm.js';
export { PermissionClient } from './PermissionClient.esm.js';
//# sourceMappingURL=index.esm.js.map
{
"name": "@backstage/plugin-permission-common",
"version": "0.0.0-nightly-20240319021037",
"version": "0.0.0-nightly-20240612021718",
"description": "Isomorphic types and client for Backstage permissions and authorization",
"backstage": {
"role": "common-library"
"role": "common-library",
"pluginId": "permission",
"pluginPackages": [
"@backstage/plugin-permission-backend",
"@backstage/plugin-permission-common",
"@backstage/plugin-permission-node",
"@backstage/plugin-permission-react"
]
},

@@ -44,4 +51,4 @@ "publishConfig": {

"dependencies": {
"@backstage/config": "^0.0.0-nightly-20240319021037",
"@backstage/errors": "^0.0.0-nightly-20240319021037",
"@backstage/config": "^1.2.0",
"@backstage/errors": "^1.2.4",
"@backstage/types": "^1.1.1",

@@ -53,3 +60,3 @@ "cross-fetch": "^4.0.0",

"devDependencies": {
"@backstage/cli": "^0.0.0-nightly-20240319021037",
"@backstage/cli": "^0.0.0-nightly-20240612021718",
"msw": "^1.0.0"

@@ -56,0 +63,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc