@quintype/framework 7.30.9-host-to-api.0 → 7.30.9-host-to-api.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quintype/framework",
3
- "version": "7.30.9-host-to-api.0",
3
+ "version": "7.30.9-host-to-api.1",
4
4
  "description": "Libraries to help build Quintype Node.js apps",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -32,7 +32,7 @@
32
32
  "dependencies": {
33
33
  "@ampproject/toolbox-optimizer": "2.8.3",
34
34
  "@quintype/amp": "^2.20.0",
35
- "@quintype/backend": "2.6.0-host-to-api.1",
35
+ "@quintype/backend": "2.6.0-host-to-api.2",
36
36
  "@quintype/components": "^3.5.0",
37
37
  "@quintype/prerender-node": "^3.2.26",
38
38
  "@quintype/seo": "^1.46.1",
@@ -25,31 +25,35 @@ const {
25
25
  AmpConfig,
26
26
  } = require("./impl/api-client-impl");
27
27
 
28
+ let config = require("./publisher-config");
29
+
28
30
  const defaultClient = new Client(config.sketches_host);
29
31
  const cachedSecondaryClients = {};
30
32
 
31
- let config = require("./publisher-config");
32
-
33
33
  const xHostAPIToken = config["x_host_mapping_token"];
34
34
  const hostInternalDomain = config["x_host_internal_domain"];
35
35
  const enableSketchesHostResolution = config["x_enable_sketches_host_resolution"];
36
36
 
37
- if (enableSketchesHostResolution && xHostAPIToken && hostInternalDomain) {
38
- const hostMapping = {};
39
- const sketchesHostMapping = Client.getHostToAPIMappingCache(xHostAPIToken);
37
+ async function mappingHost() {
38
+ if (enableSketchesHostResolution && xHostAPIToken && hostInternalDomain) {
39
+ const hostMapping = {};
40
+ const sketchesHostMapping = await defaultClient.getHostToAPIMappingCache(xHostAPIToken);
40
41
 
41
- for (const [key, value] of Object.entries(sketchesHostMapping)) {
42
- hostMapping[key] = `http://${value}${hostInternalDomain}`;
43
- }
42
+ for (const [key, value] of Object.entries(sketchesHostMapping)) {
43
+ hostMapping[key] = `http://${value}${hostInternalDomain}`;
44
+ }
44
45
 
45
- config.host_to_api_host = { ...hostMapping, ...config["host_to_api_host"] };
46
+ config.host_to_api_host = { ...hostMapping, ...config["host_to_api_host"] };
47
+ }
46
48
  }
47
49
 
48
- function getClient(hostname) {
50
+ async function getClient(hostname) {
51
+ await mappingHost();
49
52
  return getClientImpl(config, cachedSecondaryClients, hostname) || defaultClient;
50
53
  }
51
54
 
52
- function initializeAllClients() {
55
+ async function initializeAllClients() {
56
+ await mappingHost();
53
57
  const promises = [defaultClient.getConfig()];
54
58
  if (!config.skip_warm_config) {
55
59
  Object.entries(config["host_to_api_host"] || []).forEach(([host, apiHost]) => {