@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.
Files changed (73) hide show
  1. package/LICENSE +202 -0
  2. package/dist/api-keys.d.ts +251 -0
  3. package/dist/api-keys.js +78 -0
  4. package/dist/audit-events.d.ts +94 -0
  5. package/dist/audit-events.js +45 -0
  6. package/dist/billing.d.ts +30 -0
  7. package/dist/billing.js +30 -0
  8. package/dist/clients.d.ts +328 -0
  9. package/dist/clients.js +141 -0
  10. package/dist/common.d.ts +95 -0
  11. package/dist/common.js +99 -0
  12. package/dist/connections.d.ts +201 -0
  13. package/dist/connections.js +107 -0
  14. package/dist/domains.d.ts +167 -0
  15. package/dist/domains.js +74 -0
  16. package/dist/environments.d.ts +194 -0
  17. package/dist/environments.js +101 -0
  18. package/dist/index.d.ts +27 -0
  19. package/dist/index.js +27 -0
  20. package/dist/primitives.d.ts +49 -0
  21. package/dist/primitives.js +56 -0
  22. package/dist/projects.d.ts +78 -0
  23. package/dist/projects.js +49 -0
  24. package/dist/rbac.d.ts +222 -0
  25. package/dist/rbac.js +226 -0
  26. package/dist/usage.d.ts +72 -0
  27. package/dist/usage.js +52 -0
  28. package/dist/user-jobs.d.ts +253 -0
  29. package/dist/user-jobs.js +95 -0
  30. package/dist/user-subresources.d.ts +161 -0
  31. package/dist/user-subresources.js +85 -0
  32. package/dist/users.d.ts +193 -0
  33. package/dist/users.js +112 -0
  34. package/dist/webhooks.d.ts +306 -0
  35. package/dist/webhooks.js +134 -0
  36. package/dist/workspaces.d.ts +172 -0
  37. package/dist/workspaces.js +77 -0
  38. package/package.json +42 -0
  39. package/src/api-keys.test.ts +86 -0
  40. package/src/api-keys.ts +97 -0
  41. package/src/audit-events.test.ts +44 -0
  42. package/src/audit-events.ts +57 -0
  43. package/src/billing.test.ts +57 -0
  44. package/src/billing.ts +46 -0
  45. package/src/clients.test.ts +169 -0
  46. package/src/clients.ts +182 -0
  47. package/src/common.test.ts +102 -0
  48. package/src/common.ts +127 -0
  49. package/src/connections.test.ts +65 -0
  50. package/src/connections.ts +134 -0
  51. package/src/domains.test.ts +48 -0
  52. package/src/domains.ts +104 -0
  53. package/src/environments.test.ts +67 -0
  54. package/src/environments.ts +133 -0
  55. package/src/index.ts +27 -0
  56. package/src/primitives.ts +100 -0
  57. package/src/projects.test.ts +49 -0
  58. package/src/projects.ts +72 -0
  59. package/src/rbac.test.ts +148 -0
  60. package/src/rbac.ts +250 -0
  61. package/src/secret-fields.test.ts +84 -0
  62. package/src/usage.test.ts +57 -0
  63. package/src/usage.ts +66 -0
  64. package/src/user-jobs.test.ts +86 -0
  65. package/src/user-jobs.ts +120 -0
  66. package/src/user-subresources.test.ts +115 -0
  67. package/src/user-subresources.ts +128 -0
  68. package/src/users.test.ts +91 -0
  69. package/src/users.ts +149 -0
  70. package/src/webhooks.test.ts +187 -0
  71. package/src/webhooks.ts +182 -0
  72. package/src/workspaces.test.ts +127 -0
  73. package/src/workspaces.ts +106 -0
