@allthings/sdk 6.2.0-2 → 6.2.0-4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/lib.esm.js CHANGED
@@ -1,24 +1,16 @@
1
+ import { SSMClient, GetParametersCommand, GetParameterCommand } from '@aws-sdk/client-ssm';
1
2
  import querystring from 'query-string';
2
3
  import fetch from 'cross-fetch';
3
4
  import Bottleneck from 'bottleneck';
4
- import util from 'util';
5
- import stream from 'stream';
6
- import path from 'path';
7
- import http from 'http';
8
- import https from 'https';
9
- import url from 'url';
10
- import fs from 'fs';
5
+ import require$$1 from 'util';
6
+ import require$$0$1 from 'stream';
7
+ import require$$1$1 from 'path';
8
+ import require$$3 from 'http';
9
+ import require$$4 from 'https';
10
+ import require$$5 from 'url';
11
+ import require$$6 from 'fs';
11
12
 
12
- function createTokenStore(initialToken) {
13
- const token = new Map(Object.entries(initialToken || {}));
14
- return {
15
- get: (key) => token.get(key),
16
- reset: () => token.clear(),
17
- set: (update) => Object.entries(update).forEach(([key, value]) => token.set(key, value)),
18
- };
19
- }
20
-
21
- const version = "6.2.0-2";
13
+ const version = "6.2.0-4";
22
14
 
23
15
  const REST_API_URL = 'https://api.allthings.me';
24
16
  const OAUTH_URL = 'https://accounts.allthings.me';
@@ -40,6 +32,81 @@ const DEFAULT_API_WRAPPER_OPTIONS = {
40
32
  username: process.env.ALLTHINGS_OAUTH_USERNAME,
41
33
  };
42
34
  const USER_AGENT = `Allthings Node SDK REST Client/${version}`;
35
+ const DEFAULT_AWS_CONFIGURATION = {
36
+ region: 'eu-central-2',
37
+ };
38
+
39
+ var __rest$5 = (undefined && undefined.__rest) || function (s, e) {
40
+ var t = {};
41
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
42
+ t[p] = s[p];
43
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
44
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
45
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
46
+ t[p[i]] = s[p[i]];
47
+ }
48
+ return t;
49
+ };
50
+ const DEFAULT_CLIENT_CONFIG = {
51
+ clientConfig: DEFAULT_AWS_CONFIGURATION,
52
+ onlyDefault: false,
53
+ prefix: process.env.SSM_PARAM_PATH,
54
+ };
55
+ const getSecrets = async (ssm, config, params, defaultValue = '') => {
56
+ var _a, _b;
57
+ if (config.onlyDefault) {
58
+ return [defaultValue];
59
+ }
60
+ try {
61
+ const parameters = await ssm.send(new GetParametersCommand({
62
+ Names: params.map((param) => config.prefix + param),
63
+ WithDecryption: true,
64
+ }));
65
+ return ((_b = (_a = parameters === null || parameters === void 0 ? void 0 : parameters.Parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => { var _a; return (_a = parameter.Value) !== null && _a !== void 0 ? _a : defaultValue; })) !== null && _b !== void 0 ? _b : [defaultValue]);
66
+ }
67
+ catch (e) {
68
+ if (config.logger) {
69
+ config.logger(e);
70
+ }
71
+ return [defaultValue];
72
+ }
73
+ };
74
+ const getSecret = async (ssm, config, param, defaultValue = '') => {
75
+ var _a, _b;
76
+ if (config.onlyDefault) {
77
+ return defaultValue;
78
+ }
79
+ try {
80
+ const parameter = await ssm.send(new GetParameterCommand({
81
+ Name: config.prefix + param,
82
+ WithDecryption: true,
83
+ }));
84
+ return (_b = (_a = parameter === null || parameter === void 0 ? void 0 : parameter.Parameter) === null || _a === void 0 ? void 0 : _a.Value) !== null && _b !== void 0 ? _b : defaultValue;
85
+ }
86
+ catch (e) {
87
+ if (config.logger) {
88
+ config.logger(e);
89
+ }
90
+ return defaultValue;
91
+ }
92
+ };
93
+ const parameterStore = (userConfig) => {
94
+ const _a = Object.assign(Object.assign({}, DEFAULT_CLIENT_CONFIG), userConfig), { clientConfig } = _a, config = __rest$5(_a, ["clientConfig"]);
95
+ const ssm = new SSMClient(clientConfig);
96
+ return {
97
+ getSecret: (param, defaultValue) => getSecret(ssm, config, param, defaultValue),
98
+ getSecrets: (params, defaultValue) => getSecrets(ssm, config, params, defaultValue),
99
+ };
100
+ };
101
+
102
+ function createTokenStore(initialToken) {
103
+ const token = new Map(Object.entries(initialToken || {}));
104
+ return {
105
+ get: (key) => token.get(key),
106
+ reset: () => token.clear(),
107
+ set: (update) => Object.entries(update).forEach(([key, value]) => token.set(key, value)),
108
+ };
109
+ }
43
110
 
44
111
  const RESPONSE_TYPE$1 = 'code';
45
112
  const GRANT_TYPE$3 = 'authorization_code';
@@ -847,11 +914,15 @@ async function put(request, method, body, returnRawResultObject, headers) {
847
914
  return request('put', method, { body, headers }, returnRawResultObject);
848
915
  }
849
916
 
850
- var Stream$2 = stream.Stream;
917
+ function getDefaultExportFromCjs (x) {
918
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
919
+ }
851
920
 
921
+ var Stream$2 = require$$0$1.Stream;
922
+ var util$2 = require$$1;
852
923
 
