UNPKG

@wordpress/core-data

Version:
61 lines (59 loc) 2.13 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // packages/core-data/src/utils/user-permissions.js var user_permissions_exports = {}; __export(user_permissions_exports, { ALLOWED_RESOURCE_ACTIONS: () => ALLOWED_RESOURCE_ACTIONS, getUserPermissionCacheKey: () => getUserPermissionCacheKey, getUserPermissionsFromAllowHeader: () => getUserPermissionsFromAllowHeader }); module.exports = __toCommonJS(user_permissions_exports); var ALLOWED_RESOURCE_ACTIONS = [ "create", "read", "update", "delete" ]; function getUserPermissionsFromAllowHeader(allowedMethods) { const permissions = {}; if (!allowedMethods) { return permissions; } const methods = { create: "POST", read: "GET", update: "PUT", delete: "DELETE" }; for (const [actionName, methodName] of Object.entries(methods)) { permissions[actionName] = allowedMethods.includes(methodName); } return permissions; } function getUserPermissionCacheKey(action, resource, id) { const key = (typeof resource === "object" ? [action, resource.kind, resource.name, resource.id] : [action, resource, id]).filter(Boolean).join("/"); return key; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ALLOWED_RESOURCE_ACTIONS, getUserPermissionCacheKey, getUserPermissionsFromAllowHeader }); //# sourceMappingURL=user-permissions.js.map