@faasjs/http 0.0.3-beta.38 → 0.0.3-beta.40

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 (3) hide show
  1. package/dist/index.js +15 -135
  2. package/dist/index.mjs +10 -126
  3. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -29,130 +29,7 @@ __export(src_exports, {
29
29
  useHttp: () => useHttp
30
30
  });
31
31
  module.exports = __toCommonJS(src_exports);
32
-
33
- // ../logger/src/index.ts
34
- var import_util = require("util");
35
- var LevelColor = ((LevelColor2) => {
36
- LevelColor2[LevelColor2["debug"] = 90 /* GRAY */] = "debug";
37
- LevelColor2[LevelColor2["info"] = 32 /* GREEN */] = "info";
38
- LevelColor2[LevelColor2["warn"] = 33 /* ORANGE */] = "warn";
39
- LevelColor2[LevelColor2["error"] = 31 /* RED */] = "error";
40
- return LevelColor2;
41
- })(LevelColor || {});
42
- var LevelPriority = {
43
- debug: 0,
44
- info: 1,
45
- warn: 2,
46
- error: 3
47
- };
48
- var Logger = class {
49
- constructor(label) {
50
- this.colorfyOutput = true;
51
- if (label)
52
- this.label = label;
53
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
54
- if (["remote", "mono"].includes(process.env.FaasMode))
55
- this.colorfyOutput = false;
56
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
57
- this.cachedTimers = {};
58
- this.size = 1e3;
59
- this.stdout = console.log;
60
- this.stderr = console.error;
61
- }
62
- debug(message, ...args) {
63
- this.log("debug", message, ...args);
64
- return this;
65
- }
66
- info(message, ...args) {
67
- this.log("info", message, ...args);
68
- return this;
69
- }
70
- warn(message, ...args) {
71
- this.log("warn", message, ...args);
72
- return this;
73
- }
74
- error(message, ...args) {
75
- let stack = false;
76
- [message].concat(Array.from(args)).forEach((e) => {
77
- if (e.stack) {
78
- stack = true;
79
- this.log("error", e.stack);
80
- }
81
- });
82
- if (!stack)
83
- this.log("error", message, ...args);
84
- return this;
85
- }
86
- time(key, level = "debug") {
87
- this.cachedTimers[key] = {
88
- level,
89
- time: new Date().getTime()
90
- };
91
- return this;
92
- }
93
- timeEnd(key, message, ...args) {
94
- if (this.cachedTimers[key]) {
95
- const timer = this.cachedTimers[key];
96
- message = message + " +%ims";
97
- args.push(new Date().getTime() - timer.time);
98
- this[timer.level](message, ...args);
99
- delete this.cachedTimers[key];
100
- } else {
101
- this.warn("timeEnd not found key %s", key);
102
- this.debug(message);
103
- }
104
- return this;
105
- }
106
- raw(message, ...args) {
107
- if (this.silent)
108
- return this;
109
- this.stdout((0, import_util.format)(message, ...args));
110
- return this;
111
- }
112
- colorfy(color, message) {
113
- return `\x1B[0${color}m${message}\x1B[39m`;
114
- }
115
- log(level, message, ...args) {
116
- if (this.silent)
117
- return this;
118
- if (LevelPriority[level] < this.level)
119
- return this;
120
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + (0, import_util.format)(message, ...args);
121
- if (this.colorfyOutput && level !== "error")
122
- output = this.colorfy(LevelColor[level], output);
123
- else if (!this.colorfyOutput)
124
- output = output.replace(/\n/g, "");
125
- if (!output)
126
- return this;
127
- if (output.length > this.size && !["error", "warn"].includes(level))
128
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
129
- if (level === "error")
130
- this.stderr(output);
131
- else
132
- this.stdout(output);
133
- return this;
134
- }
135
- };
136
-
137
- // ../func/src/index.ts
138
- var import_crypto = require("crypto");
139
- var plugins = [];
140
- function usePlugin(plugin) {
141
- if (!plugins.find((p) => p.name === plugin.name))
142
- plugins.push(plugin);
143
- if (!plugin.mount)
144
- plugin.mount = async function(data) {
145
- if (plugin.onMount)
146
- await plugin.onMount({
147
- config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
148
- event: /* @__PURE__ */ Object.create(null),
149
- context: /* @__PURE__ */ Object.create(null),
150
- logger: new Logger(plugin.name)
151
- }, async () => Promise.resolve());
152
- return plugin;
153
- };
154
- return plugin;
155
- }
32
+ var import_func = require("@faasjs/func");
156
33
 