@@ -0,0 +1,253 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * `user-import-jobs` / `user-export-jobs` (design.md §26.2 route list).
4
+ *
5
+ * DEVIATION: design.md §11/§12 do not define a D1 table for either job kind
6
+ * (unlike every other resource in this package, whose field set is a direct
7
+ * projection of a named table). The shape below is derived from:
8
+ * - design.md §33.3 ("Export"): the fixed list of data an export contains
9
+ * (profile, emails, linked identities, passkey metadata, sessions,
10
+ * consent, the user's own audit events) and its explicit exclusion list
11
+ * (private key, provider token, internal risk score).
12
+ * - the async job lifecycle convention used elsewhere in the schema, e.g.
13
+ * `email_deliveries.status` (§12.8) and `outbox_events.status` (§11.16).
14
+ * - design.md §14.0's "1 row/valueは64 KB以下" (rows/values capped at 64 KB) —
15
+ * bulk import records and export output are therefore referenced by an R2
16
+ * URL, never embedded inline in the job resource itself.
17
+ *
18
+ * Should a future design.md revision add explicit
19
+ * `user_import_jobs`/`user_export_jobs` tables, this file's field set should
20
+ * be reconciled against them.
21
+ */
22
+ export declare const JOB_STATUSES: readonly ["pending", "processing", "completed", "failed"];
23
+ export declare const jobStatusSchema: z.ZodEnum<{
24
+ failed: "failed";
25
+ pending: "pending";
26
+ processing: "processing";
27
+ completed: "completed";
28
+ }>;
29
+ export type JobStatus = (typeof JOB_STATUSES)[number];
30
+ export declare const USER_IMPORT_FORMATS: readonly ["json", "csv"];
31
+ export declare const userImportFormatSchema: z.ZodEnum<{
32
+ json: "json";
33
+ csv: "csv";
34
+ }>;
35
+ export type UserImportFormat = (typeof USER_IMPORT_FORMATS)[number];
36
+ export declare const userImportJobSchema: z.ZodObject<{
37
+ id: z.ZodString;
38
+ environment_id: z.ZodString;
39
+ status: z.ZodEnum<{
40
+ failed: "failed";
41
+ pending: "pending";
42
+ processing: "processing";
43
+ completed: "completed";
44
+ }>;
45
+ format: z.ZodEnum<{
46
+ json: "json";
47
+ csv: "csv";
48
+ }>;
49
+ source_url: z.ZodURL;
50
+ total_records: z.ZodNullable<z.ZodNumber>;
51
+ processed_records: z.ZodNumber;
52
+ succeeded_records: z.ZodNumber;
53
+ failed_records: z.ZodNumber;
54
+ error_report_url: z.ZodNullable<z.ZodURL>;
55
+ created_by: z.ZodObject<{
56
+ actor_type: z.ZodEnum<{
57
+ workspace_member: "workspace_member";
58
+ api_key: "api_key";
59
+ }>;
60
+ actor_id: z.ZodString;
61
+ }, z.core.$strict>;
62
+ created_at: z.ZodISODateTime;
63
+ updated_at: z.ZodISODateTime;
64
+ completed_at: z.ZodNullable<z.ZodISODateTime>;
65
+ }, z.core.$strict>;
66
+ export type UserImportJob = z.infer<typeof userImportJobSchema>;
67
+ export declare const userImportJobCreateRequestSchema: z.ZodObject<{
68
+ environment_id: z.ZodString;
69
+ format: z.ZodEnum<{
70
+ json: "json";
71
+ csv: "csv";
72
+ }>;
73
+ source_url: z.ZodURL;
74
+ }, z.core.$strict>;
75
+ export type UserImportJobCreateRequest = z.infer<typeof userImportJobCreateRequestSchema>;
76
+ export declare const userImportJobCreateResponseSchema: z.ZodObject<{
77
+ id: z.ZodString;
78
+ environment_id: z.ZodString;
79
+ status: z.ZodEnum<{
80
+ failed: "failed";
81
+ pending: "pending";
82
+ processing: "processing";
83
+ completed: "completed";
84
+ }>;
85
+ format: z.ZodEnum<{
86
+ json: "json";
87
+ csv: "csv";
88
+ }>;
89
+ source_url: z.ZodURL;
90
+ total_records: z.ZodNullable<z.ZodNumber>;
91
+ processed_records: z.ZodNumber;
92
+ succeeded_records: z.ZodNumber;
93
+ failed_records: z.ZodNumber;
94
+ error_report_url: z.ZodNullable<z.ZodURL>;
95
+ created_by: z.ZodObject<{
96
+ actor_type: z.ZodEnum<{
97
+ workspace_member: "workspace_member";
98
+ api_key: "api_key";
99
+ }>;
100
+ actor_id: z.ZodString;
101
+ }, z.core.$strict>;
102
+ created_at: z.ZodISODateTime;
103
+ updated_at: z.ZodISODateTime;
104
+ completed_at: z.ZodNullable<z.ZodISODateTime>;
105
+ }, z.core.$strict>;
106
+ export type UserImportJobCreateResponse = z.infer<typeof userImportJobCreateResponseSchema>;
107
+ export declare const userImportJobGetResponseSchema: z.ZodObject<{
108
+ id: z.ZodString;
109
+ environment_id: z.ZodString;
110
+ status: z.ZodEnum<{
111
+ failed: "failed";
112
+ pending: "pending";
113
+ processing: "processing";
114
+ completed: "completed";
115
+ }>;
116
+ format: z.ZodEnum<{
117
+ json: "json";
118
+ csv: "csv";
119
+ }>;
120
+ source_url: z.ZodURL;
121
+ total_records: z.ZodNullable<z.ZodNumber>;
122
+ processed_records: z.ZodNumber;
123
+ succeeded_records: z.ZodNumber;
124
+ failed_records: z.ZodNumber;
125
+ error_report_url: z.ZodNullable<z.ZodURL>;
126
+ created_by: z.ZodObject<{
127
+ actor_type: z.ZodEnum<{
128
+ workspace_member: "workspace_member";
129
+ api_key: "api_key";
130
+ }>;
131
+ actor_id: z.ZodString;
132
+ }, z.core.$strict>;
133
+ created_at: z.ZodISODateTime;
134
+ updated_at: z.ZodISODateTime;
135
+ completed_at: z.ZodNullable<z.ZodISODateTime>;
136
+ }, z.core.$strict>;
137
+ export type UserImportJobGetResponse = z.infer<typeof userImportJobGetResponseSchema>;
138
+ /** design.md §33.3's fixed export content list; not caller-configurable. */
139
+ export declare const USER_EXPORT_CONTENTS: readonly ["profile", "emails", "linked_identities", "passkey_metadata", "sessions", "consent", "audit_events"];
140
+ export declare const userExportContentSchema: z.ZodEnum<{
141
+ profile: "profile";
142
+ sessions: "sessions";
143
+ emails: "emails";
144
+ linked_identities: "linked_identities";
145
+ passkey_metadata: "passkey_metadata";
146
+ consent: "consent";
147
+ audit_events: "audit_events";
148
+ }>;
149
+ export type UserExportContent = (typeof USER_EXPORT_CONTENTS)[number];
150
+ export declare const userExportJobSchema: z.ZodObject<{
151
+ id: z.ZodString;
152
+ environment_id: z.ZodString;
153
+ target_user_id: z.ZodString;
154
+ status: z.ZodEnum<{
155
+ failed: "failed";
156
+ pending: "pending";
157
+ processing: "processing";
158
+ completed: "completed";
159
+ }>;
160
+ contents: z.ZodArray<z.ZodEnum<{
161
+ profile: "profile";
162
+ sessions: "sessions";
163
+ emails: "emails";
164
+ linked_identities: "linked_identities";
165
+ passkey_metadata: "passkey_metadata";
166
+ consent: "consent";
167
+ audit_events: "audit_events";
168
+ }>>;
169
+ download_url: z.ZodNullable<z.ZodURL>;
170
+ download_url_expires_at: z.ZodNullable<z.ZodISODateTime>;
171
+ created_by: z.ZodObject<{
172
+ actor_type: z.ZodEnum<{
173
+ workspace_member: "workspace_member";
174
+ api_key: "api_key";
175
+ }>;
176
+ actor_id: z.ZodString;
177
+ }, z.core.$strict>;
178
+ created_at: z.ZodISODateTime;
179
+ updated_at: z.ZodISODateTime;
180
+ completed_at: z.ZodNullable<z.ZodISODateTime>;
181
+ }, z.core.$strict>;
182
+ export type UserExportJob = z.infer<typeof userExportJobSchema>;
183
+ export declare const userExportJobCreateRequestSchema: z.ZodObject<{
184
+ environment_id: z.ZodString;
185
+ target_user_id: z.ZodString;
186
+ }, z.core.$strict>;
187
+ export type UserExportJobCreateRequest = z.infer<typeof userExportJobCreateRequestSchema>;
188
+ export declare const userExportJobCreateResponseSchema: z.ZodObject<{
189
+ id: z.ZodString;
190
+ environment_id: z.ZodString;
191
+ target_user_id: z.ZodString;
192
+ status: z.ZodEnum<{
193
+ failed: "failed";
194
+ pending: "pending";
195
+ processing: "processing";
196
+ completed: "completed";
197
+ }>;
198
+ contents: z.ZodArray<z.ZodEnum<{
199
+ profile: "profile";
200
+ sessions: "sessions";
201
+ emails: "emails";
202
+ linked_identities: "linked_identities";
203
+ passkey_metadata: "passkey_metadata";
204
+ consent: "consent";
205
+ audit_events: "audit_events";
206
+ }>>;
207
+ download_url: z.ZodNullable<z.ZodURL>;
208
+ download_url_expires_at: z.ZodNullable<z.ZodISODateTime>;
209
+ created_by: z.ZodObject<{
210
+ actor_type: z.ZodEnum<{
211
+ workspace_member: "workspace_member";
212
+ api_key: "api_key";
213
+ }>;
214
+ actor_id: z.ZodString;
215
+ }, z.core.$strict>;
216
+ created_at: z.ZodISODateTime;
217
+ updated_at: z.ZodISODateTime;
218
+ completed_at: z.ZodNullable<z.ZodISODateTime>;
219
+ }, z.core.$strict>;
220
+ export type UserExportJobCreateResponse = z.infer<typeof userExportJobCreateResponseSchema>;
221
+ export declare const userExportJobGetResponseSchema: z.ZodObject<{
222
+ id: z.ZodString;
223
+ environment_id: z.ZodString;
224
+ target_user_id: z.ZodString;
225
+ status: z.ZodEnum<{
226
+ failed: "failed";
227
+ pending: "pending";
228
+ processing: "processing";
229
+ completed: "completed";
230
+ }>;
231
+ contents: z.ZodArray<z.ZodEnum<{
232
+ profile: "profile";
233
+ sessions: "sessions";
234
+ emails: "emails";
235
+ linked_identities: "linked_identities";
236
+ passkey_metadata: "passkey_metadata";
237
+ consent: "consent";
238
+ audit_events: "audit_events";
239
+ }>>;
240
+ download_url: z.ZodNullable<z.ZodURL>;
241
+ download_url_expires_at: z.ZodNullable<z.ZodISODateTime>;
242
+ created_by: z.ZodObject<{
243
+ actor_type: z.ZodEnum<{
244
+ workspace_member: "workspace_member";
245
+ api_key: "api_key";
246
+ }>;
247
+ actor_id: z.ZodString;
248
+ }, z.core.$strict>;
249
+ created_at: z.ZodISODateTime;
250
+ updated_at: z.ZodISODateTime;
251
+ completed_at: z.ZodNullable<z.ZodISODateTime>;
252
+ }, z.core.$strict>;
253
+ export type UserExportJobGetResponse = z.infer<typeof userExportJobGetResponseSchema>;
@@ -0,0 +1,95 @@
1
+ import { httpsUrlSchema } from "@smartcrab/contracts-public";
2
+ import { z } from "zod";
3
+ import { environmentIdSchema, jobIdSchema, userIdSchema } from "./primitives.js";
4
+ /**
5
+ * `user-import-jobs` / `user-export-jobs` (design.md §26.2 route list).
6
+ *
7
+ * DEVIATION: design.md §11/§12 do not define a D1 table for either job kind
8
+ * (unlike every other resource in this package, whose field set is a direct
9
+ * projection of a named table). The shape below is derived from:
10
+ * - design.md §33.3 ("Export"): the fixed list of data an export contains
11
+ * (profile, emails, linked identities, passkey metadata, sessions,
12
+ * consent, the user's own audit events) and its explicit exclusion list
13
+ * (private key, provider token, internal risk score).
14
+ * - the async job lifecycle convention used elsewhere in the schema, e.g.
15
+ * `email_deliveries.status` (§12.8) and `outbox_events.status` (§11.16).
16
+ * - design.md §14.0's "1 row/valueは64 KB以下" (rows/values capped at 64 KB) —
17
+ * bulk import records and export output are therefore referenced by an R2
18
+ * URL, never embedded inline in the job resource itself.
19
+ *
20
+ * Should a future design.md revision add explicit
21
+ * `user_import_jobs`/`user_export_jobs` tables, this file's field set should
22
+ * be reconciled against them.
23
+ */
24
+ export const JOB_STATUSES = ["pending", "processing", "completed", "failed"];
25
+ export const jobStatusSchema = z.enum(JOB_STATUSES);
26
+ /** Who requested the job (design.md §12.11 `audit_events.actor_type` narrowed to the kinds that can trigger a job). */
27
+ const JOB_ACTOR_TYPES = ["workspace_member", "api_key"];
28
+ const jobActorSchema = z.strictObject({
29
+ actor_type: z.enum(JOB_ACTOR_TYPES),
30
+ actor_id: z.string().min(1),
31
+ });
32
+ // ---------------------------------------------------------------------------
33
+ // POST /user-import-jobs, GET /user-import-jobs/:jobId
34
+ // ---------------------------------------------------------------------------
35
+ export const USER_IMPORT_FORMATS = ["json", "csv"];
36
+ export const userImportFormatSchema = z.enum(USER_IMPORT_FORMATS);
37
+ export const userImportJobSchema = z.strictObject({
38
+ id: jobIdSchema,
39
+ environment_id: environmentIdSchema,
40
+ status: jobStatusSchema,
41
+ format: userImportFormatSchema,
42
+ /** Where the platform fetched the source records from (an R2/customer-hosted HTTPS URL). */
43
+ source_url: httpsUrlSchema,
44
+ total_records: z.number().int().nonnegative().nullable(),
45
+ processed_records: z.number().int().nonnegative(),
46
+ succeeded_records: z.number().int().nonnegative(),
47
+ failed_records: z.number().int().nonnegative(),
48
+ /** Present once the job has processed at least one failing record; an R2-hosted per-row error report. */
49
+ error_report_url: httpsUrlSchema.nullable(),
50
+ created_by: jobActorSchema,
51
+ created_at: z.iso.datetime(),
52
+ updated_at: z.iso.datetime(),
53
+ completed_at: z.iso.datetime().nullable(),
54
+ });
55
+ export const userImportJobCreateRequestSchema = z.strictObject({
56
+ environment_id: environmentIdSchema,
57
+ format: userImportFormatSchema,
58
+ source_url: httpsUrlSchema,
59
+ });
60
+ export const userImportJobCreateResponseSchema = userImportJobSchema;
61
+ export const userImportJobGetResponseSchema = userImportJobSchema;
62
+ // ---------------------------------------------------------------------------
63
+ // POST /user-export-jobs, GET /user-export-jobs/:jobId
64
+ // ---------------------------------------------------------------------------
65
+ /** design.md §33.3's fixed export content list; not caller-configurable. */
66
+ export const USER_EXPORT_CONTENTS = [
67
+ "profile",
68
+ "emails",
69
+ "linked_identities",
70
+ "passkey_metadata",
71
+ "sessions",
72
+ "consent",
73
+ "audit_events",
74
+ ];
75
+ export const userExportContentSchema = z.enum(USER_EXPORT_CONTENTS);
76
+ export const userExportJobSchema = z.strictObject({
77
+ id: jobIdSchema,
78
+ environment_id: environmentIdSchema,
79
+ target_user_id: userIdSchema,
80
+ status: jobStatusSchema,
81
+ contents: z.array(userExportContentSchema),
82
+ /** Present once `status: "completed"`: a time-limited presigned R2 URL for the JSON export. */
83
+ download_url: httpsUrlSchema.nullable(),
84
+ download_url_expires_at: z.iso.datetime().nullable(),
85
+ created_by: jobActorSchema,
86
+ created_at: z.iso.datetime(),
87
+ updated_at: z.iso.datetime(),
88
+ completed_at: z.iso.datetime().nullable(),
89
+ });
90
+ export const userExportJobCreateRequestSchema = z.strictObject({
91
+ environment_id: environmentIdSchema,
92
+ target_user_id: userIdSchema,
93
+ });
94
+ export const userExportJobCreateResponseSchema = userExportJobSchema;
95
+ export const userExportJobGetResponseSchema = userExportJobSchema;
@@ -0,0 +1,161 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Admin-facing projections of a user's sub-resources: `identities` (design.md
4
+ * §12.3), `passkeys` (§12.5), `sessions` (§12.4). Same exclusions as
5
+ * `@smartcrab/contracts-public`'s `/v1/me` sub-resource schemas
6
+ * (`provider_subject`, `profile_json`, token ciphertexts, `credential_id`,
7
+ * `public_key`, `sign_count`, `token_mac` (assignment's forbidden list),
8
+ * `ip_prefix_hash`/`user_agent_hash`), plus `user_id` added back in since
9
+ * these admin routes are not scoped to "the current session's own user" the
10
+ * way `/v1/me` is.
11
+ */
12
+ /** Environment context required by every user sub-resource route. */
13
+ export declare const userSubresourceQuerySchema: z.ZodObject<{
14
+ environment_id: z.ZodString;
15
+ }, z.core.$strict>;
16
+ export type UserSubresourceQuery = z.infer<typeof userSubresourceQuerySchema>;
17
+ export declare const userIdentitySchema: z.ZodObject<{
18
+ identity_id: z.ZodString;
19
+ user_id: z.ZodString;
20
+ provider: z.ZodEnum<{
21
+ google: "google";
22
+ apple: "apple";
23
+ github: "github";
24
+ microsoft: "microsoft";
25
+ generic_oidc: "generic_oidc";
26
+ }>;
27
+ linked_at: z.ZodISODateTime;
28
+ last_used_at: z.ZodNullable<z.ZodISODateTime>;
29
+ }, z.core.$strict>;
30
+ export type UserIdentity = z.infer<typeof userIdentitySchema>;
31
+ export declare const userIdentityListQuerySchema: z.ZodObject<{
32
+ cursor: z.ZodOptional<z.ZodString>;
33
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
34
+ environment_id: z.ZodString;
35
+ }, z.core.$strip>;
36
+ export type UserIdentityListQuery = z.infer<typeof userIdentityListQuerySchema>;
37
+ export declare const userIdentityListResponseSchema: z.ZodObject<{
38
+ items: z.ZodArray<z.ZodObject<{
39
+ identity_id: z.ZodString;
40
+ user_id: z.ZodString;
41
+ provider: z.ZodEnum<{
42
+ google: "google";
43
+ apple: "apple";
44
+ github: "github";
45
+ microsoft: "microsoft";
46
+ generic_oidc: "generic_oidc";
47
+ }>;
48
+ linked_at: z.ZodISODateTime;
49
+ last_used_at: z.ZodNullable<z.ZodISODateTime>;
50
+ }, z.core.$strict>>;
51
+ next_cursor: z.ZodNullable<z.ZodString>;
52
+ }, z.core.$strict>;
53
+ export type UserIdentityListResponse = z.infer<typeof userIdentityListResponseSchema>;
54
+ export declare const userIdentityDeleteResponseSchema: z.ZodObject<{
55
+ identity_id: z.ZodString;
56
+ deleted: z.ZodLiteral<true>;
57
+ }, z.core.$strict>;
58
+ export type UserIdentityDeleteResponse = z.infer<typeof userIdentityDeleteResponseSchema>;
59
+ export declare const PASSKEY_DEVICE_TYPES: readonly ["single_device", "multi_device"];
60
+ export declare const passkeyDeviceTypeSchema: z.ZodEnum<{
61
+ single_device: "single_device";
62
+ multi_device: "multi_device";
63
+ }>;
64
+ export type PasskeyDeviceType = (typeof PASSKEY_DEVICE_TYPES)[number];
65
+ export declare const userPasskeySchema: z.ZodObject<{
66
+ passkey_id: z.ZodString;
67
+ user_id: z.ZodString;
68
+ name: z.ZodNullable<z.ZodString>;
69
+ created_at: z.ZodISODateTime;
70
+ last_used_at: z.ZodNullable<z.ZodISODateTime>;
71
+ device_type: z.ZodNullable<z.ZodEnum<{
72
+ single_device: "single_device";
73
+ multi_device: "multi_device";
74
+ }>>;
75
+ backed_up: z.ZodBoolean;
76
+ transports: z.ZodOptional<z.ZodArray<z.ZodEnum<{
77
+ ble: "ble";
78
+ hybrid: "hybrid";
79
+ internal: "internal";
80
+ nfc: "nfc";
81
+ usb: "usb";
82
+ }>>>;
83
+ }, z.core.$strict>;
84
+ export type UserPasskey = z.infer<typeof userPasskeySchema>;
85
+ export declare const userPasskeyListQuerySchema: z.ZodObject<{
86
+ cursor: z.ZodOptional<z.ZodString>;
87
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
88
+ environment_id: z.ZodString;
89
+ }, z.core.$strip>;
90
+ export type UserPasskeyListQuery = z.infer<typeof userPasskeyListQuerySchema>;
91
+ export declare const userPasskeyListResponseSchema: z.ZodObject<{
92
+ items: z.ZodArray<z.ZodObject<{
93
+ passkey_id: z.ZodString;
94
+ user_id: z.ZodString;
95
+ name: z.ZodNullable<z.ZodString>;
96
+ created_at: z.ZodISODateTime;
97
+ last_used_at: z.ZodNullable<z.ZodISODateTime>;
98
+ device_type: z.ZodNullable<z.ZodEnum<{
99
+ single_device: "single_device";
100
+ multi_device: "multi_device";
101
+ }>>;
102
+ backed_up: z.ZodBoolean;
103
+ transports: z.ZodOptional<z.ZodArray<z.ZodEnum<{
104
+ ble: "ble";
105
+ hybrid: "hybrid";
106
+ internal: "internal";
107
+ nfc: "nfc";
108
+ usb: "usb";
109
+ }>>>;
110
+ }, z.core.$strict>>;
111
+ next_cursor: z.ZodNullable<z.ZodString>;
112
+ }, z.core.$strict>;
113
+ export type UserPasskeyListResponse = z.infer<typeof userPasskeyListResponseSchema>;
114
+ export declare const userPasskeyDeleteResponseSchema: z.ZodObject<{
115
+ passkey_id: z.ZodString;
116
+ deleted: z.ZodLiteral<true>;
117
+ }, z.core.$strict>;
118
+ export type UserPasskeyDeleteResponse = z.infer<typeof userPasskeyDeleteResponseSchema>;
119
+ export declare const userSessionSchema: z.ZodObject<{
120
+ session_id: z.ZodString;
121
+ user_id: z.ZodString;
122
+ client_id: z.ZodString;
123
+ device_name: z.ZodNullable<z.ZodString>;
124
+ created_at: z.ZodISODateTime;
125
+ last_active_at: z.ZodISODateTime;
126
+ idle_expires_at: z.ZodISODateTime;
127
+ absolute_expires_at: z.ZodISODateTime;
128
+ revoked_at: z.ZodNullable<z.ZodISODateTime>;
129
+ }, z.core.$strict>;
130
+ export type UserSession = z.infer<typeof userSessionSchema>;
131
+ export declare const userSessionListQuerySchema: z.ZodObject<{
132
+ cursor: z.ZodOptional<z.ZodString>;
133
+ limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
134
+ environment_id: z.ZodString;
135
+ }, z.core.$strip>;
136
+ export type UserSessionListQuery = z.infer<typeof userSessionListQuerySchema>;
137
+ export declare const userSessionListResponseSchema: z.ZodObject<{
138
+ items: z.ZodArray<z.ZodObject<{
139
+ session_id: z.ZodString;
140
+ user_id: z.ZodString;
141
+ client_id: z.ZodString;
142
+ device_name: z.ZodNullable<z.ZodString>;
143
+ created_at: z.ZodISODateTime;
144
+ last_active_at: z.ZodISODateTime;
145
+ idle_expires_at: z.ZodISODateTime;
146
+ absolute_expires_at: z.ZodISODateTime;
147
+ revoked_at: z.ZodNullable<z.ZodISODateTime>;
148
+ }, z.core.$strict>>;
149
+ next_cursor: z.ZodNullable<z.ZodString>;
150
+ }, z.core.$strict>;
151
+ export type UserSessionListResponse = z.infer<typeof userSessionListResponseSchema>;
152
+ export declare const userSessionRevokeResponseSchema: z.ZodObject<{
153
+ session_id: z.ZodString;
154
+ revoked: z.ZodLiteral<true>;
155
+ }, z.core.$strict>;
156
+ export type UserSessionRevokeResponse = z.infer<typeof userSessionRevokeResponseSchema>;
157
+ /** design.md §24.3: revoking all of a user's sessions bumps `UserSecurityDO.securityVersion`. */
158
+ export declare const userSessionsRevokeAllResponseSchema: z.ZodObject<{
159
+ revoked: z.ZodLiteral<true>;
160
+ }, z.core.$strict>;
161
+ export type UserSessionsRevokeAllResponse = z.infer<typeof userSessionsRevokeAllResponseSchema>;
@@ -0,0 +1,85 @@
1
+ import { socialProviderSchema } from "@smartcrab/contracts-public";
2
+ import { z } from "zod";
3
+ import { cursorPageSchema, paginationQuerySchema } from "./common.js";
4
+ import { clientIdSchema, environmentIdSchema, identityIdSchema, passkeyIdSchema, sessionIdSchema, userIdSchema, } from "./primitives.js";
5
+ /**
6
+ * Admin-facing projections of a user's sub-resources: `identities` (design.md
7
+ * §12.3), `passkeys` (§12.5), `sessions` (§12.4). Same exclusions as
8
+ * `@smartcrab/contracts-public`'s `/v1/me` sub-resource schemas
9
+ * (`provider_subject`, `profile_json`, token ciphertexts, `credential_id`,
10
+ * `public_key`, `sign_count`, `token_mac` (assignment's forbidden list),
11
+ * `ip_prefix_hash`/`user_agent_hash`), plus `user_id` added back in since
12
+ * these admin routes are not scoped to "the current session's own user" the
13
+ * way `/v1/me` is.
14
+ */
15
+ /** Environment context required by every user sub-resource route. */
16
+ export const userSubresourceQuerySchema = z.strictObject({
17
+ environment_id: environmentIdSchema,
18
+ });
19
+ const userSubresourceListQuerySchema = paginationQuerySchema.extend({
20
+ environment_id: environmentIdSchema,
21
+ });
22
+ // ---------------------------------------------------------------------------
23
+ // GET /users/:userId/identities, DELETE /users/:userId/identities/:identityId
24
+ // ---------------------------------------------------------------------------
25
+ export const userIdentitySchema = z.strictObject({
26
+ identity_id: identityIdSchema,
27
+ user_id: userIdSchema,
28
+ provider: socialProviderSchema,
29
+ linked_at: z.iso.datetime(),
30
+ last_used_at: z.iso.datetime().nullable(),
31
+ });
32
+ export const userIdentityListQuerySchema = userSubresourceListQuerySchema;
33
+ export const userIdentityListResponseSchema = cursorPageSchema(userIdentitySchema);
34
+ export const userIdentityDeleteResponseSchema = z.strictObject({
35
+ identity_id: identityIdSchema,
36
+ deleted: z.literal(true),
37
+ });
38
+ // ---------------------------------------------------------------------------
39
+ // GET /users/:userId/passkeys, DELETE /users/:userId/passkeys/:passkeyId
40
+ // ---------------------------------------------------------------------------
41
+ const AUTHENTICATOR_TRANSPORTS = ["ble", "hybrid", "internal", "nfc", "usb"];
42
+ const authenticatorTransportSchema = z.enum(AUTHENTICATOR_TRANSPORTS);
43
+ export const PASSKEY_DEVICE_TYPES = ["single_device", "multi_device"];
44
+ export const passkeyDeviceTypeSchema = z.enum(PASSKEY_DEVICE_TYPES);
45
+ export const userPasskeySchema = z.strictObject({
46
+ passkey_id: passkeyIdSchema,
47
+ user_id: userIdSchema,
48
+ name: z.string().nullable(),
49
+ created_at: z.iso.datetime(),
50
+ last_used_at: z.iso.datetime().nullable(),
51
+ device_type: passkeyDeviceTypeSchema.nullable(),
52
+ backed_up: z.boolean(),
53
+ transports: z.array(authenticatorTransportSchema).optional(),
54
+ });
55
+ export const userPasskeyListQuerySchema = userSubresourceListQuerySchema;
56
+ export const userPasskeyListResponseSchema = cursorPageSchema(userPasskeySchema);
57
+ export const userPasskeyDeleteResponseSchema = z.strictObject({
58
+ passkey_id: passkeyIdSchema,
59
+ deleted: z.literal(true),
60
+ });
61
+ // ---------------------------------------------------------------------------
62
+ // GET /users/:userId/sessions, DELETE /users/:userId/sessions/:sessionId,
63
+ // DELETE /users/:userId/sessions
64
+ // ---------------------------------------------------------------------------
65
+ export const userSessionSchema = z.strictObject({
66
+ session_id: sessionIdSchema,
67
+ user_id: userIdSchema,
68
+ client_id: clientIdSchema,
69
+ device_name: z.string().nullable(),
70
+ created_at: z.iso.datetime(),
71
+ last_active_at: z.iso.datetime(),
72
+ idle_expires_at: z.iso.datetime(),
73
+ absolute_expires_at: z.iso.datetime(),
74
+ revoked_at: z.iso.datetime().nullable(),
75
+ });
76
+ export const userSessionListQuerySchema = userSubresourceListQuerySchema;
77
+ export const userSessionListResponseSchema = cursorPageSchema(userSessionSchema);
78
+ export const userSessionRevokeResponseSchema = z.strictObject({
79
+ session_id: sessionIdSchema,
80
+ revoked: z.literal(true),
81
+ });
82
+ /** design.md §24.3: revoking all of a user's sessions bumps `UserSecurityDO.securityVersion`. */
83
+ export const userSessionsRevokeAllResponseSchema = z.strictObject({
84
+ revoked: z.literal(true),
85
+ });