ag-common 0.0.307 → 0.0.310
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/aws.js +4 -2
- package/dist/api/helpers/index.d.ts +1 -0
- package/dist/api/helpers/index.js +1 -0
- package/dist/api/helpers/ses.d.ts +12 -0
- package/dist/api/helpers/ses.js +49 -0
- package/dist/ui/helpers/routes.d.ts +10 -6
- package/dist/ui/helpers/routes.js +13 -7
- package/package.json +6 -6
package/dist/api/helpers/aws.js
CHANGED
|
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setAwsRegion = void 0;
|
|
4
4
|
const dynamo_1 = require("./dynamo");
|
|
5
5
|
const s3_1 = require("./s3");
|
|
6
|
-
const
|
|
6
|
+
const ses_1 = require("./ses");
|
|
7
|
+
const sqs_1 = require("./sqs");
|
|
7
8
|
const setAwsRegion = (region) => {
|
|
8
9
|
(0, dynamo_1.setDynamo)(region);
|
|
9
10
|
(0, s3_1.setS3)(region);
|
|
10
|
-
(0,
|
|
11
|
+
(0, ses_1.setSes)(region);
|
|
12
|
+
(0, sqs_1.setSqs)(region);
|
|
11
13
|
};
|
|
12
14
|
exports.setAwsRegion = setAwsRegion;
|
|
@@ -21,6 +21,7 @@ __exportStar(require("./enforceDynamoProvisionCap"), exports);
|
|
|
21
21
|
__exportStar(require("./dynamoInfra"), exports);
|
|
22
22
|
__exportStar(require("./openApiHelpers"), exports);
|
|
23
23
|
__exportStar(require("./s3"), exports);
|
|
24
|
+
__exportStar(require("./ses"), exports);
|
|
24
25
|
__exportStar(require("./sqs"), exports);
|
|
25
26
|
__exportStar(require("./validateOpenApi"), exports);
|
|
26
27
|
__exportStar(require("./validations"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import AWS from 'aws-sdk';
|
|
2
|
+
export declare let ses: AWS.SES;
|
|
3
|
+
export declare const setSes: (region: string) => void;
|
|
4
|
+
export interface ISendEmail {
|
|
5
|
+
to: string;
|
|
6
|
+
message: string;
|
|
7
|
+
subject: string;
|
|
8
|
+
sourceArn: string;
|
|
9
|
+
from: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const sendEmail: ({ to, message, subject, sourceArn, from, }: ISendEmail) => Promise<void>;
|
|
12
|
+
export declare const sendEmails: (emails: ISendEmail[]) => Promise<void[]>;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.sendEmails = exports.sendEmail = exports.setSes = exports.ses = void 0;
|
|
16
|
+
const aws_sdk_1 = __importDefault(require("aws-sdk"));
|
|
17
|
+
exports.ses = new aws_sdk_1.default.SES();
|
|
18
|
+
const setSes = (region) => {
|
|
19
|
+
exports.ses = new aws_sdk_1.default.SES({ region });
|
|
20
|
+
};
|
|
21
|
+
exports.setSes = setSes;
|
|
22
|
+
const sendEmail = ({ to, message, subject, sourceArn, from, }) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
+
// Create sendEmail params
|
|
24
|
+
const params = {
|
|
25
|
+
Destination: {
|
|
26
|
+
CcAddresses: [],
|
|
27
|
+
ToAddresses: [to],
|
|
28
|
+
},
|
|
29
|
+
Message: {
|
|
30
|
+
Body: {
|
|
31
|
+
Text: {
|
|
32
|
+
Charset: 'UTF-8',
|
|
33
|
+
Data: message,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
Subject: {
|
|
37
|
+
Charset: 'UTF-8',
|
|
38
|
+
Data: subject,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
Source: from,
|
|
42
|
+
ReplyToAddresses: [from],
|
|
43
|
+
SourceArn: sourceArn,
|
|
44
|
+
};
|
|
45
|
+
yield exports.ses.sendEmail(params).promise();
|
|
46
|
+
});
|
|
47
|
+
exports.sendEmail = sendEmail;
|
|
48
|
+
const sendEmails = (emails) => __awaiter(void 0, void 0, void 0, function* () { return Promise.all(emails.map(exports.sendEmail)); });
|
|
49
|
+
exports.sendEmails = sendEmails;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ICognitoAuth } from './cognito';
|
|
2
2
|
import { AxiosWrapperLite } from './jwt';
|
|
3
3
|
import { TLang } from '../../common/helpers/i18n';
|
|
4
|
+
export declare type TProtocol = 'http:' | 'https:';
|
|
4
5
|
export interface LocationSubset {
|
|
5
6
|
/**
|
|
6
7
|
* slash only path eg /aaa/bbb
|
|
@@ -22,10 +23,7 @@ export interface LocationSubset {
|
|
|
22
23
|
* protocol less up to first slash eg aaa.com:1111
|
|
23
24
|
*/
|
|
24
25
|
host: string;
|
|
25
|
-
|
|
26
|
-
* eg http: or https:
|
|
27
|
-
*/
|
|
28
|
-
protocol: string;
|
|
26
|
+
protocol: TProtocol;
|
|
29
27
|
/**
|
|
30
28
|
* full url
|
|
31
29
|
*/
|
|
@@ -65,7 +63,7 @@ export interface IStateCommon<TRequest extends IRequestCommon> extends IInitialS
|
|
|
65
63
|
* @param param0
|
|
66
64
|
* @returns
|
|
67
65
|
*/
|
|
68
|
-
export declare const getClientOrServerReqHref: ({ url: { href, query }, forceServer, userAgent, darkMode, defaultHost, }: {
|
|
66
|
+
export declare const getClientOrServerReqHref: ({ url: { href, query, protocol }, forceServer, userAgent, darkMode, defaultHost, }: {
|
|
69
67
|
url: {
|
|
70
68
|
/**
|
|
71
69
|
* parse querystring keyvalues
|
|
@@ -75,6 +73,7 @@ export declare const getClientOrServerReqHref: ({ url: { href, query }, forceSer
|
|
|
75
73
|
* full url
|
|
76
74
|
*/
|
|
77
75
|
href?: string | undefined;
|
|
76
|
+
protocol: TProtocol;
|
|
78
77
|
};
|
|
79
78
|
/**
|
|
80
79
|
* if true, wont use window location. default false
|
|
@@ -96,13 +95,14 @@ export declare const getClientOrServerReqHref: ({ url: { href, query }, forceSer
|
|
|
96
95
|
* get server side parsed url
|
|
97
96
|
* @param param0 * @returns
|
|
98
97
|
*/
|
|
99
|
-
export declare const getServerReq: ({ defaultHost, pathname, query, headers, }: {
|
|
98
|
+
export declare const getServerReq: ({ defaultHost, pathname, query, headers, encrypted, }: {
|
|
100
99
|
/**
|
|
101
100
|
* eg ctx?.req?.headers || {}
|
|
102
101
|
*/
|
|
103
102
|
headers: {
|
|
104
103
|
host?: string;
|
|
105
104
|
'user-agent'?: string;
|
|
105
|
+
'x-forwarded-proto'?: 'http' | 'https';
|
|
106
106
|
};
|
|
107
107
|
/** what to use if host is not available on headers */
|
|
108
108
|
defaultHost: string;
|
|
@@ -114,6 +114,10 @@ export declare const getServerReq: ({ defaultHost, pathname, query, headers, }:
|
|
|
114
114
|
* eg ctx.query
|
|
115
115
|
*/
|
|
116
116
|
query: Record<string, string | string[] | undefined>;
|
|
117
|
+
/**
|
|
118
|
+
* eg (ctx?.req?.socket as any)?.encrypted)
|
|
119
|
+
*/
|
|
120
|
+
encrypted: boolean;
|
|
117
121
|
}) => {
|
|
118
122
|
url: LocationSubset;
|
|
119
123
|
userAgent: string;
|
|
@@ -34,10 +34,11 @@ const getRenderLanguage = ({ defaultHost, url, }) => {
|
|
|
34
34
|
* @param param0
|
|
35
35
|
* @returns
|
|
36
36
|
*/
|
|
37
|
-
const getClientOrServerReqHref = ({ url: { href, query }, forceServer = false, userAgent, darkMode, defaultHost, }) => {
|
|
37
|
+
const getClientOrServerReqHref = ({ url: { href, query, protocol }, forceServer = false, userAgent, darkMode, defaultHost, }) => {
|
|
38
38
|
if (typeof window !== 'undefined') {
|
|
39
39
|
if (!forceServer) {
|
|
40
40
|
href = window.location.href;
|
|
41
|
+
protocol = window.location.protocol;
|
|
41
42
|
}
|
|
42
43
|
darkMode =
|
|
43
44
|
window.matchMedia &&
|
|
@@ -53,11 +54,11 @@ const getClientOrServerReqHref = ({ url: { href, query }, forceServer = false, u
|
|
|
53
54
|
const url = {
|
|
54
55
|
hash: parsed.hash || '',
|
|
55
56
|
host: parsed.host || '',
|
|
56
|
-
origin: `${
|
|
57
|
-
href: `${
|
|
57
|
+
origin: `${protocol}//${parsed.host}`,
|
|
58
|
+
href: `${protocol}//${parsed.host}${parsed.path}${parsed.hash || ''}`,
|
|
58
59
|
path: `${parsed.path}${parsed.hash || ''}`,
|
|
59
60
|
pathname: parsed.pathname || '',
|
|
60
|
-
protocol:
|
|
61
|
+
protocol: protocol || '',
|
|
61
62
|
query: Object.assign(Object.assign({}, query), (0, string_1.stringToObject)(parsed.query || '', '=', '&')),
|
|
62
63
|
};
|
|
63
64
|
return {
|
|
@@ -73,12 +74,16 @@ exports.getClientOrServerReqHref = getClientOrServerReqHref;
|
|
|
73
74
|
* get server side parsed url
|
|
74
75
|
* @param param0 * @returns
|
|
75
76
|
*/
|
|
76
|
-
const getServerReq = ({ defaultHost, pathname, query, headers, }) => {
|
|
77
|
-
var _a;
|
|
77
|
+
const getServerReq = ({ defaultHost, pathname, query, headers, encrypted, }) => {
|
|
78
|
+
var _a, _b;
|
|
78
79
|
const href = calculateServerHref({
|
|
79
80
|
host: headers.host || defaultHost,
|
|
80
81
|
pathname,
|
|
81
82
|
});
|
|
83
|
+
let protocol = 'http:';
|
|
84
|
+
if (((_a = headers['x-forwarded-proto']) === null || _a === void 0 ? void 0 : _a.includes('https')) || encrypted) {
|
|
85
|
+
protocol = 'https:';
|
|
86
|
+
}
|
|
82
87
|
const parsedQuery = !query || Object.keys(query).length === 0
|
|
83
88
|
? undefined
|
|
84
89
|
: (0, object_1.castStringlyObject)(query);
|
|
@@ -86,9 +91,10 @@ const getServerReq = ({ defaultHost, pathname, query, headers, }) => {
|
|
|
86
91
|
url: {
|
|
87
92
|
href,
|
|
88
93
|
query: parsedQuery,
|
|
94
|
+
protocol,
|
|
89
95
|
},
|
|
90
96
|
forceServer: true,
|
|
91
|
-
userAgent: (
|
|
97
|
+
userAgent: (_b = headers['user-agent']) === null || _b === void 0 ? void 0 : _b.toLowerCase(),
|
|
92
98
|
defaultHost,
|
|
93
99
|
});
|
|
94
100
|
return ret;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.310",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -42,12 +42,12 @@
|
|
|
42
42
|
"@storybook/react": "6.5.10",
|
|
43
43
|
"@storybook/theming": "6.5.10",
|
|
44
44
|
"@types/jsonwebtoken": "8.5.8",
|
|
45
|
-
"@types/node": "18.
|
|
46
|
-
"@types/react": "18.0.
|
|
45
|
+
"@types/node": "18.7.1",
|
|
46
|
+
"@types/react": "18.0.17",
|
|
47
47
|
"@types/react-dom": "18.0.6",
|
|
48
|
-
"@types/styled-components": "5.1.
|
|
49
|
-
"@typescript-eslint/eslint-plugin": "5.
|
|
50
|
-
"@typescript-eslint/parser": "5.
|
|
48
|
+
"@types/styled-components": "5.1.26",
|
|
49
|
+
"@typescript-eslint/eslint-plugin": "5.33.0",
|
|
50
|
+
"@typescript-eslint/parser": "5.33.0",
|
|
51
51
|
"cross-env": "7.0.3",
|
|
52
52
|
"eslint": "8.21.0",
|
|
53
53
|
"eslint-config-airbnb-typescript": "17.0.0",
|