-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create svix consumer app and event types on create product
- Loading branch information
Showing
7 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from "./src"; | ||
export * from "./src/publish"; | ||
export * from "./src/utils"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { svix } from "./index"; | ||
import { eventSchemas, EventTypes } from "@dotinc/bouncer-core"; | ||
import { zodToJsonSchema } from "zod-to-json-schema"; | ||
|
||
const missingTypes = <T>(arr1: T[], arr2: T[]) => | ||
arr1.filter((e) => !arr2.includes(e)); | ||
|
||
export const deployEventTypes = async () => { | ||
const eventTypes = await svix.eventType.list({}); | ||
const names = eventTypes.data.map((e) => e.name); | ||
const missing = missingTypes<keyof EventTypes>( | ||
Object.keys(eventSchemas) as (keyof EventTypes)[], | ||
names as (keyof EventTypes)[] | ||
); | ||
if (missing.length === 0) { | ||
return; // all types are present | ||
} | ||
|
||
const creates = []; | ||
for (let i = 0; i < missing.length; i++) { | ||
const eventType = missing[i]; | ||
if (!eventType) continue; | ||
|
||
const eventSchema = zodToJsonSchema(eventSchemas[eventType], eventType); | ||
|
||
const jsonString = JSON.stringify(eventSchema); | ||
|
||
creates.push( | ||
svix.eventType.create({ | ||
name: eventType, | ||
description: "", | ||
schemas: { | ||
default: jsonString, | ||
}, | ||
}) | ||
); | ||
} | ||
|
||
await Promise.all(creates); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters