@chaaskit/db 0.1.1 → 0.1.2

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Matt Ferrante
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ declare global {
5
5
  }
6
6
  export declare const prisma: PrismaClientPkg.PrismaClient<PrismaClientPkg.Prisma.PrismaClientOptions, unknown, import("@prisma/client/runtime/library").InternalArgs>;
7
7
  export declare const Prisma: typeof PrismaClientPkg.Prisma;
8
- export type { PrismaClient } from '@prisma/client';
8
+ export type { Prisma as PrismaTypes, PrismaClient } from '@prisma/client';
9
9
  export { prisma as db };
10
10
  export { getSchemaFolderPath, getBaseSchemaPath, getBaseSchemaContent, getCustomSchemaContent, copySchemaToProject, schemaExists, hasLegacySchema, initializePrisma, } from './schema-helpers.js';
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,gBAAgB,CAAC;AAC7C,QAAA,MAAQ,YAAY,qCAAoB,CAAC;AAEzC,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,MAAM,EAAE,YAAY,CAAC,OAAO,YAAY,CAAC,GAAG,SAAS,CAAC;CAC3D;AAED,eAAO,MAAM,MAAM,0IAA0C,CAAC;AAO9D,eAAO,MAAM,MAAM,+BAAyB,CAAC;AAC7C,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC;AAGxB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,gBAAgB,GACjB,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,eAAe,MAAM,gBAAgB,CAAC;AAC7C,QAAA,MAAQ,YAAY,qCAAoB,CAAC;AAEzC,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,MAAM,EAAE,YAAY,CAAC,OAAO,YAAY,CAAC,GAAG,SAAS,CAAC;CAC3D;AAED,eAAO,MAAM,MAAM,0IAA0C,CAAC;AAO9D,eAAO,MAAM,MAAM,+BAAyB,CAAC;AAC7C,YAAY,EAAE,MAAM,IAAI,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAAE,MAAM,IAAI,EAAE,EAAE,CAAC;AAGxB,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,YAAY,EACZ,eAAe,EACf,gBAAgB,GACjB,MAAM,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chaaskit/db",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Prisma database layer for ChaasKit applications",
5
5
  "license": "MIT",
6
6
  "author": "Matt Ferrante <@ferrants>",
@@ -13,7 +13,14 @@
13
13
  "bugs": {
14
14
  "url": "https://github.com/ferrants/chaaskit/issues"
15
15
  },
16
- "keywords": ["chaaskit", "ai", "chat", "saas", "database", "prisma"],
16
+ "keywords": [
17
+ "chaaskit",
18
+ "ai",
19
+ "chat",
20
+ "saas",
21
+ "database",
22
+ "prisma"
23
+ ],
17
24
  "type": "module",
18
25
  "main": "./dist/index.js",
19
26
  "types": "./dist/index.d.ts",
@@ -30,6 +37,14 @@
30
37
  "dist",
31
38
  "prisma/schema"
32
39
  ],
40
+ "dependencies": {
41
+ "@prisma/client": "^6.0.0"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^22.0.0",
45
+ "prisma": "^6.0.0",
46
+ "typescript": "^5.6.0"
47
+ },
33
48
  "scripts": {
34
49
  "build": "tsc",
35
50
  "dev": "tsc --watch",
@@ -39,13 +54,5 @@
39
54
  "push": "prisma db push",
40
55
  "migrate": "prisma migrate dev",
41
56
  "studio": "prisma studio"
42
- },
43
- "dependencies": {
44
- "@prisma/client": "^6.0.0"
45
- },
46
- "devDependencies": {
47
- "@types/node": "^22.0.0",
48
- "prisma": "^6.0.0",
49
- "typescript": "^5.6.0"
50
57
  }
