@bash-app/bash-common 1.0.0 → 1.0.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/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@bash-app/bash-common",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Common data and scripts to use on the frontend and backend",
5
5
  "scripts": {
6
6
  "generate": "prisma generate",
7
- "tsc": "tsc"
7
+ "tsc": "tsc",
8
+ "postinstall": "ts-node ./src/postinstall.ts",
9
+ "prepublishOnly": "npm run tsc"
8
10
  },
9
11
  "repository": {
10
12
  "type": "git",
@@ -13,7 +15,6 @@
13
15
  "author": "Frank Nielson",
14
16
  "license": "ISC",
15
17
  "dependencies": {
16
- "@prisma/client": "^5.13.0",
17
18
  "ts-node": "^10.9.1",
18
19
  "typescript": "^5.2.2"
19
20
  },
@@ -21,7 +22,10 @@
21
22
  "@types/jest": "^29.5.5",
22
23
  "@types/node": "^20.8.4",
23
24
  "jest": "^29.7.0",
24
- "prisma": "^5.13.0",
25
25
  "ts-jest": "^29.1.1"
26
+ },
27
+ "peerDependencies": {
28
+ "@prisma/client": "^5.13.0",
29
+ "prisma": "^5.13.0"
26
30
  }
27
31
  }
@@ -0,0 +1,16 @@
1
+ import fs from 'node:fs/promises';
2
+
3
+ async function copyPrisma(): Promise<void> {
4
+ try {
5
+ const cwd = process.cwd();
6
+ const filePath = `${cwd}/prisma`;
7
+ console.log(`Copying local prisma folder to root of project: ${filePath}`);
8
+ const copied = await fs.cp('./prisma', filePath, {
9
+ recursive: true
10
+ });
11
+ }
12
+ catch (e) {
13
+ console.error(`Unable to copy prisma directory to root of project: ${e}`);
14
+ }
15
+ }
16
+ copyPrisma();
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "ES5",
4
+ "noEmit": true,
4
5
  "outDir": "./dist",
5
6
  "rootDir": "./src",
6
7
  "strict": true,
@@ -9,7 +10,6 @@
9
10
  "skipLibCheck": true,
10
11
  "forceConsistentCasingInFileNames": true,
11
12
  "jsx": "react-jsx",
12
- "noEmit": true,
13
13
  "noImplicitAny": true,
14
14
  "sourceMap": true
15
15
  },
