@superdurable/connector-elasticsearch 0.1.0 → 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/dex-connector.json +2 -2
- package/dist/{chunk-S7BMYXLB.js → chunk-5WBVTQWI.js} +22 -6
- package/dist/{connection-BpzhI70A.d.ts → connection-Du7eKAvn.d.ts} +7 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.js +32 -6
- package/dist/mock.d.ts +1 -1
- package/dist/mock.js +1 -1
- package/package.json +1 -1
package/dex-connector.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"connectorId": "elasticsearch",
|
|
3
|
-
"releaseTag": "connectors/elastic/elasticsearch/go/v0.1.
|
|
3
|
+
"releaseTag": "connectors/elastic/elasticsearch/go/v0.1.1",
|
|
4
4
|
"package": {
|
|
5
5
|
"ecosystem": "npm",
|
|
6
6
|
"name": "@superdurable/connector-elasticsearch",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.1"
|
|
8
8
|
},
|
|
9
9
|
"factories": [
|
|
10
10
|
{
|
|
@@ -7,17 +7,31 @@ var ConfigSchema = z.object({
|
|
|
7
7
|
"maxResponseBytes": z.number().int().optional(),
|
|
8
8
|
"maxDocumentBytes": z.number().int().optional()
|
|
9
9
|
});
|
|
10
|
+
var CredentialMaterialError = class extends TypeError {
|
|
11
|
+
constructor(message) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.name = "CredentialMaterialError";
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
|
|
17
|
+
"project credential decoding failed",
|
|
18
|
+
"shared project credential decoding failed",
|
|
19
|
+
"project credential decoding failed: this connector version does not support shared credentials"
|
|
20
|
+
]);
|
|
21
|
+
function isCredentialMaterialError(error) {
|
|
22
|
+
return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
|
|
23
|
+
}
|
|
10
24
|
function decodeCredentials(value) {
|
|
11
|
-
if (!value || typeof value !== "object" || Array.isArray(value)) throw new
|
|
25
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
|
|
12
26
|
const fields = value;
|
|
13
27
|
const allowed = /* @__PURE__ */ new Set(["password", "username"]);
|
|
14
|
-
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new
|
|
15
|
-
if (fields["password"] != null && !(typeof fields["password"] === "string")) throw new
|
|
16
|
-
if (fields["username"] != null && !(typeof fields["username"] === "string")) throw new
|
|
28
|
+
if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
|
|
29
|
+
if (fields["password"] != null && !(typeof fields["password"] === "string")) throw new CredentialMaterialError("credential password has an invalid type");
|
|
30
|
+
if (fields["username"] != null && !(typeof fields["username"] === "string")) throw new CredentialMaterialError("credential username has an invalid type");
|
|
17
31
|
const credentials = {};
|
|
18
|
-
if (!fields["username"]) throw new
|
|
32
|
+
if (!fields["username"]) throw new CredentialMaterialError("credential username is required");
|
|
19
33
|
credentials.username = fields["username"] ?? "";
|
|
20
|
-
if (!fields["password"]) throw new
|
|
34
|
+
if (!fields["password"]) throw new CredentialMaterialError("credential password is required");
|
|
21
35
|
credentials.password = new SecretString(fields["password"] ?? "");
|
|
22
36
|
return credentials;
|
|
23
37
|
}
|
|
@@ -156,6 +170,8 @@ function newProjectConnection(project, connectionName, createClient) {
|
|
|
156
170
|
|
|
157
171
|
export {
|
|
158
172
|
ConfigSchema,
|
|
173
|
+
CredentialMaterialError,
|
|
174
|
+
isCredentialMaterialError,
|
|
159
175
|
decodeCredentials,
|
|
160
176
|
IndexDocumentInputSchema,
|
|
161
177
|
IndexedDocumentSchema,
|
|
@@ -26,6 +26,12 @@ interface Credentials {
|
|
|
26
26
|
/** Non-secret native username from https://cloud.elastic.co/ > deployment > Open Kibana > Stack Management > Security > Users > Create user, or the same page in self-managed Kibana. Enter the exact username with index read, index, or delete privileges. Blank prevents calls. */
|
|
27
27
|
username: string;
|
|
28
28
|
}
|
|
29
|
+
/** Stored credential material that fails the connector credential checks, so no retry can succeed. */
|
|
30
|
+
declare class CredentialMaterialError extends TypeError {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
/** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
|
|
34
|
+
declare function isCredentialMaterialError(error: unknown): boolean;
|
|
29
35
|
/** Decode private credential fields for the connector. */
|
|
30
36
|
declare function decodeCredentials(value: unknown): Credentials;
|
|
31
37
|
/** Host-owned source of private connector credentials. */
|
|
@@ -164,4 +170,4 @@ declare function newConnection(client: Operations, reference: ConnectionRef): Co
|
|
|
164
170
|
/** Bind scripted operations to a named connection. */
|
|
165
171
|
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
166
172
|
|
|
167
|
-
export { Connection as C, type DeleteDocumentInput as D, type IndexDocumentInput as I, type Operations as O, type SearchDocumentsInput as S, type DeletedDocument as a, type IndexedDocument as b, type SearchPage as c, type Config as d, type Credentials as e, ConfigSchema as f, type CredentialSource as
|
|
173
|
+
export { Connection as C, type DeleteDocumentInput as D, type IndexDocumentInput as I, type Operations as O, type SearchDocumentsInput as S, type DeletedDocument as a, type IndexedDocument as b, type SearchPage as c, type Config as d, type Credentials as e, ConfigSchema as f, CredentialMaterialError as g, type CredentialSource as h, DeleteDocumentInputSchema as i, DeletedDocumentSchema as j, IndexDocumentInputSchema as k, IndexedDocumentSchema as l, SearchDocumentsInputSchema as m, type SearchHit as n, SearchHitSchema as o, SearchPageSchema as p, decodeCredentials as q, isCredentialMaterialError as r, newConnection as s, newConnectionWithOperations as t };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DeleteDocumentInput, a as DeletedDocument, C as Connection, I as IndexDocumentInput, b as IndexedDocument, S as SearchDocumentsInput, c as SearchPage, d as Config, e as Credentials, O as Operations } from './connection-
|
|
2
|
-
export { f as ConfigSchema, g as
|
|
1
|
+
import { D as DeleteDocumentInput, a as DeletedDocument, C as Connection, I as IndexDocumentInput, b as IndexedDocument, S as SearchDocumentsInput, c as SearchPage, d as Config, e as Credentials, O as Operations } from './connection-Du7eKAvn.js';
|
|
2
|
+
export { f as ConfigSchema, g as CredentialMaterialError, h as CredentialSource, i as DeleteDocumentInputSchema, j as DeletedDocumentSchema, k as IndexDocumentInputSchema, l as IndexedDocumentSchema, m as SearchDocumentsInputSchema, n as SearchHit, o as SearchHitSchema, p as SearchPageSchema, q as decodeCredentials, r as isCredentialMaterialError, s as newConnection, t as newConnectionWithOperations } from './connection-Du7eKAvn.js';
|
|
3
3
|
import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
|
|
4
4
|
import { MutationDefinition, QueryDefinition, MutationStepConfig, Mutation, MutationResult, QueryStepConfig, Query, QueryResult, MutationStep, QueryStep, CredentialProvider, Call, MutationAttempt, QueryAttempt } from '@superdurable/connectors-sdk';
|
|
5
5
|
import { StepTarget } from '@superdurable/dex';
|
|
@@ -169,6 +169,8 @@ declare class ElasticsearchClient {
|
|
|
169
169
|
/** Bind the bounded search Query. */ searchDocuments(): SearchDocumentsOperation;
|
|
170
170
|
/** Resolve Basic authorization without returning credentials in failures. */
|
|
171
171
|
authorization(call: Call): Promise<string | undefined>;
|
|
172
|
+
/** Return null for a transient credential failure and undefined for a terminal or invalid one. */
|
|
173
|
+
private resolveAuthorization;
|
|
172
174
|
/** Send one bounded request without automatic redirects. */
|
|
173
175
|
exchange(call: Call, method: 'GET' | 'PUT' | 'DELETE', url: string, headers: Record<string, string>, body?: Uint8Array): Promise<ElasticsearchExchange>;
|
|
174
176
|
private retryAfter;
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
ConfigSchema,
|
|
3
3
|
Connection,
|
|
4
4
|
ConnectorID,
|
|
5
|
+
CredentialMaterialError,
|
|
5
6
|
DeleteDocumentBranch,
|
|
6
7
|
DeleteDocumentBranchAbsent,
|
|
7
8
|
DeleteDocumentBranchDefect,
|
|
@@ -32,10 +33,11 @@ import {
|
|
|
32
33
|
SearchHitSchema,
|
|
33
34
|
SearchPageSchema,
|
|
34
35
|
decodeCredentials,
|
|
36
|
+
isCredentialMaterialError,
|
|
35
37
|
newConnection,
|
|
36
38
|
newConnectionWithOperations,
|
|
37
39
|
newProjectConnection
|
|
38
|
-
} from "./chunk-
|
|
40
|
+
} from "./chunk-5WBVTQWI.js";
|
|
39
41
|
|
|
40
42
|
// src/generated/steps.ts
|
|
41
43
|
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
@@ -78,8 +80,10 @@ import {
|
|
|
78
80
|
newMutationBranch,
|
|
79
81
|
newMutationRetry,
|
|
80
82
|
newQueryBranch,
|
|
81
|
-
newQueryRetry
|
|
83
|
+
newQueryRetry,
|
|
84
|
+
ReauthorizationRequiredError
|
|
82
85
|
} from "@superdurable/connectors-sdk";
|
|
86
|
+
import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
|
|
83
87
|
import {
|
|
84
88
|
BodyTooLargeError,
|
|
85
89
|
ProviderTransportError,
|
|
@@ -128,8 +132,17 @@ var ElasticsearchClient = class {
|
|
|
128
132
|
}
|
|
129
133
|
/** Resolve Basic authorization without returning credentials in failures. */
|
|
130
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
|
+
}
|
|
131
145
|
try {
|
|
132
|
-
const credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
133
146
|
const username = credentials.username;
|
|
134
147
|
const password = credentials.password.reveal();
|
|
135
148
|
if (!username || /[:\r\n\0]/.test(username) || !password || /[\r\n\0]/.test(password)) return void 0;
|
|
@@ -200,7 +213,8 @@ var IndexDocumentOperation = class {
|
|
|
200
213
|
return indexFailure("defect", "VALIDATION");
|
|
201
214
|
}
|
|
202
215
|
if (body.byteLength > this.client.maxDocumentBytes) return indexFailure("defect", "VALIDATION");
|
|
203
|
-
const authorization = await this.client
|
|
216
|
+
const authorization = await this.client["resolveAuthorization"](call);
|
|
217
|
+
if (authorization === null) return indexRetry("AVAILABILITY");
|
|
204
218
|
if (!authorization) return indexFailure("defect", "AUTHENTICATION");
|
|
205
219
|
const exchange = await this.client.exchange(
|
|
206
220
|
call,
|
|
@@ -216,6 +230,7 @@ var IndexDocumentOperation = class {
|
|
|
216
230
|
if (!isRecord(result) || result._index !== input.index || result._id !== input.documentId || result.result !== "created" && result.result !== "updated") return indexRetry("PROTOCOL");
|
|
217
231
|
return newMutationBranch("indexed", { index: input.index, id: input.documentId });
|
|
218
232
|
}
|
|
233
|
+
if (!isDefiniteRefusalStatus(exchange.status)) return indexRetry("AVAILABILITY");
|
|
219
234
|
return indexFailure("providerRejected", rejectionKind(exchange.status));
|
|
220
235
|
}
|
|
221
236
|
};
|
|
@@ -237,7 +252,8 @@ var DeleteDocumentOperation = class {
|
|
|
237
252
|
async invoke(call, input) {
|
|
238
253
|
if (!input || !validIndex(input.index) || !validDocumentID(input.documentId))
|
|
239
254
|
return deleteFailure("defect", "VALIDATION");
|
|
240
|
-
const authorization = await this.client
|
|
255
|
+
const authorization = await this.client["resolveAuthorization"](call);
|
|
256
|
+
if (authorization === null) return deleteRetry("AVAILABILITY");
|
|
241
257
|
if (!authorization) return deleteFailure("defect", "AUTHENTICATION");
|
|
242
258
|
const exchange = await this.client.exchange(
|
|
243
259
|
call,
|
|
@@ -260,6 +276,7 @@ var DeleteDocumentOperation = class {
|
|
|
260
276
|
wasDeleted: result.result === "deleted"
|
|
261
277
|
});
|
|
262
278
|
}
|
|
279
|
+
if (!isDefiniteRefusalStatus(exchange.status)) return deleteRetry("AVAILABILITY");
|
|
263
280
|
return deleteFailure("providerRejected", rejectionKind(exchange.status));
|
|
264
281
|
}
|
|
265
282
|
};
|
|
@@ -279,7 +296,8 @@ var SearchDocumentsOperation = class {
|
|
|
279
296
|
const from = input?.from ?? 0;
|
|
280
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)
|
|
281
298
|
return searchFailure("defect", "VALIDATION");
|
|
282
|
-
const authorization = await this.client
|
|
299
|
+
const authorization = await this.client["resolveAuthorization"](call);
|
|
300
|
+
if (authorization === null) return searchRetry("AVAILABILITY");
|
|
283
301
|
if (!authorization) return searchFailure("defect", "AUTHENTICATION");
|
|
284
302
|
const query = new URLSearchParams({
|
|
285
303
|
q: input.query,
|
|
@@ -360,6 +378,12 @@ function documentRetry(exchange, operation) {
|
|
|
360
378
|
function indexFailure(branch, kind) {
|
|
361
379
|
return newMutationBranch(branch, emptyIndexed, {}, failure("indexDocument", kind));
|
|
362
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
|
+
}
|
|
363
387
|
function indexRetry(kind) {
|
|
364
388
|
return newMutationRetry(failure("indexDocument", kind));
|
|
365
389
|
}
|
|
@@ -430,6 +454,7 @@ export {
|
|
|
430
454
|
ConfigSchema,
|
|
431
455
|
Connection,
|
|
432
456
|
ConnectorID,
|
|
457
|
+
CredentialMaterialError,
|
|
433
458
|
DeleteDocumentBranch,
|
|
434
459
|
DeleteDocumentBranchAbsent,
|
|
435
460
|
DeleteDocumentBranchDefect,
|
|
@@ -464,6 +489,7 @@ export {
|
|
|
464
489
|
SearchHitSchema,
|
|
465
490
|
SearchPageSchema,
|
|
466
491
|
decodeCredentials,
|
|
492
|
+
isCredentialMaterialError,
|
|
467
493
|
newConnection,
|
|
468
494
|
newConnectionWithOperations,
|
|
469
495
|
newDeleteDocumentStep,
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MockMutation, MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
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,
|
|
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
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/** Go zero value for IndexDocumentInput in scripted cases. */
|
package/dist/mock.js
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
SearchHitSchema,
|
|
12
12
|
SearchPageSchema,
|
|
13
13
|
newConnectionWithOperations
|
|
14
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-5WBVTQWI.js";
|
|
15
15
|
|
|
16
16
|
// src/generated/mock.ts
|
|
17
17
|
import { branchCase, retryCase, newMutation, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
package/package.json
CHANGED