{"version":3,"file":"templates.mjs","names":[],"sources":["../src/api/templates.ts"],"sourcesContent":["import type { RawAxiosRequestHeaders } from 'axios';\nimport type { IDataObject, INode, INodeCredentialsDetails } from 'n8n-workflow';\n\nimport type { VersionNode } from './versions';\nimport type { WorkflowData } from './workflows';\nimport type { IRestApiContext } from '../types';\nimport { get, makeRestApiRequest } from '../utils';\n\nexport interface IWorkflowTemplateNode\n\textends Pick<\n\t\tINode,\n\t\t'name' | 'type' | 'position' | 'parameters' | 'typeVersion' | 'webhookId' | 'id' | 'disabled'\n\t> {\n\t// The credentials in a template workflow have a different type than in a regular workflow\n\tcredentials?: IWorkflowTemplateNodeCredentials;\n}\n\nexport interface IWorkflowTemplateNodeCredentials {\n\t[key: string]: string | INodeCredentialsDetails;\n}\n\nexport interface IWorkflowTemplate {\n\tid: number;\n\tname: string;\n\tworkflow: Pick<WorkflowData, 'connections' | 'settings' | 'pinData'> & {\n\t\tnodes: IWorkflowTemplateNode[];\n\t};\n}\n\nexport interface ITemplatesNode extends VersionNode {\n\tid: number;\n\tcategories?: ITemplatesCategory[];\n}\n\nexport interface ITemplatesCollection {\n\tid: number;\n\tname: string;\n\tnodes: ITemplatesNode[];\n\tworkflows: Array<{ id: number }>;\n}\n\ninterface ITemplatesImage {\n\tid: number;\n\turl: string;\n}\n\ninterface ITemplatesCollectionExtended extends ITemplatesCollection {\n\tdescription: string | null;\n\timage: ITemplatesImage[];\n\tcategories: ITemplatesCategory[];\n\tcreatedAt: string;\n}\n\nexport interface ITemplatesCollectionFull extends ITemplatesCollectionExtended {\n\tfull: true;\n}\n\nexport interface ITemplatesCollectionResponse extends ITemplatesCollectionExtended {\n\tworkflows: ITemplatesWorkflow[];\n}\n\n/**\n * A template without the actual workflow definition\n */\n\nexport interface ITemplatesWorkflow {\n\tid: number;\n\tcreatedAt: string;\n\tname: string;\n\tnodes: ITemplatesNode[];\n\ttotalViews: number;\n\tuser: {\n\t\tusername: string;\n\t\tname: string;\n\t\tavatar: string;\n\t\tverified: boolean;\n\t};\n\treadyToDemo?: boolean | null;\n}\n\nexport interface ITemplatesWorkflowInfo {\n\tnodeCount: number;\n\tnodeTypes: {\n\t\t[key: string]: {\n\t\t\tcount: number;\n\t\t};\n\t};\n}\n\nexport type TemplateSearchFacet = {\n\tfield_name: string;\n\tsampled: boolean;\n\tstats: {\n\t\ttotal_values: number;\n\t};\n\tcounts: Array<{\n\t\tcount: number;\n\t\thighlighted: string;\n\t\tvalue: string;\n\t}>;\n};\n\nexport interface ITemplatesWorkflowResponse extends ITemplatesWorkflow, IWorkflowTemplate {\n\tdescription: string | null;\n\timage: ITemplatesImage[];\n\tcategories: ITemplatesCategory[];\n\tworkflowInfo: ITemplatesWorkflowInfo;\n}\n\n/**\n * A template with also the full workflow definition\n */\n\nexport interface ITemplatesWorkflowFull extends ITemplatesWorkflowResponse {\n\tfull: true;\n}\n\nexport interface ITemplatesQuery {\n\tcategories: string[];\n\tsearch: string;\n\tapps?: string[];\n\tnodes?: string[];\n\tsort?: string;\n\tcombineWith?: string;\n}\n\nexport interface ITemplatesCategory {\n\tid: number;\n\tname: string;\n}\n\nfunction stringifyArray(arr: string[]) {\n\treturn arr.join(',');\n}\n\nexport async function testHealthEndpoint(apiEndpoint: string) {\n\treturn await get(apiEndpoint, '/health');\n}\n\nexport async function getCategories(\n\tapiEndpoint: string,\n\theaders?: RawAxiosRequestHeaders,\n): Promise<{ categories: ITemplatesCategory[] }> {\n\treturn await get(apiEndpoint, '/templates/categories', undefined, headers);\n}\n\nexport async function getCollections(\n\tapiEndpoint: string,\n\tquery: ITemplatesQuery,\n\theaders?: RawAxiosRequestHeaders,\n): Promise<{ collections: ITemplatesCollection[] }> {\n\treturn await get(\n\t\tapiEndpoint,\n\t\t'/templates/collections',\n\t\t{ category: query.categories, search: query.search },\n\t\theaders,\n\t);\n}\n\nexport async function getWorkflows(\n\tapiEndpoint: string,\n\tquery: {\n\t\tpage: number;\n\t\tlimit: number;\n\t\tcategories: string[];\n\t\tsearch: string;\n\t\tsort?: string;\n\t\tapps?: string[];\n\t\tnodes?: string[];\n\t\tcombineWith?: string;\n\t},\n\theaders?: RawAxiosRequestHeaders,\n): Promise<{\n\ttotalWorkflows: number;\n\tworkflows: ITemplatesWorkflow[];\n\tfilters: TemplateSearchFacet[];\n}> {\n\tconst { apps, sort, combineWith, categories, nodes, ...restQuery } = query;\n\tconst finalQuery = {\n\t\t...restQuery,\n\t\tcategory: stringifyArray(categories),\n\t\t...(apps && { apps: stringifyArray(apps) }),\n\t\t...(nodes && { nodes: stringifyArray(nodes) }),\n\t\t...(sort && { sort }),\n\t\t...(combineWith && { combineWith }),\n\t};\n\n\treturn await get(apiEndpoint, '/templates/search', finalQuery, headers);\n}\n\nexport async function getCollectionById(\n\tapiEndpoint: string,\n\tcollectionId: string,\n\theaders?: RawAxiosRequestHeaders,\n): Promise<{ collection: ITemplatesCollectionResponse }> {\n\treturn await get(apiEndpoint, `/templates/collections/${collectionId}`, undefined, headers);\n}\n\nexport async function getTemplateById(\n\tapiEndpoint: string,\n\ttemplateId: string,\n\theaders?: RawAxiosRequestHeaders,\n): Promise<{ workflow: ITemplatesWorkflowResponse }> {\n\treturn await get(apiEndpoint, `/templates/workflows/${templateId}`, undefined, headers);\n}\n\nexport async function getWorkflowTemplate(\n\tapiEndpoint: string,\n\ttemplateId: string,\n\theaders?: RawAxiosRequestHeaders,\n): Promise<IWorkflowTemplate> {\n\treturn await get(apiEndpoint, `/workflows/templates/${templateId}`, undefined, headers);\n}\n\nexport interface IInstanceAiExamplesQuery {\n\tcategory?: string;\n\tsubcategory?: string;\n\tpage?: number;\n\tlimit?: number;\n}\n\nexport interface IInstanceAiExampleWorkflow {\n\tid: number;\n\tname: string;\n\tcategory: string;\n\tsubcategory?: string;\n\trelevanceScore?: number;\n\tprompt?: string;\n\tnodes: Array<{\n\t\tname: string;\n\t\tdisplayName?: string;\n\t\ticon?: string;\n\t\ticonData?: { type: string; fileBuffer: string };\n\t}>;\n}\n\nexport interface IInstanceAiExamplesResponse {\n\tcategories: string[];\n\tsubcategories: Record<string, string[]>;\n\ttotalWorkflows: number;\n\tworkflows: IInstanceAiExampleWorkflow[];\n}\n\nexport async function getInstanceAiExamples(\n\tcontext: IRestApiContext,\n\tquery: IInstanceAiExamplesQuery,\n): Promise<IInstanceAiExamplesResponse> {\n\treturn await makeRestApiRequest(context, 'GET', '/instance-ai-examples', query as IDataObject);\n}\n"],"mappings":";;;AAmIA,SAAS,eAAe,KAAe;AACtC,QAAO,IAAI,KAAK,IAAI;;AAGrB,eAAsB,mBAAmB,aAAqB;AAC7D,QAAO,MAAM,IAAI,aAAa,UAAU;;AAGzC,eAAsB,cACrB,aACA,SACgD;AAChD,QAAO,MAAM,IAAI,aAAa,yBAAyB,QAAW,QAAQ;;AAG3E,eAAsB,eACrB,aACA,OACA,SACmD;AACnD,QAAO,MAAM,IACZ,aACA,0BACA;EAAE,UAAU,MAAM;EAAY,QAAQ,MAAM;EAAQ,EACpD,QACA;;AAGF,eAAsB,aACrB,aACA,OAUA,SAKE;CACF,MAAM,EAAE,MAAM,MAAM,aAAa,YAAY,OAAO,GAAG,cAAc;AAUrE,QAAO,MAAM,IAAI,aAAa,qBATX;EAClB,GAAG;EACH,UAAU,eAAe,WAAW;EACpC,GAAI,QAAQ,EAAE,MAAM,eAAe,KAAK,EAAE;EAC1C,GAAI,SAAS,EAAE,OAAO,eAAe,MAAM,EAAE;EAC7C,GAAI,QAAQ,EAAE,MAAM;EACpB,GAAI,eAAe,EAAE,aAAa;EAClC,EAE8D,QAAQ;;AAGxE,eAAsB,kBACrB,aACA,cACA,SACwD;AACxD,QAAO,MAAM,IAAI,aAAa,0BAA0B,gBAAgB,QAAW,QAAQ;;AAG5F,eAAsB,gBACrB,aACA,YACA,SACoD;AACpD,QAAO,MAAM,IAAI,aAAa,wBAAwB,cAAc,QAAW,QAAQ;;AAGxF,eAAsB,oBACrB,aACA,YACA,SAC6B;AAC7B,QAAO,MAAM,IAAI,aAAa,wBAAwB,cAAc,QAAW,QAAQ;;AAgCxF,eAAsB,sBACrB,SACA,OACuC;AACvC,QAAO,MAAM,mBAAmB,SAAS,OAAO,yBAAyB,MAAqB"}