diff --git a/infrastructure/services/.gitignore b/backend/.gitignore similarity index 100% rename from infrastructure/services/.gitignore rename to backend/.gitignore diff --git a/infrastructure/services/package-lock.json b/backend/package-lock.json similarity index 65% rename from infrastructure/services/package-lock.json rename to backend/package-lock.json index 53bec19f..8d2653df 100644 --- a/infrastructure/services/package-lock.json +++ b/backend/package-lock.json @@ -4,6 +4,15 @@ "lockfileVersion": 1, "requires": true, "dependencies": { + "accepts": { + "version": "1.3.5", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.5.tgz", + "integrity": "sha1-63d99gEXI6OxTopywIBcjoZ0a9I=", + "requires": { + "mime-types": "~2.1.18", + "negotiator": "0.6.1" + } + }, "ajv": { "version": "5.5.2", "resolved": "https://registry.npmjs.org/ajv/-/ajv-5.5.2.tgz", @@ -15,6 +24,11 @@ "json-schema-traverse": "^0.3.0" } }, + "array-flatten": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz", + "integrity": "sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=" + }, "array-uniq": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/array-uniq/-/array-uniq-1.0.2.tgz", @@ -102,6 +116,38 @@ "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-4.0.4.tgz", "integrity": "sha512-LDXpJKVzEx2/OqNbG9mXBNvHuiRL4PzHCGfnANHMJ+fv68Ads3exDVJeGDJws+AoNEuca93bU3q+S0woeUaCdg==" }, + "body-parser": { + "version": "1.18.3", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.3.tgz", + "integrity": "sha1-WykhmP/dVTs6DyDe0FkrlWlVyLQ=", + "requires": { + "bytes": "3.0.0", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.2", + "http-errors": "~1.6.3", + "iconv-lite": "0.4.23", + "on-finished": "~2.3.0", + "qs": "6.5.2", + "raw-body": "2.3.3", + "type-is": "~1.6.16" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", @@ -134,6 +180,11 @@ "resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz", "integrity": "sha1-+OcRMvf/5uAaXJaXpMbz5I1cyBk=" }, + "bytes": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.0.0.tgz", + "integrity": "sha1-0ygVQE1olpn4Wk6k+odV3ROpYEg=" + }, "caseless": { "version": "0.12.0", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", @@ -190,6 +241,26 @@ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", "dev": true }, + "content-disposition": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-0.5.2.tgz", + "integrity": "sha1-DPaLud318r55YcOoUXjLhdunjLQ=" + }, + "content-type": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz", + "integrity": "sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==" + }, + "cookie": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.3.1.tgz", + "integrity": "sha1-5+Ch+e9DtMi6klxcWpboBtFoc7s=" + }, + "cookie-signature": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.0.6.tgz", + "integrity": "sha1-4wOogrNCzD7oylE6eZmXNNqzriw=" + }, "core-util-is": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", @@ -234,6 +305,16 @@ "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" }, + "depd": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.2.tgz", + "integrity": "sha1-m81S4UwJd2PnSbJ0xDRu0uVgtak=" + }, + "destroy": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.0.4.tgz", + "integrity": "sha1-l4hXRCxEdJ5CBmE+N5RiBYJqvYA=" + }, "diff": { "version": "3.5.0", "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", @@ -257,18 +338,156 @@ "safe-buffer": "^5.0.1" } }, + "ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=" + }, + "encodeurl": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-1.0.2.tgz", + "integrity": "sha1-rT/0yG7C0CkyL1oCw6mmBslbP1k=" + }, + "escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha1-Aljq5NPQwJdN4cFpGI7wBR0dGYg=" + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "dev": true }, + "etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha1-Qa4u62XvpiJorr/qg6x9eSmbCIc=" + }, "events": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=", "dev": true }, + "express": { + "version": "4.16.3", + "resolved": "https://registry.npmjs.org/express/-/express-4.16.3.tgz", + "integrity": "sha1-avilAjUNsyRuzEvs9rWjTSL37VM=", + "requires": { + "accepts": "~1.3.5", + "array-flatten": "1.1.1", + "body-parser": "1.18.2", + "content-disposition": "0.5.2", + "content-type": "~1.0.4", + "cookie": "0.3.1", + "cookie-signature": "1.0.6", + "debug": "2.6.9", + "depd": "~1.1.2", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "finalhandler": "1.1.1", + "fresh": "0.5.2", + "merge-descriptors": "1.0.1", + "methods": "~1.1.2", + "on-finished": "~2.3.0", + "parseurl": "~1.3.2", + "path-to-regexp": "0.1.7", + "proxy-addr": "~2.0.3", + "qs": "6.5.1", + "range-parser": "~1.2.0", + "safe-buffer": "5.1.1", + "send": "0.16.2", + "serve-static": "1.13.2", + "setprototypeof": "1.1.0", + "statuses": "~1.4.0", + "type-is": "~1.6.16", + "utils-merge": "1.0.1", + "vary": "~1.1.2" + }, + "dependencies": { + "body-parser": { + "version": "1.18.2", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.18.2.tgz", + "integrity": "sha1-h2eKGdhLR9hZuDGZvVm84iKxBFQ=", + "requires": { + "bytes": "3.0.0", + "content-type": "~1.0.4", + "debug": "2.6.9", + "depd": "~1.1.1", + "http-errors": "~1.6.2", + "iconv-lite": "0.4.19", + "on-finished": "~2.3.0", + "qs": "6.5.1", + "raw-body": "2.3.2", + "type-is": "~1.6.15" + } + }, + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "qs": { + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.1.tgz", + "integrity": "sha512-eRzhrN1WSINYCDCbrz796z37LOe3m5tmW7RQf6oBntukAG1nmovJvhnwHHRMAfeoItc1m2Hk02WER2aQ/iqs+A==" + }, + "raw-body": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.2.tgz", + "integrity": "sha1-vNYMd9Prk83gBQKVw/N5OJvIj4k=", + "requires": { + "bytes": "3.0.0", + "http-errors": "1.6.2", + "iconv-lite": "0.4.19", + "unpipe": "1.0.0" + }, + "dependencies": { + "depd": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/depd/-/depd-1.1.1.tgz", + "integrity": "sha1-V4O04cRZ8G+lyif5kfPQbnoxA1k=" + }, + "http-errors": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.2.tgz", + "integrity": "sha1-CgAsyFcHGSp+eUbO7cERVfYOxzY=", + "requires": { + "depd": "1.1.1", + "inherits": "2.0.3", + "setprototypeof": "1.0.3", + "statuses": ">= 1.3.1 < 2" + } + }, + "setprototypeof": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.0.3.tgz", + "integrity": "sha1-ZlZ+NwQ+608E2RvWWMDL77VbjgQ=" + } + } + }, + "safe-buffer": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" + } + } + }, "extend": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.1.tgz", @@ -289,6 +508,35 @@ "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz", "integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I=" }, + "finalhandler": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-1.1.1.tgz", + "integrity": "sha512-Y1GUDo39ez4aHAw7MysnUD5JzYX+WaIj8I57kO3aEPT1fFRL4sr7mjei97FgnwhAyyzRYmQZaTHb2+9uZ1dPtg==", + "requires": { + "debug": "2.6.9", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "on-finished": "~2.3.0", + "parseurl": "~1.3.2", + "statuses": "~1.4.0", + "unpipe": "~1.0.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, "forever-agent": { "version": "0.6.1", "resolved": "https://registry.npmjs.org/forever-agent/-/forever-agent-0.6.1.tgz", @@ -304,6 +552,16 @@ "mime-types": "^2.1.12" } }, + "forwarded": { + "version": "0.1.2", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", + "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" + }, + "fresh": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-0.5.2.tgz", + "integrity": "sha1-PYyt2Q2XZWn6g1qx+OSyOhBWBac=" + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -370,6 +628,17 @@ "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", "dev": true }, + "http-errors": { + "version": "1.6.3", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.6.3.tgz", + "integrity": "sha1-i1VoC7S+KDoLW/TqLjhYC+HZMg0=", + "requires": { + "depd": "~1.1.2", + "inherits": "2.0.3", + "setprototypeof": "1.1.0", + "statuses": ">= 1.4.0 < 2" + } + }, "http-signature": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", @@ -380,6 +649,14 @@ "sshpk": "^1.7.0" } }, + "iconv-lite": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", + "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, "ieee754": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.8.tgz", @@ -401,6 +678,11 @@ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" }, + "ipaddr.js": { + "version": "1.8.0", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.8.0.tgz", + "integrity": "sha1-6qM9bd16zo9/b+DJygRA5wZzix4=" + }, "is-typedarray": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", @@ -536,6 +818,26 @@ "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", "integrity": "sha1-DdOXEhPHxW34gJd9UEyI+0cal6w=" }, + "media-typer": { + "version": "0.3.0", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", + "integrity": "sha1-hxDXrwqmJvj/+hzgAWhUUmMlV0g=" + }, + "merge-descriptors": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-1.0.1.tgz", + "integrity": "sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=" + }, + "methods": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/methods/-/methods-1.1.2.tgz", + "integrity": "sha1-VSmk1nZUE07cxSZmVoNbD4Ua/O4=" + }, + "mime": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.4.1.tgz", + "integrity": "sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ==" + }, "mime-db": { "version": "1.33.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.33.0.tgz", @@ -620,11 +922,24 @@ } } }, + "negotiator": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.1.tgz", + "integrity": "sha1-KzJxhOiZIQEXeyhWP7XnECrNDKk=" + }, "oauth-sign": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.8.2.tgz", "integrity": "sha1-Rqarfwrq2N6unsBWV4C31O/rnUM=" }, + "on-finished": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "integrity": "sha1-IPEzZIGwg811M3mSoWlxqi2QaUc=", + "requires": { + "ee-first": "1.1.1" + } + }, "once": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", @@ -634,12 +949,22 @@ "wrappy": "1" } }, + "parseurl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.2.tgz", + "integrity": "sha1-/CidTtiZMRlGDBViUyYs3I3mW/M=" + }, "path-is-absolute": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", "dev": true }, + "path-to-regexp": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-0.1.7.tgz", + "integrity": "sha1-32BBeABfUi8V60SQ5yR6G/qmf4w=" + }, "pathval": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", @@ -656,6 +981,15 @@ "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz", "integrity": "sha1-FQ4gt1ZZCtP5EJPyWk8q2L/zC6M=" }, + "proxy-addr": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.4.tgz", + "integrity": "sha512-5erio2h9jp5CHGwcybmxmVqHmnCBZeewlfJ0pex+UW7Qny7OOZXTtH56TGNyBizkgiOwhJtMKrVzDTeKcySZwA==", + "requires": { + "forwarded": "~0.1.2", + "ipaddr.js": "1.8.0" + } + }, "punycode": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz", @@ -681,6 +1015,22 @@ "array-uniq": "1.0.2" } }, + "range-parser": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.0.tgz", + "integrity": "sha1-9JvmtIeJTdxA3MlKMi9hEJLgDV4=" + }, + "raw-body": { + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-2.3.3.tgz", + "integrity": "sha512-9esiElv1BrZoI3rCDuOuKCBRbuApGGaDPQfjSflGxdy4oyzqghxu6klEkkVIvBje+FF0BX9coEv8KqW6X/7njw==", + "requires": { + "bytes": "3.0.0", + "http-errors": "1.6.3", + "iconv-lite": "0.4.23", + "unpipe": "1.0.0" + } + }, "readable-stream": { "version": "2.3.3", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", @@ -727,12 +1077,68 @@ "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, "sax": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.1.tgz", "integrity": "sha1-e45lYZCyKOgaZq6nSEgNgozS03o=", "dev": true }, + "send": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/send/-/send-0.16.2.tgz", + "integrity": "sha512-E64YFPUssFHEFBvpbbjr44NCLtI1AohxQ8ZSiJjQLskAdKuriYEP6VyGEsRDH8ScozGpkaX1BGvhanqCwkcEZw==", + "requires": { + "debug": "2.6.9", + "depd": "~1.1.2", + "destroy": "~1.0.4", + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "etag": "~1.8.1", + "fresh": "0.5.2", + "http-errors": "~1.6.2", + "mime": "1.4.1", + "ms": "2.0.0", + "on-finished": "~2.3.0", + "range-parser": "~1.2.0", + "statuses": "~1.4.0" + }, + "dependencies": { + "debug": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz", + "integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==", + "requires": { + "ms": "2.0.0" + } + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + } + } + }, + "serve-static": { + "version": "1.13.2", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-1.13.2.tgz", + "integrity": "sha512-p/tdJrO4U387R9oMjb1oj7qSMaMfmOyd4j9hOFoxZe2baQszgHcSWjuya/CiT5kgZZKRudHNOA0pYXOl8rQ5nw==", + "requires": { + "encodeurl": "~1.0.2", + "escape-html": "~1.0.3", + "parseurl": "~1.3.2", + "send": "0.16.2" + } + }, + "setprototypeof": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", + "integrity": "sha512-BvE/TwpZX4FXExxOxZyRGQQv651MSwmWKZGqvmPcRIjDqWub67kTKuIMx43cZZrS/cBBzwBcNDWoFxt2XEFIpQ==" + }, "sqlstring": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/sqlstring/-/sqlstring-2.3.0.tgz", @@ -753,6 +1159,11 @@ "tweetnacl": "~0.14.0" } }, + "statuses": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.4.0.tgz", + "integrity": "sha512-zhSCtt8v2NDrRlPQpCNtw/heZLtfUDqxBM1udqikb/Hbk52LK4nQSwr10u77iopCW5LsyHpuXS0GnEc48mLeew==" + }, "string_decoder": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz", @@ -805,6 +1216,20 @@ "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true }, + "type-is": { + "version": "1.6.16", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.16.tgz", + "integrity": "sha512-HRkVv/5qY2G6I8iab9cI7v1bOIdhm94dVjQCPFElW9W+3GeDOSHmy2EBYe4VTApuzolPcmgFTN3ftVJRKR2J9Q==", + "requires": { + "media-typer": "0.3.0", + "mime-types": "~2.1.18" + } + }, + "unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha1-sr9O6FFKrmFltIF4KdIbLvSZBOw=" + }, "url": { "version": "0.10.3", "resolved": "https://registry.npmjs.org/url/-/url-0.10.3.tgz", @@ -820,11 +1245,21 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" }, + "utils-merge": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/utils-merge/-/utils-merge-1.0.1.tgz", + "integrity": "sha1-n5VxD1CiZ5R7LMwSR0HBAoQn5xM=" + }, "uuid": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.2.1.tgz", "integrity": "sha512-jZnMwlb9Iku/O3smGWvZhauCf6cvvpKi4BKRiliS3cxnI+Gz9j5MEpTz2UFuXiKPJocb7gnsLHwiS05ige5BEA==" }, + "vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha1-IpnwLG3tMNSllhsLn3RSShj2NPw=" + }, "verror": { "version": "1.10.0", "resolved": "https://registry.npmjs.org/verror/-/verror-1.10.0.tgz", diff --git a/backend/package.json b/backend/package.json new file mode 100644 index 00000000..82729e99 --- /dev/null +++ b/backend/package.json @@ -0,0 +1,26 @@ +{ + "name": "carpal", + "version": "1.0.0", + "scripts": { + "test": "mocha './src/test/**/*.test.js'", + "refresh-db": "node ./src/main/database/index.js", + "refresh-test-db": "node ./src/test/database/refreshDatabase.js" + }, + "dependencies": { + "body-parser": "^1.18.3", + "express": "^4.16.3", + "jsonschema": "^1.2.4", + "jsonwebtoken": "^8.1.0", + "moment": "^2.22.2", + "mysql": "^2.15.0", + "randomstring": "^1.1.5", + "request": "^2.87.0", + "uuid": "^3.2.1" + }, + "devDependencies": { + "aws-sdk": "^2.250.1", + "chai": "^4.1.2", + "chai-exclude": "^1.0.9", + "mocha": "^5.2.0" + } +} diff --git a/infrastructure/services/props.json b/backend/props.json similarity index 100% rename from infrastructure/services/props.json rename to backend/props.json diff --git a/infrastructure/services/public_key b/backend/public_key similarity index 98% rename from infrastructure/services/public_key rename to backend/public_key index 7cb399d7..3aef10fc 100644 --- a/infrastructure/services/public_key +++ b/backend/public_key @@ -1,19 +1,19 @@ ------BEGIN CERTIFICATE----- -MIIDATCCAemgAwIBAgIJRppYVkre6ervMA0GCSqGSIb3DQEBCwUAMB4xHDAaBgNV -BAMTE2NhcnBhbC5hdS5hdXRoMC5jb20wHhcNMTgwNjAyMDMyOTA5WhcNMzIwMjA5 -MDMyOTA5WjAeMRwwGgYDVQQDExNjYXJwYWwuYXUuYXV0aDAuY29tMIIBIjANBgkq -hkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqvdMuabJiGr2ntuurtTZB/Mu6GNVyBQN -tnDWjktZIkPKqDiIyl2xxbufIpIw4qEQjOUlJDg4YSi8K9T/mCv+wRes65cjQcw2 -x0TNlZtdZ6vG8luWVWLvNE+DjqmsdMIgiLNirdKzNL3Ku2VvuFFvwcBAmXsqORT8 -LcLOE2etTqdPuBdC0sGzAMncf+3J+BxLoZNCpxJUsh1vbw6mz6/TJjGmmBzOC70o -LyXX9K+OevsW0bLkZeOJZAsGxDWDJ8B31TOarzvko66IlGukUSmmcg/PPiWdBjp5 -IHdjjSjKVdApVrZmltjR7glh3RswVrvqEKGa7dH62928alo2yi0zRwIDAQABo0Iw -QDAPBgNVHRMBAf8EBTADAQH/MB0GA1UdDgQWBBTqR7LijtYwkBuqB8txw+TDugz+ -6TAOBgNVHQ8BAf8EBAMCAoQwDQYJKoZIhvcNAQEL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oZIhvcNAQELBQADggEBAC9tL9V5NOs1OFkg +wEzRynYByZZpij2YHhZmnJxuIhdHKBf2+/AXcq4zN78y97D6lfdXVueJrB5OSm3R +6yhffgY7JSURIE96LfEjoh63Y7Viy1Pdk4A9aYWvpoAjlnIb+s3vg+13ChH4b5p5 +m4w3hOU8jJV2VoGooiTAWeHJsUYUPsMLneVKV7wv8Wl7sgLvO+xeRKpa+Sc71Cym +dLGt3NP+EP9zhFRPxpaCIW3rsMnEgSIuekFmVqzv7exMy+srY2V3p0uqiCHdjDQo +ZoumDRlverqMTWICzZsCRRpT4XcM4NlUMLw+zkQtymmDJGIBkZ7pxF+OfQXLRCHr +bOPxM6M= +-----END CERTIFICATE----- diff --git a/infrastructure/services.md b/backend/readme.md similarity index 87% rename from infrastructure/services.md rename to backend/readme.md index 0823afc8..24d36b66 100644 --- a/infrastructure/services.md +++ b/backend/readme.md @@ -1,9 +1,6 @@ -# Services -The services are created with Serverless and a few manual steps. - ## Initial Setup -### Serverless +### Deploying with serverless Run the following in the ./infrastructure/services directory to create the API Gateway config and lambdas: ``` npm install diff --git a/infrastructure/services/serverless.yml b/backend/serverless.yml similarity index 99% rename from infrastructure/services/serverless.yml rename to backend/serverless.yml index 6930d561..c164d29e 100644 --- a/infrastructure/services/serverless.yml +++ b/backend/serverless.yml @@ -13,6 +13,7 @@ provider: MYSQL_PW: ${file(./secrets.json):MYSQL_PW} MYSQL_PORT: ${file(./secrets.json):MYSQL_PORT} MYSQL_USER: carpaladmin + DOMAIN: carpal.org.au AUTH0_CLIENT_PUBLIC_KEY: ${file(./public_key)} vpc: diff --git a/infrastructure/services/src/main/auth/auth.js b/backend/src/main/auth/auth.js similarity index 100% rename from infrastructure/services/src/main/auth/auth.js rename to backend/src/main/auth/auth.js diff --git a/backend/src/main/auth/express/ExpressAuthApis.js b/backend/src/main/auth/express/ExpressAuthApis.js new file mode 100644 index 00000000..cc0e1cda --- /dev/null +++ b/backend/src/main/auth/express/ExpressAuthApis.js @@ -0,0 +1,135 @@ +const moment = require('moment'); +const fs = require('fs'); +const path = require('path'); +const jwt = require('jsonwebtoken'); + +function toBase64(value){ + return Buffer.from(value).toString('base64') +} + +class ExpressAuthApis { + constructor(app) { + this.app = app; + this.app.get('/authorize', this.auth.bind(this)); + this.app.get('/userinfo', this.userinfo.bind(this)); + this.app.get('/authcheck', this.authcheck.bind(this)); + this.app.get('/.well-known/jwks.json', this.wellKnown.bind(this)); + } + + wellKnown(req, res) { + let expiry = moment().add(100, 'd'); + console.log(req.query); + let jwks = fs.readFileSync(path.resolve(__dirname, '../../config/express/certs/jwks.json')); + res.status(200).send(JSON.parse(jwks)); + } + + auth(req, res) { + let queryParams = req.query || {}; + let nonce = queryParams.nonce; + let state = queryParams.state; + let expiry = moment().add(100, 'd'); + let date = expiry.toDate(); + let host = req.get('host'); + + let urls = { + driver: this.extractUrl(queryParams, expiry, state, date, host, this._getDriver()), + admin: this.extractUrl(queryParams, expiry, state, date, host, this._getAdmin()), + falicitator: this.extractUrl(queryParams, expiry, state, date, host, this._getFacilitator()) + }; + + let redirectNow = queryParams.loginAs ? `window.location = "${urls[queryParams.loginAs]}"` : ''; + res.status(200).send(` + + +
+
+
+ `); + } + + extractUrl(queryParams, expiry, state, date, host, userInfo) { + let {accessToken, jwtToken} = this._authAs(queryParams, host, userInfo, expiry); + let url = `${queryParams.redirect_uri}#access_token=${accessToken}&id_token=${jwtToken}&refresh_token=6789&state=${state}&expires_in=${date.getTime()}`; + return url; + } + + _authAs(queryParams, host, userInfo, expiry) { + let payload = this._completeJWT(userInfo, host, expiry.toDate(), queryParams.nonce); + + let accessToken = userInfo.role; + let cert = fs.readFileSync(path.resolve(__dirname, '../../config/express/certs/private.key')); + let jwtToken = jwt.sign(payload, cert, {algorithm: 'RS256'}); + return {accessToken, jwtToken}; + } + + _completeJWT(data, host, expiryDate, nonce){ + let result = { + "nonce": nonce.replace("@", "~"), + "iss": `https://${host}/`, + "aud": '1234', + "exp": expiryDate.getTime() / 1000, + "nbf": new Date().getTime() / 1000, + ...this._uriBased(data, `https://${host}/`) + }; + return result; + } + + _uriBased(data, uri){ + let result = {}; + Reflect.ownKeys(data).forEach(k => result[uri + k] = data[k]); + return result; + } + + _getDriver(uri){ + let data = { + "email": "test-driver@carpal.com", + "gender": "male", + "car": "suv", + "role": "driver" + }; + return uri ? this._uriBased(data, uri) : data; + } + + _getAdmin(uri){ + let data = { + "email": "test-admin@carpal.com", + "gender": "male", + "role": "admin" + }; + return uri ? this._uriBased(data, uri) : data; + } + + _getFacilitator(uri){ + let data = { + "email": "test-facilitator@carpal.com", + "gender": "female", + "role": "facilitator" + }; + return uri ? this._uriBased(data, uri) : data; + } + + userinfo(req, res){ + let uri = req.get('origin') + '/'; + let tokens = (req.get('authorization') || '').split(' '); + switch (tokens[1]){ + case 'admin': + return res.status(200).send(this._getAdmin(uri)); + case 'facilitator': + return res.status(200).send(this._getFacilitator(uri)); + default: + return res.status(200).send(this._getDriver(uri)); + } + } + + authcheck(req, res){ + res.status(200).send({ name: 'Foo' }); + } + +} + +module.exports = ExpressAuthApis; \ No newline at end of file diff --git a/infrastructure/services/src/main/auth/loggedin.js b/backend/src/main/auth/loggedin.js similarity index 100% rename from infrastructure/services/src/main/auth/loggedin.js rename to backend/src/main/auth/loggedin.js diff --git a/backend/src/main/config/express/certs/certificate.p12 b/backend/src/main/config/express/certs/certificate.p12 new file mode 100644 index 00000000..59e3a11f Binary files /dev/null and b/backend/src/main/config/express/certs/certificate.p12 differ diff --git a/backend/src/main/config/express/certs/certificate.pem b/backend/src/main/config/express/certs/certificate.pem new file mode 100644 index 00000000..8bd84ba7 --- /dev/null +++ b/backend/src/main/config/express/certs/certificate.pem @@ -0,0 +1,18 @@ +-----BEGIN CERTIFICATE----- +MIIC9jCCAd4CCQDfAD2g+Y7RJzANBgkqhkiG9w0BAQsFADA9MQswCQYDVQQGEwJh +dTEMMAoGA1UECAwDbnN3MQ8wDQYDVQQHDAZzeWRuZXkxDzANBgNVBAoMBmNhcnBh +bDAeFw0xODA4MjYwODI0NDBaFw0xOTA4MjYwODI0NDBaMD0xCzAJBgNVBAYTAmF1 +MQwwCgYDVQQIDANuc3cxDzANBgNVBAcMBnN5ZG5leTEPMA0GA1UECgwGY2FycGFs +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8HoBueljoBmBbe54tbu5 +ge0SFtebybklIKvmghgqR/Busi4azNwtGYBvvA0Ibodi/OGFJPvH2L89RuwWpxvp +Nb74NHEGlwN8QNq7jUSLrcgZ13zc9y4N030Xis4YNGO/dnsweGfqG/I3LjEl/ZJV +fDf5c+cZvFep7Z3OaPz9UawE5MkCA+GT5hycTLYhLNu4ODQfTJu3YmMHI5J0GyaF ++80Rj3vZ4XOwAgIlQk3uFVOrKswFvN/WM7HZTLwW6gX3SbG7LaCEE1toBoEtm3Nf +vKq2QaAe1AcjXWGgF7UEjzZ0B1kkp/LyV/fJkMxeQL5r3pz8tBIJzH478t3IuU22 +HQIDAQABMA0GCSqGSIb3DQEBCwUAA4IBAQBg5xdJx/0weyC5FXlc4i5cajs3ziEX +oGr704AgK3A+DNPkNPy5ZwfG7Axz0PSzrLWRAWhjnAGC4x+AcdGJtkoZ6/RfbkVO +s0cI7dYNLlGbBIwyiZnC36CtMYJ1blUBPZGF7hEdQER2Bq0yfgju9yr6YrpGwuUo +Kwnsl/nj03MnwbUc75nIPZRDLJmx7QsoTJm5R88l3MjCqcD6xSA9pX9wugnfKCNq +RRXV2ZRxiUsgAhcMEkyglYrawZ4gQi5Rp6/jNNjq0c5ARBYCjcZcBkk2buuKAZjv +AkXAAT/3E01s3af3+XXTEkfTj4/f84FloutSUVqXuLgNIYEztS9fHVho +-----END CERTIFICATE----- diff --git a/backend/src/main/config/express/certs/jwks.json b/backend/src/main/config/express/certs/jwks.json new file mode 100644 index 00000000..816546a5 --- /dev/null +++ b/backend/src/main/config/express/certs/jwks.json @@ -0,0 +1,17 @@ +{ + "keys": [ + { + "kty": "RSA", + "n": "wkR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SjJzm7604VIXpGe9wwx2N8yjw97t19tpZvl7qZv56OhwbY7PPykSQIP5Qv6URGHb09LcUUEvOXciBHX-oMMh2-sLUeDiZr0vIRP1L7jzNQF2jPPnf6LvVcKAjvE8n3OxFnqj98VBK8R8yD9nMwRfc5gLy4LprONL8GzBtO1esb3OWM1uvy7wKDauSR6L8O_n2-ivaCUYvWO8adxKjhrY2tin4QlRv_Lnqqi5iuk8dEsPaJL3OPrVKGEGIq-4oAErt-5_ENVdnqDEMdhopPSf0oQl_s0agHcmBqBQ", + "dq": "tjsWSB-gYH4jUdwCMOv6Sx3Tbg3obeppJaf0PizHJaOEHHXj1FeRoj7t7oeNMBXHhtmeezDl2Xkgp3eQ_s8eirCjnsjFu68VagS2wJUBeWatH32l-TGoMtVVjyvExYzB7M-cTc8RDy6LU9vtn0b0sE7_2J30r8rCL0EfUokNawmESuNhulIXbqghcFKs6K5MEaBRzndS0zAbqlFDmCtRDjDVbXNH3wtuAssJLjTV24BEYdfyFWIzA3plbrmCUYMy_iSu1jivygb33SnxcVUM_RoEZUfXNYDfNaB5PHYcf5bPu0PtGPIZNuVNWNf6wbj74iBciXj_i8tT4qz_aE2xxQ", + "qi": "6R57N1Qyk2GUPUGJ0Yz50c9ooK5basDNXIKnzYGmmqaZRRF-cMywIwiR5PbfIyAd6MuW4tIoEvvv3VGW6NszpH-c6YhRCFBW4kvuv4lzdKNHpRP57MuFJiXlBe0KKso4G4vMaEnsx7ifNsWVjzNWgmNx06avpng7VTdyZSFbxe_JVRNUbkN5WJtZsh-IXF9L9LMsEE05r-VGnsjAz9ShD9-R-_TUk4Wsqzhm-ILo0NNCHfsW_qvC7kdysRa96tncMeQ45xuj_BuG2l6p8gdIjvGDErvfG4JhrdY3kyX7G_dISH5Do1U8mkIJQ2I-Z49MAN5BrBHmpeCSt8b1KUHzYg", + "alg": "RS256", + "use": "sig" + } + ] +} \ No newline at end of file diff --git a/backend/src/main/config/express/certs/key.pem b/backend/src/main/config/express/certs/key.pem new file mode 100644 index 00000000..ac797abe --- /dev/null +++ b/backend/src/main/config/express/certs/key.pem @@ -0,0 +1,28 @@ +-----BEGIN PRIVATE KEY----- +MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDwegG56WOgGYFt +7ni1u7mB7RIW15vJuSUgq+aCGCpH8G6yLhrM3C0ZgG+8DQhuh2L84YUk+8fYvz1G +7BanG+k1vvg0cQaXA3xA2ruNRIutyBnXfNz3Lg3TfReKzhg0Y792ezB4Z+ob8jcu +MSX9klV8N/lz5xm8V6ntnc5o/P1RrATkyQID4ZPmHJxMtiEs27g4NB9Mm7diYwcj +knQbJoX7zRGPe9nhc7ACAiVCTe4VU6sqzAW839YzsdlMvBbqBfdJsbstoIQTW2gG +gS2bc1+8qrZBoB7UByNdYaAXtQSPNnQHWSSn8vJX98mQzF5AvmvenPy0EgnMfjvy +3ci5TbYdAgMBAAECggEAQzjX4rBrOQXoOGLBO4wOf1NWCyyaT/mBd3CWLyeyKgn7 +57Mbqsihks9kbJz4Dm2qLiacoYoAg4ZyCrFUY8JZnryThZVS0kQXJ8n9Q7A1m46k +Kqis3CvzkXsWaabS/VIk42nsUrw5pTZAVplGlWuimebLxKqFdzDKP7ItUQvnhDyX +JQ1eIfbdf/Xf+QosNDSMyVLC2z3hnyP/Q+ajRS034wKNmkth7GPIdwPbti5nbVHD +m+QzL/wI13dyp+3tnnNVuVGeelWcqiJ5+5v7wjyuRDmk/POp0ETvX1EYO3xm03Jw +XWwA/kvX13n2ILgHry1gNV/Nqe13+gQWSyUJBzgfwQKBgQD8PfmpR4loz1Xj1p5o +xahJL3MHRaE3LHtl8RNoeUSOILIat2LeFrIHRETnd7/XZ/3knLeexqAT6XD/bkfg +iDuZIazU/+k8QCZX3NXhUvl2ja7zENDQI9O3q5FNKtQpBwOh0rUa6+koJLtQSWBc +7SMp3G8ZITDujyrgb0SnZHRWZwKBgQD0Dyi8A9IG/0DL7ZENKbSmSdKWJ5xqydY2 +cFh9RRb/dFX7It8hBXp+HCRGJaJ3xVp1NFCO7KVdZ/xLO63RmQBqgAHiNe5oP26w +fzeaj644xABUM9GsFxDFSoNOgGB9aBjVHTctI9LtQYUrxVLYwfwTsFk4nz6JXDwZ +ysMa5mJU2wKBgQCo8QFkJWuc7TEDll0moyvhSIxsVHBzubE0R9DN6lrGLpPbXPQ0 +91Jpl4nm1ceBiD7+fRBmoXXZoEJ0cfJmKhhwqaNOTdBy8Cw+MMR3U9GNW7vPRHX2 +0egdXiXFX2gVyoLeQXfW/iZ9IozqaxrFYnZotSEb3aUeQnlfNGbxDlD1BQKBgQDG +w6nLJdlhNXUSIFKnw7WKUEkfXPc4yVSaVXjb3O7T8W0s8MOD4zBVkJnCP1hH7wSy +u354SCaNIekJZHs1XkRGeCYQkxes8yw0tgcU67taI9aYvPMgElDoPL0fq9HpkGPY +/Mg5DRn1fAz3Dudf/OxNJKwlPxvxRprz7nxjZgnjTQKBgDfW/bjsMGn/XFodVsqS +j3CcNLcIqRMw4fhiRTO6AfZL9wMhqglzt2uZuXibPz3+7aN/QeqRm1vWwjC+ckzK +UUHDvbMJqBJ/Wj9bpeVifjxML8yRkhWnxlCmxWywyFNHToBaI0/1FT+jEsYfd1bE +TX6ZfR8fcsygXYzco244LGmY +-----END PRIVATE KEY----- diff --git a/backend/src/main/config/express/certs/private.key b/backend/src/main/config/express/certs/private.key new file mode 100644 index 00000000..8ca6861a --- /dev/null +++ b/backend/src/main/config/express/certs/private.key @@ -0,0 +1,51 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIJKQIBAAKCAgEAwkRco/VjxfT/Zp2FCN+WnKTls9GaoRpUcrvwukH65u+Q0R9J +UdjJiUQHxCgkBAOzEmsIeeEYRW19+E3Yk7fYzftbaD5cC9nZyf3jA9fF9kbbnD2w +PFtk2Go9g5+TtWVKB4r/dd9D88tNAfTpa4b20uh9Uj92E6H0+fw7ZSg4kkkMv7mb +0utRtsERi8+6hAu/kv3b7aayryBYVxKwwgkuXJ0SHJ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YzW6/LvAoNq5JHovw7+fb6K9oJRi9Y7xp3EqOGtja2KfhCVG/8u +eqqLmK6Tx0Sw9okvc4+tUoYQYir7igASu37n8Q1V2eoMQx2Gik9J/ShCX+zRqAdy +YGoFAoIBAQC2OxZIH6BgfiNR3AIw6/pLHdNuDeht6mklp/Q+LMclo4QcdePUV5Gi +Pu3uh40wFceG2Z57MOXZeSCnd5D+zx6KsKOeyMW7rxVqBLbAlQF5Zq0ffaX5Magy +1VWPK8TFjMHsz5xNzxEPLotT2+2fRvSwTv/YnfSvysIvQR9SiQ1rCYRK42G6Uhdu +qCFwUqzorkwRoFHOd1LTMBuqUUOYK1EOMNVtc0ffC24CywkuNNXbgERh1/IVYjMD +emVuuYJRgzL+JK7WOK/KBvfdKfFxVQz9GgRlR9c1gN81oHk8dhx/ls+7Q+0Y8hk2 +5U1Y1/rBuPviIFyJeP+Ly1PirP9oTbHFAoIBAQDpHns3VDKTYZQ9QYnRjPnRz2ig +rltqwM1cgqfNgaaapplFEX5wzLAjCJHk9t8jIB3oy5bi0igS++/dUZbo2zOkf5zp +iFEIUFbiS+6/iXN0o0elE/nsy4UmJeUF7Qoqyjgbi8xoSezHuJ82xZWPM1aCY3HT +pq+meDtVN3JlIVvF78lVE1RuQ3lYm1myH4hcX0v0sywQTTmv5UaeyMDP1KEP35H7 +9NSThayrOGb4gujQ00Id+xb+q8LuR3KxFr3q2dwx5DjnG6P8G4baXqnyB0iO8YMS +u98bgmGt1jeTJfsb90hIfkOjVTyaQglDYj5nj0wA3kGsEeal4JK3xvUpQfNi +-----END RSA PRIVATE KEY----- diff --git a/backend/src/main/config/express/certs/public.key b/backend/src/main/config/express/certs/public.key new file mode 100644 index 00000000..84babe0a --- /dev/null +++ b/backend/src/main/config/express/certs/public.key @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDCRFyj9WPF9P9mnYUI35acpOWz0ZqhGlRyu/C6Qfrm75DRH0lR2MmJRAfEKCQEA7MSawh54RhFbX34TdiTt9jN+1toPlwL2dnJ/eMD18X2RtucPbA8W2TYaj2Dn5O1ZUoHiv9130Pzy00B9OlrhvbS6H1SP3YTofT5/DtlKDiSSQy/uZvS61G2wRGLz7qEC7+S/dvtprKvIFhXErDCCS5cnRIcncD2jVcvviLyXq+4l1yB19IzxKf0ZgVt7O4BHokFtN2LnmRJh/TqsmqJQf7USnfJG/syBbBZ7xb9NFViMaBvAlnFN2MTcmz6FTyryanr9xC2CMn3BjYSOKWJg9X9W/2/U19YV/6Wh2p7Z4kJx9goUN6neZR5XilH9MnKltFa2VyfK4s15J4vi5ukdnyNYpaAcnmJl3Y7b6zXoH+0R9FnRwIRg2588ZtnM8azDpiuEon7aTECSufsUk8rc1cwjeKYQNDEKIQmXTsNmbkWD5xCwbgXuz9XwAbiz8FFNLoEEe0CQqm338bqfFYI5Yw92NNtcIcZ2HYiSu6Tin4CV69g24RuE7IbNLIcRzUmCy7y9I6Z9+HPD2vl1aMhn5/NZlMSHQ9kN5zVv7bcO/18eeqOq3HeCitGDxwq/m7YpL8l+FtCruW4JmPRjLyfpxOdhZvNvmbj580r4sNu6THRAQ== test@carpal.com diff --git a/backend/src/main/controller/awsLambdaApis.js b/backend/src/main/controller/awsLambdaApis.js new file mode 100644 index 00000000..ea472fad --- /dev/null +++ b/backend/src/main/controller/awsLambdaApis.js @@ -0,0 +1,14 @@ +const CreateRideService = require('../rides/CreateRideService'); +const ListRidesService = require('../rides/ListRidesService'); +const DatabaseManager = require('../database/DatabaseManager'); +const AwsLambdaRideApis = require('../rides/aws/AwsLambdaRideApis'); +const databaseManager = new DatabaseManager(); + +const createRideService = new CreateRideService(databaseManager); +const listRidesService = new ListRidesService(databaseManager); + +const rides = new AwsLambdaRideApis(createRideService, listRidesService); + +module.exports = { + rides: rides +}; \ No newline at end of file diff --git a/backend/src/main/controller/expressApis.js b/backend/src/main/controller/expressApis.js new file mode 100644 index 00000000..53c2013a --- /dev/null +++ b/backend/src/main/controller/expressApis.js @@ -0,0 +1,45 @@ +const express = require('express'); +const fs = require('fs'); +const CreateRideService = require('../rides/CreateRideService'); +const ListRidesService = require('../rides/ListRidesService'); +const DatabaseManager = require('../database/DatabaseManager'); +const ExpressRideApis = require('../rides/express/ExpressRidesApis'); +const ExpressAuthApis = require('../auth/express/ExpressAuthApis'); +const bodyParser = require('body-parser'); +const databaseManager = new DatabaseManager(); + +const https = require('https'); +const http = require('http'); + +process.on('uncaughtException', function (err) { + console.log(err); +}); + +process.env.DOMAIN = 'localhost:8081'; + +const createRideService = new CreateRideService(databaseManager); +const listRidesService = new ListRidesService(databaseManager); +const app = express(); +app.use(bodyParser.json()); // for parsing application/json +app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded + +app.use(function(req, res, next) { + res.header("Access-Control-Allow-Origin", "*"); + res.header("Access-Control-Allow-Headers", "*"); + next(); +}); + +new ExpressAuthApis(app); +new ExpressRideApis(app, createRideService, listRidesService); + +const options = { + key: fs.readFileSync('../config/express/certs/key.pem'), + cert: fs.readFileSync('../config/express/certs/certificate.pem') +}; + +http.createServer(app).listen(8080, () => { + console.log("HTTP Server started and listening on port 8080") +}); +https.createServer(options, app).listen(8081, () => { + console.log("HTTPS Server started and listening on port 8081") +}); \ No newline at end of file diff --git a/infrastructure/services/src/main/database/DatabaseManager.js b/backend/src/main/database/DatabaseManager.js similarity index 100% rename from infrastructure/services/src/main/database/DatabaseManager.js rename to backend/src/main/database/DatabaseManager.js diff --git a/backend/src/main/database/RefreshDatabase.js b/backend/src/main/database/RefreshDatabase.js new file mode 100644 index 00000000..46f731e1 --- /dev/null +++ b/backend/src/main/database/RefreshDatabase.js @@ -0,0 +1,30 @@ +const fs = require('fs'); +const path = require('path'); + +const changeSet = [ + '2018-08-04-1-create-database.sql', + '2018-08-04-2-create-location-table.sql', + '2018-08-04-3-create-rides-table.sql', + '2018-08-04-4-create-driver-table.sql', + '2018-08-04-5-create-driver_car-table.sql', + '2018-08-04-6-create-driver_ride-table.sql' +]; + +class RefreshDatabase { + constructor(databaseManager) { + this.databaseManager = databaseManager; + } + + async executeAll() { + for (let fileName of changeSet) { + await this.execute(fileName); + } + } + + async execute(fileName) { + let sql = fs.readFileSync(path.resolve(__dirname, './changes/' + fileName)).toString().trim(); + return this.databaseManager.query(sql); + } +} + +module.exports = RefreshDatabase; \ No newline at end of file diff --git a/backend/src/main/database/changes/2018-08-04-1-create-database.sql b/backend/src/main/database/changes/2018-08-04-1-create-database.sql new file mode 100644 index 00000000..95e1904f --- /dev/null +++ b/backend/src/main/database/changes/2018-08-04-1-create-database.sql @@ -0,0 +1 @@ +CREATE DATABASE IF NOT EXISTS carpal; \ No newline at end of file diff --git a/infrastructure/services/src/main/database/changes/2018-08-04-1-create-location-table.sql b/backend/src/main/database/changes/2018-08-04-2-create-location-table.sql similarity index 69% rename from infrastructure/services/src/main/database/changes/2018-08-04-1-create-location-table.sql rename to backend/src/main/database/changes/2018-08-04-2-create-location-table.sql index 5adbfdda..884ad0a3 100644 --- a/infrastructure/services/src/main/database/changes/2018-08-04-1-create-location-table.sql +++ b/backend/src/main/database/changes/2018-08-04-2-create-location-table.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS location ( +CREATE TABLE IF NOT EXISTS carpal.location ( id INT(11), location GEOMETRY NOT NULL, suburb TEXT, diff --git a/infrastructure/services/src/main/database/changes/2018-08-04-2-create-rides-table.sql b/backend/src/main/database/changes/2018-08-04-3-create-rides-table.sql similarity index 92% rename from infrastructure/services/src/main/database/changes/2018-08-04-2-create-rides-table.sql rename to backend/src/main/database/changes/2018-08-04-3-create-rides-table.sql index acff5563..c01c83f1 100644 --- a/infrastructure/services/src/main/database/changes/2018-08-04-2-create-rides-table.sql +++ b/backend/src/main/database/changes/2018-08-04-3-create-rides-table.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS rides ( +CREATE TABLE IF NOT EXISTS carpal.rides ( id INT(11) AUTO_INCREMENT PRIMARY KEY, client VARCHAR(255), facilitatorEmail VARCHAR(255), diff --git a/infrastructure/services/src/main/database/changes/2018-08-04-3-create-driver-table.sql b/backend/src/main/database/changes/2018-08-04-4-create-driver-table.sql similarity index 52% rename from infrastructure/services/src/main/database/changes/2018-08-04-3-create-driver-table.sql rename to backend/src/main/database/changes/2018-08-04-4-create-driver-table.sql index 9f8fe8f0..18ad69f8 100644 --- a/infrastructure/services/src/main/database/changes/2018-08-04-3-create-driver-table.sql +++ b/backend/src/main/database/changes/2018-08-04-4-create-driver-table.sql @@ -1,7 +1,7 @@ -CREATE TABLE IF NOT EXISTS driver ( +CREATE TABLE IF NOT EXISTS carpal.driver ( id INT(11) PRIMARY KEY, name VARCHAR(255), - phone VARCHAR(20), + phoneNumber VARCHAR(20), facebookUrl VARCHAR(255) ); diff --git a/infrastructure/services/src/main/database/changes/2018-08-04-4-create-driver_car-table.sql b/backend/src/main/database/changes/2018-08-04-5-create-driver_car-table.sql similarity index 79% rename from infrastructure/services/src/main/database/changes/2018-08-04-4-create-driver_car-table.sql rename to backend/src/main/database/changes/2018-08-04-5-create-driver_car-table.sql index 025dc814..747b7462 100644 --- a/infrastructure/services/src/main/database/changes/2018-08-04-4-create-driver_car-table.sql +++ b/backend/src/main/database/changes/2018-08-04-5-create-driver_car-table.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS driver_car ( +CREATE TABLE IF NOT EXISTS carpal.driver_car ( id INT(11) PRIMARY KEY, driver_id INT(11), carModel VARCHAR(255), diff --git a/infrastructure/services/src/main/database/changes/2018-08-04-5-create-driver_ride-table.sql b/backend/src/main/database/changes/2018-08-04-6-create-driver_ride-table.sql similarity index 83% rename from infrastructure/services/src/main/database/changes/2018-08-04-5-create-driver_ride-table.sql rename to backend/src/main/database/changes/2018-08-04-6-create-driver_ride-table.sql index bbac59f7..44aee2b2 100644 --- a/infrastructure/services/src/main/database/changes/2018-08-04-5-create-driver_ride-table.sql +++ b/backend/src/main/database/changes/2018-08-04-6-create-driver_ride-table.sql @@ -1,4 +1,4 @@ -CREATE TABLE IF NOT EXISTS driver_ride ( +CREATE TABLE IF NOT EXISTS carpal.driver_ride ( id INT(11) PRIMARY KEY, driver_id INT(11), ride_id INT(11), diff --git a/backend/src/main/database/index.js b/backend/src/main/database/index.js new file mode 100644 index 00000000..5c3c6cd3 --- /dev/null +++ b/backend/src/main/database/index.js @@ -0,0 +1,11 @@ +const DatabaseManager = require("./DatabaseManager"); +const RefreshDatabase = require("./RefreshDatabase"); +const refreshDatabase = new RefreshDatabase(new DatabaseManager()); + +process.on('unhandledRejection', error => { + console.log('unhandledRejection', error); +}); + + +refreshDatabase.executeAll(refreshDatabase) + .catch(e => console.log(e)); \ No newline at end of file diff --git a/infrastructure/services/src/main/notification/notify.js b/backend/src/main/notification/notify.js similarity index 100% rename from infrastructure/services/src/main/notification/notify.js rename to backend/src/main/notification/notify.js diff --git a/infrastructure/services/src/main/rides/Coordinates.js b/backend/src/main/rides/Coordinates.js similarity index 100% rename from infrastructure/services/src/main/rides/Coordinates.js rename to backend/src/main/rides/Coordinates.js diff --git a/infrastructure/services/src/main/rides/CreateRideController.js b/backend/src/main/rides/CreateRideService.js similarity index 97% rename from infrastructure/services/src/main/rides/CreateRideController.js rename to backend/src/main/rides/CreateRideService.js index c012cb41..a576e05c 100644 --- a/infrastructure/services/src/main/rides/CreateRideController.js +++ b/backend/src/main/rides/CreateRideService.js @@ -6,7 +6,7 @@ const RideStatus = require('./RideStatus'); const RideRepository = require('./RideRepository'); const Coordinates = require('./Coordinates'); -class CreateRideController { +class CreateRideService { constructor(databaseManager) { this._databaseManager = databaseManager; @@ -69,4 +69,4 @@ class CreateRideController { } } -module.exports = CreateRideController; \ No newline at end of file +module.exports = CreateRideService; \ No newline at end of file diff --git a/infrastructure/services/src/main/rides/ListRidesController.js b/backend/src/main/rides/ListRidesService.js similarity index 94% rename from infrastructure/services/src/main/rides/ListRidesController.js rename to backend/src/main/rides/ListRidesService.js index 50208eea..84e077e8 100644 --- a/infrastructure/services/src/main/rides/ListRidesController.js +++ b/backend/src/main/rides/ListRidesService.js @@ -2,7 +2,7 @@ const RideRepository = require('./RideRepository'); -class ListRidesController { +class ListRidesService { constructor(databaseManager) { this._databaseManager = databaseManager; @@ -34,4 +34,4 @@ class ListRidesController { } } -module.exports = ListRidesController; \ No newline at end of file +module.exports = ListRidesService; \ No newline at end of file diff --git a/infrastructure/services/src/main/rides/RideRepository.js b/backend/src/main/rides/RideRepository.js similarity index 100% rename from infrastructure/services/src/main/rides/RideRepository.js rename to backend/src/main/rides/RideRepository.js diff --git a/infrastructure/services/src/main/rides/RideStatus.js b/backend/src/main/rides/RideStatus.js similarity index 100% rename from infrastructure/services/src/main/rides/RideStatus.js rename to backend/src/main/rides/RideStatus.js diff --git a/backend/src/main/rides/aws/AwsLambdaRideApis.js b/backend/src/main/rides/aws/AwsLambdaRideApis.js new file mode 100644 index 00000000..976aefbd --- /dev/null +++ b/backend/src/main/rides/aws/AwsLambdaRideApis.js @@ -0,0 +1,26 @@ +const decodeJwt = require('../../utils/jwt').decodeJwt; + +class AwsLambdaRideApis { + constructor(createRideService, + listRidesService) { + this.createRideService = createRideService; + this.listRidesService = listRidesService; + } + + create(event, context, callback) { + let loginData = decodeJwt(event); + return this.createRideService.createRide(JSON.parse(event.body), loginData) + .then(result => callback(null, result)) + .catch(result => callback(result)); + } + + list(event, context, callback) { + let loginData = decodeJwt(event); + let queryParams = event.queryStringParameters || {}; + return this.listRidesService.listRides(queryParams, loginData) + .then(result => callback(null, result)) + .catch(result => callback(result)); + } +} + +module.exports = AwsLambdaRideApis; \ No newline at end of file diff --git a/backend/src/main/rides/express/ExpressRidesApis.js b/backend/src/main/rides/express/ExpressRidesApis.js new file mode 100644 index 00000000..ecbca24f --- /dev/null +++ b/backend/src/main/rides/express/ExpressRidesApis.js @@ -0,0 +1,47 @@ +const AwsLambdaRideApis = require('../aws/AwsLambdaRideApis'); +class ExpressRideApis { + constructor(app, + createRideService, + listRidesService) { + this.app = app; + this.createRideService = createRideService; + this.listRidesService = listRidesService; + this.awsLambdaRideApis = new AwsLambdaRideApis(createRideService, listRidesService); + this.app.post('/rides', this.create.bind(this)); + this.app.get('/rides', this.list.bind(this)); + } + + create(req, res) { + this.awsLambdaRideApis.create(this._extractAwsEvent(req), {}, (error, result) => { + if(error){ + return res.status(500).send(error); + } + res.status(200).send(result); + }); + } + + list(req, res) { + this.awsLambdaRideApis.list(this._extractAwsEvent(req), {}, (error, result) => { + if(error){ + return res.status(500).send(error); + } + res.status(200).send(result); + }); + // let queryParams = req.query || {}; + // return this.listRidesService.listRides(queryParams, req.loginData) + // .then(result => res.status(200).json(result)) + // .catch(error => res.send(500).send(error)); + } + + _extractAwsEvent(req){ + let event = { + headers: { + Authorization: req.get('authorization') + }, + body: JSON.stringify(req.body) + }; + return event; + } +} + +module.exports = ExpressRideApis; \ No newline at end of file diff --git a/infrastructure/services/src/main/rides/findone.js b/backend/src/main/rides/findone.js similarity index 100% rename from infrastructure/services/src/main/rides/findone.js rename to backend/src/main/rides/findone.js diff --git a/infrastructure/services/src/main/rides/rides-mapper.js b/backend/src/main/rides/rides-mapper.js similarity index 100% rename from infrastructure/services/src/main/rides/rides-mapper.js rename to backend/src/main/rides/rides-mapper.js diff --git a/infrastructure/services/src/main/rides/update.js b/backend/src/main/rides/update.js similarity index 100% rename from infrastructure/services/src/main/rides/update.js rename to backend/src/main/rides/update.js diff --git a/infrastructure/services/src/main/schema/ride.json b/backend/src/main/schema/ride.json similarity index 100% rename from infrastructure/services/src/main/schema/ride.json rename to backend/src/main/schema/ride.json diff --git a/backend/src/main/utils/jwt.js b/backend/src/main/utils/jwt.js new file mode 100644 index 00000000..27586656 --- /dev/null +++ b/backend/src/main/utils/jwt.js @@ -0,0 +1,26 @@ +const jsonwebtoken = require('jsonwebtoken'); + +module.exports.decodeJwt = (event) => { + if (!event.headers.Authorization) { + return; + } + const tokenValue = event + .headers + .Authorization + .split(' ')[1]; + + try { + const domain = process.env.DOMAIN || 'carpal.org.au'; + const decodedToken = jsonwebtoken.decode(tokenValue); + const claims = {}; + claims.email = decodedToken[`https://${domain}/email`]; + claims.role = decodedToken[`https://${domain}/role`]; + if (claims.role === 'driver') { + claims.driverGender = decodedToken[`https://${domain}/gender`]; + claims.car = decodedToken[`https://${domain}/car`]; + } + return claims; + } catch (err) { + console.log('catch error. Invalid token', err); + } +} \ No newline at end of file diff --git a/infrastructure/services/src/main/utils/ping.js b/backend/src/main/utils/ping.js similarity index 100% rename from infrastructure/services/src/main/utils/ping.js rename to backend/src/main/utils/ping.js diff --git a/infrastructure/services/src/test/RandomUtils.js b/backend/src/test/RandomUtils.js similarity index 100% rename from infrastructure/services/src/test/RandomUtils.js rename to backend/src/test/RandomUtils.js diff --git a/infrastructure/services/src/test/database/databaseTestConfig.js b/backend/src/test/database/databaseTestConfig.js similarity index 100% rename from infrastructure/services/src/test/database/databaseTestConfig.js rename to backend/src/test/database/databaseTestConfig.js diff --git a/backend/src/test/database/refreshDatabase.js b/backend/src/test/database/refreshDatabase.js new file mode 100644 index 00000000..d64e44a8 --- /dev/null +++ b/backend/src/test/database/refreshDatabase.js @@ -0,0 +1,13 @@ +const DatabaseManager = require("../../main/database/DatabaseManager"); +const RefreshDatabase = require("../../main/database/RefreshDatabase"); +const config = Object.assign({}, require('./databaseTestConfig')); +delete config.database; +const refreshDatabase = new RefreshDatabase(new DatabaseManager(config)); + +process.on('unhandledRejection', error => { + console.log('unhandledRejection', error); +}); + + +refreshDatabase.executeAll(refreshDatabase) + .catch(e => console.log(e)); \ No newline at end of file diff --git a/infrastructure/services/src/test/rides/CreateRide.integration.test.js b/backend/src/test/rides/CreateRide.integration.test.js similarity index 99% rename from infrastructure/services/src/test/rides/CreateRide.integration.test.js rename to backend/src/test/rides/CreateRide.integration.test.js index d2cd07e8..44f68e38 100644 --- a/infrastructure/services/src/test/rides/CreateRide.integration.test.js +++ b/backend/src/test/rides/CreateRide.integration.test.js @@ -1,5 +1,5 @@ const DatabaseManager = require('../../main/database/DatabaseManager'); -const CreateRideController = require('../../main/rides/CreateRideController'); +const CreateRideController = require('../../main/rides/CreateRideService'); const FindRideTestRepository = require('./FindRideTestRepository'); const databaseTestConfig = require('../database/databaseTestConfig'); const RandomUtils = require('../RandomUtils'); diff --git a/infrastructure/services/src/test/rides/FindRideTestRepository.js b/backend/src/test/rides/FindRideTestRepository.js similarity index 100% rename from infrastructure/services/src/test/rides/FindRideTestRepository.js rename to backend/src/test/rides/FindRideTestRepository.js diff --git a/infrastructure/services/src/test/rides/ListRides.integration.test.js b/backend/src/test/rides/ListRides.integration.test.js similarity index 98% rename from infrastructure/services/src/test/rides/ListRides.integration.test.js rename to backend/src/test/rides/ListRides.integration.test.js index 7ae9b144..c29c9d9e 100644 --- a/infrastructure/services/src/test/rides/ListRides.integration.test.js +++ b/backend/src/test/rides/ListRides.integration.test.js @@ -1,5 +1,5 @@ const DatabaseManager = require('../../main/database/DatabaseManager'); -const ListRidesController = require('../../main/rides/ListRidesController'); +const ListRidesController = require('../../main/rides/ListRidesService'); const FindRideTestRepository = require('./FindRideTestRepository'); const databaseTestConfig = require('../database/databaseTestConfig'); const RideEntityBuilder = require('./RideEntityBuilder'); diff --git a/infrastructure/services/src/test/rides/RideEntityBuilder.js b/backend/src/test/rides/RideEntityBuilder.js similarity index 100% rename from infrastructure/services/src/test/rides/RideEntityBuilder.js rename to backend/src/test/rides/RideEntityBuilder.js diff --git a/infrastructure/readme.md b/infrastructure/readme.md index b863ffb3..c485da37 100644 --- a/infrastructure/readme.md +++ b/infrastructure/readme.md @@ -6,4 +6,3 @@ The CarPal infrastructure is based on the following Amazon Web Services (AWS): - MySQL relational database service (RDS) In addition authentication is based on Auth0 and JSON Web Tokens (JWTs). - diff --git a/infrastructure/services/package.json b/infrastructure/services/package.json deleted file mode 100644 index ffa41e49..00000000 --- a/infrastructure/services/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "carpal", - "version": "1.0.0", - "scripts": { - "test": "mocha './src/test/**/*.test.js'" - }, - "dependencies": { - "jsonschema": "^1.2.4", - "jsonwebtoken": "^8.1.0", - "moment": "^2.22.2", - "mysql": "^2.15.0", - "randomstring": "^1.1.5", - "request": "^2.87.0", - "uuid": "^3.2.1" - }, - "devDependencies": { - "aws-sdk": "^2.250.1", - "chai": "^4.1.2", - "chai-exclude": "^1.0.9", - "mocha": "^5.2.0" - } -} diff --git a/infrastructure/services/src/main/database/index.js b/infrastructure/services/src/main/database/index.js deleted file mode 100644 index 1171977f..00000000 --- a/infrastructure/services/src/main/database/index.js +++ /dev/null @@ -1,3 +0,0 @@ -let reloadDb = require("./reload-db"); -reloadDb.executeAll() - .catch(e => console.log(e)); \ No newline at end of file diff --git a/infrastructure/services/src/main/database/reload-db.js b/infrastructure/services/src/main/database/reload-db.js deleted file mode 100644 index 48447f3f..00000000 --- a/infrastructure/services/src/main/database/reload-db.js +++ /dev/null @@ -1,24 +0,0 @@ -const DbUtils = require('./db-utils'); -const fs = require('fs'); -const path = require('path'); - -const changeSet = [ - '2018-08-04-1-create-location-table.sql', - '2018-08-04-2-create-rides-table.sql', - '2018-08-04-3-create-driver-table.sql', - '2018-08-04-4-create-driver_car-table.sql', - '2018-08-04-5-create-driver_ride-table.sql' -]; - -class ReloadDB { - executeAll() { - return Promise.all(changeSet.map(file => this.execute(file))); - } - - execute(fileName) { - let sql = fs.readFileSync(path.resolve(__dirname, './changes/' + fileName)).toString().trim(); - return DbUtils.query(sql); - } -} - -module.exports = new ReloadDB(); \ No newline at end of file diff --git a/infrastructure/services/src/main/rides/rideAwsLambdas.js b/infrastructure/services/src/main/rides/rideAwsLambdas.js deleted file mode 100644 index 7bf5d3f2..00000000 --- a/infrastructure/services/src/main/rides/rideAwsLambdas.js +++ /dev/null @@ -1,21 +0,0 @@ -const decodeJwt = require('../utils/jwt').decodeJwt; -const CreateRideController = require('./CreateRideController'); -const DatabaseManager = require('../database/DatabaseManager'); -const databaseManager = new DatabaseManager(); - -module.exports = { - create: function(event, context, callback){ - let controller = new CreateRideController(databaseManager); - let loginData = decodeJwt(event); - controller.createRide(JSON.parse(event.body), loginData) - .then(result => callback(null, result)) - .catch(result => callback(result)); - }, - list: function(event, context, callback){ - let controller = new CreateRideController(databaseManager); - let loginData = decodeJwt(event); - controller.createRide(JSON.parse(event.body), loginData) - .then(result => callback(null, result)) - .catch(result => callback(result)); - } -}; \ No newline at end of file diff --git a/infrastructure/services/src/main/utils/jwt.js b/infrastructure/services/src/main/utils/jwt.js deleted file mode 100644 index 699c50ca..00000000 --- a/infrastructure/services/src/main/utils/jwt.js +++ /dev/null @@ -1,25 +0,0 @@ -const jsonwebtoken = require('jsonwebtoken'); - -module.exports.decodeJwt = (event) => { - if (!event.headers.Authorization) { - return; - } - const tokenValue = event - .headers - .Authorization - .split(' ')[1]; - - try { - const decodedToken = jsonwebtoken.decode(tokenValue); - var claims = {}; - claims.email = decodedToken['https://carpal.org.au/email']; - claims.role = decodedToken['https://carpal.org.au/role']; - if (claims.role === 'driver') { - claims.driverGender = decodedToken['https://carpal.org.au/gender']; - claims.car = decodedToken['https://carpal.org.au/car']; - } - return claims; - } catch (err) { - console.log('catch error. Invalid token', err); - } -} \ No newline at end of file diff --git a/infrastructure/services/src/test/database/DatabaseTestManager.js b/infrastructure/services/src/test/database/DatabaseTestManager.js deleted file mode 100644 index 5eb29ab1..00000000 --- a/infrastructure/services/src/test/database/DatabaseTestManager.js +++ /dev/null @@ -1,6 +0,0 @@ -class DatabaseTestManager { - afterTest(){ - - } - beforeTest(); -} \ No newline at end of file