polar icon indicating copy to clipboard operation
polar copied to clipboard

SDKValidationError: Supabase Deno WebHook error

Open murnifine opened this issue 3 months ago • 0 comments
trafficstars

Description

I'm using WebHook with a supabase function with Deno, but the results always give an error as follows:

"SDKValidationError: Failed to parse event: TypeError: Cannot read properties of undefined (reading '_zod')\n    at parseEvent (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/@polar-sh/sdk/0.34.3/dist/esm/webhooks.js:98:15)\n    at validateEvent (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/@polar-sh/sdk/0.34.3/dist/esm/webhooks.js:106:16)\n    at Object.handler (https://jsr.io/@polar-sh/deno/0.1.2/main.ts:106:24)\n    at eventLoopTick (ext:core/01_core.js:168:7)\n    at async respond (ext:sb_core_main_js/js/http.js:197:14)\nCaused by TypeError: Cannot read properties of undefined (reading '_zod')\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:1222:46)\n    at eval (eval at compile (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/doc.js:33:16), <anonymous>:59:40)\n    at file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:777:34\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:803:23)\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:1591:34)\n    at eval (eval at compile (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/doc.js:33:16), <anonymous>:157:40)\n    at file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:777:34\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:803:23)\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:1591:34)\n    at eval (eval at compile (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/doc.js:33:16), <anonymous>:11:36) {\n  name: \"SDKValidationError\",\n  cause: TypeError: Cannot read properties of undefined (reading '_zod')\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:1222:46)\n    at eval (eval at compile (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/doc.js:33:16), <anonymous>:59:40)\n    at file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:777:34\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:803:23)\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:1591:34)\n    at eval (eval at compile (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/doc.js:33:16), <anonymous>:157:40)\n    at file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:777:34\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:803:23)\n    at inst._zod.parse (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/schemas.js:1591:34)\n    at eval (eval at compile (file:///var/tmp/sb-compile-edge-runtime/node_modules/localhost/zod/4.0.5/v4/core/doc.js:33:16), <anonymous>:11:36),\n  rawValue: {\n    type: \"subscription.updated\",\n    data: {\n      created_at: \"2025-07-17T18:03:29.149355Z\",\n      modified_at: \"2025-07-21T17:23:31.880346Z\",\n      id: \"0d3b101f-1ebb-4b3f-8d9e-37b447ce70c6\",\n      amount: 1900,\n      currency: \"usd\",\n      recurring_interval: \"month\",\n      status: \"canceled\",\n      current_period_start: \"2025-07-17T18:03:24Z\",\n      current_period_end: \"2025-08-17T18:03:24Z\",\n      cancel_at_period_end: false,\n      canceled_at: \"2025-07-21T17:15:54.640680Z\",\n      started_at: \"2025-07-17T18:03:29.144023Z\",\n      ends_at: \"2025-07-21T17:23:30Z\",\n      ended_at: \"2025-07-21T17:23:30Z\",\n      customer_id: \"708b7e49-e2a0-4131-9486-33b90c125f2c\",\n      product_id: \"9117f48e-2264-464b-8638-c5a803793242\",\n      discount_id: null,\n      checkout_id: \"657de801-1ead-40b2-9f66-cba159929296\",\n      customer_cancellation_reason: null,\n      customer_cancellation_comment: null,\n      price_id: \"d87b5fd0-4d8a-4c5c-bf3d-15dd2e84ec5b\",\n      metadata: {},\n      custom_field_data: {},\n      customer: {\n        id: \"708b7e49-e2a0-4131-9486-33b90c125f2c\",\n        created_at: \"2025-07-17T18:03:22.921819Z\",\n        modified_at: null,\n        metadata: {},\n        external_id: null,\n        email: \"[email protected]\",\n        email_verified: false,\n        name: \"budi\",\n        billing_address: {\n          line1: null,\n          line2: null,\n          postal_code: null,\n          city: null,\n          state: null,\n          country: \"ID\"\n        },\n        tax_id: null,\n        organization_id: \"cc74c15d-9a9c-4cca-ac8f-5d972b592068\",\n        deleted_at: null,\n        avatar_url: \"https://www.gravatar.com/avatar/2bce01477c87752cec4089979381537d501fdec1b1153f26e39e137024790ad7?d=404\"\n      },\n      user_id: \"708b7e49-e2a0-4131-9486-33b90c125f2c\",\n      user: {\n        id: \"708b7e49-e2a0-4131-9486-33b90c125f2c\",\n        email: \"[email protected]\",\n        public_name: \"b\",\n        avatar_url: null,\n        github_username: null\n      },\n      product: {\n        created_at: \"2025-07-17T16:36:48.509139Z\",\n        modified_at: \"2025-07-18T17:46:40.048991Z\",\n        id: \"9117f48e-2264-464b-8638-c5a803793242\",\n        name: \"Pro+\",\n        description: \"Priority access\",\n        recurring_interval: \"month\",\n        is_recurring: true,\n        is_archived: false,\n        organization_id: \"cc74c15d-9a9c-4cca-ac8f-5d972b592068\",\n        metadata: { index: \"2\" },\n        prices: [ [Object] ],\n        benefits: [],\n        medias: [],\n        attached_custom_fields: []\n      },\n      discount: null,\n      price: {\n        created_at: \"2025-07-17T16:36:48.513320Z\",\n        modified_at: \"2025-07-20T06:00:33.859518Z\",\n        id: \"d87b5fd0-4d8a-4c5c-bf3d-15dd2e84ec5b\",\n        amount_type: \"fixed\",\n        is_archived: true,\n        product_id: \"9117f48e-2264-464b-8638-c5a803793242\",\n        type: \"recurring\",\n        recurring_interval: \"month\",\n        price_currency: \"usd\",\n        price_amount: 1900\n      },\n      prices: [\n        {\n          created_at: \"2025-07-17T16:36:48.513320Z\",\n          modified_at: \"2025-07-20T06:00:33.859518Z\",\n          id: \"d87b5fd0-4d8a-4c5c-bf3d-15dd2e84ec5b\",\n          amount_type: \"fixed\",\n          is_archived: true,\n          product_id: \"9117f48e-2264-464b-8638-c5a803793242\",\n          type: \"recurring\",\n          recurring_interval: \"month\",\n          price_currency: \"usd\",\n          price_amount: 1900\n        }\n      ],\n      meters: []\n    }\n  },\n  rawMessage: \"Failed to parse event\"\n}\n"

code:

import "jsr:@supabase/functions-js/edge-runtime.d.ts";
import { Webhooks } from "jsr:@polar-sh/deno";

Deno.serve(
  Webhooks({
    webhookSecret: Deno.env.get('POLAR_WEBHOOK_SECRET'),
    onSubscriptionUpdated: async (payload) => {
      console.log({ payload });
    },
  })
);

Environment:

  • Operating System: Windows
  • Browser: Chrome

murnifine avatar Jul 21 '25 17:07 murnifine