
* initial setup * GRaphql setup * [skip ci] * Manifest and register endpoints * Add config schemas * contentful client * contentful client * [skip ci] trpc setup * metadata manager and contentful router * Configuration config * contentful config - adding providers * add provider page * wip contentful form * contentful form * list providrs * edit contentful form * [skip ci] * [skip ci] replace contentful sdk * replace contentful lib * Delete contetnful provider feature * variant created webhook draft * channel provider connection model * Channel connections ui * adding new connection * connections ui (adding) * [skip ci] wip edit conn * removing connection * rebuild modal * refactor providers * implement update product webhook * add deleting product * [skip ci] wip * refactor contentful router * refactor wip * refactor config * webhooks processor * webhook delegations * bulk sync section * bulk sync page * gql for imports * [skip ci] bulk import contentful * temp variant sync list with rate limiters * wip * wip * wip * new frontend for uploading * update zod * print config keys * wip * [skip ci] datocms init * dato add provdier page * dato form skeleton * dato display content type select * full dato form * ButtonsBox extraction * edit dato config form * update product in dato * [skip ci] * extract bulk sync processor * dato bulk update * [skip ci] product updated webhook * product webhook * crud operations router * update cruds * refactor webhook operations * refactors * refactors * helper texts * [skip ci] deps * Init * fix macaw icon * unify app skd * unify nextjs * strapi setup * fix strapi types * strapi upload product * strapi delete product * strapi product updated webhook * processor for bulk sync strapi * shared add provider page * refactors * refactors * wrap providers into folder * refactors * refactors * refactors * pnpm lock * add logs * name configuration mapping name * form configurable side notes * remove commentns * wip providers resolver working * central config for providers resolving * tests wip * remove vscode condig * cleanup * provider meta extract * some tests for contentufl * contentful client test * more tests for contentful * strapi helper texts * builderio setup * builderio form * builderio client draft * validate connection modal * Add sending product to builderio * rename builder field * add public api key for read access * update products * Builder.io - bulk sync * Fix manifest * cr fixes * Make strapi to work with multiple products * Github actions
187 lines
5.8 KiB
TypeScript
187 lines
5.8 KiB
TypeScript
import { BulkSyncProcessor } from "../bulk-sync/bulk-sync-processor";
|
|
import {
|
|
BuilderIoProviderConfig,
|
|
ContentfulProviderConfig,
|
|
ProvidersConfig,
|
|
StrapiProviderConfig,
|
|
} from "../configuration";
|
|
import { ContentfulBulkSyncProcessor } from "./contentful/contentful-bulk-sync-processor";
|
|
import { DatocmsBulkSyncProcessor } from "./datocms/datocms-bulk-sync-processor";
|
|
import { StrapiBulkSyncProcessor } from "./strapi/strapi-bulk-sync-processor";
|
|
|
|
import dynamic from "next/dynamic";
|
|
import { ComponentType, ReactElement } from "react";
|
|
import { Contentful } from "./contentful/contentful";
|
|
import { ContentfulWebhooksProcessor } from "./contentful/contentful-webhooks-processor";
|
|
import { Datocms } from "./datocms/datocms";
|
|
import { DatocmsWebhooksProcessor } from "./datocms/datocms-webhooks-processor";
|
|
import { CMS, CMSType } from "./providers-registry";
|
|
import { Strapi } from "./strapi/strapi";
|
|
import { StrapiWebhooksProcessor } from "./strapi/strapi-webhooks-processor";
|
|
import { DatocmsProviderConfig } from "../configuration/schemas/datocms-provider.schema";
|
|
import { BuilderIo } from "./builder.io/builder-io";
|
|
import { BuilderIoWebhooksProcessor } from "./builder.io/builder-io-webhooks-processor";
|
|
import { BuilderIoBulkSyncProcessor } from "./builder.io/builder-io-bulk-sync-processor";
|
|
|
|
/**
|
|
* Almost-single source of new providers. Every time app will need to resolve a provider, it will use on of these factories.
|
|
* Frontend/UI must be dynamic, to render async chunk. Otherwise there is a circular dependency.
|
|
*/
|
|
export const ProvidersResolver = {
|
|
createBulkSyncProcessor(config: ProvidersConfig.AnyFullShape): BulkSyncProcessor {
|
|
switch (config.type) {
|
|
case "contentful":
|
|
return new ContentfulBulkSyncProcessor(config);
|
|
case "datocms":
|
|
return new DatocmsBulkSyncProcessor(config);
|
|
case "strapi":
|
|
return new StrapiBulkSyncProcessor(config);
|
|
case "builder.io": {
|
|
return new BuilderIoBulkSyncProcessor(config);
|
|
}
|
|
|
|
default:
|
|
throw new Error(`Unknown provider`);
|
|
}
|
|
},
|
|
getProviderInputSchema(type: CMSType) {
|
|
switch (type) {
|
|
case "contentful":
|
|
return ContentfulProviderConfig.Schema.Input;
|
|
case "datocms":
|
|
return DatocmsProviderConfig.Schema.Input;
|
|
case "strapi":
|
|
return StrapiProviderConfig.Schema.Input;
|
|
case "builder.io":
|
|
return BuilderIoProviderConfig.Schema.Input;
|
|
default: {
|
|
throw new Error("Failed to build input schema");
|
|
}
|
|
}
|
|
},
|
|
getProviderSchema(type: CMSType) {
|
|
switch (type) {
|
|
case "contentful":
|
|
return ContentfulProviderConfig.Schema.Full;
|
|
case "datocms":
|
|
return DatocmsProviderConfig.Schema.Full;
|
|
case "strapi":
|
|
return StrapiProviderConfig.Schema.Full;
|
|
case "builder.io":
|
|
return BuilderIoProviderConfig.Schema.Full;
|
|
default: {
|
|
throw new Error("Failed to build provdier schema");
|
|
}
|
|
}
|
|
},
|
|
createProviderMeta(type: CMSType | string): CMS {
|
|
switch (type) {
|
|
case "contentful": {
|
|
return Contentful;
|
|
}
|
|
case "datocms": {
|
|
return Datocms;
|
|
}
|
|
case "strapi": {
|
|
return Strapi;
|
|
}
|
|
case "builder.io": {
|
|
return BuilderIo;
|
|
}
|
|
default: {
|
|
throw new Error("Unknown provider");
|
|
}
|
|
}
|
|
},
|
|
createWebhooksProcessor(config: ProvidersConfig.AnyFullShape) {
|
|
switch (config.type) {
|
|
case "contentful": {
|
|
return new ContentfulWebhooksProcessor(config);
|
|
}
|
|
case "datocms": {
|
|
return new DatocmsWebhooksProcessor(config);
|
|
}
|
|
case "strapi": {
|
|
return new StrapiWebhooksProcessor(config);
|
|
}
|
|
case "builder.io": {
|
|
return new BuilderIoWebhooksProcessor(config);
|
|
}
|
|
default: {
|
|
throw new Error("Failed to build webhook processor.");
|
|
}
|
|
}
|
|
},
|
|
getEditProviderFormComponent: (
|
|
type: CMSType
|
|
): ComponentType<{
|
|
configId: string;
|
|
}> => {
|
|
switch (type) {
|
|
case "contentful": {
|
|
return dynamic(() =>
|
|
import("./contentful/contentful-config-form").then(
|
|
(module) => module.ContentfulConfigForm.EditVariant
|
|
)
|
|
);
|
|
}
|
|
case "datocms": {
|
|
return dynamic(() =>
|
|
import("./datocms/datocms-config-form").then(
|
|
(module) => module.DatoCMSConfigForm.EditVariant
|
|
)
|
|
);
|
|
}
|
|
case "strapi": {
|
|
return dynamic(() =>
|
|
import("./strapi/strapi-config-form").then(
|
|
(module) => module.StrapiConfigForm.EditVariant
|
|
)
|
|
);
|
|
}
|
|
case "builder.io": {
|
|
return dynamic(() =>
|
|
import("./builder.io/builder-io-config-form").then(
|
|
(module) => module.BuilderIoConfigForm.EditVariant
|
|
)
|
|
);
|
|
}
|
|
default: {
|
|
throw new Error("Provider form not registered");
|
|
}
|
|
}
|
|
},
|
|
getAddNewProviderFormComponent: (type: CMSType): ComponentType<{}> => {
|
|
switch (type) {
|
|
case "contentful": {
|
|
return dynamic(() =>
|
|
import("./contentful/contentful-config-form").then(
|
|
(module) => module.ContentfulConfigForm.AddVariant
|
|
)
|
|
);
|
|
}
|
|
case "datocms": {
|
|
return dynamic(() =>
|
|
import("./datocms/datocms-config-form").then(
|
|
(module) => module.DatoCMSConfigForm.AddVariant
|
|
)
|
|
);
|
|
}
|
|
case "strapi": {
|
|
return dynamic(() =>
|
|
import("./strapi/strapi-config-form").then((module) => module.StrapiConfigForm.AddVariant)
|
|
);
|
|
}
|
|
case "builder.io": {
|
|
return dynamic(() =>
|
|
import("./builder.io/builder-io-config-form").then(
|
|
(module) => module.BuilderIoConfigForm.AddVariant
|
|
)
|
|
);
|
|
}
|
|
default: {
|
|
throw new Error("Provider form not registered");
|
|
}
|
|
}
|
|
},
|
|
};
|