@faasjs/http 0.0.2-beta.453 → 0.0.2-beta.454

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 -134
  2. package/dist/index.mjs +10 -125
  3. package/package.json +3 -7
package/dist/index.js CHANGED
@@ -29,129 +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 = 500;
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)
128
- output = output.slice(0, this.size) + "...";
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({ config }) {
145
- if (plugin.onMount)
146
- await plugin.onMount({
147
- config,
148
- event: {},
149
- context: {},
150
- logger: new Logger(plugin.name)
151
- }, async () => Promise.resolve());
152
- };
153
- return plugin;
154
- }
32
+ var import_func = require("@faasjs/func");
155
33
 
156
34
  // ../deep_merge/src/index.ts
157
35
  var shouldMerge = function(item) {
@@ -180,14 +58,17 @@ function deepMerge(...sources) {
180
58
  return acc;
181
59
  }
182
60
 
61
+ // src/index.ts
62
+ var import_logger = require("@faasjs/logger");
63
+
183
64
  // src/session.ts
184
- var import_crypto2 = require("crypto");
65
+ var import_crypto = require("crypto");
185
66
  var Session = class {
186
67
  constructor(cookie, config) {
187
68
  this.cookie = cookie;
188
69
  this.config = Object.assign({
189
70
  key: "key",
190
- secret: (0, import_crypto2.randomBytes)(128).toString("hex"),
71
+ secret: (0, import_crypto.randomBytes)(128).toString("hex"),
191
72
  salt: "salt",
192
73
  signedSalt: "signedSalt",
193
74
  keylen: 64,
@@ -195,14 +76,14 @@ var Session = class {
195
76
  digest: "sha256",
196
77
  cipherName: "aes-256-cbc"
197
78
  }, config);
198
- this.secret = (0, import_crypto2.pbkdf2Sync)(
79
+ this.secret = (0, import_crypto.pbkdf2Sync)(
199
80
  this.config.secret,
200
81
  this.config.salt,
201
82
  this.config.iterations,
202
83
  this.config.keylen / 2,
203
84
  this.config.digest
204
85
  );
205
- this.signedSecret = (0, import_crypto2.pbkdf2Sync)(
86
+ this.signedSecret = (0, import_crypto.pbkdf2Sync)(
206
87
  this.config.secret,
207
88
  this.config.signedSalt,
208
89
  this.config.iterations,
@@ -223,11 +104,11 @@ var Session = class {
223
104
  encode(text) {
224
105
  if (typeof text !== "string")
225
106
  text = JSON.stringify(text);
226
- const iv = (0, import_crypto2.randomBytes)(16);
227
- const cipher = (0, import_crypto2.createCipheriv)(this.config.cipherName, this.secret, iv);
107
+ const iv = (0, import_crypto.randomBytes)(16);
108
+ const cipher = (0, import_crypto.createCipheriv)(this.config.cipherName, this.secret, iv);
228
109
  const encrypted = Buffer.concat([cipher.update(text), cipher.final()]).toString("base64");
229
110
  const main = Buffer.from([encrypted, iv.toString("base64")].join("--")).toString("base64");
230
- const hmac = (0, import_crypto2.createHmac)(this.config.digest, this.signedSecret);
111
+ const hmac = (0, import_crypto.createHmac)(this.config.digest, this.signedSecret);
231
112
  hmac.update(main);
232
113
  const digest = hmac.digest("hex");
233
114
  return main + "--" + digest;
@@ -235,7 +116,7 @@ var Session = class {
235
116
  decode(text) {
236
117
  text = decodeURIComponent(text);
237
118
  const signedParts = text.split("--");
238
- const hmac = (0, import_crypto2.createHmac)(this.config.digest, this.signedSecret);
119
+ const hmac = (0, import_crypto.createHmac)(this.config.digest, this.signedSecret);
239
120
  hmac.update(signedParts[0]);
240
121
  const digest = hmac.digest("hex");
241
122
  if (signedParts[1] !== digest)
@@ -244,7 +125,7 @@ var Session = class {
244
125
  const parts = message.split("--").map(function(part2) {
245
126
  return Buffer.from(part2, "base64");
246
127
  });
247
- const cipher = (0, import_crypto2.createDecipheriv)(this.config.cipherName, this.secret, parts[1]);
128
+ const cipher = (0, import_crypto.createDecipheriv)(this.config.cipherName, this.secret, parts[1]);
248
129
  const part = Buffer.from(cipher.update(parts[0])).toString("utf8");
249
130
  const final = cipher.final("utf8");
250
131
  const decrypt = [part, final].join("");
@@ -557,7 +438,7 @@ var Http = class {
557
438
  var _a;
558
439
  data.dependencies["@faasjs/http"] = "*";
559
440
  await next();
560
- const logger = new Logger(this.name);
441
+ const logger = new import_logger.Logger(this.name);
561
442
  logger.debug("Generate api gateway's config");
562
443
  logger.debug("%j", data);
563
444
  const config = data.config.plugins ? deepMerge(data.config.plugins[this.name || this.type], { config: this.config }) : { config: this.config };
@@ -694,7 +575,7 @@ var Http = class {
694
575
  }
695
576
  };
696
577
  function useHttp(config) {
697
- return usePlugin(new Http(config));
578
+ return (0, import_func.usePlugin)(new Http(config));
698
579
  }
699
580
  // Annotate the CommonJS export names for ESM import in node:
700
581
  0 && (module.exports = {
package/dist/index.mjs CHANGED
@@ -6,128 +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 = 500;
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)
104
- output = output.slice(0, this.size) + "...";
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({ config }) {
121
- if (plugin.onMount)
122
- await plugin.onMount({
123
- config,
124
- event: {},
125
- context: {},
126
- logger: new Logger(plugin.name)
127
- }, async () => Promise.resolve());
128
- };
129
- return plugin;
130
- }
9
+ // src/index.ts
10
+ import {
11
+ usePlugin
12
+ } from "@faasjs/func";
131
13
 
132
14
  // ../deep_merge/src/index.ts
133
15
  var shouldMerge = function(item) {
@@ -156,9 +38,12 @@ function deepMerge(...sources) {
156
38
  return acc;
157
39
  }
158
40
 
41
+ // src/index.ts
42
+ import { Logger } from "@faasjs/logger";
43
+
159
44
  // src/session.ts
160
45
  import {
161
- randomBytes as randomBytes2,
46
+ randomBytes,
162
47
  pbkdf2Sync,
163
48
  createCipheriv,
164
49
  createHmac,
@@ -169,7 +54,7 @@ var Session = class {
169
54
  this.cookie = cookie;
170
55
  this.config = Object.assign({
171
56
  key: "key",
172
- secret: randomBytes2(128).toString("hex"),
57
+ secret: randomBytes(128).toString("hex"),
173
58
  salt: "salt",
174
59
  signedSalt: "signedSalt",
175
60
  keylen: 64,
@@ -205,7 +90,7 @@ var Session = class {
205
90
  encode(text) {
206
91
  if (typeof text !== "string")
207
92
  text = JSON.stringify(text);
208
- const iv = randomBytes2(16);
93
+ const iv = randomBytes(16);
209
94
  const cipher = createCipheriv(this.config.cipherName, this.secret, iv);
210
95
  const encrypted = Buffer.concat([cipher.update(text), cipher.final()]).toString("base64");
211
96
  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.2-beta.453",
3
+ "version": "0.0.2-beta.454",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,12 +23,8 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "@faasjs/func": "^0.0.2-beta.453",
27
- "@faasjs/logger": "^0.0.2-beta.453"
28
- },
29
- "devDependencies": {
30
- "tsup": "*",
31
- "typescript": "*"
26
+ "@faasjs/func": "^0.0.2-beta.454",
27
+ "@faasjs/logger": "^0.0.2-beta.454"
32
28
  },
33
29
  "engines": {
34
30
  "npm": ">=8.0.0",