Skip to content

OpenPanel is an open-source web and product analytics platform, an open-source alternative to Mixpanel with optional self-hosting.

fix: polar api issues 🤬

Carl-Gerhard Lindesvärd61a9245309c1
diff --git a/patches/@polar-sh__sdk.patch b/patches/@polar-sh__sdk.patch
new file mode 100644
index 000000000..05275a993
--- /dev/null
+++ b/patches/@polar-sh__sdk.patch
@@ -0,0 +1,128 @@
+diff --git a/dist/commonjs/models/components/benefitdiscordproperties.d.ts b/dist/commonjs/models/components/benefitdiscordproperties.d.ts
+index 5eed446..a233f87 100644
+--- a/dist/commonjs/models/components/benefitdiscordproperties.d.ts
++++ b/dist/commonjs/models/components/benefitdiscordproperties.d.ts
+@@ -17,7 +17,7 @@ export type BenefitDiscordProperties = {
+ * Whether to kick the member from the Discord server on revocation.
+ */
+ kickMember: boolean;
+- guildToken: string;
++ guildToken?: string;
+ };
+ /** @internal */
+ export declare const BenefitDiscordProperties$inboundSchema: z.ZodMiniType<BenefitDiscordProperties, unknown>;
+@@ -26,7 +26,7 @@ export type BenefitDiscordProperties$Outbound = {
+ guild_id: string;
+ role_id: string;
+ kick_member: boolean;
+- guild_token: string;
++ guild_token?: string;
+ };
+ /** @internal */
+ export declare const BenefitDiscordProperties$outboundSchema: z.ZodMiniType<BenefitDiscordProperties$Outbound, BenefitDiscordProperties>;
+diff --git a/dist/commonjs/models/components/benefitdiscordproperties.js b/dist/commonjs/models/components/benefitdiscordproperties.js
+index 9e7f4a6..df20afb 100644
+--- a/dist/commonjs/models/components/benefitdiscordproperties.js
++++ b/dist/commonjs/models/components/benefitdiscordproperties.js
+@@ -47,7 +47,7 @@ exports.BenefitDiscordProperties$inboundSchema = z.pipe(z.object({
+ guild_id: z.string(),
+ role_id: z.string(),
+ kick_member: z.boolean(),
+- guild_token: z.string(),
++ guild_token: z.optional(z.string()),
+ }), z.transform((v) => {
+ return (0, primitives_js_1.remap)(v, {
+ "guild_id": "guildId",
+@@ -61,7 +61,7 @@ exports.BenefitDiscordProperties$outboundSchema = z.pipe(z.object({
+ guildId: z.string(),
+ roleId: z.string(),
+ kickMember: z.boolean(),
+- guildToken: z.string(),
++ guildToken: z.optional(z.string()),
+ }), z.transform((v) => {
+ return (0, primitives_js_1.remap)(v, {
+ guildId: "guild_id",
+diff --git a/dist/esm/models/components/benefitdiscordproperties.d.ts b/dist/esm/models/components/benefitdiscordproperties.d.ts
+index 5eed446..a233f87 100644
+--- a/dist/esm/models/components/benefitdiscordproperties.d.ts
++++ b/dist/esm/models/components/benefitdiscordproperties.d.ts
+@@ -17,7 +17,7 @@ export type BenefitDiscordProperties = {
+ * Whether to kick the member from the Discord server on revocation.
+ */
+ kickMember: boolean;
+- guildToken: string;
++ guildToken?: string;
+ };
+ /** @internal */
+ export declare const BenefitDiscordProperties$inboundSchema: z.ZodMiniType<BenefitDiscordProperties, unknown>;
+@@ -26,7 +26,7 @@ export type BenefitDiscordProperties$Outbound = {
+ guild_id: string;
+ role_id: string;
+ kick_member: boolean;
+- guild_token: string;
++ guild_token?: string;
+ };
+ /** @internal */
+ export declare const BenefitDiscordProperties$outboundSchema: z.ZodMiniType<BenefitDiscordProperties$Outbound, BenefitDiscordProperties>;
+diff --git a/dist/esm/models/components/benefitdiscordproperties.js b/dist/esm/models/components/benefitdiscordproperties.js
+index 770d69d..fded0a1 100644
+--- a/dist/esm/models/components/benefitdiscordproperties.js
++++ b/dist/esm/models/components/benefitdiscordproperties.js
+@@ -9,7 +9,7 @@ export const BenefitDiscordProperties$inboundSchema = z.pipe(z.object({
+ guild_id: z.string(),
+ role_id: z.string(),
+ kick_member: z.boolean(),
+- guild_token: z.string(),
++ guild_token: z.optional(z.string()),
+ }), z.transform((v) => {
+ return remap$(v, {
+ "guild_id": "guildId",
+@@ -23,7 +23,7 @@ export const BenefitDiscordProperties$outboundSchema = z.pipe(z.object({
+ guildId: z.string(),
+ roleId: z.string(),
+ kickMember: z.boolean(),
+- guildToken: z.string(),
++ guildToken: z.optional(z.string()),
+ }), z.transform((v) => {
+ return remap$(v, {
+ guildId: "guild_id",
+diff --git a/src/models/components/benefitdiscordproperties.ts b/src/models/components/benefitdiscordproperties.ts
+index 77e670c..1d93f8a 100644
+--- a/src/models/components/benefitdiscordproperties.ts
++++ b/src/models/components/benefitdiscordproperties.ts
+@@ -24,7 +24,7 @@ export type BenefitDiscordProperties = {
+ * Whether to kick the member from the Discord server on revocation.
+ */
+ kickMember: boolean;
+- guildToken: string;
++ guildToken?: string;
+ };
+
+ /** @internal */
+@@ -36,7 +36,7 @@ export const BenefitDiscordProperties$inboundSchema: z.ZodMiniType<
+ guild_id: z.string(),
+ role_id: z.string(),
+ kick_member: z.boolean(),
+- guild_token: z.string(),
++ guild_token: z.optional(z.string()),
+ }),
+ z.transform((v) => {
+ return remap$(v, {
+@@ -52,7 +52,7 @@ export type BenefitDiscordProperties$Outbound = {
+ guild_id: string;
+ role_id: string;
+ kick_member: boolean;
+- guild_token: string;
++ guild_token?: string;
+ };
+
+ /** @internal */
+@@ -64,7 +64,7 @@ export const BenefitDiscordProperties$outboundSchema: z.ZodMiniType<
+ guildId: z.string(),
+ roleId: z.string(),
+ kickMember: z.boolean(),
+- guildToken: z.string(),
++ guildToken: z.optional(z.string()),
+ }),
+ z.transform((v) => {
+ return remap$(v, {
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index a88b23d96..be8b3b43a 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -49,6 +49,7 @@ overrides:
embla-carousel: 8.0.0-rc22
patchedDependencies:
+ '@polar-sh/sdk': b5b5752d3b9103ff6fd4e3b3f2c9a6b91befd898fc40ada35cfe9bb546fa7af0
nuqs: 4f93812bf7a04685f9477b2935e3acbf2aa24dfbb1b00b9ae0ed8f7a2877a98e
importers:
@@ -1624,7 +1625,7 @@ importers:
dependencies:
'@polar-sh/sdk':
specifier: ^0.49.0
- version: 0.49.0
+ version: 0.49.0(patch_hash=b5b5752d3b9103ff6fd4e3b3f2c9a6b91befd898fc40ada35cfe9bb546fa7af0)
date-fns:
specifier: ^3.3.1
version: 3.3.1
@@ -26655,7 +26656,7 @@ snapshots:
optional: true
- '@polar-sh/[email protected]':
+ '@polar-sh/[email protected](patch_hash=b5b5752d3b9103ff6fd4e3b3f2c9a6b91befd898fc40ada35cfe9bb546fa7af0)':
dependencies:
standardwebhooks: 1.0.0
zod: 4.3.6
diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml
index f34c8ded8..6d278b331 100644
--- a/pnpm-workspace.yaml
+++ b/pnpm-workspace.yaml
@@ -7,6 +7,18 @@ packages:
# pnpm 11 no longer reads the "pnpm" field in package.json — these moved here.
patchedDependencies:
nuqs: patches/nuqs.patch
+ # @polar-sh/sdk 0.49 validates every response against generated zod schemas,
+ # and its `discord` benefit schema still requires `properties.guild_token` —
+ # a field the Polar API no longer returns (it is the Discord bot token).
+ # One strict schema for a field we never read took down everything that
+ # embeds a product: `products.list` 500'd `subscription.products` (the whole
+ # billing page) as soon as the Supporter products carried the Discord
+ # benefit, and `validateEvent` throws on any Supporter webhook before
+ # webhook.controller gets to ignore it, so Polar retries it forever.
+ # The patch makes `guild_token` optional. Deliberately unpinned: a version
+ # bump should re-apply it and fail loudly if upstream reworked that file,
+ # rather than silently drop it under allowUnusedPatches below.
+ "@polar-sh/sdk": patches/@polar-sh__sdk.patch
# nuqs is an apps/start dependency, but the api and worker images install a
# subset of the workspace (their Dockerfiles copy only their own and their