Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: upgrade monk auth #144

Merged
merged 9 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 6 additions & 40 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,8 @@
# Drone CI File!

kind: pipeline
type: kubernetes
name: default

metadata:
namespace: builds

node_selector:
doks.digitalocean.com/node-pool: josa-cloud-np

steps:
- name: build
image: plugins/docker
settings:
repo: josaorg/nuha-web
build_args: [USER=1001]
build_args_from_env:
[
DRONE_BUILD_NUMBER,
DRONE_BUILD_LINK,
DRONE_COMMIT_SHA,
DRONE_COMMIT_LINK,
DRONE_REPO_LINK,
DRONE_BUILD_FINISHED,
]
tags:
- ${DRONE_COMMIT_SHA}
- stable
username:
from_secret: docker_username
password:
from_secret: docker_password
- name: notify
image: plugins/slack
settings:
webhook:
from_secret: slack_webhook
channel: heartbeat
depends_on:
- build
kind: template
load: container.jsonnet
data:
repositoryName: josaorg/nuha-web
releaseName: nuha-web
buildArgs: USER=1001
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ typings/

# nuxt.js build output
.nuxt
.output

# Nuxt generate
dist
Expand Down
4 changes: 2 additions & 2 deletions .sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ NUXT_SMTP_PASSWORD=somepass
NUXT_LIST_MONK_API_URL="https://monk.josa.ngo/api"
#samplr#NUXT_LIST_MONK_USER=monkusername
NUXT_LIST_MONK_USER=monkusername
#samplr#NUXT_LIST_MONK_PASSWORD=somepass
NUXT_LIST_MONK_PASSWORD=somepass
#samplr#NUXT_LIST_MONK_TOKEN=somepass
NUXT_LIST_MONK_TOKEN=somepass
NUXT_LIST_MONK_EN_TEMPLATE_ID="13"
NUXT_LIST_MONK_AR_TEMPLATE_ID="14"
NUXT_PUBLIC_MATOMO_HOST=""
Expand Down
5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ ARG USER=node DRONE_COMMIT_SHA=${DRONE_COMMIT_SHA} DRONE_BUILD_NUMBER=${DRONE_BU
###########
# BUILDER #
###########
FROM node:18.14.0 AS builder

FROM node:22.11.0 AS builder

# copy build context and install dependencinpm res
WORKDIR /workspace
Expand All @@ -18,7 +17,7 @@ RUN yarn build
###########
# PROJECT #
###########
FROM node:18-slim
FROM node:22-slim

# pass the global args
ARG USER
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
FROM node:18 AS builder

FROM node:22.11.0

# copy build context and install dependencinpm res
WORKDIR /app
COPY . .
# Or try the below command since we are mapping the volumns
# COPY ./package.json .

RUN yarn install

# expose port
Expand Down
2 changes: 0 additions & 2 deletions docker-compose.yml → compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.8'

services:
nuha-web:
container_name: nuha-web
Expand Down
6 changes: 5 additions & 1 deletion nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default defineNuxtConfig({
include: ['~/types/*.ts'],
},
},

plugins: [
{ src: '~/plugins/use-scroll.ts', ssr: false, mode: 'client' },
{
Expand Down Expand Up @@ -76,6 +77,7 @@ export default defineNuxtConfig({
baseUrl: 'http://localhost:3000/',
debug: false,
},

runtimeConfig: {
public: {
targetEnv: '',
Expand Down Expand Up @@ -103,10 +105,12 @@ export default defineNuxtConfig({
listMonk: {
apiUrl: '',
user: '',
password: '',
token: '',
enTemplateId: '',
arTemplateId: '',
listId: '',
},
},

compatibilityDate: '2024-11-26',
})
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,27 @@
"start": "node .output/server/index.mjs"
},
"devDependencies": {
"@nuxtjs/i18n": "^8.3.0",
"@nuxtjs/tailwindcss": "^6.12.0",
"@sidebase/nuxt-auth": "^0.6.7",
"@nuxtjs/i18n": "^8.5.2",
"@nuxtjs/tailwindcss": "^6.12.2",
"@sidebase/nuxt-auth": "^0.9.4",
"@types/d3": "^7.4.3",
"nuxt": "^3.11.2"
},
"dependencies": {
"@auth/mongodb-adapter": "^3.0.0",
"@element-plus/nuxt": "^1.0.9",
"@auth/mongodb-adapter": "^3.7.4",
"@element-plus/nuxt": "^1.1.0",
"@josango/nuxt3-build-banner": "^3.0.2",
"@nuxt/content": "^2.12.1",
"@nuxtjs/robots": "^3.0.0",
"@types/nodemailer": "^6.4.14",
"@vueuse/core": "^10.9.0",
"csv-parse": "^5.5.5",
"@nuxt/content": "^2.13.4",
"@nuxtjs/robots": "^4.1.11",
"@types/nodemailer": "^6.4.17",
"@vueuse/core": "^11.3.0",
"csv-parse": "^5.6.0",
"d3": "^7.9.0",
"element-plus": "^2.7.1",
"mongodb": "^6.5.0",
"element-plus": "^2.8.8",
"mongodb": "^6.10.0",
"next-auth": "4.21.1",
"node-xlsx": "^0.24.0",
"nodemailer": "^6.9.13",
"nodemailer": "^6.9.16",
"vue-matomo": "^4.2.0"
}
}
}
7 changes: 4 additions & 3 deletions server/api/upload-comment.post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { predictCommentsResults } from '../utils'
import { predictCommentsResults } from '../utils/nuha-api-request'
import { reject } from '../utils/promise-handlers'

export default defineEventHandler(async (event) => {
const data = await readBody<SingleComment>(event)
Expand Down Expand Up @@ -33,14 +34,14 @@ async function verifyData(input: SingleComment): Promise<void> {
}

const emailPattern = new RegExp(
/(?:[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+(?:\.[a-zA-Z\d!#$%&'*+/=?^_{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?\.)+[a-zA-Z\d](?:[a-zA-Z\d-]*[a-zA-Z\d])?|\[(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?|[a-zA-Z\d-]*[a-zA-Z\d]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])/gm,
/^(?:[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/gm
)
if (input.comment.match(emailPattern)) {
return reject('apiResponse.commentContainsEmail')
}

const urlPattern = new RegExp(
/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gm,
/[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/gm
)
if (input.comment.match(urlPattern)) {
return reject('apiResponse.commentContainsUrl')
Expand Down
4 changes: 2 additions & 2 deletions server/api/upload-file.post.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FileParser, getFileParser, getFileType } from '../utils'
import { FileParser, getFileParser, getFileType } from '../utils/file-parser'

export default defineEventHandler(async (event) => {
const files = await readMultipartFormData(event)
Expand All @@ -8,7 +8,7 @@ export default defineEventHandler(async (event) => {
}

const fileType = getFileType(
files[0].filename?.substring(files[0].filename?.lastIndexOf('.') + 1) ?? '',
files[0].filename?.substring(files[0].filename?.lastIndexOf('.') + 1) ?? ''
)
let err: unknown
const parser = await getFileParser(fileType).catch((_err) => {
Expand Down
1 change: 1 addition & 0 deletions server/utils/file-parser.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { parse } from 'csv-parse/sync'
import { resolve, reject } from './promise-handlers'
import xlsx from 'node-xlsx'

export interface FileParser {
Expand Down
13 changes: 0 additions & 13 deletions server/utils/index.ts

This file was deleted.

18 changes: 9 additions & 9 deletions server/utils/listmonk-requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ enum ListmonkEndpoint {
export async function sendLoginEmail(
targetEmail: string,
locale: string,
loginUrl: string,
loginUrl: string
): Promise<void> {
await makeListmonkRequest(
ListmonkEndpoint.SEND_TRANSACTIONAL_EMAIL,
Expand All @@ -19,13 +19,13 @@ export async function sendLoginEmail(
template_id: parseInt(
locale === 'en'
? runtimeConfig.listMonk.enTemplateId
: runtimeConfig.listMonk.arTemplateId,
: runtimeConfig.listMonk.arTemplateId
),
data: {
link: loginUrl,
},
content_type: 'html',
}),
})
)
}

Expand All @@ -37,24 +37,24 @@ export async function subscribeEmail(email: string): Promise<void> {
name: email.substring(0, email.indexOf('@')),
status: 'enabled',
lists: [runtimeConfig.listMonk.listId].map(parseInt),
}),
})
)
}

async function makeListmonkRequest(
path: ListmonkEndpoint,
body: BodyInit,
body: BodyInit
): Promise<void | Response> {
return await fetch(`${runtimeConfig.listMonk.apiUrl}/${path}`, {
method: 'POST',
mode: 'cors',
headers: new Headers({
'Content-Type': 'application/json',
Authorization:
'Basic ' +
btoa(
runtimeConfig.listMonk.user + ':' + runtimeConfig.listMonk.password,
),
'token ' +
runtimeConfig.listMonk.user +
':' +
runtimeConfig.listMonk.token,
}),
body,
})
Expand Down
Loading
Loading