@bash-app/bash-common 29.44.3 → 29.45.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/src/index.ts CHANGED
@@ -1,16 +1,16 @@
1
- export * from "./extendedSchemas";
2
- export * from "./definitions";
3
- export * from "./utils/ticketListUtils";
4
- export * from "./utils/dateTimeUtils";
5
- export * from "./utils/recurrenceUtils";
6
- export * from "./utils/addressUtils";
7
- export * from "./utils/paymentUtils";
8
- export * from "./utils/awsS3Utils";
9
- export * from "./utils/qrCodeUtils";
10
- export * from "./utils/sortUtils";
11
- export * from "./utils/apiUtils";
12
- export * from "./utils/urlUtils";
13
- export * from "./utils/promoCodesUtils";
14
- export * from "./utils/service/serviceUtils";
15
- export * from "./utils/service/venueUtils";
16
- export * from "./utils/stripeAccountUtils";
1
+ export * from "./extendedSchemas";
2
+ export * from "./definitions";
3
+ export * from "./utils/ticketListUtils";
4
+ export * from "./utils/dateTimeUtils";
5
+ export * from "./utils/recurrenceUtils";
6
+ export * from "./utils/addressUtils";
7
+ export * from "./utils/paymentUtils";
8
+ export * from "./utils/awsS3Utils";
9
+ export * from "./utils/qrCodeUtils";
10
+ export * from "./utils/sortUtils";
11
+ export * from "./utils/apiUtils";
12
+ export * from "./utils/urlUtils";
13
+ export * from "./utils/promoCodesUtils";
14
+ export * from "./utils/service/serviceUtils";
15
+ export * from "./utils/service/venueUtils";
16
+ export * from "./utils/stripeAccountUtils";
@@ -1,173 +1,173 @@
1
- import {IAddress} from "../definitions";
2
-
3
- const ADDRESS_DELIM = '|';
4
-
5
- const googleMapsApiKey = process.env.REACT_APP_GOOGLE_MAP_API_KEY as string;
6
-
7
-
8
- export function addressHasEnoughDataForGeolocation(address: IAddress): boolean {
9
- return !!((address.place && address.city && address.state) || (address.street && address.city && address.state));
10
- }
11
-
12
- export function addressValuesToDatabaseAddressString(addressValues: IAddress): string {
13
- const { place = '', street, city, state, zipCode, country } = addressValues;
14
- return [place, street, city, state, zipCode, country].join(ADDRESS_DELIM);
15
- }
16
-
17
- export function databaseAddressStringToAddressValues(addressString: string | undefined | null): IAddress {
18
- if (addressString) {
19
- const addressArray = addressString.split(ADDRESS_DELIM);
20
- return {
21
- place: addressArray[0],
22
- street: addressArray[1],
23
- city: addressArray[2],
24
- state: addressArray[3],
25
- zipCode: addressArray[4],
26
- country: 'USA'
27
- }
28
- }
29
- return { place: '', street: '', city: '', state: '', zipCode: '', country: '' };
30
- }
31
-
32
-
33
- export function databaseAddressStringToOneLineString(addressString: string | undefined | null): string {
34
- if (addressString) {
35
- const address = databaseAddressStringToAddressValues(addressString);
36
- let addressArr = address.place ? [address.place] : [];
37
- addressArr = [...addressArr, address.street, address.city, address.state];
38
- const addressStr = addressArr.filter((str) => !!str).join(', ');
39
- return `${addressStr} ${address.zipCode}`;
40
- }
41
- return '';
42
- }
43
-
44
- export function databaseAddressStringToDisplayString(addressString: string | undefined | null): string {
45
- if (addressString) {
46
- const oneLineString = databaseAddressStringToOneLineString(addressString);
47
- const formatted = oneLineString.replace(/([A-Z])(?=[A-Z][a-z])/g, "$1 ") // Add space between a single uppercase letter and a capitalized word
48
- .replace(/(\d)(?=[A-Z])/g, "$1 ") // Add space between numbers and letters
49
- .replace(/,/g, ", "); // Add space after commas
50
- return formatted;
51
- }
52
- return '';
53
- }
54
-
55
- export function addressToDisplayString(address: IAddress): string {
56
- let addressArr = address.place ? [address.place] : [];
57
- addressArr = [...addressArr, address.street, address.city, address.state];
58
- const addressStr = addressArr.filter((str) => !!str).join(', ');
59
- return `${addressStr} ${address.zipCode}`;
60
- }
61
-
62
-
63
- export async function getAddressFromCoordinates( lat: number, lng: number ): Promise<IAddress> {
64
- const apiUrl = `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&key=${googleMapsApiKey}&loading=async`;
65
- try {
66
- const response = await fetch(apiUrl);
67
- const data = await response.json();
68
- if (data.results.length > 0) {
69
- const addressComponents = data.results[0].address_components;
70
-
71
- let street = "";
72
- let city = "";
73
- let state = "";
74
- let zipCode = "";
75
-
76
- addressComponents.forEach((component: any) => {
77
- if (component.types.includes("route")) {
78
- street = component.long_name;
79
- } else if (component.types.includes("locality")) {
80
- city = component.long_name;
81
- } else if (component.types.includes("administrative_area_level_1")) {
82
- state = component.short_name;
83
- } else if (component.types.includes("postal_code")) {
84
- zipCode = component.long_name;
85
- }
86
- });
87
-
88
- return { place: '', street, city, state, zipCode, country: 'USA' };
89
- } else {
90
- throw new Error("No address found");
91
- }
92
- } catch (error) {
93
- console.error(error);
94
- return {
95
- place: '',
96
- street: "",
97
- city: "",
98
- state: "",
99
- zipCode: "",
100
- country: 'USA'
101
- };
102
- }
103
- }
104
-
105
- export function extractAddressComponents(place: any): IAddress {
106
- const addressComponents = place.address_components;
107
- let streetNumber = '';
108
- let streetName = '';
109
- let city = '';
110
- let state = '';
111
- let zipCode = '';
112
- let country = 'USA';
113
-
114
- addressComponents.forEach((component: any) => {
115
- const types = component.types;
116
- if (types.includes('street_number')) {
117
- streetNumber = component.long_name;
118
- }
119
- if (types.includes('route')) {
120
- streetName = component.long_name;
121
- }
122
- if (types.includes('locality')) {
123
- city = component.long_name;
124
- }
125
- if (types.includes('administrative_area_level_1')) {
126
- state = component.short_name;
127
- }
128
- if (types.includes('postal_code')) {
129
- zipCode = component.long_name;
130
- }
131
- if (types.includes('country')) {
132
- country = component.long_name;
133
- }
134
- });
135
-
136
- const street = `${streetNumber} ${streetName}`.trim();
137
-
138
- return {
139
- googlePlaceId: place.place_id,
140
- place: place.name || '',
141
- street,
142
- city,
143
- state,
144
- zipCode,
145
- country
146
- };
147
- }
148
-
149
-
150
- export async function getGeoCoordinatesFromAddress(address: IAddress): Promise<{lat: number, lng: number} | undefined> {
151
- const addressStr = `${address.street}, ${address.city}, ${address.state} ${address.zipCode}, ${address.country}`;
152
-
153
- const response = await fetch(
154
- `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(addressStr)}&key=${googleMapsApiKey}`
155
- );
156
- if (!response.ok) {
157
- console.error('Geocode response was not ok for address: ' + addressStr);
158
- }
159
-
160
- const data = await response.json();
161
-
162
- if (data.status === 'OK') {
163
- if (data.results?.length) {
164
- return data.results[0].geometry.location;
165
- }
166
- else {
167
- console.error('Geocode results were empty with address: ' + addressStr);
168
- }
169
- }
170
- else {
171
- console.error(`Geocode was not successful with address: ${addressStr}\nfor the following reason: ${data.status}`);
172
- }
173
- }
1
+ import {IAddress} from "../definitions";
2
+
3
+ const ADDRESS_DELIM = '|';
4
+
5
+ const googleMapsApiKey = process.env.REACT_APP_GOOGLE_MAP_API_KEY as string;
6
+
7
+
8
+ export function addressHasEnoughDataForGeolocation(address: IAddress): boolean {
9
+ return !!((address.place && address.city && address.state) || (address.street && address.city && address.state));
10
+ }
11
+
12
+ export function addressValuesToDatabaseAddressString(addressValues: IAddress): string {
13
+ const { place = '', street, city, state, zipCode, country } = addressValues;
14
+ return [place, street, city, state, zipCode, country].join(ADDRESS_DELIM);
15
+ }
16
+
17
+ export function databaseAddressStringToAddressValues(addressString: string | undefined | null): IAddress {
18
+ if (addressString) {
19
+ const addressArray = addressString.split(ADDRESS_DELIM);
20
+ return {
21
+ place: addressArray[0],
22
+ street: addressArray[1],
23
+ city: addressArray[2],
24
+ state: addressArray[3],
25
+ zipCode: addressArray[4],
26
+ country: 'USA'
27
+ }
28
+ }
29
+ return { place: '', street: '', city: '', state: '', zipCode: '', country: '' };
30
+ }
31
+
32
+
33
+ export function databaseAddressStringToOneLineString(addressString: string | undefined | null): string {
34
+ if (addressString) {
35
+ const address = databaseAddressStringToAddressValues(addressString);
36
+ let addressArr = address.place ? [address.place] : [];
37
+ addressArr = [...addressArr, address.street, address.city, address.state];
38
+ const addressStr = addressArr.filter((str) => !!str).join(', ');
39
+ return `${addressStr} ${address.zipCode}`;
40
+ }
41
+ return '';
42
+ }
43
+
44
+ export function databaseAddressStringToDisplayString(addressString: string | undefined | null): string {
45
+ if (addressString) {
46
+ const oneLineString = databaseAddressStringToOneLineString(addressString);
47
+ const formatted = oneLineString.replace(/([A-Z])(?=[A-Z][a-z])/g, "$1 ") // Add space between a single uppercase letter and a capitalized word
48
+ .replace(/(\d)(?=[A-Z])/g, "$1 ") // Add space between numbers and letters
49
+ .replace(/,/g, ", "); // Add space after commas
50
+ return formatted;
51
+ }
52
+ return '';
53
+ }
54
+
55
+ export function addressToDisplayString(address: IAddress): string {
56
+ let addressArr = address.place ? [address.place] : [];
57
+ addressArr = [...addressArr, address.street, address.city, address.state];
58
+ const addressStr = addressArr.filter((str) => !!str).join(', ');
59
+ return `${addressStr} ${address.zipCode}`;
60
+ }
61
+
62
+
63
+ export async function getAddressFromCoordinates( lat: number, lng: number ): Promise<IAddress> {
64
+ const apiUrl = `https://maps.googleapis.com/maps/api/geocode/json?latlng=${lat},${lng}&key=${googleMapsApiKey}&loading=async`;
65
+ try {
66
+ const response = await fetch(apiUrl);
67
+ const data = await response.json();
68
+ if (data.results.length > 0) {
69
+ const addressComponents = data.results[0].address_components;
70
+
71
+ let street = "";
72
+ let city = "";
73
+ let state = "";
74
+ let zipCode = "";
75
+
76
+ addressComponents.forEach((component: any) => {
77
+ if (component.types.includes("route")) {
78
+ street = component.long_name;
79
+ } else if (component.types.includes("locality")) {
80
+ city = component.long_name;
81
+ } else if (component.types.includes("administrative_area_level_1")) {
82
+ state = component.short_name;
83
+ } else if (component.types.includes("postal_code")) {
84
+ zipCode = component.long_name;
85
+ }
86
+ });
87
+
88
+ return { place: '', street, city, state, zipCode, country: 'USA' };
89
+ } else {
90
+ throw new Error("No address found");
91
+ }
92
+ } catch (error) {
93
+ console.error(error);
94
+ return {
95
+ place: '',
96
+ street: "",
97
+ city: "",
98
+ state: "",
99
+ zipCode: "",
100
+ country: 'USA'
101
+ };
102
+ }
103
+ }
104
+
105
+ export function extractAddressComponents(place: any): IAddress {
106
+ const addressComponents = place.address_components;
107
+ let streetNumber = '';
108
+ let streetName = '';
109
+ let city = '';
110
+ let state = '';
111
+ let zipCode = '';
112
+ let country = 'USA';
113
+
114
+ addressComponents.forEach((component: any) => {
115
+ const types = component.types;
116
+ if (types.includes('street_number')) {
117
+ streetNumber = component.long_name;
118
+ }
119
+ if (types.includes('route')) {
120
+ streetName = component.long_name;
121
+ }
122
+ if (types.includes('locality')) {
123
+ city = component.long_name;
124
+ }
125
+ if (types.includes('administrative_area_level_1')) {
126
+ state = component.short_name;
127
+ }
128
+ if (types.includes('postal_code')) {
129
+ zipCode = component.long_name;
130
+ }
131
+ if (types.includes('country')) {
132
+ country = component.long_name;
133
+ }
134
+ });
135
+
136
+ const street = `${streetNumber} ${streetName}`.trim();
137
+
138
+ return {
139
+ googlePlaceId: place.place_id,
140
+ place: place.name || '',
141
+ street,
142
+ city,
143
+ state,
144
+ zipCode,
145
+ country
146
+ };
147
+ }
148
+
149
+
150
+ export async function getGeoCoordinatesFromAddress(address: IAddress): Promise<{lat: number, lng: number} | undefined> {
151
+ const addressStr = `${address.street}, ${address.city}, ${address.state} ${address.zipCode}, ${address.country}`;
152
+
153
+ const response = await fetch(
154
+ `https://maps.googleapis.com/maps/api/geocode/json?address=${encodeURIComponent(addressStr)}&key=${googleMapsApiKey}`
155
+ );
156
+ if (!response.ok) {
157
+ console.error('Geocode response was not ok for address: ' + addressStr);
158
+ }
159
+
160
+ const data = await response.json();
161
+
162
+ if (data.status === 'OK') {
163
+ if (data.results?.length) {
164
+ return data.results[0].geometry.location;
165
+ }
166
+ else {
167
+ console.error('Geocode results were empty with address: ' + addressStr);
168
+ }
169
+ }
170
+ else {
171
+ console.error(`Geocode was not successful with address: ${addressStr}\nfor the following reason: ${data.status}`);
172
+ }
173
+ }
@@ -1,76 +1,76 @@
1
- import {BashEvent, Contact, User } from "@prisma/client";
2
- import {ContactOrUser} from "../definitions";
3
- import {PublicUser} from "../extendedSchemas";
4
-
5
- type CombinedUser = User | PublicUser;
6
- type CombinedUserOrContact = CombinedUser | Contact;
7
-
8
- export function isContactAndNotUser(contactOrUser: Partial<ContactOrUser>): contactOrUser is Contact {
9
- return !!(contactOrUser as Contact).contactOwnerId;
10
- }
11
-
12
- export function getUserName(contactOrUser: Partial<CombinedUserOrContact> | undefined): string {
13
- if (!contactOrUser) {
14
- return '';
15
- }
16
- if (isContactAndNotUser(contactOrUser)) {
17
- return contactOrUser.fullName ?? (contactOrUser as Contact).contactEmail ?? '';
18
- }
19
- const user = contactOrUser as CombinedUser;
20
- const combinedName = user.givenName && user.familyName ? `${user.givenName} ${user.familyName}` : null;
21
- return combinedName ?? user.email;
22
- }
23
-
24
- export function getUserImage(contactOrUser: CombinedUserOrContact | undefined): string {
25
- if (!contactOrUser) {
26
- return '';
27
- }
28
- const noProfilePicture = '/noProfilePicture.svg';
29
- if (isContactAndNotUser(contactOrUser)) {
30
- return noProfilePicture;
31
- }
32
- const user = contactOrUser as CombinedUser;
33
- return user.uploadedImage ?? user.image ?? noProfilePicture;
34
- }
35
-
36
- export function getContactOrUserEmail(contactOrUser: Partial<ContactOrUser>): string {
37
- return isContactAndNotUser(contactOrUser)
38
- ? (contactOrUser as Contact).contactEmail ?? ''
39
- : (contactOrUser as User).email;
40
- }
41
-
42
- export function getUserIdAndNotContactId(contactOrUser: Partial<ContactOrUser>): string | null {
43
- return isContactAndNotUser(contactOrUser)
44
- ? null
45
- : (contactOrUser as User).id;
46
- }
47
-
48
- export function getBashEventDetailUrlParamsFromBashEvent(bashEvent: BashEvent | undefined, coverPhoto?: string): string {
49
- if (!bashEvent) {
50
- return '';
51
- }
52
- return getBashEventDetailUrlParams(bashEvent.title, bashEvent.description, coverPhoto ?? bashEvent.coverPhoto);
53
- }
54
-
55
- function getBashEventDetailUrlParams(bashEventTitle: string | undefined,
56
- bashEventDescription: string | undefined | null,
57
- coverPhoto?: string | null): string {
58
- // Don't let the description be huge
59
- const desc = bashEventDescription && bashEventDescription.length > 10 ? bashEventDescription?.slice(0, 10) + '...' : bashEventDescription;
60
- // Need to add characters if any of the args is undefined or else the params get thrown off
61
- const params: string[] = [];
62
- if (bashEventTitle) {
63
- // params.push(`${URL_PARAMS_BASH_EVENT_TITLE}=${encodeURIComponent(bashEventTitle)}`);
64
- }
65
- if (desc) {
66
- // params.push(`${URL_PARAMS_BASH_EVENT_DESC}=${encodeURIComponent(desc)}`);
67
- }
68
- if (coverPhoto) {
69
- // params.push(`${URL_PARAMS_BASH_EVENT_COVER_PHOTO}=${encodeURIComponent(coverPhoto)}`);
70
- }
71
- return params.join('&');
72
- }
73
-
74
- export function isProduction(): boolean {
75
- return process.env.NODE_ENV === 'production';
76
- }
1
+ import {BashEvent, Contact, User } from "@prisma/client";
2
+ import {ContactOrUser} from "../definitions";
3
+ import {PublicUser} from "../extendedSchemas";
4
+
5
+ type CombinedUser = User | PublicUser;
6
+ type CombinedUserOrContact = CombinedUser | Contact;
7
+
8
+ export function isContactAndNotUser(contactOrUser: Partial<ContactOrUser>): contactOrUser is Contact {
9
+ return !!(contactOrUser as Contact).contactOwnerId;
10
+ }
11
+
12
+ export function getUserName(contactOrUser: Partial<CombinedUserOrContact> | undefined): string {
13
+ if (!contactOrUser) {
14
+ return '';
15
+ }
16
+ if (isContactAndNotUser(contactOrUser)) {
17
+ return contactOrUser.fullName ?? (contactOrUser as Contact).contactEmail ?? '';
18
+ }
19
+ const user = contactOrUser as CombinedUser;
20
+ const combinedName = user.givenName && user.familyName ? `${user.givenName} ${user.familyName}` : null;
21
+ return combinedName ?? user.email;
22
+ }
23
+
24
+ export function getUserImage(contactOrUser: CombinedUserOrContact | undefined): string {
25
+ if (!contactOrUser) {
26
+ return '';
27
+ }
28
+ const noProfilePicture = '/noProfilePicture.svg';
29
+ if (isContactAndNotUser(contactOrUser)) {
30
+ return noProfilePicture;
31
+ }
32
+ const user = contactOrUser as CombinedUser;
33
+ return user.uploadedImage ?? user.image ?? noProfilePicture;
34
+ }
35
+
36
+ export function getContactOrUserEmail(contactOrUser: Partial<ContactOrUser>): string {
37
+ return isContactAndNotUser(contactOrUser)
38
+ ? (contactOrUser as Contact).contactEmail ?? ''
39
+ : (contactOrUser as User).email;
40
+ }
41
+
42
+ export function getUserIdAndNotContactId(contactOrUser: Partial<ContactOrUser>): string | null {
43
+ return isContactAndNotUser(contactOrUser)
44
+ ? null
45
+ : (contactOrUser as User).id;
46
+ }
47
+
48
+ export function getBashEventDetailUrlParamsFromBashEvent(bashEvent: BashEvent | undefined, coverPhoto?: string): string {
49
+ if (!bashEvent) {
50
+ return '';
51
+ }
52
+ return getBashEventDetailUrlParams(bashEvent.title, bashEvent.description, coverPhoto ?? bashEvent.coverPhoto);
53
+ }
54
+
55
+ function getBashEventDetailUrlParams(bashEventTitle: string | undefined,
56
+ bashEventDescription: string | undefined | null,
57
+ coverPhoto?: string | null): string {
58
+ // Don't let the description be huge
59
+ const desc = bashEventDescription && bashEventDescription.length > 10 ? bashEventDescription?.slice(0, 10) + '...' : bashEventDescription;
60
+ // Need to add characters if any of the args is undefined or else the params get thrown off
61
+ const params: string[] = [];
62
+ if (bashEventTitle) {
63
+ // params.push(`${URL_PARAMS_BASH_EVENT_TITLE}=${encodeURIComponent(bashEventTitle)}`);
64
+ }
65
+ if (desc) {
66
+ // params.push(`${URL_PARAMS_BASH_EVENT_DESC}=${encodeURIComponent(desc)}`);
67
+ }
68
+ if (coverPhoto) {
69
+ // params.push(`${URL_PARAMS_BASH_EVENT_COVER_PHOTO}=${encodeURIComponent(coverPhoto)}`);
70
+ }
71
+ return params.join('&');
72
+ }
73
+
74
+ export function isProduction(): boolean {
75
+ return process.env.NODE_ENV === 'production';
76
+ }