@shushed/helpers 0.0.171 → 0.0.172

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/dist/index.d.ts CHANGED
@@ -33624,6 +33624,7 @@ declare class EnvEngine extends Runtime {
33624
33624
  workflowId: string;
33625
33625
  triggerId: string;
33626
33626
  }): <T extends unknown>(fn: (value: string, requestCacheRefresh?: (() => void) | undefined) => T | Promise<T>) => Promise<T>;
33627
+ resolveEnvName(envName: string): string;
33627
33628
  checkGoogleIdentiyToken(accessToken: string, audience?: {
33628
33629
  workflowId?: string;
33629
33630
  triggerId?: string;
@@ -34172,6 +34173,7 @@ type RequiredTriggerOptions = {
34172
34173
  declare class ActionHelper<C extends Record<string, any>, O extends RequiredTriggerOptions, R> {
34173
34174
  private onExecuteFunction;
34174
34175
  actionOptions: ActionHelperOptions;
34176
+ private envEngine;
34175
34177
  flags: Record<string, boolean>;
34176
34178
  opts: O | null;
34177
34179
  config: C | null;
package/dist/index.js CHANGED
@@ -106867,6 +106867,14 @@ var EnvEngine = class extends Runtime {
106867
106867
  const expectedAudience = [process.env.GCLOUD_PROJECT, audienceNorm.workflowId, audienceNorm.triggerId].filter((x) => x !== null).join("-");
106868
106868
  return this.with(`google_identity_token_${serviceName}_${expectedAudience}`, "env", { encrypted: true, ephemeralMs: 10 * 60 * 1e3, fetch: () => getIdentityToken(expectedAudience) });
106869
106869
  }
106870
+ resolveEnvName(envName) {
106871
+ if (!this._envCache[this.systemEnvName]) {
106872
+ const jsonEnv = JSON.parse(process.env[`${this.systemEnvName}ProjectEnv`] || "{}");
106873
+ this._envCache[this.systemEnvName] = jsonEnv;
106874
+ }
106875
+ const envObj = this._envCache[this.systemEnvName];
106876
+ return envObj[envName] || envName;
106877
+ }
106870
106878
  async checkGoogleIdentiyToken(accessToken, audience, allowedServiceAccounts = [`runtime@${process.env.GCLOUD_PROJECT}.iam.gserviceaccount.com`]) {
106871
106879
  if (!accessToken) {
106872
106880
  return false;
@@ -108765,6 +108773,7 @@ var import_rate_limiter_flexible = require("rate-limiter-flexible");
108765
108773
  var ActionHelper = class _ActionHelper {
108766
108774
  onExecuteFunction;
108767
108775
  actionOptions;
108776
+ envEngine = null;
108768
108777
  flags = {};
108769
108778
  opts = null;
108770
108779
  config = null;
@@ -108914,15 +108923,7 @@ var ActionHelper = class _ActionHelper {
108914
108923
  return this.getTopicName(false);
108915
108924
  }
108916
108925
  resolveEnvName(envName) {
108917
- if (!this.runtime) {
108918
- throw new Error("Invariant. preOnExecute must be called first");
108919
- }
108920
- if (!this._envCache[this.runtime.systemEnvName]) {
108921
- const jsonEnv = JSON.parse(process.env[`${this.runtime.systemEnvName}ProjectEnv`] || "{}");
108922
- this._envCache[this.runtime.systemEnvName] = jsonEnv;
108923
- }
108924
- const envObj = this._envCache[this.runtime.systemEnvName];
108925
- return envObj[envName] || envName;
108926
+ return this.getEnvEngine().resolveEnvName(envName);
108926
108927
  }
108927
108928
  resolveSecret(secretName) {
108928
108929
  if (!this.runtime) {
@@ -108977,8 +108978,10 @@ var ActionHelper = class _ActionHelper {
108977
108978
  if (!this.runtime) {
108978
108979
  throw new Error("Invariant. Runtime must be set on the context first");
108979
108980
  }
108980
- const envEngine = new env_default(this.runtime, getFirestore(this.runtime.systemEnvName));
108981
- return envEngine;
108981
+ if (!this.envEngine) {
108982
+ this.envEngine = new env_default(this.runtime);
108983
+ }
108984
+ return this.envEngine;
108982
108985
  }
108983
108986
  getRespectfulNudgeStatus(topicName, {
108984
108987
  rnWorkflowTriggerId,
@@ -109366,7 +109369,7 @@ var TriggerHelper = class {
109366
109369
  };
109367
109370
  if (reqIsRespectfulNudge) {
109368
109371
  const authHeader = options.request.headers.authorization || options.request.headers.Authorization || "";
109369
- const allowedServiceAccounts = this.actions[0].resolveEnvName("RESPECTFUL_NUDGE_SERVICE_ACCOUNT");
109372
+ const allowedServiceAccounts = envEngine.resolveEnvName("RESPECTFUL_NUDGE_SERVICE_ACCOUNT");
109370
109373
  const serviceAccount = await envEngine.checkGoogleIdentiyToken(authHeader.slice("Bearer ".length), void 0, [allowedServiceAccounts]);
109371
109374
  if (!serviceAccount) {
109372
109375
  optionsEnchanced.req.throw(401, `Invalid Authorization Header`);
@@ -109411,7 +109414,7 @@ var TriggerHelper = class {
109411
109414
  return;
109412
109415
  }
109413
109416
  if (authHeader.split(".").length === 3) {
109414
- const allowedServiceAccounts = [defaultServiceAccount, ...this.actions.map((x) => x.actionOptions.routingConditions?.api?.roles.map((y) => y.indexOf("process.env.") === 0 ? x.resolveEnvName(y.slice("process.env.".length)) : y)).flat().filter((x) => x?.includes("@"))];
109417
+ const allowedServiceAccounts = [defaultServiceAccount, ...this.actions.map((x) => x.actionOptions.routingConditions?.api?.roles.map((y) => y.indexOf("process.env.") === 0 ? envEngine.resolveEnvName(y.slice("process.env.".length)) : y)).flat().filter((x) => x?.includes("@"))];
109415
109418
  const serviceAccount = await envEngine.checkGoogleIdentiyToken(authHeader.slice("Bearer ".length), void 0, allowedServiceAccounts);
109416
109419
  if (serviceAccount) {
109417
109420
  if (serviceAccount === defaultServiceAccount) {
@@ -109520,7 +109523,7 @@ var TriggerHelper = class {
109520
109523
  let name = x;
109521
109524
  if (x.indexOf("process.env.") === 0) {
109522
109525
  const envName = name.slice("process.env.".length);
109523
- name = action.resolveEnvName(envName);
109526
+ name = envEngine.resolveEnvName(envName);
109524
109527
  if (name === envName) {
109525
109528
  options.logging.log(`The role ${x} is not specified in the environment variables. Ignoring it from the role check.`);
109526
109529
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shushed/helpers",
3
- "version": "0.0.171",
3
+ "version": "0.0.172",
4
4
  "author": "",
5
5
  "license": "UNLICENSED",
6
6
  "description": "",