node-autotask 0.68.0 → 0.68.1
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/CHANGELOG.md +6 -0
- package/dist/{chunk-HFWOHUVF.cjs → chunk-2D2KJOX2.cjs} +171 -171
- package/dist/{chunk-CG6OPTFG.cjs → chunk-KRQONGLD.cjs} +31 -31
- package/dist/{chunk-BF22HBNT.js → chunk-LOLWHPTJ.js} +2 -2
- package/dist/{chunk-OUVUQQXH.js → chunk-S6HEIGGM.js} +1 -1
- package/dist/{chunk-V2GE763R.cjs → chunk-XKIRTR37.cjs} +74 -51
- package/dist/{chunk-DPJLN5BB.js → chunk-YYHCZRUH.js} +74 -51
- package/dist/index.cjs +83 -83
- package/dist/index.js +4 -4
- package/dist/operations/index.cjs +49 -49
- package/dist/operations/index.js +1 -1
- package/dist/pool.cjs +11 -11
- package/dist/pool.js +3 -3
- package/dist/resources/index.cjs +26 -26
- package/dist/resources/index.js +2 -2
- package/docs/VENDOR-QUIRKS.md +15 -0
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk2D2KJOX2_cjs = require('./chunk-2D2KJOX2.cjs');
|
|
4
|
+
var chunkXKIRTR37_cjs = require('./chunk-XKIRTR37.cjs');
|
|
5
5
|
|
|
6
6
|
// src/client.ts
|
|
7
7
|
var AutotaskClient = class {
|
|
@@ -154,34 +154,34 @@ var AutotaskClient = class {
|
|
|
154
154
|
* anything is wired. Construction issues NO request.
|
|
155
155
|
*/
|
|
156
156
|
constructor(options) {
|
|
157
|
-
this.config =
|
|
158
|
-
this.http = new
|
|
157
|
+
this.config = chunkXKIRTR37_cjs.resolveConfig(options);
|
|
158
|
+
this.http = new chunkXKIRTR37_cjs.HttpClient(this.config);
|
|
159
159
|
this.http.client = this;
|
|
160
|
-
for (const entry of
|
|
161
|
-
this[entry.accessor] = new
|
|
160
|
+
for (const entry of chunkXKIRTR37_cjs.SIMPLE_RESOURCES) {
|
|
161
|
+
this[entry.accessor] = new chunkXKIRTR37_cjs.GenericResource(this.http, entry, this.config.pageSize);
|
|
162
162
|
}
|
|
163
|
-
this.companies = new
|
|
164
|
-
this.configurationItems = new
|
|
165
|
-
this.contacts = new
|
|
166
|
-
this.contracts = new
|
|
167
|
-
this.inventoryProducts = new
|
|
168
|
-
this.invoices = new
|
|
169
|
-
this.quotes = new
|
|
170
|
-
this.resourceTimeOffAdditional = new
|
|
171
|
-
this.resourceTimeOffBalances = new
|
|
172
|
-
this.resources = new
|
|
173
|
-
this.serviceCalls = new
|
|
174
|
-
this.ticketCharges = new
|
|
175
|
-
this.tickets = new
|
|
176
|
-
this.timeEntries = new
|
|
177
|
-
this.timeOffRequests = new
|
|
178
|
-
this.authenticateResource = new
|
|
179
|
-
this.entityInformation = new
|
|
180
|
-
this.modules = new
|
|
181
|
-
this.thresholdInformation = new
|
|
182
|
-
this.version = new
|
|
183
|
-
this.versionInformation = new
|
|
184
|
-
this.zoneInformation = new
|
|
163
|
+
this.companies = new chunkXKIRTR37_cjs.CompaniesResource(this.http, this.config.pageSize);
|
|
164
|
+
this.configurationItems = new chunk2D2KJOX2_cjs.ConfigurationItemsResource(this.http, this.config.pageSize);
|
|
165
|
+
this.contacts = new chunk2D2KJOX2_cjs.ContactsResource(this.http, this.config.pageSize);
|
|
166
|
+
this.contracts = new chunkXKIRTR37_cjs.ContractsResource(this.http, this.config.pageSize);
|
|
167
|
+
this.inventoryProducts = new chunk2D2KJOX2_cjs.InventoryProductsResource(this.http, this.config.pageSize);
|
|
168
|
+
this.invoices = new chunkXKIRTR37_cjs.InvoicesResource(this.http, this.config.pageSize);
|
|
169
|
+
this.quotes = new chunk2D2KJOX2_cjs.QuotesResource(this.http, this.config.pageSize);
|
|
170
|
+
this.resourceTimeOffAdditional = new chunk2D2KJOX2_cjs.ResourceTimeOffAdditionalResource(this.http, this.config.pageSize);
|
|
171
|
+
this.resourceTimeOffBalances = new chunk2D2KJOX2_cjs.ResourceTimeOffBalancesResource(this.http, this.config.pageSize);
|
|
172
|
+
this.resources = new chunk2D2KJOX2_cjs.ResourcesResource(this.http, this.config, this.config.pageSize);
|
|
173
|
+
this.serviceCalls = new chunk2D2KJOX2_cjs.ServiceCallsResource(this.http, this.config.pageSize);
|
|
174
|
+
this.ticketCharges = new chunk2D2KJOX2_cjs.TicketChargesResource(this.http, this.config.pageSize);
|
|
175
|
+
this.tickets = new chunk2D2KJOX2_cjs.TicketsResource(this.http, this.config.pageSize);
|
|
176
|
+
this.timeEntries = new chunkXKIRTR37_cjs.TimeEntriesResource(this.http, this.config.pageSize);
|
|
177
|
+
this.timeOffRequests = new chunk2D2KJOX2_cjs.TimeOffRequestsResource(this.http, this.config.pageSize);
|
|
178
|
+
this.authenticateResource = new chunk2D2KJOX2_cjs.AuthenticateResource(this.http);
|
|
179
|
+
this.entityInformation = new chunk2D2KJOX2_cjs.EntityInformationResource(this.http);
|
|
180
|
+
this.modules = new chunk2D2KJOX2_cjs.ModulesResource(this.http);
|
|
181
|
+
this.thresholdInformation = new chunk2D2KJOX2_cjs.ThresholdInformationResource(this.http);
|
|
182
|
+
this.version = new chunk2D2KJOX2_cjs.VersionResource(this.http);
|
|
183
|
+
this.versionInformation = new chunk2D2KJOX2_cjs.VersionInformationResource(this.http);
|
|
184
|
+
this.zoneInformation = new chunk2D2KJOX2_cjs.ZoneInformationResource(this.http);
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
187
|
* `GET /V1.0/Authenticate` → `AuthTokenResultModel` (as-is). The SDK does
|
|
@@ -215,12 +215,12 @@ var AutotaskClient = class {
|
|
|
215
215
|
* parameter on each: `await client.withSignal(signal, () => invoke(client, ...))`.
|
|
216
216
|
*/
|
|
217
217
|
withSignal(signal, fn) {
|
|
218
|
-
return
|
|
218
|
+
return chunkXKIRTR37_cjs.runWithSignal(signal, fn);
|
|
219
219
|
}
|
|
220
220
|
async batch(fn, items, opts = {}) {
|
|
221
221
|
const concurrency = opts.concurrency ?? this.config.maxConcurrent;
|
|
222
222
|
if (!Number.isInteger(concurrency) || concurrency <= 0) {
|
|
223
|
-
throw new
|
|
223
|
+
throw new chunkXKIRTR37_cjs.AutotaskConfigError("batch concurrency must be a positive integer");
|
|
224
224
|
}
|
|
225
225
|
const { signal, settle } = opts;
|
|
226
226
|
const results = new Array(items.length);
|
|
@@ -235,7 +235,7 @@ var AutotaskClient = class {
|
|
|
235
235
|
const i = next++;
|
|
236
236
|
try {
|
|
237
237
|
const item = items[i];
|
|
238
|
-
const value = await (signal === void 0 ? fn(item) :
|
|
238
|
+
const value = await (signal === void 0 ? fn(item) : chunkXKIRTR37_cjs.runWithSignal(signal, () => fn(item)));
|
|
239
239
|
results[i] = settle ? { status: "fulfilled", value } : value;
|
|
240
240
|
} catch (error) {
|
|
241
241
|
if (settle) results[i] = { status: "rejected", reason: error };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConfigurationItemsResource, ContactsResource, InventoryProductsResource, QuotesResource, ResourceTimeOffAdditionalResource, ResourceTimeOffBalancesResource, ResourcesResource, ServiceCallsResource, TicketChargesResource, TicketsResource, TimeOffRequestsResource, AuthenticateResource, EntityInformationResource, ModulesResource, ThresholdInformationResource, VersionResource, VersionInformationResource, ZoneInformationResource } from './chunk-
|
|
2
|
-
import { resolveConfig, HttpClient, SIMPLE_RESOURCES, GenericResource, CompaniesResource, ContractsResource, InvoicesResource, TimeEntriesResource, runWithSignal, AutotaskConfigError } from './chunk-
|
|
1
|
+
import { ConfigurationItemsResource, ContactsResource, InventoryProductsResource, QuotesResource, ResourceTimeOffAdditionalResource, ResourceTimeOffBalancesResource, ResourcesResource, ServiceCallsResource, TicketChargesResource, TicketsResource, TimeOffRequestsResource, AuthenticateResource, EntityInformationResource, ModulesResource, ThresholdInformationResource, VersionResource, VersionInformationResource, ZoneInformationResource } from './chunk-S6HEIGGM.js';
|
|
2
|
+
import { resolveConfig, HttpClient, SIMPLE_RESOURCES, GenericResource, CompaniesResource, ContractsResource, InvoicesResource, TimeEntriesResource, runWithSignal, AutotaskConfigError } from './chunk-YYHCZRUH.js';
|
|
3
3
|
|
|
4
4
|
// src/client.ts
|
|
5
5
|
var AutotaskClient = class {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GenericResource, parseIdentifier, AutotaskConfigError, StaleObjectError, buildDryRunResult, createNamePlan, resolveCompositeNames, addNameSibling, NotFoundError, unwrapItems, ConflictError, clientOf, compositePartLimit, invokeRead, compositePart, openTicketsOfPart, unwrapOperation, unwrapItem, ResolutionError, numericIds, IN_FILTER_CAP, runMove, resolveTicketStatusSemantics, openStatusFilter, isClosedStatus, vendorId, isAutotaskError, resolveLineOfBusinessChain, uiLinkFor, refuse, queryRows, mergePartialBody, AutotaskError, TICKET_LABEL_FIELDS, addLabelSibling, parseVendorErrors, RELATIONSHIP_MAP, cursorToPath } from './chunk-
|
|
1
|
+
import { GenericResource, parseIdentifier, AutotaskConfigError, StaleObjectError, buildDryRunResult, createNamePlan, resolveCompositeNames, addNameSibling, NotFoundError, unwrapItems, ConflictError, clientOf, compositePartLimit, invokeRead, compositePart, openTicketsOfPart, unwrapOperation, unwrapItem, ResolutionError, numericIds, IN_FILTER_CAP, runMove, resolveTicketStatusSemantics, openStatusFilter, isClosedStatus, vendorId, isAutotaskError, resolveLineOfBusinessChain, uiLinkFor, refuse, queryRows, mergePartialBody, AutotaskError, TICKET_LABEL_FIELDS, addLabelSibling, parseVendorErrors, RELATIONSHIP_MAP, cursorToPath } from './chunk-YYHCZRUH.js';
|
|
2
2
|
import { loadCapabilityRecords } from './chunk-JCMXQUIC.js';
|
|
3
3
|
|
|
4
4
|
// src/resources/special/configuration_items.ts
|
|
@@ -14955,17 +14955,14 @@ async function collectAll(fetchPage, opts = {}) {
|
|
|
14955
14955
|
return all;
|
|
14956
14956
|
}
|
|
14957
14957
|
|
|
14958
|
-
// src/search/
|
|
14959
|
-
|
|
14960
|
-
|
|
14961
|
-
|
|
14962
|
-
return
|
|
14963
|
-
}
|
|
14964
|
-
function companyTerms(value) {
|
|
14965
|
-
return normaliseCompanyName(value).split(" ").filter((t) => t && !LEGAL_SUFFIXES.has(t) && !STOPWORDS.has(t));
|
|
14958
|
+
// src/search/fuzzy-text.ts
|
|
14959
|
+
function normaliseText(value, options = {}) {
|
|
14960
|
+
let folded = value.normalize("NFKD").replace(new RegExp("\\p{M}+", "gu"), "").toLowerCase();
|
|
14961
|
+
if (options.ampersandAsAnd) folded = folded.replace(/&/g, " and ");
|
|
14962
|
+
return folded.replace(/[^\p{L}\p{N}]+/gu, " ").split(/\s+/).filter((term) => term && !options.excludeTerms?.has(term)).join(" ");
|
|
14966
14963
|
}
|
|
14967
|
-
function
|
|
14968
|
-
return
|
|
14964
|
+
function textTerms(value, normalise = normaliseText, excludeTerms) {
|
|
14965
|
+
return normalise(value).split(" ").filter((term) => term && !excludeTerms?.has(term));
|
|
14969
14966
|
}
|
|
14970
14967
|
function ngramsOf(token) {
|
|
14971
14968
|
if (token.length < 3) return [token];
|
|
@@ -15001,6 +14998,67 @@ function editDistanceAtMost(a, b, k) {
|
|
|
15001
14998
|
}
|
|
15002
14999
|
return previous[b.length];
|
|
15003
15000
|
}
|
|
15001
|
+
function textFragments(terms) {
|
|
15002
|
+
const pieces = /* @__PURE__ */ new Set();
|
|
15003
|
+
const prefixes = /* @__PURE__ */ new Set();
|
|
15004
|
+
const longest = [...terms].sort((a, b) => b.length - a.length || a.localeCompare(b)).slice(0, 2);
|
|
15005
|
+
for (const word of longest) {
|
|
15006
|
+
const count = Math.max(1, Math.min(editBudget(word) + 1, Math.floor(word.length / 4)));
|
|
15007
|
+
for (let i = 0; i < count; i++) pieces.add(word.slice(Math.floor(i * word.length / count), Math.floor((i + 1) * word.length / count)));
|
|
15008
|
+
if (word.length >= 4 && word.length <= 6) prefixes.add(word.slice(0, 3));
|
|
15009
|
+
}
|
|
15010
|
+
if (terms.length > 1) pieces.add(terms.join(""));
|
|
15011
|
+
return { pieces: [...pieces], prefixes: [...prefixes] };
|
|
15012
|
+
}
|
|
15013
|
+
function scoreTerms(terms, words) {
|
|
15014
|
+
const candidates = [...words, words.join("")];
|
|
15015
|
+
const matchedTerms = [];
|
|
15016
|
+
let distance = 0;
|
|
15017
|
+
for (const term of terms) {
|
|
15018
|
+
const budget = editBudget(term);
|
|
15019
|
+
const best = Math.min(budget + 1, ...candidates.map((word) => editDistanceAtMost(term, word, budget)));
|
|
15020
|
+
if (best <= budget) {
|
|
15021
|
+
matchedTerms.push(term);
|
|
15022
|
+
distance += best;
|
|
15023
|
+
}
|
|
15024
|
+
}
|
|
15025
|
+
if (terms.length > 1) {
|
|
15026
|
+
const compact = terms.join("");
|
|
15027
|
+
const budget = editBudget(compact);
|
|
15028
|
+
const best = Math.min(budget + 1, ...candidates.map((word) => editDistanceAtMost(compact, word, budget)));
|
|
15029
|
+
if (best <= budget && matchedTerms.length < terms.length) return { coverage: terms.length, distance: best, matchedTerms: [...terms] };
|
|
15030
|
+
}
|
|
15031
|
+
return matchedTerms.length === 0 ? void 0 : { coverage: matchedTerms.length, distance, matchedTerms };
|
|
15032
|
+
}
|
|
15033
|
+
function compareTermScores(a, b) {
|
|
15034
|
+
return b.coverage - a.coverage || a.distance - b.distance;
|
|
15035
|
+
}
|
|
15036
|
+
function vocabularyCandidates(vocabulary, terms) {
|
|
15037
|
+
const keys = /* @__PURE__ */ new Set();
|
|
15038
|
+
for (const term of terms) {
|
|
15039
|
+
const budget = editBudget(term);
|
|
15040
|
+
const words = [...vocabulary.keys()].filter((word) => Math.abs(word.length - term.length) <= budget).map((word) => ({ word, dice: diceCoefficient(term, word) })).sort((a, b) => b.dice - a.dice);
|
|
15041
|
+
for (const { word } of words) if (editDistanceAtMost(term, word, budget) <= budget) {
|
|
15042
|
+
for (const key of vocabulary.get(word)) keys.add(key);
|
|
15043
|
+
}
|
|
15044
|
+
}
|
|
15045
|
+
return keys;
|
|
15046
|
+
}
|
|
15047
|
+
|
|
15048
|
+
// src/search/company-names.ts
|
|
15049
|
+
var LEGAL_SUFFIXES = /* @__PURE__ */ new Set(["pty", "ltd", "limited", "inc", "llc", "co", "corp", "gmbh"]);
|
|
15050
|
+
var STOPWORDS = /* @__PURE__ */ new Set(["the", "and", "of"]);
|
|
15051
|
+
var NAME_EXCLUSIONS = /* @__PURE__ */ new Set(["the"]);
|
|
15052
|
+
var SCORE_EXCLUSIONS = /* @__PURE__ */ new Set([...LEGAL_SUFFIXES, ...STOPWORDS]);
|
|
15053
|
+
function normaliseCompanyName(value) {
|
|
15054
|
+
return normaliseText(value, { ampersandAsAnd: true, excludeTerms: NAME_EXCLUSIONS });
|
|
15055
|
+
}
|
|
15056
|
+
function companyTerms(value) {
|
|
15057
|
+
return textTerms(value, normaliseCompanyName, SCORE_EXCLUSIONS);
|
|
15058
|
+
}
|
|
15059
|
+
function companyDedupeName(value) {
|
|
15060
|
+
return textTerms(value, normaliseCompanyName, LEGAL_SUFFIXES).join(" ");
|
|
15061
|
+
}
|
|
15004
15062
|
|
|
15005
15063
|
// src/search/company-index.ts
|
|
15006
15064
|
var COMPANY_INDEX_WRITE_DEBOUNCE_MS = 1e3;
|
|
@@ -15074,18 +15132,9 @@ var CompanyNameIndex = class {
|
|
|
15074
15132
|
if (this.timer) clearTimeout(this.timer);
|
|
15075
15133
|
if (this.started) this.start(COMPANY_INDEX_WRITE_DEBOUNCE_MS);
|
|
15076
15134
|
}
|
|
15077
|
-
/**
|
|
15078
|
-
* A Dice floor would lose valid short-word swaps, so zero-overlap vocabulary
|
|
15079
|
-
* remains eligible when its length is within the edit budget. */
|
|
15135
|
+
/** The index owns company rows; the shared engine selects vocabulary keys. */
|
|
15080
15136
|
candidates(terms) {
|
|
15081
|
-
const ids2 =
|
|
15082
|
-
for (const term of terms) {
|
|
15083
|
-
const budget = editBudget(term);
|
|
15084
|
-
const words = [...this.vocabulary.keys()].filter((word) => Math.abs(word.length - term.length) <= budget).map((word) => ({ word, dice: diceCoefficient(term, word) })).sort((a, b) => b.dice - a.dice);
|
|
15085
|
-
for (const { word } of words) if (editDistanceAtMost(term, word, budget) <= budget) {
|
|
15086
|
-
for (const id of this.vocabulary.get(word)) ids2.add(id);
|
|
15087
|
-
}
|
|
15088
|
-
}
|
|
15137
|
+
const ids2 = vocabularyCandidates(this.vocabulary, terms);
|
|
15089
15138
|
return [...ids2].map((id) => ({ ...this.rows.get(id) }));
|
|
15090
15139
|
}
|
|
15091
15140
|
schedule(delay, fn) {
|
|
@@ -20182,37 +20231,11 @@ function prepare(query, opts) {
|
|
|
20182
20231
|
return { terms, limit };
|
|
20183
20232
|
}
|
|
20184
20233
|
function companyPieces(terms) {
|
|
20185
|
-
|
|
20186
|
-
const prefixes = /* @__PURE__ */ new Set();
|
|
20187
|
-
const longest = [...terms].sort((a, b) => b.length - a.length || a.localeCompare(b)).slice(0, 2);
|
|
20188
|
-
for (const word of longest) {
|
|
20189
|
-
const count = Math.max(1, Math.min(editBudget(word) + 1, Math.floor(word.length / 4)));
|
|
20190
|
-
for (let i = 0; i < count; i++) pieces.add(word.slice(Math.floor(i * word.length / count), Math.floor((i + 1) * word.length / count)));
|
|
20191
|
-
if (word.length >= 4 && word.length <= 6) prefixes.add(word.slice(0, 3));
|
|
20192
|
-
}
|
|
20193
|
-
if (terms.length > 1) pieces.add(terms.join(""));
|
|
20194
|
-
return { pieces: [...pieces], prefixes: [...prefixes] };
|
|
20234
|
+
return textFragments(terms);
|
|
20195
20235
|
}
|
|
20196
20236
|
function score(record, terms, source) {
|
|
20197
|
-
const
|
|
20198
|
-
|
|
20199
|
-
const matchedTerms = [];
|
|
20200
|
-
let distance = 0;
|
|
20201
|
-
for (const term of terms) {
|
|
20202
|
-
const budget = editBudget(term);
|
|
20203
|
-
const best = Math.min(budget + 1, ...candidates.map((word) => editDistanceAtMost(term, word, budget)));
|
|
20204
|
-
if (best <= budget) {
|
|
20205
|
-
matchedTerms.push(term);
|
|
20206
|
-
distance += best;
|
|
20207
|
-
}
|
|
20208
|
-
}
|
|
20209
|
-
if (terms.length > 1) {
|
|
20210
|
-
const compact = terms.join("");
|
|
20211
|
-
const budget = editBudget(compact);
|
|
20212
|
-
const best = Math.min(budget + 1, ...candidates.map((word) => editDistanceAtMost(compact, word, budget)));
|
|
20213
|
-
if (best <= budget && matchedTerms.length < terms.length) return { record, source, coverage: terms.length, distance: best, matchedTerms: [...terms] };
|
|
20214
|
-
}
|
|
20215
|
-
return matchedTerms.length === 0 ? void 0 : { record, source, coverage: matchedTerms.length, distance, matchedTerms };
|
|
20237
|
+
const match = scoreTerms(terms, companyTerms(record.companyName ?? ""));
|
|
20238
|
+
return match === void 0 ? void 0 : { record, source, ...match };
|
|
20216
20239
|
}
|
|
20217
20240
|
async function searchFuzzy(resource, query, opts = {}) {
|
|
20218
20241
|
const { terms, limit } = prepare(query, opts);
|
|
@@ -20240,7 +20263,7 @@ async function searchFuzzy(resource, query, opts = {}) {
|
|
|
20240
20263
|
const validIndex = index?.revision() === revision;
|
|
20241
20264
|
for (const row of validIndex ? indexed : []) if (typeof row.id === "number") merged.set(row.id, { row, source: "index" });
|
|
20242
20265
|
for (const row of live) if (typeof row.id === "number") merged.set(row.id, { row: slimCompany(row), source: merged.has(row.id) ? "both" : "live" });
|
|
20243
|
-
const ranked = [...merged.values()].filter(({ row }) => opts.includeInactive || row.isActive === true).map(({ row, source }) => score(row, terms, source)).filter((row) => row !== void 0).sort((a, b) =>
|
|
20266
|
+
const ranked = [...merged.values()].filter(({ row }) => opts.includeInactive || row.isActive === true).map(({ row, source }) => score(row, terms, source)).filter((row) => row !== void 0).sort((a, b) => compareTermScores(a, b) || Number(b.record.isActive === true) - Number(a.record.isActive === true) || (a.record.id ?? 0) - (b.record.id ?? 0));
|
|
20244
20267
|
const items = ranked.slice(0, limit);
|
|
20245
20268
|
if (opts.includeFamily) {
|
|
20246
20269
|
const records = await addCompanyFamilies(resource.http, items.map((row) => row.record), "companies.searchFuzzy");
|
|
@@ -14953,17 +14953,14 @@ async function collectAll(fetchPage, opts = {}) {
|
|
|
14953
14953
|
return all;
|
|
14954
14954
|
}
|
|
14955
14955
|
|
|
14956
|
-
// src/search/
|
|
14957
|
-
|
|
14958
|
-
|
|
14959
|
-
|
|
14960
|
-
return
|
|
14961
|
-
}
|
|
14962
|
-
function companyTerms(value) {
|
|
14963
|
-
return normaliseCompanyName(value).split(" ").filter((t) => t && !LEGAL_SUFFIXES.has(t) && !STOPWORDS.has(t));
|
|
14956
|
+
// src/search/fuzzy-text.ts
|
|
14957
|
+
function normaliseText(value, options = {}) {
|
|
14958
|
+
let folded = value.normalize("NFKD").replace(new RegExp("\\p{M}+", "gu"), "").toLowerCase();
|
|
14959
|
+
if (options.ampersandAsAnd) folded = folded.replace(/&/g, " and ");
|
|
14960
|
+
return folded.replace(/[^\p{L}\p{N}]+/gu, " ").split(/\s+/).filter((term) => term && !options.excludeTerms?.has(term)).join(" ");
|
|
14964
14961
|
}
|
|
14965
|
-
function
|
|
14966
|
-
return
|
|
14962
|
+
function textTerms(value, normalise = normaliseText, excludeTerms) {
|
|
14963
|
+
return normalise(value).split(" ").filter((term) => term && !excludeTerms?.has(term));
|
|
14967
14964
|
}
|
|
14968
14965
|
function ngramsOf(token) {
|
|
14969
14966
|
if (token.length < 3) return [token];
|
|
@@ -14999,6 +14996,67 @@ function editDistanceAtMost(a, b, k) {
|
|
|
14999
14996
|
}
|
|
15000
14997
|
return previous[b.length];
|
|
15001
14998
|
}
|
|
14999
|
+
function textFragments(terms) {
|
|
15000
|
+
const pieces = /* @__PURE__ */ new Set();
|
|
15001
|
+
const prefixes = /* @__PURE__ */ new Set();
|
|
15002
|
+
const longest = [...terms].sort((a, b) => b.length - a.length || a.localeCompare(b)).slice(0, 2);
|
|
15003
|
+
for (const word of longest) {
|
|
15004
|
+
const count = Math.max(1, Math.min(editBudget(word) + 1, Math.floor(word.length / 4)));
|
|
15005
|
+
for (let i = 0; i < count; i++) pieces.add(word.slice(Math.floor(i * word.length / count), Math.floor((i + 1) * word.length / count)));
|
|
15006
|
+
if (word.length >= 4 && word.length <= 6) prefixes.add(word.slice(0, 3));
|
|
15007
|
+
}
|
|
15008
|
+
if (terms.length > 1) pieces.add(terms.join(""));
|
|
15009
|
+
return { pieces: [...pieces], prefixes: [...prefixes] };
|
|
15010
|
+
}
|
|
15011
|
+
function scoreTerms(terms, words) {
|
|
15012
|
+
const candidates = [...words, words.join("")];
|
|
15013
|
+
const matchedTerms = [];
|
|
15014
|
+
let distance = 0;
|
|
15015
|
+
for (const term of terms) {
|
|
15016
|
+
const budget = editBudget(term);
|
|
15017
|
+
const best = Math.min(budget + 1, ...candidates.map((word) => editDistanceAtMost(term, word, budget)));
|
|
15018
|
+
if (best <= budget) {
|
|
15019
|
+
matchedTerms.push(term);
|
|
15020
|
+
distance += best;
|
|
15021
|
+
}
|
|
15022
|
+
}
|
|
15023
|
+
if (terms.length > 1) {
|
|
15024
|
+
const compact = terms.join("");
|
|
15025
|
+
const budget = editBudget(compact);
|
|
15026
|
+
const best = Math.min(budget + 1, ...candidates.map((word) => editDistanceAtMost(compact, word, budget)));
|
|
15027
|
+
if (best <= budget && matchedTerms.length < terms.length) return { coverage: terms.length, distance: best, matchedTerms: [...terms] };
|
|
15028
|
+
}
|
|
15029
|
+
return matchedTerms.length === 0 ? void 0 : { coverage: matchedTerms.length, distance, matchedTerms };
|
|
15030
|
+
}
|
|
15031
|
+
function compareTermScores(a, b) {
|
|
15032
|
+
return b.coverage - a.coverage || a.distance - b.distance;
|
|
15033
|
+
}
|
|
15034
|
+
function vocabularyCandidates(vocabulary, terms) {
|
|
15035
|
+
const keys = /* @__PURE__ */ new Set();
|
|
15036
|
+
for (const term of terms) {
|
|
15037
|
+
const budget = editBudget(term);
|
|
15038
|
+
const words = [...vocabulary.keys()].filter((word) => Math.abs(word.length - term.length) <= budget).map((word) => ({ word, dice: diceCoefficient(term, word) })).sort((a, b) => b.dice - a.dice);
|
|
15039
|
+
for (const { word } of words) if (editDistanceAtMost(term, word, budget) <= budget) {
|
|
15040
|
+
for (const key of vocabulary.get(word)) keys.add(key);
|
|
15041
|
+
}
|
|
15042
|
+
}
|
|
15043
|
+
return keys;
|
|
15044
|
+
}
|
|
15045
|
+
|
|
15046
|
+
// src/search/company-names.ts
|
|
15047
|
+
var LEGAL_SUFFIXES = /* @__PURE__ */ new Set(["pty", "ltd", "limited", "inc", "llc", "co", "corp", "gmbh"]);
|
|
15048
|
+
var STOPWORDS = /* @__PURE__ */ new Set(["the", "and", "of"]);
|
|
15049
|
+
var NAME_EXCLUSIONS = /* @__PURE__ */ new Set(["the"]);
|
|
15050
|
+
var SCORE_EXCLUSIONS = /* @__PURE__ */ new Set([...LEGAL_SUFFIXES, ...STOPWORDS]);
|
|
15051
|
+
function normaliseCompanyName(value) {
|
|
15052
|
+
return normaliseText(value, { ampersandAsAnd: true, excludeTerms: NAME_EXCLUSIONS });
|
|
15053
|
+
}
|
|
15054
|
+
function companyTerms(value) {
|
|
15055
|
+
return textTerms(value, normaliseCompanyName, SCORE_EXCLUSIONS);
|
|
15056
|
+
}
|
|
15057
|
+
function companyDedupeName(value) {
|
|
15058
|
+
return textTerms(value, normaliseCompanyName, LEGAL_SUFFIXES).join(" ");
|
|
15059
|
+
}
|
|
15002
15060
|
|
|
15003
15061
|
// src/search/company-index.ts
|
|
15004
15062
|
var COMPANY_INDEX_WRITE_DEBOUNCE_MS = 1e3;
|
|
@@ -15072,18 +15130,9 @@ var CompanyNameIndex = class {
|
|
|
15072
15130
|
if (this.timer) clearTimeout(this.timer);
|
|
15073
15131
|
if (this.started) this.start(COMPANY_INDEX_WRITE_DEBOUNCE_MS);
|
|
15074
15132
|
}
|
|
15075
|
-
/**
|
|
15076
|
-
* A Dice floor would lose valid short-word swaps, so zero-overlap vocabulary
|
|
15077
|
-
* remains eligible when its length is within the edit budget. */
|
|
15133
|
+
/** The index owns company rows; the shared engine selects vocabulary keys. */
|
|
15078
15134
|
candidates(terms) {
|
|
15079
|
-
const ids2 =
|
|
15080
|
-
for (const term of terms) {
|
|
15081
|
-
const budget = editBudget(term);
|
|
15082
|
-
const words = [...this.vocabulary.keys()].filter((word) => Math.abs(word.length - term.length) <= budget).map((word) => ({ word, dice: diceCoefficient(term, word) })).sort((a, b) => b.dice - a.dice);
|
|
15083
|
-
for (const { word } of words) if (editDistanceAtMost(term, word, budget) <= budget) {
|
|
15084
|
-
for (const id of this.vocabulary.get(word)) ids2.add(id);
|
|
15085
|
-
}
|
|
15086
|
-
}
|
|
15135
|
+
const ids2 = vocabularyCandidates(this.vocabulary, terms);
|
|
15087
15136
|
return [...ids2].map((id) => ({ ...this.rows.get(id) }));
|
|
15088
15137
|
}
|
|
15089
15138
|
schedule(delay, fn) {
|
|
@@ -20180,37 +20229,11 @@ function prepare(query, opts) {
|
|
|
20180
20229
|
return { terms, limit };
|
|
20181
20230
|
}
|
|
20182
20231
|
function companyPieces(terms) {
|
|
20183
|
-
|
|
20184
|
-
const prefixes = /* @__PURE__ */ new Set();
|
|
20185
|
-
const longest = [...terms].sort((a, b) => b.length - a.length || a.localeCompare(b)).slice(0, 2);
|
|
20186
|
-
for (const word of longest) {
|
|
20187
|
-
const count = Math.max(1, Math.min(editBudget(word) + 1, Math.floor(word.length / 4)));
|
|
20188
|
-
for (let i = 0; i < count; i++) pieces.add(word.slice(Math.floor(i * word.length / count), Math.floor((i + 1) * word.length / count)));
|
|
20189
|
-
if (word.length >= 4 && word.length <= 6) prefixes.add(word.slice(0, 3));
|
|
20190
|
-
}
|
|
20191
|
-
if (terms.length > 1) pieces.add(terms.join(""));
|
|
20192
|
-
return { pieces: [...pieces], prefixes: [...prefixes] };
|
|
20232
|
+
return textFragments(terms);
|
|
20193
20233
|
}
|
|
20194
20234
|
function score(record, terms, source) {
|
|
20195
|
-
const
|
|
20196
|
-
|
|
20197
|
-
const matchedTerms = [];
|
|
20198
|
-
let distance = 0;
|
|
20199
|
-
for (const term of terms) {
|
|
20200
|
-
const budget = editBudget(term);
|
|
20201
|
-
const best = Math.min(budget + 1, ...candidates.map((word) => editDistanceAtMost(term, word, budget)));
|
|
20202
|
-
if (best <= budget) {
|
|
20203
|
-
matchedTerms.push(term);
|
|
20204
|
-
distance += best;
|
|
20205
|
-
}
|
|
20206
|
-
}
|
|
20207
|
-
if (terms.length > 1) {
|
|
20208
|
-
const compact = terms.join("");
|
|
20209
|
-
const budget = editBudget(compact);
|
|
20210
|
-
const best = Math.min(budget + 1, ...candidates.map((word) => editDistanceAtMost(compact, word, budget)));
|
|
20211
|
-
if (best <= budget && matchedTerms.length < terms.length) return { record, source, coverage: terms.length, distance: best, matchedTerms: [...terms] };
|
|
20212
|
-
}
|
|
20213
|
-
return matchedTerms.length === 0 ? void 0 : { record, source, coverage: matchedTerms.length, distance, matchedTerms };
|
|
20235
|
+
const match = scoreTerms(terms, companyTerms(record.companyName ?? ""));
|
|
20236
|
+
return match === void 0 ? void 0 : { record, source, ...match };
|
|
20214
20237
|
}
|
|
20215
20238
|
async function searchFuzzy(resource, query, opts = {}) {
|
|
20216
20239
|
const { terms, limit } = prepare(query, opts);
|
|
@@ -20238,7 +20261,7 @@ async function searchFuzzy(resource, query, opts = {}) {
|
|
|
20238
20261
|
const validIndex = index?.revision() === revision;
|
|
20239
20262
|
for (const row of validIndex ? indexed : []) if (typeof row.id === "number") merged.set(row.id, { row, source: "index" });
|
|
20240
20263
|
for (const row of live) if (typeof row.id === "number") merged.set(row.id, { row: slimCompany(row), source: merged.has(row.id) ? "both" : "live" });
|
|
20241
|
-
const ranked = [...merged.values()].filter(({ row }) => opts.includeInactive || row.isActive === true).map(({ row, source }) => score(row, terms, source)).filter((row) => row !== void 0).sort((a, b) =>
|
|
20264
|
+
const ranked = [...merged.values()].filter(({ row }) => opts.includeInactive || row.isActive === true).map(({ row, source }) => score(row, terms, source)).filter((row) => row !== void 0).sort((a, b) => compareTermScores(a, b) || Number(b.record.isActive === true) - Number(a.record.isActive === true) || (a.record.id ?? 0) - (b.record.id ?? 0));
|
|
20242
20265
|
const items = ranked.slice(0, limit);
|
|
20243
20266
|
if (opts.includeFamily) {
|
|
20244
20267
|
const records = await addCompanyFamilies(resource.http, items.map((row) => row.record), "companies.searchFuzzy");
|