@bash-app/bash-common 1.0.2 → 1.0.3
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/index.ts +2 -0
- package/package.json +1 -2
- package/src/definitions.ts +183 -0
- package/src/extendedSchemas.ts +143 -0
- package/src/postinstall.ts +0 -16
package/index.ts
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bash-app/bash-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "Common data and scripts to use on the frontend and backend",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"generate": "prisma generate",
|
|
7
7
|
"tsc": "tsc",
|
|
8
|
-
"postinstall": "ts-node ./src/postinstall.ts",
|
|
9
8
|
"prepublishOnly": "npm run tsc"
|
|
10
9
|
},
|
|
11
10
|
"repository": {
|
|
@@ -0,0 +1,183 @@
|
|
|
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>[];
|
|
@@ -0,0 +1,143 @@
|
|
|
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>>;
|
package/src/postinstall.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
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();
|