@smartcrab/management-client 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/client.d.ts +19 -0
- package/dist/client.js +22 -0
- package/dist/client.test.js +199 -1
- package/dist/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/client.test.ts +216 -1
- package/src/client.ts +76 -1
- package/src/index.ts +2 -0
package/dist/client.d.ts
CHANGED
|
@@ -68,6 +68,18 @@ export interface WebhookDeliveryListParams extends PaginationParams {
|
|
|
68
68
|
readonly occurred_after?: string;
|
|
69
69
|
readonly occurred_before?: string;
|
|
70
70
|
}
|
|
71
|
+
export interface DlqRecordListParams extends PaginationParams {
|
|
72
|
+
readonly queue?: cm.DlqQueue;
|
|
73
|
+
/** Exact domain event type (e.g. `user.created`). */
|
|
74
|
+
readonly event_type?: string;
|
|
75
|
+
/** Only records of this Environment; workspace-level records are excluded. */
|
|
76
|
+
readonly environment_id?: string;
|
|
77
|
+
readonly status?: cm.DlqRecordStatus;
|
|
78
|
+
/** ISO 8601 date-time. */
|
|
79
|
+
readonly failed_after?: string;
|
|
80
|
+
/** ISO 8601 date-time. */
|
|
81
|
+
readonly failed_before?: string;
|
|
82
|
+
}
|
|
71
83
|
export interface AuditEventListParams extends PaginationParams {
|
|
72
84
|
readonly environment_id: string;
|
|
73
85
|
readonly actor_type?: cm.AuditActorType;
|
|
@@ -82,6 +94,7 @@ export interface MauUsageParams {
|
|
|
82
94
|
readonly billing_month?: string;
|
|
83
95
|
readonly environment_id?: string;
|
|
84
96
|
}
|
|
97
|
+
export type BillingNotificationListParams = PaginationParams;
|
|
85
98
|
export type WorkspaceCreateInput = InputOf<typeof cm.workspaceCreateRequestSchema>;
|
|
86
99
|
export type WorkspaceUpdateInput = InputOf<typeof cm.workspaceUpdateRequestSchema>;
|
|
87
100
|
export type ProjectCreateInput = InputOf<typeof cm.projectCreateRequestSchema>;
|
|
@@ -99,6 +112,7 @@ export type DomainUpdateInput = InputOf<typeof cm.domainUpdateRequestSchema>;
|
|
|
99
112
|
export type UserCreateInput = InputOf<typeof cm.userCreateRequestSchema>;
|
|
100
113
|
export type UserUpdateInput = InputOf<typeof cm.userUpdateRequestSchema>;
|
|
101
114
|
export type UserBlockInput = InputOf<typeof cm.userBlockRequestSchema>;
|
|
115
|
+
export type UserRecoveryInput = InputOf<typeof cm.userRecoveryRequestSchema>;
|
|
102
116
|
export type UserImportJobCreateInput = InputOf<typeof cm.userImportJobCreateRequestSchema>;
|
|
103
117
|
export type UserExportJobCreateInput = InputOf<typeof cm.userExportJobCreateRequestSchema>;
|
|
104
118
|
export type WebhookCreateInput = InputOf<typeof cm.webhookCreateRequestSchema>;
|
|
@@ -148,6 +162,7 @@ export interface ManagementClient {
|
|
|
148
162
|
deleteUser(environmentId: string, userId: string, options?: WriteOptions): Api<cm.UserDeleteResponse>;
|
|
149
163
|
blockUser(environmentId: string, userId: string, body?: UserBlockInput, options?: WriteOptions): Api<cm.UserBlockResponse>;
|
|
150
164
|
unblockUser(environmentId: string, userId: string, options?: WriteOptions): Api<cm.UserUnblockResponse>;
|
|
165
|
+
initiateUserRecovery(environmentId: string, userId: string, body: UserRecoveryInput, options?: WriteOptions): Api<cm.UserRecoveryResponse>;
|
|
151
166
|
listUserIdentities(environmentId: string, userId: string, params?: PaginationParams): Api<cm.UserIdentityListResponse>;
|
|
152
167
|
deleteUserIdentity(environmentId: string, userId: string, identityId: string, options?: WriteOptions): Api<cm.UserIdentityDeleteResponse>;
|
|
153
168
|
listUserPasskeys(environmentId: string, userId: string, params?: PaginationParams): Api<cm.UserPasskeyListResponse>;
|
|
@@ -166,8 +181,12 @@ export interface ManagementClient {
|
|
|
166
181
|
deleteWebhook(webhookId: string, options?: WriteOptions): Api<cm.WebhookDeleteResponse>;
|
|
167
182
|
rotateWebhookSecret(webhookId: string, options?: WriteOptions): Api<cm.WebhookRotateSecretResponse>;
|
|
168
183
|
testWebhook(webhookId: string, body?: WebhookTestInput, options?: WriteOptions): Api<cm.WebhookTestResponse>;
|
|
184
|
+
listDlqRecords(params?: DlqRecordListParams): Api<cm.DlqRecordListResponse>;
|
|
185
|
+
getDlqRecord(recordId: string): Api<cm.DlqRecordDetail>;
|
|
186
|
+
redriveDlqRecord(recordId: string, options?: WriteOptions): Api<cm.DlqRedriveResponse>;
|
|
169
187
|
listAuditEvents(params: AuditEventListParams): Api<cm.AuditEventListResponse>;
|
|
170
188
|
getMauUsage(params?: MauUsageParams): Api<cm.MauUsageResponse>;
|
|
189
|
+
listBillingNotifications(params?: BillingNotificationListParams): Api<cm.BillingNotificationListResponse>;
|
|
171
190
|
createBillingCheckoutSession(body: BillingCheckoutSessionCreateInput, options?: WriteOptions): Api<cm.BillingCheckoutSessionCreateResponse>;
|
|
172
191
|
createBillingPortalSession(body: BillingPortalSessionCreateInput, options?: WriteOptions): Api<cm.BillingPortalSessionCreateResponse>;
|
|
173
192
|
}
|
package/dist/client.js
CHANGED
|
@@ -152,6 +152,9 @@ export const createManagementClient = (options) => {
|
|
|
152
152
|
unblockUser: (environmentId, userId, writeOptions) => send(config, writeSpec("POST", `/users/${segment(userId)}/unblock`, {}, writeOptions, {
|
|
153
153
|
environment_id: environmentId,
|
|
154
154
|
}), cm.userUnblockResponseSchema),
|
|
155
|
+
initiateUserRecovery: (environmentId, userId, body, writeOptions) => withValidBody(cm.userRecoveryRequestSchema, body, (valid) => send(config, writeSpec("POST", `/users/${segment(userId)}/recovery`, valid, writeOptions, {
|
|
156
|
+
environment_id: environmentId,
|
|
157
|
+
}), cm.userRecoveryResponseSchema)),
|
|
155
158
|
// --------------------------------------------------------------
|
|
156
159
|
// User sub-resources
|
|
157
160
|
// --------------------------------------------------------------
|
|
@@ -204,6 +207,21 @@ export const createManagementClient = (options) => {
|
|
|
204
207
|
rotateWebhookSecret: (webhookId, writeOptions) => send(config, writeSpec("POST", `/webhooks/${segment(webhookId)}/rotate-secret`, {}, writeOptions), cm.webhookRotateSecretResponseSchema),
|
|
205
208
|
testWebhook: (webhookId, body, writeOptions) => withValidBody(cm.webhookTestRequestSchema, body ?? {}, (valid) => send(config, writeSpec("POST", `/webhooks/${segment(webhookId)}/test`, valid, writeOptions), cm.webhookTestResponseSchema)),
|
|
206
209
|
// --------------------------------------------------------------
|
|
210
|
+
// DLQ records (design.md §29.3)
|
|
211
|
+
// --------------------------------------------------------------
|
|
212
|
+
listDlqRecords: (params) => send(config, getSpec("/dlq/records", {
|
|
213
|
+
cursor: params?.cursor,
|
|
214
|
+
limit: params?.limit,
|
|
215
|
+
queue: params?.queue,
|
|
216
|
+
event_type: params?.event_type,
|
|
217
|
+
environment_id: params?.environment_id,
|
|
218
|
+
status: params?.status,
|
|
219
|
+
failed_after: params?.failed_after,
|
|
220
|
+
failed_before: params?.failed_before,
|
|
221
|
+
}), cm.dlqRecordListResponseSchema),
|
|
222
|
+
getDlqRecord: (recordId) => send(config, getSpec(`/dlq/records/${segment(recordId)}`), cm.dlqRecordDetailSchema),
|
|
223
|
+
redriveDlqRecord: (recordId, writeOptions) => send(config, writeSpec("POST", `/dlq/records/${segment(recordId)}/redrive`, undefined, writeOptions), cm.dlqRedriveResponseSchema),
|
|
224
|
+
// --------------------------------------------------------------
|
|
207
225
|
// Audit events / usage / billing
|
|
208
226
|
// --------------------------------------------------------------
|
|
209
227
|
listAuditEvents: (params) => send(config, getSpec("/audit-events", {
|
|
@@ -222,6 +240,10 @@ export const createManagementClient = (options) => {
|
|
|
222
240
|
billing_month: params?.billing_month,
|
|
223
241
|
environment_id: params?.environment_id,
|
|
224
242
|
}), cm.mauUsageResponseSchema),
|
|
243
|
+
listBillingNotifications: (params) => send(config, getSpec("/billing/notifications", {
|
|
244
|
+
cursor: params?.cursor,
|
|
245
|
+
limit: params?.limit,
|
|
246
|
+
}), cm.billingNotificationListResponseSchema),
|
|
225
247
|
createBillingCheckoutSession: (body, writeOptions) => withValidBody(cm.billingCheckoutSessionCreateRequestSchema, body, (valid) => send(config, writeSpec("POST", "/billing/checkout-session", valid, writeOptions), cm.billingCheckoutSessionCreateResponseSchema)),
|
|
226
248
|
createBillingPortalSession: (body, writeOptions) => withValidBody(cm.billingPortalSessionCreateRequestSchema, body, (valid) => send(config, writeSpec("POST", "/billing/portal-session", valid, writeOptions), cm.billingPortalSessionCreateResponseSchema)),
|
|
227
249
|
};
|
package/dist/client.test.js
CHANGED
|
@@ -195,6 +195,33 @@ const webhook = {
|
|
|
195
195
|
created_at: TS,
|
|
196
196
|
updated_at: TS,
|
|
197
197
|
};
|
|
198
|
+
const DLQ_RECORD_ID = `dlq_${"a".repeat(40)}`;
|
|
199
|
+
const dlqRecord = {
|
|
200
|
+
id: DLQ_RECORD_ID,
|
|
201
|
+
queue: "webhook-deliveries",
|
|
202
|
+
event_id: ID("evt"),
|
|
203
|
+
event_type: "user.created",
|
|
204
|
+
webhook_id: ID("whk"),
|
|
205
|
+
environment_id: ID("env"),
|
|
206
|
+
attempts: 8,
|
|
207
|
+
failed_at: TS,
|
|
208
|
+
status: "dead_lettered",
|
|
209
|
+
redriven_at: null,
|
|
210
|
+
redrive_outcome: null,
|
|
211
|
+
};
|
|
212
|
+
const dlqRecordDetail = {
|
|
213
|
+
...dlqRecord,
|
|
214
|
+
payload: { userId: ID("usr"), email: "[redacted]", otp: "[redacted]" },
|
|
215
|
+
payload_truncated: false,
|
|
216
|
+
redrivable: true,
|
|
217
|
+
};
|
|
218
|
+
const dlqRedriveResult = {
|
|
219
|
+
id: DLQ_RECORD_ID,
|
|
220
|
+
queue: "webhook-deliveries",
|
|
221
|
+
status: "redriven",
|
|
222
|
+
outcome: "enqueued",
|
|
223
|
+
redriven_at: TS,
|
|
224
|
+
};
|
|
198
225
|
const auditEvent = {
|
|
199
226
|
id: ID("evt"),
|
|
200
227
|
environment_id: ID("env"),
|
|
@@ -225,6 +252,17 @@ const mauUsage = {
|
|
|
225
252
|
},
|
|
226
253
|
environments: [],
|
|
227
254
|
};
|
|
255
|
+
const billingNotification = {
|
|
256
|
+
notification_key: "payment_failed:episode-1",
|
|
257
|
+
kind: "payment_failed",
|
|
258
|
+
billing_month: null,
|
|
259
|
+
threshold_percent: null,
|
|
260
|
+
current_mau: null,
|
|
261
|
+
free_tier_limit: null,
|
|
262
|
+
grace_ends_at: null,
|
|
263
|
+
restriction_days: null,
|
|
264
|
+
created_at: TS,
|
|
265
|
+
};
|
|
228
266
|
const jsonResponse = (body, status = 200, extraHeaders = {}) => new Response(JSON.stringify(body), {
|
|
229
267
|
status,
|
|
230
268
|
headers: {
|
|
@@ -609,6 +647,17 @@ const ROUTES = [
|
|
|
609
647
|
responseBody: { id: ID("usr"), status: "active" },
|
|
610
648
|
write: true,
|
|
611
649
|
},
|
|
650
|
+
{
|
|
651
|
+
name: "initiateUserRecovery",
|
|
652
|
+
invoke: (c) => c.initiateUserRecovery(ID("env"), ID("usr"), { reason: "Support request" }),
|
|
653
|
+
method: "POST",
|
|
654
|
+
path: `/users/${ID("usr")}/recovery`,
|
|
655
|
+
responseBody: {
|
|
656
|
+
initiated: true,
|
|
657
|
+
instructions: "Sign in using an already-enrolled verified email OTP or linked social identity, then register a new passkey.",
|
|
658
|
+
},
|
|
659
|
+
write: true,
|
|
660
|
+
},
|
|
612
661
|
// User sub-resources
|
|
613
662
|
{
|
|
614
663
|
name: "listUserIdentities",
|
|
@@ -764,6 +813,31 @@ const ROUTES = [
|
|
|
764
813
|
responseBody: { delivered: true, response_status: 200, response_time_ms: 12, requested_at: TS },
|
|
765
814
|
write: true,
|
|
766
815
|
},
|
|
816
|
+
// DLQ records (design.md §29.3)
|
|
817
|
+
{
|
|
818
|
+
name: "listDlqRecords",
|
|
819
|
+
invoke: (c) => c.listDlqRecords({ queue: "webhook-deliveries" }),
|
|
820
|
+
method: "GET",
|
|
821
|
+
path: "/dlq/records",
|
|
822
|
+
responseBody: page(dlqRecord),
|
|
823
|
+
write: false,
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
name: "getDlqRecord",
|
|
827
|
+
invoke: (c) => c.getDlqRecord(DLQ_RECORD_ID),
|
|
828
|
+
method: "GET",
|
|
829
|
+
path: `/dlq/records/${DLQ_RECORD_ID}`,
|
|
830
|
+
responseBody: dlqRecordDetail,
|
|
831
|
+
write: false,
|
|
832
|
+
},
|
|
833
|
+
{
|
|
834
|
+
name: "redriveDlqRecord",
|
|
835
|
+
invoke: (c) => c.redriveDlqRecord(DLQ_RECORD_ID),
|
|
836
|
+
method: "POST",
|
|
837
|
+
path: `/dlq/records/${DLQ_RECORD_ID}/redrive`,
|
|
838
|
+
responseBody: dlqRedriveResult,
|
|
839
|
+
write: true,
|
|
840
|
+
},
|
|
767
841
|
// Audit / usage / billing
|
|
768
842
|
{
|
|
769
843
|
name: "listAuditEvents",
|
|
@@ -781,6 +855,14 @@ const ROUTES = [
|
|
|
781
855
|
responseBody: mauUsage,
|
|
782
856
|
write: false,
|
|
783
857
|
},
|
|
858
|
+
{
|
|
859
|
+
name: "listBillingNotifications",
|
|
860
|
+
invoke: (c) => c.listBillingNotifications({ limit: 25 }),
|
|
861
|
+
method: "GET",
|
|
862
|
+
path: "/billing/notifications",
|
|
863
|
+
responseBody: page(billingNotification),
|
|
864
|
+
write: false,
|
|
865
|
+
},
|
|
784
866
|
{
|
|
785
867
|
name: "createBillingCheckoutSession",
|
|
786
868
|
invoke: (c) => c.createBillingCheckoutSession({
|
|
@@ -803,7 +885,7 @@ const ROUTES = [
|
|
|
803
885
|
];
|
|
804
886
|
describe("createManagementClient — one method per design.md §26.2 route", () => {
|
|
805
887
|
test(`covers ${ROUTES.length} routes`, () => {
|
|
806
|
-
expect(ROUTES.length).toBe(
|
|
888
|
+
expect(ROUTES.length).toBe(67);
|
|
807
889
|
expect(new Set(ROUTES.map((r) => r.name)).size).toBe(ROUTES.length);
|
|
808
890
|
});
|
|
809
891
|
for (const route of ROUTES) {
|
|
@@ -843,6 +925,14 @@ describe("createManagementClient — one method per design.md §26.2 route", ()
|
|
|
843
925
|
const request = await recordSingle(workspace, (c) => c.updateWorkspace(ID("wsp"), { name: "Acme 2" }));
|
|
844
926
|
expect(request.headers["if-match"]).toBeUndefined();
|
|
845
927
|
});
|
|
928
|
+
test("serializes billing notification cursor pagination", async () => {
|
|
929
|
+
const { client, requests } = createClient(() => jsonResponse(page(billingNotification)));
|
|
930
|
+
await client.listBillingNotifications({ cursor: "cur/1", limit: 50 });
|
|
931
|
+
const url = new URL(requests[0]?.url ?? "");
|
|
932
|
+
expect(url.pathname).toBe("/v1/billing/notifications");
|
|
933
|
+
expect(url.searchParams.get("cursor")).toBe("cur/1");
|
|
934
|
+
expect(url.searchParams.get("limit")).toBe("50");
|
|
935
|
+
});
|
|
846
936
|
test("serializes list query params (cursor/limit/filters) with encoding", async () => {
|
|
847
937
|
const { client, requests } = createClient(() => jsonResponse(page(user)));
|
|
848
938
|
await client.listUsers({
|
|
@@ -867,6 +957,16 @@ describe("createManagementClient — one method per design.md §26.2 route", ()
|
|
|
867
957
|
const listRequest = await recordSingle(page(identity), (c) => c.listUserIdentities(ID("env"), ID("usr"), { limit: 10 }));
|
|
868
958
|
expect(new URL(listRequest.url).searchParams.get("environment_id")).toBe(ID("env"));
|
|
869
959
|
});
|
|
960
|
+
test("initiates user recovery with environment context, trimmed reason, and stable key", async () => {
|
|
961
|
+
const request = await recordSingle({
|
|
962
|
+
initiated: true,
|
|
963
|
+
instructions: "Sign in using an already-enrolled verified email OTP or linked social identity, then register a new passkey.",
|
|
964
|
+
}, (client) => client.initiateUserRecovery(ID("env"), ID("usr"), { reason: " account access concern " }, { idempotencyKey: "recovery-attempt-1" }));
|
|
965
|
+
const url = new URL(request.url);
|
|
966
|
+
expect(url.searchParams.get("environment_id")).toBe(ID("env"));
|
|
967
|
+
expect(request.headers["idempotency-key"]).toBe("recovery-attempt-1");
|
|
968
|
+
expect(JSON.parse(request.body ?? "{}")).toEqual({ reason: "account access concern" });
|
|
969
|
+
});
|
|
870
970
|
test("sends the validated JSON body and applies schema defaults", async () => {
|
|
871
971
|
const { client, requests } = createClient(() => jsonResponse(clientResource));
|
|
872
972
|
await client.createClient({
|
|
@@ -995,6 +1095,104 @@ describe("error mapping (design.md §26.3 Problem Details)", () => {
|
|
|
995
1095
|
}
|
|
996
1096
|
});
|
|
997
1097
|
});
|
|
1098
|
+
describe("DLQ records (design.md §29.3)", () => {
|
|
1099
|
+
test("listDlqRecords without params sends no query string", async () => {
|
|
1100
|
+
const { client, requests } = createClient(() => jsonResponse(page(dlqRecord)));
|
|
1101
|
+
const result = await client.listDlqRecords();
|
|
1102
|
+
expect(isSuccess(result)).toBe(true);
|
|
1103
|
+
expect(new URL(requests[0]?.url ?? "").search).toBe("");
|
|
1104
|
+
});
|
|
1105
|
+
test("listDlqRecords serializes cursor, limit, and every filter", async () => {
|
|
1106
|
+
const { client, requests } = createClient(() => jsonResponse(page(dlqRecord)));
|
|
1107
|
+
await client.listDlqRecords({
|
|
1108
|
+
cursor: "cur/1",
|
|
1109
|
+
limit: 20,
|
|
1110
|
+
queue: "webhook-deliveries",
|
|
1111
|
+
event_type: "user.created",
|
|
1112
|
+
environment_id: ID("env"),
|
|
1113
|
+
status: "redriven",
|
|
1114
|
+
failed_after: "2026-08-01T00:00:00Z",
|
|
1115
|
+
failed_before: "2026-08-02T00:00:00Z",
|
|
1116
|
+
});
|
|
1117
|
+
const url = new URL(requests[0]?.url ?? "");
|
|
1118
|
+
expect(url.pathname).toBe("/v1/dlq/records");
|
|
1119
|
+
expect(Object.fromEntries(url.searchParams.entries())).toEqual({
|
|
1120
|
+
cursor: "cur/1",
|
|
1121
|
+
limit: "20",
|
|
1122
|
+
queue: "webhook-deliveries",
|
|
1123
|
+
event_type: "user.created",
|
|
1124
|
+
environment_id: ID("env"),
|
|
1125
|
+
status: "redriven",
|
|
1126
|
+
failed_after: "2026-08-01T00:00:00Z",
|
|
1127
|
+
failed_before: "2026-08-02T00:00:00Z",
|
|
1128
|
+
});
|
|
1129
|
+
});
|
|
1130
|
+
test("getDlqRecord surfaces a null payload for truncated or non-object bodies", async () => {
|
|
1131
|
+
const truncated = {
|
|
1132
|
+
...dlqRecordDetail,
|
|
1133
|
+
payload: null,
|
|
1134
|
+
payload_truncated: true,
|
|
1135
|
+
redrivable: false,
|
|
1136
|
+
};
|
|
1137
|
+
const { client } = createClient(() => jsonResponse(truncated));
|
|
1138
|
+
const result = await client.getDlqRecord(DLQ_RECORD_ID);
|
|
1139
|
+
expect(isSuccess(result)).toBe(true);
|
|
1140
|
+
if (isSuccess(result)) {
|
|
1141
|
+
expect(result.value.data.payload).toBeNull();
|
|
1142
|
+
expect(result.value.data.payload_truncated).toBe(true);
|
|
1143
|
+
expect(result.value.data.redrivable).toBe(false);
|
|
1144
|
+
}
|
|
1145
|
+
});
|
|
1146
|
+
test("redriveDlqRecord sends no body and forwards an Idempotency-Key override", async () => {
|
|
1147
|
+
const { client, requests } = createClient(() => jsonResponse(dlqRedriveResult, 202));
|
|
1148
|
+
await client.redriveDlqRecord(DLQ_RECORD_ID, { idempotencyKey: "idem-dlq-1" });
|
|
1149
|
+
expect(requests[0]?.headers["idempotency-key"]).toBe("idem-dlq-1");
|
|
1150
|
+
expect(requests[0]?.body).toBeUndefined();
|
|
1151
|
+
expect(requests[0]?.headers["content-type"]).toBeUndefined();
|
|
1152
|
+
});
|
|
1153
|
+
test("redriveDlqRecord accepts 202 enqueued and 200 already_* outcomes", async () => {
|
|
1154
|
+
const cases = [
|
|
1155
|
+
[202, "enqueued"],
|
|
1156
|
+
[200, "already_delivered"],
|
|
1157
|
+
[200, "already_redriven"],
|
|
1158
|
+
];
|
|
1159
|
+
for (const [status, outcome] of cases) {
|
|
1160
|
+
const { client } = createClient(() => jsonResponse({ ...dlqRedriveResult, outcome }, status));
|
|
1161
|
+
const result = await client.redriveDlqRecord(DLQ_RECORD_ID);
|
|
1162
|
+
expect(isSuccess(result), `${status} ${outcome}`).toBe(true);
|
|
1163
|
+
if (isSuccess(result))
|
|
1164
|
+
expect(result.value.data.outcome).toBe(outcome);
|
|
1165
|
+
}
|
|
1166
|
+
});
|
|
1167
|
+
test("dlq_redrive_unavailable (503) is a retryable api_error", async () => {
|
|
1168
|
+
const { client } = createClient(() => jsonResponse(problem(503, "dlq_redrive_unavailable"), 503));
|
|
1169
|
+
const result = await client.redriveDlqRecord(DLQ_RECORD_ID);
|
|
1170
|
+
expect(isFailure(result)).toBe(true);
|
|
1171
|
+
if (!isFailure(result))
|
|
1172
|
+
return;
|
|
1173
|
+
expect(result.error.type).toBe("api_error");
|
|
1174
|
+
if (result.error.type === "api_error") {
|
|
1175
|
+
expect(result.error.status).toBe(503);
|
|
1176
|
+
expect(result.error.code).toBe("dlq_redrive_unavailable");
|
|
1177
|
+
expect(result.error.retryable).toBe(true);
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
test("dlq_redrive_in_progress and dlq_record_not_redrivable (409) are not retryable", async () => {
|
|
1181
|
+
for (const code of ["dlq_redrive_in_progress", "dlq_record_not_redrivable"]) {
|
|
1182
|
+
const { client } = createClient(() => jsonResponse(problem(409, code), 409));
|
|
1183
|
+
const result = await client.redriveDlqRecord(DLQ_RECORD_ID);
|
|
1184
|
+
expect(isFailure(result), code).toBe(true);
|
|
1185
|
+
if (!isFailure(result))
|
|
1186
|
+
continue;
|
|
1187
|
+
expect(result.error.type).toBe("api_error");
|
|
1188
|
+
if (result.error.type === "api_error") {
|
|
1189
|
+
expect(result.error.status).toBe(409);
|
|
1190
|
+
expect(result.error.code).toBe(code);
|
|
1191
|
+
expect(result.error.retryable).toBeUndefined();
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
});
|
|
1195
|
+
});
|
|
998
1196
|
describe("createManagementClient option validation", () => {
|
|
999
1197
|
test("rejects an unparseable baseUrl", () => {
|
|
1000
1198
|
expect(() => createManagementClient({ baseUrl: "not a url", apiKey: API_KEY })).toThrow(TypeError);
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* (design.md §26). See `createManagementClient` for the entry point.
|
|
4
4
|
*/
|
|
5
5
|
export { createManagementClient } from "./client.js";
|
|
6
|
-
export type { AuditEventListParams, BillingCheckoutSessionCreateInput, BillingPortalSessionCreateInput, ClientCreateInput, ClientListParams, ClientUpdateInput, ConnectionCreateInput, ConnectionListParams, ConnectionUpdateInput, DomainCreateInput, DomainListParams, DomainUpdateInput, EnvironmentCreateInput, EnvironmentListParams, EnvironmentUpdateInput, ManagementClient, ManagementClientOptions, MauUsageParams, PaginationParams, ProjectCreateInput, ProjectListParams, ProjectUpdateInput, RpMigration, RpMigrationDisableInput, UserBlockInput, UserCreateInput, UserExportJobCreateInput, UserImportJobCreateInput, UserListParams, UserUpdateInput, WebhookCreateInput, WebhookDeliveryListParams, WebhookListParams, WebhookTestInput, WebhookUpdateInput, WorkspaceCreateInput, WorkspaceMemberListParams, WorkspaceListParams, WorkspaceUpdateInput, WriteOptions, } from "./client.js";
|
|
6
|
+
export type { AuditEventListParams, BillingCheckoutSessionCreateInput, BillingPortalSessionCreateInput, ClientCreateInput, ClientListParams, ClientUpdateInput, ConnectionCreateInput, ConnectionListParams, ConnectionUpdateInput, DlqRecordListParams, DomainCreateInput, DomainListParams, DomainUpdateInput, EnvironmentCreateInput, EnvironmentListParams, EnvironmentUpdateInput, ManagementClient, ManagementClientOptions, MauUsageParams, PaginationParams, ProjectCreateInput, ProjectListParams, ProjectUpdateInput, RpMigration, RpMigrationDisableInput, UserBlockInput, UserCreateInput, UserExportJobCreateInput, UserImportJobCreateInput, UserListParams, UserRecoveryInput, UserUpdateInput, WebhookCreateInput, WebhookDeliveryListParams, WebhookListParams, WebhookTestInput, WebhookUpdateInput, WorkspaceCreateInput, WorkspaceMemberListParams, WorkspaceListParams, WorkspaceUpdateInput, WriteOptions, } from "./client.js";
|
|
7
7
|
export type { ApiError, InvalidRequestError, InvalidResponseError, ManagementClientError, NetworkError, } from "./errors.js";
|
|
8
8
|
export { collectAll, DEFAULT_MAX_PAGES, paginate } from "./paginate.js";
|
|
9
9
|
export type { PageFetcher, PaginateOptions } from "./paginate.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartcrab/management-client",
|
|
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",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"access": "public"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@smartcrab/contracts-management": "0.
|
|
30
|
+
"@smartcrab/contracts-management": "0.4.0-next-20261016193833"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"typescript": "5.9.3",
|
package/src/client.test.ts
CHANGED
|
@@ -201,6 +201,33 @@ const webhook = {
|
|
|
201
201
|
created_at: TS,
|
|
202
202
|
updated_at: TS,
|
|
203
203
|
};
|
|
204
|
+
const DLQ_RECORD_ID = `dlq_${"a".repeat(40)}`;
|
|
205
|
+
const dlqRecord = {
|
|
206
|
+
id: DLQ_RECORD_ID,
|
|
207
|
+
queue: "webhook-deliveries",
|
|
208
|
+
event_id: ID("evt"),
|
|
209
|
+
event_type: "user.created",
|
|
210
|
+
webhook_id: ID("whk"),
|
|
211
|
+
environment_id: ID("env"),
|
|
212
|
+
attempts: 8,
|
|
213
|
+
failed_at: TS,
|
|
214
|
+
status: "dead_lettered",
|
|
215
|
+
redriven_at: null,
|
|
216
|
+
redrive_outcome: null,
|
|
217
|
+
};
|
|
218
|
+
const dlqRecordDetail = {
|
|
219
|
+
...dlqRecord,
|
|
220
|
+
payload: { userId: ID("usr"), email: "[redacted]", otp: "[redacted]" },
|
|
221
|
+
payload_truncated: false,
|
|
222
|
+
redrivable: true,
|
|
223
|
+
};
|
|
224
|
+
const dlqRedriveResult = {
|
|
225
|
+
id: DLQ_RECORD_ID,
|
|
226
|
+
queue: "webhook-deliveries",
|
|
227
|
+
status: "redriven",
|
|
228
|
+
outcome: "enqueued",
|
|
229
|
+
redriven_at: TS,
|
|
230
|
+
};
|
|
204
231
|
const auditEvent = {
|
|
205
232
|
id: ID("evt"),
|
|
206
233
|
environment_id: ID("env"),
|
|
@@ -231,6 +258,17 @@ const mauUsage = {
|
|
|
231
258
|
},
|
|
232
259
|
environments: [],
|
|
233
260
|
};
|
|
261
|
+
const billingNotification = {
|
|
262
|
+
notification_key: "payment_failed:episode-1",
|
|
263
|
+
kind: "payment_failed",
|
|
264
|
+
billing_month: null,
|
|
265
|
+
threshold_percent: null,
|
|
266
|
+
current_mau: null,
|
|
267
|
+
free_tier_limit: null,
|
|
268
|
+
grace_ends_at: null,
|
|
269
|
+
restriction_days: null,
|
|
270
|
+
created_at: TS,
|
|
271
|
+
};
|
|
234
272
|
|
|
235
273
|
// ---------------------------------------------------------------------------
|
|
236
274
|
// Recording stub fetch
|
|
@@ -655,6 +693,18 @@ const ROUTES: readonly RouteCase[] = [
|
|
|
655
693
|
responseBody: { id: ID("usr"), status: "active" },
|
|
656
694
|
write: true,
|
|
657
695
|
},
|
|
696
|
+
{
|
|
697
|
+
name: "initiateUserRecovery",
|
|
698
|
+
invoke: (c) => c.initiateUserRecovery(ID("env"), ID("usr"), { reason: "Support request" }),
|
|
699
|
+
method: "POST",
|
|
700
|
+
path: `/users/${ID("usr")}/recovery`,
|
|
701
|
+
responseBody: {
|
|
702
|
+
initiated: true,
|
|
703
|
+
instructions:
|
|
704
|
+
"Sign in using an already-enrolled verified email OTP or linked social identity, then register a new passkey.",
|
|
705
|
+
},
|
|
706
|
+
write: true,
|
|
707
|
+
},
|
|
658
708
|
// User sub-resources
|
|
659
709
|
{
|
|
660
710
|
name: "listUserIdentities",
|
|
@@ -812,6 +862,31 @@ const ROUTES: readonly RouteCase[] = [
|
|
|
812
862
|
responseBody: { delivered: true, response_status: 200, response_time_ms: 12, requested_at: TS },
|
|
813
863
|
write: true,
|
|
814
864
|
},
|
|
865
|
+
// DLQ records (design.md §29.3)
|
|
866
|
+
{
|
|
867
|
+
name: "listDlqRecords",
|
|
868
|
+
invoke: (c) => c.listDlqRecords({ queue: "webhook-deliveries" }),
|
|
869
|
+
method: "GET",
|
|
870
|
+
path: "/dlq/records",
|
|
871
|
+
responseBody: page(dlqRecord),
|
|
872
|
+
write: false,
|
|
873
|
+
},
|
|
874
|
+
{
|
|
875
|
+
name: "getDlqRecord",
|
|
876
|
+
invoke: (c) => c.getDlqRecord(DLQ_RECORD_ID),
|
|
877
|
+
method: "GET",
|
|
878
|
+
path: `/dlq/records/${DLQ_RECORD_ID}`,
|
|
879
|
+
responseBody: dlqRecordDetail,
|
|
880
|
+
write: false,
|
|
881
|
+
},
|
|
882
|
+
{
|
|
883
|
+
name: "redriveDlqRecord",
|
|
884
|
+
invoke: (c) => c.redriveDlqRecord(DLQ_RECORD_ID),
|
|
885
|
+
method: "POST",
|
|
886
|
+
path: `/dlq/records/${DLQ_RECORD_ID}/redrive`,
|
|
887
|
+
responseBody: dlqRedriveResult,
|
|
888
|
+
write: true,
|
|
889
|
+
},
|
|
815
890
|
// Audit / usage / billing
|
|
816
891
|
{
|
|
817
892
|
name: "listAuditEvents",
|
|
@@ -829,6 +904,14 @@ const ROUTES: readonly RouteCase[] = [
|
|
|
829
904
|
responseBody: mauUsage,
|
|
830
905
|
write: false,
|
|
831
906
|
},
|
|
907
|
+
{
|
|
908
|
+
name: "listBillingNotifications",
|
|
909
|
+
invoke: (c) => c.listBillingNotifications({ limit: 25 }),
|
|
910
|
+
method: "GET",
|
|
911
|
+
path: "/billing/notifications",
|
|
912
|
+
responseBody: page(billingNotification),
|
|
913
|
+
write: false,
|
|
914
|
+
},
|
|
832
915
|
{
|
|
833
916
|
name: "createBillingCheckoutSession",
|
|
834
917
|
invoke: (c) =>
|
|
@@ -853,7 +936,7 @@ const ROUTES: readonly RouteCase[] = [
|
|
|
853
936
|
|
|
854
937
|
describe("createManagementClient — one method per design.md §26.2 route", () => {
|
|
855
938
|
test(`covers ${ROUTES.length} routes`, () => {
|
|
856
|
-
expect(ROUTES.length).toBe(
|
|
939
|
+
expect(ROUTES.length).toBe(67);
|
|
857
940
|
expect(new Set(ROUTES.map((r) => r.name)).size).toBe(ROUTES.length);
|
|
858
941
|
});
|
|
859
942
|
|
|
@@ -904,6 +987,14 @@ describe("createManagementClient — one method per design.md §26.2 route", ()
|
|
|
904
987
|
expect(request.headers["if-match"]).toBeUndefined();
|
|
905
988
|
});
|
|
906
989
|
|
|
990
|
+
test("serializes billing notification cursor pagination", async () => {
|
|
991
|
+
const { client, requests } = createClient(() => jsonResponse(page(billingNotification)));
|
|
992
|
+
await client.listBillingNotifications({ cursor: "cur/1", limit: 50 });
|
|
993
|
+
const url = new URL(requests[0]?.url ?? "");
|
|
994
|
+
expect(url.pathname).toBe("/v1/billing/notifications");
|
|
995
|
+
expect(url.searchParams.get("cursor")).toBe("cur/1");
|
|
996
|
+
expect(url.searchParams.get("limit")).toBe("50");
|
|
997
|
+
});
|
|
907
998
|
test("serializes list query params (cursor/limit/filters) with encoding", async () => {
|
|
908
999
|
const { client, requests } = createClient(() => jsonResponse(page(user)));
|
|
909
1000
|
await client.listUsers({
|
|
@@ -934,6 +1025,26 @@ describe("createManagementClient — one method per design.md §26.2 route", ()
|
|
|
934
1025
|
);
|
|
935
1026
|
expect(new URL(listRequest.url).searchParams.get("environment_id")).toBe(ID("env"));
|
|
936
1027
|
});
|
|
1028
|
+
test("initiates user recovery with environment context, trimmed reason, and stable key", async () => {
|
|
1029
|
+
const request = await recordSingle(
|
|
1030
|
+
{
|
|
1031
|
+
initiated: true,
|
|
1032
|
+
instructions:
|
|
1033
|
+
"Sign in using an already-enrolled verified email OTP or linked social identity, then register a new passkey.",
|
|
1034
|
+
},
|
|
1035
|
+
(client) =>
|
|
1036
|
+
client.initiateUserRecovery(
|
|
1037
|
+
ID("env"),
|
|
1038
|
+
ID("usr"),
|
|
1039
|
+
{ reason: " account access concern " },
|
|
1040
|
+
{ idempotencyKey: "recovery-attempt-1" },
|
|
1041
|
+
),
|
|
1042
|
+
);
|
|
1043
|
+
const url = new URL(request.url);
|
|
1044
|
+
expect(url.searchParams.get("environment_id")).toBe(ID("env"));
|
|
1045
|
+
expect(request.headers["idempotency-key"]).toBe("recovery-attempt-1");
|
|
1046
|
+
expect(JSON.parse(request.body ?? "{}")).toEqual({ reason: "account access concern" });
|
|
1047
|
+
});
|
|
937
1048
|
|
|
938
1049
|
test("sends the validated JSON body and applies schema defaults", async () => {
|
|
939
1050
|
const { client, requests } = createClient(() => jsonResponse(clientResource));
|
|
@@ -1075,6 +1186,110 @@ describe("error mapping (design.md §26.3 Problem Details)", () => {
|
|
|
1075
1186
|
});
|
|
1076
1187
|
});
|
|
1077
1188
|
|
|
1189
|
+
describe("DLQ records (design.md §29.3)", () => {
|
|
1190
|
+
test("listDlqRecords without params sends no query string", async () => {
|
|
1191
|
+
const { client, requests } = createClient(() => jsonResponse(page(dlqRecord)));
|
|
1192
|
+
const result = await client.listDlqRecords();
|
|
1193
|
+
expect(isSuccess(result)).toBe(true);
|
|
1194
|
+
expect(new URL(requests[0]?.url ?? "").search).toBe("");
|
|
1195
|
+
});
|
|
1196
|
+
|
|
1197
|
+
test("listDlqRecords serializes cursor, limit, and every filter", async () => {
|
|
1198
|
+
const { client, requests } = createClient(() => jsonResponse(page(dlqRecord)));
|
|
1199
|
+
await client.listDlqRecords({
|
|
1200
|
+
cursor: "cur/1",
|
|
1201
|
+
limit: 20,
|
|
1202
|
+
queue: "webhook-deliveries",
|
|
1203
|
+
event_type: "user.created",
|
|
1204
|
+
environment_id: ID("env"),
|
|
1205
|
+
status: "redriven",
|
|
1206
|
+
failed_after: "2026-08-01T00:00:00Z",
|
|
1207
|
+
failed_before: "2026-08-02T00:00:00Z",
|
|
1208
|
+
});
|
|
1209
|
+
const url = new URL(requests[0]?.url ?? "");
|
|
1210
|
+
expect(url.pathname).toBe("/v1/dlq/records");
|
|
1211
|
+
expect(Object.fromEntries(url.searchParams.entries())).toEqual({
|
|
1212
|
+
cursor: "cur/1",
|
|
1213
|
+
limit: "20",
|
|
1214
|
+
queue: "webhook-deliveries",
|
|
1215
|
+
event_type: "user.created",
|
|
1216
|
+
environment_id: ID("env"),
|
|
1217
|
+
status: "redriven",
|
|
1218
|
+
failed_after: "2026-08-01T00:00:00Z",
|
|
1219
|
+
failed_before: "2026-08-02T00:00:00Z",
|
|
1220
|
+
});
|
|
1221
|
+
});
|
|
1222
|
+
|
|
1223
|
+
test("getDlqRecord surfaces a null payload for truncated or non-object bodies", async () => {
|
|
1224
|
+
const truncated = {
|
|
1225
|
+
...dlqRecordDetail,
|
|
1226
|
+
payload: null,
|
|
1227
|
+
payload_truncated: true,
|
|
1228
|
+
redrivable: false,
|
|
1229
|
+
};
|
|
1230
|
+
const { client } = createClient(() => jsonResponse(truncated));
|
|
1231
|
+
const result = await client.getDlqRecord(DLQ_RECORD_ID);
|
|
1232
|
+
expect(isSuccess(result)).toBe(true);
|
|
1233
|
+
if (isSuccess(result)) {
|
|
1234
|
+
expect(result.value.data.payload).toBeNull();
|
|
1235
|
+
expect(result.value.data.payload_truncated).toBe(true);
|
|
1236
|
+
expect(result.value.data.redrivable).toBe(false);
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
|
|
1240
|
+
test("redriveDlqRecord sends no body and forwards an Idempotency-Key override", async () => {
|
|
1241
|
+
const { client, requests } = createClient(() => jsonResponse(dlqRedriveResult, 202));
|
|
1242
|
+
await client.redriveDlqRecord(DLQ_RECORD_ID, { idempotencyKey: "idem-dlq-1" });
|
|
1243
|
+
expect(requests[0]?.headers["idempotency-key"]).toBe("idem-dlq-1");
|
|
1244
|
+
expect(requests[0]?.body).toBeUndefined();
|
|
1245
|
+
expect(requests[0]?.headers["content-type"]).toBeUndefined();
|
|
1246
|
+
});
|
|
1247
|
+
|
|
1248
|
+
test("redriveDlqRecord accepts 202 enqueued and 200 already_* outcomes", async () => {
|
|
1249
|
+
const cases = [
|
|
1250
|
+
[202, "enqueued"],
|
|
1251
|
+
[200, "already_delivered"],
|
|
1252
|
+
[200, "already_redriven"],
|
|
1253
|
+
] as const;
|
|
1254
|
+
for (const [status, outcome] of cases) {
|
|
1255
|
+
const { client } = createClient(() => jsonResponse({ ...dlqRedriveResult, outcome }, status));
|
|
1256
|
+
const result = await client.redriveDlqRecord(DLQ_RECORD_ID);
|
|
1257
|
+
expect(isSuccess(result), `${status} ${outcome}`).toBe(true);
|
|
1258
|
+
if (isSuccess(result)) expect(result.value.data.outcome).toBe(outcome);
|
|
1259
|
+
}
|
|
1260
|
+
});
|
|
1261
|
+
|
|
1262
|
+
test("dlq_redrive_unavailable (503) is a retryable api_error", async () => {
|
|
1263
|
+
const { client } = createClient(() =>
|
|
1264
|
+
jsonResponse(problem(503, "dlq_redrive_unavailable"), 503),
|
|
1265
|
+
);
|
|
1266
|
+
const result = await client.redriveDlqRecord(DLQ_RECORD_ID);
|
|
1267
|
+
expect(isFailure(result)).toBe(true);
|
|
1268
|
+
if (!isFailure(result)) return;
|
|
1269
|
+
expect(result.error.type).toBe("api_error");
|
|
1270
|
+
if (result.error.type === "api_error") {
|
|
1271
|
+
expect(result.error.status).toBe(503);
|
|
1272
|
+
expect(result.error.code).toBe("dlq_redrive_unavailable");
|
|
1273
|
+
expect(result.error.retryable).toBe(true);
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
|
|
1277
|
+
test("dlq_redrive_in_progress and dlq_record_not_redrivable (409) are not retryable", async () => {
|
|
1278
|
+
for (const code of ["dlq_redrive_in_progress", "dlq_record_not_redrivable"]) {
|
|
1279
|
+
const { client } = createClient(() => jsonResponse(problem(409, code), 409));
|
|
1280
|
+
const result = await client.redriveDlqRecord(DLQ_RECORD_ID);
|
|
1281
|
+
expect(isFailure(result), code).toBe(true);
|
|
1282
|
+
if (!isFailure(result)) continue;
|
|
1283
|
+
expect(result.error.type).toBe("api_error");
|
|
1284
|
+
if (result.error.type === "api_error") {
|
|
1285
|
+
expect(result.error.status).toBe(409);
|
|
1286
|
+
expect(result.error.code).toBe(code);
|
|
1287
|
+
expect(result.error.retryable).toBeUndefined();
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
});
|
|
1291
|
+
});
|
|
1292
|
+
|
|
1078
1293
|
describe("createManagementClient option validation", () => {
|
|
1079
1294
|
test("rejects an unparseable baseUrl", () => {
|
|
1080
1295
|
expect(() => createManagementClient({ baseUrl: "not a url", apiKey: API_KEY })).toThrow(
|
package/src/client.ts
CHANGED
|
@@ -79,6 +79,20 @@ export interface WebhookDeliveryListParams extends PaginationParams {
|
|
|
79
79
|
readonly occurred_after?: string;
|
|
80
80
|
readonly occurred_before?: string;
|
|
81
81
|
}
|
|
82
|
+
|
|
83
|
+
export interface DlqRecordListParams extends PaginationParams {
|
|
84
|
+
readonly queue?: cm.DlqQueue;
|
|
85
|
+
/** Exact domain event type (e.g. `user.created`). */
|
|
86
|
+
readonly event_type?: string;
|
|
87
|
+
/** Only records of this Environment; workspace-level records are excluded. */
|
|
88
|
+
readonly environment_id?: string;
|
|
89
|
+
readonly status?: cm.DlqRecordStatus;
|
|
90
|
+
/** ISO 8601 date-time. */
|
|
91
|
+
readonly failed_after?: string;
|
|
92
|
+
/** ISO 8601 date-time. */
|
|
93
|
+
readonly failed_before?: string;
|
|
94
|
+
}
|
|
95
|
+
|
|
82
96
|
export interface AuditEventListParams extends PaginationParams {
|
|
83
97
|
readonly environment_id: string;
|
|
84
98
|
readonly actor_type?: cm.AuditActorType;
|
|
@@ -93,7 +107,7 @@ export interface MauUsageParams {
|
|
|
93
107
|
readonly billing_month?: string;
|
|
94
108
|
readonly environment_id?: string;
|
|
95
109
|
}
|
|
96
|
-
|
|
110
|
+
export type BillingNotificationListParams = PaginationParams;
|
|
97
111
|
// ---------------------------------------------------------------------------
|
|
98
112
|
// Request body input types (zod input side: schema-defaulted fields optional)
|
|
99
113
|
// ---------------------------------------------------------------------------
|
|
@@ -115,6 +129,7 @@ export type DomainUpdateInput = InputOf<typeof cm.domainUpdateRequestSchema>;
|
|
|
115
129
|
export type UserCreateInput = InputOf<typeof cm.userCreateRequestSchema>;
|
|
116
130
|
export type UserUpdateInput = InputOf<typeof cm.userUpdateRequestSchema>;
|
|
117
131
|
export type UserBlockInput = InputOf<typeof cm.userBlockRequestSchema>;
|
|
132
|
+
export type UserRecoveryInput = InputOf<typeof cm.userRecoveryRequestSchema>;
|
|
118
133
|
export type UserImportJobCreateInput = InputOf<typeof cm.userImportJobCreateRequestSchema>;
|
|
119
134
|
export type UserExportJobCreateInput = InputOf<typeof cm.userExportJobCreateRequestSchema>;
|
|
120
135
|
export type WebhookCreateInput = InputOf<typeof cm.webhookCreateRequestSchema>;
|
|
@@ -226,6 +241,12 @@ export interface ManagementClient {
|
|
|
226
241
|
userId: string,
|
|
227
242
|
options?: WriteOptions,
|
|
228
243
|
): Api<cm.UserUnblockResponse>;
|
|
244
|
+
initiateUserRecovery(
|
|
245
|
+
environmentId: string,
|
|
246
|
+
userId: string,
|
|
247
|
+
body: UserRecoveryInput,
|
|
248
|
+
options?: WriteOptions,
|
|
249
|
+
): Api<cm.UserRecoveryResponse>;
|
|
229
250
|
|
|
230
251
|
// User sub-resources (identities / passkeys / sessions)
|
|
231
252
|
listUserIdentities(
|
|
@@ -302,9 +323,17 @@ export interface ManagementClient {
|
|
|
302
323
|
options?: WriteOptions,
|
|
303
324
|
): Api<cm.WebhookTestResponse>;
|
|
304
325
|
|
|
326
|
+
// DLQ records (design.md §29.3)
|
|
327
|
+
listDlqRecords(params?: DlqRecordListParams): Api<cm.DlqRecordListResponse>;
|
|
328
|
+
getDlqRecord(recordId: string): Api<cm.DlqRecordDetail>;
|
|
329
|
+
redriveDlqRecord(recordId: string, options?: WriteOptions): Api<cm.DlqRedriveResponse>;
|
|
330
|
+
|
|
305
331
|
// Audit events / usage / billing
|
|
306
332
|
listAuditEvents(params: AuditEventListParams): Api<cm.AuditEventListResponse>;
|
|
307
333
|
getMauUsage(params?: MauUsageParams): Api<cm.MauUsageResponse>;
|
|
334
|
+
listBillingNotifications(
|
|
335
|
+
params?: BillingNotificationListParams,
|
|
336
|
+
): Api<cm.BillingNotificationListResponse>;
|
|
308
337
|
createBillingCheckoutSession(
|
|
309
338
|
body: BillingCheckoutSessionCreateInput,
|
|
310
339
|
options?: WriteOptions,
|
|
@@ -708,6 +737,16 @@ export const createManagementClient = (options: ManagementClientOptions): Manage
|
|
|
708
737
|
}),
|
|
709
738
|
cm.userUnblockResponseSchema,
|
|
710
739
|
),
|
|
740
|
+
initiateUserRecovery: (environmentId, userId, body, writeOptions) =>
|
|
741
|
+
withValidBody(cm.userRecoveryRequestSchema, body, (valid) =>
|
|
742
|
+
send(
|
|
743
|
+
config,
|
|
744
|
+
writeSpec("POST", `/users/${segment(userId)}/recovery`, valid, writeOptions, {
|
|
745
|
+
environment_id: environmentId,
|
|
746
|
+
}),
|
|
747
|
+
cm.userRecoveryResponseSchema,
|
|
748
|
+
),
|
|
749
|
+
),
|
|
711
750
|
|
|
712
751
|
// --------------------------------------------------------------
|
|
713
752
|
// User sub-resources
|
|
@@ -881,6 +920,33 @@ export const createManagementClient = (options: ManagementClientOptions): Manage
|
|
|
881
920
|
),
|
|
882
921
|
),
|
|
883
922
|
|
|
923
|
+
// --------------------------------------------------------------
|
|
924
|
+
// DLQ records (design.md §29.3)
|
|
925
|
+
// --------------------------------------------------------------
|
|
926
|
+
listDlqRecords: (params) =>
|
|
927
|
+
send(
|
|
928
|
+
config,
|
|
929
|
+
getSpec("/dlq/records", {
|
|
930
|
+
cursor: params?.cursor,
|
|
931
|
+
limit: params?.limit,
|
|
932
|
+
queue: params?.queue,
|
|
933
|
+
event_type: params?.event_type,
|
|
934
|
+
environment_id: params?.environment_id,
|
|
935
|
+
status: params?.status,
|
|
936
|
+
failed_after: params?.failed_after,
|
|
937
|
+
failed_before: params?.failed_before,
|
|
938
|
+
}),
|
|
939
|
+
cm.dlqRecordListResponseSchema,
|
|
940
|
+
),
|
|
941
|
+
getDlqRecord: (recordId) =>
|
|
942
|
+
send(config, getSpec(`/dlq/records/${segment(recordId)}`), cm.dlqRecordDetailSchema),
|
|
943
|
+
redriveDlqRecord: (recordId, writeOptions) =>
|
|
944
|
+
send(
|
|
945
|
+
config,
|
|
946
|
+
writeSpec("POST", `/dlq/records/${segment(recordId)}/redrive`, undefined, writeOptions),
|
|
947
|
+
cm.dlqRedriveResponseSchema,
|
|
948
|
+
),
|
|
949
|
+
|
|
884
950
|
// --------------------------------------------------------------
|
|
885
951
|
// Audit events / usage / billing
|
|
886
952
|
// --------------------------------------------------------------
|
|
@@ -910,6 +976,15 @@ export const createManagementClient = (options: ManagementClientOptions): Manage
|
|
|
910
976
|
}),
|
|
911
977
|
cm.mauUsageResponseSchema,
|
|
912
978
|
),
|
|
979
|
+
listBillingNotifications: (params) =>
|
|
980
|
+
send(
|
|
981
|
+
config,
|
|
982
|
+
getSpec("/billing/notifications", {
|
|
983
|
+
cursor: params?.cursor,
|
|
984
|
+
limit: params?.limit,
|
|
985
|
+
}),
|
|
986
|
+
cm.billingNotificationListResponseSchema,
|
|
987
|
+
),
|
|
913
988
|
createBillingCheckoutSession: (body, writeOptions) =>
|
|
914
989
|
withValidBody(cm.billingCheckoutSessionCreateRequestSchema, body, (valid) =>
|
|
915
990
|
send(
|
package/src/index.ts
CHANGED
|
@@ -13,6 +13,7 @@ export type {
|
|
|
13
13
|
ConnectionCreateInput,
|
|
14
14
|
ConnectionListParams,
|
|
15
15
|
ConnectionUpdateInput,
|
|
16
|
+
DlqRecordListParams,
|
|
16
17
|
DomainCreateInput,
|
|
17
18
|
DomainListParams,
|
|
18
19
|
DomainUpdateInput,
|
|
@@ -33,6 +34,7 @@ export type {
|
|
|
33
34
|
UserExportJobCreateInput,
|
|
34
35
|
UserImportJobCreateInput,
|
|
35
36
|
UserListParams,
|
|
37
|
+
UserRecoveryInput,
|
|
36
38
|
UserUpdateInput,
|
|
37
39
|
WebhookCreateInput,
|
|
38
40
|
WebhookDeliveryListParams,
|