@teardown/schemas 0.1.36 → 0.1.38
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/package.json +6 -4
- package/src/common/constants.ts +14 -0
- package/src/common/index.ts +1 -0
- package/src/index.ts +1 -0
- package/src/modules/billing/index.ts +1 -0
- package/src/modules/billing/schemas.ts +160 -0
- package/src/modules/identify/schemas.ts +9 -11
- package/src/modules/projects/schemas.ts +4 -0
- package/tsconfig.json +14 -0
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teardown/schemas",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.38",
|
|
4
4
|
"private": false,
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
8
8
|
"type": "module",
|
|
9
9
|
"files": [
|
|
10
|
-
"src/**/*"
|
|
10
|
+
"src/**/*",
|
|
11
|
+
"generated/**/*",
|
|
12
|
+
"tsconfig.json"
|
|
11
13
|
],
|
|
12
14
|
"main": "./src/index.ts",
|
|
13
15
|
"exports": {
|
|
@@ -91,11 +93,11 @@
|
|
|
91
93
|
},
|
|
92
94
|
"dependencies": {
|
|
93
95
|
"@sinclair/typebox": "^0.34.41",
|
|
94
|
-
"@teardown/types": "0.1.
|
|
96
|
+
"@teardown/types": "0.1.38"
|
|
95
97
|
},
|
|
96
98
|
"devDependencies": {
|
|
97
99
|
"@biomejs/biome": "2.3.7",
|
|
98
|
-
"@teardown/tsconfig": "0.1.
|
|
100
|
+
"@teardown/tsconfig": "0.1.38",
|
|
99
101
|
"typescript": "^5.9.3"
|
|
100
102
|
},
|
|
101
103
|
"peerDependencies": {
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session token expiry in days
|
|
3
|
+
*/
|
|
4
|
+
export const SESSION_TOKEN_EXPIRY_DAYS = 30;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Session token expiry in milliseconds
|
|
8
|
+
*/
|
|
9
|
+
export const SESSION_TOKEN_EXPIRY_MS = SESSION_TOKEN_EXPIRY_DAYS * 24 * 60 * 60 * 1000;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Session token expiry as jose duration string
|
|
13
|
+
*/
|
|
14
|
+
export const SESSION_TOKEN_EXPIRY_JOSE = `${SESSION_TOKEN_EXPIRY_DAYS}d` as const;
|
package/src/common/index.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./schemas";
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { Type, type Static } from "@sinclair/typebox";
|
|
2
|
+
import { SubscriptionStatusEnum, SubscriptionTierEnum } from "@teardown/types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Subscription tier schema
|
|
6
|
+
*/
|
|
7
|
+
export const SubscriptionTierSchema = Type.Enum(SubscriptionTierEnum);
|
|
8
|
+
export type SubscriptionTier = Static<typeof SubscriptionTierSchema>;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Subscription status schema
|
|
12
|
+
*/
|
|
13
|
+
export const SubscriptionStatusSchema = Type.Enum(SubscriptionStatusEnum);
|
|
14
|
+
export type SubscriptionStatus = Static<typeof SubscriptionStatusSchema>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Subscription details schema
|
|
18
|
+
*/
|
|
19
|
+
export const SubscriptionSchema = Type.Object({
|
|
20
|
+
tier: SubscriptionTierSchema,
|
|
21
|
+
status: Type.Union([SubscriptionStatusSchema, Type.Null()]),
|
|
22
|
+
period_start: Type.Union([Type.String(), Type.Null()]),
|
|
23
|
+
period_end: Type.Union([Type.String(), Type.Null()]),
|
|
24
|
+
mau_limit: Type.Number({ minimum: 0 }),
|
|
25
|
+
project_limit: Type.Number({ minimum: 0 }),
|
|
26
|
+
seat_limit: Type.Number({ minimum: 0 }),
|
|
27
|
+
stripe_customer_id: Type.Union([Type.String(), Type.Null()]),
|
|
28
|
+
stripe_subscription_id: Type.Union([Type.String(), Type.Null()]),
|
|
29
|
+
billing_email: Type.Union([Type.String({ format: "email" }), Type.Null()]),
|
|
30
|
+
});
|
|
31
|
+
export type Subscription = Static<typeof SubscriptionSchema>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Current usage schema
|
|
35
|
+
*/
|
|
36
|
+
export const UsageSchema = Type.Object({
|
|
37
|
+
mau_count: Type.Number({ minimum: 0 }),
|
|
38
|
+
project_count: Type.Number({ minimum: 0 }),
|
|
39
|
+
seat_count: Type.Number({ minimum: 0 }),
|
|
40
|
+
period_start: Type.String(),
|
|
41
|
+
period_end: Type.String(),
|
|
42
|
+
});
|
|
43
|
+
export type Usage = Static<typeof UsageSchema>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Subscription with usage schema
|
|
47
|
+
*/
|
|
48
|
+
export const SubscriptionWithUsageSchema = Type.Object({
|
|
49
|
+
subscription: SubscriptionSchema,
|
|
50
|
+
usage: UsageSchema,
|
|
51
|
+
is_over_limit: Type.Object({
|
|
52
|
+
mau: Type.Boolean(),
|
|
53
|
+
projects: Type.Boolean(),
|
|
54
|
+
seats: Type.Boolean(),
|
|
55
|
+
}),
|
|
56
|
+
});
|
|
57
|
+
export type SubscriptionWithUsage = Static<typeof SubscriptionWithUsageSchema>;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Create checkout session request
|
|
61
|
+
*/
|
|
62
|
+
export const CreateCheckoutSessionSchema = Type.Object({
|
|
63
|
+
tier: Type.Union([
|
|
64
|
+
Type.Literal(SubscriptionTierEnum.STARTER),
|
|
65
|
+
Type.Literal(SubscriptionTierEnum.GROWTH),
|
|
66
|
+
Type.Literal(SubscriptionTierEnum.SCALE),
|
|
67
|
+
]),
|
|
68
|
+
success_url: Type.String({ format: "uri" }),
|
|
69
|
+
cancel_url: Type.String({ format: "uri" }),
|
|
70
|
+
});
|
|
71
|
+
export type CreateCheckoutSession = Static<typeof CreateCheckoutSessionSchema>;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Checkout session response
|
|
75
|
+
*/
|
|
76
|
+
export const CheckoutSessionResponseSchema = Type.Object({
|
|
77
|
+
success: Type.Literal(true),
|
|
78
|
+
data: Type.Object({
|
|
79
|
+
session_url: Type.String({ format: "uri" }),
|
|
80
|
+
session_id: Type.String(),
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
export type CheckoutSessionResponse = Static<typeof CheckoutSessionResponseSchema>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Create portal session request
|
|
87
|
+
*/
|
|
88
|
+
export const CreatePortalSessionSchema = Type.Object({
|
|
89
|
+
return_url: Type.String({ format: "uri" }),
|
|
90
|
+
});
|
|
91
|
+
export type CreatePortalSession = Static<typeof CreatePortalSessionSchema>;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Portal session response
|
|
95
|
+
*/
|
|
96
|
+
export const PortalSessionResponseSchema = Type.Object({
|
|
97
|
+
success: Type.Literal(true),
|
|
98
|
+
data: Type.Object({
|
|
99
|
+
portal_url: Type.String({ format: "uri" }),
|
|
100
|
+
}),
|
|
101
|
+
});
|
|
102
|
+
export type PortalSessionResponse = Static<typeof PortalSessionResponseSchema>;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Get subscription response
|
|
106
|
+
*/
|
|
107
|
+
export const GetSubscriptionResponseSchema = Type.Object({
|
|
108
|
+
success: Type.Literal(true),
|
|
109
|
+
data: SubscriptionWithUsageSchema,
|
|
110
|
+
});
|
|
111
|
+
export type GetSubscriptionResponse = Static<typeof GetSubscriptionResponseSchema>;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Billing error codes
|
|
115
|
+
*/
|
|
116
|
+
export const BillingErrorSchema = Type.Union([
|
|
117
|
+
Type.Object({
|
|
118
|
+
code: Type.Literal("NOT_FOUND"),
|
|
119
|
+
message: Type.String(),
|
|
120
|
+
}),
|
|
121
|
+
Type.Object({
|
|
122
|
+
code: Type.Literal("FORBIDDEN"),
|
|
123
|
+
message: Type.String(),
|
|
124
|
+
}),
|
|
125
|
+
Type.Object({
|
|
126
|
+
code: Type.Literal("ALREADY_SUBSCRIBED"),
|
|
127
|
+
message: Type.String(),
|
|
128
|
+
}),
|
|
129
|
+
Type.Object({
|
|
130
|
+
code: Type.Literal("STRIPE_ERROR"),
|
|
131
|
+
message: Type.String(),
|
|
132
|
+
}),
|
|
133
|
+
Type.Object({
|
|
134
|
+
code: Type.Literal("INVALID_TIER"),
|
|
135
|
+
message: Type.String(),
|
|
136
|
+
}),
|
|
137
|
+
Type.Object({
|
|
138
|
+
code: Type.Literal("LIMIT_EXCEEDED"),
|
|
139
|
+
message: Type.String(),
|
|
140
|
+
details: Type.Object({
|
|
141
|
+
limit_type: Type.Union([Type.Literal("mau"), Type.Literal("projects"), Type.Literal("seats")]),
|
|
142
|
+
current: Type.Number(),
|
|
143
|
+
limit: Type.Number(),
|
|
144
|
+
}),
|
|
145
|
+
}),
|
|
146
|
+
Type.Object({
|
|
147
|
+
code: Type.Literal("NO_STRIPE_CUSTOMER"),
|
|
148
|
+
message: Type.String(),
|
|
149
|
+
}),
|
|
150
|
+
]);
|
|
151
|
+
export type BillingError = Static<typeof BillingErrorSchema>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Billing error response
|
|
155
|
+
*/
|
|
156
|
+
export const BillingErrorResponseSchema = Type.Object({
|
|
157
|
+
success: Type.Literal(false),
|
|
158
|
+
error: BillingErrorSchema,
|
|
159
|
+
});
|
|
160
|
+
export type BillingErrorResponse = Static<typeof BillingErrorResponseSchema>;
|
|
@@ -99,25 +99,25 @@ export const DeviceInfoSchema = Type.Object({
|
|
|
99
99
|
*/
|
|
100
100
|
timestamp: Type.Optional(Type.Date({ error: "timestamp is required" })),
|
|
101
101
|
/**
|
|
102
|
-
*
|
|
102
|
+
* OS info, required
|
|
103
103
|
*/
|
|
104
|
-
|
|
104
|
+
os: OSInfoSchema,
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
106
|
+
* Application info, required
|
|
107
107
|
*/
|
|
108
|
-
|
|
108
|
+
application: ApplicationInfoSchema,
|
|
109
109
|
/**
|
|
110
110
|
* Hardware info, required
|
|
111
111
|
*/
|
|
112
112
|
hardware: HardwareInfoSchema,
|
|
113
113
|
/**
|
|
114
|
-
*
|
|
114
|
+
* Update info (optional) - not all builds will have an update
|
|
115
115
|
*/
|
|
116
|
-
|
|
116
|
+
update: Type.Union([DeviceUpdateInfoSchema, Type.Null()]),
|
|
117
117
|
/**
|
|
118
|
-
* Notifications info
|
|
118
|
+
* Notifications info (optional)
|
|
119
119
|
*/
|
|
120
|
-
notifications: NotificationsInfoSchema,
|
|
120
|
+
notifications: Type.Union([NotificationsInfoSchema, Type.Null()]),
|
|
121
121
|
});
|
|
122
122
|
export type DeviceInfo = Static<typeof DeviceInfoSchema>;
|
|
123
123
|
|
|
@@ -142,7 +142,7 @@ export const IdentifyRequestSchema = Type.Object({
|
|
|
142
142
|
});
|
|
143
143
|
export type IdentifyRequest = Static<typeof IdentifyRequestSchema>;
|
|
144
144
|
|
|
145
|
-
enum IdentifyVersionStatusEnum {
|
|
145
|
+
export enum IdentifyVersionStatusEnum {
|
|
146
146
|
/**
|
|
147
147
|
* A new version is available
|
|
148
148
|
*/
|
|
@@ -165,8 +165,6 @@ enum IdentifyVersionStatusEnum {
|
|
|
165
165
|
DISABLED = "DISABLED",
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
export { IdentifyVersionStatusEnum };
|
|
169
|
-
|
|
170
168
|
export const UpdateInfoSchema = Type.Object({
|
|
171
169
|
version: Type.String({ error: "version is required" }),
|
|
172
170
|
build: Type.String({ error: "build is required" }),
|
|
@@ -159,6 +159,10 @@ export const ProjectErrorSchema = Type.Union([
|
|
|
159
159
|
code: Type.Literal("INVALID_REQUEST"),
|
|
160
160
|
message: Type.String(),
|
|
161
161
|
}),
|
|
162
|
+
Type.Object({
|
|
163
|
+
code: Type.Literal("PROJECT_LIMIT_REACHED"),
|
|
164
|
+
message: Type.String(),
|
|
165
|
+
}),
|
|
162
166
|
]);
|
|
163
167
|
export type ProjectError = Static<typeof ProjectErrorSchema>;
|
|
164
168
|
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@teardown/tsconfig/tsconfig.lib.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"noEmit": true,
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"baseUrl": ".",
|
|
7
|
+
"paths": {
|
|
8
|
+
"@/*": ["./src/*"]
|
|
9
|
+
},
|
|
10
|
+
"noUnusedLocals": false
|
|
11
|
+
},
|
|
12
|
+
"include": ["src/**/*"],
|
|
13
|
+
"exclude": ["node_modules"]
|
|
14
|
+
}
|