Skip to content

Commit 90a6255

Browse files
[Samples] update communication and app-config samples (#18362)
1 parent 6e6fb6a commit 90a6255

24 files changed

+164
-125
lines changed

sdk/appconfiguration/app-configuration/package.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,6 @@
151151
],
152152
"requiredResources": {
153153
"Azure App Configuration account": "https://docs.microsoft.com/azure/azure-app-configuration/quickstart-aspnet-core-app?tabs=core5x#create-an-app-configuration-store"
154-
},
155-
"skip": [
156-
"featureFlag.js",
157-
"secretReference.js"
158-
]
154+
}
159155
}
160156
}

sdk/appconfiguration/app-configuration/samples-dev/featureFlag.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -147,24 +147,10 @@ async function cleanupSampleValues(keys: string[], client: AppConfigurationClien
147147
}
148148
}
149149

150-
/**
151-
* Returns the environment variable, throws an error if not defined.
152-
*
153-
* @export
154-
* @param {string} name
155-
*/
156-
export function getEnvVar(name: string) {
157-
const val = process.env[name];
158-
if (!val) {
159-
throw `Environment variable ${name} is not defined.`;
160-
}
161-
return val;
162-
}
163-
164150
/**
165151
* typeguard - for targeting client filter
166152
*/
167-
export function isTargetingClientFilter(
153+
function isTargetingClientFilter(
168154
clientFilter: any
169155
): clientFilter is {
170156
parameters: {

sdk/appconfiguration/app-configuration/samples-dev/secretReference.ts

-14
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,6 @@ async function cleanupSampleValues(keys: string[], client: AppConfigurationClien
9595
}
9696
}
9797

98-
/**
99-
* Returns the environment variable, throws an error if not defined.
100-
*
101-
* @export
102-
* @param {string} name
103-
*/
104-
export function getEnvVar(name: string) {
105-
const val = process.env[name];
106-
if (!val) {
107-
throw `Environment variable ${name} is not defined.`;
108-
}
109-
return val;
110-
}
111-
11298
main().catch((err) => {
11399
console.error("Failed to run sample:", err);
114100
process.exit(1);

sdk/appconfiguration/app-configuration/samples/v1/javascript/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ These sample programs show how to use the JavaScript client libraries for Azure
2626

2727
## Prerequisites
2828

29-
The sample programs are compatible with Node.js >=12.0.0.
29+
The sample programs are compatible with [LTS versions of Node.js](https://nodejs.org/about/releases/).
3030

3131
You need [an Azure subscription][freesub] and the following Azure resources to run these sample programs:
3232

sdk/appconfiguration/app-configuration/samples/v1/javascript/featureFlag.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -143,24 +143,10 @@ async function cleanupSampleValues(keys, client) {
143143
}
144144
}
145145

146-
/**
147-
* Returns the environment variable, throws an error if not defined.
148-
*
149-
* @export
150-
* @param {string} name
151-
*/
152-
export function getEnvVar(name) {
153-
const val = process.env[name];
154-
if (!val) {
155-
throw `Environment variable ${name} is not defined.`;
156-
}
157-
return val;
158-
}
159-
160146
/**
161147
* typeguard - for targeting client filter
162148
*/
163-
export function isTargetingClientFilter(clientFilter) {
149+
function isTargetingClientFilter(clientFilter) {
164150
return (
165151
clientFilter.name === "Microsoft.Targeting" &&
166152
clientFilter.parameters &&

sdk/appconfiguration/app-configuration/samples/v1/javascript/listConfigurationSettings.js

+29
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,35 @@ async function main() {
5656
for await (const setting of samplesWithDevelopmentLabel) {
5757
console.log(` Found key: ${setting.key}, label: ${setting.label}`);
5858
}
59+
60+
////////////////////////////////////////////////////////
61+
/////////////// Example for .byPage() ////////////////
62+
////////////////////////////////////////////////////////
63+
64+
// Passing marker as an argument
65+
let iterator = client.listConfigurationSettings({ keyFilter: "sample*" }).byPage();
66+
let response = await iterator.next();
67+
if (!response.done) {
68+
for (const setting of response.value.items) {
69+
console.log(` Found key: ${setting.key}`);
70+
}
71+
}
72+
// Gets next marker
73+
let marker = response.value.continuationToken;
74+
// Passing next marker as continuationToken
75+
iterator = client.listConfigurationSettings({ keyFilter: "sample*" }).byPage({
76+
continuationToken: marker
77+
});
78+
response = await iterator.next();
79+
if (response.done) {
80+
console.log("List done.");
81+
} else {
82+
if (response.value.items) {
83+
for (const setting of response.value.items) {
84+
console.log(` Found key: ${setting.key}`);
85+
}
86+
}
87+
}
5988
}
6089

6190
main().catch((err) => {

sdk/appconfiguration/app-configuration/samples/v1/javascript/listRevisions.js

+35
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,41 @@ async function main() {
4747
console.log(`At ${revision.lastModified}, the value was ${revision.value}`);
4848
}
4949

50+
////////////////////////////////////////////////////////
51+
/////////////// Example for .byPage() ////////////////
52+
////////////////////////////////////////////////////////
53+
54+
// If you want to see the pagination
55+
// for (let index = 0; index < 135; index++) {
56+
// await client.setConfigurationSetting({ ...originalSetting, value: `new value = ${index}` });
57+
// await new Promise((resolve) => setTimeout(resolve, 1000));
58+
// }
59+
60+
// Passing marker as an argument
61+
let iterator = client.listRevisions({ keyFilter: "keyWithRevisions-1626819906487" }).byPage();
62+
let response = await iterator.next();
63+
if (!response.done) {
64+
for (const revision of response.value.items) {
65+
console.log(` Found key: ${revision.key}, ${revision.value} === ${revision.lastModified}`);
66+
}
67+
}
68+
// Gets next marker
69+
let marker = response.value.continuationToken;
70+
// Passing next marker as continuationToken
71+
iterator = client.listRevisions({ keyFilter: "keyWithRevisions-1626819906487" }).byPage({
72+
continuationToken: marker
73+
});
74+
response = await iterator.next();
75+
if (response.done) {
76+
console.log("List done.");
77+
} else {
78+
if (response.value.items) {
79+
for (const revision of response.value.items) {
80+
console.log(` Found key: ${revision.key}, ${revision.value} === ${revision.lastModified}`);
81+
}
82+
}
83+
}
84+
5085
cleanupSampleValues([originalSetting.key], client);
5186
}
5287

sdk/appconfiguration/app-configuration/samples/v1/javascript/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"version": "1.0.0",
55
"description": "Azure App Configuration client library samples for JavaScript",
6-
"engine": {
6+
"engines": {
77
"node": ">=12.0.0"
88
},
99
"repository": {
@@ -26,9 +26,9 @@
2626
},
2727
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/appconfiguration/app-configuration",
2828
"dependencies": {
29-
"@azure/app-configuration": "next",
29+
"@azure/app-configuration": "latest",
3030
"dotenv": "latest",
31-
"@azure/keyvault-secrets": "^4.1.0",
32-
"@azure/identity": "2.0.0-beta.5"
31+
"@azure/keyvault-secrets": "^4.2.0",
32+
"@azure/identity": "2.0.0-beta.6"
3333
}
3434
}

sdk/appconfiguration/app-configuration/samples/v1/javascript/secretReference.js

-14
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,6 @@ async function cleanupSampleValues(keys, client) {
8989
}
9090
}
9191

92-
/**
93-
* Returns the environment variable, throws an error if not defined.
94-
*
95-
* @export
96-
* @param {string} name
97-
*/
98-
export function getEnvVar(name) {
99-
const val = process.env[name];
100-
if (!val) {
101-
throw `Environment variable ${name} is not defined.`;
102-
}
103-
return val;
104-
}
105-
10692
main().catch((err) => {
10793
console.error("Failed to run sample:", err);
10894
process.exit(1);

sdk/appconfiguration/app-configuration/samples/v1/typescript/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ These sample programs show how to use the TypeScript client libraries for Azure
2626

2727
## Prerequisites
2828

29-
The sample programs are compatible with Node.js >=12.0.0.
29+
The sample programs are compatible with [LTS versions of Node.js](https://nodejs.org/about/releases/).
3030

3131
Before running the samples in Node, they must be compiled to JavaScript using the TypeScript compiler. For more information on TypeScript, see the [TypeScript documentation][typescript]. Install the TypeScript compiler using:
3232

sdk/appconfiguration/app-configuration/samples/v1/typescript/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"private": true,
44
"version": "1.0.0",
55
"description": "Azure App Configuration client library samples for TypeScript",
6-
"engine": {
6+
"engines": {
77
"node": ">=12.0.0"
88
},
99
"scripts": {
@@ -30,13 +30,13 @@
3030
},
3131
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/appconfiguration/app-configuration",
3232
"dependencies": {
33-
"@azure/app-configuration": "next",
33+
"@azure/app-configuration": "latest",
3434
"dotenv": "latest",
35-
"@azure/keyvault-secrets": "^4.1.0",
36-
"@azure/identity": "2.0.0-beta.5"
35+
"@azure/keyvault-secrets": "^4.2.0",
36+
"@azure/identity": "2.0.0-beta.6"
3737
},
3838
"devDependencies": {
39-
"typescript": "~4.2.0",
39+
"typescript": "~4.4.0",
4040
"rimraf": "latest"
4141
}
4242
}

sdk/appconfiguration/app-configuration/samples/v1/typescript/src/featureFlag.ts

+1-15
Original file line numberDiff line numberDiff line change
@@ -145,24 +145,10 @@ async function cleanupSampleValues(keys: string[], client: AppConfigurationClien
145145
}
146146
}
147147

148-
/**
149-
* Returns the environment variable, throws an error if not defined.
150-
*
151-
* @export
152-
* @param {string} name
153-
*/
154-
export function getEnvVar(name: string) {
155-
const val = process.env[name];
156-
if (!val) {
157-
throw `Environment variable ${name} is not defined.`;
158-
}
159-
return val;
160-
}
161-
162148
/**
163149
* typeguard - for targeting client filter
164150
*/
165-
export function isTargetingClientFilter(
151+
function isTargetingClientFilter(
166152
clientFilter: any
167153
): clientFilter is {
168154
parameters: {

sdk/appconfiguration/app-configuration/samples/v1/typescript/src/listConfigurationSettings.ts

+29
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,35 @@ export async function main() {
5656
for await (const setting of samplesWithDevelopmentLabel) {
5757
console.log(` Found key: ${setting.key}, label: ${setting.label}`);
5858
}
59+
60+
////////////////////////////////////////////////////////
61+
/////////////// Example for .byPage() ////////////////
62+
////////////////////////////////////////////////////////
63+
64+
// Passing marker as an argument
65+
let iterator = client.listConfigurationSettings({ keyFilter: "sample*" }).byPage();
66+
let response = await iterator.next();
67+
if (!response.done) {
68+
for (const setting of response.value.items) {
69+
console.log(` Found key: ${setting.key}`);
70+
}
71+
}
72+
// Gets next marker
73+
let marker = response.value.continuationToken;
74+
// Passing next marker as continuationToken
75+
iterator = client.listConfigurationSettings({ keyFilter: "sample*" }).byPage({
76+
continuationToken: marker
77+
});
78+
response = await iterator.next();
79+
if (response.done) {
80+
console.log("List done.");
81+
} else {
82+
if (response.value.items) {
83+
for (const setting of response.value.items) {
84+
console.log(` Found key: ${setting.key}`);
85+
}
86+
}
87+
}
5988
}
6089

6190
main().catch((err) => {

sdk/appconfiguration/app-configuration/samples/v1/typescript/src/listRevisions.ts

+35
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,41 @@ export async function main() {
4747
console.log(`At ${revision.lastModified}, the value was ${revision.value}`);
4848
}
4949

50+
////////////////////////////////////////////////////////
51+
/////////////// Example for .byPage() ////////////////
52+
////////////////////////////////////////////////////////
53+
54+
// If you want to see the pagination
55+
// for (let index = 0; index < 135; index++) {
56+
// await client.setConfigurationSetting({ ...originalSetting, value: `new value = ${index}` });
57+
// await new Promise((resolve) => setTimeout(resolve, 1000));
58+
// }
59+
60+
// Passing marker as an argument
61+
let iterator = client.listRevisions({ keyFilter: "keyWithRevisions-1626819906487" }).byPage();
62+
let response = await iterator.next();
63+
if (!response.done) {
64+
for (const revision of response.value.items) {
65+
console.log(` Found key: ${revision.key}, ${revision.value} === ${revision.lastModified}`);
66+
}
67+
}
68+
// Gets next marker
69+
let marker = response.value.continuationToken;
70+
// Passing next marker as continuationToken
71+
iterator = client.listRevisions({ keyFilter: "keyWithRevisions-1626819906487" }).byPage({
72+
continuationToken: marker
73+
});
74+
response = await iterator.next();
75+
if (response.done) {
76+
console.log("List done.");
77+
} else {
78+
if (response.value.items) {
79+
for (const revision of response.value.items) {
80+
console.log(` Found key: ${revision.key}, ${revision.value} === ${revision.lastModified}`);
81+
}
82+
}
83+
}
84+
5085
cleanupSampleValues([originalSetting.key], client);
5186
}
5287

sdk/appconfiguration/app-configuration/samples/v1/typescript/src/secretReference.ts

-14
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,6 @@ async function cleanupSampleValues(keys: string[], client: AppConfigurationClien
9393
}
9494
}
9595

96-
/**
97-
* Returns the environment variable, throws an error if not defined.
98-
*
99-
* @export
100-
* @param {string} name
101-
*/
102-
export function getEnvVar(name: string) {
103-
const val = process.env[name];
104-
if (!val) {
105-
throw `Environment variable ${name} is not defined.`;
106-
}
107-
return val;
108-
}
109-
11096
main().catch((err) => {
11197
console.error("Failed to run sample:", err);
11298
process.exit(1);

sdk/communication/communication-sms/package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,6 @@
145145
],
146146
"requiredResources": {
147147
"Azure Communication Services account": "https://docs.microsoft.com/azure/communication-services/quickstarts/create-communication-resource"
148-
},
149-
"skip": [
150-
"sendSmsWithOptions.js"
151-
]
148+
}
152149
}
153150
}

0 commit comments

Comments
 (0)