UNPKG

@blotato/n8n-nodes-blotato

Version:
95 lines 3.14 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAccounts = getAccounts; exports.getSubaccounts = getSubaccounts; exports.getTemplates = getTemplates; async function getAccounts() { const platform = this.getNodeParameter('platform', 0); const credentials = await this.getCredentials('blotatoApi'); const options = { method: 'GET', url: `${credentials.server}/v2/users/me/accounts`, qs: { platform }, }; let responseData; try { responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'blotatoApi', options); } catch (error) { return { results: [] }; } const results = responseData.items.map((item) => ({ name: item.fullname || item.username, value: item.id, url: `${credentials.server}/v2/accounts/${item.id}`, })); return { results }; } async function getSubaccounts() { const platform = this.getNodeParameter('platform', 0); try { const accountIdParam = this.getNodeParameter('accountId', 0); const accountId = typeof accountIdParam === 'object' ? accountIdParam.value : accountIdParam; if (!accountId) { return { results: [ { name: 'Please select an account above first', value: '', }, ], }; } const credentials = await this.getCredentials('blotatoApi'); const options = { method: 'GET', url: `${credentials.server}/v2/users/me/accounts/${accountId}/subaccounts`, qs: { platform }, }; let responseData; try { responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'blotatoApi', options); } catch (error) { return { results: [] }; } const results = responseData.items.map((item) => ({ name: item.name, value: item.id, url: `${credentials.server}/v2/accounts/${item.accountId}/subaccounts/${item.id}`, })); return { results }; } catch (error) { return { results: [ { name: 'Please select an account above first', value: '', }, ], }; } } async function getTemplates() { const credentials = await this.getCredentials('blotatoApi'); const options = { method: 'GET', url: `${credentials.server}/v2/videos/templates`, }; let responseData; try { responseData = await this.helpers.httpRequestWithAuthentication.call(this, 'blotatoApi', options); } catch (error) { return { results: [] }; } const templates = responseData.items || responseData; const results = templates.map((item) => ({ name: `${item.description}`, value: item.id, description: item.type ? `Type: ${item.type}` : undefined, })); return { results }; } //# sourceMappingURL=SearchFunctions.js.map