@smartcrab/contracts-management 0.2.0 → 0.2.1-next-20261009084044
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/dist/domains.d.ts +19 -1
- package/dist/domains.js +19 -3
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/quotas.d.ts +13 -0
- package/dist/quotas.js +13 -0
- package/package.json +2 -2
- package/src/domains.test.ts +47 -0
- package/src/domains.ts +28 -3
- package/src/index.ts +1 -0
- package/src/quotas.ts +13 -0
package/dist/domains.d.ts
CHANGED
|
@@ -29,6 +29,9 @@ export declare const domainSchema: z.ZodObject<{
|
|
|
29
29
|
moved: "moved";
|
|
30
30
|
deleting: "deleting";
|
|
31
31
|
}>;
|
|
32
|
+
ownership_verified: z.ZodBoolean;
|
|
33
|
+
verification_record_name: z.ZodNullable<z.ZodString>;
|
|
34
|
+
verification_record_value: z.ZodNullable<z.ZodString>;
|
|
32
35
|
rp_enabled: z.ZodBoolean;
|
|
33
36
|
validation_errors: z.ZodArray<z.ZodString>;
|
|
34
37
|
created_at: z.ZodISODateTime;
|
|
@@ -61,6 +64,9 @@ export declare const domainListResponseSchema: z.ZodObject<{
|
|
|
61
64
|
moved: "moved";
|
|
62
65
|
deleting: "deleting";
|
|
63
66
|
}>;
|
|
67
|
+
ownership_verified: z.ZodBoolean;
|
|
68
|
+
verification_record_name: z.ZodNullable<z.ZodString>;
|
|
69
|
+
verification_record_value: z.ZodNullable<z.ZodString>;
|
|
64
70
|
rp_enabled: z.ZodBoolean;
|
|
65
71
|
validation_errors: z.ZodArray<z.ZodString>;
|
|
66
72
|
created_at: z.ZodISODateTime;
|
|
@@ -88,6 +94,9 @@ export declare const domainCreateResponseSchema: z.ZodObject<{
|
|
|
88
94
|
moved: "moved";
|
|
89
95
|
deleting: "deleting";
|
|
90
96
|
}>;
|
|
97
|
+
ownership_verified: z.ZodBoolean;
|
|
98
|
+
verification_record_name: z.ZodNullable<z.ZodString>;
|
|
99
|
+
verification_record_value: z.ZodNullable<z.ZodString>;
|
|
91
100
|
rp_enabled: z.ZodBoolean;
|
|
92
101
|
validation_errors: z.ZodArray<z.ZodString>;
|
|
93
102
|
created_at: z.ZodISODateTime;
|
|
@@ -106,6 +115,9 @@ export declare const domainGetResponseSchema: z.ZodObject<{
|
|
|
106
115
|
moved: "moved";
|
|
107
116
|
deleting: "deleting";
|
|
108
117
|
}>;
|
|
118
|
+
ownership_verified: z.ZodBoolean;
|
|
119
|
+
verification_record_name: z.ZodNullable<z.ZodString>;
|
|
120
|
+
verification_record_value: z.ZodNullable<z.ZodString>;
|
|
109
121
|
rp_enabled: z.ZodBoolean;
|
|
110
122
|
validation_errors: z.ZodArray<z.ZodString>;
|
|
111
123
|
created_at: z.ZodISODateTime;
|
|
@@ -137,6 +149,9 @@ export declare const domainUpdateResponseSchema: z.ZodObject<{
|
|
|
137
149
|
moved: "moved";
|
|
138
150
|
deleting: "deleting";
|
|
139
151
|
}>;
|
|
152
|
+
ownership_verified: z.ZodBoolean;
|
|
153
|
+
verification_record_name: z.ZodNullable<z.ZodString>;
|
|
154
|
+
verification_record_value: z.ZodNullable<z.ZodString>;
|
|
140
155
|
rp_enabled: z.ZodBoolean;
|
|
141
156
|
validation_errors: z.ZodArray<z.ZodString>;
|
|
142
157
|
created_at: z.ZodISODateTime;
|
|
@@ -146,7 +161,7 @@ export declare const domainUpdateResponseSchema: z.ZodObject<{
|
|
|
146
161
|
export type DomainUpdateResponse = z.infer<typeof domainUpdateResponseSchema>;
|
|
147
162
|
export declare const domainRetryValidationRequestSchema: z.ZodObject<{}, z.core.$strict>;
|
|
148
163
|
export type DomainRetryValidationRequest = z.infer<typeof domainRetryValidationRequestSchema>;
|
|
149
|
-
/**
|
|
164
|
+
/** Retries ownership verification when needed, then refreshes Cloudflare SSL state. */
|
|
150
165
|
export declare const domainRetryValidationResponseSchema: z.ZodObject<{
|
|
151
166
|
id: z.ZodString;
|
|
152
167
|
environment_id: z.ZodString;
|
|
@@ -158,6 +173,9 @@ export declare const domainRetryValidationResponseSchema: z.ZodObject<{
|
|
|
158
173
|
moved: "moved";
|
|
159
174
|
deleting: "deleting";
|
|
160
175
|
}>;
|
|
176
|
+
ownership_verified: z.ZodBoolean;
|
|
177
|
+
verification_record_name: z.ZodNullable<z.ZodString>;
|
|
178
|
+
verification_record_value: z.ZodNullable<z.ZodString>;
|
|
161
179
|
rp_enabled: z.ZodBoolean;
|
|
162
180
|
validation_errors: z.ZodArray<z.ZodString>;
|
|
163
181
|
created_at: z.ZodISODateTime;
|
package/dist/domains.js
CHANGED
|
@@ -11,14 +11,30 @@ import { domainIdSchema, environmentIdSchema } from "./primitives.js";
|
|
|
11
11
|
*/
|
|
12
12
|
export const CUSTOM_DOMAIN_STATUSES = ["pending", "active", "moved", "failed", "deleting"];
|
|
13
13
|
export const customDomainStatusSchema = z.enum(CUSTOM_DOMAIN_STATUSES);
|
|
14
|
-
const
|
|
14
|
+
const isCustomHostname = (hostname) => {
|
|
15
|
+
const canonicalHostname = hostname.toLowerCase();
|
|
16
|
+
const labels = canonicalHostname.split(".");
|
|
17
|
+
return (canonicalHostname.length <= 253 &&
|
|
18
|
+
labels.length >= 2 &&
|
|
19
|
+
!(labels.length === 4 &&
|
|
20
|
+
labels.every((label) => /^\d{1,3}$/.test(label) && Number(label) <= 255)) &&
|
|
21
|
+
labels.every((label) => label.length >= 1 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label)));
|
|
22
|
+
};
|
|
23
|
+
const customHostnameSchema = z.string().min(1).max(253).refine(isCustomHostname, {
|
|
24
|
+
message: "hostname must be a DNS hostname with at least two LDH labels, each 1-63 characters; wildcards, trailing dots, and IP literals are not allowed",
|
|
25
|
+
});
|
|
15
26
|
/** Canonicalize a custom hostname at an external boundary before persistence or routing. */
|
|
16
27
|
export const canonicalizeCustomHostname = (hostname) => hostname.toLowerCase();
|
|
17
28
|
export const domainSchema = z.strictObject({
|
|
18
29
|
id: domainIdSchema,
|
|
19
30
|
environment_id: environmentIdSchema,
|
|
20
|
-
hostname:
|
|
31
|
+
hostname: z.string().min(1).max(253),
|
|
21
32
|
status: customDomainStatusSchema,
|
|
33
|
+
/** Whether the domain owner has published the TXT challenge value. */
|
|
34
|
+
ownership_verified: z.boolean(),
|
|
35
|
+
/** TXT challenge details are null for domains that predate ownership verification. */
|
|
36
|
+
verification_record_name: z.string().nullable(),
|
|
37
|
+
verification_record_value: z.string().nullable(),
|
|
22
38
|
/** design.md §11.9: whether this custom domain also serves as the WebAuthn RP ID host. */
|
|
23
39
|
rp_enabled: z.boolean(),
|
|
24
40
|
validation_errors: z.array(z.string().min(1)),
|
|
@@ -70,5 +86,5 @@ export const domainUpdateResponseSchema = domainSchema;
|
|
|
70
86
|
// POST /domains/:domainId/retry-validation
|
|
71
87
|
// ---------------------------------------------------------------------------
|
|
72
88
|
export const domainRetryValidationRequestSchema = z.strictObject({});
|
|
73
|
-
/**
|
|
89
|
+
/** Retries ownership verification when needed, then refreshes Cloudflare SSL state. */
|
|
74
90
|
export const domainRetryValidationResponseSchema = domainSchema;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/quotas.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Self-serve resource limits enforced by control-worker (design.md §28.7). */
|
|
2
|
+
export declare const MANAGEMENT_RESOURCE_QUOTAS: {
|
|
3
|
+
readonly workspacesPerUser: 5;
|
|
4
|
+
readonly projectsPerWorkspace: 20;
|
|
5
|
+
readonly environmentsPerProject: 10;
|
|
6
|
+
readonly clientsPerEnvironment: 50;
|
|
7
|
+
readonly connectionsPerEnvironment: 20;
|
|
8
|
+
readonly webhooksPerEnvironment: 20;
|
|
9
|
+
readonly activeApiKeysPerWorkspace: 50;
|
|
10
|
+
readonly customDomainsPerEnvironment: 5;
|
|
11
|
+
readonly customDomainsPerWorkspace: 10;
|
|
12
|
+
readonly provisionedCustomHostnamesPerCell: 900;
|
|
13
|
+
};
|
package/dist/quotas.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Self-serve resource limits enforced by control-worker (design.md §28.7). */
|
|
2
|
+
export const MANAGEMENT_RESOURCE_QUOTAS = {
|
|
3
|
+
workspacesPerUser: 5,
|
|
4
|
+
projectsPerWorkspace: 20,
|
|
5
|
+
environmentsPerProject: 10,
|
|
6
|
+
clientsPerEnvironment: 50,
|
|
7
|
+
connectionsPerEnvironment: 20,
|
|
8
|
+
webhooksPerEnvironment: 20,
|
|
9
|
+
activeApiKeysPerWorkspace: 50,
|
|
10
|
+
customDomainsPerEnvironment: 5,
|
|
11
|
+
customDomainsPerWorkspace: 10,
|
|
12
|
+
provisionedCustomHostnamesPerCell: 900,
|
|
13
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartcrab/contracts-management",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1-next-20261009084044",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"zod": "4.4.3",
|
|
31
|
-
"@smartcrab/contracts-public": "0.2.
|
|
31
|
+
"@smartcrab/contracts-public": "0.2.1-next-20261009084044"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"typescript": "5.9.3",
|
package/src/domains.test.ts
CHANGED
|
@@ -6,6 +6,9 @@ const VALID_DOMAIN = {
|
|
|
6
6
|
environment_id: `env_${"a".repeat(32)}`,
|
|
7
7
|
hostname: "login.customer.example",
|
|
8
8
|
status: "pending",
|
|
9
|
+
ownership_verified: false,
|
|
10
|
+
verification_record_name: "_zeroword-challenge.login.customer.example",
|
|
11
|
+
verification_record_value: "97e82b0a-e14a-4cf0-9c82-62c267f26328",
|
|
9
12
|
rp_enabled: true,
|
|
10
13
|
validation_errors: [],
|
|
11
14
|
created_at: "2026-08-02T08:10:00Z",
|
|
@@ -18,6 +21,28 @@ describe("domainSchema (design.md §11.9)", () => {
|
|
|
18
21
|
expect(domainSchema.safeParse(VALID_DOMAIN).success).toBe(true);
|
|
19
22
|
});
|
|
20
23
|
|
|
24
|
+
test("accepts previously provisioned domains without a TXT challenge", () => {
|
|
25
|
+
expect(
|
|
26
|
+
domainSchema.safeParse({
|
|
27
|
+
...VALID_DOMAIN,
|
|
28
|
+
ownership_verified: true,
|
|
29
|
+
verification_record_name: null,
|
|
30
|
+
verification_record_value: null,
|
|
31
|
+
}).success,
|
|
32
|
+
).toBe(true);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test("accepts legacy hostnames in responses but rejects them as input", () => {
|
|
36
|
+
const hostname = "legacy_host.customer.example.";
|
|
37
|
+
expect(domainSchema.safeParse({ ...VALID_DOMAIN, hostname }).success).toBe(true);
|
|
38
|
+
expect(
|
|
39
|
+
domainCreateRequestSchema.safeParse({
|
|
40
|
+
environment_id: VALID_DOMAIN.environment_id,
|
|
41
|
+
hostname,
|
|
42
|
+
}).success,
|
|
43
|
+
).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
21
46
|
test("rejects an unknown top-level key (e.g. leaking cloudflare_custom_hostname_id)", () => {
|
|
22
47
|
expect(
|
|
23
48
|
domainSchema.safeParse({ ...VALID_DOMAIN, cloudflare_custom_hostname_id: "ch_123" }).success,
|
|
@@ -45,4 +70,26 @@ describe("domainCreateRequestSchema", () => {
|
|
|
45
70
|
});
|
|
46
71
|
expect(canonicalizeCustomHostname(parsed.hostname)).toBe("login.customer.example");
|
|
47
72
|
});
|
|
73
|
+
|
|
74
|
+
test("rejects values that are not DNS hostnames", () => {
|
|
75
|
+
for (const hostname of [
|
|
76
|
+
"localhost",
|
|
77
|
+
"*.customer.example",
|
|
78
|
+
"customer.example.",
|
|
79
|
+
"bad..customer.example",
|
|
80
|
+
"-bad.customer.example",
|
|
81
|
+
"bad-.customer.example",
|
|
82
|
+
`${"a".repeat(64)}.customer.example`,
|
|
83
|
+
"127.0.0.1",
|
|
84
|
+
"001.002.003.004",
|
|
85
|
+
"[::1]",
|
|
86
|
+
]) {
|
|
87
|
+
expect(
|
|
88
|
+
domainCreateRequestSchema.safeParse({
|
|
89
|
+
environment_id: VALID_DOMAIN.environment_id,
|
|
90
|
+
hostname,
|
|
91
|
+
}).success,
|
|
92
|
+
).toBe(false);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
48
95
|
});
|
package/src/domains.ts
CHANGED
|
@@ -14,7 +14,27 @@ export const CUSTOM_DOMAIN_STATUSES = ["pending", "active", "moved", "failed", "
|
|
|
14
14
|
export const customDomainStatusSchema = z.enum(CUSTOM_DOMAIN_STATUSES);
|
|
15
15
|
export type CustomDomainStatus = (typeof CUSTOM_DOMAIN_STATUSES)[number];
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const isCustomHostname = (hostname: string): boolean => {
|
|
18
|
+
const canonicalHostname = hostname.toLowerCase();
|
|
19
|
+
const labels = canonicalHostname.split(".");
|
|
20
|
+
return (
|
|
21
|
+
canonicalHostname.length <= 253 &&
|
|
22
|
+
labels.length >= 2 &&
|
|
23
|
+
!(
|
|
24
|
+
labels.length === 4 &&
|
|
25
|
+
labels.every((label) => /^\d{1,3}$/.test(label) && Number(label) <= 255)
|
|
26
|
+
) &&
|
|
27
|
+
labels.every(
|
|
28
|
+
(label) =>
|
|
29
|
+
label.length >= 1 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/.test(label),
|
|
30
|
+
)
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const customHostnameSchema = z.string().min(1).max(253).refine(isCustomHostname, {
|
|
35
|
+
message:
|
|
36
|
+
"hostname must be a DNS hostname with at least two LDH labels, each 1-63 characters; wildcards, trailing dots, and IP literals are not allowed",
|
|
37
|
+
});
|
|
18
38
|
|
|
19
39
|
/** Canonicalize a custom hostname at an external boundary before persistence or routing. */
|
|
20
40
|
export const canonicalizeCustomHostname = (hostname: string): string => hostname.toLowerCase();
|
|
@@ -22,8 +42,13 @@ export const canonicalizeCustomHostname = (hostname: string): string => hostname
|
|
|
22
42
|
export const domainSchema = z.strictObject({
|
|
23
43
|
id: domainIdSchema,
|
|
24
44
|
environment_id: environmentIdSchema,
|
|
25
|
-
hostname:
|
|
45
|
+
hostname: z.string().min(1).max(253),
|
|
26
46
|
status: customDomainStatusSchema,
|
|
47
|
+
/** Whether the domain owner has published the TXT challenge value. */
|
|
48
|
+
ownership_verified: z.boolean(),
|
|
49
|
+
/** TXT challenge details are null for domains that predate ownership verification. */
|
|
50
|
+
verification_record_name: z.string().nullable(),
|
|
51
|
+
verification_record_value: z.string().nullable(),
|
|
27
52
|
/** design.md §11.9: whether this custom domain also serves as the WebAuthn RP ID host. */
|
|
28
53
|
rp_enabled: z.boolean(),
|
|
29
54
|
validation_errors: z.array(z.string().min(1)),
|
|
@@ -99,6 +124,6 @@ export type DomainUpdateResponse = z.infer<typeof domainUpdateResponseSchema>;
|
|
|
99
124
|
export const domainRetryValidationRequestSchema = z.strictObject({});
|
|
100
125
|
export type DomainRetryValidationRequest = z.infer<typeof domainRetryValidationRequestSchema>;
|
|
101
126
|
|
|
102
|
-
/**
|
|
127
|
+
/** Retries ownership verification when needed, then refreshes Cloudflare SSL state. */
|
|
103
128
|
export const domainRetryValidationResponseSchema = domainSchema;
|
|
104
129
|
export type DomainRetryValidationResponse = z.infer<typeof domainRetryValidationResponseSchema>;
|
package/src/index.ts
CHANGED
package/src/quotas.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Self-serve resource limits enforced by control-worker (design.md §28.7). */
|
|
2
|
+
export const MANAGEMENT_RESOURCE_QUOTAS = {
|
|
3
|
+
workspacesPerUser: 5,
|
|
4
|
+
projectsPerWorkspace: 20,
|
|
5
|
+
environmentsPerProject: 10,
|
|
6
|
+
clientsPerEnvironment: 50,
|
|
7
|
+
connectionsPerEnvironment: 20,
|
|
8
|
+
webhooksPerEnvironment: 20,
|
|
9
|
+
activeApiKeysPerWorkspace: 50,
|
|
10
|
+
customDomainsPerEnvironment: 5,
|
|
11
|
+
customDomainsPerWorkspace: 10,
|
|
12
|
+
provisionedCustomHostnamesPerCell: 900,
|
|
13
|
+
} as const;
|