From faeb61e1f480b32854aeb263684af4d864ba1133 Mon Sep 17 00:00:00 2001 From: DrMint <29893320+DrMint@users.noreply.github.com> Date: Sat, 13 Jul 2024 19:03:21 +0200 Subject: [PATCH] Using shared library --- .gitmodules | 3 + .prettierignore | 2 + .vscode/settings.json | 12 +- package.json | 7 +- src/accesses/collections/mustBeAdmin.ts | 2 +- src/accesses/collections/mustBeAdminOrSelf.ts | 2 +- src/accesses/collections/shownOnlyToAdmin.ts | 2 +- src/accesses/fields/mustBeAdmin.ts | 2 +- src/blocks/attributeBlocks/numberBlock.ts | 2 +- src/blocks/attributeBlocks/tagsBlock.ts | 2 +- src/blocks/attributeBlocks/textBlock.ts | 2 +- src/blocks/breakBlock.ts | 2 +- src/collections/Attributes/Attributes.ts | 2 +- src/collections/Audios/Audios.ts | 2 +- src/collections/Audios/endpoints/getByID.ts | 8 +- .../ChronologyEvents/ChronologyEvents.ts | 2 +- .../blocks/collectibleBlock.ts | 2 +- .../ChronologyEvents/blocks/contentBlock.ts | 2 +- .../endpoints/getAllEndpoint.ts | 4 +- .../ChronologyEvents/endpoints/getByID.ts | 2 +- .../endpoints/importFromStrapi.ts | 2 +- src/collections/Collectibles/Collectibles.ts | 14 +- .../endpoints/getBySlugEndpoint.ts | 7 +- .../endpoints/getBySlugEndpointGallery.ts | 4 +- .../getBySlugEndpointGalleryImage.ts | 4 +- .../endpoints/getBySlugEndpointScanPage.ts | 4 +- .../endpoints/getBySlugEndpointScans.ts | 4 +- src/collections/CreditsRoles/CreditsRoles.ts | 2 +- src/collections/Currencies/Currencies.ts | 2 +- .../Currencies/endpoints/getAllEndpoint.ts | 2 +- .../Currencies/endpoints/importFromStrapi.ts | 2 +- src/collections/Files/Files.ts | 2 +- src/collections/Files/endpoints/getByID.ts | 8 +- src/collections/Folders/Folders.ts | 2 +- .../Folders/endpoints/getBySlugEndpoint.ts | 4 +- .../GenericContents/GenericContents.ts | 2 +- src/collections/Images/Images.ts | 2 +- src/collections/Images/endpoints/getByID.ts | 8 +- src/collections/Languages/Languages.ts | 2 +- .../Languages/endpoints/getAllEndpoint.ts | 2 +- .../Languages/endpoints/importFromStrapi.ts | 2 +- .../MediaThumbnails/MediaThumbnails.ts | 2 +- src/collections/Pages/Pages.ts | 2 +- .../Pages/endpoints/getBySlugEndpoint.ts | 21 +- src/collections/Recorders/Recorders.ts | 2 +- .../Recorders/endpoints/getByID.ts | 4 +- .../Recorders/endpoints/importFromStrapi.ts | 2 +- src/collections/Scans/Scans.ts | 2 +- src/collections/Tags/Tags.ts | 2 +- src/collections/Videos/Videos.ts | 2 +- src/collections/Videos/endpoints/getByID.ts | 8 +- .../VideosChannels/VideosChannels.ts | 2 +- .../VideosSubtitles/VideosSubtitles.ts | 2 +- .../WebsiteConfig/WebsiteConfig.ts | 2 +- .../endpoints/getConfigEndpoint.ts | 4 +- src/collections/Wordings/Wordings.ts | 2 +- .../Wordings/endpoints/getAllEndpoint.ts | 4 +- src/components/QuickFilters.tsx | 2 +- src/constants.ts | 312 -------- src/endpoints/getAllIdsEndpoint.ts | 4 +- src/endpoints/getAllSDKUrlsEndpoint.ts | 5 +- src/fields/creditsField/creditsField.ts | 2 +- .../translatedFields/translatedFields.ts | 2 +- src/hooks/afterOperationWebhook.ts | 3 +- src/hooks/beforeDuplicateUnpublish.ts | 2 +- src/payload.config.ts | 2 +- src/sdk.ts | 727 ------------------ src/server.ts | 30 +- src/utils/asserts.ts | 4 +- src/utils/endpoints.ts | 42 +- src/utils/imageCollectionConfig.ts | 2 +- src/utils/string.ts | 2 +- src/utils/versionedCollectionConfig.ts | 2 +- 73 files changed, 158 insertions(+), 1193 deletions(-) create mode 100644 .gitmodules create mode 100644 .prettierignore delete mode 100644 src/constants.ts delete mode 100644 src/sdk.ts diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..2c28f1e --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "src/shared"] + path = src/shared + url = https://github.com/Accords-Library/shared-library.git diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..c24330b --- /dev/null +++ b/.prettierignore @@ -0,0 +1,2 @@ +src/shared/* +dist \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 9315f09..39ae3e1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,9 +1,11 @@ { - "css.lint.unknownAtRules": "ignore", "editor.rulers": [100], - "typescript.preferences.importModuleSpecifier": "non-relative", - "editor.codeActionsOnSave": { - "source.fixAll": "explicit", - "source.organizeImports": "explicit" + "editor.tabSize": 2, + "typescript.preferences.importModuleSpecifier": "relative", + "explorer.fileNesting.enabled": true, + "explorer.fileNesting.patterns": { + "package.json": ".git*, package-lock.json, yarn.lock, pnpm-lock.yaml, bun.lockb, .ncurc.*, .nvmrc, *.config.cjs, *.config.js, *.config.ts, *config.json, .*ignore", + ".env": ".env.*", + "README.md": "*.md" } } diff --git a/package.json b/package.json index 07ea198..7bd0b3a 100644 --- a/package.json +++ b/package.json @@ -10,12 +10,13 @@ "build:server": "tsc", "build": "npm run copyfiles && npm run build:payload && npm run build:server", "serve": "cross-env PAYLOAD_CONFIG_PATH=dist/payload.config.js NODE_ENV=production node dist/server.js", - "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/ && copyfiles -u 1 \"src/sdk.ts\" dist/ && copyfiles -u 1 \"src/constants.ts\" dist/ && copyfiles -u 1 \"src/types/collections.ts\" dist/", + "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}\" dist/", "generate:types": "cross-env PAYLOAD_CONFIG_PATH=src/payload.config.ts payload generate:types", - "unused-exports": "ts-unused-exports ./tsconfig.json --excludePathsFromReport='src/payload.config.ts;src/constants.ts;src/sdk.ts;src/types/collections.ts'", + "unused-exports": "ts-unused-exports ./tsconfig.json --excludePathsFromReport='src/payload.config.ts;src/types/collections.ts;src/shared/*'", "prettier": "prettier --list-different --end-of-line auto --write src", "tsc": "tsc --noEmit", - "precommit": "npm run generate:types && npm run prettier && npm run unused-exports && npm run tsc", + "fetch-submodules": "cd src/shared && git pull && cd ../..", + "precommit": "npm run fetch-submodules && npm run generate:types && npm run prettier && npm run unused-exports && npm run tsc", "upgrade": "ncu", "prod": "rm -rf build && rm -rf dist && npm ci && npm run precommit && npm run build && npm run serve" }, diff --git a/src/accesses/collections/mustBeAdmin.ts b/src/accesses/collections/mustBeAdmin.ts index ff533ed..25d8c26 100644 --- a/src/accesses/collections/mustBeAdmin.ts +++ b/src/accesses/collections/mustBeAdmin.ts @@ -1,7 +1,7 @@ import { Access } from "payload/config"; -import { RecordersRoles } from "../../constants"; import { Recorder } from "../../types/collections"; import { isDefined, isUndefined } from "../../utils/asserts"; +import { RecordersRoles } from "../../shared/payload/constants"; export const mustBeAdmin: Access = ({ req: { user } }): boolean => { if (isUndefined(user)) return false; diff --git a/src/accesses/collections/mustBeAdminOrSelf.ts b/src/accesses/collections/mustBeAdminOrSelf.ts index fd27cfa..0777a80 100644 --- a/src/accesses/collections/mustBeAdminOrSelf.ts +++ b/src/accesses/collections/mustBeAdminOrSelf.ts @@ -1,7 +1,7 @@ import { Access } from "payload/config"; -import { RecordersRoles } from "../../constants"; import { Recorder } from "../../types/collections"; import { isUndefined } from "../../utils/asserts"; +import { RecordersRoles } from "../../shared/payload/constants"; export const mustBeAdminOrSelf: Access = ({ req: { user } }) => { if (isUndefined(user)) return false; diff --git a/src/accesses/collections/shownOnlyToAdmin.ts b/src/accesses/collections/shownOnlyToAdmin.ts index 632b98e..1224b78 100644 --- a/src/accesses/collections/shownOnlyToAdmin.ts +++ b/src/accesses/collections/shownOnlyToAdmin.ts @@ -1,7 +1,7 @@ import { User } from "payload/auth"; -import { RecordersRoles } from "../../constants"; import { Recorder } from "../../types/collections"; import { isDefined, isUndefined } from "../../utils/asserts"; +import { RecordersRoles } from "../../shared/payload/constants"; export const shownOnlyToAdmin = ({ user }: { user: User }): boolean => { if (isUndefined(user)) return false; diff --git a/src/accesses/fields/mustBeAdmin.ts b/src/accesses/fields/mustBeAdmin.ts index 1c3c34b..e60333e 100644 --- a/src/accesses/fields/mustBeAdmin.ts +++ b/src/accesses/fields/mustBeAdmin.ts @@ -1,7 +1,7 @@ import { FieldAccess } from "payload/types"; -import { RecordersRoles } from "../../constants"; import { Recorder } from "../../types/collections"; import { isDefined, isUndefined } from "../../utils/asserts"; +import { RecordersRoles } from "../../shared/payload/constants"; export const mustBeAdmin: FieldAccess = ({ req: { user } }): boolean => { if (isUndefined(user)) return false; diff --git a/src/blocks/attributeBlocks/numberBlock.ts b/src/blocks/attributeBlocks/numberBlock.ts index b0e45d4..3eff661 100644 --- a/src/blocks/attributeBlocks/numberBlock.ts +++ b/src/blocks/attributeBlocks/numberBlock.ts @@ -1,6 +1,6 @@ import { Block } from "payload/types"; -import { AttributeTypes, Collections } from "../../constants"; import { rowField } from "../../fields/rowField/rowField"; +import { AttributeTypes, Collections } from "../../shared/payload/constants"; export const numberBlock: Block = { slug: "numberBlock", diff --git a/src/blocks/attributeBlocks/tagsBlock.ts b/src/blocks/attributeBlocks/tagsBlock.ts index 87dc406..f0e2168 100644 --- a/src/blocks/attributeBlocks/tagsBlock.ts +++ b/src/blocks/attributeBlocks/tagsBlock.ts @@ -1,6 +1,6 @@ import { Block } from "payload/types"; -import { AttributeTypes, Collections } from "../../constants"; import { rowField } from "../../fields/rowField/rowField"; +import { Collections, AttributeTypes } from "../../shared/payload/constants"; export const tagsBlock: Block = { slug: "tagsBlock", diff --git a/src/blocks/attributeBlocks/textBlock.ts b/src/blocks/attributeBlocks/textBlock.ts index b006179..b1415b8 100644 --- a/src/blocks/attributeBlocks/textBlock.ts +++ b/src/blocks/attributeBlocks/textBlock.ts @@ -1,6 +1,6 @@ import { Block } from "payload/types"; -import { AttributeTypes, Collections } from "../../constants"; import { rowField } from "../../fields/rowField/rowField"; +import { AttributeTypes, Collections } from "../../shared/payload/constants"; export const textBlock: Block = { slug: "textBlock", diff --git a/src/blocks/breakBlock.ts b/src/blocks/breakBlock.ts index d93af4c..e1295d8 100644 --- a/src/blocks/breakBlock.ts +++ b/src/blocks/breakBlock.ts @@ -1,5 +1,5 @@ import { Block } from "payload/types"; -import { BreakBlockType } from "../constants"; +import { BreakBlockType } from "../shared/payload/constants"; export const breakBlock: Block = { slug: "breakBlock", diff --git a/src/collections/Attributes/Attributes.ts b/src/collections/Attributes/Attributes.ts index 3019c67..6a08d15 100644 --- a/src/collections/Attributes/Attributes.ts +++ b/src/collections/Attributes/Attributes.ts @@ -1,11 +1,11 @@ import { CollectionConfig } from "payload/types"; import { mustBeAdmin } from "../../accesses/fields/mustBeAdmin"; -import { AttributeTypes, CollectionGroups, Collections } from "../../constants"; import { iconField } from "../../fields/iconField/iconField"; import { rowField } from "../../fields/rowField/rowField"; import { slugField } from "../../fields/slugField/slugField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; import { buildCollectionConfig } from "../../utils/collectionConfig"; +import { Collections, CollectionGroups, AttributeTypes } from "../../shared/payload/constants"; const fields = { slug: "slug", diff --git a/src/collections/Audios/Audios.ts b/src/collections/Audios/Audios.ts index 22ff29a..ebe2efe 100644 --- a/src/collections/Audios/Audios.ts +++ b/src/collections/Audios/Audios.ts @@ -1,9 +1,9 @@ -import { CollectionGroups, Collections } from "../../constants"; import { attributesField } from "../../fields/attributesField/attributesField"; import { creditsField } from "../../fields/creditsField/creditsField"; import { imageField } from "../../fields/imageField/imageField"; import { rowField } from "../../fields/rowField/rowField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; import { buildCollectionConfig } from "../../utils/collectionConfig"; import { createEditor } from "../../utils/editor"; import { getByID } from "./endpoints/getByID"; diff --git a/src/collections/Audios/endpoints/getByID.ts b/src/collections/Audios/endpoints/getByID.ts index 8ce5449..232dd8c 100644 --- a/src/collections/Audios/endpoints/getByID.ts +++ b/src/collections/Audios/endpoints/getByID.ts @@ -1,6 +1,4 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointAudio, EndpointAudioPreview, PayloadMedia } from "../../../sdk"; import { Audio } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { isAudio, isMediaThumbnail, isNotEmpty } from "../../../utils/asserts"; @@ -11,6 +9,12 @@ import { convertRTCToEndpointRTC, getLanguageId, } from "../../../utils/endpoints"; +import { Collections } from "../../../shared/payload/constants"; +import { + PayloadMedia, + EndpointAudioPreview, + EndpointAudio, +} from "../../../shared/payload/endpoint-types"; export const getByID: CollectionEndpoint = { method: "get", diff --git a/src/collections/ChronologyEvents/ChronologyEvents.ts b/src/collections/ChronologyEvents/ChronologyEvents.ts index e407ea5..890ec86 100644 --- a/src/collections/ChronologyEvents/ChronologyEvents.ts +++ b/src/collections/ChronologyEvents/ChronologyEvents.ts @@ -4,7 +4,6 @@ import { languageBasedFilters, publishStatusFilters, } from "../../components/QuickFilters"; -import { CollectionGroups, Collections } from "../../constants"; import { creditsField } from "../../fields/creditsField/creditsField"; import { rowField } from "../../fields/rowField/rowField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; @@ -20,6 +19,7 @@ import { beforeValidatePopulateNameField } from "./hooks/beforeValidatePopulateN import { validateDate } from "./validations/validateDate"; import { validateEventsTranslationsDescription } from "./validations/validateEventsTranslationsDescription"; import { validateEventsTranslationsTitle } from "./validations/validateEventsTranslationsTitle"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { name: "name", diff --git a/src/collections/ChronologyEvents/blocks/collectibleBlock.ts b/src/collections/ChronologyEvents/blocks/collectibleBlock.ts index 850a3d0..ed596c2 100644 --- a/src/collections/ChronologyEvents/blocks/collectibleBlock.ts +++ b/src/collections/ChronologyEvents/blocks/collectibleBlock.ts @@ -1,6 +1,6 @@ import { Block } from "payload/types"; -import { Collections } from "../../../constants"; import { translatedFields } from "../../../fields/translatedFields/translatedFields"; +import { Collections } from "../../../shared/payload/constants"; export const collectibleBlock: Block = { slug: "collectibleBlock", diff --git a/src/collections/ChronologyEvents/blocks/contentBlock.ts b/src/collections/ChronologyEvents/blocks/contentBlock.ts index ade726d..e14a051 100644 --- a/src/collections/ChronologyEvents/blocks/contentBlock.ts +++ b/src/collections/ChronologyEvents/blocks/contentBlock.ts @@ -1,5 +1,5 @@ import { Block } from "payload/types"; -import { Collections } from "../../../constants"; +import { Collections } from "../../../shared/payload/constants"; export const pageBlock: Block = { slug: "pageBlock", diff --git a/src/collections/ChronologyEvents/endpoints/getAllEndpoint.ts b/src/collections/ChronologyEvents/endpoints/getAllEndpoint.ts index c88b6c6..f870cbd 100644 --- a/src/collections/ChronologyEvents/endpoints/getAllEndpoint.ts +++ b/src/collections/ChronologyEvents/endpoints/getAllEndpoint.ts @@ -1,12 +1,12 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointChronologyEvent, EndpointSource } from "../../../sdk"; import { ChronologyEvent, CollectibleBlock } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { isDefined, isNotEmpty, isPayloadType } from "../../../utils/asserts"; import { convertCreditsToEndpointCredits, getDomainFromUrl } from "../../../utils/endpoints"; import { convertCollectibleToEndpointCollectiblePreview } from "../../Collectibles/endpoints/getBySlugEndpoint"; import { convertPageToEndpointPagePreview } from "../../Pages/endpoints/getBySlugEndpoint"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointChronologyEvent, EndpointSource } from "../../../shared/payload/endpoint-types"; export const getAllEndpoint: CollectionEndpoint = { method: "get", diff --git a/src/collections/ChronologyEvents/endpoints/getByID.ts b/src/collections/ChronologyEvents/endpoints/getByID.ts index 5c84ee5..2cd73db 100644 --- a/src/collections/ChronologyEvents/endpoints/getByID.ts +++ b/src/collections/ChronologyEvents/endpoints/getByID.ts @@ -1,7 +1,7 @@ import payload from "payload"; -import { Collections } from "../../../constants"; import { CollectionEndpoint } from "../../../types/payload"; import { eventToEndpointEvent } from "./getAllEndpoint"; +import { Collections } from "../../../shared/payload/constants"; export const getByID: CollectionEndpoint = { method: "get", diff --git a/src/collections/ChronologyEvents/endpoints/importFromStrapi.ts b/src/collections/ChronologyEvents/endpoints/importFromStrapi.ts index d1d9f3a..81c419b 100644 --- a/src/collections/ChronologyEvents/endpoints/importFromStrapi.ts +++ b/src/collections/ChronologyEvents/endpoints/importFromStrapi.ts @@ -1,5 +1,5 @@ -import { Collections } from "../../../constants"; import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint"; +import { Collections } from "../../../shared/payload/constants"; import { StrapiLanguage } from "../../../types/strapi"; import { isDefined, isUndefined } from "../../../utils/asserts"; import { plainTextToLexical } from "../../../utils/string"; diff --git a/src/collections/Collectibles/Collectibles.ts b/src/collections/Collectibles/Collectibles.ts index b6a873c..c0b5956 100644 --- a/src/collections/Collectibles/Collectibles.ts +++ b/src/collections/Collectibles/Collectibles.ts @@ -1,12 +1,5 @@ import { RowLabelArgs } from "payload/dist/admin/components/forms/RowLabel/types"; import { Where } from "payload/types"; -import { - CollectibleBindingTypes, - CollectibleNature, - CollectiblePageOrders, - CollectionGroups, - Collections, -} from "../../constants"; import { attributesField } from "../../fields/attributesField/attributesField"; import { backPropagationField } from "../../fields/backPropagationField/backPropagationField"; import { componentField } from "../../fields/componentField/componentField"; @@ -28,6 +21,13 @@ import { getBySlugEndpointGallery } from "./endpoints/getBySlugEndpointGallery"; import { getBySlugEndpointGalleryImage } from "./endpoints/getBySlugEndpointGalleryImage"; import { getBySlugEndpointScanPage } from "./endpoints/getBySlugEndpointScanPage"; import { getBySlugEndpointScans } from "./endpoints/getBySlugEndpointScans"; +import { + Collections, + CollectionGroups, + CollectibleNature, + CollectibleBindingTypes, + CollectiblePageOrders, +} from "../../shared/payload/constants"; const fields = { status: "_status", diff --git a/src/collections/Collectibles/endpoints/getBySlugEndpoint.ts b/src/collections/Collectibles/endpoints/getBySlugEndpoint.ts index cff7a53..bf409cf 100644 --- a/src/collections/Collectibles/endpoints/getBySlugEndpoint.ts +++ b/src/collections/Collectibles/endpoints/getBySlugEndpoint.ts @@ -1,6 +1,9 @@ -import { CollectibleNature, Collections } from "../../../constants"; import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint"; -import { EndpointCollectible, EndpointCollectiblePreview } from "../../../sdk"; +import { Collections, CollectibleNature } from "../../../shared/payload/constants"; +import { + EndpointCollectiblePreview, + EndpointCollectible, +} from "../../../shared/payload/endpoint-types"; import { Collectible } from "../../../types/collections"; import { isAudio, diff --git a/src/collections/Collectibles/endpoints/getBySlugEndpointGallery.ts b/src/collections/Collectibles/endpoints/getBySlugEndpointGallery.ts index 7d75e86..f472f6b 100644 --- a/src/collections/Collectibles/endpoints/getBySlugEndpointGallery.ts +++ b/src/collections/Collectibles/endpoints/getBySlugEndpointGallery.ts @@ -1,6 +1,6 @@ -import { Collections } from "../../../constants"; import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint"; -import { EndpointCollectibleGallery } from "../../../sdk"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointCollectibleGallery } from "../../../shared/payload/endpoint-types"; import { isImage, isNotEmpty, isPayloadType } from "../../../utils/asserts"; import { convertImageToEndpointPayloadImage, diff --git a/src/collections/Collectibles/endpoints/getBySlugEndpointGalleryImage.ts b/src/collections/Collectibles/endpoints/getBySlugEndpointGalleryImage.ts index b27bef7..36ec12c 100644 --- a/src/collections/Collectibles/endpoints/getBySlugEndpointGalleryImage.ts +++ b/src/collections/Collectibles/endpoints/getBySlugEndpointGalleryImage.ts @@ -1,11 +1,11 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointCollectibleGalleryImage } from "../../../sdk"; import { Collectible, Image } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { isDefined, isImage, isNotEmpty, isPayloadType } from "../../../utils/asserts"; import { convertSourceToEndpointSource } from "../../../utils/endpoints"; import { convertImageToEndpointImage } from "../../Images/endpoints/getByID"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointCollectibleGalleryImage } from "../../../shared/payload/endpoint-types"; export const getBySlugEndpointGalleryImage: CollectionEndpoint = { path: "/slug/:slug/gallery/:index", diff --git a/src/collections/Collectibles/endpoints/getBySlugEndpointScanPage.ts b/src/collections/Collectibles/endpoints/getBySlugEndpointScanPage.ts index 206ef28..1f93359 100644 --- a/src/collections/Collectibles/endpoints/getBySlugEndpointScanPage.ts +++ b/src/collections/Collectibles/endpoints/getBySlugEndpointScanPage.ts @@ -1,6 +1,4 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointCollectibleScanPage } from "../../../sdk"; import { Collectible, Scan } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { isDefined, isNotEmpty, isPayloadType, isScan } from "../../../utils/asserts"; @@ -8,6 +6,8 @@ import { convertScanToEndpointScanImage, convertSourceToEndpointSource, } from "../../../utils/endpoints"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointCollectibleScanPage } from "../../../shared/payload/endpoint-types"; export const getBySlugEndpointScanPage: CollectionEndpoint = { path: "/slug/:slug/scans/:index", diff --git a/src/collections/Collectibles/endpoints/getBySlugEndpointScans.ts b/src/collections/Collectibles/endpoints/getBySlugEndpointScans.ts index 5d5a881..ced5cd9 100644 --- a/src/collections/Collectibles/endpoints/getBySlugEndpointScans.ts +++ b/src/collections/Collectibles/endpoints/getBySlugEndpointScans.ts @@ -1,6 +1,6 @@ -import { Collections } from "../../../constants"; import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint"; -import { EndpointCollectibleScans } from "../../../sdk"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointCollectibleScans } from "../../../shared/payload/endpoint-types"; import { Collectible } from "../../../types/collections"; import { isImage, isNotEmpty, isPayloadType, isScan } from "../../../utils/asserts"; import { diff --git a/src/collections/CreditsRoles/CreditsRoles.ts b/src/collections/CreditsRoles/CreditsRoles.ts index 33c9674..b6e7380 100644 --- a/src/collections/CreditsRoles/CreditsRoles.ts +++ b/src/collections/CreditsRoles/CreditsRoles.ts @@ -1,9 +1,9 @@ import { CollectionConfig } from "payload/types"; -import { CollectionGroups, Collections } from "../../constants"; import { iconField } from "../../fields/iconField/iconField"; import { slugField } from "../../fields/slugField/slugField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; import { buildCollectionConfig } from "../../utils/collectionConfig"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { slug: "slug", diff --git a/src/collections/Currencies/Currencies.ts b/src/collections/Currencies/Currencies.ts index 0cc658c..e4b8194 100644 --- a/src/collections/Currencies/Currencies.ts +++ b/src/collections/Currencies/Currencies.ts @@ -1,10 +1,10 @@ import { text } from "payload/dist/fields/validations"; import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin"; -import { CollectionGroups, Collections } from "../../constants"; import { buildCollectionConfig } from "../../utils/collectionConfig"; import { getAllEndpoint } from "./endpoints/getAllEndpoint"; import { importFromStrapi } from "./endpoints/importFromStrapi"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { id: "id", diff --git a/src/collections/Currencies/endpoints/getAllEndpoint.ts b/src/collections/Currencies/endpoints/getAllEndpoint.ts index 28811cd..f48644a 100644 --- a/src/collections/Currencies/endpoints/getAllEndpoint.ts +++ b/src/collections/Currencies/endpoints/getAllEndpoint.ts @@ -1,7 +1,7 @@ import payload from "payload"; -import { Collections } from "../../../constants"; import { Currency } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; +import { Collections } from "../../../shared/payload/constants"; export const getAllEndpoint: CollectionEndpoint = { method: "get", diff --git a/src/collections/Currencies/endpoints/importFromStrapi.ts b/src/collections/Currencies/endpoints/importFromStrapi.ts index 6067eb3..37344f3 100644 --- a/src/collections/Currencies/endpoints/importFromStrapi.ts +++ b/src/collections/Currencies/endpoints/importFromStrapi.ts @@ -1,5 +1,5 @@ -import { Collections } from "../../../constants"; import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint"; +import { Collections } from "../../../shared/payload/constants"; type StrapiLanguage = { code: string; diff --git a/src/collections/Files/Files.ts b/src/collections/Files/Files.ts index 9c76d3d..1976a13 100644 --- a/src/collections/Files/Files.ts +++ b/src/collections/Files/Files.ts @@ -1,9 +1,9 @@ -import { CollectionGroups, Collections } from "../../constants"; import { attributesField } from "../../fields/attributesField/attributesField"; import { creditsField } from "../../fields/creditsField/creditsField"; import { imageField } from "../../fields/imageField/imageField"; import { rowField } from "../../fields/rowField/rowField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; +import { CollectionGroups, Collections } from "../../shared/payload/constants"; import { buildCollectionConfig } from "../../utils/collectionConfig"; import { createEditor } from "../../utils/editor"; import { getByID } from "./endpoints/getByID"; diff --git a/src/collections/Files/endpoints/getByID.ts b/src/collections/Files/endpoints/getByID.ts index 17b8dfb..46d7744 100644 --- a/src/collections/Files/endpoints/getByID.ts +++ b/src/collections/Files/endpoints/getByID.ts @@ -1,6 +1,4 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointFile, EndpointFilePreview, PayloadMedia } from "../../../sdk"; import { File } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { isFile, isMediaThumbnail, isNotEmpty } from "../../../utils/asserts"; @@ -11,6 +9,12 @@ import { convertRTCToEndpointRTC, getLanguageId, } from "../../../utils/endpoints"; +import { Collections } from "../../../shared/payload/constants"; +import { + PayloadMedia, + EndpointFilePreview, + EndpointFile, +} from "../../../shared/payload/endpoint-types"; export const getByID: CollectionEndpoint = { method: "get", diff --git a/src/collections/Folders/Folders.ts b/src/collections/Folders/Folders.ts index b4bcefe..f650dec 100644 --- a/src/collections/Folders/Folders.ts +++ b/src/collections/Folders/Folders.ts @@ -1,9 +1,9 @@ -import { CollectionGroups, Collections } from "../../constants"; import { backPropagationField } from "../../fields/backPropagationField/backPropagationField"; import { iconField } from "../../fields/iconField/iconField"; import { rowField } from "../../fields/rowField/rowField"; import { slugField } from "../../fields/slugField/slugField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; import { Folder } from "../../types/collections"; import { isPayloadType } from "../../utils/asserts"; import { buildCollectionConfig } from "../../utils/collectionConfig"; diff --git a/src/collections/Folders/endpoints/getBySlugEndpoint.ts b/src/collections/Folders/endpoints/getBySlugEndpoint.ts index fe470d0..0c7bbec 100644 --- a/src/collections/Folders/endpoints/getBySlugEndpoint.ts +++ b/src/collections/Folders/endpoints/getBySlugEndpoint.ts @@ -1,6 +1,6 @@ -import { Collections } from "../../../constants"; import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint"; -import { EndpointFolder, EndpointFolderPreview } from "../../../sdk"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointFolderPreview, EndpointFolder } from "../../../shared/payload/endpoint-types"; import { Folder, Language } from "../../../types/collections"; import { isAudio, diff --git a/src/collections/GenericContents/GenericContents.ts b/src/collections/GenericContents/GenericContents.ts index de25d5c..157e202 100644 --- a/src/collections/GenericContents/GenericContents.ts +++ b/src/collections/GenericContents/GenericContents.ts @@ -1,10 +1,10 @@ import { CollectionConfig } from "payload/types"; import { QuickFilters, languageBasedFilters } from "../../components/QuickFilters"; -import { CollectionGroups, Collections } from "../../constants"; import { rowField } from "../../fields/rowField/rowField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo"; import { buildCollectionConfig } from "../../utils/collectionConfig"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { name: "name", diff --git a/src/collections/Images/Images.ts b/src/collections/Images/Images.ts index f832d8d..3b61037 100644 --- a/src/collections/Images/Images.ts +++ b/src/collections/Images/Images.ts @@ -1,9 +1,9 @@ -import { Collections } from "../../constants"; import { createImageSizesRegenerationEndpoint } from "../../endpoints/imageSizesRegenerationEndpoint"; import { attributesField } from "../../fields/attributesField/attributesField"; import { creditsField } from "../../fields/creditsField/creditsField"; import { rowField } from "../../fields/rowField/rowField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; +import { Collections } from "../../shared/payload/constants"; import { createEditor } from "../../utils/editor"; import { buildImageCollectionConfig, diff --git a/src/collections/Images/endpoints/getByID.ts b/src/collections/Images/endpoints/getByID.ts index d4640f0..39da5d4 100644 --- a/src/collections/Images/endpoints/getByID.ts +++ b/src/collections/Images/endpoints/getByID.ts @@ -1,6 +1,4 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointImage, EndpointImagePreview, PayloadImage } from "../../../sdk"; import { Image } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { isImage, isNotEmpty, isPayloadImage } from "../../../utils/asserts"; @@ -11,6 +9,12 @@ import { convertSizesToPayloadImages, getLanguageId, } from "../../../utils/endpoints"; +import { Collections } from "../../../shared/payload/constants"; +import { + PayloadImage, + EndpointImagePreview, + EndpointImage, +} from "../../../shared/payload/endpoint-types"; export const getByID: CollectionEndpoint = { method: "get", diff --git a/src/collections/Languages/Languages.ts b/src/collections/Languages/Languages.ts index 817c8ba..9953ef7 100644 --- a/src/collections/Languages/Languages.ts +++ b/src/collections/Languages/Languages.ts @@ -1,11 +1,11 @@ import { text } from "payload/dist/fields/validations"; import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin"; -import { CollectionGroups, Collections } from "../../constants"; import { rowField } from "../../fields/rowField/rowField"; import { buildCollectionConfig } from "../../utils/collectionConfig"; import { getAllEndpoint } from "./endpoints/getAllEndpoint"; import { importFromStrapi } from "./endpoints/importFromStrapi"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { id: "id", diff --git a/src/collections/Languages/endpoints/getAllEndpoint.ts b/src/collections/Languages/endpoints/getAllEndpoint.ts index 8c95684..f9b4aa1 100644 --- a/src/collections/Languages/endpoints/getAllEndpoint.ts +++ b/src/collections/Languages/endpoints/getAllEndpoint.ts @@ -1,7 +1,7 @@ import payload from "payload"; -import { Collections } from "../../../constants"; import { Language } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; +import { Collections } from "../../../shared/payload/constants"; export const getAllEndpoint: CollectionEndpoint = { method: "get", diff --git a/src/collections/Languages/endpoints/importFromStrapi.ts b/src/collections/Languages/endpoints/importFromStrapi.ts index 61705df..b698c0b 100644 --- a/src/collections/Languages/endpoints/importFromStrapi.ts +++ b/src/collections/Languages/endpoints/importFromStrapi.ts @@ -1,5 +1,5 @@ -import { Collections } from "../../../constants"; import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint"; +import { Collections } from "../../../shared/payload/constants"; type StrapiLanguage = { name: string; diff --git a/src/collections/MediaThumbnails/MediaThumbnails.ts b/src/collections/MediaThumbnails/MediaThumbnails.ts index c72ceef..8025fc1 100644 --- a/src/collections/MediaThumbnails/MediaThumbnails.ts +++ b/src/collections/MediaThumbnails/MediaThumbnails.ts @@ -1,6 +1,6 @@ import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin"; -import { Collections } from "../../constants"; import { createImageSizesRegenerationEndpoint } from "../../endpoints/imageSizesRegenerationEndpoint"; +import { Collections } from "../../shared/payload/constants"; import { buildImageCollectionConfig, generateOpenGraphSize, diff --git a/src/collections/Pages/Pages.ts b/src/collections/Pages/Pages.ts index d091a41..c514b79 100644 --- a/src/collections/Pages/Pages.ts +++ b/src/collections/Pages/Pages.ts @@ -3,7 +3,6 @@ import { breakBlock } from "../../blocks/breakBlock"; import { sectionBlock } from "../../blocks/sectionBlock"; import { transcriptBlock } from "../../blocks/transcriptBlock"; import { QuickFilters, publishStatusFilters } from "../../components/QuickFilters"; -import { CollectionGroups, Collections } from "../../constants"; import { attributesField } from "../../fields/attributesField/attributesField"; import { backPropagationField } from "../../fields/backPropagationField/backPropagationField"; import { creditsField } from "../../fields/creditsField/creditsField"; @@ -17,6 +16,7 @@ import { beforeDuplicateUnpublish } from "../../hooks/beforeDuplicateUnpublish"; import { createEditor } from "../../utils/editor"; import { buildVersionedCollectionConfig } from "../../utils/versionedCollectionConfig"; import { getBySlugEndpoint } from "./endpoints/getBySlugEndpoint"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { slug: "slug", diff --git a/src/collections/Pages/endpoints/getBySlugEndpoint.ts b/src/collections/Pages/endpoints/getBySlugEndpoint.ts index 4d12633..fa4a743 100644 --- a/src/collections/Pages/endpoints/getBySlugEndpoint.ts +++ b/src/collections/Pages/endpoints/getBySlugEndpoint.ts @@ -1,13 +1,16 @@ -import { - BreakBlockType, - Collections, - RichTextContent, - isBlockNodeBreakBlock, - isBlockNodeSectionBlock, - isNodeBlockNode, -} from "../../../constants"; import { createGetByEndpoint } from "../../../endpoints/createGetByEndpoint"; -import { EndpointPage, EndpointPagePreview, TableOfContentEntry } from "../../../sdk"; +import { Collections, BreakBlockType } from "../../../shared/payload/constants"; +import { + EndpointPagePreview, + EndpointPage, + TableOfContentEntry, +} from "../../../shared/payload/endpoint-types"; +import { + RichTextContent, + isNodeBlockNode, + isBlockNodeSectionBlock, + isBlockNodeBreakBlock, +} from "../../../shared/payload/rich-text"; import { Page } from "../../../types/collections"; import { isImage, isNotEmpty, isPayloadType } from "../../../utils/asserts"; import { diff --git a/src/collections/Recorders/Recorders.ts b/src/collections/Recorders/Recorders.ts index 2909bde..da9ef2f 100644 --- a/src/collections/Recorders/Recorders.ts +++ b/src/collections/Recorders/Recorders.ts @@ -2,10 +2,10 @@ import { mustBeAdmin as mustBeAdminForCollections } from "../../accesses/collect import { mustBeAdminOrSelf } from "../../accesses/collections/mustBeAdminOrSelf"; import { mustBeAdmin as mustBeAdminForFields } from "../../accesses/fields/mustBeAdmin"; import { QuickFilters } from "../../components/QuickFilters"; -import { CollectionGroups, Collections, RecordersRoles } from "../../constants"; import { imageField } from "../../fields/imageField/imageField"; import { rowField } from "../../fields/rowField/rowField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; +import { Collections, CollectionGroups, RecordersRoles } from "../../shared/payload/constants"; import { buildCollectionConfig } from "../../utils/collectionConfig"; import { createEditor } from "../../utils/editor"; import { getByID } from "./endpoints/getByID"; diff --git a/src/collections/Recorders/endpoints/getByID.ts b/src/collections/Recorders/endpoints/getByID.ts index c6dcb2a..2f09625 100644 --- a/src/collections/Recorders/endpoints/getByID.ts +++ b/src/collections/Recorders/endpoints/getByID.ts @@ -1,6 +1,4 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointRecorder, EndpointRecorderPreview } from "../../../sdk"; import { Recorder } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { isImage, isPayloadType } from "../../../utils/asserts"; @@ -8,6 +6,8 @@ import { convertImageToEndpointPayloadImage, convertRTCToEndpointRTC, } from "../../../utils/endpoints"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointRecorderPreview, EndpointRecorder } from "../../../shared/payload/endpoint-types"; export const getByID: CollectionEndpoint = { method: "get", diff --git a/src/collections/Recorders/endpoints/importFromStrapi.ts b/src/collections/Recorders/endpoints/importFromStrapi.ts index 7b9ef85..52414f4 100644 --- a/src/collections/Recorders/endpoints/importFromStrapi.ts +++ b/src/collections/Recorders/endpoints/importFromStrapi.ts @@ -1,10 +1,10 @@ import payload from "payload"; -import { Collections } from "../../../constants"; import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint"; import { Recorder } from "../../../types/collections"; import { StrapiImage, StrapiLanguage } from "../../../types/strapi"; import { isDefined } from "../../../utils/asserts"; import { uploadStrapiImage } from "../../../utils/localApi"; +import { Collections } from "../../../shared/payload/constants"; type StrapiRecorder = { username: string; diff --git a/src/collections/Scans/Scans.ts b/src/collections/Scans/Scans.ts index 92fb517..9c6e4f0 100644 --- a/src/collections/Scans/Scans.ts +++ b/src/collections/Scans/Scans.ts @@ -1,6 +1,6 @@ import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin"; -import { Collections } from "../../constants"; import { createImageSizesRegenerationEndpoint } from "../../endpoints/imageSizesRegenerationEndpoint"; +import { Collections } from "../../shared/payload/constants"; import { buildImageCollectionConfig, generateWebpSize } from "../../utils/imageCollectionConfig"; const fields = { diff --git a/src/collections/Tags/Tags.ts b/src/collections/Tags/Tags.ts index f4ef886..c34dd35 100644 --- a/src/collections/Tags/Tags.ts +++ b/src/collections/Tags/Tags.ts @@ -1,10 +1,10 @@ import { CollectionConfig } from "payload/types"; -import { CollectionGroups, Collections } from "../../constants"; import { rowField } from "../../fields/rowField/rowField"; import { slugField } from "../../fields/slugField/slugField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo"; import { buildCollectionConfig } from "../../utils/collectionConfig"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { slug: "slug", diff --git a/src/collections/Videos/Videos.ts b/src/collections/Videos/Videos.ts index fef3537..b9abf49 100644 --- a/src/collections/Videos/Videos.ts +++ b/src/collections/Videos/Videos.ts @@ -1,10 +1,10 @@ -import { CollectionGroups, Collections } from "../../constants"; import { attributesField } from "../../fields/attributesField/attributesField"; import { componentField } from "../../fields/componentField/componentField"; import { creditsField } from "../../fields/creditsField/creditsField"; import { imageField } from "../../fields/imageField/imageField"; import { rowField } from "../../fields/rowField/rowField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; import { Video } from "../../types/collections"; import { isPayloadType } from "../../utils/asserts"; import { buildCollectionConfig } from "../../utils/collectionConfig"; diff --git a/src/collections/Videos/endpoints/getByID.ts b/src/collections/Videos/endpoints/getByID.ts index 0548fef..937dad5 100644 --- a/src/collections/Videos/endpoints/getByID.ts +++ b/src/collections/Videos/endpoints/getByID.ts @@ -1,6 +1,4 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointVideo, EndpointVideoPreview, PayloadMedia } from "../../../sdk"; import { Video } from "../../../types/collections"; import { CollectionEndpoint } from "../../../types/payload"; import { @@ -19,6 +17,12 @@ import { convertRTCToEndpointRTC, getLanguageId, } from "../../../utils/endpoints"; +import { Collections } from "../../../shared/payload/constants"; +import { + PayloadMedia, + EndpointVideoPreview, + EndpointVideo, +} from "../../../shared/payload/endpoint-types"; export const getByID: CollectionEndpoint = { method: "get", diff --git a/src/collections/VideosChannels/VideosChannels.ts b/src/collections/VideosChannels/VideosChannels.ts index d3bd118..243865a 100644 --- a/src/collections/VideosChannels/VideosChannels.ts +++ b/src/collections/VideosChannels/VideosChannels.ts @@ -1,8 +1,8 @@ import { CollectionConfig } from "payload/types"; -import { CollectionGroups, Collections } from "../../constants"; import { backPropagationField } from "../../fields/backPropagationField/backPropagationField"; import { rowField } from "../../fields/rowField/rowField"; import { buildCollectionConfig } from "../../utils/collectionConfig"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { url: "url", diff --git a/src/collections/VideosSubtitles/VideosSubtitles.ts b/src/collections/VideosSubtitles/VideosSubtitles.ts index 4f7ce9c..36dff73 100644 --- a/src/collections/VideosSubtitles/VideosSubtitles.ts +++ b/src/collections/VideosSubtitles/VideosSubtitles.ts @@ -1,5 +1,5 @@ import { shownOnlyToAdmin } from "../../accesses/collections/shownOnlyToAdmin"; -import { CollectionGroups, Collections } from "../../constants"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; import { buildCollectionConfig } from "../../utils/collectionConfig"; export const VideosSubtitles = buildCollectionConfig({ diff --git a/src/collections/WebsiteConfig/WebsiteConfig.ts b/src/collections/WebsiteConfig/WebsiteConfig.ts index 7bc840a..fa48563 100644 --- a/src/collections/WebsiteConfig/WebsiteConfig.ts +++ b/src/collections/WebsiteConfig/WebsiteConfig.ts @@ -1,10 +1,10 @@ import { GlobalConfig } from "payload/types"; import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; -import { CollectionGroups, Collections } from "../../constants"; import { imageField } from "../../fields/imageField/imageField"; import { rowField } from "../../fields/rowField/rowField"; import { globalAfterChangeWebhook } from "../../hooks/afterOperationWebhook"; import { getConfigEndpoint } from "./endpoints/getConfigEndpoint"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { homeBackgroundImage: "homeBackgroundImage", diff --git a/src/collections/WebsiteConfig/endpoints/getConfigEndpoint.ts b/src/collections/WebsiteConfig/endpoints/getConfigEndpoint.ts index dab72c8..a974f3f 100644 --- a/src/collections/WebsiteConfig/endpoints/getConfigEndpoint.ts +++ b/src/collections/WebsiteConfig/endpoints/getConfigEndpoint.ts @@ -1,10 +1,10 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointWebsiteConfig } from "../../../sdk"; import { CollectionEndpoint } from "../../../types/payload"; import { isImage, isPayloadType } from "../../../utils/asserts"; import { convertImageToEndpointPayloadImage } from "../../../utils/endpoints"; import { convertFolderToEndpointFolderPreview } from "../../Folders/endpoints/getBySlugEndpoint"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointWebsiteConfig } from "../../../shared/payload/endpoint-types"; export const getConfigEndpoint: CollectionEndpoint = { method: "get", diff --git a/src/collections/Wordings/Wordings.ts b/src/collections/Wordings/Wordings.ts index b8096f1..fe4d71a 100644 --- a/src/collections/Wordings/Wordings.ts +++ b/src/collections/Wordings/Wordings.ts @@ -1,12 +1,12 @@ import { CollectionConfig } from "payload/types"; import { mustBeAdmin } from "../../accesses/collections/mustBeAdmin"; import { QuickFilters, languageBasedFilters } from "../../components/QuickFilters"; -import { CollectionGroups, Collections } from "../../constants"; import { rowField } from "../../fields/rowField/rowField"; import { translatedFields } from "../../fields/translatedFields/translatedFields"; import { beforeDuplicateAddCopyTo } from "../../hooks/beforeDuplicateAddCopyTo"; import { buildCollectionConfig } from "../../utils/collectionConfig"; import { getAllEndpoint } from "./endpoints/getAllEndpoint"; +import { Collections, CollectionGroups } from "../../shared/payload/constants"; const fields = { name: "name", diff --git a/src/collections/Wordings/endpoints/getAllEndpoint.ts b/src/collections/Wordings/endpoints/getAllEndpoint.ts index bb25c61..0b7cf68 100644 --- a/src/collections/Wordings/endpoints/getAllEndpoint.ts +++ b/src/collections/Wordings/endpoints/getAllEndpoint.ts @@ -1,8 +1,8 @@ import payload from "payload"; -import { Collections } from "../../../constants"; -import { EndpointWording } from "../../../sdk"; import { CollectionEndpoint } from "../../../types/payload"; import { isPayloadType } from "../../../utils/asserts"; +import { Collections } from "../../../shared/payload/constants"; +import { EndpointWording } from "../../../shared/payload/endpoint-types"; export const getAllEndpoint: CollectionEndpoint = { method: "get", diff --git a/src/components/QuickFilters.tsx b/src/components/QuickFilters.tsx index 6eab081..078ab10 100644 --- a/src/components/QuickFilters.tsx +++ b/src/components/QuickFilters.tsx @@ -3,7 +3,7 @@ import QueryString from "qs"; import React from "react"; import { Link } from "react-router-dom"; import styled from "styled-components"; -import { LanguageCodes } from "../constants"; +import { LanguageCodes } from "../shared/payload/constants"; type Props = { slug: string; diff --git a/src/constants.ts b/src/constants.ts deleted file mode 100644 index d221367..0000000 --- a/src/constants.ts +++ /dev/null @@ -1,312 +0,0 @@ -import { EndpointAudioPreview, EndpointImagePreview, EndpointVideoPreview } from "./sdk"; -import type { BreakBlock, SectionBlock, TranscriptBlock } from "./types/collections"; - -// END MOCKING SECTION - -export enum Collections { - Attributes = "attributes", - Audios = "audios", - ChronologyEvents = "chronology-events", - Collectibles = "collectibles", - CreditsRole = "credits-roles", - Currencies = "currencies", - Files = "files", - Folders = "folders", - GenericContents = "generic-contents", - Images = "images", - Languages = "languages", - MediaThumbnails = "media-thumbnails", - Pages = "pages", - Recorders = "recorders", - Scans = "scans", - Tags = "tags", - Videos = "videos", - VideosChannels = "videos-channels", - VideosSubtitles = "videos-subtitles", - Wordings = "wordings", - WebsiteConfig = "website-config", -} - -export enum CollectionGroups { - Collections = "Collections", - Media = "Media", - Meta = "Meta", -} - -export enum LanguageCodes { - en = "English", - fr = "French", - ja = "Japan", - es = "Spanish", - "pt-br" = "Portuguese", - "zh" = "Chinese", -} - -export enum BreakBlockType { - sceneBreak = "Scene break", - space = "Empty space", - solidLine = "Solid line", - dottedLine = "Dotted line", -} - -export enum CollectibleBindingTypes { - Paperback = "Paperback", - Hardcover = "Hardcover", -} - -export enum CollectiblePageOrders { - LeftToRight = "Left to right", - RightToLeft = "Right to left", -} - -export enum CollectibleNature { - Physical = "Physical", - Digital = "Digital", -} - -export enum CollectibleContentType { - None = "None", - Indexes = "Index-based", - Pages = "Page-based", -} - -export enum RecordersRoles { - Admin = "Admin", - Recorder = "Recorder", - Api = "Api", -} - -export enum CollectionStatus { - Draft = "draft", - Published = "published", -} - -export enum AttributeTypes { - Number = "Number", - Text = "Text", - Tags = "Tags", -} - -/* WEB HOOKS */ - -export type AfterOperationWebHookMessage = { - collection: Collections; - id?: string; - addedDependantIds: string[]; - urls: string[]; -}; -/* RICH TEXT */ - -export type RichTextContent = { - root: { - children: RichTextNode[]; - direction: ("ltr" | "rtl") | null; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; - indent: number; - type: string; - version: number; - }; - [k: string]: unknown; -}; - -export type RichTextNode = { - type: string; - version: number; - [k: string]: unknown; -}; - -export interface RichTextNodeWithChildren extends RichTextNode { - children: RichTextNode[]; -} - -export interface RichTextParagraphNode extends RichTextNodeWithChildren { - type: "paragraph"; - format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; -} - -export interface RichTextListNode extends RichTextNode { - type: "list"; - children: RichTextNodeWithChildren[]; - listType: string; -} - -export interface RichTextListNumberNode extends RichTextListNode { - listType: "number"; -} - -export interface RichTextListBulletNode extends RichTextListNode { - listType: "bullet"; -} - -export interface RichTextListCheckNode extends RichTextListNode { - listType: "check"; -} - -export interface RichTextLinebreakNode extends RichTextNode { - type: "linebreak"; -} - -export interface RichTextUploadNode extends RichTextNode { - type: "upload"; - relationTo: string; -} - -export interface RichTextUploadImageNode extends RichTextUploadNode { - relationTo: Collections.Images; - value: EndpointImagePreview; -} - -export interface RichTextUploadVideoNode extends RichTextUploadNode { - relationTo: Collections.Videos; - value: EndpointVideoPreview; -} - -export interface RichTextUploadAudioNode extends RichTextUploadNode { - relationTo: Collections.Audios; - value: EndpointAudioPreview; -} - -export interface RichTextTextNode extends RichTextNode { - type: "text"; - format: number; - text: string; -} - -export interface RichTextTabNode extends RichTextNode { - type: "tab"; - format: number; -} - -export interface RichTextLinkNode extends RichTextNodeWithChildren { - type: "link"; - fields: { - linkType: "internal" | "custom"; - }; -} - -export interface RichTextLinkInternalNode extends RichTextLinkNode { - fields: { - linkType: "internal"; - newTab: boolean; - doc: { - relationTo: string; - value: any; - }; - }; -} - -export interface RichTextLinkCustomNode extends RichTextLinkNode { - fields: { - linkType: "custom"; - newTab: boolean; - url: string; - }; -} - -export interface RichTextBlockNode extends RichTextNode { - type: "block"; - fields: { - blockType: string; - }; -} - -export interface RichTextSectionBlock extends RichTextBlockNode { - fields: SectionBlock; - anchorHash: string; -} - -export interface RichTextTranscriptBlock extends RichTextBlockNode { - fields: TranscriptBlock; -} - -export interface RichTextBreakBlock extends RichTextBlockNode { - fields: BreakBlock; - anchorHash: string; -} - -export const isNodeParagraphNode = (node: RichTextNode): node is RichTextParagraphNode => - node.type === "paragraph"; - -export const isNodeUploadNode = (node: RichTextNode): node is RichTextUploadNode => - node.type === "upload"; - -export const isUploadNodeImageNode = (node: RichTextUploadNode): node is RichTextUploadImageNode => - node.relationTo === Collections.Images; - -export const isUploadNodeVideoNode = (node: RichTextUploadNode): node is RichTextUploadVideoNode => - node.relationTo === Collections.Videos; - -export const isUploadNodeAudioNode = (node: RichTextUploadNode): node is RichTextUploadAudioNode => - node.relationTo === Collections.Audios; - -export const isNodeListNode = (node: RichTextNode): node is RichTextListNode => - node.type === "list"; - -export const isListNodeNumberListNode = (node: RichTextListNode): node is RichTextListNumberNode => - node.listType === "number"; - -export const isListNodeBulletListNode = (node: RichTextListNode): node is RichTextListBulletNode => - node.listType === "bullet"; - -export const isListNodeCheckListNode = (node: RichTextListNode): node is RichTextListCheckNode => - node.listType === "check"; - -export const isNodeLinebreakNode = (node: RichTextNode): node is RichTextLinebreakNode => - node.type === "linebreak"; - -export const isNodeTextNode = (node: RichTextNode): node is RichTextTextNode => - node.type === "text"; - -export const isNodeTabNode = (node: RichTextNode): node is RichTextTabNode => node.type === "tab"; - -export const isNodeLinkNode = (node: RichTextNode): node is RichTextLinkNode => - node.type === "link"; - -export const isLinkNodeInternalLinkNode = ( - node: RichTextLinkNode -): node is RichTextLinkInternalNode => node.fields.linkType === "internal"; - -export const isLinkNodeCustomLinkNode = (node: RichTextLinkNode): node is RichTextLinkCustomNode => - node.fields.linkType === "custom"; - -export const isNodeBlockNode = (node: RichTextNode): node is RichTextBlockNode => - node.type === "block"; - -export const isBlockNodeSectionBlock = (node: RichTextBlockNode): node is RichTextSectionBlock => - node.fields.blockType === "sectionBlock"; - -export const isBlockNodeTranscriptBlock = ( - node: RichTextBlockNode -): node is RichTextTranscriptBlock => node.fields.blockType === "transcriptBlock"; - -export const isBlockNodeBreakBlock = (node: RichTextBlockNode): node is RichTextBreakBlock => - node.fields.blockType === "breakBlock"; - -/* BLOCKS */ - -/* TODO: TO BE REMOVED WHEN https://github.com/payloadcms/payload/issues/5216 is closed */ -export interface CueBlock { - content: RichTextContent; - blockType: "cueBlock"; - id?: string | null; - blockName?: string | null; -} - -export interface LineBlock { - content: RichTextContent; - blockType: "lineBlock"; - id?: string | null; - blockName?: string | null; -} - -export interface GenericBlock { - id?: string | null; - blockName?: string | null; - blockType: string; -} - -export const isBlockCueBlock = (block: GenericBlock): block is CueBlock => - block.blockType === "cueBlock"; - -export const isBlockLineBlock = (block: GenericBlock): block is LineBlock => - block.blockType === "lineBlock"; diff --git a/src/endpoints/getAllIdsEndpoint.ts b/src/endpoints/getAllIdsEndpoint.ts index e5451cf..6d2c5bc 100644 --- a/src/endpoints/getAllIdsEndpoint.ts +++ b/src/endpoints/getAllIdsEndpoint.ts @@ -1,7 +1,7 @@ import payload from "payload"; import { Endpoint } from "payload/config"; -import { Collections } from "../constants"; -import { EndpointAllIds } from "../sdk"; +import { Collections } from "../shared/payload/constants"; +import { EndpointAllIds } from "../shared/payload/endpoint-types"; export const getAllIds: Endpoint = { method: "get", diff --git a/src/endpoints/getAllSDKUrlsEndpoint.ts b/src/endpoints/getAllSDKUrlsEndpoint.ts index 74b4e83..e96ed12 100644 --- a/src/endpoints/getAllSDKUrlsEndpoint.ts +++ b/src/endpoints/getAllSDKUrlsEndpoint.ts @@ -1,8 +1,9 @@ import payload from "payload"; import { Endpoint } from "payload/config"; -import { Collections } from "../constants"; -import { EndpointAllSDKUrls, getSDKEndpoint } from "../sdk"; import { Collectible } from "../types/collections"; +import { Collections } from "../shared/payload/constants"; +import { EndpointAllSDKUrls } from "../shared/payload/endpoint-types"; +import { getSDKEndpoint } from "../shared/payload/sdk"; export const getAllSDKUrlsEndpoint: Endpoint = { method: "get", diff --git a/src/fields/creditsField/creditsField.ts b/src/fields/creditsField/creditsField.ts index a509549..92ab98d 100644 --- a/src/fields/creditsField/creditsField.ts +++ b/src/fields/creditsField/creditsField.ts @@ -1,9 +1,9 @@ import { array } from "payload/dist/fields/validations"; import { ArrayField } from "payload/types"; -import { Collections } from "../../constants"; import { Credits } from "../../types/collections"; import { hasDuplicates, isDefined, isPayloadType, isUndefined } from "../../utils/asserts"; import { rowField } from "../rowField/rowField"; +import { Collections } from "../../shared/payload/constants"; type Props = Omit; diff --git a/src/fields/translatedFields/translatedFields.ts b/src/fields/translatedFields/translatedFields.ts index 64149d1..bb0e4e6 100644 --- a/src/fields/translatedFields/translatedFields.ts +++ b/src/fields/translatedFields/translatedFields.ts @@ -1,11 +1,11 @@ import { RowLabelArgs } from "payload/dist/admin/components/forms/RowLabel/types"; import { array } from "payload/dist/fields/validations"; import { ArrayField, Field } from "payload/types"; -import { Collections } from "../../constants"; import { hasDuplicates, isDefined, isUndefined } from "../../utils/asserts"; import { rowField } from "../rowField/rowField"; import { Cell } from "./Cell"; import { RowLabel } from "./RowLabel"; +import { Collections } from "../../shared/payload/constants"; const fieldsNames = { language: "language", diff --git a/src/hooks/afterOperationWebhook.ts b/src/hooks/afterOperationWebhook.ts index e6f6c2e..449b63d 100644 --- a/src/hooks/afterOperationWebhook.ts +++ b/src/hooks/afterOperationWebhook.ts @@ -3,9 +3,10 @@ import { AfterChangeHook as CollectionAfterChangeHook, } from "payload/dist/collections/config/types"; import { AfterChangeHook as GlobalAfterChangeHook } from "payload/dist/globals/config/types"; -import { AfterOperationWebHookMessage, Collections } from "../constants"; import { getSDKUrlsForDocument } from "../endpoints/getAllSDKUrlsEndpoint"; import { getAddedBackPropagationRelationships } from "../fields/backPropagationField/backPropagationUtils"; +import { Collections } from "../shared/payload/constants"; +import { AfterOperationWebHookMessage } from "../shared/payload/webhooks"; export const globalAfterChangeWebhook: GlobalAfterChangeHook = async ({ global, diff --git a/src/hooks/beforeDuplicateUnpublish.ts b/src/hooks/beforeDuplicateUnpublish.ts index 42573a3..36246db 100644 --- a/src/hooks/beforeDuplicateUnpublish.ts +++ b/src/hooks/beforeDuplicateUnpublish.ts @@ -1,5 +1,5 @@ import { BeforeDuplicate } from "payload/types"; -import { CollectionStatus } from "../constants"; +import { CollectionStatus } from "../shared/payload/constants"; export const beforeDuplicateUnpublish: BeforeDuplicate = ({ data }) => ({ ...data, diff --git a/src/payload.config.ts b/src/payload.config.ts index c513b0c..2ed2915 100644 --- a/src/payload.config.ts +++ b/src/payload.config.ts @@ -27,10 +27,10 @@ import { WebsiteConfig } from "./collections/WebsiteConfig/WebsiteConfig"; import { Wordings } from "./collections/Wordings/Wordings"; import { Icon } from "./components/Icon"; import { Logo } from "./components/Logo"; -import { Collections } from "./constants"; import { getAllIds } from "./endpoints/getAllIdsEndpoint"; import { getAllSDKUrlsEndpoint } from "./endpoints/getAllSDKUrlsEndpoint"; import { createEditor } from "./utils/editor"; +import { Collections } from "./shared/payload/constants"; const configuredSftpAdapter = sftpAdapter({ connectOptions: { diff --git a/src/sdk.ts b/src/sdk.ts deleted file mode 100644 index 4646110..0000000 --- a/src/sdk.ts +++ /dev/null @@ -1,727 +0,0 @@ -import { - AttributeTypes, - CollectibleBindingTypes, - CollectibleNature, - CollectiblePageOrders, - Collections, - RichTextContent, -} from "./constants"; -import { Currency, Language } from "./types/collections"; - -// END MOCKING SECTION - -export type EndpointFolderPreview = { - id: string; - slug: string; - icon?: string; - translations: { - language: string; - title: string; - }[]; -}; - -export type EndpointFolder = Omit & { - translations: (EndpointFolderPreview["translations"][number] & { - description?: RichTextContent; - })[]; - sections: - | { type: "single"; subfolders: EndpointFolderPreview[] } - | { - type: "multiple"; - sections: { - translations: { language: string; name: string }[]; - subfolders: EndpointFolderPreview[]; - }[]; - }; - files: ( - | { - relationTo: Collections.Collectibles; - value: EndpointCollectiblePreview; - } - | { - relationTo: Collections.Pages; - value: EndpointPagePreview; - } - | { - relationTo: Collections.Images; - value: EndpointImagePreview; - } - | { - relationTo: Collections.Audios; - value: EndpointAudioPreview; - } - | { - relationTo: Collections.Videos; - value: EndpointVideoPreview; - } - | { - relationTo: Collections.Files; - value: EndpointFilePreview; - } - )[]; - parentPages: EndpointSource[]; -}; - -export type EndpointWebsiteConfig = { - home: { - backgroundImage?: EndpointPayloadImage; - folders: (EndpointFolderPreview & { - lightThumbnail?: EndpointPayloadImage; - darkThumbnail?: EndpointPayloadImage; - })[]; - }; - timeline: { - backgroundImage?: EndpointPayloadImage; - breaks: number[]; - eventCount: number; - eras: { - startingYear: number; - endingYear: number; - name: string; - }[]; - }; - defaultOpenGraphImage?: EndpointPayloadImage; -}; - -export type EndpointRecorderPreview = { - id: string; - username: string; -}; - -export type EndpointRecorder = EndpointRecorderPreview & { - avatar?: EndpointPayloadImage; - translations: { - language: string; - biography: RichTextContent; - }[]; - languages: string[]; -}; - -export type EndpointWording = { - name: string; - translations: { - language: string; - name: string; - }[]; -}; - -export type EndpointTag = { - id: string; - slug: string; - page?: { slug: string }; - translations: { - language: string; - name: string; - }[]; -}; - -export type EndpointGenericAttribute = { - id: string; - slug: string; - icon: string; - translations: { - language: string; - name: string; - }[]; -}; - -export type EndpointNumberAttribute = EndpointGenericAttribute & { - type: AttributeTypes.Number; - value: number; -}; - -export type EndpointTextAttribute = EndpointGenericAttribute & { - type: AttributeTypes.Text; - value: string; -}; - -export type EndpointTagsAttribute = EndpointGenericAttribute & { - type: AttributeTypes.Tags; - value: EndpointTag[]; -}; - -export type EndpointAttribute = - | EndpointNumberAttribute - | EndpointTextAttribute - | EndpointTagsAttribute; - -export type EndpointRole = { - id: string; - icon: string; - translations: { - language: string; - name: string; - }[]; -}; - -export type EndpointCredit = { - role: EndpointRole; - recorders: EndpointRecorderPreview[]; -}; - -export type EndpointPagePreview = { - id: string; - slug: string; - thumbnail?: EndpointPayloadImage; - attributes: EndpointAttribute[]; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - }[]; - updatedAt: string; -}; - -export type EndpointPage = Omit & { - backgroundImage?: EndpointPayloadImage; - translations: (EndpointPagePreview["translations"][number] & { - sourceLanguage: string; - summary?: RichTextContent; - content: RichTextContent; - credits: EndpointCredit[]; - toc: TableOfContentEntry[]; - })[]; - createdAt: string; - updatedBy?: EndpointRecorderPreview; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectiblePreview = { - id: string; - slug: string; - thumbnail?: EndpointPayloadImage; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - }[]; - attributes: EndpointAttribute[]; - releaseDate?: string; - languages: string[]; - price?: { - amount: number; - currency: string; - }; -}; - -export type EndpointCollectible = Omit & { - translations: (EndpointCollectiblePreview["translations"][number] & { - description?: RichTextContent; - })[]; - backgroundImage?: EndpointPayloadImage; - nature: CollectibleNature; - gallery?: { count: number; thumbnail: EndpointPayloadImage }; - scans?: { count: number; thumbnail: EndpointPayloadImage }; - urls: { url: string; label: string }[]; - size?: { - width: number; - height: number; - thickness?: number; - }; - weight?: number; - pageInfo?: { - pageCount: number; - bindingType?: CollectibleBindingTypes; - pageOrder?: CollectiblePageOrders; - }; - subitems: EndpointCollectiblePreview[]; - files: EndpointFilePreview[]; - contents: { - content: - | { - relationTo: Collections.Pages; - value: EndpointPagePreview; - } - | { - relationTo: Collections.Audios; - value: EndpointAudioPreview; - } - | { - relationTo: Collections.Videos; - value: EndpointVideoPreview; - } - | { - relationTo: Collections.GenericContents; - value: { - translations: { - language: string; - name: string; - }[]; - }; - }; - - range?: - | { - type: "pageRange"; - start: number; - end: number; - } - | { - type: "timeRange"; - start: string; - end: string; - } - | { - type: "other"; - translations: { - language: string; - note: RichTextContent; - }[]; - }; - }[]; - createdAt: string; - updatedAt: string; - updatedBy?: EndpointRecorderPreview; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectibleScans = { - slug: string; - thumbnail?: EndpointPayloadImage; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - description?: RichTextContent; - }[]; - credits: EndpointCredit[]; - cover?: { - front?: EndpointScanImage; - spine?: EndpointScanImage; - back?: EndpointScanImage; - insideFront?: EndpointScanImage; - insideBack?: EndpointScanImage; - flapFront?: EndpointScanImage; - flapBack?: EndpointScanImage; - insideFlapFront?: EndpointScanImage; - insideFlapBack?: EndpointScanImage; - }; - dustjacket?: { - front?: EndpointScanImage; - spine?: EndpointScanImage; - back?: EndpointScanImage; - insideFront?: EndpointScanImage; - insideSpine?: EndpointScanImage; - insideBack?: EndpointScanImage; - flapFront?: EndpointScanImage; - flapBack?: EndpointScanImage; - insideFlapFront?: EndpointScanImage; - insideFlapBack?: EndpointScanImage; - }; - obi?: { - front?: EndpointScanImage; - spine?: EndpointScanImage; - back?: EndpointScanImage; - insideFront?: EndpointScanImage; - insideSpine?: EndpointScanImage; - insideBack?: EndpointScanImage; - flapFront?: EndpointScanImage; - flapBack?: EndpointScanImage; - insideFlapFront?: EndpointScanImage; - insideFlapBack?: EndpointScanImage; - }; - pages: EndpointScanImage[]; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectibleGallery = { - slug: string; - thumbnail?: EndpointPayloadImage; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - description?: RichTextContent; - }[]; - images: EndpointPayloadImage[]; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectibleGalleryImage = { - slug: string; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - description?: RichTextContent; - }[]; - image: EndpointImage; - previousIndex?: string; - nextIndex?: string; - parentPages: EndpointSource[]; -}; - -export type EndpointCollectibleScanPage = { - slug: string; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - description?: RichTextContent; - }[]; - image: EndpointScanImage; - previousIndex?: string; - nextIndex?: string; - parentPages: EndpointSource[]; -}; - -export type EndpointScanImage = PayloadImage & { - index: string; - sizes: PayloadImage[]; -}; - -export type TableOfContentEntry = { - prefix: string; - title: string; - type: "sceneBreak" | "break" | "section"; - index: number; - children: TableOfContentEntry[]; -}; - -export type EndpointChronologyEvent = { - id: string; - date: { - year: number; - month?: number; - day?: number; - }; - events: { - sources: EndpointSource[]; - translations: { - language: string; - sourceLanguage: string; - title?: string; - description?: RichTextContent; - notes?: RichTextContent; - credits: EndpointCredit[]; - }[]; - }[]; -}; - -export type EndpointSourcePreview = { - id: string; - slug: string; - translations: { language: string; pretitle?: string; title: string; subtitle?: string }[]; -}; - -export type EndpointSource = - | { type: "url"; url: string; label: string } - | { - type: "collectible"; - collectible: EndpointSourcePreview; - range?: - | { type: "page"; page: number } - | { type: "timestamp"; timestamp: string } - | { type: "custom"; translations: { language: string; note: string }[] }; - } - | { type: "page"; page: EndpointSourcePreview } - | { type: "folder"; folder: EndpointSourcePreview } - | { type: "scans"; collectible: EndpointSourcePreview } - | { type: "gallery"; collectible: EndpointSourcePreview }; - -export type EndpointMediaPreview = { - id: string; - url: string; - filename: string; - mimeType: string; - attributes: EndpointAttribute[]; - translations: { - language: string; - pretitle?: string; - title: string; - subtitle?: string; - }[]; -}; - -export type EndpointMedia = Omit & { - filesize: number; - updatedAt: string; - createdAt: string; - translations: (EndpointMediaPreview["translations"][number] & { - description?: RichTextContent; - })[]; - credits: EndpointCredit[]; -}; - -export type EndpointImagePreview = EndpointMediaPreview & { - width: number; - height: number; - sizes: PayloadImage[]; - openGraph?: PayloadImage; -}; - -export type EndpointImage = EndpointMedia & { - width: number; - height: number; - sizes: PayloadImage[]; - openGraph?: PayloadImage; -}; - -export type EndpointAudioPreview = EndpointMediaPreview & { - thumbnail?: EndpointPayloadImage; - duration: number; -}; - -export type EndpointAudio = EndpointMedia & { - thumbnail?: EndpointPayloadImage; - duration: number; -}; - -export type EndpointVideoPreview = EndpointMediaPreview & { - thumbnail?: EndpointPayloadImage; - subtitles: { - language: string; - url: string; - }[]; - duration: number; -}; - -export type EndpointVideo = EndpointMedia & { - thumbnail?: EndpointPayloadImage; - subtitles: { - language: string; - url: string; - }[]; - platform?: { - channel: { - url: string; - title: string; - subscribers: number; - }; - views?: number; - likes?: number; - dislikes?: number; - url: string; - publishedDate: string; - }; - duration: number; -}; - -export type EndpointFilePreview = EndpointMediaPreview & { - filesize: number; - thumbnail?: EndpointPayloadImage; -}; - -export type EndpointFile = EndpointMedia & { - filesize: number; - thumbnail?: EndpointPayloadImage; -}; - -export type EndpointPayloadImage = PayloadImage & { - sizes: PayloadImage[]; - openGraph?: PayloadImage; -}; - -export type PayloadMedia = { - id: string; - url: string; - mimeType: string; - filename: string; - filesize: number; -}; - -export type PayloadImage = PayloadMedia & { - width: number; - height: number; -}; - -export type EndpointAllSDKUrls = { - urls: string[]; -}; - -export type EndpointAllIds = { - collectibles: { slugs: string[] }; - pages: { slugs: string[] }; - folders: { slugs: string[] }; - videos: { ids: string[] }; - audios: { ids: string[] }; - images: { ids: string[] }; - files: { ids: string[] }; - recorders: { ids: string[] }; - chronologyEvents: { ids: string[] }; -}; - -// SDK - -export const getSDKEndpoint = { - getConfigEndpoint: () => `/globals/${Collections.WebsiteConfig}/config`, - getFolderEndpoint: (slug: string) => `/${Collections.Folders}/slug/${slug}`, - getLanguagesEndpoint: () => `/${Collections.Languages}/all`, - getCurrenciesEndpoint: () => `/${Collections.Currencies}/all`, - getWordingsEndpoint: () => `/${Collections.Wordings}/all`, - getPageEndpoint: (slug: string) => `/${Collections.Pages}/slug/${slug}`, - getCollectibleEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}`, - getCollectibleScansEndpoint: (slug: string) => `/${Collections.Collectibles}/slug/${slug}/scans`, - getCollectibleScanPageEndpoint: (slug: string, index: string) => - `/${Collections.Collectibles}/slug/${slug}/scans/${index}`, - getCollectibleGalleryEndpoint: (slug: string) => - `/${Collections.Collectibles}/slug/${slug}/gallery`, - getCollectibleGalleryImageEndpoint: (slug: string, index: string) => - `/${Collections.Collectibles}/slug/${slug}/gallery/${index}`, - getChronologyEventsEndpoint: () => `/${Collections.ChronologyEvents}/all`, - getChronologyEventByIDEndpoint: (id: string) => `/${Collections.ChronologyEvents}/id/${id}`, - getImageByIDEndpoint: (id: string) => `/${Collections.Images}/id/${id}`, - getAudioByIDEndpoint: (id: string) => `/${Collections.Audios}/id/${id}`, - getVideoByIDEndpoint: (id: string) => `/${Collections.Videos}/id/${id}`, - getFileByIDEndpoint: (id: string) => `/${Collections.Files}/id/${id}`, - getRecorderByIDEndpoint: (id: string) => `/${Collections.Recorders}/id/${id}`, - getAllSDKUrlsEndpoint: () => `/all-sdk-urls`, - getAllIds: () => `/all-ids`, - getLoginEndpoint: () => `/${Collections.Recorders}/login`, -}; - -type PayloadSDKResponse = { - data: T; - endpointCalled: string; -}; - -type PayloadTokenCache = { - set: (token: string, expirationTimestamp: number) => void; - get: () => string | undefined; -}; - -type PayloadDataCache = { - set: (url: string, response: any) => void; - get: (url: string) => any | undefined; -}; - -export class PayloadSDK { - private tokenCache: PayloadTokenCache | undefined; - private dataCache: PayloadDataCache | undefined; - - constructor( - private readonly apiURL: string, - private readonly email: string, - private readonly password: string - ) {} - - addTokenCache(tokenCache: PayloadTokenCache) { - this.tokenCache = tokenCache; - } - - addDataCache(dataCache: PayloadDataCache) { - this.dataCache = dataCache; - } - - private logResponse(res: Response) { - console.log(res.status, res.statusText, res.url); - } - - private async refreshToken() { - const loginUrl = `${this.apiURL}${getSDKEndpoint.getLoginEndpoint()}`; - const loginResult = await fetch(loginUrl, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ email: this.email, password: this.password }), - }); - this.logResponse(loginResult); - - if (loginResult.status !== 200) { - throw new Error("Unable to login"); - } - - const { token, exp } = (await loginResult.json()) as { - token: string; - exp: number; - }; - this.tokenCache?.set(token, exp); - return token; - } - - async request(endpoint: string): Promise> { - const cachedResponse = this.dataCache?.get(endpoint); - if (cachedResponse) { - return cachedResponse; - } - - const result = await fetch(`${this.apiURL}${endpoint}`, { - headers: { - Authorization: `JWT ${this.tokenCache?.get() ?? (await this.refreshToken())}`, - }, - }); - this.logResponse(result); - - if (!result.ok) { - throw new Error("Unhandled fetch error"); - } - - const response = { data: await result.json(), endpointCalled: endpoint }; - this.dataCache?.set(endpoint, response); - return response; - } - - async getConfig(): Promise> { - return await this.request(getSDKEndpoint.getConfigEndpoint()); - } - async getFolder(slug: string): Promise> { - return await this.request(getSDKEndpoint.getFolderEndpoint(slug)); - } - async getLanguages(): Promise> { - return await this.request(getSDKEndpoint.getLanguagesEndpoint()); - } - async getCurrencies(): Promise> { - return await this.request(getSDKEndpoint.getCurrenciesEndpoint()); - } - async getWordings(): Promise> { - return await this.request(getSDKEndpoint.getWordingsEndpoint()); - } - async getPage(slug: string): Promise> { - return await this.request(getSDKEndpoint.getPageEndpoint(slug)); - } - async getCollectible(slug: string): Promise> { - return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug)); - } - async getCollectibleScans(slug: string): Promise> { - return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug)); - } - async getCollectibleScanPage( - slug: string, - index: string - ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index)); - } - async getCollectibleGallery( - slug: string - ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleGalleryEndpoint(slug)); - } - async getCollectibleGalleryImage( - slug: string, - index: string - ): Promise> { - return await this.request(getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index)); - } - async getChronologyEvents(): Promise> { - return await this.request(getSDKEndpoint.getChronologyEventsEndpoint()); - } - async getChronologyEventByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getChronologyEventByIDEndpoint(id)); - } - async getImageByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getImageByIDEndpoint(id)); - } - async getAudioByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getAudioByIDEndpoint(id)); - } - async getVideoByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getVideoByIDEndpoint(id)); - } - async getFileByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getFileByIDEndpoint(id)); - } - async getRecorderByID(id: string): Promise> { - return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id)); - } - async getAllSdkUrls(): Promise> { - return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint()); - } - async getAllIds(): Promise> { - return await this.request(getSDKEndpoint.getAllIds()); - } -} diff --git a/src/server.ts b/src/server.ts index d837d40..640e2ae 100644 --- a/src/server.ts +++ b/src/server.ts @@ -1,10 +1,9 @@ import "dotenv/config"; import express from "express"; -import { readFileSync } from "fs"; import path from "path"; import payload from "payload"; -import { Collections, RecordersRoles } from "./constants"; import { isDefined, isUndefined } from "./utils/asserts"; +import { Collections, RecordersRoles } from "./shared/payload/constants"; const app = express(); @@ -58,33 +57,6 @@ const start = async () => { // Add your own express routes here app.use("/public", express.static(path.join(__dirname, "../public"))); - app.get("/api/sdk", (_, res) => { - const removeMockingSection = (text: string): string => { - const lines = text.split("\n"); - const endMockingLine = lines.findIndex((line) => line === "// END MOCKING SECTION") ?? 0; - return lines.slice(endMockingLine + 1).join("\n"); - }; - - const removeDeclare = (text: string): string => { - const lines = text.split("\n"); - const startDeclareLine = lines.findIndex((line) => line.startsWith("declare module")) ?? 0; - return lines.slice(0, startDeclareLine).join("\n"); - }; - - const result = []; - - result.push(removeDeclare(readFileSync(path.join(__dirname, "types/collections.ts"), "utf-8"))); - - result.push("/////////////// CONSTANTS ///////////////"); - result.push(removeMockingSection(readFileSync(path.join(__dirname, "constants.ts"), "utf-8"))); - - result.push("////////////////// SDK //////////////////"); - result.push(removeMockingSection(readFileSync(path.join(__dirname, "sdk.ts"), "utf-8"))); - - res.type("text/plain"); - res.send(result.join("\n\n")); - }); - app.get("/robots.txt", (_, res) => { res.type("text/plain"); res.send("User-agent: *\nDisallow: /"); diff --git a/src/utils/asserts.ts b/src/utils/asserts.ts index 7e5c564..869eb59 100644 --- a/src/utils/asserts.ts +++ b/src/utils/asserts.ts @@ -1,5 +1,5 @@ -import { RichTextContent, isNodeParagraphNode } from "../constants"; -import { PayloadImage, PayloadMedia } from "../sdk"; +import { PayloadImage, PayloadMedia } from "../shared/payload/endpoint-types"; +import { RichTextContent, isNodeParagraphNode } from "../shared/payload/rich-text"; import { Audio, File, Image, MediaThumbnail, Scan, Video } from "../types/collections"; export const isDefined = (value: T | null | undefined): value is T => diff --git a/src/utils/endpoints.ts b/src/utils/endpoints.ts index db90e15..e47a364 100644 --- a/src/utils/endpoints.ts +++ b/src/utils/endpoints.ts @@ -2,31 +2,31 @@ import { convertAudioToEndpointAudioPreview } from "../collections/Audios/endpoi import { convertImageToEndpointImagePreview } from "../collections/Images/endpoints/getByID"; import { convertRecorderToEndpointRecorderPreview } from "../collections/Recorders/endpoints/getByID"; import { convertVideoToEndpointVideoPreview } from "../collections/Videos/endpoints/getByID"; +import { AttributeTypes } from "../shared/payload/constants"; import { - AttributeTypes, - RichTextBreakBlock, - RichTextContent, - RichTextSectionBlock, - RichTextUploadNode, - isBlockNodeBreakBlock, - isBlockNodeSectionBlock, - isNodeBlockNode, - isNodeUploadNode, - isUploadNodeAudioNode, - isUploadNodeImageNode, - isUploadNodeVideoNode, -} from "../constants"; -import { - EndpointAttribute, - EndpointCredit, - EndpointPayloadImage, - EndpointRole, - EndpointScanImage, + EndpointTag, EndpointSource, EndpointSourcePreview, - EndpointTag, + EndpointRole, + EndpointCredit, + EndpointAttribute, PayloadImage, -} from "../sdk"; + EndpointScanImage, + EndpointPayloadImage, +} from "../shared/payload/endpoint-types"; +import { + RichTextContent, + isNodeBlockNode, + isBlockNodeSectionBlock, + RichTextSectionBlock, + isBlockNodeBreakBlock, + RichTextBreakBlock, + isNodeUploadNode, + RichTextUploadNode, + isUploadNodeImageNode, + isUploadNodeAudioNode, + isUploadNodeVideoNode, +} from "../shared/payload/rich-text"; import { Audio, Collectible, diff --git a/src/utils/imageCollectionConfig.ts b/src/utils/imageCollectionConfig.ts index d668073..024be71 100644 --- a/src/utils/imageCollectionConfig.ts +++ b/src/utils/imageCollectionConfig.ts @@ -1,8 +1,8 @@ import { ImageSize } from "payload/dist/uploads/types"; import { CollectionConfig } from "payload/types"; import { publicAccess } from "../accesses/publicAccess"; -import { CollectionGroups } from "../constants"; import { BuildCollectionConfig, buildCollectionConfig } from "./collectionConfig"; +import { CollectionGroups } from "../shared/payload/constants"; const fields = { filename: "filename", diff --git a/src/utils/string.ts b/src/utils/string.ts index 07b6ef9..76088c1 100644 --- a/src/utils/string.ts +++ b/src/utils/string.ts @@ -1,6 +1,6 @@ import tags from "language-tags"; -import { RichTextContent } from "../constants"; import { isUndefined } from "./asserts"; +import { RichTextContent } from "../shared/payload/rich-text"; export const shortenEllipsis = (text: string, length: number): string => text.length - 3 > length ? `${text.substring(0, length)}...` : text; diff --git a/src/utils/versionedCollectionConfig.ts b/src/utils/versionedCollectionConfig.ts index 787aca8..6ab35ac 100644 --- a/src/utils/versionedCollectionConfig.ts +++ b/src/utils/versionedCollectionConfig.ts @@ -1,6 +1,6 @@ import { CollectionBeforeChangeHook, CollectionConfig, RelationshipField } from "payload/types"; -import { Collections } from "../constants"; import { BuildCollectionConfig, buildCollectionConfig } from "./collectionConfig"; +import { Collections } from "../shared/payload/constants"; const fields = { updatedBy: "updatedBy" };