@automate.ax/integration-contracts 0.146.1 → 0.147.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.
@@ -0,0 +1,58 @@
1
+ /* oxlint-disable typescript/no-unsafe-type-assertion -- Generated schema names index a frozen external contract. */
2
+ import type { Encodable } from "@automate.ax/codec"
3
+ import { Validator } from "@cfworker/json-schema"
4
+ import * as z from "zod"
5
+ import schemaData from "./openapi-schemas.generated.json" with { type: "json" }
6
+ import type { components } from "./openapi-types.generated"
7
+
8
+ type OpenApiSchemas = components["schemas"]
9
+
10
+ export type TallySchemaName = keyof OpenApiSchemas
11
+
12
+ type TallyEncodable<TValue> = unknown extends TValue
13
+ ? Encodable
14
+ : TValue extends null | undefined | boolean | number | string
15
+ ? TValue
16
+ : TValue extends readonly (infer TItem)[]
17
+ ? TallyEncodable<TItem>[]
18
+ : TValue extends object
19
+ ? keyof TValue extends never
20
+ ? Record<string, Encodable>
21
+ : { [TKey in keyof TValue]: TallyEncodable<TValue[TKey]> }
22
+ : never
23
+
24
+ /** Public JSON-safe value for one generated Tally OpenAPI schema. */
25
+ export type TallySchemaValue<TName extends TallySchemaName> = TallyEncodable<
26
+ OpenApiSchemas[TName]
27
+ >
28
+
29
+ const VALIDATOR = new Validator(
30
+ {
31
+ $defs: schemaData.definitions,
32
+ $schema: "https://json-schema.org/draft/2020-12/schema",
33
+ additionalProperties: false,
34
+ maxProperties: 1,
35
+ minProperties: 1,
36
+ properties: Object.fromEntries(
37
+ Object.keys(schemaData.definitions).map((name) => [
38
+ name,
39
+ { $ref: `#/$defs/${name}` },
40
+ ]),
41
+ ),
42
+ type: "object",
43
+ },
44
+ "2020-12",
45
+ )
46
+
47
+ /**
48
+ * Validates one value against the frozen Tally OpenAPI schema.
49
+ *
50
+ * @param name OpenAPI schema name.
51
+ */
52
+ export function tallySchema<TName extends TallySchemaName>(
53
+ name: TName,
54
+ ): z.ZodType<TallySchemaValue<TName>, TallySchemaValue<TName>> {
55
+ return z.custom<TallySchemaValue<TName>>(
56
+ (value) => VALIDATOR.validate({ [name]: value }).valid,
57
+ )
58
+ }
package/src/triggers.ts CHANGED
@@ -32,6 +32,7 @@ import type { resendTriggerContracts } from "./resend"
32
32
  import type { slackTriggerContracts } from "./slack"
33
33
  import type { stripeTriggerContracts } from "./stripe"
34
34
  import type { teamsTriggerContracts } from "./teams"
35
+ import type { tallyTriggerContracts } from "./tally"
35
36
  import type { trelloTriggerContracts } from "./trello"
36
37
  import type { vercelTriggerContracts } from "./vercel"
37
38
  import type { webflowTriggerContracts } from "./webflow"
@@ -72,6 +73,7 @@ export type TriggerContractMap = typeof airtableTriggerContracts &
72
73
  typeof slackTriggerContracts &
73
74
  typeof stripeTriggerContracts &
74
75
  typeof teamsTriggerContracts &
76
+ typeof tallyTriggerContracts &
75
77
  typeof trelloTriggerContracts &
76
78
  typeof vercelTriggerContracts &
77
79
  typeof webflowTriggerContracts &