Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import tsParser from '@typescript-eslint/parser'
import importPlugin from 'eslint-plugin-import'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import js from '@eslint/js'
Expand All @@ -20,8 +21,21 @@ export default [
ecmaVersion: 2022,
sourceType: 'module',
},
plugins: {
import: importPlugin,
},
rules: {
'@typescript-eslint/ban-ts-comment': 'off',
'import/extensions': [
'error',
'always',
{
js: 'always',
jsx: 'always',
ts: 'always',
tsx: 'always',
},
],
},
},
]
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@typescript-eslint/parser": "^8.44.0",
"eslint": "^9.35.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-import": "^2.32.0",
"eslint-plugin-prettier": "^5.5.4",
"prettier": "^3.6.2",
"rimraf": "^6.0.1",
Expand Down
11 changes: 7 additions & 4 deletions packages/fastify-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0",
"description": "Stripe sync engine. Sync your Stripe account to your Postgres database.",
"main": "src/server.ts",
"type": "module",
"scripts": {
"clean": "rimraf dist",
"dev": "tsx --watch ./src/server.ts",
Expand All @@ -21,15 +22,17 @@
"@fastify/autoload": "^6.3.1",
"@fastify/swagger": "^9.5.1",
"@fastify/swagger-ui": "^5.2.3",
"@supabase/stripe-sync-engine": "workspace:",
"dotenv": "^17.2.2",
"fastify": "^5.6.0",
"@supabase/stripe-sync-engine": "workspace:",
"stripe": "^19.0.0"
},
"devDependencies": {
"@types/pg": "^8.15.2",
"@types/node": "^24.5.0",
"tsx": "^4.20.5",
"vitest": "^3.2.4"
"@types/pg": "^8.15.2",
"tsc-alias": "^1.8.16",
"tsx": "^4.20.6",
"vite-tsconfig-paths": "^5.1.4",
"vitest": "^4.0.6"
}
}
6 changes: 3 additions & 3 deletions packages/fastify-app/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import autoload from '@fastify/autoload'
import fastifySwagger from '@fastify/swagger'
import fastifySwaggerUi from '@fastify/swagger-ui'
import { join } from 'node:path'
import { getConfig } from './utils/config'
import { getConfig } from './utils/config.js'
import { StripeSync } from '@supabase/stripe-sync-engine'
import { errorSchema } from './error'
import { logger } from './logger'
import { errorSchema } from './error.js'
import { logger } from './logger.js'
import { type PoolConfig } from 'pg'

interface buildOpts extends FastifyServerOptions {
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-app/src/routes/sync.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify'
import { verifyApiKey } from '../utils/verifyApiKey'
import { verifyApiKey } from '../utils/verifyApiKey.js'
import { SyncBackfillParams } from '@supabase/stripe-sync-engine'

export default async function routes(fastify: FastifyInstance) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-app/src/routes/sync/daily.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify'
import { verifyApiKey } from '../../utils/verifyApiKey'
import { verifyApiKey } from '../../utils/verifyApiKey.js'
import { SyncBackfillParams } from '@supabase/stripe-sync-engine'

export default async function routes(fastify: FastifyInstance) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-app/src/routes/sync/monthly.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify'
import { verifyApiKey } from '../../utils/verifyApiKey'
import { verifyApiKey } from '../../utils/verifyApiKey.js'
import { SyncBackfillParams } from '@supabase/stripe-sync-engine'

export default async function routes(fastify: FastifyInstance) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-app/src/routes/sync/weekly.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify'
import { verifyApiKey } from '../../utils/verifyApiKey'
import { verifyApiKey } from '../../utils/verifyApiKey.js'
import { SyncBackfillParams } from '@supabase/stripe-sync-engine'

export default async function routes(fastify: FastifyInstance) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-app/src/routes/webhooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyInstance } from 'fastify'
import { logger } from '../logger'
import { logger } from '../logger.js'