@@ -1,12 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="WEB_MODULE" version="4">
3
- <component name="NewModuleRootManager">
4
- <content url="file://$MODULE_DIR$">
5
- <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
- <excludeFolder url="file://$MODULE_DIR$/temp" />
7
- <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
- </content>
9
- <orderEntry type="inheritedJdk" />
10
- <orderEntry type="sourceFolder" forTests="false" />
11
- </component>
12
- </module>
package/.idea/modules.xml DELETED
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="ProjectModuleManager">
4
- <modules>
5
- <module fileurl="file://$PROJECT_DIR$/.idea/bash-common.iml" filepath="$PROJECT_DIR$/.idea/bash-common.iml" />
6
- </modules>
7
- </component>
8
- </project>
package/.idea/vcs.xml DELETED
@@ -1,6 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <project version="4">
3
- <component name="VcsDirectoryMappings">
4
- <mapping directory="" vcs="Git" />
5
- </component>
6
- </project>
@@ -1,183 +0,0 @@
1
- // TODO: Move everything here to common repo along with prisma interface ext interfaces
2
- import {TicketTier} from "@prisma/client";
3
-
4
- export const GOOGLE_CALLBACK_URL = '/auth/google/callback' as const;
5
- export const CHECKOUT_RETURN_SUCCESS_URL = `/checkout-return/success/{CHECKOUT_SESSION_ID}` as const;
6
- export const CHECKOUT_RETURN_CANCEL_URL = `/checkout-return/cancel/{CHECKOUT_SESSION_ID}` as const;
7
- export const VERIFICATION_RETURN_URL = `/sign-up` as const
8
-
9
-
10
-
11
- export const MIN_AMOUNT_OF_TICKETS_FOR_PUBLIC_EVENT_TO_SHOW = 0 as const;
12
- export const DEFAULT_MAX_NUMBER_OF_TICKETS = 35 as const
13
-
14
- export const MAX_NUMBER_OF_FREE_TICKETS_PER_USER_FOR_A_BASH_EVENT = 100 as const;
15
- export const MAX_NUMBER_OF_TICKETS_PER_REQUEST_FOR_A_BASH_EVENT = 50 as const;
16
-
17
- export const MONTHS_PREVIOUS_THAT_STRIPE_ACCOUNTS_WILL_BE_SEARCHED_BY_EMAIL = 1 as const;
18
-
19
- export const HTTP_CODE_OK = 200 as const;
20
- export const HTTP_CODE_TEMPORARY_REDIRECT = 307 as const;
21
- export const HTTP_CODE_INTERNAL_SERVER_ERR = 500 as const
22
- export const HTTP_CODE_BAD_REQUEST = 400 as const;
23
- export const HTTP_CODE_UNAUTHORIZED = 401 as const;
24
- export const HTTP_CODE_NOT_FOUND = 404 as const;
25
- export const ERR_UNAUTHORIZED_REQUEST = "Unauthorized to perform requested action. Have you logged in?" as const;
26
-
27
- export const URL_PARAMS_BASH_EVENT_ID = 'bashEventId' as const;
28
- export const URL_PARAMS_BASH_EVENT_TITLE = 'bashEventId' as const;
29
- export const URL_PARAMS_BASH_EVENT_DESC = 'bashEventDesc' as const;
30
- export const URL_PARAMS_BASH_EVENT_COVER_PHOTO = 'bashEventCoverPhoto' as const;
31
- export const URL_PARAMS_EMAIL = 'email' as const;
32
- export const URL_PARAMS_OTP_CODE = 'code' as const;
33
- export const URL_PARAMS_INCLUDE = 'include' as const;
34
-
35
- export const URL_INCLUDE_QUERY_PARAM_DELIM = ',' as const;
36
- export const URL_INCLUDE_PRISMA_DATA_KEYS_DELIM = '.' as const;
37
-
38
- export const DEFAULT_PRISMA_TTL_SECONDS = 60 as const;
39
- export const PRISMA_MEDIA_TTL_SECONDS = 60 * 5; // 5 hours
40
- export const PRISMA_USER_TTL_SECONDS = 60 * 7; // 7 hours
41
- export const PRISMA_BASH_EVENT_TTL_SECONDS = 60 as const;
42
-
43
- export const MIN_PASSWORD_LENGTH = 10;
44
-
45
-
46
- export type DateTimeArgType = Date | string | undefined | null;
47
- export type RecordKey = string | number | symbol;
48
- export type PartialExcept<T, K extends keyof T> = Partial<T> & {[P in K]: T[P]};
49
- type GetTypeOfArray<T> = T extends (infer U)[] ? U : never;
50
-
51
-
52
- const ASSET_MIME_TYPES_TO_EXT = {
53
- 'image/jpeg': '.jpeg',
54
- 'image/png': '.png',
55
- 'image/gif': '.gif',
56
- 'image/bmp': '.bmp',
57
- 'image/webp': '.webp',
58
- 'image/svg+xml': '.svg',
59
- 'image/tiff': '.tiff',
60
- 'image/vnd': '.ico',
61
- 'video/mp4': '.mp4',
62
- // '.webm',
63
- // '.ogg',
64
- // '.avi',
65
- // '.mov',
66
- // '.mkv'
67
- };
68
- export const VALID_ASSET_MIME_TYPES = Object.keys(ASSET_MIME_TYPES_TO_EXT);
69
-
70
- export interface NumberOfTicketsForDate {
71
- numberOfTickets: number;
72
- ticketDateTime: DateTimeArgType;
73
- }
74
-
75
- export interface AvailableTicketsForTicketTier {
76
- ticketTier: TicketTier;
77
- availableTickets: NumberOfTicketsForDate[];
78
- }
79
-
80
- export interface SignInEmailWithCode {
81
- email: string;
82
- code: string;
83
- }
84
-
85
- export enum ApiErrorType {
86
- Unknown = 1,
87
- UserAlreadyHasMaximumAllowedFreeTicketsForBashEvent,
88
- BashHasNoMoreTicketsAvailable,
89
- NotEnoughTicketsAvailable,
90
- UserExceededMaxTicketNumberForOneRequest,
91
- UserDoesNotExist,
92
- StripeCreateCheckoutSessionFailed,
93
- StripeUserInfoIncomplete,
94
- TicketsAlreadyPurchasedUsingThisCheckoutSession,
95
- StripeAccountHasNotSetupTaxData,
96
- StripeCheckoutSessionIncomplete
97
- }
98
-
99
- export const StripeErrorToApiErrorType = {
100
- "stripe_tax_inactive": ApiErrorType.StripeAccountHasNotSetupTaxData
101
- }
102
-
103
- export type ErrorDataType = Record<RecordKey, any>;
104
- export interface ApiResult<T, P extends ErrorDataType = ErrorDataType> {
105
- data?: T;
106
- token?: string;
107
- error?: string;
108
- errorType?: ApiErrorType;
109
- errorData?: P;
110
- details?: string;
111
- message?: string;
112
- }
113
-
114
- export interface StripeCreateCheckoutSessionArgs {
115
- currency: string;
116
- paymentMethodType: string;
117
- ticketListStr: string;
118
- }
119
-
120
- export interface StripeSessionRedirect {
121
- redirectUrl: string;
122
- }
123
-
124
- export interface StripeConfirmPayment {
125
- checkoutSessionId: string;
126
- }
127
-
128
- export interface StripeAccountLinkArgs {
129
- userId: string;
130
- returnUrl: string;
131
- refreshUrl: string;
132
- }
133
-
134
- export interface StripeConfirmPaymentResult {
135
- bashEventId: string;
136
- numberOfTickets: number;
137
- }
138
-
139
- export interface IMediaUploadArgs {
140
- mimetype: string;
141
- idOfLinkedPrismaEntry: string;
142
- assetKey: string;
143
- }
144
-
145
- export interface IPreSignedUrlArgs {
146
- assetKey: string;
147
- mimetype: string;
148
- }
149
-
150
- export interface IPreSignedUrlResult {
151
- assetKey: string;
152
- preSignedUrl: string | undefined;
153
- }
154
-
155
- export type AllKeysUnionOfDescendants<T> = T extends object
156
- ? T[keyof T] extends infer K
157
- ? K extends string | number | symbol
158
- ? {[K in keyof T]-?: T[K] extends any[]
159
- ? GetTypeOfArray<T[K]> extends Record<RecordKey, any>
160
- ? `${K & string}` | `${AllKeysUnion<GetTypeOfArray<T[K]>>}`
161
- : never
162
- : `${K & string}` | `${AllKeysUnion<T[K]>}`}[keyof T]
163
- : never
164
- : never
165
- : never;
166
-
167
- export type AllKeysOfDescendants<T> = AllKeysUnionOfDescendants<T>[];
168
-
169
- type AllKeysUnion<T> = T extends object
170
- ? T[keyof T] extends infer K
171
- ? K extends string | number | symbol
172
- ? {[K in keyof T]-?: T[K] extends any[]
173
- ? GetTypeOfArray<T[K]> extends Record<RecordKey, any>
174
- ? `${K & string}` | `${K & string}${typeof URL_INCLUDE_PRISMA_DATA_KEYS_DELIM}${AllKeysUnion<GetTypeOfArray<T[K]>> & string}`
175
- : never
176
- : T[K] extends Function
177
- ? never
178
- : `${K & string}` | `${K & string}${typeof URL_INCLUDE_PRISMA_DATA_KEYS_DELIM}${AllKeysUnion<T[K]> & string}`}[keyof T]
179
- : never
180
- : never
181
- : never;
182
-
183
- export type AllKeys<T> = AllKeysUnion<T>[];
@@ -1,143 +0,0 @@
1
- import {
2
- AmountOfGuests,
3
- EventTask,
4
- AssociatedBash,
5
- BashEvent,
6
- Invitation,
7
- TargetAudience,
8
- Ticket,
9
- User,
10
- TicketTier, Service, Review, Media, BashComment, Recurrence, Contact
11
- } from "@prisma/client";
12
- import {RecordKey} from "./definitions";
13
-
14
- // TODO: Get this to work
15
- type PrismaInclude<T extends Record<RecordKey, unknown>> = {[key in keyof T]: boolean | {include: T[key]}};
16
-
17
- export interface BashEventExt extends BashEvent {
18
- targetAudience?: TargetAudience;
19
- amountOfGuests?: AmountOfGuests;
20
- recurrence?: Recurrence;
21
- creator?: User;
22
- ticketTiers: TicketTierExt[];
23
- media: Media[];
24
- eventTasks: EventTask[];
25
- tickets?: Ticket[]; // Only include tickets that the user has purchased and not all tickets (could be thousands + privacy)
26
- // Do not include in fetch. Could be hundreds of these
27
- invitations: InvitationExt[];
28
- }
29
-
30
- export const BASH_EVENT_DATA_TO_INCLUDE = {
31
- targetAudience: true,
32
- amountOfGuests: true,
33
- recurrence: true,
34
- ticketTiers: true,
35
- creator: true,
36
- eventTasks: true,
37
- media: true
38
- }
39
-
40
- export const BASH_EVENT_DATA_TO_CLONE = [
41
- 'targetAudience',
42
- 'amountOfGuests',
43
- 'ticketTiers',
44
- 'media',
45
- 'recurrence',
46
- 'invitations',
47
- ] as const;
48
-
49
- type RemoveCommonProperties<T, U> = keyof (Omit<T, keyof U> & Omit<U, keyof T>);
50
- type UnionFromArray<T extends ReadonlyArray<any>> = T[number];
51
- type BashEventExtMinusDataToCloneType = Omit<BashEventExt, UnionFromArray<typeof BASH_EVENT_DATA_TO_CLONE>>;
52
-
53
- export const BASH_EVENT_DATA_TO_REMOVE: RemoveCommonProperties<BashEvent, BashEventExtMinusDataToCloneType>[] = [
54
- 'creator',
55
- 'eventTasks',
56
- 'tickets'
57
- ];
58
-
59
- export interface InvitationExt extends Invitation {
60
- creator: User;
61
- sentTo: User;
62
- tickets: Ticket[];
63
- }
64
-
65
- export const INVITATION_DATA_TO_INCLUDE = {
66
- creator: true,
67
- sentTo: true,
68
- tickets: true
69
- }
70
-
71
- export interface InvitationExtraData extends Invitation {
72
- isFreeGuest?: boolean;
73
- isOrganizer?: boolean;
74
- }
75
-
76
- export interface AssociatedBashExt extends AssociatedBash {
77
- bashEvent: BashEventExt;
78
- invitation: InvitationExt;
79
- }
80
-
81
-
82
- export const ASSOCIATED_BASH_DATA_TO_INCLUDE = {
83
- bashEvent: {
84
- include: BASH_EVENT_DATA_TO_INCLUDE
85
- },
86
- invitation: {
87
- include: INVITATION_DATA_TO_INCLUDE
88
- }
89
- }
90
-
91
- export interface TicketTierExt extends TicketTier {
92
- bashEvent: BashEvent;
93
- tickets: TicketExt[];
94
- }
95
-
96
- export interface TicketExt extends Ticket {
97
- owner: User;
98
- forUser: User;
99
- }
100
-
101
- export interface ReviewExt extends Review {
102
- comments: BashComment[];
103
- }
104
-
105
- export interface UserExtraData extends User {
106
- password: string;
107
- }
108
-
109
- export interface UserExt extends User {
110
- services: Service[];
111
-
112
- // Do not include in fetch as there could be thousands of these
113
- associatedBashes?: AssociatedBash[]
114
- reviews?: ReviewExt[];
115
- contacts?: Contact[];
116
- }
117
-
118
- export const USER_DATA_TO_INCLUDE = {
119
- services: true,
120
- }
121
-
122
- export const USER_DATA_SELECT_REVIEWS_COMMENTS = {
123
- reviews: {
124
- include: {
125
- comments: true
126
- }
127
- }
128
- }
129
-
130
- export const PUBLIC_USER_DATA_TO_SELECT = {
131
- id: true,
132
- email: true,
133
- givenName: true,
134
- familyName: true,
135
- fullName: true,
136
- username: true,
137
- image: true,
138
- uploadedImage: true,
139
- services: true,
140
- }
141
-
142
- export type Public_User = Pick<UserExt, keyof typeof PUBLIC_USER_DATA_TO_SELECT>
143
- & Partial<Pick<UserExt, keyof typeof USER_DATA_SELECT_REVIEWS_COMMENTS>>;