@posty5/n8n-nodes-posty5 4.2.0 → 5.0.0

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.
Files changed (170) hide show
  1. package/README.md +351 -15
  2. package/dist/credentials/Posty5Api.credentials.d.ts +4 -0
  3. package/dist/credentials/Posty5Api.credentials.d.ts.map +1 -1
  4. package/dist/credentials/Posty5Api.credentials.js +30 -4
  5. package/dist/credentials/Posty5Api.credentials.js.map +1 -1
  6. package/dist/nodes/Posty5FormSubmission/Posty5FormSubmission.node.d.ts.map +1 -1
  7. package/dist/nodes/Posty5FormSubmission/Posty5FormSubmission.node.js +6 -2
  8. package/dist/nodes/Posty5FormSubmission/Posty5FormSubmission.node.js.map +1 -1
  9. package/dist/nodes/Posty5HtmlHosting/Posty5HtmlHosting.node.d.ts.map +1 -1
  10. package/dist/nodes/Posty5HtmlHosting/Posty5HtmlHosting.node.js +14 -3
  11. package/dist/nodes/Posty5HtmlHosting/Posty5HtmlHosting.node.js.map +1 -1
  12. package/dist/nodes/Posty5QrCode/Posty5QrCode.node.d.ts +6 -0
  13. package/dist/nodes/Posty5QrCode/Posty5QrCode.node.d.ts.map +1 -1
  14. package/dist/nodes/Posty5QrCode/Posty5QrCode.node.js +850 -189
  15. package/dist/nodes/Posty5QrCode/Posty5QrCode.node.js.map +1 -1
  16. package/dist/nodes/Posty5QrCode/helpers.d.ts +12 -0
  17. package/dist/nodes/Posty5QrCode/helpers.d.ts.map +1 -0
  18. package/dist/nodes/Posty5QrCode/helpers.js +56 -0
  19. package/dist/nodes/Posty5QrCode/helpers.js.map +1 -0
  20. package/dist/nodes/Posty5ShortLink/Posty5ShortLink.node.d.ts +8 -0
  21. package/dist/nodes/Posty5ShortLink/Posty5ShortLink.node.d.ts.map +1 -1
  22. package/dist/nodes/Posty5ShortLink/Posty5ShortLink.node.js +389 -78
  23. package/dist/nodes/Posty5ShortLink/Posty5ShortLink.node.js.map +1 -1
  24. package/dist/nodes/Posty5ShortLink/helpers.d.ts +12 -0
  25. package/dist/nodes/Posty5ShortLink/helpers.d.ts.map +1 -0
  26. package/dist/nodes/Posty5ShortLink/helpers.js +46 -0
  27. package/dist/nodes/Posty5ShortLink/helpers.js.map +1 -0
  28. package/dist/nodes/Posty5SocialPublisherPost/Posty5SocialPublisherPost.node.d.ts.map +1 -1
  29. package/dist/nodes/Posty5SocialPublisherPost/Posty5SocialPublisherPost.node.js +143 -52
  30. package/dist/nodes/Posty5SocialPublisherPost/Posty5SocialPublisherPost.node.js.map +1 -1
  31. package/dist/nodes/Posty5Store/Posty5Store.node.d.ts +17 -0
  32. package/dist/nodes/Posty5Store/Posty5Store.node.d.ts.map +1 -0
  33. package/dist/nodes/Posty5Store/Posty5Store.node.js +230 -0
  34. package/dist/nodes/Posty5Store/Posty5Store.node.js.map +1 -0
  35. package/dist/nodes/Posty5Store/descriptions/fulfilment-group.description.d.ts +4 -0
  36. package/dist/nodes/Posty5Store/descriptions/fulfilment-group.description.d.ts.map +1 -0
  37. package/dist/nodes/Posty5Store/descriptions/fulfilment-group.description.js +55 -0
  38. package/dist/nodes/Posty5Store/descriptions/fulfilment-group.description.js.map +1 -0
  39. package/dist/nodes/Posty5Store/descriptions/order.description.d.ts +4 -0
  40. package/dist/nodes/Posty5Store/descriptions/order.description.d.ts.map +1 -0
  41. package/dist/nodes/Posty5Store/descriptions/order.description.js +91 -0
  42. package/dist/nodes/Posty5Store/descriptions/order.description.js.map +1 -0
  43. package/dist/nodes/Posty5Store/descriptions/product-link.description.d.ts +4 -0
  44. package/dist/nodes/Posty5Store/descriptions/product-link.description.d.ts.map +1 -0
  45. package/dist/nodes/Posty5Store/descriptions/product-link.description.js +48 -0
  46. package/dist/nodes/Posty5Store/descriptions/product-link.description.js.map +1 -0
  47. package/dist/nodes/Posty5Store/descriptions/supplier-order.description.d.ts +4 -0
  48. package/dist/nodes/Posty5Store/descriptions/supplier-order.description.d.ts.map +1 -0
  49. package/dist/nodes/Posty5Store/descriptions/supplier-order.description.js +118 -0
  50. package/dist/nodes/Posty5Store/descriptions/supplier-order.description.js.map +1 -0
  51. package/dist/nodes/Posty5Store/descriptions/supplier-product.description.d.ts +4 -0
  52. package/dist/nodes/Posty5Store/descriptions/supplier-product.description.d.ts.map +1 -0
  53. package/dist/nodes/Posty5Store/descriptions/supplier-product.description.js +167 -0
  54. package/dist/nodes/Posty5Store/descriptions/supplier-product.description.js.map +1 -0
  55. package/dist/nodes/Posty5Store/descriptions/supplier.description.d.ts +4 -0
  56. package/dist/nodes/Posty5Store/descriptions/supplier.description.d.ts.map +1 -0
  57. package/dist/nodes/Posty5Store/descriptions/supplier.description.js +50 -0
  58. package/dist/nodes/Posty5Store/descriptions/supplier.description.js.map +1 -0
  59. package/dist/nodes/Posty5Trigger/Posty5Trigger.node.d.ts +13 -0
  60. package/dist/nodes/Posty5Trigger/Posty5Trigger.node.d.ts.map +1 -0
  61. package/dist/nodes/Posty5Trigger/Posty5Trigger.node.js +171 -0
  62. package/dist/nodes/Posty5Trigger/Posty5Trigger.node.js.map +1 -0
  63. package/dist/nodes/Posty5Trigger/config.d.ts +51 -0
  64. package/dist/nodes/Posty5Trigger/config.d.ts.map +1 -0
  65. package/dist/nodes/Posty5Trigger/config.js +76 -0
  66. package/dist/nodes/Posty5Trigger/config.js.map +1 -0
  67. package/dist/nodes/Posty5Trigger/descriptions.d.ts +4 -0
  68. package/dist/nodes/Posty5Trigger/descriptions.d.ts.map +1 -0
  69. package/dist/nodes/Posty5Trigger/descriptions.js +99 -0
  70. package/dist/nodes/Posty5Trigger/descriptions.js.map +1 -0
  71. package/dist/nodes/Posty5Trigger/helpers.d.ts +34 -0
  72. package/dist/nodes/Posty5Trigger/helpers.d.ts.map +1 -0
  73. package/dist/nodes/Posty5Trigger/helpers.js +139 -0
  74. package/dist/nodes/Posty5Trigger/helpers.js.map +1 -0
  75. package/dist/package.json +78 -0
  76. package/dist/types/common.d.ts +62 -0
  77. package/dist/types/common.d.ts.map +1 -1
  78. package/dist/types/link-analytics.types.d.ts +147 -0
  79. package/dist/types/link-analytics.types.d.ts.map +1 -0
  80. package/dist/types/link-analytics.types.js +10 -0
  81. package/dist/types/link-analytics.types.js.map +1 -0
  82. package/dist/types/link-bulk.types.d.ts +68 -0
  83. package/dist/types/link-bulk.types.d.ts.map +1 -0
  84. package/dist/types/link-bulk.types.js +8 -0
  85. package/dist/types/link-bulk.types.js.map +1 -0
  86. package/dist/types/qr-code.types.d.ts +189 -56
  87. package/dist/types/qr-code.types.d.ts.map +1 -1
  88. package/dist/types/short-link-controls.types.d.ts +82 -0
  89. package/dist/types/short-link-controls.types.d.ts.map +1 -0
  90. package/dist/types/short-link-controls.types.js +7 -0
  91. package/dist/types/short-link-controls.types.js.map +1 -0
  92. package/dist/types/short-link.types.d.ts +63 -15
  93. package/dist/types/short-link.types.d.ts.map +1 -1
  94. package/dist/types/store.types.d.ts +71 -0
  95. package/dist/types/store.types.d.ts.map +1 -0
  96. package/dist/types/store.types.js +7 -0
  97. package/dist/types/store.types.js.map +1 -0
  98. package/dist/types/webhook.types.d.ts +66 -0
  99. package/dist/types/webhook.types.d.ts.map +1 -0
  100. package/dist/types/webhook.types.js +7 -0
  101. package/dist/types/webhook.types.js.map +1 -0
  102. package/dist/utils/analytics.helpers.d.ts +68 -0
  103. package/dist/utils/analytics.helpers.d.ts.map +1 -0
  104. package/dist/utils/analytics.helpers.js +202 -0
  105. package/dist/utils/analytics.helpers.js.map +1 -0
  106. package/dist/utils/analytics.properties.d.ts +10 -0
  107. package/dist/utils/analytics.properties.d.ts.map +1 -0
  108. package/dist/utils/analytics.properties.js +172 -0
  109. package/dist/utils/analytics.properties.js.map +1 -0
  110. package/dist/utils/api.helpers.d.ts +36 -3
  111. package/dist/utils/api.helpers.d.ts.map +1 -1
  112. package/dist/utils/api.helpers.js +77 -7
  113. package/dist/utils/api.helpers.js.map +1 -1
  114. package/dist/utils/constants.d.ts +198 -0
  115. package/dist/utils/constants.d.ts.map +1 -1
  116. package/dist/utils/constants.js +215 -1
  117. package/dist/utils/constants.js.map +1 -1
  118. package/dist/utils/date.helpers.d.ts +25 -0
  119. package/dist/utils/date.helpers.d.ts.map +1 -0
  120. package/dist/utils/date.helpers.js +65 -0
  121. package/dist/utils/date.helpers.js.map +1 -0
  122. package/dist/utils/link-bulk.helpers.d.ts +26 -0
  123. package/dist/utils/link-bulk.helpers.d.ts.map +1 -0
  124. package/dist/utils/link-bulk.helpers.js +135 -0
  125. package/dist/utils/link-bulk.helpers.js.map +1 -0
  126. package/dist/utils/link-bulk.properties.d.ts +9 -0
  127. package/dist/utils/link-bulk.properties.d.ts.map +1 -0
  128. package/dist/utils/link-bulk.properties.js +113 -0
  129. package/dist/utils/link-bulk.properties.js.map +1 -0
  130. package/dist/utils/link-tool.helpers.d.ts +43 -0
  131. package/dist/utils/link-tool.helpers.d.ts.map +1 -0
  132. package/dist/utils/link-tool.helpers.js +121 -0
  133. package/dist/utils/link-tool.helpers.js.map +1 -0
  134. package/dist/utils/post-comments.d.ts +43 -0
  135. package/dist/utils/post-comments.d.ts.map +1 -0
  136. package/dist/utils/post-comments.js +53 -0
  137. package/dist/utils/post-comments.js.map +1 -0
  138. package/dist/utils/qr-content.config.d.ts +66 -0
  139. package/dist/utils/qr-content.config.d.ts.map +1 -0
  140. package/dist/utils/qr-content.config.js +139 -0
  141. package/dist/utils/qr-content.config.js.map +1 -0
  142. package/dist/utils/qr-file.helpers.d.ts +22 -0
  143. package/dist/utils/qr-file.helpers.d.ts.map +1 -0
  144. package/dist/utils/qr-file.helpers.js +63 -0
  145. package/dist/utils/qr-file.helpers.js.map +1 -0
  146. package/dist/utils/qr-target.helpers.d.ts +35 -0
  147. package/dist/utils/qr-target.helpers.d.ts.map +1 -0
  148. package/dist/utils/qr-target.helpers.js +260 -0
  149. package/dist/utils/qr-target.helpers.js.map +1 -0
  150. package/dist/utils/qr-templates.helpers.d.ts +26 -0
  151. package/dist/utils/qr-templates.helpers.d.ts.map +1 -0
  152. package/dist/utils/qr-templates.helpers.js +70 -0
  153. package/dist/utils/qr-templates.helpers.js.map +1 -0
  154. package/dist/utils/short-link-controls.helpers.d.ts +31 -0
  155. package/dist/utils/short-link-controls.helpers.d.ts.map +1 -0
  156. package/dist/utils/short-link-controls.helpers.js +185 -0
  157. package/dist/utils/short-link-controls.helpers.js.map +1 -0
  158. package/dist/utils/short-link-controls.properties.d.ts +17 -0
  159. package/dist/utils/short-link-controls.properties.d.ts.map +1 -0
  160. package/dist/utils/short-link-controls.properties.js +315 -0
  161. package/dist/utils/short-link-controls.properties.js.map +1 -0
  162. package/dist/utils/store.helpers.d.ts +43 -0
  163. package/dist/utils/store.helpers.d.ts.map +1 -0
  164. package/dist/utils/store.helpers.js +87 -0
  165. package/dist/utils/store.helpers.js.map +1 -0
  166. package/dist/utils/versioned-write.helpers.d.ts +31 -0
  167. package/dist/utils/versioned-write.helpers.d.ts.map +1 -0
  168. package/dist/utils/versioned-write.helpers.js +120 -0
  169. package/dist/utils/versioned-write.helpers.js.map +1 -0
  170. package/package.json +7 -3
