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

Adapter V2 #489

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16
- name: Use Node.js 20
uses: actions/setup-node@v2
with:
node-version: lts/*
node-version: 20

- name: Restore Dependencies
uses: actions/cache@v2
Expand Down Expand Up @@ -54,10 +54,10 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Use Node.js 16
- name: Use Node.js 20
uses: actions/setup-node@v2
with:
node-version: lts/*
node-version: 20

- name: Restore Dependencies
uses: actions/cache@v2
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Compile stage
FROM node:lts-slim
FROM node:20-slim
WORKDIR /usr/lib/app

# Copy the project dir
Expand All @@ -13,7 +13,7 @@ RUN npm install
RUN nx run-many --target=build --all


FROM node:lts-alpine
FROM node:20-alpine

WORKDIR /usr/lib/app

Expand Down
9 changes: 8 additions & 1 deletion libs/velo-external-db-core/src/converters/data_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@ export const asWixData = (item: Item) => {
return generateIdsIfNeeded(packDates(item))
}

const replaceNonAlphanumeric = (str: string) => {
// Replace non-alphanumeric characters with dashes
return str.replace(/[^a-zA-Z0-9]/g, '-')
}

export const generateIdsIfNeeded = (item: Item): ItemWithId => {
if ('_id' in item)
return item as ItemWithId
const sha = crypto.createHash('sha1')
const fieldsConcat = Object.values(item).join('')
return { ...item, _id: sha.update(fieldsConcat).digest('base64') }
const base64Digest = sha.update(fieldsConcat).digest('base64')
const validId = replaceNonAlphanumeric(base64Digest)
return { ...item, _id: validId }
}

const packDates = (item: Item) => Object.entries(item)
Expand Down
13 changes: 12 additions & 1 deletion libs/velo-external-db-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ export const createRouter = () => {
router.use('/assets', express.static(path.join(__dirname, 'assets')))
router.use(unless(['/', '/provision', '/favicon.ico'], secretKeyAuthMiddleware({ secretKey: cfg.secretKey })))

//set timeout of 1.5 minutes per request
router.use((req, res, next) => {
const NinetySecondsInMs = 90 * 1000
res.setTimeout(NinetySecondsInMs, () => {
console.warn(`Request has timed out - ${req.method} ${req.url}`)
console.dir({ body: req.body }, { depth: 3 })
res.status(408).send('Request Timeout')
})
next()
})

config.forEach(({ pathPrefix, roles }) => router.use(includes([pathPrefix], authRoleMiddleware({ roles }))))

// *************** INFO **********************
Expand Down Expand Up @@ -201,7 +212,7 @@ export const createRouter = () => {
const { collectionName } = req.body
const customContext = {}
const { items } = await executeDataHooksFor(DataActions.BeforeBulkUpdate, dataPayloadFor(BULK_UPDATE, req.body), requestContextFor(BULK_UPDATE, req.body), customContext)
await roleAuthorizationService.authorizeWrite(collectionName, extractRole(req.body))
roleAuthorizationService.authorizeWrite(collectionName, extractRole(req.body))
const data = await schemaAwareDataService.bulkUpdate(collectionName, items)

const dataAfterAction = await executeDataHooksFor(DataActions.AfterBulkUpdate, data, requestContextFor(BULK_UPDATE, req.body), customContext)
Expand Down
Loading