From a3fefcf373d79a686867fa17d0a7bb312223dda3 Mon Sep 17 00:00:00 2001 From: shadrach Date: Sat, 21 Dec 2024 10:23:07 +0100 Subject: [PATCH 1/3] migrate fully to sync worker --- .env.example | 2 +- desci-repo/src/controllers/nodes/documents.ts | 141 +++++------ desci-server/src/services/repoService.ts | 21 +- desci-server/test/integration/data.test.ts | 4 +- sync-server/src/index.ts | 236 ++++++------------ 5 files changed, 151 insertions(+), 253 deletions(-) diff --git a/.env.example b/.env.example index 408d3087..dfe08912 100755 --- a/.env.example +++ b/.env.example @@ -167,4 +167,4 @@ OPEN_ALEX_DATABASE_URL=postgresql://username:password@host/database?schema=opena CLOUDFLARE_WORKER_API=http://host.docker.internal:5445 CLOUDFLARE_WORKER_API_SECRET=auth-token -ENABLE_WORKERS_API=false +ENABLE_WORKERS_API=true diff --git a/desci-repo/src/controllers/nodes/documents.ts b/desci-repo/src/controllers/nodes/documents.ts index a65d88c5..d4c1f3aa 100644 --- a/desci-repo/src/controllers/nodes/documents.ts +++ b/desci-repo/src/controllers/nodes/documents.ts @@ -3,7 +3,7 @@ import os from 'os'; import { Doc } from '@automerge/automerge'; import { AutomergeUrl, DocHandleEphemeralMessagePayload, DocumentId, PeerId, Repo } from '@automerge/automerge-repo'; import { ManifestActions, ResearchObjectV1 } from '@desci-labs/desci-models'; -import { Request, Response } from 'express'; +import { json, Request, Response } from 'express'; import WebSocket from 'isomorphic-ws'; import { ZodError } from 'zod'; @@ -49,21 +49,42 @@ export const createNodeDocument = async function (req: Request, res: Response) { } const { uuid, manifest } = req.body; - logger.trace({ protocol, PARTY_SERVER_HOST, PARTY_SERVER_TOKEN }, 'ENV'); - const response = await fetch(`${protocol}${PARTY_SERVER_HOST}/api/documents`, { - method: 'POST', - body: JSON.stringify({ uuid, manifest }), - headers: { - 'x-api-key': process.env.CLOUDFLARE_WORKER_API_SECRET ?? 'auth-token', - }, - }); - if (response.status === 200) { - const data = await response.json(); - - logger.trace({ uuid }, 'Document Created'); - res.status(200).send({ ok: true, ...data }); + logger.trace({ protocol, PARTY_SERVER_HOST, ENABLE_PARTYKIT_FEATURE }, 'ENV'); + if (ENABLE_PARTYKIT_FEATURE) { + const response = await fetch(`${protocol}${PARTY_SERVER_HOST}/api/documents`, { + method: 'POST', + body: JSON.stringify({ uuid, manifest }), + headers: { + 'x-api-key': process.env.CLOUDFLARE_WORKER_API_SECRET ?? 'auth-token', + }, + }); + if (response.status === 200) { + const data = await response.json(); + + logger.trace({ uuid }, 'Document Created'); + res.status(200).send({ ok: true, ...data }); + } else { + res.status(response.status).send({ ok: false }); + } } else { - res.status(response.status).send({ ok: false }); + let uuid = req.body.uuid; + const manifest = req.body.manifest; + uuid = ensureUuidEndsWithDot(uuid); + logger.info({ peerId: backendRepo.networkSubsystem.peerId, uuid }, '[Backend REPO]:'); + const handle = backendRepo.create(); + handle.change( + (d) => { + d.manifest = manifest; + d.uuid = uuid; + d.driveClock = Date.now().toString(); + }, + { message: 'Init Document', time: Date.now() }, + ); + + logger.trace({ peerId: backendRepo.networkSubsystem.peerId, uuid }, 'Document Created'); + + const document = await handle.doc(); + res.status(200).send({ ok: true, document, documentId: handle.documentId }); } } catch (err) { logger.error({ err }, '[Error]::createNodeDocument'); @@ -81,8 +102,7 @@ export const getLatestNodeManifest = async function (req: Request, res: Response // fast track call if documentId is available if (documentId) { if (ENABLE_PARTYKIT_FEATURE) { - const response = await fetch(`${protocol}${PARTY_SERVER_HOST}/api/documents?documentId=${documentId}`, { - // body: JSON.stringify({ uuid, documentId }), + const response = await fetch(`${protocol}${PARTY_SERVER_HOST}/parties/automerge/${documentId}`, { headers: { 'x-api-key': PARTY_SERVER_TOKEN!, }, @@ -124,7 +144,7 @@ export const getLatestNodeManifest = async function (req: Request, res: Response } if (ENABLE_PARTYKIT_FEATURE) { - const response = await fetch(`${protocol}${PARTY_SERVER_HOST}/api/documents?documentId=${documentId}`, { + const response = await fetch(`${protocol}${PARTY_SERVER_HOST}/parties/automerge/${documentId}`, { headers: { 'x-api-key': PARTY_SERVER_TOKEN!, }, @@ -162,39 +182,26 @@ export const dispatchDocumentChange = async function (req: RequestWithNode, res: res.status(400).send({ ok: false, message: 'No actions to dispatch' }); return; } - - const repo = new Repo({ - peerId: `repo-server-${hostname}` as PeerId, - // Since this is a server, we don't share generously — meaning we only sync documents they already - // know about and can ask for by ID. - sharePolicy: async () => true, - }); - const adapter = new PartykitNodeWsAdapter({ - host: PARTY_SERVER_HOST!, - party: 'automerge', - room: documentId, - query: { auth: PARTY_SERVER_TOKEN, documentId }, - protocol: IS_DEV || IS_TEST ? 'ws' : 'wss', - WebSocket: WebSocket, - }); - repo.networkSubsystem.addNetworkAdapter(adapter); - await repo.networkSubsystem.whenReady(); - - const handle = repo.find(getAutomergeUrl(documentId)); - handle.broadcast([documentId, { type: 'dispatch-changes', actions }]); - - // await new Promise((resolve) => setTimeout(resolve, 2000)); - // console.log('[TIMEOUT]', { documentId, actions }); logger.trace({ documentId, actions }, 'Actions'); let document: Doc | undefined; - const dispatchChange = await getDocumentUpdater(documentId); - - // await new Promise((resolve) => setTimeout(resolve, 5000)); + if (ENABLE_PARTYKIT_FEATURE) { + const response = await fetch(`${protocol}${PARTY_SERVER_HOST}/parties/automerge/${documentId}`, { + method: 'POST', + body: JSON.stringify({ actions, documentId }), + headers: { + 'x-api-key': PARTY_SERVER_TOKEN!, + }, + }); + const data = (await response.json()) as { document: ResearchObjectDocument }; + document = data.document; + } else { + const dispatchChange = await getDocumentUpdater(documentId); - for (const action of actions) { - document = await dispatchChange(action); + for (const action of actions) { + document = await dispatchChange(action); + } } if (!document) { @@ -230,36 +237,24 @@ export const dispatchDocumentActions = async function (req: RequestWithNode, res const validatedActions = await actionsSchema.parseAsync(actions); logger.trace({ validatedActions }, 'Actions validated'); - // const handle = await getDocumentHandle(documentId); - const repo = new Repo({ - peerId: `repo-server-${hostname}` as PeerId, - // Since this is a server, we don't share generously — meaning we only sync documents they already - // know about and can ask for by ID. - sharePolicy: async () => true, - }); - const adapter = new PartykitNodeWsAdapter({ - host: PARTY_SERVER_HOST!, - party: 'automerge', - room: documentId, - query: { auth: PARTY_SERVER_TOKEN, documentId }, - protocol: IS_DEV || IS_TEST ? 'ws' : 'wss', - WebSocket: WebSocket, - }); - repo.networkSubsystem.addNetworkAdapter(adapter); - await repo.networkSubsystem.whenReady(); - - const handle = repo.find(getAutomergeUrl(documentId)); - handle.broadcast([documentId, { type: 'dispatch-action', actions }]); - - logger.trace({ documentId, validatedActions }, 'Actions'); - let document: Doc | undefined; - const dispatchChange = await getDocumentUpdater(documentId, actions); - // await new Promise((resolve) => setTimeout(resolve, 300)); + if (ENABLE_PARTYKIT_FEATURE) { + const response = await fetch(`${protocol}${PARTY_SERVER_HOST}/parties/automerge/${documentId}`, { + method: 'POST', + body: JSON.stringify({ actions, documentId }), + headers: { + 'x-api-key': PARTY_SERVER_TOKEN!, + }, + }); + const data = (await response.json()) as { document: ResearchObjectDocument }; + document = data.document; + } else { + const dispatchChange = await getDocumentUpdater(documentId); - for (const action of actions) { - document = await dispatchChange(action); + for (const action of actions) { + document = await dispatchChange(action); + } } logger.trace({ actions, document }, '[Post Action]'); diff --git a/desci-server/src/services/repoService.ts b/desci-server/src/services/repoService.ts index 91954a59..a02fd40c 100644 --- a/desci-server/src/services/repoService.ts +++ b/desci-server/src/services/repoService.ts @@ -13,7 +13,6 @@ const logger = parentLogger.child({ module: 'Repo Service' }); const cloudflareWorkerApi = process.env.CLOUDFLARE_WORKER_API || 'https://nodes-dev-sync.desci.com'; const cloudflareWorkerApiSecret = process.env.CLOUDFLARE_WORKER_API_SECRET || 'auth-token'; const enableWorkersApi = process.env.ENABLE_WORKERS_API == 'true'; -// const enableWorkersPullApi = process.env.ENABLE_WORKERS_API == 'true'; type ApiResponse = { ok: boolean } & B; @@ -53,15 +52,14 @@ class RepoService { async dispatchAction(arg: { uuid: NodeUuid | string; documentId: DocumentId; actions: ManifestActions[] }) { logger.info({ arg, enableWorkersApi, cloudflareWorkerApi }, 'Disatch Changes'); const response = await this.#client.post<{ ok: boolean; document: ResearchObjectDocument }>( - // enableWorkersApi - // ? `${cloudflareWorkerApi}/api/documents/dispatch` - // : - `${this.baseUrl}/v1/nodes/documents/dispatch`, + enableWorkersApi + ? `${cloudflareWorkerApi}/parties/automerge/${arg.documentId}` + : `${this.baseUrl}/v1/nodes/documents/dispatch`, arg, { headers: { 'x-api-remote-traceid': (als.getStore() as any)?.traceId, - // ...(enableWorkersApi ? { 'x-api-key': cloudflareWorkerApiSecret } : undefined), + ...(enableWorkersApi ? { 'x-api-key': cloudflareWorkerApiSecret } : undefined), }, }, ); @@ -80,15 +78,14 @@ class RepoService { logger.info({ arg }, 'Disatch Actions'); try { const response = await this.#client.post<{ ok: boolean; document: ResearchObjectDocument }>( - // enableWorkersApi - // ? `${cloudflareWorkerApi}/api/documents/actions` - // : - `${this.baseUrl}/v1/nodes/documents/actions`, + enableWorkersApi + ? `${cloudflareWorkerApi}/parties/automerge/${arg.documentId}` + : `${this.baseUrl}/v1/nodes/documents/actions`, arg, { headers: { 'x-api-remote-traceid': (als.getStore() as any)?.traceId, - // ...(enableWorkersApi ? { 'x-api-key': cloudflareWorkerApiSecret } : undefined), + ...(enableWorkersApi ? { 'x-api-key': cloudflareWorkerApiSecret } : undefined), }, }, ); @@ -141,7 +138,7 @@ class RepoService { ); const response = await this.#client.get>( enableWorkersApi - ? `${cloudflareWorkerApi}/api/documents?documentId=${arg.documentId}` + ? `${cloudflareWorkerApi}/parties/automerge/${arg.documentId}` : `${this.baseUrl}/v1/nodes/documents/draft/${arg.uuid}?documentId=${arg.documentId}`, { headers: { diff --git a/desci-server/test/integration/data.test.ts b/desci-server/test/integration/data.test.ts index b248f434..7fb206ba 100644 --- a/desci-server/test/integration/data.test.ts +++ b/desci-server/test/integration/data.test.ts @@ -484,12 +484,12 @@ describe('Data Controllers', () => { const correctRefs = missingRefs.length === 0 && unusedRefs.length === 0 && Object.keys(diffRefs).length === 0; expect(correctRefs).to.equal(true); }); - it.skip('should remove deleted component from manifest', () => { + it('should remove deleted component from manifest', () => { const deletedComponentFound = res.body.manifest.components.find((c) => c.payload.path === deleteDirPath); console.log('Deleted component', res.body.manifest); expect(!!deletedComponentFound).to.not.equal(true); }); - it.skip('should cascade delete all components that were contained within the deleted directory', () => { + it('should cascade delete all components that were contained within the deleted directory', () => { const containedComponentFound = res.body.manifest.components.some((c) => c.payload.path.includes(deleteDirPath), ); diff --git a/sync-server/src/index.ts b/sync-server/src/index.ts index ae5d3f0e..17121818 100644 --- a/sync-server/src/index.ts +++ b/sync-server/src/index.ts @@ -2,7 +2,7 @@ import { Doc, DocHandle, DocHandleChangePayload, - DocHandleEphemeralMessagePayload, + // DocHandleEphemeralMessagePayload, DocHandleEvents, DocumentId, type PeerId, @@ -11,7 +11,7 @@ import { } from '@automerge/automerge-repo/slim'; import { DurableObjectState } from '@cloudflare/workers-types'; import { routePartykitRequest, Server as PartyServer, Connection, ConnectionContext, WSMessage } from 'partyserver'; -import { req, err as serialiseErr } from 'pino-std-serializers'; +import { err as serialiseErr } from 'pino-std-serializers'; import { ManifestActions, ResearchObjectV1 } from '@desci-labs/desci-models'; import { PartyKitWSServerAdapter } from './automerge-repo-network-websocket/PartykitWsServerAdapter.js'; @@ -21,7 +21,7 @@ import { PostgresStorageAdapter } from './automerge-repo-storage-postgres/Postgr import { Env } from './types.js'; import { ensureUuidEndsWithDot } from './utils.js'; import { assert } from './automerge-repo-network-websocket/assert.js'; -import { actionsSchema } from './lib/schema.js'; +// import { actionsSchema } from './lib/schema.js'; import { actionDispatcher, getAutomergeUrl, getDocumentUpdater } from './manifestRepo.js'; import { ZodError } from 'zod'; import { FromClientMessage } from './automerge-repo-network-websocket/messages.js'; @@ -39,18 +39,15 @@ export class AutomergeServer extends PartyServer { // private options: { // hibernate: true; // }; - repo: Repo; - private API_TOKEN: string; - private DATABASE_URL: string; - private environment: string; + handle: DocHandle; constructor( private readonly ctx: DurableObjectState, private readonly env: Env, ) { super(ctx, env); - // console.log('Room: ', ctx.id, env); + console.log('Room: ', ctx.id, env); } async onStart(): Promise { @@ -75,7 +72,7 @@ export class AutomergeServer extends PartyServer { const newTitle = change.patchInfo.after.manifest.title; const newCover = change.patchInfo.after.manifest.coverImage; const uuid = ensureUuidEndsWithDot(change.doc.uuid); - // console.log({ uuid: uuid, newTitle }, 'UPDATE NODE'); + // console.log({ uuid: uuid, documentId: change.handle.documentId, newTitle }, 'UPDATE NODE'); try { // TODO: Check if update message is 'UPDATE TITLE' @@ -179,6 +176,26 @@ export class AutomergeServer extends PartyServer { } } + async onRequest(request: Request) { + console.log('Incoming Request', request.url); + + if (request.headers.get('x-api-key') != this.env.API_TOKEN) { + console.log('[Error]::Api key error'); + return new Response('UnAuthorized', { status: 401 }); + } + + // push new message + if (request.method === 'POST') { + return this.dispatchAction(request); + } + + if (request.method.toLowerCase() === 'get') { + return this.getLatestDocument(request); + } + + return new Response('Method not allowed', { status: 405 }); + } + onMessage(connection: Connection, message: WSMessage): void | Promise { this.broadcast(message, [connection.id]); } @@ -195,114 +212,22 @@ export class AutomergeServer extends PartyServer { console.error({ err, msg: 'Failed to close connection', code, reason, wasClean }); } } -} - -export const delay = async (timeMs: number) => { - return new Promise((resolve) => setTimeout(resolve, timeMs)); -}; - -async function handleCreateDocument(request: Request, env: Env) { - const { Repo } = await import('@automerge/automerge-repo'); - const { query } = await database.init(env.NODES_DB.connectionString); - const config = { - storage: new PostgresStorageAdapter(query), - peerId: `cloudflare-ephemeral-peer` as PeerId, - sharePolicy: async () => true, - }; - - const repo = new Repo(config); - - let body = (await request.clone().json()) as { uuid: string; manifest: ResearchObjectV1 }; - assert(body && body.uuid && body.manifest, 'Invalid request body'); - let uuid = ensureUuidEndsWithDot(body.uuid); - const handle = repo.create(); - handle.change( - (d) => { - d.manifest = body.manifest; - d.uuid = uuid; - d.driveClock = Date.now().toString(); - }, - { message: 'Init Document', time: Date.now() }, - ); - - await repo.flush(); - let document = await handle.doc(); - - // console.log('[Request]::handleCreateDocument ', { env, document: !!document }); - return new Response(JSON.stringify({ documentId: handle.documentId, document }), { status: 200 }); -} - -async function dispatchDocumentChanges(request: Request, env: Env) { - try { - console.log('[Request]::dispatchDocumentChanges ', { env }); - // const environment = env.ENVIRONMENT || 'dev'; - // const localDbUrl = - // env.DATABASE_URL ?? process.env.WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_NODES_DB ?? ''; - // const DATABASE_URL = environment === 'dev' ? localDbUrl : env.NODES_DB.connectionString; - - const { Repo } = await import('@automerge/automerge-repo'); - const { query } = await database.init(env.NODES_DB.connectionString); - const config = { - storage: new PostgresStorageAdapter(query), - peerId: `cloudflare-ephemeral-peer` as PeerId, - sharePolicy: async () => true, - }; - - const repo = new Repo(config); - - let body = (await request.clone().json()) as { uuid: string; documentId: DocumentId; actions: ManifestActions[] }; - const actions = body.actions as ManifestActions[]; - const documentId = body.documentId as DocumentId; - - if (!(actions && actions.length > 0)) { - console.error({ body }, 'No actions to dispatch'); - return new Response(JSON.stringify({ ok: false, message: 'No actions to dispatch' }), { status: 400 }); - } - - let document: Doc | undefined; - - const dispatchChange = await getDocumentUpdater(repo, documentId); - - for (const action of actions) { - document = await dispatchChange(action); - await repo.flush(); - } - - if (!document) { - console.error({ document }, 'Document not found'); - return new Response(JSON.stringify({ ok: false, message: 'Document not found' }), { status: 400 }); + async getLatestDocument(request) { + const url = new URL(request.url); + const documentId = request.url.split('/').pop() as DocumentId; + console.log('getLatestDocument: ', { documentId, url }); + if (!documentId) { + console.error('No DocumentID found'); + return new Response(JSON.stringify({ ok: false, message: 'Invalid body' }), { status: 400 }); } - await repo.flush(); - + if (!this.handle) this.handle = this.repo.find(getAutomergeUrl(documentId)); + const document: Doc | undefined = await this.handle.doc(); return new Response(JSON.stringify({ document, ok: true }), { status: 200 }); - } catch (err) { - console.error(err, 'Error [dispatchDocumentChange]'); - - if (err instanceof ZodError) { - // res.status(400).send({ ok: false, error: err }); - return new Response(JSON.stringify({ ok: false, message: JSON.stringify(err) }), { status: 400 }); - } - - return new Response(JSON.stringify({ ok: false, message: JSON.stringify(err) }), { status: 500 }); } -} - -async function handleAutomergeActions(request: Request, env: Env) { - try { - console.log('[Request]::handleAutomergeActions ', { env }); - - const { Repo } = await import('@automerge/automerge-repo'); - const { query } = await database.init(env.NODES_DB.connectionString); - const config = { - storage: new PostgresStorageAdapter(query), - peerId: `cloudflare-ephemeral-peer` as PeerId, - sharePolicy: async () => true, - }; - - const repo = new Repo(config); + async dispatchAction(request: Request) { let body = (await request.clone().json()) as { uuid: string; documentId: DocumentId; actions: ManifestActions[] }; const actions = body.actions as ManifestActions[]; const documentId = body.documentId as DocumentId; @@ -312,31 +237,25 @@ async function handleAutomergeActions(request: Request, env: Env) { return new Response(JSON.stringify({ ok: false, message: 'No actions to dispatch' }), { status: 400 }); } - const validatedActions = await actionsSchema.parseAsync(actions); - console.log({ validatedActions }, 'Actions validated'); - - let document: Doc | undefined; - - const dispatchChange = await getDocumentUpdater(repo, documentId); + console.log('dispatchAction', { actions }); + if (!this.handle) this.handle = this.repo.find(getAutomergeUrl(documentId)); for (const action of actions) { - document = await dispatchChange(action); - await repo.flush(); + await actionDispatcher({ action, handle: this.handle, documentId }); } + const document: Doc | undefined = await this.handle.doc(); if (!document) { console.error({ document }, 'Document not found'); return new Response(JSON.stringify({ ok: false, message: 'Document not found' }), { status: 400 }); } - await repo.flush(); - return new Response(JSON.stringify({ document, ok: true }), { status: 200 }); - } catch (err) { - console.error(err, 'Error [dispatchDocumentChange]'); + } + catch(err) { + console.error('[dispatchAction Error]', { err }); if (err instanceof ZodError) { - // res.status(400).send({ ok: false, error: err }); return new Response(JSON.stringify({ ok: false, message: JSON.stringify(err) }), { status: 400 }); } @@ -344,60 +263,47 @@ async function handleAutomergeActions(request: Request, env: Env) { } } -async function getLatestDocument(request: Request, env: Env) { - try { - console.log('[Request]::getLatestDocument ', { env }); +export const delay = async (timeMs: number) => { + return new Promise((resolve) => setTimeout(resolve, timeMs)); +}; - const { Repo } = await import('@automerge/automerge-repo'); - const { query } = await database.init(env.NODES_DB.connectionString); - const config = { - storage: new PostgresStorageAdapter(query), - peerId: `cloudflare-ephemeral-peer` as PeerId, - sharePolicy: async () => true, - }; +async function handleCreateDocument(request: Request, env: Env) { + const { Repo } = await import('@automerge/automerge-repo'); + const { query } = await database.init(env.NODES_DB.connectionString); + const config = { + storage: new PostgresStorageAdapter(query), + peerId: `cloudflare-ephemeral-peer` as PeerId, + sharePolicy: async () => true, + }; - const repo = new Repo(config); - const url = new URL(request.url); - const documentId = url.searchParams.get('documentId') as DocumentId; - if (!documentId) { - console.error('No DocumentID found'); - return new Response(JSON.stringify({ ok: false, message: 'Invalid body' }), { status: 400 }); - } + const repo = new Repo(config); - let document: Doc | undefined; + let body = (await request.clone().json()) as { uuid: string; manifest: ResearchObjectV1 }; + assert(body && body.uuid && body.manifest, 'Invalid request body'); + let uuid = ensureUuidEndsWithDot(body.uuid); - const handle = repo.find(getAutomergeUrl(documentId)); - document = await handle.doc(); - console.log('LatestDocument', { documentId, document: document?.manifest.components }); + const handle = repo.create(); + handle.change( + (d) => { + d.manifest = body.manifest; + d.uuid = uuid; + d.driveClock = Date.now().toString(); + }, + { message: 'Init Document', time: Date.now() }, + ); - return new Response(JSON.stringify({ document, ok: true }), { status: 200 }); - } catch (err) { - console.error({ err }, 'Error [getLatestDocument]'); + await repo.flush(); + let document = await handle.doc(); - return new Response(JSON.stringify({ ok: false, message: JSON.stringify(err) }), { status: 500 }); - } + console.log('[Request]::handleCreateDocument ', { env, document: !!document }); + return new Response(JSON.stringify({ documentId: handle.documentId, document }), { status: 200 }); } export default { fetch(request: Request, env) { - if (request.url.includes('/api/') && request.headers.get('x-api-key') != env.API_TOKEN) { - console.log('[Error]::Api key error'); - return new Response('UnAuthorized', { status: 401 }); - } - - if (request.url.includes('/api/documents') && request.method.toLowerCase() === 'get') - return getLatestDocument(request, env); - - if (request.url.includes('/api/documents/actions') && request.method.toLowerCase() === 'post') - return handleAutomergeActions(request, env); - - if (request.url.includes('/api/documents/dispatch') && request.method.toLowerCase() === 'post') - return dispatchDocumentChanges(request, env); - if (request.url.includes('/api/documents') && request.method.toLowerCase() === 'post') return handleCreateDocument(request, env); - if (!request.url.includes('/parties/automerge')) return new Response('Not found', { status: 404 }); return routePartykitRequest(request, env) || new Response('Not found', { status: 404 }); }, }; From 3b82b77fd7b6a2f1f7a3a8105cbe82efaed23f02 Mon Sep 17 00:00:00 2001 From: shadrach Date: Sat, 21 Dec 2024 10:57:52 +0100 Subject: [PATCH 2/3] fix: workflow config --- .github/workflows/build-and-test.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-and-test.yaml b/.github/workflows/build-and-test.yaml index 0940f4a4..b457b52c 100644 --- a/.github/workflows/build-and-test.yaml +++ b/.github/workflows/build-and-test.yaml @@ -75,13 +75,13 @@ jobs: echo -e "\nSENTRY_AUTH_TOKEN=$SENTRY_AUTH" >> desci-server/.env cd desci-server && yarn build - - name: Set up sync server - run: | - cd sync-server && yarn --ignore-engines && ./scripts/build.sh test - if [ $? -ne 0 ]; then - exit 1 - fi - echo "DISK USE:"; find / -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \; 2>/dev/null + # - name: Set up sync server + # run: | + # cd sync-server && yarn --ignore-engines && ./scripts/build.sh test + # if [ $? -ne 0 ]; then + # exit 1 + # fi + # echo "DISK USE:"; find / -maxdepth 1 -mindepth 1 -type d -exec du -hs {} \; 2>/dev/null - name: Run tests run: | From 2dbc02482882a833a99d0b4b2f228f825e32907e Mon Sep 17 00:00:00 2001 From: shadrach Date: Sat, 21 Dec 2024 15:39:11 +0100 Subject: [PATCH 3/3] add secret to workflow --- .github/workflows/deploy-sync-server.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-sync-server.yaml b/.github/workflows/deploy-sync-server.yaml index 5e7f0b6d..af45425f 100644 --- a/.github/workflows/deploy-sync-server.yaml +++ b/.github/workflows/deploy-sync-server.yaml @@ -7,7 +7,8 @@ on: branches: # array of glob patterns matching against refs/heads. Optional; defaults to all - main # triggers on pushes that contain changes - develop - +env: + API_TOKEN: ${{ secrets.API_TOKEN }} jobs: deploy: runs-on: ubuntu-latest @@ -37,6 +38,8 @@ jobs: environment: staging workingDirectory: sync-server wranglerVersion: 3.95.0 + secrets: API_TOKEN + - name: Build & Deploy Worker (Production) if: github.ref == 'refs/heads/main' uses: cloudflare/wrangler-action@v3 @@ -46,3 +49,4 @@ jobs: environment: production workingDirectory: sync-server wranglerVersion: 3.95.0 + secrets: API_TOKEN