@justworkflowit/cdk-constructs 0.0.13 → 0.0.15

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