n8n-nodes-synca 1.0.21 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SyncaWoltTrigger = void 0;
4
+ class SyncaWoltTrigger {
5
+ constructor() {
6
+ this.description = {
7
+ displayName: 'Synca Wolt Trigger',
8
+ name: 'customSyncaWoltTrigger',
9
+ icon: { light: 'file:icon.svg', dark: 'file:icon.svg' },
10
+ group: ['trigger'],
11
+ version: 1,
12
+ subtitle: '={{$parameter["eventFilter"].length == 0 ? "All events" : $parameter["eventFilter"].map(e => e.replace("order.notification.", "")).join(", ")}}',
13
+ description: 'Starts the workflow when a Synca event occurs',
14
+ defaults: {
15
+ name: 'Synca Wolt Trigger',
16
+ },
17
+ inputs: [],
18
+ outputs: ["main"],
19
+ credentials: [
20
+ {
21
+ name: 'customSyncaApiCredentials',
22
+ required: true,
23
+ },
24
+ ],
25
+ webhooks: [
26
+ {
27
+ name: 'default',
28
+ httpMethod: 'POST',
29
+ responseMode: 'onReceived',
30
+ path: 'webhook',
31
+ },
32
+ ],
33
+ properties: [
34
+ {
35
+ displayName: 'Credentials',
36
+ name: 'credentials',
37
+ type: 'options',
38
+ typeOptions: { loadOptionsMethod: 'getCredentials' },
39
+ default: '',
40
+ required: true,
41
+ description: 'Select the Wolt credentials to listen to',
42
+ },
43
+ {
44
+ displayName: 'Event Filter',
45
+ name: 'eventFilter',
46
+ type: 'multiOptions',
47
+ options: [
48
+ {
49
+ name: 'Order Created',
50
+ description: 'Sent for all new orders which the merchant is receiving on the Wolt marketplace. ',
51
+ value: 'order.notification.CREATED',
52
+ },
53
+ {
54
+ name: 'Order has been accepted or confirmed',
55
+ description: 'Sent once the order has been accepted or confirmed* by the venue staff, either automatically or manually. *pre-orders should be confirmed upon creation, Wolt will move them automatically in "PRODUCTION" status when it\'s time to start the food preparation or order collection.',
56
+ value: 'order.notification.PRODUCTION',
57
+ },
58
+ {
59
+ name: 'Order ready for pick-up',
60
+ description: 'Sent once the merchant has completed the preparation or collection of the order.',
61
+ value: 'order.notification.READY',
62
+ },
63
+ {
64
+ name: 'Order has been canceled',
65
+ description: 'Sent once the order has been “rejected”, either by the merchant, the customer or Wolt Support.',
66
+ value: 'order.notification.CANCELED',
67
+ },
68
+ {
69
+ name: 'Order has been courier arrival',
70
+ description: 'Sent X* min before the courier\'s arrival at the merchant\'s location. *X is configurable per location.',
71
+ value: 'order.notification.COURIER-ARRIVAL',
72
+ },
73
+ {
74
+ name: 'Order has been picked up',
75
+ description: 'Sent once the courier has completed the pick-up at the merchant\'s location.',
76
+ value: 'order.notification.PICK-UP-COMPLETED',
77
+ },
78
+ {
79
+ name: 'Order has been delivered',
80
+ description: 'Sent once the order is delivered to the customer.',
81
+ value: 'order.notification.DELIVERED',
82
+ },
83
+ {
84
+ name: 'Order has been reviewed',
85
+ description: 'Sent once a consumer has provided a review or rating of their order.',
86
+ value: 'order.notification.REVIEW',
87
+ },
88
+ ],
89
+ default: [],
90
+ description: 'The events to listen for. Leave empty for all events.',
91
+ },
92
+ ],
93
+ };
94
+ this.methods = {
95
+ loadOptions: {
96
+ async getCredentials() {
97
+ try {
98
+ const { apiToken, baseUrl } = await this.getCredentials('customSyncaApiCredentials');
99
+ const res = await this.helpers.httpRequest({
100
+ method: 'GET',
101
+ url: `${baseUrl}/v1/invoke/get-credentials`,
102
+ headers: { 'x-api-token': apiToken },
103
+ json: true,
104
+ });
105
+ return Array.isArray(res)
106
+ ? res.map((c) => ({ name: c.name || c.id, value: c.id }))
107
+ : [];
108
+ }
109
+ catch {
110
+ return [{ name: 'Default', value: 'default' }];
111
+ }
112
+ },
113
+ },
114
+ };
115
+ this.webhookMethods = {
116
+ default: {
117
+ async checkExists() {
118
+ return false;
119
+ },
120
+ async create() {
121
+ const credentialId = this.getNodeParameter('credentials');
122
+ const events = this.getNodeParameter('eventFilter');
123
+ const webhookUrl = this.getNodeWebhookUrl('default');
124
+ const { apiToken, baseUrl } = await this.getCredentials('customSyncaApiCredentials');
125
+ const endpoint = `${baseUrl}/v1/n8n/triggers/register`;
126
+ const body = {
127
+ credentialId,
128
+ events: events.length > 0 ? events : ['*'],
129
+ targetUrl: webhookUrl,
130
+ };
131
+ const options = {
132
+ method: 'POST',
133
+ url: endpoint,
134
+ headers: {
135
+ 'x-api-token': apiToken,
136
+ 'Content-Type': 'application/json',
137
+ },
138
+ body,
139
+ json: true,
140
+ };
141
+ try {
142
+ const response = await this.helpers.httpRequest(options);
143
+ if (response && response.id) {
144
+ const webhookData = this.getWorkflowStaticData('node');
145
+ webhookData.webhookId = response.id;
146
+ return true;
147
+ }
148
+ return false;
149
+ }
150
+ catch (error) {
151
+ throw new Error(`Failed to register webhook: ${error.message}`);
152
+ }
153
+ },
154
+ async delete() {
155
+ const webhookData = this.getWorkflowStaticData('node');
156
+ if (!webhookData.webhookId) {
157
+ return true;
158
+ }
159
+ const { apiToken, baseUrl } = await this.getCredentials('customSyncaApiCredentials');
160
+ const endpoint = `${baseUrl}/v1/n8n/triggers/${webhookData.webhookId}`;
161
+ const options = {
162
+ method: 'DELETE',
163
+ url: endpoint,
164
+ headers: {
165
+ 'x-api-token': apiToken,
166
+ },
167
+ json: true,
168
+ };
169
+ try {
170
+ await this.helpers.httpRequest(options);
171
+ delete webhookData.webhookId;
172
+ return true;
173
+ }
174
+ catch (error) {
175
+ return false;
176
+ }
177
+ },
178
+ },
179
+ };
180
+ }
181
+ async webhook() {
182
+ const bodyData = this.getBodyData();
183
+ const headerData = this.getHeaderData();
184
+ const req = this.getRequestObject();
185
+ return {
186
+ workflowData: [
187
+ [
188
+ {
189
+ json: {
190
+ body: bodyData,
191
+ headers: headerData,
192
+ query: req.query,
193
+ },
194
+ },
195
+ ],
196
+ ],
197
+ };
198
+ }
199
+ }
200
+ exports.SyncaWoltTrigger = SyncaWoltTrigger;
201
+ //# sourceMappingURL=SyncaWoltTrigger.node.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SyncaWoltTrigger.node.js","sourceRoot":"","sources":["../../../nodes/Wolt/SyncaWoltTrigger.node.ts"],"names":[],"mappings":";;;AAiBA,MAAa,gBAAgB;IAA7B;QACI,gBAAW,GAAyB;YAChC,WAAW,EAAE,oBAAoB;YACjC,IAAI,EAAE,wBAAwB;YAC9B,IAAI,EAAE,EAAE,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,eAAe,EAAE;YACvD,KAAK,EAAE,CAAC,SAAS,CAAC;YAClB,OAAO,EAAE,CAAC;YACV,QAAQ,EAAE,iJAAiJ;YAC3J,WAAW,EAAE,+CAA+C;YAC5D,QAAQ,EAAE;gBACN,IAAI,EAAE,oBAAoB;aAC7B;YACD,MAAM,EAAE,EAAE;YACV,OAAO,EAAE,QAAyB;YAClC,WAAW,EAAE;gBACT;oBACI,IAAI,EAAE,2BAA2B;oBACjC,QAAQ,EAAE,IAAI;iBACjB;aACJ;YACD,QAAQ,EAAE;gBACN;oBACI,IAAI,EAAE,SAAS;oBACf,UAAU,EAAE,MAAM;oBAClB,YAAY,EAAE,YAAY;oBAC1B,IAAI,EAAE,SAAS;iBAClB;aACJ;YACD,UAAU,EAAE;gBAIR;oBACI,WAAW,EAAE,aAAa;oBAC1B,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,SAAS;oBACf,WAAW,EAAE,EAAE,iBAAiB,EAAE,gBAAgB,EAAE;oBACpD,OAAO,EAAE,EAAE;oBACX,QAAQ,EAAE,IAAI;oBACd,WAAW,EAAE,0CAA0C;iBAC1D;gBACD;oBACI,WAAW,EAAE,cAAc;oBAC3B,IAAI,EAAE,aAAa;oBACnB,IAAI,EAAE,cAAc;oBACpB,OAAO,EAAE;wBACL;4BACI,IAAI,EAAE,eAAe;4BACrB,WAAW,EAAE,mFAAmF;4BAChG,KAAK,EAAE,4BAA4B;yBACtC;wBACD;4BACI,IAAI,EAAE,sCAAsC;4BAC5C,WAAW,E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