n8n-nodes-confirm8 0.26.0 → 0.28.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.
@@ -1,12 +1,49 @@
1
- import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription } from "n8n-workflow";
1
+ import { IExecuteFunctions, INodeExecutionData, INodeType, INodeTypeDescription, IDataObject, NodeOperationError } from "n8n-workflow";
2
2
  /**
3
- * CONFIRM8 OS TOOL (CHUMBED)
3
+ * =========================
4
+ * Confirm8 Utils (merged)
5
+ * =========================
6
+ */
7
+ export declare const VALID_RESOURCES: readonly ["user", "client", "item", "itemType", "task", "service", "product", "order", "modality", "ticket", "property"];
8
+ export declare const VALID_OPERATIONS: readonly ["getAll", "get", "create", "update", "activate", "deactivate"];
9
+ export type Confirm8Resource = (typeof VALID_RESOURCES)[number];
10
+ export type Confirm8Operation = (typeof VALID_OPERATIONS)[number];
11
+ export declare const RESOURCE_ENDPOINTS: Record<Confirm8Resource, {
12
+ endpoint: string;
13
+ relations: string[];
14
+ }>;
15
+ export declare function assertIsoDate(dateStr: string, label: string): void;
16
+ export declare function formatIsoDate(d: Date): string;
17
+ /**
18
+ * Week starts on Monday (pt-BR business default).
19
+ * Returns inclusive start/end in YYYY-MM-DD.
20
+ */
21
+ export declare function getThisWeekRange(now?: Date): {
22
+ start: string;
23
+ end: string;
24
+ };
25
+ /** Build query params for relations + filters in Confirm8 format. */
26
+ export declare function buildQueryParams(relations: string[], filters?: IDataObject): string;
27
+ export declare function confirm8Request(this: IExecuteFunctions, i: number, args: {
28
+ baseUrl: string;
29
+ bearerToken: string;
30
+ apiDomain: string;
31
+ apiKeyToken: string;
32
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
33
+ endpoint: string;
34
+ query?: string;
35
+ body?: IDataObject;
36
+ }): Promise<any>;
37
+ export declare function toNodeError(node: any, err: unknown, i: number): NodeOperationError;
38
+ /**
39
+ * =========================
40
+ * Confirm8 OS Tool (merged)
41
+ * =========================
42
+ *
43
+ * CHUMBED:
4
44
  * - resource is ALWAYS "order"
5
45
  * - operation is ALWAYS "getAll" OR "get" (derived only from presence of recordId)
6
46
  * - dates are ALWAYS ISO YYYY-MM-DD (validated / computed here)
7
- *
8
- * This is the recommended single-tool version to use inside an AI Agent.
9
- * The agent never sees 'resource' or 'operation' parameters, so it cannot fill them wrong.
10
47
  */