export default async function routes(fastify: FastifyInstance) {
fastify.post('/webhooks', {
Expand Down
6 changes: 3 additions & 3 deletions packages/fastify-app/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { FastifyInstance } from 'fastify'
import { Server, IncomingMessage, ServerResponse } from 'node:http'
import { runMigrations } from '@supabase/stripe-sync-engine'
import { createServer } from './app'
import { getConfig } from './utils/config'
import { logger } from './logger'
import { createServer } from './app.js'
import { getConfig } from './utils/config.js'
import { logger } from './logger.js'

const main = async () => {
const app: FastifyInstance<Server, IncomingMessage, ServerResponse> = await createServer({
Expand Down
6 changes: 3 additions & 3 deletions packages/fastify-app/src/test/checkoutSessions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type Stripe from 'stripe'
import { StripeSync } from '@supabase/stripe-sync-engine'
import { vitest, beforeAll, describe, test, expect } from 'vitest'
import { runMigrations } from '@supabase/stripe-sync-engine'
import { getConfig } from '../utils/config'
import { mockStripe } from './helpers/mockStripe'
import { logger } from '../logger'
import { getConfig } from '../utils/config.js'
import { mockStripe } from './helpers/mockStripe.js'
import { logger } from '../logger.js'

let stripeSync: StripeSync

Expand Down
6 changes: 3 additions & 3 deletions packages/fastify-app/src/test/entitlements.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StripeSync } from '@supabase/stripe-sync-engine'
import { vitest, beforeAll, describe, test, expect, afterAll } from 'vitest'
import { runMigrations } from '@supabase/stripe-sync-engine'
import { getConfig } from '../utils/config'
import { mockStripe } from './helpers/mockStripe'
import { logger } from '../logger'
import { getConfig } from '../utils/config.js'
import { mockStripe } from './helpers/mockStripe.js'
import { logger } from '../logger.js'
import Stripe from 'stripe'

let stripeSync: StripeSync
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-app/src/test/health.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'
import { FastifyInstance } from 'fastify'
import { beforeAll, describe, test, expect, afterAll } from 'vitest'
import { createServer } from '../app'
import { createServer } from '../app.js'

describe('/health', () => {
let server: FastifyInstance
Expand Down
6 changes: 3 additions & 3 deletions packages/fastify-app/src/test/invoices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import type Stripe from 'stripe'
import { StripeSync } from '@supabase/stripe-sync-engine'
import { vitest, beforeAll, describe, test, expect } from 'vitest'
import { runMigrations } from '@supabase/stripe-sync-engine'
import { getConfig } from '../utils/config'
import { mockStripe } from './helpers/mockStripe'
import { logger } from '../logger'
import { getConfig } from '../utils/config.js'
import { mockStripe } from './helpers/mockStripe.js'
import { logger } from '../logger.js'

let stripeSync: StripeSync

Expand Down
6 changes: 3 additions & 3 deletions packages/fastify-app/src/test/revalidate.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { StripeSync } from '@supabase/stripe-sync-engine'
import { vitest, beforeAll, describe, test, expect, afterEach } from 'vitest'
import { runMigrations } from '@supabase/stripe-sync-engine'
import { getConfig } from '../utils/config'
import { mockStripe } from './helpers/mockStripe'
import { logger } from '../logger'
import { getConfig } from '../utils/config.js'
import { mockStripe } from './helpers/mockStripe.js'
import { logger } from '../logger.js'
import type Stripe from 'stripe'

let stripeSync: StripeSync
Expand Down
8 changes: 4 additions & 4 deletions packages/fastify-app/src/test/webhooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { FastifyInstance } from 'fastify'
import { createHmac } from 'node:crypto'
import { PostgresClient, runMigrations } from '@supabase/stripe-sync-engine'
import { beforeAll, describe, test, expect, afterAll, vitest } from 'vitest'
import { getConfig } from '../utils/config'
import { createServer } from '../app'
import { logger } from '../logger'
import { mockStripe } from './helpers/mockStripe'
import { getConfig } from '../utils/config.js'
import { createServer } from '../app.js'
import { logger } from '../logger.js'
import { mockStripe } from './helpers/mockStripe.js'
import { StripeSync } from '@supabase/stripe-sync-engine'

const unixtime = Math.floor(new Date().getTime() / 1000)
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-app/src/utils/verifyApiKey.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { apiKeyMatches } from './verifyApiKey'
import { apiKeyMatches } from './verifyApiKey.js'
import { describe, test, expect } from 'vitest'

describe('verifyApiKey', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/fastify-app/src/utils/verifyApiKey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FastifyReply, FastifyRequest, HookHandlerDoneFunction } from 'fastify'
import { getConfig } from './config'
import { getConfig } from './config.js'
import { timingSafeEqual } from 'node:crypto'

const config = getConfig()
Expand Down
3 changes: 2 additions & 1 deletion packages/fastify-app/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"rootDir": ".",
"module": "commonjs",
"module": "esnext",
"moduleResolution": "node",
"outDir": "dist",
"declaration": true,
"declarationMap": true,
Expand Down
5 changes: 5 additions & 0 deletions packages/fastify-app/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
/// <reference types="vitest" />
import { defineConfig } from 'vite'
import tsconfigPaths from 'vite-tsconfig-paths'

export default defineConfig({
plugins: [tsconfigPaths()],
test: {
resolve: {
alias: [{ find: /(.*)\.js$/, replacement: '$1.ts' }],
},
environment: 'node',
deps: {
inline: [/.*/], // inline deps for Vite to transform
Expand Down
2 changes: 1 addition & 1 deletion packages/sync-engine/src/database/postgres.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pg, { PoolConfig, QueryResult } from 'pg'
import { pg as sql } from 'yesql'
import { EntitySchema } from '../schemas/types'
import { EntitySchema } from '../schemas/types.js'

type PostgresConfig = {
schema: string
Expand Down
6 changes: 3 additions & 3 deletions packages/sync-engine/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { StripeSync } from './stripeSync'
export { StripeSync } from './stripeSync.js'

export type * from './types'

export { runMigrations } from './database/migrate'
export { PostgresClient } from './database/postgres'
export { runMigrations } from './database/migrate.js'
export { PostgresClient } from './database/postgres.js'
48 changes: 24 additions & 24 deletions packages/sync-engine/src/stripeSync.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import Stripe from 'stripe'
import { pg as sql } from 'yesql'
import { PostgresClient } from './database/postgres'
import { chargeSchema } from './schemas/charge'
import { checkoutSessionSchema } from './schemas/checkout_sessions'
import { checkoutSessionLineItemSchema } from './schemas/checkout_session_line_items'
import { creditNoteSchema } from './schemas/credit_note'
import { customerDeletedSchema, customerSchema } from './schemas/customer'
import { disputeSchema } from './schemas/dispute'
import { invoiceSchema } from './schemas/invoice'
import { planSchema } from './schemas/plan'
import { priceSchema } from './schemas/price'
import { productSchema } from './schemas/product'
import { paymentIntentSchema } from './schemas/payment_intent'
import { paymentMethodsSchema } from './schemas/payment_methods'
import { setupIntentsSchema } from './schemas/setup_intents'
import { taxIdSchema } from './schemas/tax_id'
import { subscriptionItemSchema } from './schemas/subscription_item'
import { subscriptionScheduleSchema } from './schemas/subscription_schedules'
import { subscriptionSchema } from './schemas/subscription'
import { PostgresClient } from './database/postgres.js'
import { chargeSchema } from './schemas/charge.js'
import { checkoutSessionSchema } from './schemas/checkout_sessions.js'
import { checkoutSessionLineItemSchema } from './schemas/checkout_session_line_items.js'
import { creditNoteSchema } from './schemas/credit_note.js'
import { customerDeletedSchema, customerSchema } from './schemas/customer.js'
import { disputeSchema } from './schemas/dispute.js'
import { invoiceSchema } from './schemas/invoice.js'
import { planSchema } from './schemas/plan.js'
import { priceSchema } from './schemas/price.js'
import { productSchema } from './schemas/product.js'
import { paymentIntentSchema } from './schemas/payment_intent.js'
import { paymentMethodsSchema } from './schemas/payment_methods.js'
import { setupIntentsSchema } from './schemas/setup_intents.js'
import { taxIdSchema } from './schemas/tax_id.js'
import { subscriptionItemSchema } from './schemas/subscription_item.js'
import { subscriptionScheduleSchema } from './schemas/subscription_schedules.js'
import { subscriptionSchema } from './schemas/subscription.js'
import {
StripeSyncConfig,
Sync,
Expand All @@ -26,12 +26,12 @@ import {
SyncEntitlementsParams,
SyncFeaturesParams,
type RevalidateEntity,
} from './types'
import { earlyFraudWarningSchema } from './schemas/early_fraud_warning'
import { reviewSchema } from './schemas/review'
import { refundSchema } from './schemas/refund'
import { activeEntitlementSchema } from './schemas/active_entitlement'
import { featureSchema } from './schemas/feature'
} from './types.js'
import { earlyFraudWarningSchema } from './schemas/early_fraud_warning.js'
import { reviewSchema } from './schemas/review.js'
import { refundSchema } from './schemas/refund.js'
import { activeEntitlementSchema } from './schemas/active_entitlement.js'
import { featureSchema } from './schemas/feature.js'
import type { PoolConfig } from 'pg'

function getUniqueIds<T>(entries: T[], key: string): string[] {
Expand Down
Loading
Loading