@usearete/sdk 0.19.0 → 0.20.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/dist/index.cjs +46 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.esm.js +45 -2
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -512,6 +512,48 @@ const MIN_REFRESH_DELAY_MS = 1000;
|
|
|
512
512
|
const DEFAULT_QUERY_PARAMETER = 'hs_token';
|
|
513
513
|
const DEFAULT_HOSTED_TOKEN_ENDPOINT = 'https://api.arete.run/ws/sessions';
|
|
514
514
|
const HOSTED_WEBSOCKET_SUFFIX = '.stack.arete.run';
|
|
515
|
+
/**
|
|
516
|
+
* Extra suffixes treated as hosted Arete, beyond the default.
|
|
517
|
+
*
|
|
518
|
+
* A deployment can be served on a hostname outside the default suffix - the
|
|
519
|
+
* live service's test domain is the first - and a client that does not
|
|
520
|
+
* recognise it will not mint a session. It then connects unauthenticated and
|
|
521
|
+
* the host answers 401, which reads as a credential problem rather than an
|
|
522
|
+
* unrecognised hostname.
|
|
523
|
+
*
|
|
524
|
+
* Read from `ARETE_HOSTED_WEBSOCKET_SUFFIXES` where a process environment
|
|
525
|
+
* exists, and settable directly with `setHostedWebsocketSuffixes` for
|
|
526
|
+
* browsers, which have none.
|
|
527
|
+
*/
|
|
528
|
+
let extraHostedSuffixes = readHostedSuffixesFromEnvironment();
|
|
529
|
+
function normaliseHostedSuffix(entry) {
|
|
530
|
+
const trimmed = entry.trim().replace(/\.+$/, '').toLowerCase();
|
|
531
|
+
if (trimmed === '')
|
|
532
|
+
return undefined;
|
|
533
|
+
return trimmed.startsWith('.') ? trimmed : `.${trimmed}`;
|
|
534
|
+
}
|
|
535
|
+
function readHostedSuffixesFromEnvironment() {
|
|
536
|
+
const environment = globalThis
|
|
537
|
+
.process?.env;
|
|
538
|
+
const configured = environment?.['ARETE_HOSTED_WEBSOCKET_SUFFIXES'];
|
|
539
|
+
if (!configured)
|
|
540
|
+
return [];
|
|
541
|
+
return configured.split(',').flatMap((entry) => {
|
|
542
|
+
const suffix = normaliseHostedSuffix(entry);
|
|
543
|
+
return suffix === undefined ? [] : [suffix];
|
|
544
|
+
});
|
|
545
|
+
}
|
|
546
|
+
/** Replace the extra hosted suffixes. Pass `[]` to keep only the default. */
|
|
547
|
+
function setHostedWebsocketSuffixes(suffixes) {
|
|
548
|
+
extraHostedSuffixes = suffixes.flatMap((entry) => {
|
|
549
|
+
const suffix = normaliseHostedSuffix(entry);
|
|
550
|
+
return suffix === undefined ? [] : [suffix];
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
/** Every suffix treated as hosted Arete: the default plus any extras. */
|
|
554
|
+
function hostedWebsocketSuffixes() {
|
|
555
|
+
return [HOSTED_WEBSOCKET_SUFFIX, ...extraHostedSuffixes];
|
|
556
|
+
}
|
|
515
557
|
const MAX_HTTP_AUTH_TOKEN_STATES = 32;
|
|
516
558
|
function normalizeTokenResult(result) {
|
|
517
559
|
if (typeof result === 'string') {
|
|
@@ -640,7 +682,8 @@ function isSocketIssueMessage(value) {
|
|
|
640
682
|
}
|
|
641
683
|
function isHostedAreteEndpoint(url) {
|
|
642
684
|
try {
|
|
643
|
-
|
|
685
|
+
const hostname = new URL(url).hostname.toLowerCase().replace(/\.+$/, '');
|
|
686
|
+
return hostedWebsocketSuffixes().some((suffix) => hostname.endsWith(suffix));
|
|
644
687
|
}
|
|
645
688
|
catch {
|
|
646
689
|
return false;
|
|
@@ -7764,6 +7807,7 @@ exports.getOperationKind = getOperationKind;
|
|
|
7764
7807
|
exports.getProgramRuntimeExtensions = getProgramRuntimeExtensions;
|
|
7765
7808
|
exports.getStackRuntimeExtensions = getStackRuntimeExtensions;
|
|
7766
7809
|
exports.getTransactionFailureOutcome = getTransactionFailureOutcome;
|
|
7810
|
+
exports.hostedWebsocketSuffixes = hostedWebsocketSuffixes;
|
|
7767
7811
|
exports.inspectPreparedOperation = inspectPreparedOperation;
|
|
7768
7812
|
exports.instructionOperation = instructionOperation;
|
|
7769
7813
|
exports.isEntityFrame = isEntityFrame;
|
|
@@ -7796,6 +7840,7 @@ exports.resolveTransactionBuildOptions = resolveTransactionBuildOptions;
|
|
|
7796
7840
|
exports.safeToRawAmount = safeToRawAmount;
|
|
7797
7841
|
exports.serializeInstructionData = serializeInstructionData;
|
|
7798
7842
|
exports.serializeViewKey = serializeViewKey;
|
|
7843
|
+
exports.setHostedWebsocketSuffixes = setHostedWebsocketSuffixes;
|
|
7799
7844
|
exports.stackQuery = stackQuery;
|
|
7800
7845
|
exports.stringifyBigints = stringifyBigints;
|
|
7801
7846
|
exports.toJsonValue = toJsonValue;
|