2023-01-27 03:22:44 -08:00
|
|
|
import type {
|
2023-03-09 09:13:15 -08:00
|
|
|
IPollFunctions,
|
2020-10-01 05:01:39 -07:00
|
|
|
IDataObject,
|
2019-12-31 12:19:37 -08:00
|
|
|
INodeExecutionData,
|
2019-12-21 18:44:56 -08:00
|
|
|
INodeType,
|
|
|
|
INodeTypeDescription,
|
2023-02-27 19:39:43 -08:00
|
|
|
JsonObject,
|
2019-12-21 18:44:56 -08:00
|
|
|
} from 'n8n-workflow';
|
2023-01-27 03:22:44 -08:00
|
|
|
import { NodeApiError, NodeOperationError } from 'n8n-workflow';
|
2019-12-21 18:44:56 -08:00
|
|
|
|
2024-01-15 06:45:33 -08:00
|
|
|
import moment from 'moment-timezone';
|
2019-12-21 18:44:56 -08:00
|
|
|
import { togglApiRequest } from './GenericFunctions';
|
|
|
|
|
|
|
|
export class TogglTrigger implements INodeType {
|
|
|
|
description: INodeTypeDescription = {
|
2020-01-05 07:52:00 -08:00
|
|
|
displayName: 'Toggl Trigger',
|
2020-05-12 06:08:19 -07:00
|
|
|
name: 'togglTrigger',
|
2022-06-20 07:54:01 -07:00
|
|
|
// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg
|
2019-12-21 18:44:56 -08:00
|
|
|
icon: 'file:toggl.png',
|
|
|
|
group: ['trigger'],
|
|
|
|
version: 1,
|
2021-05-15 09:02:07 -07:00
|
|
|
description: 'Starts the workflow when Toggl events occur',
|
2019-12-21 18:44:56 -08:00
|
|
|
defaults: {
|
feat(editor): Node creator actions (#4696)
* WIP: Node Actions List UI
* WIP: Recommended Actions and preseting of fields
* WIP: Resource category
* :art: Moved actions categorisation to the server
* :label: Add missing INodeAction type
* :sparkles: Improve SSR categorisation, fix adding of mixed actions
* :recycle: Refactor CategorizedItems to composition api, style fixes
* WIP: Adding multiple nodes
* :recycle: Refactor rest of the NodeCreator component to composition API, conver globalLinkActions to composable
* :sparkles: Allow actions dragging, fix search and refactor passing of actions to categorized items
* :lipstick: Fix node actions title
* Migrate to the pinia store, add posthog feature and various fixes
* :bug: Fix filtering of trigger actions when not merged
* fix: N8N-5439 — Do not use simple node item when at NodeHelperPanel root
* :bug: Design review fixes
* :bug: Fix disabling of merged actions
* Fix trigger root filtering
* :sparkles: Allow for custom node actions parser, introduce hubspot parser
* :bug: Fix initial node params validation, fix position of second added node
* :bug: Introduce operations category, removed canvas node names overrride, fix API actions display and prevent dragging of action nodes
* :sparkles: Prevent NDV auto-open feature flag
* :bug: Inject recommened action for trigger nodes without actions
* Refactored NodeCreatorNode to Storybook, change filtering of merged nodes for the trigger helper panel, minor fixes
* Improve rendering of app nodes and animation
* Cleanup, any only enable accordion transition on triggerhelperpanel
* Hide node creator scrollbars in Firefox
* Minor styles fixes
* Do not copy the array in rendering method
* Removed unused props
* Fix memory leak
* Fix categorisation of regular nodes with a single resource
* Implement telemetry calls for node actions
* Move categorization to FE
* Fix client side actions categorisation
* Skip custom action show
* Only load tooltip for NodeIcon if necessary
* Fix lodash startCase import
* Remove lodash.startcase
* Cleanup
* Fix node creator autofocus on "tab"
* Prevent posthog getFeatureFlag from crashing
* Debugging preview env search issues
* Remove logs
* Make sure the pre-filled params are update not overwritten
* Get rid of transition in itemiterator
* WIP: Rough version of NodeActions keyboard navigation, replace nodeCreator composable with Pinia store module
* Rewrite to add support for ActionItem to ItemIterator and make CategorizedItems accept items props
* Fix category item counter & cleanup
* Add APIHint to actions search no-result, clean up NodeCreatorNode
* Improve node actions no results message
* Remove logging, fix filtering of recommended placeholder category
* Remove unused NodeActions component and node merging feature falg
* Do not show regular nodes without actions
* Make sure to add manual trigger when adding http node via actions hint
* Fixed api hint footer line height
* Prevent pointer-events od NodeIcon img and remove "this" from template
* Address PR points
* Fix e2e specs
* Make sure canvas ia loaded
* Make sure canvas ia loaded before opening nodeCreator in e2e spec
* Fix flaky workflows tags e2e getter
* Imrpove node creator click outside UX, add manual node to regular nodes added from trigger panel
* Add manual trigger node if dragging regular from trigger panel
2022-12-09 01:56:36 -08:00
|
|
|
name: 'Toggl Trigger',
|
2019-12-21 18:44:56 -08:00
|
|
|
},
|
|
|
|
credentials: [
|
|
|
|
{
|
|
|
|
name: 'togglApi',
|
|
|
|
required: true,
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2019-12-21 18:44:56 -08:00
|
|
|
],
|
2019-12-31 12:19:37 -08:00
|
|
|
polling: true,
|
2019-12-21 18:44:56 -08:00
|
|
|
inputs: [],
|
|
|
|
outputs: ['main'],
|
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
displayName: 'Event',
|
|
|
|
name: 'event',
|
|
|
|
type: 'options',
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
name: 'New Time Entry',
|
|
|
|
value: 'newTimeEntry',
|
2020-10-22 06:46:03 -07:00
|
|
|
},
|
2019-12-21 18:44:56 -08:00
|
|
|
],
|
|
|
|
required: true,
|
|
|
|
default: 'newTimeEntry',
|
|
|
|
},
|
2020-10-22 06:46:03 -07:00
|
|
|
],
|
2019-12-21 18:44:56 -08:00
|
|
|
};
|
|
|
|
|
2019-12-31 12:19:37 -08:00
|
|
|
async poll(this: IPollFunctions): Promise<INodeExecutionData[][] | null> {
|
2019-12-21 18:44:56 -08:00
|
|
|
const webhookData = this.getWorkflowStaticData('node');
|
|
|
|
const event = this.getNodeParameter('event') as string;
|
|
|
|
let endpoint: string;
|
2019-12-31 12:19:37 -08:00
|
|
|
|
2019-12-21 18:44:56 -08:00
|
|
|
if (event === 'newTimeEntry') {
|
|
|
|
endpoint = '/time_entries';
|
2019-12-31 12:19:37 -08:00
|
|
|
} else {
|
2021-04-16 09:33:36 -07:00
|
|
|
throw new NodeOperationError(this.getNode(), `The defined event "${event}" is not supported`);
|
2019-12-21 18:44:56 -08:00
|
|
|
}
|
|
|
|
|
2019-12-31 12:19:37 -08:00
|
|
|
const qs: IDataObject = {};
|
|
|
|
let timeEntries = [];
|
|
|
|
qs.start_date = webhookData.lastTimeChecked;
|
|
|
|
qs.end_date = moment().format();
|
2019-12-21 18:44:56 -08:00
|
|
|
|
2019-12-31 12:19:37 -08:00
|
|
|
try {
|
|
|
|
timeEntries = await togglApiRequest.call(this, 'GET', endpoint, {}, qs);
|
|
|
|
webhookData.lastTimeChecked = qs.end_date;
|
2021-04-16 09:33:36 -07:00
|
|
|
} catch (error) {
|
2023-02-27 19:39:43 -08:00
|
|
|
throw new NodeApiError(this.getNode(), error as JsonObject);
|
2019-12-21 18:44:56 -08:00
|
|
|
}
|
2019-12-31 12:19:37 -08:00
|
|
|
if (Array.isArray(timeEntries) && timeEntries.length !== 0) {
|
|
|
|
return [this.helpers.returnJsonArray(timeEntries)];
|
2019-12-21 18:44:56 -08:00
|
|
|
}
|
2019-12-31 12:19:37 -08:00
|
|
|
|
|
|
|
return null;
|
2019-12-21 18:44:56 -08:00
|
|
|
}
|
|
|
|
}
|