Skip to content

Commit

Permalink
Create new repo workspaces for billing and postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
habdelra committed Nov 8, 2024
1 parent f70ca43 commit ac8cbd9
Show file tree
Hide file tree
Showing 50 changed files with 287 additions and 71 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ jobs:
if: always()
run: pnpm run lint
working-directory: packages/runtime-common
- name: Lint Billing
if: always()
run: pnpm run lint
working-directory: packages/billing
- name: Lint Postgres
if: always()
run: pnpm run lint
working-directory: packages/postgres
- name: Lint Base Realm
if: always()
run: pnpm run lint
Expand Down
28 changes: 28 additions & 0 deletions packages/billing/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

module.exports = {
overrides: [
{
files: ['./.eslintrc.js'],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
extends: ['plugin:n/recommended'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
rules: {
'qunit/require-expect': 'off',
'qunit/no-conditional-assertions': 'off',
},
},
],
};
File renamed without changes.
23 changes: 23 additions & 0 deletions packages/billing/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@cardstack/billing",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"@cardstack/postgres": "workspace:*",
"@cardstack/runtime-common": "workspace:*",
"stripe": "^17.2.1"
},
"devDependencies": {
"concurrently": "^8.0.1"
},
"scripts": {
"lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\"",
"lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\"",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:glint": "glint"
},
"volta": {
"extends": "../../package.json"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { DBAdapter } from '@cardstack/runtime-common';
import { type DBAdapter } from '@cardstack/runtime-common';
import {
insertStripeEvent,
markStripeEventAsProcessed,
updateUserStripeCustomerId,
} from '../billing-queries';
import { StripeCheckoutSessionCompletedWebhookEvent } from '.';

import PgAdapter from '../../pg-adapter';
import { TransactionManager } from '../../pg-transaction-manager';
import { PgAdapter, TransactionManager } from '@cardstack/postgres';

export async function handleCheckoutSessionCompleted(
dbAdapter: DBAdapter,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DBAdapter } from '@cardstack/runtime-common';
import { type DBAdapter, retry } from '@cardstack/runtime-common';
import {
addToCreditsLedger,
getCurrentActiveSubscription,
Expand All @@ -13,9 +13,7 @@ import {
} from '../billing-queries';
import { StripeInvoicePaymentSucceededWebhookEvent } from '.';

import PgAdapter from '../../pg-adapter';
import { retry } from '../../lib/utils';
import { TransactionManager } from '../../pg-transaction-manager';
import { PgAdapter, TransactionManager } from '@cardstack/postgres';

// TODOs that will be handled in a separated PRs:
// - handle plan changes (going from smaller plan to bigger plan, or vice versa) - this will be handled in a separate ticket CS-7444
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
getSubscriptionByStripeSubscriptionId,
} from '../billing-queries';

import { TransactionManager } from '../../pg-transaction-manager';
import PgAdapter from '../../pg-adapter';
import { PgAdapter, TransactionManager } from '@cardstack/postgres';

export async function handleSubscriptionDeleted(
dbAdapter: DBAdapter,
Expand Down
41 changes: 41 additions & 0 deletions packages/billing/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"compilerOptions": {
"target": "es2020",
"allowJs": true,
"module": "CommonJS",
"moduleResolution": "nodenext",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"noImplicitThis": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noEmitOnError": false,
"noEmit": true,
"inlineSourceMap": true,
"inlineSources": true,
"baseUrl": ".",
"esModuleInterop": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"strict": true,
"paths": {
"https://cardstack.com/base/*": ["../base/*"],
"@cardstack/boxel-ui": ["../boxel-ui/addon"],
"@cardstack/boxel-ui/*": ["../boxel-ui/addon/*"],
"*": ["types/*"]
}
},
"glint": {
"environment": ["ember-loose", "ember-template-imports"],
"transform": {
"include": ["../base/**", "./**", "../boxel-ui/addon/**"]
}
},
"include": ["../base/**/*", "./**/*"],
"exclude": ["../base/**/__boxel/**"]
}
28 changes: 28 additions & 0 deletions packages/postgres/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

module.exports = {
overrides: [
{
files: ['./.eslintrc.js'],
parserOptions: {
sourceType: 'script',
},
env: {
browser: false,
node: true,
},
extends: ['plugin:n/recommended'],
rules: {
'@typescript-eslint/no-var-requires': 'off',
},
},
{
files: ['tests/**/*-test.{js,ts}'],
extends: ['plugin:qunit/recommended'],
rules: {
'qunit/require-expect': 'off',
'qunit/no-conditional-assertions': 'off',
},
},
],
};
4 changes: 4 additions & 0 deletions packages/postgres/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './pg-adapter';
export * from './pg-config';
export * from './pg-queue';
export * from './pg-transaction-manager';
File renamed without changes.
25 changes: 25 additions & 0 deletions packages/postgres/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "@cardstack/postgres",
"version": "0.0.0",
"license": "MIT",
"dependencies": {
"@cardstack/runtime-common": "workspace:*",
"@sentry/node": "^8.31.0",
"@types/pg": "^8.11.5",
"node-pg-migrate": "^6.2.2",
"pg": "^8.11.5"
},
"devDependencies": {
"concurrently": "^8.0.1"
},
"scripts": {
"lint": "concurrently \"pnpm:lint:*(!fix)\" --names \"lint:\"",
"lint:fix": "concurrently \"pnpm:lint:*:fix\" --names \"fix:\"",
"lint:js": "eslint . --cache",
"lint:js:fix": "eslint . --fix",
"lint:glint": "glint"
},
"volta": {
"extends": "../../package.json"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import migrate from 'node-pg-migrate';
import { join } from 'path';
import { Pool, Client, type Notification } from 'pg';

import postgresConfig from './pg-config';
import { postgresConfig } from './pg-config';

const log = logger('pg-adapter');

Expand All @@ -22,7 +22,7 @@ function config() {

type Config = ReturnType<typeof config>;

export default class PgAdapter implements DBAdapter {
export class PgAdapter implements DBAdapter {
#isClosed = false;
private pool: Pool;
private started = this.#startClient();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { type ClientConfig } from 'pg';

export default function postgresConfig(defaultConfig: ClientConfig = {}) {
export function postgresConfig(defaultConfig: ClientConfig = {}) {
return Object.assign({}, defaultConfig, {
host: process.env.PGHOST || 'localhost',
port: process.env.PGPORT || '5432',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
Deferred,
Job,
} from '@cardstack/runtime-common';
import PgAdapter from './pg-adapter';
import { PgAdapter } from './pg-adapter';
import * as Sentry from '@sentry/node';

const log = logger('queue');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PgAdapter from './pg-adapter';
import { PgAdapter } from './pg-adapter';

export class TransactionManager {
private isInTransaction = false;
Expand Down
41 changes: 41 additions & 0 deletions packages/postgres/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"compilerOptions": {
"target": "es2020",
"allowJs": true,
"module": "CommonJS",
"moduleResolution": "nodenext",
"allowSyntheticDefaultImports": true,
"noImplicitAny": true,
"noImplicitThis": true,
"alwaysStrict": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noEmitOnError": false,
"noEmit": true,
"inlineSourceMap": true,
"inlineSources": true,
"baseUrl": ".",
"esModuleInterop": true,
"experimentalDecorators": true,
"skipLibCheck": true,
"strict": true,
"paths": {
"https://cardstack.com/base/*": ["../base/*"],
"@cardstack/boxel-ui": ["../boxel-ui/addon"],
"@cardstack/boxel-ui/*": ["../boxel-ui/addon/*"],
"*": ["types/*"]
}
},
"glint": {
"environment": ["ember-loose", "ember-template-imports"],
"transform": {
"include": ["../base/**", "./**", "../boxel-ui/addon/**"]
}
},
"include": ["../base/**/*", "./**/*"],
"exclude": ["../base/**/__boxel/**"]
}
3 changes: 1 addition & 2 deletions packages/realm-server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { spawn } from 'child_process';
import { makeFastBootIndexRunner } from './fastboot';
import { shimExternals } from './lib/externals';
import * as Sentry from '@sentry/node';
import PgAdapter from './pg-adapter';
import { PgQueuePublisher } from './pg-queue';
import { PgAdapter, PgQueuePublisher } from '@cardstack/postgres';
import { MatrixClient } from '@cardstack/runtime-common/matrix-client';
import flattenDeep from 'lodash/flattenDeep';

Expand Down
6 changes: 2 additions & 4 deletions packages/realm-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
"version": "0.0.0",
"license": "MIT",
"devDependencies": {
"@cardstack/billing": "workspace:*",
"@cardstack/boxel-icons": "workspace:*",
"@cardstack/boxel-ui": "workspace:*",
"@cardstack/postgres": "workspace:*",
"@cardstack/runtime-common": "workspace:*",
"@koa/cors": "^4.0.0",
"@koa/router": "^12.0.0",
Expand All @@ -21,7 +23,6 @@
"@types/lodash": "^4.14.182",
"@types/mime-types": "^2.1.1",
"@types/node": "^18.18.5",
"@types/pg": "^8.11.5",
"@types/qs": "^6.9.17",
"@types/qunit": "^2.11.3",
"@types/sane": "^2.0.1",
Expand All @@ -46,17 +47,14 @@
"lodash": "^4.17.21",
"loglevel": "^1.8.1",
"mime-types": "^2.1.35",
"node-pg-migrate": "^6.2.2",
"npm-run-all": "^4.1.5",
"pg": "^8.11.5",
"prettier": "^2.8.4",
"prettier-plugin-ember-template-tag": "^1.1.0",
"qs": "^6.13.0",
"qunit": "^2.20.0",
"sane": "^5.0.1",
"sql-parser-cst": "^0.28.0",
"start-server-and-test": "^1.14.0",
"stripe": "^17.2.1",
"supertest": "^6.2.4",
"testem": "^3.10.1",
"tmp": "^0.2.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/realm-server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ import {
sign,
verify,
} from 'jsonwebtoken';
import stripeWebhookHandler from './billing/stripe-webhook-handlers';
import stripeWebhookHandler from '@cardstack/billing/stripe-webhook-handlers';

interface RealmServerTokenClaim {
user: string;
Expand Down
12 changes: 6 additions & 6 deletions packages/realm-server/tests/billing-test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { asExpressions, insert, param, query } from '@cardstack/runtime-common';
import { module, test } from 'qunit';
import { prepareTestDB } from './helpers';
import PgAdapter from '../pg-adapter';
import { handlePaymentSucceeded } from '../billing/stripe-webhook-handlers/payment-succeeded';
import { handleSubscriptionDeleted } from '../billing/stripe-webhook-handlers/subscription-deleted';
import { handleCheckoutSessionCompleted } from '../billing/stripe-webhook-handlers/checkout-session-completed';
import { PgAdapter } from '@cardstack/postgres';
import { handlePaymentSucceeded } from '@cardstack/billing/stripe-webhook-handlers/payment-succeeded';
import { handleSubscriptionDeleted } from '@cardstack/billing/stripe-webhook-handlers/subscription-deleted';
import { handleCheckoutSessionCompleted } from '@cardstack/billing/stripe-webhook-handlers/checkout-session-completed';
import {
LedgerEntry,
Plan,
Expand All @@ -15,13 +15,13 @@ import {
sumUpCreditsLedger,
addToCreditsLedger,
insertSubscription,
} from '../billing/billing-queries';
} from '@cardstack/billing/billing-queries';

import {
StripeInvoicePaymentSucceededWebhookEvent,
StripeSubscriptionDeletedWebhookEvent,
StripeCheckoutSessionCompletedWebhookEvent,
} from '../billing/stripe-webhook-handlers';
} from '@cardstack/billing/stripe-webhook-handlers';

async function insertUser(
dbAdapter: PgAdapter,
Expand Down
7 changes: 5 additions & 2 deletions packages/realm-server/tests/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ import { getLocalConfig as getSynapseConfig } from '../../synapse';
import { makeFastBootIndexRunner } from '../../fastboot';
import type * as CardAPI from 'https://cardstack.com/base/card-api';
import { RealmServer } from '../../server';
import PgAdapter from '../../pg-adapter';
import { PgQueueRunner, PgQueuePublisher } from '../../pg-queue';
import {
PgAdapter,
PgQueuePublisher,
PgQueueRunner,
} from '@cardstack/postgres';
import { Server } from 'http';
import { MatrixClient } from '@cardstack/runtime-common/matrix-client';
import { shimExternals } from '../../lib/externals';
Expand Down
Loading

0 comments on commit ac8cbd9

Please sign in to comment.