@justworkflowit/cdk-constructs 0.0.13 → 0.0.14
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/constructs/justWorkflowItConstructs.d.ts +8 -0
- package/dist/constructs/justWorkflowItConstructs.js +98 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/lambda/definitionDeployerLambda.d.ts +7 -0
- package/dist/lambda/definitionDeployerLambda.js +16387 -0
- package/dist/lambda/justWorkflowItApiClient.d.ts +4 -0
- package/{src/lambda/justWorkflowItApiClient.ts → dist/lambda/justWorkflowItApiClient.js} +36 -49
- package/dist/lambda/justWorkflowItApiExceptions.d.ts +3 -0
- package/dist/lambda/justWorkflowItApiExceptions.js +70 -0
- package/package.json +4 -5
- package/src/lambda/definitionDeployerLambda.ts +0 -20
- package/src/lambda/justWorkflowItApiExceptions.ts +0 -41
|
@@ -1,78 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getApiClient = exports.getErrorMessage = void 0;
|
|
1
4
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { deserializeSmithyError } from './justWorkflowItApiExceptions';
|
|
5
|
-
|
|
5
|
+
const api_client_1 = require("@justworkflowit/api-client");
|
|
6
|
+
const justWorkflowItApiExceptions_1 = require("./justWorkflowItApiExceptions");
|
|
6
7
|
const endpoint = process.env.API_BASE_URL;
|
|
7
|
-
|
|
8
|
-
type ProviderFactory = (
|
|
9
|
-
config: IdentityProviderConfig
|
|
10
|
-
) => IdentityProvider<Identity> | undefined;
|
|
11
|
-
|
|
12
|
-
|
|
13
8
|
const getAccessToken = async () => {
|
|
14
9
|
return process.env.AUTH_SECRET_NAME;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const identityProvider: IdentityProvider<Identity> = async (_props) => {
|
|
10
|
+
};
|
|
11
|
+
const cognitoIdentityProviderFactory = (_config) => {
|
|
12
|
+
const identityProvider = async (_props) => {
|
|
19
13
|
const token = await getAccessToken();
|
|
20
14
|
return {
|
|
21
15
|
id: 'cognito-user',
|
|
22
16
|
token,
|
|
23
|
-
}
|
|
17
|
+
};
|
|
24
18
|
};
|
|
25
|
-
|
|
26
19
|
return identityProvider;
|
|
27
20
|
};
|
|
28
|
-
|
|
29
21
|
const cognitoBearerSigner = {
|
|
30
|
-
sign: async (request
|
|
22
|
+
sign: async (request) => {
|
|
31
23
|
const token = await getAccessToken();
|
|
32
24
|
request.headers['Authorization'] = `Bearer ${token}`;
|
|
33
25
|
return request;
|
|
34
26
|
},
|
|
35
27
|
};
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
const identityProvider: IdentityProvider<Identity> = (_props) => {
|
|
28
|
+
const noAuthIdentityProviderFactory = (_config) => {
|
|
29
|
+
const identityProvider = (_props) => {
|
|
39
30
|
return Promise.resolve({
|
|
40
31
|
id: 'anonymous',
|
|
41
|
-
}
|
|
32
|
+
});
|
|
42
33
|
};
|
|
43
|
-
|
|
44
34
|
return identityProvider;
|
|
45
35
|
};
|
|
46
|
-
|
|
47
36
|
const noAuthSigner = {
|
|
48
|
-
sign: (request
|
|
37
|
+
sign: (request) => {
|
|
49
38
|
return Promise.resolve(request);
|
|
50
39
|
},
|
|
51
40
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const e = err as any;
|
|
55
|
-
|
|
41
|
+
const getErrorMessage = (err) => {
|
|
42
|
+
const e = err;
|
|
56
43
|
const errorType = e?.errorType;
|
|
57
44
|
const message = e?.message;
|
|
58
45
|
const httpStatus = e?.$metadata?.httpStatusCode;
|
|
59
|
-
|
|
60
46
|
if (errorType === 'ValidationError' && e.fields) {
|
|
61
47
|
const fieldErrors = Object.entries(e.fields)
|
|
62
48
|
.map(([field, msg]) => `${field}: ${msg}`)
|
|
63
49
|
.join(', ');
|
|
64
50
|
return `Validation Error: ${fieldErrors}`;
|
|
65
51
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (message)
|
|
69
|
-
|
|
70
|
-
|
|
52
|
+
if (errorType && message)
|
|
53
|
+
return `${errorType}: ${message}`;
|
|
54
|
+
if (message)
|
|
55
|
+
return message;
|
|
56
|
+
if (httpStatus)
|
|
57
|
+
return `Unexpected error (${httpStatus})`;
|
|
71
58
|
return 'Unexpected error';
|
|
72
59
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
const client = new JustWorkflowIt({
|
|
60
|
+
exports.getErrorMessage = getErrorMessage;
|
|
61
|
+
const getApiClient = () => {
|
|
62
|
+
const client = new api_client_1.JustWorkflowIt({
|
|
76
63
|
endpoint,
|
|
77
64
|
httpAuthSchemes: [
|
|
78
65
|
{
|
|
@@ -87,22 +74,22 @@ export const getApiClient = (): AssertiveClient<JustWorkflowIt> => {
|
|
|
87
74
|
},
|
|
88
75
|
],
|
|
89
76
|
});
|
|
90
|
-
|
|
91
77
|
const proxy = new Proxy(client, {
|
|
92
|
-
get(target, prop
|
|
78
|
+
get(target, prop) {
|
|
93
79
|
const orig = target[prop];
|
|
94
|
-
if (typeof orig !== 'function')
|
|
95
|
-
|
|
96
|
-
return async (...args
|
|
80
|
+
if (typeof orig !== 'function')
|
|
81
|
+
return orig;
|
|
82
|
+
return async (...args) => {
|
|
97
83
|
try {
|
|
98
|
-
return await
|
|
99
|
-
}
|
|
100
|
-
|
|
84
|
+
return await orig.apply(target, args);
|
|
85
|
+
}
|
|
86
|
+
catch (err) {
|
|
87
|
+
const rehydrated = await (0, justWorkflowItApiExceptions_1.deserializeSmithyError)(err);
|
|
101
88
|
throw rehydrated;
|
|
102
89
|
}
|
|
103
90
|
};
|
|
104
91
|
},
|
|
105
92
|
});
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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/package.json
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justworkflowit/cdk-constructs",
|
|
3
3
|
"description": "",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"main": "dist/
|
|
6
|
-
"types": "dist/
|
|
4
|
+
"version": "0.0.14",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"publishConfig": {
|
|
8
8
|
"access": "public"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
11
|
+
"build": "tsc && node esbuild-lambdas.js",
|
|
12
12
|
"lint": "eslint . --ext .ts",
|
|
13
13
|
"lint:fix": "eslint --fix . --ext .ts"
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
"src/lambda",
|
|
18
17
|
"README.md"
|
|
19
18
|
],
|
|
20
19
|
"keywords": [],
|
|
@@ -1,20 +0,0 @@
|
|
|
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,41 +0,0 @@
|
|
|
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
|
-
}
|