ag-common 0.0.182 → 0.0.185
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/api/helpers/api.d.ts +10 -0
- package/dist/api/helpers/api.js +10 -0
- package/dist/api/helpers/openApiHelpers.d.ts +11 -3
- package/dist/api/helpers/openApiHelpers.js +28 -15
- package/dist/api/types/index.d.ts +6 -1
- package/dist/ui/components/LoginButton/index.d.ts +4 -1
- package/dist/ui/components/LoginButton/index.js +5 -4
- package/package.json +1 -1
|
@@ -9,6 +9,16 @@ export declare const returnCode: <T>(statusCode: number, body?: T | undefined, e
|
|
|
9
9
|
* @returns stripped record
|
|
10
10
|
*/
|
|
11
11
|
export declare const stripPKs: <T>(record: T, keepPk?: boolean) => T;
|
|
12
|
+
/**
|
|
13
|
+
* generate dynamo PKs.
|
|
14
|
+
* PK = all Ls joined with #
|
|
15
|
+
* PK1 = L1
|
|
16
|
+
* PK2 = L1#L2
|
|
17
|
+
* PK3 = L1#L2#L3
|
|
18
|
+
* ...
|
|
19
|
+
* @param param0
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
12
22
|
export declare const generateDynamoPKS: ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }: {
|
|
13
23
|
type: string;
|
|
14
24
|
L1: string;
|
package/dist/api/helpers/api.js
CHANGED
|
@@ -57,6 +57,16 @@ const stripPKs = (record, keepPk = true) => {
|
|
|
57
57
|
return rest;
|
|
58
58
|
};
|
|
59
59
|
exports.stripPKs = stripPKs;
|
|
60
|
+
/**
|
|
61
|
+
* generate dynamo PKs.
|
|
62
|
+
* PK = all Ls joined with #
|
|
63
|
+
* PK1 = L1
|
|
64
|
+
* PK2 = L1#L2
|
|
65
|
+
* PK3 = L1#L2#L3
|
|
66
|
+
* ...
|
|
67
|
+
* @param param0
|
|
68
|
+
* @returns
|
|
69
|
+
*/
|
|
60
70
|
const generateDynamoPKS = ({ type, L1, L2, L3, L4, L5, L6, additionalPKValues, }) => {
|
|
61
71
|
const c = '#';
|
|
62
72
|
const keys = [L1, L2, L3, L4, L5, L6].filter(array_1.notEmpty);
|
|
@@ -3,17 +3,19 @@ import { Construct } from 'constructs';
|
|
|
3
3
|
import { aws_certificatemanager as certmgr, aws_route53 as route53 } from 'aws-cdk-lib';
|
|
4
4
|
import { TokenAuthorizer } from 'aws-cdk-lib/aws-apigateway/lib/authorizers/lambda';
|
|
5
5
|
export declare const openApiImpl: (p: {
|
|
6
|
-
schema: unknown;
|
|
7
6
|
stack: Construct;
|
|
7
|
+
/**
|
|
8
|
+
* pass in generated openapi file
|
|
9
|
+
* eg schema: require('common/openapi.generated').default;
|
|
10
|
+
*/
|
|
11
|
+
schema: unknown;
|
|
8
12
|
NODE_ENV: string;
|
|
9
|
-
baseUrl: string;
|
|
10
13
|
endpointsBase: string;
|
|
11
14
|
/**
|
|
12
15
|
* 'default' will be applied to all functions
|
|
13
16
|
*/
|
|
14
17
|
lambdaConfig: ILambdaConfigs;
|
|
15
18
|
certificate: certmgr.ICertificate;
|
|
16
|
-
hostedZone: route53.IHostedZone;
|
|
17
19
|
shortStackName: string;
|
|
18
20
|
/**
|
|
19
21
|
* defaults:
|
|
@@ -28,4 +30,10 @@ export declare const openApiImpl: (p: {
|
|
|
28
30
|
* dictionary of named authorizer functions. these names are to be used in the lambdaConfig param
|
|
29
31
|
*/
|
|
30
32
|
authorizers?: Record<string, TokenAuthorizer>;
|
|
33
|
+
hostedZone: route53.IHostedZone;
|
|
34
|
+
/**
|
|
35
|
+
* A record will be created in hosted zone for the apigw on this path. if undefined, record wont be created
|
|
36
|
+
* eg api.mydomain.com
|
|
37
|
+
*/
|
|
38
|
+
apiUrl?: string;
|
|
31
39
|
}) => void;
|
|
@@ -11,26 +11,28 @@ const getPaths = (schema) => Object.entries(schema.paths).map(([fullPath, verbs]
|
|
|
11
11
|
pathList: fullPath.split('/').filter((s) => s),
|
|
12
12
|
verbs: Object.keys(verbs),
|
|
13
13
|
}));
|
|
14
|
-
const setUpApiGw = ({ stack, NODE_ENV,
|
|
14
|
+
const setUpApiGw = ({ stack, NODE_ENV, certificate, hostedZone, shortStackName, apiUrl, cors = {
|
|
15
15
|
allowOrigins: aws_cdk_lib_1.aws_apigateway.Cors.ALL_ORIGINS,
|
|
16
16
|
allowHeaders: aws_cdk_lib_1.aws_apigateway.Cors.DEFAULT_HEADERS,
|
|
17
17
|
}, }) => {
|
|
18
18
|
const api = new aws_cdk_lib_1.aws_apigateway.RestApi(stack, `${shortStackName}-api-${NODE_ENV}`, {
|
|
19
19
|
defaultCorsPreflightOptions: Object.assign({}, (cors || {})),
|
|
20
20
|
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
if (apiUrl) {
|
|
22
|
+
const dn = new aws_cdk_lib_1.aws_apigateway.DomainName(stack, 'domain', {
|
|
23
|
+
domainName: apiUrl,
|
|
24
|
+
certificate,
|
|
25
|
+
endpointType: aws_cdk_lib_1.aws_apigateway.EndpointType.EDGE,
|
|
26
|
+
securityPolicy: aws_cdk_lib_1.aws_apigateway.SecurityPolicy.TLS_1_2,
|
|
27
|
+
mapping: api,
|
|
28
|
+
});
|
|
29
|
+
new aws_cdk_lib_1.aws_route53.ARecord(stack, 'ARecord', {
|
|
30
|
+
comment: '(cdk)',
|
|
31
|
+
recordName: apiUrl.substring(0, apiUrl.indexOf('.')),
|
|
32
|
+
zone: hostedZone,
|
|
33
|
+
target: aws_cdk_lib_1.aws_route53.RecordTarget.fromAlias(new aws_cdk_lib_1.aws_route53_targets.ApiGatewayDomain(dn)),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
34
36
|
return api;
|
|
35
37
|
};
|
|
36
38
|
const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers, }) => {
|
|
@@ -53,6 +55,16 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers,
|
|
|
53
55
|
const policies = [...(def.policies || []), ...((lp === null || lp === void 0 ? void 0 : lp.policies) || [])].filter(array_1.notEmpty);
|
|
54
56
|
const layers = [...(def.layers || []), ...((lp === null || lp === void 0 ? void 0 : lp.layers) || [])].filter(array_1.notEmpty);
|
|
55
57
|
const memory = (lp === null || lp === void 0 ? void 0 : lp.memory) || (def === null || def === void 0 ? void 0 : def.memory) || 128;
|
|
58
|
+
// null forces undefined, undefined forces 5
|
|
59
|
+
let reservedConcurrentExecutions = lp === null || lp === void 0 ? void 0 : lp.reservedConcurrentExecutions;
|
|
60
|
+
if (reservedConcurrentExecutions === undefined) {
|
|
61
|
+
reservedConcurrentExecutions = def === null || def === void 0 ? void 0 : def.reservedConcurrentExecutions;
|
|
62
|
+
}
|
|
63
|
+
if (reservedConcurrentExecutions === undefined) {
|
|
64
|
+
reservedConcurrentExecutions = 5;
|
|
65
|
+
}
|
|
66
|
+
reservedConcurrentExecutions = reservedConcurrentExecutions !== null && reservedConcurrentExecutions !== void 0 ? reservedConcurrentExecutions : undefined;
|
|
67
|
+
//
|
|
56
68
|
const timeout = aws_cdk_lib_1.Duration.seconds((lp === null || lp === void 0 ? void 0 : lp.timeoutS) || (def === null || def === void 0 ? void 0 : def.timeoutS) || 30);
|
|
57
69
|
let authorizerName = lp === null || lp === void 0 ? void 0 : lp.authorizerName;
|
|
58
70
|
if (authorizerName === undefined) {
|
|
@@ -79,6 +91,7 @@ const setupLambda = ({ lambdaConfig, pathV, verb, seenPermissions, authorizers,
|
|
|
79
91
|
authorizer,
|
|
80
92
|
memory,
|
|
81
93
|
timeout,
|
|
94
|
+
reservedConcurrentExecutions,
|
|
82
95
|
};
|
|
83
96
|
};
|
|
84
97
|
const addApiPaths = (api, pathList, apiRoots) => {
|
|
@@ -133,7 +146,7 @@ const openApiImpl = (p) => {
|
|
|
133
146
|
bundling: {
|
|
134
147
|
externalModules: ['aws-sdk', 'aws-lambda'],
|
|
135
148
|
},
|
|
136
|
-
reservedConcurrentExecutions:
|
|
149
|
+
reservedConcurrentExecutions: lc.reservedConcurrentExecutions,
|
|
137
150
|
logRetention: aws_cdk_lib_1.aws_logs.RetentionDays.FIVE_DAYS,
|
|
138
151
|
layers: lc.layers,
|
|
139
152
|
});
|
|
@@ -37,6 +37,10 @@ export interface ILambdaConfig {
|
|
|
37
37
|
* lambda memory. defaults to 128
|
|
38
38
|
*/
|
|
39
39
|
memory?: number;
|
|
40
|
+
/**
|
|
41
|
+
* reserved lambda concurrency. defaults to 5. if null, doesnt apply
|
|
42
|
+
*/
|
|
43
|
+
reservedConcurrentExecutions?: number | null;
|
|
40
44
|
}
|
|
41
45
|
/**
|
|
42
46
|
* 'default' will be applied to all functions
|
|
@@ -46,13 +50,14 @@ export interface ILambdaConfigs {
|
|
|
46
50
|
default?: ILambdaConfig;
|
|
47
51
|
};
|
|
48
52
|
}
|
|
53
|
+
export declare type TSkOperator = 'BETWEEN' | '<' | '<=' | '=' | '>=' | '>';
|
|
49
54
|
export interface IQueryDynamo {
|
|
50
55
|
pkName: string;
|
|
51
56
|
pkValue: string | number;
|
|
52
57
|
pkOperator?: string;
|
|
53
58
|
skName?: string;
|
|
54
59
|
skValue?: string | number | string[] | number[];
|
|
55
|
-
skOperator?:
|
|
60
|
+
skOperator?: TSkOperator;
|
|
56
61
|
tableName: string;
|
|
57
62
|
indexName?: string;
|
|
58
63
|
count?: number;
|
|
@@ -3,7 +3,10 @@ export declare const LoginButton: ({ className, text, invert, savePath, loginPat
|
|
|
3
3
|
invert?: boolean | undefined;
|
|
4
4
|
text: string;
|
|
5
5
|
className?: string | undefined;
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* pass in request.url.path to save redirect. undefined will not set redirect
|
|
8
|
+
*/
|
|
9
|
+
savePath: string | undefined;
|
|
7
10
|
loginPath: (state?: Record<string, unknown> | undefined) => string;
|
|
8
11
|
style?: Record<string, string | number | boolean> | undefined;
|
|
9
12
|
}) => JSX.Element;
|
|
@@ -10,12 +10,13 @@ const styled_components_1 = __importDefault(require("styled-components"));
|
|
|
10
10
|
const Base = styled_components_1.default.a `
|
|
11
11
|
${Button_1.ButtonBase}
|
|
12
12
|
`;
|
|
13
|
-
const LoginButton = ({ className, text, invert, savePath
|
|
14
|
-
const
|
|
13
|
+
const LoginButton = ({ className, text, invert, savePath, loginPath, style, }) => {
|
|
14
|
+
const state = !savePath
|
|
15
15
|
? undefined
|
|
16
16
|
: {
|
|
17
|
-
redirect:
|
|
18
|
-
}
|
|
17
|
+
redirect: savePath,
|
|
18
|
+
};
|
|
19
|
+
const lp = loginPath(state);
|
|
19
20
|
return (react_1.default.createElement(Base, { style: style, href: lp, title: text, "data-invert": invert, "data-disabled": false, className: className }, text));
|
|
20
21
|
};
|
|
21
22
|
exports.LoginButton = LoginButton;
|