@idelio/contracts 0.1.0-beta.0 → 0.1.0-beta.1

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.
@@ -4,15 +4,17 @@ export declare const webhookEndpointSchema: z.ZodObject<{
4
4
  url: z.ZodString;
5
5
  events: z.ZodArray<z.ZodEnum<{
6
6
  "brand.completed": "brand.completed";
7
- "brand.updated": "brand.updated";
8
7
  "asset.ready": "asset.ready";
9
8
  "asset.regenerated": "asset.regenerated";
10
9
  "job.failed": "job.failed";
11
10
  "credits.low": "credits.low";
12
- "credits.settled": "credits.settled";
13
- "subscription.changed": "subscription.changed";
14
11
  }>>;
15
12
  disabled: z.ZodBoolean;
13
+ disabled_reason: z.ZodNullable<z.ZodEnum<{
14
+ manual: "manual";
15
+ failures: "failures";
16
+ }>>;
17
+ consecutive_failures: z.ZodNumber;
16
18
  created_at: z.ZodString;
17
19
  }, z.core.$strip>;
18
20
  export declare const webhookEndpointCreateResponseSchema: z.ZodObject<{
@@ -21,15 +23,17 @@ export declare const webhookEndpointCreateResponseSchema: z.ZodObject<{
21
23
  url: z.ZodString;
22
24
  events: z.ZodArray<z.ZodEnum<{
23
25
  "brand.completed": "brand.completed";
24
- "brand.updated": "brand.updated";
25
26
  "asset.ready": "asset.ready";
26
27
  "asset.regenerated": "asset.regenerated";
27
28
  "job.failed": "job.failed";
28
29
  "credits.low": "credits.low";
29
- "credits.settled": "credits.settled";
30
- "subscription.changed": "subscription.changed";
31
30
  }>>;
32
31
  disabled: z.ZodBoolean;
32
+ disabled_reason: z.ZodNullable<z.ZodEnum<{
33
+ manual: "manual";
34
+ failures: "failures";
35
+ }>>;
36
+ consecutive_failures: z.ZodNumber;
33
37
  created_at: z.ZodString;
34
38
  }, z.core.$strip>;
35
39
  secret: z.ZodString;
@@ -38,25 +42,19 @@ export declare const createWebhookEndpointRequestSchema: z.ZodObject<{
38
42
  url: z.ZodString;
39
43
  events: z.ZodArray<z.ZodEnum<{
40
44
  "brand.completed": "brand.completed";
41
- "brand.updated": "brand.updated";
42
45
  "asset.ready": "asset.ready";
43
46
  "asset.regenerated": "asset.regenerated";
44
47
  "job.failed": "job.failed";
45
48
  "credits.low": "credits.low";
46
- "credits.settled": "credits.settled";
47
- "subscription.changed": "subscription.changed";
48
49
  }>>;
49
50
  }, z.core.$strip>;
50
51
  export declare const updateWebhookEndpointRequestSchema: z.ZodObject<{
51
52
  events: z.ZodOptional<z.ZodArray<z.ZodEnum<{
52
53
  "brand.completed": "brand.completed";
53
- "brand.updated": "brand.updated";
54
54
  "asset.ready": "asset.ready";
55
55
  "asset.regenerated": "asset.regenerated";
56
56
  "job.failed": "job.failed";
57
57
  "credits.low": "credits.low";
58
- "credits.settled": "credits.settled";
59
- "subscription.changed": "subscription.changed";
60
58
  }>>>;
61
59
  disabled: z.ZodOptional<z.ZodBoolean>;
62
60
  }, z.core.$strip>;
@@ -72,3 +70,66 @@ export declare const stripeWebhookEventSchema: z.ZodObject<{
72
70
  }, z.core.$strip>>;
73
71
  }, z.core.$strip>;
74
72
  export type StripeWebhookEvent = z.infer<typeof stripeWebhookEventSchema>;
