@xylex-group/athena 2.3.0 → 2.4.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 +124 -106
- package/dist/browser.cjs +584 -99
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +7 -7
- package/dist/browser.d.ts +7 -7
- package/dist/browser.js +583 -100
- package/dist/browser.js.map +1 -1
- package/dist/cli/index.cjs +573 -97
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.d.cts +3 -3
- package/dist/cli/index.d.ts +3 -3
- package/dist/cli/index.js +573 -97
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +584 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -7
- package/dist/index.d.ts +7 -7
- package/dist/index.js +583 -100
- package/dist/index.js.map +1 -1
- package/dist/{model-form-BpDXlbxb.d.ts → model-form-C0FAbOaf.d.ts} +1 -1
- package/dist/{model-form-hoE2jHIi.d.cts → model-form-GzTqhEzM.d.cts} +1 -1
- package/dist/{pipeline-BNIw8pDQ.d.ts → pipeline-CR4V15jF.d.ts} +1 -1
- package/dist/{pipeline-DNIpEsN8.d.cts → pipeline-DZeExYMA.d.cts} +1 -1
- package/dist/{react-email-BvyCZnfW.d.cts → react-email-BuApZuyG.d.ts} +19 -6
- package/dist/{react-email-qPA1wjFV.d.ts → react-email-CQJq92zQ.d.cts} +19 -6
- package/dist/react.cjs +249 -12
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +4 -4
- package/dist/react.d.ts +4 -4
- package/dist/react.js +249 -12
- package/dist/react.js.map +1 -1
- package/dist/{types-A5e97acl.d.cts → types-09Q4D86N.d.cts} +23 -2
- package/dist/{types-A5e97acl.d.ts → types-09Q4D86N.d.ts} +23 -2
- package/dist/{types-bDlr4u7p.d.cts → types-D1JvL21V.d.cts} +1 -1
- package/dist/{types-BnD22-vb.d.ts → types-DU3gNdFv.d.ts} +1 -1
- package/package.json +40 -40
package/dist/react.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import { aj as AthenaAuthFetchCompatibleInput, b as AthenaAuthCallOptions, L as AthenaAuthSessionResponse, m as AthenaAuthErrorDetails, H as AthenaAuthResult } from './model-form-
|
|
4
|
-
export { _ as AthenaGatewayError, a9 as ModelFormAdapter, aa as ModelFormDefaults, ab as ModelFormNullishMode, ac as ModelFormValues, ad as ToModelFormDefaultsOptions, ae as ToModelPayloadOptions, af as createModelFormAdapter, ag as isAthenaGatewayError, ah as toModelFormDefaults, ai as toModelPayload } from './model-form-
|
|
1
|
+
import { O as AthenaGatewayHookConfig, P as AthenaGatewayHookResult } from './types-09Q4D86N.cjs';
|
|
2
|
+
export { Q as AthenaDeletePayload, V as AthenaFetchPayload, a as AthenaGatewayCallOptions, d as AthenaGatewayErrorCode, e as AthenaGatewayErrorDetails, W as AthenaGatewayResponse, X as AthenaInsertPayload, f as AthenaJsonArray, g as AthenaJsonObject, h as AthenaJsonPrimitive, i as AthenaJsonValue, j as AthenaRpcCallOptions, k as AthenaRpcFilter, l as AthenaRpcFilterOperator, m as AthenaRpcOrder, n as AthenaRpcPayload, Y as AthenaUpdatePayload } from './types-09Q4D86N.cjs';
|
|
3
|
+
import { aj as AthenaAuthFetchCompatibleInput, b as AthenaAuthCallOptions, L as AthenaAuthSessionResponse, m as AthenaAuthErrorDetails, H as AthenaAuthResult } from './model-form-GzTqhEzM.cjs';
|
|
4
|
+
export { _ as AthenaGatewayError, a9 as ModelFormAdapter, aa as ModelFormDefaults, ab as ModelFormNullishMode, ac as ModelFormValues, ad as ToModelFormDefaultsOptions, ae as ToModelPayloadOptions, af as createModelFormAdapter, ag as isAthenaGatewayError, ah as toModelFormDefaults, ai as toModelPayload } from './model-form-GzTqhEzM.cjs';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
7
|
|
package/dist/react.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import { aj as AthenaAuthFetchCompatibleInput, b as AthenaAuthCallOptions, L as AthenaAuthSessionResponse, m as AthenaAuthErrorDetails, H as AthenaAuthResult } from './model-form-
|
|
4
|
-
export { _ as AthenaGatewayError, a9 as ModelFormAdapter, aa as ModelFormDefaults, ab as ModelFormNullishMode, ac as ModelFormValues, ad as ToModelFormDefaultsOptions, ae as ToModelPayloadOptions, af as createModelFormAdapter, ag as isAthenaGatewayError, ah as toModelFormDefaults, ai as toModelPayload } from './model-form-
|
|
1
|
+
import { O as AthenaGatewayHookConfig, P as AthenaGatewayHookResult } from './types-09Q4D86N.js';
|
|
2
|
+
export { Q as AthenaDeletePayload, V as AthenaFetchPayload, a as AthenaGatewayCallOptions, d as AthenaGatewayErrorCode, e as AthenaGatewayErrorDetails, W as AthenaGatewayResponse, X as AthenaInsertPayload, f as AthenaJsonArray, g as AthenaJsonObject, h as AthenaJsonPrimitive, i as AthenaJsonValue, j as AthenaRpcCallOptions, k as AthenaRpcFilter, l as AthenaRpcFilterOperator, m as AthenaRpcOrder, n as AthenaRpcPayload, Y as AthenaUpdatePayload } from './types-09Q4D86N.js';
|
|
3
|
+
import { aj as AthenaAuthFetchCompatibleInput, b as AthenaAuthCallOptions, L as AthenaAuthSessionResponse, m as AthenaAuthErrorDetails, H as AthenaAuthResult } from './model-form-C0FAbOaf.js';
|
|
4
|
+
export { _ as AthenaGatewayError, a9 as ModelFormAdapter, aa as ModelFormDefaults, ab as ModelFormNullishMode, ac as ModelFormValues, ad as ToModelFormDefaultsOptions, ae as ToModelPayloadOptions, af as createModelFormAdapter, ag as isAthenaGatewayError, ah as toModelFormDefaults, ai as toModelPayload } from './model-form-C0FAbOaf.js';
|
|
5
5
|
import * as react from 'react';
|
|
6
6
|
import { ReactNode } from 'react';
|
|
7
7
|
|
package/dist/react.js
CHANGED
|
@@ -63,8 +63,74 @@ function isAthenaGatewayError(error) {
|
|
|
63
63
|
return error instanceof AthenaGatewayError;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
+
// src/gateway/url.ts
|
|
67
|
+
var ATHENA_DEFAULT_BASE_URL = "https://athena-db.com";
|
|
68
|
+
function describeReceivedValue(value) {
|
|
69
|
+
if (value === void 0) return "undefined";
|
|
70
|
+
if (value === null) return "null";
|
|
71
|
+
if (typeof value === "string") {
|
|
72
|
+
return value.trim().length > 0 ? JSON.stringify(value) : "an empty string";
|
|
73
|
+
}
|
|
74
|
+
return `${typeof value} ${JSON.stringify(value)}`;
|
|
75
|
+
}
|
|
76
|
+
function invalidBaseUrlError(message, hint) {
|
|
77
|
+
return new AthenaGatewayError({
|
|
78
|
+
code: "INVALID_URL",
|
|
79
|
+
message,
|
|
80
|
+
status: 0,
|
|
81
|
+
hint
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function normalizeAthenaGatewayBaseUrl(input, options = {}) {
|
|
85
|
+
const label = options.label ?? "Athena gateway base URL";
|
|
86
|
+
const candidate = input ?? options.defaultBaseUrl;
|
|
87
|
+
if (candidate === void 0 || candidate === null) {
|
|
88
|
+
throw invalidBaseUrlError(
|
|
89
|
+
`${label} must be a non-empty absolute http(s) URL. Received ${describeReceivedValue(input)}.`,
|
|
90
|
+
'Set ATHENA_URL (or pass createClient(url, ...)) to a full URL such as "https://mirror3.athena-db.com".'
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const trimmed = candidate.trim();
|
|
94
|
+
if (!trimmed) {
|
|
95
|
+
throw invalidBaseUrlError(
|
|
96
|
+
`${label} must be a non-empty absolute http(s) URL. Received ${describeReceivedValue(candidate)}.`,
|
|
97
|
+
'Set ATHENA_URL (or pass createClient(url, ...)) to a full URL such as "https://mirror3.athena-db.com".'
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
let parsed;
|
|
101
|
+
try {
|
|
102
|
+
parsed = new URL(trimmed);
|
|
103
|
+
} catch {
|
|
104
|
+
throw invalidBaseUrlError(
|
|
105
|
+
`${label} must be a valid absolute http(s) URL. Received ${describeReceivedValue(candidate)}.`,
|
|
106
|
+
'Use a full URL including the protocol, for example "https://mirror3.athena-db.com".'
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
110
|
+
throw invalidBaseUrlError(
|
|
111
|
+
`${label} must use http or https. Received ${JSON.stringify(trimmed)}.`,
|
|
112
|
+
'Use an Athena gateway URL such as "https://mirror3.athena-db.com".'
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
if (parsed.search || parsed.hash) {
|
|
116
|
+
throw invalidBaseUrlError(
|
|
117
|
+
`${label} must not include query parameters or hash fragments. Received ${JSON.stringify(trimmed)}.`,
|
|
118
|
+
'Pass only the base URL. Endpoint paths such as "/gateway/fetch" are appended by the SDK.'
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
return parsed.toString().replace(/\/+$/, "");
|
|
122
|
+
}
|
|
123
|
+
function buildAthenaGatewayUrl(baseUrl, path) {
|
|
124
|
+
if (!path.startsWith("/")) {
|
|
125
|
+
throw invalidBaseUrlError(
|
|
126
|
+
`Athena gateway path must start with "/". Received ${JSON.stringify(path)}.`,
|
|
127
|
+
'Use a leading slash such as "/gateway/fetch" or "/".'
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
return `${baseUrl}${path}`;
|
|
131
|
+
}
|
|
132
|
+
|
|
66
133
|
// src/gateway/client.ts
|
|
67
|
-
var DEFAULT_BASE_URL = "https://athena-db.com";
|
|
68
134
|
var DEFAULT_CLIENT = "railway_direct";
|
|
69
135
|
var FALLBACK_SDK_VERSION = "1.3.0";
|
|
70
136
|
var SDK_NAME = "xylex-group/athena";
|
|
@@ -261,9 +327,168 @@ function buildHeaders(config, options) {
|
|
|
261
327
|
});
|
|
262
328
|
return headers;
|
|
263
329
|
}
|
|
330
|
+
function toInvalidUrlResponse(error, endpoint, method) {
|
|
331
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
332
|
+
const gatewayError = error instanceof AthenaGatewayError ? error : new AthenaGatewayError({
|
|
333
|
+
code: "INVALID_URL",
|
|
334
|
+
message,
|
|
335
|
+
status: 0,
|
|
336
|
+
endpoint,
|
|
337
|
+
method,
|
|
338
|
+
cause: message,
|
|
339
|
+
hint: "Set ATHENA_URL to a full http(s) URL before running queries."
|
|
340
|
+
});
|
|
341
|
+
return {
|
|
342
|
+
ok: false,
|
|
343
|
+
status: 0,
|
|
344
|
+
statusText: null,
|
|
345
|
+
data: null,
|
|
346
|
+
error: gatewayError.message,
|
|
347
|
+
errorDetails: detailsFromError(
|
|
348
|
+
new AthenaGatewayError({
|
|
349
|
+
code: gatewayError.code,
|
|
350
|
+
message: gatewayError.message,
|
|
351
|
+
status: gatewayError.status,
|
|
352
|
+
endpoint,
|
|
353
|
+
method,
|
|
354
|
+
requestId: gatewayError.requestId,
|
|
355
|
+
hint: gatewayError.hint,
|
|
356
|
+
cause: gatewayError.causeDetail
|
|
357
|
+
})
|
|
358
|
+
),
|
|
359
|
+
raw: null
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
function resolveGatewayBaseUrl(input) {
|
|
363
|
+
return normalizeAthenaGatewayBaseUrl(input, {
|
|
364
|
+
defaultBaseUrl: ATHENA_DEFAULT_BASE_URL
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
function resolveProbePath(path) {
|
|
368
|
+
if (!path) return "/";
|
|
369
|
+
if (!path.startsWith("/")) {
|
|
370
|
+
throw new AthenaGatewayError({
|
|
371
|
+
code: "INVALID_URL",
|
|
372
|
+
message: `Athena gateway probe path must start with "/". Received ${JSON.stringify(path)}.`,
|
|
373
|
+
status: 0,
|
|
374
|
+
hint: 'Use a leading slash such as "/" or "/health".'
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
return path;
|
|
378
|
+
}
|
|
379
|
+
function mergeConnectionHeaders(baseHeaders, headers) {
|
|
380
|
+
const merged = {
|
|
381
|
+
...baseHeaders,
|
|
382
|
+
...headers ?? {}
|
|
383
|
+
};
|
|
384
|
+
if (!merged["X-Athena-Sdk"] && !merged["x-athena-sdk"]) {
|
|
385
|
+
merged["X-Athena-Sdk"] = SDK_HEADER_VALUE;
|
|
386
|
+
}
|
|
387
|
+
return merged;
|
|
388
|
+
}
|
|
389
|
+
async function performConnectionCheck(baseUrl, requestHeaders, options) {
|
|
390
|
+
const path = resolveProbePath(options?.path);
|
|
391
|
+
const url = buildAthenaGatewayUrl(baseUrl, path);
|
|
392
|
+
try {
|
|
393
|
+
const response = await fetch(url, {
|
|
394
|
+
method: "GET",
|
|
395
|
+
headers: mergeConnectionHeaders(requestHeaders, options?.headers),
|
|
396
|
+
signal: options?.signal
|
|
397
|
+
});
|
|
398
|
+
const rawText = await response.text();
|
|
399
|
+
const requestId = resolveRequestId(response.headers);
|
|
400
|
+
const parsedBody = parseResponseBody(
|
|
401
|
+
rawText ?? "",
|
|
402
|
+
response.headers.get("content-type")
|
|
403
|
+
);
|
|
404
|
+
if (parsedBody.parseFailed) {
|
|
405
|
+
const invalidJsonError = new AthenaGatewayError({
|
|
406
|
+
code: "INVALID_JSON",
|
|
407
|
+
message: "Gateway probe returned malformed JSON",
|
|
408
|
+
status: response.status,
|
|
409
|
+
method: "GET",
|
|
410
|
+
requestId,
|
|
411
|
+
hint: "Verify the gateway response body is valid JSON.",
|
|
412
|
+
cause: rawText.slice(0, 300)
|
|
413
|
+
});
|
|
414
|
+
return {
|
|
415
|
+
ok: false,
|
|
416
|
+
reachable: true,
|
|
417
|
+
status: response.status,
|
|
418
|
+
statusText: resolveStatusText(response, parsedBody.parsed),
|
|
419
|
+
baseUrl,
|
|
420
|
+
url,
|
|
421
|
+
error: invalidJsonError.message,
|
|
422
|
+
errorDetails: detailsFromError(invalidJsonError),
|
|
423
|
+
raw: parsedBody.parsed
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
const parsed = parsedBody.parsed;
|
|
427
|
+
if (!response.ok) {
|
|
428
|
+
const httpError = new AthenaGatewayError({
|
|
429
|
+
code: "HTTP_ERROR",
|
|
430
|
+
message: resolveErrorMessage(
|
|
431
|
+
parsed,
|
|
432
|
+
`Athena gateway GET ${path} failed with status ${response.status}`
|
|
433
|
+
),
|
|
434
|
+
status: response.status,
|
|
435
|
+
method: "GET",
|
|
436
|
+
requestId,
|
|
437
|
+
hint: resolveErrorHint(parsed)
|
|
438
|
+
});
|
|
439
|
+
return {
|
|
440
|
+
ok: false,
|
|
441
|
+
reachable: true,
|
|
442
|
+
status: response.status,
|
|
443
|
+
statusText: resolveStatusText(response, parsed),
|
|
444
|
+
baseUrl,
|
|
445
|
+
url,
|
|
446
|
+
error: httpError.message,
|
|
447
|
+
errorDetails: detailsFromError(httpError),
|
|
448
|
+
raw: parsed
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
return {
|
|
452
|
+
ok: true,
|
|
453
|
+
reachable: true,
|
|
454
|
+
status: response.status,
|
|
455
|
+
statusText: resolveStatusText(response, parsed),
|
|
456
|
+
baseUrl,
|
|
457
|
+
url,
|
|
458
|
+
error: void 0,
|
|
459
|
+
errorDetails: null,
|
|
460
|
+
raw: parsed
|
|
461
|
+
};
|
|
462
|
+
} catch (callError) {
|
|
463
|
+
const message = callError instanceof Error ? callError.message : String(callError);
|
|
464
|
+
const networkError = new AthenaGatewayError({
|
|
465
|
+
code: "NETWORK_ERROR",
|
|
466
|
+
message: `Network error while probing Athena gateway ${url}: ${message}`,
|
|
467
|
+
method: "GET",
|
|
468
|
+
cause: message,
|
|
469
|
+
hint: "Check gateway URL, DNS, and network reachability."
|
|
470
|
+
});
|
|
471
|
+
return {
|
|
472
|
+
ok: false,
|
|
473
|
+
reachable: false,
|
|
474
|
+
status: 0,
|
|
475
|
+
statusText: null,
|
|
476
|
+
baseUrl,
|
|
477
|
+
url,
|
|
478
|
+
error: networkError.message,
|
|
479
|
+
errorDetails: detailsFromError(networkError),
|
|
480
|
+
raw: null
|
|
481
|
+
};
|
|
482
|
+
}
|
|
483
|
+
}
|
|
264
484
|
async function callAthena(config, endpoint, method, payload, options) {
|
|
265
|
-
|
|
266
|
-
|
|
485
|
+
let baseUrl;
|
|
486
|
+
try {
|
|
487
|
+
baseUrl = resolveGatewayBaseUrl(options?.baseUrl ?? config.baseUrl);
|
|
488
|
+
} catch (error) {
|
|
489
|
+
return toInvalidUrlResponse(error, endpoint, method);
|
|
490
|
+
}
|
|
491
|
+
const url = buildAthenaGatewayUrl(baseUrl, endpoint);
|
|
267
492
|
const headers = buildHeaders(config, options);
|
|
268
493
|
try {
|
|
269
494
|
const requestInit = {
|
|
@@ -360,32 +585,44 @@ async function callAthena(config, endpoint, method, payload, options) {
|
|
|
360
585
|
}
|
|
361
586
|
}
|
|
362
587
|
function createAthenaGatewayClient(config = {}) {
|
|
588
|
+
const normalizedBaseUrl = resolveGatewayBaseUrl(config.baseUrl);
|
|
589
|
+
const normalizedConfig = {
|
|
590
|
+
...config,
|
|
591
|
+
baseUrl: normalizedBaseUrl
|
|
592
|
+
};
|
|
363
593
|
return {
|
|
364
|
-
baseUrl:
|
|
594
|
+
baseUrl: normalizedBaseUrl,
|
|
365
595
|
buildHeaders(options) {
|
|
366
|
-
return buildHeaders(
|
|
596
|
+
return buildHeaders(normalizedConfig, options);
|
|
597
|
+
},
|
|
598
|
+
verifyConnection(options) {
|
|
599
|
+
return performConnectionCheck(
|
|
600
|
+
normalizedBaseUrl,
|
|
601
|
+
buildHeaders(normalizedConfig),
|
|
602
|
+
options
|
|
603
|
+
);
|
|
367
604
|
},
|
|
368
605
|
fetchGateway(payload, options) {
|
|
369
|
-
return callAthena(
|
|
606
|
+
return callAthena(normalizedConfig, "/gateway/fetch", "POST", payload, options);
|
|
370
607
|
},
|
|
371
608
|
insertGateway(payload, options) {
|
|
372
|
-
return callAthena(
|
|
609
|
+
return callAthena(normalizedConfig, "/gateway/insert", "PUT", payload, options);
|
|
373
610
|
},
|
|
374
611
|
updateGateway(payload, options) {
|
|
375
|
-
return callAthena(
|
|
612
|
+
return callAthena(normalizedConfig, "/gateway/update", "POST", payload, options);
|
|
376
613
|
},
|
|
377
614
|
deleteGateway(payload, options) {
|
|
378
|
-
return callAthena(
|
|
615
|
+
return callAthena(normalizedConfig, "/gateway/delete", "DELETE", payload, options);
|
|
379
616
|
},
|
|
380
617
|
rpcGateway(payload, options) {
|
|
381
618
|
if (options?.get) {
|
|
382
619
|
const endpoint = buildRpcGetEndpoint(payload);
|
|
383
|
-
return callAthena(
|
|
620
|
+
return callAthena(normalizedConfig, endpoint, "GET", null, options);
|
|
384
621
|
}
|
|
385
|
-
return callAthena(
|
|
622
|
+
return callAthena(normalizedConfig, "/gateway/rpc", "POST", payload, options);
|
|
386
623
|
},
|
|
387
624
|
queryGateway(payload, options) {
|
|
388
|
-
return callAthena(
|
|
625
|
+
return callAthena(normalizedConfig, "/gateway/query", "POST", payload, options);
|
|
389
626
|
}
|
|
390
627
|
};
|
|
391
628
|
}
|