@azure/app-configuration-importer 1.0.0-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.
@@ -0,0 +1,59 @@
1
+ # Examples for Azure App Configuration Importer
2
+
3
+ These examples show how to use the App Configuration Importer in some common scenarios
4
+
5
+ | File Name | Description |
6
+ | ---------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
7
+ | [fileSourceExample.ts](./src/fileSourceExample.ts) | Demonstrates importing configuration settings from a File source |
8
+ | [iterableSourceExample.ts](./src/iterableSourceExample.ts) | Demonstrates importing configuration settings from an Iterable source |
9
+ | [stringSourceExample.ts](./src/stringSourceExample.ts) | Demonstrates importing configuration settings from a String source |
10
+ | [readableStreamSourceExample](./src/readableStreamSourceExample.ts) | Demonstrates importing configuration settings from a ReadableStream source |
11
+
12
+ ## Prerequisites
13
+
14
+ The example are compatible with [LTS version of Node.js](https://github.com/nodejs/release#release-schedule)
15
+
16
+ You'll need the following Azure resources to run the examples
17
+
18
+ - An [Azure subscription](https://azure.microsoft.com/free/)
19
+ - An [Azure App Configuration store](https://learn.microsoft.com/azure/azure-app-configuration/quickstart-azure-app-configuration-create?tabs=azure-portal)
20
+
21
+ Before running the samples in Node, they must be complied to JavaScript using the TypeScript complier. For more information on TypeScript,
22
+ see the [TypeScript documentation](https://www.typescriptlang.org/docs/home). Install the TypeScript compiler using:
23
+
24
+ ```bash
25
+ npm install -g typescript
26
+ ```
27
+
28
+ ## Setup & Run
29
+
30
+ To run the examples using the published version of the package:
31
+
32
+ 1. Install the dependencies using `npm`:
33
+
34
+ ```bash
35
+ npm install
36
+ ```
37
+ 2. There are two ways to run the examples using the correct credentials:
38
+
39
+ - Edit the file `sample.env`, adding the correct credentials to access your App Configuration. Then rename the file from `sample.env` to just `.env`. The examples will read the file automatically.
40
+
41
+ - Alternatively, you can set the environment variable to the access keys to your App Configuration store. In this case, setting up the `.env` file is not required.
42
+
43
+ ```bash
44
+ npx cross-env APPCONFIG_CONNECTION_STRING="<appconfig connection string>"
45
+ ```
46
+
47
+ 3. Compile the examples
48
+
49
+ ```bash
50
+ npm run build
51
+ ```
52
+
53
+ 4. Run whichever example you like
54
+
55
+ ```bash
56
+ node dist\fileSourceExample.js
57
+ ```
58
+
59
+ 5. Clean up any configuration settings that may have been imported to your store if you don't plan on using them.
@@ -0,0 +1,32 @@
1
+ {
2
+ "name": "@azure-samples/app-configuration-importer-ts",
3
+ "private": true,
4
+ "version": "1.0.0",
5
+ "description": "Azure App Configuration Importer client library samples for TypeScript",
6
+ "engines": {
7
+ "node": ">=18.0.0"
8
+ },
9
+ "scripts": {
10
+ "build": "npm run clean && tsc -b",
11
+ "clean": "rimraf dist/"
12
+ },
13
+ "keywords": [
14
+ "node",
15
+ "azure",
16
+ "typescript",
17
+ "browser",
18
+ "cloud"
19
+ ],
20
+ "author": "Microsoft Corporation",
21
+ "license": "MIT",
22
+ "dependencies": {
23
+ "dotenv": "latest",
24
+ "@azure/app-configuration-importer": "latest",
25
+ "@azure/app-configuration-importer-file-source": "latest"
26
+ },
27
+ "devDependencies": {
28
+ "@types/node": "^18.0.0",
29
+ "typescript": "~5.4.5",
30
+ "rimraf": "latest"
31
+ }
32
+ }
@@ -0,0 +1,6 @@
1
+ # This is the connection string for your app-configuration resource
2
+ # You can get this from the Azure portal.
3
+ APPCONFIG_CONNECTION_STRING=<app-configuration connection string goes here>
4
+
5
+ # This is the connection string for your source app-configuration resource, will be used in the iterableSource example, when importing configuration settings from one store to another
6
+ APPCONFIG_CONNECTION_STRING_SRC_STORE=<app-configuration connection string goes here>
@@ -0,0 +1,24 @@
1
+ {
2
+ "app":{
3
+ "Settings":{
4
+ "FontSize": "45",
5
+ "BackgroundColor": "yellow",
6
+ "FontColor":"black"
7
+ }
8
+ },
9
+ "FeatureManagement": {
10
+ "FeatureT": true,
11
+ "FeatureU": false,
12
+ "FeatureV": {
13
+ "EnabledFor": [
14
+ {
15
+ "Name": "TimeWindow",
16
+ "Parameters": {
17
+ "Start": "Wed, 01 May 2019 13:59:59 GMT",
18
+ "End": "Mon, 01 July 2019 00:00:00 GMT"
19
+ }
20
+ }
21
+ ]
22
+ }
23
+ }
24
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "items": [
3
+ {
4
+ "key": ".appconfig.featureflag/Beta",
5
+ "value": "{\"id\":\"Beta\",\"description\":\"Beta feature\",\"enabled\":true,\"conditions\":{\"client_filters\":[]}}",
6
+ "label": "MyLabel",
7
+ "content_type": "application/vnd.microsoft.appconfig.ff+json;charset=utf-8",
8
+ "tags": {}
9
+ },
10
+ {
11
+ "key": "test:app:Database:ConnectionString",
12
+ "value": "{\"uri\":\"https://keyvault.vault.azure.net/secrets/db-secret\"}",
13
+ "label": "MyLabel",
14
+ "content_type": "application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8",
15
+ "tags": {}
16
+ },
17
+ {
18
+ "key": "test:app:Env",
19
+ "value": "Debug",
20
+ "label": "MyLabel",
21
+ "content_type": null,
22
+ "tags": {
23
+ "tag1": "value1",
24
+ "tag2": "value2"
25
+ }
26
+ },
27
+ {
28
+ "key": "test:app:BackgroundColor",
29
+ "value": "yellow",
30
+ "label": "MyLabel",
31
+ "content_type": null,
32
+ "tags": {}
33
+ }
34
+ ]
35
+ }
package/package.json ADDED
@@ -0,0 +1,78 @@
1
+ {
2
+ "name": "@azure/app-configuration-importer",
3
+ "author": "Microsoft Corporation",
4
+ "description": "A client library for importing/exporting key-values between configuration sources and Azure App Configuration service",
5
+ "version": "1.0.0-preview",
6
+ "sdk-type": "client",
7
+ "keywords": [
8
+ "node",
9
+ "azure",
10
+ "typescript"
11
+ ],
12
+ "license": "MIT",
13
+ "main": "./dist/index.js",
14
+ "module": "./dist-esm/src/index.js",
15
+ "browser": {
16
+ "./dist-esm/src/internal/stream.js": "./dist-esm/src/internal/stream.browser.js"
17
+ },
18
+ "types": "./types/azure-app-configuration-importer.d.ts",
19
+ "scripts": {
20
+ "build": "npm run clean && tsc -p . && rollup -c && api-extractor run --local",
21
+ "test": "cross-env TS_NODE_PROJECT=\"tsconfig.test.json\" mocha -r ts-node/register 'tests/**/*.ts'",
22
+ "check-format": "eslint src tests",
23
+ "format": "eslint src tests --fix",
24
+ "clean": "rimraf dist dist-* types *.tgz *.log"
25
+ },
26
+ "dependencies": {
27
+ "@azure/app-configuration": "1.5.0",
28
+ "@azure/core-paging": "^1.4.0",
29
+ "@azure/core-rest-pipeline": "^1.6.0",
30
+ "flat": "^5.0.2",
31
+ "js-yaml": "^4.1.0",
32
+ "properties-file": "^3.5.4",
33
+ "rxjs": "^7.5.6",
34
+ "tslib": "^2.2.0",
35
+ "strip-json-comments": "^3.1.1",
36
+ "lodash": "^4.17.21"
37
+ },
38
+ "devDependencies": {
39
+ "@microsoft/api-extractor": "^7.22.2",
40
+ "@rollup/plugin-commonjs": "^21.0.1",
41
+ "@rollup/plugin-inject": "^4.0.0",
42
+ "@rollup/plugin-json": "^4.0.0",
43
+ "@rollup/plugin-multi-entry": "^3.0.0",
44
+ "@rollup/plugin-node-resolve": "^8.0.0",
45
+ "@rollup/plugin-replace": "^2.2.0",
46
+ "@types/chai": "^4.1.6",
47
+ "@types/flat": "^5.0.2",
48
+ "@types/js-yaml": "^3.12.7",
49
+ "@types/lodash": "^4.14.189",
50
+ "@types/mocha": "^7.0.2",
51
+ "@types/node": "^18.0.0",
52
+ "@types/nodegit": "^0.22.5",
53
+ "@types/sinon": "^10.0.11",
54
+ "@typescript-eslint/eslint-plugin": "^5.30.0",
55
+ "@typescript-eslint/parser": "^5.30.0",
56
+ "chai": "^4.2.0",
57
+ "colors": "1.4.0",
58
+ "cross-env": "^7.0.2",
59
+ "dotenv": "^8.2.0",
60
+ "eslint": "^8.18.0",
61
+ "esm": "^3.2.18",
62
+ "mocha": "^10.2.0",
63
+ "mocha-junit-reporter": "^2.0.0",
64
+ "rimraf": "^3.0.0",
65
+ "rollup": "^2.38.3",
66
+ "rollup-plugin-commonjs": "^10.1.0",
67
+ "rollup-plugin-dts": "^4.2.1",
68
+ "rollup-plugin-node-resolve": "^5.2.0",
69
+ "rollup-plugin-shim": "^1.0.0",
70
+ "rollup-plugin-sourcemaps": "^0.4.2",
71
+ "rollup-plugin-terser": "^5.1.1",
72
+ "rollup-plugin-typescript2": "^0.31.2",
73
+ "sinon": "^13.0.2",
74
+ "ts-node": "^10.0.0",
75
+ "typescript": "^4.6.3",
76
+ "@azure/core-http": "^3.0.1"
77
+ }
78
+ }
@@ -0,0 +1,203 @@
1
+ /// <reference types="node" />
2
+
3
+ import { AppConfigurationClient } from '@azure/app-configuration';
4
+ import { ConfigurationSetting } from '@azure/app-configuration';
5
+ import { FeatureFlagValue } from '@azure/app-configuration';
6
+ import { ListConfigurationSettingPage } from '@azure/app-configuration';
7
+ import { ListConfigurationSettingsOptions } from '@azure/app-configuration';
8
+ import { PagedAsyncIterableIterator } from '@azure/core-paging';
9
+ import { PageSettings } from '@azure/core-paging';
10
+ import { SecretReferenceValue } from '@azure/app-configuration';
11
+ import { SetConfigurationSettingParam } from '@azure/app-configuration';
12
+
13
+ /**
14
+ * Entrypoint class for sync configuration
15
+ */
16
+ export declare class AppConfigurationImporter {
17
+ private configurationClient;
18
+ /**
19
+ * Initializes a new instance of the AppConfigurationSync class.
20
+ * @param configurationClient - App configuration client for manipulate the target App Configuration.
21
+ */
22
+ constructor(configurationClient: AppConfigurationClient);
23
+ /**
24
+ * Import source settings into the Azure App Configuration service
25
+ *
26
+ * Example usage:
27
+ * ```ts
28
+ * const fileData = fs.readFileSync("mylocalPath").toString();
29
+ * const result = await asyncClient.Import(new StringConfigurationSettingsSource({data:fileData, format: ConfigurationFormat.Json}));
30
+ * ```
31
+ * @param configSettingsSource - A ConfigurationSettingsSource instance.
32
+ * @param strict - Use strict mode or not.
33
+ * @param timeout - Seconds of entire import progress timeout
34
+ * @param progressCallback - Callback for report the progress of import
35
+ * @param importMode - Determines the behavior when importing key-values. The default value, 'All' will import all key-values in the input file to App Configuration. 'Ignore-Match' will only import settings that have no matching key-value in App Configuration.
36
+ * @param dryRun - When dry run is enabled, no updates will be performed to App Configuration. Instead, any updates that would have been performed in a normal run will be printed to the console for review
37
+ */
38
+ Import(configSettingsSource: ConfigurationSettingsSource, timeout: number, strict?: boolean, progressCallback?: (progress: ImportResult) => unknown, importMode?: ImportMode, dryRun?: boolean): Promise<void>;
39
+ private printUpdatesToConsole;
40
+ private applyUpdatesToServer;
41
+ private newAdaptiveTaskManager;
42
+ private executeTasksWithTimeout;
43
+ private validateImportMode;
44
+ }
45
+
46
+ /**
47
+ * Custom error type used during input validation
48
+ */
49
+ export declare class ArgumentError extends Error {
50
+ constructor(message: string);
51
+ }
52
+
53
+ /**
54
+ * Custom error type used when null arguments are passed
55
+ */
56
+ export declare class ArgumentNullError extends Error {
57
+ }
58
+
59
+ /**
60
+ * Enums of configuration Format.
61
+ */
62
+ export declare enum ConfigurationFormat {
63
+ Json = 0,
64
+ Properties = 1,
65
+ Yaml = 2
66
+ }
67
+
68
+ /**
69
+ * Enums of configuration Profile.
70
+ */
71
+ export declare enum ConfigurationProfile {
72
+ Default = 0,
73
+ KvSet = 1
74
+ }
75
+
76
+ /**
77
+ * Interface of all ConfigurationSettingsSource
78
+ */
79
+ export declare interface ConfigurationSettingsSource {
80
+ /**
81
+ * Get ConfigurationSettings collection from source.
82
+ *
83
+ * @returns Collection of ConfigurationSettings
84
+ */
85
+ GetConfigurationSettings(): Promise<Array<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>>>;
86
+ /**
87
+ * Get label and prefix filter
88
+ *
89
+ * @returns label and prefix
90
+ */
91
+ FilterOptions: ListConfigurationSettingsOptions;
92
+ }
93
+
94
+ /**
95
+ * Enums of import mode.
96
+ */
97
+ export declare enum ImportMode {
98
+ All = 0,
99
+ IgnoreMatch = 1
100
+ }
101
+
102
+ export declare interface ImportResult {
103
+ successCount: number;
104
+ importCount: number;
105
+ }
106
+
107
+ export declare class IterableConfigurationSettingsSource implements ConfigurationSettingsSource {
108
+ FilterOptions: ListConfigurationSettingsOptions;
109
+ private data;
110
+ private options;
111
+ constructor(options: IterableSourceOptions);
112
+ /**
113
+ * @inheritdoc
114
+ */
115
+ GetConfigurationSettings(): Promise<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>[]>;
116
+ }
117
+
118
+ export declare type IterableSourceOptions = Options & {
119
+ data: PagedAsyncIterableIterator<ConfigurationSetting<string>, ListConfigurationSettingPage, PageSettings>;
120
+ trimPrefix?: string;
121
+ };
122
+
123
+ /**
124
+ * Custom error type used for set configuration timeout error
125
+ */
126
+ export declare class OperationTimeoutError extends Error {
127
+ constructor();
128
+ }
129
+
130
+ declare type Options = {
131
+ label?: string;
132
+ skipFeatureFlags?: boolean;
133
+ prefix?: string;
134
+ contentType?: string;
135
+ tags?: Tags;
136
+ };
137
+
138
+ /**
139
+ * Custom error type used during configuration file parsing
140
+ */
141
+ export declare class ParseError extends Error {
142
+ message: string;
143
+ constructor(message: string);
144
+ }
145
+
146
+ export declare class ReadableStreamConfigurationSettingsSource implements ConfigurationSettingsSource {
147
+ FilterOptions: ListConfigurationSettingsOptions;
148
+ private options;
149
+ private data;
150
+ constructor(options: ReadableStreamSourceOptions);
151
+ GetConfigurationSettings(): Promise<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>[]>;
152
+ }
153
+
154
+ export declare type ReadableStreamSourceOptions = SourceOptions & {
155
+ data: ReadableStream<Uint8Array> | NodeJS.ReadableStream;
156
+ };
157
+
158
+ /**
159
+ * Base options for configuration import
160
+ *
161
+ * @internal
162
+ */
163
+ declare type SourceOptions = {
164
+ format: ConfigurationFormat;
165
+ separator?: string;
166
+ depth?: number;
167
+ profile?: ConfigurationProfile;
168
+ } & Options;
169
+
170
+ /**
171
+ * ConfigurationSettingsSource implementation of string data configuration source
172
+ */
173
+ export declare class StringConfigurationSettingsSource implements ConfigurationSettingsSource {
174
+ FilterOptions: ListConfigurationSettingsOptions;
175
+ private options;
176
+ private data;
177
+ constructor(options: StringSourceOptions);
178
+ /**
179
+ * @inheritdoc
180
+ */
181
+ GetConfigurationSettings(): Promise<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>[]>;
182
+ /**
183
+ * Get the ConfigurationSettings from supplied data string source.
184
+ *
185
+ * @param data The string data being parsed.
186
+ * @returns Collection of ConfigurationSettings
187
+ */
188
+ protected getConfigurationSettingsInternal(data: string): Array<SetConfigurationSettingParam<string | FeatureFlagValue | SecretReferenceValue>>;
189
+ }
190
+
191
+ /**
192
+ * Provides options for importing from string data source
193
+ *
194
+ */
195
+ export declare type StringSourceOptions = SourceOptions & {
196
+ data: string;
197
+ };
198
+
199
+ declare interface Tags {
200
+ [propertyName: string]: string;
201
+ }
202
+
203
+ export { }
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.47.0"
9
+ }
10
+ ]
11
+ }