73
+ export declare const webhookEventDataSchemas: {
74
+ readonly "brand.completed": z.ZodObject<{
75
+ brand_id: z.ZodString;
76
+ job_id: z.ZodString;
77
+ status: z.ZodEnum<{
78
+ completed: "completed";
79
+ completed_with_errors: "completed_with_errors";
80
+ }>;
81
+ failed_kinds: z.ZodArray<z.ZodString>;
82
+ credits_used: z.ZodNumber;
83
+ }, z.core.$strip>;
84
+ readonly "asset.ready": z.ZodObject<{
85
+ asset_id: z.ZodString;
86
+ kind: z.ZodString;
87
+ brand_id: z.ZodString;
88
+ job_id: z.ZodString;
89
+ }, z.core.$strip>;
90
+ readonly "asset.regenerated": z.ZodObject<{
91
+ asset_id: z.ZodString;
92
+ kind: z.ZodString;
93
+ brand_id: z.ZodString;
94
+ job_id: z.ZodNullable<z.ZodString>;
95
+ }, z.core.$strip>;
96
+ readonly "job.failed": z.ZodObject<{
97
+ job_id: z.ZodString;
98
+ job_kind: z.ZodEnum<{
99
+ brand_generation: "brand_generation";
100
+ asset_regeneration: "asset_regeneration";
101
+ brand_expand: "brand_expand";
102
+ brand_export: "brand_export";
103
+ brand_bundle: "brand_bundle";
104
+ brand_dna_refine: "brand_dna_refine";
105
+ }>;
106
+ brand_id: z.ZodNullable<z.ZodString>;
107
+ canceled: z.ZodBoolean;
108
+ reason: z.ZodOptional<z.ZodString>;
109
+ }, z.core.$strip>;
110
+ readonly "credits.low": z.ZodObject<{
111
+ balance: z.ZodNumber;
112
+ threshold: z.ZodNumber;
113
+ }, z.core.$strip>;
114
+ };
115
+ export type WebhookEventData = {
116
+ [K in keyof typeof webhookEventDataSchemas]: z.infer<(typeof webhookEventDataSchemas)[K]>;
117
+ };
118
+ export declare const webhookDeliveryStatuses: readonly ["pending", "delivered", "failed"];
119
+ export declare const webhookDeliverySchema: z.ZodObject<{
120
+ id: z.ZodString;
121
+ event_id: z.ZodString;
122
+ event_type: z.ZodString;
123
+ status: z.ZodEnum<{
124
+ failed: "failed";
125
+ pending: "pending";
126
+ delivered: "delivered";
127
+ }>;
128
+ attempt_count: z.ZodNumber;
129
+ last_status_code: z.ZodNullable<z.ZodNumber>;
130
+ last_error: z.ZodNullable<z.ZodString>;
131
+ payload: z.ZodRecord<z.ZodString, z.ZodUnknown>;
132
+ created_at: z.ZodString;
133
+ delivered_at: z.ZodNullable<z.ZodString>;
134
+ }, z.core.$strip>;
135
+ export type WebhookDelivery = z.infer<typeof webhookDeliverySchema>;
package/dist/webhooks.js CHANGED
@@ -1,10 +1,13 @@
1
1
  import { z } from "zod";
2
2
  import { webhookEventTypes } from "./events.js";
3
+ import { jobKinds } from "./jobs.js";
3
4
  export const webhookEndpointSchema = z.object({
4
5
  id: z.string(),
5
6
  url: z.string().url(),
6
7
  events: z.array(z.enum(webhookEventTypes)),
7
8
  disabled: z.boolean(),
9
+ disabled_reason: z.enum(["manual", "failures"]).nullable(),
10
+ consecutive_failures: z.number().int(),
8
11
  created_at: z.string().datetime(),
9
12
  });
10
13
  export const webhookEndpointCreateResponseSchema = z.object({
@@ -24,3 +27,48 @@ export const stripeWebhookEventSchema = z.object({
24
27
  type: z.string(),
25
28
  data: z.object({ object: z.record(z.string(), z.unknown()) }).optional(),
26
29
  });
30
+ export const webhookEventDataSchemas = {
31
+ "brand.completed": z.object({
32
+ brand_id: z.string(),
33
+ job_id: z.string(),
34
+ status: z.enum(["completed", "completed_with_errors"]),
35
+ failed_kinds: z.array(z.string()),
36
+ credits_used: z.number().int(),
37
+ }),
38
+ "asset.ready": z.object({
39
+ asset_id: z.string(),
40
+ kind: z.string(),
41
+ brand_id: z.string(),
42
+ job_id: z.string(),
43
+ }),
44
+ "asset.regenerated": z.object({
45
+ asset_id: z.string(),
46
+ kind: z.string(),
47
+ brand_id: z.string(),
48
+ job_id: z.string().nullable(),
49
+ }),
50
+ "job.failed": z.object({
51
+ job_id: z.string(),
52
+ job_kind: z.enum(jobKinds),
53
+ brand_id: z.string().nullable(),
54
+ canceled: z.boolean(),
55
+ reason: z.string().optional(),
56
+ }),
57
+ "credits.low": z.object({
58
+ balance: z.number().int(),
59
+ threshold: z.number().int(),
60
+ }),
61
+ };
62
+ export const webhookDeliveryStatuses = ["pending", "delivered", "failed"];
63
+ export const webhookDeliverySchema = z.object({
64
+ id: z.string(),
65
+ event_id: z.string(),
66
+ event_type: z.string(),
67
+ status: z.enum(webhookDeliveryStatuses),
68
+ attempt_count: z.number().int(),
69
+ last_status_code: z.number().int().nullable(),
70
+ last_error: z.string().nullable(),
71
+ payload: z.record(z.string(), z.unknown()),
72
+ created_at: z.string().datetime(),
73
+ delivered_at: z.string().datetime().nullable(),
74
+ });