diff --git a/apps/frontend/src/api/dbs.ts b/apps/frontend/src/api/dbs.ts index 4021512..1a5829a 100644 --- a/apps/frontend/src/api/dbs.ts +++ b/apps/frontend/src/api/dbs.ts @@ -16,6 +16,9 @@ export const messagesDbLocal = new PouchDB('messages') export const webPushSubscriptionsDbRemote = new PouchDB( `${import.meta.env.VITE_API_URL}/web_push_subscriptions`, + { + skip_setup: true, + }, ) export const messagesDbRemote = new PouchDB( diff --git a/package-lock.json b/package-lock.json index 3f52b03..8bd9bb0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1182,6 +1182,10 @@ "vue": "^3.3.4" } }, + "node_modules/@hereconnect/db-migrations": { + "resolved": "services/db-migrations", + "link": true + }, "node_modules/@hereconnect/frontend": { "resolved": "apps/frontend", "link": true @@ -3139,7 +3143,6 @@ "version": "4.1.2", "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", - "dev": true, "license": "MIT", "dependencies": { "ansi-styles": "^4.1.0", @@ -3437,6 +3440,15 @@ "node": ">=18" } }, + "node_modules/dateformat": { + "version": "4.6.3", + "resolved": "https://registry.npmjs.org/dateformat/-/dateformat-4.6.3.tgz", + "integrity": "sha512-2P0p0pFGzHS5EMnhdxQi7aJN+iMheud0UhG4dlE1DLAlvL8JHjJJTX/CSm4JXwV0Ka5nGk3zC5mcb5bUQUxxMA==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/de-indent": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz", @@ -3611,6 +3623,18 @@ "url": "https://github.com/fb55/domutils?sponsor=1" } }, + "node_modules/dotenv": { + "version": "16.4.5", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.5.tgz", + "integrity": "sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==", + "license": "BSD-2-Clause", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://dotenvx.com" + } + }, "node_modules/eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -4473,7 +4497,6 @@ "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", - "dev": true, "license": "MIT", "engines": { "node": ">=8" @@ -5285,6 +5308,39 @@ "integrity": "sha512-n7DHHMjR1avBbSpsTBj6fmMGh2AGrifVV4e+WYc3Q9lO+xnSZ3NyhcBND3vzzatt05LFhoKFRxrIyklmLlUtyA==", "license": "MIT" }, + "node_modules/migrate": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/migrate/-/migrate-2.1.0.tgz", + "integrity": "sha512-xSwTScy7ozxQtzDtO/LpmZzWTmItXBC3k3wOQGf8TjHpudQUS/m7uyboBHHsv2nFmioyyC7gtbcI7IPj89aJLA==", + "license": "MIT", + "dependencies": { + "chalk": "^4.1.2", + "commander": "^2.20.3", + "dateformat": "^4.6.3", + "dotenv": "^16.0.0", + "inherits": "^2.0.3", + "minimatch": "^9.0.1", + "mkdirp": "^3.0.1", + "slug": "^8.2.2" + }, + "bin": { + "migrate": "bin/migrate", + "migrate-create": "bin/migrate-create", + "migrate-down": "bin/migrate-down", + "migrate-init": "bin/migrate-init", + "migrate-list": "bin/migrate-list", + "migrate-up": "bin/migrate-up" + }, + "engines": { + "node": ">= 14.0.0" + } + }, + "node_modules/migrate/node_modules/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==", + "license": "MIT" + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -5367,6 +5423,21 @@ "dev": true, "license": "MIT" }, + "node_modules/mkdirp": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-3.0.1.tgz", + "integrity": "sha512-+NsyUUAZDmo6YVHzL/stxSu3t9YS1iljliy3BSDrXJ/dkn1KYdmtZODGGjLcc9XLgVVpH4KshHB8XmZgMhaBXg==", + "license": "MIT", + "bin": { + "mkdirp": "dist/cjs/src/bin.js" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/mlly": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/mlly/-/mlly-1.7.3.tgz", @@ -6871,6 +6942,15 @@ "node": ">=18" } }, + "node_modules/slug": { + "version": "8.2.3", + "resolved": "https://registry.npmjs.org/slug/-/slug-8.2.3.tgz", + "integrity": "sha512-fXjhAZszNecz855GUNIwW0+sFPi9WV4bMiEKDOCA4wcq1ts1UnUVNy/F78B0Aat7/W3rA+se//33ILKNMrbeYQ==", + "license": "MIT", + "bin": { + "slug": "cli.js" + } + }, "node_modules/source-map-js": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz", @@ -7080,7 +7160,6 @@ "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", - "dev": true, "license": "MIT", "dependencies": { "has-flag": "^4.0.0" @@ -8370,6 +8449,22 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "services/db-migrations": { + "name": "@hereconnect/db-migrations", + "version": "1.0.0", + "license": "@hereconnect", + "dependencies": { + "migrate": "^2.1.0", + "pouchdb-adapter-http": "^9.0.0", + "pouchdb-core": "^9.0.0", + "pouchdb-fetch": "^9.0.0", + "pouchdb-find": "^9.0.0" + }, + "engines": { + "node": ">=v20.10.0", + "pnpm": ">=8.15.0" + } + }, "services/message-delivery-method-web-push": { "name": "@hereconnect/message-delivery-method-web-push", "version": "1.0.0", @@ -8383,6 +8478,19 @@ "node": ">=v20.10.0", "pnpm": ">=8.15.0" } + }, + "services/migrations": { + "name": "@hereconnect/migrations", + "version": "1.0.0", + "extraneous": true, + "license": "@hereconnect", + "dependencies": { + "migrate": "^2.1.0" + }, + "engines": { + "node": ">=v20.10.0", + "pnpm": ">=8.15.0" + } } } } diff --git a/services/couchdb/config/chttpd_auth.ini b/services/couchdb/config/chttpd_auth.ini new file mode 100644 index 0000000..2b86964 --- /dev/null +++ b/services/couchdb/config/chttpd_auth.ini @@ -0,0 +1,2 @@ +[chttpd_auth] +timeout = 315362081 diff --git a/services/db-migrations/.gitignore b/services/db-migrations/.gitignore new file mode 100644 index 0000000..8ca80b8 --- /dev/null +++ b/services/db-migrations/.gitignore @@ -0,0 +1 @@ +.migrate diff --git a/services/db-migrations/PouchDB.js b/services/db-migrations/PouchDB.js new file mode 100644 index 0000000..c56d7c5 --- /dev/null +++ b/services/db-migrations/PouchDB.js @@ -0,0 +1,5 @@ +import PouchDB from "pouchdb-core"; +import PouchDBAdapterHttp from "pouchdb-adapter-http"; +import PouchdbFind from "pouchdb-find"; + +export default PouchDB.plugin(PouchDBAdapterHttp).plugin(PouchdbFind); diff --git a/services/db-migrations/migrations/1732483677017-dbs.js b/services/db-migrations/migrations/1732483677017-dbs.js new file mode 100644 index 0000000..a57198c --- /dev/null +++ b/services/db-migrations/migrations/1732483677017-dbs.js @@ -0,0 +1,40 @@ +import { fetch } from "pouchdb-fetch"; + +const dbsSecurity = { + web_push_subscriptions: { + admins: { roles: ["_admin"] }, + members: { roles: [] }, + }, + messages: { + admins: { roles: ["_admin"] }, + members: { roles: [] }, + }, + server_settings: { + admins: { roles: ["_admin"] }, + members: { roles: ["_admin"] }, + }, + // qr: { + // admins: { roles: ["_admin"] }, + // members: { roles: [] }, + // }, +}; + +export const up = async () => { + for (const [dbName, dbSecurity] of Object.entries(dbsSecurity)) { + await fetch(`${process.env.API_URL}/${dbName}`, { + method: "PUT", + }); + await fetch(`${process.env.API_URL}/${dbName}/_security`, { + method: "PUT", + body: JSON.stringify(dbSecurity), + }); + } +}; + +export const down = async () => { + for (const dbName of Object.keys(dbsSecurity)) { + await fetch(`${process.env.API_URL}/${dbName}`, { + method: "DELETE", + }); + } +}; diff --git a/services/db-migrations/my-migration-template.js b/services/db-migrations/my-migration-template.js new file mode 100644 index 0000000..5d5005d --- /dev/null +++ b/services/db-migrations/my-migration-template.js @@ -0,0 +1,9 @@ +import PouchDB from "../PouchDB.js"; + +export const up = async () => { + await new PouchDB(`${process.env.API_URL}/`, { skip_setup: true }); +}; + +export const down = async () => { + await new PouchDB(`${process.env.API_URL}/`, { skip_setup: true }); +}; diff --git a/services/db-migrations/package.json b/services/db-migrations/package.json new file mode 100644 index 0000000..a38f91a --- /dev/null +++ b/services/db-migrations/package.json @@ -0,0 +1,18 @@ +{ + "name": "@hereconnect/db-migrations", + "version": "1.0.0", + "type": "module", + "license": "@hereconnect", + "private": true, + "engines": { + "node": ">=v20.10.0", + "pnpm": ">=8.15.0" + }, + "dependencies": { + "migrate": "^2.1.0", + "pouchdb-adapter-http": "^9.0.0", + "pouchdb-core": "^9.0.0", + "pouchdb-fetch": "^9.0.0", + "pouchdb-find": "^9.0.0" + } +}