@digitraffic/common 2023.12.15-1 → 2024.1.19-1
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/aws/infra/api/handler-factory.d.ts +2 -2
- package/dist/aws/infra/api/handler-factory.js +4 -9
- package/dist/aws/infra/api/integration.d.ts +1 -1
- package/dist/aws/infra/api/integration.js +9 -13
- package/dist/aws/infra/api/response.d.ts +2 -3
- package/dist/aws/infra/api/response.js +25 -30
- package/dist/aws/infra/api/responses.d.ts +2 -3
- package/dist/aws/infra/api/responses.js +25 -31
- package/dist/aws/infra/api/static-integration.d.ts +1 -1
- package/dist/aws/infra/api/static-integration.js +7 -11
- package/dist/aws/infra/canaries/canary-alarm.d.ts +1 -1
- package/dist/aws/infra/canaries/canary-alarm.js +7 -11
- package/dist/aws/infra/canaries/canary-keys.js +3 -6
- package/dist/aws/infra/canaries/canary-parameters.js +1 -2
- package/dist/aws/infra/canaries/canary-role.js +8 -12
- package/dist/aws/infra/canaries/canary.d.ts +2 -2
- package/dist/aws/infra/canaries/canary.js +9 -13
- package/dist/aws/infra/canaries/database-canary.d.ts +3 -3
- package/dist/aws/infra/canaries/database-canary.js +8 -12
- package/dist/aws/infra/canaries/database-checker.d.ts +1 -1
- package/dist/aws/infra/canaries/database-checker.js +10 -14
- package/dist/aws/infra/canaries/url-canary.d.ts +4 -4
- package/dist/aws/infra/canaries/url-canary.js +8 -12
- package/dist/aws/infra/canaries/url-checker.d.ts +2 -2
- package/dist/aws/infra/canaries/url-checker.js +33 -40
- package/dist/aws/infra/documentation.js +8 -16
- package/dist/aws/infra/import-util.js +10 -18
- package/dist/aws/infra/scheduler.js +10 -14
- package/dist/aws/infra/security-rule.js +4 -8
- package/dist/aws/infra/sqs-integration.d.ts +1 -2
- package/dist/aws/infra/sqs-integration.js +11 -15
- package/dist/aws/infra/sqs-queue.d.ts +1 -1
- package/dist/aws/infra/sqs-queue.js +51 -50
- package/dist/aws/infra/stack/lambda-configs.d.ts +2 -2
- package/dist/aws/infra/stack/lambda-configs.js +14 -20
- package/dist/aws/infra/stack/monitoredfunction.d.ts +3 -3
- package/dist/aws/infra/stack/monitoredfunction.js +19 -27
- package/dist/aws/infra/stack/parameters.d.ts +1 -1
- package/dist/aws/infra/stack/parameters.js +5 -10
- package/dist/aws/infra/stack/rest_apis.d.ts +3 -3
- package/dist/aws/infra/stack/rest_apis.js +41 -54
- package/dist/aws/infra/stack/stack-checking-aspect.d.ts +1 -1
- package/dist/aws/infra/stack/stack-checking-aspect.js +28 -39
- package/dist/aws/infra/stack/stack.d.ts +5 -6
- package/dist/aws/infra/stack/stack.js +16 -20
- package/dist/aws/infra/stack/subscription.d.ts +2 -2
- package/dist/aws/infra/stack/subscription.js +5 -10
- package/dist/aws/infra/stacks/db-dns-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/db-dns-stack.js +25 -29
- package/dist/aws/infra/stacks/db-proxy-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/db-proxy-stack.js +23 -27
- package/dist/aws/infra/stacks/db-stack.d.ts +3 -4
- package/dist/aws/infra/stacks/db-stack.js +30 -34
- package/dist/aws/infra/stacks/intra-stack-configuration.js +1 -2
- package/dist/aws/infra/stacks/network-stack.d.ts +2 -2
- package/dist/aws/infra/stacks/network-stack.js +15 -19
- package/dist/aws/infra/usage-plans.js +2 -7
- package/dist/aws/runtime/apikey.js +3 -7
- package/dist/aws/runtime/digitraffic-integration-response.d.ts +1 -1
- package/dist/aws/runtime/digitraffic-integration-response.js +7 -11
- package/dist/aws/runtime/dt-logger-default.d.ts +2 -2
- package/dist/aws/runtime/dt-logger-default.js +2 -5
- package/dist/aws/runtime/dt-logger.d.ts +1 -1
- package/dist/aws/runtime/dt-logger.js +3 -10
- package/dist/aws/runtime/environment.js +3 -7
- package/dist/aws/runtime/messaging.js +1 -5
- package/dist/aws/runtime/s3.js +3 -7
- package/dist/aws/runtime/secrets/dbsecret.d.ts +1 -1
- package/dist/aws/runtime/secrets/dbsecret.js +5 -9
- package/dist/aws/runtime/secrets/proxy-holder.js +12 -16
- package/dist/aws/runtime/secrets/rds-holder.js +12 -16
- package/dist/aws/runtime/secrets/secret-holder.d.ts +1 -1
- package/dist/aws/runtime/secrets/secret-holder.js +9 -13
- package/dist/aws/runtime/secrets/secret.js +7 -11
- package/dist/aws/types/errors.js +5 -9
- package/dist/aws/types/lambda-response.js +3 -10
- package/dist/aws/types/mediatypes.js +2 -5
- package/dist/aws/types/model-with-reference.js +1 -2
- package/dist/aws/types/proxytypes.js +1 -2
- package/dist/aws/types/tags.js +2 -5
- package/dist/database/cached.d.ts +1 -1
- package/dist/database/cached.js +8 -14
- package/dist/database/database.js +14 -21
- package/dist/database/last-updated.d.ts +1 -1
- package/dist/database/last-updated.js +8 -17
- package/dist/database/models.js +1 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/marine/id_utils.js +3 -9
- package/dist/marine/rtz.js +1 -2
- package/dist/test/asserter.js +1 -5
- package/dist/test/db-testutils.d.ts +1 -1
- package/dist/test/db-testutils.js +8 -13
- package/dist/test/httpserver.d.ts +1 -1
- package/dist/test/httpserver.js +19 -18
- package/dist/test/secrets-manager.js +9 -35
- package/dist/test/testutils.js +8 -19
- package/dist/types/async-timeout-error.js +1 -5
- package/dist/types/aws-env.js +1 -2
- package/dist/types/either.js +1 -2
- package/dist/types/http-error.js +1 -5
- package/dist/types/input-error.js +1 -5
- package/dist/types/language.js +2 -5
- package/dist/types/nullable.d.ts +1 -1
- package/dist/types/nullable.js +1 -2
- package/dist/types/traffictype.js +2 -5
- package/dist/types/urn.js +1 -2
- package/dist/types/util-types.js +1 -2
- package/dist/types/validator.js +4 -9
- package/dist/utils/api-model.d.ts +1 -1
- package/dist/utils/api-model.js +17 -27
- package/dist/utils/base64.d.ts +1 -1
- package/dist/utils/base64.js +2 -7
- package/dist/utils/date-utils.js +9 -16
- package/dist/utils/geojson-types.js +2 -7
- package/dist/utils/geometry.js +15 -48
- package/dist/utils/logging.d.ts +1 -1
- package/dist/utils/logging.js +8 -13
- package/dist/utils/retry.js +21 -26
- package/dist/utils/slack.js +7 -14
- package/dist/utils/utils.d.ts +2 -2
- package/dist/utils/utils.js +14 -29
- package/package.json +127 -41
- package/src/aws/infra/api/handler-factory.ts +3 -3
- package/src/aws/infra/api/integration.ts +2 -2
- package/src/aws/infra/api/response.ts +3 -3
- package/src/aws/infra/api/responses.ts +4 -4
- package/src/aws/infra/api/static-integration.ts +2 -2
- package/src/aws/infra/canaries/canary-alarm.ts +1 -1
- package/src/aws/infra/canaries/canary.ts +3 -3
- package/src/aws/infra/canaries/database-canary.ts +3 -3
- package/src/aws/infra/canaries/database-checker.ts +6 -6
- package/src/aws/infra/canaries/url-canary.ts +6 -6
- package/src/aws/infra/canaries/url-checker.ts +8 -8
- package/src/aws/infra/sqs-integration.ts +1 -1
- package/src/aws/infra/sqs-queue.ts +29 -44
- package/src/aws/infra/stack/lambda-configs.ts +9 -9
- package/src/aws/infra/stack/monitoredfunction.ts +4 -4
- package/src/aws/infra/stack/parameters.ts +1 -1
- package/src/aws/infra/stack/rest_apis.ts +6 -6
- package/src/aws/infra/stack/stack-checking-aspect.ts +20 -72
- package/src/aws/infra/stack/stack.ts +4 -5
- package/src/aws/infra/stack/subscription.ts +2 -2
- package/src/aws/infra/stacks/db-dns-stack.ts +4 -4
- package/src/aws/infra/stacks/db-proxy-stack.ts +5 -5
- package/src/aws/infra/stacks/db-stack.ts +5 -5
- package/src/aws/infra/stacks/network-stack.ts +3 -3
- package/src/aws/runtime/digitraffic-integration-response.ts +2 -2
- package/src/aws/runtime/dt-logger-default.ts +2 -2
- package/src/aws/runtime/secrets/dbsecret.ts +1 -1
- package/src/aws/runtime/secrets/proxy-holder.ts +4 -4
- package/src/aws/runtime/secrets/rds-holder.ts +4 -4
- package/src/aws/runtime/secrets/secret-holder.ts +4 -4
- package/src/aws/runtime/secrets/secret.ts +2 -2
- package/src/database/cached.ts +1 -1
- package/src/database/database.ts +3 -3
- package/src/database/last-updated.ts +1 -1
- package/src/index.ts +2 -0
- package/src/test/db-testutils.ts +2 -2
- package/src/test/httpserver.ts +13 -7
- package/src/test/secrets-manager.ts +2 -2
- package/src/types/nullable.ts +1 -1
- package/src/utils/api-model.ts +1 -1
- package/src/utils/geometry.ts +5 -3
- package/src/utils/logging.ts +2 -2
- package/src/utils/retry.ts +3 -3
- package/src/utils/slack.ts +2 -2
- package/src/utils/utils.ts +3 -3
package/dist/test/httpserver.js
CHANGED
@@ -1,14 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
const
|
5
|
-
const url_1 = require("url");
|
6
|
-
exports.ERROR_NO_MATCH = "NO MATCH";
|
7
|
-
exports.ERRORCODE_NOT_FOUND = 404;
|
1
|
+
import { createServer } from "http";
|
2
|
+
import { parse } from "url";
|
3
|
+
export const ERROR_NO_MATCH = "NO MATCH";
|
4
|
+
export const ERRORCODE_NOT_FOUND = 404;
|
8
5
|
/**
|
9
6
|
* A mock HTTP server created for testing connections from a Lambda to an outside integration
|
10
7
|
*/
|
11
|
-
class TestHttpServer {
|
8
|
+
export class TestHttpServer {
|
12
9
|
constructor() {
|
13
10
|
this.debug = false;
|
14
11
|
this.messageStack = [];
|
@@ -23,14 +20,14 @@ class TestHttpServer {
|
|
23
20
|
this.debug = debug;
|
24
21
|
this.messageStack = [];
|
25
22
|
this.debuglog(`Starting test server on port ${port}`);
|
26
|
-
this.server =
|
23
|
+
this.server = createServer((req, res) => {
|
27
24
|
this.debuglog("Mapped urls: ");
|
28
25
|
Object.keys(props).forEach((k) => this.debuglog(k));
|
29
26
|
if (!req.url) {
|
30
27
|
throw new Error("Missing request url!");
|
31
28
|
}
|
32
29
|
this.debuglog(`Received request to url ${req.url} ..`);
|
33
|
-
const path =
|
30
|
+
const path = parse(req.url).pathname;
|
34
31
|
if (!path) {
|
35
32
|
throw new Error("Missing path from request!");
|
36
33
|
}
|
@@ -56,19 +53,24 @@ class TestHttpServer {
|
|
56
53
|
req.on("end", () => {
|
57
54
|
// assume sent data is in JSON format
|
58
55
|
this.messageStack[this.messageStack.length] =
|
59
|
-
|
60
|
-
res.writeHead(
|
61
|
-
res.end(
|
56
|
+
ERROR_NO_MATCH;
|
57
|
+
res.writeHead(ERRORCODE_NOT_FOUND);
|
58
|
+
res.end(ERROR_NO_MATCH);
|
62
59
|
});
|
63
60
|
}
|
64
61
|
});
|
65
62
|
this.server.listen(port);
|
66
63
|
}
|
67
64
|
close() {
|
68
|
-
|
69
|
-
|
70
|
-
this.server
|
71
|
-
|
65
|
+
return new Promise((resolve, reject) => {
|
66
|
+
this.debuglog("Closing test server");
|
67
|
+
if (this.server !== undefined) {
|
68
|
+
this.server.close((error) => error != null ? reject(false) : resolve(true));
|
69
|
+
}
|
70
|
+
else {
|
71
|
+
resolve(true);
|
72
|
+
}
|
73
|
+
});
|
72
74
|
}
|
73
75
|
debuglog(str) {
|
74
76
|
if (this.debug) {
|
@@ -76,5 +78,4 @@ class TestHttpServer {
|
|
76
78
|
}
|
77
79
|
}
|
78
80
|
}
|
79
|
-
exports.TestHttpServer = TestHttpServer;
|
80
81
|
//# sourceMappingURL=httpserver.js.map
|
@@ -1,34 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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 (mod) {
|
19
|
-
if (mod && mod.__esModule) return mod;
|
20
|
-
var result = {};
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
22
|
-
__setModuleDefault(result, mod);
|
23
|
-
return result;
|
24
|
-
};
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
-
exports.mockSecret = exports.stubSecretsManager = void 0;
|
27
|
-
const AWS = require("aws-sdk");
|
28
|
-
const sinon = __importStar(require("sinon"));
|
29
|
-
const environment_1 = require("../aws/runtime/environment");
|
30
|
-
const utils_1 = require("../utils/utils");
|
31
|
-
(0, utils_1.setEnvVariable)(environment_1.EnvKeys.AWS_REGION, "eu-west-1");
|
1
|
+
import { createRequire as _createRequire } from "module";
|
2
|
+
const __require = _createRequire(import.meta.url);
|
3
|
+
const AWS = __require("aws-sdk");
|
4
|
+
import * as sinon from "sinon";
|
5
|
+
import { EnvKeys } from "../aws/runtime/environment.js";
|
6
|
+
import { setEnvVariable } from "../utils/utils.js";
|
7
|
+
setEnvVariable(EnvKeys.AWS_REGION, "eu-west-1");
|
32
8
|
const secretValue = sinon.stub();
|
33
9
|
/**
|
34
10
|
* Stub Secrets Manager for tests. You must call this
|
@@ -36,15 +12,14 @@ const secretValue = sinon.stub();
|
|
36
12
|
*
|
37
13
|
* To mock the actual secret, call mockSecret()
|
38
14
|
*/
|
39
|
-
function stubSecretsManager() {
|
15
|
+
export function stubSecretsManager() {
|
40
16
|
const smStub = {
|
41
17
|
getSecretValue: secretValue,
|
42
18
|
};
|
43
19
|
sinon.stub(AWS, "SecretsManager").returns(smStub);
|
44
20
|
return smStub.getSecretValue;
|
45
21
|
}
|
46
|
-
|
47
|
-
function mockSecret(secret) {
|
22
|
+
export function mockSecret(secret) {
|
48
23
|
if (!secret) {
|
49
24
|
secretValue.returns({
|
50
25
|
promise: sinon.stub().returns({}),
|
@@ -58,5 +33,4 @@ function mockSecret(secret) {
|
|
58
33
|
});
|
59
34
|
}
|
60
35
|
}
|
61
|
-
exports.mockSecret = mockSecret;
|
62
36
|
//# sourceMappingURL=secrets-manager.js.map
|
package/dist/test/testutils.js
CHANGED
@@ -1,44 +1,33 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.shuffle = exports.randomBoolean = exports.getRandomBigInt = exports.getRandomIntegerAsString = exports.getRandomInteger = exports.getRandomNumberAsString = exports.getRandomNumber = exports.randomString = void 0;
|
4
|
-
function randomString() {
|
1
|
+
export function randomString() {
|
5
2
|
return Math.random().toString(36).substring(2);
|
6
3
|
}
|
7
|
-
|
8
|
-
function getRandomNumber(min, max) {
|
4
|
+
export function getRandomNumber(min, max) {
|
9
5
|
return Math.random() * (max - min) + min;
|
10
6
|
}
|
11
|
-
|
12
|
-
function getRandomNumberAsString(min, max) {
|
7
|
+
export function getRandomNumberAsString(min, max) {
|
13
8
|
return getRandomNumber(min, max).toString();
|
14
9
|
}
|
15
|
-
|
16
|
-
function getRandomInteger(min, max) {
|
10
|
+
export function getRandomInteger(min, max) {
|
17
11
|
return Math.round(getRandomNumber(min, max));
|
18
12
|
}
|
19
|
-
|
20
|
-
function getRandomIntegerAsString(min, max) {
|
13
|
+
export function getRandomIntegerAsString(min, max) {
|
21
14
|
return Math.round(getRandomInteger(min, max)).toString();
|
22
15
|
}
|
23
|
-
|
24
|
-
function getRandomBigInt(min, max) {
|
16
|
+
export function getRandomBigInt(min, max) {
|
25
17
|
return BigInt(getRandomInteger(min, max));
|
26
18
|
}
|
27
|
-
|
28
|
-
function randomBoolean() {
|
19
|
+
export function randomBoolean() {
|
29
20
|
return Math.random() < 0.5;
|
30
21
|
}
|
31
|
-
exports.randomBoolean = randomBoolean;
|
32
22
|
/**
|
33
23
|
* Returns a new copy of an array, shuffled using Math.random()
|
34
24
|
* @param array Array
|
35
25
|
*/
|
36
|
-
function shuffle(array) {
|
26
|
+
export function shuffle(array) {
|
37
27
|
// pretty fast way to copy an array, not necessarily the fastest
|
38
28
|
const newArray = array.slice(0);
|
39
29
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
40
30
|
newArray.sort((x) => 0.5 - Math.random());
|
41
31
|
return newArray;
|
42
32
|
}
|
43
|
-
exports.shuffle = shuffle;
|
44
33
|
//# sourceMappingURL=testutils.js.map
|
@@ -1,10 +1,6 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.AsyncTimeoutError = void 0;
|
4
|
-
class AsyncTimeoutError extends Error {
|
1
|
+
export class AsyncTimeoutError extends Error {
|
5
2
|
constructor() {
|
6
3
|
super("Async operation timed out");
|
7
4
|
}
|
8
5
|
}
|
9
|
-
exports.AsyncTimeoutError = AsyncTimeoutError;
|
10
6
|
//# sourceMappingURL=async-timeout-error.js.map
|
package/dist/types/aws-env.js
CHANGED
package/dist/types/either.js
CHANGED
package/dist/types/http-error.js
CHANGED
@@ -1,11 +1,7 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.HttpError = void 0;
|
4
|
-
class HttpError extends Error {
|
1
|
+
export class HttpError extends Error {
|
5
2
|
constructor(statusCode, message) {
|
6
3
|
super(message);
|
7
4
|
this.statusCode = statusCode;
|
8
5
|
}
|
9
6
|
}
|
10
|
-
exports.HttpError = HttpError;
|
11
7
|
//# sourceMappingURL=http-error.js.map
|
@@ -1,7 +1,3 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.InputError = void 0;
|
4
|
-
class InputError extends Error {
|
1
|
+
export class InputError extends Error {
|
5
2
|
}
|
6
|
-
exports.InputError = InputError;
|
7
3
|
//# sourceMappingURL=input-error.js.map
|
package/dist/types/language.js
CHANGED
@@ -1,10 +1,7 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.Language = void 0;
|
4
|
-
var Language;
|
1
|
+
export var Language;
|
5
2
|
(function (Language) {
|
6
3
|
Language["FI"] = "fi";
|
7
4
|
Language["EN"] = "en";
|
8
5
|
Language["SV"] = "sv";
|
9
|
-
})(Language
|
6
|
+
})(Language || (Language = {}));
|
10
7
|
//# sourceMappingURL=language.js.map
|
package/dist/types/nullable.d.ts
CHANGED
package/dist/types/nullable.js
CHANGED
@@ -1,7 +1,4 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.TrafficType = void 0;
|
4
|
-
var TrafficType;
|
1
|
+
export var TrafficType;
|
5
2
|
(function (TrafficType) {
|
6
3
|
TrafficType["ROAD"] = "Road";
|
7
4
|
TrafficType["MARINE"] = "Marine";
|
@@ -9,5 +6,5 @@ var TrafficType;
|
|
9
6
|
TrafficType["AVIATION"] = "Aviation";
|
10
7
|
TrafficType["MCP"] = "MCP";
|
11
8
|
TrafficType["OTHER"] = "Other";
|
12
|
-
})(TrafficType
|
9
|
+
})(TrafficType || (TrafficType = {}));
|
13
10
|
//# sourceMappingURL=traffictype.js.map
|
package/dist/types/urn.js
CHANGED
package/dist/types/util-types.js
CHANGED
package/dist/types/validator.js
CHANGED
@@ -1,14 +1,9 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
exports.MIN_YEAR = 1900;
|
5
|
-
exports.MAX_YEAR = 2100;
|
6
|
-
function validateYear(year, minYear = exports.MIN_YEAR, maxYear = exports.MAX_YEAR) {
|
1
|
+
export const MIN_YEAR = 1900;
|
2
|
+
export const MAX_YEAR = 2100;
|
3
|
+
export function validateYear(year, minYear = MIN_YEAR, maxYear = MAX_YEAR) {
|
7
4
|
return year >= minYear && year <= maxYear;
|
8
5
|
}
|
9
|
-
|
10
|
-
function validateMonth(month) {
|
6
|
+
export function validateMonth(month) {
|
11
7
|
return month > 0 && month < 13;
|
12
8
|
}
|
13
|
-
exports.validateMonth = validateMonth;
|
14
9
|
//# sourceMappingURL=validator.js.map
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { RestApi, Model, JsonSchema, RequestValidator, JsonSchemaType, JsonSchemaVersion } from 'aws-cdk-lib/aws-apigateway';
|
2
|
-
import { ModelWithReference } from "../aws/types/model-with-reference";
|
2
|
+
import { ModelWithReference } from "../aws/types/model-with-reference.js";
|
3
3
|
/**
|
4
4
|
* Get a reference to an OpenAPI model object in a REST API.
|
5
5
|
* Can be used to supply a reference to properties of a GeoJSON feature.
|
package/dist/utils/api-model.js
CHANGED
@@ -1,29 +1,24 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.geojsonSchema = exports.featureSchema = exports.createArraySchema = exports.addSimpleServiceModel = exports.addServiceModel = exports.addDefaultValidator = exports.getModelReference = void 0;
|
4
|
-
const aws_apigateway_1 = require("aws-cdk-lib/aws-apigateway");
|
1
|
+
import { JsonSchemaType, JsonSchemaVersion, } from 'aws-cdk-lib/aws-apigateway';
|
5
2
|
/**
|
6
3
|
* Get a reference to an OpenAPI model object in a REST API.
|
7
4
|
* Can be used to supply a reference to properties of a GeoJSON feature.
|
8
5
|
* @param modelId Id of the referenced object
|
9
6
|
* @param restApiId Id of the REST API
|
10
7
|
*/
|
11
|
-
function getModelReference(modelId, restApiId) {
|
8
|
+
export function getModelReference(modelId, restApiId) {
|
12
9
|
return `https://apigateway.amazonaws.com/restapis/${restApiId}/models/${modelId}`;
|
13
10
|
}
|
14
|
-
exports.getModelReference = getModelReference;
|
15
11
|
/**
|
16
12
|
* Adds a request validator to a REST API to enforce request parameters/body requirements.
|
17
13
|
* https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html
|
18
14
|
* @param api REST API
|
19
15
|
*/
|
20
|
-
function addDefaultValidator(api) {
|
16
|
+
export function addDefaultValidator(api) {
|
21
17
|
return api.addRequestValidator('DefaultValidator', {
|
22
18
|
validateRequestParameters: true,
|
23
19
|
validateRequestBody: true,
|
24
20
|
});
|
25
21
|
}
|
26
|
-
exports.addDefaultValidator = addDefaultValidator;
|
27
22
|
/**
|
28
23
|
* Adds a JSON Schema model to an API Gateway API. Can be used later to generate OpenAPI specifications.
|
29
24
|
* This method adds a schema for _a single object._
|
@@ -32,7 +27,7 @@ exports.addDefaultValidator = addDefaultValidator;
|
|
32
27
|
* @param schema JSON Schema
|
33
28
|
* @return ModelWithReference A model object with a reference to an API Gateway model object.
|
34
29
|
*/
|
35
|
-
function addServiceModel(modelName, api, schema) {
|
30
|
+
export function addServiceModel(modelName, api, schema) {
|
36
31
|
const mwr = api.addModel(modelName, {
|
37
32
|
contentType: 'application/json',
|
38
33
|
modelName,
|
@@ -41,7 +36,6 @@ function addServiceModel(modelName, api, schema) {
|
|
41
36
|
mwr.modelReference = getModelReference(mwr.modelId, api.restApiId);
|
42
37
|
return mwr;
|
43
38
|
}
|
44
|
-
exports.addServiceModel = addServiceModel;
|
45
39
|
/**
|
46
40
|
* Add an empty JSON schema model to an API Gateway API.
|
47
41
|
* Usable for example if the incoming data is in XML format but some template transformation is necessary.
|
@@ -49,42 +43,40 @@ exports.addServiceModel = addServiceModel;
|
|
49
43
|
* @param api
|
50
44
|
* @param contentType
|
51
45
|
*/
|
52
|
-
function addSimpleServiceModel(modelName, api, contentType = 'application/xml') {
|
46
|
+
export function addSimpleServiceModel(modelName, api, contentType = 'application/xml') {
|
53
47
|
return api.addModel(modelName, {
|
54
48
|
contentType,
|
55
49
|
modelName,
|
56
50
|
schema: {},
|
57
51
|
});
|
58
52
|
}
|
59
|
-
exports.addSimpleServiceModel = addSimpleServiceModel;
|
60
53
|
/**
|
61
54
|
* Adds a JSON Schema model to an API Gateway API. Can be used later to generate OpenAPI specifications.
|
62
55
|
* This method adds a schema for _an array._
|
63
56
|
* @param model
|
64
57
|
* @param api
|
65
58
|
*/
|
66
|
-
function createArraySchema(model, api) {
|
59
|
+
export function createArraySchema(model, api) {
|
67
60
|
return {
|
68
|
-
type:
|
61
|
+
type: JsonSchemaType.ARRAY,
|
69
62
|
items: {
|
70
63
|
ref: getModelReference(model.modelId, api.restApiId),
|
71
64
|
},
|
72
65
|
};
|
73
66
|
}
|
74
|
-
exports.createArraySchema = createArraySchema;
|
75
67
|
/**
|
76
68
|
* Creates a JSON Schema for a GeoJSON Feature. Can be used to generate OpenAPI descriptions.
|
77
69
|
* @param modelReference Reference to a model object
|
78
70
|
*/
|
79
|
-
function featureSchema(modelReference) {
|
71
|
+
export function featureSchema(modelReference) {
|
80
72
|
return {
|
81
|
-
schema:
|
82
|
-
type:
|
73
|
+
schema: JsonSchemaVersion.DRAFT4,
|
74
|
+
type: JsonSchemaType.OBJECT,
|
83
75
|
description: 'GeoJson Feature',
|
84
76
|
required: ['type', 'properties', 'geometry'],
|
85
77
|
properties: {
|
86
78
|
type: {
|
87
|
-
type:
|
79
|
+
type: JsonSchemaType.STRING,
|
88
80
|
description: 'Feature',
|
89
81
|
enum: ['Feature'],
|
90
82
|
},
|
@@ -92,32 +84,31 @@ function featureSchema(modelReference) {
|
|
92
84
|
ref: modelReference,
|
93
85
|
},
|
94
86
|
geometry: {
|
95
|
-
type:
|
87
|
+
type: JsonSchemaType.OBJECT,
|
96
88
|
description: 'GeoJSON geometry',
|
97
89
|
},
|
98
90
|
},
|
99
91
|
};
|
100
92
|
}
|
101
|
-
exports.featureSchema = featureSchema;
|
102
93
|
/**
|
103
94
|
*
|
104
95
|
* Creates a JSON Schema for a GeoJSON Feature Collection. Can be used to generate OpenAPI descriptions.
|
105
96
|
* @param modelReference Reference to a model object, in this case Features.
|
106
97
|
*/
|
107
|
-
function geojsonSchema(modelReference) {
|
98
|
+
export function geojsonSchema(modelReference) {
|
108
99
|
return {
|
109
|
-
schema:
|
110
|
-
type:
|
100
|
+
schema: JsonSchemaVersion.DRAFT4,
|
101
|
+
type: JsonSchemaType.OBJECT,
|
111
102
|
description: 'GeoJson FeatureCollection',
|
112
103
|
required: ['type', 'features'],
|
113
104
|
properties: {
|
114
105
|
type: {
|
115
|
-
type:
|
106
|
+
type: JsonSchemaType.STRING,
|
116
107
|
description: 'FeatureCollection',
|
117
108
|
enum: ['FeatureCollection'],
|
118
109
|
},
|
119
110
|
features: {
|
120
|
-
type:
|
111
|
+
type: JsonSchemaType.ARRAY,
|
121
112
|
items: {
|
122
113
|
ref: modelReference,
|
123
114
|
},
|
@@ -125,5 +116,4 @@ function geojsonSchema(modelReference) {
|
|
125
116
|
},
|
126
117
|
};
|
127
118
|
}
|
128
|
-
exports.geojsonSchema = geojsonSchema;
|
129
119
|
//# sourceMappingURL=api-model.js.map
|
package/dist/utils/base64.d.ts
CHANGED
package/dist/utils/base64.js
CHANGED
@@ -1,21 +1,16 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.decodeBase64 = exports.decodeBase64ToAscii = void 0;
|
4
1
|
/**
|
5
2
|
* Decode given string from base64 to ascii
|
6
3
|
* @param str string
|
7
4
|
*/
|
8
|
-
function decodeBase64ToAscii(str) {
|
5
|
+
export function decodeBase64ToAscii(str) {
|
9
6
|
return decodeBase64(str, 'ascii');
|
10
7
|
}
|
11
|
-
exports.decodeBase64ToAscii = decodeBase64ToAscii;
|
12
8
|
/**
|
13
9
|
* Decode given string from base64 to given encoding
|
14
10
|
* @param str
|
15
11
|
* @param encoding
|
16
12
|
*/
|
17
|
-
function decodeBase64(str, encoding) {
|
13
|
+
export function decodeBase64(str, encoding) {
|
18
14
|
return Buffer.from(str, 'base64').toString(encoding);
|
19
15
|
}
|
20
|
-
exports.decodeBase64 = decodeBase64;
|
21
16
|
//# sourceMappingURL=base64.js.map
|
package/dist/utils/date-utils.js
CHANGED
@@ -1,51 +1,44 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.dateToUTCString = exports.dateFromIsoString = exports.countDiffInSeconds = exports.countDiffMs = exports.MYSQL_DATETIME_FORMAT = exports.UTC = exports.EPOCH = void 0;
|
4
|
-
const date_fns_tz_1 = require("date-fns-tz");
|
1
|
+
import { formatInTimeZone } from "date-fns-tz";
|
5
2
|
/**
|
6
3
|
* Constant for the 1970-01-01T00:00:00Z epoch Date.
|
7
4
|
*/
|
8
|
-
|
9
|
-
|
10
|
-
|
5
|
+
export const EPOCH = new Date(Date.UTC(1970, 0, 1));
|
6
|
+
export const UTC = "UTC";
|
7
|
+
export const MYSQL_DATETIME_FORMAT = "yyyy-MM-dd HH:mm";
|
11
8
|
/**
|
12
9
|
* Counts difference in milliseconds between dates.
|
13
10
|
* @param start
|
14
11
|
* @param end
|
15
12
|
*/
|
16
|
-
function countDiffMs(start, end) {
|
13
|
+
export function countDiffMs(start, end) {
|
17
14
|
return end.getTime() - start.getTime();
|
18
15
|
}
|
19
|
-
exports.countDiffMs = countDiffMs;
|
20
16
|
/**
|
21
17
|
* Counts difference in seconds between dates.
|
22
18
|
* @param start
|
23
19
|
* @param end
|
24
20
|
*/
|
25
|
-
function countDiffInSeconds(start, end) {
|
21
|
+
export function countDiffInSeconds(start, end) {
|
26
22
|
return countDiffMs(start, end) / 1000;
|
27
23
|
}
|
28
|
-
exports.countDiffInSeconds = countDiffInSeconds;
|
29
24
|
/**
|
30
25
|
* Converts ISO 8601 date-time -string to Date object
|
31
26
|
* @param isoString to convert
|
32
27
|
*/
|
33
|
-
function dateFromIsoString(isoString) {
|
28
|
+
export function dateFromIsoString(isoString) {
|
34
29
|
const parsed = new Date(isoString);
|
35
30
|
if (!isValidDate(parsed)) {
|
36
31
|
throw new Error(`Could not parse iso date-time string: "${isoString}" to date`);
|
37
32
|
}
|
38
33
|
return parsed;
|
39
34
|
}
|
40
|
-
exports.dateFromIsoString = dateFromIsoString;
|
41
35
|
function isValidDate(d) {
|
42
36
|
return d instanceof Date && !isNaN(d.getTime());
|
43
37
|
}
|
44
38
|
/**
|
45
39
|
* Formats a date in UTC in the given format, regardless of system time zone
|
46
40
|
*/
|
47
|
-
function dateToUTCString(date, format) {
|
48
|
-
return
|
41
|
+
export function dateToUTCString(date, format) {
|
42
|
+
return formatInTimeZone(date, UTC, format);
|
49
43
|
}
|
50
|
-
exports.dateToUTCString = dateToUTCString;
|
51
44
|
//# sourceMappingURL=date-utils.js.map
|
@@ -1,18 +1,13 @@
|
|
1
|
-
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.GeoJsonLineString = exports.GeoJsonPoint = void 0;
|
4
|
-
class GeoJsonPoint {
|
1
|
+
export class GeoJsonPoint {
|
5
2
|
constructor(coordinates) {
|
6
3
|
this.type = "Point";
|
7
4
|
this.coordinates = coordinates;
|
8
5
|
}
|
9
6
|
}
|
10
|
-
|
11
|
-
class GeoJsonLineString {
|
7
|
+
export class GeoJsonLineString {
|
12
8
|
constructor(coordinates) {
|
13
9
|
this.type = "LineString";
|
14
10
|
this.coordinates = coordinates;
|
15
11
|
}
|
16
12
|
}
|
17
|
-
exports.GeoJsonLineString = GeoJsonLineString;
|
18
13
|
//# sourceMappingURL=geojson-types.js.map
|