@smartcrab/contracts-management 0.3.2 → 0.4.0-next-20261016193833
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/api-keys.d.ts +8 -0
- package/dist/billing-notifications.d.ts +83 -0
- package/dist/billing-notifications.js +42 -0
- package/dist/dlq.d.ts +188 -0
- package/dist/dlq.js +104 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/rbac.d.ts +27 -6
- package/dist/rbac.js +42 -5
- package/dist/user-recovery.d.ts +12 -0
- package/dist/user-recovery.js +10 -0
- package/package.json +2 -2
- package/src/billing-notifications.test.ts +44 -0
- package/src/billing-notifications.ts +51 -0
- package/src/dlq.ts +126 -0
- package/src/index.ts +3 -0
- package/src/rbac.test.ts +15 -1
- package/src/rbac.ts +49 -5
- package/src/user-recovery.ts +16 -0
package/dist/api-keys.d.ts
CHANGED
|
@@ -63,6 +63,8 @@ export declare const managementApiKeySchema: z.ZodObject<{
|
|
|
63
63
|
"webhooks:write": "webhooks:write";
|
|
64
64
|
"webhooks:rotate_secret": "webhooks:rotate_secret";
|
|
65
65
|
"webhooks:test": "webhooks:test";
|
|
66
|
+
"dlq:read": "dlq:read";
|
|
67
|
+
"dlq:write": "dlq:write";
|
|
66
68
|
"audit_events:read": "audit_events:read";
|
|
67
69
|
"usage:read": "usage:read";
|
|
68
70
|
introspect: "introspect";
|
|
@@ -124,6 +126,8 @@ export declare const managementApiKeyListResponseSchema: z.ZodObject<{
|
|
|
124
126
|
"webhooks:write": "webhooks:write";
|
|
125
127
|
"webhooks:rotate_secret": "webhooks:rotate_secret";
|
|
126
128
|
"webhooks:test": "webhooks:test";
|
|
129
|
+
"dlq:read": "dlq:read";
|
|
130
|
+
"dlq:write": "dlq:write";
|
|
127
131
|
"audit_events:read": "audit_events:read";
|
|
128
132
|
"usage:read": "usage:read";
|
|
129
133
|
introspect: "introspect";
|
|
@@ -176,6 +180,8 @@ export declare const managementApiKeyCreateRequestSchema: z.ZodObject<{
|
|
|
176
180
|
"webhooks:write": "webhooks:write";
|
|
177
181
|
"webhooks:rotate_secret": "webhooks:rotate_secret";
|
|
178
182
|
"webhooks:test": "webhooks:test";
|
|
183
|
+
"dlq:read": "dlq:read";
|
|
184
|
+
"dlq:write": "dlq:write";
|
|
179
185
|
"audit_events:read": "audit_events:read";
|
|
180
186
|
"usage:read": "usage:read";
|
|
181
187
|
introspect: "introspect";
|
|
@@ -227,6 +233,8 @@ export declare const managementApiKeyCreateResponseSchema: z.ZodObject<{
|
|
|
227
233
|
"webhooks:write": "webhooks:write";
|
|
228
234
|
"webhooks:rotate_secret": "webhooks:rotate_secret";
|
|
229
235
|
"webhooks:test": "webhooks:test";
|
|
236
|
+
"dlq:read": "dlq:read";
|
|
237
|
+
"dlq:write": "dlq:write";
|
|
230
238
|
"audit_events:read": "audit_events:read";
|
|
231
239
|
"usage:read": "usage:read";
|
|
232
240
|
introspect: "introspect";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const billingNotificationKindSchema: z.ZodEnum<{
|
|
3
|
+
mau_threshold_reached: "mau_threshold_reached";
|
|
4
|
+
grace_period_started: "grace_period_started";
|
|
5
|
+
grace_period_expired: "grace_period_expired";
|
|
6
|
+
payment_failed: "payment_failed";
|
|
7
|
+
payment_recovered: "payment_recovered";
|
|
8
|
+
payment_restricted_new_users: "payment_restricted_new_users";
|
|
9
|
+
payment_restricted_config: "payment_restricted_config";
|
|
10
|
+
}>;
|
|
11
|
+
/** Non-secret rendering data persisted in the workspace billing inbox. */
|
|
12
|
+
export declare const billingNotificationPayloadSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
13
|
+
kind: z.ZodLiteral<"mau_threshold_reached">;
|
|
14
|
+
billingMonth: z.ZodString;
|
|
15
|
+
thresholdPercent: z.ZodUnion<readonly [z.ZodLiteral<80>, z.ZodLiteral<95>, z.ZodLiteral<100>]>;
|
|
16
|
+
currentMau: z.ZodNumber;
|
|
17
|
+
freeTierLimit: z.ZodNumber;
|
|
18
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
19
|
+
kind: z.ZodLiteral<"grace_period_started">;
|
|
20
|
+
graceEndsAt: z.ZodISODateTime;
|
|
21
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
22
|
+
kind: z.ZodLiteral<"grace_period_expired">;
|
|
23
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
24
|
+
kind: z.ZodLiteral<"payment_failed">;
|
|
25
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
26
|
+
kind: z.ZodLiteral<"payment_recovered">;
|
|
27
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
28
|
+
kind: z.ZodLiteral<"payment_restricted_new_users">;
|
|
29
|
+
daysPastDue: z.ZodLiteral<14>;
|
|
30
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
31
|
+
kind: z.ZodLiteral<"payment_restricted_config">;
|
|
32
|
+
daysPastDue: z.ZodLiteral<30>;
|
|
33
|
+
}, z.core.$strict>], "kind">;
|
|
34
|
+
export type BillingNotificationPayload = z.infer<typeof billingNotificationPayloadSchema>;
|
|
35
|
+
/** Legacy rows have null payload fields and remain renderable by kind and timestamp. */
|
|
36
|
+
export declare const billingNotificationSchema: z.ZodObject<{
|
|
37
|
+
notification_key: z.ZodString;
|
|
38
|
+
kind: z.ZodEnum<{
|
|
39
|
+
mau_threshold_reached: "mau_threshold_reached";
|
|
40
|
+
grace_period_started: "grace_period_started";
|
|
41
|
+
grace_period_expired: "grace_period_expired";
|
|
42
|
+
payment_failed: "payment_failed";
|
|
43
|
+
payment_recovered: "payment_recovered";
|
|
44
|
+
payment_restricted_new_users: "payment_restricted_new_users";
|
|
45
|
+
payment_restricted_config: "payment_restricted_config";
|
|
46
|
+
}>;
|
|
47
|
+
billing_month: z.ZodNullable<z.ZodString>;
|
|
48
|
+
threshold_percent: z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<80>, z.ZodLiteral<95>, z.ZodLiteral<100>]>>;
|
|
49
|
+
current_mau: z.ZodNullable<z.ZodNumber>;
|
|
50
|
+
free_tier_limit: z.ZodNullable<z.ZodNumber>;
|
|
51
|
+
grace_ends_at: z.ZodNullable<z.ZodISODateTime>;
|
|
52
|
+
restriction_days: z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<14>, z.ZodLiteral<30>]>>;
|
|
53
|
+
created_at: z.ZodISODateTime;
|
|
54
|
+
}, z.core.$strict>;
|
|
55
|
+
export type BillingNotification = z.infer<typeof billingNotificationSchema>;
|
|
56
|
+
export declare const billingNotificationListQuerySchema: z.ZodObject<{
|
|
57
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
58
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
59
|
+
}, z.core.$strip>;
|
|
60
|
+
export type BillingNotificationListQuery = z.infer<typeof billingNotificationListQuerySchema>;
|
|
61
|
+
export declare const billingNotificationListResponseSchema: z.ZodObject<{
|
|
62
|
+
items: z.ZodArray<z.ZodObject<{
|
|
63
|
+
notification_key: z.ZodString;
|
|
64
|
+
kind: z.ZodEnum<{
|
|
65
|
+
mau_threshold_reached: "mau_threshold_reached";
|
|
66
|
+
grace_period_started: "grace_period_started";
|
|
67
|
+
grace_period_expired: "grace_period_expired";
|
|
68
|
+
payment_failed: "payment_failed";
|
|
69
|
+
payment_recovered: "payment_recovered";
|
|
70
|
+
payment_restricted_new_users: "payment_restricted_new_users";
|
|
71
|
+
payment_restricted_config: "payment_restricted_config";
|
|
72
|
+
}>;
|
|
73
|
+
billing_month: z.ZodNullable<z.ZodString>;
|
|
74
|
+
threshold_percent: z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<80>, z.ZodLiteral<95>, z.ZodLiteral<100>]>>;
|
|
75
|
+
current_mau: z.ZodNullable<z.ZodNumber>;
|
|
76
|
+
free_tier_limit: z.ZodNullable<z.ZodNumber>;
|
|
77
|
+
grace_ends_at: z.ZodNullable<z.ZodISODateTime>;
|
|
78
|
+
restriction_days: z.ZodNullable<z.ZodUnion<readonly [z.ZodLiteral<14>, z.ZodLiteral<30>]>>;
|
|
79
|
+
created_at: z.ZodISODateTime;
|
|
80
|
+
}, z.core.$strict>>;
|
|
81
|
+
next_cursor: z.ZodNullable<z.ZodString>;
|
|
82
|
+
}, z.core.$strict>;
|
|
83
|
+
export type BillingNotificationListResponse = z.infer<typeof billingNotificationListResponseSchema>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { cursorPageSchema, paginationQuerySchema } from "./common.js";
|
|
3
|
+
import { billingMonthSchema, mauThresholdLevelSchema } from "./usage.js";
|
|
4
|
+
export const billingNotificationKindSchema = z.enum([
|
|
5
|
+
"mau_threshold_reached",
|
|
6
|
+
"grace_period_started",
|
|
7
|
+
"grace_period_expired",
|
|
8
|
+
"payment_failed",
|
|
9
|
+
"payment_recovered",
|
|
10
|
+
"payment_restricted_new_users",
|
|
11
|
+
"payment_restricted_config",
|
|
12
|
+
]);
|
|
13
|
+
/** Non-secret rendering data persisted in the workspace billing inbox. */
|
|
14
|
+
export const billingNotificationPayloadSchema = z.discriminatedUnion("kind", [
|
|
15
|
+
z.strictObject({
|
|
16
|
+
kind: z.literal("mau_threshold_reached"),
|
|
17
|
+
billingMonth: billingMonthSchema,
|
|
18
|
+
thresholdPercent: mauThresholdLevelSchema,
|
|
19
|
+
currentMau: z.number().int().nonnegative(),
|
|
20
|
+
freeTierLimit: z.number().int().positive(),
|
|
21
|
+
}),
|
|
22
|
+
z.strictObject({ kind: z.literal("grace_period_started"), graceEndsAt: z.iso.datetime() }),
|
|
23
|
+
z.strictObject({ kind: z.literal("grace_period_expired") }),
|
|
24
|
+
z.strictObject({ kind: z.literal("payment_failed") }),
|
|
25
|
+
z.strictObject({ kind: z.literal("payment_recovered") }),
|
|
26
|
+
z.strictObject({ kind: z.literal("payment_restricted_new_users"), daysPastDue: z.literal(14) }),
|
|
27
|
+
z.strictObject({ kind: z.literal("payment_restricted_config"), daysPastDue: z.literal(30) }),
|
|
28
|
+
]);
|
|
29
|
+
/** Legacy rows have null payload fields and remain renderable by kind and timestamp. */
|
|
30
|
+
export const billingNotificationSchema = z.strictObject({
|
|
31
|
+
notification_key: z.string().min(1).max(255),
|
|
32
|
+
kind: billingNotificationKindSchema,
|
|
33
|
+
billing_month: billingMonthSchema.nullable(),
|
|
34
|
+
threshold_percent: mauThresholdLevelSchema.nullable(),
|
|
35
|
+
current_mau: z.number().int().nonnegative().nullable(),
|
|
36
|
+
free_tier_limit: z.number().int().positive().nullable(),
|
|
37
|
+
grace_ends_at: z.iso.datetime().nullable(),
|
|
38
|
+
restriction_days: z.union([z.literal(14), z.literal(30)]).nullable(),
|
|
39
|
+
created_at: z.iso.datetime(),
|
|
40
|
+
});
|
|
41
|
+
export const billingNotificationListQuerySchema = paginationQuerySchema;
|
|
42
|
+
export const billingNotificationListResponseSchema = cursorPageSchema(billingNotificationSchema);
|
package/dist/dlq.d.ts
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dead-letter queue (DLQ) records (design.md §29.3: "DLQはDashboardから閲覧・
|
|
3
|
+
* 再送できる"). A record is one message that exhausted its queue's retries (or
|
|
4
|
+
* was rejected by its consumer) and was written to the workspace's DLQ store.
|
|
5
|
+
*
|
|
6
|
+
* Read: `GET /dlq/records`, `GET /dlq/records/:recordId` (payload redacted per
|
|
7
|
+
* design.md §32.6). Write: `POST /dlq/records/:recordId/redrive` re-sends the
|
|
8
|
+
* original message to its source queue with the original event id, so the
|
|
9
|
+
* consumer's dedupe (design.md §29.3) suppresses any second successful
|
|
10
|
+
* customer delivery.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
/** Logical source queues a dead-letter record can belong to (design.md §29.1). */
|
|
14
|
+
export declare const DLQ_QUEUES: readonly ["auth-events", "billing-events", "webhook-deliveries", "audit-events", "email-service-events", "outbox-recovery"];
|
|
15
|
+
export declare const dlqQueueSchema: z.ZodEnum<{
|
|
16
|
+
"auth-events": "auth-events";
|
|
17
|
+
"billing-events": "billing-events";
|
|
18
|
+
"webhook-deliveries": "webhook-deliveries";
|
|
19
|
+
"audit-events": "audit-events";
|
|
20
|
+
"email-service-events": "email-service-events";
|
|
21
|
+
"outbox-recovery": "outbox-recovery";
|
|
22
|
+
}>;
|
|
23
|
+
export type DlqQueue = z.infer<typeof dlqQueueSchema>;
|
|
24
|
+
/** Opaque record id: `dlq_` + base64url(`<queue>/<eventKey>`). Not a secret: tenancy is enforced server-side. */
|
|
25
|
+
export declare const dlqRecordIdSchema: z.ZodString;
|
|
26
|
+
/**
|
|
27
|
+
* Lifecycle as shown to operators. `dead_lettered`: never re-driven (or a
|
|
28
|
+
* failed re-drive was released). `redriving`: a re-drive holds the record's
|
|
29
|
+
* lease. `redriven`: a re-drive completed (see `redrive_outcome`).
|
|
30
|
+
*/
|
|
31
|
+
export declare const DLQ_RECORD_STATUSES: readonly ["dead_lettered", "redriving", "redriven"];
|
|
32
|
+
export declare const dlqRecordStatusSchema: z.ZodEnum<{
|
|
33
|
+
dead_lettered: "dead_lettered";
|
|
34
|
+
redriving: "redriving";
|
|
35
|
+
redriven: "redriven";
|
|
36
|
+
}>;
|
|
37
|
+
export type DlqRecordStatus = z.infer<typeof dlqRecordStatusSchema>;
|
|
38
|
+
/** How a completed re-drive resolved (design.md §29.4: delivered events are never re-sent). */
|
|
39
|
+
export declare const DLQ_REDRIVE_OUTCOMES: readonly ["enqueued", "already_delivered"];
|
|
40
|
+
export declare const dlqRedriveOutcomeSchema: z.ZodEnum<{
|
|
41
|
+
enqueued: "enqueued";
|
|
42
|
+
already_delivered: "already_delivered";
|
|
43
|
+
}>;
|
|
44
|
+
export type DlqRedriveOutcome = z.infer<typeof dlqRedriveOutcomeSchema>;
|
|
45
|
+
export declare const dlqRecordListQuerySchema: z.ZodObject<{
|
|
46
|
+
cursor: z.ZodOptional<z.ZodString>;
|
|
47
|
+
limit: z.ZodDefault<z.ZodCoercedNumber<unknown>>;
|
|
48
|
+
queue: z.ZodOptional<z.ZodEnum<{
|
|
49
|
+
"auth-events": "auth-events";
|
|
50
|
+
"billing-events": "billing-events";
|
|
51
|
+
"webhook-deliveries": "webhook-deliveries";
|
|
52
|
+
"audit-events": "audit-events";
|
|
53
|
+
"email-service-events": "email-service-events";
|
|
54
|
+
"outbox-recovery": "outbox-recovery";
|
|
55
|
+
}>>;
|
|
56
|
+
event_type: z.ZodOptional<z.ZodString>;
|
|
57
|
+
environment_id: z.ZodOptional<z.ZodString>;
|
|
58
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
59
|
+
dead_lettered: "dead_lettered";
|
|
60
|
+
redriving: "redriving";
|
|
61
|
+
redriven: "redriven";
|
|
62
|
+
}>>;
|
|
63
|
+
failed_after: z.ZodOptional<z.ZodISODateTime>;
|
|
64
|
+
failed_before: z.ZodOptional<z.ZodISODateTime>;
|
|
65
|
+
}, z.core.$strip>;
|
|
66
|
+
export type DlqRecordListQuery = z.infer<typeof dlqRecordListQuerySchema>;
|
|
67
|
+
export declare const dlqRecordSchema: z.ZodObject<{
|
|
68
|
+
id: z.ZodString;
|
|
69
|
+
queue: z.ZodEnum<{
|
|
70
|
+
"auth-events": "auth-events";
|
|
71
|
+
"billing-events": "billing-events";
|
|
72
|
+
"webhook-deliveries": "webhook-deliveries";
|
|
73
|
+
"audit-events": "audit-events";
|
|
74
|
+
"email-service-events": "email-service-events";
|
|
75
|
+
"outbox-recovery": "outbox-recovery";
|
|
76
|
+
}>;
|
|
77
|
+
event_id: z.ZodNullable<z.ZodString>;
|
|
78
|
+
event_type: z.ZodNullable<z.ZodString>;
|
|
79
|
+
webhook_id: z.ZodNullable<z.ZodString>;
|
|
80
|
+
environment_id: z.ZodNullable<z.ZodString>;
|
|
81
|
+
attempts: z.ZodNumber;
|
|
82
|
+
failed_at: z.ZodISODateTime;
|
|
83
|
+
status: z.ZodEnum<{
|
|
84
|
+
dead_lettered: "dead_lettered";
|
|
85
|
+
redriving: "redriving";
|
|
86
|
+
redriven: "redriven";
|
|
87
|
+
}>;
|
|
88
|
+
redriven_at: z.ZodNullable<z.ZodISODateTime>;
|
|
89
|
+
redrive_outcome: z.ZodNullable<z.ZodEnum<{
|
|
90
|
+
enqueued: "enqueued";
|
|
91
|
+
already_delivered: "already_delivered";
|
|
92
|
+
}>>;
|
|
93
|
+
}, z.core.$strict>;
|
|
94
|
+
export type DlqRecord = z.infer<typeof dlqRecordSchema>;
|
|
95
|
+
export declare const dlqRecordListResponseSchema: z.ZodObject<{
|
|
96
|
+
items: z.ZodArray<z.ZodObject<{
|
|
97
|
+
id: z.ZodString;
|
|
98
|
+
queue: z.ZodEnum<{
|
|
99
|
+
"auth-events": "auth-events";
|
|
100
|
+
"billing-events": "billing-events";
|
|
101
|
+
"webhook-deliveries": "webhook-deliveries";
|
|
102
|
+
"audit-events": "audit-events";
|
|
103
|
+
"email-service-events": "email-service-events";
|
|
104
|
+
"outbox-recovery": "outbox-recovery";
|
|
105
|
+
}>;
|
|
106
|
+
event_id: z.ZodNullable<z.ZodString>;
|
|
107
|
+
event_type: z.ZodNullable<z.ZodString>;
|
|
108
|
+
webhook_id: z.ZodNullable<z.ZodString>;
|
|
109
|
+
environment_id: z.ZodNullable<z.ZodString>;
|
|
110
|
+
attempts: z.ZodNumber;
|
|
111
|
+
failed_at: z.ZodISODateTime;
|
|
112
|
+
status: z.ZodEnum<{
|
|
113
|
+
dead_lettered: "dead_lettered";
|
|
114
|
+
redriving: "redriving";
|
|
115
|
+
redriven: "redriven";
|
|
116
|
+
}>;
|
|
117
|
+
redriven_at: z.ZodNullable<z.ZodISODateTime>;
|
|
118
|
+
redrive_outcome: z.ZodNullable<z.ZodEnum<{
|
|
119
|
+
enqueued: "enqueued";
|
|
120
|
+
already_delivered: "already_delivered";
|
|
121
|
+
}>>;
|
|
122
|
+
}, z.core.$strict>>;
|
|
123
|
+
next_cursor: z.ZodNullable<z.ZodString>;
|
|
124
|
+
}, z.core.$strict>;
|
|
125
|
+
export type DlqRecordListResponse = z.infer<typeof dlqRecordListResponseSchema>;
|
|
126
|
+
export declare const dlqRecordDetailSchema: z.ZodObject<{
|
|
127
|
+
id: z.ZodString;
|
|
128
|
+
queue: z.ZodEnum<{
|
|
129
|
+
"auth-events": "auth-events";
|
|
130
|
+
"billing-events": "billing-events";
|
|
131
|
+
"webhook-deliveries": "webhook-deliveries";
|
|
132
|
+
"audit-events": "audit-events";
|
|
133
|
+
"email-service-events": "email-service-events";
|
|
134
|
+
"outbox-recovery": "outbox-recovery";
|
|
135
|
+
}>;
|
|
136
|
+
event_id: z.ZodNullable<z.ZodString>;
|
|
137
|
+
event_type: z.ZodNullable<z.ZodString>;
|
|
138
|
+
webhook_id: z.ZodNullable<z.ZodString>;
|
|
139
|
+
environment_id: z.ZodNullable<z.ZodString>;
|
|
140
|
+
attempts: z.ZodNumber;
|
|
141
|
+
failed_at: z.ZodISODateTime;
|
|
142
|
+
status: z.ZodEnum<{
|
|
143
|
+
dead_lettered: "dead_lettered";
|
|
144
|
+
redriving: "redriving";
|
|
145
|
+
redriven: "redriven";
|
|
146
|
+
}>;
|
|
147
|
+
redriven_at: z.ZodNullable<z.ZodISODateTime>;
|
|
148
|
+
redrive_outcome: z.ZodNullable<z.ZodEnum<{
|
|
149
|
+
enqueued: "enqueued";
|
|
150
|
+
already_delivered: "already_delivered";
|
|
151
|
+
}>>;
|
|
152
|
+
payload: z.ZodNullable<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
153
|
+
payload_truncated: z.ZodBoolean;
|
|
154
|
+
redrivable: z.ZodBoolean;
|
|
155
|
+
}, z.core.$strict>;
|
|
156
|
+
export type DlqRecordDetail = z.infer<typeof dlqRecordDetailSchema>;
|
|
157
|
+
/**
|
|
158
|
+
* `enqueued`: the original message was sent to its source queue (HTTP 202).
|
|
159
|
+
* `already_delivered`: the webhook event was already delivered, so nothing was
|
|
160
|
+
* sent (HTTP 200). `already_redriven`: an earlier re-drive already handled this
|
|
161
|
+
* record, so the call is idempotent and sends nothing (HTTP 200).
|
|
162
|
+
*/
|
|
163
|
+
export declare const DLQ_REDRIVE_RESPONSE_OUTCOMES: readonly ["enqueued", "already_delivered", "already_redriven"];
|
|
164
|
+
export declare const dlqRedriveResponseOutcomeSchema: z.ZodEnum<{
|
|
165
|
+
enqueued: "enqueued";
|
|
166
|
+
already_delivered: "already_delivered";
|
|
167
|
+
already_redriven: "already_redriven";
|
|
168
|
+
}>;
|
|
169
|
+
export type DlqRedriveResponseOutcome = z.infer<typeof dlqRedriveResponseOutcomeSchema>;
|
|
170
|
+
export declare const dlqRedriveResponseSchema: z.ZodObject<{
|
|
171
|
+
id: z.ZodString;
|
|
172
|
+
queue: z.ZodEnum<{
|
|
173
|
+
"auth-events": "auth-events";
|
|
174
|
+
"billing-events": "billing-events";
|
|
175
|
+
"webhook-deliveries": "webhook-deliveries";
|
|
176
|
+
"audit-events": "audit-events";
|
|
177
|
+
"email-service-events": "email-service-events";
|
|
178
|
+
"outbox-recovery": "outbox-recovery";
|
|
179
|
+
}>;
|
|
180
|
+
status: z.ZodLiteral<"redriven">;
|
|
181
|
+
outcome: z.ZodEnum<{
|
|
182
|
+
enqueued: "enqueued";
|
|
183
|
+
already_delivered: "already_delivered";
|
|
184
|
+
already_redriven: "already_redriven";
|
|
185
|
+
}>;
|
|
186
|
+
redriven_at: z.ZodISODateTime;
|
|
187
|
+
}, z.core.$strict>;
|
|
188
|
+
export type DlqRedriveResponse = z.infer<typeof dlqRedriveResponseSchema>;
|
package/dist/dlq.js
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dead-letter queue (DLQ) records (design.md §29.3: "DLQはDashboardから閲覧・
|
|
3
|
+
* 再送できる"). A record is one message that exhausted its queue's retries (or
|
|
4
|
+
* was rejected by its consumer) and was written to the workspace's DLQ store.
|
|
5
|
+
*
|
|
6
|
+
* Read: `GET /dlq/records`, `GET /dlq/records/:recordId` (payload redacted per
|
|
7
|
+
* design.md §32.6). Write: `POST /dlq/records/:recordId/redrive` re-sends the
|
|
8
|
+
* original message to its source queue with the original event id, so the
|
|
9
|
+
* consumer's dedupe (design.md §29.3) suppresses any second successful
|
|
10
|
+
* customer delivery.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { cursorPageSchema, paginationQuerySchema } from "./common.js";
|
|
14
|
+
import { environmentIdSchema } from "./primitives.js";
|
|
15
|
+
/** Logical source queues a dead-letter record can belong to (design.md §29.1). */
|
|
16
|
+
export const DLQ_QUEUES = [
|
|
17
|
+
"auth-events",
|
|
18
|
+
"billing-events",
|
|
19
|
+
"webhook-deliveries",
|
|
20
|
+
"audit-events",
|
|
21
|
+
"email-service-events",
|
|
22
|
+
"outbox-recovery",
|
|
23
|
+
];
|
|
24
|
+
export const dlqQueueSchema = z.enum(DLQ_QUEUES);
|
|
25
|
+
/** Opaque record id: `dlq_` + base64url(`<queue>/<eventKey>`). Not a secret: tenancy is enforced server-side. */
|
|
26
|
+
export const dlqRecordIdSchema = z.string().regex(/^dlq_[A-Za-z0-9_-]{1,2048}$/);
|
|
27
|
+
/**
|
|
28
|
+
* Lifecycle as shown to operators. `dead_lettered`: never re-driven (or a
|
|
29
|
+
* failed re-drive was released). `redriving`: a re-drive holds the record's
|
|
30
|
+
* lease. `redriven`: a re-drive completed (see `redrive_outcome`).
|
|
31
|
+
*/
|
|
32
|
+
export const DLQ_RECORD_STATUSES = ["dead_lettered", "redriving", "redriven"];
|
|
33
|
+
export const dlqRecordStatusSchema = z.enum(DLQ_RECORD_STATUSES);
|
|
34
|
+
/** How a completed re-drive resolved (design.md §29.4: delivered events are never re-sent). */
|
|
35
|
+
export const DLQ_REDRIVE_OUTCOMES = ["enqueued", "already_delivered"];
|
|
36
|
+
export const dlqRedriveOutcomeSchema = z.enum(DLQ_REDRIVE_OUTCOMES);
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
// GET /dlq/records
|
|
39
|
+
// ---------------------------------------------------------------------------
|
|
40
|
+
export const dlqRecordListQuerySchema = paginationQuerySchema.extend({
|
|
41
|
+
queue: dlqQueueSchema.optional(),
|
|
42
|
+
/** Exact domain event type (e.g. `user.created`). */
|
|
43
|
+
event_type: z.string().min(1).max(64).optional(),
|
|
44
|
+
/** Only records of this Environment; workspace-level records are excluded. */
|
|
45
|
+
environment_id: environmentIdSchema.optional(),
|
|
46
|
+
status: dlqRecordStatusSchema.optional(),
|
|
47
|
+
failed_after: z.iso.datetime().optional(),
|
|
48
|
+
failed_before: z.iso.datetime().optional(),
|
|
49
|
+
});
|
|
50
|
+
export const dlqRecordSchema = z.strictObject({
|
|
51
|
+
id: dlqRecordIdSchema,
|
|
52
|
+
queue: dlqQueueSchema,
|
|
53
|
+
/** Domain event id (`evt_...`), when the message carried one. */
|
|
54
|
+
event_id: z.string().nullable(),
|
|
55
|
+
event_type: z.string().nullable(),
|
|
56
|
+
/** Webhook endpoint the delivery targeted (`webhook-deliveries` only). */
|
|
57
|
+
webhook_id: z.string().nullable(),
|
|
58
|
+
environment_id: z.string().nullable(),
|
|
59
|
+
/** Attempts the platform made before dead-lettering. */
|
|
60
|
+
attempts: z.number().int().nonnegative(),
|
|
61
|
+
failed_at: z.iso.datetime(),
|
|
62
|
+
status: dlqRecordStatusSchema,
|
|
63
|
+
redriven_at: z.iso.datetime().nullable(),
|
|
64
|
+
redrive_outcome: dlqRedriveOutcomeSchema.nullable(),
|
|
65
|
+
});
|
|
66
|
+
export const dlqRecordListResponseSchema = cursorPageSchema(dlqRecordSchema);
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
// GET /dlq/records/:recordId
|
|
69
|
+
// ---------------------------------------------------------------------------
|
|
70
|
+
export const dlqRecordDetailSchema = dlqRecordSchema.extend({
|
|
71
|
+
/**
|
|
72
|
+
* The original message body with secrets masked (design.md §32.6: OTP,
|
|
73
|
+
* token, cookie, provider secret, private key, full email, authorization
|
|
74
|
+
* code, raw WebAuthn assertion). `null` when the stored body was truncated
|
|
75
|
+
* or is not a JSON object.
|
|
76
|
+
*/
|
|
77
|
+
payload: z.record(z.string(), z.unknown()).nullable(),
|
|
78
|
+
/** `true` when the stored body was cut at the 64 KiB record cap (design.md §10.9). */
|
|
79
|
+
payload_truncated: z.boolean(),
|
|
80
|
+
/** `true` when the stored body is a complete message this queue can re-drive. */
|
|
81
|
+
redrivable: z.boolean(),
|
|
82
|
+
});
|
|
83
|
+
// ---------------------------------------------------------------------------
|
|
84
|
+
// POST /dlq/records/:recordId/redrive
|
|
85
|
+
// ---------------------------------------------------------------------------
|
|
86
|
+
/**
|
|
87
|
+
* `enqueued`: the original message was sent to its source queue (HTTP 202).
|
|
88
|
+
* `already_delivered`: the webhook event was already delivered, so nothing was
|
|
89
|
+
* sent (HTTP 200). `already_redriven`: an earlier re-drive already handled this
|
|
90
|
+
* record, so the call is idempotent and sends nothing (HTTP 200).
|
|
91
|
+
*/
|
|
92
|
+
export const DLQ_REDRIVE_RESPONSE_OUTCOMES = [
|
|
93
|
+
"enqueued",
|
|
94
|
+
"already_delivered",
|
|
95
|
+
"already_redriven",
|
|
96
|
+
];
|
|
97
|
+
export const dlqRedriveResponseOutcomeSchema = z.enum(DLQ_REDRIVE_RESPONSE_OUTCOMES);
|
|
98
|
+
export const dlqRedriveResponseSchema = z.strictObject({
|
|
99
|
+
id: dlqRecordIdSchema,
|
|
100
|
+
queue: dlqQueueSchema,
|
|
101
|
+
status: z.literal("redriven"),
|
|
102
|
+
outcome: dlqRedriveResponseOutcomeSchema,
|
|
103
|
+
redriven_at: z.iso.datetime(),
|
|
104
|
+
});
|
package/dist/index.d.ts
CHANGED
|
@@ -20,9 +20,12 @@ export * from "./connections.js";
|
|
|
20
20
|
export * from "./domains.js";
|
|
21
21
|
export * from "./users.js";
|
|
22
22
|
export * from "./user-subresources.js";
|
|
23
|
+
export * from "./user-recovery.js";
|
|
23
24
|
export * from "./user-jobs.js";
|
|
24
25
|
export * from "./webhooks.js";
|
|
26
|
+
export * from "./dlq.js";
|
|
25
27
|
export * from "./audit-events.js";
|
|
26
28
|
export * from "./usage.js";
|
|
27
29
|
export * from "./billing.js";
|
|
30
|
+
export * from "./billing-notifications.js";
|
|
28
31
|
export * from "./quotas.js";
|
package/dist/index.js
CHANGED
|
@@ -20,9 +20,12 @@ export * from "./connections.js";
|
|
|
20
20
|
export * from "./domains.js";
|
|
21
21
|
export * from "./users.js";
|
|
22
22
|
export * from "./user-subresources.js";
|
|
23
|
+
export * from "./user-recovery.js";
|
|
23
24
|
export * from "./user-jobs.js";
|
|
24
25
|
export * from "./webhooks.js";
|
|
26
|
+
export * from "./dlq.js";
|
|
25
27
|
export * from "./audit-events.js";
|
|
26
28
|
export * from "./usage.js";
|
|
27
29
|
export * from "./billing.js";
|
|
30
|
+
export * from "./billing-notifications.js";
|
|
28
31
|
export * from "./quotas.js";
|
package/dist/rbac.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export type WorkspaceRole = (typeof WORKSPACE_ROLES)[number];
|
|
|
19
19
|
* standalone. This is the declarative permission vocabulary both Management
|
|
20
20
|
* API keys (design.md §11.12) and dashboard roles (design.md §27.2) use.
|
|
21
21
|
*/
|
|
22
|
-
export declare const MANAGEMENT_SCOPES: readonly ["workspaces:read", "workspaces:write", "workspace_members:read", "projects:read", "projects:write", "environments:read", "environments:write", "clients:read", "clients:write", "clients:rotate_secret", "connections:read", "connections:write", "domains:read", "domains:write", "users:read", "users:write", "users:block", "users:delete", "user_identities:read", "user_identities:write", "user_passkeys:read", "user_passkeys:write", "user_sessions:read", "user_sessions:write", "user_data_jobs:read", "user_data_jobs:write", "webhooks:read", "webhooks:write", "webhooks:rotate_secret", "webhooks:test", "audit_events:read", "usage:read", "introspect", "billing:read", "billing:write", "api_keys:read", "api_keys:write", "impersonation:create"];
|
|
22
|
+
export declare const MANAGEMENT_SCOPES: readonly ["workspaces:read", "workspaces:write", "workspace_members:read", "projects:read", "projects:write", "environments:read", "environments:write", "clients:read", "clients:write", "clients:rotate_secret", "connections:read", "connections:write", "domains:read", "domains:write", "users:read", "users:write", "users:block", "users:delete", "user_identities:read", "user_identities:write", "user_passkeys:read", "user_passkeys:write", "user_sessions:read", "user_sessions:write", "user_data_jobs:read", "user_data_jobs:write", "webhooks:read", "webhooks:write", "webhooks:rotate_secret", "webhooks:test", "dlq:read", "dlq:write", "audit_events:read", "usage:read", "introspect", "billing:read", "billing:write", "api_keys:read", "api_keys:write", "impersonation:create"];
|
|
23
23
|
export declare const managementScopeSchema: z.ZodEnum<{
|
|
24
24
|
"workspaces:read": "workspaces:read";
|
|
25
25
|
"workspaces:write": "workspaces:write";
|
|
@@ -51,6 +51,8 @@ export declare const managementScopeSchema: z.ZodEnum<{
|
|
|
51
51
|
"webhooks:write": "webhooks:write";
|
|
52
52
|
"webhooks:rotate_secret": "webhooks:rotate_secret";
|
|
53
53
|
"webhooks:test": "webhooks:test";
|
|
54
|
+
"dlq:read": "dlq:read";
|
|
55
|
+
"dlq:write": "dlq:write";
|
|
54
56
|
"audit_events:read": "audit_events:read";
|
|
55
57
|
"usage:read": "usage:read";
|
|
56
58
|
introspect: "introspect";
|
|
@@ -91,17 +93,32 @@ export declare const IMPERSONATION_FORBIDDEN_SCOPES: readonly ["user_identities:
|
|
|
91
93
|
* requires a defensible reading of it): granted to owner/admin/support/
|
|
92
94
|
* billing/viewer, withheld from developer. The Developer table lists "Client,
|
|
93
95
|
* Connection, Domain, Webhook" resources, with `introspect` as a standalone
|
|
94
|
-
* OAuth capability for resource-server token validation.
|
|
95
|
-
*
|
|
96
|
-
* role either reads broadly (`viewer`, "読み取りのみ") or
|
|
97
|
-
* its work (`admin` administers the workspace;
|
|
98
|
-
* the workspace's people and billing contacts day to day).
|
|
96
|
+
* OAuth capability for resource-server token validation. `dlq:read` is limited
|
|
97
|
+
* to inspection; `dlq:write` is Owner/Admin-only because redrive covers every
|
|
98
|
+
* source queue. Every other role either reads broadly (`viewer`, "読み取りのみ") or
|
|
99
|
+
* needs the roster for its work (`admin` administers the workspace;
|
|
100
|
+
* `support`/`billing` deal with the workspace's people and billing contacts day to day).
|
|
99
101
|
*/
|
|
100
102
|
export declare const ROLE_SCOPES: Readonly<Record<WorkspaceRole, readonly ManagementScope[]>>;
|
|
101
103
|
export declare const scopesForRole: (role: WorkspaceRole) => readonly ManagementScope[];
|
|
102
104
|
export declare const roleHasScope: (role: WorkspaceRole, scope: ManagementScope) => boolean;
|
|
103
105
|
/** A scope is read-only when it grants inspection without changing a resource or token state. */
|
|
104
106
|
export declare const isReadOnlyScope: (scope: ManagementScope) => boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Scopes whose effect is the Workspace as a whole (Workspace settings, the
|
|
109
|
+
* Project list, Workspace members, billing, starting an impersonation) rather
|
|
110
|
+
* than one Environment's resources. An Environment-pinned Management API key
|
|
111
|
+
* MUST NOT be granted or use these (design.md §11.12: a pinned key is bound to
|
|
112
|
+
* one Environment), and an impersonation session MUST NOT perform them
|
|
113
|
+
* (design.md §27.4).
|
|
114
|
+
*/
|
|
115
|
+
export declare const WORKSPACE_LEVEL_SCOPES: readonly ["workspaces:read", "workspaces:write", "workspace_members:read", "projects:read", "projects:write", "billing:read", "billing:write", "impersonation:create"];
|
|
116
|
+
/**
|
|
117
|
+
* Whether an operation requiring `scope` acts on the Workspace as a whole.
|
|
118
|
+
* Environment creation and unfiltered Environment/usage listings are
|
|
119
|
+
* workspace-level because they have no target Environment.
|
|
120
|
+
*/
|
|
121
|
+
export declare const isWorkspaceLevelOperation: (scope: ManagementScope, targetEnvironmentId: string | undefined) => boolean;
|
|
105
122
|
/** design.md §27.4: "OwnerまたはAdmin" may start an impersonation session. */
|
|
106
123
|
export declare const IMPERSONATION_ALLOWED_ROLES: readonly ["owner", "admin"];
|
|
107
124
|
export declare const impersonationAllowedRoleSchema: z.ZodEnum<{
|
|
@@ -161,6 +178,8 @@ export declare const impersonationSessionSchema: z.ZodObject<{
|
|
|
161
178
|
"webhooks:write": "webhooks:write";
|
|
162
179
|
"webhooks:rotate_secret": "webhooks:rotate_secret";
|
|
163
180
|
"webhooks:test": "webhooks:test";
|
|
181
|
+
"dlq:read": "dlq:read";
|
|
182
|
+
"dlq:write": "dlq:write";
|
|
164
183
|
"audit_events:read": "audit_events:read";
|
|
165
184
|
"usage:read": "usage:read";
|
|
166
185
|
introspect: "introspect";
|
|
@@ -209,6 +228,8 @@ export declare const impersonationCreateResponseSchema: z.ZodObject<{
|
|
|
209
228
|
"webhooks:write": "webhooks:write";
|
|
210
229
|
"webhooks:rotate_secret": "webhooks:rotate_secret";
|
|
211
230
|
"webhooks:test": "webhooks:test";
|
|
231
|
+
"dlq:read": "dlq:read";
|
|
232
|
+
"dlq:write": "dlq:write";
|
|
212
233
|
"audit_events:read": "audit_events:read";
|
|
213
234
|
"usage:read": "usage:read";
|
|
214
235
|
introspect: "introspect";
|
package/dist/rbac.js
CHANGED
|
@@ -57,6 +57,10 @@ export const MANAGEMENT_SCOPES = [
|
|
|
57
57
|
"webhooks:write",
|
|
58
58
|
"webhooks:rotate_secret",
|
|
59
59
|
"webhooks:test",
|
|
60
|
+
// Dead-letter records (design.md §29.3): `dlq:read` lists/reads the DLQ store;
|
|
61
|
+
// `dlq:write` re-drives records from any source queue, including billing and audit.
|
|
62
|
+
"dlq:read",
|
|
63
|
+
"dlq:write",
|
|
60
64
|
"audit_events:read",
|
|
61
65
|
"usage:read",
|
|
62
66
|
// Scoped Management API key permission for POST /oauth2/introspect
|
|
@@ -108,11 +112,11 @@ export const IMPERSONATION_FORBIDDEN_SCOPES = [
|
|
|
108
112
|
* requires a defensible reading of it): granted to owner/admin/support/
|
|
109
113
|
* billing/viewer, withheld from developer. The Developer table lists "Client,
|
|
110
114
|
* Connection, Domain, Webhook" resources, with `introspect` as a standalone
|
|
111
|
-
* OAuth capability for resource-server token validation.
|
|
112
|
-
*
|
|
113
|
-
* role either reads broadly (`viewer`, "読み取りのみ") or
|
|
114
|
-
* its work (`admin` administers the workspace;
|
|
115
|
-
* the workspace's people and billing contacts day to day).
|
|
115
|
+
* OAuth capability for resource-server token validation. `dlq:read` is limited
|
|
116
|
+
* to inspection; `dlq:write` is Owner/Admin-only because redrive covers every
|
|
117
|
+
* source queue. Every other role either reads broadly (`viewer`, "読み取りのみ") or
|
|
118
|
+
* needs the roster for its work (`admin` administers the workspace;
|
|
119
|
+
* `support`/`billing` deal with the workspace's people and billing contacts day to day).
|
|
116
120
|
*/
|
|
117
121
|
export const ROLE_SCOPES = {
|
|
118
122
|
owner: MANAGEMENT_SCOPES,
|
|
@@ -137,6 +141,8 @@ export const ROLE_SCOPES = {
|
|
|
137
141
|
"user_data_jobs:read",
|
|
138
142
|
"user_data_jobs:write",
|
|
139
143
|
"audit_events:read",
|
|
144
|
+
"dlq:read",
|
|
145
|
+
"dlq:write",
|
|
140
146
|
"impersonation:create",
|
|
141
147
|
],
|
|
142
148
|
developer: [
|
|
@@ -152,6 +158,7 @@ export const ROLE_SCOPES = {
|
|
|
152
158
|
"webhooks:write",
|
|
153
159
|
"webhooks:rotate_secret",
|
|
154
160
|
"webhooks:test",
|
|
161
|
+
"dlq:read",
|
|
155
162
|
],
|
|
156
163
|
support: [
|
|
157
164
|
"users:read",
|
|
@@ -182,6 +189,7 @@ export const ROLE_SCOPES = {
|
|
|
182
189
|
"user_sessions:read",
|
|
183
190
|
"user_data_jobs:read",
|
|
184
191
|
"webhooks:read",
|
|
192
|
+
"dlq:read",
|
|
185
193
|
"audit_events:read",
|
|
186
194
|
"usage:read",
|
|
187
195
|
"billing:read",
|
|
@@ -193,6 +201,35 @@ export const roleHasScope = (role, scope) => ROLE_SCOPES[role].includes(scope);
|
|
|
193
201
|
/** A scope is read-only when it grants inspection without changing a resource or token state. */
|
|
194
202
|
export const isReadOnlyScope = (scope) => scope === "introspect" || scope.endsWith(":read");
|
|
195
203
|
// ---------------------------------------------------------------------------
|
|
204
|
+
// Workspace-level vs Environment-level operations (design.md §11.12, §27.4)
|
|
205
|
+
// ---------------------------------------------------------------------------
|
|
206
|
+
/**
|
|
207
|
+
* Scopes whose effect is the Workspace as a whole (Workspace settings, the
|
|
208
|
+
* Project list, Workspace members, billing, starting an impersonation) rather
|
|
209
|
+
* than one Environment's resources. An Environment-pinned Management API key
|
|
210
|
+
* MUST NOT be granted or use these (design.md §11.12: a pinned key is bound to
|
|
211
|
+
* one Environment), and an impersonation session MUST NOT perform them
|
|
212
|
+
* (design.md §27.4).
|
|
213
|
+
*/
|
|
214
|
+
export const WORKSPACE_LEVEL_SCOPES = [
|
|
215
|
+
"workspaces:read",
|
|
216
|
+
"workspaces:write",
|
|
217
|
+
"workspace_members:read",
|
|
218
|
+
"projects:read",
|
|
219
|
+
"projects:write",
|
|
220
|
+
"billing:read",
|
|
221
|
+
"billing:write",
|
|
222
|
+
"impersonation:create",
|
|
223
|
+
];
|
|
224
|
+
/**
|
|
225
|
+
* Whether an operation requiring `scope` acts on the Workspace as a whole.
|
|
226
|
+
* Environment creation and unfiltered Environment/usage listings are
|
|
227
|
+
* workspace-level because they have no target Environment.
|
|
228
|
+
*/
|
|
229
|
+
export const isWorkspaceLevelOperation = (scope, targetEnvironmentId) => WORKSPACE_LEVEL_SCOPES.includes(scope) ||
|
|
230
|
+
(targetEnvironmentId === undefined &&
|
|
231
|
+
(scope === "environments:write" || scope === "environments:read" || scope === "usage:read"));
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
196
233
|
// Impersonation (design.md §27.4)
|
|
197
234
|
// ---------------------------------------------------------------------------
|
|
198
235
|
/** design.md §27.4: "OwnerまたはAdmin" may start an impersonation session. */
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Request to initiate account recovery for an existing user. */
|
|
3
|
+
export declare const userRecoveryRequestSchema: z.ZodObject<{
|
|
4
|
+
reason: z.ZodString;
|
|
5
|
+
}, z.core.$strict>;
|
|
6
|
+
export type UserRecoveryRequest = z.infer<typeof userRecoveryRequestSchema>;
|
|
7
|
+
/** Static, non-sensitive instructions returned after recovery is initiated. */
|
|
8
|
+
export declare const userRecoveryResponseSchema: z.ZodObject<{
|
|
9
|
+
initiated: z.ZodLiteral<true>;
|
|
10
|
+
instructions: z.ZodLiteral<"Sign in using an already-enrolled verified email OTP or linked social identity, then register a new passkey.">;
|
|
11
|
+
}, z.core.$strict>;
|
|
12
|
+
export type UserRecoveryResponse = z.infer<typeof userRecoveryResponseSchema>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Request to initiate account recovery for an existing user. */
|
|
3
|
+
export const userRecoveryRequestSchema = z.strictObject({
|
|
4
|
+
reason: z.string().trim().min(1).max(1000),
|
|
5
|
+
});
|
|
6
|
+
/** Static, non-sensitive instructions returned after recovery is initiated. */
|
|
7
|
+
export const userRecoveryResponseSchema = z.strictObject({
|
|
8
|
+
initiated: z.literal(true),
|
|
9
|
+
instructions: z.literal("Sign in using an already-enrolled verified email OTP or linked social identity, then register a new passkey."),
|
|
10
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartcrab/contracts-management",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0-next-20261016193833",
|
|
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.6.5",
|
|
31
|
-
"@smartcrab/contracts-public": "0.
|
|
31
|
+
"@smartcrab/contracts-public": "0.4.0-next-20261016193833"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"typescript": "5.9.3",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
billingNotificationListResponseSchema,
|
|
4
|
+
billingNotificationPayloadSchema,
|
|
5
|
+
} from "./billing-notifications.js";
|
|
6
|
+
|
|
7
|
+
describe("billing notification inbox contracts", () => {
|
|
8
|
+
test("accepts rendering data without workspace or Stripe identifiers", () => {
|
|
9
|
+
const parsed = billingNotificationPayloadSchema.safeParse({
|
|
10
|
+
kind: "mau_threshold_reached",
|
|
11
|
+
billingMonth: "2026-08",
|
|
12
|
+
thresholdPercent: 95,
|
|
13
|
+
currentMau: 28_500,
|
|
14
|
+
freeTierLimit: 30_000,
|
|
15
|
+
});
|
|
16
|
+
expect(parsed.success).toBe(true);
|
|
17
|
+
expect(
|
|
18
|
+
billingNotificationPayloadSchema.safeParse({
|
|
19
|
+
kind: "payment_failed",
|
|
20
|
+
stripe_customer_id: "cus_secret",
|
|
21
|
+
}).success,
|
|
22
|
+
).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("accepts legacy inbox rows with null detail fields and cursor pagination", () => {
|
|
26
|
+
const parsed = billingNotificationListResponseSchema.safeParse({
|
|
27
|
+
items: [
|
|
28
|
+
{
|
|
29
|
+
notification_key: "payment_failed:episode-1",
|
|
30
|
+
kind: "payment_failed",
|
|
31
|
+
billing_month: null,
|
|
32
|
+
threshold_percent: null,
|
|
33
|
+
current_mau: null,
|
|
34
|
+
free_tier_limit: null,
|
|
35
|
+
grace_ends_at: null,
|
|
36
|
+
restriction_days: null,
|
|
37
|
+
created_at: "2026-08-05T00:00:00.000Z",
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
next_cursor: "cursor",
|
|
41
|
+
});
|
|
42
|
+
expect(parsed.success).toBe(true);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { cursorPageSchema, paginationQuerySchema } from "./common.js";
|
|
3
|
+
import { billingMonthSchema, mauThresholdLevelSchema } from "./usage.js";
|
|
4
|
+
|
|
5
|
+
export const billingNotificationKindSchema = z.enum([
|
|
6
|
+
"mau_threshold_reached",
|
|
7
|
+
"grace_period_started",
|
|
8
|
+
"grace_period_expired",
|
|
9
|
+
"payment_failed",
|
|
10
|
+
"payment_recovered",
|
|
11
|
+
"payment_restricted_new_users",
|
|
12
|
+
"payment_restricted_config",
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
/** Non-secret rendering data persisted in the workspace billing inbox. */
|
|
16
|
+
export const billingNotificationPayloadSchema = z.discriminatedUnion("kind", [
|
|
17
|
+
z.strictObject({
|
|
18
|
+
kind: z.literal("mau_threshold_reached"),
|
|
19
|
+
billingMonth: billingMonthSchema,
|
|
20
|
+
thresholdPercent: mauThresholdLevelSchema,
|
|
21
|
+
currentMau: z.number().int().nonnegative(),
|
|
22
|
+
freeTierLimit: z.number().int().positive(),
|
|
23
|
+
}),
|
|
24
|
+
z.strictObject({ kind: z.literal("grace_period_started"), graceEndsAt: z.iso.datetime() }),
|
|
25
|
+
z.strictObject({ kind: z.literal("grace_period_expired") }),
|
|
26
|
+
z.strictObject({ kind: z.literal("payment_failed") }),
|
|
27
|
+
z.strictObject({ kind: z.literal("payment_recovered") }),
|
|
28
|
+
z.strictObject({ kind: z.literal("payment_restricted_new_users"), daysPastDue: z.literal(14) }),
|
|
29
|
+
z.strictObject({ kind: z.literal("payment_restricted_config"), daysPastDue: z.literal(30) }),
|
|
30
|
+
]);
|
|
31
|
+
export type BillingNotificationPayload = z.infer<typeof billingNotificationPayloadSchema>;
|
|
32
|
+
|
|
33
|
+
/** Legacy rows have null payload fields and remain renderable by kind and timestamp. */
|
|
34
|
+
export const billingNotificationSchema = z.strictObject({
|
|
35
|
+
notification_key: z.string().min(1).max(255),
|
|
36
|
+
kind: billingNotificationKindSchema,
|
|
37
|
+
billing_month: billingMonthSchema.nullable(),
|
|
38
|
+
threshold_percent: mauThresholdLevelSchema.nullable(),
|
|
39
|
+
current_mau: z.number().int().nonnegative().nullable(),
|
|
40
|
+
free_tier_limit: z.number().int().positive().nullable(),
|
|
41
|
+
grace_ends_at: z.iso.datetime().nullable(),
|
|
42
|
+
restriction_days: z.union([z.literal(14), z.literal(30)]).nullable(),
|
|
43
|
+
created_at: z.iso.datetime(),
|
|
44
|
+
});
|
|
45
|
+
export type BillingNotification = z.infer<typeof billingNotificationSchema>;
|
|
46
|
+
|
|
47
|
+
export const billingNotificationListQuerySchema = paginationQuerySchema;
|
|
48
|
+
export type BillingNotificationListQuery = z.infer<typeof billingNotificationListQuerySchema>;
|
|
49
|
+
|
|
50
|
+
export const billingNotificationListResponseSchema = cursorPageSchema(billingNotificationSchema);
|
|
51
|
+
export type BillingNotificationListResponse = z.infer<typeof billingNotificationListResponseSchema>;
|
package/src/dlq.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dead-letter queue (DLQ) records (design.md §29.3: "DLQはDashboardから閲覧・
|
|
3
|
+
* 再送できる"). A record is one message that exhausted its queue's retries (or
|
|
4
|
+
* was rejected by its consumer) and was written to the workspace's DLQ store.
|
|
5
|
+
*
|
|
6
|
+
* Read: `GET /dlq/records`, `GET /dlq/records/:recordId` (payload redacted per
|
|
7
|
+
* design.md §32.6). Write: `POST /dlq/records/:recordId/redrive` re-sends the
|
|
8
|
+
* original message to its source queue with the original event id, so the
|
|
9
|
+
* consumer's dedupe (design.md §29.3) suppresses any second successful
|
|
10
|
+
* customer delivery.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import { cursorPageSchema, paginationQuerySchema } from "./common.js";
|
|
14
|
+
import { environmentIdSchema } from "./primitives.js";
|
|
15
|
+
|
|
16
|
+
/** Logical source queues a dead-letter record can belong to (design.md §29.1). */
|
|
17
|
+
export const DLQ_QUEUES = [
|
|
18
|
+
"auth-events",
|
|
19
|
+
"billing-events",
|
|
20
|
+
"webhook-deliveries",
|
|
21
|
+
"audit-events",
|
|
22
|
+
"email-service-events",
|
|
23
|
+
"outbox-recovery",
|
|
24
|
+
] as const;
|
|
25
|
+
export const dlqQueueSchema = z.enum(DLQ_QUEUES);
|
|
26
|
+
export type DlqQueue = z.infer<typeof dlqQueueSchema>;
|
|
27
|
+
|
|
28
|
+
/** Opaque record id: `dlq_` + base64url(`<queue>/<eventKey>`). Not a secret: tenancy is enforced server-side. */
|
|
29
|
+
export const dlqRecordIdSchema = z.string().regex(/^dlq_[A-Za-z0-9_-]{1,2048}$/);
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Lifecycle as shown to operators. `dead_lettered`: never re-driven (or a
|
|
33
|
+
* failed re-drive was released). `redriving`: a re-drive holds the record's
|
|
34
|
+
* lease. `redriven`: a re-drive completed (see `redrive_outcome`).
|
|
35
|
+
*/
|
|
36
|
+
export const DLQ_RECORD_STATUSES = ["dead_lettered", "redriving", "redriven"] as const;
|
|
37
|
+
export const dlqRecordStatusSchema = z.enum(DLQ_RECORD_STATUSES);
|
|
38
|
+
export type DlqRecordStatus = z.infer<typeof dlqRecordStatusSchema>;
|
|
39
|
+
|
|
40
|
+
/** How a completed re-drive resolved (design.md §29.4: delivered events are never re-sent). */
|
|
41
|
+
export const DLQ_REDRIVE_OUTCOMES = ["enqueued", "already_delivered"] as const;
|
|
42
|
+
export const dlqRedriveOutcomeSchema = z.enum(DLQ_REDRIVE_OUTCOMES);
|
|
43
|
+
export type DlqRedriveOutcome = z.infer<typeof dlqRedriveOutcomeSchema>;
|
|
44
|
+
|
|
45
|
+
// ---------------------------------------------------------------------------
|
|
46
|
+
// GET /dlq/records
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
export const dlqRecordListQuerySchema = paginationQuerySchema.extend({
|
|
50
|
+
queue: dlqQueueSchema.optional(),
|
|
51
|
+
/** Exact domain event type (e.g. `user.created`). */
|
|
52
|
+
event_type: z.string().min(1).max(64).optional(),
|
|
53
|
+
/** Only records of this Environment; workspace-level records are excluded. */
|
|
54
|
+
environment_id: environmentIdSchema.optional(),
|
|
55
|
+
status: dlqRecordStatusSchema.optional(),
|
|
56
|
+
failed_after: z.iso.datetime().optional(),
|
|
57
|
+
failed_before: z.iso.datetime().optional(),
|
|
58
|
+
});
|
|
59
|
+
export type DlqRecordListQuery = z.infer<typeof dlqRecordListQuerySchema>;
|
|
60
|
+
|
|
61
|
+
export const dlqRecordSchema = z.strictObject({
|
|
62
|
+
id: dlqRecordIdSchema,
|
|
63
|
+
queue: dlqQueueSchema,
|
|
64
|
+
/** Domain event id (`evt_...`), when the message carried one. */
|
|
65
|
+
event_id: z.string().nullable(),
|
|
66
|
+
event_type: z.string().nullable(),
|
|
67
|
+
/** Webhook endpoint the delivery targeted (`webhook-deliveries` only). */
|
|
68
|
+
webhook_id: z.string().nullable(),
|
|
69
|
+
environment_id: z.string().nullable(),
|
|
70
|
+
/** Attempts the platform made before dead-lettering. */
|
|
71
|
+
attempts: z.number().int().nonnegative(),
|
|
72
|
+
failed_at: z.iso.datetime(),
|
|
73
|
+
status: dlqRecordStatusSchema,
|
|
74
|
+
redriven_at: z.iso.datetime().nullable(),
|
|
75
|
+
redrive_outcome: dlqRedriveOutcomeSchema.nullable(),
|
|
76
|
+
});
|
|
77
|
+
export type DlqRecord = z.infer<typeof dlqRecordSchema>;
|
|
78
|
+
|
|
79
|
+
export const dlqRecordListResponseSchema = cursorPageSchema(dlqRecordSchema);
|
|
80
|
+
export type DlqRecordListResponse = z.infer<typeof dlqRecordListResponseSchema>;
|
|
81
|
+
|
|
82
|
+
// ---------------------------------------------------------------------------
|
|
83
|
+
// GET /dlq/records/:recordId
|
|
84
|
+
// ---------------------------------------------------------------------------
|
|
85
|
+
|
|
86
|
+
export const dlqRecordDetailSchema = dlqRecordSchema.extend({
|
|
87
|
+
/**
|
|
88
|
+
* The original message body with secrets masked (design.md §32.6: OTP,
|
|
89
|
+
* token, cookie, provider secret, private key, full email, authorization
|
|
90
|
+
* code, raw WebAuthn assertion). `null` when the stored body was truncated
|
|
91
|
+
* or is not a JSON object.
|
|
92
|
+
*/
|
|
93
|
+
payload: z.record(z.string(), z.unknown()).nullable(),
|
|
94
|
+
/** `true` when the stored body was cut at the 64 KiB record cap (design.md §10.9). */
|
|
95
|
+
payload_truncated: z.boolean(),
|
|
96
|
+
/** `true` when the stored body is a complete message this queue can re-drive. */
|
|
97
|
+
redrivable: z.boolean(),
|
|
98
|
+
});
|
|
99
|
+
export type DlqRecordDetail = z.infer<typeof dlqRecordDetailSchema>;
|
|
100
|
+
|
|
101
|
+
// ---------------------------------------------------------------------------
|
|
102
|
+
// POST /dlq/records/:recordId/redrive
|
|
103
|
+
// ---------------------------------------------------------------------------
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* `enqueued`: the original message was sent to its source queue (HTTP 202).
|
|
107
|
+
* `already_delivered`: the webhook event was already delivered, so nothing was
|
|
108
|
+
* sent (HTTP 200). `already_redriven`: an earlier re-drive already handled this
|
|
109
|
+
* record, so the call is idempotent and sends nothing (HTTP 200).
|
|
110
|
+
*/
|
|
111
|
+
export const DLQ_REDRIVE_RESPONSE_OUTCOMES = [
|
|
112
|
+
"enqueued",
|
|
113
|
+
"already_delivered",
|
|
114
|
+
"already_redriven",
|
|
115
|
+
] as const;
|
|
116
|
+
export const dlqRedriveResponseOutcomeSchema = z.enum(DLQ_REDRIVE_RESPONSE_OUTCOMES);
|
|
117
|
+
export type DlqRedriveResponseOutcome = z.infer<typeof dlqRedriveResponseOutcomeSchema>;
|
|
118
|
+
|
|
119
|
+
export const dlqRedriveResponseSchema = z.strictObject({
|
|
120
|
+
id: dlqRecordIdSchema,
|
|
121
|
+
queue: dlqQueueSchema,
|
|
122
|
+
status: z.literal("redriven"),
|
|
123
|
+
outcome: dlqRedriveResponseOutcomeSchema,
|
|
124
|
+
redriven_at: z.iso.datetime(),
|
|
125
|
+
});
|
|
126
|
+
export type DlqRedriveResponse = z.infer<typeof dlqRedriveResponseSchema>;
|
package/src/index.ts
CHANGED
|
@@ -20,9 +20,12 @@ export * from "./connections.js";
|
|
|
20
20
|
export * from "./domains.js";
|
|
21
21
|
export * from "./users.js";
|
|
22
22
|
export * from "./user-subresources.js";
|
|
23
|
+
export * from "./user-recovery.js";
|
|
23
24
|
export * from "./user-jobs.js";
|
|
24
25
|
export * from "./webhooks.js";
|
|
26
|
+
export * from "./dlq.js";
|
|
25
27
|
export * from "./audit-events.js";
|
|
26
28
|
export * from "./usage.js";
|
|
27
29
|
export * from "./billing.js";
|
|
30
|
+
export * from "./billing-notifications.js";
|
|
28
31
|
export * from "./quotas.js";
|
package/src/rbac.test.ts
CHANGED
|
@@ -79,7 +79,8 @@ describe("design.md §27.2 role table invariants", () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
test("developer has integration resource scopes and token introspection (design.md §27.2)", () => {
|
|
82
|
-
|
|
82
|
+
// Developers may inspect DLQ records, but only Owner/Admin can re-drive them.
|
|
83
|
+
const allowedResources = ["clients", "connections", "domains", "webhooks", "dlq"];
|
|
83
84
|
expect(ROLE_SCOPES.developer.length).toBeGreaterThan(0);
|
|
84
85
|
expect(ROLE_SCOPES.developer).toContain("introspect");
|
|
85
86
|
for (const scope of ROLE_SCOPES.developer) {
|
|
@@ -89,6 +90,19 @@ describe("design.md §27.2 role table invariants", () => {
|
|
|
89
90
|
}
|
|
90
91
|
});
|
|
91
92
|
|
|
93
|
+
test("dead-letter scopes: read for owner/admin/developer/viewer, re-drive for owner/admin only (design.md §29.3, §27.2)", () => {
|
|
94
|
+
const readers = ["owner", "admin", "developer", "viewer"] as const;
|
|
95
|
+
const writers = ["owner", "admin"] as const;
|
|
96
|
+
for (const role of WORKSPACE_ROLES) {
|
|
97
|
+
expect(roleHasScope(role, "dlq:read"), `dlq:read for ${role}`).toBe(
|
|
98
|
+
(readers as readonly string[]).includes(role),
|
|
99
|
+
);
|
|
100
|
+
expect(roleHasScope(role, "dlq:write"), `dlq:write for ${role}`).toBe(
|
|
101
|
+
(writers as readonly string[]).includes(role),
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
92
106
|
test("introspect is a read-only scope for owner/admin/developer", () => {
|
|
93
107
|
expect(MANAGEMENT_SCOPES).toContain("introspect");
|
|
94
108
|
expect(isReadOnlyScope("introspect")).toBe(true);
|
package/src/rbac.ts
CHANGED
|
@@ -61,6 +61,10 @@ export const MANAGEMENT_SCOPES = [
|
|
|
61
61
|
"webhooks:write",
|
|
62
62
|
"webhooks:rotate_secret",
|
|
63
63
|
"webhooks:test",
|
|
64
|
+
// Dead-letter records (design.md §29.3): `dlq:read` lists/reads the DLQ store;
|
|
65
|
+
// `dlq:write` re-drives records from any source queue, including billing and audit.
|
|
66
|
+
"dlq:read",
|
|
67
|
+
"dlq:write",
|
|
64
68
|
"audit_events:read",
|
|
65
69
|
"usage:read",
|
|
66
70
|
// Scoped Management API key permission for POST /oauth2/introspect
|
|
@@ -116,11 +120,11 @@ export const IMPERSONATION_FORBIDDEN_SCOPES = [
|
|
|
116
120
|
* requires a defensible reading of it): granted to owner/admin/support/
|
|
117
121
|
* billing/viewer, withheld from developer. The Developer table lists "Client,
|
|
118
122
|
* Connection, Domain, Webhook" resources, with `introspect` as a standalone
|
|
119
|
-
* OAuth capability for resource-server token validation.
|
|
120
|
-
*
|
|
121
|
-
* role either reads broadly (`viewer`, "読み取りのみ") or
|
|
122
|
-
* its work (`admin` administers the workspace;
|
|
123
|
-
* the workspace's people and billing contacts day to day).
|
|
123
|
+
* OAuth capability for resource-server token validation. `dlq:read` is limited
|
|
124
|
+
* to inspection; `dlq:write` is Owner/Admin-only because redrive covers every
|
|
125
|
+
* source queue. Every other role either reads broadly (`viewer`, "読み取りのみ") or
|
|
126
|
+
* needs the roster for its work (`admin` administers the workspace;
|
|
127
|
+
* `support`/`billing` deal with the workspace's people and billing contacts day to day).
|
|
124
128
|
*/
|
|
125
129
|
export const ROLE_SCOPES: Readonly<Record<WorkspaceRole, readonly ManagementScope[]>> = {
|
|
126
130
|
owner: MANAGEMENT_SCOPES,
|
|
@@ -145,6 +149,8 @@ export const ROLE_SCOPES: Readonly<Record<WorkspaceRole, readonly ManagementScop
|
|
|
145
149
|
"user_data_jobs:read",
|
|
146
150
|
"user_data_jobs:write",
|
|
147
151
|
"audit_events:read",
|
|
152
|
+
"dlq:read",
|
|
153
|
+
"dlq:write",
|
|
148
154
|
"impersonation:create",
|
|
149
155
|
],
|
|
150
156
|
developer: [
|
|
@@ -160,6 +166,7 @@ export const ROLE_SCOPES: Readonly<Record<WorkspaceRole, readonly ManagementScop
|
|
|
160
166
|
"webhooks:write",
|
|
161
167
|
"webhooks:rotate_secret",
|
|
162
168
|
"webhooks:test",
|
|
169
|
+
"dlq:read",
|
|
163
170
|
],
|
|
164
171
|
support: [
|
|
165
172
|
"users:read",
|
|
@@ -190,6 +197,7 @@ export const ROLE_SCOPES: Readonly<Record<WorkspaceRole, readonly ManagementScop
|
|
|
190
197
|
"user_sessions:read",
|
|
191
198
|
"user_data_jobs:read",
|
|
192
199
|
"webhooks:read",
|
|
200
|
+
"dlq:read",
|
|
193
201
|
"audit_events:read",
|
|
194
202
|
"usage:read",
|
|
195
203
|
"billing:read",
|
|
@@ -206,6 +214,42 @@ export const roleHasScope = (role: WorkspaceRole, scope: ManagementScope): boole
|
|
|
206
214
|
export const isReadOnlyScope = (scope: ManagementScope): boolean =>
|
|
207
215
|
scope === "introspect" || scope.endsWith(":read");
|
|
208
216
|
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
// Workspace-level vs Environment-level operations (design.md §11.12, §27.4)
|
|
219
|
+
// ---------------------------------------------------------------------------
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Scopes whose effect is the Workspace as a whole (Workspace settings, the
|
|
223
|
+
* Project list, Workspace members, billing, starting an impersonation) rather
|
|
224
|
+
* than one Environment's resources. An Environment-pinned Management API key
|
|
225
|
+
* MUST NOT be granted or use these (design.md §11.12: a pinned key is bound to
|
|
226
|
+
* one Environment), and an impersonation session MUST NOT perform them
|
|
227
|
+
* (design.md §27.4).
|
|
228
|
+
*/
|
|
229
|
+
export const WORKSPACE_LEVEL_SCOPES = [
|
|
230
|
+
"workspaces:read",
|
|
231
|
+
"workspaces:write",
|
|
232
|
+
"workspace_members:read",
|
|
233
|
+
"projects:read",
|
|
234
|
+
"projects:write",
|
|
235
|
+
"billing:read",
|
|
236
|
+
"billing:write",
|
|
237
|
+
"impersonation:create",
|
|
238
|
+
] as const satisfies readonly ManagementScope[];
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Whether an operation requiring `scope` acts on the Workspace as a whole.
|
|
242
|
+
* Environment creation and unfiltered Environment/usage listings are
|
|
243
|
+
* workspace-level because they have no target Environment.
|
|
244
|
+
*/
|
|
245
|
+
export const isWorkspaceLevelOperation = (
|
|
246
|
+
scope: ManagementScope,
|
|
247
|
+
targetEnvironmentId: string | undefined,
|
|
248
|
+
): boolean =>
|
|
249
|
+
(WORKSPACE_LEVEL_SCOPES as readonly ManagementScope[]).includes(scope) ||
|
|
250
|
+
(targetEnvironmentId === undefined &&
|
|
251
|
+
(scope === "environments:write" || scope === "environments:read" || scope === "usage:read"));
|
|
252
|
+
|
|
209
253
|
// ---------------------------------------------------------------------------
|
|
210
254
|
// Impersonation (design.md §27.4)
|
|
211
255
|
// ---------------------------------------------------------------------------
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
/** Request to initiate account recovery for an existing user. */
|
|
4
|
+
export const userRecoveryRequestSchema = z.strictObject({
|
|
5
|
+
reason: z.string().trim().min(1).max(1000),
|
|
6
|
+
});
|
|
7
|
+
export type UserRecoveryRequest = z.infer<typeof userRecoveryRequestSchema>;
|
|
8
|
+
|
|
9
|
+
/** Static, non-sensitive instructions returned after recovery is initiated. */
|
|
10
|
+
export const userRecoveryResponseSchema = z.strictObject({
|
|
11
|
+
initiated: z.literal(true),
|
|
12
|
+
instructions: z.literal(
|
|
13
|
+
"Sign in using an already-enrolled verified email OTP or linked social identity, then register a new passkey.",
|
|
14
|
+
),
|
|
15
|
+
});
|
|
16
|
+
export type UserRecoveryResponse = z.infer<typeof userRecoveryResponseSchema>;
|