@8ms/helpers 3.0.20 → 3.0.22

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.
@@ -97,8 +97,9 @@ var ApiResponseClass = class ApiResponseClass {
97
97
  };
98
98
  validateZod = (schema) => {
99
99
  try {
100
+ const validatedBody = schema.parse(this.body);
100
101
  return new ApiResponseClass({
101
- body: schema.parse(this.body),
102
+ body: validatedBody,
102
103
  state: this.state
103
104
  });
104
105
  } catch (error) {
@@ -96,8 +96,9 @@ var ApiResponseClass = class ApiResponseClass {
96
96
  };
97
97
  validateZod = (schema) => {
98
98
  try {
99
+ const validatedBody = schema.parse(this.body);
99
100
  return new ApiResponseClass({
100
- body: schema.parse(this.body),
101
+ body: validatedBody,
101
102
  state: this.state
102
103
  });
103
104
  } catch (error) {
@@ -28,8 +28,10 @@ const getAwsConfig = async (props) => {
28
28
  if (props.oidcRoleArn && require_environment_environment.isVercel()) {
29
29
  const { awsCredentialsProvider } = await import("@vercel/oidc-aws-credentials-provider");
30
30
  credentials = await awsCredentialsProvider({ roleArn: props.oidcRoleArn })();
31
+ } else if (props.oidcRoleArn && require_environment_environment.isGoogleCloud()) {
32
+ const gcpToken = await getGcpOidcToken();
33
+ credentials = await assumeAwsRoleWithGcpToken(gcpToken, props);
31
34
  }
32
- if (props.oidcRoleArn && require_environment_environment.isGoogleCloud()) credentials = await assumeAwsRoleWithGcpToken(await getGcpOidcToken(), props);
33
35
  return { credentials };
34
36
  };
35
37
  //#endregion
@@ -27,8 +27,10 @@ const getAwsConfig = async (props) => {
27
27
  if (props.oidcRoleArn && isVercel()) {
28
28
  const { awsCredentialsProvider } = await import("@vercel/oidc-aws-credentials-provider");
29
29
  credentials = await awsCredentialsProvider({ roleArn: props.oidcRoleArn })();
30
+ } else if (props.oidcRoleArn && isGoogleCloud()) {
31
+ const gcpToken = await getGcpOidcToken();
32
+ credentials = await assumeAwsRoleWithGcpToken(gcpToken, props);
30
33
  }
31
- if (props.oidcRoleArn && isGoogleCloud()) credentials = await assumeAwsRoleWithGcpToken(await getGcpOidcToken(), props);
32
34
  return { credentials };
33
35
  };
34
36
  //#endregion
@@ -86,25 +86,29 @@ const getYearMonthString = (input) => {
86
86
  * Shorthand to get the current date.
87
87
  */
88
88
  const getTodayYmdString = (setMidnight) => {
89
- return getYmdString(require_date_calculation.getToday(setMidnight));
89
+ const today = require_date_calculation.getToday(setMidnight);
90
+ return getYmdString(today);
90
91
  };
91
92
  /**
92
93
  * Shorthand to get the current date.
93
94
  */
94
95
  const getTodayYmdHisString = (setMidnight) => {
95
- return getYmdHisString(require_date_calculation.getToday(setMidnight));
96
+ const today = require_date_calculation.getToday(setMidnight);
97
+ return getYmdHisString(today);
96
98
  };
97
99
  /**
98
100
  * Shorthand to get the current date.
99
101
  */
100
102
  const getTodayYmdNumber = (setMidnight) => {
101
- return getYmdNumber(require_date_calculation.getToday(setMidnight));
103
+ const today = require_date_calculation.getToday(setMidnight);
104
+ return getYmdNumber(today);
102
105
  };
103
106
  /**
104
107
  * Shorthand to get the current date.
105
108
  */
106
109
  const getTodayYmdHisNumber = (setMidnight) => {
107
- return getYmdHisNumber(require_date_calculation.getToday(setMidnight));
110
+ const today = require_date_calculation.getToday(setMidnight);
111
+ return getYmdHisNumber(today);
108
112
  };
109
113
  /**
110
114
  * Convert a Date into a YYYY number.
@@ -85,25 +85,29 @@ const getYearMonthString = (input) => {
85
85
  * Shorthand to get the current date.
86
86
  */
87
87
  const getTodayYmdString = (setMidnight) => {
88
- return getYmdString(getToday(setMidnight));
88
+ const today = getToday(setMidnight);
89
+ return getYmdString(today);
89
90
  };
90
91
  /**
91
92
  * Shorthand to get the current date.
92
93
  */
93
94
  const getTodayYmdHisString = (setMidnight) => {
94
- return getYmdHisString(getToday(setMidnight));
95
+ const today = getToday(setMidnight);
96
+ return getYmdHisString(today);
95
97
  };
96
98
  /**
97
99
  * Shorthand to get the current date.
98
100
  */
99
101
  const getTodayYmdNumber = (setMidnight) => {
100
- return getYmdNumber(getToday(setMidnight));
102
+ const today = getToday(setMidnight);
103
+ return getYmdNumber(today);
101
104
  };
102
105
  /**
103
106
  * Shorthand to get the current date.
104
107
  */
105
108
  const getTodayYmdHisNumber = (setMidnight) => {
106
- return getYmdHisNumber(getToday(setMidnight));
109
+ const today = getToday(setMidnight);
110
+ return getYmdHisNumber(today);
107
111
  };
108
112
  /**
109
113
  * Convert a Date into a YYYY number.
@@ -7,6 +7,7 @@ const environment = {
7
7
  };
8
8
  const platform = {
9
9
  AWS: "AWS",
10
+ LOCALHOST: "LOCALHOST",
10
11
  VERCEL: "VERCEL",
11
12
  GCP: "GCP"
12
13
  };
@@ -37,7 +38,7 @@ const getEnvironment = () => {
37
38
  * Check to see if we are working on AWS Lambda.
38
39
  */
39
40
  const isAws = () => platform.AWS === process.env["EMS_PLATFORM"];
40
- const isVercel = () => "undefined" !== typeof process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF;
41
+ const isVercel = () => platform.VERCEL === process.env["EMS_PLATFORM"];
41
42
  const isGoogleCloud = () => platform.GCP === process.env["EMS_PLATFORM"];
42
43
  /**
43
44
  * Some code should only run on the server side to protect the data.
@@ -52,12 +53,7 @@ const isProduction = () => environment.PRODUCTION === getEnvironment();
52
53
  /**
53
54
  * Check to see if we are developing locally or on the hosted platform.
54
55
  */
55
- const isLocalhost = () => {
56
- if ("true" === process.env["IS_LOCAL"]) return true;
57
- if (isAws()) return "true" === process.env["AWS_SAM_LOCAL"];
58
- if (isVercel()) return "undefined" === typeof process.env["NEXT_PUBLIC_VERCEL_GIT_REPO_ID"];
59
- return false;
60
- };
56
+ const isLocalhost = () => platform.LOCALHOST === process.env["EMS_PLATFORM"];
61
57
  //#endregion
62
58
  exports.environment = environment;
63
59
  exports.getEnvironment = getEnvironment;
@@ -7,6 +7,7 @@ declare const environment: {
7
7
  type Environment = typeof environment[keyof typeof environment];
8
8
  declare const platform: {
9
9
  readonly AWS: "AWS";
10
+ readonly LOCALHOST: "LOCALHOST";
10
11
  readonly VERCEL: "VERCEL";
11
12
  readonly GCP: "GCP";
12
13
  };
@@ -7,6 +7,7 @@ declare const environment: {
7
7
  type Environment = typeof environment[keyof typeof environment];
8
8
  declare const platform: {
9
9
  readonly AWS: "AWS";
10
+ readonly LOCALHOST: "LOCALHOST";
10
11
  readonly VERCEL: "VERCEL";
11
12
  readonly GCP: "GCP";
12
13
  };
@@ -6,6 +6,7 @@ const environment = {
6
6
  };
7
7
  const platform = {
8
8
  AWS: "AWS",
9
+ LOCALHOST: "LOCALHOST",
9
10
  VERCEL: "VERCEL",
10
11
  GCP: "GCP"
11
12
  };
@@ -36,7 +37,7 @@ const getEnvironment = () => {
36
37
  * Check to see if we are working on AWS Lambda.
37
38
  */
38
39
  const isAws = () => platform.AWS === process.env["EMS_PLATFORM"];
39
- const isVercel = () => "undefined" !== typeof process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF;
40
+ const isVercel = () => platform.VERCEL === process.env["EMS_PLATFORM"];
40
41
  const isGoogleCloud = () => platform.GCP === process.env["EMS_PLATFORM"];
41
42
  /**
42
43
  * Some code should only run on the server side to protect the data.
@@ -51,11 +52,6 @@ const isProduction = () => environment.PRODUCTION === getEnvironment();
51
52
  /**
52
53
  * Check to see if we are developing locally or on the hosted platform.
53
54
  */
54
- const isLocalhost = () => {
55
- if ("true" === process.env["IS_LOCAL"]) return true;
56
- if (isAws()) return "true" === process.env["AWS_SAM_LOCAL"];
57
- if (isVercel()) return "undefined" === typeof process.env["NEXT_PUBLIC_VERCEL_GIT_REPO_ID"];
58
- return false;
59
- };
55
+ const isLocalhost = () => platform.LOCALHOST === process.env["EMS_PLATFORM"];
60
56
  //#endregion
61
57
  export { environment, getEnvironment, isAws, isDevelopment, isGoogleCloud, isLocalhost, isProduction, isServer, isStaging, isVercel, platform };
@@ -6,7 +6,8 @@ const undefinedValue = "__!!UNDEFINED!!__";
6
6
  * Check to see if a value is undefined.
7
7
  */
8
8
  const isUndefined = (instance, keys) => {
9
- return undefinedValue === require_util_defaultTo.defaultTo(instance, keys, undefinedValue);
9
+ const value = require_util_defaultTo.defaultTo(instance, keys, undefinedValue);
10
+ return undefinedValue === value;
10
11
  };
11
12
  //#endregion
12
13
  exports.isUndefined = isUndefined;
@@ -5,7 +5,8 @@ const undefinedValue = "__!!UNDEFINED!!__";
5
5
  * Check to see if a value is undefined.
6
6
  */
7
7
  const isUndefined = (instance, keys) => {
8
- return undefinedValue === defaultTo(instance, keys, undefinedValue);
8
+ const value = defaultTo(instance, keys, undefinedValue);
9
+ return undefinedValue === value;
9
10
  };
10
11
  //#endregion
11
12
  export { isUndefined };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "3.0.20",
4
+ "version": "3.0.22",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"