@azure/app-configuration 1.3.2-alpha.20220401.1 → 1.4.0-alpha.20220407.2

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 (50) hide show
  1. package/CHANGELOG.md +11 -7
  2. package/dist/index.js +153 -374
  3. package/dist/index.js.map +1 -1
  4. package/dist-esm/src/appConfigCredential.js +24 -30
  5. package/dist-esm/src/appConfigCredential.js.map +1 -1
  6. package/dist-esm/src/appConfigurationClient.js +48 -63
  7. package/dist-esm/src/appConfigurationClient.js.map +1 -1
  8. package/dist-esm/src/generated/src/appConfiguration.js +47 -89
  9. package/dist-esm/src/generated/src/appConfiguration.js.map +1 -1
  10. package/dist-esm/src/generated/src/index.js +0 -1
  11. package/dist-esm/src/generated/src/index.js.map +1 -1
  12. package/dist-esm/src/generated/src/models/index.js +78 -1
  13. package/dist-esm/src/generated/src/models/index.js.map +1 -1
  14. package/dist-esm/src/generated/src/models/mappers.js.map +1 -1
  15. package/dist-esm/src/generated/src/models/parameters.js +7 -8
  16. package/dist-esm/src/generated/src/models/parameters.js.map +1 -1
  17. package/dist-esm/src/internal/helpers.js +33 -18
  18. package/dist-esm/src/internal/helpers.js.map +1 -1
  19. package/dist-esm/src/internal/synctokenpolicy.js +9 -18
  20. package/dist-esm/src/internal/synctokenpolicy.js.map +1 -1
  21. package/dist-esm/src/internal/tracingHelpers.js +1 -1
  22. package/dist-esm/src/internal/tracingHelpers.js.map +1 -1
  23. package/dist-esm/src/models.js.map +1 -1
  24. package/dist-esm/test/internal/helpers.spec.js +3 -12
  25. package/dist-esm/test/internal/helpers.spec.js.map +1 -1
  26. package/dist-esm/test/internal/http.spec.js +2 -14
  27. package/dist-esm/test/internal/http.spec.js.map +1 -1
  28. package/dist-esm/test/internal/node/throttlingRetryPolicy.spec.js +6 -5
  29. package/dist-esm/test/internal/node/throttlingRetryPolicy.spec.js.map +1 -1
  30. package/dist-esm/test/internal/tracingHelpers.spec.js.map +1 -1
  31. package/dist-esm/test/public/auth.spec.js +1 -1
  32. package/dist-esm/test/public/auth.spec.js.map +1 -1
  33. package/dist-esm/test/public/etags.spec.js +1 -2
  34. package/dist-esm/test/public/etags.spec.js.map +1 -1
  35. package/dist-esm/test/public/index.readonlytests.spec.js +6 -1
  36. package/dist-esm/test/public/index.readonlytests.spec.js.map +1 -1
  37. package/dist-esm/test/public/index.spec.js +23 -8
  38. package/dist-esm/test/public/index.spec.js.map +1 -1
  39. package/dist-esm/test/public/secretReference.spec.js.map +1 -1
  40. package/dist-esm/test/public/throwOrNotThrow.spec.js +1 -1
  41. package/dist-esm/test/public/throwOrNotThrow.spec.js.map +1 -1
  42. package/dist-esm/test/public/utils/testHelpers.js.map +1 -1
  43. package/package.json +10 -2
  44. package/types/app-configuration.d.ts +5 -13
  45. package/dist-esm/src/generated/src/appConfigurationContext.js +0 -46
  46. package/dist-esm/src/generated/src/appConfigurationContext.js.map +0 -1
  47. package/dist-esm/src/policies/throttlingRetryPolicy.js +0 -126
  48. package/dist-esm/src/policies/throttlingRetryPolicy.js.map +0 -1
  49. package/dist-esm/test/internal/throttlingRetryPolicyTests.spec.js +0 -145
  50. package/dist-esm/test/internal/throttlingRetryPolicyTests.spec.js.map +0 -1
package/dist/index.js CHANGED
@@ -3,11 +3,13 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var tslib = require('tslib');
6
- var coreHttp = require('@azure/core-http');
7
6
  var crypto = require('crypto');
8
- var abortController = require('@azure/abort-controller');
7
+ var coreClient = require('@azure/core-client');
8
+ var coreHttpCompat = require('@azure/core-http-compat');
9
+ var coreAuth = require('@azure/core-auth');
9
10
  require('@azure/core-asynciterator-polyfill');
10
11
  var coreTracing = require('@azure/core-tracing');
12
+ var coreRestPipeline = require('@azure/core-rest-pipeline');
11
13
 
