@tryvitris/website-admin-contracts 0.1.0-alpha.1 → 1.0.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 +21 -21
- package/README.md +3 -3
- package/dist/billing.d.ts +117 -0
- package/dist/billing.js +7 -0
- package/dist/client-onboarding.d.ts +69 -0
- package/dist/client-onboarding.js +35 -0
- package/dist/client-portfolio.d.ts +64 -0
- package/dist/client-portfolio.js +9 -0
- package/dist/index.d.ts +163 -1
- package/dist/index.js +75 -8
- package/dist/scheduling.d.ts +410 -0
- package/dist/scheduling.js +216 -0
- package/dist/stripe-billing.d.ts +103 -0
- package/dist/stripe-billing.js +0 -0
- package/package.json +36 -32
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.
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/** Local preview contracts. These are not a production Stripe integration. */
|
|
2
|
+
export declare const billingPermissions: readonly ["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"];
|
|
3
|
+
export interface BillingCustomer {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
contact: string;
|
|
7
|
+
email: string;
|
|
8
|
+
initials: string;
|
|
9
|
+
color: string;
|
|
10
|
+
websites: string[];
|
|
11
|
+
note: string;
|
|
12
|
+
}
|
|
13
|
+
export interface BillingPlan {
|
|
14
|
+
id: string;
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
amount: number;
|
|
18
|
+
interval: 'month' | 'year';
|
|
19
|
+
features: string[];
|
|
20
|
+
selfService: boolean;
|
|
21
|
+
}
|
|
22
|
+
export interface BillingSubscription {
|
|
23
|
+
id: string;
|
|
24
|
+
customerId: string;
|
|
25
|
+
planId: string;
|
|
26
|
+
status: 'active' | 'past_due' | 'trialing' | 'canceled';
|
|
27
|
+
renewal: string;
|
|
28
|
+
cancelAtPeriodEnd: boolean;
|
|
29
|
+
scheduledPlanId: string | null;
|
|
30
|
+
}
|
|
31
|
+
export interface BillingLine {
|
|
32
|
+
description: string;
|
|
33
|
+
quantity: number;
|
|
34
|
+
unitAmount: number;
|
|
35
|
+
}
|
|
36
|
+
export interface BillingInvoice {
|
|
37
|
+
id: string;
|
|
38
|
+
customerId: string;
|
|
39
|
+
number: string;
|
|
40
|
+
description: string;
|
|
41
|
+
lines: BillingLine[];
|
|
42
|
+
status: 'draft' | 'open' | 'paid' | 'void';
|
|
43
|
+
issued: string;
|
|
44
|
+
due: string;
|
|
45
|
+
paidAt: string | null;
|
|
46
|
+
kind: 'subscription' | 'one_off';
|
|
47
|
+
}
|
|
48
|
+
export interface BillingPayment {
|
|
49
|
+
id: string;
|
|
50
|
+
customerId: string;
|
|
51
|
+
invoiceId: string;
|
|
52
|
+
amount: number;
|
|
53
|
+
status: 'succeeded' | 'failed' | 'refunded';
|
|
54
|
+
date: string;
|
|
55
|
+
}
|
|
56
|
+
export interface BillingActivity {
|
|
57
|
+
id: string;
|
|
58
|
+
customerId: string | null;
|
|
59
|
+
text: string;
|
|
60
|
+
at: string;
|
|
61
|
+
}
|
|
62
|
+
export interface BillingState {
|
|
63
|
+
customers: BillingCustomer[];
|
|
64
|
+
plans: BillingPlan[];
|
|
65
|
+
subscriptions: BillingSubscription[];
|
|
66
|
+
invoices: BillingInvoice[];
|
|
67
|
+
payments: BillingPayment[];
|
|
68
|
+
activity: BillingActivity[];
|
|
69
|
+
connection: boolean;
|
|
70
|
+
card: {
|
|
71
|
+
brand: string;
|
|
72
|
+
last4: string;
|
|
73
|
+
expiry: string;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
export interface BillingResponse extends BillingState {
|
|
77
|
+
revision: number;
|
|
78
|
+
simulated: true;
|
|
79
|
+
audience: 'seller' | 'customer';
|
|
80
|
+
customerId: string | null;
|
|
81
|
+
supplier: string;
|
|
82
|
+
asOf: string;
|
|
83
|
+
currency: 'USD';
|
|
84
|
+
}
|
|
85
|
+
export type BillingCommand = {
|
|
86
|
+
action: 'plan';
|
|
87
|
+
subscriptionId: string;
|
|
88
|
+
planId: string;
|
|
89
|
+
timing: 'renewal' | 'now';
|
|
90
|
+
reviewed: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
action: 'cancel' | 'resume';
|
|
93
|
+
subscriptionId: string;
|
|
94
|
+
reviewed: boolean;
|
|
95
|
+
} | {
|
|
96
|
+
action: 'draft';
|
|
97
|
+
invoiceId?: string;
|
|
98
|
+
customerId: string;
|
|
99
|
+
description: string;
|
|
100
|
+
due: string;
|
|
101
|
+
lines: BillingLine[];
|
|
102
|
+
} | {
|
|
103
|
+
action: 'send' | 'void' | 'pay';
|
|
104
|
+
invoiceId: string;
|
|
105
|
+
reviewed: boolean;
|
|
106
|
+
} | {
|
|
107
|
+
action: 'card';
|
|
108
|
+
reviewed: boolean;
|
|
109
|
+
} | {
|
|
110
|
+
action: 'connection';
|
|
111
|
+
connected: boolean;
|
|
112
|
+
};
|
|
113
|
+
export type BillingMutation = BillingCommand & {
|
|
114
|
+
revision: number;
|
|
115
|
+
idempotencyKey: string;
|
|
116
|
+
};
|
|
117
|
+
export declare const invoiceTotal: (invoice: Pick<BillingInvoice, "lines">) => number;
|
package/dist/billing.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// packages/contracts/src/billing.ts
|
|
2
|
+
var billingPermissions = ["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"];
|
|
3
|
+
var invoiceTotal = (invoice) => invoice.lines.reduce((sum, line) => sum + line.quantity * line.unitAmount, 0);
|
|
4
|
+
export {
|
|
5
|
+
billingPermissions,
|
|
6
|
+
invoiceTotal
|
|
7
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare const clientOnboardingPermissions: readonly ["prospects:read", "prospects:write"];
|
|
2
|
+
export interface OnboardingField {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
required: boolean;
|
|
6
|
+
value: string;
|
|
7
|
+
kind?: 'text' | 'textarea' | 'tel' | 'url';
|
|
8
|
+
section?: 'business' | 'website';
|
|
9
|
+
help?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface OnboardingTemplate {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
businessType: string;
|
|
15
|
+
title: string;
|
|
16
|
+
intro: string;
|
|
17
|
+
message: string;
|
|
18
|
+
fields: OnboardingField[];
|
|
19
|
+
requiresPayment: boolean;
|
|
20
|
+
revision: number;
|
|
21
|
+
updatedAt: string | null;
|
|
22
|
+
source: 'starter' | 'saved';
|
|
23
|
+
}
|
|
24
|
+
export interface OnboardingConfig {
|
|
25
|
+
templateId?: string;
|
|
26
|
+
templateName?: string;
|
|
27
|
+
templateRevision?: number;
|
|
28
|
+
title: string;
|
|
29
|
+
intro: string;
|
|
30
|
+
}
|
|
31
|
+
export interface OnboardingDraft {
|
|
32
|
+
name?: string;
|
|
33
|
+
fields?: OnboardingField[];
|
|
34
|
+
step?: 'business' | 'website' | 'account';
|
|
35
|
+
savedAt?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface Prospect {
|
|
38
|
+
id: string;
|
|
39
|
+
business: string;
|
|
40
|
+
name: string;
|
|
41
|
+
email: string;
|
|
42
|
+
previewUrl: string;
|
|
43
|
+
message: string;
|
|
44
|
+
status: 'draft' | 'invited' | 'expired' | 'active' | 'revoked';
|
|
45
|
+
createdAt: string;
|
|
46
|
+
invitedAt: string | null;
|
|
47
|
+
expiresAt: string | null;
|
|
48
|
+
activatedAt: string | null;
|
|
49
|
+
feedback: string;
|
|
50
|
+
feedbackAt: string | null;
|
|
51
|
+
fields: OnboardingField[];
|
|
52
|
+
requiresPayment: boolean;
|
|
53
|
+
paymentStatus: 'not_requested' | 'pending' | 'demo_complete';
|
|
54
|
+
onboarding?: OnboardingConfig;
|
|
55
|
+
}
|
|
56
|
+
export interface ProspectWorkspace {
|
|
57
|
+
rows: Prospect[];
|
|
58
|
+
templates: OnboardingTemplate[];
|
|
59
|
+
localOnly: true;
|
|
60
|
+
delivery: 'copy-link';
|
|
61
|
+
}
|
|
62
|
+
export type ProspectPortal = Pick<Prospect, 'business' | 'name' | 'email' | 'previewUrl' | 'message' | 'feedback' | 'feedbackAt' | 'fields' | 'requiresPayment' | 'paymentStatus'> & {
|
|
63
|
+
onboarding?: Pick<OnboardingConfig, 'title' | 'intro'>;
|
|
64
|
+
draft?: OnboardingDraft;
|
|
65
|
+
inviteId?: string;
|
|
66
|
+
};
|
|
67
|
+
export declare function normalizeOnboardingFields(value: unknown): OnboardingField[] | null;
|
|
68
|
+
export declare function onboardingFieldError(field: OnboardingField): string | null;
|
|
69
|
+
export declare function onboardingAnswersMatch(answers: OnboardingField[], original: OnboardingField[], complete?: boolean): boolean;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// packages/contracts/src/client-onboarding.ts
|
|
2
|
+
var clientOnboardingPermissions = ["prospects:read", "prospects:write"];
|
|
3
|
+
function normalizeOnboardingFields(value) {
|
|
4
|
+
if (!Array.isArray(value) || value.length > 10) return null;
|
|
5
|
+
const result = [];
|
|
6
|
+
for (const item of value) {
|
|
7
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return null;
|
|
8
|
+
const f = item;
|
|
9
|
+
if (typeof f.id !== "string" || !/^[\w-]{1,60}$/.test(f.id) || result.some((v) => v.id === f.id) || typeof f.label !== "string" || !f.label.trim() || f.label.trim().length > 80 || typeof f.required !== "boolean" || typeof f.value !== "string" || f.value.trim().length > 1e3 || f.kind !== void 0 && !["text", "textarea", "tel", "url"].includes(String(f.kind)) || f.section !== void 0 && !["business", "website"].includes(String(f.section)) || f.help !== void 0 && (typeof f.help !== "string" || f.help.length > 180)) return null;
|
|
10
|
+
result.push({ id: f.id, label: f.label.trim(), required: f.required, value: f.value.trim(), ...f.kind ? { kind: f.kind } : {}, ...f.section ? { section: f.section } : {}, ...f.help ? { help: String(f.help).trim() } : {} });
|
|
11
|
+
}
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
function onboardingFieldError(field) {
|
|
15
|
+
if (!field.value.trim()) return field.required ? "Please complete this field." : null;
|
|
16
|
+
if (field.kind === "tel" && field.value.replace(/[^0-9]/g, "").length < 5) return "Enter a phone number.";
|
|
17
|
+
if (field.kind === "url") {
|
|
18
|
+
try {
|
|
19
|
+
const u = new URL(field.value);
|
|
20
|
+
if (!["http:", "https:"].includes(u.protocol) || !u.hostname.includes(".") || u.username || u.password) return "Enter a complete website URL.";
|
|
21
|
+
} catch {
|
|
22
|
+
return "Enter a complete website URL, including https://.";
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
function onboardingAnswersMatch(answers, original, complete = false) {
|
|
28
|
+
return answers.length === original.length && original.every((f) => answers.some((a) => a.id === f.id && a.label === f.label && a.required === f.required && (a.kind || "text") === (f.kind || "text") && (a.section || "business") === (f.section || "business") && (a.help || "") === (f.help || "") && (!complete || !onboardingFieldError(a))));
|
|
29
|
+
}
|
|
30
|
+
export {
|
|
31
|
+
clientOnboardingPermissions,
|
|
32
|
+
normalizeOnboardingFields,
|
|
33
|
+
onboardingAnswersMatch,
|
|
34
|
+
onboardingFieldError
|
|
35
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { AnalyticsRow, AnalyticsResponse } from './index.ts';
|
|
2
|
+
export declare const clientPortfolioPermissions: readonly ["clients:read", "client-changes:request", "client-releases:publish"];
|
|
3
|
+
export type PortfolioStatus = 'requested' | 'in_progress' | 'preview_ready' | 'queued' | 'published' | 'failed' | 'canceled';
|
|
4
|
+
export interface PortfolioClient {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
contact: string;
|
|
8
|
+
sector: string;
|
|
9
|
+
}
|
|
10
|
+
export interface PortfolioWebsite {
|
|
11
|
+
id: string;
|
|
12
|
+
clientId: string;
|
|
13
|
+
name: string;
|
|
14
|
+
origin: string;
|
|
15
|
+
initials: string;
|
|
16
|
+
color: string;
|
|
17
|
+
connection: 'healthy' | 'unavailable' | 'not_configured';
|
|
18
|
+
lastSuccess: string | null;
|
|
19
|
+
rows: AnalyticsRow[];
|
|
20
|
+
previousRows: AnalyticsRow[];
|
|
21
|
+
source?: 'synthetic' | 'connected' | 'not-connected';
|
|
22
|
+
message?: string;
|
|
23
|
+
windows?: Partial<Record<'14' | '30', AnalyticsResponse>>;
|
|
24
|
+
/** Verified collector activation, independent of padded/reporting-window rows. */
|
|
25
|
+
trackingStartedAt?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface PortfolioChange {
|
|
28
|
+
id: string;
|
|
29
|
+
websiteId: string;
|
|
30
|
+
title: string;
|
|
31
|
+
request: string;
|
|
32
|
+
status: PortfolioStatus;
|
|
33
|
+
candidate: string | null;
|
|
34
|
+
createdAt: string;
|
|
35
|
+
updatedAt: string;
|
|
36
|
+
idempotencyKey: string;
|
|
37
|
+
history: {
|
|
38
|
+
label: string;
|
|
39
|
+
at: string;
|
|
40
|
+
}[];
|
|
41
|
+
checks: {
|
|
42
|
+
label: string;
|
|
43
|
+
result: 'simulated' | 'failed';
|
|
44
|
+
}[];
|
|
45
|
+
receipt: {
|
|
46
|
+
id: string;
|
|
47
|
+
candidate: string;
|
|
48
|
+
publishedAt: string;
|
|
49
|
+
simulated: true;
|
|
50
|
+
} | null;
|
|
51
|
+
}
|
|
52
|
+
export interface PortfolioState {
|
|
53
|
+
clients: PortfolioClient[];
|
|
54
|
+
websites: PortfolioWebsite[];
|
|
55
|
+
changes: PortfolioChange[];
|
|
56
|
+
runnerOnline: boolean;
|
|
57
|
+
}
|
|
58
|
+
export interface PortfolioResponse extends PortfolioState {
|
|
59
|
+
revision: number;
|
|
60
|
+
simulated: true;
|
|
61
|
+
analyticsMode?: 'live';
|
|
62
|
+
}
|
|
63
|
+
export type PortfolioAction = 'start' | 'prepare' | 'fail' | 'retry' | 'cancel' | 'queue' | 'publish';
|
|
64
|
+
export declare function isTrackingTimestamp(value: unknown): value is string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// packages/contracts/src/client-portfolio.ts
|
|
2
|
+
var clientPortfolioPermissions = ["clients:read", "client-changes:request", "client-releases:publish"];
|
|
3
|
+
function isTrackingTimestamp(value) {
|
|
4
|
+
return typeof value === "string" && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/.test(value) && Number.isFinite(Date.parse(value)) && new Date(value).toISOString() === value;
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
clientPortfolioPermissions,
|
|
8
|
+
isTrackingTimestamp
|
|
9
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
export * from './billing.js';
|
|
2
|
+
export * from './stripe-billing.js';
|
|
3
|
+
export * from './client-portfolio.js';
|
|
4
|
+
export * from './client-onboarding.js';
|
|
5
|
+
export * from './scheduling.js';
|
|
1
6
|
export declare const contractVersion = 1;
|
|
2
7
|
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"];
|
|
8
|
+
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"];
|
|
4
9
|
export type Permission = typeof permissions[number];
|
|
5
10
|
export type Role = 'owner' | 'administrator' | 'editor' | 'analyst';
|
|
6
11
|
export declare const roles: Record<Role, readonly Permission[]>;
|
|
@@ -24,14 +29,171 @@ export interface AdminManifest {
|
|
|
24
29
|
origin: string;
|
|
25
30
|
tenantId: string;
|
|
26
31
|
};
|
|
32
|
+
theme?: WebsiteTheme;
|
|
27
33
|
}
|
|
34
|
+
export declare const websiteColorKeys: readonly ["colorBg", "colorText", "colorMuted", "colorAccent", "colorAccentText", "colorSurface", "colorSurface2", "colorBorder", "colorFocus"];
|
|
35
|
+
export type WebsiteTheme = Partial<Record<typeof websiteColorKeys[number], string>>;
|
|
36
|
+
export declare function isThemeColor(value: unknown): value is string;
|
|
37
|
+
export declare function isWebsiteTheme(value: unknown): value is WebsiteTheme;
|
|
28
38
|
export interface ModuleDefinition {
|
|
39
|
+
ui?: 'stripe-billing' | 'stripe-account';
|
|
29
40
|
id: string;
|
|
30
41
|
version: number;
|
|
31
42
|
label: string;
|
|
32
43
|
permission: Permission;
|
|
33
44
|
description: string;
|
|
34
45
|
}
|
|
46
|
+
export interface User {
|
|
47
|
+
id: string;
|
|
48
|
+
email: string;
|
|
49
|
+
role: Role;
|
|
50
|
+
}
|
|
51
|
+
export interface BootstrapResponse {
|
|
52
|
+
manifest: AdminManifest;
|
|
53
|
+
user: User | null;
|
|
54
|
+
passwordLogin: boolean;
|
|
55
|
+
localDemo: boolean;
|
|
56
|
+
connected: boolean;
|
|
57
|
+
modules: ModuleDefinition[];
|
|
58
|
+
capabilities: string[];
|
|
59
|
+
theme?: WebsiteTheme | null;
|
|
60
|
+
themeStatus?: 'website' | 'installation' | 'unavailable' | 'default';
|
|
61
|
+
accountAuth?: AccountCapabilities;
|
|
62
|
+
emailLoginConfigured?: boolean;
|
|
63
|
+
privateLocalSignIn?: boolean;
|
|
64
|
+
}
|
|
65
|
+
export type DataSource = 'synthetic' | 'connected' | 'not-connected';
|
|
66
|
+
export interface LeadRow {
|
|
67
|
+
id: string;
|
|
68
|
+
name: string;
|
|
69
|
+
email: string;
|
|
70
|
+
message: string;
|
|
71
|
+
status: string;
|
|
72
|
+
created_at: string;
|
|
73
|
+
source?: string | null;
|
|
74
|
+
phone?: string | null;
|
|
75
|
+
fields_json?: string | null;
|
|
76
|
+
notification_policy?: string | null;
|
|
77
|
+
notification_status?: string | null;
|
|
78
|
+
notification_error?: string | null;
|
|
79
|
+
followUp?: LeadFollowUp;
|
|
80
|
+
}
|
|
81
|
+
export interface LeadFollowUp {
|
|
82
|
+
assignedTo: string | null;
|
|
83
|
+
dueDate: string | null;
|
|
84
|
+
notes: string;
|
|
85
|
+
completed: boolean;
|
|
86
|
+
revision: number;
|
|
87
|
+
updatedAt: string | null;
|
|
88
|
+
}
|
|
89
|
+
export interface LeadPagination {
|
|
90
|
+
version: 1;
|
|
91
|
+
total: number;
|
|
92
|
+
newCount: number;
|
|
93
|
+
nextCursor: string | null;
|
|
94
|
+
}
|
|
95
|
+
export interface LeadTeamMember {
|
|
96
|
+
id: string;
|
|
97
|
+
email: string;
|
|
98
|
+
}
|
|
99
|
+
export declare function isLeadFollowUp(value: unknown): value is LeadFollowUp;
|
|
100
|
+
export declare function isLeadPagination(value: unknown): value is LeadPagination;
|
|
101
|
+
export declare const analyticsMetricKeys: readonly ["sessions", "bounces", "engaged", "duration_ms", "leave_count", "scroll_25", "scroll_50", "scroll_75", "scroll_100", "converts_form", "converts_tel", "converts_mailto", "converts_maps", "engage_nav", "engage_btn", "engage_img", "engage_carousel"];
|
|
102
|
+
export declare const analyticsBreakdownKeys: readonly ["top_paths_json", "top_refs_json", "channels_json", "devices_json", "hours_json", "top_engage_json"];
|
|
103
|
+
export type AnalyticsMetric = 'views' | 'visitors' | 'enquiries' | typeof analyticsMetricKeys[number];
|
|
104
|
+
export type AnalyticsBreakdown = typeof analyticsBreakdownKeys[number];
|
|
105
|
+
export interface AnalyticsItem {
|
|
106
|
+
key: string;
|
|
107
|
+
n: number;
|
|
108
|
+
}
|
|
109
|
+
export type AnalyticsRow = {
|
|
110
|
+
day: string;
|
|
111
|
+
views: number;
|
|
112
|
+
visitors: number;
|
|
113
|
+
enquiries: number;
|
|
114
|
+
} & Partial<Record<typeof analyticsMetricKeys[number], number>> & Partial<Record<AnalyticsBreakdown, string>>;
|
|
115
|
+
export interface LeadsResponse {
|
|
116
|
+
rows: LeadRow[];
|
|
117
|
+
source: DataSource;
|
|
118
|
+
writable?: boolean;
|
|
119
|
+
message?: string;
|
|
120
|
+
mode?: string;
|
|
121
|
+
followUpsEnabled?: boolean;
|
|
122
|
+
pagination?: LeadPagination;
|
|
123
|
+
truncated?: boolean;
|
|
124
|
+
}
|
|
125
|
+
export interface AnalyticsResponse {
|
|
126
|
+
rows: AnalyticsRow[];
|
|
127
|
+
previousRows?: AnalyticsRow[];
|
|
128
|
+
source: DataSource;
|
|
129
|
+
timezone: string;
|
|
130
|
+
days: number;
|
|
131
|
+
generatedAt?: string;
|
|
132
|
+
}
|
|
133
|
+
export interface SettingsResponse {
|
|
134
|
+
notification_email: string;
|
|
135
|
+
revision: number;
|
|
136
|
+
}
|
|
137
|
+
export interface AccessRow extends User {
|
|
138
|
+
active: number;
|
|
139
|
+
}
|
|
140
|
+
export interface AccountCapabilities {
|
|
141
|
+
enabled: boolean;
|
|
142
|
+
emailReady: boolean;
|
|
143
|
+
setupAvailable: boolean;
|
|
144
|
+
emailVerified: boolean;
|
|
145
|
+
canInvite: boolean;
|
|
146
|
+
}
|
|
147
|
+
export interface AccountAction {
|
|
148
|
+
purpose: 'owner' | 'invite' | 'verify' | 'reset';
|
|
149
|
+
email: string;
|
|
150
|
+
expiresAt: number;
|
|
151
|
+
business: string;
|
|
152
|
+
}
|
|
153
|
+
export interface TeamInvitation {
|
|
154
|
+
id: string;
|
|
155
|
+
email: string;
|
|
156
|
+
role: string;
|
|
157
|
+
expiresAt: number;
|
|
158
|
+
status: 'accepted' | 'canceled' | 'expired' | 'pending';
|
|
159
|
+
delivery: 'pending' | 'sending' | 'sent' | 'failed' | 'superseded';
|
|
160
|
+
}
|
|
161
|
+
export interface AccessResponse extends RowsResponse<AccessRow & {
|
|
162
|
+
email_verified_at?: number | null;
|
|
163
|
+
}> {
|
|
164
|
+
invitations?: TeamInvitation[];
|
|
165
|
+
accountAuth?: AccountCapabilities;
|
|
166
|
+
}
|
|
167
|
+
export interface ActivityRow {
|
|
168
|
+
id: string;
|
|
169
|
+
actor: string;
|
|
170
|
+
action: string;
|
|
171
|
+
created_at: string;
|
|
172
|
+
}
|
|
173
|
+
export interface TaskRow {
|
|
174
|
+
id: string;
|
|
175
|
+
title: string;
|
|
176
|
+
done: number;
|
|
177
|
+
}
|
|
178
|
+
export interface RowsResponse<T> {
|
|
179
|
+
rows: T[];
|
|
180
|
+
message?: string;
|
|
181
|
+
}
|
|
182
|
+
export interface ModuleRow {
|
|
183
|
+
id?: string;
|
|
184
|
+
title?: string;
|
|
185
|
+
name?: string;
|
|
186
|
+
}
|
|
187
|
+
export interface MutationResponse {
|
|
188
|
+
ok: true;
|
|
189
|
+
}
|
|
190
|
+
export interface AuthRequestResponse {
|
|
191
|
+
ok: true;
|
|
192
|
+
message: string;
|
|
193
|
+
}
|
|
194
|
+
export declare function isObject(value: unknown): value is Record<string, unknown>;
|
|
195
|
+
export declare function isLeadRow(value: unknown): value is LeadRow;
|
|
196
|
+
export declare function isAnalyticsRow(value: unknown): value is AnalyticsRow;
|
|
35
197
|
export declare const workQueueModule: ModuleDefinition;
|
|
36
198
|
export declare function isLoopback(origin: string): boolean;
|
|
37
199
|
export declare function parseManifest(value: unknown): AdminManifest;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,72 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { schedulingPermissions } from "./scheduling.js";
|
|
2
|
+
import { clientPortfolioPermissions } from "./client-portfolio.js";
|
|
3
|
+
import { clientOnboardingPermissions } from "./client-onboarding.js";
|
|
4
|
+
import { billingPermissions } from "./billing.js";
|
|
5
|
+
export * from "./billing.js";
|
|
6
|
+
export * from "./stripe-billing.js";
|
|
7
|
+
export * from "./client-portfolio.js";
|
|
8
|
+
export * from "./client-onboarding.js";
|
|
9
|
+
export * from "./scheduling.js";
|
|
10
|
+
const contractVersion = 1;
|
|
11
|
+
const coreSections = ["overview", "leads", "analytics", "settings", "access", "activity"];
|
|
12
|
+
const permissions = ["leads:read", "leads:write", "analytics:read", "settings:write", "access:read", "access:write", "activity:read", "tasks:read", "tasks:write", ...schedulingPermissions, ...clientPortfolioPermissions, ...clientOnboardingPermissions, ...billingPermissions];
|
|
13
|
+
const roles = {
|
|
6
14
|
owner: permissions,
|
|
7
|
-
administrator: permissions,
|
|
15
|
+
administrator: permissions.filter((p) => p !== "access:write" && !clientPortfolioPermissions.includes(p) && !clientOnboardingPermissions.includes(p) && !billingPermissions.includes(p)),
|
|
8
16
|
editor: ["leads:read", "leads:write", "activity:read", "tasks:read", "tasks:write"],
|
|
9
17
|
analyst: ["analytics:read", "activity:read"]
|
|
10
18
|
};
|
|
11
19
|
function can(role, permission) {
|
|
12
20
|
return roles[role]?.includes(permission) ?? false;
|
|
13
21
|
}
|
|
14
|
-
|
|
22
|
+
const websiteColorKeys = ["colorBg", "colorText", "colorMuted", "colorAccent", "colorAccentText", "colorSurface", "colorSurface2", "colorBorder", "colorFocus"];
|
|
23
|
+
function isThemeColor(value) {
|
|
24
|
+
if (typeof value !== "string" || value.length > 100) return false;
|
|
25
|
+
if (/^#(?:[\da-f]{3}|[\da-f]{4}|[\da-f]{6}|[\da-f]{8})$/i.test(value)) return true;
|
|
26
|
+
const match = value.match(/^(rgb|rgba|hsl|hsla)\(([^()]+)\)$/i);
|
|
27
|
+
if (!match) return false;
|
|
28
|
+
const parts = match[2].trim().split(/[\s,/]+/);
|
|
29
|
+
if (parts.length < 3 || parts.length > 4) return false;
|
|
30
|
+
const numeric = (part, max) => /^\d+(?:\.\d+)?%?$/.test(part) && parseFloat(part) >= 0 && parseFloat(part) <= (part.endsWith("%") ? 100 : max);
|
|
31
|
+
const components = match[1].toLowerCase().startsWith("rgb") ? parts.slice(0, 3).every((p) => numeric(p, 255)) : /^[+-]?\d+(?:\.\d+)?(?:deg)?$/.test(parts[0]) && parts.slice(1, 3).every((p) => p.endsWith("%") && numeric(p, 100));
|
|
32
|
+
return components && (parts.length === 3 || numeric(parts[3], 1));
|
|
33
|
+
}
|
|
34
|
+
function isWebsiteTheme(value) {
|
|
35
|
+
return isObject(value) && Object.keys(value).length > 0 && Object.entries(value).every(([key, color]) => websiteColorKeys.includes(key) && isThemeColor(color));
|
|
36
|
+
}
|
|
37
|
+
function isLeadFollowUp(value) {
|
|
38
|
+
if (!isObject(value)) return false;
|
|
39
|
+
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");
|
|
40
|
+
}
|
|
41
|
+
function isLeadPagination(value) {
|
|
42
|
+
return isObject(value) && value.version === 1 && [value.total, value.newCount].every((n) => Number.isSafeInteger(n) && Number(n) >= 0) && (value.nextCursor === null || typeof value.nextCursor === "string" && value.nextCursor.length <= 4096);
|
|
43
|
+
}
|
|
44
|
+
const analyticsMetricKeys = ["sessions", "bounces", "engaged", "duration_ms", "leave_count", "scroll_25", "scroll_50", "scroll_75", "scroll_100", "converts_form", "converts_tel", "converts_mailto", "converts_maps", "engage_nav", "engage_btn", "engage_img", "engage_carousel"];
|
|
45
|
+
const analyticsBreakdownKeys = ["top_paths_json", "top_refs_json", "channels_json", "devices_json", "hours_json", "top_engage_json"];
|
|
46
|
+
function isObject(value) {
|
|
47
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
48
|
+
}
|
|
49
|
+
function isLeadRow(value) {
|
|
50
|
+
if (!isObject(value)) return false;
|
|
51
|
+
return ["id", "name", "email", "message", "status", "created_at"].every((key) => typeof value[key] === "string") && ["source", "phone", "fields_json", "notification_policy", "notification_status", "notification_error"].every((key) => value[key] === void 0 || value[key] === null || typeof value[key] === "string") && (value.followUp === void 0 || isLeadFollowUp(value.followUp));
|
|
52
|
+
}
|
|
53
|
+
function isAnalyticsRow(value) {
|
|
54
|
+
if (!isObject(value) || typeof value.day !== "string" || !/^\d{4}-\d{2}-\d{2}$/.test(value.day)) return false;
|
|
55
|
+
const count = (n) => typeof n === "number" && Number.isSafeInteger(n) && n >= 0;
|
|
56
|
+
if (!["views", "visitors", "enquiries"].every((key) => count(value[key])) || !analyticsMetricKeys.every((key) => value[key] === void 0 || count(value[key]))) return false;
|
|
57
|
+
return analyticsBreakdownKeys.every((key) => {
|
|
58
|
+
const raw = value[key];
|
|
59
|
+
if (raw === void 0) return true;
|
|
60
|
+
if (typeof raw !== "string" || raw.length > 1e5) return false;
|
|
61
|
+
try {
|
|
62
|
+
const items = JSON.parse(raw);
|
|
63
|
+
return Array.isArray(items) && items.length <= 200 && items.every((item) => isObject(item) && typeof item.key === "string" && item.key.length <= 300 && count(item.n) && (key !== "hours_json" || /^(?:[0-9]|1[0-9]|2[0-3])$/.test(item.key)));
|
|
64
|
+
} catch {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const workQueueModule = {
|
|
15
70
|
id: "work-queue",
|
|
16
71
|
version: 1,
|
|
17
72
|
label: "Work queue",
|
|
@@ -49,6 +104,7 @@ function parseManifest(value) {
|
|
|
49
104
|
if (!Array.isArray(v.modules) || v.modules.length > 20) throw new Error("Invalid modules");
|
|
50
105
|
const modules = v.modules.map((x) => id(x, "module ID"));
|
|
51
106
|
if (new Set(modules).size !== modules.length) throw new Error("Duplicate module");
|
|
107
|
+
if (v.theme !== void 0 && !isWebsiteTheme(v.theme)) throw new Error("Invalid website theme colors");
|
|
52
108
|
let backend;
|
|
53
109
|
if (v.backend !== void 0) {
|
|
54
110
|
const b = object(v.backend);
|
|
@@ -65,7 +121,8 @@ function parseManifest(value) {
|
|
|
65
121
|
site: { id: id(site.id, "site ID"), name: text(site.name, "site name"), origin: origin(site.origin, "website origin") },
|
|
66
122
|
adminOrigin: origin(v.adminOrigin, "admin origin"),
|
|
67
123
|
modules,
|
|
68
|
-
...backend ? { backend } : {}
|
|
124
|
+
...backend ? { backend } : {},
|
|
125
|
+
...v.theme ? { theme: v.theme } : {}
|
|
69
126
|
};
|
|
70
127
|
}
|
|
71
128
|
function validateModules(manifest, modules) {
|
|
@@ -79,13 +136,23 @@ function validateModules(manifest, modules) {
|
|
|
79
136
|
for (const enabled of manifest.modules) if (!ids.has(enabled)) throw new Error(`Module ${enabled} is not installed`);
|
|
80
137
|
}
|
|
81
138
|
export {
|
|
139
|
+
analyticsBreakdownKeys,
|
|
140
|
+
analyticsMetricKeys,
|
|
82
141
|
can,
|
|
83
142
|
contractVersion,
|
|
84
143
|
coreSections,
|
|
144
|
+
isAnalyticsRow,
|
|
145
|
+
isLeadFollowUp,
|
|
146
|
+
isLeadPagination,
|
|
147
|
+
isLeadRow,
|
|
85
148
|
isLoopback,
|
|
149
|
+
isObject,
|
|
150
|
+
isThemeColor,
|
|
151
|
+
isWebsiteTheme,
|
|
86
152
|
parseManifest,
|
|
87
153
|
permissions,
|
|
88
154
|
roles,
|
|
89
155
|
validateModules,
|
|
156
|
+
websiteColorKeys,
|
|
90
157
|
workQueueModule
|
|
91
158
|
};
|