From 7a10eb6576331358d0e7952fb929dea3262f58ad Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Fri, 4 Aug 2023 14:36:05 +0100
Subject: [PATCH 01/31] debug: req
---
node/email-contact-form/src/main.js | 2 ++
1 file changed, 2 insertions(+)
diff --git a/node/email-contact-form/src/main.js b/node/email-contact-form/src/main.js
index 4a560f2c..680ab8cb 100644
--- a/node/email-contact-form/src/main.js
+++ b/node/email-contact-form/src/main.js
@@ -34,6 +34,8 @@ export default async ({ req, res, log, error }) => {
});
}
+ log(JSON.stringify(req, null, 2));
+
throwIfMissing(req.headers, ['referer', 'origin']);
if (req.headers['content-type'] !== 'application/x-www-form-urlencoded') {
From 4d48e461f27199030746b1dbf4b8b30620a55dbe Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Fri, 4 Aug 2023 14:49:08 +0100
Subject: [PATCH 02/31] fix: origin issues
---
node/email-contact-form/src/cors.js | 7 ++++++-
node/email-contact-form/src/main.js | 10 ++++------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/node/email-contact-form/src/cors.js b/node/email-contact-form/src/cors.js
index 29d597e6..74227806 100644
--- a/node/email-contact-form/src/cors.js
+++ b/node/email-contact-form/src/cors.js
@@ -1,11 +1,16 @@
export function isOriginPermitted(req) {
- if (!process.env.ALLOWED_ORIGINS || process.env.ALLOWED_ORIGINS === '*')
+ if (
+ !process.env.ALLOWED_ORIGINS ||
+ process.env.ALLOWED_ORIGINS === '*' ||
+ !req.headers['origin']
+ )
return true;
const allowedOriginsArray = process.env.ALLOWED_ORIGINS.split(',');
return allowedOriginsArray.includes(req.headers['origin']);
}
export function getCorsHeaders(req) {
+ if (!req.headers['origin']) return {};
return {
'Access-Control-Allow-Origin':
!process.env.ALLOWED_ORIGINS || process.env.ALLOWED_ORIGINS === '*'
diff --git a/node/email-contact-form/src/main.js b/node/email-contact-form/src/main.js
index 680ab8cb..4bbb4c13 100644
--- a/node/email-contact-form/src/main.js
+++ b/node/email-contact-form/src/main.js
@@ -36,8 +36,6 @@ export default async ({ req, res, log, error }) => {
log(JSON.stringify(req, null, 2));
- throwIfMissing(req.headers, ['referer', 'origin']);
-
if (req.headers['content-type'] !== 'application/x-www-form-urlencoded') {
error('Incorrect content type.');
return res.redirect(
@@ -45,7 +43,7 @@ export default async ({ req, res, log, error }) => {
);
}
- if (!isOriginPermitted(req.headers['origin'])) {
+ if (!isOriginPermitted(req)) {
error('Origin not permitted.');
return res.redirect(
urlWithCodeParam(req.headers['referer'], ErrorCode.INVALID_REQUEST)
@@ -59,7 +57,7 @@ export default async ({ req, res, log, error }) => {
return res.redirect(
urlWithCodeParam(req.headers['referer'], err.message),
301,
- getCorsHeaders(req.headers['origin'])
+ getCorsHeaders(req)
);
}
@@ -75,7 +73,7 @@ export default async ({ req, res, log, error }) => {
return res.redirect(
urlWithCodeParam(req.headers['referer'], ErrorCode.SERVER_ERROR),
301,
- getCorsHeaders(req.headers['origin'])
+ getCorsHeaders(req)
);
}
@@ -88,6 +86,6 @@ export default async ({ req, res, log, error }) => {
return res.redirect(
new URL(form._next, req.headers['origin']).toString(),
301,
- getCorsHeaders(req.headers['origin'])
+ getCorsHeaders(req)
);
};
From a6d9db969c8e0e3484f08a653745a52121b8bdb0 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Fri, 4 Aug 2023 15:05:06 +0100
Subject: [PATCH 03/31] fix: referer bugs
---
node/email-contact-form/src/main.js | 5 +++--
node/email-contact-form/static/index.html | 1 -
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/node/email-contact-form/src/main.js b/node/email-contact-form/src/main.js
index 4bbb4c13..e20f7b5d 100644
--- a/node/email-contact-form/src/main.js
+++ b/node/email-contact-form/src/main.js
@@ -65,7 +65,7 @@ export default async ({ req, res, log, error }) => {
sendEmail({
to: process.env.SUBMIT_EMAIL,
from: /** @type {string} */ (form['email']),
- subject: `New form submission: ${origin}`,
+ subject: `New form submission: ${req.headers['referer']}`,
text: templateFormMessage(form),
});
} catch (err) {
@@ -83,8 +83,9 @@ export default async ({ req, res, log, error }) => {
});
}
+ const baseUrl = new URL(req.headers['referer']).origin;
return res.redirect(
- new URL(form._next, req.headers['origin']).toString(),
+ new URL(form._next, baseUrl).toString(),
301,
getCorsHeaders(req)
);
diff --git a/node/email-contact-form/static/index.html b/node/email-contact-form/static/index.html
index 29670f76..b324a86c 100644
--- a/node/email-contact-form/static/index.html
+++ b/node/email-contact-form/static/index.html
@@ -35,7 +35,6 @@
Contact
placeholder="Your Message"
required
>
-
Submit
From 4524d251e023c013214e0d37bc1282c95438943f Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Fri, 4 Aug 2023 15:20:46 +0100
Subject: [PATCH 04/31] chore: improve comment
---
node/email-contact-form/src/utils.js | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/node/email-contact-form/src/utils.js b/node/email-contact-form/src/utils.js
index 5cbdd4db..10bfa6f9 100644
--- a/node/email-contact-form/src/utils.js
+++ b/node/email-contact-form/src/utils.js
@@ -41,10 +41,10 @@ export function getStaticFile(fileName) {
*/
export function templateFormMessage(form) {
return `You've received a new message.\n
- ${Object.entries(form)
- .filter(([key]) => key !== '_next')
- .map(([key, value]) => `${key}: ${value}`)
- .join('\n')}`;
+${Object.entries(form)
+ .filter(([key]) => key !== '_next')
+ .map(([key, value]) => `${key}: ${value}`)
+ .join('\n')}`;
}
/**
@@ -63,7 +63,7 @@ export function urlWithCodeParam(baseUrl, codeParam) {
export async function sendEmail(options) {
const transport = nodemailer.createTransport({
// @ts-ignore
- // Not sure what's going on here.
+ // Bypass some weird type checks
host: process.env.SMTP_HOST,
port: process.env.SMTP_PORT || 587,
auth: {
From f62b8089a3dfa1e1ba9b5690523fc7b163473084 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Fri, 4 Aug 2023 15:23:18 +0100
Subject: [PATCH 05/31] debug: improve logging
---
node/email-contact-form/src/main.js | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/node/email-contact-form/src/main.js b/node/email-contact-form/src/main.js
index e20f7b5d..ce8b46a2 100644
--- a/node/email-contact-form/src/main.js
+++ b/node/email-contact-form/src/main.js
@@ -34,8 +34,6 @@ export default async ({ req, res, log, error }) => {
});
}
- log(JSON.stringify(req, null, 2));
-
if (req.headers['content-type'] !== 'application/x-www-form-urlencoded') {
error('Incorrect content type.');
return res.redirect(
@@ -84,6 +82,9 @@ export default async ({ req, res, log, error }) => {
}
const baseUrl = new URL(req.headers['referer']).origin;
+
+ log(`Redirecting to ${new URL(form._next, baseUrl).toString()}`);
+
return res.redirect(
new URL(form._next, baseUrl).toString(),
301,
From 7685ea6eef25336be3dc2814faf3892c03e85ec3 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Mon, 7 Aug 2023 20:40:07 +0100
Subject: [PATCH 06/31] fix: ruby env vars
---
ruby/starter/lib/main.rb | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/ruby/starter/lib/main.rb b/ruby/starter/lib/main.rb
index e1f28e39..9c4b488d 100644
--- a/ruby/starter/lib/main.rb
+++ b/ruby/starter/lib/main.rb
@@ -8,8 +8,8 @@ def main(context)
# client = Appwrite::Client.new
# client
# .set_endpoint('https://cloud.appwrite.io/v1')
- # .set_project(req.variables['APPWRITE_FUNCTION_PROJECT_ID'])
- # .set_key(req.variables['APPWRITE_API_KEY'])
+ # .set_project(ENV['APPWRITE_FUNCTION_PROJECT_ID'])
+ # .set_key(ENV['APPWRITE_API_KEY'])
# You can log messages to the console
context.log("Hello, Logs!")
From 7f83cf948be0c0b406cecfd22a38820afde769b9 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Fri, 11 Aug 2023 09:19:48 +0100
Subject: [PATCH 07/31] chore: fmt, add missing import
---
node/generate-pdf/src/faker.js | 32 +++++++--------
node/generate-pdf/src/pdf.js | 73 +++++++++++++++++-----------------
2 files changed, 53 insertions(+), 52 deletions(-)
diff --git a/node/generate-pdf/src/faker.js b/node/generate-pdf/src/faker.js
index e0d0010b..5185fa9b 100644
--- a/node/generate-pdf/src/faker.js
+++ b/node/generate-pdf/src/faker.js
@@ -1,20 +1,20 @@
import { faker } from '@faker-js/faker';
export function generateFakeOrder() {
- const items = Array.from(
- { length: faker.number.int({ min: 1, max: 5 }) },
- () => ({
- description: faker.commerce.productName(),
- quantity: faker.number.int({ min: 1, max: 10 }),
- cost: faker.commerce.price(),
- })
- );
+ const items = Array.from(
+ { length: faker.number.int({ min: 1, max: 5 }) },
+ () => ({
+ description: faker.commerce.productName(),
+ quantity: faker.number.int({ min: 1, max: 10 }),
+ cost: faker.commerce.price(),
+ })
+ );
- return {
- id: faker.string.uuid(),
- date: faker.date.past(),
- name: faker.person.fullName(),
- items,
- total: items.reduce((acc, { cost }) => acc + parseFloat(cost), 0),
- };
-}
\ No newline at end of file
+ return {
+ id: faker.string.uuid(),
+ date: faker.date.past(),
+ name: faker.person.fullName(),
+ items,
+ total: items.reduce((acc, { cost }) => acc + parseFloat(cost), 0),
+ };
+}
diff --git a/node/generate-pdf/src/pdf.js b/node/generate-pdf/src/pdf.js
index dedf2930..481b5c8f 100644
--- a/node/generate-pdf/src/pdf.js
+++ b/node/generate-pdf/src/pdf.js
@@ -1,40 +1,41 @@
import { PDFDocument } from 'pdf-lib';
+import { Buffer } from 'node:buffer';
export async function createPdf({ id, date, name, items, total }) {
- const document = await PDFDocument.create();
- const page = document.addPage([595.28, 841.89]); // A4 size
-
- page.drawText('Sample Invoice', { x: 50, y: 750, size: 20 });
- page.drawText(new Date(date).toLocaleDateString(), {
- x: 400,
- y: 750,
- size: 15,
- });
-
- page.drawText(`Hello, ${name}!`, {
- x: 50,
- y: 700,
- size: 30,
- });
-
- page.drawText(`Order ID: ${id}`, {
- x: 50,
- y: 650,
- size: 10,
- });
-
- page.drawText(`Total: $${total}`, { x: 50, y: 600, size: 15 });
-
- const orderList = items
- .map(
- ({ description, quantity, cost }) =>
- `${description} x ${quantity} = $${cost}`
- )
- .join('\n');
-
- page.drawText(orderList, { x: 50, y: 550, size: 15 });
-
- const pdfBytes = await document.save();
-
- return Buffer.from(pdfBytes.buffer);
+ const document = await PDFDocument.create();
+ const page = document.addPage([595.28, 841.89]); // A4 size
+
+ page.drawText('Sample Invoice', { x: 50, y: 750, size: 20 });
+ page.drawText(new Date(date).toLocaleDateString(), {
+ x: 400,
+ y: 750,
+ size: 15,
+ });
+
+ page.drawText(`Hello, ${name}!`, {
+ x: 50,
+ y: 700,
+ size: 30,
+ });
+
+ page.drawText(`Order ID: ${id}`, {
+ x: 50,
+ y: 650,
+ size: 10,
+ });
+
+ page.drawText(`Total: $${total}`, { x: 50, y: 600, size: 15 });
+
+ const orderList = items
+ .map(
+ ({ description, quantity, cost }) =>
+ `${description} x ${quantity} = $${cost}`
+ )
+ .join('\n');
+
+ page.drawText(orderList, { x: 50, y: 550, size: 15 });
+
+ const pdfBytes = await document.save();
+
+ return Buffer.from(pdfBytes);
}
From cfb92a4bf6d89bb4ab4073b319078a0e57ff46ce Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 15 Aug 2023 13:11:15 +0100
Subject: [PATCH 08/31] fix: comment bug
---
node/github-issue-bot/src/github.js | 6 +++---
node/github-issue-bot/src/main.js | 3 +++
2 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/node/github-issue-bot/src/github.js b/node/github-issue-bot/src/github.js
index 985591ce..21a8d953 100644
--- a/node/github-issue-bot/src/github.js
+++ b/node/github-issue-bot/src/github.js
@@ -33,10 +33,10 @@ class GithubService {
* @param {any} issue
* @param {string} comment
*/
- async postComment(issue, comment) {
+ async postComment(repository, issue, comment) {
await this.octokit.issues.createComment({
- owner: issue.repository.owner.login,
- repo: issue.repository.name,
+ owner: repository.owner.login,
+ repo: repository.name,
issue_number: issue.number,
body: comment,
});
diff --git a/node/github-issue-bot/src/main.js b/node/github-issue-bot/src/main.js
index 15abb12c..4c0c8210 100644
--- a/node/github-issue-bot/src/main.js
+++ b/node/github-issue-bot/src/main.js
@@ -11,7 +11,10 @@ export default async ({ res, req, log, error }) => {
return res.json({ ok: false, error: 'Invalid signature' }, 401);
}
+ log(JSON.stringify(req.body, null, 2));
+
await github.postComment(
+ req.body.repository,
req.body.issue,
`Thanks for the issue report @${req.body.issue.user.login}! We will look into it as soon as possible.`
);
From 4f7e95bae36133cb5536a44eb8cb1313de97d5ba Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 15 Aug 2023 13:16:53 +0100
Subject: [PATCH 09/31] fix: response
---
node/github-issue-bot/src/main.js | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/node/github-issue-bot/src/main.js b/node/github-issue-bot/src/main.js
index 4c0c8210..4adf62ff 100644
--- a/node/github-issue-bot/src/main.js
+++ b/node/github-issue-bot/src/main.js
@@ -11,7 +11,10 @@ export default async ({ res, req, log, error }) => {
return res.json({ ok: false, error: 'Invalid signature' }, 401);
}
- log(JSON.stringify(req.body, null, 2));
+ if (!github.isIssueOpenedEvent(req)) {
+ log('Received non-issue event - ignoring');
+ return res.json({ ok: true });
+ }
await github.postComment(
req.body.repository,
@@ -19,7 +22,5 @@ export default async ({ res, req, log, error }) => {
`Thanks for the issue report @${req.body.issue.user.login}! We will look into it as soon as possible.`
);
- if (!github.isIssueOpenedEvent(req)) {
- return res.json({ ok: true });
- }
+ return res.json({ ok: true });
};
From 6a5c2e9b016b1d6fe5e995e213b05f27d1a91bbc Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 15 Aug 2023 14:10:05 +0100
Subject: [PATCH 10/31] debug: obj response bug
---
node/prompt-chatgpt/src/main.js | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/node/prompt-chatgpt/src/main.js b/node/prompt-chatgpt/src/main.js
index 5ec385db..5ab15be9 100644
--- a/node/prompt-chatgpt/src/main.js
+++ b/node/prompt-chatgpt/src/main.js
@@ -1,7 +1,7 @@
import { OpenAIApi, Configuration } from 'openai';
import { getStaticFile, throwIfMissing } from './utils.js';
-export default async ({ req, res, error }) => {
+export default async ({ req, res, log }) => {
throwIfMissing(process.env, ['OPENAI_API_KEY']);
if (req.method === 'GET') {
@@ -28,6 +28,8 @@ export default async ({ req, res, error }) => {
messages: [{ role: 'user', content: req.body.prompt }],
});
+ log(JSON.stringify(response, null, 2));
+
const completion = response.data?.choices[0]?.message ?? '';
if (!completion) {
return res.json({ ok: false, error: 'Failed to query model.' }, 500);
From 9fffd95d8f22b8323d7528ba2ae7fe8c17e0a02e Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 15 Aug 2023 14:14:10 +0100
Subject: [PATCH 11/31] fix: response accessor
---
node/prompt-chatgpt/src/main.js | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/node/prompt-chatgpt/src/main.js b/node/prompt-chatgpt/src/main.js
index 5ab15be9..3e638de2 100644
--- a/node/prompt-chatgpt/src/main.js
+++ b/node/prompt-chatgpt/src/main.js
@@ -28,9 +28,7 @@ export default async ({ req, res, log }) => {
messages: [{ role: 'user', content: req.body.prompt }],
});
- log(JSON.stringify(response, null, 2));
-
- const completion = response.data?.choices[0]?.message ?? '';
+ const completion = response.data?.choices[0]?.message?.content ?? '';
if (!completion) {
return res.json({ ok: false, error: 'Failed to query model.' }, 500);
}
From 28bbe10188ae668ed5c1fdfde825a1326d14c7e5 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 15 Aug 2023 14:18:49 +0100
Subject: [PATCH 12/31] feat: standardise message on pages
---
node/analyze-with-perspectiveapi/static/index.html | 5 ++---
node/censor-with-redact/static/index.html | 5 ++---
node/prompt-chatgpt/static/index.html | 5 ++---
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/node/analyze-with-perspectiveapi/static/index.html b/node/analyze-with-perspectiveapi/static/index.html
index af9309b2..9e1dc2f3 100644
--- a/node/analyze-with-perspectiveapi/static/index.html
+++ b/node/analyze-with-perspectiveapi/static/index.html
@@ -45,9 +45,8 @@ Analyze with Perspective API Demo
class="body-text-1 u-normal u-margin-block-start-8"
style="max-width: 50rem"
>
- Use this page to test your implementation with PerspectiveAPI. Use
- the input below to enter text and receive the toxicity measure of
- the text as a response.
+ Use this page to test your implementation with PerspectiveAPI. Enter
+ text and receive the toxicity measure of the text as a response.
diff --git a/node/censor-with-redact/static/index.html b/node/censor-with-redact/static/index.html
index 4e2ba6d3..e656f36c 100644
--- a/node/censor-with-redact/static/index.html
+++ b/node/censor-with-redact/static/index.html
@@ -45,9 +45,8 @@ Censor with Redact API Demo
class="body-text-1 u-normal u-margin-block-start-8"
style="max-width: 50rem"
>
- Use this page to test your implementation with Redact API. Use the
- input below to enter text and receive the censored message as a
- response.
+ Use this page to test your implementation with Redact API. Enter
+ text and receive the censored message as a response.
diff --git a/node/prompt-chatgpt/static/index.html b/node/prompt-chatgpt/static/index.html
index ddbe6912..5e5e5d2e 100644
--- a/node/prompt-chatgpt/static/index.html
+++ b/node/prompt-chatgpt/static/index.html
@@ -45,9 +45,8 @@ Prompt ChatGPT Demo
class="body-text-1 u-normal u-margin-block-start-8"
style="max-width: 50rem"
>
- This is demo application. You can ue this app to ensure
- implementation with ChatGPT works properly. Use input below to
- enter prompts and get a response.
+ Use this page to test your implementation with OpenAI ChatGPT. Enter
+ text and receive the model output as a response.
From eaec3b717e82f7503a675b377c734bc10f32a0d5 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 15 Aug 2023 16:54:13 +0100
Subject: [PATCH 13/31] feat: use meilisearch api
---
node/sync-with-meilisearch/package-lock.json | 81 +++++++++++++-------
node/sync-with-meilisearch/package.json | 4 +-
node/sync-with-meilisearch/src/main.js | 22 +++---
node/sync-with-meilisearch/static/index.html | 33 ++++----
4 files changed, 77 insertions(+), 63 deletions(-)
diff --git a/node/sync-with-meilisearch/package-lock.json b/node/sync-with-meilisearch/package-lock.json
index 900ab9c8..515bb3fc 100644
--- a/node/sync-with-meilisearch/package-lock.json
+++ b/node/sync-with-meilisearch/package-lock.json
@@ -7,10 +7,9 @@
"": {
"name": "sync-with-meilisearch",
"version": "1.0.0",
- "license": "ISC",
"dependencies": {
- "node-appwrite": "^9.0.0",
- "undici": "^5.22.1"
+ "meilisearch": "^0.34.1",
+ "node-appwrite": "^9.0.0"
},
"devDependencies": {
"prettier": "^3.0.0"
@@ -31,17 +30,6 @@
"proxy-from-env": "^1.1.0"
}
},
- "node_modules/busboy": {
- "version": "1.6.0",
- "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz",
- "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==",
- "dependencies": {
- "streamsearch": "^1.1.0"
- },
- "engines": {
- "node": ">=10.16.0"
- }
- },
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
@@ -53,6 +41,14 @@
"node": ">= 0.8"
}
},
+ "node_modules/cross-fetch": {
+ "version": "3.1.8",
+ "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz",
+ "integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==",
+ "dependencies": {
+ "node-fetch": "^2.6.12"
+ }
+ },
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
@@ -93,6 +89,14 @@
"node": ">= 6"
}
},
+ "node_modules/meilisearch": {
+ "version": "0.34.1",
+ "resolved": "https://registry.npmjs.org/meilisearch/-/meilisearch-0.34.1.tgz",
+ "integrity": "sha512-7mrLp88JfrbvhAMhOjNPzHGd2iCLHgzNhkveMxppMOToMLQw4Ygof4ksQ9uFi7SKq3UwEhIoMoFT1rUHLD3vWQ==",
+ "dependencies": {
+ "cross-fetch": "^3.1.6"
+ }
+ },
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
@@ -121,6 +125,25 @@
"form-data": "^4.0.0"
}
},
+ "node_modules/node-fetch": {
+ "version": "2.6.12",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.12.tgz",
+ "integrity": "sha512-C/fGU2E8ToujUivIO0H+tpQ6HWo4eEmchoPIoXtxCrVghxdKq+QOHqEZW7tuP3KlV3bC8FRMO5nMCC7Zm1VP6g==",
+ "dependencies": {
+ "whatwg-url": "^5.0.0"
+ },
+ "engines": {
+ "node": "4.x || >=6.0.0"
+ },
+ "peerDependencies": {
+ "encoding": "^0.1.0"
+ },
+ "peerDependenciesMeta": {
+ "encoding": {
+ "optional": true
+ }
+ }
+ },
"node_modules/prettier": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz",
@@ -141,23 +164,23 @@
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
},
- "node_modules/streamsearch": {
- "version": "1.1.0",
- "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz",
- "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==",
- "engines": {
- "node": ">=10.0.0"
- }
+ "node_modules/tr46": {
+ "version": "0.0.3",
+ "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz",
+ "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw=="
},
- "node_modules/undici": {
- "version": "5.22.1",
- "resolved": "https://registry.npmjs.org/undici/-/undici-5.22.1.tgz",
- "integrity": "sha512-Ji2IJhFXZY0x/0tVBXeQwgPlLWw13GVzpsWPQ3rV50IFMMof2I55PZZxtm4P6iNq+L5znYN9nSTAq0ZyE6lSJw==",
+ "node_modules/webidl-conversions": {
+ "version": "3.0.1",
+ "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
+ "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ=="
+ },
+ "node_modules/whatwg-url": {
+ "version": "5.0.0",
+ "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz",
+ "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==",
"dependencies": {
- "busboy": "^1.6.0"
- },
- "engines": {
- "node": ">=14.0"
+ "tr46": "~0.0.3",
+ "webidl-conversions": "^3.0.0"
}
}
}
diff --git a/node/sync-with-meilisearch/package.json b/node/sync-with-meilisearch/package.json
index 23a8d83a..d9707a93 100644
--- a/node/sync-with-meilisearch/package.json
+++ b/node/sync-with-meilisearch/package.json
@@ -9,8 +9,8 @@
},
"keywords": [],
"dependencies": {
- "node-appwrite": "^9.0.0",
- "undici": "^5.22.1"
+ "meilisearch": "^0.34.1",
+ "node-appwrite": "^9.0.0"
},
"devDependencies": {
"prettier": "^3.0.0"
diff --git a/node/sync-with-meilisearch/src/main.js b/node/sync-with-meilisearch/src/main.js
index 306dc702..e4be4a25 100644
--- a/node/sync-with-meilisearch/src/main.js
+++ b/node/sync-with-meilisearch/src/main.js
@@ -1,6 +1,6 @@
import { Client, Databases, Query } from 'node-appwrite';
-import { fetch } from 'undici';
import { getStaticFile, interpolate, throwIfMissing } from './utils.js';
+import { MeiliSearch } from 'meilisearch';
export default async ({ req, res, log }) => {
throwIfMissing(process.env, [
@@ -31,6 +31,13 @@ export default async ({ req, res, log }) => {
const databases = new Databases(client);
+ const meilisearch = new MeiliSearch({
+ host: process.env.MEILISEARCH_ENDPOINT,
+ apiKey: process.env.MEILISEARCH_ADMIN_API_KEY,
+ });
+
+ const index = meilisearch.index(process.env.MEILISEARCH_INDEX_NAME);
+
let cursor = null;
do {
@@ -55,18 +62,7 @@ export default async ({ req, res, log }) => {
}
log(`Syncing chunk of ${documents.length} documents ...`);
-
- await fetch(
- `${process.env.MEILISEARCH_ENDPOINT}/indexes/${process.env.MEILISEARCH_INDEX_NAME}/documents?primaryKey=$id`,
- {
- method: 'POST',
- headers: {
- 'Content-Type': 'application/json',
- Authorization: `Bearer ${process.env.MEILISEARCH_ADMIN_API_KEY}`,
- },
- body: JSON.stringify(documents),
- }
- );
+ index.addDocuments(documents);
} while (cursor !== null);
log('Sync finished.');
diff --git a/node/sync-with-meilisearch/static/index.html b/node/sync-with-meilisearch/static/index.html
index b10f9b59..fe15b0c4 100644
--- a/node/sync-with-meilisearch/static/index.html
+++ b/node/sync-with-meilisearch/static/index.html
@@ -1,4 +1,4 @@
-
+
@@ -6,23 +6,18 @@
Meilisearch Search Demo
-
@@ -44,9 +39,9 @@ Meilisearch Search Demo
class="body-text-1 u-normal u-margin-block-start-8"
style="max-width: 50rem"
>
- This is demo application. You can ue this app to ensure sync between
- Appwrite Databases and Meilisearch Seach was successful. Use search
- input below to search your data.
+ Use this demo to verify that the sync between Appwrite Databases and
+ Meilisearch Seach was successful. Search your MeiliSearch index
+ using the input below.
From 3ce6332b4b84028833879a42006544ee5efc5612 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Tue, 15 Aug 2023 16:57:25 +0100
Subject: [PATCH 14/31] fix: text
---
node/sync-with-meilisearch/static/index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/node/sync-with-meilisearch/static/index.html b/node/sync-with-meilisearch/static/index.html
index fe15b0c4..e839fbed 100644
--- a/node/sync-with-meilisearch/static/index.html
+++ b/node/sync-with-meilisearch/static/index.html
@@ -4,7 +4,7 @@
- Meilisearch Search Demo
+ Meilisearch Demo
From dc82fa89303d68b7ef22780416c4480062c89480 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Wed, 16 Aug 2023 10:46:52 +0100
Subject: [PATCH 20/31] fix: dont use esm
---
node/sync-with-meilisearch/static/index.html | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/node/sync-with-meilisearch/static/index.html b/node/sync-with-meilisearch/static/index.html
index 475eb49e..6a879854 100644
--- a/node/sync-with-meilisearch/static/index.html
+++ b/node/sync-with-meilisearch/static/index.html
@@ -6,20 +6,20 @@
Meilisearch Demo
-
+
+
-
From f2a025d4e32a0688cff28cbe92523ead948b7c1c Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Wed, 16 Aug 2023 11:04:34 +0100
Subject: [PATCH 21/31] fix: return hits from onSearch
---
node/sync-with-meilisearch/static/index.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/node/sync-with-meilisearch/static/index.html b/node/sync-with-meilisearch/static/index.html
index 6a879854..395b3595 100644
--- a/node/sync-with-meilisearch/static/index.html
+++ b/node/sync-with-meilisearch/static/index.html
@@ -17,7 +17,7 @@
var index = meilisearch.index('{{MEILISEARCH_INDEX_NAME}}');
window.onSearch = async function (prompt) {
- return await index.search(prompt);
+ return await index.search(prompt).hits;
};
From e333817b470536647dcc35b4b3664fcea75f5575 Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Wed, 16 Aug 2023 11:19:14 +0100
Subject: [PATCH 22/31] fix: display hits
---
node/sync-with-meilisearch/static/index.html | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/node/sync-with-meilisearch/static/index.html b/node/sync-with-meilisearch/static/index.html
index 395b3595..2b987d4e 100644
--- a/node/sync-with-meilisearch/static/index.html
+++ b/node/sync-with-meilisearch/static/index.html
@@ -64,13 +64,12 @@ Meilisearch Demo
-
Date: Wed, 16 Aug 2023 11:39:09 +0100
Subject: [PATCH 23/31] fix: output hits
---
node/sync-with-meilisearch/static/index.html | 20 +++-----------------
1 file changed, 3 insertions(+), 17 deletions(-)
diff --git a/node/sync-with-meilisearch/static/index.html b/node/sync-with-meilisearch/static/index.html
index 2b987d4e..c25c5c9b 100644
--- a/node/sync-with-meilisearch/static/index.html
+++ b/node/sync-with-meilisearch/static/index.html
@@ -17,7 +17,7 @@
var index = meilisearch.index('{{MEILISEARCH_INDEX_NAME}}');
window.onSearch = async function (prompt) {
- return await index.search(prompt).hits;
+ return (await index.search(prompt)).hits;
};
@@ -60,22 +60,8 @@
Meilisearch Demo
-
From a7153f326cb590f1b7245db4d81b557834034aca Mon Sep 17 00:00:00 2001
From: loks0n <22452787+loks0n@users.noreply.github.com>
Date: Wed, 16 Aug 2023 13:16:29 +0100
Subject: [PATCH 24/31] chore: standardise sync templates
---
node/sync-with-algolia/env.d.ts | 1 +
node/sync-with-algolia/src/main.js | 20 +++---
node/sync-with-algolia/static/index.html | 67 +++++++-------------
node/sync-with-meilisearch/src/main.js | 2 +-
node/sync-with-meilisearch/static/index.html | 30 ++++-----
5 files changed, 50 insertions(+), 70 deletions(-)
diff --git a/node/sync-with-algolia/env.d.ts b/node/sync-with-algolia/env.d.ts
index 66c2fa46..bd364f7a 100644
--- a/node/sync-with-algolia/env.d.ts
+++ b/node/sync-with-algolia/env.d.ts
@@ -3,6 +3,7 @@ declare global {
interface ProcessEnv {
ALGOLIA_APP_ID: string;
ALGOLIA_ADMIN_API_KEY: string;
+ ALGOLIA_SEARCH_API_KEY: string;
ALGOLIA_INDEX_ID: string;
APPWRITE_ENDPOINT?: string;
APPWRITE_API_KEY: string;
diff --git a/node/sync-with-algolia/src/main.js b/node/sync-with-algolia/src/main.js
index 74f9abf9..d2793585 100644
--- a/node/sync-with-algolia/src/main.js
+++ b/node/sync-with-algolia/src/main.js
@@ -4,13 +4,13 @@ import { getStaticFile, interpolate, throwIfMissing } from './utils.js';
export default async ({ req, res, log }) => {
throwIfMissing(process.env, [
- 'ALGOLIA_APP_ID',
- 'ALGOLIA_ADMIN_API_KEY',
- 'ALGOLIA_INDEX_ID',
- 'ALGOLIA_SEARCH_API_KEY',
'APPWRITE_API_KEY',
'APPWRITE_DATABASE_ID',
'APPWRITE_COLLECTION_ID',
+ 'ALGOLIA_APP_ID',
+ 'ALGOLIA_INDEX_ID',
+ 'ALGOLIA_ADMIN_API_KEY',
+ 'ALGOLIA_SEARCH_API_KEY',
]);
if (req.method === 'GET') {
@@ -36,10 +36,9 @@ export default async ({ req, res, log }) => {
process.env.ALGOLIA_APP_ID,
process.env.ALGOLIA_ADMIN_API_KEY
);
- const algoliaIndex = algolia.initIndex(process.env.ALGOLIA_INDEX_ID);
+ const index = algolia.initIndex(process.env.ALGOLIA_INDEX_ID);
let cursor = null;
-
do {
const queries = [Query.limit(100)];
@@ -63,14 +62,15 @@ export default async ({ req, res, log }) => {
log(`Syncing chunk of ${response.documents.length} documents ...`);
- const records = response.documents.map((document) => ({
+ const records = response.documents.map(({ $id, ...document }) => ({
...document,
- objectID: document.$id,
+ objectID: $id,
}));
- await algoliaIndex.saveObjects(records);
+
+ await index.saveObjects(records);
} while (cursor !== null);
log('Sync finished.');
- return res.empty();
+ return res.send('Sync finished.', 200);
};
diff --git a/node/sync-with-algolia/static/index.html b/node/sync-with-algolia/static/index.html
index c0b519d0..9ea7ddba 100644
--- a/node/sync-with-algolia/static/index.html
+++ b/node/sync-with-algolia/static/index.html
@@ -6,23 +6,12 @@
Algolia Search Demo
-
-
+
+
-
@@ -40,9 +29,9 @@ Algolia Search Demo
class="body-text-1 u-normal u-margin-block-start-8"
style="max-width: 50rem"
>
- This is demo application. You can ue this app to ensure sync between
- Appwrite Databases and Algolia Seach was successful. Use search
- input below to search your data.
+ Use this demo to verify that the sync between Appwrite Databases and
+ Algolia was successful. Search your Algolia index using the input
+ below.
@@ -55,44 +44,34 @@ Algolia Search Demo
diff --git a/node/sync-with-meilisearch/src/main.js b/node/sync-with-meilisearch/src/main.js
index 18534831..432133d7 100644
--- a/node/sync-with-meilisearch/src/main.js
+++ b/node/sync-with-meilisearch/src/main.js
@@ -9,8 +9,8 @@ export default async ({ req, res, log }) => {
'APPWRITE_COLLECTION_ID',
'MEILISEARCH_ENDPOINT',
'MEILISEARCH_INDEX_NAME',
- 'MEILISEARCH_SEARCH_API_KEY',
'MEILISEARCH_ADMIN_API_KEY',
+ 'MEILISEARCH_SEARCH_API_KEY',
]);
if (req.method === 'GET') {
diff --git a/node/sync-with-meilisearch/static/index.html b/node/sync-with-meilisearch/static/index.html
index c25c5c9b..ca23d017 100644
--- a/node/sync-with-meilisearch/static/index.html
+++ b/node/sync-with-meilisearch/static/index.html
@@ -8,18 +8,6 @@
-
@@ -39,8 +27,8 @@ Meilisearch Demo
style="max-width: 50rem"
>
Use this demo to verify that the sync between Appwrite Databases and
- Meilisearch Seach was successful. Search your MeiliSearch index
- using the input below.
+ Meilisearch was successful. Search your Meilisearch index using the
+ input below.
@@ -60,7 +48,7 @@ Meilisearch Demo
-
+
@@ -68,5 +56,17 @@
Meilisearch Demo
+