diff --git a/package-lock.json b/package-lock.json index 597daa7..610e266 100644 --- a/package-lock.json +++ b/package-lock.json @@ -996,6 +996,14 @@ "resolved": "https://registry.npmjs.org/@middy/core/-/core-2.5.7.tgz", "integrity": "sha512-KX5Ud0SP+pol6PGkYtMCH4goHobs1XJo3OvEUwdiZUIjZgo56Q08nLu5N7Bs6P+FwGTQHA+hlQ3I5SZbfpO/jg==" }, + "@middy/http-error-handler": { + "version": "2.5.7", + "resolved": "https://registry.npmjs.org/@middy/http-error-handler/-/http-error-handler-2.5.7.tgz", + "integrity": "sha512-1/7L3OHGlQ2IuxL4e4Ylt81sfq5OX2G7q+uZoV5tP4d4KKVN8ftS1ExiMrZGH1r1fyVR3Voh9b2rHD6t/TZZyQ==", + "requires": { + "@middy/util": "^2.5.7" + } + }, "@middy/http-json-body-parser": { "version": "2.5.7", "resolved": "https://registry.npmjs.org/@middy/http-json-body-parser/-/http-json-body-parser-2.5.7.tgz", @@ -1009,6 +1017,36 @@ "resolved": "https://registry.npmjs.org/@middy/util/-/util-2.5.7.tgz", "integrity": "sha512-4CwEVfUyvF0n1qtEzrcrV56L7iQYyt6zChYQ9N5/uvQgAhdExLzOinW6ki1ZjTMgaMypqdHNUyDAEiAuNJLRUw==" }, + "@middy/validator": { + "version": "2.5.7", + "resolved": "https://registry.npmjs.org/@middy/validator/-/validator-2.5.7.tgz", + "integrity": "sha512-zCWNCu7mDbnkGLEsFCbsRGo7FGhN62I5sbJjgcMHtVNksjtJUoImM/KQPT4tH+o81JAg8UZRZVMNWDgZGn1lTw==", + "requires": { + "@middy/util": "^2.5.7", + "ajv": "8.6.3", + "ajv-formats": "2.1.1", + "ajv-formats-draft2019": "1.6.1", + "ajv-i18n": "4.1.0" + }, + "dependencies": { + "ajv": { + "version": "8.6.3", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.6.3.tgz", + "integrity": "sha512-SMJOdDP6LqTkD0Uq8qLi+gMwSt0imXLSV080qFVwJCpH9U6Mb+SUGHAXM0KNbcBPguytWyvFxcHgMLe2D2XSpw==", + "requires": { + "fast-deep-equal": "^3.1.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2", + "uri-js": "^4.2.2" + } + }, + "json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + } + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -1944,7 +1982,6 @@ "version": "2.1.1", "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz", "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==", - "dev": true, "requires": { "ajv": "^8.0.0" }, @@ -1953,7 +1990,6 @@ "version": "8.11.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.11.0.tgz", "integrity": "sha512-wGgprdCvMalC0BztXvitD2hC04YffAvtsUn93JbGXYLAtCUO4xd17mCCZQxUOItiBwZvJScWo8NIvQMQ71rdpg==", - "dev": true, "requires": { "fast-deep-equal": "^3.1.1", "json-schema-traverse": "^1.0.0", @@ -1964,11 +2000,33 @@ "json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", - "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", - "dev": true + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" } } }, + "ajv-formats-draft2019": { + "version": "1.6.1", + "resolved": "https://registry.npmjs.org/ajv-formats-draft2019/-/ajv-formats-draft2019-1.6.1.tgz", + "integrity": "sha512-JQPvavpkWDvIsBp2Z33UkYCtXCSpW4HD3tAZ+oL4iEFOk9obQZffx0yANwECt6vzr6ET+7HN5czRyqXbnq/u0Q==", + "requires": { + "punycode": "^2.1.1", + "schemes": "^1.4.0", + "smtp-address-parser": "^1.0.3", + "uri-js": "^4.4.1" + }, + "dependencies": { + "punycode": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" + } + } + }, + "ajv-i18n": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ajv-i18n/-/ajv-i18n-4.1.0.tgz", + "integrity": "sha512-GmRKPqWbZc+wn77IVPixJ336h9opyWSd4iTEGv825jxbccN1JKVEG/JnJX9wxYa1/yPmT/4v/YZN3ymmHwY4ag==" + }, "ajv-keywords": { "version": "3.5.2", "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", @@ -2968,8 +3026,7 @@ "commander": { "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", - "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", - "dev": true + "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, "component-emitter": { "version": "1.3.0", @@ -3054,11 +3111,6 @@ "requires": { "follow-redirects": "^1.14.4" } - }, - "follow-redirects": { - "version": "1.14.4", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz", - "integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==" } } }, @@ -3083,11 +3135,6 @@ "follow-redirects": "^1.14.0" } }, - "follow-redirects": { - "version": "1.14.4", - "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.4.tgz", - "integrity": "sha512-zwGkiSXC1MUJG/qmeIFH2HBJx9u0V46QGUe3YR1fXG8bXQxq7fLj0RjLZQ5nubr9qNJUZrH+xUcwXEoXNpfS+g==" - }, "type-fest": { "version": "0.21.3", "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-0.21.3.tgz", @@ -3641,6 +3688,11 @@ "path-type": "^4.0.0" } }, + "discontinuous-range": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/discontinuous-range/-/discontinuous-range-1.0.0.tgz", + "integrity": "sha1-44Mx8IRLukm5qctxx3FYWqsbxlo=" + }, "domexception": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/domexception/-/domexception-2.0.1.tgz", @@ -4156,8 +4208,7 @@ "extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", - "dev": true + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" }, "extend-shallow": { "version": "3.0.2", @@ -4291,8 +4342,7 @@ "fast-deep-equal": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", - "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", - "dev": true + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==" }, "fast-glob": { "version": "3.2.11", @@ -4449,8 +4499,7 @@ "follow-redirects": { "version": "1.14.9", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz", - "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==", - "dev": true + "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==" }, "for-in": { "version": "1.0.2", @@ -7082,6 +7131,11 @@ "moment": ">= 2.9.0" } }, + "moo": { + "version": "0.5.1", + "resolved": "https://registry.npmjs.org/moo/-/moo-0.5.1.tgz", + "integrity": "sha512-I1mnb5xn4fO80BH9BLcF0yLypy2UKl+Cb01Fu0hJRkJjlCRtxZMWkTdAtDd5ZqCOxtCkhmRwyI57vWT+1iZ67w==" + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -7140,6 +7194,17 @@ "type": "^2.5.0" } }, + "nearley": { + "version": "2.20.1", + "resolved": "https://registry.npmjs.org/nearley/-/nearley-2.20.1.tgz", + "integrity": "sha512-+Mc8UaAebFzgV+KpI5n7DasuuQCHA89dmwm7JXw3TV43ukfNQ9DnBH3Mdb2g/I4Fdxc26pwimBWvjIw0UAILSQ==", + "requires": { + "commander": "^2.19.0", + "moo": "^0.5.0", + "railroad-diagrams": "^1.0.0", + "randexp": "0.4.6" + } + }, "neo-async": { "version": "2.6.2", "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", @@ -8227,6 +8292,20 @@ "integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==", "dev": true }, + "railroad-diagrams": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/railroad-diagrams/-/railroad-diagrams-1.0.0.tgz", + "integrity": "sha1-635iZ1SN3t+4mcG5Dlc3RVnN234=" + }, + "randexp": { + "version": "0.4.6", + "resolved": "https://registry.npmjs.org/randexp/-/randexp-0.4.6.tgz", + "integrity": "sha512-80WNmd9DA0tmZrw9qQa62GPPWfuXJknrmVmLcxvq4uZBdYqb1wYoKTmnlGUchvVWe0XiLupYkBoXVOxz3C8DYQ==", + "requires": { + "discontinuous-range": "1.0.0", + "ret": "~0.1.10" + } + }, "randombytes": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.1.0.tgz", @@ -8480,8 +8559,7 @@ "require-from-string": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", - "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", - "dev": true + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==" }, "require-main-filename": { "version": "2.0.0", @@ -8556,8 +8634,7 @@ "ret": { "version": "0.1.15", "resolved": "https://registry.npmjs.org/ret/-/ret-0.1.15.tgz", - "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==", - "dev": true + "integrity": "sha512-TTlYpa+OL+vMMNG24xSlQGEJ3B/RzEfUlLct7b5G/ytav+wPrplCpVMFuwzXbkecJrb6IYo1iFb0S9v37754mg==" }, "retry": { "version": "0.13.1", @@ -8812,6 +8889,14 @@ "ajv-keywords": "^3.4.1" } }, + "schemes": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/schemes/-/schemes-1.4.0.tgz", + "integrity": "sha512-ImFy9FbCsQlVgnE3TCWmLPCFnVzx0lHL/l+umHplDqAKd0dzFpnS6lFZIpagBlYhKwzVmlV36ec0Y1XTu8JBAQ==", + "requires": { + "extend": "^3.0.0" + } + }, "seek-bzip": { "version": "1.0.6", "resolved": "https://registry.npmjs.org/seek-bzip/-/seek-bzip-1.0.6.tgz", @@ -9554,6 +9639,14 @@ "integrity": "sha512-g9Q1haeby36OSStwb4ntCGGGaKsaVSjQ68fBxoQcutl5fS1vuY18H3wSt3jFyFtrkx+Kz0V1G85A4MyAdDMi2Q==", "dev": true }, + "smtp-address-parser": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/smtp-address-parser/-/smtp-address-parser-1.0.10.tgz", + "integrity": "sha512-Osg9LmvGeAG/hyao4mldbflLOkkr3a+h4m1lwKCK5U8M6ZAr7tdXEz/+/vr752TSGE4MNUlUl9cIK2cB8cgzXg==", + "requires": { + "nearley": "^2.20.1" + } + }, "snapdragon": { "version": "0.8.2", "resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz", @@ -10753,7 +10846,6 @@ "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", "integrity": "sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==", - "dev": true, "requires": { "punycode": "^2.1.0" }, @@ -10761,8 +10853,7 @@ "punycode": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", - "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==", - "dev": true + "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" } } }, diff --git a/package.json b/package.json index 26823be..bc3c623 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,9 @@ "dependencies": { "@contentful/rich-text-plain-text-renderer": "^15.11.1", "@middy/core": "^2.5.7", + "@middy/http-error-handler": "^2.5.7", "@middy/http-json-body-parser": "^2.5.7", + "@middy/validator": "^2.5.7", "aws-sdk": "^2.824.0", "chrome-aws-lambda": "^10.0.0", "contentful": "^9.0.3", diff --git a/src/functions/debitoor/handler.ts b/src/functions/debitoor/handler.ts index 46a52c7..7129fe2 100644 --- a/src/functions/debitoor/handler.ts +++ b/src/functions/debitoor/handler.ts @@ -1,6 +1,6 @@ import { httpResponse, - ValidatedEventAPIGatewayProxyEvent, + ValidatedEventAPIGatewayProxyEvent } from '@libs/apiGateway'; import { BOOK, LABEL_BILLED, MAIL } from '@libs/constants'; import { fetchCompanies } from '@libs/contentful'; @@ -9,7 +9,7 @@ import { bookSendDraftInvoice, changeCompany, createDraftInvoices, - CreateDraftInvoicesResponse, + CreateDraftInvoicesResponse } from '@libs/debitoor'; import { middyfy } from '@libs/lambda'; import { @@ -18,7 +18,7 @@ import { fetchTimeEntriesBetween, filterClientTimeEntriesByCustomer, filterTimeEntriesByLabel, - sanitizeTimeEntries, + sanitizeTimeEntries } from '@libs/toggl'; import { clearCaches, getConfig, initTranslate, Logger } from '@libs/utils'; import 'source-map-support/register'; @@ -146,4 +146,4 @@ const handler: ValidatedEventAPIGatewayProxyEvent = async ( } }; -export const main = middyfy(handler); +export const main = middyfy(handler, schema); diff --git a/src/functions/sheet/handler.ts b/src/functions/sheet/handler.ts index 52a593c..2599d49 100644 --- a/src/functions/sheet/handler.ts +++ b/src/functions/sheet/handler.ts @@ -1,6 +1,6 @@ import { httpResponse, - ValidatedEventAPIGatewayProxyEvent, + ValidatedEventAPIGatewayProxyEvent } from '@libs/apiGateway'; import { createCsv } from '@libs/csv'; import { middyfy } from '@libs/lambda'; @@ -10,7 +10,7 @@ import { fetchTimeEntriesBetween, filterClientTimeEntriesByCustomer, filterTimeEntriesByLabel, - sanitizeTimeEntries, + sanitizeTimeEntries } from '@libs/toggl'; import { clearCaches, getConfig, Logger } from '@libs/utils'; import 'source-map-support/register'; @@ -72,4 +72,4 @@ const handler: ValidatedEventAPIGatewayProxyEvent = async ( } }; -export const main = middyfy(handler); +export const main = middyfy(handler, schema); diff --git a/src/functions/sync-contentful/handler.ts b/src/functions/sync-contentful/handler.ts index 249c072..3539710 100644 --- a/src/functions/sync-contentful/handler.ts +++ b/src/functions/sync-contentful/handler.ts @@ -1,10 +1,10 @@ import { httpResponse, - ValidatedEventAPIGatewayProxyEvent, + ValidatedEventAPIGatewayProxyEvent } from '@libs/apiGateway'; import { updateDebitoorCustomers, - updateDebitoorProducts, + updateDebitoorProducts } from '@libs/debitoor'; import { middyfy } from '@libs/lambda'; import { updateTogglClients, updateTogglProjects } from '@libs/toggl'; @@ -27,4 +27,4 @@ const handler: ValidatedEventAPIGatewayProxyEvent = async () => { } }; -export const main = middyfy(handler); +export const main = middyfy(handler, {}); diff --git a/src/libs/debitoor-types.ts b/src/libs/debitoor-types.ts index 7061dda..7d4f3b6 100644 --- a/src/libs/debitoor-types.ts +++ b/src/libs/debitoor-types.ts @@ -200,6 +200,7 @@ export interface LogoResponse { // GENERATED WITH https://jvilk.com/MakeTypes/ export interface Settings { customerSettings: CustomerSettings; + accountMigratedAt?: unknown; supplierSettings: SupplierSettings; invoiceSettings: InvoiceSettings; quoteSettings: QuoteSettings; diff --git a/src/libs/debitoor.ts b/src/libs/debitoor.ts index a1b3f77..ea590e7 100644 --- a/src/libs/debitoor.ts +++ b/src/libs/debitoor.ts @@ -182,10 +182,14 @@ export const changeCompanyDetails = async ( settings.companyProfile.webSite = website; settings.companyProfile.email = email; settings.companyProfile.logoUrl = logoUrl; + settings.customerSettings.lastCustomerNumber = + settings.customerSettings.lastCustomerNumber ?? 1000; settings.ccInfo.billingInfo.company = name; delete settings.vatReported; + delete settings.accountMigratedAt; + delete settings.featuresQuota; return fetch(`${BASE_URL}/${SETTINGS_PATH}`, { method: 'PUT', diff --git a/src/libs/lambda.ts b/src/libs/lambda.ts index 967e0b1..be23c09 100644 --- a/src/libs/lambda.ts +++ b/src/libs/lambda.ts @@ -1,4 +1,19 @@ import middy from '@middy/core'; -import middyJsonBodyParser from '@middy/http-json-body-parser'; +import httpErrorHandler from '@middy/http-error-handler'; +import jsonBodyParser from '@middy/http-json-body-parser'; -export const middyfy = (handler) => middy(handler).use(middyJsonBodyParser()); +export const middyfy = (handler, inputSchema) => + middy(handler) + .use(jsonBodyParser()) + // .use(validator({ inputSchema })) + .use( + httpErrorHandler({ + logger(error) { + try { + console.dir(error, { depth: null, colors: true }); + } catch (error) { + console.log(error); + } + }, + }) + );