From 41a3cae1b2892b672672a8f99d4965e1794fce12 Mon Sep 17 00:00:00 2001 From: Superblocks Admin Date: Wed, 30 Oct 2024 16:20:39 +0000 Subject: [PATCH] syncing up to 1cfe8fc3169b9728b7e0150e0edaecc390f65317 Co-authored-by: Joey Greco <57115019+joeyagreco@users.noreply.github.com> --- CHANGELOG.md | 1 + postman/collection.json | 69 ++++++++++++++++++- .../packages/plugins/email/src/index.ts | 5 +- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0c72f40..3069b21b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Include signing algorithms with verification keys when registering agent - Include signing algorithm and public key in response from Sign endpoint (`/v1/signature/sign`) - Set errors on responses for all resources that fail to get re-signed during a signature rotation job +- Improved error messages in Email Plugin ## v1.15.1 diff --git a/postman/collection.json b/postman/collection.json index 22266fe1..0b782e13 100644 --- a/postman/collection.json +++ b/postman/collection.json @@ -1,9 +1,9 @@ { "info": { - "_postman_id": "ff2052f4-9acc-4efe-8b1c-e8616d464336", + "_postman_id": "5435b4bc-a466-4819-a943-1c14adbfdb6c", "name": "collection.json - [HTTP] Superblocks Orchestrator", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "28659047" + "_exporter_id": "25579613" }, "item": [ { @@ -13325,6 +13325,71 @@ ] } ] + }, + { + "name": "email", + "item": [ + { + "name": "execute", + "item": [ + { + "name": "no api key", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "const response = pm.response.json();", + "", + "pm.test(\"assert response body\", () => {", + " pm.expect(response.execution.length).to.gt(0);", + " pm.expect(response.status).to.be.eql(\"STATUS_COMPLETED\");", + " pm.expect(response.errors).to.eql([{", + " \"name\": \"IntegrationError\",", + " \"message\": \"Payment required. Email isn't available for your organization's plan. Upgrade your account or [contact sales](mailto://billing-requests@superblockshq.com) to use this feature.\",", + " \"blockPath\": \"put\"", + " }])", + "});", + "", + "pm.test(\"assert status\", () => {", + " pm.response.to.have.status(200);", + "});" + ], + "type": "text/javascript", + "packages": {} + } + } + ], + "request": { + "method": "POST", + "header": [], + "body": { + "mode": "raw", + "raw": "{\n \"options\": {\n \"include_events\": false\n },\n \"definition\": {\n \"api\": {\n \"metadata\": {\n \"name\": \"s3 integration test\",\n \"organization\": \"00000000-0000-0000-0000-000000000001\"\n },\n \"blocks\": [\n {\n \"name\": \"put\",\n \"step\": {\n \"integration\": \"email-i\",\n \"email\": {\n \"emailTo\": \"foo@gmail.com\",\n \"emailSubject\": \"bar\"\n }\n }\n }\n ]\n },\n \"integrations\": {\n \"email-i\": {\n \"authentication\": {\n \"custom\": {\n \"apiKey\": {\n \"value\": \"\"\n },\n \"senderEmail\": {\n \"value\": \"foo\"\n },\n \"senderName\": {\n \"value\": \"bar\"\n }\n }\n }\n }\n }\n }\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{orchestrator_scheme}}://{{orchestrator_host}}:{{orchestrator_port}}/v2/execute", + "protocol": "{{orchestrator_scheme}}", + "host": [ + "{{orchestrator_host}}" + ], + "port": "{{orchestrator_port}}", + "path": [ + "v2", + "execute" + ] + } + }, + "response": [] + } + ] + } + ] } ] }, diff --git a/workers/javascript/packages/plugins/email/src/index.ts b/workers/javascript/packages/plugins/email/src/index.ts index 5ffd9bb0..9c5ffb16 100644 --- a/workers/javascript/packages/plugins/email/src/index.ts +++ b/workers/javascript/packages/plugins/email/src/index.ts @@ -65,8 +65,11 @@ export default class EmailPlugin extends BasePlugin { createClient(datasourceConfiguration: EmailDatasourceConfiguration): MailService { const key = datasourceConfiguration.authentication?.custom?.apiKey?.value ?? ''; + // NOTE: (joey) the api key will be empty when an organization is not allowed to use this plugin if (isEmpty(key)) { - throw new IntegrationError(`No API key found`, ErrorCode.INTEGRATION_MISSING_REQUIRED_FIELD, { pluginName: this.pluginName }); + const errorMsg = + "Payment required. Email isn't available for your organization's plan. Upgrade your account or [contact sales](mailto://billing-requests@superblockshq.com) to use this feature."; + throw new IntegrationError(errorMsg, ErrorCode.INTEGRATION_MISSING_REQUIRED_FIELD, { pluginName: this.pluginName }); } sgMail.setApiKey(key);