@tryvitris/website-admin-contracts 1.0.0 → 1.2.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/LICENSE CHANGED
@@ -1,21 +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.
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
- # Website Admin Contracts
2
-
3
- Validated installation manifests, roles, permissions and module contracts for `@tryvitris/website-admin-harness`. Node.js 24+. MIT licensed.
1
+ # Website Admin Contracts
2
+
3
+ Validated installation manifests, roles, permissions and module contracts for `@tryvitris/website-admin-harness`. Node.js 24+. MIT licensed.
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export * from './stripe-billing.js';
3
3
  export * from './client-portfolio.js';
4
4
  export * from './client-onboarding.js';
5
5
  export * from './scheduling.js';
6
+ export * from './webmaster.js';
7
+ export * from './pairing.js';
6
8
  export declare const contractVersion = 1;
7
9
  export declare const coreSections: readonly ["overview", "leads", "analytics", "settings", "access", "activity"];
8
10
  export declare const permissions: readonly ["leads:read", "leads:write", "analytics:read", "settings:write", "access:read", "access:write", "activity:read", "tasks:read", "tasks:write", "appointments:read", "appointments:write", "availability:write", "scheduling:configure", "calendar-connections:manage", "clients:read", "client-changes:request", "client-releases:publish", "prospects:read", "prospects:write", "billing:read", "billing:customers:write", "billing:catalog:read", "billing:subscriptions:write", "billing:invoices:write", "billing:collect", "billing:connection:manage", "account-billing:read", "account-billing:manage"];
@@ -11,6 +13,7 @@ export type Role = 'owner' | 'administrator' | 'editor' | 'analyst';
11
13
  export declare const roles: Record<Role, readonly Permission[]>;
12
14
  export declare function can(role: Role, permission: Permission): boolean;
