@justworkflowit/cdk-constructs 0.0.12 → 0.0.13

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,7 +1,7 @@
1
1
  {
2
2
  "name": "@justworkflowit/cdk-constructs",
3
3
  "description": "",
4
- "version": "0.0.12",
4
+ "version": "0.0.13",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "publishConfig": {
@@ -14,6 +14,7 @@
14
14
  },
15
15
  "files": [
16
16
  "dist",
17
+ "src/lambda",
17
18
  "README.md"
18
19
  ],
19
20
  "keywords": [],
@@ -0,0 +1,20 @@
1
+ import { CloudFormationCustomResourceEvent } from 'aws-lambda';
2
+ import { getApiClient } from './justWorkflowItApiClient';
3
+
4
+
5
+ export const handler = async (event: CloudFormationCustomResourceEvent) => {
6
+ console.log("Custom Resource Event:", JSON.stringify(event, null, 2));
7
+
8
+ const { RequestType } = event;
9
+
10
+ if (RequestType === 'Create') {
11
+ getApiClient();
12
+ }
13
+
14
+ return {
15
+ PhysicalResourceId: 'JustWorkflowItIntegrationTrigger',
16
+ Data: {
17
+ Message: `Ran ${RequestType} successfully`,
18
+ },
19
+ };
20
+ };
@@ -1,65 +1,78 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getApiClient = exports.getErrorMessage = void 0;
4
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
5
- const api_client_1 = require("@justworkflowit/api-client");
6
- const justWorkflowItApiExceptions_1 = require("./justWorkflowItApiExceptions");
2
+ import { JustWorkflowIt } from '@justworkflowit/api-client';
3
+ import { AssertiveClient, HttpRequest, Identity, IdentityProvider, IdentityProviderConfig } from '@smithy/types';
4
+ import { deserializeSmithyError } from './justWorkflowItApiExceptions';
5
+
7
6
  const endpoint = process.env.API_BASE_URL;
7
+
8
+ type ProviderFactory = (
9
+ config: IdentityProviderConfig
10
+ ) => IdentityProvider<Identity> | undefined;
11
+
12
+
8
13
  const getAccessToken = async () => {
9
14
  return process.env.AUTH_SECRET_NAME;
10
- };
11
- const cognitoIdentityProviderFactory = (_config) => {
12
- const identityProvider = async (_props) => {
15
+ }
16
+
17
+ const cognitoIdentityProviderFactory: ProviderFactory = (_config) => {
18
+ const identityProvider: IdentityProvider<Identity> = async (_props) => {
13
19
  const token = await getAccessToken();
14
20
  return {
15
21
  id: 'cognito-user',
16
22
  token,
17
- };
23
+ } as Identity;
18
24
  };
25
+
19
26
  return identityProvider;
20
27
  };
28
+
21
29
  const cognitoBearerSigner = {
22
- sign: async (request) => {
30
+ sign: async (request: HttpRequest) => {
23
31
  const token = await getAccessToken();
24
32
  request.headers['Authorization'] = `Bearer ${token}`;
25
33
  return request;
26
34
  },
27
35
  };
28
- const noAuthIdentityProviderFactory = (_config) => {
29
- const identityProvider = (_props) => {
36
+
37
+ const noAuthIdentityProviderFactory: ProviderFactory = (_config) => {
38
+ const identityProvider: IdentityProvider<Identity> = (_props) => {
30
39
  return Promise.resolve({
31
40
  id: 'anonymous',
32
- });
41
+ } as Identity);
33
42
  };
43
+
34
44
  return identityProvider;
35
45
  };
46
+
36
47
  const noAuthSigner = {
37
- sign: (request) => {
48
+ sign: (request: HttpRequest) => {
38
49
  return Promise.resolve(request);
39
50
  },
40
51
  };
41
- const getErrorMessage = (err) => {
42
- const e = err;
52
+
53
+ export const getErrorMessage = (err: unknown): string => {
54
+ const e = err as any;
55
+
43
56
  const errorType = e?.errorType;
44
57
  const message = e?.message;
45
58
  const httpStatus = e?.$metadata?.httpStatusCode;
59
+
46
60
  if (errorType === 'ValidationError' && e.fields) {
47
61
  const fieldErrors = Object.entries(e.fields)
48
62
  .map(([field, msg]) => `${field}: ${msg}`)
49
63
  .join(', ');
50
64
  return `Validation Error: ${fieldErrors}`;
51
65
  }
52
- if (errorType && message)
53
- return `${errorType}: ${message}`;
54
- if (message)
55
- return message;
56
- if (httpStatus)
57
- return `Unexpected error (${httpStatus})`;
66
+
67
+ if (errorType && message) return `${errorType}: ${message}`;
68
+ if (message) return message;
69
+ if (httpStatus) return `Unexpected error (${httpStatus})`;
70
+
58
71
  return 'Unexpected error';
59
72
  };
60
- exports.getErrorMessage = getErrorMessage;
61
- const getApiClient = () => {
62
- const client = new api_client_1.JustWorkflowIt({
73
+
74
+ export const getApiClient = (): AssertiveClient<JustWorkflowIt> => {
75
+ const client = new JustWorkflowIt({
63
76
  endpoint,
64
77
  httpAuthSchemes: [
65
78
  {
@@ -74,22 +87,22 @@ const getApiClient = () => {
74
87
  },
75
88
  ],
76
89
  });
90
+
77
91
  const proxy = new Proxy(client, {
78
- get(target, prop) {
92
+ get(target, prop: keyof JustWorkflowIt) {
79
93
  const orig = target[prop];
80
- if (typeof orig !== 'function')
81
- return orig;
82
- return async (...args) => {
94
+ if (typeof orig !== 'function') return orig;
95
+
96
+ return async (...args: any[]) => {
83
97
  try {
84
- return await orig.apply(target, args);
85
- }
86
- catch (err) {
87
- const rehydrated = await (0, justWorkflowItApiExceptions_1.deserializeSmithyError)(err);
98
+ return await (orig as any).apply(target, args);
99
+ } catch (err) {
100
+ const rehydrated = await deserializeSmithyError(err);
88
101
  throw rehydrated;
89
102
  }
90
103
  };
91
104
  },
92
105
  });
93
- return proxy;
94
- };
95
- exports.getApiClient = getApiClient;
106
+
107
+ return proxy as AssertiveClient<JustWorkflowIt>;
108
+ };
@@ -0,0 +1,41 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
3
+ export type SmithyErrorClass = new (args: any) => Error;
4
+
5
+ export async function buildSmithyErrorRegistry(): Promise<Record<string, SmithyErrorClass>> {
6
+ const module = await import('@justworkflowit/api-client');
7
+ console.log(module);
8
+ return Object.entries(module)
9
+ .filter(([key, val]) => {
10
+ return (
11
+ typeof val === 'function' &&
12
+ key.endsWith('Error') // &&
13
+ // typeof (val as any).prototype?.errorType === 'string' &&
14
+ // typeof (val as any).prototype?.constructor === 'function'
15
+ );
16
+ })
17
+ .reduce((acc, [name, ctor]) => {
18
+ acc[name] = ctor as SmithyErrorClass;
19
+ return acc;
20
+ }, {} as Record<string, SmithyErrorClass>);
21
+ }
22
+
23
+ export async function deserializeSmithyError(err: any): Promise<Error> {
24
+ if (!err || typeof err !== 'object') return new Error('Unknown error');
25
+
26
+ const registry = await buildSmithyErrorRegistry();
27
+ const typeName = err?.errorType;
28
+
29
+ if (typeName && registry[typeName]) {
30
+ const ErrorClass = registry[typeName];
31
+ const { message, errorType, statusCode, ...rest } = err;
32
+ return new ErrorClass({
33
+ message: typeof message === 'string' ? message : 'Unknown error',
34
+ errorType,
35
+ statusCode,
36
+ ...rest,
37
+ });
38
+ }
39
+
40
+ return new Error(err?.message || 'Unknown error');
41
+ }
@@ -1,8 +0,0 @@
1
- import { Construct } from 'constructs';
2
- export interface JustWorkflowItConstructProps {
3
- disambiguator: string;
4
- }
5
- export declare class JustWorkflowItConstruct extends Construct {
6
- private static readonly CONSTRUCT_ID_PREFIX;
7
- constructor(scope: Construct, props: JustWorkflowItConstructProps);
8
- }
@@ -1,80 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.JustWorkflowItConstruct = void 0;
4
- const aws_cdk_lib_1 = require("aws-cdk-lib");
5
- const constructs_1 = require("constructs");
6
- const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
7
- const aws_iam_1 = require("aws-cdk-lib/aws-iam");
8
- const aws_secretsmanager_1 = require("aws-cdk-lib/aws-secretsmanager");
9
- const custom_resources_1 = require("aws-cdk-lib/custom-resources");
10
- class JustWorkflowItConstruct extends constructs_1.Construct {
11
- constructor(scope, props) {
12
- super(scope, `${JustWorkflowItConstruct.CONSTRUCT_ID_PREFIX}${props.disambiguator}`);
13
- const secretName = '/justworkflowit/api/authToken';
14
- const secret = new aws_secretsmanager_1.Secret(this, 'JustWorkflowItAuthTokenSecret', {
15
- secretName,
16
- secretStringValue: aws_cdk_lib_1.SecretValue.unsafePlainText('REPLACE_ME_WITH_JUST_WORKFLOW_IT_AUTH_TOKEN'),
17
- description: 'Paste your JustWorkflowIt API auth token here to enable secure communication.',
18
- });
19
- const integrationLambda = new aws_lambda_1.Function(this, 'JustWorkflowItAutomationIntegrationLambda', {
20
- functionName: 'JustWorkflowItAutomationIntegrationLambda',
21
- runtime: aws_lambda_1.Runtime.NODEJS_18_X,
22
- handler: 'index.handler',
23
- code: aws_lambda_1.Code.fromInline(`
24
- exports.handler = async (event) => {
25
- console.log("Custom Resource event:", JSON.stringify(event, null, 2));
26
-
27
- const requestType = event.RequestType;
28
- if (requestType === 'Create') {
29
- console.log("Handling CREATE...");
30
- } else if (requestType === 'Update') {
31
- console.log("Handling UPDATE...");
32
- } else if (requestType === 'Delete') {
33
- console.log("Handling DELETE...");
34
- }
35
-
36
- return {
37
- PhysicalResourceId: 'JustWorkflowItIntegrationTrigger',
38
- Data: {
39
- Message: "Integration Lambda ran successfully"
40
- }
41
- };
42
- };
43
- `),
44
- timeout: aws_cdk_lib_1.Duration.seconds(10),
45
- environment: {
46
- AUTH_SECRET_NAME: secretName,
47
- API_BASE_URL: 'https://api.justworkflowit.com',
48
- },
49
- });
50
- secret.grantRead(integrationLambda);
51
- const provider = new custom_resources_1.Provider(this, 'JustWorkflowItAutomationLambdaTriggerProvider', {
52
- onEventHandler: integrationLambda,
53
- });
54
- new aws_cdk_lib_1.CustomResource(this, 'JustWorkflowItAutomationLambdaTrigger', {
55
- serviceToken: provider.serviceToken,
56
- properties: {
57
- timestamp: new Date().toISOString()
58
- }
59
- });
60
- const executionRole = new aws_iam_1.Role(this, 'JustWorkflowItAutomationExecutionRole', {
61
- roleName: 'JustWorkflowItAutomationExecutionRole',
62
- assumedBy: new aws_iam_1.AccountPrincipal('588738588052'),
63
- description: 'Role assumed by JustWorkflowIt backend to perform actions inside this account.',
64
- });
65
- executionRole.addToPolicy(new aws_iam_1.PolicyStatement({
66
- actions: ['lambda:InvokeFunction'],
67
- resources: ['*'],
68
- }));
69
- executionRole.addToPolicy(new aws_iam_1.PolicyStatement({
70
- actions: ['sns:Publish'],
71
- resources: ['*'],
72
- }));
73
- executionRole.addToPolicy(new aws_iam_1.PolicyStatement({
74
- actions: ['sqs:SendMessage'],
75
- resources: ['*'],
76
- }));
77
- }
78
- }
79
- exports.JustWorkflowItConstruct = JustWorkflowItConstruct;
80
- JustWorkflowItConstruct.CONSTRUCT_ID_PREFIX = "JustWorkflowItConstruct";
@@ -1,8 +0,0 @@
1
- import { Construct } from 'constructs';
2
- export interface JustWorkflowItConstructsProps {
3
- disambiguator: string;
4
- }
5
- export declare class JustWorkflowItConstructs extends Construct {
6
- private static readonly CONSTRUCT_ID_PREFIX;
7
- constructor(scope: Construct, props: JustWorkflowItConstructsProps);
8
- }
@@ -1,98 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.JustWorkflowItConstructs = void 0;
37
- const aws_cdk_lib_1 = require("aws-cdk-lib");
38
- const constructs_1 = require("constructs");
39
- const aws_lambda_1 = require("aws-cdk-lib/aws-lambda");
40
- const aws_iam_1 = require("aws-cdk-lib/aws-iam");
41
- const aws_secretsmanager_1 = require("aws-cdk-lib/aws-secretsmanager");
42
- const custom_resources_1 = require("aws-cdk-lib/custom-resources");
43
- const aws_lambda_nodejs_1 = require("aws-cdk-lib/aws-lambda-nodejs");
44
- const path = __importStar(require("path"));
45
- class JustWorkflowItConstructs extends constructs_1.Construct {
46
- constructor(scope, props) {
47
- super(scope, `${JustWorkflowItConstructs.CONSTRUCT_ID_PREFIX}${props.disambiguator}`);
48
- const secretName = '/justworkflowit/api/authToken';
49
- const secret = new aws_secretsmanager_1.Secret(this, 'JustWorkflowItAuthTokenSecret', {
50
- secretName,
51
- secretStringValue: aws_cdk_lib_1.SecretValue.unsafePlainText('REPLACE_ME_WITH_JUST_WORKFLOW_IT_AUTH_TOKEN'),
52
- description: 'Paste your JustWorkflowIt API auth token here to enable secure communication.',
53
- });
54
- const integrationLambda = new aws_lambda_nodejs_1.NodejsFunction(this, 'JustWorkflowItDefinitionDeployerLambda', {
55
- functionName: 'JustWorkflowItDefinitionDeployerLambda',
56
- entry: path.join(__dirname, '../lambda/definitionDeployerLambda.ts'),
57
- handler: 'handler',
58
- runtime: aws_lambda_1.Runtime.NODEJS_18_X,
59
- timeout: aws_cdk_lib_1.Duration.minutes(5),
60
- environment: {
61
- AUTH_SECRET_NAME: secretName,
62
- API_BASE_URL: 'https://api.justworkflowit.com',
63
- },
64
- bundling: {
65
- nodeModules: ['@justworkflowit/api-client'],
66
- },
67
- });
68
- secret.grantRead(integrationLambda);
69
- const provider = new custom_resources_1.Provider(this, 'JustWorkflowItDefinitionDeployerTriggerProvider', {
70
- onEventHandler: integrationLambda,
71
- });
72
- new aws_cdk_lib_1.CustomResource(this, 'JustWorkflowItDefinitionDeployerTrigger', {
73
- serviceToken: provider.serviceToken,
74
- properties: {
75
- timestamp: new Date().toISOString()
76
- }
77
- });
78
- const executionRole = new aws_iam_1.Role(this, 'JustWorkflowItAutomationExecutionRole', {
79
- roleName: 'JustWorkflowItAutomationExecutionRole',
80
- assumedBy: new aws_iam_1.AccountPrincipal('588738588052'),
81
- description: 'Role assumed by JustWorkflowIt backend to perform actions inside this account.',
82
- });
83
- executionRole.addToPolicy(new aws_iam_1.PolicyStatement({
84
- actions: ['lambda:InvokeFunction'],
85
- resources: ['*'],
86
- }));
87
- executionRole.addToPolicy(new aws_iam_1.PolicyStatement({
88
- actions: ['sns:Publish'],
89
- resources: ['*'],
90
- }));
91
- executionRole.addToPolicy(new aws_iam_1.PolicyStatement({
92
- actions: ['sqs:SendMessage'],
93
- resources: ['*'],
94
- }));
95
- }
96
- }
97
- exports.JustWorkflowItConstructs = JustWorkflowItConstructs;
98
- JustWorkflowItConstructs.CONSTRUCT_ID_PREFIX = "JustWorkflowItConstructs";
@@ -1,7 +0,0 @@
1
- import { CloudFormationCustomResourceEvent } from 'aws-lambda';
2
- export declare const handler: (event: CloudFormationCustomResourceEvent) => Promise<{
3
- PhysicalResourceId: string;
4
- Data: {
5
- Message: string;
6
- };
7
- }>;
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handler = void 0;
4
- const justWorkflowItApiClient_1 = require("./justWorkflowItApiClient");
5
- const handler = async (event) => {
6
- console.log("Custom Resource Event:", JSON.stringify(event, null, 2));
7
- const { RequestType } = event;
8
- if (RequestType === 'Create') {
9
- (0, justWorkflowItApiClient_1.getApiClient)();
10
- }
11
- return {
12
- PhysicalResourceId: 'JustWorkflowItIntegrationTrigger',
13
- Data: {
14
- Message: `Ran ${RequestType} successfully`,
15
- },
16
- };
17
- };
18
- exports.handler = handler;
@@ -1,4 +0,0 @@
1
- import { JustWorkflowIt } from '@justworkflowit/api-client';
2
- import { AssertiveClient } from '@smithy/types';
3
- export declare const getErrorMessage: (err: unknown) => string;
4
- export declare const getApiClient: () => AssertiveClient<JustWorkflowIt>;
@@ -1,3 +0,0 @@
1
- export type SmithyErrorClass = new (args: any) => Error;
2
- export declare function buildSmithyErrorRegistry(): Promise<Record<string, SmithyErrorClass>>;
3
- export declare function deserializeSmithyError(err: any): Promise<Error>;
@@ -1,70 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.buildSmithyErrorRegistry = buildSmithyErrorRegistry;
37
- exports.deserializeSmithyError = deserializeSmithyError;
38
- async function buildSmithyErrorRegistry() {
39
- const module = await Promise.resolve().then(() => __importStar(require('@justworkflowit/api-client')));
40
- console.log(module);
41
- return Object.entries(module)
42
- .filter(([key, val]) => {
43
- return (typeof val === 'function' &&
44
- key.endsWith('Error') // &&
45
- // typeof (val as any).prototype?.errorType === 'string' &&
46
- // typeof (val as any).prototype?.constructor === 'function'
47
- );
48
- })
49
- .reduce((acc, [name, ctor]) => {
50
- acc[name] = ctor;
51
- return acc;
52
- }, {});
53
- }
54
- async function deserializeSmithyError(err) {
55
- if (!err || typeof err !== 'object')
56
- return new Error('Unknown error');
57
- const registry = await buildSmithyErrorRegistry();
58
- const typeName = err?.errorType;
59
- if (typeName && registry[typeName]) {
60
- const ErrorClass = registry[typeName];
61
- const { message, errorType, statusCode, ...rest } = err;
62
- return new ErrorClass({
63
- message: typeof message === 'string' ? message : 'Unknown error',
64
- errorType,
65
- statusCode,
66
- ...rest,
67
- });
68
- }
69
- return new Error(err?.message || 'Unknown error');
70
- }
@@ -1 +0,0 @@
1
- export * from '../lib/justWorkflowItConstructs';
package/dist/src/index.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("../lib/justWorkflowItConstructs"), exports);