@middlewr/contracts 0.0.11 → 0.0.13

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.
@@ -2,12 +2,22 @@ import { z } from 'zod';
2
2
  export declare const WorkspaceSchema: z.ZodObject<{
3
3
  id: z.ZodString;
4
4
  name: z.ZodString;
5
+ billing_plan: z.ZodString;
6
+ billing_status: z.ZodString;
7
+ billing_email: z.ZodNullable<z.ZodString>;
8
+ billing_current_period_end: z.ZodNullable<z.ZodCoercedDate<unknown>>;
9
+ billing_cancel_at_period_end: z.ZodBoolean;
5
10
  created_at: z.ZodCoercedDate<unknown>;
6
11
  updated_at: z.ZodNullable<z.ZodCoercedDate<unknown>>;
7
12
  }, z.core.$strip>;
8
13
  export declare const WorkspaceWithCountSchema: z.ZodObject<{
9
14
  id: z.ZodString;
10
15
  name: z.ZodString;
16
+ billing_plan: z.ZodString;
17
+ billing_status: z.ZodString;
18
+ billing_email: z.ZodNullable<z.ZodString>;
19
+ billing_current_period_end: z.ZodNullable<z.ZodCoercedDate<unknown>>;
20
+ billing_cancel_at_period_end: z.ZodBoolean;
11
21
  created_at: z.ZodCoercedDate<unknown>;
12
22
  updated_at: z.ZodNullable<z.ZodCoercedDate<unknown>>;
13
23
  member_count: z.ZodNumber;
@@ -1 +1 @@
1
- {"version":3,"file":"workspaces.schema.d.ts","sourceRoot":"","sources":["../../src/workspaces.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe;;;;;iBAK1B,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;iBAEnC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;iBAErC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;iBAErC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;iBAEvC,CAAC;AAGH,eAAO,MAAM,yBAAyB;;;;;iBAKpC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;iBAShC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;iBAElC,CAAC;AAGH,eAAO,MAAM,yBAAyB;;;;;;;;;iBASpC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;iBAGtC,CAAC;AAGH,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC"}
1
+ {"version":3,"file":"workspaces.schema.d.ts","sourceRoot":"","sources":["../../src/workspaces.schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,eAAe;;;;;;;;;;iBAU1B,CAAC;AAEH,eAAO,MAAM,wBAAwB;;;;;;;;;;;iBAEnC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;iBAErC,CAAC;AAEH,eAAO,MAAM,0BAA0B;;iBAErC,CAAC;AAEH,eAAO,MAAM,4BAA4B;;iBAEvC,CAAC;AAGH,eAAO,MAAM,yBAAyB;;;;;iBAKpC,CAAC;AAEH,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;iBAShC,CAAC;AAEH,eAAO,MAAM,uBAAuB;;iBAElC,CAAC;AAGH,eAAO,MAAM,yBAAyB;;;;;;;;;iBASpC,CAAC;AAEH,eAAO,MAAM,2BAA2B;;;iBAGtC,CAAC;AAGH,eAAO,MAAM,mBAAmB;;;;iBAI9B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@middlewr/contracts",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "type": "module",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -0,0 +1,7 @@
1
+ import { z } from 'zod';
2
+
3
+ export const LinkAnalyticsQuerySchema = z.object({
4
+ link_id: z.string().uuid(),
5
+ from: z.coerce.date(),
6
+ to: z.coerce.date(),
7
+ });
@@ -0,0 +1,19 @@
1
+ import { z } from 'zod';
2
+
3
+ export const ApiKeySchema = z.object({
4
+ id: z.string().uuid(),
5
+ user_id: z.string().uuid(),
6
+ name: z.string(),
7
+ key_prefix: z.string(),
8
+ last_used_at: z.coerce.date().nullable(),
9
+ created_at: z.coerce.date(),
10
+ updated_at: z.coerce.date().nullable(),
11
+ });
12
+
13
+ export const CreateApiKeyInputSchema = z.object({
14
+ name: z.string().min(1).max(255),
15
+ });
16
+
17
+ export const CreateApiKeyResponseSchema = ApiKeySchema.extend({
18
+ key: z.string(),
19
+ });
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod';
2
+
3
+ export const BillingStatusSchema = z.object({
4
+ billing_plan: z.string(),
5
+ billing_status: z.string(),
6
+ billing_email: z.string().nullable(),
7
+ billing_current_period_end: z.coerce.date().nullable(),
8
+ billing_cancel_at_period_end: z.boolean(),
9
+ billing_customer_id: z.string().nullable(),
10
+ billing_subscription_id: z.string().nullable(),
11
+ });
12
+
13
+ export const CreateCheckoutInputSchema = z.object({
14
+ plan: z.enum(['pro', 'business']),
15
+ success_url: z.string().url().optional(),
16
+ billing_email: z.string().email().optional(),
17
+ });
18
+
19
+ export const CheckoutSessionSchema = z.object({
20
+ url: z.string().url(),
21
+ });
22
+
23
+ export const CustomerPortalSchema = z.object({
24
+ url: z.string().url(),
25
+ });
@@ -29,6 +29,14 @@ export const DomainIdParamSchema = z.object({
29
29
  domain_id: z.string().uuid(),
30
30
  });
31
31
 
32
+ export const UserIdParamSchema = z.object({
33
+ user_id: z.string().uuid(),
34
+ });
35
+
36
+ export const ApiKeyIdParamSchema = z.object({
37
+ api_key_id: z.string().uuid(),
38
+ });
39
+
32
40
  export const TokenParamSchema = z.object({
33
41
  token: z.string(),
34
42
  });
package/src/index.ts CHANGED
@@ -2,7 +2,10 @@ import type { ContractRouterClient } from '@orpc/contract';
2
2
  import { oc } from '@orpc/contract';
3
3
  import { z } from 'zod';
4
4
 
5
+ import { ApiKeySchema, CreateApiKeyInputSchema, CreateApiKeyResponseSchema } from './api-keys.schema';
6
+ import { BillingStatusSchema, CheckoutSessionSchema, CreateCheckoutInputSchema, CustomerPortalSchema } from './billing.schema';
5
7
  import {
8
+ ApiKeyIdParamSchema,
6
9
  DomainIdParamSchema,
7
10
  InvitationIdParamSchema,
8
11
  LinkIdParamSchema,
@@ -28,6 +31,9 @@ import {
28
31
  WorkspaceWithCountSchema,
29
32
  } from './workspaces.schema';
30
33
 
34
+ export * from './analytics.schema';
35
+ export * from './api-keys.schema';
36
+ export * from './billing.schema';
31
37
  export * from './common.schema';
32
38
  export * from './domains.schema';
33
39
  export * from './links.schema';
@@ -51,6 +57,15 @@ export const usersContract = {
51
57
  .output(z.object({ user: UserSchema })),
52
58
  };
53
59
 
60
+ // API Keys contract
61
+ export const apiKeysContract = {
62
+ create: oc.route({ method: 'POST', path: '/api/api-keys' }).input(CreateApiKeyInputSchema).output(CreateApiKeyResponseSchema),
63
+
64
+ list: oc.route({ method: 'GET', path: '/api/api-keys' }).output(z.array(ApiKeySchema)),
65
+
66
+ delete: oc.route({ method: 'DELETE', path: '/api/api-keys/{api_key_id}' }).input(ApiKeyIdParamSchema).output(z.void()),
67
+ };
68
+
54
69
  // Workspaces contract
55
70
  export const workspacesContract = {
56
71
  create: oc.route({ method: 'POST', path: '/api/workspaces' }).input(CreateWorkspaceInputSchema).output(WorkspaceSchema),
@@ -194,14 +209,34 @@ export const domainsContract = {
194
209
  .output(DomainSchema),
195
210
  };
196
211
 
212
+ // Billing contract
213
+ export const billingContract = {
214
+ status: oc
215
+ .route({ method: 'GET', path: '/api/workspaces/{workspace_id}/billing' })
216
+ .input(WorkspaceIdParamSchema)
217
+ .output(BillingStatusSchema),
218
+
219
+ checkout: oc
220
+ .route({ method: 'POST', path: '/api/workspaces/{workspace_id}/billing/checkout' })
221
+ .input(WorkspaceIdParamSchema.merge(CreateCheckoutInputSchema))
222
+ .output(CheckoutSessionSchema),
223
+
224
+ portal: oc
225
+ .route({ method: 'POST', path: '/api/workspaces/{workspace_id}/billing/portal' })
226
+ .input(WorkspaceIdParamSchema)
227
+ .output(CustomerPortalSchema),
228
+ };
229
+
197
230
  // Full contract
198
231
  export const contract = {
199
232
  users: usersContract,
233
+ apiKeys: apiKeysContract,
200
234
  workspaces: workspacesContract,
201
235
  invitations: invitationsContract,
202
236
  links: linksContract,
203
237
  tags: tagsContract,
204
238
  domains: domainsContract,
239
+ billing: billingContract,
205
240
  };
206
241
 
207
242
  export type Contract = typeof contract;
@@ -3,6 +3,11 @@ import { z } from 'zod';
3
3
  export const WorkspaceSchema = z.object({
4
4
  id: z.string().uuid(),
5
5
  name: z.string(),
6
+ billing_plan: z.string(),
7
+ billing_status: z.string(),
8
+ billing_email: z.string().nullable(),
9
+ billing_current_period_end: z.coerce.date().nullable(),
10
+ billing_cancel_at_period_end: z.boolean(),
6
11
  created_at: z.coerce.date(),
7
12
  updated_at: z.coerce.date().nullable(),
8
13
  });