The minimalistic document archiving platform.
fix(demo): added missing routes in demo (#297)
Corentin Thomasset5aac3f7ba6ac
diff --git a/apps/papra-client/src/locales/en.yml b/apps/papra-client/src/locales/en.ymlindex 68622dc7..b82d9300 100644--- a/apps/papra-client/src/locales/en.yml+++ b/apps/papra-client/src/locales/en.yml@@ -169,6 +169,7 @@ api-errors.default: An error occurred while processing your request.api-errors.organization.invitation_already_exists: An invitation for this email already exists in this organization.api-errors.user.already_in_organization: This user is already in this organization.api-errors.user.organization_invitation_limit_reached: The maximum number of invitations has been reached for today. Please try again tomorrow.+api-errors.demo.not_available: This feature is not available in demoapi-keys.permissions.documents.title: Documentsapi-keys.permissions.documents.documents:create: Create documentsdiff --git a/apps/papra-client/src/modules/demo/demo-api-mock.ts b/apps/papra-client/src/modules/demo/demo-api-mock.tsindex b1230416..9bdf8613 100644--- a/apps/papra-client/src/modules/demo/demo-api-mock.ts+++ b/apps/papra-client/src/modules/demo/demo-api-mock.ts@@ -1,4 +1,5 @@import type { ApiKey } from '../api-keys/api-keys.types';+import type { Webhook } from '../webhooks/webhooks.types';import { get } from 'lodash-es';import { FetchError } from 'ofetch';import { createRouter } from 'radix3';@@ -11,6 +12,7 @@ import {tagDocumentStorage,taggingRuleStorage,tagStorage,+ webhooksStorage,} from './demo.storage';import { findMany, getValues } from './demo.storage.models';@@ -565,6 +567,55 @@ const inMemoryApiMock: Record<string, { handler: any }> = {},}),+ ...defineHandler({+ path: '/api/organizations/:organizationId/members',+ method: 'GET',+ handler: async ({ params: { organizationId } }) => {+ return {+ members: [{+ id: 'mem_1',+ user: {+ id: 'usr_1',+ email: '[email protected]',+ name: 'Jane Doe',+ },+ role: 'owner',+ organizationId,+ }],+ };+ },+ }),++ ...defineHandler({+ path: '/api/organizations/:organizationId/members/invitations',+ method: 'POST',+ handler: async () => {+ throw Object.assign(new FetchError('Not available in demo'), {+ status: 501,+ data: {+ error: {+ message: 'This feature is not available in demo',+ code: 'demo.not_available',+ },+ },+ });+ },+ }),++ ...defineHandler({+ path: '/api/organizations/:organizationId/members/me',+ method: 'GET',+ handler: async ({ params: { organizationId } }) => {+ return {+ member: {+ id: 'mem_1',+ role: 'owner',+ organizationId,+ },+ };+ },+ }),+...defineHandler({path: '/api/api-keys',method: 'GET',@@ -606,6 +657,80 @@ const inMemoryApiMock: Record<string, { handler: any }> = {await apiKeyStorage.removeItem(apiKeyId);},}),++ ...defineHandler({+ path: '/api/invitations/count',+ method: 'GET',+ handler: async () => ({ pendingInvitationsCount: 0 }),+ }),++ ...defineHandler({+ path: '/api/invitations',+ method: 'GET',+ handler: async () => ({ invitations: [] }),+ }),++ ...defineHandler({+ path: '/api/organizations/:organizationId/webhooks',+ method: 'GET',+ handler: async ({ params: { organizationId } }) => {+ const webhooks = await findMany(webhooksStorage, webhook => webhook.organizationId === organizationId);++ return { webhooks };+ },+ }),++ ...defineHandler({+ path: '/api/organizations/:organizationId/webhooks',+ method: 'POST',+ handler: async ({ params: { organizationId }, body }) => {+ const webhook: Webhook = {+ id: createId({ prefix: 'webhook' }),+ organizationId,+ name: get(body, 'name'),+ url: get(body, 'url'),+ enabled: true,+ events: get(body, 'events'),+ createdAt: new Date(),+ updatedAt: new Date(),+ };++ await webhooksStorage.setItem(webhook.id, webhook);++ return { webhook };+ },+ }),++ ...defineHandler({+ path: '/api/organizations/:organizationId/webhooks/:webhookId',+ method: 'GET',+ handler: async ({ params: { webhookId } }) => {+ const webhook = await webhooksStorage.getItem(webhookId);+ return { webhook };+ },+ }),++ ...defineHandler({+ path: '/api/organizations/:organizationId/webhooks/:webhookId',+ method: 'DELETE',+ handler: async ({ params: { webhookId } }) => {+ await webhooksStorage.removeItem(webhookId);+ },+ }),++ ...defineHandler({+ path: '/api/organizations/:organizationId/webhooks/:webhookId',+ method: 'PUT',+ handler: async ({ params: { webhookId }, body }) => {+ const webhook = await webhooksStorage.getItem(webhookId);++ assert(webhook, { status: 404 });++ await webhooksStorage.setItem(webhookId, Object.assign(webhook, body, { updatedAt: new Date() }));++ return { webhook };+ },+ }),};export const router = createRouter({ routes: inMemoryApiMock, strictTrailingSlash: false });diff --git a/apps/papra-client/src/modules/demo/demo.storage.ts b/apps/papra-client/src/modules/demo/demo.storage.tsindex 8e2b5366..8230c19c 100644--- a/apps/papra-client/src/modules/demo/demo.storage.ts+++ b/apps/papra-client/src/modules/demo/demo.storage.ts@@ -3,6 +3,7 @@ import type { Document } from '../documents/documents.types';import type { Organization } from '../organizations/organizations.types';import type { TaggingRule } from '../tagging-rules/tagging-rules.types';import type { Tag } from '../tags/tags.types';+import type { Webhook } from '../webhooks/webhooks.types';import { createStorage, prefixStorage } from 'unstorage';import localStorageDriver from 'unstorage/drivers/localstorage';import { trackingServices } from '../tracking/tracking.services';@@ -18,6 +19,7 @@ export const tagStorage = prefixStorage<Omit<Tag, 'documentsCount'>>(storage, 'texport const tagDocumentStorage = prefixStorage<{ documentId: string; tagId: string; id: string }>(storage, 'tagDocuments');export const taggingRuleStorage = prefixStorage<TaggingRule>(storage, 'taggingRules');export const apiKeyStorage = prefixStorage<ApiKey>(storage, 'apiKeys');+export const webhooksStorage = prefixStorage<Webhook>(storage, 'webhooks');export async function clearDemoStorage() {await storage.clear();diff --git a/apps/papra-client/src/modules/i18n/locales.types.ts b/apps/papra-client/src/modules/i18n/locales.types.tsindex 7c066695..dcf926c5 100644--- a/apps/papra-client/src/modules/i18n/locales.types.ts+++ b/apps/papra-client/src/modules/i18n/locales.types.ts@@ -163,6 +163,7 @@ export type LocaleKeys =| 'api-errors.organization.invitation_already_exists'| 'api-errors.user.already_in_organization'| 'api-errors.user.organization_invitation_limit_reached'+ | 'api-errors.demo.not_available'| 'api-keys.permissions.documents.title'| 'api-keys.permissions.documents.documents:create'| 'api-keys.permissions.documents.documents:read'