853
- var delayed_stream = DelayedStream;
854
- function DelayedStream() {
924
+ var delayed_stream = DelayedStream$1;
925
+ function DelayedStream$1() {
855
926
  this.source = null;
856
927
  this.dataSize = 0;
857
928
  this.maxDataSize = 1024 * 1024;
@@ -861,9 +932,9 @@ function DelayedStream() {
861
932
  this._released = false;
862
933
  this._bufferedEvents = [];
863
934
  }
864
- util.inherits(DelayedStream, Stream$2);
935
+ util$2.inherits(DelayedStream$1, Stream$2);
865
936
 
866
- DelayedStream.create = function(source, options) {
937
+ DelayedStream$1.create = function(source, options) {
867
938
  var delayedStream = new this();
868
939
 
869
940
  options = options || {};
@@ -887,7 +958,7 @@ DelayedStream.create = function(source, options) {
887
958
  return delayedStream;
888
959
  };
889
960
 
890
- Object.defineProperty(DelayedStream.prototype, 'readable', {
961
+ Object.defineProperty(DelayedStream$1.prototype, 'readable', {
891
962
  configurable: true,
892
963
  enumerable: true,
893
964
  get: function() {
@@ -895,11 +966,11 @@ Object.defineProperty(DelayedStream.prototype, 'readable', {
895
966
  }
896
967
  });
897
968
 
898
- DelayedStream.prototype.setEncoding = function() {
969
+ DelayedStream$1.prototype.setEncoding = function() {
899
970
  return this.source.setEncoding.apply(this.source, arguments);
900
971
  };
901
972
 
902
- DelayedStream.prototype.resume = function() {
973
+ DelayedStream$1.prototype.resume = function() {
903
974
  if (!this._released) {
904
975
  this.release();
905
976
  }
@@ -907,11 +978,11 @@ DelayedStream.prototype.resume = function() {
907
978
  this.source.resume();
908
979
  };
909
980
 
910
- DelayedStream.prototype.pause = function() {
981
+ DelayedStream$1.prototype.pause = function() {
911
982
  this.source.pause();
912
983
  };
913
984
 
914
- DelayedStream.prototype.release = function() {
985
+ DelayedStream$1.prototype.release = function() {
915
986
  this._released = true;
916
987
 
917
988
  this._bufferedEvents.forEach(function(args) {
@@ -920,13 +991,13 @@ DelayedStream.prototype.release = function() {
920
991
  this._bufferedEvents = [];
921
992
  };
922
993
 
923
- DelayedStream.prototype.pipe = function() {
994
+ DelayedStream$1.prototype.pipe = function() {
924
995
  var r = Stream$2.prototype.pipe.apply(this, arguments);
925
996
  this.resume();
926
997
  return r;
927
998
  };
928
999
 
929
- DelayedStream.prototype._handleEmit = function(args) {
1000
+ DelayedStream$1.prototype._handleEmit = function(args) {
930
1001
  if (this._released) {
931
1002
  this.emit.apply(this, args);
932
1003
  return;
@@ -940,7 +1011,7 @@ DelayedStream.prototype._handleEmit = function(args) {
940
1011
  this._bufferedEvents.push(args);
941
1012
  };
942
1013
 
943
- DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
1014
+ DelayedStream$1.prototype._checkIfMaxDataSizeExceeded = function() {
944
1015
  if (this._maxDataSizeExceeded) {
945
1016
  return;
946
1017
  }
@@ -955,11 +1026,12 @@ DelayedStream.prototype._checkIfMaxDataSizeExceeded = function() {
955
1026
  this.emit('error', new Error(message));
956
1027
  };
957
1028
 
958
- var Stream$1 = stream.Stream;
959
-
1029
+ var util$1 = require$$1;
1030
+ var Stream$1 = require$$0$1.Stream;
1031
+ var DelayedStream = delayed_stream;
960
1032
 
961
- var combined_stream = CombinedStream;
962
- function CombinedStream() {
1033
+ var combined_stream = CombinedStream$1;
1034
+ function CombinedStream$1() {
963
1035
  this.writable = false;
964
1036
  this.readable = true;
965
1037
  this.dataSize = 0;
@@ -972,9 +1044,9 @@ function CombinedStream() {
972
1044
  this._insideLoop = false;
973
1045
  this._pendingNext = false;
974
1046
  }
975
- util.inherits(CombinedStream, Stream$1);
1047
+ util$1.inherits(CombinedStream$1, Stream$1);
976
1048
 
977
- CombinedStream.create = function(options) {
1049
+ CombinedStream$1.create = function(options) {
978
1050
  var combinedStream = new this();
979
1051
 
980
1052
  options = options || {};
@@ -985,7 +1057,7 @@ CombinedStream.create = function(options) {
985
1057
  return combinedStream;
986
1058
  };
987
1059
 
988
- CombinedStream.isStreamLike = function(stream) {
1060
+ CombinedStream$1.isStreamLike = function(stream) {
989
1061
  return (typeof stream !== 'function')
990
1062
  && (typeof stream !== 'string')
991
1063
  && (typeof stream !== 'boolean')
@@ -993,12 +1065,12 @@ CombinedStream.isStreamLike = function(stream) {
993
1065
  && (!Buffer.isBuffer(stream));
994
1066
  };
995
1067
 
996
- CombinedStream.prototype.append = function(stream) {
997
- var isStreamLike = CombinedStream.isStreamLike(stream);
1068
+ CombinedStream$1.prototype.append = function(stream) {
1069
+ var isStreamLike = CombinedStream$1.isStreamLike(stream);
998
1070
 
999
1071
  if (isStreamLike) {
1000
- if (!(stream instanceof delayed_stream)) {
1001
- var newStream = delayed_stream.create(stream, {
1072
+ if (!(stream instanceof DelayedStream)) {
1073
+ var newStream = DelayedStream.create(stream, {
1002
1074
  maxDataSize: Infinity,
1003
1075
  pauseStream: this.pauseStreams,
1004
1076
  });
@@ -1017,13 +1089,13 @@ CombinedStream.prototype.append = function(stream) {
1017
1089
  return this;
1018
1090
  };
1019
1091
 
1020
- CombinedStream.prototype.pipe = function(dest, options) {
1092
+ CombinedStream$1.prototype.pipe = function(dest, options) {
1021
1093
  Stream$1.prototype.pipe.call(this, dest, options);
1022
1094
  this.resume();
1023
1095
  return dest;
1024
1096
  };
1025
1097
 
1026
- CombinedStream.prototype._getNext = function() {
1098
+ CombinedStream$1.prototype._getNext = function() {
1027
1099
  this._currentStream = null;
1028
1100
 
1029
1101
  if (this._insideLoop) {
@@ -1042,7 +1114,7 @@ CombinedStream.prototype._getNext = function() {
1042
1114
  }
1043
1115
  };
1044
1116
 
1045
- CombinedStream.prototype._realGetNext = function() {
1117
+ CombinedStream$1.prototype._realGetNext = function() {
1046
1118
  var stream = this._streams.shift();
1047
1119
 
1048
1120
 
@@ -1058,7 +1130,7 @@ CombinedStream.prototype._realGetNext = function() {
1058
1130
 
1059
1131
  var getStream = stream;
1060
1132
  getStream(function(stream) {
1061
- var isStreamLike = CombinedStream.isStreamLike(stream);
1133
+ var isStreamLike = CombinedStream$1.isStreamLike(stream);
1062
1134
  if (isStreamLike) {
1063
1135
  stream.on('data', this._checkDataSize.bind(this));
1064
1136
  this._handleErrors(stream);
@@ -1068,10 +1140,10 @@ CombinedStream.prototype._realGetNext = function() {
1068
1140
  }.bind(this));
1069
1141
  };
1070
1142
 
1071
- CombinedStream.prototype._pipeNext = function(stream) {
1143
+ CombinedStream$1.prototype._pipeNext = function(stream) {
1072
1144
  this._currentStream = stream;
1073
1145
 
1074
- var isStreamLike = CombinedStream.isStreamLike(stream);
1146
+ var isStreamLike = CombinedStream$1.isStreamLike(stream);
1075
1147
  if (isStreamLike) {
1076
1148
  stream.on('end', this._getNext.bind(this));
1077
1149
  stream.pipe(this, {end: false});
@@ -1083,18 +1155,18 @@ CombinedStream.prototype._pipeNext = function(stream) {
1083
1155
  this._getNext();
1084
1156
  };
1085
1157
 
1086
- CombinedStream.prototype._handleErrors = function(stream) {
1158
+ CombinedStream$1.prototype._handleErrors = function(stream) {
1087
1159
  var self = this;
1088
1160
  stream.on('error', function(err) {
1089
1161
  self._emitError(err);
1090
1162
  });
1091
1163
  };
1092
1164
 
1093
- CombinedStream.prototype.write = function(data) {
1165
+ CombinedStream$1.prototype.write = function(data) {
1094
1166
  this.emit('data', data);
1095
1167
  };
1096
1168
 
1097
- CombinedStream.prototype.pause = function() {
1169
+ CombinedStream$1.prototype.pause = function() {
1098
1170
  if (!this.pauseStreams) {
1099
1171
  return;
1100
1172
  }
@@ -1103,7 +1175,7 @@ CombinedStream.prototype.pause = function() {
1103
1175
  this.emit('pause');
1104
1176
  };
1105
1177
 
1106
- CombinedStream.prototype.resume = function() {
1178
+ CombinedStream$1.prototype.resume = function() {
1107
1179
  if (!this._released) {
1108
1180
  this._released = true;
1109
1181
  this.writable = true;
@@ -1114,23 +1186,23 @@ CombinedStream.prototype.resume = function() {
1114
1186
  this.emit('resume');
1115
1187
  };
1116
1188
 
1117
- CombinedStream.prototype.end = function() {
1189
+ CombinedStream$1.prototype.end = function() {
1118
1190
  this._reset();
1119
1191
  this.emit('end');
1120
1192
  };
1121
1193
 
1122
- CombinedStream.prototype.destroy = function() {
1194
+ CombinedStream$1.prototype.destroy = function() {
1123
1195
  this._reset();
1124
1196
  this.emit('close');
1125
1197
  };
1126
1198
 
1127
- CombinedStream.prototype._reset = function() {
1199
+ CombinedStream$1.prototype._reset = function() {
1128
1200
  this.writable = false;
1129
1201
  this._streams = [];
1130
1202
  this._currentStream = null;
1131
1203
  };
1132
1204
 
1133
- CombinedStream.prototype._checkDataSize = function() {
1205
+ CombinedStream$1.prototype._checkDataSize = function() {
1134
1206
  this._updateDataSize();
1135
1207
  if (this.dataSize <= this.maxDataSize) {
1136
1208
  return;
@@ -1141,7 +1213,7 @@ CombinedStream.prototype._checkDataSize = function() {
1141
1213
  this._emitError(new Error(message));
1142
1214
  };
1143
1215
 
1144
- CombinedStream.prototype._updateDataSize = function() {
1216
+ CombinedStream$1.prototype._updateDataSize = function() {
1145
1217
  this.dataSize = 0;
1146
1218
 
1147
1219
  var self = this;
@@ -1158,20 +1230,14 @@ CombinedStream.prototype._updateDataSize = function() {
1158
1230
  }
1159
1231
  };
1160
1232
 
1161
- CombinedStream.prototype._emitError = function(err) {
1233
+ CombinedStream$1.prototype._emitError = function(err) {
1162
1234
  this._reset();
1163
1235
  this.emit('error', err);
1164
1236
  };
1165
1237
 
1166
- function createCommonjsModule(fn, module) {
1167
- return module = { exports: {} }, fn(module, module.exports), module.exports;
1168
- }
1169
-
1170
- function getCjsExportFromNamespace (n) {
1171
- return n && n['default'] || n;
1172
- }
1238
+ var mimeTypes = {};
1173
1239
 
1174
- var db = {
1240
+ var require$$0 = {
1175
1241
  "application/1d-interleaved-parityfec": {
1176
1242
  source: "iana"
1177
1243
  },
@@ -10827,13 +10893,6 @@ var db = {
10827
10893
  }
10828
10894
  };
10829
10895
 
10830
- var db$1 = /*#__PURE__*/Object.freeze({
10831
- __proto__: null,
10832
- default: db
10833
- });
10834
-
10835
- var require$$0 = getCjsExportFromNamespace(db$1);
10836
-
10837
10896
  /*!
10838
10897
  * mime-db
10839
10898
  * Copyright(c) 2014 Jonathan Ong
@@ -10846,204 +10905,204 @@ var require$$0 = getCjsExportFromNamespace(db$1);
10846
10905
 
10847
10906
  var mimeDb = require$$0;
10848
10907
 
10849
- var mimeTypes = createCommonjsModule(function (module, exports) {
10850
-
10851
- /**
10852
- * Module dependencies.
10853
- * @private
10854
- */
10855
-
10856
-
10857
- var extname = path.extname;
10858
-
10859
- /**
10860
- * Module variables.
10861
- * @private
10862
- */
10863
-
10864
- var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
10865
- var TEXT_TYPE_REGEXP = /^text\//i;
10866
-
10867
- /**
10868
- * Module exports.
10869
- * @public
10870
- */
10871
-
10872
- exports.charset = charset;
10873
- exports.charsets = { lookup: charset };
10874
- exports.contentType = contentType;
10875
- exports.extension = extension;
10876
- exports.extensions = Object.create(null);
10877
- exports.lookup = lookup;
10878
- exports.types = Object.create(null);
10879
-
10880
- // Populate the extensions/types maps
10881
- populateMaps(exports.extensions, exports.types);
10882
-
10883
- /**
10884
- * Get the default charset for a MIME type.
10885
- *
10886
- * @param {string} type
10887
- * @return {boolean|string}
10888
- */
10889
-
10890
- function charset (type) {
10891
- if (!type || typeof type !== 'string') {
10892
- return false
10893
- }
10894
-
10895
- // TODO: use media-typer
10896
- var match = EXTRACT_TYPE_REGEXP.exec(type);
10897
- var mime = match && mimeDb[match[1].toLowerCase()];
10898
-
10899
- if (mime && mime.charset) {
10900
- return mime.charset
10901
- }
10902
-
10903
- // default text/* to utf-8
10904
- if (match && TEXT_TYPE_REGEXP.test(match[1])) {
10905
- return 'UTF-8'
10906
- }
10907
-
10908
- return false
10909
- }
10910
-
10911
- /**
10912
- * Create a full Content-Type header given a MIME type or extension.
10913
- *
10914
- * @param {string} str
10915
- * @return {boolean|string}
10916
- */
10917
-
10918
- function contentType (str) {
10919
- // TODO: should this even be in this module?
10920
- if (!str || typeof str !== 'string') {
10921
- return false
10922
- }
10923
-
10924
- var mime = str.indexOf('/') === -1
10925
- ? exports.lookup(str)
10926
- : str;
10927
-
10928
- if (!mime) {
10929
- return false
10930
- }
10931
-
10932
- // TODO: use content-type or other module
10933
- if (mime.indexOf('charset') === -1) {
10934
- var charset = exports.charset(mime);
10935
- if (charset) mime += '; charset=' + charset.toLowerCase();
10936
- }
10937
-
10938
- return mime
10939
- }
10940
-
10941
- /**
10942
- * Get the default extension for a MIME type.
10943
- *
10944
- * @param {string} type
10945
- * @return {boolean|string}
10946
- */
10947
-
10948
- function extension (type) {
10949
- if (!type || typeof type !== 'string') {
10950
- return false
10951
- }
10952
-
10953
- // TODO: use media-typer
10954
- var match = EXTRACT_TYPE_REGEXP.exec(type);
10955
-
10956
- // get extensions
10957
- var exts = match && exports.extensions[match[1].toLowerCase()];
10958
-
10959
- if (!exts || !exts.length) {
10960
- return false
10961
- }
10962
-
10963
- return exts[0]
10964
- }
10965
-
10966
- /**
10967
- * Lookup the MIME type for a file path/extension.
10968
- *
10969
- * @param {string} path
10970
- * @return {boolean|string}
10971
- */
10972
-
10973
- function lookup (path) {
10974
- if (!path || typeof path !== 'string') {
10975
- return false
10976
- }
10977
-
10978
- // get the extension ("ext" or ".ext" or full path)
10979
- var extension = extname('x.' + path)
10980
- .toLowerCase()
10981
- .substr(1);
10982
-
10983
- if (!extension) {
10984
- return false
10985
- }
10986
-
10987
- return exports.types[extension] || false
10988
- }
10989
-
10990
- /**
10991
- * Populate the extensions and types maps.
10992
- * @private
10908
+ /*!
10909
+ * mime-types
10910
+ * Copyright(c) 2014 Jonathan Ong
10911
+ * Copyright(c) 2015 Douglas Christopher Wilson
10912
+ * MIT Licensed
10993
10913
  */
10994
10914
 
10995
- function populateMaps (extensions, types) {
10996
- // source preference (least -> most)
10997
- var preference = ['nginx', 'apache', undefined, 'iana'];
10998
-
10999
- Object.keys(mimeDb).forEach(function forEachMimeType (type) {
11000
- var mime = mimeDb[type];
11001
- var exts = mime.extensions;
11002
-
11003
- if (!exts || !exts.length) {
11004
- return
11005
- }
11006
-
11007
- // mime -> extensions
11008
- extensions[type] = exts;
11009
-
11010
- // extension -> mime
11011
- for (var i = 0; i < exts.length; i++) {
11012
- var extension = exts[i];
11013
-
11014
- if (types[extension]) {
11015
- var from = preference.indexOf(mimeDb[types[extension]].source);
11016
- var to = preference.indexOf(mime.source);
11017
-
11018
- if (types[extension] !== 'application/octet-stream' &&
11019
- (from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) {
11020
- // skip the remapping
11021
- continue
11022
- }
11023
- }
11024
-
11025
- // set the extension -> mime
11026
- types[extension] = type;
11027
- }
11028
- });
11029
- }
11030
- });
11031
- mimeTypes.charset;
11032
- mimeTypes.charsets;
11033
- mimeTypes.contentType;
11034
- mimeTypes.extension;
11035
- mimeTypes.extensions;
11036
- mimeTypes.lookup;
11037
- mimeTypes.types;
11038
-
11039
- var defer_1 = defer;
10915
+ (function (exports) {
10916
+
10917
+ /**
10918
+ * Module dependencies.
10919
+ * @private
10920
+ */
10921
+
10922
+ var db = mimeDb;
10923
+ var extname = require$$1$1.extname;
10924
+
10925
+ /**
10926
+ * Module variables.
10927
+ * @private
10928
+ */
10929
+
10930
+ var EXTRACT_TYPE_REGEXP = /^\s*([^;\s]*)(?:;|\s|$)/;
10931
+ var TEXT_TYPE_REGEXP = /^text\//i;
10932
+
10933
+ /**
10934
+ * Module exports.
10935
+ * @public
10936
+ */
10937
+
10938
+ exports.charset = charset;
10939
+ exports.charsets = { lookup: charset };
10940
+ exports.contentType = contentType;
10941
+ exports.extension = extension;
10942
+ exports.extensions = Object.create(null);
10943
+ exports.lookup = lookup;
10944
+ exports.types = Object.create(null);
10945
+
10946
+ // Populate the extensions/types maps
10947
+ populateMaps(exports.extensions, exports.types);
10948
+
10949
+ /**
10950
+ * Get the default charset for a MIME type.
10951
+ *
10952
+ * @param {string} type
10953
+ * @return {boolean|string}
10954
+ */
10955
+
10956
+ function charset (type) {
10957
+ if (!type || typeof type !== 'string') {
10958
+ return false
10959
+ }
10960
+
10961
+ // TODO: use media-typer
10962
+ var match = EXTRACT_TYPE_REGEXP.exec(type);
10963
+ var mime = match && db[match[1].toLowerCase()];
10964
+
10965
+ if (mime && mime.charset) {
10966
+ return mime.charset
10967
+ }
10968
+
10969
+ // default text/* to utf-8
10970
+ if (match && TEXT_TYPE_REGEXP.test(match[1])) {
10971
+ return 'UTF-8'
10972
+ }
10973
+
10974
+ return false
10975
+ }
10976
+
10977
+ /**
10978
+ * Create a full Content-Type header given a MIME type or extension.
10979
+ *
10980
+ * @param {string} str
10981
+ * @return {boolean|string}
10982
+ */
10983
+
10984
+ function contentType (str) {
10985
+ // TODO: should this even be in this module?
10986
+ if (!str || typeof str !== 'string') {
10987
+ return false
10988
+ }
10989
+
10990
+ var mime = str.indexOf('/') === -1
10991
+ ? exports.lookup(str)
10992
+ : str;
10993
+
10994
+ if (!mime) {
10995
+ return false
10996
+ }
10997
+
10998
+ // TODO: use content-type or other module
10999
+ if (mime.indexOf('charset') === -1) {
11000
+ var charset = exports.charset(mime);
11001
+ if (charset) mime += '; charset=' + charset.toLowerCase();
11002
+ }
11003
+
11004
+ return mime
11005
+ }
11006
+
11007
+ /**
11008
+ * Get the default extension for a MIME type.
11009
+ *
11010
+ * @param {string} type
11011
+ * @return {boolean|string}
11012
+ */
11013
+
11014
+ function extension (type) {
11015
+ if (!type || typeof type !== 'string') {
11016
+ return false
11017
+ }
11018
+
11019
+ // TODO: use media-typer
11020
+ var match = EXTRACT_TYPE_REGEXP.exec(type);
11021
+
11022
+ // get extensions
11023
+ var exts = match && exports.extensions[match[1].toLowerCase()];
11024
+
11025
+ if (!exts || !exts.length) {
11026
+ return false
11027
+ }
11028
+
11029
+ return exts[0]
11030
+ }
11031
+
11032
+ /**
11033
+ * Lookup the MIME type for a file path/extension.
11034
+ *
11035
+ * @param {string} path
11036
+ * @return {boolean|string}
11037
+ */
11038
+
11039
+ function lookup (path) {
11040
+ if (!path || typeof path !== 'string') {
11041
+ return false
11042
+ }
11043
+
11044
+ // get the extension ("ext" or ".ext" or full path)
11045
+ var extension = extname('x.' + path)
11046
+ .toLowerCase()
11047
+ .substr(1);
11048
+
11049
+ if (!extension) {
11050
+ return false
11051
+ }
11052
+
11053
+ return exports.types[extension] || false
11054
+ }
11055
+
11056
+ /**
11057
+ * Populate the extensions and types maps.
11058
+ * @private
11059
+ */
11060
+
11061
+ function populateMaps (extensions, types) {
11062
+ // source preference (least -> most)
11063
+ var preference = ['nginx', 'apache', undefined, 'iana'];
11064
+
11065
+ Object.keys(db).forEach(function forEachMimeType (type) {
11066
+ var mime = db[type];
11067
+ var exts = mime.extensions;
11068
+
11069
+ if (!exts || !exts.length) {
11070
+ return
11071
+ }
11072
+
11073
+ // mime -> extensions
11074
+ extensions[type] = exts;
11075
+
11076
+ // extension -> mime
11077
+ for (var i = 0; i < exts.length; i++) {
11078
+ var extension = exts[i];
11079
+
11080
+ if (types[extension]) {
11081
+ var from = preference.indexOf(db[types[extension]].source);
11082
+ var to = preference.indexOf(mime.source);
11083
+
11084
+ if (types[extension] !== 'application/octet-stream' &&
11085
+ (from > to || (from === to && types[extension].substr(0, 12) === 'application/'))) {
11086
+ // skip the remapping
11087
+ continue
11088
+ }
11089
+ }
11090
+
11091
+ // set the extension -> mime
11092
+ types[extension] = type;
11093
+ }
11094
+ });
11095
+ }
11096
+ } (mimeTypes));
11097
+
11098
+ var defer_1 = defer$1;
11040
11099
 
11041
11100
  /**
11042
11101
  * Runs provided function on next iteration of the event loop
11043
11102
  *
11044
11103
  * @param {function} fn - function to run
11045
11104
  */
11046
- function defer(fn)
11105
+ function defer$1(fn)
11047
11106
  {
11048
11107
  var nextTick = typeof setImmediate == 'function'
11049
11108
  ? setImmediate
@@ -11063,8 +11122,10 @@ function defer(fn)
11063
11122
  }
11064
11123
  }
11065
11124
 
11125
+ var defer = defer_1;
11126
+
11066
11127
  // API
11067
- var async_1 = async;
11128
+ var async_1 = async$2;
11068
11129
 
11069
11130
  /**
11070
11131
  * Runs provided callback asynchronously
@@ -11073,12 +11134,12 @@ var async_1 = async;
11073
11134
  * @param {function} callback - callback to invoke
11074
11135
  * @returns {function} - augmented callback
11075
11136
  */
11076
- function async(callback)
11137
+ function async$2(callback)
11077
11138
  {
11078
11139
  var isAsync = false;
11079
11140
 
11080
11141
  // check if async happened
11081
- defer_1(function() { isAsync = true; });
11142
+ defer(function() { isAsync = true; });
11082
11143
 
11083
11144
  return function async_callback(err, result)
11084
11145
  {
@@ -11088,7 +11149,7 @@ function async(callback)
11088
11149
  }
11089
11150
  else
11090
11151
  {
11091
- defer_1(function nextTick_callback()
11152
+ defer(function nextTick_callback()
11092
11153
  {
11093
11154
  callback(err, result);
11094
11155
  });
@@ -11097,14 +11158,14 @@ function async(callback)
11097
11158
  }
11098
11159
 
11099
11160
  // API
11100
- var abort_1 = abort;
11161
+ var abort_1 = abort$2;
11101
11162
 
11102
11163
  /**
11103
11164
  * Aborts leftover active jobs
11104
11165
  *
11105
11166
  * @param {object} state - current state object
11106
11167
  */
11107
- function abort(state)
11168
+ function abort$2(state)
11108
11169
  {
11109
11170
  Object.keys(state.jobs).forEach(clean.bind(state));
11110
11171
 
@@ -11126,8 +11187,12 @@ function clean(key)
11126
11187
  }
11127
11188
  }
11128
11189
 
11190
+ var async$1 = async_1
11191
+ , abort$1 = abort_1
11192
+ ;
11193
+
11129
11194
  // API
11130
- var iterate_1 = iterate;
11195
+ var iterate_1 = iterate$2;
11131
11196
 
11132
11197
  /**
11133
11198
  * Iterates over each job object
@@ -11137,7 +11202,7 @@ var iterate_1 = iterate;
11137
11202
  * @param {object} state - current job status
11138
11203
  * @param {function} callback - invoked when all elements processed
11139
11204
  */
11140
- function iterate(list, iterator, state, callback)
11205
+ function iterate$2(list, iterator, state, callback)
11141
11206
  {
11142
11207
  // store current index
11143
11208
  var key = state['keyedList'] ? state['keyedList'][state.index] : state.index;
@@ -11159,7 +11224,7 @@ function iterate(list, iterator, state, callback)
11159
11224
  // don't process rest of the results
11160
11225
  // stop still active jobs
11161
11226
  // and reset the list
11162
- abort_1(state);
11227
+ abort$1(state);
11163
11228
  }
11164
11229
  else
11165
11230
  {
@@ -11187,12 +11252,12 @@ function runJob(iterator, key, item, callback)
11187
11252
  // allow shortcut if iterator expects only two arguments
11188
11253
  if (iterator.length == 2)
11189
11254
  {
11190
- aborter = iterator(item, async_1(callback));
11255
+ aborter = iterator(item, async$1(callback));
11191
11256
  }
11192
11257
  // otherwise go with full three arguments
11193
11258
  else
11194
11259
  {
11195
- aborter = iterator(item, key, async_1(callback));
11260
+ aborter = iterator(item, key, async$1(callback));
11196
11261
  }
11197
11262
 
11198
11263
  return aborter;
@@ -11236,8 +11301,12 @@ function state(list, sortMethod)
11236
11301
  return initState;
11237
11302
  }
11238
11303
 
11304
+ var abort = abort_1
11305
+ , async = async_1
11306
+ ;
11307
+
11239
11308
  // API
11240
- var terminator_1 = terminator;
11309
+ var terminator_1 = terminator$2;
11241
11310
 
11242
11311
  /**
11243
11312
  * Terminates jobs in the attached state context
@@ -11245,7 +11314,7 @@ var terminator_1 = terminator;
11245
11314
  * @this AsyncKitState#
11246
11315
  * @param {function} callback - final callback to invoke after termination
11247
11316
  */
11248
- function terminator(callback)
11317
+ function terminator$2(callback)
11249
11318
  {
11250
11319
  if (!Object.keys(this.jobs).length)
11251
11320
  {
@@ -11256,12 +11325,17 @@ function terminator(callback)
11256
11325
  this.index = this.size;
11257
11326
 
11258
11327
  // abort jobs
11259
- abort_1(this);
11328
+ abort(this);
11260
11329
 
11261
11330
  // send back results we have so far
11262
- async_1(callback)(null, this.results);
11331
+ async(callback)(null, this.results);
11263
11332
  }
11264
11333
 
11334
+ var iterate$1 = iterate_1
11335
+ , initState$1 = state_1
11336
+ , terminator$1 = terminator_1
11337
+ ;
11338
+
11265
11339
  // Public API
11266
11340
  var parallel_1 = parallel;
11267
11341
 
@@ -11275,11 +11349,11 @@ var parallel_1 = parallel;
11275
11349
  */
11276
11350
  function parallel(list, iterator, callback)
11277
11351
  {
11278
- var state = state_1(list);
11352
+ var state = initState$1(list);
11279
11353
 
11280
11354
  while (state.index < (state['keyedList'] || list).length)
11281
11355
  {
11282
- iterate_1(list, iterator, state, function(error, result)
11356
+ iterate$1(list, iterator, state, function(error, result)
11283
11357
  {
11284
11358
  if (error)
11285
11359
  {
@@ -11298,14 +11372,21 @@ function parallel(list, iterator, callback)
11298
11372
  state.index++;
11299
11373
  }
11300
11374
 
11301
- return terminator_1.bind(state, callback);
11375
+ return terminator$1.bind(state, callback);
11302
11376
  }
11303
11377
 
11378
+ var serialOrdered$2 = {exports: {}};
11379
+
11380
+ var iterate = iterate_1
11381
+ , initState = state_1
11382
+ , terminator = terminator_1
11383
+ ;
11384
+
11304
11385
  // Public API
11305
- var serialOrdered_1 = serialOrdered;
11386
+ serialOrdered$2.exports = serialOrdered$1;
11306
11387
  // sorting helpers
11307
- var ascending_1 = ascending;
11308
- var descending_1 = descending;
11388
+ serialOrdered$2.exports.ascending = ascending;
11389
+ serialOrdered$2.exports.descending = descending;
11309
11390
 
11310
11391
  /**
11311
11392
  * Runs iterator over provided sorted array elements in series
@@ -11316,11 +11397,11 @@ var descending_1 = descending;
11316
11397
  * @param {function} callback - invoked when all elements processed
11317
11398
  * @returns {function} - jobs terminator
11318
11399
  */
11319
- function serialOrdered(list, iterator, sortMethod, callback)
11400
+ function serialOrdered$1(list, iterator, sortMethod, callback)
11320
11401
  {
11321
- var state = state_1(list, sortMethod);
11402
+ var state = initState(list, sortMethod);
11322
11403
 
11323
- iterate_1(list, iterator, state, function iteratorHandler(error, result)
11404
+ iterate(list, iterator, state, function iteratorHandler(error, result)
11324
11405
  {
11325
11406
  if (error)
11326
11407
  {
@@ -11333,7 +11414,7 @@ function serialOrdered(list, iterator, sortMethod, callback)
11333
11414
  // are we there yet?
11334
11415
  if (state.index < (state['keyedList'] || list).length)
11335
11416
  {
11336
- iterate_1(list, iterator, state, iteratorHandler);
11417
+ iterate(list, iterator, state, iteratorHandler);
11337
11418
  return;
11338
11419
  }
11339
11420
 
@@ -11341,7 +11422,7 @@ function serialOrdered(list, iterator, sortMethod, callback)
11341
11422
  callback(null, state.results);
11342
11423
  });
11343
11424
 
11344
- return terminator_1.bind(state, callback);
11425
+ return terminator.bind(state, callback);
11345
11426
  }
11346
11427
 
11347
11428
  /*
@@ -11371,8 +11452,10 @@ function descending(a, b)
11371
11452
  {
11372
11453
  return -1 * ascending(a, b);
11373
11454
  }
11374
- serialOrdered_1.ascending = ascending_1;
11375
- serialOrdered_1.descending = descending_1;
11455
+
11456
+ var serialOrderedExports = serialOrdered$2.exports;
11457
+
11458
+ var serialOrdered = serialOrderedExports;
11376
11459
 
11377
11460
  // Public API
11378
11461
  var serial_1 = serial;
@@ -11387,18 +11470,18 @@ var serial_1 = serial;
11387
11470
  */
11388
11471
  function serial(list, iterator, callback)
11389
11472
  {
11390
- return serialOrdered_1(list, iterator, null, callback);
11473
+ return serialOrdered(list, iterator, null, callback);
11391
11474
  }
11392
11475
 
11393
- var asynckit =
11476
+ var asynckit$1 =
11394
11477
  {
11395
11478
  parallel : parallel_1,
11396
11479
  serial : serial_1,
11397
- serialOrdered : serialOrdered_1
11480
+ serialOrdered : serialOrderedExports
11398
11481
  };
11399
11482
 
11400
11483
  // populates missing values
11401
- var populate = function(dst, src) {
11484
+ var populate$1 = function(dst, src) {
11402
11485
 
11403
11486
  Object.keys(src).forEach(function(prop)
11404
11487
  {
@@ -11408,18 +11491,23 @@ var populate = function(dst, src) {
11408
11491
  return dst;
11409
11492
  };
11410
11493
 
11411
- var parseUrl = url.parse;
11412
-
11413
- var Stream = stream.Stream;
11414
-
11415
-
11416
-
11494
+ var CombinedStream = combined_stream;
11495
+ var util = require$$1;
11496
+ var path = require$$1$1;
11497
+ var http = require$$3;
11498
+ var https = require$$4;
11499
+ var parseUrl = require$$5.parse;
11500
+ var fs = require$$6;
11501
+ var Stream = require$$0$1.Stream;
11502
+ var mime = mimeTypes;
11503
+ var asynckit = asynckit$1;
11504
+ var populate = populate$1;
11417
11505
 
11418
11506
  // Public API
11419
11507
  var form_data = FormData;
11420
11508
 
11421
11509
  // make it a Stream
11422
- util.inherits(FormData, combined_stream);
11510
+ util.inherits(FormData, CombinedStream);
11423
11511
 
11424
11512
  /**
11425
11513
  * Create readable "multipart/form-data" streams.
@@ -11438,7 +11526,7 @@ function FormData(options) {
11438
11526
  this._valueLength = 0;
11439
11527
  this._valuesToMeasure = [];
11440
11528
 
11441
- combined_stream.call(this);
11529
+ CombinedStream.call(this);
11442
11530
 
11443
11531
  options = options || {};
11444
11532
  for (var option in options) {
@@ -11458,7 +11546,7 @@ FormData.prototype.append = function(field, value, options) {
11458
11546
  options = {filename: options};
11459
11547
  }
11460
11548
 
11461
- var append = combined_stream.prototype.append.bind(this);
11549
+ var append = CombinedStream.prototype.append.bind(this);
11462
11550
 
11463
11551
  // all that streamy business can't handle numbers
11464
11552
  if (typeof value == 'number') {
@@ -11653,12 +11741,12 @@ FormData.prototype._getContentType = function(value, options) {
11653
11741
 
11654
11742
  // or try `name` from formidable, browser
11655
11743
  if (!contentType && value.name) {
11656
- contentType = mimeTypes.lookup(value.name);
11744
+ contentType = mime.lookup(value.name);
11657
11745
  }
11658
11746
 
11659
11747
  // or try `path` from fs-, request- streams
11660
11748
  if (!contentType && value.path) {
11661
- contentType = mimeTypes.lookup(value.path);
11749
+ contentType = mime.lookup(value.path);
11662
11750
  }
11663
11751
 
11664
11752
  // or if it's http-reponse
@@ -11668,7 +11756,7 @@ FormData.prototype._getContentType = function(value, options) {
11668
11756
 
11669
11757
  // or guess it from the filepath or filename
11670
11758
  if (!contentType && (options.filepath || options.filename)) {
11671
- contentType = mimeTypes.lookup(options.filepath || options.filename);
11759
+ contentType = mime.lookup(options.filepath || options.filename);
11672
11760
  }
11673
11761
 
11674
11762
  // fallback to the default content type if `value` is not simple value
@@ -11905,6 +11993,8 @@ FormData.prototype.toString = function () {
11905
11993
  return '[object FormData]';
11906
11994
  };
11907
11995
 
11996
+ var FormDataModule = /*@__PURE__*/getDefaultExportFromCjs(form_data);
11997
+
11908
11998
  const GRANT_TYPE$1 = 'client_credentials';
11909
11999
  const castClientOptionsToRequestParams = (clientOptions) => {
11910
12000
  const { scope, clientId, clientSecret } = clientOptions;
@@ -12098,7 +12188,7 @@ function makeApiRequest(oauthTokenStore, oauthTokenRequester, options, httpMetho
12098
12188
  const formData = Object.entries(form).reduce((previous, [name, value]) => {
12099
12189
  previous.append.apply(previous, [name].concat(value));
12100
12190
  return previous;
12101
- }, new form_data());
12191
+ }, new FormDataModule());
12102
12192
  const headers = Object.assign(Object.assign(Object.assign(Object.assign({ accept: 'application/json', authorization: `Bearer ${oauthTokenStore.get('accessToken')}`, 'X-Allthings-Caller': `${options.serviceName
12103
12193
  ? options.serviceName
12104
12194
  : process.env.SEVICE_NAME
@@ -12322,4 +12412,4 @@ var EnumLookupUserType;
12322
12412
  EnumLookupUserType["tenant"] = "tenant";
12323
12413
  })(EnumLookupUserType || (EnumLookupUserType = {}));
12324
12414
 
12325
- export { EnumCommunicationMethodType, EnumCommunicationPreferenceChannel, EnumCountryCode, EnumInputChannel, EnumLocale, EnumLookupUserType, EnumResource, EnumServiceProviderType, EnumTimezone, EnumUnitObjectType, EnumUnitType, EnumUserPermissionObjectType, EnumUserPermissionRole, EnumUserRelationType, EnumUtilisationPeriodType, createTokenStore, restClient };
12415
+ export { DEFAULT_CLIENT_CONFIG as DEFAULT_PARAMETER_STORE_CLIENT_CONFIG, EnumCommunicationMethodType, EnumCommunicationPreferenceChannel, EnumCountryCode, EnumInputChannel, EnumLocale, EnumLookupUserType, EnumResource, EnumServiceProviderType, EnumTimezone, EnumUnitObjectType, EnumUnitType, EnumUserPermissionObjectType, EnumUserPermissionRole, EnumUserRelationType, EnumUtilisationPeriodType, createTokenStore, parameterStore, restClient };