@justworkflowit/cdk-constructs 0.0.11 → 0.0.12
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/README.md +2 -2
- package/dist/lib/justWorkflowItConstructs.d.ts +8 -0
- package/dist/lib/justWorkflowItConstructs.js +98 -0
- package/dist/lib/lambda/definitionDeployerLambda.d.ts +7 -0
- package/dist/lib/lambda/definitionDeployerLambda.js +18 -0
- package/dist/lib/lambda/justWorkflowItApiClient.d.ts +4 -0
- package/dist/lib/lambda/justWorkflowItApiClient.js +95 -0
- package/dist/lib/lambda/justWorkflowItApiExceptions.d.ts +3 -0
- package/dist/lib/lambda/justWorkflowItApiExceptions.js +70 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +1 -1
- package/package.json +5 -6
package/README.md
CHANGED
|
@@ -21,9 +21,9 @@ npm install @justworkflowit/cdk-constructs
|
|
|
21
21
|
### 2. Add the construct to your CDK stack
|
|
22
22
|
|
|
23
23
|
```ts
|
|
24
|
-
import {
|
|
24
|
+
import { JustWorkflowItConstructs } from "@justworkflowit/cdk-constructs";
|
|
25
25
|
|
|
26
|
-
new
|
|
26
|
+
new JustWorkflowItConstructs(this, { disambiguator: "Prod" });
|
|
27
27
|
```
|
|
28
28
|
|
|
29
29
|
---
|
|
@@ -0,0 +1,8 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
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";
|
|
@@ -0,0 +1,18 @@
|
|
|
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;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getApiClient = exports.getErrorMessage = void 0;
|
|
4
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
|
+
const api_client_1 = require("@justworkflowit/api-client");
|
|
6
|
+
const justWorkflowItApiExceptions_1 = require("./justWorkflowItApiExceptions");
|
|
7
|
+
const endpoint = process.env.API_BASE_URL;
|
|
8
|
+
const getAccessToken = async () => {
|
|
9
|
+
return process.env.AUTH_SECRET_NAME;
|
|
10
|
+
};
|
|
11
|
+
const cognitoIdentityProviderFactory = (_config) => {
|
|
12
|
+
const identityProvider = async (_props) => {
|
|
13
|
+
const token = await getAccessToken();
|
|
14
|
+
return {
|
|
15
|
+
id: 'cognito-user',
|
|
16
|
+
token,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
return identityProvider;
|
|
20
|
+
};
|
|
21
|
+
const cognitoBearerSigner = {
|
|
22
|
+
sign: async (request) => {
|
|
23
|
+
const token = await getAccessToken();
|
|
24
|
+
request.headers['Authorization'] = `Bearer ${token}`;
|
|
25
|
+
return request;
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
const noAuthIdentityProviderFactory = (_config) => {
|
|
29
|
+
const identityProvider = (_props) => {
|
|
30
|
+
return Promise.resolve({
|
|
31
|
+
id: 'anonymous',
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
return identityProvider;
|
|
35
|
+
};
|
|
36
|
+
const noAuthSigner = {
|
|
37
|
+
sign: (request) => {
|
|
38
|
+
return Promise.resolve(request);
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const getErrorMessage = (err) => {
|
|
42
|
+
const e = err;
|
|
43
|
+
const errorType = e?.errorType;
|
|
44
|
+
const message = e?.message;
|
|
45
|
+
const httpStatus = e?.$metadata?.httpStatusCode;
|
|
46
|
+
if (errorType === 'ValidationError' && e.fields) {
|
|
47
|
+
const fieldErrors = Object.entries(e.fields)
|
|
48
|
+
.map(([field, msg]) => `${field}: ${msg}`)
|
|
49
|
+
.join(', ');
|
|
50
|
+
return `Validation Error: ${fieldErrors}`;
|
|
51
|
+
}
|
|
52
|
+
if (errorType && message)
|
|
53
|
+
return `${errorType}: ${message}`;
|
|
54
|
+
if (message)
|
|
55
|
+
return message;
|
|
56
|
+
if (httpStatus)
|
|
57
|
+
return `Unexpected error (${httpStatus})`;
|
|
58
|
+
return 'Unexpected error';
|
|
59
|
+
};
|
|
60
|
+
exports.getErrorMessage = getErrorMessage;
|
|
61
|
+
const getApiClient = () => {
|
|
62
|
+
const client = new api_client_1.JustWorkflowIt({
|
|
63
|
+
endpoint,
|
|
64
|
+
httpAuthSchemes: [
|
|
65
|
+
{
|
|
66
|
+
schemeId: 'aws.auth#cognitoUserPools',
|
|
67
|
+
identityProvider: cognitoIdentityProviderFactory,
|
|
68
|
+
signer: cognitoBearerSigner,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
schemeId: 'smithy.api#noAuth',
|
|
72
|
+
identityProvider: noAuthIdentityProviderFactory,
|
|
73
|
+
signer: noAuthSigner,
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
});
|
|
77
|
+
const proxy = new Proxy(client, {
|
|
78
|
+
get(target, prop) {
|
|
79
|
+
const orig = target[prop];
|
|
80
|
+
if (typeof orig !== 'function')
|
|
81
|
+
return orig;
|
|
82
|
+
return async (...args) => {
|
|
83
|
+
try {
|
|
84
|
+
return await orig.apply(target, args);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const rehydrated = await (0, justWorkflowItApiExceptions_1.deserializeSmithyError)(err);
|
|
88
|
+
throw rehydrated;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
return proxy;
|
|
94
|
+
};
|
|
95
|
+
exports.getApiClient = getApiClient;
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from '../lib/
|
|
1
|
+
export * from '../lib/justWorkflowItConstructs';
|
package/dist/src/index.js
CHANGED
|
@@ -14,4 +14,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("../lib/
|
|
17
|
+
__exportStar(require("../lib/justWorkflowItConstructs"), exports);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justworkflowit/cdk-constructs",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
@@ -9,7 +9,6 @@
|
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build": "tsc",
|
|
12
|
-
"prepare": "npm run build",
|
|
13
12
|
"lint": "eslint . --ext .ts",
|
|
14
13
|
"lint:fix": "eslint --fix . --ext .ts"
|
|
15
14
|
},
|
|
@@ -22,8 +21,9 @@
|
|
|
22
21
|
"license": "MIT",
|
|
23
22
|
"type": "commonjs",
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
24
|
+
"@justworkflowit/api-client": "*",
|
|
25
|
+
"aws-cdk-lib": "^2.0.0",
|
|
26
|
+
"constructs": "^10.0.0"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"cdk-cli": "^1.1.0",
|
|
@@ -43,6 +43,5 @@
|
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"aws-cdk-lib": "^2.0.0",
|
|
45
45
|
"constructs": "^10.0.0"
|
|
46
|
-
}
|
|
47
|
-
"gitHead": "9b9ce5a7b0045085dac785b25ca151ae0658ae94"
|
|
46
|
+
}
|
|
48
47
|
}
|