@automate.ax/catalog 0.74.0 → 0.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/authoring.d.ts +1 -0
  2. package/dist/authoring.js +1 -0
  3. package/dist/triggers/airtable.js +1 -2
  4. package/dist/triggers/asana.js +1 -2
  5. package/dist/triggers/brevo.js +1 -2
  6. package/dist/triggers/core-dashboard.d.ts +374 -0
  7. package/dist/triggers/core-dashboard.js +202 -0
  8. package/dist/triggers/core-http.d.ts +30 -0
  9. package/dist/triggers/core-http.js +43 -0
  10. package/dist/triggers/core-invocation.d.ts +9 -0
  11. package/dist/triggers/core-invocation.js +15 -0
  12. package/dist/triggers/core-mailhook.d.ts +35 -0
  13. package/dist/triggers/core-mailhook.js +63 -0
  14. package/dist/triggers/core-schedule.d.ts +9 -0
  15. package/dist/triggers/core-schedule.js +17 -0
  16. package/dist/triggers/core.d.ts +15 -426
  17. package/dist/triggers/core.js +16 -346
  18. package/dist/triggers/github.js +4 -5
  19. package/dist/triggers/google.js +4 -5
  20. package/dist/triggers/index.d.ts +20 -20
  21. package/dist/triggers/index.js +2 -1
  22. package/dist/triggers/linear.js +1 -2
  23. package/dist/triggers/microsoft.js +3 -4
  24. package/dist/triggers/name.d.ts +13 -0
  25. package/dist/triggers/name.js +31 -0
  26. package/dist/triggers/resend.js +1 -2
  27. package/dist/triggers/slack.js +3 -4
  28. package/dist/triggers/trello.js +1 -2
  29. package/dist/triggers/vercel.js +5 -6
  30. package/dist/triggers/whatsapp.js +1 -2
  31. package/package.json +118 -5
  32. package/src/authoring.ts +8 -0
  33. package/src/triggers/airtable.ts +1 -2
  34. package/src/triggers/asana.ts +1 -2
  35. package/src/triggers/brevo.ts +1 -2
  36. package/src/triggers/core-dashboard.ts +361 -0
  37. package/src/triggers/core-http.ts +69 -0
  38. package/src/triggers/core-invocation.ts +18 -0
  39. package/src/triggers/core-mailhook.ts +83 -0
  40. package/src/triggers/core-schedule.ts +21 -0
  41. package/src/triggers/core.ts +38 -544
  42. package/src/triggers/github.ts +4 -5
  43. package/src/triggers/google.ts +4 -5
  44. package/src/triggers/index.ts +2 -1
  45. package/src/triggers/linear.ts +1 -2
  46. package/src/triggers/microsoft.ts +3 -4
  47. package/src/triggers/name.ts +37 -0
  48. package/src/triggers/resend.ts +1 -2
  49. package/src/triggers/slack.ts +3 -4
  50. package/src/triggers/trello.ts +1 -2
  51. package/src/triggers/vercel.ts +5 -6
  52. package/src/triggers/whatsapp.ts +1 -2