@@ -0,0 +1,202 @@
1
+ "use strict";
2
+ /**
3
+ * *Get Analytics* on the Short Link and QR Code nodes (contract C2).
4
+ *
5
+ * Both nodes read the same parameters and answer the same shape, so the range
6
+ * resolution, the query, the output shaping and the plan-gate error live here,
7
+ * not in either node's `execute`. The query follows the SDKs: dates as
8
+ * `YYYY-MM-DD`, an explicit breakdown list joined with `,`, `all` sent as is,
9
+ * an empty list left out (the API default applies).
10
+ */
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.executeGetAnalytics = executeGetAnalytics;
13
+ exports.getAnalyticsParameters = getAnalyticsParameters;
14
+ exports.resolveAnalyticsTimeZone = resolveAnalyticsTimeZone;
15
+ exports.buildAnalyticsEndpoint = buildAnalyticsEndpoint;
16
+ exports.resolveAnalyticsRange = resolveAnalyticsRange;
17
+ exports.buildAnalyticsQuery = buildAnalyticsQuery;
18
+ exports.toAnalyticsOutput = toAnalyticsOutput;
19
+ exports.toAnalyticsError = toAnalyticsError;
20
+ exports.executeGetStatistics = executeGetStatistics;
21
+ exports.buildStatisticsQuery = buildStatisticsQuery;
22
+ const n8n_workflow_1 = require("n8n-workflow");
23
+ const api_helpers_1 = require("./api.helpers");
24
+ const constants_1 = require("./constants");
25
+ const date_helpers_1 = require("./date.helpers");
26
+ const link_tool_helpers_1 = require("./link-tool.helpers");
27
+ /**
28
+ * Runs *Get Analytics* for item `itemIndex`: reads its parameters, resolves the
29
+ * range, calls `GET <basePath>/<id>/analytics` and shapes the output.
30
+ * @param basePath `API_ENDPOINTS.SHORT_LINK` or `API_ENDPOINTS.QR_CODE`.
31
+ * @param id The record's ID parameter value.
32
+ */
33
+ async function executeGetAnalytics(context, apiKey, basePath, id, itemIndex) {
34
+ const endpoint = buildAnalyticsEndpoint(context, basePath, id, itemIndex);
35
+ const parameters = getAnalyticsParameters(context, itemIndex);
36
+ const qs = buildAnalyticsQuery(resolveAnalyticsRange(context, parameters, new Date(), itemIndex), parameters);
37
+ const output = context.getNodeParameter('output', itemIndex, constants_1.LINK_ANALYTICS.DEFAULT_OUTPUT);
38
+ let response;
39
+ try {
40
+ response = (await api_helpers_1.makeApiRequest.call(context, apiKey, { method: 'GET', endpoint, qs }));
41
+ }
42
+ catch (error) {
43
+ throw toAnalyticsError(context, error, itemIndex);
44
+ }
45
+ return toAnalyticsOutput(response, output);
46
+ }
47
+ /** Reads every *Get Analytics* parameter of item `itemIndex`. */
48
+ function getAnalyticsParameters(context, itemIndex) {
49
+ const range = context.getNodeParameter('range', itemIndex, constants_1.LINK_ANALYTICS.DEFAULT_RANGE);
50
+ const isCustom = range === 'custom';
51
+ const allBreakdowns = context.getNodeParameter('allBreakdowns', itemIndex, true);
52
+ const options = context.getNodeParameter('analyticsOptions', itemIndex, {});
53
+ // A field hidden by its display options is not read.
54
+ return {
55
+ range,
56
+ from: isCustom ? context.getNodeParameter('from', itemIndex, '') : undefined,
57
+ to: isCustom ? context.getNodeParameter('to', itemIndex, '') : undefined,
58
+ interval: context.getNodeParameter('interval', itemIndex, constants_1.LINK_ANALYTICS.DEFAULT_INTERVAL),
59
+ allBreakdowns,
60
+ breakdowns: allBreakdowns
61
+ ? []
62
+ : context.getNodeParameter('breakdowns', itemIndex, []),
63
+ options,
64
+ timeZone: resolveAnalyticsTimeZone(context, options),
65
+ };
66
+ }
67
+ /**
68
+ * The zone of one request: the Time Zone option, else the workflow's time zone
69
+ * (Workflow Settings → Timezone, which defaults to the instance's
70
+ * `GENERIC_TIMEZONE`), else UTC. Sent as `tz` so the API buckets days in the
71
+ * same zone the presets count "today" in.
72
+ */
73
+ function resolveAnalyticsTimeZone(context, options) {
74
+ return ((0, link_tool_helpers_1.firstText)(options.timezone) ??
75
+ (0, link_tool_helpers_1.firstText)(typeof context.getTimezone === 'function' ? context.getTimezone() : undefined) ??
76
+ constants_1.LINK_ANALYTICS.FALLBACK_TIME_ZONE);
77
+ }
78
+ /**
79
+ * `<basePath>/<id>/analytics`, with the ID trimmed and escaped.
80
+ * @throws NodeOperationError when the ID is empty.
81
+ */
82
+ function buildAnalyticsEndpoint(context, basePath, id, itemIndex) {
83
+ const recordId = (0, link_tool_helpers_1.firstText)(id);
84
+ if (!recordId) {
85
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), constants_1.LINK_ANALYTICS_MESSAGES.ID_REQUIRED, { itemIndex });
86
+ }
87
+ return `${basePath}/${encodeURIComponent(recordId)}/${constants_1.LINK_ANALYTICS.PATH_SEGMENT}`;
88
+ }
89
+ /**
90
+ * The range as two inclusive day keys. A preset ends today — counted in
91
+ * `parameters.timeZone` — and spans its number of days, today included
92
+ * (*Last 7 days* on 2026-10-05 is 2026-09-29 … 2026-10-05). *Custom* sends the
93
+ * From and To days as picked; the API checks their order, span and plan window.
94
+ * @throws NodeOperationError for an unknown time zone, or a missing or
95
+ * unreadable custom date.
96
+ */
97
+ function resolveAnalyticsRange(context, parameters, now, itemIndex) {
98
+ // Checked for every range: the zone is also sent as `tz`, which the API validates.
99
+ if (!(0, date_helpers_1.isKnownTimeZone)(parameters.timeZone)) {
100
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), `Time Zone "${parameters.timeZone}" ${constants_1.LINK_ANALYTICS_MESSAGES.UNKNOWN_TIME_ZONE}`, { itemIndex });
101
+ }
102
+ if (parameters.range === 'custom') {
103
+ if (!(0, link_tool_helpers_1.firstText)(parameters.from) || !(0, link_tool_helpers_1.firstText)(parameters.to)) {
104
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), constants_1.LINK_ANALYTICS_MESSAGES.CUSTOM_RANGE_REQUIRED, {
105
+ itemIndex,
106
+ });
107
+ }
108
+ return {
109
+ from: requireDayKey(context, 'From', parameters.from, itemIndex),
110
+ to: requireDayKey(context, 'To', parameters.to, itemIndex),
111
+ };
112
+ }
113
+ const presets = constants_1.LINK_ANALYTICS.RANGE_DAYS;
114
+ const days = presets[parameters.range] ?? presets[constants_1.LINK_ANALYTICS.DEFAULT_RANGE];
115
+ const to = (0, date_helpers_1.toDayKey)(now, parameters.timeZone);
116
+ return { from: (0, date_helpers_1.shiftDayKey)(to, 1 - days), to };
117
+ }
118
+ /** The query string of one *Get Analytics* request. */
119
+ function buildAnalyticsQuery(range, parameters) {
120
+ const query = {
121
+ from: range.from,
122
+ to: range.to,
123
+ interval: parameters.interval,
124
+ tz: parameters.timeZone,
125
+ };
126
+ if (parameters.allBreakdowns) {
127
+ query.breakdown = constants_1.LINK_ANALYTICS.ALL_BREAKDOWNS;
128
+ }
129
+ else if (parameters.breakdowns.length > 0) {
130
+ query.breakdown = parameters.breakdowns.join(constants_1.LINK_ANALYTICS.BREAKDOWN_SEPARATOR);
131
+ }
132
+ if (typeof parameters.options.limit === 'number')
133
+ query.limit = parameters.options.limit;
134
+ return query;
135
+ }
136
+ /**
137
+ * What the operation outputs for one input item: the API answer unchanged, or
138
+ * — *Series as Items* — one item per series point, each still carrying `meta`.
139
+ */
140
+ function toAnalyticsOutput(response, output) {
141
+ if (output !== 'seriesAsItems')
142
+ return response;
143
+ return (response?.series ?? []).map((point) => ({ ...point, meta: response.meta }));
144
+ }
145
+ /**
146
+ * A failed analytics request as the node throws it. The plan-gate 403 (a
147
+ * breakdown or a range the owner's plan does not include, or a record the API
148
+ * key may not read) becomes a `NodeApiError` carrying the API's message
149
+ * unchanged (C4: no client hard-codes a plan); any other error is returned as is.
150
+ */
151
+ function toAnalyticsError(context, error, itemIndex) {
152
+ const apiError = error;
153
+ if (apiError?.httpCode !== constants_1.LINK_ANALYTICS.PLAN_GATE_HTTP_CODE)
154
+ return error;
155
+ const message = apiError.apiMessage || apiError.message;
156
+ return new n8n_workflow_1.NodeApiError(context.getNode(), { message, httpCode: apiError.httpCode }, {
157
+ message,
158
+ httpCode: apiError.httpCode,
159
+ itemIndex,
160
+ });
161
+ }
162
+ /**
163
+ * Runs *Get Statistics* for item `itemIndex`: `GET <basePath>/statistics` with
164
+ * the Period (and, for Custom, From / To), returning the API answer unchanged.
165
+ * @param basePath `API_ENDPOINTS.SHORT_LINK` or `API_ENDPOINTS.QR_CODE`.
166
+ */
167
+ async function executeGetStatistics(context, apiKey, basePath, itemIndex) {
168
+ const period = context.getNodeParameter('statisticsPeriod', itemIndex, constants_1.LINK_STATISTICS.DEFAULT_PERIOD);
169
+ const isCustom = period === constants_1.LINK_STATISTICS.CUSTOM_PERIOD;
170
+ const qs = buildStatisticsQuery(context, period, isCustom ? context.getNodeParameter('statisticsFrom', itemIndex, '') : undefined, isCustom ? context.getNodeParameter('statisticsTo', itemIndex, '') : undefined, itemIndex);
171
+ return (await api_helpers_1.makeApiRequest.call(context, apiKey, {
172
+ method: 'GET',
173
+ endpoint: `${basePath}/${constants_1.LINK_STATISTICS.PATH_SEGMENT}`,
174
+ qs,
175
+ }));
176
+ }
177
+ /**
178
+ * The *Get Statistics* query: the period, plus `from` / `to` as day keys for
179
+ * Custom (both required, like *Get Analytics*).
180
+ * @throws NodeOperationError for a missing or unreadable custom date.
181
+ */
182
+ function buildStatisticsQuery(context, period, from, to, itemIndex) {
183
+ if (period !== constants_1.LINK_STATISTICS.CUSTOM_PERIOD)
184
+ return { period };
185
+ if (!(0, link_tool_helpers_1.firstText)(from) || !(0, link_tool_helpers_1.firstText)(to)) {
186
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), constants_1.LINK_ANALYTICS_MESSAGES.CUSTOM_RANGE_REQUIRED, { itemIndex });
187
+ }
188
+ return {
189
+ period,
190
+ from: requireDayKey(context, 'From', from, itemIndex),
191
+ to: requireDayKey(context, 'To', to, itemIndex),
192
+ };
193
+ }
194
+ /** A custom From / To value as a day key. */
195
+ function requireDayKey(context, label, value, itemIndex) {
196
+ const dayKey = (0, date_helpers_1.parseDayKey)(value);
197
+ if (!dayKey) {
198
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), `${label} "${String(value)}" ${constants_1.LINK_ANALYTICS_MESSAGES.INVALID_DATE}`, { itemIndex });
199
+ }
200
+ return dayKey;
201
+ }
202
+ //# sourceMappingURL=analytics.helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.helpers.js","sourceRoot":"","sources":["../../utils/analytics.helpers.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AA+BH,kDAmBC;AAGD,wDAsBC;AAQD,4DAMC;AAMD,wDAWC;AAUD,sDA8BC;AAGD,kDAgBC;AAMD,8CAMC;AAQD,4CAUC;AAOD,oDAwBC;AAOD,oDAgBC;AAvPD,+CAAgE;AAEhE,+CAA+C;AAC/C,2CAAuF;AACvF,iDAAqF;AACrF,2DAAgD;AAkBhD;;;;;GAKG;AACI,KAAK,UAAU,mBAAmB,CACxC,OAA0B,EAC1B,MAAc,EACd,QAAgB,EAChB,EAAW,EACX,SAAiB;IAEjB,MAAM,QAAQ,GAAG,sBAAsB,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,SAAS,CAAC,CAAC;IAC1E,MAAM,UAAU,GAAG,sBAAsB,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IA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A,6BAAS,EAAC,IAAI,CAAC,IAAI,CAAC,IAAA,6BAAS,EAAC,EAAE,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,iCAAkB,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,mCAAuB,CAAC,qBAAqB,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC;IAC/G,CAAC;IACD,OAAO;QACN,MAAM;QACN,IAAI,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,CAAC;QACrD,EAAE,EAAE,aAAa,CAAC,OAAO,EAAE,IAAI,EAAE,EAAE,EAAE,SAAS,CAAC;KAC/C,CAAC;AACH,CAAC;AAED,6CAA6C;AAC7C,SAAS,aAAa,CAAC,OAA0B,EAAE,KAAa,EAAE,KAAc,EAAE,SAAiB;IAClG,MAAM,MAAM,GAAG,IAAA,0BAAW,EAAC,KAAK,CAAC,CAAC;IAClC,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,iCAAkB,CAC3B,OAAO,CAAC,OAAO,EAAE,EACjB,GAAG,KAAK,KAAK,MAAM,CAAC,KAAK,CAAC,KAAK,mCAAuB,CAAC,YAAY,EAAE,EACrE,EAAE,SAAS,EAAE,CACb,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * The *Get Analytics* parameters, shared by the Short Link and QR Code nodes
3
+ * (each node keeps its own ID field and adds `getAnalytics` to its display
4
+ * options). Read by `getAnalyticsParameters` in `analytics.helpers.ts`.
5
+ */
6
+ import type { INodeProperties } from 'n8n-workflow';
7
+ export declare const LINK_ANALYTICS_PROPERTIES: INodeProperties[];
8
+ /** *Get Statistics* parameters (account-wide counts; no ID field). Read by `executeGetStatistics`. */
9
+ export declare const LINK_STATISTICS_PROPERTIES: INodeProperties[];
10
+ //# sourceMappingURL=analytics.properties.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.properties.d.ts","sourceRoot":"","sources":["../../utils/analytics.properties.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAMpD,eAAO,MAAM,yBAAyB,EAAE,eAAe,EA6HtD,CAAC;AAKF,sGAAsG;AACtG,eAAO,MAAM,0BAA0B,EAAE,eAAe,EAkCvD,CAAC"}
@@ -0,0 +1,172 @@
1
+ "use strict";
2
+ /**
3
+ * The *Get Analytics* parameters, shared by the Short Link and QR Code nodes
4
+ * (each node keeps its own ID field and adds `getAnalytics` to its display
5
+ * options). Read by `getAnalyticsParameters` in `analytics.helpers.ts`.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.LINK_STATISTICS_PROPERTIES = exports.LINK_ANALYTICS_PROPERTIES = void 0;
9
+ const constants_1 = require("./constants");
10
+ /** Shown only for the *Get Analytics* operation. */
11
+ const SHOW_ON_GET_ANALYTICS = { show: { operation: ['getAnalytics'] } };
12
+ exports.LINK_ANALYTICS_PROPERTIES = [
13
+ {
14
+ displayName: 'Range',
15
+ name: 'range',
16
+ type: 'options',
17
+ displayOptions: SHOW_ON_GET_ANALYTICS,
18
+ options: [
19
+ { name: 'Custom', value: 'custom', description: 'Pick the first and last day' },
20
+ { name: 'Last 30 Days', value: 'last30Days', description: 'Today and the 29 days before it' },
21
+ { name: 'Last 7 Days', value: 'last7Days', description: 'Today and the 6 days before it' },
22
+ { name: 'Last 90 Days', value: 'last90Days', description: 'Today and the 89 days before it' },
23
+ ],
24
+ default: constants_1.LINK_ANALYTICS.DEFAULT_RANGE,
25
+ description: 'The days to read. "Today" is counted in the Time Zone option, or in the time zone of the workflow when it is empty. A range that reaches further back than your plan allows answers the plan error.',
26
+ },
27
+ {
28
+ displayName: 'From',
29
+ name: 'from',
30
+ type: 'dateTime',
31
+ required: true,
32
+ displayOptions: { show: { operation: ['getAnalytics'], range: ['custom'] } },
33
+ default: '',
34
+ description: 'First day of the range (only the date is used)',
35
+ },
36
+ {
37
+ displayName: 'To',
38
+ name: 'to',
39
+ type: 'dateTime',
40
+ required: true,
41
+ displayOptions: { show: { operation: ['getAnalytics'], range: ['custom'] } },
42
+ default: '',
43
+ description: 'Last day of the range, included (only the date is used). A future day is clamped to today.',
44
+ },
45
+ {
46
+ displayName: 'Interval',
47
+ name: 'interval',
48
+ type: 'options',
49
+ displayOptions: SHOW_ON_GET_ANALYTICS,
50
+ options: [
51
+ { name: 'Day', value: 'day' },
52
+ { name: 'Month', value: 'month', description: 'Each point starts on the 1st' },
53
+ { name: 'Week', value: 'week', description: 'Each point starts on a Monday' },
54
+ ],
55
+ default: constants_1.LINK_ANALYTICS.DEFAULT_INTERVAL,
56
+ description: 'Width of one point of the series',
57
+ },
58
+ {
59
+ displayName: 'All Breakdowns My Plan Allows',
60
+ name: 'allBreakdowns',
61
+ type: 'boolean',
62
+ displayOptions: SHOW_ON_GET_ANALYTICS,
63
+ default: true,
64
+ description: 'Whether to return every breakdown your plan includes. The ones it does not are listed in meta.locked with the plan that adds them.',
65
+ },
66
+ {
67
+ displayName: 'Breakdowns',
68
+ name: 'breakdowns',
69
+ type: 'multiOptions',
70
+ displayOptions: { show: { operation: ['getAnalytics'], allBreakdowns: [false] } },
71
+ options: [
72
+ { name: 'A/B Variant', value: 'variant', description: 'Empty until link campaigns are available' },
73
+ { name: 'Browser', value: 'browser' },
74
+ { name: 'Channel', value: 'channel', description: 'Click (link) or scan (qr)' },
75
+ { name: 'Country', value: 'country', description: 'Two-letter country code' },
76
+ { name: 'Device', value: 'device', description: 'Desktop, mobile, tablet or other' },
77
+ { name: 'Language', value: 'language', description: 'Primary browser language' },
78
+ { name: 'Operating System', value: 'os' },
79
+ { name: 'Referrer', value: 'referrer', description: 'The site the visitor came from' },
80
+ { name: 'Routing Rule', value: 'rule', description: 'Empty until link campaigns are available' },
81
+ ],
82
+ default: [],
83
+ description: 'Breakdowns to return. Naming one your plan does not include answers the plan error. Left empty, the API returns every breakdown your plan allows.',
84
+ },
85
+ {
86
+ displayName: 'Output',
87
+ name: 'output',
88
+ type: 'options',
89
+ displayOptions: SHOW_ON_GET_ANALYTICS,
90
+ options: [
91
+ {
92
+ name: 'Full Response',
93
+ value: 'response',
94
+ description: 'One item: totals, series, breakdowns and meta, as the API answers',
95
+ },
96
+ {
97
+ name: 'Series as Items',
98
+ value: 'seriesAsItems',
99
+ description: 'One item per series point (date, visits, unique visitors), each with meta',
100
+ },
101
+ ],
102
+ default: constants_1.LINK_ANALYTICS.DEFAULT_OUTPUT,
103
+ },
104
+ {
105
+ displayName: 'Options',
106
+ name: 'analyticsOptions',
107
+ type: 'collection',
108
+ placeholder: 'Add Option',
109
+ default: {},
110
+ displayOptions: SHOW_ON_GET_ANALYTICS,
111
+ options: [
112
+ {
113
+ displayName: 'Breakdown Rows',
114
+ name: 'limit',
115
+ type: 'number',
116
+ typeOptions: {
117
+ minValue: constants_1.LINK_ANALYTICS.LIMIT_MIN,
118
+ maxValue: constants_1.LINK_ANALYTICS.LIMIT_MAX,
119
+ },
120
+ default: constants_1.LINK_ANALYTICS.LIMIT_DEFAULT,
121
+ description: 'Rows per breakdown, 1 to 50 (API default 10); the rest is summed into an "other" row',
122
+ },
123
+ {
124
+ displayName: 'Time Zone',
125
+ name: 'timezone',
126
+ type: 'string',
127
+ default: '',
128
+ placeholder: 'Africa/Cairo',
129
+ description: 'IANA time zone the days are counted in, sent as tz. Empty: the time zone of the workflow (Workflow Settings > Timezone). Ranges older than the raw-visit retention are counted in UTC days (meta.timezone says so).',
130
+ },
131
+ ],
132
+ },
133
+ ];
134
+ /** Shown only for the *Get Statistics* operation. */
135
+ const SHOW_ON_GET_STATISTICS = { show: { operation: ['getStatistics'] } };
136
+ /** *Get Statistics* parameters (account-wide counts; no ID field). Read by `executeGetStatistics`. */
137
+ exports.LINK_STATISTICS_PROPERTIES = [
138
+ {
139
+ displayName: 'Period',
140
+ name: 'statisticsPeriod',
141
+ type: 'options',
142
+ displayOptions: SHOW_ON_GET_STATISTICS,
143
+ options: [
144
+ { name: 'Custom', value: 'custom', description: 'Pick the first and last day' },
145
+ { name: 'Last 30 Days', value: '30d', description: 'Today and the 29 days before it' },
146
+ { name: 'Last 7 Days', value: '7d', description: 'Today and the 6 days before it' },
147
+ { name: 'This Month', value: 'month', description: 'From the 1st of this month' },
148
+ { name: 'Today', value: 'today' },
149
+ ],
150
+ default: constants_1.LINK_STATISTICS.DEFAULT_PERIOD,
151
+ description: 'The days to count. Days are UTC days.',
152
+ },
153
+ {
154
+ displayName: 'From',
155
+ name: 'statisticsFrom',
156
+ type: 'dateTime',
157
+ required: true,
158
+ displayOptions: { show: { operation: ['getStatistics'], statisticsPeriod: ['custom'] } },
159
+ default: '',
160
+ description: 'First day of the period (only the date is used)',
161
+ },
162
+ {
163
+ displayName: 'To',
164
+ name: 'statisticsTo',
165
+ type: 'dateTime',
166
+ required: true,
167
+ displayOptions: { show: { operation: ['getStatistics'], statisticsPeriod: ['custom'] } },
168
+ default: '',
169
+ description: 'Last day of the period, included (only the date is used)',
170
+ },
171
+ ];
172
+ //# sourceMappingURL=analytics.properties.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics.properties.js","sourceRoot":"","sources":["../../utils/analytics.properties.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;;AAGH,2CAA8D;AAE9D,oDAAoD;AACpD,MAAM,qBAAqB,GAAG,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;AAE3D,QAAA,yBAAyB,GAAsB;IAC3D;QACC,WAAW,EAAE,OAAO;QACpB,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,SAAS;QACf,cAAc,EAAE,qBAAqB;QACrC,OAAO,EAAE;YACR,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,6BAA6B,EAAE;YAC/E,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,YAAY,EAAE,WAA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,EAAE,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,6BAA6B,EAAE;YAC/E,EAAE,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,iCAAiC,EAAE;YACtF,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,gCAAgC,EAAE;YACnF,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,4BAA4B,EAAE;YACjF,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE;SACjC;QACD,OAAO,EAAE,2BAAe,CAAC,cAAc;QACvC,WAAW,EAAE,uCAAuC;KACpD;IACD;QACC,WAAW,EAAE,MAAM;QACnB,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,eAAe,CAAC,EAAE,gBAAgB,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE;QACxF,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,iDAAiD;KAC9D;IACD;QACC,WAAW,EAAE,IAAI;QACjB,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,EAAE,IAAI,EAAE,EAAE,SAAS,EAAE,CAAC,eAAe,CAAC,EAAE,gBAAgB,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE;QACxF,OAAO,EAAE,EAAE;QACX,WAAW,EAAE,0DAA0D;KACvE;CACD,CAAC"}
@@ -2,21 +2,54 @@
2
2
  * Posty5 API Helper Functions