13
15
  export interface AdminManifest {
16
+ reportingPairing?: import('./pairing.js').PairingConfiguration;
14
17
  schemaVersion: 1;
15
18
  installationId: string;
16
19
  business: {
@@ -47,7 +50,14 @@ export interface User {
47
50
  id: string;
48
51
  email: string;
49
52
  role: Role;
53
+ webmaster?: {
54
+ organizationId: string;
55
+ organizationName: string;
56
+ permissions: Permission[];
57
+ revision: number;
58
+ };
50
59
  }
60
+ export declare function userCan(user: User, permission: Permission): boolean;
51
61
  export interface BootstrapResponse {
52
62
  manifest: AdminManifest;
53
63
  user: User | null;
@@ -61,6 +71,7 @@ export interface BootstrapResponse {
61
71
  accountAuth?: AccountCapabilities;
62
72
  emailLoginConfigured?: boolean;
63
73
  privateLocalSignIn?: boolean;
74
+ webmasterEnabled?: boolean;
64
75
  }
65
76
  export type DataSource = 'synthetic' | 'connected' | 'not-connected';
66
77
  export interface LeadRow {
@@ -169,6 +180,9 @@ export interface ActivityRow {
169
180
  actor: string;
170
181
  action: string;
171
182
  created_at: string;
183
+ person_id?: string | null;
184
+ organization_id?: string | null;
185
+ organization_name?: string | null;
172
186
  }
173
187
  export interface TaskRow {
174
188
  id: string;
package/dist/index.js CHANGED
@@ -7,6 +7,8 @@ export * from "./stripe-billing.js";
7
7
  export * from "./client-portfolio.js";
8
8
  export * from "./client-onboarding.js";
9
9
  export * from "./scheduling.js";
10
+ export * from "./webmaster.js";
11
+ export * from "./pairing.js";
10
12
  const contractVersion = 1;
11
13
  const coreSections = ["overview", "leads", "analytics", "settings", "access", "activity"];
12
14
  const permissions = ["leads:read", "leads:write", "analytics:read", "settings:write", "access:read", "access:write", "activity:read", "tasks:read", "tasks:write", ...schedulingPermissions, ...clientPortfolioPermissions, ...clientOnboardingPermissions, ...billingPermissions];
@@ -34,6 +36,9 @@ function isThemeColor(value) {
34
36
  function isWebsiteTheme(value) {
35
37
  return isObject(value) && Object.keys(value).length > 0 && Object.entries(value).every(([key, color]) => websiteColorKeys.includes(key) && isThemeColor(color));
36
38
  }
39
+ function userCan(user, permission) {
40
+ return user.webmaster ? user.webmaster.permissions.includes(permission) : can(user.role, permission);
41
+ }
37
42
  function isLeadFollowUp(value) {
38
43
  if (!isObject(value)) return false;
39
44
  return (value.assignedTo === null || typeof value.assignedTo === "string" && value.assignedTo.length > 0 && value.assignedTo.length <= 100) && (value.dueDate === null || typeof value.dueDate === "string" && /^\d{4}-\d{2}-\d{2}$/.test(value.dueDate) && Number.isFinite(Date.parse(value.dueDate + "T00:00:00Z")) && (/* @__PURE__ */ new Date(value.dueDate + "T00:00:00Z")).toISOString().slice(0, 10) === value.dueDate) && typeof value.notes === "string" && value.notes.length <= 3e3 && typeof value.completed === "boolean" && Number.isSafeInteger(value.revision) && Number(value.revision) >= 0 && (value.updatedAt === null || typeof value.updatedAt === "string");
@@ -114,6 +119,18 @@ function parseManifest(value) {
114
119
  backend = { provider: "vitris-harness", origin: origin(b.origin, "backend origin"), tenantId };
115
120
  if (isLoopback(backend.origin) && !isLoopback(String(v.adminOrigin))) throw new Error("Production admin cannot connect to a local backend");
116
121
  }
122
+ let reportingPairing;
123
+ if (v.reportingPairing !== void 0) {
124
+ const config = object(v.reportingPairing);
125
+ if (!Array.isArray(config.trustedWebmasters) || config.trustedWebmasters.length < 1 || config.trustedWebmasters.length > 10) throw new Error("Configure trusted webmaster installations explicitly");
126
+ const trustedWebmasters = config.trustedWebmasters.map((raw) => {
127
+ const p = object(raw), adminOrigin = origin(p.adminOrigin, "trusted webmaster origin");
128
+ if (isLoopback(adminOrigin) && !isLoopback(String(v.adminOrigin))) throw new Error("A production issuer cannot trust a local webmaster");
129
+ return { installationId: id(p.installationId, "webmaster installation ID"), siteId: id(p.siteId, "webmaster site ID"), adminOrigin, organizationId: id(p.organizationId, "webmaster organization ID"), organizationName: text(p.organizationName, "webmaster organization name") };
130
+ });
131
+ if (new Set(trustedWebmasters.map((p) => p.adminOrigin)).size !== trustedWebmasters.length) throw new Error("Duplicate trusted webmaster origin");
132
+ reportingPairing = { trustedWebmasters };
133
+ }
117
134
  return {
118
135
  schemaVersion: 1,
119
136
  installationId: id(v.installationId, "installation ID"),
@@ -122,7 +139,8 @@ function parseManifest(value) {
122
139
  adminOrigin: origin(v.adminOrigin, "admin origin"),
123
140
  modules,
124
141
  ...backend ? { backend } : {},
125
- ...v.theme ? { theme: v.theme } : {}
142
+ ...v.theme ? { theme: v.theme } : {},
143
+ ...reportingPairing ? { reportingPairing } : {}
126
144
  };
127
145
  }
128
146
  function validateModules(manifest, modules) {
@@ -152,6 +170,7 @@ export {
152
170
  parseManifest,
153
171
  permissions,
154
172
  roles,
173
+ userCan,
155
174
  validateModules,
156
175
  websiteColorKeys,
157
176
  workQueueModule
@@ -0,0 +1,94 @@
1
+ export declare const reportingPairingVersion = 1;
2
+ export declare const pairingBase = "/api/webmaster-reporting/v1";
3
+ export declare const pairingMachineActions: readonly ["request", "poll", "exchange", "report", "rotate", "revoke"];
4
+ export type PairingMachineAction = typeof pairingMachineActions[number];
5
+ export declare const pairingPaths: Record<"capabilities" | "approval" | "approve" | "reject" | "grants" | "revoke-grant" | PairingMachineAction, string>;
6
+ export declare const pairingPolicy: {
7
+ requestLifetimeSeconds: number;
8
+ receiptLifetimeSeconds: number;
9
+ signatureSkewSeconds: number;
10
+ analyticsDays: readonly [14, 30];
11
+ };
12
+ export interface PairingStart {
13
+ requestId: string;
14
+ challenge: string;
15
+ }
16
+ export interface PairingExchange {
17
+ requestId: string;
18
+ code: string;
19
+ verifier: string;
20
+ }
21
+ export interface PairingReportRequest {
22
+ grantId: string;
23
+ operation: 'status' | 'analytics';
24
+ days?: 14 | 30;
25
+ }
26
+ export interface PairingMutation {
27
+ grantId: string;
28
+ operationId: string;
29
+ }
30
+ export declare const reportingOperations: readonly ["status", "analytics"];
31
+ export interface PairingIdentity {
32
+ installationId: string;
33
+ siteId: string;
34
+ adminOrigin: string;
35
+ }
36
+ export interface PairingPeer extends PairingIdentity {
37
+ organizationId: string;
38
+ organizationName: string;
39
+ }
40
+ export interface PairingConfiguration {
41
+ trustedWebmasters: PairingPeer[];
42
+ }
43
+ export interface PairingCapabilities {
44
+ version: 1;
45
+ issuer: PairingIdentity;
46
+ siteOrigin: string;
47
+ operations: readonly ['status', 'analytics'];
48
+ scope: 'analytics:read';
49
+ requestPath: string;
50
+ approvalPath: string;
51
+ }
52
+ export interface PairingEnvelope {
53
+ version: 1;
54
+ identity: PairingIdentity;
55
+ target: string;
56
+ path: string;
57
+ time: number;
58
+ nonce: string;
59
+ tokenHash: string;
60
+ request: Record<string, unknown>;
61
+ }
62
+ export interface PairingCredential {
63
+ version: 1;
64
+ issuer: PairingIdentity;
65
+ consumer: PairingIdentity;
66
+ siteOrigin: string;
67
+ grantId: string;
68
+ token: string;
69
+ keyId: string;
70
+ scope: 'analytics:read';
71
+ operations: readonly ['status', 'analytics'];
72
+ }
73
+ export interface PairingGrantView {
74
+ id: string;
75
+ organizationId: string;
76
+ organizationName: string;
77
+ consumer: PairingIdentity;
78
+ createdAt: number;
79
+ lastUsedAt: number | null;
80
+ revokedAt: number | null;
81
+ revision: number;
82
+ }
83
+ export interface PairingRequestView {
84
+ id: string;
85
+ organizationName: string;
86
+ consumer: PairingIdentity;
87
+ issuer: PairingIdentity;
88
+ expiresAt: number;
89
+ status: 'pending' | 'approved' | 'revoked' | 'expired';
90
+ scope: 'analytics:read';
91
+ createsRelationship: boolean;
92
+ }
93
+ export type PairingErrorCode = 'invalid_request' | 'unauthorized' | 'forbidden' | 'expired' | 'replay' | 'conflict' | 'unavailable' | 'unsupported';
94
+ export declare function samePairingIdentity(a: PairingIdentity, b: PairingIdentity): boolean;
@@ -0,0 +1,19 @@
1
+ // packages/contracts/src/pairing.ts
2
+ var reportingPairingVersion = 1;
3
+ var pairingBase = "/api/webmaster-reporting/v1";
4
+ var pairingMachineActions = ["request", "poll", "exchange", "report", "rotate", "revoke"];
5
+ var pairingPaths = Object.fromEntries(["capabilities", "approval", "approve", "reject", "grants", "revoke-grant", ...pairingMachineActions].map((action) => [action, pairingBase + "/" + action]));
6
+ var pairingPolicy = { requestLifetimeSeconds: 600, receiptLifetimeSeconds: 600, signatureSkewSeconds: 90, analyticsDays: [14, 30] };
7
+ var reportingOperations = ["status", "analytics"];
8
+ function samePairingIdentity(a, b) {
9
+ return a.installationId === b.installationId && a.siteId === b.siteId && a.adminOrigin === b.adminOrigin;
10
+ }
11
+ export {
12
+ pairingBase,
13
+ pairingMachineActions,
14
+ pairingPaths,
15
+ pairingPolicy,
16
+ reportingOperations,
17
+ reportingPairingVersion,
18
+ samePairingIdentity
19
+ };
@@ -0,0 +1,25 @@
1
+ /** Operational access never includes ownership, access administration or billing. */
2
+ export declare const webmasterScopes: readonly ["analytics:read", "settings:write", "tasks:read", "tasks:write", "leads:read", "leads:write"];
3
+ export type WebmasterScope = typeof webmasterScopes[number];
4
+ export interface WebmasterMember {
5
+ userId: string;
6
+ permissions: WebmasterScope[];
7
+ }
8
+ export interface WebmasterConnection {
9
+ organizationId: string;
10
+ organizationName: string;
11
+ billingProvider: boolean;
12
+ status: 'connected' | 'disconnected';
13
+ revision: number;
14
+ members: WebmasterMember[];
15
+ permissions: WebmasterScope[];
16
+ }
17
+ export interface WebmasterResponse {
18
+ connection: WebmasterConnection | null;
19
+ canManage: boolean;
20
+ eligibleUsers: Array<{
21
+ id: string;
22
+ email: string;
23
+ }>;
24
+ }
25
+ export declare function validWebmasterScopes(value: unknown): value is WebmasterScope[];
@@ -0,0 +1,9 @@
1
+ // packages/contracts/src/webmaster.ts
2
+ var webmasterScopes = ["analytics:read", "settings:write", "tasks:read", "tasks:write", "leads:read", "leads:write"];
3
+ function validWebmasterScopes(value) {
4
+ return Array.isArray(value) && value.length <= webmasterScopes.length && new Set(value).size === value.length && value.every((p) => webmasterScopes.includes(p)) && (!value.includes("leads:write") || value.includes("leads:read")) && (!value.includes("tasks:write") || value.includes("tasks:read"));
5
+ }
6
+ export {
7
+ validWebmasterScopes,
8
+ webmasterScopes
9
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tryvitris/website-admin-contracts",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "description": "Validated installation and module contracts for Cloudflare business admin apps",