@jfdevelops/react-layout-composable-access 0.0.0 → 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/README.md +39 -2
- package/dist/contract.cjs +27 -0
- package/dist/contract.cjs.map +1 -0
- package/dist/contract.d.cts +16 -0
- package/dist/contract.d.cts.map +1 -0
- package/dist/contract.d.mts +16 -0
- package/dist/contract.d.mts.map +1 -0
- package/dist/contract.mjs +26 -0
- package/dist/contract.mjs.map +1 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/package.json +63 -4
package/README.md
CHANGED
|
@@ -1,3 +1,40 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Access composable
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A preset composable for what a page requires before its content is shown. It
|
|
4
|
+
ships its props, so a page declares its requirements and your render callback
|
|
5
|
+
checks them against your own auth.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { createAccessComposable } from '@jfdevelops/react-layout-composable-access';
|
|
9
|
+
|
|
10
|
+
composables: (create) => ({
|
|
11
|
+
Layout: create({ name: 'Layout' }),
|
|
12
|
+
...createAccessComposable(({ roles, permissions, flag, children }) => (
|
|
13
|
+
<AppGuard roles={roles} permissions={permissions} flag={flag}>
|
|
14
|
+
{children}
|
|
15
|
+
</AppGuard>
|
|
16
|
+
)),
|
|
17
|
+
});
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
| Prop | Type | Meaning |
|
|
21
|
+
| -------------- | ---------- | ----------------------------------- |
|
|
22
|
+
| `roles?` | `string[]` | Roles that may view the page |
|
|
23
|
+
| `permissions?` | `string[]` | Permissions the viewer needs |
|
|
24
|
+
| `flag?` | `string` | Feature flag that must be turned on |
|
|
25
|
+
|
|
26
|
+
Every prop is optional, so a page with no requirements declares nothing. The
|
|
27
|
+
composable does not check anything itself.
|
|
28
|
+
|
|
29
|
+
## The contract
|
|
30
|
+
|
|
31
|
+
The preset is the access contract itself, also exported from the `/contract`
|
|
32
|
+
entry point for `extend`:
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
import { createAccessComposable } from '@jfdevelops/react-layout-composable-access/contract';
|
|
36
|
+
|
|
37
|
+
export const createGuardComposable = createAccessComposable.extend({
|
|
38
|
+
name: 'Guard',
|
|
39
|
+
});
|
|
40
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _jfdevelops_react_layout_composables = require("@jfdevelops/react-layout-composables");
|
|
3
|
+
|
|
4
|
+
//#region src/contract.ts
|
|
5
|
+
const names = (0, _jfdevelops_react_layout_composables.createPropValidator)(({ value, error }) => {
|
|
6
|
+
if (!Array.isArray(value) || !value.every((name) => typeof name === "string")) throw error("Expected a list of names");
|
|
7
|
+
return value;
|
|
8
|
+
}).optional();
|
|
9
|
+
/**
|
|
10
|
+
* The access contract: what a page requires before its content is shown. The
|
|
11
|
+
* render callback decides how each requirement is checked.
|
|
12
|
+
*/
|
|
13
|
+
const createAccessComposable = (0, _jfdevelops_react_layout_composables.defineComposableComponent)({
|
|
14
|
+
name: "Access",
|
|
15
|
+
props: {
|
|
16
|
+
roles: names,
|
|
17
|
+
permissions: names,
|
|
18
|
+
flag: ({ value, error }) => {
|
|
19
|
+
if (value !== void 0 && typeof value !== "string") throw error("Expected a flag name");
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.createAccessComposable = createAccessComposable;
|
|
27
|
+
//# sourceMappingURL=contract.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.cjs","names":[],"sources":["../src/contract.ts"],"sourcesContent":["import {\n createPropValidator,\n defineComposableComponent,\n} from '@jfdevelops/react-layout-composables';\n\nconst names = createPropValidator(({ value, error }) => {\n if (\n !Array.isArray(value) ||\n !value.every((name) => typeof name === 'string')\n ) {\n throw error('Expected a list of names');\n }\n\n return value;\n}).optional();\n\n/**\n * The access contract: what a page requires before its content is shown. The\n * render callback decides how each requirement is checked.\n */\nexport const createAccessComposable = defineComposableComponent({\n name: 'Access',\n props: {\n roles: names,\n permissions: names,\n flag: ({ value, error }) => {\n if (value !== undefined && typeof value !== 'string') {\n throw error('Expected a flag name');\n }\n\n return value;\n },\n },\n});\n"],"mappings":";;;;AAKA,MAAM,uEAA6B,EAAE,OAAO,YAAY;CACtD,IACE,CAAC,MAAM,QAAQ,KAAK,KACpB,CAAC,MAAM,OAAO,SAAS,OAAO,SAAS,QAAQ,GAE/C,MAAM,MAAM,0BAA0B;CAGxC,OAAO;AACT,CAAC,EAAE,SAAS;;;;;AAMZ,MAAa,6FAAmD;CAC9D,MAAM;CACN,OAAO;EACL,OAAO;EACP,aAAa;EACb,OAAO,EAAE,OAAO,YAAY;GAC1B,IAAI,UAAU,UAAa,OAAO,UAAU,UAC1C,MAAM,MAAM,sBAAsB;GAGpC,OAAO;EACT;CACF;AACF,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/contract.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The access contract: what a page requires before its content is shown. The
|
|
4
|
+
* render callback decides how each requirement is checked.
|
|
5
|
+
*/
|
|
6
|
+
declare const createAccessComposable: import("@jfdevelops/react-layout-composables").DefinedComposableComponentFactory<"Access", import("@jfdevelops/react-layout-composables").NormalizeComposableProps<{
|
|
7
|
+
roles: import("@jfdevelops/react-layout-validator").PropValidatorSchema<string[] | undefined>;
|
|
8
|
+
permissions: import("@jfdevelops/react-layout-validator").PropValidatorSchema<string[] | undefined>;
|
|
9
|
+
flag: ({
|
|
10
|
+
value,
|
|
11
|
+
error
|
|
12
|
+
}: import("@jfdevelops/react-layout-validator").PropValidatorContext) => string | undefined;
|
|
13
|
+
}>, undefined, {}>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createAccessComposable };
|
|
16
|
+
//# sourceMappingURL=contract.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.cts","names":[],"sources":["../src/contract.ts"],"mappings":";;AAoBA;;;cAAa,sBAAA,iDAAsB,iCAAA,0DAAA,wBAAA"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
//#region src/contract.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The access contract: what a page requires before its content is shown. The
|
|
4
|
+
* render callback decides how each requirement is checked.
|
|
5
|
+
*/
|
|
6
|
+
declare const createAccessComposable: import("@jfdevelops/react-layout-composables").DefinedComposableComponentFactory<"Access", import("@jfdevelops/react-layout-composables").NormalizeComposableProps<{
|
|
7
|
+
roles: import("@jfdevelops/react-layout-validator").PropValidatorSchema<string[] | undefined>;
|
|
8
|
+
permissions: import("@jfdevelops/react-layout-validator").PropValidatorSchema<string[] | undefined>;
|
|
9
|
+
flag: ({
|
|
10
|
+
value,
|
|
11
|
+
error
|
|
12
|
+
}: import("@jfdevelops/react-layout-validator").PropValidatorContext) => string | undefined;
|
|
13
|
+
}>, undefined, {}>;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { createAccessComposable };
|
|
16
|
+
//# sourceMappingURL=contract.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.mts","names":[],"sources":["../src/contract.ts"],"mappings":";;AAoBA;;;cAAa,sBAAA,iDAAsB,iCAAA,0DAAA,wBAAA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { createPropValidator, defineComposableComponent } from "@jfdevelops/react-layout-composables";
|
|
2
|
+
|
|
3
|
+
//#region src/contract.ts
|
|
4
|
+
const names = createPropValidator(({ value, error }) => {
|
|
5
|
+
if (!Array.isArray(value) || !value.every((name) => typeof name === "string")) throw error("Expected a list of names");
|
|
6
|
+
return value;
|
|
7
|
+
}).optional();
|
|
8
|
+
/**
|
|
9
|
+
* The access contract: what a page requires before its content is shown. The
|
|
10
|
+
* render callback decides how each requirement is checked.
|
|
11
|
+
*/
|
|
12
|
+
const createAccessComposable = defineComposableComponent({
|
|
13
|
+
name: "Access",
|
|
14
|
+
props: {
|
|
15
|
+
roles: names,
|
|
16
|
+
permissions: names,
|
|
17
|
+
flag: ({ value, error }) => {
|
|
18
|
+
if (value !== void 0 && typeof value !== "string") throw error("Expected a flag name");
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { createAccessComposable };
|
|
26
|
+
//# sourceMappingURL=contract.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.mjs","names":[],"sources":["../src/contract.ts"],"sourcesContent":["import {\n createPropValidator,\n defineComposableComponent,\n} from '@jfdevelops/react-layout-composables';\n\nconst names = createPropValidator(({ value, error }) => {\n if (\n !Array.isArray(value) ||\n !value.every((name) => typeof name === 'string')\n ) {\n throw error('Expected a list of names');\n }\n\n return value;\n}).optional();\n\n/**\n * The access contract: what a page requires before its content is shown. The\n * render callback decides how each requirement is checked.\n */\nexport const createAccessComposable = defineComposableComponent({\n name: 'Access',\n props: {\n roles: names,\n permissions: names,\n flag: ({ value, error }) => {\n if (value !== undefined && typeof value !== 'string') {\n throw error('Expected a flag name');\n }\n\n return value;\n },\n },\n});\n"],"mappings":";;;AAKA,MAAM,QAAQ,qBAAqB,EAAE,OAAO,YAAY;CACtD,IACE,CAAC,MAAM,QAAQ,KAAK,KACpB,CAAC,MAAM,OAAO,SAAS,OAAO,SAAS,QAAQ,GAE/C,MAAM,MAAM,0BAA0B;CAGxC,OAAO;AACT,CAAC,EAAE,SAAS;;;;;AAMZ,MAAa,yBAAyB,0BAA0B;CAC9D,MAAM;CACN,OAAO;EACL,OAAO;EACP,aAAa;EACb,OAAO,EAAE,OAAO,YAAY;GAC1B,IAAI,UAAU,UAAa,OAAO,UAAU,UAC1C,MAAM,MAAM,sBAAsB;GAGpC,OAAO;EACT;CACF;AACF,CAAC"}
|
package/dist/index.cjs
ADDED
package/dist/index.d.cts
ADDED
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,9 +1,68 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jfdevelops/react-layout-composable-access",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Access preset composable for react-layout and its contract.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/jfdevelops/react-layout.git",
|
|
8
|
+
"directory": "packages/composable-access"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"type": "module",
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"main": "./dist/index.cjs",
|
|
16
|
+
"module": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.mts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.mts",
|
|
21
|
+
"import": "./dist/index.mjs",
|
|
22
|
+
"require": "./dist/index.cjs"
|
|
23
|
+
},
|
|
24
|
+
"./contract": {
|
|
25
|
+
"types": "./dist/contract.d.mts",
|
|
26
|
+
"import": "./dist/contract.mjs",
|
|
27
|
+
"require": "./dist/contract.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
6
31
|
"publishConfig": {
|
|
7
|
-
"access": "public"
|
|
32
|
+
"access": "public",
|
|
33
|
+
"provenance": true
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@jfdevelops/react-layout-composables": "1.1.0",
|
|
37
|
+
"@jfdevelops/react-layout-validator": "1.1.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@testing-library/jest-dom": "6.9.1",
|
|
41
|
+
"@testing-library/react": "16.3.2",
|
|
42
|
+
"@types/node": "24.10.1",
|
|
43
|
+
"@types/react": "18.3.28",
|
|
44
|
+
"@types/react-dom": "18.3.7",
|
|
45
|
+
"@vitejs/plugin-react": "6.0.1",
|
|
46
|
+
"jsdom": "29.0.2",
|
|
47
|
+
"react": "18.3.1",
|
|
48
|
+
"react-dom": "18.3.1",
|
|
49
|
+
"tsdown": "0.22.1",
|
|
50
|
+
"unrun": "0.3.0",
|
|
51
|
+
"vite": "8.0.10",
|
|
52
|
+
"vitest": "4.1.5",
|
|
53
|
+
"zod": "^4.6.7"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"react": ">=18",
|
|
57
|
+
"react-dom": ">=18"
|
|
58
|
+
},
|
|
59
|
+
"engines": {
|
|
60
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
61
|
+
},
|
|
62
|
+
"scripts": {
|
|
63
|
+
"build": "tsdown",
|
|
64
|
+
"typecheck": "tsc --noEmit",
|
|
65
|
+
"test": "vitest run",
|
|
66
|
+
"test:watch": "vitest"
|
|
8
67
|
}
|
|
9
68
|
}
|