3
3
  * Utility functions for making API requests using n8n's native HTTP helpers
4
4
  */
5
- import { IExecuteFunctions } from 'n8n-workflow';
5
+ import { IExecuteFunctions, IHookFunctions, ILoadOptionsFunctions } from 'n8n-workflow';
6
+ import type { IPosty5ApiError } from '../types/common';
6
7
  export interface IApiRequestOptions {
7
8
  method: 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
8
9
  endpoint: string;
9
10
  body?: any;
10
11
  qs?: any;
12
+ /**
13
+ * Add `createdFrom: 'n8n'` to a POST body (the default). The store node turns
14
+ * it off for `/api/store-suppliers`: those bodies are validated by schemas that
15
+ * never declared the key, and a body should not carry what its route ignores.
16
+ */
17
+ stampCreatedFrom?: boolean;
18
+ /** Extra request headers (e.g. `Idempotency-Key`), merged over the fixed ones. */
19
+ headers?: Record<string, string>;
20
+ /**
21
+ * The document version the caller read (`__v`). Sent as `If-Match: "<v>"`
22
+ * (optimistic concurrency, D-5), and the answer's envelope `version` is
23
+ * copied onto the result as `__v` so the next step can chain it.
24
+ */
25
+ version?: number;
26
+ /** Return the whole `{ message, result, version }` envelope instead of `result`. */
27
+ returnEnvelope?: boolean;
11
28
  }
