@koralabs/kora-labs-common 6.11.0 → 6.12.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/chain/config.js
CHANGED
|
@@ -26,10 +26,20 @@ const chainConfigFromEnv = (env = process.env) => {
|
|
|
26
26
|
network: (0, providerConfig_1.normalizeNetwork)((_a = env.NETWORK) !== null && _a !== void 0 ? _a : 'mainnet'),
|
|
27
27
|
koiosBearerToken: ((_b = env.KOIOS_API_BEARER_TOKEN) === null || _b === void 0 ? void 0 : _b.trim()) || undefined,
|
|
28
28
|
blockfrostApiKey: ((_c = env.BLOCKFROST_API_KEY) === null || _c === void 0 ? void 0 : _c.trim()) || undefined,
|
|
29
|
-
apiHost: ((_d = env.HANDLE_API_ENDPOINT) === null || _d === void 0 ? void 0 : _d.trim()) || undefined
|
|
29
|
+
apiHost: ((_d = env.HANDLE_API_ENDPOINT) === null || _d === void 0 ? void 0 : _d.trim()) || undefined,
|
|
30
|
+
apiHeaders: buildApiHeaders(env)
|
|
30
31
|
});
|
|
31
32
|
};
|
|
32
33
|
exports.chainConfigFromEnv = chainConfigFromEnv;
|
|
34
|
+
const buildApiHeaders = (env) => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const headers = {};
|
|
37
|
+
if ((_a = env.HANDLE_ME_API_KEY) === null || _a === void 0 ? void 0 : _a.trim())
|
|
38
|
+
headers['api-key'] = env.HANDLE_ME_API_KEY.trim();
|
|
39
|
+
if ((_b = env.KORA_USER_AGENT) === null || _b === void 0 ? void 0 : _b.trim())
|
|
40
|
+
headers['User-Agent'] = env.KORA_USER_AGENT.trim();
|
|
41
|
+
return Object.keys(headers).length ? headers : undefined;
|
|
42
|
+
};
|
|
33
43
|
/**
|
|
34
44
|
* Factory for the default read-failover provider set: Koios + Blockfrost, mutually redundant.
|
|
35
45
|
*/
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { ICreatorDefaults } from '../../handles/interfaces';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export interface DatumDecodeOptions {
|
|
3
|
+
/** Extra request headers (e.g. api-key, User-Agent) required by the Handles API /datum endpoint. */
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
/** Injectable fetch for tests; defaults to the runtime global fetch. */
|
|
6
|
+
fetcher?: (url: string, init?: any) => Promise<{
|
|
7
|
+
text: () => Promise<string>;
|
|
8
|
+
}>;
|
|
9
|
+
}
|
|
10
|
+
export declare const decodeDatumViaApi: <T>(apiHost: string, datum: string, schema?: Record<string, unknown>, options?: DatumDecodeOptions) => Promise<T>;
|
|
5
11
|
export declare const decode0xHexToUtf8: (v: unknown) => unknown;
|
|
6
12
|
export declare const normalizeCreatorDefaultTextFields: (creatorDefaults: Record<string, unknown>) => void;
|
|
7
13
|
export interface ImageDatumDetails {
|
|
@@ -9,6 +15,4 @@ export interface ImageDatumDetails {
|
|
|
9
15
|
creatorDefaults?: ICreatorDefaults;
|
|
10
16
|
metadata?: Record<string, unknown>;
|
|
11
17
|
}
|
|
12
|
-
export declare const getImageDataFromDatum: (apiHost: string, datum: string,
|
|
13
|
-
text: () => Promise<string>;
|
|
14
|
-
}>) => Promise<ImageDatumDetails>;
|
|
18
|
+
export declare const getImageDataFromDatum: (apiHost: string, datum: string, options?: DatumDecodeOptions) => Promise<ImageDatumDetails>;
|
|
@@ -6,10 +6,12 @@ exports.getImageDataFromDatum = exports.normalizeCreatorDefaultTextFields = expo
|
|
|
6
6
|
// with a field schema so specific TEXT fields are UTF-8-decoded. This is handle-property-correctness
|
|
7
7
|
// critical — the schema and the 0x-hex fallback below must not drift.
|
|
8
8
|
const defaultFetch = (url, init) => globalThis.fetch(url, init);
|
|
9
|
-
const decodeDatumViaApi = async (apiHost, datum, schema,
|
|
9
|
+
const decodeDatumViaApi = async (apiHost, datum, schema, options = {}) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
const fetcher = (_a = options.fetcher) !== null && _a !== void 0 ? _a : defaultFetch;
|
|
10
12
|
const response = await fetcher(`${apiHost}/datum?from=plutus_data_cbor&to=json`, {
|
|
11
13
|
method: 'POST',
|
|
12
|
-
headers: { 'Content-Type': 'application/json' },
|
|
14
|
+
headers: { 'Content-Type': 'application/json', ...((_b = options.headers) !== null && _b !== void 0 ? _b : {}) },
|
|
13
15
|
body: JSON.stringify({ cbor: datum, schema })
|
|
14
16
|
});
|
|
15
17
|
const text = await response.text();
|
|
@@ -53,7 +55,7 @@ const normalizeCreatorDefaultTextFields = (creatorDefaults) => {
|
|
|
53
55
|
}
|
|
54
56
|
};
|
|
55
57
|
exports.normalizeCreatorDefaultTextFields = normalizeCreatorDefaultTextFields;
|
|
56
|
-
const getImageDataFromDatum = async (apiHost, datum,
|
|
58
|
+
const getImageDataFromDatum = async (apiHost, datum, options) => {
|
|
57
59
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
58
60
|
let decodedDatum;
|
|
59
61
|
try {
|
|
@@ -70,7 +72,7 @@ const getImageDataFromDatum = async (apiHost, datum, fetcher) => {
|
|
|
70
72
|
qr_image: 'string'
|
|
71
73
|
}
|
|
72
74
|
}
|
|
73
|
-
},
|
|
75
|
+
}, options);
|
|
74
76
|
}
|
|
75
77
|
catch (_j) {
|
|
76
78
|
return { image: '' };
|
|
@@ -16,6 +16,12 @@ export interface ChainProviderConfig {
|
|
|
16
16
|
* critical — do NOT swap it for a local CBOR decode without matching that behavior.
|
|
17
17
|
*/
|
|
18
18
|
apiHost?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Extra headers sent with the datum-decode POST to `apiHost` (e.g. `api-key`, `User-Agent`).
|
|
21
|
+
* Required when the Handles API gates `/datum` by api-key — omitting them silently changes
|
|
22
|
+
* datum-decode behavior. `chainConfigFromEnv` populates these from HANDLE_ME_API_KEY / KORA_USER_AGENT.
|
|
23
|
+
*/
|
|
24
|
+
apiHeaders?: Record<string, string>;
|
|
19
25
|
}
|
|
20
26
|
export declare const normalizeNetwork: (network: string) => string;
|
|
21
27
|
/** Public api.handle.me host for a network (mainnet has no subdomain prefix). */
|
|
@@ -118,7 +118,9 @@ class Blockfrost {
|
|
|
118
118
|
: hex;
|
|
119
119
|
const datum = await this.getAssetDatum(policyId, updateHex);
|
|
120
120
|
if (datum) {
|
|
121
|
-
return (0, imageDatum_1.getImageDataFromDatum)((_a = this.config.apiHost) !== null && _a !== void 0 ? _a : (0, providerConfig_1.defaultApiHost)(this.config.network), datum
|
|
121
|
+
return (0, imageDatum_1.getImageDataFromDatum)((_a = this.config.apiHost) !== null && _a !== void 0 ? _a : (0, providerConfig_1.defaultApiHost)(this.config.network), datum, {
|
|
122
|
+
headers: this.config.apiHeaders
|
|
123
|
+
});
|
|
122
124
|
}
|
|
123
125
|
let image = '';
|
|
124
126
|
if ((data === null || data === void 0 ? void 0 : data.onchain_metadata) && (data === null || data === void 0 ? void 0 : data.onchain_metadata.image)) {
|
package/chain/providers/Koios.js
CHANGED
|
@@ -180,7 +180,9 @@ class Koios {
|
|
|
180
180
|
if (metadata && metadata.image)
|
|
181
181
|
image = metadata.image;
|
|
182
182
|
if (datum) {
|
|
183
|
-
return (0, imageDatum_1.getImageDataFromDatum)((_a = this.config.apiHost) !== null && _a !== void 0 ? _a : (0, providerConfig_1.defaultApiHost)(this.config.network), datum
|
|
183
|
+
return (0, imageDatum_1.getImageDataFromDatum)((_a = this.config.apiHost) !== null && _a !== void 0 ? _a : (0, providerConfig_1.defaultApiHost)(this.config.network), datum, {
|
|
184
|
+
headers: this.config.apiHeaders
|
|
185
|
+
});
|
|
184
186
|
}
|
|
185
187
|
return { image, metadata };
|
|
186
188
|
}
|