Using shared library

This commit is contained in:
DrMint 2024-07-13 19:03:21 +02:00
parent d52febb766
commit faeb61e1f4
73 changed files with 158 additions and 1193 deletions

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "src/shared"]
path = src/shared
url = https://github.com/Accords-Library/shared-library.git

2
.prettierignore Normal file
View File

@ -0,0 +1,2 @@
src/shared/*
dist

12
.vscode/settings.json vendored
View File

@ -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"
}
}

View File

@ -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"
},

View File

@ -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<unknown, Recorder> = ({ req: { user } }): boolean => {
if (isUndefined(user)) return false;

View File

@ -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<unknown, Recorder> = ({ req: { user } }) => {
if (isUndefined(user)) return false;

View File

@ -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;

View File

@ -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<any, any, Recorder> = ({ req: { user } }): boolean => {
if (isUndefined(user)) return false;

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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";

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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";

View File

@ -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",

View File

@ -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,

View File

@ -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,

View File

@ -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",

View File

@ -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",

View File

@ -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 {

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -1,5 +1,5 @@
import { Collections } from "../../../constants";
import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint";
import { Collections } from "../../../shared/payload/constants";
type StrapiLanguage = {
code: string;

View File

@ -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";

View File

@ -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",

View File

@ -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";

View File

@ -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,

View File

@ -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",

View File

@ -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,

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -1,5 +1,5 @@
import { Collections } from "../../../constants";
import { createStrapiImportEndpoint } from "../../../endpoints/createStrapiImportEndpoint";
import { Collections } from "../../../shared/payload/constants";
type StrapiLanguage = {
name: string;

View File

@ -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,

View File

@ -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",

View File

@ -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 {

View File

@ -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";

View File

@ -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",

View File

@ -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;

View File

@ -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 = {

View File

@ -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",

View File

@ -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";

View File

@ -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",

View File

@ -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",

View File

@ -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({

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -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;

View File

@ -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";

View File

@ -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",

View File

@ -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",

View File

@ -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<ArrayField, "type" | "fields">;

View File

@ -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",

View File

@ -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,

View File

@ -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,

View File

@ -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: {

View File

@ -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<EndpointFolderPreview, "translations"> & {
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<EndpointPagePreview, "translations"> & {
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<EndpointCollectiblePreview, "translations"> & {
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<EndpointMediaPreview, "translations"> & {
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<T> = {
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<T>(endpoint: string): Promise<PayloadSDKResponse<T>> {
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<PayloadSDKResponse<EndpointWebsiteConfig>> {
return await this.request(getSDKEndpoint.getConfigEndpoint());
}
async getFolder(slug: string): Promise<PayloadSDKResponse<EndpointFolder>> {
return await this.request(getSDKEndpoint.getFolderEndpoint(slug));
}
async getLanguages(): Promise<PayloadSDKResponse<Language[]>> {
return await this.request(getSDKEndpoint.getLanguagesEndpoint());
}
async getCurrencies(): Promise<PayloadSDKResponse<Currency[]>> {
return await this.request(getSDKEndpoint.getCurrenciesEndpoint());
}
async getWordings(): Promise<PayloadSDKResponse<EndpointWording[]>> {
return await this.request(getSDKEndpoint.getWordingsEndpoint());
}
async getPage(slug: string): Promise<PayloadSDKResponse<EndpointPage>> {
return await this.request(getSDKEndpoint.getPageEndpoint(slug));
}
async getCollectible(slug: string): Promise<PayloadSDKResponse<EndpointCollectible>> {
return await this.request(getSDKEndpoint.getCollectibleEndpoint(slug));
}
async getCollectibleScans(slug: string): Promise<PayloadSDKResponse<EndpointCollectibleScans>> {
return await this.request(getSDKEndpoint.getCollectibleScansEndpoint(slug));
}
async getCollectibleScanPage(
slug: string,
index: string
): Promise<PayloadSDKResponse<EndpointCollectibleScanPage>> {
return await this.request(getSDKEndpoint.getCollectibleScanPageEndpoint(slug, index));
}
async getCollectibleGallery(
slug: string
): Promise<PayloadSDKResponse<EndpointCollectibleGallery>> {
return await this.request(getSDKEndpoint.getCollectibleGalleryEndpoint(slug));
}
async getCollectibleGalleryImage(
slug: string,
index: string
): Promise<PayloadSDKResponse<EndpointCollectibleGalleryImage>> {
return await this.request(getSDKEndpoint.getCollectibleGalleryImageEndpoint(slug, index));
}
async getChronologyEvents(): Promise<PayloadSDKResponse<EndpointChronologyEvent[]>> {
return await this.request(getSDKEndpoint.getChronologyEventsEndpoint());
}
async getChronologyEventByID(id: string): Promise<PayloadSDKResponse<EndpointChronologyEvent>> {
return await this.request(getSDKEndpoint.getChronologyEventByIDEndpoint(id));
}
async getImageByID(id: string): Promise<PayloadSDKResponse<EndpointImage>> {
return await this.request(getSDKEndpoint.getImageByIDEndpoint(id));
}
async getAudioByID(id: string): Promise<PayloadSDKResponse<EndpointAudio>> {
return await this.request(getSDKEndpoint.getAudioByIDEndpoint(id));
}
async getVideoByID(id: string): Promise<PayloadSDKResponse<EndpointVideo>> {
return await this.request(getSDKEndpoint.getVideoByIDEndpoint(id));
}
async getFileByID(id: string): Promise<PayloadSDKResponse<EndpointFile>> {
return await this.request(getSDKEndpoint.getFileByIDEndpoint(id));
}
async getRecorderByID(id: string): Promise<PayloadSDKResponse<EndpointRecorder>> {
return await this.request(getSDKEndpoint.getRecorderByIDEndpoint(id));
}
async getAllSdkUrls(): Promise<PayloadSDKResponse<EndpointAllSDKUrls>> {
return await this.request(getSDKEndpoint.getAllSDKUrlsEndpoint());
}
async getAllIds(): Promise<PayloadSDKResponse<EndpointAllIds>> {
return await this.request(getSDKEndpoint.getAllIds());
}
}

View File

@ -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: /");

View File

@ -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 = <T>(value: T | null | undefined): value is T =>

View File

@ -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,

View File

@ -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",

View File

@ -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;

View File

@ -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" };