@backstage/config-loader 1.9.2 → 1.9.3-next.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/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @backstage/config-loader
2
2
 
3
+ ## 1.9.3-next.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+ - @backstage/errors@1.2.6-next.0
9
+ - @backstage/cli-common@0.1.15
10
+ - @backstage/config@1.3.1-next.0
11
+ - @backstage/types@1.2.0
12
+
13
+ ## 1.9.3-next.0
14
+
15
+ ### Patch Changes
16
+
17
+ - 5c9cc05: Use native fetch instead of node-fetch
18
+ - Updated dependencies
19
+ - @backstage/cli-common@0.1.15
20
+ - @backstage/config@1.3.0
21
+ - @backstage/errors@1.2.5
22
+ - @backstage/types@1.2.0
23
+
3
24
  ## 1.9.2
4
25
 
5
26
  ### Patch Changes
@@ -8,7 +8,6 @@ require('path');
8
8
  require('yaml');
9
9
  require('@backstage/types');
10
10
  require('lodash/isEqual');
11
- require('node-fetch');
12
11
 
13
12
  async function loadConfig(options) {
14
13
  const source = ConfigSources.ConfigSources.default({
@@ -1 +1 @@
1
- {"version":3,"file":"loader.cjs.js","sources":["../src/loader.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AppConfig } from '@backstage/config';\nimport { ConfigSources } from './sources';\n\n/**\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type ConfigTarget = { path: string } | { url: string };\n\n/**\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type LoadConfigOptionsWatch = {\n /**\n * A listener that is called when a config file is changed.\n */\n onChange: (configs: AppConfig[]) => void;\n\n /**\n * An optional signal that stops the watcher once the promise resolves.\n */\n stopSignal?: Promise<void>;\n};\n\n/**\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type LoadConfigOptionsRemote = {\n /**\n * A remote config reloading period, in seconds\n */\n reloadIntervalSeconds: number;\n};\n\n/**\n * Options that control the loading of configuration files in the backend.\n *\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type LoadConfigOptions = {\n // The root directory of the config loading context. Used to find default configs.\n configRoot: string;\n\n // Paths to load config files from. Configs from earlier paths have lower priority.\n configTargets: ConfigTarget[];\n\n /**\n * Custom environment variable loading function\n *\n * @experimental This API is not stable and may change at any point\n */\n experimentalEnvFunc?: (name: string) => Promise<string | undefined>;\n\n /**\n * An optional remote config\n */\n remote?: LoadConfigOptionsRemote;\n\n /**\n * An optional configuration that enables watching of config files.\n */\n watch?: LoadConfigOptionsWatch;\n};\n\n/**\n * Results of loading configuration files.\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type LoadConfigResult = {\n /**\n * Array of all loaded configs.\n */\n appConfigs: AppConfig[];\n};\n\n/**\n * Load configuration data.\n *\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport async function loadConfig(\n options: LoadConfigOptions,\n): Promise<LoadConfigResult> {\n const source = ConfigSources.default({\n substitutionFunc: options.experimentalEnvFunc,\n remote: options.remote && {\n reloadInterval: { seconds: options.remote.reloadIntervalSeconds },\n },\n watch: Boolean(options.watch),\n rootDir: options.configRoot,\n argv: options.configTargets.flatMap(t => [\n '--config',\n 'url' in t ? t.url : t.path,\n ]),\n });\n\n return new Promise<LoadConfigResult>((resolve, reject) => {\n async function loadConfigReaderLoop() {\n let loaded = false;\n\n try {\n const abortController = new AbortController();\n options.watch?.stopSignal?.then(() => abortController.abort());\n\n for await (const { configs } of source.readConfigData({\n signal: abortController.signal,\n })) {\n if (loaded) {\n options.watch?.onChange(configs);\n } else {\n resolve({ appConfigs: configs });\n loaded = true;\n\n if (options.watch) {\n options.watch.stopSignal?.then(() => abortController.abort());\n } else {\n abortController.abort();\n }\n }\n }\n } catch (error) {\n if (loaded) {\n console.error(`Failed to reload configuration, ${error}`);\n } else {\n reject(error);\n }\n }\n }\n loadConfigReaderLoop();\n });\n}\n"],"names":["ConfigSources"],"mappings":";;;;;;;;;;;;AAqGA,eAAsB,WACpB,OAC2B,EAAA;AAC3B,EAAM,MAAA,MAAA,GAASA,4BAAc,OAAQ,CAAA;AAAA,IACnC,kBAAkB,OAAQ,CAAA,mBAAA;AAAA,IAC1B,MAAA,EAAQ,QAAQ,MAAU,IAAA;AAAA,MACxB,cAAgB,EAAA,EAAE,OAAS,EAAA,OAAA,CAAQ,OAAO,qBAAsB;AAAA,KAClE;AAAA,IACA,KAAA,EAAO,OAAQ,CAAA,OAAA,CAAQ,KAAK,CAAA;AAAA,IAC5B,SAAS,OAAQ,CAAA,UAAA;AAAA,IACjB,IAAM,EAAA,OAAA,CAAQ,aAAc,CAAA,OAAA,CAAQ,CAAK,CAAA,KAAA;AAAA,MACvC,UAAA;AAAA,MACA,KAAS,IAAA,CAAA,GAAI,CAAE,CAAA,GAAA,GAAM,CAAE,CAAA;AAAA,KACxB;AAAA,GACF,CAAA;AAED,EAAA,OAAO,IAAI,OAAA,CAA0B,CAAC,OAAA,EAAS,MAAW,KAAA;AACxD,IAAA,eAAe,oBAAuB,GAAA;AACpC,MAAA,IAAI,MAAS,GAAA,KAAA;AAEb,MAAI,IAAA;AACF,QAAM,MAAA,eAAA,GAAkB,IAAI,eAAgB,EAAA;AAC5C,QAAA,OAAA,CAAQ,OAAO,UAAY,EAAA,IAAA,CAAK,MAAM,eAAA,CAAgB,OAAO,CAAA;AAE7D,QAAA,WAAA,MAAiB,EAAE,OAAA,EAAa,IAAA,MAAA,CAAO,cAAe,CAAA;AAAA,UACpD,QAAQ,eAAgB,CAAA;AAAA,SACzB,CAAG,EAAA;AACF,UAAA,IAAI,MAAQ,EAAA;AACV,YAAQ,OAAA,CAAA,KAAA,EAAO,SAAS,OAAO,CAAA;AAAA,WAC1B,MAAA;AACL,YAAQ,OAAA,CAAA,EAAE,UAAY,EAAA,OAAA,EAAS,CAAA;AAC/B,YAAS,MAAA,GAAA,IAAA;AAET,YAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,cAAA,OAAA,CAAQ,MAAM,UAAY,EAAA,IAAA,CAAK,MAAM,eAAA,CAAgB,OAAO,CAAA;AAAA,aACvD,MAAA;AACL,cAAA,eAAA,CAAgB,KAAM,EAAA;AAAA;AACxB;AACF;AACF,eACO,KAAO,EAAA;AACd,QAAA,IAAI,MAAQ,EAAA;AACV,UAAQ,OAAA,CAAA,KAAA,CAAM,CAAmC,gCAAA,EAAA,KAAK,CAAE,CAAA,CAAA;AAAA,SACnD,MAAA;AACL,UAAA,MAAA,CAAO,KAAK,CAAA;AAAA;AACd;AACF;AAEF,IAAqB,oBAAA,EAAA;AAAA,GACtB,CAAA;AACH;;;;"}
1
+ {"version":3,"file":"loader.cjs.js","sources":["../src/loader.ts"],"sourcesContent":["/*\n * Copyright 2020 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AppConfig } from '@backstage/config';\nimport { ConfigSources } from './sources';\n\n/**\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type ConfigTarget = { path: string } | { url: string };\n\n/**\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type LoadConfigOptionsWatch = {\n /**\n * A listener that is called when a config file is changed.\n */\n onChange: (configs: AppConfig[]) => void;\n\n /**\n * An optional signal that stops the watcher once the promise resolves.\n */\n stopSignal?: Promise<void>;\n};\n\n/**\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type LoadConfigOptionsRemote = {\n /**\n * A remote config reloading period, in seconds\n */\n reloadIntervalSeconds: number;\n};\n\n/**\n * Options that control the loading of configuration files in the backend.\n *\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type LoadConfigOptions = {\n // The root directory of the config loading context. Used to find default configs.\n configRoot: string;\n\n // Paths to load config files from. Configs from earlier paths have lower priority.\n configTargets: ConfigTarget[];\n\n /**\n * Custom environment variable loading function\n *\n * @experimental This API is not stable and may change at any point\n */\n experimentalEnvFunc?: (name: string) => Promise<string | undefined>;\n\n /**\n * An optional remote config\n */\n remote?: LoadConfigOptionsRemote;\n\n /**\n * An optional configuration that enables watching of config files.\n */\n watch?: LoadConfigOptionsWatch;\n};\n\n/**\n * Results of loading configuration files.\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport type LoadConfigResult = {\n /**\n * Array of all loaded configs.\n */\n appConfigs: AppConfig[];\n};\n\n/**\n * Load configuration data.\n *\n * @public\n * @deprecated Use {@link ConfigSources.default} instead.\n */\nexport async function loadConfig(\n options: LoadConfigOptions,\n): Promise<LoadConfigResult> {\n const source = ConfigSources.default({\n substitutionFunc: options.experimentalEnvFunc,\n remote: options.remote && {\n reloadInterval: { seconds: options.remote.reloadIntervalSeconds },\n },\n watch: Boolean(options.watch),\n rootDir: options.configRoot,\n argv: options.configTargets.flatMap(t => [\n '--config',\n 'url' in t ? t.url : t.path,\n ]),\n });\n\n return new Promise<LoadConfigResult>((resolve, reject) => {\n async function loadConfigReaderLoop() {\n let loaded = false;\n\n try {\n const abortController = new AbortController();\n options.watch?.stopSignal?.then(() => abortController.abort());\n\n for await (const { configs } of source.readConfigData({\n signal: abortController.signal,\n })) {\n if (loaded) {\n options.watch?.onChange(configs);\n } else {\n resolve({ appConfigs: configs });\n loaded = true;\n\n if (options.watch) {\n options.watch.stopSignal?.then(() => abortController.abort());\n } else {\n abortController.abort();\n }\n }\n }\n } catch (error) {\n if (loaded) {\n console.error(`Failed to reload configuration, ${error}`);\n } else {\n reject(error);\n }\n }\n }\n loadConfigReaderLoop();\n });\n}\n"],"names":["ConfigSources"],"mappings":";;;;;;;;;;;AAqGA,eAAsB,WACpB,OAC2B,EAAA;AAC3B,EAAM,MAAA,MAAA,GAASA,4BAAc,OAAQ,CAAA;AAAA,IACnC,kBAAkB,OAAQ,CAAA,mBAAA;AAAA,IAC1B,MAAA,EAAQ,QAAQ,MAAU,IAAA;AAAA,MACxB,cAAgB,EAAA,EAAE,OAAS,EAAA,OAAA,CAAQ,OAAO,qBAAsB;AAAA,KAClE;AAAA,IACA,KAAA,EAAO,OAAQ,CAAA,OAAA,CAAQ,KAAK,CAAA;AAAA,IAC5B,SAAS,OAAQ,CAAA,UAAA;AAAA,IACjB,IAAM,EAAA,OAAA,CAAQ,aAAc,CAAA,OAAA,CAAQ,CAAK,CAAA,KAAA;AAAA,MACvC,UAAA;AAAA,MACA,KAAS,IAAA,CAAA,GAAI,CAAE,CAAA,GAAA,GAAM,CAAE,CAAA;AAAA,KACxB;AAAA,GACF,CAAA;AAED,EAAA,OAAO,IAAI,OAAA,CAA0B,CAAC,OAAA,EAAS,MAAW,KAAA;AACxD,IAAA,eAAe,oBAAuB,GAAA;AACpC,MAAA,IAAI,MAAS,GAAA,KAAA;AAEb,MAAI,IAAA;AACF,QAAM,MAAA,eAAA,GAAkB,IAAI,eAAgB,EAAA;AAC5C,QAAA,OAAA,CAAQ,OAAO,UAAY,EAAA,IAAA,CAAK,MAAM,eAAA,CAAgB,OAAO,CAAA;AAE7D,QAAA,WAAA,MAAiB,EAAE,OAAA,EAAa,IAAA,MAAA,CAAO,cAAe,CAAA;AAAA,UACpD,QAAQ,eAAgB,CAAA;AAAA,SACzB,CAAG,EAAA;AACF,UAAA,IAAI,MAAQ,EAAA;AACV,YAAQ,OAAA,CAAA,KAAA,EAAO,SAAS,OAAO,CAAA;AAAA,WAC1B,MAAA;AACL,YAAQ,OAAA,CAAA,EAAE,UAAY,EAAA,OAAA,EAAS,CAAA;AAC/B,YAAS,MAAA,GAAA,IAAA;AAET,YAAA,IAAI,QAAQ,KAAO,EAAA;AACjB,cAAA,OAAA,CAAQ,MAAM,UAAY,EAAA,IAAA,CAAK,MAAM,eAAA,CAAgB,OAAO,CAAA;AAAA,aACvD,MAAA;AACL,cAAA,eAAA,CAAgB,KAAM,EAAA;AAAA;AACxB;AACF;AACF,eACO,KAAO,EAAA;AACd,QAAA,IAAI,MAAQ,EAAA;AACV,UAAQ,OAAA,CAAA,KAAA,CAAM,CAAmC,gCAAA,EAAA,KAAK,CAAE,CAAA,CAAA;AAAA,SACnD,MAAA;AACL,UAAA,MAAA,CAAO,KAAK,CAAA;AAAA;AACd;AACF;AAEF,IAAqB,oBAAA,EAAA;AAAA,GACtB,CAAA;AACH;;;;"}
@@ -3,14 +3,12 @@
3
3
  var errors = require('@backstage/errors');
4
4
  var types = require('@backstage/types');
5
5
  var isEqual = require('lodash/isEqual');
6
- var fetch = require('node-fetch');
7
6
  var apply = require('./transform/apply.cjs.js');
8
7
  var utils = require('./utils.cjs.js');
9
8
 
10
9
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
11
10
 
12
11
  var isEqual__default = /*#__PURE__*/_interopDefaultCompat(isEqual);
13
- var fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
14
12
 
15
13
  const DEFAULT_RELOAD_INTERVAL = { seconds: 60 };
16
14
  class RemoteConfigSource {
@@ -69,7 +67,7 @@ class RemoteConfigSource {
69
67
  return `RemoteConfigSource{path="${this.#url}"}`;
70
68
  }
71
69
  async #load(signal) {
72
- const res = await fetch__default.default(this.#url, {
70
+ const res = await fetch(this.#url, {
73
71
  signal
74
72
  });
75
73
  if (!res.ok) {
@@ -1 +1 @@
1
- {"version":3,"file":"RemoteConfigSource.cjs.js","sources":["../../src/sources/RemoteConfigSource.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ResponseError } from '@backstage/errors';\nimport {\n HumanDuration,\n JsonObject,\n durationToMilliseconds,\n} from '@backstage/types';\nimport isEqual from 'lodash/isEqual';\nimport fetch from 'node-fetch';\nimport { ConfigTransformer, createConfigTransformer } from './transform';\nimport {\n AsyncConfigSourceGenerator,\n ConfigSource,\n SubstitutionFunc,\n ReadConfigDataOptions,\n Parser,\n} from './types';\nimport { parseYamlContent } from './utils';\n\nconst DEFAULT_RELOAD_INTERVAL = { seconds: 60 };\n\n/**\n * Options for {@link RemoteConfigSource.create}.\n *\n * @public\n */\nexport interface RemoteConfigSourceOptions {\n /**\n * The URL to load the config from.\n */\n url: string;\n\n /**\n * How often to reload the config from the remote URL, defaults to 1 minute.\n *\n * Set to Infinity to disable reloading, for example `{ days: Infinity }`.\n */\n reloadInterval?: HumanDuration;\n\n /**\n * A substitution function to use instead of the default environment substitution.\n */\n substitutionFunc?: SubstitutionFunc;\n\n /**\n * A content parsing function to transform string content to configuration values.\n */\n parser?: Parser;\n}\n\n/**\n * A config source that loads configuration from a remote URL.\n *\n * @public\n */\nexport class RemoteConfigSource implements ConfigSource {\n /**\n * Creates a new {@link RemoteConfigSource}.\n *\n * @param options - Options for the source.\n * @returns A new remote config source.\n */\n static create(options: RemoteConfigSourceOptions): ConfigSource {\n try {\n // eslint-disable-next-line no-new\n new URL(options.url);\n } catch (error) {\n throw new Error(\n `Invalid URL provided to remote config source, '${options.url}', ${error}`,\n );\n }\n return new RemoteConfigSource(options);\n }\n\n readonly #url: string;\n readonly #reloadIntervalMs: number;\n readonly #transformer: ConfigTransformer;\n readonly #parser: Parser;\n\n private constructor(options: RemoteConfigSourceOptions) {\n this.#url = options.url;\n this.#reloadIntervalMs = durationToMilliseconds(\n options.reloadInterval ?? DEFAULT_RELOAD_INTERVAL,\n );\n this.#transformer = createConfigTransformer({\n substitutionFunc: options.substitutionFunc,\n });\n this.#parser = options.parser ?? parseYamlContent;\n }\n\n async *readConfigData(\n options?: ReadConfigDataOptions | undefined,\n ): AsyncConfigSourceGenerator {\n let data = await this.#load();\n\n yield { configs: [{ data, context: this.#url }] };\n\n for (;;) {\n await this.#wait(options?.signal);\n\n if (options?.signal?.aborted) {\n return;\n }\n\n try {\n const newData = await this.#load(options?.signal);\n if (newData && !isEqual(data, newData)) {\n data = newData;\n yield { configs: [{ data, context: this.#url }] };\n }\n } catch (error) {\n if (error.name !== 'AbortError') {\n console.error(`Failed to read config from ${this.#url}, ${error}`);\n }\n }\n }\n }\n\n toString() {\n return `RemoteConfigSource{path=\"${this.#url}\"}`;\n }\n\n async #load(signal?: AbortSignal): Promise<JsonObject> {\n const res = await fetch(this.#url, {\n signal: signal as import('node-fetch').RequestInit['signal'],\n });\n if (!res.ok) {\n throw await ResponseError.fromResponse(res);\n }\n\n const contents = await res.text();\n const { result: rawData } = await this.#parser({ contents });\n if (rawData === undefined) {\n /**\n * This error message is/was coupled to the implementation and with refactoring it is no longer truly accurate\n * This behavior is also inconsistent with {@link FileConfigSource}, which doesn't error on unparseable or empty\n * content\n *\n * Preserving to not make a breaking change\n */\n throw new Error('configuration data is null');\n }\n\n const data = await this.#transformer(rawData);\n if (typeof data !== 'object') {\n throw new Error('configuration data is not an object');\n } else if (Array.isArray(data)) {\n throw new Error(\n 'configuration data is an array, expected an object instead',\n );\n }\n return data;\n }\n\n async #wait(signal?: AbortSignal) {\n return new Promise<void>(resolve => {\n const timeoutId = setTimeout(onDone, this.#reloadIntervalMs);\n signal?.addEventListener('abort', onDone);\n\n function onDone() {\n clearTimeout(timeoutId);\n signal?.removeEventListener('abort', onDone);\n resolve();\n }\n });\n }\n}\n"],"names":["durationToMilliseconds","createConfigTransformer","parseYamlContent","isEqual","fetch","ResponseError"],"mappings":";;;;;;;;;;;;;;AAkCA,MAAM,uBAAA,GAA0B,EAAE,OAAA,EAAS,EAAG,EAAA;AAoCvC,MAAM,kBAA2C,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOtD,OAAO,OAAO,OAAkD,EAAA;AAC9D,IAAI,IAAA;AAEF,MAAI,IAAA,GAAA,CAAI,QAAQ,GAAG,CAAA;AAAA,aACZ,KAAO,EAAA;AACd,MAAA,MAAM,IAAI,KAAA;AAAA,QACR,CAAkD,+CAAA,EAAA,OAAA,CAAQ,GAAG,CAAA,GAAA,EAAM,KAAK,CAAA;AAAA,OAC1E;AAAA;AAEF,IAAO,OAAA,IAAI,mBAAmB,OAAO,CAAA;AAAA;AACvC,EAES,IAAA;AAAA,EACA,iBAAA;AAAA,EACA,YAAA;AAAA,EACA,OAAA;AAAA,EAED,YAAY,OAAoC,EAAA;AACtD,IAAA,IAAA,CAAK,OAAO,OAAQ,CAAA,GAAA;AACpB,IAAA,IAAA,CAAK,iBAAoB,GAAAA,4BAAA;AAAA,MACvB,QAAQ,cAAkB,IAAA;AAAA,KAC5B;AACA,IAAA,IAAA,CAAK,eAAeC,6BAAwB,CAAA;AAAA,MAC1C,kBAAkB,OAAQ,CAAA;AAAA,KAC3B,CAAA;AACD,IAAK,IAAA,CAAA,OAAA,GAAU,QAAQ,MAAU,IAAAC,sBAAA;AAAA;AACnC,EAEA,OAAO,eACL,OAC4B,EAAA;AAC5B,IAAI,IAAA,IAAA,GAAO,MAAM,IAAA,CAAK,KAAM,EAAA;AAE5B,IAAM,MAAA,EAAE,SAAS,CAAC,EAAE,MAAM,OAAS,EAAA,IAAA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AY,KAAW,CAAA,EAAA;AAQzB,MAAM,MAAA,IAAI,MAAM,4BAA4B,CAAA;AAAA;AAG9C,IAAA,MAAM,IAAO,GAAA,MAAM,IAAK,CAAA,YAAA,CAAa,OAAO,CAAA;AAC5C,IAAI,IAAA,OAAO,SAAS,QAAU,EAAA;AAC5B,MAAM,MAAA,IAAI,MAAM,qCAAqC,CAAA;AAAA,KAC5C,MAAA,IAAA,KAAA,CAAM,OAAQ,CAAA,IAAI,CAAG,EAAA;AAC9B,MAAA,MAAM,IAAI,KAAA;AAAA,QACR;AAAA,OACF;AAAA;AAEF,IAAO,OAAA,IAAA;AAAA;AACT,EAEA,MAAM,MAAM,MAAsB,EAAA;AAChC,IAAO,OAAA,IAAI,QAAc,CAAW,OAAA,KAAA;AAClC,MAAA,MAAM,SAAY,GAAA,UAAA,CAAW,MAAQ,EAAA,IAAA,CAAK,iBAAiB,CAAA;AAC3D,MAAQ,MAAA,EAAA,gBAAA,CAAiB,SAAS,MAAM,CAAA;AAExC,MAAA,SAAS,MAAS,GAAA;AAChB,QAAA,YAAA,CAAa,SAAS,CAAA;AACtB,QAAQ,MAAA,EAAA,mBAAA,CAAoB,SAAS,MAAM,CAAA;AAC3C,QAAQ,OAAA,EAAA;AAAA;AACV,KACD,CAAA;AAAA;AAEL;;;;"}
1
+ {"version":3,"file":"RemoteConfigSource.cjs.js","sources":["../../src/sources/RemoteConfigSource.ts"],"sourcesContent":["/*\n * Copyright 2023 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { ResponseError } from '@backstage/errors';\nimport {\n HumanDuration,\n JsonObject,\n durationToMilliseconds,\n} from '@backstage/types';\nimport isEqual from 'lodash/isEqual';\nimport { ConfigTransformer, createConfigTransformer } from './transform';\nimport {\n AsyncConfigSourceGenerator,\n ConfigSource,\n SubstitutionFunc,\n ReadConfigDataOptions,\n Parser,\n} from './types';\nimport { parseYamlContent } from './utils';\n\nconst DEFAULT_RELOAD_INTERVAL = { seconds: 60 };\n\n/**\n * Options for {@link RemoteConfigSource.create}.\n *\n * @public\n */\nexport interface RemoteConfigSourceOptions {\n /**\n * The URL to load the config from.\n */\n url: string;\n\n /**\n * How often to reload the config from the remote URL, defaults to 1 minute.\n *\n * Set to Infinity to disable reloading, for example `{ days: Infinity }`.\n */\n reloadInterval?: HumanDuration;\n\n /**\n * A substitution function to use instead of the default environment substitution.\n */\n substitutionFunc?: SubstitutionFunc;\n\n /**\n * A content parsing function to transform string content to configuration values.\n */\n parser?: Parser;\n}\n\n/**\n * A config source that loads configuration from a remote URL.\n *\n * @public\n */\nexport class RemoteConfigSource implements ConfigSource {\n /**\n * Creates a new {@link RemoteConfigSource}.\n *\n * @param options - Options for the source.\n * @returns A new remote config source.\n */\n static create(options: RemoteConfigSourceOptions): ConfigSource {\n try {\n // eslint-disable-next-line no-new\n new URL(options.url);\n } catch (error) {\n throw new Error(\n `Invalid URL provided to remote config source, '${options.url}', ${error}`,\n );\n }\n return new RemoteConfigSource(options);\n }\n\n readonly #url: string;\n readonly #reloadIntervalMs: number;\n readonly #transformer: ConfigTransformer;\n readonly #parser: Parser;\n\n private constructor(options: RemoteConfigSourceOptions) {\n this.#url = options.url;\n this.#reloadIntervalMs = durationToMilliseconds(\n options.reloadInterval ?? DEFAULT_RELOAD_INTERVAL,\n );\n this.#transformer = createConfigTransformer({\n substitutionFunc: options.substitutionFunc,\n });\n this.#parser = options.parser ?? parseYamlContent;\n }\n\n async *readConfigData(\n options?: ReadConfigDataOptions | undefined,\n ): AsyncConfigSourceGenerator {\n let data = await this.#load();\n\n yield { configs: [{ data, context: this.#url }] };\n\n for (;;) {\n await this.#wait(options?.signal);\n\n if (options?.signal?.aborted) {\n return;\n }\n\n try {\n const newData = await this.#load(options?.signal);\n if (newData && !isEqual(data, newData)) {\n data = newData;\n yield { configs: [{ data, context: this.#url }] };\n }\n } catch (error) {\n if (error.name !== 'AbortError') {\n console.error(`Failed to read config from ${this.#url}, ${error}`);\n }\n }\n }\n }\n\n toString() {\n return `RemoteConfigSource{path=\"${this.#url}\"}`;\n }\n\n async #load(signal?: AbortSignal): Promise<JsonObject> {\n const res = await fetch(this.#url, {\n signal: signal as RequestInit['signal'],\n });\n if (!res.ok) {\n throw await ResponseError.fromResponse(res);\n }\n\n const contents = await res.text();\n const { result: rawData } = await this.#parser({ contents });\n if (rawData === undefined) {\n /**\n * This error message is/was coupled to the implementation and with refactoring it is no longer truly accurate\n * This behavior is also inconsistent with {@link FileConfigSource}, which doesn't error on unparseable or empty\n * content\n *\n * Preserving to not make a breaking change\n */\n throw new Error('configuration data is null');\n }\n\n const data = await this.#transformer(rawData);\n if (typeof data !== 'object') {\n throw new Error('configuration data is not an object');\n } else if (Array.isArray(data)) {\n throw new Error(\n 'configuration data is an array, expected an object instead',\n );\n }\n return data;\n }\n\n async #wait(signal?: AbortSignal) {\n return new Promise<void>(resolve => {\n const timeoutId = setTimeout(onDone, this.#reloadIntervalMs);\n signal?.addEventListener('abort', onDone);\n\n function onDone() {\n clearTimeout(timeoutId);\n signal?.removeEventListener('abort', onDone);\n resolve();\n }\n });\n }\n}\n"],"names":["durationToMilliseconds","createConfigTransformer","parseYamlContent","isEqual","ResponseError"],"mappings":";;;;;;;;;;;;AAiCA,MAAM,uBAAA,GAA0B,EAAE,OAAA,EAAS,EAAG,EAAA;AAoCvC,MAAM,kBAA2C,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOtD,OAAO,OAAO,OAAkD,EAAA;AAC9D,IAAI,IAAA;AAEF,MAAI,IAAA,GAAA,CAAI,QAAQ,GAAG,CAAA;AAAA,aACZ,KAAO,EAA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C,MAAA,MAAM,SAAY,GAAA,UAAA,CAAW,MAAQ,EAAA,IAAA,CAAK,iBAAiB,CAAA;AAC3D,MAAQ,MAAA,EAAA,gBAAA,CAAiB,SAAS,MAAM,CAAA;AAExC,MAAA,SAAS,MAAS,GAAA;AAChB,QAAA,YAAA,CAAa,SAAS,CAAA;AACtB,QAAQ,MAAA,EAAA,mBAAA,CAAoB,SAAS,MAAM,CAAA;AAC3C,QAAQ,OAAA,EAAA;AAAA;AACV,KACD,CAAA;AAAA;AAEL;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/config-loader",
3
- "version": "1.9.2",
3
+ "version": "1.9.3-next.1",
4
4
  "description": "Config loading functionality used by Backstage backend, and CLI",
5
5
  "backstage": {
6
6
  "role": "node-library"
@@ -36,10 +36,10 @@
36
36
  "test": "backstage-cli package test"
37
37
  },
38
38
  "dependencies": {
39
- "@backstage/cli-common": "^0.1.15",
40
- "@backstage/config": "^1.3.0",
41
- "@backstage/errors": "^1.2.5",
42
- "@backstage/types": "^1.2.0",
39
+ "@backstage/cli-common": "0.1.15",
40
+ "@backstage/config": "1.3.1-next.0",
41
+ "@backstage/errors": "1.2.6-next.0",
42
+ "@backstage/types": "1.2.0",
43
43
  "@types/json-schema": "^7.0.6",
44
44
  "ajv": "^8.10.0",
45
45
  "chokidar": "^3.5.2",
@@ -49,13 +49,12 @@
49
49
  "json-schema-traverse": "^1.0.0",
50
50
  "lodash": "^4.17.21",
51
51
  "minimist": "^1.2.5",
52
- "node-fetch": "^2.7.0",
53
52
  "typescript-json-schema": "^0.65.0",
54
53
  "yaml": "^2.0.0"
55
54
  },
56
55
  "devDependencies": {
57
- "@backstage/backend-test-utils": "^1.1.0",
58
- "@backstage/cli": "^0.29.0",
56
+ "@backstage/backend-test-utils": "1.2.0-next.2",
57
+ "@backstage/cli": "0.29.3-next.2",
59
58
  "@types/json-schema-merge-allof": "^0.6.0",
60
59
  "msw": "^1.0.0",
61
60
  "zen-observable": "^0.10.0"