77 * to detect if all streams have completed.
88 */
99
10- import Stripe from 'npm:stripe'
1110import pg from 'npm:pg@8'
1211import { buildResourceRegistry } from '@stripe/source-stripe'
12+ import { resolveOpenApiSpec } from '@stripe/openapi'
1313import { upsertMany } from '@stripe/destination-postgres'
1414
1515// Module-level singletons (reused across requests in Deno edge functions)
@@ -22,9 +22,10 @@ const PAGES_PER_INVOCATION = Number(Deno.env.get('PAGES_PER_INVOCATION')) || 10
2222const schemaName = Deno . env . get ( 'SYNC_SCHEMA_NAME' ) ?? 'stripe'
2323const safeSchema = schemaName . replace ( / " / g, '""' )
2424
25- const stripe = new Stripe ( Deno . env . get ( 'STRIPE_SECRET_KEY' ) ! )
25+ const stripeKey = Deno . env . get ( 'STRIPE_SECRET_KEY' ) !
2626const pool = new pg . Pool ( { connectionString : dbUrl , max : 2 } )
27- const registry = buildResourceRegistry ( stripe )
27+ const resolved = await resolveOpenApiSpec ( { apiVersion : '2020-08-27' } )
28+ const registry = buildResourceRegistry ( resolved . spec , stripeKey )
2829
2930/** Find the resource config whose tableName matches the given stream name. */
3031function findConfigByTableName ( stream : string ) {
@@ -117,7 +118,7 @@ Deno.serve(async (req) => {
117118 let newRecords = 0
118119
119120 for ( let page = 0 ; page < PAGES_PER_INVOCATION && hasMore ; page ++ ) {
120- const params : Stripe . PaginationParams = { limit : 100 }
121+ const params : { limit : number ; starting_after ?: string } = { limit : 100 }
121122 if ( cursor ) params . starting_after = cursor
122123
123124 const response = await listFn ( params )
0 commit comments