@shushed/helpers 0.0.180 → 0.0.181
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 +1 -0
- package/dist/index.js +17 -17
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -34168,6 +34168,7 @@ type RequiredTriggerOptions = {
|
|
|
34168
34168
|
req: {
|
|
34169
34169
|
throw: (status: number, body: string) => void;
|
|
34170
34170
|
};
|
|
34171
|
+
terminate: (status: number, message: string) => void;
|
|
34171
34172
|
logging: any;
|
|
34172
34173
|
runtimeUrl?: string;
|
|
34173
34174
|
};
|
package/dist/index.js
CHANGED
|
@@ -109165,7 +109165,7 @@ var ActionHelper = class _ActionHelper {
|
|
|
109165
109165
|
if (err instanceof Error) {
|
|
109166
109166
|
throw err;
|
|
109167
109167
|
}
|
|
109168
|
-
return this.opts.
|
|
109168
|
+
return this.opts.terminate(429, "Rate limit exceeeded");
|
|
109169
109169
|
}
|
|
109170
109170
|
}
|
|
109171
109171
|
}
|
|
@@ -109360,7 +109360,7 @@ var TriggerHelper = class {
|
|
|
109360
109360
|
throw: (code, message2) => {
|
|
109361
109361
|
executionFinished = true;
|
|
109362
109362
|
options.logging.error(message2 + ". Execution stoped.", code);
|
|
109363
|
-
options.
|
|
109363
|
+
options.terminate(code, message2);
|
|
109364
109364
|
}
|
|
109365
109365
|
},
|
|
109366
109366
|
terminate: (statusCode, message2) => {
|
|
@@ -109389,7 +109389,7 @@ var TriggerHelper = class {
|
|
|
109389
109389
|
const allowedServiceAccounts = envEngine.resolveEnvName("RESPECTFUL_NUDGE_SERVICE_ACCOUNT");
|
|
109390
109390
|
const serviceAccount = await envEngine.checkGoogleIdentiyToken(authHeader.slice("Bearer ".length), void 0, [allowedServiceAccounts]);
|
|
109391
109391
|
if (!serviceAccount) {
|
|
109392
|
-
optionsEnchanced.
|
|
109392
|
+
optionsEnchanced.terminate(401, `Invalid Authorization Header`);
|
|
109393
109393
|
return;
|
|
109394
109394
|
}
|
|
109395
109395
|
} else if (reqIsPubSub || reqIsScheduler || reqIsCloudTask) {
|
|
@@ -109402,24 +109402,24 @@ var TriggerHelper = class {
|
|
|
109402
109402
|
url: options.request.host
|
|
109403
109403
|
}, options.request.headers, getFirestore(runtime.systemEnvName));
|
|
109404
109404
|
} catch (err) {
|
|
109405
|
-
optionsEnchanced.
|
|
109405
|
+
optionsEnchanced.terminate(401, `Invalid Authorization Header. ${err.message}`);
|
|
109406
109406
|
return;
|
|
109407
109407
|
}
|
|
109408
109408
|
if (reqIsScheduler) {
|
|
109409
109409
|
if (!(validationResult.email === defaultServiceAccount || this.helperOpts.serviceAccounts?.scheduler?.some((y) => y === validationResult.email))) {
|
|
109410
|
-
optionsEnchanced.
|
|
109410
|
+
optionsEnchanced.terminate(401, `Invalid Authorization Header`);
|
|
109411
109411
|
return;
|
|
109412
109412
|
}
|
|
109413
109413
|
}
|
|
109414
109414
|
if (reqIsPubSub) {
|
|
109415
109415
|
if (!(validationResult.email === defaultServiceAccount || this.helperOpts.serviceAccounts?.pubsub?.some((y) => y === validationResult.email))) {
|
|
109416
|
-
optionsEnchanced.
|
|
109416
|
+
optionsEnchanced.terminate(401, `Invalid Authorization Header`);
|
|
109417
109417
|
return;
|
|
109418
109418
|
}
|
|
109419
109419
|
}
|
|
109420
109420
|
if (reqIsCloudTask) {
|
|
109421
109421
|
if (!(validationResult.email === defaultServiceAccount || this.helperOpts.serviceAccounts?.cloudtasks?.some((y) => y === validationResult.email))) {
|
|
109422
|
-
optionsEnchanced.
|
|
109422
|
+
optionsEnchanced.terminate(401, `Invalid Authorization Header`);
|
|
109423
109423
|
return;
|
|
109424
109424
|
}
|
|
109425
109425
|
}
|
|
@@ -109427,7 +109427,7 @@ var TriggerHelper = class {
|
|
|
109427
109427
|
const clientIp = getClientIp(optionsEnchanced.nodeReq);
|
|
109428
109428
|
const authHeader = options.request.headers.authorization || options.request.headers.Authorization || "";
|
|
109429
109429
|
if (!clientIp) {
|
|
109430
|
-
optionsEnchanced.
|
|
109430
|
+
optionsEnchanced.terminate(401, `Invalid Client IP`);
|
|
109431
109431
|
return;
|
|
109432
109432
|
}
|
|
109433
109433
|
if (authHeader.split(".").length === 3) {
|
|
@@ -109476,11 +109476,11 @@ var TriggerHelper = class {
|
|
|
109476
109476
|
try {
|
|
109477
109477
|
message = await pubsub_default.decodeMessageFromRequest(optionsEnchanced.nodeReq);
|
|
109478
109478
|
} catch (err) {
|
|
109479
|
-
optionsEnchanced.
|
|
109479
|
+
optionsEnchanced.terminate(400, `Malformed Message. ${err.message}`);
|
|
109480
109480
|
return;
|
|
109481
109481
|
}
|
|
109482
109482
|
if (!message) {
|
|
109483
|
-
optionsEnchanced.
|
|
109483
|
+
optionsEnchanced.terminate(400, `Missing Message.`);
|
|
109484
109484
|
return;
|
|
109485
109485
|
}
|
|
109486
109486
|
} else {
|
|
@@ -109493,19 +109493,19 @@ var TriggerHelper = class {
|
|
|
109493
109493
|
limit: "2mb"
|
|
109494
109494
|
});
|
|
109495
109495
|
} catch (err) {
|
|
109496
|
-
optionsEnchanced.
|
|
109496
|
+
optionsEnchanced.terminate(400, `Unfetchable Body. ${err.message}`);
|
|
109497
109497
|
return;
|
|
109498
109498
|
}
|
|
109499
109499
|
if (rawBody) {
|
|
109500
109500
|
try {
|
|
109501
109501
|
bodyAsJson = JSON.parse(rawBody);
|
|
109502
109502
|
} catch (err) {
|
|
109503
|
-
optionsEnchanced.
|
|
109503
|
+
optionsEnchanced.terminate(400, `Unparsable body ${err.message}`);
|
|
109504
109504
|
return;
|
|
109505
109505
|
}
|
|
109506
109506
|
}
|
|
109507
109507
|
} else {
|
|
109508
|
-
optionsEnchanced.
|
|
109508
|
+
optionsEnchanced.terminate(400, "Invalid Content-Type");
|
|
109509
109509
|
return;
|
|
109510
109510
|
}
|
|
109511
109511
|
message = {
|
|
@@ -109532,7 +109532,7 @@ var TriggerHelper = class {
|
|
|
109532
109532
|
atLeastOneHandlerMatched = true;
|
|
109533
109533
|
if (!reqIsPubSub && !reqIsRespectfulNudge && !reqIsScheduler && !reqIsCloudTask) {
|
|
109534
109534
|
if (!matchingAPIKeysDetails.roles.length && (action.actionOptions.routingConditions || {}).api?.havingApiKey) {
|
|
109535
|
-
return optionsEnchanced.
|
|
109535
|
+
return optionsEnchanced.terminate(401, `No roles associated to API key`);
|
|
109536
109536
|
}
|
|
109537
109537
|
if (action.actionOptions.routingConditions?.api?.roles) {
|
|
109538
109538
|
const apiKeyHasWildcard = matchingAPIKeysDetails.roles.includes("*");
|
|
@@ -109551,7 +109551,7 @@ var TriggerHelper = class {
|
|
|
109551
109551
|
}).filter(Boolean);
|
|
109552
109552
|
const matchingRoles = normalizedRoles.some((x) => matchingAPIKeysDetails.roles.includes(x));
|
|
109553
109553
|
if (!matchingRoles) {
|
|
109554
|
-
return optionsEnchanced.
|
|
109554
|
+
return optionsEnchanced.terminate(401, `API does not allow the key due to the roles configuration`);
|
|
109555
109555
|
}
|
|
109556
109556
|
}
|
|
109557
109557
|
}
|
|
@@ -109562,7 +109562,7 @@ var TriggerHelper = class {
|
|
|
109562
109562
|
} catch (error) {
|
|
109563
109563
|
options.logging.error("Action execution failed:", error, error.stack);
|
|
109564
109564
|
if (!executionFinished) {
|
|
109565
|
-
optionsEnchanced.
|
|
109565
|
+
optionsEnchanced.terminate(500, `Action execution failed: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
109566
109566
|
}
|
|
109567
109567
|
return;
|
|
109568
109568
|
}
|
|
@@ -109572,7 +109572,7 @@ var TriggerHelper = class {
|
|
|
109572
109572
|
return result;
|
|
109573
109573
|
}
|
|
109574
109574
|
if (!atLeastOneHandlerMatched && !executionFinished) {
|
|
109575
|
-
optionsEnchanced.
|
|
109575
|
+
optionsEnchanced.terminate(404, "No matching handler found");
|
|
109576
109576
|
}
|
|
109577
109577
|
};
|
|
109578
109578
|
fn.$TriggerHelper = this;
|