55 | {siteConfig.customFields.installCommand}
56 |
57 |
55 | {siteConfig.customFields.installCommand}
56 |
57 | event.type and event.data.object fields for better developer experience and implementation.",
37 | },
38 |
39 | presets: [
40 | [
41 | "classic",
42 | /** @type {import('@docusaurus/preset-classic').Options} */
43 | ({
44 | docs: {
45 | sidebarPath: false,
46 | },
47 | blog: false,
48 | theme: {
49 | customCss: require.resolve("./src/css/custom.css"),
50 | },
51 | }),
52 | ],
53 | ],
54 |
55 | themeConfig:
56 | /** @type {import('@docusaurus/preset-classic').ThemeConfig} */
57 | ({
58 | navbar: {
59 | title: "stripe-event-types",
60 | logo: {
61 | alt: "stripe-event-types Logo",
62 | src: "img/logo.svg",
63 | },
64 | items: [
65 | {
66 | type: "doc",
67 | docId: "index",
68 | position: "right",
69 | label: "Docs",
70 | },
71 | {
72 | href: "https://github.com/kgajera/stripe-event-types",
73 | label: "GitHub",
74 | position: "right",
75 | },
76 | ],
77 | },
78 | footer: {
79 | links: [
80 | {
81 | label: "GitHub",
82 | href: "https://github.com/kgajera/stripe-event-types",
83 | },
84 | ],
85 | copyright: "Built with Docusaurus.",
86 | },
87 | prism: {
88 | theme: lightCodeTheme,
89 | darkTheme: darkCodeTheme,
90 | },
91 | }),
92 | };
93 |
94 | module.exports = config;
95 |
--------------------------------------------------------------------------------
/scripts/generate.mts:
--------------------------------------------------------------------------------
1 | import fs from "fs";
2 | import _ from "lodash";
3 | import path from "path";
4 | import prettier from "prettier";
5 | import { launch } from "puppeteer";
6 |
7 | interface StripeDocsEventScrape {
8 | // Name of event, for example "charge.succeeded"
9 | type: string;
10 | // Description scraped from docs about the type of the `data.object` value, for example "card"
11 | objectTypes: string[];
12 | }
13 |
14 | interface EventTree {
15 | [key: string]: EventTree | boolean | string[] | undefined;
16 | _isLeaf?: boolean;
17 | _objectTypes?: string[];
18 | }
19 |
20 | type FlatTree = Record<
21 | string,
22 | {
23 | eventType: string;
24 | interfaceName: string;
25 | objectType: string;
26 | }
27 | >;
28 |
29 | interface TypingTree {
30 | [key: string]: null | TypingTree;
31 | }
32 |
33 | const TYPES_DIR = `node_modules/stripe/types`;
34 |
35 | const typingsTree = await buildTypingFilesTree();
36 | const scrapedEvents = await scrapeEvents();
37 | const fullEventTypeList = await getOpenApiEventTypeList();
38 | const unscrapedEvents = _.pullAllWith(
39 | fullEventTypeList,
40 | scrapedEvents,
41 | (a, b) => a == b.type,
42 | );
43 | scrapedEvents.push(
44 | ...unscrapedEvents.map((type) => ({
45 | type,
46 | objectTypes: [],
47 | })),
48 | );
49 |
50 | const eventTree = buildEventTree(scrapedEvents);
51 | const flatTree = buildFlatEventTree(eventTree);
52 |
53 | await fs.promises.writeFile(
54 | path.join("index.d.ts"),
55 | await format(`
56 | declare module "stripe" {
57 | namespace Stripe {
58 | type DiscriminatedEvent = ${Object.keys(flatTree)
59 | .map((g) => `DiscriminatedEvent.${flatTree[g].interfaceName}`)
60 | .join(" | ")}
61 |
62 | namespace DiscriminatedEvent {
63 | /**
64 | * All possible event types: https://stripe.com/docs/api/events/types
65 | */
66 | type Type = ${scrapedEvents.map((e) => `'${e.type}'`).join(" | ")};
67 |
68 | interface Data