12
29
  /**
13
30
  * Make an API request to Posty5 API using n8n's HTTP request helper
14
- * @param context - N8n execution context
31
+ * @param context - N8n execution context, or a `loadOptions` context (both carry `helpers.httpRequest`)
15
32
  * @param apiKey - Posty5 API key
16
33
  * @param options - Request options
17
34
  * @returns API response
18
35
  */
19
- export declare function makeApiRequest(this: IExecuteFunctions, apiKey: string, options: IApiRequestOptions): Promise<any>;
36
+ export declare function makeApiRequest(this: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, apiKey: string, options: IApiRequestOptions): Promise<any>;
37
+ /**
38
+ * The `NodeApiError` `makeApiRequest` throws. Its message stays
39
+ * `Posty5 API Error: <message>` (except a version conflict, which says how to
40
+ * fix it); `httpCode`, `apiMessage`, the API's `code` and, on a
41
+ * `VERSION_CONFLICT`, `currentVersion` ride along. A context without
42
+ * `getNode` (never in n8n) gets the plain error.
43
+ */
44
+ export declare function toPosty5NodeApiError(context: IExecuteFunctions | ILoadOptionsFunctions | IHookFunctions, error: any): IPosty5ApiError;
45
+ /**
46
+ * The error `makeApiRequest` throws for a failed request. The API's message is
47
+ * read from the answer: `response.data` is where n8n's `httpRequest` (axios)
48
+ * puts the parsed body, `response.body` is the older request-library shape.
49
+ * The HTTP status is kept as `httpCode` so a caller can map one status (the
50
+ * analytics plan-gate 403) to a `NodeApiError` without parsing the message.
51
+ */
52
+ export declare function toPosty5ApiError(error: any): IPosty5ApiError;
20
53
  /**
21
54
  * Make a paginated list request
22
55
  * @param context - N8n execution context
@@ -1 +1 @@
1
- {"version":3,"file":"api.helpers.d.ts","sourceRoot":"","sources":["../../utils/api.helpers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAuB,MAAM,cAAc,CAAC;AAGtE,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,EAAE,CAAC,EAAE,GAAG,CAAC;CACT;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CACnC,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,kBAAkB,GACzB,OAAO,CAAC,GAAG,CAAC,CA4Cd;AAED;;;;;;;;GAQG;AACH,wBAAsB,oBAAoB,CACzC,IAAI,EAAE,iBAAiB,EACvB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,GAAQ,EACjB,UAAU,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,GAAG,CAAC,CASd;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC/B,IAAI,EAAE,iBAAiB,EACvB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,GAAG,CAAC,CAkBd"}
1
+ {"version":3,"file":"api.helpers.d.ts","sourceRoot":"","sources":["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CAAC,EAAE,MAAM,CAAA;CAAO,GACnD,OAAO,CAAC,GAAG,CAAC,CASd;AAED;;;;;GAKG;AACH,wBAAsB,UAAU,CAC/B,IAAI,EAAE,iBAAiB,EACvB,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,GAAG,CAAC,CAkBd"}
@@ -5,12 +5,15 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.makeApiRequest = makeApiRequest;
8
+ exports.toPosty5NodeApiError = toPosty5NodeApiError;
9
+ exports.toPosty5ApiError = toPosty5ApiError;
8
10
  exports.makePaginatedRequest = makePaginatedRequest;
9
11
  exports.uploadFile = uploadFile;
12
+ const n8n_workflow_1 = require("n8n-workflow");
10
13
  const constants_1 = require("./constants");
11
14
  /**
12
15
  * Make an API request to Posty5 API using n8n's HTTP request helper
13
- * @param context - N8n execution context
16
+ * @param context - N8n execution context, or a `loadOptions` context (both carry `helpers.httpRequest`)
14
17
  * @param apiKey - Posty5 API key
15
18
  * @param options - Request options
16
19
  * @returns API response
@@ -23,14 +26,19 @@ async function makeApiRequest(apiKey, options) {
23
26
  headers: {
24
27
  'X-API-Key': apiKey,
25
28
  'Content-Type': 'application/json',
29
+ [constants_1.Posty5ClientConst.HEADER]: constants_1.Posty5ClientConst.VALUE,
30
+ ...(typeof options.version === 'number'
31
+ ? { [constants_1.VERSIONED_WRITES.IF_MATCH_HEADER]: `"${options.version}"` }
32
+ : {}),
33
+ ...(options.headers || {}),
26
34
  },
27
35
  json: true,
28
36
  };
29
37
  if (options.body) {
30
38
  requestOptions.body = options.body;
31
39
  }
32
- // Add createdFrom to all POST request bodies
33
- if (options.method === 'POST') {
40
+ // Add createdFrom to POST request bodies, unless the caller opts out
41
+ if (options.method === 'POST' && options.stampCreatedFrom !== false) {
34
42
  requestOptions.body = { ...requestOptions.body, createdFrom: 'n8n' };
35
43
  }
36
44
  if (options.qs) {
@@ -40,19 +48,81 @@ async function makeApiRequest(apiKey, options) {
40
48
  const response = await this.helpers.httpRequest(requestOptions);
41
49
  // Handle standard Posty5 API response format
42
50
  if (response && typeof response === 'object') {
51
+ if (options.returnEnvelope)
52
+ return response;
43
53
  // API returns { success, result, message } format
44
54
  if ('result' in response) {
45
- return response.result;
55
+ return withEnvelopeVersion(response.result, response.version, options.version);
46
56
  }
47
57
  return response;
48
58
  }
49
59
  return response;
50
60
  }
51
61
  catch (error) {
52
- // Enhance error message with API details
53
- const errorMessage = error.response?.body?.message || error.message || 'Unknown error';
54
- throw new Error(`Posty5 API Error: ${errorMessage}`);
62
+ throw toPosty5NodeApiError(this, error);
63
+ }
64
+ }
65
+ /**
66
+ * On a versioned write, the envelope's `version` becomes the result's `__v`
67
+ * (a DELETE answers without one, so its result is returned as is).
68
+ */
69
+ function withEnvelopeVersion(result, envelopeVersion, sentVersion) {
70
+ if (typeof sentVersion !== 'number' || typeof envelopeVersion !== 'number')
71
+ return result;
72
+ if (!result || typeof result !== 'object' || Array.isArray(result))
73
+ return result;
74
+ return { ...result, __v: envelopeVersion };
75
+ }
76
+ /**
77
+ * The `NodeApiError` `makeApiRequest` throws. Its message stays
78
+ * `Posty5 API Error: <message>` (except a version conflict, which says how to
79
+ * fix it); `httpCode`, `apiMessage`, the API's `code` and, on a
80
+ * `VERSION_CONFLICT`, `currentVersion` ride along. A context without
81
+ * `getNode` (never in n8n) gets the plain error.
82
+ */
83
+ function toPosty5NodeApiError(context, error) {
84
+ const plain = toPosty5ApiError(error);
85
+ if (typeof context?.getNode !== 'function')
86
+ return plain;
87
+ const message = plain.code === constants_1.VERSIONED_WRITES.CONFLICT_CODE
88
+ ? constants_1.VERSIONED_WRITES.CONFLICT_MESSAGE(plain.currentVersion)
89
+ : plain.message;
90
+ const apiError = new n8n_workflow_1.NodeApiError(context.getNode(), { message, httpCode: plain.httpCode ?? null, code: plain.code ?? null }, { message, ...(plain.httpCode ? { httpCode: plain.httpCode } : {}), description: plain.apiMessage });
91
+ if (plain.httpCode)
92
+ apiError.httpCode = plain.httpCode;
93
+ if (plain.apiMessage)
94
+ apiError.apiMessage = plain.apiMessage;
95
+ if (plain.code)
96
+ apiError.code = plain.code;
97
+ if (plain.currentVersion !== undefined)
98
+ apiError.currentVersion = plain.currentVersion;
99
+ return apiError;
100
+ }
101
+ /**
102
+ * The error `makeApiRequest` throws for a failed request. The API's message is
103
+ * read from the answer: `response.data` is where n8n's `httpRequest` (axios)
104
+ * puts the parsed body, `response.body` is the older request-library shape.
105
+ * The HTTP status is kept as `httpCode` so a caller can map one status (the
106
+ * analytics plan-gate 403) to a `NodeApiError` without parsing the message.
107
+ */
108
+ function toPosty5ApiError(error) {
109
+ const apiMessage = error?.response?.data?.message || error?.response?.body?.message || undefined;
110
+ const errorMessage = apiMessage || error?.message || 'Unknown error';
111
+ const apiError = new Error(`Posty5 API Error: ${errorMessage}`);
112
+ const status = error?.response?.status ?? error?.response?.statusCode ?? error?.statusCode ?? error?.httpCode;
113
+ if (status !== undefined && status !== null)
114
+ apiError.httpCode = String(status);
115
+ if (apiMessage)
116
+ apiError.apiMessage = apiMessage;
117
+ const body = error?.response?.data ?? error?.response?.body;
118
+ if (body && typeof body === 'object') {
119
+ if (typeof body.code === 'string')
120
+ apiError.code = body.code;
121
+ const currentVersion = body.result?.currentVersion ?? body.currentVersion;
122
+ if (typeof currentVersion === 'number')
123
+ apiError.currentVersion = currentVersion;
55
124
  }
125
+ return apiError;
56
126
  }
57
127
  /**
58
128
  * Make a paginated list request
@@ -1 +1 @@
1
- {"version":3,"file":"api.helpers.js","sourceRoot":"","sources":["../../utils/api.helpers.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAmBH,wCAgDC;AAWD,oDAeC;AAQD,gCAsBC;AAxHD,2CAAkD;AASlD;;;;;;GAMG;AACI,KAAK,UAAU,cAAc,CAEnC,MAAc,EACd,OAA2B;IAE3B,MAAM,OAAO,GAAG,+BAAmB,CAAC;IAEpC,MAAM,cAAc,GAAwB;QAC3C,MAAM,EAAE,OA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