157
34
  // ../deep_merge/src/index.ts
158
35
  var shouldMerge = function(item) {
@@ -181,8 +58,11 @@ function deepMerge(...sources) {
181
58
  return acc;
182
59
  }
183
60
 
61
+ // src/index.ts
62
+ var import_logger = require("@faasjs/logger");
63
+
184
64
  // src/session.ts
185
- var import_crypto2 = require("crypto");
65
+ var import_crypto = require("crypto");
186
66
  var Session = class {
187
67
  constructor(cookie, config) {
188
68
  this.cookie = cookie;
@@ -190,7 +70,7 @@ var Session = class {
190
70
  console.warn("Session's secret is missing.");
191
71
  this.config = Object.assign({
192
72
  key: "key",
193
- secret: (0, import_crypto2.randomBytes)(128).toString("hex"),
73
+ secret: (0, import_crypto.randomBytes)(128).toString("hex"),
194
74
  salt: "salt",
195
75
  signedSalt: "signedSalt",
196
76
  keylen: 64,
@@ -198,14 +78,14 @@ var Session = class {
198
78
  digest: "sha256",
199
79
  cipherName: "aes-256-cbc"
200
80
  }, config);
201
- this.secret = (0, import_crypto2.pbkdf2Sync)(
81
+ this.secret = (0, import_crypto.pbkdf2Sync)(
202
82
  this.config.secret,
203
83
  this.config.salt,
204
84
  this.config.iterations,
205
85
  this.config.keylen / 2,
206
86
  this.config.digest
207
87
  );
208
- this.signedSecret = (0, import_crypto2.pbkdf2Sync)(
88
+ this.signedSecret = (0, import_crypto.pbkdf2Sync)(
209
89
  this.config.secret,
210
90
  this.config.signedSalt,
211
91
  this.config.iterations,
@@ -226,11 +106,11 @@ var Session = class {
226
106
  encode(text) {
227
107
  if (typeof text !== "string")
228
108
  text = JSON.stringify(text);
229
- const iv = (0, import_crypto2.randomBytes)(16);
230
- const cipher = (0, import_crypto2.createCipheriv)(this.config.cipherName, this.secret, iv);
109
+ const iv = (0, import_crypto.randomBytes)(16);
110
+ const cipher = (0, import_crypto.createCipheriv)(this.config.cipherName, this.secret, iv);
231
111
  const encrypted = Buffer.concat([cipher.update(text), cipher.final()]).toString("base64");
232
112
  const main = Buffer.from([encrypted, iv.toString("base64")].join("--")).toString("base64");
233
- const hmac = (0, import_crypto2.createHmac)(this.config.digest, this.signedSecret);
113
+ const hmac = (0, import_crypto.createHmac)(this.config.digest, this.signedSecret);
234
114
  hmac.update(main);
235
115
  const digest = hmac.digest("hex");
236
116
  return main + "--" + digest;
@@ -238,7 +118,7 @@ var Session = class {
238
118
  decode(text) {
239
119
  text = decodeURIComponent(text);
240
120
  const signedParts = text.split("--");
241
- const hmac = (0, import_crypto2.createHmac)(this.config.digest, this.signedSecret);
121
+ const hmac = (0, import_crypto.createHmac)(this.config.digest, this.signedSecret);
242
122
  hmac.update(signedParts[0]);
243
123
  const digest = hmac.digest("hex");
244
124
  if (signedParts[1] !== digest)
@@ -247,7 +127,7 @@ var Session = class {
247
127
  const parts = message.split("--").map(function(part2) {
248
128
  return Buffer.from(part2, "base64");
249
129
  });
250
- const cipher = (0, import_crypto2.createDecipheriv)(this.config.cipherName, this.secret, parts[1]);
130
+ const cipher = (0, import_crypto.createDecipheriv)(this.config.cipherName, this.secret, parts[1]);
251
131
  const part = Buffer.from(cipher.update(parts[0])).toString("utf8");
252
132
  const final = cipher.final("utf8");
253
133
  const decrypt = [part, final].join("");
@@ -557,7 +437,7 @@ var Http = class {
557
437
  var _a;
558
438
  data.dependencies["@faasjs/http"] = "*";
559
439
  await next();
560
- const logger = new Logger(this.name);
440
+ const logger = new import_logger.Logger(this.name);
561
441
  logger.debug("Generate api gateway's config");
562
442
  logger.debug("%j", data);
563
443
  const config = data.config.plugins ? deepMerge(data.config.plugins[this.name || this.type], { config: this.config }) : { config: this.config };
@@ -711,7 +591,7 @@ var Http = class {
711
591
  }
712
592
  };
713
593
  function useHttp(config) {
714
- return usePlugin(new Http(config));
594
+ return (0, import_func.usePlugin)(new Http(config));
715
595
  }
716
596
  // Annotate the CommonJS export names for ESM import in node:
717
597
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -6,129 +6,10 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  throw new Error('Dynamic require of "' + x + '" is not supported');
7
7
  });
8
8
 
9
- // ../logger/src/index.ts
10
- import { format } from "util";
11
- var LevelColor = ((LevelColor2) => {
12
- LevelColor2[LevelColor2["debug"] = 90 /* GRAY */] = "debug";
13
- LevelColor2[LevelColor2["info"] = 32 /* GREEN */] = "info";
14
- LevelColor2[LevelColor2["warn"] = 33 /* ORANGE */] = "warn";
15
- LevelColor2[LevelColor2["error"] = 31 /* RED */] = "error";
16
- return LevelColor2;
17
- })(LevelColor || {});
18
- var LevelPriority = {
19
- debug: 0,
20
- info: 1,
21
- warn: 2,
22
- error: 3
23
- };
24
- var Logger = class {
25
- constructor(label) {
26
- this.colorfyOutput = true;
27
- if (label)
28
- this.label = label;
29
- this.silent = !process.env.FaasLog && process.env.npm_config_argv && JSON.parse(process.env.npm_config_argv).original.includes("--silent");
30
- if (["remote", "mono"].includes(process.env.FaasMode))
31
- this.colorfyOutput = false;
32
- this.level = process.env.FaasLog ? LevelPriority[process.env.FaasLog.toLowerCase()] : 0;
33
- this.cachedTimers = {};
34
- this.size = 1e3;
35
- this.stdout = console.log;
36
- this.stderr = console.error;
37
- }
38
- debug(message, ...args) {
39
- this.log("debug", message, ...args);
40
- return this;
41
- }
42
- info(message, ...args) {
43
- this.log("info", message, ...args);
44
- return this;
45
- }
46
- warn(message, ...args) {
47
- this.log("warn", message, ...args);
48
- return this;
49
- }
50
- error(message, ...args) {
51
- let stack = false;
52
- [message].concat(Array.from(args)).forEach((e) => {
53
- if (e.stack) {
54
- stack = true;
55
- this.log("error", e.stack);
56
- }
57
- });
58
- if (!stack)
59
- this.log("error", message, ...args);
60
- return this;
61
- }
62
- time(key, level = "debug") {
63
- this.cachedTimers[key] = {
64
- level,
65
- time: new Date().getTime()
66
- };
67
- return this;
68
- }
69
- timeEnd(key, message, ...args) {
70
- if (this.cachedTimers[key]) {
71
- const timer = this.cachedTimers[key];
72
- message = message + " +%ims";
73
- args.push(new Date().getTime() - timer.time);
74
- this[timer.level](message, ...args);
75
- delete this.cachedTimers[key];
76
- } else {
77
- this.warn("timeEnd not found key %s", key);
78
- this.debug(message);
79
- }
80
- return this;
81
- }
82
- raw(message, ...args) {
83
- if (this.silent)
84
- return this;
85
- this.stdout(format(message, ...args));
86
- return this;
87
- }
88
- colorfy(color, message) {
89
- return `\x1B[0${color}m${message}\x1B[39m`;
90
- }
91
- log(level, message, ...args) {
92
- if (this.silent)
93
- return this;
94
- if (LevelPriority[level] < this.level)
95
- return this;
96
- let output = level.toUpperCase() + " " + (this.label ? `[${this.label}] ` : "") + format(message, ...args);
97
- if (this.colorfyOutput && level !== "error")
98
- output = this.colorfy(LevelColor[level], output);
99
- else if (!this.colorfyOutput)
100
- output = output.replace(/\n/g, "");
101
- if (!output)
102
- return this;
103
- if (output.length > this.size && !["error", "warn"].includes(level))
104
- output = output.slice(0, this.size - 100) + "..." + output.slice(output.length - 100);
105
- if (level === "error")
106
- this.stderr(output);
107
- else
108
- this.stdout(output);
109
- return this;
110
- }
111
- };
112
-
113
- // ../func/src/index.ts
114
- import { randomBytes } from "crypto";
115
- var plugins = [];
116
- function usePlugin(plugin) {
117
- if (!plugins.find((p) => p.name === plugin.name))
118
- plugins.push(plugin);
119
- if (!plugin.mount)
120
- plugin.mount = async function(data) {
121
- if (plugin.onMount)
122
- await plugin.onMount({
123
- config: (data == null ? void 0 : data.config) || /* @__PURE__ */ Object.create(null),
124
- event: /* @__PURE__ */ Object.create(null),
125
- context: /* @__PURE__ */ Object.create(null),
126
- logger: new Logger(plugin.name)
127
- }, async () => Promise.resolve());
128
- return plugin;
129
- };
130
- return plugin;
131
- }
9
+ // src/index.ts
10
+ import {
11
+ usePlugin
12
+ } from "@faasjs/func";
132
13
 
133
14
  // ../deep_merge/src/index.ts
134
15
  var shouldMerge = function(item) {
@@ -157,9 +38,12 @@ function deepMerge(...sources) {
157
38
  return acc;
158
39
  }
159
40
 
41
+ // src/index.ts
42
+ import { Logger } from "@faasjs/logger";
43
+
160
44
  // src/session.ts
161
45
  import {
162
- randomBytes as randomBytes2,
46
+ randomBytes,
163
47
  pbkdf2Sync,
164
48
  createCipheriv,
165
49
  createHmac,
@@ -172,7 +56,7 @@ var Session = class {
172
56
  console.warn("Session's secret is missing.");
173
57
  this.config = Object.assign({
174
58
  key: "key",
175
- secret: randomBytes2(128).toString("hex"),
59
+ secret: randomBytes(128).toString("hex"),
176
60
  salt: "salt",
177
61
  signedSalt: "signedSalt",
178
62
  keylen: 64,
@@ -208,7 +92,7 @@ var Session = class {
208
92
  encode(text) {
209
93
  if (typeof text !== "string")
210
94
  text = JSON.stringify(text);
211
- const iv = randomBytes2(16);
95
+ const iv = randomBytes(16);
212
96
  const cipher = createCipheriv(this.config.cipherName, this.secret, iv);
213
97
  const encrypted = Buffer.concat([cipher.update(text), cipher.final()]).toString("base64");
214
98
  const main = Buffer.from([encrypted, iv.toString("base64")].join("--")).toString("base64");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@faasjs/http",
3
- "version": "0.0.3-beta.38",
3
+ "version": "0.0.3-beta.40",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,8 +23,8 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "@faasjs/func": "^0.0.3-beta.38",
27
- "@faasjs/logger": "^0.0.3-beta.38"
26
+ "@faasjs/func": "^0.0.3-beta.40",
27
+ "@faasjs/logger": "^0.0.3-beta.40"
28
28
  },
29
29
  "engines": {
30
30
  "npm": ">=8.0.0",