@sortipei/api-contracts 0.1.0

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 ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "@sortipei/api-contracts",
3
+ "version": "0.1.0",
4
+ "license": "UNLICENCED",
5
+ "main": "dist/api-contracts.js",
6
+ "module": "dist/api-contracts.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "dependencies": {
9
+ "zod": "^3.24.1"
10
+ },
11
+ "devDependencies": {
12
+ "@types/node": "^20.10.5",
13
+ "eslint": "^8.57.0",
14
+ "eslint-config-prettier": "^9.1.0",
15
+ "eslint-import-resolver-typescript": "^3.6.1",
16
+ "eslint-plugin-file-extension-in-import-ts": "^2.1.0",
17
+ "eslint-plugin-import": "^2.29.1",
18
+ "eslint-plugin-jsx-a11y": "^6.7.1",
19
+ "eslint-plugin-prettier": "^5.1.3",
20
+ "tslib": "^2.6.2",
21
+ "typescript": "5.4.5",
22
+ "vite": "^5.4.6",
23
+ "vite-plugin-dts": "^4.2.1"
24
+ },
25
+ "scripts": {
26
+ "build": "tsc --noEmit && vite build"
27
+ }
28
+ }
@@ -0,0 +1,96 @@
1
+ import { EventIdSchema, OrganizerIdSchema } from '../../flavors';
2
+ import {
3
+ RegionSchema,
4
+ SafeNonNegativeFloatSchema,
5
+ SafeNonNegativeIntegerSchema,
6
+ StringSchema,
7
+ URLSchema,
8
+ } from '../../shared';
9
+ import { z } from 'zod';
10
+
11
+ export const EventDTOSchema = z.object({
12
+ capacity: SafeNonNegativeIntegerSchema.nullable(),
13
+ description: StringSchema,
14
+ finishTime: z.string().datetime().nullable(),
15
+ hasHandicapAccess: z.boolean().nullable(),
16
+ id: EventIdSchema,
17
+ imageUrls: URLSchema.array(),
18
+ isDisplayed: z.boolean(),
19
+ isPromoted: z.boolean(),
20
+ link: URLSchema.nullable(),
21
+ price: SafeNonNegativeFloatSchema.nullable(),
22
+ region: RegionSchema,
23
+ startTime: z.string().datetime(),
24
+ title: StringSchema,
25
+
26
+ organizers: z
27
+ .object({
28
+ id: OrganizerIdSchema,
29
+ name: StringSchema,
30
+ })
31
+ .array()
32
+ .min(1),
33
+ });
34
+
35
+ export const CreateEventDTOSchema = z.object({
36
+ capacity: SafeNonNegativeIntegerSchema.nullable(),
37
+ description: StringSchema,
38
+ finishTime: z.string().datetime().nullable(),
39
+ hasHandicapAccess: z.boolean().nullable(),
40
+ id: EventIdSchema,
41
+ imageUrls: URLSchema.array(),
42
+ isDisplayed: z.boolean(),
43
+ link: URLSchema.nullable(),
44
+ organizersIds: OrganizerIdSchema.array().min(1),
45
+ price: SafeNonNegativeFloatSchema.nullable(),
46
+ region: RegionSchema,
47
+ startTime: z.string().datetime(),
48
+ title: StringSchema,
49
+ });
50
+
51
+ export const UpdateEventDTOSchema = CreateEventDTOSchema.omit({
52
+ id: true,
53
+ });
54
+
55
+ export const DisplayEventDTOSchema = z.object({
56
+ isDisplayed: z.boolean(),
57
+ });
58
+
59
+ export const PromoteEventDTOSchema = z.object({
60
+ isPromoted: z.boolean(),
61
+ });
62
+
63
+ export const EventFileUploadsDTOSchema = z
64
+ .object({
65
+ publicUrl: URLSchema,
66
+ uploadUrl: URLSchema,
67
+ })
68
+ .array();
69
+
70
+ export type CreateEventDTO = z.infer<typeof CreateEventDTOSchema>;
71
+ export type UpdateEventDTO = z.infer<typeof UpdateEventDTOSchema>;
72
+ export type DisplayEventDTO = z.infer<typeof DisplayEventDTOSchema>;
73
+ export type PromoteEventDTO = z.infer<typeof PromoteEventDTOSchema>;
74
+ export type EventFileUploadsDTO = z.infer<typeof EventFileUploadsDTOSchema>;
75
+
76
+ export type EventDTO = z.infer<typeof EventDTOSchema>;
77
+
78
+ export const constraints = {
79
+ description: {
80
+ minLength: 3,
81
+ maxLength: 10_000,
82
+ },
83
+ title: {
84
+ minLength: 3,
85
+ maxLength: 100,
86
+ },
87
+ };
88
+
89
+ export const ImportDTOSchema = z.object({
90
+ id: StringSchema,
91
+ userId: StringSchema,
92
+ createdAt: StringSchema.datetime(),
93
+ partialEventState: EventDTOSchema.partial(),
94
+ });
95
+
96
+ export type ImportDTO = z.infer<typeof ImportDTOSchema>;
@@ -0,0 +1,9 @@
1
+ export * from './event';
2
+ export * from './organizer';
3
+ import { constraints as eventsConstraints } from './event';
4
+ import { constraints as organizerConstraints } from './organizer';
5
+
6
+ export const constraints = {
7
+ events: eventsConstraints,
8
+ organizers: organizerConstraints,
9
+ };
@@ -0,0 +1,27 @@
1
+ import { EventIdSchema, OrganizerIdSchema } from '../../flavors';
2
+ import { StringSchema } from '../../shared';
3
+ import { z } from 'zod';
4
+
5
+ export const OrganizerDTOSchema = z.object({
6
+ eventsIds: EventIdSchema.array(),
7
+ id: OrganizerIdSchema,
8
+ name: StringSchema,
9
+ });
10
+
11
+ export const CreateOrganizerDTOSchema = z.object({
12
+ id: OrganizerIdSchema,
13
+ name: StringSchema,
14
+ });
15
+
16
+ export const UpdateOrganizerDTOSchema = CreateOrganizerDTOSchema.omit({ id: true });
17
+
18
+ export type CreateOrganizerDTO = z.infer<typeof CreateOrganizerDTOSchema>;
19
+ export type UpdateOrganizerDTO = z.infer<typeof UpdateOrganizerDTOSchema>;
20
+ export type OrganizerDTO = z.infer<typeof OrganizerDTOSchema>;
21
+
22
+ export const constraints = {
23
+ name: {
24
+ minLength: 3,
25
+ maxLength: 100,
26
+ },
27
+ };
@@ -0,0 +1 @@
1
+ export * from './partial-imported-event';
@@ -0,0 +1,11 @@
1
+ import { StringSchema } from '../../shared';
2
+ import { z } from 'zod';
3
+ import { EventDTOSchema } from '../api/event';
4
+
5
+ export const CreatePartialImportedEventDTOSchema = z.object({
6
+ partialEventState: EventDTOSchema.partial(),
7
+ token: StringSchema,
8
+ userId: StringSchema,
9
+ });
10
+
11
+ export type CreatePartialImportedEventDTO = z.infer<typeof CreatePartialImportedEventDTOSchema>;
@@ -0,0 +1,4 @@
1
+ import * as api from './api';
2
+ import * as external from './external';
3
+
4
+ export { api, external };
package/src/errors.ts ADDED
@@ -0,0 +1,3 @@
1
+ export enum ErrorCodes {
2
+ OrganizerHasEvents = '60001',
3
+ }
package/src/flavors.ts ADDED
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ import { UUIDSchema } from './shared';
3
+
4
+ export const EventIdSchema = UUIDSchema.brand('EventId');
5
+ export type EventId = z.infer<typeof EventIdSchema>;
6
+
7
+ export const createEventId = (id: string = crypto.randomUUID()): EventId => EventIdSchema.parse(id);
8
+
9
+ export const OrganizerIdSchema = UUIDSchema.brand('OrganizerId');
10
+ export type OrganizerId = z.infer<typeof OrganizerIdSchema>;
11
+
12
+ export const createOrganizerId = (id: string = crypto.randomUUID()): OrganizerId => OrganizerIdSchema.parse(id);
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './errors';
2
+ export * from './flavors';
3
+ export * from './shared';
4
+
5
+ export * as V1 from './V1';
@@ -0,0 +1,10 @@
1
+ import { z } from 'zod';
2
+
3
+ export enum Region {
4
+ East = 'East',
5
+ North = 'North',
6
+ South = 'South',
7
+ West = 'West',
8
+ }
9
+
10
+ export const RegionSchema = z.nativeEnum(Region);
@@ -0,0 +1,2 @@
1
+ export * from './schemas';
2
+ export * from './event';
@@ -0,0 +1,18 @@
1
+ import { z } from 'zod';
2
+
3
+ export const StringSchema = z.string().trim();
4
+ export const UUIDSchema = StringSchema.uuid();
5
+
6
+ const DateLikeSchema = z.union([z.number(), z.string(), z.date()]);
7
+ const DateLikeOrNullSchema = z.union([z.number(), z.null(), z.string(), z.date()]);
8
+
9
+ export const CoerceDateSchema = DateLikeSchema.pipe(z.coerce.date());
10
+ export const CoerceNullableDateSchema = DateLikeOrNullSchema.pipe(z.coerce.date()).nullable();
11
+
12
+ const SafeFloatSchema = z.number().finite().safe();
13
+ const SafeIntegerSchema = SafeFloatSchema.int();
14
+
15
+ export const SafeNonNegativeIntegerSchema = SafeIntegerSchema.nonnegative();
16
+ export const SafeNonNegativeFloatSchema = SafeFloatSchema.nonnegative();
17
+
18
+ export const URLSchema = StringSchema.url();
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "extends": "../tsconfig.packages.json",
3
+ "compilerOptions": {
4
+ "allowJs": false,
5
+ "alwaysStrict": true,
6
+ "composite": true,
7
+ "lib": ["es5", "ES2015", "ES2016"],
8
+ "outDir": "dist",
9
+ "resolveJsonModule": true,
10
+ "rootDir": "src",
11
+ "skipLibCheck": true,
12
+ "strict": true,
13
+ "module": "ES6",
14
+ "moduleResolution": "node",
15
+ "target": "es6"
16
+ },
17
+ "include": ["src"]
18
+ }
package/vite.config.ts ADDED
@@ -0,0 +1,15 @@
1
+ import { defineConfig } from 'vite';
2
+ import dts from 'vite-plugin-dts';
3
+
4
+ export default defineConfig({
5
+ plugins: [dts()],
6
+ build: {
7
+ emptyOutDir: true,
8
+ outDir: 'dist',
9
+ minify: false,
10
+ lib: {
11
+ entry: 'src/index.ts',
12
+ formats: ['es', 'cjs'],
13
+ },
14
+ },
15
+ });