@checkstack/scripts 0.0.2 → 0.1.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 +68 -0
- package/package.json +1 -1
- package/src/commands/create.ts +1 -1
- package/src/templates/backend/src/index.ts.hbs +2 -2
- package/src/templates/backend/src/router.ts.hbs +2 -2
- package/src/templates/common/README.md.hbs +2 -2
- package/src/templates/common/src/access.ts.hbs +28 -0
- package/src/templates/common/src/index.ts.hbs +2 -2
- package/src/templates/common/src/rpc-contract.ts.hbs +7 -7
- package/src/templates/frontend/src/index.tsx.hbs +2 -3
- package/src/templates/common/src/permissions.ts.hbs +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,73 @@
|
|
|
1
1
|
# @checkstack/scripts
|
|
2
2
|
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 9faec1f: # Unified AccessRule Terminology Refactoring
|
|
8
|
+
|
|
9
|
+
This release completes a comprehensive terminology refactoring from "permission" to "accessRule" across the entire codebase, establishing a consistent and modern access control vocabulary.
|
|
10
|
+
|
|
11
|
+
## Changes
|
|
12
|
+
|
|
13
|
+
### Core Infrastructure (`@checkstack/common`)
|
|
14
|
+
|
|
15
|
+
- Introduced `AccessRule` interface as the primary access control type
|
|
16
|
+
- Added `accessPair()` helper for creating read/manage access rule pairs
|
|
17
|
+
- Added `access()` builder for individual access rules
|
|
18
|
+
- Replaced `Permission` type with `AccessRule` throughout
|
|
19
|
+
|
|
20
|
+
### API Changes
|
|
21
|
+
|
|
22
|
+
- `env.registerPermissions()` → `env.registerAccessRules()`
|
|
23
|
+
- `meta.permissions` → `meta.access` in RPC contracts
|
|
24
|
+
- `usePermission()` → `useAccess()` in frontend hooks
|
|
25
|
+
- Route `permission:` field → `accessRule:` field
|
|
26
|
+
|
|
27
|
+
### UI Changes
|
|
28
|
+
|
|
29
|
+
- "Roles & Permissions" tab → "Roles & Access Rules"
|
|
30
|
+
- "You don't have permission..." → "You don't have access..."
|
|
31
|
+
- All permission-related UI text updated
|
|
32
|
+
|
|
33
|
+
### Documentation & Templates
|
|
34
|
+
|
|
35
|
+
- Updated 18 documentation files with AccessRule terminology
|
|
36
|
+
- Updated 7 scaffolding templates with `accessPair()` pattern
|
|
37
|
+
- All code examples use new AccessRule API
|
|
38
|
+
|
|
39
|
+
## Migration Guide
|
|
40
|
+
|
|
41
|
+
### Backend Plugins
|
|
42
|
+
|
|
43
|
+
```diff
|
|
44
|
+
- import { permissionList } from "./permissions";
|
|
45
|
+
- env.registerPermissions(permissionList);
|
|
46
|
+
+ import { accessRules } from "./access";
|
|
47
|
+
+ env.registerAccessRules(accessRules);
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### RPC Contracts
|
|
51
|
+
|
|
52
|
+
```diff
|
|
53
|
+
- .meta({ userType: "user", permissions: [permissions.read.id] })
|
|
54
|
+
+ .meta({ userType: "user", access: [access.read] })
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Frontend Hooks
|
|
58
|
+
|
|
59
|
+
```diff
|
|
60
|
+
- const canRead = accessApi.usePermission(permissions.read.id);
|
|
61
|
+
+ const canRead = accessApi.useAccess(access.read);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Routes
|
|
65
|
+
|
|
66
|
+
```diff
|
|
67
|
+
- permission: permissions.entityRead.id,
|
|
68
|
+
+ accessRule: access.read,
|
|
69
|
+
```
|
|
70
|
+
|
|
3
71
|
## 0.0.2
|
|
4
72
|
|
|
5
73
|
### Patch Changes
|
package/package.json
CHANGED
package/src/commands/create.ts
CHANGED
|
@@ -240,7 +240,7 @@ export async function createCommand() {
|
|
|
240
240
|
break;
|
|
241
241
|
}
|
|
242
242
|
case "common": {
|
|
243
|
-
console.log(` 3. Define your
|
|
243
|
+
console.log(` 3. Define your access rules in src/access.ts`);
|
|
244
244
|
console.log(` 4. Define your schemas in src/schemas.ts`);
|
|
245
245
|
console.log(` 5. Define your contract in src/rpc-contract.ts`);
|
|
246
246
|
break;
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
coreServices,
|
|
4
4
|
} from "@checkstack/backend-api";
|
|
5
5
|
import {
|
|
6
|
-
|
|
6
|
+
{{pluginNameCamel}}AccessRules,
|
|
7
7
|
pluginMetadata,
|
|
8
8
|
{{pluginNameCamel}}Contract,
|
|
9
9
|
} from "@checkstack/{{pluginBaseName}}-common";
|
|
@@ -13,7 +13,7 @@ import { create{{pluginNamePascal}}Router } from "./router";
|
|
|
13
13
|
export default createBackendPlugin({
|
|
14
14
|
metadata: pluginMetadata,
|
|
15
15
|
register(env) {
|
|
16
|
-
env.
|
|
16
|
+
env.registerAccessRules({{pluginNameCamel}}AccessRules);
|
|
17
17
|
|
|
18
18
|
env.registerInit({
|
|
19
19
|
schema,
|
|
@@ -8,8 +8,8 @@ import { {{pluginNamePascal}}Service } from "./service";
|
|
|
8
8
|
/**
|
|
9
9
|
* Creates the {{pluginBaseName}} router using contract-based implementation.
|
|
10
10
|
*
|
|
11
|
-
* Auth and
|
|
12
|
-
* based on the contract's meta.userType and meta.
|
|
11
|
+
* Auth and access rules are automatically enforced via autoAuthMiddleware
|
|
12
|
+
* based on the contract's meta.userType and meta.access.
|
|
13
13
|
*/
|
|
14
14
|
const os = implement({{pluginNameCamel}}Contract)
|
|
15
15
|
.$context<RpcContext>()
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
{{pluginNamePascal}}
|
|
3
3
|
Common Common package for the
|
|
4
4
|
{{pluginNamePascal}}
|
|
5
|
-
plugin. Contains shared contracts, types, and
|
|
6
|
-
`src/
|
|
5
|
+
plugin. Contains shared contracts, types, and access rules. ## Structure -
|
|
6
|
+
`src/access.ts - Access rule definitions - `src/schemas.ts` - Zod schemas
|
|
7
7
|
and type definitions - `src/rpc-contract.ts` - oRPC contract definition -
|
|
8
8
|
`src/index.ts` - Barrel exports ## Usage This package is consumed by both: -
|
|
9
9
|
`@checkstack/{{pluginBaseName}}-backend` - Implements the contract -
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { accessPair } from "@checkstack/common";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Access rules for the {{pluginBaseName}} plugin.
|
|
5
|
+
* Uses accessPair() to create read/manage access rule pairs.
|
|
6
|
+
*/
|
|
7
|
+
export const {{pluginNameCamel}}Access = {
|
|
8
|
+
/**
|
|
9
|
+
* Access rules for {{pluginBaseName}} data operations.
|
|
10
|
+
* - read: View {{pluginBaseName}} data (auto-assigned to authenticated users)
|
|
11
|
+
* - manage: Create, update, and delete {{pluginBaseName}} data
|
|
12
|
+
*/
|
|
13
|
+
...accessPair(
|
|
14
|
+
"{{pluginBaseName}}",
|
|
15
|
+
{
|
|
16
|
+
read: "Read {{pluginBaseName}} data",
|
|
17
|
+
manage: "Manage {{pluginBaseName}} data",
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
readIsDefault: true, // read is auto-assigned to "users" role
|
|
21
|
+
}
|
|
22
|
+
),
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* List of all access rules for registration.
|
|
27
|
+
*/
|
|
28
|
+
export const {{pluginNameCamel}}AccessRules = Object.values({{pluginNameCamel}}Access);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Export
|
|
2
|
-
export {
|
|
1
|
+
// Export access rules
|
|
2
|
+
export { {{pluginNameCamel}}Access, {{pluginNameCamel}}AccessRules } from "./access";
|
|
3
3
|
|
|
4
4
|
// Export routes
|
|
5
5
|
export { {{pluginNameCamel}}Routes } from "./routes";
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
Create{{pluginNamePascal}}ItemSchema,
|
|
7
7
|
Update{{pluginNamePascal}}ItemSchema,
|
|
8
8
|
} from "./schemas";
|
|
9
|
-
import {
|
|
9
|
+
import { {{pluginNameCamel}}Access } from "./access";
|
|
10
10
|
import { pluginMetadata } from "./plugin-metadata";
|
|
11
11
|
|
|
12
12
|
// Create base builder with ProcedureMetadata support
|
|
@@ -14,26 +14,26 @@ import { pluginMetadata } from "./plugin-metadata";
|
|
|
14
14
|
const _base = oc.$meta<ProcedureMetadata>({});
|
|
15
15
|
|
|
16
16
|
export const {{pluginNameCamel}}Contract = {
|
|
17
|
-
// List all items - requires authenticated user with read
|
|
17
|
+
// List all items - requires authenticated user with read access
|
|
18
18
|
getItems: _base
|
|
19
|
-
.meta({ userType: "user",
|
|
19
|
+
.meta({ userType: "user", access: [{{pluginNameCamel}}Access.read] })
|
|
20
20
|
.output(z.array({{pluginNamePascal}}ItemSchema)),
|
|
21
21
|
|
|
22
22
|
// Get single item
|
|
23
23
|
getItem: _base
|
|
24
|
-
.meta({ userType: "user",
|
|
24
|
+
.meta({ userType: "user", access: [{{pluginNameCamel}}Access.read] })
|
|
25
25
|
.input(z.string())
|
|
26
26
|
.output({{pluginNamePascal}}ItemSchema),
|
|
27
27
|
|
|
28
28
|
// Create item
|
|
29
29
|
createItem: _base
|
|
30
|
-
.meta({ userType: "user",
|
|
30
|
+
.meta({ userType: "user", access: [{{pluginNameCamel}}Access.manage] })
|
|
31
31
|
.input(Create{{pluginNamePascal}}ItemSchema)
|
|
32
32
|
.output({{pluginNamePascal}}ItemSchema),
|
|
33
33
|
|
|
34
34
|
// Update item
|
|
35
35
|
updateItem: _base
|
|
36
|
-
.meta({ userType: "user",
|
|
36
|
+
.meta({ userType: "user", access: [{{pluginNameCamel}}Access.manage] })
|
|
37
37
|
.input(
|
|
38
38
|
z.object({
|
|
39
39
|
id: z.string(),
|
|
@@ -44,7 +44,7 @@ export const {{pluginNameCamel}}Contract = {
|
|
|
44
44
|
|
|
45
45
|
// Delete item
|
|
46
46
|
deleteItem: _base
|
|
47
|
-
.meta({ userType: "user",
|
|
47
|
+
.meta({ userType: "user", access: [{{pluginNameCamel}}Access.manage] })
|
|
48
48
|
.input(z.string())
|
|
49
49
|
.output(z.void()),
|
|
50
50
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createFrontendPlugin, rpcApiRef, type ApiRef } from "@checkstack/frontend-api";
|
|
2
2
|
import { {{pluginNameCamel}}ApiRef, type {{pluginNamePascal}}ApiClient } from "./api";
|
|
3
3
|
import { {{pluginNamePascal}}ListPage } from "./components/{{pluginNamePascal}}ListPage";
|
|
4
|
-
import { {{pluginNameCamel}}Routes, {{pluginNamePascal}}Api, pluginMetadata,
|
|
4
|
+
import { {{pluginNameCamel}}Routes, {{pluginNamePascal}}Api, pluginMetadata, {{pluginNameCamel}}Access } from "@checkstack/{{pluginBaseName}}-common";
|
|
5
5
|
|
|
6
6
|
export default createFrontendPlugin({
|
|
7
7
|
metadata: pluginMetadata,
|
|
@@ -12,7 +12,7 @@ export default createFrontendPlugin({
|
|
|
12
12
|
route: {{pluginNameCamel}}Routes.routes.home,
|
|
13
13
|
element: <{{pluginNamePascal}}ListPage />,
|
|
14
14
|
title: "{{pluginNamePascal}}",
|
|
15
|
-
|
|
15
|
+
accessRule: {{pluginNameCamel}}Access.read,
|
|
16
16
|
},
|
|
17
17
|
],
|
|
18
18
|
|
|
@@ -30,4 +30,3 @@ export default createFrontendPlugin({
|
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
export * from "./api";
|
|
33
|
-
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createPermission } from "@checkstack/common";
|
|
2
|
-
|
|
3
|
-
export const permissions = {
|
|
4
|
-
{{pluginNameCamel}}Read: createPermission(
|
|
5
|
-
"{{pluginBaseName}}",
|
|
6
|
-
"read",
|
|
7
|
-
"Read {{pluginBaseName}} data",
|
|
8
|
-
{ isAuthenticatedDefault: true } // Auto-assigned to "users" role
|
|
9
|
-
),
|
|
10
|
-
{{pluginNameCamel}}Manage: createPermission(
|
|
11
|
-
"{{pluginBaseName}}",
|
|
12
|
-
"manage",
|
|
13
|
-
"Manage {{pluginBaseName}} data"
|
|
14
|
-
),
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const permissionList = Object.values(permissions);
|