@revojs/billing 0.2.45 → 0.2.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,59 @@
1
+ import { and, asc, equals, useReferenceStorage } from "@revojs/storage";
2
+ import { index, integer, table, text, unique } from "@revojs/storage/protocols/sqlite";
3
+ //#region src/storage/sqlite.ts
4
+ function useBillingStorage(scope, database = useReferenceStorage(scope, billingSchema)) {
5
+ const schema = database.$schema;
6
+ return {
7
+ async getCustomerByReference(provider, reference) {
8
+ return database.select(schema.customers).from(schema.customers).where(and(equals(schema.customers.provider, provider), equals(schema.customers.reference, reference))).first();
9
+ },
10
+ async getCustomerByExternalId(provider, externalId) {
11
+ return database.select(schema.customers).from(schema.customers).where(and(equals(schema.customers.provider, provider), equals(schema.customers.externalId, externalId))).first();
12
+ },
13
+ async createCustomer(customer) {
14
+ await database.insert(schema.customers).values(customer).run();
15
+ },
16
+ async getSubscriptionByExternalId(provider, externalId) {
17
+ return database.select(schema.subscriptions).from(schema.subscriptions).where(and(equals(schema.subscriptions.provider, provider), equals(schema.subscriptions.externalId, externalId))).first();
18
+ },
19
+ async getSubscriptions(customerId) {
20
+ return database.select(schema.subscriptions).from(schema.subscriptions).where(equals(schema.subscriptions.customerId, customerId)).orderBy(asc(schema.subscriptions.createdAt), asc(schema.subscriptions.id));
21
+ },
22
+ async createSubscription(subscription) {
23
+ await database.insert(schema.subscriptions).values(subscription).run();
24
+ },
25
+ async updateSubscription(id, values) {
26
+ await database.update(schema.subscriptions).set({
27
+ ...values,
28
+ updatedAt: /* @__PURE__ */ new Date()
29
+ }).where(equals(schema.subscriptions.id, id)).run();
30
+ }
31
+ };
32
+ }
33
+ var customers = table("Customers", {
34
+ id: text("Id").primaryKey().default(() => crypto.randomUUID()),
35
+ provider: text("Provider").notNull(),
36
+ externalId: text("ExternalId").notNull(),
37
+ reference: text("Reference").notNull(),
38
+ email: text("Email").notNull(),
39
+ createdAt: integer("CreatedAt", { mode: "timestamp_ms" }).notNull().default(() => /* @__PURE__ */ new Date())
40
+ }, (columns) => [unique(columns.provider, columns.externalId), unique(columns.provider, columns.reference)]);
41
+ var subscriptions = table("Subscriptions", {
42
+ id: text("Id").primaryKey().default(() => crypto.randomUUID()),
43
+ provider: text("Provider").notNull(),
44
+ externalId: text("ExternalId").notNull(),
45
+ status: text("Status").notNull().type(),
46
+ price: text("Price").notNull(),
47
+ quantity: integer("Quantity").notNull(),
48
+ currentPeriodEnd: integer("CurrentPeriodEnd", { mode: "timestamp_ms" }).notNull(),
49
+ cancelAtPeriodEnd: integer("CancelAtPeriodEnd", { mode: "boolean" }).notNull(),
50
+ updatedAt: integer("UpdatedAt", { mode: "timestamp_ms" }).notNull().default(() => /* @__PURE__ */ new Date()),
51
+ createdAt: integer("CreatedAt", { mode: "timestamp_ms" }).notNull().default(() => /* @__PURE__ */ new Date()),
52
+ customerId: text("CustomerId").notNull().references(() => customers.id, { onDelete: "cascade" })
53
+ }, (columns) => [unique(columns.provider, columns.externalId), index(columns.customerId)]);
54
+ var billingSchema = {
55
+ customers,
56
+ subscriptions
57
+ };
58
+ //#endregion
59
+ export { billingSchema, customers, subscriptions, useBillingStorage };
@@ -0,0 +1,8 @@
1
+ declare module "#billing" {
2
+ import type { BillingProvider } from "../index";
3
+ import type { Resolvable, Source } from "revojs";
4
+ import type { Awaitable } from "revojs/shared";
5
+
6
+ const entries: Source<Resolvable<Awaitable<BillingProvider>>>;
7
+ export default entries;
8
+ }
package/package.json CHANGED
@@ -1,55 +1,55 @@
1
- {
2
- "name": "@revojs/billing",
3
- "version": "0.2.45",
4
- "license": "MIT",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/tellua/revojs.git"
8
- },
9
- "files": [
10
- "dist"
11
- ],
12
- "type": "module",
13
- "main": "./dist/index.js",
14
- "module": "./dist/index.js",
15
- "types": "./dist/index.d.ts",
16
- "exports": {
17
- ".": {
18
- "types": "./dist/index.d.ts",
19
- "import": "./dist/index.js"
20
- },
21
- "./module": {
22
- "types": "./dist/module/index.d.ts",
23
- "import": "./dist/module/index.js"
24
- },
25
- "./providers/stripe": {
26
- "types": "./dist/providers/stripe.d.ts",
27
- "import": "./dist/providers/stripe.js"
28
- },
29
- "./storage/sqlite": {
30
- "types": "./dist/storage/sqlite.d.ts",
31
- "import": "./dist/storage/sqlite.js"
32
- },
33
- "./storage/postgresql": {
34
- "types": "./dist/storage/postgresql.d.ts",
35
- "import": "./dist/storage/postgresql.js"
36
- },
37
- "./storage/mysql": {
38
- "types": "./dist/storage/mysql.d.ts",
39
- "import": "./dist/storage/mysql.js"
40
- }
41
- },
42
- "scripts": {
43
- "build": "vite build",
44
- "typecheck": "tsc --noEmit -p tsconfig.json",
45
- "watch": "vite build --watch"
46
- },
47
- "dependencies": {
48
- "@revojs/server": "*",
49
- "@revojs/storage": "*",
50
- "revojs": "*"
51
- },
52
- "devDependencies": {
53
- "@revojs/tsconfig": "*"
54
- }
55
- }
1
+ {
2
+ "name": "@revojs/billing",
3
+ "version": "0.2.47",
4
+ "license": "MIT",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/tellua/revojs.git"
8
+ },
9
+ "files": [
10
+ "dist"
11
+ ],
12
+ "type": "module",
13
+ "main": "./dist/index.js",
14
+ "module": "./dist/index.js",
15
+ "types": "./dist/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./dist/index.d.ts",
19
+ "import": "./dist/index.js"
20
+ },
21
+ "./module": {
22
+ "types": "./dist/module/index.d.ts",
23
+ "import": "./dist/module/index.js"
24
+ },
25
+ "./providers/stripe": {
26
+ "types": "./dist/providers/stripe.d.ts",
27
+ "import": "./dist/providers/stripe.js"
28
+ },
29
+ "./storage/sqlite": {
30
+ "types": "./dist/storage/sqlite.d.ts",
31
+ "import": "./dist/storage/sqlite.js"
32
+ },
33
+ "./storage/postgresql": {
34
+ "types": "./dist/storage/postgresql.d.ts",
35
+ "import": "./dist/storage/postgresql.js"
36
+ },
37
+ "./storage/mysql": {
38
+ "types": "./dist/storage/mysql.d.ts",
39
+ "import": "./dist/storage/mysql.js"
40
+ }
41
+ },
42
+ "scripts": {
43
+ "build": "vite build",
44
+ "typecheck": "tsc --noEmit -p tsconfig.json",
45
+ "watch": "vite build --watch"
46
+ },
47
+ "dependencies": {
48
+ "@revojs/server": "*",
49
+ "@revojs/storage": "*",
50
+ "revojs": "*"
51
+ },
52
+ "devDependencies": {
53
+ "@revojs/tsconfig": "*"
54
+ }
55
+ }