n8n-nodes-servicem8-jobcreation 1.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.
- package/README.md +517 -0
- package/dist/credentials/ServiceM8Api.credentials.d.ts +9 -0
- package/dist/credentials/ServiceM8Api.credentials.js +38 -0
- package/dist/credentials/ServiceM8Api.credentials.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/ServiceM8JobCreation.node.d.ts +18 -0
- package/dist/nodes/ServiceM8JobCreation/ServiceM8JobCreation.node.js +39 -0
- package/dist/nodes/ServiceM8JobCreation/ServiceM8JobCreation.node.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/execute.d.ts +6 -0
- package/dist/nodes/ServiceM8JobCreation/execute.js +47 -0
- package/dist/nodes/ServiceM8JobCreation/execute.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/addressUtils.d.ts +56 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/addressUtils.js +124 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/addressUtils.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/api.d.ts +180 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/api.js +418 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/api.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/clientMatcher.d.ts +67 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/clientMatcher.js +216 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/clientMatcher.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/phoneUtils.d.ts +35 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/phoneUtils.js +122 -0
- package/dist/nodes/ServiceM8JobCreation/helpers/phoneUtils.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/methods/index.d.ts +13 -0
- package/dist/nodes/ServiceM8JobCreation/methods/index.js +17 -0
- package/dist/nodes/ServiceM8JobCreation/methods/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/methods/loadOptions.d.ts +9 -0
- package/dist/nodes/ServiceM8JobCreation/methods/loadOptions.js +61 -0
- package/dist/nodes/ServiceM8JobCreation/methods/loadOptions.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/categoryAssign.d.ts +22 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/categoryAssign.js +61 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/categoryAssign.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/clientCreate.d.ts +36 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/clientCreate.js +66 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/clientCreate.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/clientLookup.d.ts +28 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/clientLookup.js +46 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/clientLookup.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/contactLookup.d.ts +18 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/contactLookup.js +48 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/contactLookup.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/index.d.ts +12 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/index.js +40 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/inputProcessor.d.ts +63 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/inputProcessor.js +176 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/inputProcessor.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/jobCreate.d.ts +43 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/jobCreate.js +82 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/jobCreate.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/notifications.d.ts +38 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/notifications.js +123 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/notifications.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/orchestrator.d.ts +12 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/orchestrator.js +192 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/orchestrator.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/queueAssign.d.ts +22 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/queueAssign.js +61 -0
- package/dist/nodes/ServiceM8JobCreation/operations/create/queueAssign.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/index.d.ts +8 -0
- package/dist/nodes/ServiceM8JobCreation/operations/index.js +35 -0
- package/dist/nodes/ServiceM8JobCreation/operations/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/attachmentsUpload.d.ts +41 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/attachmentsUpload.js +243 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/attachmentsUpload.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/badgesAssign.d.ts +21 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/badgesAssign.js +65 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/badgesAssign.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/index.d.ts +7 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/index.js +15 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/notesCreate.d.ts +42 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/notesCreate.js +103 -0
- package/dist/nodes/ServiceM8JobCreation/operations/shared/notesCreate.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/update/index.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/operations/update/index.js +9 -0
- package/dist/nodes/ServiceM8JobCreation/operations/update/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/operations/update/jobUpdate.d.ts +10 -0
- package/dist/nodes/ServiceM8JobCreation/operations/update/jobUpdate.js +239 -0
- package/dist/nodes/ServiceM8JobCreation/operations/update/jobUpdate.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/address.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/address.js +145 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/address.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/business.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/business.js +22 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/business.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/contact.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/contact.js +85 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/contact.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/index.d.ts +10 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/index.js +30 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/job.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/job.js +43 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/job.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/additionalOptions.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/additionalOptions.js +49 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/additionalOptions.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/attachments.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/attachments.js +151 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/attachments.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/badges.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/badges.js +65 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/badges.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/category.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/category.js +65 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/category.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/index.d.ts +12 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/index.js +38 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/notes.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/notes.js +49 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/notes.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/notifications.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/notifications.js +197 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/notifications.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/queue.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/queue.js +65 -0
- package/dist/nodes/ServiceM8JobCreation/properties/create/options/queue.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/index.d.ts +9 -0
- package/dist/nodes/ServiceM8JobCreation/properties/index.js +23 -0
- package/dist/nodes/ServiceM8JobCreation/properties/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/operation.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/operation.js +28 -0
- package/dist/nodes/ServiceM8JobCreation/properties/operation.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/fields.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/fields.js +74 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/fields.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/index.d.ts +8 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/index.js +22 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/jobSelection.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/jobSelection.js +63 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/jobSelection.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/options.d.ts +5 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/options.js +142 -0
- package/dist/nodes/ServiceM8JobCreation/properties/update/options.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/servicem8.svg +75 -0
- package/dist/nodes/ServiceM8JobCreation/types/api.d.ts +59 -0
- package/dist/nodes/ServiceM8JobCreation/types/api.js +34 -0
- package/dist/nodes/ServiceM8JobCreation/types/api.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/types/index.d.ts +7 -0
- package/dist/nodes/ServiceM8JobCreation/types/index.js +21 -0
- package/dist/nodes/ServiceM8JobCreation/types/index.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/types/input.d.ts +119 -0
- package/dist/nodes/ServiceM8JobCreation/types/input.js +6 -0
- package/dist/nodes/ServiceM8JobCreation/types/input.js.map +1 -0
- package/dist/nodes/ServiceM8JobCreation/types/result.d.ts +79 -0
- package/dist/nodes/ServiceM8JobCreation/types/result.js +96 -0
- package/dist/nodes/ServiceM8JobCreation/types/result.js.map +1 -0
- package/package.json +66 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Execute Method
|
|
4
|
+
* Main execution logic for the ServiceM8 Smart Job Creation node
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.execute = void 0;
|
|
8
|
+
const operations_1 = require("./operations");
|
|
9
|
+
const types_1 = require("./types");
|
|
10
|
+
async function execute() {
|
|
11
|
+
const items = this.getInputData();
|
|
12
|
+
const returnData = [];
|
|
13
|
+
for (let i = 0; i < items.length; i++) {
|
|
14
|
+
try {
|
|
15
|
+
const operation = this.getNodeParameter('operation', i);
|
|
16
|
+
let result;
|
|
17
|
+
if (operation === 'update') {
|
|
18
|
+
result = (await (0, operations_1.executeJobUpdate)(this, i));
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
result = (await (0, operations_1.executeJobCreation)(this, i));
|
|
22
|
+
}
|
|
23
|
+
returnData.push({
|
|
24
|
+
json: result,
|
|
25
|
+
pairedItem: i,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
if (this.continueOnFail()) {
|
|
30
|
+
const operation = this.getNodeParameter('operation', i);
|
|
31
|
+
const errorResult = operation === 'update'
|
|
32
|
+
? { ...(0, types_1.createEmptyUpdateResult)(), error: error.message }
|
|
33
|
+
: { ...(0, types_1.createEmptyExecutionResult)(), error: error.message };
|
|
34
|
+
returnData.push({
|
|
35
|
+
json: errorResult,
|
|
36
|
+
pairedItem: i,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return [returnData];
|
|
45
|
+
}
|
|
46
|
+
exports.execute = execute;
|
|
47
|
+
//# sourceMappingURL=execute.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute.js","sourceRoot":"","sources":["../../../nodes/ServiceM8JobCreation/execute.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,6CAAoE;AACpE,mCAA8E;AAEvE,KAAK,UAAU,OAAO;IAG5B,MAAM,KAAK,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;IAClC,MAAM,U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Address Building and Matching Utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { AddressParts, AddressMatchResult } from '../types/index';
|
|
5
|
+
/**
|
|
6
|
+
* Join non-empty strings with a separator
|
|
7
|
+
*/
|
|
8
|
+
export declare function joinNonEmpty(parts: (string | undefined | null)[], separator?: string): string;
|
|
9
|
+
/**
|
|
10
|
+
* Build a concatenated address string from parts
|
|
11
|
+
*/
|
|
12
|
+
export declare function buildAddressString(parts: AddressParts): string;
|
|
13
|
+
/**
|
|
14
|
+
* Normalize a string for matching (lowercase, remove special chars)
|
|
15
|
+
*/
|
|
16
|
+
export declare function normalizeForMatching(str: string | undefined | null): string;
|
|
17
|
+
/**
|
|
18
|
+
* Light normalization (lowercase, trim, but keep spaces)
|
|
19
|
+
*/
|
|
20
|
+
export declare function lightNormalize(str: string | undefined | null): string;
|
|
21
|
+
/**
|
|
22
|
+
* Compare two addresses and return match quality
|
|
23
|
+
* - 'exact': street + (postcode OR city) match
|
|
24
|
+
* - 'near': postcode matches OR street contains/starts with
|
|
25
|
+
* - 'none': no meaningful match
|
|
26
|
+
*/
|
|
27
|
+
export declare function matchAddresses(input: AddressParts, existing: {
|
|
28
|
+
address_street?: string;
|
|
29
|
+
address_city?: string;
|
|
30
|
+
address_postcode?: string;
|
|
31
|
+
}): AddressMatchResult;
|
|
32
|
+
/**
|
|
33
|
+
* Parse address parts from a node's fixedCollection input
|
|
34
|
+
*/
|
|
35
|
+
export declare function parseAddressFromInput(addressData: {
|
|
36
|
+
address?: Array<{
|
|
37
|
+
street?: string;
|
|
38
|
+
city?: string;
|
|
39
|
+
state?: string;
|
|
40
|
+
postcode?: string;
|
|
41
|
+
country?: string;
|
|
42
|
+
}>;
|
|
43
|
+
} | undefined): AddressParts;
|
|
44
|
+
/**
|
|
45
|
+
* Check if an address has any meaningful content
|
|
46
|
+
*/
|
|
47
|
+
export declare function hasAddressContent(parts: AddressParts): boolean;
|
|
48
|
+
/**
|
|
49
|
+
* Australian states for validation
|
|
50
|
+
*/
|
|
51
|
+
export declare const AUSTRALIAN_STATES: readonly ["NSW", "VIC", "QLD", "WA", "SA", "TAS", "ACT", "NT"];
|
|
52
|
+
export type AustralianState = (typeof AUSTRALIAN_STATES)[number];
|
|
53
|
+
/**
|
|
54
|
+
* Validate an Australian postcode format
|
|
55
|
+
*/
|
|
56
|
+
export declare function isValidAustralianPostcode(postcode: string | undefined | null): boolean;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Address Building and Matching Utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isValidAustralianPostcode = exports.AUSTRALIAN_STATES = exports.hasAddressContent = exports.parseAddressFromInput = exports.matchAddresses = exports.lightNormalize = exports.normalizeForMatching = exports.buildAddressString = exports.joinNonEmpty = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Join non-empty strings with a separator
|
|
9
|
+
*/
|
|
10
|
+
function joinNonEmpty(parts, separator = ', ') {
|
|
11
|
+
return parts
|
|
12
|
+
.filter((p) => p != null && String(p).trim() !== '')
|
|
13
|
+
.map((p) => String(p).trim())
|
|
14
|
+
.join(separator);
|
|
15
|
+
}
|
|
16
|
+
exports.joinNonEmpty = joinNonEmpty;
|
|
17
|
+
/**
|
|
18
|
+
* Build a concatenated address string from parts
|
|
19
|
+
*/
|
|
20
|
+
function buildAddressString(parts) {
|
|
21
|
+
return joinNonEmpty([
|
|
22
|
+
parts.street,
|
|
23
|
+
parts.city,
|
|
24
|
+
parts.state,
|
|
25
|
+
parts.postcode,
|
|
26
|
+
parts.country,
|
|
27
|
+
]);
|
|
28
|
+
}
|
|
29
|
+
exports.buildAddressString = buildAddressString;
|
|
30
|
+
/**
|
|
31
|
+
* Normalize a string for matching (lowercase, remove special chars)
|
|
32
|
+
*/
|
|
33
|
+
function normalizeForMatching(str) {
|
|
34
|
+
return (str || '').toLowerCase().trim().replace(/[^a-z0-9]/g, '');
|
|
35
|
+
}
|
|
36
|
+
exports.normalizeForMatching = normalizeForMatching;
|
|
37
|
+
/**
|
|
38
|
+
* Light normalization (lowercase, trim, but keep spaces)
|
|
39
|
+
*/
|
|
40
|
+
function lightNormalize(str) {
|
|
41
|
+
return (str || '').toLowerCase().trim();
|
|
42
|
+
}
|
|
43
|
+
exports.lightNormalize = lightNormalize;
|
|
44
|
+
/**
|
|
45
|
+
* Compare two addresses and return match quality
|
|
46
|
+
* - 'exact': street + (postcode OR city) match
|
|
47
|
+
* - 'near': postcode matches OR street contains/starts with
|
|
48
|
+
* - 'none': no meaningful match
|
|
49
|
+
*/
|
|
50
|
+
function matchAddresses(input, existing) {
|
|
51
|
+
const inputStreet = normalizeForMatching(input.street);
|
|
52
|
+
const inputPostcode = normalizeForMatching(input.postcode);
|
|
53
|
+
const inputCity = normalizeForMatching(input.city);
|
|
54
|
+
const existingStreet = normalizeForMatching(existing.address_street);
|
|
55
|
+
const existingPostcode = normalizeForMatching(existing.address_postcode);
|
|
56
|
+
const existingCity = normalizeForMatching(existing.address_city);
|
|
57
|
+
// Exact: street matches AND (postcode OR city matches)
|
|
58
|
+
if (inputStreet && existingStreet && inputStreet === existingStreet) {
|
|
59
|
+
if ((inputPostcode && existingPostcode && inputPostcode === existingPostcode) ||
|
|
60
|
+
(inputCity && existingCity && inputCity === existingCity)) {
|
|
61
|
+
return 'exact';
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
// Near-exact: postcode matches
|
|
65
|
+
if (inputPostcode && existingPostcode && inputPostcode === existingPostcode) {
|
|
66
|
+
return 'near';
|
|
67
|
+
}
|
|
68
|
+
// Near-exact: street contains or starts with
|
|
69
|
+
if (inputStreet &&
|
|
70
|
+
existingStreet &&
|
|
71
|
+
(existingStreet.includes(inputStreet) || inputStreet.includes(existingStreet))) {
|
|
72
|
+
return 'near';
|
|
73
|
+
}
|
|
74
|
+
return 'none';
|
|
75
|
+
}
|
|
76
|
+
exports.matchAddresses = matchAddresses;
|
|
77
|
+
/**
|
|
78
|
+
* Parse address parts from a node's fixedCollection input
|
|
79
|
+
*/
|
|
80
|
+
function parseAddressFromInput(addressData) {
|
|
81
|
+
var _a;
|
|
82
|
+
const addr = (_a = addressData === null || addressData === void 0 ? void 0 : addressData.address) === null || _a === void 0 ? void 0 : _a[0];
|
|
83
|
+
return {
|
|
84
|
+
street: (addr === null || addr === void 0 ? void 0 : addr.street) || '',
|
|
85
|
+
city: (addr === null || addr === void 0 ? void 0 : addr.city) || '',
|
|
86
|
+
state: (addr === null || addr === void 0 ? void 0 : addr.state) || '',
|
|
87
|
+
postcode: (addr === null || addr === void 0 ? void 0 : addr.postcode) || '',
|
|
88
|
+
country: (addr === null || addr === void 0 ? void 0 : addr.country) || 'Australia',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
exports.parseAddressFromInput = parseAddressFromInput;
|
|
92
|
+
/**
|
|
93
|
+
* Check if an address has any meaningful content
|
|
94
|
+
*/
|
|
95
|
+
function hasAddressContent(parts) {
|
|
96
|
+
return !!(parts.street ||
|
|
97
|
+
parts.city ||
|
|
98
|
+
parts.state ||
|
|
99
|
+
parts.postcode);
|
|
100
|
+
}
|
|
101
|
+
exports.hasAddressContent = hasAddressContent;
|
|
102
|
+
/**
|
|
103
|
+
* Australian states for validation
|
|
104
|
+
*/
|
|
105
|
+
exports.AUSTRALIAN_STATES = [
|
|
106
|
+
'NSW',
|
|
107
|
+
'VIC',
|
|
108
|
+
'QLD',
|
|
109
|
+
'WA',
|
|
110
|
+
'SA',
|
|
111
|
+
'TAS',
|
|
112
|
+
'ACT',
|
|
113
|
+
'NT',
|
|
114
|
+
];
|
|
115
|
+
/**
|
|
116
|
+
* Validate an Australian postcode format
|
|
117
|
+
*/
|
|
118
|
+
function isValidAustralianPostcode(postcode) {
|
|
119
|
+
if (!postcode)
|
|
120
|
+
return false;
|
|
121
|
+
return /^\d{4}$/.test(postcode.trim());
|
|
122
|
+
}
|
|
123
|
+
exports.isValidAustralianPostcode = isValidAustralianPostcode;
|
|
124
|
+
//# sourceMappingURL=addressUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addressUtils.js","sourceRoot":"","sources":["../../../../nodes/ServiceM8JobCreation/helpers/addressUtils.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAIH;;GAEG;AACH,SAAgB,YAAY,CAAC,KAAoC,EAAE,SAAS,GAAG,IAAI;IAClF,OAAO,KAAK;SACV,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC;SACnD,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;SAC5B,IAAI,CAAC,SAAS,CAAC,CAAC;AACnB,CAAC;AALD,oCAKC;AAED;;GAEG;AACH,SAAgB,kBAAkB,CAAC,KAAmB;IACrD,OAAO,YAAY,CAAC;QACnB,KAAK,CAAC,MAAM;QACZ,KAAK,CAAC,IAAI;QACV,KAAK,CAAC,KAAK;QACX,KAAK,CAAC,QAAQ;QACd,KAAK,CAAC,OAAO;KACb,CAAC,CAAC;AACJ,CAAC;AARD,gDAQC;AAED;;GAEG;AACH,SAAgB,oBAAoB,CAAC,GAA8B;IAClE,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;AACnE,CAAC;AAFD,oDAEC;AAED;;GAEG;AACH,SAAgB,cAAc,CAAC,GAA8B;IAC5D,OAAO,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,cAAc,CAC7B,KAAmB,EACnB,QAIC;IAED,MAAM,WAAW,GA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EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,IAAI,KAAI,EAAE;QACtB,KAAK,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,KAAK,KAAI,EAAE;QACxB,QAAQ,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,KAAI,EAAE;QAC9B,OAAO,EAAE,CAAA,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,OAAO,KAAI,WAAW;KACrC,CAAC;AACH,CAAC;AAXD,sDAWC;AAED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,KAAmB;IACpD,OAAO,CAAC,CAAC,CACR,KAAK,CAAC,MAAM;QACZ,KAAK,CAAC,IAAI;QACV,KAAK,CAAC,KAAK;QACX,KAAK,CAAC,QAAQ,CACd,CAAC;AACH,CAAC;AAPD,8CAOC;AAED;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAChC,KAAK;IACL,KAAK;IACL,KAAK;IACL,IAAI;IACJ,IAAI;IACJ,KAAK;IACL,KAAK;IACL,IAAI;CACK,CAAC;AAIX;;GAEG;AACH,SAAgB,yBAAyB,CAAC,QAAmC;IAC5E,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,OAAO,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;AACxC,CAAC;AAHD,8DAGC"}
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ServiceM8 API Helper Functions
|
|
3
|
+
*/
|
|
4
|
+
/// <reference types="node" />
|
|
5
|
+
/// <reference types="node" />
|
|
6
|
+
import type { IExecuteFunctions, ILoadOptionsFunctions, IHttpRequestMethods } from 'n8n-workflow';
|
|
7
|
+
export interface ServiceM8RequestOptions {
|
|
8
|
+
method?: IHttpRequestMethods;
|
|
9
|
+
endpoint: string;
|
|
10
|
+
body?: Record<string, unknown>;
|
|
11
|
+
query?: Record<string, string>;
|
|
12
|
+
returnFullResponse?: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Make an authenticated request to the ServiceM8 API
|
|
16
|
+
*/
|
|
17
|
+
export declare function serviceM8Request(context: IExecuteFunctions | ILoadOptionsFunctions, options: ServiceM8RequestOptions): Promise<unknown>;
|
|
18
|
+
/**
|
|
19
|
+
* Extract UUID from response headers (for POST requests that return x-record-uuid)
|
|
20
|
+
*/
|
|
21
|
+
export declare function extractUuidFromResponse(response: unknown): string | null;
|
|
22
|
+
/**
|
|
23
|
+
* Build OData $filter query parameter
|
|
24
|
+
*/
|
|
25
|
+
export interface FilterCondition {
|
|
26
|
+
field: string;
|
|
27
|
+
operator: 'eq' | 'ne' | 'gt' | 'lt' | 'ge' | 'le';
|
|
28
|
+
value: string | number;
|
|
29
|
+
}
|
|
30
|
+
export declare function buildODataFilter(conditions: FilterCondition[]): string;
|
|
31
|
+
/**
|
|
32
|
+
* Escape single quotes for OData filter values
|
|
33
|
+
*/
|
|
34
|
+
export declare function escapeOData(value: string): string;
|
|
35
|
+
/**
|
|
36
|
+
* Parse API response to ensure it's always an array
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseArrayResponse<T>(response: unknown): T[];
|
|
39
|
+
/**
|
|
40
|
+
* Create a company (client) in ServiceM8
|
|
41
|
+
*/
|
|
42
|
+
export declare function createClient(context: IExecuteFunctions, data: {
|
|
43
|
+
name: string;
|
|
44
|
+
is_individual: number;
|
|
45
|
+
address?: string;
|
|
46
|
+
address_street?: string;
|
|
47
|
+
address_city?: string;
|
|
48
|
+
address_state?: string;
|
|
49
|
+
address_postcode?: string;
|
|
50
|
+
address_country?: string;
|
|
51
|
+
}): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
* Create a company contact in ServiceM8
|
|
54
|
+
*/
|
|
55
|
+
export declare function createCompanyContact(context: IExecuteFunctions, data: {
|
|
56
|
+
company_uuid: string;
|
|
57
|
+
first: string;
|
|
58
|
+
last: string;
|
|
59
|
+
email?: string;
|
|
60
|
+
phone?: string;
|
|
61
|
+
mobile?: string;
|
|
62
|
+
type?: string;
|
|
63
|
+
}): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Create a job in ServiceM8
|
|
66
|
+
*/
|
|
67
|
+
export declare function createJob(context: IExecuteFunctions, data: {
|
|
68
|
+
company_uuid: string;
|
|
69
|
+
status: string;
|
|
70
|
+
job_address?: string;
|
|
71
|
+
billing_address?: string;
|
|
72
|
+
job_description?: string;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
uuid: string;
|
|
75
|
+
jobNumber?: string;
|
|
76
|
+
}>;
|
|
77
|
+
/**
|
|
78
|
+
* Create a job contact in ServiceM8
|
|
79
|
+
*/
|
|
80
|
+
export declare function createJobContact(context: IExecuteFunctions, data: {
|
|
81
|
+
job_uuid: string;
|
|
82
|
+
first: string;
|
|
83
|
+
last: string;
|
|
84
|
+
email?: string;
|
|
85
|
+
phone?: string;
|
|
86
|
+
mobile?: string;
|
|
87
|
+
is_primary_contact?: boolean;
|
|
88
|
+
}): Promise<string>;
|
|
89
|
+
/**
|
|
90
|
+
* Update a job (for category assignment)
|
|
91
|
+
*/
|
|
92
|
+
export declare function updateJob(context: IExecuteFunctions, jobUuid: string, data: Record<string, unknown>): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Assign badges to a job by updating the job's badges field
|
|
95
|
+
* The badges field is a JSON array string of badge UUIDs
|
|
96
|
+
*/
|
|
97
|
+
export declare function assignBadgesToJob(context: IExecuteFunctions, jobUuid: string, badgeUuids: string[]): Promise<void>;
|
|
98
|
+
/**
|
|
99
|
+
* Assign a job to a queue by updating the job's queue_uuid field
|
|
100
|
+
*/
|
|
101
|
+
export declare function assignJobToQueue(context: IExecuteFunctions, jobUuid: string, queueUuid: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Send SMS notification via ServiceM8
|
|
104
|
+
*/
|
|
105
|
+
export declare function sendSms(context: IExecuteFunctions, to: string, message: string, jobUuid?: string): Promise<void>;
|
|
106
|
+
export interface EmailAttachment {
|
|
107
|
+
uuid: string;
|
|
108
|
+
fileName: string;
|
|
109
|
+
}
|
|
110
|
+
export interface SendEmailOptions {
|
|
111
|
+
to: string;
|
|
112
|
+
subject: string;
|
|
113
|
+
htmlBody?: string;
|
|
114
|
+
textBody?: string;
|
|
115
|
+
jobUuid?: string;
|
|
116
|
+
attachmentUuids?: string[];
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Send email notification via ServiceM8
|
|
120
|
+
* Supports both HTML and plain text format, plus attachments
|
|
121
|
+
*/
|
|
122
|
+
export declare function sendEmail(context: IExecuteFunctions, options: SendEmailOptions): Promise<void>;
|
|
123
|
+
/**
|
|
124
|
+
* Legacy sendEmail function for backward compatibility
|
|
125
|
+
* @deprecated Use sendEmail with options object instead
|
|
126
|
+
*/
|
|
127
|
+
export declare function sendEmailLegacy(context: IExecuteFunctions, to: string, subject: string, htmlBody: string, jobUuid?: string): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Upload binary data as a job attachment and return the UUID
|
|
130
|
+
* This can be used to attach files to emails
|
|
131
|
+
*/
|
|
132
|
+
export declare function uploadBinaryAsAttachment(context: IExecuteFunctions, itemIndex: number, jobUuid: string, binaryPropertyName: string): Promise<EmailAttachment | null>;
|
|
133
|
+
/**
|
|
134
|
+
* Delete a job contact
|
|
135
|
+
*/
|
|
136
|
+
export declare function deleteJobContact(context: IExecuteFunctions, contactUuid: string): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Get job details
|
|
139
|
+
*/
|
|
140
|
+
export declare function getJob(context: IExecuteFunctions, jobUuid: string): Promise<Record<string, unknown>>;
|
|
141
|
+
/**
|
|
142
|
+
* Create a job note
|
|
143
|
+
* Uses /api_1.0/note.json with related_object and related_object_uuid
|
|
144
|
+
*/
|
|
145
|
+
export declare function createJobNote(context: IExecuteFunctions, jobUuid: string, note: string): Promise<string>;
|
|
146
|
+
/**
|
|
147
|
+
* Find badge UUID by name (case-insensitive)
|
|
148
|
+
*/
|
|
149
|
+
export declare function findBadgeByName(badges: Array<{
|
|
150
|
+
uuid: string;
|
|
151
|
+
name: string;
|
|
152
|
+
}>, searchName: string): {
|
|
153
|
+
uuid: string;
|
|
154
|
+
name: string;
|
|
155
|
+
} | null;
|
|
156
|
+
/**
|
|
157
|
+
* Find category UUID by name (case-insensitive)
|
|
158
|
+
*/
|
|
159
|
+
export declare function findCategoryByName(categories: Array<{
|
|
160
|
+
uuid: string;
|
|
161
|
+
name: string;
|
|
162
|
+
}>, searchName: string): {
|
|
163
|
+
uuid: string;
|
|
164
|
+
name: string;
|
|
165
|
+
} | null;
|
|
166
|
+
/**
|
|
167
|
+
* Find queue UUID by name (case-insensitive)
|
|
168
|
+
*/
|
|
169
|
+
export declare function findQueueByName(queues: Array<{
|
|
170
|
+
uuid: string;
|
|
171
|
+
name: string;
|
|
172
|
+
}>, searchName: string): {
|
|
173
|
+
uuid: string;
|
|
174
|
+
name: string;
|
|
175
|
+
} | null;
|
|
176
|
+
/**
|
|
177
|
+
* Upload binary content to an attachment
|
|
178
|
+
* Uses multipart/form-data format
|
|
179
|
+
*/
|
|
180
|
+
export declare function uploadAttachmentBinary(context: IExecuteFunctions, attachmentUuid: string, buffer: Buffer, fileName: string, mimeType: string): Promise<void>;
|