11
48
  export declare class Confirm8OSTool implements INodeType {
12
49
  description: INodeTypeDescription;
@@ -1,15 +1,171 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Confirm8OSTool = void 0;
4
- const confirm8_utils_1 = require("./confirm8.utils");
3
+ exports.Confirm8OSTool = exports.RESOURCE_ENDPOINTS = exports.VALID_OPERATIONS = exports.VALID_RESOURCES = void 0;
4
+ exports.assertIsoDate = assertIsoDate;
5
+ exports.formatIsoDate = formatIsoDate;
6
+ exports.getThisWeekRange = getThisWeekRange;
7
+ exports.buildQueryParams = buildQueryParams;
8
+ exports.confirm8Request = confirm8Request;
9
+ exports.toNodeError = toNodeError;
10
+ const n8n_workflow_1 = require("n8n-workflow");
5
11
  /**
6
- * CONFIRM8 OS TOOL (CHUMBED)
12
+ * =========================
13
+ * Confirm8 Utils (merged)
14
+ * =========================
15
+ */
16
+ exports.VALID_RESOURCES = [
17
+ "user",
18
+ "client",
19
+ "item",
20
+ "itemType",
21
+ "task",
22
+ "service",
23
+ "product",
24
+ "order",
25
+ "modality",
26
+ "ticket",
27
+ "property",
28
+ ];
29
+ exports.VALID_OPERATIONS = [
30
+ "getAll",
31
+ "get",
32
+ "create",
33
+ "update",
34
+ "activate",
35
+ "deactivate",
36
+ ];
37
+ exports.RESOURCE_ENDPOINTS = {
38
+ user: {
39
+ endpoint: "users",
40
+ relations: ["clients", "attachments", "permissions", "device", "employee"],
41
+ },
42
+ client: {
43
+ endpoint: "clients",
44
+ relations: [
45
+ "address",
46
+ "contacts",
47
+ "items",
48
+ "tickets",
49
+ "orders",
50
+ "properties",
51
+ "attachments",
52
+ ],
53
+ },
54
+ item: {
55
+ endpoint: "items",
56
+ relations: ["client", "itemType", "properties", "attachments"],
57
+ },
58
+ itemType: { endpoint: "item-types", relations: ["properties"] },
59
+ task: {
60
+ endpoint: "tasks",
61
+ relations: ["itemType", "modality", "services", "products"],
62
+ },
63
+ service: { endpoint: "services", relations: ["task"] },
64
+ product: { endpoint: "products", relations: [] },
65
+ // IMPORTANT: Confirm8 Work Orders endpoint is 'wos'
66
+ order: {
67
+ endpoint: "wos",
68
+ relations: [
69
+ "client",
70
+ "modalities",
71
+ "tasks",
72
+ "pivot_tasks",
73
+ "products",
74
+ "users",
75
+ "items",
76
+ "tickets",
77
+ "services",
78
+ "collects",
79
+ "attachments",
80
+ ],
81
+ },
82
+ modality: { endpoint: "modalities", relations: ["tasks"] },
83
+ ticket: {
84
+ endpoint: "tickets",
85
+ relations: ["client", "subject_category", "category", "user", "attachments"],
86
+ },
87
+ property: { endpoint: "properties", relations: ["client", "item", "itemType"] },
88
+ };
89
+ const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/;
90
+ function assertIsoDate(dateStr, label) {
91
+ if (!ISO_DATE.test(dateStr)) {
92
+ throw new Error(`${label} must be in YYYY-MM-DD format. Received: "${dateStr}"`);
93
+ }
94
+ }
95
+ function formatIsoDate(d) {
96
+ const y = d.getFullYear();
97
+ const m = String(d.getMonth() + 1).padStart(2, "0");
98
+ const day = String(d.getDate()).padStart(2, "0");
99
+ return `${y}-${m}-${day}`;
100
+ }
101
+ /**
102
+ * Week starts on Monday (pt-BR business default).
103
+ * Returns inclusive start/end in YYYY-MM-DD.
104
+ */
105
+ function getThisWeekRange(now = new Date()) {
106
+ const d = new Date(now);
107
+ d.setHours(0, 0, 0, 0);
108
+ // JS: Sunday=0 ... Saturday=6
109
+ const day = d.getDay();
110
+ const diffToMonday = day === 0 ? -6 : 1 - day; // if Sunday -> go back 6 days
111
+ const startDate = new Date(d);
112
+ startDate.setDate(d.getDate() + diffToMonday);
113
+ const endDate = new Date(startDate);
114
+ endDate.setDate(startDate.getDate() + 6);
115
+ return { start: formatIsoDate(startDate), end: formatIsoDate(endDate) };
116
+ }
117
+ /** Build query params for relations + filters in Confirm8 format. */
118
+ function buildQueryParams(relations, filters) {
119
+ const queryParams = [];
120
+ if (relations?.length) {
121
+ for (const rel of relations)
122
+ queryParams.push(`relations=${encodeURIComponent(rel)}`);
123
+ }
124
+ if (filters && Object.keys(filters).length) {
125
+ for (const field of Object.keys(filters)) {
126
+ const operators = filters[field];
127
+ for (const op of Object.keys(operators)) {
128
+ const value = operators[op];
129
+ queryParams.push(`filters[${encodeURIComponent(field)}][${encodeURIComponent(op)}]=${encodeURIComponent(String(value))}`);
130
+ }
131
+ }
132
+ }
133
+ return queryParams.length ? `?${queryParams.join("&")}` : "";
134
+ }
135
+ function confirm8Request(i, args) {
136
+ const { baseUrl, bearerToken, apiDomain, apiKeyToken, method, endpoint, query, body, } = args;
137
+ const uri = `${baseUrl}${endpoint}${query ?? ""}`;
138
+ const options = {
139
+ method,
140
+ uri,
141
+ headers: {
142
+ Authorization: `Bearer ${bearerToken}`,
143
+ "X-API-DOMAIN": apiDomain,
144
+ "X-APIKEY-TOKEN": apiKeyToken,
145
+ "Content-Type": "application/json",
146
+ },
147
+ json: true,
148
+ };
149
+ if (body && method !== "GET" && method !== "DELETE") {
150
+ options.body = body;
151
+ }
152
+ return this.helpers.request(options);
153
+ }
154
+ function toNodeError(node, err, i) {
155
+ if (err instanceof n8n_workflow_1.NodeOperationError)
156
+ return err;
157
+ const message = err instanceof Error ? err.message : String(err);
158
+ return new n8n_workflow_1.NodeOperationError(node, message, { itemIndex: i });
159
+ }
160
+ /**
161
+ * =========================
162
+ * Confirm8 OS Tool (merged)
163
+ * =========================
164
+ *
165
+ * CHUMBED:
7
166
  * - resource is ALWAYS "order"
8
167
  * - operation is ALWAYS "getAll" OR "get" (derived only from presence of recordId)
9
168
  * - dates are ALWAYS ISO YYYY-MM-DD (validated / computed here)
10
- *
11
- * This is the recommended single-tool version to use inside an AI Agent.
12
- * The agent never sees 'resource' or 'operation' parameters, so it cannot fill them wrong.
13
169
  */
14
170
  class Confirm8OSTool {
15
171
  constructor() {
@@ -145,15 +301,17 @@ class Confirm8OSTool {
145
301
  const recordId = this.getNodeParameter("recordId", i, "").trim();
146
302
  // CHUMBED RESOURCE
147
303
  const resource = "order";
148
- const config = confirm8_utils_1.RESOURCE_ENDPOINTS[resource];
304
+ const config = exports.RESOURCE_ENDPOINTS[resource];
149
305
  // Decide operation internally
150
306
  const operation = recordId ? "get" : "getAll";
151
307
  if (operation === "get") {
152
308
  const endpoint = `/v3/${config.endpoint}/${encodeURIComponent(recordId)}`;
153
309
  const query = config.relations?.length
154
- ? `?${config.relations.map((r) => `relations=${encodeURIComponent(r)}`).join("&")}`
310
+ ? `?${config.relations
311
+ .map((r) => `relations=${encodeURIComponent(r)}`)
312
+ .join("&")}`
155
313
  : "";
156
- const data = await confirm8_utils_1.confirm8Request.call(this, i, {
314
+ const data = await confirm8Request.call(this, i, {
157
315
  baseUrl,
158
316
  bearerToken,
159
317
  apiDomain,
@@ -184,11 +342,11 @@ class Confirm8OSTool {
184
342
  if (!start || !end) {
185
343
  throw new Error("When Date Range is Custom, startDate and endDate are required.");
186
344
  }
187
- (0, confirm8_utils_1.assertIsoDate)(start, "startDate");
188
- (0, confirm8_utils_1.assertIsoDate)(end, "endDate");
345
+ assertIsoDate(start, "startDate");
346
+ assertIsoDate(end, "endDate");
189
347
  }
190
348
  else {
191
- const r = (0, confirm8_utils_1.getThisWeekRange)(new Date());
349
+ const r = getThisWeekRange(new Date());
192
350
  start = r.start;
193
351
  end = r.end;
194
352
  }
@@ -196,10 +354,12 @@ class Confirm8OSTool {
196
354
  const filters = { [dateField]: { gte: start, lte: end } };
197
355
  const page = this.getNodeParameter("page", i);
198
356
  const perPage = this.getNodeParameter("perPage", i);
199
- const query = (0, confirm8_utils_1.buildQueryParams)(config.relations, filters);
357
+ const query = buildQueryParams(config.relations, filters);
200
358
  const pagination = `&page=${encodeURIComponent(String(page))}&per_page=${encodeURIComponent(String(perPage))}`;
201
- const finalQuery = query ? `${query}${pagination}` : `?page=${page}&per_page=${perPage}`;
202
- const data = await confirm8_utils_1.confirm8Request.call(this, i, {
359
+ const finalQuery = query
360
+ ? `${query}${pagination}`
361
+ : `?page=${page}&per_page=${perPage}`;
362
+ const data = await confirm8Request.call(this, i, {
203
363
  baseUrl,
204
364
  bearerToken,
205
365
  apiDomain,
@@ -228,7 +388,7 @@ class Confirm8OSTool {
228
388
  });
229
389
  }
230
390
  catch (err) {
231
- throw (0, confirm8_utils_1.toNodeError)(this.getNode(), err, i);
391
+ throw toNodeError(this.getNode(), err, i);
232
392
  }
233
393
  }
234
394
  return [returnData];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-confirm8",
3
- "version": "0.26.0",
3
+ "version": "0.28.0",
4
4
  "description": "Simple n8n node for Confirm8 API - no credentials needed",
5
5
  "license": "MIT",
6
6
  "author": "Bill Hebert",