@raytio/decrypt-helper 6.4.1 → 6.4.3
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/api/fetchInstanceData.js +3 -0
- package/dist/api/getLookupOption.d.ts +1 -1
- package/dist/api/getLookupOption.js +7 -6
- package/dist/api/getSchema.js +12 -3
- package/dist/helpers/formatOutput.js +1 -1
- package/dist/helpers/lookup.d.ts +1 -1
- package/dist/helpers/lookup.js +2 -2
- package/package.json +1 -1
|
@@ -11,6 +11,9 @@ import { authedFetch } from "./authedFetch.js";
|
|
|
11
11
|
export function fetchInstanceData(apiToken, envConfig, instanceId) {
|
|
12
12
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
13
|
const [instance] = yield authedFetch(apiToken, `${envConfig.api_url}/db/v1/dsm_access_application_instances?id=eq.${instanceId}`);
|
|
14
|
+
if (!instance) {
|
|
15
|
+
throw new Error(`Instance "${instanceId}" not found`);
|
|
16
|
+
}
|
|
14
17
|
return instance;
|
|
15
18
|
});
|
|
16
19
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Lookup } from "@raytio/types";
|
|
2
|
-
export declare function getLookupOption(apiToken: string, lookup: string): Promise<Lookup[]>;
|
|
2
|
+
export declare function getLookupOption(apiToken: string, lookup: string, apiBaseUrl?: string): Promise<Lookup[]>;
|
|
@@ -12,17 +12,18 @@ import { authedFetch } from "./authedFetch.js";
|
|
|
12
12
|
* We cache the promise so that only one XHR request is ever sent
|
|
13
13
|
*/
|
|
14
14
|
const cache = new Map();
|
|
15
|
-
export function getLookupOption(apiToken, lookup) {
|
|
15
|
+
export function getLookupOption(apiToken, lookup, apiBaseUrl) {
|
|
16
16
|
return __awaiter(this, void 0, void 0, function* () {
|
|
17
|
-
const
|
|
18
|
-
const
|
|
17
|
+
const resolvedLookup = lookup.startsWith("/") && apiBaseUrl ? `${apiBaseUrl}${lookup}` : lookup;
|
|
18
|
+
const { origin } = new URL(resolvedLookup);
|
|
19
|
+
const cached = cache.get(resolvedLookup);
|
|
19
20
|
if (cached)
|
|
20
21
|
return cached;
|
|
21
22
|
// if it's a lookup to our own API, then include the IdentityToken
|
|
22
23
|
const promise = origin.endsWith(".rayt.io")
|
|
23
|
-
? authedFetch(apiToken,
|
|
24
|
-
: fetch(
|
|
25
|
-
cache.set(
|
|
24
|
+
? authedFetch(apiToken, resolvedLookup)
|
|
25
|
+
: fetch(resolvedLookup).then((r) => r.json());
|
|
26
|
+
cache.set(resolvedLookup, promise);
|
|
26
27
|
return promise;
|
|
27
28
|
});
|
|
28
29
|
}
|
package/dist/api/getSchema.js
CHANGED
|
@@ -12,8 +12,17 @@ import { authedFetch } from "./authedFetch.js";
|
|
|
12
12
|
export function getAllSchema(envConfig) {
|
|
13
13
|
return __awaiter(this, void 0, void 0, function* () {
|
|
14
14
|
const list = yield authedFetch("", `${envConfig.api_url}/db/v1/dsm_schema?version_current=eq.true`);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
const expandedSchemas = [];
|
|
16
|
+
for (const wrappedSchema of list) {
|
|
17
|
+
try {
|
|
18
|
+
expandedSchemas.push(expandSchema(wrappedSchema, list, [
|
|
19
|
+
process.env.PDF_LANGUAGE || process.env.DATE_FORMAT || "en-NZ",
|
|
20
|
+
]));
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
console.warn(`Failed to expand schema "${wrappedSchema.schema_name}": ${error instanceof Error ? error.message : error}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return expandedSchemas;
|
|
18
27
|
});
|
|
19
28
|
}
|
|
@@ -53,7 +53,7 @@ export function formatOutput(profileObjects, allSchemas, realVers, apiToken, env
|
|
|
53
53
|
const accumulatorInner = yield accumulatorPromiseInner;
|
|
54
54
|
assertSafeProperty(key);
|
|
55
55
|
const prettyValue = typeof value === "string"
|
|
56
|
-
? yield maybeGetLookupValue(schema, key, value, apiToken)
|
|
56
|
+
? yield maybeGetLookupValue(schema, key, value, apiToken, envConfig.api_url)
|
|
57
57
|
: undefined;
|
|
58
58
|
const schemaField = Object.values(schema.properties || {}).find((f) => f.$prop.split(" <=> ")[0] === (key === null || key === void 0 ? void 0 : key.split(" <=> ")[0]));
|
|
59
59
|
const POInfo = {
|
package/dist/helpers/lookup.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Schema } from "@raytio/types";
|
|
2
|
-
export declare const maybeGetLookupValue: <T>(schema: Schema, k: string, value: T, apiToken: string) => Promise<string | number | T | undefined>;
|
|
2
|
+
export declare const maybeGetLookupValue: <T>(schema: Schema, k: string, value: T, apiToken: string, apiBaseUrl?: string) => Promise<string | number | T | undefined>;
|
package/dist/helpers/lookup.js
CHANGED
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { getLookupOption } from "../api/getLookupOption.js";
|
|
11
|
-
export const maybeGetLookupValue = (schema, k, value, apiToken) => __awaiter(void 0, void 0, void 0, function* () {
|
|
11
|
+
export const maybeGetLookupValue = (schema, k, value, apiToken, apiBaseUrl) => __awaiter(void 0, void 0, void 0, function* () {
|
|
12
12
|
var _a, _b, _c;
|
|
13
13
|
const lookupUrl = (_b = (_a = schema.properties) === null || _a === void 0 ? void 0 : _a[k]) === null || _b === void 0 ? void 0 : _b.lookup;
|
|
14
14
|
if (!lookupUrl)
|
|
@@ -26,6 +26,6 @@ export const maybeGetLookupValue = (schema, k, value, apiToken) => __awaiter(voi
|
|
|
26
26
|
.reduce((url, match, i) => { var _a; return url.replace(match, (_a = replaced === null || replaced === void 0 ? void 0 : replaced[i]) !== null && _a !== void 0 ? _a : ""); }, lookupUrl)
|
|
27
27
|
.replaceAll(/([^:]\/)\/+/g, "$1") // replaces doubles slashes (bar http://)
|
|
28
28
|
: lookupUrl;
|
|
29
|
-
const lookup = yield getLookupOption(apiToken, resolvedLookupUrl);
|
|
29
|
+
const lookup = yield getLookupOption(apiToken, resolvedLookupUrl, apiBaseUrl);
|
|
30
30
|
return (_c = lookup.find((l) => l.key === value)) === null || _c === void 0 ? void 0 : _c.value;
|
|
31
31
|
});
|