12
14
  function _interopNamespace(e) {
13
15
  if (e && e.__esModule) return e;
@@ -27,7 +29,8 @@ function _interopNamespace(e) {
27
29
  return Object.freeze(n);
28
30
  }
29
31
 
30
- var coreHttp__namespace = /*#__PURE__*/_interopNamespace(coreHttp);
32
+ var coreClient__namespace = /*#__PURE__*/_interopNamespace(coreClient);
33
+ var coreHttpCompat__namespace = /*#__PURE__*/_interopNamespace(coreHttpCompat);
31
34
 
32
35
  // Copyright (c) Microsoft Corporation.
33
36
  /**
@@ -48,36 +51,31 @@ async function sha256Hmac(secret, stringToSign) {
48
51
 
49
52
  // Copyright (c) Microsoft Corporation.
50
53
  /**
51
- * @internal
54
+ * Create an HTTP pipeline policy to authenticate a request
55
+ * using an `AzureKeyCredential` for AppConfig.
52
56
  */
53
- class AppConfigCredential {
54
- constructor(credential, secret) {
55
- this.credential = credential;
56
- this.secret = secret;
57
- }
58
- /**
59
- * Signs a request with the values provided in the credential and secret parameter.
60
- *
61
- * @param webResource - The WebResource to be signed.
62
- * @returns The signed request object.
63
- */
64
- async signRequest(webResource) {
65
- const verb = webResource.method.toUpperCase();
66
- const utcNow = new Date().toUTCString();
67
- const contentHash = await sha256Digest(webResource.body || "");
68
- const signedHeaders = "x-ms-date;host;x-ms-content-sha256";
69
- const url = coreHttp.URLBuilder.parse(webResource.url);
70
- const query = url.getQuery();
71
- const urlPathAndQuery = `${url.getPath()}${query ? "?" + query : ""}`;
72
- const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${url.getHost()};${contentHash}`;
73
- const signature = await sha256Hmac(this.secret, stringToSign);
74
- webResource.headers.set("x-ms-date", utcNow);
75
- webResource.headers.set("x-ms-content-sha256", contentHash);
76
- // Syntax for Authorization header
77
- // Reference - https://docs.microsoft.com/en-us/azure/azure-app-configuration/rest-api-authentication-hmac#syntax
78
- webResource.headers.set("Authorization", `HMAC-SHA256 Credential=${this.credential}&SignedHeaders=${signedHeaders}&Signature=${signature}`);
79
- return webResource;
80
- }
57
+ function appConfigKeyCredentialPolicy(credential, secret) {
58
+ return {
59
+ name: "AppConfigKeyCredentialPolicy",
60
+ async sendRequest(request, next) {
61
+ var _a;
62
+ const verb = request.method;
63
+ const utcNow = new Date().toUTCString();
64
+ const contentHash = await sha256Digest(((_a = request.body) === null || _a === void 0 ? void 0 : _a.toString()) || "");
65
+ const signedHeaders = "x-ms-date;host;x-ms-content-sha256";
66
+ const url = new URL(request.url);
67
+ const query = url.search;
68
+ const urlPathAndQuery = query ? `${url.pathname}${query}` : url.pathname;
69
+ const stringToSign = `${verb}\n${urlPathAndQuery}\n${utcNow};${url.host};${contentHash}`;
70
+ const signature = await sha256Hmac(secret, stringToSign);
71
+ request.headers.set("x-ms-date", utcNow);
72
+ request.headers.set("x-ms-content-sha256", contentHash);
73
+ // Syntax for Authorization header
74
+ // Reference - https://docs.microsoft.com/en-us/azure/azure-app-configuration/rest-api-authentication-hmac#syntax
75
+ request.headers.set("Authorization", `HMAC-SHA256 Credential=${credential}&SignedHeaders=${signedHeaders}&Signature=${signature}`);
76
+ return next(request);
77
+ },
78
+ };
81
79
  }
82
80
 
83
81
  /*
@@ -738,7 +736,7 @@ const select = {
738
736
  }
739
737
  }
740
738
  },
741
- collectionFormat: coreHttp.QueryCollectionFormat.Csv
739
+ collectionFormat: "CSV"
742
740
  };
743
741
  const select1 = {
744
742
  parameterPath: ["options", "select"],
@@ -753,7 +751,7 @@ const select1 = {
753
751
  }
754
752
  }
755
753
  },
756
- collectionFormat: coreHttp.QueryCollectionFormat.Csv
754
+ collectionFormat: "CSV"
757
755
  };
758
756
  const accept2 = {
759
757
  parameterPath: "accept",
@@ -807,7 +805,7 @@ const select2 = {
807
805
  }
808
806
  }
809
807
  },
810
- collectionFormat: coreHttp.QueryCollectionFormat.Csv
808
+ collectionFormat: "CSV"
811
809
  };
812
810
  const contentType = {
813
811
  parameterPath: ["options", "contentType"],
@@ -837,7 +835,7 @@ const select3 = {
837
835
  }
838
836
  }
839
837
  },
840
- collectionFormat: coreHttp.QueryCollectionFormat.Csv
838
+ collectionFormat: "CSV"
841
839
  };
842
840
  const accept3 = {
843
841
  parameterPath: "accept",
@@ -865,7 +863,7 @@ const select4 = {
865
863
  }
866
864
  }
867
865
  },
868
- collectionFormat: coreHttp.QueryCollectionFormat.Csv
866
+ collectionFormat: "CSV"
869
867
  };
870
868
  const select5 = {
871
869
  parameterPath: ["options", "select"],
@@ -880,7 +878,7 @@ const select5 = {
880
878
  }
881
879
  }
882
880
  },
883
- collectionFormat: coreHttp.QueryCollectionFormat.Csv
881
+ collectionFormat: "CSV"
884
882
  };
885
883
  const select6 = {
886
884
  parameterPath: ["options", "select"],
@@ -895,7 +893,7 @@ const select6 = {
895
893
  }
896
894
  }
897
895
  },
898
- collectionFormat: coreHttp.QueryCollectionFormat.Csv
896
+ collectionFormat: "CSV"
899
897
  };
900
898
  const nextLink = {
901
899
  parameterPath: "nextLink",
@@ -916,21 +914,15 @@ const nextLink = {
916
914
  * Code generated by Microsoft (R) AutoRest Code Generator.
917
915
  * Changes may cause incorrect behavior and will be lost if the code is regenerated.
918
916
  */
919
- const packageName$1 = "app-configuration";
920
- const packageVersion$1 = "1.3.2";
921
917
  /** @internal */
922
- class AppConfigurationContext extends coreHttp__namespace.ServiceClient {
918
+ class AppConfiguration extends coreHttpCompat__namespace.ExtendedServiceClient {
923
919
  /**
924
- * Initializes a new instance of the AppConfigurationContext class.
925
- * @param credentials Subscription credentials which uniquely identify client subscription.
920
+ * Initializes a new instance of the AppConfiguration class.
926
921
  * @param endpoint The endpoint of the App Configuration instance to send requests to.
927
922
  * @param apiVersion Api Version
928
923
  * @param options The parameter options
929
924
  */
930
- constructor(credentials, endpoint, apiVersion, options) {
931
- if (credentials === undefined) {
932
- throw new Error("'credentials' cannot be null");
933
- }
925
+ constructor(endpoint, apiVersion, options) {
934
926
  if (endpoint === undefined) {
935
927
  throw new Error("'endpoint' cannot be null");
936
928
  }
@@ -941,77 +933,48 @@ class AppConfigurationContext extends coreHttp__namespace.ServiceClient {
941
933
  if (!options) {
942
934
  options = {};
943
935
  }
944
- if (!options.userAgent) {
945
- const defaultUserAgent = coreHttp__namespace.getDefaultUserAgentValue();
946
- options.userAgent = `${packageName$1}/${packageVersion$1} ${defaultUserAgent}`;
947
- }
948
- super(credentials, options);
949
- this.requestContentType = "application/json; charset=utf-8";
950
- this.baseUri = options.endpoint || "{endpoint}";
936
+ const defaults = {
937
+ requestContentType: "application/json; charset=utf-8"
938
+ };
939
+ const packageDetails = `azsdk-js-app-configuration/1.4.0-beta.1`;
940
+ const userAgentPrefix = options.userAgentOptions && options.userAgentOptions.userAgentPrefix
941
+ ? `${options.userAgentOptions.userAgentPrefix} ${packageDetails}`
942
+ : `${packageDetails}`;
943
+ const optionsWithDefaults = Object.assign(Object.assign(Object.assign({}, defaults), options), { userAgentOptions: {
944
+ userAgentPrefix
945
+ }, baseUri: options.endpoint || "{endpoint}" });
946
+ super(optionsWithDefaults);
951
947
  // Parameter assignments
952
948
  this.endpoint = endpoint;
953
949
  this.apiVersion = apiVersion;
954
950
  }
955
- }
956
-
957
- /*
958
- * Copyright (c) Microsoft Corporation.
959
- * Licensed under the MIT License.
960
- *
961
- * Code generated by Microsoft (R) AutoRest Code Generator.
962
- * Changes may cause incorrect behavior and will be lost if the code is regenerated.
963
- */
964
- /** @internal */
965
- class AppConfiguration extends AppConfigurationContext {
966
- /**
967
- * Initializes a new instance of the AppConfiguration class.
968
- * @param credentials Subscription credentials which uniquely identify client subscription.
969
- * @param endpoint The endpoint of the App Configuration instance to send requests to.
970
- * @param apiVersion Api Version
971
- * @param options The parameter options
972
- */
973
- constructor(credentials, endpoint, apiVersion, options) {
974
- super(credentials, endpoint, apiVersion, options);
975
- }
976
951
  /**
977
952
  * Gets a list of keys.
978
953
  * @param options The options parameters.
979
954
  */
980
955
  getKeys(options) {
981
- const operationArguments = {
982
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
983
- };
984
- return this.sendOperationRequest(operationArguments, getKeysOperationSpec);
956
+ return this.sendOperationRequest({ options }, getKeysOperationSpec);
985
957
  }
986
958
  /**
987
959
  * Requests the headers and status of the given resource.
988
960
  * @param options The options parameters.
989
961
  */
990
962
  checkKeys(options) {
991
- const operationArguments = {
992
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
993
- };
994
- return this.sendOperationRequest(operationArguments, checkKeysOperationSpec);
963
+ return this.sendOperationRequest({ options }, checkKeysOperationSpec);
995
964
  }
996
965
  /**
997
966
  * Gets a list of key-values.
998
967
  * @param options The options parameters.
999
968
  */
1000
969
  getKeyValues(options) {
1001
- const operationArguments = {
1002
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1003
- };
1004
- return this.sendOperationRequest(operationArguments, getKeyValuesOperationSpec);
970
+ return this.sendOperationRequest({ options }, getKeyValuesOperationSpec);
1005
971
  }
1006
972
  /**
1007
973
  * Requests the headers and status of the given resource.
1008
974
  * @param options The options parameters.
1009
975
  */
1010
976
  checkKeyValues(options) {
1011
- const operationArguments = {
1012
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1013
- };
1014
- return this.sendOperationRequest(operationArguments, checkKeyValuesOperationSpec);
977
+ return this.sendOperationRequest({ options }, checkKeyValuesOperationSpec);
1015
978
  }
1016
979
  /**
1017
980
  * Gets a single key-value.
@@ -1019,11 +982,7 @@ class AppConfiguration extends AppConfigurationContext {
1019
982
  * @param options The options parameters.
1020
983
  */
1021
984
  getKeyValue(key, options) {
1022
- const operationArguments = {
1023
- key,
1024
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1025
- };
1026
- return this.sendOperationRequest(operationArguments, getKeyValueOperationSpec);
985
+ return this.sendOperationRequest({ key, options }, getKeyValueOperationSpec);
1027
986
  }
1028
987
  /**
1029
988
  * Creates a key-value.
@@ -1031,11 +990,7 @@ class AppConfiguration extends AppConfigurationContext {
1031
990
  * @param options The options parameters.
1032
991
  */
1033
992
  putKeyValue(key, options) {
1034
- const operationArguments = {
1035
- key,
1036
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1037
- };
1038
- return this.sendOperationRequest(operationArguments, putKeyValueOperationSpec);
993
+ return this.sendOperationRequest({ key, options }, putKeyValueOperationSpec);
1039
994
  }
1040
995
  /**
1041
996
  * Deletes a key-value.
@@ -1043,11 +998,7 @@ class AppConfiguration extends AppConfigurationContext {
1043
998
  * @param options The options parameters.
1044
999
  */
1045
1000
  deleteKeyValue(key, options) {
1046
- const operationArguments = {
1047
- key,
1048
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1049
- };
1050
- return this.sendOperationRequest(operationArguments, deleteKeyValueOperationSpec);
1001
+ return this.sendOperationRequest({ key, options }, deleteKeyValueOperationSpec);
1051
1002
  }
1052
1003
  /**
1053
1004
  * Requests the headers and status of the given resource.
@@ -1055,31 +1006,21 @@ class AppConfiguration extends AppConfigurationContext {
1055
1006
  * @param options The options parameters.
1056
1007
  */
1057
1008
  checkKeyValue(key, options) {
1058
- const operationArguments = {
1059
- key,
1060
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1061
- };
1062
- return this.sendOperationRequest(operationArguments, checkKeyValueOperationSpec);
1009
+ return this.sendOperationRequest({ key, options }, checkKeyValueOperationSpec);
1063
1010
  }
1064
1011
  /**
1065
1012
  * Gets a list of labels.
1066
1013
  * @param options The options parameters.
1067
1014
  */
1068
1015
  getLabels(options) {
1069
- const operationArguments = {
1070
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1071
- };
1072
- return this.sendOperationRequest(operationArguments, getLabelsOperationSpec);
1016
+ return this.sendOperationRequest({ options }, getLabelsOperationSpec);
1073
1017
  }
1074
1018
  /**
1075
1019
  * Requests the headers and status of the given resource.
1076
1020
  * @param options The options parameters.
1077
1021
  */
1078
1022
  checkLabels(options) {
1079
- const operationArguments = {
1080
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1081
- };
1082
- return this.sendOperationRequest(operationArguments, checkLabelsOperationSpec);
1023
+ return this.sendOperationRequest({ options }, checkLabelsOperationSpec);
1083
1024
  }
1084
1025
  /**
1085
1026
  * Locks a key-value.
@@ -1087,11 +1028,7 @@ class AppConfiguration extends AppConfigurationContext {
1087
1028
  * @param options The options parameters.
1088
1029
  */
1089
1030
  putLock(key, options) {
1090
- const operationArguments = {
1091
- key,
1092
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1093
- };
1094
- return this.sendOperationRequest(operationArguments, putLockOperationSpec);
1031
+ return this.sendOperationRequest({ key, options }, putLockOperationSpec);
1095
1032
  }
1096
1033
  /**
1097
1034
  * Unlocks a key-value.
@@ -1099,31 +1036,21 @@ class AppConfiguration extends AppConfigurationContext {
1099
1036
  * @param options The options parameters.
1100
1037
  */
1101
1038
  deleteLock(key, options) {
1102
- const operationArguments = {
1103
- key,
1104
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1105
- };
1106
- return this.sendOperationRequest(operationArguments, deleteLockOperationSpec);
1039
+ return this.sendOperationRequest({ key, options }, deleteLockOperationSpec);
1107
1040
  }
1108
1041
  /**
1109
1042
  * Gets a list of key-value revisions.
1110
1043
  * @param options The options parameters.
1111
1044
  */
1112
1045
  getRevisions(options) {
1113
- const operationArguments = {
1114
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1115
- };
1116
- return this.sendOperationRequest(operationArguments, getRevisionsOperationSpec);
1046
+ return this.sendOperationRequest({ options }, getRevisionsOperationSpec);
1117
1047
  }
1118
1048
  /**
1119
1049
  * Requests the headers and status of the given resource.
1120
1050
  * @param options The options parameters.
1121
1051
  */
1122
1052
  checkRevisions(options) {
1123
- const operationArguments = {
1124
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1125
- };
1126
- return this.sendOperationRequest(operationArguments, checkRevisionsOperationSpec);
1053
+ return this.sendOperationRequest({ options }, checkRevisionsOperationSpec);
1127
1054
  }
1128
1055
  /**
1129
1056
  * GetKeysNext
@@ -1131,11 +1058,7 @@ class AppConfiguration extends AppConfigurationContext {
1131
1058
  * @param options The options parameters.
1132
1059
  */
1133
1060
  getKeysNext(nextLink, options) {
1134
- const operationArguments = {
1135
- nextLink,
1136
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1137
- };
1138
- return this.sendOperationRequest(operationArguments, getKeysNextOperationSpec);
1061
+ return this.sendOperationRequest({ nextLink, options }, getKeysNextOperationSpec);
1139
1062
  }
1140
1063
  /**
1141
1064
  * GetKeyValuesNext
@@ -1143,11 +1066,7 @@ class AppConfiguration extends AppConfigurationContext {
1143
1066
  * @param options The options parameters.
1144
1067
  */
1145
1068
  getKeyValuesNext(nextLink, options) {
1146
- const operationArguments = {
1147
- nextLink,
1148
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1149
- };
1150
- return this.sendOperationRequest(operationArguments, getKeyValuesNextOperationSpec);
1069
+ return this.sendOperationRequest({ nextLink, options }, getKeyValuesNextOperationSpec);
1151
1070
  }
1152
1071
  /**
1153
1072
  * GetLabelsNext
@@ -1155,11 +1074,7 @@ class AppConfiguration extends AppConfigurationContext {
1155
1074
  * @param options The options parameters.
1156
1075
  */
1157
1076
  getLabelsNext(nextLink, options) {
1158
- const operationArguments = {
1159
- nextLink,
1160
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1161
- };
1162
- return this.sendOperationRequest(operationArguments, getLabelsNextOperationSpec);
1077
+ return this.sendOperationRequest({ nextLink, options }, getLabelsNextOperationSpec);
1163
1078
  }
1164
1079
  /**
1165
1080
  * GetRevisionsNext
@@ -1167,15 +1082,11 @@ class AppConfiguration extends AppConfigurationContext {
1167
1082
  * @param options The options parameters.
1168
1083
  */
1169
1084
  getRevisionsNext(nextLink, options) {
1170
- const operationArguments = {
1171
- nextLink,
1172
- options: coreHttp__namespace.operationOptionsToRequestOptionsBase(options || {})
1173
- };
1174
- return this.sendOperationRequest(operationArguments, getRevisionsNextOperationSpec);
1085
+ return this.sendOperationRequest({ nextLink, options }, getRevisionsNextOperationSpec);
1175
1086
  }
1176
1087
  }
1177
1088
  // Operation Specifications
1178
- const serializer = new coreHttp__namespace.Serializer(Mappers, /* isXml */ false);
1089
+ const serializer = coreClient__namespace.createSerializer(Mappers, /* isXml */ false);
1179
1090
  const getKeysOperationSpec = {
1180
1091
  path: "/keys",
1181
1092
  httpMethod: "GET",
@@ -1601,128 +1512,6 @@ const getRevisionsNextOperationSpec = {
1601
1512
  serializer
1602
1513
  };
1603
1514
 
1604
- // Copyright (c) Microsoft Corporation.
1605
- /**
1606
- * @internal
1607
- */
1608
- function throttlingRetryPolicy(retryOptions) {
1609
- return {
1610
- create: (nextPolicy, options) => {
1611
- return new ThrottlingRetryPolicy(nextPolicy, options, retryOptions);
1612
- },
1613
- };
1614
- }
1615
- const StandardAbortMessage = "The operation was aborted.";
1616
- // Merge this constant with the one in core-http when we unify throttling retry policy in core-http and app-config
1617
- const DEFAULT_CLIENT_RETRY_COUNT = 3;
1618
- /**
1619
- * This policy is a close copy of the ThrottlingRetryPolicy class from
1620
- * core-http with modifications to work with how AppConfig is currently
1621
- * responding to 429 responses (which is to throw a RestError).
1622
- *
1623
- * @internal
1624
- */
1625
- class ThrottlingRetryPolicy extends coreHttp.BaseRequestPolicy {
1626
- constructor(nextPolicy, options, retryOptions = { maxRetries: DEFAULT_CLIENT_RETRY_COUNT }) {
1627
- super(nextPolicy, options);
1628
- this.retryOptions = retryOptions;
1629
- this.numberOfRetries = 0;
1630
- }
1631
- async sendRequest(httpRequest) {
1632
- return this._nextPolicy.sendRequest(httpRequest.clone()).catch(async (err) => {
1633
- var _a;
1634
- if (isRestErrorWithHeaders(err)) {
1635
- let delayInMs = getDelayInMs(err.response.headers);
1636
- if (delayInMs == null) {
1637
- throw err;
1638
- }
1639
- if (this.retryOptions.maxRetryDelayInMs &&
1640
- delayInMs > this.retryOptions.maxRetryDelayInMs) {
1641
- delayInMs = this.retryOptions.maxRetryDelayInMs;
1642
- }
1643
- this.numberOfRetries += 1;
1644
- await coreHttp.delay(delayInMs, undefined, {
1645
- abortSignal: httpRequest.abortSignal,
1646
- abortErrorMsg: StandardAbortMessage,
1647
- });
1648
- if ((_a = httpRequest.abortSignal) === null || _a === void 0 ? void 0 : _a.aborted) {
1649
- throw new abortController.AbortError(StandardAbortMessage);
1650
- }
1651
- if (this.retryOptions.maxRetries === undefined || this.retryOptions.maxRetries === null) {
1652
- this.retryOptions.maxRetries = DEFAULT_CLIENT_RETRY_COUNT;
1653
- }
1654
- if (this.numberOfRetries < this.retryOptions.maxRetries) {
1655
- // retries
1656
- return this.sendRequest(httpRequest.clone());
1657
- }
1658
- else {
1659
- // passes on to the next policy
1660
- return this._nextPolicy.sendRequest(httpRequest.clone());
1661
- }
1662
- }
1663
- else {
1664
- throw err;
1665
- }
1666
- });
1667
- }
1668
- static parseRetryAfterHeader(headerValue) {
1669
- const retryAfterInSeconds = Number(headerValue);
1670
- if (Number.isNaN(retryAfterInSeconds)) {
1671
- return ThrottlingRetryPolicy.parseDateRetryAfterHeader(headerValue);
1672
- }
1673
- else {
1674
- return retryAfterInSeconds * 1000;
1675
- }
1676
- }
1677
- static parseDateRetryAfterHeader(headerValue) {
1678
- try {
1679
- const now = Date.now();
1680
- const date = Date.parse(headerValue);
1681
- const diff = date - now;
1682
- return Number.isNaN(diff) ? undefined : diff;
1683
- }
1684
- catch (error) {
1685
- return undefined;
1686
- }
1687
- }
1688
- }
1689
- /**
1690
- * The headers that come back from Azure services representing
1691
- * the amount of time (minimum) to wait to retry (in milliseconds).
1692
- */
1693
- const RetryAfterMillisecondsHeaders = ["retry-after-ms", "x-ms-retry-after-ms"];
1694
- /**
1695
- * Extracts the retry response header, checking against several
1696
- * header names.
1697
- * @internal
1698
- */
1699
- function getDelayInMs(responseHeaders) {
1700
- for (const name of RetryAfterMillisecondsHeaders) {
1701
- const delayValueString = responseHeaders.get(name);
1702
- if (delayValueString == null) {
1703
- continue;
1704
- }
1705
- const delayValueMs = Number(delayValueString);
1706
- if (Number.isNaN(delayValueMs)) {
1707
- return undefined;
1708
- }
1709
- return delayValueMs;
1710
- }
1711
- const retryAfterValue = responseHeaders.get(coreHttp.Constants.HeaderConstants.RETRY_AFTER);
1712
- if (retryAfterValue != null) {
1713
- return ThrottlingRetryPolicy.parseRetryAfterHeader(retryAfterValue);
1714
- }
1715
- return undefined;
1716
- }
1717
- function isRestErrorWithHeaders(err) {
1718
- return (err &&
1719
- err.statusCode &&
1720
- typeof err.statusCode === "number" &&
1721
- err.response &&
1722
- err.response.headers &&
1723
- typeof err.response.headers.get === "function");
1724
- }
1725
-
1726
1515
  // Copyright (c) Microsoft Corporation.
1727
1516
  // Licensed under the MIT license.
1728
1517
  /**
@@ -1927,8 +1716,8 @@ function formatAcceptDateTime(newOptions) {
1927
1716
  * @internal
1928
1717
  */
1929
1718
  function extractAfterTokenFromNextLink(nextLink) {
1930
- const parsedLink = coreHttp.URLBuilder.parse(nextLink);
1931
- const afterToken = parsedLink.getQueryParameterValue("after");
1719
+ const searchParams = new URLSearchParams(nextLink);
1720
+ const afterToken = searchParams.get("after");
1932
1721
  if (afterToken == null || Array.isArray(afterToken)) {
1933
1722
  throw new Error("Invalid nextLink - invalid after token");
1934
1723
  }
@@ -2008,24 +1797,29 @@ function serializeAsConfigurationSettingParam(setting) {
2008
1797
  /**
2009
1798
  * @internal
2010
1799
  */
2011
- function transformKeyValueResponseWithStatusCode(kvp) {
2012
- return normalizeResponse(kvp, Object.assign(Object.assign({}, transformKeyValue(kvp)), { statusCode: kvp._response.status }));
1800
+ function transformKeyValueResponseWithStatusCode(kvp, status) {
1801
+ const response = Object.assign(Object.assign({}, transformKeyValue(kvp)), { statusCode: status !== null && status !== void 0 ? status : -1 });
1802
+ if (hasUnderscoreResponse(kvp)) {
1803
+ Object.defineProperty(response, "_response", {
1804
+ enumerable: false,
1805
+ value: kvp._response,
1806
+ });
1807
+ }
1808
+ return response;
2013
1809
  }
2014
1810
  /**
2015
1811
  * @internal
2016
1812
  */
2017
1813
  function transformKeyValueResponse(kvp) {
2018
- return normalizeResponse(kvp, Object.assign({}, transformKeyValue(kvp)));
2019
- }
2020
- function normalizeResponse(originalResponse, newResponse) {
2021
- Object.defineProperty(newResponse, "_response", {
2022
- enumerable: false,
2023
- value: originalResponse._response,
2024
- });
2025
- // this field comes from the header but it's redundant with
2026
- // the one serialized in the model itself
2027
- delete newResponse.eTag;
2028
- return newResponse;
1814
+ const setting = transformKeyValue(kvp);
1815
+ if (hasUnderscoreResponse(kvp)) {
1816
+ Object.defineProperty(setting, "_response", {
1817
+ enumerable: false,
1818
+ value: kvp._response,
1819
+ });
1820
+ }
1821
+ delete setting.eTag;
1822
+ return setting;
2029
1823
  }
2030
1824
  /**
2031
1825
  * Translates user-facing field names into their `select` equivalents (these can be
@@ -2054,6 +1848,17 @@ function formatFieldsForSelect(fieldNames) {
2054
1848
  });
2055
1849
  return mappedFieldNames;
2056
1850
  }
1851
+ function assertResponse(result) {
1852
+ if (!hasUnderscoreResponse(result)) {
1853
+ Object.defineProperty(result, "_response", {
1854
+ enumerable: false,
1855
+ value: "Something went wrong, _response(raw response) is supposed to be part of the response. Please file a bug at https://github.com/Azure/azure-sdk-for-js",
1856
+ });
1857
+ }
1858
+ }
1859
+ function hasUnderscoreResponse(result) {
1860
+ return Object.prototype.hasOwnProperty.call(result, "_response");
1861
+ }
2057
1862
 
2058
1863
  // Copyright (c) Microsoft Corporation.
2059
1864
  /** @internal */
@@ -2094,6 +1899,7 @@ async function trace(operationName, options, fn, createSpanFn = createSpan) {
2094
1899
  }
2095
1900
 
2096
1901
  // Copyright (c) Microsoft Corporation.
1902
+ // Licensed under the MIT license.
2097
1903
  /**
2098
1904
  * The sync token header, as described here:
2099
1905
  * https://docs.microsoft.com/azure/azure-app-configuration/rest-api-consistency
@@ -2107,26 +1913,18 @@ const SyncTokenHeaderName = "sync-token";
2107
1913
  */
2108
1914
  function syncTokenPolicy(syncTokens) {
2109
1915
  return {
2110
- create: (nextPolicy, options) => {
2111
- return new SyncTokenPolicy(nextPolicy, options, syncTokens);
1916
+ name: "Sync Token Policy",
1917
+ async sendRequest(request, next) {
1918
+ const syncTokenHeaderValue = syncTokens.getSyncTokenHeaderValue();
1919
+ if (syncTokenHeaderValue) {
1920
+ request.headers.set(SyncTokenHeaderName, syncTokenHeaderValue);
1921
+ }
1922
+ const response = await next(request);
1923
+ syncTokens.addSyncTokenFromHeaderValue(response.headers.get(SyncTokenHeaderName));
1924
+ return response;
2112
1925
  },
2113
1926
  };
2114
1927
  }
2115
- class SyncTokenPolicy extends coreHttp.BaseRequestPolicy {
2116
- constructor(nextPolicy, options, _syncTokens) {
2117
- super(nextPolicy, options);
2118
- this._syncTokens = _syncTokens;
2119
- }
2120
- async sendRequest(webResource) {
2121
- const syncTokenHeaderValue = this._syncTokens.getSyncTokenHeaderValue();
2122
- if (syncTokenHeaderValue != null) {
2123
- webResource.headers.set(SyncTokenHeaderName, syncTokenHeaderValue);
2124
- }
2125
- const response = await this._nextPolicy.sendRequest(webResource);
2126
- this._syncTokens.addSyncTokenFromHeaderValue(response.headers.get(SyncTokenHeaderName));
2127
- return response;
2128
- }
2129
- }
2130
1928
  /**
2131
1929
  * Sync token tracker (allows for real-time consistency, even in the face of
2132
1930
  * caching and load balancing within App Configuration).
@@ -2216,13 +2014,6 @@ function parseSyncToken(syncToken) {
2216
2014
  }
2217
2015
 
2218
2016
  // Copyright (c) Microsoft Corporation.
2219
- const packageName = "azsdk-js-app-configuration";
2220
- /**
2221
- * This constant should always be the same as the package.json's version - we use it when forming the
2222
- * User - Agent header. There's a unit test that makes sure it always stays in sync.
2223
- * @internal
2224
- */
2225
- const packageVersion = "1.3.2";
2226
2017
  const apiVersion = "1.0";
2227
2018
  const ConnectionStringRegex = /Endpoint=(.*);Id=(.*);Secret=(.*)/;
2228
2019
  const deserializationContentTypes = {
@@ -2244,24 +2035,35 @@ class AppConfigurationClient {
2244
2035
  let appConfigOptions = {};
2245
2036
  let appConfigCredential;
2246
2037
  let appConfigEndpoint;
2247
- if (coreHttp.isTokenCredential(tokenCredentialOrOptions)) {
2038
+ let authPolicy;
2039
+ if (coreAuth.isTokenCredential(tokenCredentialOrOptions)) {
2248
2040
  appConfigOptions = options || {};
2249
2041
  appConfigCredential = tokenCredentialOrOptions;
2250
- appConfigEndpoint = connectionStringOrEndpoint;
2042
+ appConfigEndpoint = connectionStringOrEndpoint.endsWith("/")
2043
+ ? connectionStringOrEndpoint.slice(0, -1)
2044
+ : connectionStringOrEndpoint;
2045
+ authPolicy = coreRestPipeline.bearerTokenAuthenticationPolicy({
2046
+ scopes: `${appConfigEndpoint}/.default`,
2047
+ credential: appConfigCredential,
2048
+ });
2251
2049
  }
2252
2050
  else {
2253
2051
  appConfigOptions = tokenCredentialOrOptions || {};
2254
2052
  const regexMatch = connectionStringOrEndpoint === null || connectionStringOrEndpoint === void 0 ? void 0 : connectionStringOrEndpoint.match(ConnectionStringRegex);
2255
2053
  if (regexMatch) {
2256
- appConfigCredential = new AppConfigCredential(regexMatch[2], regexMatch[3]);
2257
2054
  appConfigEndpoint = regexMatch[1];
2055
+ authPolicy = appConfigKeyCredentialPolicy(regexMatch[2], regexMatch[3]);
2258
2056
  }
2259
2057
  else {
2260
2058
  throw new Error(`Invalid connection string. Valid connection strings should match the regex '${ConnectionStringRegex.source}'.`);
2261
2059
  }
2262
2060
  }
2263
2061
  this._syncTokens = appConfigOptions.syncTokens || new SyncTokens();
2264
- this.client = new AppConfiguration(appConfigCredential, appConfigEndpoint, apiVersion, getGeneratedClientOptions(appConfigEndpoint, this._syncTokens, appConfigOptions));
2062
+ this.client = new AppConfiguration(appConfigEndpoint, apiVersion, appConfigOptions);
2063
+ this.client.pipeline.addPolicy(authPolicy, { phase: "Sign" });
2064
+ this.client.pipeline.addPolicy(syncTokenPolicy(this._syncTokens), { afterPhase: "Retry" });
2065
+ this.client.pipeline.removePolicy({ name: coreClient.deserializationPolicyName });
2066
+ this.client.pipeline.addPolicy(coreClient.deserializationPolicy({ expectedContentTypes: deserializationContentTypes }), { phase: "Deserialize" });
2265
2067
  }
2266
2068
  /**
2267
2069
  * Add a setting into the Azure App Configuration service, failing if it
@@ -2278,7 +2080,9 @@ class AppConfigurationClient {
2278
2080
  return this._trace("addConfigurationSetting", options, async (newOptions) => {
2279
2081
  const keyValue = serializeAsConfigurationSettingParam(configurationSetting);
2280
2082
  const originalResponse = await this.client.putKeyValue(configurationSetting.key, Object.assign({ ifNoneMatch: "*", label: configurationSetting.label, entity: keyValue }, newOptions));
2281
- return transformKeyValueResponse(originalResponse);
2083
+ const response = transformKeyValueResponse(originalResponse);
2084
+ assertResponse(response);
2085
+ return response;
2282
2086
  });
2283
2087
  }
2284
2088
  /**
@@ -2293,8 +2097,13 @@ class AppConfigurationClient {
2293
2097
  */
2294
2098
  deleteConfigurationSetting(id, options = {}) {
2295
2099
  return this._trace("deleteConfigurationSetting", options, async (newOptions) => {
2296
- const originalResponse = await this.client.deleteKeyValue(id.key, Object.assign(Object.assign({ label: id.label }, newOptions), checkAndFormatIfAndIfNoneMatch(id, options)));
2297
- return transformKeyValueResponseWithStatusCode(originalResponse);
2100
+ let status;
2101
+ const originalResponse = await this.client.deleteKeyValue(id.key, Object.assign(Object.assign(Object.assign({ label: id.label }, newOptions), checkAndFormatIfAndIfNoneMatch(id, options)), { onResponse: (response) => {
2102
+ status = response.status;
2103
+ } }));
2104
+ const response = transformKeyValueResponseWithStatusCode(originalResponse, status);
2105
+ assertResponse(response);
2106
+ return response;
2298
2107
  });
2299
2108
  }
2300
2109
  /**
@@ -2309,8 +2118,11 @@ class AppConfigurationClient {
2309
2118
  */
2310
2119
  async getConfigurationSetting(id, options = {}) {
2311
2120
  return this._trace("getConfigurationSetting", options, async (newOptions) => {
2312
- const originalResponse = await this.client.getKeyValue(id.key, Object.assign(Object.assign(Object.assign(Object.assign({}, newOptions), { label: id.label, select: formatFieldsForSelect(options.fields) }), formatAcceptDateTime(options)), checkAndFormatIfAndIfNoneMatch(id, options)));
2313
- const response = transformKeyValueResponseWithStatusCode(originalResponse);
2121
+ let status;
2122
+ const originalResponse = await this.client.getKeyValue(id.key, Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, newOptions), { label: id.label, select: formatFieldsForSelect(options.fields) }), formatAcceptDateTime(options)), checkAndFormatIfAndIfNoneMatch(id, options)), { onResponse: (response) => {
2123
+ status = response.status;
2124
+ } }));
2125
+ const response = transformKeyValueResponseWithStatusCode(originalResponse, status);
2314
2126
  // 304 only comes back if the user has passed a conditional option in their
2315
2127
  // request _and_ the remote object has the same etag as what the user passed.
2316
2128
  if (response.statusCode === 304) {
@@ -2320,6 +2132,7 @@ class AppConfigurationClient {
2320
2132
  // and now we'll undefine all the other properties that are not HTTP related
2321
2133
  makeConfigurationSettingEmpty(response);
2322
2134
  }
2135
+ assertResponse(response);
2323
2136
  return response;
2324
2137
  });
2325
2138
  }
@@ -2449,9 +2262,9 @@ class AppConfigurationClient {
2449
2262
  }));
2450
2263
  yield tslib.__await(yield* tslib.__asyncDelegator(tslib.__asyncValues(this.createListRevisionsPageFromResponse(currentResponse))));
2451
2264
  while (currentResponse.nextLink) {
2452
- currentResponse = yield tslib.__await(this._trace("listRevisions", options, (newOptions) => {
2265
+ currentResponse = (yield tslib.__await(this._trace("listRevisions", options, (newOptions) => {
2453
2266
  return this.client.getRevisions(Object.assign(Object.assign(Object.assign(Object.assign({}, newOptions), formatAcceptDateTime(options)), formatFiltersAndSelect(options)), { after: extractAfterTokenFromNextLink(currentResponse.nextLink) }));
2454
- }));
2267
+ })));
2455
2268
  if (!currentResponse.items) {
2456
2269
  break;
2457
2270
  }
@@ -2478,8 +2291,9 @@ class AppConfigurationClient {
2478
2291
  async setConfigurationSetting(configurationSetting, options = {}) {
2479
2292
  return this._trace("setConfigurationSetting", options, async (newOptions) => {
2480
2293
  const keyValue = serializeAsConfigurationSettingParam(configurationSetting);
2481
- const response = await this.client.putKeyValue(configurationSetting.key, Object.assign(Object.assign(Object.assign({}, newOptions), { label: configurationSetting.label, entity: keyValue }), checkAndFormatIfAndIfNoneMatch(configurationSetting, options)));
2482
- return transformKeyValueResponse(response);
2294
+ const response = transformKeyValueResponse(await this.client.putKeyValue(configurationSetting.key, Object.assign(Object.assign(Object.assign({}, newOptions), { label: configurationSetting.label, entity: keyValue }), checkAndFormatIfAndIfNoneMatch(configurationSetting, options))));
2295
+ assertResponse(response);
2296
+ return response;
2483
2297
  });
2484
2298
  }
2485
2299
  /**
@@ -2488,14 +2302,16 @@ class AppConfigurationClient {
2488
2302
  */
2489
2303
  async setReadOnly(id, readOnly, options = {}) {
2490
2304
  return this._trace("setReadOnly", options, async (newOptions) => {
2305
+ let response;
2491
2306
  if (readOnly) {
2492
- const response = await this.client.putLock(id.key, Object.assign(Object.assign(Object.assign({}, newOptions), { label: id.label }), checkAndFormatIfAndIfNoneMatch(id, options)));
2493
- return transformKeyValueResponse(response);
2307
+ response = await this.client.putLock(id.key, Object.assign(Object.assign(Object.assign({}, newOptions), { label: id.label }), checkAndFormatIfAndIfNoneMatch(id, options)));
2494
2308
  }
2495
2309
  else {
2496
- const response = await this.client.deleteLock(id.key, Object.assign(Object.assign(Object.assign({}, newOptions), { label: id.label }), checkAndFormatIfAndIfNoneMatch(id, options)));
2497
- return transformKeyValueResponse(response);
2310
+ response = await this.client.deleteLock(id.key, Object.assign(Object.assign(Object.assign({}, newOptions), { label: id.label }), checkAndFormatIfAndIfNoneMatch(id, options)));
2498
2311
  }
2312
+ response = transformKeyValueResponse(response);
2313
+ assertResponse(response);
2314
+ return response;
2499
2315
  });
2500
2316
  }
2501
2317
  /**
@@ -2507,43 +2323,6 @@ class AppConfigurationClient {
2507
2323
  this._syncTokens.addSyncTokenFromHeaderValue(syncToken);
2508
2324
  }
2509
2325
  }
2510
- /**
2511
- * Gets the options for the generated AppConfigurationClient
2512
- * @internal
2513
- */
2514
- function getGeneratedClientOptions(endpoint, syncTokens, internalAppConfigOptions) {
2515
- const retryPolicies = [
2516
- coreHttp.exponentialRetryPolicy(),
2517
- coreHttp.systemErrorRetryPolicy(),
2518
- throttlingRetryPolicy(internalAppConfigOptions.retryOptions),
2519
- ];
2520
- const userAgent = getUserAgentPrefix(internalAppConfigOptions.userAgentOptions &&
2521
- internalAppConfigOptions.userAgentOptions.userAgentPrefix);
2522
- return {
2523
- endpoint,
2524
- deserializationContentTypes,
2525
- // we'll add in our own custom retry policies
2526
- noRetryPolicy: true,
2527
- requestPolicyFactories: (defaults) => [
2528
- coreHttp.tracingPolicy({ userAgent }),
2529
- syncTokenPolicy(syncTokens),
2530
- coreHttp.userAgentPolicy({ value: userAgent }),
2531
- ...retryPolicies,
2532
- ...defaults,
2533
- ],
2534
- generateClientRequestIdHeader: true,
2535
- };
2536
- }
2537
- /**
2538
- * @internal
2539
- */
2540
- function getUserAgentPrefix(userSuppliedUserAgent) {
2541
- const appConfigDefaultUserAgent = `${packageName}/${packageVersion} ${coreHttp.getDefaultUserAgentValue()}`;
2542
- if (!userSuppliedUserAgent) {
2543
- return appConfigDefaultUserAgent;
2544
- }
2545
- return `${userSuppliedUserAgent} ${appConfigDefaultUserAgent}`;
2546
- }
2547
2326
 
2548
2327
  exports.AppConfigurationClient = AppConfigurationClient;
2549
2328
  exports.featureFlagContentType = featureFlagContentType;