@@ -1,4 +1,3 @@
1
- import { vercelService } from "../catalog.js";
2
1
  const VERCEL_DEPLOYMENT_ACCOUNT = {
3
2
  connectionOptions: [
4
3
  {
@@ -6,7 +5,7 @@ const VERCEL_DEPLOYMENT_ACCOUNT = {
6
5
  requiredScopes: ["deployment:read"],
7
6
  },
8
7
  ],
9
- serviceId: vercelService.id,
8
+ serviceId: "vercel",
10
9
  };
11
10
  const VERCEL_INTEGRATION_CONFIGURATION_ACCOUNT = {
12
11
  connectionOptions: [
@@ -15,7 +14,7 @@ const VERCEL_INTEGRATION_CONFIGURATION_ACCOUNT = {
15
14
  requiredScopes: [],
16
15
  },
17
16
  ],
18
- serviceId: vercelService.id,
17
+ serviceId: "vercel",
19
18
  };
20
19
  const VERCEL_PROJECT_ACCOUNT = {
21
20
  connectionOptions: [
@@ -24,7 +23,7 @@ const VERCEL_PROJECT_ACCOUNT = {
24
23
  requiredScopes: ["project:read"],
25
24
  },
26
25
  ],
27
- serviceId: vercelService.id,
26
+ serviceId: "vercel",
28
27
  };
29
28
  const VERCEL_PROJECT_DOMAIN_ACCOUNT = {
30
29
  connectionOptions: [
@@ -33,7 +32,7 @@ const VERCEL_PROJECT_DOMAIN_ACCOUNT = {
33
32
  requiredScopes: ["domain:read"],
34
33
  },
35
34
  ],
36
- serviceId: vercelService.id,
35
+ serviceId: "vercel",
37
36
  };
38
37
  const VERCEL_PROJECT_ENVIRONMENT_VARIABLE_ACCOUNT = {
39
38
  connectionOptions: [
@@ -42,7 +41,7 @@ const VERCEL_PROJECT_ENVIRONMENT_VARIABLE_ACCOUNT = {
42
41
  requiredScopes: ["global-project-env-vars:read"],
43
42
  },
44
43
  ],
45
- serviceId: vercelService.id,
44
+ serviceId: "vercel",
46
45
  };
47
46
  export const vercelTriggerDefinitions = {
48
47
  vercelDeployment: {
@@ -1,11 +1,10 @@
1
- import { whatsappService } from "../catalog.js";
2
1
  const WHATSAPP_ACCOUNT = {
3
2
  connectionOptions: [
4
3
  {
5
4
  requiredScopes: ["whatsapp_business_messaging"],
6
5
  },
7
6
  ],
8
- serviceId: whatsappService.id,
7
+ serviceId: "whatsapp",
9
8
  };
10
9
  export const whatsappTriggerDefinitions = {
11
10
  whatsappMessageDelivered: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automate.ax/catalog",
3
- "version": "0.74.0",
3
+ "version": "0.76.0",
4
4
  "description": "Shared integration service and trigger definitions for Automate.ax.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -18,7 +18,26 @@
18
18
  },
19
19
  "zshy": {
20
20
  "exports": {
21
- ".": "./src/index.ts"
21
+ ".": "./src/index.ts",
22
+ "./authoring": "./src/authoring.ts",
23
+ "./triggers/airtable": "./src/triggers/airtable.ts",
24
+ "./triggers/asana": "./src/triggers/asana.ts",
25
+ "./triggers/brevo": "./src/triggers/brevo.ts",
26
+ "./triggers/core-dashboard": "./src/triggers/core-dashboard.ts",
27
+ "./triggers/core-http": "./src/triggers/core-http.ts",
28
+ "./triggers/core-invocation": "./src/triggers/core-invocation.ts",
29
+ "./triggers/core-mailhook": "./src/triggers/core-mailhook.ts",
30
+ "./triggers/core-schedule": "./src/triggers/core-schedule.ts",
31
+ "./triggers/github": "./src/triggers/github.ts",
32
+ "./triggers/google": "./src/triggers/google.ts",
33
+ "./triggers/linear": "./src/triggers/linear.ts",
34
+ "./triggers/microsoft": "./src/triggers/microsoft.ts",
35
+ "./triggers/name": "./src/triggers/name.ts",
36
+ "./triggers/resend": "./src/triggers/resend.ts",
37
+ "./triggers/slack": "./src/triggers/slack.ts",
38
+ "./triggers/trello": "./src/triggers/trello.ts",
39
+ "./triggers/vercel": "./src/triggers/vercel.ts",
40
+ "./triggers/whatsapp": "./src/triggers/whatsapp.ts"
22
41
  },
23
42
  "cjs": false,
24
43
  "conditions": {
@@ -30,7 +49,6 @@
30
49
  "@types/bun": "latest",
31
50
  "@typescript/native": "npm:typescript@^7.0.2",
32
51
  "@zachsents/oxlint-config": "^0.4.1",
33
- "concurrently": "^10.0.4",
34
52
  "eslint": "^9.39.5",
35
53
  "oxlint": "^1.76.0",
36
54
  "oxlint-tsgolint": "^7.0.2001",
@@ -38,8 +56,8 @@
38
56
  },
39
57
  "scripts": {
40
58
  "typecheck": "tsc --noEmit",
41
- "lint": "concurrently --success all --kill-others-on-fail \"oxlint --type-aware\" \"bun --bun eslint .\"",
42
- "lint:fix": "concurrently --success all --kill-others-on-fail \"oxlint --type-aware --fix --fix-suggestions\" \"bun --bun eslint . --fix\"",
59
+ "lint": "oxlint --type-aware --threads=2 && bun --bun eslint . --cache --cache-strategy content",
60
+ "lint:fix": "oxlint --type-aware --threads=2 --fix --fix-suggestions && bun --bun eslint . --fix --cache --cache-strategy content",
43
61
  "check": "bun run typecheck && bun run lint",
44
62
  "test": "bun test --timeout 10000",
45
63
  "build": "zshy",
@@ -62,6 +80,101 @@
62
80
  "bun": "./src/index.ts",
63
81
  "types": "./dist/index.d.ts",
64
82
  "default": "./dist/index.js"
83
+ },
84
+ "./authoring": {
85
+ "bun": "./src/authoring.ts",
86
+ "types": "./dist/authoring.d.ts",
87
+ "default": "./dist/authoring.js"
88
+ },
89
+ "./triggers/airtable": {
90
+ "bun": "./src/triggers/airtable.ts",
91
+ "types": "./dist/triggers/airtable.d.ts",
92
+ "default": "./dist/triggers/airtable.js"
93
+ },
94
+ "./triggers/asana": {
95
+ "bun": "./src/triggers/asana.ts",
96
+ "types": "./dist/triggers/asana.d.ts",
97
+ "default": "./dist/triggers/asana.js"
98
+ },
99
+ "./triggers/brevo": {
100
+ "bun": "./src/triggers/brevo.ts",
101
+ "types": "./dist/triggers/brevo.d.ts",
102
+ "default": "./dist/triggers/brevo.js"
103
+ },
104
+ "./triggers/core-dashboard": {
105
+ "bun": "./src/triggers/core-dashboard.ts",
106
+ "types": "./dist/triggers/core-dashboard.d.ts",
107
+ "default": "./dist/triggers/core-dashboard.js"
108
+ },
109
+ "./triggers/core-http": {
110
+ "bun": "./src/triggers/core-http.ts",
111
+ "types": "./dist/triggers/core-http.d.ts",
112
+ "default": "./dist/triggers/core-http.js"
113
+ },
114
+ "./triggers/core-invocation": {
115
+ "bun": "./src/triggers/core-invocation.ts",
116
+ "types": "./dist/triggers/core-invocation.d.ts",
117
+ "default": "./dist/triggers/core-invocation.js"
118
+ },
119
+ "./triggers/core-mailhook": {
120
+ "bun": "./src/triggers/core-mailhook.ts",
121
+ "types": "./dist/triggers/core-mailhook.d.ts",
122
+ "default": "./dist/triggers/core-mailhook.js"
123
+ },
124
+ "./triggers/core-schedule": {
125
+ "bun": "./src/triggers/core-schedule.ts",
126
+ "types": "./dist/triggers/core-schedule.d.ts",
127
+ "default": "./dist/triggers/core-schedule.js"
128
+ },
129
+ "./triggers/github": {
130
+ "bun": "./src/triggers/github.ts",
131
+ "types": "./dist/triggers/github.d.ts",
132
+ "default": "./dist/triggers/github.js"
133
+ },
134
+ "./triggers/google": {
135
+ "bun": "./src/triggers/google.ts",
136
+ "types": "./dist/triggers/google.d.ts",
137
+ "default": "./dist/triggers/google.js"
138
+ },
139
+ "./triggers/linear": {
140
+ "bun": "./src/triggers/linear.ts",
141
+ "types": "./dist/triggers/linear.d.ts",
142
+ "default": "./dist/triggers/linear.js"
143
+ },
144
+ "./triggers/microsoft": {
145
+ "bun": "./src/triggers/microsoft.ts",
146
+ "types": "./dist/triggers/microsoft.d.ts",
147
+ "default": "./dist/triggers/microsoft.js"
148
+ },
149
+ "./triggers/name": {
150
+ "bun": "./src/triggers/name.ts",
151
+ "types": "./dist/triggers/name.d.ts",
152
+ "default": "./dist/triggers/name.js"
153
+ },
154
+ "./triggers/resend": {
155
+ "bun": "./src/triggers/resend.ts",
156
+ "types": "./dist/triggers/resend.d.ts",
157
+ "default": "./dist/triggers/resend.js"
158
+ },
159
+ "./triggers/slack": {
160
+ "bun": "./src/triggers/slack.ts",
161
+ "types": "./dist/triggers/slack.d.ts",
162
+ "default": "./dist/triggers/slack.js"
163
+ },
164
+ "./triggers/trello": {
165
+ "bun": "./src/triggers/trello.ts",
166
+ "types": "./dist/triggers/trello.d.ts",
167
+ "default": "./dist/triggers/trello.js"
168
+ },
169
+ "./triggers/vercel": {
170
+ "bun": "./src/triggers/vercel.ts",
171
+ "types": "./dist/triggers/vercel.d.ts",
172
+ "default": "./dist/triggers/vercel.js"
173
+ },
174
+ "./triggers/whatsapp": {
175
+ "bun": "./src/triggers/whatsapp.ts",
176
+ "types": "./dist/triggers/whatsapp.d.ts",
177
+ "default": "./dist/triggers/whatsapp.js"
65
178
  }
66
179
  },
67
180
  "dependencies": {
@@ -0,0 +1,8 @@
1
+ export {
2
+ integrationScope,
3
+ type IntegrationAccountConnectionOption,
4
+ type IntegrationAccountRequirement,
5
+ type IntegrationScopeRequirement,
6
+ type ScopeRequirementGroup,
7
+ type TriggerDefinition,
8
+ } from "./types"
@@ -1,4 +1,3 @@
1
- import { airtableService } from "../catalog"
2
1
  import type { IntegrationAccountRequirement, TriggerDefinition } from "../types"
3
2
 
4
3
  const AIRTABLE_ACCOUNT = {
@@ -12,7 +11,7 @@ const AIRTABLE_ACCOUNT = {
12
11
  ],
13
12
  },
14
13
  ],
15
- serviceId: airtableService.id,
14
+ serviceId: "airtable",
16
15
  } as const satisfies IntegrationAccountRequirement
17
16
 
18
17
  export const airtableTriggerDefinitions = {
@@ -1,4 +1,3 @@
1
- import { asanaService } from "../catalog"
2
1
  import type { IntegrationAccountRequirement, TriggerDefinition } from "../types"
3
2
 
4
3
  const ASANA_ACCOUNT = {
@@ -7,7 +6,7 @@ const ASANA_ACCOUNT = {
7
6
  requiredScopes: [],
8
7
  },
9
8
  ],
10
- serviceId: asanaService.id,
9
+ serviceId: "asana",
11
10
  } as const satisfies IntegrationAccountRequirement
12
11
 
13
12
  export const asanaTriggerDefinitions = {
@@ -1,4 +1,3 @@
1
- import { brevoService } from "../catalog"
2
1
  import type { IntegrationAccountRequirement, TriggerDefinition } from "../types"
3
2
 
4
3
  const BREVO_ACCOUNT = {
@@ -7,7 +6,7 @@ const BREVO_ACCOUNT = {
7
6
  requiredScopes: [],
8
7
  },
9
8
  ],
10
- serviceId: brevoService.id,
9
+ serviceId: "brevo",
11
10
  } as const satisfies IntegrationAccountRequirement
12
11
 
13
12
  export const brevoTriggerDefinitions = {
@@ -0,0 +1,361 @@
1
+ import type { TriggerDefinition } from "../types"
2
+ import { sentenceCase } from "./name"
3
+ import * as z from "zod/mini"
4
+
5
+ const EMAIL_SCHEMA = z.email()
6
+ const URL_SCHEMA = z.url()
7
+ const FIELD_NAME_SCHEMA = z
8
+ .string()
9
+ .check(z.trim(), z.minLength(1), z.maxLength(100))
10
+ const FIELD_LABEL_SCHEMA = z
11
+ .string()
12
+ .check(z.trim(), z.minLength(1), z.maxLength(255))
13
+ const FIELD_DESCRIPTION_SCHEMA = z.string().check(z.maxLength(2_000))
14
+ const FIELD_LENGTH_SCHEMA = z.int().check(z.nonnegative())
15
+ const DASHBOARD_RUN_FIELD_BASE_SCHEMA = {
16
+ description: z.optional(FIELD_DESCRIPTION_SCHEMA),
17
+ label: z.optional(FIELD_LABEL_SCHEMA),
18
+ name: FIELD_NAME_SCHEMA,
19
+ }
20
+ const DASHBOARD_RUN_TEXT_FIELD_SCHEMA = z.object({
21
+ ...DASHBOARD_RUN_FIELD_BASE_SCHEMA,
22
+ defaultValue: z.optional(z.string()),
23
+ maxLength: z.optional(FIELD_LENGTH_SCHEMA),
24
+ minLength: z.optional(FIELD_LENGTH_SCHEMA),
25
+ placeholder: z.optional(z.string()),
26
+ required: z.prefault(z.boolean(), true),
27
+ type: z.enum(["email", "phone", "text", "textarea", "url"]),
28
+ })
29
+ const DASHBOARD_RUN_NUMBER_FIELD_SCHEMA = z.object({
30
+ ...DASHBOARD_RUN_FIELD_BASE_SCHEMA,
31
+ defaultValue: z.optional(z.number()),
32
+ max: z.optional(z.number()),
33
+ min: z.optional(z.number()),
34
+ placeholder: z.optional(z.string()),
35
+ required: z.prefault(z.boolean(), true),
36
+ step: z.prefault(z.number().check(z.positive()), 1),
37
+ type: z.literal("number"),
38
+ })
39
+ const DASHBOARD_RUN_DATE_FIELD_SCHEMA = z.object({
40
+ ...DASHBOARD_RUN_FIELD_BASE_SCHEMA,
41
+ defaultValue: z.optional(z.iso.date()),
42
+ max: z.optional(z.iso.date()),
43
+ min: z.optional(z.iso.date()),
44
+ required: z.prefault(z.boolean(), true),
45
+ step: z.prefault(z.int().check(z.positive()), 1),
46
+ type: z.literal("date"),
47
+ })
48
+ const DASHBOARD_RUN_DATETIME_FIELD_SCHEMA = z.object({
49
+ ...DASHBOARD_RUN_FIELD_BASE_SCHEMA,
50
+ defaultValue: z.optional(z.iso.datetime({ local: true })),
51
+ max: z.optional(z.iso.datetime({ local: true })),
52
+ min: z.optional(z.iso.datetime({ local: true })),
53
+ required: z.prefault(z.boolean(), true),
54
+ step: z.prefault(z.number().check(z.positive()), 60),
55
+ type: z.literal("datetime"),
56
+ })
57
+ const DASHBOARD_RUN_CHOICE_FIELD_SCHEMA = {
58
+ ...DASHBOARD_RUN_FIELD_BASE_SCHEMA,
59
+ defaultValue: z.optional(FIELD_NAME_SCHEMA),
60
+ options: z
61
+ .array(
62
+ z.object({
63
+ label: FIELD_LABEL_SCHEMA,
64
+ value: FIELD_NAME_SCHEMA,
65
+ }),
66
+ )
67
+ .check(z.minLength(1)),
68
+ placeholder: z.optional(z.string()),
69
+ required: z.prefault(z.boolean(), true),
70
+ }
71
+ const DASHBOARD_RUN_SELECT_FIELD_SCHEMA = z.object({
72
+ ...DASHBOARD_RUN_CHOICE_FIELD_SCHEMA,
73
+ type: z.literal("select"),
74
+ })
75
+ const DASHBOARD_RUN_RADIO_FIELD_SCHEMA = z.object({
76
+ ...DASHBOARD_RUN_CHOICE_FIELD_SCHEMA,
77
+ type: z.literal("radio"),
78
+ })
79
+ const DASHBOARD_RUN_MULTI_SELECT_FIELD_SCHEMA = z.object({
80
+ ...DASHBOARD_RUN_FIELD_BASE_SCHEMA,
81
+ defaultValue: z.optional(z.array(FIELD_NAME_SCHEMA)),
82
+ options: z
83
+ .array(
84
+ z.object({
85
+ label: FIELD_LABEL_SCHEMA,
86
+ value: FIELD_NAME_SCHEMA,
87
+ }),
88
+ )
89
+ .check(z.minLength(1)),
90
+ placeholder: z.optional(z.string()),
91
+ required: z.prefault(z.boolean(), true),
92
+ type: z.literal("multi-select"),
93
+ })
94
+ const DASHBOARD_RUN_CHECKBOX_FIELD_SCHEMA = z.object({
95
+ ...DASHBOARD_RUN_FIELD_BASE_SCHEMA,
96
+ defaultValue: z.prefault(z.boolean(), false),
97
+ required: z.prefault(z.boolean(), false),
98
+ type: z.literal("checkbox"),
99
+ })
100
+ const DASHBOARD_RUN_FIELD_SCHEMA = z.pipe(
101
+ z.discriminatedUnion("type", [
102
+ DASHBOARD_RUN_TEXT_FIELD_SCHEMA,
103
+ DASHBOARD_RUN_NUMBER_FIELD_SCHEMA,
104
+ DASHBOARD_RUN_DATE_FIELD_SCHEMA,
105
+ DASHBOARD_RUN_DATETIME_FIELD_SCHEMA,
106
+ DASHBOARD_RUN_SELECT_FIELD_SCHEMA,
107
+ DASHBOARD_RUN_RADIO_FIELD_SCHEMA,
108
+ DASHBOARD_RUN_MULTI_SELECT_FIELD_SCHEMA,
109
+ DASHBOARD_RUN_CHECKBOX_FIELD_SCHEMA,
110
+ ]),
111
+ z.transform((field) => ({
112
+ ...field,
113
+ label:
114
+ field.label ??
115
+ `${sentenceCase(field.name)}${field.type === "checkbox" ? "?" : ""}`,
116
+ })),
117
+ )
118
+ const DASHBOARD_RUN_FIELDS_SCHEMA = z.array(DASHBOARD_RUN_FIELD_SCHEMA).check(
119
+ z.refine(
120
+ (fields) =>
121
+ new Set(fields.map((field) => field.name)).size === fields.length,
122
+ "Dashboard run field names must be unique.",
123
+ ),
124
+ z.refine(
125
+ (fields) => fields.every(isDashboardRunFieldDefaultValid),
126
+ "Dashboard run field defaults must satisfy their field constraints.",
127
+ ),
128
+ )
129
+
130
+ export const DASHBOARD_RUN_CONFIG_SCHEMA = z.object({
131
+ description: z.optional(FIELD_DESCRIPTION_SCHEMA),
132
+ fields: z.prefault(DASHBOARD_RUN_FIELDS_SCHEMA, []),
133
+ submitLabel: z.prefault(
134
+ z.string().check(z.trim(), z.minLength(1), z.maxLength(100)),
135
+ "Run",
136
+ ),
137
+ title: z.string().check(z.trim(), z.minLength(1), z.maxLength(255)),
138
+ })
139
+
140
+ export const dashboardRunTriggerDefinition = {
141
+ getDetails: ({ config }) => [
142
+ {
143
+ label: "Run form",
144
+ value: DASHBOARD_RUN_CONFIG_SCHEMA.parse(config).title,
145
+ },
146
+ ],
147
+ icon: "automation",
148
+ name: "Dashboard run",
149
+ type: "dashboard.run",
150
+ } as const satisfies TriggerDefinition
151
+
152
+ interface DashboardRunFieldBase {
153
+ /** Supporting text shown below the field. */
154
+ description?: string
155
+
156
+ /** Visible field label. Inferred from `name` when omitted. */
157
+ label?: string
158
+
159
+ /** Property name used in submitted trigger data. */
160
+ name: string
161
+
162
+ /** Whether the form must contain a value. Defaults to true. */
163
+ required?: boolean
164
+ }
165
+
166
+ export type DashboardRunField =
167
+ | (DashboardRunFieldBase & {
168
+ defaultValue?: string
169
+ maxLength?: number
170
+ minLength?: number
171
+ placeholder?: string
172
+ type: "email" | "phone" | "text" | "textarea" | "url"
173
+ })
174
+ | (DashboardRunFieldBase & {
175
+ defaultValue?: number
176
+ max?: number
177
+ min?: number
178
+ placeholder?: string
179
+
180
+ /** Increment used by the number input. Defaults to 1. */
181
+ step?: number
182
+ type: "number"
183
+ })
184
+ | (DashboardRunFieldBase & {
185
+ /** Initial local date in `YYYY-MM-DD` format. */
186
+ defaultValue?: string
187
+ max?: string
188
+ min?: string
189
+
190
+ /** Allowed increment in days. Defaults to 1. */
191
+ step?: number
192
+ type: "date"
193
+ })
194
+ | (DashboardRunFieldBase & {
195
+ /** Initial local date and time in `YYYY-MM-DDTHH:mm` format. */
196
+ defaultValue?: string
197
+ max?: string
198
+ min?: string
199
+
200
+ /** Allowed increment in seconds. Defaults to 60. */
201
+ step?: number
202
+ type: "datetime"
203
+ })
204
+ | (DashboardRunFieldBase & {
205
+ defaultValue?: string
206
+ options: readonly { label: string; value: string }[]
207
+ placeholder?: string
208
+ type: "select"
209
+ })
210
+ | (DashboardRunFieldBase & {
211
+ defaultValue?: string
212
+ options: readonly { label: string; value: string }[]
213
+ type: "radio"
214
+ })
215
+ | (DashboardRunFieldBase & {
216
+ defaultValue?: readonly string[]
217
+ options: readonly { label: string; value: string }[]
218
+ placeholder?: string
219
+ type: "multi-select"
220
+ })
221
+ | (DashboardRunFieldBase & {
222
+ /** Initial checked state. Defaults to false. */
223
+ defaultValue?: boolean
224
+
225
+ /** Whether the checkbox must be checked. Defaults to false. */
226
+ required?: boolean
227
+ type: "checkbox"
228
+ })
229
+
230
+ export interface DashboardRunConfig<
231
+ TFields extends readonly DashboardRunField[] = readonly DashboardRunField[],
232
+ > {
233
+ /** Supporting text shown below the form title. */
234
+ description?: string
235
+
236
+ /** Ordered fields. Omit to run immediately. */
237
+ fields?: TFields
238
+
239
+ /** Submit button text. Defaults to "Run". */
240
+ submitLabel?: string
241
+
242
+ /** Form heading. */
243
+ title: string
244
+ }
245
+
246
+ export interface DashboardRunEndpointOptions {
247
+ appOrigin: string
248
+ automationId: string
249
+ hookSlot: number
250
+ scopePath?: readonly number[]
251
+ }
252
+
253
+ /**
254
+ * Returns the organization-authenticated submission endpoint for one dashboard
255
+ * run.
256
+ *
257
+ * @param options - Public origin and trigger identity.
258
+ */
259
+ export function getDashboardRunEndpoint(options: DashboardRunEndpointOptions) {
260
+ return new URL(
261
+ `/api/dashboard-runs/${getDashboardRunEndpointKey(options)}`,
262
+ options.appOrigin,
263
+ ).toString()
264
+ }
265
+
266
+ /**
267
+ * Returns the durable endpoint identity for one dashboard run trigger.
268
+ *
269
+ * @param options - Trigger and owning automation identity.
270
+ */
271
+ export function getDashboardRunEndpointKey(
272
+ options: Omit<DashboardRunEndpointOptions, "appOrigin">,
273
+ ) {
274
+ return `${options.automationId}:${[
275
+ ...(options.scopePath ?? []),
276
+ options.hookSlot,
277
+ ].join(".")}`
278
+ }
279
+
280
+ /**
281
+ * Checks a configured default against the same constraints as submitted data.
282
+ *
283
+ * @param field - Field definition to validate.
284
+ */
285
+ function isDashboardRunFieldDefaultValid(field: DashboardRunField) {
286
+ if (field.type === "checkbox" || field.defaultValue === undefined) return true
287
+
288
+ if (field.type === "multi-select") {
289
+ if (field.required !== false && field.defaultValue.length === 0)
290
+ return false
291
+ return field.defaultValue.every((value) =>
292
+ field.options.some((option) => option.value === value),
293
+ )
294
+ }
295
+
296
+ if (field.type === "radio" || field.type === "select") {
297
+ return field.options.some((option) => option.value === field.defaultValue)
298
+ }
299
+
300
+ if (field.type === "number") {
301
+ return (
302
+ (field.min === undefined || field.defaultValue >= field.min) &&
303
+ (field.max === undefined || field.defaultValue <= field.max) &&
304
+ !isDashboardRunStepMismatch(
305
+ field.defaultValue,
306
+ field.min ?? field.defaultValue,
307
+ field.step ?? 1,
308
+ )
309
+ )
310
+ }
311
+
312
+ if (field.type === "date" || field.type === "datetime") {
313
+ const defaultValue = parseDashboardRunDateValue(
314
+ field.type,
315
+ field.defaultValue,
316
+ )
317
+ return (
318
+ (field.min === undefined ||
319
+ defaultValue >= parseDashboardRunDateValue(field.type, field.min)) &&
320
+ (field.max === undefined ||
321
+ defaultValue <= parseDashboardRunDateValue(field.type, field.max)) &&
322
+ !isDashboardRunStepMismatch(
323
+ defaultValue,
324
+ parseDashboardRunDateValue(field.type, field.min ?? field.defaultValue),
325
+ (field.step ?? (field.type === "date" ? 1 : 60)) *
326
+ (field.type === "date" ? 86_400_000 : 1_000),
327
+ )
328
+ )
329
+ }
330
+
331
+ const defaultValue = field.defaultValue.trim()
332
+ return (
333
+ (defaultValue.length > 0 || field.required === false) &&
334
+ (field.minLength === undefined || defaultValue.length >= field.minLength) &&
335
+ (field.maxLength === undefined || defaultValue.length <= field.maxLength) &&
336
+ (field.type !== "email" || EMAIL_SCHEMA.safeParse(defaultValue).success) &&
337
+ (field.type !== "url" || URL_SCHEMA.safeParse(defaultValue).success)
338
+ )
339
+ }
340
+
341
+ /**
342
+ * Checks whether a value falls outside an allowed step interval.
343
+ *
344
+ * @param value - Configured default value.
345
+ * @param base - Value from which step intervals begin.
346
+ * @param step - Allowed interval size.
347
+ */
348
+ function isDashboardRunStepMismatch(value: number, base: number, step: number) {
349
+ const intervals = (value - base) / step
350
+ return Math.abs(intervals - Math.round(intervals)) > 1e-9
351
+ }
352
+
353
+ /**
354
+ * Converts a validated local date or date-time string to a UTC number.
355
+ *
356
+ * @param type - Temporal field type.
357
+ * @param value - Local ISO value to convert.
358
+ */
359
+ function parseDashboardRunDateValue(type: "date" | "datetime", value: string) {
360
+ return Date.parse(type === "date" ? `${value}T00:00:00Z` : `${value}Z`)
361
+ }