/// import { AxiosResponse, Method } from 'axios'; import { Logger } from '@medusajs/medusa/dist/types/global'; import { BaseEntity, EventBusService, Product, ProductCollectionService, ProductService, ProductTypeService, ProductVariantService, RegionService, TransactionBaseService, ProductCategoryService } from '@medusajs/medusa'; import { StrapiMedusaPluginOptions, Tokens, StrapiSendParams, MedusaUserType, AuthInterface, CreateInStrapiParams, GetFromStrapiParams, userCreds as UserCreds, StrapiAdminSendParams } from '../types/globals'; import { EntityManager } from 'typeorm'; import { AxiosError } from 'axios'; export type StrapiEntity = BaseEntity & { medusa_id?: string; }; export type AdminResult = { data: any; status: number; }; export type AdminGetResult = { data: { data: { results: []; }; meta: any; }; status: number; }; export type MedusaGetResult = { data: T; meta?: any; status: number; medusa_id?: string; id?: number; }; export type StrapiResult = { medusa_id?: string; id?: number; data?: any | any[]; meta?: Record; status: number; query?: string; }; export type StrapiGetResult = StrapiResult | { data: any[]; meta?: any; status: number; medusa_id?: string; id?: number | string; }; export interface StrapiQueryInterface { fields: string[]; filters: Record; populate?: any; sort?: string[]; pagination?: { pageSize: number; page: number; }; publicationState?: string; locale?: string[]; } export interface UpdateStrapiServiceParams { manager: EntityManager; regionService: RegionService; productService: ProductService; redisClient: any; productVariantService: ProductVariantService; productTypeService: ProductTypeService; eventBusService: EventBusService; productCollectionService: ProductCollectionService; productCategoryService: ProductCategoryService; logger: Logger; } export interface LoginTokenExpiredErrorParams extends Partial { response?: { status: number; }; message?: string; error?: AxiosError; time?: Date; } export declare class LoginTokenExpiredError extends AxiosError { private readonly error; constructor(error: LoginTokenExpiredErrorParams); } export declare class UpdateStrapiService extends TransactionBaseService { protected manager_: EntityManager; protected transactionManager_: EntityManager; static lastHealthCheckTime: number; productService_: ProductService; productVariantService_: ProductVariantService; productTypeService_: ProductTypeService; regionService_: RegionService; eventBus_: EventBusService; algorithm: string; options_: StrapiMedusaPluginOptions; strapi_protocol: string; strapi_url: string; encryption_key: string; userTokens: Tokens; redis_: any; key: WithImplicitCoercion; defaultAuthInterface: AuthInterface; strapiSuperAdminAuthToken: string; defaultUserEmail: string; defaultUserPassword: string; userAdminProfile: { email: string; }; logger: Logger; static isHealthy: boolean; lastAdminLoginAttemptTime: number; static isServiceAccountRegistered: boolean; productCollectionService: ProductCollectionService; productCategoryService: any; private enableAdminDataLogging; selfTestMode: boolean; strapi_port: number; constructor(container: UpdateStrapiServiceParams, options: StrapiMedusaPluginOptions); withTransaction(transactionManager?: EntityManager): this; startInterface(): Promise; waitForServiceAccountCreation(): Promise; addIgnore_(id: any, side: any): Promise; shouldIgnore_(id: any, side: any): Promise; getVariantEntries_(variants: any, authInterface: AuthInterface): Promise; createImageAssets(product: Product, authInterface: AuthInterface): Promise; getCustomField(field: any, type: any): string; createEntityInStrapi(params: CreateInStrapiParams): Promise; getEntitiesFromStrapi(params: GetFromStrapiParams): Promise; createProductTypeInStrapi(productTypeId: string, authInterface: AuthInterface): Promise; createProductInStrapi(productId: any, authInterface: AuthInterface): Promise; updateCollectionInStrapi(data: any, authInterface: AuthInterface): Promise; strapiPluginLog(logType: string, message: string, data?: Record): void; createCollectionInStrapi(collectionId: string, authInterface: AuthInterface): Promise; updateCategoryInStrapi(data: any, authInterface: AuthInterface): Promise; createCategoryInStrapi(categoryId: string, authInterface: AuthInterface): Promise; createProductVariantInStrapi(variantId: any, authInterface: AuthInterface): Promise; convertOptionValueToMedusaReference(data: any): Record; createRegionInStrapi(regionId: any, authInterface: AuthInterface): Promise; updateRegionInStrapi(data: any, authInterface?: AuthInterface): Promise; /** * Product metafields id is the same as product id * @param data * @param authInterface * @returns */ createProductMetafieldInStrapi(data: { id: string; value: Record; }, authInterface?: AuthInterface): Promise; updateProductMetafieldInStrapi(data: { id: string; value: Record; }, authInterface: AuthInterface): Promise; updateProductsWithinCollectionInStrapi(data: any, authInterface?: AuthInterface): Promise; updateProductsWithinCategoryInStrapi(data: any, authInterface?: AuthInterface): Promise; updateProductInStrapi(data: Partial, authInterface?: AuthInterface): Promise; private adjustProductAndUpdateInStrapi; checkType(type: any, authInterface: any): Promise; updateProductVariantInStrapi(data: any, authInterface: AuthInterface): Promise; deleteProductMetafieldInStrapi(data: { id: string; }, authInterface: AuthInterface): Promise; deleteProductInStrapi(data: any, authInterface: AuthInterface): Promise; deleteProductTypeInStrapi(data: any, authInterface: AuthInterface): Promise; deleteProductVariantInStrapi(data: any, authInterface: AuthInterface): Promise; deleteRegionInStrapi(data: any, authInterface: any): Promise; deleteCollectionInStrapi(data: any, authInterface: any): Promise; deleteCategoryInStrapi(data: any, authInterface: any): Promise; getType(type: string, authInterface: AuthInterface): Promise; private executeStrapiHealthCheck; checkStrapiHealth(): Promise; /** * * @param text the text to encrpyt * @returns encrypted text */ encrypt(text: string): string; /** * @todo implement decryption * @param text * @returns */ decrypt(text: any): string; /** * * @returns the default user - service account for medusa requests */ registerDefaultMedusaUser(): Promise<{ id: string; }>; /** * Deletes the service account * @returns the deleted default user */ deleteDefaultMedusaUser(): Promise; /** * Deletes a medusa user from strapi * @param authInterface - the user authorisation parameters * @returns */ deleteMedusaUserFromStrapi(authInterface: AuthInterface): Promise; /** * @Todo Create API based access async fetchMedusaUserApiKey(emailAddress) { return await this.strapiAdminSend("get") } */ executeSync(token: string): Promise; /** * Readies the server to be used with a service account */ configureStrapiMedusaForUser(authInterface: AuthInterface): Promise; retrieveRefreshedToken(authInterface: AuthInterface, errorCode?: string | number): Promise; strapiLoginSendDatalayer(authInterface?: AuthInterface): Promise; executeLoginAsStrapiUser(authInterface?: AuthInterface): Promise; getRoleId(requestedRole: string): Promise; processStrapiEntry(command: StrapiSendParams): Promise; doesEntryExistInStrapi(type: string, id: string, authInterface: AuthInterface): Promise; createEntryInStrapi(command: StrapiSendParams): Promise; getEntriesInStrapi(command: StrapiSendParams): Promise; updateEntryInStrapi(command: StrapiSendParams): Promise; deleteEntryInStrapi(command: StrapiSendParams): Promise; private isEntity; private translateRelationNamesToStrapiFormat; private translateRelationNamesToMedusaFormat; translateDataToStrapiFormat(dataToSend: StrapiEntity): StrapiEntity; translateDataToMedusaFormat(dataReceived: StrapiGetResult): MedusaGetResult; strapiSendDataLayer(params: StrapiSendParams): Promise; /** * Blocks the process until strapi is healthy * * */ waitForHealth(): Promise; executeStrapiSend({ method, type, token, id, data, query, }: { method: Method; type: string; token: string; id?: string; data?: any; query?: string; }): Promise; appendIdToStrapiFilter(query: string, id?: string): string; _axiosError(error: AxiosError, id?: string, type?: string, data?: any, method?: Method, endPoint?: string): void; refreshResend(error: any, id: string, type: string, data: any, method: string, endPoint: string): Promise; handleError(error: any, id?: string, type?: string, data?: any, method?: Method, endPoint?: string): void; executeStrapiAdminSend(method: Method, type: string, id?: string, action?: string, data?: any, query?: string): Promise; executeRegisterMedusaUser(auth: MedusaUserType): Promise; /** * * send the command using elevated privileges */ strapiAdminSendDatalayer(command: StrapiAdminSendParams): Promise; registerSuperAdminUserInStrapi(): Promise; registerAdminUserInStrapi(email: string, firstname: string, password?: string, role?: string): Promise; updateAdminUserInStrapi(email: string, firstname: string, password?: string, role?: string, isActive?: boolean): Promise; getAdminUserInStrapi(email: string): Promise; getAllAdminUserInStrapi(): Promise; deleteAdminUserInStrapi(email: string, role?: string): Promise; fetchUserToken(email?: string): string; executeLoginAsStrapiSuperAdmin(): Promise<{ data: { user: any; token: string; }; }>; intializeServer(): Promise; registerOrLoginAdmin(): Promise<{ data: { user: any; token: string; }; }>; loginAsDefaultMedusaUser(): Promise; registerOrLoginDefaultMedusaUser(): Promise; verifyDataContainsFields(data: any, updateFields: any[]): boolean; /** * This function allows you to create a strapi query */ createStrapiRestQuery(strapiQuery: StrapiQueryInterface): string; } export default UpdateStrapiService;