@sortedyuan/plugin-permissions 0.0.0-stage → 0.2.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Yuan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,17 @@
1
- # Temporary Holding Version
1
+ # @sortedyuan/plugin-permissions
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `createPermissionPlugin({ id?, create, dispose? })` provides
4
+ `services.permissionPolicy`. `create(context)` returns the actual permission policy
5
+ for one Application. Optional `dispose(policy)` and `context.defer()` own cleanup.
6
+ An existing policy with no disposer remains caller-owned.
7
+ Typed `config`, `configSchema`, dependencies, `requiresHooks`, `state`, and `version`
8
+ are supported through [`PluginFactoryMetadata`](../../plugin-services/README.md).
9
+ Configuration is validated before resources are acquired; `create(context)` can
10
+ read declared services and persistent state.
11
+
12
+ Application keeps approval requests, durable permission events and its
13
+ `PermissionToolExecutor`; policy evaluation resolves the currently enabled service.
14
+ One plugin supplies the policy. Duplicate providers fail before setup.
15
+
16
+ Tests evaluate policies against real file resources and verify independent scope
17
+ cleanup: `pnpm --filter @sortedyuan/plugin-permissions test`.
@@ -0,0 +1,15 @@
1
+ # @sortedyuan/plugin-permissions
2
+
3
+ `createPermissionPlugin({ id?, create, dispose? })` 提供 `services.permissionPolicy`。
4
+ `create(context)` 为一个 Application 返回实际 permission policy。
5
+ 通过 `dispose(policy)` 和 `context.defer()` 管理资源清理。
6
+ 传入已有 policy 并省略 disposer 时,该实例由调用方管理。
7
+ 支持 [`PluginFactoryMetadata`](../../plugin-services/README.zh-CN.md) 中带类型的
8
+ `config`、`configSchema`、依赖、`requiresHooks`、`state` 和 `version`。
9
+ 取得资源之前验证配置,`create(context)` 可以读取声明的服务和持久状态。
10
+
11
+ Application 管理审批请求、权限事件保存和 `PermissionToolExecutor`,
12
+ 每次判定权限时取得当前服务。每种 policy 服务具有一个提供方,重复提供方在 setup 之前报错。
13
+
14
+ 测试使用实际文件资源判定权限,并验证不同作用域分别关闭资源。
15
+ 执行 `pnpm --filter @sortedyuan/plugin-permissions test`。
@@ -0,0 +1,10 @@
1
+ import type { PermissionPolicy } from "@sortedyuan/permissions";
2
+ import { type PluginContext, type PluginDefinition } from "@sortedyuan/plugin";
3
+ import { type PluginFactoryMetadata } from "@sortedyuan/plugin-services";
4
+ export interface PermissionPluginOptions<C = unknown> extends PluginFactoryMetadata<C> {
5
+ readonly id?: string;
6
+ readonly create: (context: PluginContext<C>) => PermissionPolicy | Promise<PermissionPolicy>;
7
+ readonly dispose?: (policy: PermissionPolicy) => void | Promise<void>;
8
+ }
9
+ export declare function createPermissionPlugin<C = unknown>(options: PermissionPluginOptions<C>): PluginDefinition<C>;
10
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,EAAgB,KAAK,aAAa,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAA6B,KAAK,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AAEpG,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,qBAAqB,CAAC,CAAC,CAAC;IACpF,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;IAC7F,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,gBAAgB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE;AACD,wBAAgB,sBAAsB,CAAC,CAAC,GAAG,OAAO,EAAE,OAAO,EAAE,uBAAuB,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAO5G"}
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import { definePlugin } from "@sortedyuan/plugin";
2
+ import { services, factoryMetadata } from "@sortedyuan/plugin-services";
3
+ export function createPermissionPlugin(options) {
4
+ return definePlugin({ ...factoryMetadata(options), id: options.id ?? "may.permissions", provides: [services.permissionPolicy], async setup(context) {
5
+ const policy = await options.create(context);
6
+ if (options.dispose)
7
+ context.defer(() => options.dispose(policy));
8
+ if (typeof policy !== "function")
9
+ throw new TypeError("Permission plugin must create a policy");
10
+ context.provide(services.permissionPolicy, policy);
11
+ } });
12
+ }
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAA6C,MAAM,oBAAoB,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,eAAe,EAA8B,MAAM,6BAA6B,CAAC;AAOpG,MAAM,UAAU,sBAAsB,CAAc,OAAmC;IACrF,OAAO,YAAY,CAAC,EAAE,GAAG,eAAe,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,OAAO,CAAC,EAAE,IAAI,iBAAiB,EAAE,QAAQ,EAAE,CAAC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,OAAO;YAChJ,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;YAC7C,IAAI,OAAO,CAAC,OAAO;gBAAE,OAAO,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,OAAQ,CAAC,MAAM,CAAC,CAAC,CAAC;YACnE,IAAI,OAAO,MAAM,KAAK,UAAU;gBAAE,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;YAChG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;QACrD,CAAC,EAAE,CAAC,CAAC;AACP,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,36 @@
1
1
  {
2
2
  "name": "@sortedyuan/plugin-permissions",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.3",
4
+ "description": "Permission policy plugin factory.",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "!dist/.tsbuildinfo"
17
+ ],
18
+ "dependencies": {
19
+ "@sortedyuan/permissions": "0.2.1",
20
+ "@sortedyuan/plugin": "0.2.0",
21
+ "@sortedyuan/plugin-services": "0.2.3"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "^22.0.0"
25
+ },
26
+ "engines": {
27
+ "node": ">=22"
28
+ },
29
+ "license": "MIT",
30
+ "scripts": {
31
+ "build": "tsc -b",
32
+ "clean": "tsc -b --clean",
33
+ "test": "pnpm run build && node --test test/*.test.mjs",
34
+ "test:coverage": "pnpm run build && node --test --experimental-test-coverage test/*.test.mjs"
35
+ }
6
36
  }