@pryv/boiler 1.2.4 → 1.2.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pryv/boiler",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
4
4
  "private": false,
5
5
  "description": "Logging and config boilerplate library for Node.js apps and services at Pryv",
6
6
  "keywords": [
@@ -19,6 +19,7 @@
19
19
  "license": "BSD-3-Clause",
20
20
  "author": "Pryv S.A <info@pryv.com> (https://pryv.com)",
21
21
  "main": "src/index",
22
+ "types": "src/index.d.ts",
22
23
  "scripts": {
23
24
  "license": "source-licenser -c .licenser.yml .",
24
25
  "lint": "semistandard"
@@ -27,7 +28,6 @@
27
28
  "debug": "^4.3.4",
28
29
  "js-yaml": "^4.1.0",
29
30
  "nconf": "^0.12.0",
30
- "superagent": "^8.0.9",
31
31
  "winston": "^3.9.0",
32
32
  "winston-daily-rotate-file": "^4.7.1"
33
33
  },
package/src/config.js CHANGED
@@ -24,8 +24,6 @@ const path = require('path');
24
24
  const nconf = require('nconf');
25
25
  nconf.formats.yaml = require('./lib/nconf-yaml');
26
26
 
27
- const superagent = require('superagent');
28
-
29
27
  /**
30
28
  * Default values for Logger
31
29
  */
@@ -287,7 +285,7 @@ class Config {
287
285
  if (store.type === 'file') {
288
286
  res.info = 'From file: ' + store.file;
289
287
  } else {
290
- info = 'Type: ' + store.type;
288
+ res.info = 'Type: ' + store.type;
291
289
  }
292
290
  return res;
293
291
  }
@@ -333,8 +331,8 @@ const FILE_PROTOCOL = 'file://';
333
331
  const FILE_PROTOCOL_LENGTH = FILE_PROTOCOL.length;
334
332
 
335
333
  async function loadFromUrl (url) {
336
- const res = await superagent.get(url);
337
- return res.body;
334
+ const res = await fetch(url);
335
+ return res.json();
338
336
  }
339
337
 
340
338
  function loadFromFile (fileUrl, baseFilesDir) {
package/src/index.d.ts ADDED
@@ -0,0 +1,210 @@
1
+ /**
2
+ * @license
3
+ * [BSD-3-Clause](https://github.com/pryv/pryv-boiler/blob/master/LICENSE)
4
+ */
5
+
6
+ export = boiler;
7
+
8
+ declare const boiler: {
9
+ /**
10
+ * Get a Logger
11
+ * @param name - The name of the logger
12
+ */
13
+ getLogger: (name?: string) => boiler.Logger;
14
+
15
+ /**
16
+ * Preferred way to get the configuration.
17
+ * Waits until the configuration is fully initialized.
18
+ */
19
+ getConfig: () => Promise<boiler.Config>;
20
+
21
+ /**
22
+ * Get the configuration.
23
+ * If the configuration is not fully initialized, throws an error (or warns if warnOnly is true).
24
+ * @param warnOnly - Only warns about potential misuse of config instead of throwing
25
+ */
26
+ getConfigUnsafe: (warnOnly?: boolean) => boiler.Config;
27
+
28
+ /**
29
+ * Initialize Boiler. Should be called just once when starting an app.
30
+ * @param options - Initialization options
31
+ * @param fullyLoadedCallback - Called when the config is fully loaded
32
+ */
33
+ init: (options: boiler.InitOptions, fullyLoadedCallback?: (config: boiler.Config) => void) => typeof boiler;
34
+ };
35
+
36
+ declare namespace boiler {
37
+ interface InitOptions {
38
+ /** The name of the application, used by Logger and debug */
39
+ appName: string;
40
+ /** Directory to use to look for configs (default, env) */
41
+ baseConfigDir?: string;
42
+ /** Directory to use for `file://` relative paths */
43
+ baseFilesDir?: string;
44
+ /** Array of extra config sources to load */
45
+ extraConfigs?: Array<ConfigFile | ConfigPlugin | ConfigPluginAsync | ConfigData | ConfigRemoteURL | ConfigRemoteURLFromKey | ConfigFileAsync>;
46
+ }
47
+
48
+ interface ConfigFile {
49
+ /** Scope for nconf hierarchical load */
50
+ scope: string;
51
+ /** The config file path (.yml, .json, .js) */
52
+ file: string;
53
+ }
54
+
55
+ interface ConfigFileAsync {
56
+ /** Scope for nconf hierarchical load */
57
+ scope: string;
58
+ /** The async config file path (.js that exports an async function) */
59
+ fileAsync: string;
60
+ }
61
+
62
+ interface ConfigPlugin {
63
+ plugin: {
64
+ /** Function that takes the Config instance and returns the plugin name */
65
+ load: (config: Config) => string;
66
+ };
67
+ }
68
+
69
+ interface ConfigPluginAsync {
70
+ pluginAsync: {
71
+ /** Async function that takes the Config instance and returns the plugin name */
72
+ load: (config: Config) => Promise<string>;
73
+ };
74
+ }
75
+
76
+ interface ConfigData {
77
+ /** Scope for nconf hierarchical load */
78
+ scope: string;
79
+ /** Key to load data under. If null, loaded at root of the config */
80
+ key?: string;
81
+ /** The data to load */
82
+ data: object;
83
+ }
84
+
85
+ interface ConfigRemoteURL {
86
+ /** Scope for nconf hierarchical load */
87
+ scope: string;
88
+ /** Key to load result of URL under. If null, loaded at root of the config */
89
+ key?: string;
90
+ /** The URL to the config definition */
91
+ url: string;
92
+ }
93
+
94
+ interface ConfigRemoteURLFromKey {
95
+ /** Scope for nconf hierarchical load */
96
+ scope: string;
97
+ /** Key to load result of URL under. If null, override */
98
+ key?: string;
99
+ /** Retrieve URL from config matching this key */
100
+ urlFromKey: string;
101
+ }
102
+
103
+ interface ScopeAndValue {
104
+ value: unknown;
105
+ scope: string;
106
+ info: string;
107
+ }
108
+
109
+ class Config {
110
+ /** The nconf store instance */
111
+ store: unknown;
112
+ /** The logger instance for config */
113
+ logger: Logger;
114
+ /** Base directory for config files */
115
+ baseConfigDir: string;
116
+
117
+ /**
118
+ * Return true if key has a value
119
+ * @param key - The config key to check
120
+ */
121
+ has(key: string): boolean;
122
+
123
+ /**
124
+ * Retrieve value
125
+ * @param key - The config key. If no key is provided, all the config is returned
126
+ */
127
+ get(key?: string): unknown;
128
+ get<T>(key: string): T | undefined;
129
+
130
+ /**
131
+ * Retrieve value and store info that applies
132
+ * @param key - The config key
133
+ */
134
+ getScopeAndValue(key: string): ScopeAndValue | null;
135
+
136
+ /**
137
+ * Set value
138
+ * @param key - The config key
139
+ * @param value - The value to set
140
+ */
141
+ set(key: string, value: unknown): void;
142
+
143
+ /**
144
+ * Inject test config and override any other option
145
+ * @param configObject - The config object to inject for testing
146
+ */
147
+ injectTestConfig(configObject: object): void;
148
+
149
+ /**
150
+ * Replace a scope config set
151
+ * @param scope - The scope to replace
152
+ * @param configObject - The new config object for the scope
153
+ */
154
+ replaceScopeConfig(scope: string, configObject: object): void;
155
+ }
156
+
157
+ class Logger {
158
+ /** The name of this logger */
159
+ name: string;
160
+ /** The parent logger, if any */
161
+ parent: Logger | null;
162
+
163
+ /**
164
+ * Log a message at the specified level
165
+ * @param level - The log level
166
+ * @param message - The log message
167
+ * @param context - Additional context
168
+ */
169
+ log(level: string, message: string, ...context: unknown[]): void;
170
+
171
+ /**
172
+ * Log an info message
173
+ * @param message - The log message
174
+ * @param context - Additional context
175
+ */
176
+ info(message: string, ...context: unknown[]): void;
177
+
178
+ /**
179
+ * Log a warning message
180
+ * @param message - The log message
181
+ * @param context - Additional context
182
+ */
183
+ warn(message: string, ...context: unknown[]): void;
184
+
185
+ /**
186
+ * Log an error message
187
+ * @param message - The log message
188
+ * @param context - Additional context
189
+ */
190
+ error(message: string, ...context: unknown[]): void;
191
+
192
+ /**
193
+ * Log a debug message
194
+ * @param message - The log message
195
+ * @param context - Additional context
196
+ */
197
+ debug(message: string, ...context: unknown[]): void;
198
+
199
+ /**
200
+ * Get a "sub" Logger
201
+ * @param name - The name of the child logger
202
+ */
203
+ getLogger(name: string): Logger;
204
+
205
+ /**
206
+ * Dump objects with file and line for debugging
207
+ */
208
+ inspect(...args: unknown[]): void;
209
+ }
210
+ }