@smartcrab/contracts-management 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/LICENSE +202 -0
- package/dist/api-keys.d.ts +251 -0
- package/dist/api-keys.js +78 -0
- package/dist/audit-events.d.ts +94 -0
- package/dist/audit-events.js +45 -0
- package/dist/billing.d.ts +30 -0
- package/dist/billing.js +30 -0
- package/dist/clients.d.ts +328 -0
- package/dist/clients.js +141 -0
- package/dist/common.d.ts +95 -0
- package/dist/common.js +99 -0
- package/dist/connections.d.ts +201 -0
- package/dist/connections.js +107 -0
- package/dist/domains.d.ts +167 -0
- package/dist/domains.js +74 -0
- package/dist/environments.d.ts +194 -0
- package/dist/environments.js +101 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +27 -0
- package/dist/primitives.d.ts +49 -0
- package/dist/primitives.js +56 -0
- package/dist/projects.d.ts +78 -0
- package/dist/projects.js +49 -0
- package/dist/rbac.d.ts +222 -0
- package/dist/rbac.js +226 -0
- package/dist/usage.d.ts +72 -0
- package/dist/usage.js +52 -0
- package/dist/user-jobs.d.ts +253 -0
- package/dist/user-jobs.js +95 -0
- package/dist/user-subresources.d.ts +161 -0
- package/dist/user-subresources.js +85 -0
- package/dist/users.d.ts +193 -0
- package/dist/users.js +112 -0
- package/dist/webhooks.d.ts +306 -0
- package/dist/webhooks.js +134 -0
- package/dist/workspaces.d.ts +172 -0
- package/dist/workspaces.js +77 -0
- package/package.json +42 -0
- package/src/api-keys.test.ts +86 -0
- package/src/api-keys.ts +97 -0
- package/src/audit-events.test.ts +44 -0
- package/src/audit-events.ts +57 -0
- package/src/billing.test.ts +57 -0
- package/src/billing.ts +46 -0
- package/src/clients.test.ts +169 -0
- package/src/clients.ts +182 -0
- package/src/common.test.ts +102 -0
- package/src/common.ts +127 -0
- package/src/connections.test.ts +65 -0
- package/src/connections.ts +134 -0
- package/src/domains.test.ts +48 -0
- package/src/domains.ts +104 -0
- package/src/environments.test.ts +67 -0
- package/src/environments.ts +133 -0
- package/src/index.ts +27 -0
- package/src/primitives.ts +100 -0
- package/src/projects.test.ts +49 -0
- package/src/projects.ts +72 -0
- package/src/rbac.test.ts +148 -0
- package/src/rbac.ts +250 -0
- package/src/secret-fields.test.ts +84 -0
- package/src/usage.test.ts +57 -0
- package/src/usage.ts +66 -0
- package/src/user-jobs.test.ts +86 -0
- package/src/user-jobs.ts +120 -0
- package/src/user-subresources.test.ts +115 -0
- package/src/user-subresources.ts +128 -0
- package/src/users.test.ts +91 -0
- package/src/users.ts +149 -0
- package/src/webhooks.test.ts +187 -0
- package/src/webhooks.ts +182 -0
- package/src/workspaces.test.ts +127 -0
- package/src/workspaces.ts +106 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* `environments` (design.md §11.4, §7.3). `auth_routing_version` is excluded
|
|
4
|
+
* as internal multi-cell routing state (design.md §10.6 `AuthLocatorDO`),
|
|
5
|
+
* the same category of field the assignment's "internal routing" exclusion
|
|
6
|
+
* targets alongside the explicitly named secret columns. `config_version` is
|
|
7
|
+
* kept: it is a plain monotonic counter for the environment's own config
|
|
8
|
+
* generation (design.md §11.4 `config_version INTEGER`), not a routing
|
|
9
|
+
* detail, and is useful for dashboard cache-busting.
|
|
10
|
+
*/
|
|
11
|
+
export declare const ENVIRONMENT_TYPES: readonly ["test", "production"];
|
|
12
|
+
export declare const environmentTypeSchema: z.ZodEnum<{
|
|
13
|
+
test: "test";
|
|
14
|
+
production: "production";
|
|
15
|
+
}>;
|
|
16
|
+
export type EnvironmentType = (typeof ENVIRONMENT_TYPES)[number];
|
|
17
|
+
export declare const ENVIRONMENT_STATUSES: readonly ["active", "suspended", "deleted"];
|
|
18
|
+
export declare const environmentStatusSchema: z.ZodEnum<{
|
|
19
|
+
active: "active";
|
|
20
|
+
deleted: "deleted";
|
|
21
|
+
suspended: "suspended";
|
|
22
|
+
}>;
|
|
23
|
+
export type EnvironmentStatus = (typeof ENVIRONMENT_STATUSES)[number];
|
|
24
|
+
export declare const environmentSchema: z.ZodObject<{
|
|
25
|
+
id: z.ZodString;
|
|
26
|
+
project_id: z.ZodString;
|
|
27
|
+
type: z.ZodEnum<{
|
|
28
|
+
test: "test";
|
|
29
|
+
production: "production";
|
|
30
|
+
}>;
|
|
31
|
+
name: z.ZodString;
|
|
32
|
+
status: z.ZodEnum<{
|
|
33
|
+
active: "active";
|
|
34
|
+
deleted: "deleted";
|
|
35
|
+
suspended: "suspended";
|
|
36
|
+
}>;
|
|
37
|
+
issuer: z.ZodURL;
|
|
38
|
+
interaction_domain: z.ZodString;
|
|
39
|
+
rp_id: z.ZodString;
|
|
40
|
+
config_version: z.ZodNumber;
|
|
41
|
+
created_at: z.ZodISODateTime;
|
|
42
|
+
updated_at: z.ZodISODateTime;
|
|
43
|
+
}, z.core.$strict>;
|
|
44
|
+
export type Environment = z.infer<typeof environmentSchema>;
|
|
45
|
+
export declare const environmentListQuerySchema: z.ZodObject<{
|
|
46
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
47
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
48
|
+
project_id: z.ZodString;
|
|
49
|
+
type: z.ZodOptional<z.ZodEnum<{
|
|
50
|
+
test: "test";
|
|
51
|
+
production: "production";
|
|
52
|
+
}>>;
|
|
53
|
+
}, z.core.$strip>;
|
|
54
|
+
export type EnvironmentListQuery = z.infer<typeof environmentListQuerySchema>;
|
|
55
|
+
export declare const environmentListResponseSchema: z.ZodObject<{
|
|
56
|
+
items: z.ZodArray<z.ZodObject<{
|
|
57
|
+
id: z.ZodString;
|
|
58
|
+
project_id: z.ZodString;
|
|
59
|
+
type: z.ZodEnum<{
|
|
60
|
+
test: "test";
|
|
61
|
+
production: "production";
|
|
62
|
+
}>;
|
|
63
|
+
name: z.ZodString;
|
|
64
|
+
status: z.ZodEnum<{
|
|
65
|
+
active: "active";
|
|
66
|
+
deleted: "deleted";
|
|
67
|
+
suspended: "suspended";
|
|
68
|
+
}>;
|
|
69
|
+
issuer: z.ZodURL;
|
|
70
|
+
interaction_domain: z.ZodString;
|
|
71
|
+
rp_id: z.ZodString;
|
|
72
|
+
config_version: z.ZodNumber;
|
|
73
|
+
created_at: z.ZodISODateTime;
|
|
74
|
+
updated_at: z.ZodISODateTime;
|
|
75
|
+
}, z.core.$strict>>;
|
|
76
|
+
next_cursor: z.ZodNullable<z.ZodString>;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
export type EnvironmentListResponse = z.infer<typeof environmentListResponseSchema>;
|
|
79
|
+
/**
|
|
80
|
+
* `issuer` / `interaction_domain` / `rp_id` are NOT client-settable at
|
|
81
|
+
* creation: they are server-derived from the new environment's id and the
|
|
82
|
+
* platform's root domain (design.md §8), then fixed for the environment's
|
|
83
|
+
* lifetime (design.md §7.3's isolation guarantees depend on this).
|
|
84
|
+
*/
|
|
85
|
+
export declare const environmentCreateRequestSchema: z.ZodObject<{
|
|
86
|
+
project_id: z.ZodString;
|
|
87
|
+
type: z.ZodEnum<{
|
|
88
|
+
test: "test";
|
|
89
|
+
production: "production";
|
|
90
|
+
}>;
|
|
91
|
+
name: z.ZodString;
|
|
92
|
+
}, z.core.$strict>;
|
|
93
|
+
export type EnvironmentCreateRequest = z.infer<typeof environmentCreateRequestSchema>;
|
|
94
|
+
export declare const environmentCreateResponseSchema: z.ZodObject<{
|
|
95
|
+
id: z.ZodString;
|
|
96
|
+
project_id: z.ZodString;
|
|
97
|
+
type: z.ZodEnum<{
|
|
98
|
+
test: "test";
|
|
99
|
+
production: "production";
|
|
100
|
+
}>;
|
|
101
|
+
name: z.ZodString;
|
|
102
|
+
status: z.ZodEnum<{
|
|
103
|
+
active: "active";
|
|
104
|
+
deleted: "deleted";
|
|
105
|
+
suspended: "suspended";
|
|
106
|
+
}>;
|
|
107
|
+
issuer: z.ZodURL;
|
|
108
|
+
interaction_domain: z.ZodString;
|
|
109
|
+
rp_id: z.ZodString;
|
|
110
|
+
config_version: z.ZodNumber;
|
|
111
|
+
created_at: z.ZodISODateTime;
|
|
112
|
+
updated_at: z.ZodISODateTime;
|
|
113
|
+
}, z.core.$strict>;
|
|
114
|
+
export type EnvironmentCreateResponse = z.infer<typeof environmentCreateResponseSchema>;
|
|
115
|
+
export declare const environmentGetResponseSchema: z.ZodObject<{
|
|
116
|
+
id: z.ZodString;
|
|
117
|
+
project_id: z.ZodString;
|
|
118
|
+
type: z.ZodEnum<{
|
|
119
|
+
test: "test";
|
|
120
|
+
production: "production";
|
|
121
|
+
}>;
|
|
122
|
+
name: z.ZodString;
|
|
123
|
+
status: z.ZodEnum<{
|
|
124
|
+
active: "active";
|
|
125
|
+
deleted: "deleted";
|
|
126
|
+
suspended: "suspended";
|
|
127
|
+
}>;
|
|
128
|
+
issuer: z.ZodURL;
|
|
129
|
+
interaction_domain: z.ZodString;
|
|
130
|
+
rp_id: z.ZodString;
|
|
131
|
+
config_version: z.ZodNumber;
|
|
132
|
+
created_at: z.ZodISODateTime;
|
|
133
|
+
updated_at: z.ZodISODateTime;
|
|
134
|
+
}, z.core.$strict>;
|
|
135
|
+
export type EnvironmentGetResponse = z.infer<typeof environmentGetResponseSchema>;
|
|
136
|
+
/** `status` here only toggles `active`/`suspended`; `deleted` is reached via `DELETE`, not `PATCH`. */
|
|
137
|
+
export declare const environmentUpdateRequestSchema: z.ZodObject<{
|
|
138
|
+
name: z.ZodOptional<z.ZodString>;
|
|
139
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
140
|
+
active: "active";
|
|
141
|
+
suspended: "suspended";
|
|
142
|
+
}>>;
|
|
143
|
+
}, z.core.$strict>;
|
|
144
|
+
export type EnvironmentUpdateRequest = z.infer<typeof environmentUpdateRequestSchema>;
|
|
145
|
+
export declare const environmentUpdateResponseSchema: z.ZodObject<{
|
|
146
|
+
id: z.ZodString;
|
|
147
|
+
project_id: z.ZodString;
|
|
148
|
+
type: z.ZodEnum<{
|
|
149
|
+
test: "test";
|
|
150
|
+
production: "production";
|
|
151
|
+
}>;
|
|
152
|
+
name: z.ZodString;
|
|
153
|
+
status: z.ZodEnum<{
|
|
154
|
+
active: "active";
|
|
155
|
+
deleted: "deleted";
|
|
156
|
+
suspended: "suspended";
|
|
157
|
+
}>;
|
|
158
|
+
issuer: z.ZodURL;
|
|
159
|
+
interaction_domain: z.ZodString;
|
|
160
|
+
rp_id: z.ZodString;
|
|
161
|
+
config_version: z.ZodNumber;
|
|
162
|
+
created_at: z.ZodISODateTime;
|
|
163
|
+
updated_at: z.ZodISODateTime;
|
|
164
|
+
}, z.core.$strict>;
|
|
165
|
+
export type EnvironmentUpdateResponse = z.infer<typeof environmentUpdateResponseSchema>;
|
|
166
|
+
export declare const environmentDeleteResponseSchema: z.ZodObject<{
|
|
167
|
+
id: z.ZodString;
|
|
168
|
+
status: z.ZodLiteral<"deleted">;
|
|
169
|
+
}, z.core.$strict>;
|
|
170
|
+
export type EnvironmentDeleteResponse = z.infer<typeof environmentDeleteResponseSchema>;
|
|
171
|
+
/**
|
|
172
|
+
* RP ID migration progress (design.md §8.3). The migration is in effect while
|
|
173
|
+
* the Environment has an active `rp_enabled` custom domain: `active_rp_id` is
|
|
174
|
+
* that hostname and `legacy_rp_id` the Environment's original `rp_id`;
|
|
175
|
+
* otherwise `active_rp_id` = `rp_id` and `legacy_rp_id` = null.
|
|
176
|
+
* `legacy_disabled_at` is the stored value, returned even when not in effect.
|
|
177
|
+
* User counts cover every Auth partition and only non-revoked passkeys.
|
|
178
|
+
*/
|
|
179
|
+
export declare const rpMigrationResponseSchema: z.ZodObject<{
|
|
180
|
+
environment_id: z.ZodString;
|
|
181
|
+
active_rp_id: z.ZodString;
|
|
182
|
+
legacy_rp_id: z.ZodNullable<z.ZodString>;
|
|
183
|
+
legacy_disabled_at: z.ZodNullable<z.ZodISODateTime>;
|
|
184
|
+
total_users: z.ZodNumber;
|
|
185
|
+
migrated_users: z.ZodNumber;
|
|
186
|
+
legacy_only_users: z.ZodNumber;
|
|
187
|
+
migrated_share: z.ZodNumber;
|
|
188
|
+
}, z.core.$strict>;
|
|
189
|
+
export type RpMigrationResponse = z.infer<typeof rpMigrationResponseSchema>;
|
|
190
|
+
/** Irreversible: `confirm_rp_id` must equal the Environment's legacy `rp_id`. */
|
|
191
|
+
export declare const rpMigrationDisableLegacyRequestSchema: z.ZodObject<{
|
|
192
|
+
confirm_rp_id: z.ZodString;
|
|
193
|
+
}, z.core.$strict>;
|
|
194
|
+
export type RpMigrationDisableLegacyRequest = z.infer<typeof rpMigrationDisableLegacyRequestSchema>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { cursorPageSchema, paginationQuerySchema } from "./common.js";
|
|
3
|
+
import { environmentIdSchema, httpsUrlSchema, projectIdSchema } from "./primitives.js";
|
|
4
|
+
/**
|
|
5
|
+
* `environments` (design.md §11.4, §7.3). `auth_routing_version` is excluded
|
|
6
|
+
* as internal multi-cell routing state (design.md §10.6 `AuthLocatorDO`),
|
|
7
|
+
* the same category of field the assignment's "internal routing" exclusion
|
|
8
|
+
* targets alongside the explicitly named secret columns. `config_version` is
|
|
9
|
+
* kept: it is a plain monotonic counter for the environment's own config
|
|
10
|
+
* generation (design.md §11.4 `config_version INTEGER`), not a routing
|
|
11
|
+
* detail, and is useful for dashboard cache-busting.
|
|
12
|
+
*/
|
|
13
|
+
export const ENVIRONMENT_TYPES = ["test", "production"];
|
|
14
|
+
export const environmentTypeSchema = z.enum(ENVIRONMENT_TYPES);
|
|
15
|
+
export const ENVIRONMENT_STATUSES = ["active", "suspended", "deleted"];
|
|
16
|
+
export const environmentStatusSchema = z.enum(ENVIRONMENT_STATUSES);
|
|
17
|
+
export const environmentSchema = z.strictObject({
|
|
18
|
+
id: environmentIdSchema,
|
|
19
|
+
project_id: projectIdSchema,
|
|
20
|
+
type: environmentTypeSchema,
|
|
21
|
+
name: z.string().min(1).max(200),
|
|
22
|
+
status: environmentStatusSchema,
|
|
23
|
+
/** design.md §8.1: the OIDC issuer URL, distinct from the interaction domain. */
|
|
24
|
+
issuer: httpsUrlSchema,
|
|
25
|
+
/** design.md §8.1: the Hosted Login / interaction-facing hostname. */
|
|
26
|
+
interaction_domain: z.string().min(1),
|
|
27
|
+
/** design.md §8.3, §17: WebAuthn Relying Party ID for this environment's passkeys. */
|
|
28
|
+
rp_id: z.string().min(1),
|
|
29
|
+
config_version: z.number().int().nonnegative(),
|
|
30
|
+
created_at: z.iso.datetime(),
|
|
31
|
+
updated_at: z.iso.datetime(),
|
|
32
|
+
});
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
// GET /environments
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
export const environmentListQuerySchema = paginationQuerySchema.extend({
|
|
37
|
+
project_id: projectIdSchema,
|
|
38
|
+
type: environmentTypeSchema.optional(),
|
|
39
|
+
});
|
|
40
|
+
export const environmentListResponseSchema = cursorPageSchema(environmentSchema);
|
|
41
|
+
// ---------------------------------------------------------------------------
|
|
42
|
+
// POST /environments
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
/**
|
|
45
|
+
* `issuer` / `interaction_domain` / `rp_id` are NOT client-settable at
|
|
46
|
+
* creation: they are server-derived from the new environment's id and the
|
|
47
|
+
* platform's root domain (design.md §8), then fixed for the environment's
|
|
48
|
+
* lifetime (design.md §7.3's isolation guarantees depend on this).
|
|
49
|
+
*/
|
|
50
|
+
export const environmentCreateRequestSchema = z.strictObject({
|
|
51
|
+
project_id: projectIdSchema,
|
|
52
|
+
type: environmentTypeSchema,
|
|
53
|
+
name: z.string().min(1).max(200),
|
|
54
|
+
});
|
|
55
|
+
export const environmentCreateResponseSchema = environmentSchema;
|
|
56
|
+
// ---------------------------------------------------------------------------
|
|
57
|
+
// GET /environments/:environmentId
|
|
58
|
+
// ---------------------------------------------------------------------------
|
|
59
|
+
export const environmentGetResponseSchema = environmentSchema;
|
|
60
|
+
// ---------------------------------------------------------------------------
|
|
61
|
+
// PATCH /environments/:environmentId
|
|
62
|
+
// ---------------------------------------------------------------------------
|
|
63
|
+
/** `status` here only toggles `active`/`suspended`; `deleted` is reached via `DELETE`, not `PATCH`. */
|
|
64
|
+
export const environmentUpdateRequestSchema = z.strictObject({
|
|
65
|
+
name: z.string().min(1).max(200).optional(),
|
|
66
|
+
status: z.enum(["active", "suspended"]).optional(),
|
|
67
|
+
});
|
|
68
|
+
export const environmentUpdateResponseSchema = environmentSchema;
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
// DELETE /environments/:environmentId
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
export const environmentDeleteResponseSchema = z.strictObject({
|
|
73
|
+
id: environmentIdSchema,
|
|
74
|
+
status: z.literal("deleted"),
|
|
75
|
+
});
|
|
76
|
+
// ---------------------------------------------------------------------------
|
|
77
|
+
// GET /environments/:environmentId/rp-migration
|
|
78
|
+
// POST /environments/:environmentId/rp-migration/disable-legacy
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
/**
|
|
81
|
+
* RP ID migration progress (design.md §8.3). The migration is in effect while
|
|
82
|
+
* the Environment has an active `rp_enabled` custom domain: `active_rp_id` is
|
|
83
|
+
* that hostname and `legacy_rp_id` the Environment's original `rp_id`;
|
|
84
|
+
* otherwise `active_rp_id` = `rp_id` and `legacy_rp_id` = null.
|
|
85
|
+
* `legacy_disabled_at` is the stored value, returned even when not in effect.
|
|
86
|
+
* User counts cover every Auth partition and only non-revoked passkeys.
|
|
87
|
+
*/
|
|
88
|
+
export const rpMigrationResponseSchema = z.strictObject({
|
|
89
|
+
environment_id: environmentIdSchema,
|
|
90
|
+
active_rp_id: z.string(),
|
|
91
|
+
legacy_rp_id: z.string().nullable(),
|
|
92
|
+
legacy_disabled_at: z.iso.datetime().nullable(),
|
|
93
|
+
total_users: z.number().int().min(0),
|
|
94
|
+
migrated_users: z.number().int().min(0),
|
|
95
|
+
legacy_only_users: z.number().int().min(0),
|
|
96
|
+
migrated_share: z.number().min(0).max(1),
|
|
97
|
+
});
|
|
98
|
+
/** Irreversible: `confirm_rp_id` must equal the Environment's legacy `rp_id`. */
|
|
99
|
+
export const rpMigrationDisableLegacyRequestSchema = z.strictObject({
|
|
100
|
+
confirm_rp_id: z.string().min(1),
|
|
101
|
+
});
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @smartcrab/contracts-management — zod request/response contracts for
|
|
3
|
+
* the Management API (design.md §26), consumed by control-worker routes,
|
|
4
|
+
* `@smartcrab/management-client`, the dashboard SPA, and the CLI.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors `@smartcrab/contracts-public`'s conventions: a local
|
|
7
|
+
* dependency-free style (no `@smartcrab/result`), `idPattern`-based id
|
|
8
|
+
* schemas, `z.strictObject` on every response shape, and per-field doc
|
|
9
|
+
* comments citing design.md sections.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./common.js";
|
|
12
|
+
export * from "./primitives.js";
|
|
13
|
+
export * from "./rbac.js";
|
|
14
|
+
export * from "./api-keys.js";
|
|
15
|
+
export * from "./workspaces.js";
|
|
16
|
+
export * from "./projects.js";
|
|
17
|
+
export * from "./environments.js";
|
|
18
|
+
export * from "./clients.js";
|
|
19
|
+
export * from "./connections.js";
|
|
20
|
+
export * from "./domains.js";
|
|
21
|
+
export * from "./users.js";
|
|
22
|
+
export * from "./user-subresources.js";
|
|
23
|
+
export * from "./user-jobs.js";
|
|
24
|
+
export * from "./webhooks.js";
|
|
25
|
+
export * from "./audit-events.js";
|
|
26
|
+
export * from "./usage.js";
|
|
27
|
+
export * from "./billing.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @smartcrab/contracts-management — zod request/response contracts for
|
|
3
|
+
* the Management API (design.md §26), consumed by control-worker routes,
|
|
4
|
+
* `@smartcrab/management-client`, the dashboard SPA, and the CLI.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors `@smartcrab/contracts-public`'s conventions: a local
|
|
7
|
+
* dependency-free style (no `@smartcrab/result`), `idPattern`-based id
|
|
8
|
+
* schemas, `z.strictObject` on every response shape, and per-field doc
|
|
9
|
+
* comments citing design.md sections.
|
|
10
|
+
*/
|
|
11
|
+
export * from "./common.js";
|
|
12
|
+
export * from "./primitives.js";
|
|
13
|
+
export * from "./rbac.js";
|
|
14
|
+
export * from "./api-keys.js";
|
|
15
|
+
export * from "./workspaces.js";
|
|
16
|
+
export * from "./projects.js";
|
|
17
|
+
export * from "./environments.js";
|
|
18
|
+
export * from "./clients.js";
|
|
19
|
+
export * from "./connections.js";
|
|
20
|
+
export * from "./domains.js";
|
|
21
|
+
export * from "./users.js";
|
|
22
|
+
export * from "./user-subresources.js";
|
|
23
|
+
export * from "./user-jobs.js";
|
|
24
|
+
export * from "./webhooks.js";
|
|
25
|
+
export * from "./audit-events.js";
|
|
26
|
+
export * from "./usage.js";
|
|
27
|
+
export * from "./billing.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Shared primitives for the Management API (design.md §26).
|
|
4
|
+
*
|
|
5
|
+
* ID schemas for kinds already modeled by `@smartcrab/contracts-public`
|
|
6
|
+
* (client/user/session/passkey/identity/webhook) are re-exported from there
|
|
7
|
+
* rather than redefined, per the assignment notes: this package's
|
|
8
|
+
* `package.json` only declares `zod` and `@smartcrab/contracts-public` as
|
|
9
|
+
* dependencies, so `@smartcrab/identifiers` and `@smartcrab/tenant-context`
|
|
10
|
+
* are not resolvable here directly (pnpm's strict `node_modules` only links a
|
|
11
|
+
* package's own declared dependencies, not its transitive ones). For the
|
|
12
|
+
* remaining ID kinds this Management API surface needs
|
|
13
|
+
* (workspace/project/environment/connection/domain/job/management-api-key/
|
|
14
|
+
* audit-event) that `contracts-public` does not export, the exact
|
|
15
|
+
* `<prefix>_<32 base32url chars>` rule and prefix table are mirrored locally
|
|
16
|
+
* from `@smartcrab/identifiers`'s `ID_PREFIXES` (design.md §7.5) so the
|
|
17
|
+
* pattern never drifts from the canonical source.
|
|
18
|
+
*/
|
|
19
|
+
export { clientIdSchema, httpsUrlSchema, identityIdSchema, isoDateTimeSchema, passkeyIdSchema, sessionIdSchema, userIdSchema, webhookIdSchema, } from "@smartcrab/contracts-public";
|
|
20
|
+
export type { ClientId, IdentityId, PasskeyId, SessionId, UserId, WebhookId, } from "@smartcrab/contracts-public";
|
|
21
|
+
export declare const workspaceIdSchema: z.ZodString;
|
|
22
|
+
export type WorkspaceId = z.infer<typeof workspaceIdSchema>;
|
|
23
|
+
export declare const projectIdSchema: z.ZodString;
|
|
24
|
+
export type ProjectId = z.infer<typeof projectIdSchema>;
|
|
25
|
+
export declare const environmentIdSchema: z.ZodString;
|
|
26
|
+
export type EnvironmentId = z.infer<typeof environmentIdSchema>;
|
|
27
|
+
export declare const connectionIdSchema: z.ZodString;
|
|
28
|
+
export type ConnectionId = z.infer<typeof connectionIdSchema>;
|
|
29
|
+
export declare const domainIdSchema: z.ZodString;
|
|
30
|
+
export type DomainId = z.infer<typeof domainIdSchema>;
|
|
31
|
+
export declare const jobIdSchema: z.ZodString;
|
|
32
|
+
export type JobId = z.infer<typeof jobIdSchema>;
|
|
33
|
+
export declare const apiKeyIdSchema: z.ZodString;
|
|
34
|
+
export type ApiKeyId = z.infer<typeof apiKeyIdSchema>;
|
|
35
|
+
export declare const auditEventIdSchema: z.ZodString;
|
|
36
|
+
export type AuditEventId = z.infer<typeof auditEventIdSchema>;
|
|
37
|
+
/**
|
|
38
|
+
* Generic domain event ID (`evt_...`, design.md §7.5) — the exact same ID
|
|
39
|
+
* kind as `auditEventIdSchema` above, exported under a resource-neutral name
|
|
40
|
+
* for consumers (e.g. `webhooks.ts`'s delivery history `event_id`) that
|
|
41
|
+
* reference a domain event without being about the audit log itself.
|
|
42
|
+
*/
|
|
43
|
+
export declare const eventIdSchema: z.ZodString;
|
|
44
|
+
export type EventId = z.infer<typeof eventIdSchema>;
|
|
45
|
+
/** `webhook_delivery_history.id` (design.md §29.4, §10.10): `dlv_...`. */
|
|
46
|
+
export declare const deliveryIdSchema: z.ZodString;
|
|
47
|
+
export type DeliveryId = z.infer<typeof deliveryIdSchema>;
|
|
48
|
+
/** `workspaces.slug` / `projects.slug` (design.md §11.1, §11.3): URL-safe, lowercase, hyphenated. */
|
|
49
|
+
export declare const slugSchema: z.ZodString;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/**
|
|
3
|
+
* Shared primitives for the Management API (design.md §26).
|
|
4
|
+
*
|
|
5
|
+
* ID schemas for kinds already modeled by `@smartcrab/contracts-public`
|
|
6
|
+
* (client/user/session/passkey/identity/webhook) are re-exported from there
|
|
7
|
+
* rather than redefined, per the assignment notes: this package's
|
|
8
|
+
* `package.json` only declares `zod` and `@smartcrab/contracts-public` as
|
|
9
|
+
* dependencies, so `@smartcrab/identifiers` and `@smartcrab/tenant-context`
|
|
10
|
+
* are not resolvable here directly (pnpm's strict `node_modules` only links a
|
|
11
|
+
* package's own declared dependencies, not its transitive ones). For the
|
|
12
|
+
* remaining ID kinds this Management API surface needs
|
|
13
|
+
* (workspace/project/environment/connection/domain/job/management-api-key/
|
|
14
|
+
* audit-event) that `contracts-public` does not export, the exact
|
|
15
|
+
* `<prefix>_<32 base32url chars>` rule and prefix table are mirrored locally
|
|
16
|
+
* from `@smartcrab/identifiers`'s `ID_PREFIXES` (design.md §7.5) so the
|
|
17
|
+
* pattern never drifts from the canonical source.
|
|
18
|
+
*/
|
|
19
|
+
export { clientIdSchema, httpsUrlSchema, identityIdSchema, isoDateTimeSchema, passkeyIdSchema, sessionIdSchema, userIdSchema, webhookIdSchema, } from "@smartcrab/contracts-public";
|
|
20
|
+
/** Mirrors `@smartcrab/identifiers`'s `ID_PREFIXES` (design.md §7.5) for kinds not re-exported above. */
|
|
21
|
+
const LOCAL_ID_PREFIXES = {
|
|
22
|
+
workspace: "wsp",
|
|
23
|
+
project: "prj",
|
|
24
|
+
environment: "env",
|
|
25
|
+
connection: "con",
|
|
26
|
+
domain: "dom",
|
|
27
|
+
job: "job",
|
|
28
|
+
apiKey: "mky",
|
|
29
|
+
event: "evt",
|
|
30
|
+
delivery: "dlv",
|
|
31
|
+
};
|
|
32
|
+
/** Zod-ready regex, identical shape to `@smartcrab/identifiers`'s `idPattern`. */
|
|
33
|
+
const localIdPattern = (kind) => new RegExp(`^${LOCAL_ID_PREFIXES[kind]}_[a-z2-7]{32}$`);
|
|
34
|
+
export const workspaceIdSchema = z.string().regex(localIdPattern("workspace"));
|
|
35
|
+
export const projectIdSchema = z.string().regex(localIdPattern("project"));
|
|
36
|
+
export const environmentIdSchema = z.string().regex(localIdPattern("environment"));
|
|
37
|
+
export const connectionIdSchema = z.string().regex(localIdPattern("connection"));
|
|
38
|
+
export const domainIdSchema = z.string().regex(localIdPattern("domain"));
|
|
39
|
+
export const jobIdSchema = z.string().regex(localIdPattern("job"));
|
|
40
|
+
export const apiKeyIdSchema = z.string().regex(localIdPattern("apiKey"));
|
|
41
|
+
export const auditEventIdSchema = z.string().regex(localIdPattern("event"));
|
|
42
|
+
/**
|
|
43
|
+
* Generic domain event ID (`evt_...`, design.md §7.5) — the exact same ID
|
|
44
|
+
* kind as `auditEventIdSchema` above, exported under a resource-neutral name
|
|
45
|
+
* for consumers (e.g. `webhooks.ts`'s delivery history `event_id`) that
|
|
46
|
+
* reference a domain event without being about the audit log itself.
|
|
47
|
+
*/
|
|
48
|
+
export const eventIdSchema = z.string().regex(localIdPattern("event"));
|
|
49
|
+
/** `webhook_delivery_history.id` (design.md §29.4, §10.10): `dlv_...`. */
|
|
50
|
+
export const deliveryIdSchema = z.string().regex(localIdPattern("delivery"));
|
|
51
|
+
/** `workspaces.slug` / `projects.slug` (design.md §11.1, §11.3): URL-safe, lowercase, hyphenated. */
|
|
52
|
+
export const slugSchema = z
|
|
53
|
+
.string()
|
|
54
|
+
.min(1)
|
|
55
|
+
.max(63)
|
|
56
|
+
.regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** `projects` (design.md §11.3, §7.2). No secret/internal-routing columns. */
|
|
3
|
+
export declare const projectSchema: z.ZodObject<{
|
|
4
|
+
id: z.ZodString;
|
|
5
|
+
workspace_id: z.ZodString;
|
|
6
|
+
name: z.ZodString;
|
|
7
|
+
slug: z.ZodString;
|
|
8
|
+
created_at: z.ZodISODateTime;
|
|
9
|
+
updated_at: z.ZodISODateTime;
|
|
10
|
+
deleted_at: z.ZodNullable<z.ZodISODateTime>;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export type Project = z.infer<typeof projectSchema>;
|
|
13
|
+
/** `/projects` is a flat top-level route (design.md §26.2); `workspace_id` scopes the listing. */
|
|
14
|
+
export declare const projectListQuerySchema: z.ZodObject<{
|
|
15
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
16
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
17
|
+
workspace_id: z.ZodString;
|
|
18
|
+
}, z.core.$strip>;
|
|
19
|
+
export type ProjectListQuery = z.infer<typeof projectListQuerySchema>;
|
|
20
|
+
export declare const projectListResponseSchema: z.ZodObject<{
|
|
21
|
+
items: z.ZodArray<z.ZodObject<{
|
|
22
|
+
id: z.ZodString;
|
|
23
|
+
workspace_id: z.ZodString;
|
|
24
|
+
name: z.ZodString;
|
|
25
|
+
slug: z.ZodString;
|
|
26
|
+
created_at: z.ZodISODateTime;
|
|
27
|
+
updated_at: z.ZodISODateTime;
|
|
28
|
+
deleted_at: z.ZodNullable<z.ZodISODateTime>;
|
|
29
|
+
}, z.core.$strict>>;
|
|
30
|
+
next_cursor: z.ZodNullable<z.ZodString>;
|
|
31
|
+
}, z.core.$strict>;
|
|
32
|
+
export type ProjectListResponse = z.infer<typeof projectListResponseSchema>;
|
|
33
|
+
export declare const projectCreateRequestSchema: z.ZodObject<{
|
|
34
|
+
workspace_id: z.ZodString;
|
|
35
|
+
name: z.ZodString;
|
|
36
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
37
|
+
}, z.core.$strict>;
|
|
38
|
+
export type ProjectCreateRequest = z.infer<typeof projectCreateRequestSchema>;
|
|
39
|
+
export declare const projectCreateResponseSchema: z.ZodObject<{
|
|
40
|
+
id: z.ZodString;
|
|
41
|
+
workspace_id: z.ZodString;
|
|
42
|
+
name: z.ZodString;
|
|
43
|
+
slug: z.ZodString;
|
|
44
|
+
created_at: z.ZodISODateTime;
|
|
45
|
+
updated_at: z.ZodISODateTime;
|
|
46
|
+
deleted_at: z.ZodNullable<z.ZodISODateTime>;
|
|
47
|
+
}, z.core.$strict>;
|
|
48
|
+
export type ProjectCreateResponse = z.infer<typeof projectCreateResponseSchema>;
|
|
49
|
+
export declare const projectGetResponseSchema: z.ZodObject<{
|
|
50
|
+
id: z.ZodString;
|
|
51
|
+
workspace_id: z.ZodString;
|
|
52
|
+
name: z.ZodString;
|
|
53
|
+
slug: z.ZodString;
|
|
54
|
+
created_at: z.ZodISODateTime;
|
|
55
|
+
updated_at: z.ZodISODateTime;
|
|
56
|
+
deleted_at: z.ZodNullable<z.ZodISODateTime>;
|
|
57
|
+
}, z.core.$strict>;
|
|
58
|
+
export type ProjectGetResponse = z.infer<typeof projectGetResponseSchema>;
|
|
59
|
+
export declare const projectUpdateRequestSchema: z.ZodObject<{
|
|
60
|
+
name: z.ZodOptional<z.ZodString>;
|
|
61
|
+
slug: z.ZodOptional<z.ZodString>;
|
|
62
|
+
}, z.core.$strict>;
|
|
63
|
+
export type ProjectUpdateRequest = z.infer<typeof projectUpdateRequestSchema>;
|
|
64
|
+
export declare const projectUpdateResponseSchema: z.ZodObject<{
|
|
65
|
+
id: z.ZodString;
|
|
66
|
+
workspace_id: z.ZodString;
|
|
67
|
+
name: z.ZodString;
|
|
68
|
+
slug: z.ZodString;
|
|
69
|
+
created_at: z.ZodISODateTime;
|
|
70
|
+
updated_at: z.ZodISODateTime;
|
|
71
|
+
deleted_at: z.ZodNullable<z.ZodISODateTime>;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
export type ProjectUpdateResponse = z.infer<typeof projectUpdateResponseSchema>;
|
|
74
|
+
export declare const projectDeleteResponseSchema: z.ZodObject<{
|
|
75
|
+
id: z.ZodString;
|
|
76
|
+
deleted: z.ZodLiteral<true>;
|
|
77
|
+
}, z.core.$strict>;
|
|
78
|
+
export type ProjectDeleteResponse = z.infer<typeof projectDeleteResponseSchema>;
|
package/dist/projects.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { cursorPageSchema, paginationQuerySchema } from "./common.js";
|
|
3
|
+
import { projectIdSchema, slugSchema, workspaceIdSchema } from "./primitives.js";
|
|
4
|
+
/** `projects` (design.md §11.3, §7.2). No secret/internal-routing columns. */
|
|
5
|
+
export const projectSchema = z.strictObject({
|
|
6
|
+
id: projectIdSchema,
|
|
7
|
+
workspace_id: workspaceIdSchema,
|
|
8
|
+
name: z.string().min(1).max(200),
|
|
9
|
+
slug: slugSchema,
|
|
10
|
+
created_at: z.iso.datetime(),
|
|
11
|
+
updated_at: z.iso.datetime(),
|
|
12
|
+
deleted_at: z.iso.datetime().nullable(),
|
|
13
|
+
});
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
// GET /projects
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
/** `/projects` is a flat top-level route (design.md §26.2); `workspace_id` scopes the listing. */
|
|
18
|
+
export const projectListQuerySchema = paginationQuerySchema.extend({
|
|
19
|
+
workspace_id: workspaceIdSchema,
|
|
20
|
+
});
|
|
21
|
+
export const projectListResponseSchema = cursorPageSchema(projectSchema);
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
// POST /projects
|
|
24
|
+
// ---------------------------------------------------------------------------
|
|
25
|
+
export const projectCreateRequestSchema = z.strictObject({
|
|
26
|
+
workspace_id: workspaceIdSchema,
|
|
27
|
+
name: z.string().min(1).max(200),
|
|
28
|
+
slug: slugSchema.optional(),
|
|
29
|
+
});
|
|
30
|
+
export const projectCreateResponseSchema = projectSchema;
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// GET /projects/:projectId
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
export const projectGetResponseSchema = projectSchema;
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// PATCH /projects/:projectId
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
export const projectUpdateRequestSchema = z.strictObject({
|
|
39
|
+
name: z.string().min(1).max(200).optional(),
|
|
40
|
+
slug: slugSchema.optional(),
|
|
41
|
+
});
|
|
42
|
+
export const projectUpdateResponseSchema = projectSchema;
|
|
43
|
+
// ---------------------------------------------------------------------------
|
|
44
|
+
// DELETE /projects/:projectId (design.md §11.3 `deleted_at` — logical delete)
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
export const projectDeleteResponseSchema = z.strictObject({
|
|
47
|
+
id: projectIdSchema,
|
|
48
|
+
deleted: z.literal(true),
|
|
49
|
+
});
|