@tryvitris/website-admin-contracts 0.0.0-stage → 0.1.0-alpha.1

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 Vitris contributors
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,3 @@
1
- # Temporary Holding Version
1
+ # Website Admin Contracts
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
+ Validated installation manifests, roles, permissions and module contracts for `@tryvitris/website-admin-harness`. Node.js 24+. MIT licensed.
@@ -0,0 +1,38 @@
1
+ export declare const contractVersion = 1;
2
+ export declare const coreSections: readonly ["overview", "leads", "analytics", "settings", "access", "activity"];
3
+ export declare const permissions: readonly ["leads:read", "leads:write", "analytics:read", "settings:write", "access:read", "activity:read", "tasks:read", "tasks:write"];
4
+ export type Permission = typeof permissions[number];
5
+ export type Role = 'owner' | 'administrator' | 'editor' | 'analyst';
6
+ export declare const roles: Record<Role, readonly Permission[]>;
7
+ export declare function can(role: Role, permission: Permission): boolean;
8
+ export interface AdminManifest {
9
+ schemaVersion: 1;
10
+ installationId: string;
11
+ business: {
12
+ name: string;
13
+ initials: string;
14
+ };
15
+ site: {
16
+ id: string;
17
+ name: string;
18
+ origin: string;
19
+ };
20
+ adminOrigin: string;
21
+ modules: string[];
22
+ backend?: {
23
+ provider: 'vitris-harness';
24
+ origin: string;
25
+ tenantId: string;
26
+ };
27
+ }
28
+ export interface ModuleDefinition {
29
+ id: string;
30
+ version: number;
31
+ label: string;
32
+ permission: Permission;
33
+ description: string;
34
+ }
35
+ export declare const workQueueModule: ModuleDefinition;
36
+ export declare function isLoopback(origin: string): boolean;
37
+ export declare function parseManifest(value: unknown): AdminManifest;
38
+ export declare function validateModules(manifest: AdminManifest, modules: ModuleDefinition[]): void;
package/dist/index.js ADDED
@@ -0,0 +1,91 @@
1
+ // packages/contracts/src/index.ts
2
+ var contractVersion = 1;
3
+ var coreSections = ["overview", "leads", "analytics", "settings", "access", "activity"];
4
+ var permissions = ["leads:read", "leads:write", "analytics:read", "settings:write", "access:read", "activity:read", "tasks:read", "tasks:write"];
5
+ var roles = {
6
+ owner: permissions,
7
+ administrator: permissions,
8
+ editor: ["leads:read", "leads:write", "activity:read", "tasks:read", "tasks:write"],
9
+ analyst: ["analytics:read", "activity:read"]
10
+ };
11
+ function can(role, permission) {
12
+ return roles[role]?.includes(permission) ?? false;
13
+ }
14
+ var workQueueModule = {
15
+ id: "work-queue",
16
+ version: 1,
17
+ label: "Work queue",
18
+ permission: "tasks:read",
19
+ description: "An example business module for tracking follow-up work."
20
+ };
21
+ function object(value) {
22
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new Error("Expected an object");
23
+ return value;
24
+ }
25
+ function text(value, name, limit = 100) {
26
+ if (typeof value !== "string" || !value.trim() || value.length > limit) throw new Error(`Invalid ${name}`);
27
+ return value.trim();
28
+ }
29
+ function id(value, name) {
30
+ const result = text(value, name, 64);
31
+ if (!/^[a-z][a-z0-9-]*$/.test(result)) throw new Error(`Invalid ${name}`);
32
+ return result;
33
+ }
34
+ function isLoopback(origin2) {
35
+ const url = new URL(origin2);
36
+ return ["localhost", "127.0.0.1", "[::1]"].includes(url.hostname);
37
+ }
38
+ function origin(value, name) {
39
+ const raw = text(value, name, 250);
40
+ const url = new URL(raw);
41
+ if (raw !== url.origin || url.username || url.password || url.protocol !== "https:" && !(url.protocol === "http:" && isLoopback(raw))) throw new Error(`Invalid ${name}: use an exact HTTPS origin (HTTP is local only)`);
42
+ return raw;
43
+ }
44
+ function parseManifest(value) {
45
+ const v = object(value);
46
+ const business = object(v.business);
47
+ const site = object(v.site);
48
+ if (v.schemaVersion !== 1) throw new Error("Unsupported admin contract version");
49
+ if (!Array.isArray(v.modules) || v.modules.length > 20) throw new Error("Invalid modules");
50
+ const modules = v.modules.map((x) => id(x, "module ID"));
51
+ if (new Set(modules).size !== modules.length) throw new Error("Duplicate module");
52
+ let backend;
53
+ if (v.backend !== void 0) {
54
+ const b = object(v.backend);
55
+ if (b.provider !== "vitris-harness") throw new Error("Unsupported backend provider");
56
+ const tenantId = text(b.tenantId, "tenant ID", 100);
57
+ if (!/^[a-zA-Z0-9_-]+$/.test(tenantId)) throw new Error("Invalid tenant ID");
58
+ backend = { provider: "vitris-harness", origin: origin(b.origin, "backend origin"), tenantId };
59
+ if (isLoopback(backend.origin) && !isLoopback(String(v.adminOrigin))) throw new Error("Production admin cannot connect to a local backend");
60
+ }
61
+ return {
62
+ schemaVersion: 1,
63
+ installationId: id(v.installationId, "installation ID"),
64
+ business: { name: text(business.name, "business name"), initials: text(business.initials, "initials", 3) },
65
+ site: { id: id(site.id, "site ID"), name: text(site.name, "site name"), origin: origin(site.origin, "website origin") },
66
+ adminOrigin: origin(v.adminOrigin, "admin origin"),
67
+ modules,
68
+ ...backend ? { backend } : {}
69
+ };
70
+ }
71
+ function validateModules(manifest, modules) {
72
+ const ids = /* @__PURE__ */ new Set();
73
+ for (const module of modules) {
74
+ id(module.id, "module ID");
75
+ if (ids.has(module.id) || coreSections.includes(module.id)) throw new Error("Duplicate or reserved module ID");
76
+ if (!permissions.includes(module.permission)) throw new Error("Unknown module permission");
77
+ ids.add(module.id);
78
+ }
79
+ for (const enabled of manifest.modules) if (!ids.has(enabled)) throw new Error(`Module ${enabled} is not installed`);
80
+ }
81
+ export {
82
+ can,
83
+ contractVersion,
84
+ coreSections,
85
+ isLoopback,
86
+ parseManifest,
87
+ permissions,
88
+ roles,
89
+ validateModules,
90
+ workQueueModule
91
+ };
package/package.json CHANGED
@@ -1,6 +1,32 @@
1
1
  {
2
2
  "name": "@tryvitris/website-admin-contracts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-alpha.1",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "description": "Validated installation and module contracts for Cloudflare business admin apps",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "tag": "alpha"
19
+ },
20
+ "engines": {
21
+ "node": ">=24"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/jackperrotta/website-admin-harness.git",
26
+ "directory": "packages/contracts"
27
+ },
28
+ "homepage": "https://github.com/jackperrotta/website-admin-harness#readme",
29
+ "bugs": {
30
+ "url": "https://github.com/jackperrotta/website-admin-harness/issues"
31
+ }
32
+ }