@azure/app-configuration-importer 1.0.0-preview → 1.0.1-preview

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.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +67 -0
  3. package/dist/index.js +77 -10
  4. package/dist/index.js.map +1 -1
  5. package/dist-esm/src/appConfigurationImporter.js +157 -0
  6. package/dist-esm/src/appConfigurationImporter.js.map +1 -0
  7. package/dist-esm/src/enums.js +28 -0
  8. package/dist-esm/src/enums.js.map +1 -0
  9. package/dist-esm/src/errors.js +35 -0
  10. package/dist-esm/src/errors.js.map +1 -0
  11. package/dist-esm/src/importOptions.js +4 -0
  12. package/dist-esm/src/importOptions.js.map +1 -0
  13. package/dist-esm/src/index.js +9 -0
  14. package/dist-esm/src/index.js.map +1 -0
  15. package/dist-esm/src/internal/adaptiveTaskManager.js +69 -0
  16. package/dist-esm/src/internal/adaptiveTaskManager.js.map +1 -0
  17. package/dist-esm/src/internal/constants.js +29 -0
  18. package/dist-esm/src/internal/constants.js.map +1 -0
  19. package/dist-esm/src/internal/parsers/configurationSettingsConverter.js +4 -0
  20. package/dist-esm/src/internal/parsers/configurationSettingsConverter.js.map +1 -0
  21. package/dist-esm/src/internal/parsers/defaultConfigurationSettingsConverter.js +200 -0
  22. package/dist-esm/src/internal/parsers/defaultConfigurationSettingsConverter.js.map +1 -0
  23. package/dist-esm/src/internal/parsers/kvSetConfigurationSettingsConverter.js +66 -0
  24. package/dist-esm/src/internal/parsers/kvSetConfigurationSettingsConverter.js.map +1 -0
  25. package/dist-esm/src/internal/stream.browser.js +16 -0
  26. package/dist-esm/src/internal/stream.browser.js.map +1 -0
  27. package/dist-esm/src/internal/stream.js +15 -0
  28. package/dist-esm/src/internal/stream.js.map +1 -0
  29. package/dist-esm/src/internal/utils.js +129 -0
  30. package/dist-esm/src/internal/utils.js.map +1 -0
  31. package/dist-esm/src/models.js +4 -0
  32. package/dist-esm/src/models.js.map +1 -0
  33. package/dist-esm/src/settingsImport/configurationSettingsSource.js +4 -0
  34. package/dist-esm/src/settingsImport/configurationSettingsSource.js.map +1 -0
  35. package/dist-esm/src/settingsImport/iterableConfigurationSettingsSource.js +83 -0
  36. package/dist-esm/src/settingsImport/iterableConfigurationSettingsSource.js.map +1 -0
  37. package/dist-esm/src/settingsImport/readableStreamConfigurationSettingsSource.js +49 -0
  38. package/dist-esm/src/settingsImport/readableStreamConfigurationSettingsSource.js.map +1 -0
  39. package/dist-esm/src/settingsImport/stringConfigurationSettingsSource.js +92 -0
  40. package/dist-esm/src/settingsImport/stringConfigurationSettingsSource.js.map +1 -0
  41. package/package.json +19 -5
  42. package/types/src/appConfigurationImporter.d.ts +37 -0
  43. package/types/src/appConfigurationImporter.d.ts.map +1 -0
  44. package/types/src/enums.d.ts +23 -0
  45. package/types/src/enums.d.ts.map +1 -0
  46. package/types/src/errors.d.ts +25 -0
  47. package/types/src/errors.d.ts.map +1 -0
  48. package/types/src/importOptions.d.ts +39 -0
  49. package/types/src/importOptions.d.ts.map +1 -0
  50. package/types/src/index.d.ts +10 -0
  51. package/types/src/index.d.ts.map +1 -0
  52. package/types/src/internal/adaptiveTaskManager.d.ts +20 -0
  53. package/types/src/internal/adaptiveTaskManager.d.ts.map +1 -0
  54. package/types/src/internal/constants.d.ts +8 -0
  55. package/types/src/internal/constants.d.ts.map +1 -0
  56. package/types/src/internal/parsers/configurationSettingsConverter.d.ts +11 -0
  57. package/types/src/internal/parsers/configurationSettingsConverter.d.ts.map +1 -0
  58. package/types/src/internal/parsers/defaultConfigurationSettingsConverter.d.ts +20 -0
  59. package/types/src/internal/parsers/defaultConfigurationSettingsConverter.d.ts.map +1 -0
  60. package/types/src/internal/parsers/kvSetConfigurationSettingsConverter.d.ts +15 -0
  61. package/types/src/internal/parsers/kvSetConfigurationSettingsConverter.d.ts.map +1 -0
  62. package/types/src/internal/stream.browser.d.ts +4 -0
  63. package/types/src/internal/stream.browser.d.ts.map +1 -0
  64. package/types/src/internal/stream.d.ts +4 -0
  65. package/types/src/internal/stream.d.ts.map +1 -0
  66. package/types/src/internal/utils.d.ts +17 -0
  67. package/types/src/internal/utils.d.ts.map +1 -0
  68. package/types/src/models.d.ts +42 -0
  69. package/types/src/models.d.ts.map +1 -0
  70. package/types/src/settingsImport/configurationSettingsSource.d.ts +19 -0
  71. package/types/src/settingsImport/configurationSettingsSource.d.ts.map +1 -0
  72. package/types/src/settingsImport/iterableConfigurationSettingsSource.d.ts +14 -0
  73. package/types/src/settingsImport/iterableConfigurationSettingsSource.d.ts.map +1 -0
  74. package/types/src/settingsImport/readableStreamConfigurationSettingsSource.d.ts +11 -0
  75. package/types/src/settingsImport/readableStreamConfigurationSettingsSource.d.ts.map +1 -0
  76. package/types/src/settingsImport/stringConfigurationSettingsSource.d.ts +24 -0
  77. package/types/src/settingsImport/stringConfigurationSettingsSource.d.ts.map +1 -0
  78. package/NOTICE.txt +0 -370
  79. package/app-configuration-importer.test.log +0 -164
  80. package/dist/app-configuration-importer.api.md +0 -136
  81. package/examples/README.md +0 -59
  82. package/examples/package.json +0 -32
  83. package/examples/sample.env +0 -6
  84. package/examples/testFiles/default.json +0 -24
  85. package/examples/testFiles/kvset.json +0 -35
  86. package/types/tsdoc-metadata.json +0 -11
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaultConfigurationSettingsConverter.js","sourceRoot":"","sources":["../../../../src/internal/parsers/defaultConfigurationSettingsConverter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAIL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,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iBACF;aACF;SACF;aACI,IAAI,OAAO,WAAW,CAAC,eAAe,CAAC,IAAI,SAAS,EAAE;YACzD,gBAAgB,CAAC,OAAO,GAAG,WAAW,CAAC,eAAe,CAAC,CAAC;SACzD;aACI;YACH,MAAM,IAAI,aAAa,CACrB,8DAA8D,eAAe,0CAA0C,CACxH,CAAC;SACH;QACD,OAAO,gBAAgB,CAAC;IAC1B,CAAC;IAEO,mBAAmB,CAAC,YAA0B;QACpD,MAAM,IAAI,GAAkB,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtD,MAAM,gBAAgB,GAA2B,EAAE,CAAC;QAEpD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACpC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,CAAiB,CAAC,CAAC;SACjF;QAED,OAAO,gBAAgB,CAAC;IAC1B,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n SetConfigurationSettingParam,\n FeatureFlagValue,\n SecretReferenceValue,\n featureFlagPrefix,\n featureFlagContentType\n} from \"@azure/app-configuration\";\nimport { SourceOptions } from \"../../importOptions\";\nimport { ConfigurationSettingsConverter } from \"./configurationSettingsConverter\";\nimport { Constants } from \"../constants\";\nimport { ArgumentError } from \"../../errors\";\nimport { ClientFilter } from \"../../models\";\nimport * as flat from \"flat\";\nimport { ConfigurationFormat } from \"../../enums\";\nimport { isJsonContentType } from \"../utils\";\n\n/**\n * Format Parser for common key-value configuration.\n *\n * @internal\n * */\nexport class DefaultConfigurationSettingsConverter implements ConfigurationSettingsConverter {\n /**\n * Parse the raw configuration object to collection of ConfigurationSettings\n *\n * @param config Raw configuration object\n * @param options Configuration options to dictate how the configuration be parsed.\n * */\n public Convert(\n config: object,\n options: SourceOptions\n ): SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>[] {\n let configurationSettings = new Array<\n SetConfigurationSettingParam<string | FeatureFlagValue>\n >();\n let featureFlagsConfigSettings = new Array<SetConfigurationSettingParam<FeatureFlagValue>>();\n let foundFeatureManagement = false;\n let featureFlags: any = {};\n let featureManagementKeyWord = \"\";\n let enabledForKeyWord = \"\";\n\n if (options.format == ConfigurationFormat.Properties && !options.skipFeatureFlags) {\n this.checkFeatureManagementExist(config);\n }\n\n for (let i = 0; i < Constants.FeatureManagementKeyWords.length; i++) {\n if (Constants.FeatureManagementKeyWords[i] in config) {\n if (foundFeatureManagement) {\n throw new ArgumentError(\n \"Unable to proceed because data contains multiple sections corresponding to Feature Management.\"\n );\n }\n\n featureManagementKeyWord = Constants.FeatureManagementKeyWords[i];\n enabledForKeyWord = Constants.EnabledForKeyWords[i];\n const featureManagementKey = featureManagementKeyWord as keyof object;\n featureFlags = config[featureManagementKey];\n delete config[featureManagementKey];\n foundFeatureManagement = true;\n }\n }\n\n if (foundFeatureManagement && !options.skipFeatureFlags) {\n const featureFlagConverter = new FeatureFlagConfigurationSettingsConverter(\n featureManagementKeyWord,\n enabledForKeyWord\n );\n featureFlagsConfigSettings = featureFlagConverter.Convert(featureFlags, options);\n }\n\n const flattenedConfigurationSettings: object = flat.flatten(config, {\n delimiter: options.separator,\n maxDepth: options.depth,\n safe: isJsonContentType(options.contentType) // preserve array for json content type\n });\n configurationSettings = this.toConfigurationSettings(flattenedConfigurationSettings, options);\n configurationSettings = configurationSettings.concat(featureFlagsConfigSettings);\n\n return configurationSettings;\n }\n\n private checkFeatureManagementExist(configurations: object): void {\n const keys: string[] = Object.keys(configurations);\n for (const featureFlagKeyWord of Constants.FeatureManagementKeyWords) {\n if (keys.find(key => key.startsWith(featureFlagKeyWord))) {\n throw new ArgumentError(\"Importing feature flag in Properties format is not supported. Anything in the Properties format being imported will be treated as key value.\");\n }\n }\n }\n\n private toConfigurationSettings(\n flatted: any,\n options: SourceOptions\n ): Array<SetConfigurationSettingParam<string>> {\n const result = new Array<SetConfigurationSettingParam>();\n const isJsonType = isJsonContentType(options.contentType);\n for (const element in flatted) {\n let generateKey: string = element;\n if (options.prefix) {\n generateKey = options.prefix + element;\n }\n\n if (generateKey === \".\" || generateKey === \"..\" || generateKey.indexOf(\"%\") > -1) {\n throw new ArgumentError(\"Key cannot be a '.' or '..', or contain the '%' character.\");\n }\n if (generateKey.startsWith(featureFlagPrefix)) {\n throw new ArgumentError(\"Key cannot start with the reserved prefix for feature flags.\");\n }\n\n // Ignore key-value with empty array/object value when content-type is not json, instead of pushing a kv with an empty array/obj\n // For null value it will be treated as \"null\" string.\n if (!isJsonType && flatted[element] && typeof flatted[element] === \"object\" && Object.keys(flatted[element]).length == 0 ) {\n continue;\n }\n\n const setting: SetConfigurationSettingParam<string> = {\n label: options.label,\n tags: options.tags,\n key: generateKey,\n contentType: options.contentType,\n value:\n typeof flatted[element] === \"object\" || isJsonType\n ? JSON.stringify(flatted[element])\n : flatted[element].toString()\n };\n\n result.push(setting);\n }\n\n return result;\n }\n}\n\n/**\n * ConfigurationSettings converter for feature flag.\n *\n * @internal\n * */\nclass FeatureFlagConfigurationSettingsConverter implements ConfigurationSettingsConverter {\n featureManagementKeyWord: string;\n enabledForKeyWord: string;\n constructor(featureManagementKeyWord: string, enabledForKeyWord: string) {\n this.featureManagementKeyWord = featureManagementKeyWord;\n this.enabledForKeyWord = enabledForKeyWord;\n\n if (!this.featureManagementKeyWord || !this.enabledForKeyWord) {\n throw new ArgumentError(\"No feature management was found\");\n }\n }\n\n /**\n * @inheritdoc\n * */\n Convert(\n config: object,\n options: SourceOptions\n ): SetConfigurationSettingParam<FeatureFlagValue>[] {\n const settings = new Array<SetConfigurationSettingParam<FeatureFlagValue>>();\n\n for (const featureFlag in config) {\n if (!this.validateFeatureName(featureFlag)) {\n throw new ArgumentError(\n `Feature flag ${featureFlag} contains invalid character,'%' and ':' are not allowed in feature name. Please provide valid feature name.`\n );\n }\n const prefix: string = options.prefix ?? \"\";\n settings.push({\n key: featureFlagPrefix + prefix + featureFlag,\n label: options.label,\n value: this.getFeatureFlagValue(\n featureFlag,\n config,\n this.enabledForKeyWord\n ),\n contentType: featureFlagContentType,\n tags: options.tags\n });\n }\n\n return settings;\n }\n\n private validateFeatureName(featureName: string): boolean {\n if (featureName) {\n const valid = /^[^:%]*$/;\n return valid.test(featureName);\n }\n else {\n return false;\n }\n }\n\n private getFeatureFlagValue(\n featureFlagName: any,\n featureData: any,\n enabledForKeyWord: string\n ): FeatureFlagValue {\n const defaultFeatureConditions = { clientFilters: [] };\n\n const featureFlagValue: FeatureFlagValue = {\n id: featureFlagName,\n description: \"\",\n enabled: false,\n conditions: {\n clientFilters: []\n }\n };\n\n if (typeof featureData[featureFlagName] == \"object\") {\n const filters = featureData[featureFlagName][enabledForKeyWord];\n if (!filters) {\n throw new ArgumentError(\n `Data contains feature flags in invalid format. Feature flag '${featureFlagName}' must contain '${enabledForKeyWord}' definition or have a true/false value.`\n );\n }\n\n if (filters.length != 0) {\n featureFlagValue.enabled = true;\n featureFlagValue.conditions.clientFilters = filters;\n for (let i = 0; i < featureFlagValue.conditions.clientFilters.length; i++) {\n const parameters: Partial<ClientFilter> = {};\n //\n // Converting client_filter keys to lower case\n const lowerCaseFilters = this.getLowerCaseFilters(\n featureFlagValue.conditions.clientFilters[i]\n );\n\n const filtersName = lowerCaseFilters[\"name\"];\n const filtersParameters = lowerCaseFilters[\"parameters\"];\n\n if (filtersName) {\n if (filtersName.toLowerCase() == \"alwayson\") {\n featureFlagValue.conditions = defaultFeatureConditions;\n break;\n }\n parameters.name = filtersName;\n if (filtersParameters) {\n parameters.parameters = filtersParameters;\n }\n\n featureFlagValue.conditions.clientFilters[i] = parameters as ClientFilter;\n }\n else {\n throw new ArgumentError(\n `This feature flag '${featureFlagName}' has a filter without the required 'name' property.`\n );\n }\n }\n }\n }\n else if (typeof featureData[featureFlagName] == \"boolean\") {\n featureFlagValue.enabled = featureData[featureFlagName];\n }\n else {\n throw new ArgumentError(\n `Data contains feature flags in invalid format. The type of ${featureFlagName} should be either boolean or dictionary.`\n );\n }\n return featureFlagValue;\n }\n\n private getLowerCaseFilters(clientFilter: ClientFilter): { [key: string]: any } {\n const keys: Array<string> = Object.keys(clientFilter);\n const lowerCaseFilters: { [key: string]: any } = {};\n\n for (let i = 0; i < keys.length; i++) {\n lowerCaseFilters[keys[i].toLowerCase()] = clientFilter[keys[i] as keyof object];\n }\n\n return lowerCaseFilters;\n }\n}\n"]}
@@ -0,0 +1,66 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { featureFlagPrefix, featureFlagContentType } from "@azure/app-configuration";
4
+ import { ArgumentError } from "../../errors";
5
+ /**
6
+ * Format Parser for kvset profile.
7
+ *
8
+ * @internal
9
+ * */
10
+ export class KvSetConfigurationSettingsConverter {
11
+ /**
12
+ * @inheritdoc
13
+ * */
14
+ Convert(config) {
15
+ const configurationSettings = new Array();
16
+ const itemsKeyword = "items";
17
+ if (!(itemsKeyword in config) || !Array.isArray(config[itemsKeyword])) {
18
+ throw new ArgumentError("The input data doesn't follow the KVSet file schema. See https://github.com/Azure/AppConfiguration/blob/main/docs/KVSet/KVSet.v1.0.0.schema.json");
19
+ }
20
+ const items = config[itemsKeyword];
21
+ for (let index = 0; index < items.length; index++) {
22
+ const element = items[index];
23
+ this.validateKvSetElement(element);
24
+ configurationSettings.push({
25
+ key: element.key,
26
+ value: element.value,
27
+ label: element.label,
28
+ contentType: element.content_type,
29
+ tags: element.tags
30
+ });
31
+ }
32
+ return configurationSettings;
33
+ }
34
+ validateKvSetElement(element) {
35
+ if (!element.key) {
36
+ throw new ArgumentError("Configuration key is required, cannot be an empty string");
37
+ }
38
+ if (typeof element.key !== "string") {
39
+ throw new ArgumentError(`Invalid key '${element.key}', key must be a string`);
40
+ }
41
+ if (element.key === "." || element.key === ".." || element.key.indexOf("%") > -1) {
42
+ throw new ArgumentError("Key cannot be a '.' or '..', or contain the '%' character.");
43
+ }
44
+ if (element.key.startsWith(featureFlagPrefix) && element.content_type !== featureFlagContentType) {
45
+ throw new ArgumentError(`Invalid key '${element.key}'. Key cannot start with the reserved prefix for feature flags.`);
46
+ }
47
+ if (element.value && typeof element.value !== "string") {
48
+ throw new ArgumentError(`The 'value' for the key '${element.key}' is not a string.`);
49
+ }
50
+ if (element.content_type && typeof element.content_type !== "string") {
51
+ throw new ArgumentError(`The 'content_type' for the key '${element.key}' is not a string.`);
52
+ }
53
+ if (element.label && typeof element.label !== "string") {
54
+ throw new ArgumentError(`The 'label' for the key '${element.key}' is not a string.`);
55
+ }
56
+ if (typeof element.tags !== "object") {
57
+ throw new ArgumentError(`The value for the tag '${element.tags}' for key '${element.key}' is not in a valid format.`);
58
+ }
59
+ for (const item in element.tags) {
60
+ if (typeof element.tags[item] !== "string") {
61
+ throw new ArgumentError(`The value for the tag '${element.tags}' for key '${element.key}' is not in a valid format.`);
62
+ }
63
+ }
64
+ }
65
+ }
66
+ //# sourceMappingURL=kvSetConfigurationSettingsConverter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kvSetConfigurationSettingsConverter.js","sourceRoot":"","sources":["../../../../src/internal/parsers/kvSetConfigurationSettingsConverter.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAIL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAI7C;;;;KAIK;AACL,MAAM,OAAO,mCAAmC;IAC9C;;SAEK;IACE,OAAO,CAAC,MAAc;QAC3B,MAAM,qBAAqB,GAAG,IAAI,KAAK,EAAkF,CAAC;QAC1H,MAAM,YAAY,GAAG,OAAO,CAAC;QAE7B,IAAI,CAAC,CAAC,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,YAA4B,CAAC,CAAC,EAAE;YACrF,M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EAAiE,CAAC,CAAC;SACvH;QACD,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;YACtD,MAAM,IAAI,aAAa,CAAC,4BAA4B,OAAO,CAAC,GAAG,oBAAoB,CAAC,CAAC;SACtF;QACD,IAAI,OAAO,CAAC,YAAY,IAAI,OAAO,OAAO,CAAC,YAAY,KAAK,QAAQ,EAAE;YACpE,MAAM,IAAI,aAAa,CAAC,mCAAmC,OAAO,CAAC,GAAG,oBAAoB,CAAC,CAAC;SAC7F;QACD,IAAI,OAAO,CAAC,KAAK,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,QAAQ,EAAE;YACtD,MAAM,IAAI,aAAa,CAAC,4BAA4B,OAAO,CAAC,GAAG,oBAAoB,CAAC,CAAC;SACtF;QACD,IAAI,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE;YACpC,MAAM,IAAI,aAAa,CAAC,0BAA0B,OAAO,CAAC,IAAI,cAAc,OAAO,CAAC,GAAG,6BAA6B,CAAC,CAAC;SACvH;QACD,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,EAAE;YAC/B,IAAI,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,QAAQ,EAAE;gBAC1C,MAAM,IAAI,aAAa,CAAC,0BAA0B,OAAO,CAAC,IAAI,cAAc,OAAO,CAAC,GAAG,6BAA6B,CAAC,CAAC;aACvH;SACF;IACH,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n SetConfigurationSettingParam,\n FeatureFlagValue,\n SecretReferenceValue,\n featureFlagPrefix,\n featureFlagContentType\n} from \"@azure/app-configuration\";\nimport { ArgumentError } from \"../../errors\";\nimport { KvSetConfigurationItem } from \"../../models\";\nimport { ConfigurationSettingsConverter } from \"./configurationSettingsConverter\";\n\n/**\n * Format Parser for kvset profile.\n *\n * @internal\n * */\nexport class KvSetConfigurationSettingsConverter implements ConfigurationSettingsConverter {\n /**\n * @inheritdoc\n * */\n public Convert(config: object): SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>[] {\n const configurationSettings = new Array<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>>();\n const itemsKeyword = \"items\";\n\n if (!(itemsKeyword in config) || !Array.isArray(config[itemsKeyword as keyof object])) {\n throw new ArgumentError(\"The input data doesn't follow the KVSet file schema. See https://github.com/Azure/AppConfiguration/blob/main/docs/KVSet/KVSet.v1.0.0.schema.json\");\n }\n const items: Array<KvSetConfigurationItem> = config[itemsKeyword as keyof object];\n for (let index = 0; index < items.length; index++) {\n const element = items[index];\n this.validateKvSetElement(element);\n configurationSettings.push({\n key: element.key,\n value: element.value,\n label: element.label,\n contentType: element.content_type,\n tags: element.tags\n });\n }\n\n return configurationSettings;\n }\n\n private validateKvSetElement(element: KvSetConfigurationItem) {\n if (!element.key) {\n throw new ArgumentError(\"Configuration key is required, cannot be an empty string\");\n }\n if (typeof element.key !== \"string\") {\n throw new ArgumentError(`Invalid key '${element.key}', key must be a string`);\n }\n if (element.key === \".\" || element.key === \"..\" || element.key.indexOf(\"%\") > -1) {\n throw new ArgumentError(\"Key cannot be a '.' or '..', or contain the '%' character.\");\n }\n if (element.key.startsWith(featureFlagPrefix) && element.content_type !== featureFlagContentType) {\n throw new ArgumentError(`Invalid key '${element.key}'. Key cannot start with the reserved prefix for feature flags.`);\n }\n if (element.value && typeof element.value !== \"string\") {\n throw new ArgumentError(`The 'value' for the key '${element.key}' is not a string.`);\n }\n if (element.content_type && typeof element.content_type !== \"string\") {\n throw new ArgumentError(`The 'content_type' for the key '${element.key}' is not a string.`);\n }\n if (element.label && typeof element.label !== \"string\") {\n throw new ArgumentError(`The 'label' for the key '${element.key}' is not a string.`);\n }\n if (typeof element.tags !== \"object\") {\n throw new ArgumentError(`The value for the tag '${element.tags}' for key '${element.key}' is not in a valid format.`);\n }\n for (const item in element.tags) {\n if (typeof element.tags[item] !== \"string\") {\n throw new ArgumentError(`The value for the tag '${element.tags}' for key '${element.key}' is not in a valid format.`);\n }\n }\n }\n}\n"]}
@@ -0,0 +1,16 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ /** @internal */
4
+ export function toWebStream(source) {
5
+ if (isWebReadableStream(source)) {
6
+ return source;
7
+ }
8
+ throw new Error("Unexpected Node stream in browser environment");
9
+ }
10
+ function isWebReadableStream(stream) {
11
+ return Boolean(stream &&
12
+ typeof stream === "object" &&
13
+ typeof stream.getReader === "function" &&
14
+ typeof stream.tee === "function");
15
+ }
16
+ //# sourceMappingURL=stream.browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.browser.js","sourceRoot":"","sources":["../../../src/internal/stream.browser.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,gBAAgB;AAChB,MAAM,UAAU,WAAW,CAAC,MAA2D;IACrF,IAAI,mBAAmB,CAAC,MAAM,CAAC,EAAE;QAC/B,OAAQ,MAAoC,CAAC;KAC9C;IAED,MAAM,IAAI,KAAK,CAAE,+CAA+C,CAAC,CAAC;AACpE,CAAC;AAED,SAAS,mBAAmB,CAAC,MAAe;IAC1C,OAAO,OAAO,CAAC,MAAM;QACnB,OAAO,MAAM,KAAK,QAAQ;QAC1B,OAAQ,MAAyB,CAAC,SAAS,KAAK,UAAU;QAC1D,OAAQ,MAAyB,CAAC,GAAG,KAAK,UAAU,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\n/** @internal */\nexport function toWebStream(source: NodeJS.ReadableStream | ReadableStream<Uint8Array>): ReadableStream<Uint8Array> { \n if (isWebReadableStream(source)) {\n return source as ReadableStream<Uint8Array>;\n }\n\n throw new Error (\"Unexpected Node stream in browser environment\");\n}\n\nfunction isWebReadableStream(stream: unknown): boolean {\n return Boolean(stream && \n typeof stream === \"object\" && \n typeof (stream as ReadableStream).getReader === \"function\" &&\n typeof (stream as ReadableStream).tee === \"function\");\n}\n"]}
@@ -0,0 +1,15 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { Readable } from "stream";
4
+ /** @internal */
5
+ export function toWebStream(source) {
6
+ if (isNodeReadableStream(source)) {
7
+ const stream = source;
8
+ return Readable.toWeb(Readable.from(stream));
9
+ }
10
+ return source;
11
+ }
12
+ function isNodeReadableStream(stream) {
13
+ return Boolean(stream && typeof stream === "object" && typeof stream.pipe === "function");
14
+ }
15
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../../../src/internal/stream.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,gBAAgB;AAChB,MAAM,UAAU,WAAW,CAAC,MAA2D;IACrF,IAAI,oBAAoB,CAAC,MAAM,CAAC,EAAE;QAChC,MAAM,MAAM,GAAI,MAA+B,CAAC;QAChD,OAAO,QAAQ,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAA+B,CAAC;KAC5E;IAED,OAAO,MAAoC,CAAC;AAC9C,CAAC;AAED,SAAS,oBAAoB,CAAC,MAAe;IAC3C,OAAO,OAAO,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,OAAQ,MAAgC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;AACvH,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { Readable } from \"stream\";\n\n/** @internal */\nexport function toWebStream(source: NodeJS.ReadableStream | ReadableStream<Uint8Array>): ReadableStream<Uint8Array> { \n if (isNodeReadableStream(source)) {\n const stream = source as NodeJS.ReadableStream;\n return Readable.toWeb(Readable.from(stream)) as ReadableStream<Uint8Array>;\n }\n\n return source as ReadableStream<Uint8Array>;\n}\n\nfunction isNodeReadableStream(stream: unknown): boolean {\n return Boolean(stream && typeof stream === \"object\" && typeof (stream as NodeJS.ReadableStream).pipe === \"function\");\n}\n"]}
@@ -0,0 +1,129 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import { featureFlagContentType } from "@azure/app-configuration";
4
+ import { isEmpty, isEqual } from "lodash";
5
+ import { ConfigurationFormat, ConfigurationProfile } from "../enums";
6
+ import { ArgumentError, ArgumentNullError } from "../errors";
7
+ import { Constants } from "../internal/constants";
8
+ /** @internal*/
9
+ export function isJsonContentType(contentType) {
10
+ if (!contentType) {
11
+ return false;
12
+ }
13
+ contentType = contentType.trim().toLowerCase();
14
+ const mineType = contentType.split(";")[0].trim();
15
+ const typeParts = mineType.split("/");
16
+ if (typeParts.length != 2) {
17
+ return false;
18
+ }
19
+ if (typeParts[0] != "application") {
20
+ return false;
21
+ }
22
+ const subTypes = typeParts[1].split("+");
23
+ if (subTypes[subTypes.length - 1] == "json") {
24
+ return true;
25
+ }
26
+ return false;
27
+ }
28
+ /** @internal*/
29
+ export function isConfigSettingEqual(settingA, settingB) {
30
+ let valueIsEqual = settingA.value == settingB.value;
31
+ if (settingA.contentType == featureFlagContentType &&
32
+ settingB.contentType == featureFlagContentType &&
33
+ settingA.value !== undefined &&
34
+ settingB.value !== undefined) {
35
+ valueIsEqual = isFeatureFlagValueEqual(settingA.value, settingB.value);
36
+ }
37
+ return valueIsEqual &&
38
+ settingA.contentType == settingB.contentType &&
39
+ areTagsEqual(settingA.tags, settingB.tags);
40
+ }
41
+ /** @internal*/
42
+ export function areTagsEqual(tagA, tagB) {
43
+ if (isEmpty(tagA) || isEmpty(tagB)) {
44
+ return isEmpty(tagA) && isEmpty(tagB);
45
+ }
46
+ if (Object.keys(tagA).length !== Object.keys(tagB).length) {
47
+ return false;
48
+ }
49
+ for (const key in tagA) {
50
+ if (tagA[key] !== tagB[key]) {
51
+ return false;
52
+ }
53
+ }
54
+ return true;
55
+ }
56
+ /** @internal*/
57
+ /**
58
+ * Validate the ConfigurationSyncOptions argument, throw fatal error if options are not valid.
59
+ *
60
+ * @param options - ConfigurationSyncOptions to be validated.
61
+ */
62
+ export function validateOptions(options) {
63
+ if (!options) {
64
+ throw new ArgumentNullError();
65
+ }
66
+ if (options.profile == ConfigurationProfile.KvSet) {
67
+ if (options.prefix ||
68
+ options.separator ||
69
+ options.label ||
70
+ options.depth ||
71
+ options.tags ||
72
+ options.contentType) {
73
+ throw new ArgumentError("The option label, prefix, depth, contentType, tags and separator are not supported when importing using 'appconfig/kvset' profile");
74
+ }
75
+ if (options.format !== ConfigurationFormat.Json) {
76
+ throw new ArgumentError("Yaml and Properties formats are not supported for appconfig/kvset profile. Supported value is: Json");
77
+ }
78
+ }
79
+ if (options.depth && options.depth > 1 && !options.separator) {
80
+ throw new ArgumentError("Separator must be specified if Depth is default value or set a value lager than 1");
81
+ }
82
+ if (options.separator && !Constants.Separators.includes(options.separator)) {
83
+ throw new ArgumentError(`${options.separator} is not a supported separator.`);
84
+ }
85
+ if (!options.separator && !options.depth) {
86
+ options.depth = 1;
87
+ }
88
+ if (options.format !== ConfigurationFormat.Json && isJsonContentType(options.contentType)) {
89
+ throw new ArgumentError(`Failed to import '${ConfigurationFormat[options.format]}' data format with '${options.contentType}' content type. Please provide data in JSON format to match your content type.`);
90
+ }
91
+ }
92
+ function isFeatureFlagValueEqual(valueA, valueB) {
93
+ let featureFlagAValue;
94
+ if (typeof valueA == "string") {
95
+ featureFlagAValue = toFeatureFlagValue(valueA);
96
+ }
97
+ else {
98
+ featureFlagAValue = valueA;
99
+ }
100
+ const featureFlagBValue = toFeatureFlagValue(valueB);
101
+ if (Object.keys(featureFlagAValue).length !== Object.keys(featureFlagBValue).length) {
102
+ return false;
103
+ }
104
+ return featureFlagAValue.id == featureFlagBValue.id &&
105
+ featureFlagAValue.enabled == featureFlagBValue.enabled &&
106
+ featureFlagAValue.description == featureFlagBValue.description &&
107
+ areFeatureFlagFiltersEqual(featureFlagAValue.conditions.clientFilters, featureFlagBValue.conditions.clientFilters);
108
+ }
109
+ function areFeatureFlagFiltersEqual(filterA, filterB) {
110
+ if (filterA.length !== filterB.length) {
111
+ return false;
112
+ }
113
+ for (let i = 0; i < filterA.length; i++) {
114
+ if (!isEqual(filterA[i], filterB[i])) {
115
+ return false;
116
+ }
117
+ }
118
+ return true;
119
+ }
120
+ function toFeatureFlagValue(value) {
121
+ const parsedJson = JSON.parse(value);
122
+ return {
123
+ id: parsedJson.id,
124
+ enabled: parsedJson.enabled,
125
+ description: parsedJson.description,
126
+ conditions: isEmpty(parsedJson.conditions) ? { clientFilters: [] } : { clientFilters: parsedJson.conditions.client_filters }
127
+ };
128
+ }
129
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/internal/utils.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAElC,OAAO,EAIL,sBAAsB,EACA,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAG1C,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAElD,eAAe;AACf,MAAM,UAAU,iBAAiB,CAAC,WAAoB;IACpD,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,KAAK,CAAC;KACd;IAED,WAAW,GAAG,WAAW,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAC/C,MAAM,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;I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AAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;YACpC,OAAO,KAAK,CAAC;SACd;KACF;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAS,kBAAkB,CAAC,KAAa;IACvC,MAAM,UAAU,GAAQ,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAE1C,OAAO;QACL,EAAE,EAAE,UAAU,CAAC,EAAE;QACjB,OAAO,EAAE,UAAU,CAAC,OAAO;QAC3B,WAAW,EAAC,UAAU,CAAC,WAAW;QAClC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAC,aAAa,EAAE,EAAE,EAAC,CAAC,CAAC,CAAC,EAAC,aAAa,EAAE,UAAU,CAAC,UAAU,CAAC,cAAc,EAAC;KACzH,CAAC;AACJ,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport { \n ConfigurationSetting, \n SetConfigurationSettingParam, \n FeatureFlagValue,\n featureFlagContentType,\n SecretReferenceValue } from \"@azure/app-configuration\";\nimport { isEmpty, isEqual } from \"lodash\";\nimport { Tags, FeatureFlagClientFilters } from \"../models\";\nimport { SourceOptions } from \"../importOptions\";\nimport { ConfigurationFormat, ConfigurationProfile } from \"../enums\";\nimport { ArgumentError, ArgumentNullError } from \"../errors\";\nimport { Constants } from \"../internal/constants\";\n\n/** @internal*/\nexport function isJsonContentType(contentType?: string): boolean {\n if (!contentType) {\n return false;\n }\n\n contentType = contentType.trim().toLowerCase();\n const mineType = contentType.split(\";\")[0].trim();\n const typeParts = mineType.split(\"/\");\n if (typeParts.length != 2) {\n return false;\n }\n\n if (typeParts[0] != \"application\") {\n return false;\n }\n\n const subTypes = typeParts[1].split(\"+\");\n if (subTypes[subTypes.length-1] == \"json\") {\n return true;\n }\n\n return false;\n}\n\n/** @internal*/\nexport function isConfigSettingEqual(settingA: SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>, settingB: ConfigurationSetting) {\n let valueIsEqual: boolean = settingA.value == settingB.value;\n \n if (settingA.contentType == featureFlagContentType &&\n settingB.contentType == featureFlagContentType && \n settingA.value !== undefined && \n settingB.value !== undefined) {\n valueIsEqual = isFeatureFlagValueEqual(settingA.value as string | FeatureFlagValue, settingB.value);\n }\n\n return valueIsEqual &&\n settingA.contentType == settingB.contentType &&\n areTagsEqual(settingA.tags, settingB.tags);\n}\n\n/** @internal*/\nexport function areTagsEqual(tagA?: Tags, tagB?: Tags): boolean {\n if (isEmpty(tagA) || isEmpty(tagB)) {\n return isEmpty(tagA) && isEmpty(tagB);\n }\n\n if (Object.keys(tagA).length !== Object.keys(tagB).length) {\n return false;\n }\n\n for(const key in tagA) {\n if (tagA[key] !== tagB[key]) {\n return false;\n }\n }\n return true;\n}\n\n/** @internal*/\n/**\n * Validate the ConfigurationSyncOptions argument, throw fatal error if options are not valid.\n *\n * @param options - ConfigurationSyncOptions to be validated.\n */\nexport function validateOptions(options: SourceOptions): void {\n if (!options) {\n throw new ArgumentNullError();\n }\n\n if (options.profile == ConfigurationProfile.KvSet) {\n if (\n options.prefix ||\n options.separator ||\n options.label ||\n options.depth ||\n options.tags ||\n options.contentType\n ) {\n throw new ArgumentError(\n \"The option label, prefix, depth, contentType, tags and separator are not supported when importing using 'appconfig/kvset' profile\"\n );\n }\n\n if (options.format !== ConfigurationFormat.Json) {\n throw new ArgumentError(\n \"Yaml and Properties formats are not supported for appconfig/kvset profile. Supported value is: Json\"\n );\n }\n }\n\n if (options.depth && options.depth > 1 && !options.separator) {\n throw new ArgumentError(\n \"Separator must be specified if Depth is default value or set a value lager than 1\"\n );\n }\n\n if (options.separator && !Constants.Separators.includes(options.separator)) {\n throw new ArgumentError(`${options.separator} is not a supported separator.`);\n }\n\n if (!options.separator && !options.depth) {\n options.depth = 1;\n }\n\n if (options.format !== ConfigurationFormat.Json && isJsonContentType(options.contentType)) {\n throw new ArgumentError(`Failed to import '${ConfigurationFormat[options.format]}' data format with '${options.contentType}' content type. Please provide data in JSON format to match your content type.`);\n }\n}\n\nfunction isFeatureFlagValueEqual(valueA: string | FeatureFlagValue, valueB: string): boolean {\n let featureFlagAValue: FeatureFlagValue;\n\n if (typeof valueA == \"string\") {\n featureFlagAValue = toFeatureFlagValue(valueA);\n }\n else {\n featureFlagAValue = valueA;\n }\n\n const featureFlagBValue: FeatureFlagValue = toFeatureFlagValue(valueB);\n\n if (Object.keys(featureFlagAValue).length !== Object.keys(featureFlagBValue).length) {\n return false;\n }\n\n return featureFlagAValue.id == featureFlagBValue.id &&\n featureFlagAValue.enabled == featureFlagBValue.enabled &&\n featureFlagAValue.description == featureFlagBValue.description &&\n areFeatureFlagFiltersEqual(featureFlagAValue.conditions.clientFilters, featureFlagBValue.conditions.clientFilters);\n}\n\nfunction areFeatureFlagFiltersEqual(filterA: FeatureFlagClientFilters[], filterB: FeatureFlagClientFilters[]): boolean {\n if (filterA.length !== filterB.length) {\n return false;\n }\n\n for (let i = 0; i < filterA.length; i++) {\n if (!isEqual(filterA[i], filterB[i])) {\n return false;\n }\n }\n return true;\n}\n\nfunction toFeatureFlagValue(value: string): FeatureFlagValue {\n const parsedJson: any = JSON.parse(value);\n\n return {\n id: parsedJson.id,\n enabled: parsedJson.enabled,\n description:parsedJson.description,\n conditions: isEmpty(parsedJson.conditions) ? {clientFilters: []} : {clientFilters: parsedJson.conditions.client_filters}\n };\n}\n"]}
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ export {};
4
+ //# sourceMappingURL=models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"models.js","sourceRoot":"","sources":["../../src/models.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\n/**\n * @internal\n */\nexport type ClientFilter = { name: string; parameters?: Record<string, unknown> };\n\n/**\n * @internal\n */\nexport interface JsonSecretReferenceValue {\n uri: string;\n}\n\n/**\n * @internal\n */\nexport type KvSetConfigurationItem = {\n key: string;\n value?: string;\n label?: string;\n content_type?: string;\n tags?: { [propertyName: string]: string };\n}\n\nexport interface ImportProgress {\n successCount: number;\n importCount: number;\n}\n\nexport interface Tags {\n [propertyName: string]: string;\n}\n\nexport interface FeatureFlagClientFilters {\n name: string;\n parameters?: Record<string, unknown> | undefined;\n}\n\nexport interface KeyLabelLookup {\n [key: string]: {\n [label: string] : boolean\n }\n}"]}
@@ -0,0 +1,4 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ export {};
4
+ //# sourceMappingURL=configurationSettingsSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configurationSettingsSource.js","sourceRoot":"","sources":["../../../src/settingsImport/configurationSettingsSource.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FeatureFlagValue,\n ListConfigurationSettingsOptions,\n SecretReferenceValue,\n SetConfigurationSettingParam\n} from \"@azure/app-configuration\";\n\n/**\n * Interface of all ConfigurationSettingsSource\n */\nexport interface ConfigurationSettingsSource {\n /**\n * Get ConfigurationSettings collection from source.\n *\n * @returns Collection of ConfigurationSettings\n */\n GetConfigurationSettings(): Promise<Array<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>>>;\n\n /**\n * Get label and prefix filter\n *\n * @returns label and prefix\n */\n FilterOptions: ListConfigurationSettingsOptions;\n}\n"]}
@@ -0,0 +1,83 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
4
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
5
+ var m = o[Symbol.asyncIterator], i;
6
+ return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
7
+ function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
8
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
9
+ };
10
+ import { featureFlagContentType, featureFlagPrefix, secretReferenceContentType } from "@azure/app-configuration";
11
+ import { ArgumentError } from "../errors";
12
+ export class IterableConfigurationSettingsSource {
13
+ constructor(options) {
14
+ this.FilterOptions = {};
15
+ this.data = options.data;
16
+ this.options = options;
17
+ this.FilterOptions = {
18
+ keyFilter: options.prefix ? options.prefix + "*" : undefined,
19
+ labelFilter: options.label ? options.label : "\0"
20
+ };
21
+ }
22
+ /**
23
+ * @inheritdoc
24
+ */
25
+ async GetConfigurationSettings() {
26
+ var _a, e_1, _b, _c;
27
+ const result = [];
28
+ try {
29
+ for (var _d = true, _e = __asyncValues(this.data), _f; _f = await _e.next(), _a = _f.done, !_a;) {
30
+ _c = _f.value;
31
+ _d = false;
32
+ try {
33
+ const configuration = _c;
34
+ const isFeatureFlag = configuration.key.startsWith(featureFlagPrefix) && configuration.contentType == featureFlagContentType;
35
+ const isKeyVaultReference = configuration.contentType == secretReferenceContentType;
36
+ const contentType = isFeatureFlag || isKeyVaultReference ?
37
+ configuration.contentType :
38
+ this.options.contentType || configuration.contentType;
39
+ let generatedKey = configuration.key;
40
+ if (this.options.prefix || this.options.trimPrefix) {
41
+ if (isFeatureFlag) {
42
+ generatedKey = generatedKey.substring(featureFlagPrefix.length);
43
+ }
44
+ if (this.options.trimPrefix && generatedKey.startsWith(this.options.trimPrefix)) {
45
+ generatedKey = generatedKey.substring(this.options.trimPrefix.length);
46
+ }
47
+ if (this.options.prefix) {
48
+ generatedKey = this.options.prefix + generatedKey;
49
+ }
50
+ if (isFeatureFlag) {
51
+ generatedKey = featureFlagPrefix + generatedKey;
52
+ }
53
+ }
54
+ if (generatedKey === "." || generatedKey === ".." || generatedKey.indexOf("%") > -1) {
55
+ throw new ArgumentError("Key cannot be a '.' or '..', or contain the '%' character.");
56
+ }
57
+ if (this.options.skipFeatureFlags && isFeatureFlag) {
58
+ continue;
59
+ }
60
+ result.push({
61
+ key: generatedKey,
62
+ label: this.options.label || configuration.label,
63
+ value: configuration.value,
64
+ contentType: contentType,
65
+ tags: configuration.tags
66
+ });
67
+ }
68
+ finally {
69
+ _d = true;
70
+ }
71
+ }
72
+ }
73
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
74
+ finally {
75
+ try {
76
+ if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
77
+ }
78
+ finally { if (e_1) throw e_1.error; }
79
+ }
80
+ return result;
81
+ }
82
+ }
83
+ //# sourceMappingURL=iterableConfigurationSettingsSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"iterableConfigurationSettingsSource.js","sourceRoot":"","sources":["../../../src/settingsImport/iterableConfigurationSettingsSource.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;;;;;;;;AAIlC,OAAO,EAOL,sBAAsB,EACtB,iBAAiB,EACjB,0BAA0B,EAAC,MAAM,0BAA0B,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,OAAO,mCAAmC;IAM9C,YAAY,OAA8B;QALnC,kBAAa,GAAqC,EAAE,CAAC;QAM1D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,aAAa,GAAG;YACnB,SAAS,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,SAAS;YAC5D,WAAW,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI;SA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yBACjD;qBACF;oBAED,IAAI,YAAY,KAAK,GAAG,IAAI,YAAY,KAAK,IAAI,IAAI,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE;wBACnF,MAAM,IAAI,aAAa,CAAC,4DAA4D,CAAC,CAAC;qBACvF;oBAED,IAAI,IAAI,CAAC,OAAO,CAAC,gBAAgB,IAAI,aAAa,EAAE;wBAClD,SAAS;qBACV;oBAED,MAAM,CAAC,IAAI,CAAC;wBACV,GAAG,EAAE,YAAY;wBACjB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK,IAAI,aAAa,CAAC,KAAK;wBAChD,KAAK,EAAE,aAAa,CAAC,KAAK;wBAC1B,WAAW,EAAE,WAAW;wBACxB,IAAI,EAAE,aAAa,CAAC,IAAI;qBACzB,CAAC,CAAC;;;;;aACJ;;;;;;;;;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT License.\n\nimport { PagedAsyncIterableIterator, PageSettings } from \"@azure/core-paging\";\nimport { ConfigurationSettingsSource } from \"./configurationSettingsSource\";\nimport { \n ConfigurationSetting, \n SetConfigurationSettingParam, \n FeatureFlagValue,\n SecretReferenceValue,\n ListConfigurationSettingsOptions, \n ListConfigurationSettingPage, \n featureFlagContentType,\n featureFlagPrefix,\n secretReferenceContentType} from \"@azure/app-configuration\";\nimport { IterableSourceOptions } from \"../importOptions\";\nimport { ArgumentError } from \"../errors\";\n\nexport class IterableConfigurationSettingsSource implements ConfigurationSettingsSource {\n public FilterOptions: ListConfigurationSettingsOptions = {};\n\n private data: PagedAsyncIterableIterator<ConfigurationSetting<string>, ListConfigurationSettingPage, PageSettings>;\n private options: IterableSourceOptions;\n\n constructor(options: IterableSourceOptions) {\n this.data = options.data;\n this.options = options;\n \n this.FilterOptions = {\n keyFilter: options.prefix ? options.prefix + \"*\" : undefined,\n labelFilter: options.label ? options.label : \"\\0\"\n };\n }\n \n /**\n * @inheritdoc\n */\n public async GetConfigurationSettings(): Promise<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>[]> {\n const result: SetConfigurationSettingParam[] = [];\n\n for await (const configuration of this.data) {\n const isFeatureFlag: boolean = configuration.key.startsWith(featureFlagPrefix) && configuration.contentType == featureFlagContentType;\n const isKeyVaultReference: boolean = configuration.contentType == secretReferenceContentType;\n const contentType: string | undefined = isFeatureFlag || isKeyVaultReference ?\n configuration.contentType :\n this.options.contentType || configuration.contentType;\n\n let generatedKey: string = configuration.key;\n \n if (this.options.prefix || this.options.trimPrefix) {\n if (isFeatureFlag) {\n generatedKey = generatedKey.substring(featureFlagPrefix.length);\n }\n\n if (this.options.trimPrefix && generatedKey.startsWith(this.options.trimPrefix)) {\n generatedKey = generatedKey.substring(this.options.trimPrefix.length);\n }\n\n if (this.options.prefix) {\n generatedKey = this.options.prefix + generatedKey;\n }\n\n if(isFeatureFlag) {\n generatedKey = featureFlagPrefix + generatedKey;\n }\n }\n \n if (generatedKey === \".\" || generatedKey === \"..\" || generatedKey.indexOf(\"%\") > -1) {\n throw new ArgumentError(\"Key cannot be a '.' or '..', or contain the '%' character.\");\n }\n \n if (this.options.skipFeatureFlags && isFeatureFlag) {\n continue;\n }\n\n result.push({\n key: generatedKey,\n label: this.options.label || configuration.label,\n value: configuration.value,\n contentType: contentType,\n tags: configuration.tags\n });\n }\n\n return result;\n }\n}"]}
@@ -0,0 +1,49 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { toWebStream } from "../internal/stream";
4
+ import { ConfigurationProfile } from "../enums";
5
+ import { StringConfigurationSettingsSource } from "./stringConfigurationSettingsSource";
6
+ import { validateOptions } from "../internal/utils";
7
+ export class ReadableStreamConfigurationSettingsSource {
8
+ constructor(options) {
9
+ this.FilterOptions = {};
10
+ validateOptions(options);
11
+ this.options = options;
12
+ this.data = options.data;
13
+ if (options.profile == ConfigurationProfile.Default) {
14
+ this.FilterOptions = {
15
+ keyFilter: options.prefix ? options.prefix + "*" : undefined,
16
+ labelFilter: options.label ? options.label : "\0"
17
+ };
18
+ }
19
+ else if (options.profile == ConfigurationProfile.KvSet) {
20
+ this.FilterOptions = {
21
+ keyFilter: "*",
22
+ labelFilter: "*"
23
+ };
24
+ }
25
+ }
26
+ async GetConfigurationSettings() {
27
+ const reader = toWebStream(this.data).getReader();
28
+ const textDecoder = new TextDecoder("utf-8");
29
+ try {
30
+ let allData = "";
31
+ // eslint-disable-next-line no-constant-condition
32
+ while (true) {
33
+ const { done, value } = await reader.read();
34
+ if (done) {
35
+ const stringSource = new StringConfigurationSettingsSource(Object.assign(Object.assign({}, this.options), { data: allData }));
36
+ const settings = await stringSource.GetConfigurationSettings();
37
+ return settings;
38
+ }
39
+ if (value) {
40
+ allData += textDecoder.decode(value);
41
+ }
42
+ }
43
+ }
44
+ finally {
45
+ reader.releaseLock();
46
+ }
47
+ }
48
+ }
49
+ //# sourceMappingURL=readableStreamConfigurationSettingsSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readableStreamConfigurationSettingsSource.js","sourceRoot":"","sources":["../../../src/settingsImport/readableStreamConfigurationSettingsSource.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAGlC,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AACxF,OAAO,EAAE,eAAe,EAAC,MAAM,mBAAmB,CAAC;AAEnD,MAAM,OAAO,yCAAyC;IAKpD,YAAY,OAAoC;QAJzC,kBAAa,GAAqC,EAAE,CAAC;QAK1D,eAAe,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAEzB,IAAI,OAAO,CAAC,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// Licensed under the MIT License.\n\nimport { SetConfigurationSettingParam, FeatureFlagValue, SecretReferenceValue, ListConfigurationSettingsOptions } from \"@azure/app-configuration\";\nimport { toWebStream } from \"../internal/stream\";\nimport { ReadableStreamSourceOptions, SourceOptions } from \"../importOptions\";\nimport { ConfigurationSettingsSource } from \"./configurationSettingsSource\";\nimport { ConfigurationProfile } from \"../enums\";\nimport { StringConfigurationSettingsSource } from \"./stringConfigurationSettingsSource\";\nimport { validateOptions} from \"../internal/utils\";\n\nexport class ReadableStreamConfigurationSettingsSource implements ConfigurationSettingsSource { \n public FilterOptions: ListConfigurationSettingsOptions = {};\n private options: SourceOptions;\n private data: ReadableStream<Uint8Array> | NodeJS.ReadableStream;\n\n constructor(options: ReadableStreamSourceOptions) {\n validateOptions(options);\n this.options = options;\n this.data = options.data;\n\n if (options.profile == ConfigurationProfile.Default) {\n this.FilterOptions = {\n keyFilter: options.prefix ? options.prefix + \"*\" : undefined,\n labelFilter: options.label ? options.label : \"\\0\"\n };\n }\n else if (options.profile == ConfigurationProfile.KvSet) {\n this.FilterOptions = {\n keyFilter: \"*\",\n labelFilter: \"*\"\n };\n }\n }\n\n public async GetConfigurationSettings(): Promise<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>[]> {\n const reader: ReadableStreamDefaultReader = toWebStream(this.data).getReader();\n const textDecoder = new TextDecoder(\"utf-8\");\n\n try {\n let allData = \"\";\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const { done, value } = await reader.read();\n if (done) {\n const stringSource = new StringConfigurationSettingsSource({...this.options, data: allData});\n const settings = await stringSource.GetConfigurationSettings();\n\n return settings;\n }\n\n if (value) {\n allData += textDecoder.decode(value);\n }\n }\n }\n finally{\n reader.releaseLock();\n }\n }\n}"]}
@@ -0,0 +1,92 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT license.
3
+ import * as jsyaml from "js-yaml";
4
+ import stripJSONComments from "strip-json-comments";
5
+ import { getProperties } from "properties-file";
6
+ import { ConfigurationFormat, ConfigurationProfile } from "../enums";
7
+ import { ArgumentError, ParseError } from "../errors";
8
+ import { validateOptions } from "../internal/utils";
9
+ import { DefaultConfigurationSettingsConverter } from "../internal/parsers/defaultConfigurationSettingsConverter";
10
+ import { KvSetConfigurationSettingsConverter } from "../internal/parsers/kvSetConfigurationSettingsConverter";
11
+ /**
12
+ * ConfigurationSettingsSource implementation of string data configuration source
13
+ */
14
+ export class StringConfigurationSettingsSource {
15
+ constructor(options) {
16
+ this.FilterOptions = {};
17
+ validateOptions(options);
18
+ this.options = options;
19
+ this.data = options.data;
20
+ if (options.profile == ConfigurationProfile.Default) {
21
+ this.FilterOptions = {
22
+ keyFilter: options.prefix ? options.prefix + "*" : undefined,
23
+ labelFilter: options.label ? options.label : "\0"
24
+ };
25
+ }
26
+ else if (options.profile == ConfigurationProfile.KvSet) {
27
+ this.FilterOptions = {
28
+ keyFilter: "*",
29
+ labelFilter: "*"
30
+ };
31
+ }
32
+ }
33
+ /**
34
+ * @inheritdoc
35
+ */
36
+ async GetConfigurationSettings() {
37
+ return this.getConfigurationSettingsInternal(this.data);
38
+ }
39
+ /**
40
+ * Get the ConfigurationSettings from supplied data string source.
41
+ *
42
+ * @param data The string data being parsed.
43
+ * @returns Collection of ConfigurationSettings
44
+ */
45
+ getConfigurationSettingsInternal(data) {
46
+ let loadedData = {};
47
+ // Checking string encoding format
48
+ if (/^\uFEFF/.test(data)) {
49
+ throw new ParseError("Failed to parse data: An invalid encoding, UTF-8 with BOM, was detected. Please update encoding to UTF-8 without BOM.");
50
+ }
51
+ try {
52
+ switch (this.options.format) {
53
+ case ConfigurationFormat.Json: {
54
+ loadedData = JSON.parse(stripJSONComments(data));
55
+ break;
56
+ }
57
+ case ConfigurationFormat.Yaml: {
58
+ const temp = jsyaml.load(data, { schema: jsyaml.JSON_SCHEMA });
59
+ if (temp === undefined) {
60
+ throw new ParseError("Failed to parse data: Not a valid yaml format.");
61
+ }
62
+ else {
63
+ loadedData = temp;
64
+ }
65
+ break;
66
+ }
67
+ case ConfigurationFormat.Properties: {
68
+ loadedData = getProperties(data);
69
+ break;
70
+ }
71
+ default: {
72
+ throw new ArgumentError("Data Format provided is not supported. Supported values are: Json, Yaml and Properties.");
73
+ }
74
+ }
75
+ }
76
+ catch (e) {
77
+ throw new ParseError(`Failed to parse data: ${e.message}`);
78
+ }
79
+ if (typeof loadedData !== "object") {
80
+ throw new ParseError(`Type of data be parsed is ${typeof loadedData}, not a valid object type`);
81
+ }
82
+ let converter;
83
+ if (this.options.profile === ConfigurationProfile.KvSet) {
84
+ converter = new KvSetConfigurationSettingsConverter();
85
+ }
86
+ else {
87
+ converter = new DefaultConfigurationSettingsConverter();
88
+ }
89
+ return converter.Convert(loadedData, this.options);
90
+ }
91
+ }
92
+ //# sourceMappingURL=stringConfigurationSettingsSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringConfigurationSettingsSource.js","sourceRoot":"","sources":["../../../src/settingsImport/stringConfigurationSettingsSource.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,kCAAkC;AAQlC,OAAO,KAAK,MAAM,MAAM,SAAS,CAAC;AAClC,OAAO,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAG,MAAM,iBAAiB,CAAC;AAGjD,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,OAAO,EAAE,qCAAqC,EAAE,MAAM,2DAA2D,CAAC;AAClH,OAAO,EAAE,mCAAmC,EAAE,MAAM,yDAAyD,CAAC;AAE9G;;GAEG;AACH,MAAM,OAAO,iCAAiC;IAK5C,YAAY,OAA4B;QAJjC,kBAAa,GAAqC,EAAE,CAAC;QAK1D,eAAe,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI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M,CAAC,WAAW,EAAE,CAAC,CAAC;oBAC/D,IAAI,IAAI,KAAK,SAAS,EAAE;wBACtB,MAAM,IAAI,UAAU,CAClB,gDAAgD,CACjD,CAAC;qBACH;yBACI;wBACH,UAAU,GAAG,IAAI,CAAC;qBACnB;oBACD,MAAM;iBACP;gBACD,KAAK,mBAAmB,CAAC,UAAU,CAAC,CAAC;oBACnC,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC;oBACjC,MAAM;iBACP;gBACD,OAAO,CAAC,CAAC;oBACP,MAAM,IAAI,aAAa,CAAC,yFAAyF,CAAC,CAAC;iBACpH;aACF;SACF;QACD,OAAO,CAAM,EAAE;YACb,MAAM,IAAI,UAAU,CAAC,yBAAyB,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;SAC5D;QAED,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;YAClC,MAAM,IAAI,UAAU,CAClB,6BAA6B,OAAO,UAAU,2BAA2B,CAC1E,CAAC;SACH;QAED,IAAI,SAAyC,CAAC;QAC9C,IAAI,IAAI,CAAC,OAAO,CAAC,OAAO,KAAK,oBAAoB,CAAC,KAAK,EAAE;YACvD,SAAS,GAAG,IAAI,mCAAmC,EAAE,CAAC;SACvD;aACI;YACH,SAAS,GAAG,IAAI,qCAAqC,EAAE,CAAC;SACzD;QAED,OAAO,SAAS,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;IACrD,CAAC;CACF","sourcesContent":["// Copyright (c) Microsoft Corporation.\n// Licensed under the MIT license.\n\nimport {\n FeatureFlagValue,\n ListConfigurationSettingsOptions,\n SecretReferenceValue,\n SetConfigurationSettingParam\n} from \"@azure/app-configuration\";\nimport * as jsyaml from \"js-yaml\";\nimport stripJSONComments from \"strip-json-comments\";\nimport { getProperties } from \"properties-file\";\nimport { SourceOptions, StringSourceOptions } from \"../importOptions\";\nimport { ConfigurationSettingsSource } from \"./configurationSettingsSource\";\nimport { ConfigurationFormat, ConfigurationProfile } from \"../enums\";\nimport { ArgumentError, ParseError } from \"../errors\";\nimport { validateOptions } from \"../internal/utils\";\nimport { ConfigurationSettingsConverter } from \"../internal/parsers/configurationSettingsConverter\";\nimport { DefaultConfigurationSettingsConverter } from \"../internal/parsers/defaultConfigurationSettingsConverter\";\nimport { KvSetConfigurationSettingsConverter } from \"../internal/parsers/kvSetConfigurationSettingsConverter\";\n\n/**\n * ConfigurationSettingsSource implementation of string data configuration source\n */\nexport class StringConfigurationSettingsSource implements ConfigurationSettingsSource {\n public FilterOptions: ListConfigurationSettingsOptions = {};\n private options: SourceOptions;\n private data: string;\n\n constructor(options: StringSourceOptions) {\n validateOptions(options);\n this.options = options;\n this.data = options.data;\n\n if (options.profile == ConfigurationProfile.Default) {\n this.FilterOptions = {\n keyFilter: options.prefix ? options.prefix + \"*\" : undefined,\n labelFilter: options.label ? options.label : \"\\0\"\n };\n }\n else if (options.profile == ConfigurationProfile.KvSet) {\n this.FilterOptions = {\n keyFilter: \"*\",\n labelFilter: \"*\"\n };\n }\n }\n\n /**\n * @inheritdoc\n */\n public async GetConfigurationSettings(): Promise<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>[]> {\n return this.getConfigurationSettingsInternal(this.data);\n }\n\n /**\n * Get the ConfigurationSettings from supplied data string source.\n * \n * @param data The string data being parsed.\n * @returns Collection of ConfigurationSettings\n */\n protected getConfigurationSettingsInternal(data: string): Array<\n SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>\n > {\n let loadedData: any = {};\n // Checking string encoding format\n if (/^\\uFEFF/.test(data)) {\n throw new ParseError(\n \"Failed to parse data: An invalid encoding, UTF-8 with BOM, was detected. Please update encoding to UTF-8 without BOM.\"\n );\n }\n\n try {\n switch (this.options.format) {\n case ConfigurationFormat.Json: {\n loadedData = JSON.parse(stripJSONComments(data));\n break;\n }\n case ConfigurationFormat.Yaml: {\n const temp = jsyaml.load(data, { schema: jsyaml.JSON_SCHEMA });\n if (temp === undefined) {\n throw new ParseError(\n \"Failed to parse data: Not a valid yaml format.\"\n );\n }\n else {\n loadedData = temp;\n }\n break;\n }\n case ConfigurationFormat.Properties: {\n loadedData = getProperties(data);\n break;\n }\n default: {\n throw new ArgumentError(\"Data Format provided is not supported. Supported values are: Json, Yaml and Properties.\");\n }\n }\n }\n catch (e: any) {\n throw new ParseError(`Failed to parse data: ${e.message}`);\n }\n\n if (typeof loadedData !== \"object\") {\n throw new ParseError(\n `Type of data be parsed is ${typeof loadedData}, not a valid object type`\n );\n }\n\n let converter: ConfigurationSettingsConverter;\n if (this.options.profile === ConfigurationProfile.KvSet) {\n converter = new KvSetConfigurationSettingsConverter();\n }\n else {\n converter = new DefaultConfigurationSettingsConverter();\n }\n\n return converter.Convert(loadedData, this.options);\n }\n}"]}