@bash-app/bash-common 30.21.2 → 30.23.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bash-app/bash-common",
3
- "version": "30.21.2",
3
+ "version": "30.23.0",
4
4
  "description": "Common data and scripts to use on the frontend and backend",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -46,7 +46,7 @@
46
46
  "ts-jest": "^29.1.1",
47
47
  "ts-node": "^10.9.1",
48
48
  "tslib": "^2.6.2",
49
- "typescript": "^5.2.2"
49
+ "typescript": "^5.3.3"
50
50
  },
51
51
  "files": [
52
52
  "dist",
@@ -389,6 +389,8 @@ enum TicketStatus {
389
389
  Cancelled
390
390
  Attended
391
391
  Missed
392
+ CheckedIn
393
+ LeftRadius
392
394
  }
393
395
 
394
396
  // enum BookingStatus {
@@ -698,7 +700,8 @@ enum BashStatus {
698
700
  PreSale
699
701
  Published
700
702
  Finished
701
- // should we add Approved, Rejected, Confirmed, and Canceled like services has?
703
+ Rejected
704
+ Cancelled
702
705
  }
703
706
 
704
707
  enum ServiceStatus {
@@ -11,11 +11,11 @@ import {
11
11
  YearsOfExperience,
12
12
  } from "@prisma/client";
13
13
  import { CheckoutExt, PublicUser, ServiceBookingExt } from "./extendedSchemas";
14
- import { ServiceSubscriptionTier } from "./utils/userSubscriptionUtils";
15
- import { FrontendServiceGetPriceToBookResult } from "./utils/service/frontendServiceBookingUtils";
16
14
  import { LuxonDateRange } from "./utils/luxonUtils";
17
15
  import { ApiServiceCantBookReason } from "./utils/service/apiServiceBookingApiUtils";
18
16
  import { ServiceAttendeeOption } from "./utils/service/attendeeOptionUtils";
17
+ import { FrontendServiceGetPriceToBookResult } from "./utils/service/frontendServiceBookingUtils";
18
+ import { ServiceSubscriptionTier } from "./utils/userSubscriptionUtils";
19
19
 
20
20
  export const PASSWORD_MIN_LENGTH = 8 as const;
21
21
  export const PASSWORD_REQUIREMENTS_REGEX = new RegExp(
@@ -256,7 +256,7 @@ export type ApiServiceBookingParams = {
256
256
  bookedDays: ApiServiceBookedDayParams[];
257
257
  timezone: string;
258
258
  attendeeOption: ServiceAttendeeOption;
259
- bashEventId?: string;
259
+ bashEventId?: string;
260
260
  };
261
261
 
262
262
  export type ApiServiceCanBookParams = {} & ApiServiceBookingParams;
@@ -391,6 +391,22 @@ export interface ApiResult<T, P extends ErrorDataType = ErrorDataType> {
391
391
  rawResponse?: any;
392
392
  }
393
393
 
394
+ export function removeDataFromResult<
395
+ T,
396
+ P extends ErrorDataType = ErrorDataType
397
+ >(
398
+ result: ApiResult<T, P> | null | undefined
399
+ ): ApiResult<undefined, P> | undefined {
400
+ if (result == null) {
401
+ return undefined;
402
+ }
403
+
404
+ const { data, ...rest } = result;
405
+ return {
406
+ ...rest,
407
+ };
408
+ }
409
+
394
410
  export enum ApiErrorType {
395
411
  Unknown = 1,
396
412
  UserAlreadyHasMaximumAllowedFreeTicketsForBashEvent,
@@ -606,7 +622,7 @@ export const ASSET_MIME_TYPES_TO_EXT = {
606
622
  "image/tiff": ".tiff",
607
623
  "image/vnd": ".ico",
608
624
  "video/mp4": ".mp4",
609
- "application/pdf": ".pdf",
625
+ "application/pdf": ".pdf",
610
626
  "video/mov": ".mov",
611
627
  };
612
628
  export const VALID_ASSET_MIME_TYPES = Object.keys(ASSET_MIME_TYPES_TO_EXT);
package/src/index.ts CHANGED
@@ -16,6 +16,7 @@ export * from "./utils/promoCodesUtils";
16
16
  export * from "./utils/userPromoCodeUtils";
17
17
  export * from "./utils/userSubscriptionUtils";
18
18
  export * from "./utils/service/regexUtils";
19
+ export * from "./utils/objUtils"
19
20
  export * from "./utils/service/serviceUtils";
20
21
  export * from "./utils/service/venueUtils";
21
22
  export * from "./utils/service/attendeeOptionUtils";
@@ -0,0 +1,41 @@
1
+ export function isObject(value: unknown): value is Record<string, unknown> {
2
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3
+ }
4
+
5
+ export function deepMerge<
6
+ T extends Record<string, any>,
7
+ U extends Record<string, any>
8
+ >(
9
+ target: T | undefined | null,
10
+ source: U | undefined | null,
11
+ mergeArrays: boolean = false,
12
+ mergeCommon: boolean = false
13
+ ): T & U {
14
+ const output = { ...(mergeCommon ? [] : target) } as T & U;
15
+
16
+ for (const key in source) {
17
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
18
+ const sourceVal = source[key];
19
+ const targetVal = target ? target[key] : undefined;
20
+
21
+ if (mergeArrays && Array.isArray(sourceVal) && Array.isArray(targetVal)) {
22
+ // Merge arrays by concatenating them.
23
+ output[key] = [...targetVal, ...sourceVal] as (T & U)[Extract<
24
+ keyof U,
25
+ string
26
+ >];
27
+ } else if (isObject(sourceVal) && isObject(targetVal)) {
28
+ // When both values are objects, merge them recursively.
29
+ output[key] = deepMerge(targetVal, sourceVal) as (T & U)[Extract<
30
+ keyof U,
31
+ string
32
+ >];
33
+ } else {
34
+ // Otherwise, overwrite target with source.
35
+ output[key] = sourceVal as (T & U)[Extract<keyof U, string>];
36
+ }
37
+ }
38
+ }
39
+
40
+ return output;
41
+ }