51
- }
58
+ }
@@ -51,6 +51,14 @@ model User {
51
51
  mcpCredentials MCPCredential[]
52
52
  apiKeys ApiKey[]
53
53
  documents Document[]
54
+ waitlistInvites WaitlistEntry[]
55
+ inviteTokensUsed InviteToken[] @relation("InviteTokenUsedBy")
56
+ inviteTokensCreated InviteToken[] @relation("InviteTokenCreatedBy")
57
+ promoCodeRedemptions PromoCodeRedemption[]
58
+ referralCodes ReferralCode[]
59
+ referralsSent Referral[] @relation("Referrer")
60
+ referralsReceived Referral[] @relation("Referred")
61
+ usageMeters UsageMeter[]
54
62
 
55
63
  // OAuth relations
56
64
  oauthClients OAuthClient[]
@@ -132,6 +140,7 @@ model Message {
132
140
 
133
141
  // Relations
134
142
  feedback MessageFeedback[]
143
+ usageMeters UsageMeter[]
135
144
 
136
145
  createdAt DateTime @default(now())
137
146
 
@@ -245,6 +254,7 @@ model Team {
245
254
  documents Document[]
246
255
  slackIntegration SlackIntegration?
247
256
  scheduledPrompts ScheduledPrompt[]
257
+ usageMeters UsageMeter[]
248
258
  createdAt DateTime @default(now())
249
259
  updatedAt DateTime @updatedAt
250
260
 
@@ -22,3 +22,158 @@
22
22
  // add the opposite relation field to that model in base.prisma. After running
23
23
  // db:sync, check for validation errors and add any missing relation fields.
24
24
  // =============================================================================
25
+
26
+ model WaitlistEntry {
27
+ id String @id @default(cuid())
28
+ email String @unique
29
+ name String?
30
+ status String @default("pending")
31
+ invitedAt DateTime?
32
+ invitedByUserId String?
33
+ invitedByUser User? @relation(fields: [invitedByUserId], references: [id], onDelete: SetNull)
34
+ createdAt DateTime @default(now())
35
+ updatedAt DateTime @updatedAt
36
+
37
+ @@index([status])
38
+ }
39
+
40
+ model InviteToken {
41
+ id String @id @default(cuid())
42
+ token String @unique
43
+ email String
44
+ createdAt DateTime @default(now())
45
+ expiresAt DateTime
46
+ usedAt DateTime?
47
+ usedByUserId String?
48
+ usedByUser User? @relation("InviteTokenUsedBy", fields: [usedByUserId], references: [id], onDelete: SetNull)
49
+ createdByUserId String?
50
+ createdByUser User? @relation("InviteTokenCreatedBy", fields: [createdByUserId], references: [id], onDelete: SetNull)
51
+
52
+ @@index([email])
53
+ @@index([expiresAt])
54
+ }
55
+
56
+ model CreditsLedger {
57
+ id String @id @default(cuid())
58
+ ownerType String
59
+ ownerId String
60
+ delta Int
61
+ reason String?
62
+ sourceType String
63
+ expiresAt DateTime?
64
+ metadata Json?
65
+ createdAt DateTime @default(now())
66
+
67
+ grants CreditsGrant[]
68
+
69
+ @@index([ownerType, ownerId])
70
+ @@index([expiresAt])
71
+ }
72
+
73
+ model CreditsGrant {
74
+ id String @id @default(cuid())
75
+ ownerType String
76
+ ownerId String
77
+ total Int
78
+ remaining Int
79
+ expiresAt DateTime?
80
+ ledgerId String
81
+ ledger CreditsLedger @relation(fields: [ledgerId], references: [id], onDelete: Cascade)
82
+ createdAt DateTime @default(now())
83
+
84
+ @@index([ownerType, ownerId])
85
+ @@index([expiresAt])
86
+ }
87
+
88
+ model CreditsBalance {
89
+ id String @id @default(cuid())
90
+ ownerType String
91
+ ownerId String
92
+ balance Int
93
+ updatedAt DateTime @updatedAt
94
+
95
+ @@unique([ownerType, ownerId])
96
+ }
97
+
98
+ model PromoCode {
99
+ id String @id @default(cuid())
100
+ code String @unique
101
+ credits Int
102
+ maxUses Int
103
+ startsAt DateTime?
104
+ endsAt DateTime?
105
+ creditsExpiresAt DateTime?
106
+ createdAt DateTime @default(now())
107
+
108
+ redemptions PromoCodeRedemption[]
109
+ }
110
+
111
+ model PromoCodeRedemption {
112
+ id String @id @default(cuid())
113
+ promoCodeId String
114
+ promoCode PromoCode @relation(fields: [promoCodeId], references: [id], onDelete: Cascade)
115
+ userId String
116
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
117
+ redeemedAt DateTime @default(now())
118
+
119
+ @@unique([promoCodeId, userId])
120
+ @@index([userId])
121
+ }
122
+
123
+ model ReferralCode {
124
+ id String @id @default(cuid())
125
+ code String @unique
126
+ userId String
127
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
128
+ createdAt DateTime @default(now())
129
+
130
+ @@index([userId])
131
+ }
132
+
133
+ model Referral {
134
+ id String @id @default(cuid())
135
+ referrerUserId String
136
+ referredUserId String
137
+ status String @default("pending")
138
+ createdAt DateTime @default(now())
139
+
140
+ referrer User @relation("Referrer", fields: [referrerUserId], references: [id], onDelete: Cascade)
141
+ referred User @relation("Referred", fields: [referredUserId], references: [id], onDelete: Cascade)
142
+ grants ReferralGrant[]
143
+
144
+ @@unique([referrerUserId, referredUserId])
145
+ @@index([referrerUserId])
146
+ @@index([referredUserId])
147
+ }
148
+
149
+ model ReferralGrant {
150
+ id String @id @default(cuid())
151
+ referralId String
152
+ referral Referral @relation(fields: [referralId], references: [id], onDelete: Cascade)
153
+ event String
154
+ grantedAt DateTime @default(now())
155
+
156
+ @@unique([referralId, event])
157
+ }
158
+
159
+ model UsageMeter {
160
+ id String @id @default(cuid())
161
+ provider String
162
+ model String
163
+ promptTokens Int
164
+ completionTokens Int
165
+ totalTokens Int
166
+ userId String
167
+ teamId String?
168
+ messageId String?
169
+ message Message? @relation(fields: [messageId], references: [id], onDelete: SetNull)
170
+ createdAt DateTime @default(now())
171
+
172
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
173
+ team Team? @relation(fields: [teamId], references: [id], onDelete: SetNull)
174
+
175
+ @@index([userId])
176
+ @@index([teamId])
177
+ @@index([messageId])
178
+ @@index([createdAt])
179
+ }