@superdurable/connector-elasticsearch 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +4 -2
- package/dex-connector.json +185 -0
- package/dist/chunk-5WBVTQWI.js +210 -0
- package/dist/connection-Du7eKAvn.d.ts +173 -0
- package/dist/index.d.ts +210 -0
- package/dist/index.js +499 -0
- package/dist/mock.d.ts +73 -0
- package/dist/mock.js +176 -0
- package/package.json +61 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ConfigSchema,
|
|
3
|
+
Connection,
|
|
4
|
+
ConnectorID,
|
|
5
|
+
CredentialMaterialError,
|
|
6
|
+
DeleteDocumentBranch,
|
|
7
|
+
DeleteDocumentBranchAbsent,
|
|
8
|
+
DeleteDocumentBranchDefect,
|
|
9
|
+
DeleteDocumentBranchIndexNotFound,
|
|
10
|
+
DeleteDocumentBranchProviderRejected,
|
|
11
|
+
DeleteDocumentDefinition,
|
|
12
|
+
DeleteDocumentInputSchema,
|
|
13
|
+
DeleteDocumentMetadata,
|
|
14
|
+
DeletedDocumentSchema,
|
|
15
|
+
IndexDocumentBranch,
|
|
16
|
+
IndexDocumentBranchDefect,
|
|
17
|
+
IndexDocumentBranchIndexed,
|
|
18
|
+
IndexDocumentBranchProviderRejected,
|
|
19
|
+
IndexDocumentDefinition,
|
|
20
|
+
IndexDocumentInputSchema,
|
|
21
|
+
IndexDocumentMetadata,
|
|
22
|
+
IndexedDocumentSchema,
|
|
23
|
+
ProviderID,
|
|
24
|
+
SearchDocumentsBranch,
|
|
25
|
+
SearchDocumentsBranchDefect,
|
|
26
|
+
SearchDocumentsBranchFound,
|
|
27
|
+
SearchDocumentsBranchIndexNotFound,
|
|
28
|
+
SearchDocumentsBranchInvalidResponse,
|
|
29
|
+
SearchDocumentsBranchProviderRejected,
|
|
30
|
+
SearchDocumentsDefinition,
|
|
31
|
+
SearchDocumentsInputSchema,
|
|
32
|
+
SearchDocumentsMetadata,
|
|
33
|
+
SearchHitSchema,
|
|
34
|
+
SearchPageSchema,
|
|
35
|
+
decodeCredentials,
|
|
36
|
+
isCredentialMaterialError,
|
|
37
|
+
newConnection,
|
|
38
|
+
newConnectionWithOperations,
|
|
39
|
+
newProjectConnection
|
|
40
|
+
} from "./chunk-5WBVTQWI.js";
|
|
41
|
+
|
|
42
|
+
// src/generated/steps.ts
|
|
43
|
+
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
44
|
+
function newIndexDocumentStep(configuration) {
|
|
45
|
+
const { connection, connectionName, indexed, providerRejected, defect, ...stepConfiguration } = configuration;
|
|
46
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
47
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.indexDocument(), connection: connection.reference, branches: [
|
|
48
|
+
goToBranch("indexed", indexed),
|
|
49
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
50
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
51
|
+
] });
|
|
52
|
+
}
|
|
53
|
+
function newDeleteDocumentStep(configuration) {
|
|
54
|
+
const { connection, connectionName, absent, indexNotFound, providerRejected, defect, ...stepConfiguration } = configuration;
|
|
55
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
56
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteDocument(), connection: connection.reference, branches: [
|
|
57
|
+
goToBranch("absent", absent),
|
|
58
|
+
...indexNotFound ? [goToBranch("indexNotFound", indexNotFound)] : [],
|
|
59
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
60
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
61
|
+
] });
|
|
62
|
+
}
|
|
63
|
+
function newSearchDocumentsStep(configuration) {
|
|
64
|
+
const { connection, connectionName, found, indexNotFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
65
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
66
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.searchDocuments(), connection: connection.reference, branches: [
|
|
67
|
+
goToBranch("found", found),
|
|
68
|
+
...indexNotFound ? [goToBranch("indexNotFound", indexNotFound)] : [],
|
|
69
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
70
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
71
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
72
|
+
] });
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/project.ts
|
|
76
|
+
import { z } from "zod";
|
|
77
|
+
|
|
78
|
+
// src/client.ts
|
|
79
|
+
import {
|
|
80
|
+
newMutationBranch,
|
|
81
|
+
newMutationRetry,
|
|
82
|
+
newQueryBranch,
|
|
83
|
+
newQueryRetry,
|
|
84
|
+
ReauthorizationRequiredError
|
|
85
|
+
} from "@superdurable/connectors-sdk";
|
|
86
|
+
import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
|
|
87
|
+
import {
|
|
88
|
+
BodyTooLargeError,
|
|
89
|
+
ProviderTransportError,
|
|
90
|
+
parseRetryAfter,
|
|
91
|
+
sendProviderRequest,
|
|
92
|
+
validateBaseURL
|
|
93
|
+
} from "@superdurable/connectors-sdk/providerhttp";
|
|
94
|
+
var indexPattern = /^[a-z0-9.][a-z0-9._-]*$/;
|
|
95
|
+
var emptyIndexed = { index: "", id: "" };
|
|
96
|
+
var emptyDeleted = { index: "", id: "", wasDeleted: false };
|
|
97
|
+
var emptyPage = { total: 0, relation: "", hits: [] };
|
|
98
|
+
var ElasticsearchClient = class {
|
|
99
|
+
/** Validated cluster URL without a trailing slash. */
|
|
100
|
+
clusterUrl;
|
|
101
|
+
/** Maximum complete document request size in bytes. */
|
|
102
|
+
maxDocumentBytes;
|
|
103
|
+
timeoutMs;
|
|
104
|
+
maxResponseBytes;
|
|
105
|
+
credentials;
|
|
106
|
+
send;
|
|
107
|
+
now;
|
|
108
|
+
/** Validate cluster settings without contacting Elasticsearch. */
|
|
109
|
+
constructor(config, credentials, options = {}) {
|
|
110
|
+
if (!config || !credentials) throw new TypeError("Elasticsearch configuration and credentials are required");
|
|
111
|
+
this.clusterUrl = validateBaseURL(config.clusterUrl);
|
|
112
|
+
this.timeoutMs = config.timeoutMs ?? 15e3;
|
|
113
|
+
this.maxResponseBytes = config.maxResponseBytes ?? 4194304;
|
|
114
|
+
this.maxDocumentBytes = config.maxDocumentBytes ?? 1048576;
|
|
115
|
+
if (![this.timeoutMs, this.maxResponseBytes, this.maxDocumentBytes].every((value) => Number.isSafeInteger(value) && value > 0))
|
|
116
|
+
throw new TypeError("Elasticsearch request limits must be positive integers");
|
|
117
|
+
this.credentials = credentials;
|
|
118
|
+
this.send = options.send ?? sendProviderRequest;
|
|
119
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
120
|
+
}
|
|
121
|
+
/** Bind the absolute replacement Mutation. */
|
|
122
|
+
indexDocument() {
|
|
123
|
+
return new IndexDocumentOperation(this);
|
|
124
|
+
}
|
|
125
|
+
/** Bind the stable-ID deletion Mutation. */
|
|
126
|
+
deleteDocument() {
|
|
127
|
+
return new DeleteDocumentOperation(this);
|
|
128
|
+
}
|
|
129
|
+
/** Bind the bounded search Query. */
|
|
130
|
+
searchDocuments() {
|
|
131
|
+
return new SearchDocumentsOperation(this);
|
|
132
|
+
}
|
|
133
|
+
/** Resolve Basic authorization without returning credentials in failures. */
|
|
134
|
+
async authorization(call) {
|
|
135
|
+
return await this.resolveAuthorization(call) ?? void 0;
|
|
136
|
+
}
|
|
137
|
+
/** Return null for a transient credential failure and undefined for a terminal or invalid one. */
|
|
138
|
+
async resolveAuthorization(call) {
|
|
139
|
+
let credentials;
|
|
140
|
+
try {
|
|
141
|
+
credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
142
|
+
} catch (error) {
|
|
143
|
+
return isTerminalCredentialError(error) ? void 0 : null;
|
|
144
|
+
}
|
|
145
|
+
try {
|
|
146
|
+
const username = credentials.username;
|
|
147
|
+
const password = credentials.password.reveal();
|
|
148
|
+
if (!username || /[:\r\n\0]/.test(username) || !password || /[\r\n\0]/.test(password)) return void 0;
|
|
149
|
+
return `Basic ${Buffer.from(`${username}:${password}`).toString("base64")}`;
|
|
150
|
+
} catch {
|
|
151
|
+
return void 0;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
/** Send one bounded request without automatic redirects. */
|
|
155
|
+
async exchange(call, method, url, headers, body) {
|
|
156
|
+
const request = {
|
|
157
|
+
url,
|
|
158
|
+
method,
|
|
159
|
+
headers,
|
|
160
|
+
maxResponseBytes: this.maxResponseBytes,
|
|
161
|
+
timeoutMs: this.timeoutMs,
|
|
162
|
+
addressPolicy: url.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP",
|
|
163
|
+
signal: call.context.cancellationSignal,
|
|
164
|
+
...body ? { body } : {}
|
|
165
|
+
};
|
|
166
|
+
try {
|
|
167
|
+
const response = await this.send(request);
|
|
168
|
+
return {
|
|
169
|
+
status: response.status,
|
|
170
|
+
body: response.body,
|
|
171
|
+
retryAfterMs: this.retryAfter(response.headers)
|
|
172
|
+
};
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (error instanceof BodyTooLargeError)
|
|
175
|
+
return {
|
|
176
|
+
status: error.status ?? 0,
|
|
177
|
+
body: new Uint8Array(),
|
|
178
|
+
retryAfterMs: this.retryAfter(error.headers ?? {}),
|
|
179
|
+
error: "tooLarge"
|
|
180
|
+
};
|
|
181
|
+
if (error instanceof ProviderTransportError)
|
|
182
|
+
return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error: "request" };
|
|
183
|
+
return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error: "request" };
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
retryAfter(headers) {
|
|
187
|
+
const value = Object.entries(headers).find(([name]) => name.toLowerCase() === "retry-after")?.[1];
|
|
188
|
+
return parseRetryAfter(Array.isArray(value) ? value[0] ?? "" : value ?? "", this.now());
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
var IndexDocumentOperation = class {
|
|
192
|
+
/** Bind the provider client. */
|
|
193
|
+
constructor(client) {
|
|
194
|
+
this.client = client;
|
|
195
|
+
}
|
|
196
|
+
client;
|
|
197
|
+
/** Return the generated Mutation contract. */
|
|
198
|
+
definition() {
|
|
199
|
+
return IndexDocumentDefinition;
|
|
200
|
+
}
|
|
201
|
+
/** Use stable Dex call identity; absolute PUT is safe to retry. */
|
|
202
|
+
idempotencyKey(callId) {
|
|
203
|
+
return callId;
|
|
204
|
+
}
|
|
205
|
+
/** Retry unconfirmed responses with the same absolute document source. */
|
|
206
|
+
async invoke(call, input) {
|
|
207
|
+
if (!input || !validIndex(input.index) || !validDocumentID(input.documentId) || !isRecord(input.source))
|
|
208
|
+
return indexFailure("defect", "VALIDATION");
|
|
209
|
+
let body;
|
|
210
|
+
try {
|
|
211
|
+
body = Buffer.from(JSON.stringify(input.source));
|
|
212
|
+
} catch {
|
|
213
|
+
return indexFailure("defect", "VALIDATION");
|
|
214
|
+
}
|
|
215
|
+
if (body.byteLength > this.client.maxDocumentBytes) return indexFailure("defect", "VALIDATION");
|
|
216
|
+
const authorization = await this.client["resolveAuthorization"](call);
|
|
217
|
+
if (authorization === null) return indexRetry("AVAILABILITY");
|
|
218
|
+
if (!authorization) return indexFailure("defect", "AUTHENTICATION");
|
|
219
|
+
const exchange = await this.client.exchange(
|
|
220
|
+
call,
|
|
221
|
+
"PUT",
|
|
222
|
+
documentURL(this.client.clusterUrl, input.index, input.documentId),
|
|
223
|
+
{ Accept: "application/json", "Content-Type": "application/json", Authorization: authorization },
|
|
224
|
+
body
|
|
225
|
+
);
|
|
226
|
+
const retry = documentRetry(exchange, "indexDocument");
|
|
227
|
+
if (retry) return retry;
|
|
228
|
+
if (exchange.status === 200 || exchange.status === 201) {
|
|
229
|
+
const result = parseJSON(exchange.body);
|
|
230
|
+
if (!isRecord(result) || result._index !== input.index || result._id !== input.documentId || result.result !== "created" && result.result !== "updated") return indexRetry("PROTOCOL");
|
|
231
|
+
return newMutationBranch("indexed", { index: input.index, id: input.documentId });
|
|
232
|
+
}
|
|
233
|
+
if (!isDefiniteRefusalStatus(exchange.status)) return indexRetry("AVAILABILITY");
|
|
234
|
+
return indexFailure("providerRejected", rejectionKind(exchange.status));
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
var DeleteDocumentOperation = class {
|
|
238
|
+
/** Bind the provider client. */
|
|
239
|
+
constructor(client) {
|
|
240
|
+
this.client = client;
|
|
241
|
+
}
|
|
242
|
+
client;
|
|
243
|
+
/** Return the generated Mutation contract. */
|
|
244
|
+
definition() {
|
|
245
|
+
return DeleteDocumentDefinition;
|
|
246
|
+
}
|
|
247
|
+
/** Use stable Dex call identity; repeating DELETE is safe. */
|
|
248
|
+
idempotencyKey(callId) {
|
|
249
|
+
return callId;
|
|
250
|
+
}
|
|
251
|
+
/** Treat both deleted and already absent as success. */
|
|
252
|
+
async invoke(call, input) {
|
|
253
|
+
if (!input || !validIndex(input.index) || !validDocumentID(input.documentId))
|
|
254
|
+
return deleteFailure("defect", "VALIDATION");
|
|
255
|
+
const authorization = await this.client["resolveAuthorization"](call);
|
|
256
|
+
if (authorization === null) return deleteRetry("AVAILABILITY");
|
|
257
|
+
if (!authorization) return deleteFailure("defect", "AUTHENTICATION");
|
|
258
|
+
const exchange = await this.client.exchange(
|
|
259
|
+
call,
|
|
260
|
+
"DELETE",
|
|
261
|
+
documentURL(this.client.clusterUrl, input.index, input.documentId),
|
|
262
|
+
{ Accept: "application/json", Authorization: authorization }
|
|
263
|
+
);
|
|
264
|
+
const retry = documentRetry(exchange, "deleteDocument");
|
|
265
|
+
if (retry) return retry;
|
|
266
|
+
if (exchange.status === 200 || exchange.status === 404) {
|
|
267
|
+
const result = parseJSON(exchange.body);
|
|
268
|
+
if (!isRecord(result)) return deleteRetry("PROTOCOL");
|
|
269
|
+
const error = result.error;
|
|
270
|
+
if (exchange.status === 404 && isRecord(error) && error.type === "index_not_found_exception")
|
|
271
|
+
return deleteFailure("indexNotFound", "NOT_FOUND");
|
|
272
|
+
if (result._index !== input.index || result._id !== input.documentId || result.result !== "deleted" && result.result !== "not_found") return deleteRetry("PROTOCOL");
|
|
273
|
+
return newMutationBranch("absent", {
|
|
274
|
+
index: input.index,
|
|
275
|
+
id: input.documentId,
|
|
276
|
+
wasDeleted: result.result === "deleted"
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
if (!isDefiniteRefusalStatus(exchange.status)) return deleteRetry("AVAILABILITY");
|
|
280
|
+
return deleteFailure("providerRejected", rejectionKind(exchange.status));
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
var SearchDocumentsOperation = class {
|
|
284
|
+
/** Bind the provider client. */
|
|
285
|
+
constructor(client) {
|
|
286
|
+
this.client = client;
|
|
287
|
+
}
|
|
288
|
+
client;
|
|
289
|
+
/** Return the generated Query contract. */
|
|
290
|
+
definition() {
|
|
291
|
+
return SearchDocumentsDefinition;
|
|
292
|
+
}
|
|
293
|
+
/** Reject partial results and retry timed-out or shard-failed searches. */
|
|
294
|
+
async invoke(call, input) {
|
|
295
|
+
const size = input?.size || 10;
|
|
296
|
+
const from = input?.from ?? 0;
|
|
297
|
+
if (!input || !validIndex(input.index) || typeof input.query !== "string" || !input.query.trim() || Buffer.byteLength(input.query) > 4096 || !Number.isSafeInteger(size) || size < 1 || size > 100 || !Number.isSafeInteger(from) || from < 0 || from + size > 1e4)
|
|
298
|
+
return searchFailure("defect", "VALIDATION");
|
|
299
|
+
const authorization = await this.client["resolveAuthorization"](call);
|
|
300
|
+
if (authorization === null) return searchRetry("AVAILABILITY");
|
|
301
|
+
if (!authorization) return searchFailure("defect", "AUTHENTICATION");
|
|
302
|
+
const query = new URLSearchParams({
|
|
303
|
+
q: input.query,
|
|
304
|
+
size: String(size),
|
|
305
|
+
from: String(from),
|
|
306
|
+
allow_partial_search_results: "false"
|
|
307
|
+
});
|
|
308
|
+
const exchange = await this.client.exchange(
|
|
309
|
+
call,
|
|
310
|
+
"GET",
|
|
311
|
+
`${this.client.clusterUrl}/${input.index}/_search?${query}`,
|
|
312
|
+
{ Accept: "application/json", Authorization: authorization }
|
|
313
|
+
);
|
|
314
|
+
if (exchange.error === "request") return searchRetry("AVAILABILITY");
|
|
315
|
+
if (exchange.status === 429) return searchRetry("RATE_LIMIT", exchange.retryAfterMs);
|
|
316
|
+
if (exchange.status === 408 || exchange.status === 409 || exchange.status >= 500)
|
|
317
|
+
return searchRetry("AVAILABILITY", exchange.retryAfterMs);
|
|
318
|
+
if (exchange.status === 404) return searchFailure("indexNotFound", "NOT_FOUND");
|
|
319
|
+
if (exchange.status !== 200) return searchFailure("providerRejected", rejectionKind(exchange.status));
|
|
320
|
+
if (exchange.error === "tooLarge") return searchFailure("invalidResponse", "RESPONSE_TOO_LARGE");
|
|
321
|
+
const body = parseJSON(exchange.body);
|
|
322
|
+
if (!isRecord(body) || typeof body.timed_out !== "boolean" || !isRecord(body._shards))
|
|
323
|
+
return searchFailure("invalidResponse", "PROTOCOL");
|
|
324
|
+
if (body.timed_out || typeof body._shards.failed === "number" && body._shards.failed > 0)
|
|
325
|
+
return searchRetry("AVAILABILITY");
|
|
326
|
+
const hitsRoot = body.hits;
|
|
327
|
+
const total = isRecord(hitsRoot) ? hitsRoot.total : void 0;
|
|
328
|
+
const hits = isRecord(hitsRoot) ? hitsRoot.hits : void 0;
|
|
329
|
+
if (!isRecord(total) || !Number.isSafeInteger(total.value) || total.value < 0 || total.relation !== "eq" && total.relation !== "gte" || !Array.isArray(hits))
|
|
330
|
+
return searchFailure("invalidResponse", "PROTOCOL");
|
|
331
|
+
const parsedHits = [];
|
|
332
|
+
for (const hit of hits) {
|
|
333
|
+
if (!isRecord(hit) || typeof hit._index !== "string" || !hit._index || typeof hit._id !== "string" || !hit._id || !Object.hasOwn(hit, "_source") || hit._score !== void 0 && hit._score !== null && typeof hit._score !== "number")
|
|
334
|
+
return searchFailure("invalidResponse", "PROTOCOL");
|
|
335
|
+
parsedHits.push({
|
|
336
|
+
index: hit._index,
|
|
337
|
+
id: hit._id,
|
|
338
|
+
source: hit._source,
|
|
339
|
+
...typeof hit._score === "number" ? { score: hit._score } : {}
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
return newQueryBranch("found", { total: total.value, relation: total.relation, hits: parsedHits });
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
function validIndex(index) {
|
|
346
|
+
return typeof index === "string" && index.length <= 255 && indexPattern.test(index) && index !== "." && index !== "..";
|
|
347
|
+
}
|
|
348
|
+
function validDocumentID(id) {
|
|
349
|
+
return typeof id === "string" && !!id && Buffer.byteLength(id) <= 512 && !/[\r\n\0]/.test(id);
|
|
350
|
+
}
|
|
351
|
+
function documentURL(clusterUrl, index, documentId) {
|
|
352
|
+
return `${clusterUrl}/${index}/_doc/${encodeURIComponent(documentId)}`;
|
|
353
|
+
}
|
|
354
|
+
function parseJSON(body) {
|
|
355
|
+
try {
|
|
356
|
+
return JSON.parse(Buffer.from(body).toString("utf8"));
|
|
357
|
+
} catch {
|
|
358
|
+
return void 0;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function isRecord(value) {
|
|
362
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
363
|
+
}
|
|
364
|
+
function rejectionKind(status) {
|
|
365
|
+
return status === 401 ? "AUTHENTICATION" : status === 403 ? "AUTHORIZATION" : "PROVIDER_REJECTION";
|
|
366
|
+
}
|
|
367
|
+
function failure(operation, kind) {
|
|
368
|
+
return { kind, provider: "elasticsearch", operation, message: "Elasticsearch provider operation failed" };
|
|
369
|
+
}
|
|
370
|
+
function documentRetry(exchange, operation) {
|
|
371
|
+
if (exchange.status === 429) return newMutationRetry(failure(operation, "RATE_LIMIT"), exchange.retryAfterMs);
|
|
372
|
+
if (exchange.status === 408 || exchange.status === 409 || exchange.status >= 500)
|
|
373
|
+
return newMutationRetry(failure(operation, "AVAILABILITY"), exchange.retryAfterMs);
|
|
374
|
+
if (exchange.error === "tooLarge") return newMutationRetry(failure(operation, "RESPONSE_TOO_LARGE"));
|
|
375
|
+
if (exchange.error) return newMutationRetry(failure(operation, "TRANSPORT"));
|
|
376
|
+
return void 0;
|
|
377
|
+
}
|
|
378
|
+
function indexFailure(branch, kind) {
|
|
379
|
+
return newMutationBranch(branch, emptyIndexed, {}, failure("indexDocument", kind));
|
|
380
|
+
}
|
|
381
|
+
function isTerminalCredentialError(error) {
|
|
382
|
+
return isCredentialMaterialError(error) || error instanceof ReauthorizationRequiredError || error instanceof ObjectNotFoundError || error instanceof ConnectionNotSelectedError || error instanceof CredentialBrokerRejectedError;
|
|
383
|
+
}
|
|
384
|
+
function isDefiniteRefusalStatus(status) {
|
|
385
|
+
return [400, 401, 403, 404, 411, 413, 414, 415, 422].includes(status);
|
|
386
|
+
}
|
|
387
|
+
function indexRetry(kind) {
|
|
388
|
+
return newMutationRetry(failure("indexDocument", kind));
|
|
389
|
+
}
|
|
390
|
+
function deleteFailure(branch, kind) {
|
|
391
|
+
return newMutationBranch(branch, emptyDeleted, {}, failure("deleteDocument", kind));
|
|
392
|
+
}
|
|
393
|
+
function deleteRetry(kind) {
|
|
394
|
+
return newMutationRetry(failure("deleteDocument", kind));
|
|
395
|
+
}
|
|
396
|
+
function searchFailure(branch, kind) {
|
|
397
|
+
return newQueryBranch(branch, emptyPage, {}, failure("searchDocuments", kind));
|
|
398
|
+
}
|
|
399
|
+
function searchRetry(kind, after = 0) {
|
|
400
|
+
return newQueryRetry(failure("searchDocuments", kind), after);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/project.ts
|
|
404
|
+
var settingsSchema = z.strictObject({
|
|
405
|
+
clusterUrl: z.string(),
|
|
406
|
+
timeout: z.union([z.string(), z.number().int()]).optional(),
|
|
407
|
+
maxResponseBytes: z.number().int().optional(),
|
|
408
|
+
maxDocumentBytes: z.number().int().optional()
|
|
409
|
+
});
|
|
410
|
+
function newProjectConnection2(project, connectionName, options = {}) {
|
|
411
|
+
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
412
|
+
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "elasticsearch" && entry.connectionName === name);
|
|
413
|
+
if (!selected) throw new TypeError("Elasticsearch project connection is not configured");
|
|
414
|
+
const settings = settingsSchema.parse(selected.configuration);
|
|
415
|
+
const timeoutMs = typeof settings.timeout === "number" ? Math.ceil(settings.timeout / 1e6) : settings.timeout !== void 0 ? parseDurationMilliseconds(settings.timeout) : void 0;
|
|
416
|
+
const config = {
|
|
417
|
+
clusterUrl: settings.clusterUrl,
|
|
418
|
+
...timeoutMs !== void 0 ? { timeoutMs } : {},
|
|
419
|
+
...settings.maxResponseBytes !== void 0 ? { maxResponseBytes: settings.maxResponseBytes } : {},
|
|
420
|
+
...settings.maxDocumentBytes !== void 0 ? { maxDocumentBytes: settings.maxDocumentBytes } : {}
|
|
421
|
+
};
|
|
422
|
+
const credentials = {
|
|
423
|
+
async resolve(call, signal) {
|
|
424
|
+
void call;
|
|
425
|
+
return decodeCredentials(await loadedProject.resolveCredential("elasticsearch", name, signal));
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
return new ElasticsearchClient(config, credentials, options);
|
|
429
|
+
});
|
|
430
|
+
}
|
|
431
|
+
function parseDurationMilliseconds(value) {
|
|
432
|
+
let remaining = value;
|
|
433
|
+
let milliseconds = 0;
|
|
434
|
+
const units = {
|
|
435
|
+
ns: 1e-6,
|
|
436
|
+
us: 1e-3,
|
|
437
|
+
"\xB5s": 1e-3,
|
|
438
|
+
ms: 1,
|
|
439
|
+
s: 1e3,
|
|
440
|
+
m: 6e4,
|
|
441
|
+
h: 36e5
|
|
442
|
+
};
|
|
443
|
+
while (remaining) {
|
|
444
|
+
const component = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
|
|
445
|
+
if (!component) throw new TypeError("Elasticsearch timeout must be a positive Go duration");
|
|
446
|
+
milliseconds += Number(component[1]) * (units[component[2] ?? ""] ?? NaN);
|
|
447
|
+
remaining = remaining.slice(component[0].length);
|
|
448
|
+
}
|
|
449
|
+
if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0)
|
|
450
|
+
throw new TypeError("Elasticsearch timeout must resolve to positive whole milliseconds");
|
|
451
|
+
return milliseconds;
|
|
452
|
+
}
|
|
453
|
+
export {
|
|
454
|
+
ConfigSchema,
|
|
455
|
+
Connection,
|
|
456
|
+
ConnectorID,
|
|
457
|
+
CredentialMaterialError,
|
|
458
|
+
DeleteDocumentBranch,
|
|
459
|
+
DeleteDocumentBranchAbsent,
|
|
460
|
+
DeleteDocumentBranchDefect,
|
|
461
|
+
DeleteDocumentBranchIndexNotFound,
|
|
462
|
+
DeleteDocumentBranchProviderRejected,
|
|
463
|
+
DeleteDocumentDefinition,
|
|
464
|
+
DeleteDocumentInputSchema,
|
|
465
|
+
DeleteDocumentMetadata,
|
|
466
|
+
DeleteDocumentOperation,
|
|
467
|
+
DeletedDocumentSchema,
|
|
468
|
+
ElasticsearchClient,
|
|
469
|
+
IndexDocumentBranch,
|
|
470
|
+
IndexDocumentBranchDefect,
|
|
471
|
+
IndexDocumentBranchIndexed,
|
|
472
|
+
IndexDocumentBranchProviderRejected,
|
|
473
|
+
IndexDocumentDefinition,
|
|
474
|
+
IndexDocumentInputSchema,
|
|
475
|
+
IndexDocumentMetadata,
|
|
476
|
+
IndexDocumentOperation,
|
|
477
|
+
IndexedDocumentSchema,
|
|
478
|
+
ProviderID,
|
|
479
|
+
SearchDocumentsBranch,
|
|
480
|
+
SearchDocumentsBranchDefect,
|
|
481
|
+
SearchDocumentsBranchFound,
|
|
482
|
+
SearchDocumentsBranchIndexNotFound,
|
|
483
|
+
SearchDocumentsBranchInvalidResponse,
|
|
484
|
+
SearchDocumentsBranchProviderRejected,
|
|
485
|
+
SearchDocumentsDefinition,
|
|
486
|
+
SearchDocumentsInputSchema,
|
|
487
|
+
SearchDocumentsMetadata,
|
|
488
|
+
SearchDocumentsOperation,
|
|
489
|
+
SearchHitSchema,
|
|
490
|
+
SearchPageSchema,
|
|
491
|
+
decodeCredentials,
|
|
492
|
+
isCredentialMaterialError,
|
|
493
|
+
newConnection,
|
|
494
|
+
newConnectionWithOperations,
|
|
495
|
+
newDeleteDocumentStep,
|
|
496
|
+
newIndexDocumentStep,
|
|
497
|
+
newProjectConnection2 as newProjectConnection,
|
|
498
|
+
newSearchDocumentsStep
|
|
499
|
+
};
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { MockMutation, MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
|
+
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
+
import { O as Operations, C as Connection, I as IndexDocumentInput, b as IndexedDocument, D as DeleteDocumentInput, a as DeletedDocument, S as SearchDocumentsInput, c as SearchPage, n as SearchHit } from './connection-Du7eKAvn.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/** Go zero value for IndexDocumentInput in scripted cases. */
|
|
7
|
+
declare const emptyIndexDocumentInput: IndexDocumentInput;
|
|
8
|
+
/** Go zero value for IndexedDocument in scripted cases. */
|
|
9
|
+
declare const emptyIndexedDocument: IndexedDocument;
|
|
10
|
+
/** Go zero value for DeleteDocumentInput in scripted cases. */
|
|
11
|
+
declare const emptyDeleteDocumentInput: DeleteDocumentInput;
|
|
12
|
+
/** Go zero value for DeletedDocument in scripted cases. */
|
|
13
|
+
declare const emptyDeletedDocument: DeletedDocument;
|
|
14
|
+
/** Go zero value for SearchDocumentsInput in scripted cases. */
|
|
15
|
+
declare const emptySearchDocumentsInput: SearchDocumentsInput;
|
|
16
|
+
/** Go zero value for SearchHit in scripted cases. */
|
|
17
|
+
declare const emptySearchHit: SearchHit;
|
|
18
|
+
/** Go zero value for SearchPage in scripted cases. */
|
|
19
|
+
declare const emptySearchPage: SearchPage;
|
|
20
|
+
/** Script the indexed branch. */
|
|
21
|
+
declare function indexDocumentIndexed(value: IndexedDocument, failure?: Failure): Case<IndexedDocument>;
|
|
22
|
+
/** Script the providerRejected branch. */
|
|
23
|
+
declare function indexDocumentProviderRejected(value: IndexedDocument, failure?: Failure): Case<IndexedDocument>;
|
|
24
|
+
/** Script the defect branch. */
|
|
25
|
+
declare function indexDocumentDefect(value: IndexedDocument, failure?: Failure): Case<IndexedDocument>;
|
|
26
|
+
/** Script a safe retry of indexDocument. */
|
|
27
|
+
declare function indexDocumentRetry(failure: Failure, retryAfterMs?: number): Case<IndexedDocument>;
|
|
28
|
+
/** Manifest scenario indexedProduct for indexDocument. */
|
|
29
|
+
declare function indexDocumentIndexedProduct(): Case<IndexedDocument>;
|
|
30
|
+
/** Default indexDocument scenario. */
|
|
31
|
+
declare function indexDocumentDefault(): Case<IndexedDocument>;
|
|
32
|
+
/** Script the absent branch. */
|
|
33
|
+
declare function deleteDocumentAbsent(value: DeletedDocument, failure?: Failure): Case<DeletedDocument>;
|
|
34
|
+
/** Script the indexNotFound branch. */
|
|
35
|
+
declare function deleteDocumentIndexNotFound(value: DeletedDocument, failure?: Failure): Case<DeletedDocument>;
|
|
36
|
+
/** Script the providerRejected branch. */
|
|
37
|
+
declare function deleteDocumentProviderRejected(value: DeletedDocument, failure?: Failure): Case<DeletedDocument>;
|
|
38
|
+
/** Script the defect branch. */
|
|
39
|
+
declare function deleteDocumentDefect(value: DeletedDocument, failure?: Failure): Case<DeletedDocument>;
|
|
40
|
+
/** Script a safe retry of deleteDocument. */
|
|
41
|
+
declare function deleteDocumentRetry(failure: Failure, retryAfterMs?: number): Case<DeletedDocument>;
|
|
42
|
+
/** Manifest scenario deletedProduct for deleteDocument. */
|
|
43
|
+
declare function deleteDocumentDeletedProduct(): Case<DeletedDocument>;
|
|
44
|
+
/** Default deleteDocument scenario. */
|
|
45
|
+
declare function deleteDocumentDefault(): Case<DeletedDocument>;
|
|
46
|
+
/** Script the found branch. */
|
|
47
|
+
declare function searchDocumentsFound(value: SearchPage, failure?: Failure): Case<SearchPage>;
|
|
48
|
+
/** Script the indexNotFound branch. */
|
|
49
|
+
declare function searchDocumentsIndexNotFound(value: SearchPage, failure?: Failure): Case<SearchPage>;
|
|
50
|
+
/** Script the providerRejected branch. */
|
|
51
|
+
declare function searchDocumentsProviderRejected(value: SearchPage, failure?: Failure): Case<SearchPage>;
|
|
52
|
+
/** Script the invalidResponse branch. */
|
|
53
|
+
declare function searchDocumentsInvalidResponse(value: SearchPage, failure?: Failure): Case<SearchPage>;
|
|
54
|
+
/** Script the defect branch. */
|
|
55
|
+
declare function searchDocumentsDefect(value: SearchPage, failure?: Failure): Case<SearchPage>;
|
|
56
|
+
/** Script a safe retry of searchDocuments. */
|
|
57
|
+
declare function searchDocumentsRetry(failure: Failure, retryAfterMs?: number): Case<SearchPage>;
|
|
58
|
+
/** Manifest scenario matchingDocument for searchDocuments. */
|
|
59
|
+
declare function searchDocumentsMatchingDocument(): Case<SearchPage>;
|
|
60
|
+
/** Default searchDocuments scenario. */
|
|
61
|
+
declare function searchDocumentsDefault(): Case<SearchPage>;
|
|
62
|
+
/** Scripted operations and manifest defaults for this connector. */
|
|
63
|
+
declare class GeneratedMock implements Operations {
|
|
64
|
+
#private;
|
|
65
|
+
constructor(connectionName: string);
|
|
66
|
+
connection(): Connection;
|
|
67
|
+
indexDocument(): MockMutation<IndexDocumentInput, IndexedDocument>;
|
|
68
|
+
deleteDocument(): MockMutation<DeleteDocumentInput, DeletedDocument>;
|
|
69
|
+
searchDocuments(): MockQuery<SearchDocumentsInput, SearchPage>;
|
|
70
|
+
assertNoFailures(): void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export { GeneratedMock, GeneratedMock as Mock, deleteDocumentAbsent, deleteDocumentDefault, deleteDocumentDefect, deleteDocumentDeletedProduct, deleteDocumentIndexNotFound, deleteDocumentProviderRejected, deleteDocumentRetry, emptyDeleteDocumentInput, emptyDeletedDocument, emptyIndexDocumentInput, emptyIndexedDocument, emptySearchDocumentsInput, emptySearchHit, emptySearchPage, indexDocumentDefault, indexDocumentDefect, indexDocumentIndexed, indexDocumentIndexedProduct, indexDocumentProviderRejected, indexDocumentRetry, searchDocumentsDefault, searchDocumentsDefect, searchDocumentsFound, searchDocumentsIndexNotFound, searchDocumentsInvalidResponse, searchDocumentsMatchingDocument, searchDocumentsProviderRejected, searchDocumentsRetry };
|