dauth-md-node 0.1.0
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/LICENSE +21 -0
- package/README.md +103 -0
- package/dist/dauth-md-node.cjs.development.js +393 -0
- package/dist/dauth-md-node.cjs.development.js.map +1 -0
- package/dist/dauth-md-node.cjs.production.min.js +2 -0
- package/dist/dauth-md-node.cjs.production.min.js.map +1 -0
- package/dist/dauth-md-node.esm.js +389 -0
- package/dist/dauth-md-node.esm.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +8 -0
- package/package.json +61 -0
- package/src/index.ts +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 David T. Pizarro Frick
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# TSDX User Guide
|
|
2
|
+
|
|
3
|
+
Congrats! You just saved yourself hours of work by bootstrapping this project with TSDX. Let’s get you oriented with what’s here and how to use it.
|
|
4
|
+
|
|
5
|
+
> This TSDX setup is meant for developing libraries (not apps!) that can be published to NPM. If you’re looking to build a Node app, you could use `ts-node-dev`, plain `ts-node`, or simple `tsc`.
|
|
6
|
+
|
|
7
|
+
> If you’re new to TypeScript, checkout [this handy cheatsheet](https://devhints.io/typescript)
|
|
8
|
+
|
|
9
|
+
## Commands
|
|
10
|
+
|
|
11
|
+
TSDX scaffolds your new library inside `/src`.
|
|
12
|
+
|
|
13
|
+
To run TSDX, use:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm start # or yarn start
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
This builds to `/dist` and runs the project in watch mode so any edits you save inside `src` causes a rebuild to `/dist`.
|
|
20
|
+
|
|
21
|
+
To do a one-off build, use `npm run build` or `yarn build`.
|
|
22
|
+
|
|
23
|
+
To run tests, use `npm test` or `yarn test`.
|
|
24
|
+
|
|
25
|
+
## Configuration
|
|
26
|
+
|
|
27
|
+
Code quality is set up for you with `prettier`, `husky`, and `lint-staged`. Adjust the respective fields in `package.json` accordingly.
|
|
28
|
+
|
|
29
|
+
### Jest
|
|
30
|
+
|
|
31
|
+
Jest tests are set up to run with `npm test` or `yarn test`.
|
|
32
|
+
|
|
33
|
+
### Bundle Analysis
|
|
34
|
+
|
|
35
|
+
[`size-limit`](https://github.com/ai/size-limit) is set up to calculate the real cost of your library with `npm run size` and visualize the bundle with `npm run analyze`.
|
|
36
|
+
|
|
37
|
+
#### Setup Files
|
|
38
|
+
|
|
39
|
+
This is the folder structure we set up for you:
|
|
40
|
+
|
|
41
|
+
```txt
|
|
42
|
+
/src
|
|
43
|
+
index.tsx # EDIT THIS
|
|
44
|
+
/test
|
|
45
|
+
blah.test.tsx # EDIT THIS
|
|
46
|
+
.gitignore
|
|
47
|
+
package.json
|
|
48
|
+
README.md # EDIT THIS
|
|
49
|
+
tsconfig.json
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Rollup
|
|
53
|
+
|
|
54
|
+
TSDX uses [Rollup](https://rollupjs.org) as a bundler and generates multiple rollup configs for various module formats and build settings. See [Optimizations](#optimizations) for details.
|
|
55
|
+
|
|
56
|
+
### TypeScript
|
|
57
|
+
|
|
58
|
+
`tsconfig.json` is set up to interpret `dom` and `esnext` types, as well as `react` for `jsx`. Adjust according to your needs.
|
|
59
|
+
|
|
60
|
+
## Continuous Integration
|
|
61
|
+
|
|
62
|
+
### GitHub Actions
|
|
63
|
+
|
|
64
|
+
Two actions are added by default:
|
|
65
|
+
|
|
66
|
+
- `main` which installs deps w/ cache, lints, tests, and builds on all pushes against a Node and OS matrix
|
|
67
|
+
- `size` which comments cost comparison of your library on every pull request using [`size-limit`](https://github.com/ai/size-limit)
|
|
68
|
+
|
|
69
|
+
## Optimizations
|
|
70
|
+
|
|
71
|
+
Please see the main `tsdx` [optimizations docs](https://github.com/palmerhq/tsdx#optimizations). In particular, know that you can take advantage of development-only optimizations:
|
|
72
|
+
|
|
73
|
+
```js
|
|
74
|
+
// ./types/index.d.ts
|
|
75
|
+
declare var __DEV__: boolean;
|
|
76
|
+
|
|
77
|
+
// inside your code...
|
|
78
|
+
if (__DEV__) {
|
|
79
|
+
console.log('foo');
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
You can also choose to install and use [invariant](https://github.com/palmerhq/tsdx#invariant) and [warning](https://github.com/palmerhq/tsdx#warning) functions.
|
|
84
|
+
|
|
85
|
+
## Module Formats
|
|
86
|
+
|
|
87
|
+
CJS, ESModules, and UMD module formats are supported.
|
|
88
|
+
|
|
89
|
+
The appropriate paths are configured in `package.json` and `dist/index.js` accordingly. Please report if any issues are found.
|
|
90
|
+
|
|
91
|
+
## Named Exports
|
|
92
|
+
|
|
93
|
+
Per Palmer Group guidelines, [always use named exports.](https://github.com/palmerhq/typescript#exports) Code split inside your React app instead of your React library.
|
|
94
|
+
|
|
95
|
+
## Including Styles
|
|
96
|
+
|
|
97
|
+
There are many ways to ship styles, including with CSS-in-JS. TSDX has no opinion on this, configure how you like.
|
|
98
|
+
|
|
99
|
+
For vanilla CSS, you can include it at the root directory and add it to the `files` section in your `package.json`, so that it can be imported separately by your users and run through their bundler's loader.
|
|
100
|
+
|
|
101
|
+
## Publishing to NPM
|
|
102
|
+
|
|
103
|
+
We recommend using [np](https://github.com/sindresorhus/np).
|
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
4
|
+
|
|
5
|
+
var jwt = _interopDefault(require('jsonwebtoken'));
|
|
6
|
+
|
|
7
|
+
function _regeneratorRuntime() {
|
|
8
|
+
_regeneratorRuntime = function () {
|
|
9
|
+
return e;
|
|
10
|
+
};
|
|
11
|
+
var t,
|
|
12
|
+
e = {},
|
|
13
|
+
r = Object.prototype,
|
|
14
|
+
n = r.hasOwnProperty,
|
|
15
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
16
|
+
t[e] = r.value;
|
|
17
|
+
},
|
|
18
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
19
|
+
a = i.iterator || "@@iterator",
|
|
20
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
21
|
+
u = i.toStringTag || "@@toStringTag";
|
|
22
|
+
function define(t, e, r) {
|
|
23
|
+
return Object.defineProperty(t, e, {
|
|
24
|
+
value: r,
|
|
25
|
+
enumerable: !0,
|
|
26
|
+
configurable: !0,
|
|
27
|
+
writable: !0
|
|
28
|
+
}), t[e];
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
define({}, "");
|
|
32
|
+
} catch (t) {
|
|
33
|
+
define = function (t, e, r) {
|
|
34
|
+
return t[e] = r;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function wrap(t, e, r, n) {
|
|
38
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
39
|
+
a = Object.create(i.prototype),
|
|
40
|
+
c = new Context(n || []);
|
|
41
|
+
return o(a, "_invoke", {
|
|
42
|
+
value: makeInvokeMethod(t, r, c)
|
|
43
|
+
}), a;
|
|
44
|
+
}
|
|
45
|
+
function tryCatch(t, e, r) {
|
|
46
|
+
try {
|
|
47
|
+
return {
|
|
48
|
+
type: "normal",
|
|
49
|
+
arg: t.call(e, r)
|
|
50
|
+
};
|
|
51
|
+
} catch (t) {
|
|
52
|
+
return {
|
|
53
|
+
type: "throw",
|
|
54
|
+
arg: t
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
e.wrap = wrap;
|
|
59
|
+
var h = "suspendedStart",
|
|
60
|
+
l = "suspendedYield",
|
|
61
|
+
f = "executing",
|
|
62
|
+
s = "completed",
|
|
63
|
+
y = {};
|
|
64
|
+
function Generator() {}
|
|
65
|
+
function GeneratorFunction() {}
|
|
66
|
+
function GeneratorFunctionPrototype() {}
|
|
67
|
+
var p = {};
|
|
68
|
+
define(p, a, function () {
|
|
69
|
+
return this;
|
|
70
|
+
});
|
|
71
|
+
var d = Object.getPrototypeOf,
|
|
72
|
+
v = d && d(d(values([])));
|
|
73
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
74
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
75
|
+
function defineIteratorMethods(t) {
|
|
76
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
77
|
+
define(t, e, function (t) {
|
|
78
|
+
return this._invoke(e, t);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function AsyncIterator(t, e) {
|
|
83
|
+
function invoke(r, o, i, a) {
|
|
84
|
+
var c = tryCatch(t[r], t, o);
|
|
85
|
+
if ("throw" !== c.type) {
|
|
86
|
+
var u = c.arg,
|
|
87
|
+
h = u.value;
|
|
88
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
89
|
+
invoke("next", t, i, a);
|
|
90
|
+
}, function (t) {
|
|
91
|
+
invoke("throw", t, i, a);
|
|
92
|
+
}) : e.resolve(h).then(function (t) {
|
|
93
|
+
u.value = t, i(u);
|
|
94
|
+
}, function (t) {
|
|
95
|
+
return invoke("throw", t, i, a);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
a(c.arg);
|
|
99
|
+
}
|
|
100
|
+
var r;
|
|
101
|
+
o(this, "_invoke", {
|
|
102
|
+
value: function (t, n) {
|
|
103
|
+
function callInvokeWithMethodAndArg() {
|
|
104
|
+
return new e(function (e, r) {
|
|
105
|
+
invoke(t, n, e, r);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function makeInvokeMethod(e, r, n) {
|
|
113
|
+
var o = h;
|
|
114
|
+
return function (i, a) {
|
|
115
|
+
if (o === f) throw new Error("Generator is already running");
|
|
116
|
+
if (o === s) {
|
|
117
|
+
if ("throw" === i) throw a;
|
|
118
|
+
return {
|
|
119
|
+
value: t,
|
|
120
|
+
done: !0
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
for (n.method = i, n.arg = a;;) {
|
|
124
|
+
var c = n.delegate;
|
|
125
|
+
if (c) {
|
|
126
|
+
var u = maybeInvokeDelegate(c, n);
|
|
127
|
+
if (u) {
|
|
128
|
+
if (u === y) continue;
|
|
129
|
+
return u;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
133
|
+
if (o === h) throw o = s, n.arg;
|
|
134
|
+
n.dispatchException(n.arg);
|
|
135
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
136
|
+
o = f;
|
|
137
|
+
var p = tryCatch(e, r, n);
|
|
138
|
+
if ("normal" === p.type) {
|
|
139
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
140
|
+
return {
|
|
141
|
+
value: p.arg,
|
|
142
|
+
done: n.done
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function maybeInvokeDelegate(e, r) {
|
|
150
|
+
var n = r.method,
|
|
151
|
+
o = e.iterator[n];
|
|
152
|
+
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
153
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
154
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
155
|
+
var a = i.arg;
|
|
156
|
+
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
157
|
+
}
|
|
158
|
+
function pushTryEntry(t) {
|
|
159
|
+
var e = {
|
|
160
|
+
tryLoc: t[0]
|
|
161
|
+
};
|
|
162
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
163
|
+
}
|
|
164
|
+
function resetTryEntry(t) {
|
|
165
|
+
var e = t.completion || {};
|
|
166
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
167
|
+
}
|
|
168
|
+
function Context(t) {
|
|
169
|
+
this.tryEntries = [{
|
|
170
|
+
tryLoc: "root"
|
|
171
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
172
|
+
}
|
|
173
|
+
function values(e) {
|
|
174
|
+
if (e || "" === e) {
|
|
175
|
+
var r = e[a];
|
|
176
|
+
if (r) return r.call(e);
|
|
177
|
+
if ("function" == typeof e.next) return e;
|
|
178
|
+
if (!isNaN(e.length)) {
|
|
179
|
+
var o = -1,
|
|
180
|
+
i = function next() {
|
|
181
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
182
|
+
return next.value = t, next.done = !0, next;
|
|
183
|
+
};
|
|
184
|
+
return i.next = i;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
188
|
+
}
|
|
189
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
190
|
+
value: GeneratorFunctionPrototype,
|
|
191
|
+
configurable: !0
|
|
192
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
193
|
+
value: GeneratorFunction,
|
|
194
|
+
configurable: !0
|
|
195
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
196
|
+
var e = "function" == typeof t && t.constructor;
|
|
197
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
198
|
+
}, e.mark = function (t) {
|
|
199
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
200
|
+
}, e.awrap = function (t) {
|
|
201
|
+
return {
|
|
202
|
+
__await: t
|
|
203
|
+
};
|
|
204
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
205
|
+
return this;
|
|
206
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
207
|
+
void 0 === i && (i = Promise);
|
|
208
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
209
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
210
|
+
return t.done ? t.value : a.next();
|
|
211
|
+
});
|
|
212
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
213
|
+
return this;
|
|
214
|
+
}), define(g, "toString", function () {
|
|
215
|
+
return "[object Generator]";
|
|
216
|
+
}), e.keys = function (t) {
|
|
217
|
+
var e = Object(t),
|
|
218
|
+
r = [];
|
|
219
|
+
for (var n in e) r.push(n);
|
|
220
|
+
return r.reverse(), function next() {
|
|
221
|
+
for (; r.length;) {
|
|
222
|
+
var t = r.pop();
|
|
223
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
224
|
+
}
|
|
225
|
+
return next.done = !0, next;
|
|
226
|
+
};
|
|
227
|
+
}, e.values = values, Context.prototype = {
|
|
228
|
+
constructor: Context,
|
|
229
|
+
reset: function (e) {
|
|
230
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
231
|
+
},
|
|
232
|
+
stop: function () {
|
|
233
|
+
this.done = !0;
|
|
234
|
+
var t = this.tryEntries[0].completion;
|
|
235
|
+
if ("throw" === t.type) throw t.arg;
|
|
236
|
+
return this.rval;
|
|
237
|
+
},
|
|
238
|
+
dispatchException: function (e) {
|
|
239
|
+
if (this.done) throw e;
|
|
240
|
+
var r = this;
|
|
241
|
+
function handle(n, o) {
|
|
242
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
243
|
+
}
|
|
244
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
245
|
+
var i = this.tryEntries[o],
|
|
246
|
+
a = i.completion;
|
|
247
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
248
|
+
if (i.tryLoc <= this.prev) {
|
|
249
|
+
var c = n.call(i, "catchLoc"),
|
|
250
|
+
u = n.call(i, "finallyLoc");
|
|
251
|
+
if (c && u) {
|
|
252
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
253
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
254
|
+
} else if (c) {
|
|
255
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
256
|
+
} else {
|
|
257
|
+
if (!u) throw new Error("try statement without catch or finally");
|
|
258
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
abrupt: function (t, e) {
|
|
264
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
265
|
+
var o = this.tryEntries[r];
|
|
266
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
267
|
+
var i = o;
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
272
|
+
var a = i ? i.completion : {};
|
|
273
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
274
|
+
},
|
|
275
|
+
complete: function (t, e) {
|
|
276
|
+
if ("throw" === t.type) throw t.arg;
|
|
277
|
+
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
278
|
+
},
|
|
279
|
+
finish: function (t) {
|
|
280
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
281
|
+
var r = this.tryEntries[e];
|
|
282
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
283
|
+
}
|
|
284
|
+
},
|
|
285
|
+
catch: function (t) {
|
|
286
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
287
|
+
var r = this.tryEntries[e];
|
|
288
|
+
if (r.tryLoc === t) {
|
|
289
|
+
var n = r.completion;
|
|
290
|
+
if ("throw" === n.type) {
|
|
291
|
+
var o = n.arg;
|
|
292
|
+
resetTryEntry(r);
|
|
293
|
+
}
|
|
294
|
+
return o;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
throw new Error("illegal catch attempt");
|
|
298
|
+
},
|
|
299
|
+
delegateYield: function (e, r, n) {
|
|
300
|
+
return this.delegate = {
|
|
301
|
+
iterator: values(e),
|
|
302
|
+
resultName: r,
|
|
303
|
+
nextLoc: n
|
|
304
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
305
|
+
}
|
|
306
|
+
}, e;
|
|
307
|
+
}
|
|
308
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
309
|
+
try {
|
|
310
|
+
var info = gen[key](arg);
|
|
311
|
+
var value = info.value;
|
|
312
|
+
} catch (error) {
|
|
313
|
+
reject(error);
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
if (info.done) {
|
|
317
|
+
resolve(value);
|
|
318
|
+
} else {
|
|
319
|
+
Promise.resolve(value).then(_next, _throw);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function _asyncToGenerator(fn) {
|
|
323
|
+
return function () {
|
|
324
|
+
var self = this,
|
|
325
|
+
args = arguments;
|
|
326
|
+
return new Promise(function (resolve, reject) {
|
|
327
|
+
var gen = fn.apply(self, args);
|
|
328
|
+
function _next(value) {
|
|
329
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
330
|
+
}
|
|
331
|
+
function _throw(err) {
|
|
332
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
333
|
+
}
|
|
334
|
+
_next(undefined);
|
|
335
|
+
});
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
var auth = function auth(_ref) {
|
|
340
|
+
var ssid = _ref.ssid;
|
|
341
|
+
return /*#__PURE__*/function () {
|
|
342
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, next) {
|
|
343
|
+
var token, payload;
|
|
344
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
345
|
+
while (1) switch (_context.prev = _context.next) {
|
|
346
|
+
case 0:
|
|
347
|
+
if (req.headers.authorization) {
|
|
348
|
+
_context.next = 2;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
return _context.abrupt("return", res.status(403).send({
|
|
352
|
+
status: 'token-not-found',
|
|
353
|
+
mdKey: 'ensure_auth'
|
|
354
|
+
}));
|
|
355
|
+
case 2:
|
|
356
|
+
token = req.headers.authorization.replace(/['"]+/g, "");
|
|
357
|
+
_context.prev = 3;
|
|
358
|
+
payload = jwt.verify(token, ssid);
|
|
359
|
+
req.auth = payload;
|
|
360
|
+
return _context.abrupt("return", next());
|
|
361
|
+
case 9:
|
|
362
|
+
_context.prev = 9;
|
|
363
|
+
_context.t0 = _context["catch"](3);
|
|
364
|
+
if (!(_context.t0 && (_context.t0 == null ? void 0 : _context.t0.message) === "jwt expired")) {
|
|
365
|
+
_context.next = 13;
|
|
366
|
+
break;
|
|
367
|
+
}
|
|
368
|
+
return _context.abrupt("return", res.status(500).send({
|
|
369
|
+
status: 'token-expired',
|
|
370
|
+
message: 'El token ha expirado',
|
|
371
|
+
error: _context.t0,
|
|
372
|
+
mdKey: 'ensure_auth'
|
|
373
|
+
}));
|
|
374
|
+
case 13:
|
|
375
|
+
return _context.abrupt("return", res.status(500).send({
|
|
376
|
+
status: 'token-invalid',
|
|
377
|
+
message: 'El token no es válido',
|
|
378
|
+
error: _context.t0,
|
|
379
|
+
mdKey: 'ensure_auth'
|
|
380
|
+
}));
|
|
381
|
+
case 14:
|
|
382
|
+
case "end":
|
|
383
|
+
return _context.stop();
|
|
384
|
+
}
|
|
385
|
+
}, _callee, null, [[3, 9]]);
|
|
386
|
+
}));
|
|
387
|
+
return function (_x, _x2, _x3) {
|
|
388
|
+
return _ref2.apply(this, arguments);
|
|
389
|
+
};
|
|
390
|
+
}();
|
|
391
|
+
};
|
|
392
|
+
exports.auth = auth;
|
|
393
|
+
//# sourceMappingURL=dauth-md-node.cjs.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dauth-md-node.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from \"express\";\nimport mongoose from \"mongoose\";\nimport jwt from \"jsonwebtoken\";\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId\n sid: string\n name: string\n lastname: string\n email: string\n createToken?: number\n exp?: number\n iat?: number\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken\n files: {\n image: { path: string },\n avatar: { path: string }\n },\n headers: {\n authorization: string\n }\n}\n\ninterface CustomResponse extends ExpressResponse {\n status(code: number): CustomResponse;\n send(body?: any): CustomResponse;\n}\n\nconst auth = ({ ssid }: { ssid: string }) => {\n return async (req: IRequestUser, res: CustomResponse, next: NextFunction) => {\n if (!req.headers.authorization) {\n return res.status(403).send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, \"\");\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (err) {\n if (err && err?.message === \"jwt expired\") {\n return res.status(500).send({ status: 'token-expired', message: 'El token ha expirado', error: err, mdKey: 'ensure_auth' });\n }\n return res.status(500).send({ status: 'token-invalid', message: 'El token no es válido', error: err, mdKey: 'ensure_auth' });\n }\n };\n};\n\nexports.auth = auth;"],"names":["auth","_ref","ssid","_ref2","_asyncToGenerator","_regeneratorRuntime","mark","_callee","req","res","next","token","payload","wrap","_callee$","_context","prev","headers","authorization","abrupt","status","send","mdKey","replace","jwt","verify","t0","message","error","stop","_x","_x2","_x3","apply","arguments","exports"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAMA,IAAI,GAAG,SAAPA,IAAIA,CAAAC,IAAA;MAAMC,IAAI,GAAAD,IAAA,CAAJC,IAAI;EAClB;IAAA,IAAAC,KAAA,GAAAC,iBAAA,eAAAC,mBAAA,GAAAC,IAAA,CAAO,SAAAC,QAAOC,GAAiB,EAAEC,GAAmB,EAAEC,IAAkB;MAAA,IAAAC,KAAA,EAAAC,OAAA;MAAA,OAAAP,mBAAA,GAAAQ,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAL,IAAA;UAAA;YAAA,IACjEF,GAAG,CAACS,OAAO,CAACC,aAAa;cAAAH,QAAA,CAAAL,IAAA;cAAA;;YAAA,OAAAK,QAAA,CAAAI,MAAA,WACrBV,GAAG,CAACW,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;cAAED,MAAM,EAAE,iBAAiB;cAAEE,KAAK,EAAE;aAAe,CAAC;UAAA;YAE5EX,KAAK,GAAGH,GAAG,CAACS,OAAO,CAACC,aAAa,CAACK,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;YAAAR,QAAA,CAAAC,IAAA;YAErDJ,OAAO,GAAGY,GAAG,CAACC,MAAM,CAACd,KAAK,EAAET,IAAc,CAAiB;YACjEM,GAAG,CAACR,IAAI,GAAGY,OAAO;YAAC,OAAAG,QAAA,CAAAI,MAAA,WACZT,IAAI,EAAE;UAAA;YAAAK,QAAA,CAAAC,IAAA;YAAAD,QAAA,CAAAW,EAAA,GAAAX,QAAA;YAAA,MAETA,QAAA,CAAAW,EAAA,IAAO,CAAAX,QAAA,CAAAW,EAAA,oBAAAX,QAAA,CAAAW,EAAA,CAAKC,OAAO,MAAK,aAAa;cAAAZ,QAAA,CAAAL,IAAA;cAAA;;YAAA,OAAAK,QAAA,CAAAI,MAAA,WAChCV,GAAG,CAACW,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;cAAED,MAAM,EAAE,eAAe;cAAEO,OAAO,EAAE,sBAAsB;cAAEC,KAAK,EAAAb,QAAA,CAAAW,EAAK;cAAEJ,KAAK,EAAE;aAAe,CAAC;UAAA;YAAA,OAAAP,QAAA,CAAAI,MAAA,WAEtHV,GAAG,CAACW,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;cAAED,MAAM,EAAE,eAAe;cAAEO,OAAO,EAAE,uBAAuB;cAAEC,KAAK,EAAAb,QAAA,CAAAW,EAAK;cAAEJ,KAAK,EAAE;aAAe,CAAC;UAAA;UAAA;YAAA,OAAAP,QAAA,CAAAc,IAAA;;SAAAtB,OAAA;KAE/H;IAAA,iBAAAuB,EAAA,EAAAC,GAAA,EAAAC,GAAA;MAAA,OAAA7B,KAAA,CAAA8B,KAAA,OAAAC,SAAA;;;AACH,CAAC;AAEDC,OAAO,CAACnC,IAAI,GAAGA,IAAI"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var t,r=(t=require("jsonwebtoken"))&&"object"==typeof t&&"default"in t?t.default:t;function e(){e=function(){return r};var t,r={},n=Object.prototype,o=n.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},a="function"==typeof Symbol?Symbol:{},u=a.iterator||"@@iterator",c=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function h(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{h({},"")}catch(t){h=function(t,r,e){return t[r]=e}}function f(t,r,e,n){var o=Object.create((r&&r.prototype instanceof g?r:g).prototype),a=new N(n||[]);return i(o,"_invoke",{value:j(t,e,a)}),o}function l(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=f;var p="suspendedStart",v="executing",y="completed",d={};function g(){}function m(){}function w(){}var b={};h(b,u,(function(){return this}));var x=Object.getPrototypeOf,L=x&&x(x(S([])));L&&L!==n&&o.call(L,u)&&(b=L);var E=w.prototype=g.prototype=Object.create(b);function _(t){["next","throw","return"].forEach((function(r){h(t,r,(function(t){return this._invoke(r,t)}))}))}function k(t,r){function e(n,i,a,u){var c=l(t[n],t,i);if("throw"!==c.type){var s=c.arg,h=s.value;return h&&"object"==typeof h&&o.call(h,"__await")?r.resolve(h.__await).then((function(t){e("next",t,a,u)}),(function(t){e("throw",t,a,u)})):r.resolve(h).then((function(t){s.value=t,a(s)}),(function(t){return e("throw",t,a,u)}))}u(c.arg)}var n;i(this,"_invoke",{value:function(t,o){function i(){return new r((function(r,n){e(t,o,r,n)}))}return n=n?n.then(i,i):i()}})}function j(r,e,n){var o=p;return function(i,a){if(o===v)throw new Error("Generator is already running");if(o===y){if("throw"===i)throw a;return{value:t,done:!0}}for(n.method=i,n.arg=a;;){var u=n.delegate;if(u){var c=O(u,n);if(c){if(c===d)continue;return c}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===p)throw o=y,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=v;var s=l(r,e,n);if("normal"===s.type){if(o=n.done?y:"suspendedYield",s.arg===d)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=y,n.method="throw",n.arg=s.arg)}}}function O(r,e){var n=e.method,o=r.iterator[n];if(o===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,O(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),d;var i=l(o,r.iterator,e.arg);if("throw"===i.type)return e.method="throw",e.arg=i.arg,e.delegate=null,d;var a=i.arg;return a?a.done?(e[r.resultName]=a.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,d):a:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,d)}function P(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function G(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function N(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function S(r){if(r||""===r){var e=r[u];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var n=-1,i=function e(){for(;++n<r.length;)if(o.call(r,n))return e.value=r[n],e.done=!1,e;return e.value=t,e.done=!0,e};return i.next=i}}throw new TypeError(typeof r+" is not iterable")}return m.prototype=w,i(E,"constructor",{value:w,configurable:!0}),i(w,"constructor",{value:m,configurable:!0}),m.displayName=h(w,s,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===m||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,h(t,s,"GeneratorFunction")),t.prototype=Object.create(E),t},r.awrap=function(t){return{__await:t}},_(k.prototype),h(k.prototype,c,(function(){return this})),r.AsyncIterator=k,r.async=function(t,e,n,o,i){void 0===i&&(i=Promise);var a=new k(f(t,e,n,o),i);return r.isGeneratorFunction(e)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},_(E),h(E,s,"Generator"),h(E,u,(function(){return this})),h(E,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=S,N.prototype={constructor:N,reset:function(r){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(G),!r)for(var e in this)"t"===e.charAt(0)&&o.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function n(n,o){return u.type="throw",u.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],u=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=o.call(a,"catchLoc"),s=o.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc<=this.prev&&o.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var i=n;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=r&&r<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=r,i?(this.method="next",this.next=i.finallyLoc,d):this.complete(a)},complete:function(t,r){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&r&&(this.next=r),d},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),G(e),d}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var o=n.arg;G(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:S(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),d}},r}function n(t,r,e,n,o,i,a){try{var u=t[i](a),c=u.value}catch(t){return void e(t)}u.done?r(c):Promise.resolve(c).then(n,o)}exports.auth=function(t){var o=t.ssid;return function(){var t,i=(t=e().mark((function t(n,i,a){var u,c;return e().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n.headers.authorization){t.next=2;break}return t.abrupt("return",i.status(403).send({status:"token-not-found",mdKey:"ensure_auth"}));case 2:return u=n.headers.authorization.replace(/['"]+/g,""),t.prev=3,c=r.verify(u,o),n.auth=c,t.abrupt("return",a());case 9:if(t.prev=9,t.t0=t.catch(3),!t.t0||"jwt expired"!==(null==t.t0?void 0:t.t0.message)){t.next=13;break}return t.abrupt("return",i.status(500).send({status:"token-expired",message:"El token ha expirado",error:t.t0,mdKey:"ensure_auth"}));case 13:return t.abrupt("return",i.status(500).send({status:"token-invalid",message:"El token no es válido",error:t.t0,mdKey:"ensure_auth"}));case 14:case"end":return t.stop()}}),t,null,[[3,9]])})),function(){var r=this,e=arguments;return new Promise((function(o,i){var a=t.apply(r,e);function u(t){n(a,o,i,u,c,"next",t)}function c(t){n(a,o,i,u,c,"throw",t)}u(void 0)}))});return function(t,r,e){return i.apply(this,arguments)}}()};
|
|
2
|
+
//# sourceMappingURL=dauth-md-node.cjs.production.min.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dauth-md-node.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from \"express\";\nimport mongoose from \"mongoose\";\nimport jwt from \"jsonwebtoken\";\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId\n sid: string\n name: string\n lastname: string\n email: string\n createToken?: number\n exp?: number\n iat?: number\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken\n files: {\n image: { path: string },\n avatar: { path: string }\n },\n headers: {\n authorization: string\n }\n}\n\ninterface CustomResponse extends ExpressResponse {\n status(code: number): CustomResponse;\n send(body?: any): CustomResponse;\n}\n\nconst auth = ({ ssid }: { ssid: string }) => {\n return async (req: IRequestUser, res: CustomResponse, next: NextFunction) => {\n if (!req.headers.authorization) {\n return res.status(403).send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, \"\");\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (err) {\n if (err && err?.message === \"jwt expired\") {\n return res.status(500).send({ status: 'token-expired', message: 'El token ha expirado', error: err, mdKey: 'ensure_auth' });\n }\n return res.status(500).send({ status: 'token-invalid', message: 'El token no es válido', error: err, mdKey: 'ensure_auth' });\n }\n };\n};\n\nexports.auth = auth;"],"names":["exports","auth","_ref","ssid","_ref2","_regeneratorRuntime","mark","_callee","req","res","next","token","payload","wrap","_context","prev","headers","authorization","abrupt","status","send","mdKey","replace","jwt","verify","t0","message","error","stop","_x","_x2","_x3","apply","arguments"],"mappings":"qkNAkDAA,QAAQC,KAnBK,SAAHC,OAAMC,EAAID,EAAJC,KACd,kBAAA,MAAAC,KAAAC,IAAAC,MAAO,SAAAC,EAAOC,EAAmBC,EAAqBC,GAAkB,IAAAC,EAAAC,EAAA,OAAAP,IAAAQ,eAAAC,GAAA,cAAAA,EAAAC,KAAAD,EAAAJ,MAAA,OAAA,GACjEF,EAAIQ,QAAQC,eAAaH,EAAAJ,OAAA,MAAA,OAAAI,EAAAI,gBACrBT,EAAIU,OAAO,KAAKC,KAAK,CAAED,OAAQ,kBAAmBE,MAAO,iBAAgB,OAK7D,OAHfV,EAAQH,EAAIQ,QAAQC,cAAcK,QAAQ,SAAU,IAAGR,EAAAC,OAErDH,EAAUW,EAAIC,OAAOb,EAAOR,GAClCK,EAAIP,KAAOW,EAAQE,EAAAI,gBACZR,KAAM,OAAA,GAAAI,EAAAC,OAAAD,EAAAW,GAAAX,YAETA,EAAAW,IAAwB,uBAAjBX,EAAAW,UAAAX,EAAAW,GAAKC,UAAyBZ,EAAAJ,QAAA,MAAA,OAAAI,EAAAI,gBAChCT,EAAIU,OAAO,KAAKC,KAAK,CAAED,OAAQ,gBAAiBO,QAAS,uBAAwBC,MAAKb,EAAAW,GAAOJ,MAAO,iBAAgB,QAAA,OAAAP,EAAAI,gBAEtHT,EAAIU,OAAO,KAAKC,KAAK,CAAED,OAAQ,gBAAiBO,QAAS,wBAAyBC,MAAKb,EAAAW,GAAOJ,MAAO,iBAAgB,QAAA,UAAA,OAAAP,EAAAc,UAAArB,kMAE/H,gBAAAsB,EAAAC,EAAAC,GAAA,OAAA3B,EAAA4B,WAAAC"}
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
|
|
3
|
+
function _regeneratorRuntime() {
|
|
4
|
+
_regeneratorRuntime = function () {
|
|
5
|
+
return e;
|
|
6
|
+
};
|
|
7
|
+
var t,
|
|
8
|
+
e = {},
|
|
9
|
+
r = Object.prototype,
|
|
10
|
+
n = r.hasOwnProperty,
|
|
11
|
+
o = Object.defineProperty || function (t, e, r) {
|
|
12
|
+
t[e] = r.value;
|
|
13
|
+
},
|
|
14
|
+
i = "function" == typeof Symbol ? Symbol : {},
|
|
15
|
+
a = i.iterator || "@@iterator",
|
|
16
|
+
c = i.asyncIterator || "@@asyncIterator",
|
|
17
|
+
u = i.toStringTag || "@@toStringTag";
|
|
18
|
+
function define(t, e, r) {
|
|
19
|
+
return Object.defineProperty(t, e, {
|
|
20
|
+
value: r,
|
|
21
|
+
enumerable: !0,
|
|
22
|
+
configurable: !0,
|
|
23
|
+
writable: !0
|
|
24
|
+
}), t[e];
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
define({}, "");
|
|
28
|
+
} catch (t) {
|
|
29
|
+
define = function (t, e, r) {
|
|
30
|
+
return t[e] = r;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function wrap(t, e, r, n) {
|
|
34
|
+
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
35
|
+
a = Object.create(i.prototype),
|
|
36
|
+
c = new Context(n || []);
|
|
37
|
+
return o(a, "_invoke", {
|
|
38
|
+
value: makeInvokeMethod(t, r, c)
|
|
39
|
+
}), a;
|
|
40
|
+
}
|
|
41
|
+
function tryCatch(t, e, r) {
|
|
42
|
+
try {
|
|
43
|
+
return {
|
|
44
|
+
type: "normal",
|
|
45
|
+
arg: t.call(e, r)
|
|
46
|
+
};
|
|
47
|
+
} catch (t) {
|
|
48
|
+
return {
|
|
49
|
+
type: "throw",
|
|
50
|
+
arg: t
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
e.wrap = wrap;
|
|
55
|
+
var h = "suspendedStart",
|
|
56
|
+
l = "suspendedYield",
|
|
57
|
+
f = "executing",
|
|
58
|
+
s = "completed",
|
|
59
|
+
y = {};
|
|
60
|
+
function Generator() {}
|
|
61
|
+
function GeneratorFunction() {}
|
|
62
|
+
function GeneratorFunctionPrototype() {}
|
|
63
|
+
var p = {};
|
|
64
|
+
define(p, a, function () {
|
|
65
|
+
return this;
|
|
66
|
+
});
|
|
67
|
+
var d = Object.getPrototypeOf,
|
|
68
|
+
v = d && d(d(values([])));
|
|
69
|
+
v && v !== r && n.call(v, a) && (p = v);
|
|
70
|
+
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
71
|
+
function defineIteratorMethods(t) {
|
|
72
|
+
["next", "throw", "return"].forEach(function (e) {
|
|
73
|
+
define(t, e, function (t) {
|
|
74
|
+
return this._invoke(e, t);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
function AsyncIterator(t, e) {
|
|
79
|
+
function invoke(r, o, i, a) {
|
|
80
|
+
var c = tryCatch(t[r], t, o);
|
|
81
|
+
if ("throw" !== c.type) {
|
|
82
|
+
var u = c.arg,
|
|
83
|
+
h = u.value;
|
|
84
|
+
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
85
|
+
invoke("next", t, i, a);
|
|
86
|
+
}, function (t) {
|
|
87
|
+
invoke("throw", t, i, a);
|
|
88
|
+
}) : e.resolve(h).then(function (t) {
|
|
89
|
+
u.value = t, i(u);
|
|
90
|
+
}, function (t) {
|
|
91
|
+
return invoke("throw", t, i, a);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
a(c.arg);
|
|
95
|
+
}
|
|
96
|
+
var r;
|
|
97
|
+
o(this, "_invoke", {
|
|
98
|
+
value: function (t, n) {
|
|
99
|
+
function callInvokeWithMethodAndArg() {
|
|
100
|
+
return new e(function (e, r) {
|
|
101
|
+
invoke(t, n, e, r);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function makeInvokeMethod(e, r, n) {
|
|
109
|
+
var o = h;
|
|
110
|
+
return function (i, a) {
|
|
111
|
+
if (o === f) throw new Error("Generator is already running");
|
|
112
|
+
if (o === s) {
|
|
113
|
+
if ("throw" === i) throw a;
|
|
114
|
+
return {
|
|
115
|
+
value: t,
|
|
116
|
+
done: !0
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
for (n.method = i, n.arg = a;;) {
|
|
120
|
+
var c = n.delegate;
|
|
121
|
+
if (c) {
|
|
122
|
+
var u = maybeInvokeDelegate(c, n);
|
|
123
|
+
if (u) {
|
|
124
|
+
if (u === y) continue;
|
|
125
|
+
return u;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
129
|
+
if (o === h) throw o = s, n.arg;
|
|
130
|
+
n.dispatchException(n.arg);
|
|
131
|
+
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
132
|
+
o = f;
|
|
133
|
+
var p = tryCatch(e, r, n);
|
|
134
|
+
if ("normal" === p.type) {
|
|
135
|
+
if (o = n.done ? s : l, p.arg === y) continue;
|
|
136
|
+
return {
|
|
137
|
+
value: p.arg,
|
|
138
|
+
done: n.done
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function maybeInvokeDelegate(e, r) {
|
|
146
|
+
var n = r.method,
|
|
147
|
+
o = e.iterator[n];
|
|
148
|
+
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
149
|
+
var i = tryCatch(o, e.iterator, r.arg);
|
|
150
|
+
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
151
|
+
var a = i.arg;
|
|
152
|
+
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
153
|
+
}
|
|
154
|
+
function pushTryEntry(t) {
|
|
155
|
+
var e = {
|
|
156
|
+
tryLoc: t[0]
|
|
157
|
+
};
|
|
158
|
+
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
159
|
+
}
|
|
160
|
+
function resetTryEntry(t) {
|
|
161
|
+
var e = t.completion || {};
|
|
162
|
+
e.type = "normal", delete e.arg, t.completion = e;
|
|
163
|
+
}
|
|
164
|
+
function Context(t) {
|
|
165
|
+
this.tryEntries = [{
|
|
166
|
+
tryLoc: "root"
|
|
167
|
+
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
168
|
+
}
|
|
169
|
+
function values(e) {
|
|
170
|
+
if (e || "" === e) {
|
|
171
|
+
var r = e[a];
|
|
172
|
+
if (r) return r.call(e);
|
|
173
|
+
if ("function" == typeof e.next) return e;
|
|
174
|
+
if (!isNaN(e.length)) {
|
|
175
|
+
var o = -1,
|
|
176
|
+
i = function next() {
|
|
177
|
+
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
178
|
+
return next.value = t, next.done = !0, next;
|
|
179
|
+
};
|
|
180
|
+
return i.next = i;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
throw new TypeError(typeof e + " is not iterable");
|
|
184
|
+
}
|
|
185
|
+
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
186
|
+
value: GeneratorFunctionPrototype,
|
|
187
|
+
configurable: !0
|
|
188
|
+
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
189
|
+
value: GeneratorFunction,
|
|
190
|
+
configurable: !0
|
|
191
|
+
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
192
|
+
var e = "function" == typeof t && t.constructor;
|
|
193
|
+
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
194
|
+
}, e.mark = function (t) {
|
|
195
|
+
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
196
|
+
}, e.awrap = function (t) {
|
|
197
|
+
return {
|
|
198
|
+
__await: t
|
|
199
|
+
};
|
|
200
|
+
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
201
|
+
return this;
|
|
202
|
+
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
203
|
+
void 0 === i && (i = Promise);
|
|
204
|
+
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
205
|
+
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
206
|
+
return t.done ? t.value : a.next();
|
|
207
|
+
});
|
|
208
|
+
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
209
|
+
return this;
|
|
210
|
+
}), define(g, "toString", function () {
|
|
211
|
+
return "[object Generator]";
|
|
212
|
+
}), e.keys = function (t) {
|
|
213
|
+
var e = Object(t),
|
|
214
|
+
r = [];
|
|
215
|
+
for (var n in e) r.push(n);
|
|
216
|
+
return r.reverse(), function next() {
|
|
217
|
+
for (; r.length;) {
|
|
218
|
+
var t = r.pop();
|
|
219
|
+
if (t in e) return next.value = t, next.done = !1, next;
|
|
220
|
+
}
|
|
221
|
+
return next.done = !0, next;
|
|
222
|
+
};
|
|
223
|
+
}, e.values = values, Context.prototype = {
|
|
224
|
+
constructor: Context,
|
|
225
|
+
reset: function (e) {
|
|
226
|
+
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
227
|
+
},
|
|
228
|
+
stop: function () {
|
|
229
|
+
this.done = !0;
|
|
230
|
+
var t = this.tryEntries[0].completion;
|
|
231
|
+
if ("throw" === t.type) throw t.arg;
|
|
232
|
+
return this.rval;
|
|
233
|
+
},
|
|
234
|
+
dispatchException: function (e) {
|
|
235
|
+
if (this.done) throw e;
|
|
236
|
+
var r = this;
|
|
237
|
+
function handle(n, o) {
|
|
238
|
+
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
239
|
+
}
|
|
240
|
+
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
241
|
+
var i = this.tryEntries[o],
|
|
242
|
+
a = i.completion;
|
|
243
|
+
if ("root" === i.tryLoc) return handle("end");
|
|
244
|
+
if (i.tryLoc <= this.prev) {
|
|
245
|
+
var c = n.call(i, "catchLoc"),
|
|
246
|
+
u = n.call(i, "finallyLoc");
|
|
247
|
+
if (c && u) {
|
|
248
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
249
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
250
|
+
} else if (c) {
|
|
251
|
+
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
252
|
+
} else {
|
|
253
|
+
if (!u) throw new Error("try statement without catch or finally");
|
|
254
|
+
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
},
|
|
259
|
+
abrupt: function (t, e) {
|
|
260
|
+
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
261
|
+
var o = this.tryEntries[r];
|
|
262
|
+
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
263
|
+
var i = o;
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
268
|
+
var a = i ? i.completion : {};
|
|
269
|
+
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
270
|
+
},
|
|
271
|
+
complete: function (t, e) {
|
|
272
|
+
if ("throw" === t.type) throw t.arg;
|
|
273
|
+
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
274
|
+
},
|
|
275
|
+
finish: function (t) {
|
|
276
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
277
|
+
var r = this.tryEntries[e];
|
|
278
|
+
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
279
|
+
}
|
|
280
|
+
},
|
|
281
|
+
catch: function (t) {
|
|
282
|
+
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
283
|
+
var r = this.tryEntries[e];
|
|
284
|
+
if (r.tryLoc === t) {
|
|
285
|
+
var n = r.completion;
|
|
286
|
+
if ("throw" === n.type) {
|
|
287
|
+
var o = n.arg;
|
|
288
|
+
resetTryEntry(r);
|
|
289
|
+
}
|
|
290
|
+
return o;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
throw new Error("illegal catch attempt");
|
|
294
|
+
},
|
|
295
|
+
delegateYield: function (e, r, n) {
|
|
296
|
+
return this.delegate = {
|
|
297
|
+
iterator: values(e),
|
|
298
|
+
resultName: r,
|
|
299
|
+
nextLoc: n
|
|
300
|
+
}, "next" === this.method && (this.arg = t), y;
|
|
301
|
+
}
|
|
302
|
+
}, e;
|
|
303
|
+
}
|
|
304
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
305
|
+
try {
|
|
306
|
+
var info = gen[key](arg);
|
|
307
|
+
var value = info.value;
|
|
308
|
+
} catch (error) {
|
|
309
|
+
reject(error);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
if (info.done) {
|
|
313
|
+
resolve(value);
|
|
314
|
+
} else {
|
|
315
|
+
Promise.resolve(value).then(_next, _throw);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
function _asyncToGenerator(fn) {
|
|
319
|
+
return function () {
|
|
320
|
+
var self = this,
|
|
321
|
+
args = arguments;
|
|
322
|
+
return new Promise(function (resolve, reject) {
|
|
323
|
+
var gen = fn.apply(self, args);
|
|
324
|
+
function _next(value) {
|
|
325
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
326
|
+
}
|
|
327
|
+
function _throw(err) {
|
|
328
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
329
|
+
}
|
|
330
|
+
_next(undefined);
|
|
331
|
+
});
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
var auth = function auth(_ref) {
|
|
336
|
+
var ssid = _ref.ssid;
|
|
337
|
+
return /*#__PURE__*/function () {
|
|
338
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, next) {
|
|
339
|
+
var token, payload;
|
|
340
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
341
|
+
while (1) switch (_context.prev = _context.next) {
|
|
342
|
+
case 0:
|
|
343
|
+
if (req.headers.authorization) {
|
|
344
|
+
_context.next = 2;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
return _context.abrupt("return", res.status(403).send({
|
|
348
|
+
status: 'token-not-found',
|
|
349
|
+
mdKey: 'ensure_auth'
|
|
350
|
+
}));
|
|
351
|
+
case 2:
|
|
352
|
+
token = req.headers.authorization.replace(/['"]+/g, "");
|
|
353
|
+
_context.prev = 3;
|
|
354
|
+
payload = jwt.verify(token, ssid);
|
|
355
|
+
req.auth = payload;
|
|
356
|
+
return _context.abrupt("return", next());
|
|
357
|
+
case 9:
|
|
358
|
+
_context.prev = 9;
|
|
359
|
+
_context.t0 = _context["catch"](3);
|
|
360
|
+
if (!(_context.t0 && (_context.t0 == null ? void 0 : _context.t0.message) === "jwt expired")) {
|
|
361
|
+
_context.next = 13;
|
|
362
|
+
break;
|
|
363
|
+
}
|
|
364
|
+
return _context.abrupt("return", res.status(500).send({
|
|
365
|
+
status: 'token-expired',
|
|
366
|
+
message: 'El token ha expirado',
|
|
367
|
+
error: _context.t0,
|
|
368
|
+
mdKey: 'ensure_auth'
|
|
369
|
+
}));
|
|
370
|
+
case 13:
|
|
371
|
+
return _context.abrupt("return", res.status(500).send({
|
|
372
|
+
status: 'token-invalid',
|
|
373
|
+
message: 'El token no es válido',
|
|
374
|
+
error: _context.t0,
|
|
375
|
+
mdKey: 'ensure_auth'
|
|
376
|
+
}));
|
|
377
|
+
case 14:
|
|
378
|
+
case "end":
|
|
379
|
+
return _context.stop();
|
|
380
|
+
}
|
|
381
|
+
}, _callee, null, [[3, 9]]);
|
|
382
|
+
}));
|
|
383
|
+
return function (_x, _x2, _x3) {
|
|
384
|
+
return _ref2.apply(this, arguments);
|
|
385
|
+
};
|
|
386
|
+
}();
|
|
387
|
+
};
|
|
388
|
+
exports.auth = auth;
|
|
389
|
+
//# sourceMappingURL=dauth-md-node.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dauth-md-node.esm.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from \"express\";\nimport mongoose from \"mongoose\";\nimport jwt from \"jsonwebtoken\";\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId\n sid: string\n name: string\n lastname: string\n email: string\n createToken?: number\n exp?: number\n iat?: number\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken\n files: {\n image: { path: string },\n avatar: { path: string }\n },\n headers: {\n authorization: string\n }\n}\n\ninterface CustomResponse extends ExpressResponse {\n status(code: number): CustomResponse;\n send(body?: any): CustomResponse;\n}\n\nconst auth = ({ ssid }: { ssid: string }) => {\n return async (req: IRequestUser, res: CustomResponse, next: NextFunction) => {\n if (!req.headers.authorization) {\n return res.status(403).send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, \"\");\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (err) {\n if (err && err?.message === \"jwt expired\") {\n return res.status(500).send({ status: 'token-expired', message: 'El token ha expirado', error: err, mdKey: 'ensure_auth' });\n }\n return res.status(500).send({ status: 'token-invalid', message: 'El token no es válido', error: err, mdKey: 'ensure_auth' });\n }\n };\n};\n\nexports.auth = auth;"],"names":["auth","_ref","ssid","_ref2","_asyncToGenerator","_regeneratorRuntime","mark","_callee","req","res","next","token","payload","wrap","_callee$","_context","prev","headers","authorization","abrupt","status","send","mdKey","replace","jwt","verify","t0","message","error","stop","_x","_x2","_x3","apply","arguments","exports"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,IAAMA,IAAI,GAAG,SAAPA,IAAIA,CAAAC,IAAA;MAAMC,IAAI,GAAAD,IAAA,CAAJC,IAAI;EAClB;IAAA,IAAAC,KAAA,GAAAC,iBAAA,eAAAC,mBAAA,GAAAC,IAAA,CAAO,SAAAC,QAAOC,GAAiB,EAAEC,GAAmB,EAAEC,IAAkB;MAAA,IAAAC,KAAA,EAAAC,OAAA;MAAA,OAAAP,mBAAA,GAAAQ,IAAA,UAAAC,SAAAC,QAAA;QAAA,kBAAAA,QAAA,CAAAC,IAAA,GAAAD,QAAA,CAAAL,IAAA;UAAA;YAAA,IACjEF,GAAG,CAACS,OAAO,CAACC,aAAa;cAAAH,QAAA,CAAAL,IAAA;cAAA;;YAAA,OAAAK,QAAA,CAAAI,MAAA,WACrBV,GAAG,CAACW,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;cAAED,MAAM,EAAE,iBAAiB;cAAEE,KAAK,EAAE;aAAe,CAAC;UAAA;YAE5EX,KAAK,GAAGH,GAAG,CAACS,OAAO,CAACC,aAAa,CAACK,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;YAAAR,QAAA,CAAAC,IAAA;YAErDJ,OAAO,GAAGY,GAAG,CAACC,MAAM,CAACd,KAAK,EAAET,IAAc,CAAiB;YACjEM,GAAG,CAACR,IAAI,GAAGY,OAAO;YAAC,OAAAG,QAAA,CAAAI,MAAA,WACZT,IAAI,EAAE;UAAA;YAAAK,QAAA,CAAAC,IAAA;YAAAD,QAAA,CAAAW,EAAA,GAAAX,QAAA;YAAA,MAETA,QAAA,CAAAW,EAAA,IAAO,CAAAX,QAAA,CAAAW,EAAA,oBAAAX,QAAA,CAAAW,EAAA,CAAKC,OAAO,MAAK,aAAa;cAAAZ,QAAA,CAAAL,IAAA;cAAA;;YAAA,OAAAK,QAAA,CAAAI,MAAA,WAChCV,GAAG,CAACW,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;cAAED,MAAM,EAAE,eAAe;cAAEO,OAAO,EAAE,sBAAsB;cAAEC,KAAK,EAAAb,QAAA,CAAAW,EAAK;cAAEJ,KAAK,EAAE;aAAe,CAAC;UAAA;YAAA,OAAAP,QAAA,CAAAI,MAAA,WAEtHV,GAAG,CAACW,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;cAAED,MAAM,EAAE,eAAe;cAAEO,OAAO,EAAE,uBAAuB;cAAEC,KAAK,EAAAb,QAAA,CAAAW,EAAK;cAAEJ,KAAK,EAAE;aAAe,CAAC;UAAA;UAAA;YAAA,OAAAP,QAAA,CAAAc,IAAA;;SAAAtB,OAAA;KAE/H;IAAA,iBAAAuB,EAAA,EAAAC,GAAA,EAAAC,GAAA;MAAA,OAAA7B,KAAA,CAAA8B,KAAA,OAAAC,SAAA;;;AACH,CAAC;AAEDC,OAAO,CAACnC,IAAI,GAAGA,IAAI"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "0.1.0",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"typings": "dist/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"src"
|
|
9
|
+
],
|
|
10
|
+
"engines": {
|
|
11
|
+
"node": ">=10"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"start": "tsdx watch",
|
|
15
|
+
"build": "tsdx build",
|
|
16
|
+
"test": "tsdx test",
|
|
17
|
+
"lint": "tsdx lint",
|
|
18
|
+
"prepare": "tsdx build",
|
|
19
|
+
"size": "size-limit",
|
|
20
|
+
"analyze": "size-limit --why"
|
|
21
|
+
},
|
|
22
|
+
"husky": {
|
|
23
|
+
"hooks": {
|
|
24
|
+
"pre-commit": "tsdx lint"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"prettier": {
|
|
28
|
+
"printWidth": 80,
|
|
29
|
+
"semi": true,
|
|
30
|
+
"singleQuote": true,
|
|
31
|
+
"trailingComma": "es5"
|
|
32
|
+
},
|
|
33
|
+
"name": "dauth-md-node",
|
|
34
|
+
"author": "David T. Pizarro Frick",
|
|
35
|
+
"module": "dist/dauth-md-node.esm.js",
|
|
36
|
+
"size-limit": [
|
|
37
|
+
{
|
|
38
|
+
"path": "dist/dauth-md-node.cjs.production.min.js",
|
|
39
|
+
"limit": "10 KB"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
"path": "dist/dauth-md-node.esm.js",
|
|
43
|
+
"limit": "10 KB"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@size-limit/preset-small-lib": "^11.0.2",
|
|
48
|
+
"@types/express": "^4.17.21",
|
|
49
|
+
"@types/jsonwebtoken": "^9.0.5",
|
|
50
|
+
"husky": "^9.0.11",
|
|
51
|
+
"size-limit": "^11.0.2",
|
|
52
|
+
"tsdx": "^0.14.1",
|
|
53
|
+
"tslib": "^2.6.2",
|
|
54
|
+
"typescript": "^3.9.10"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"express": "^4.18.2",
|
|
58
|
+
"jsonwebtoken": "^9.0.2",
|
|
59
|
+
"mongoose": "^8.1.2"
|
|
60
|
+
}
|
|
61
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Request, NextFunction, Response as ExpressResponse } from "express";
|
|
2
|
+
import mongoose from "mongoose";
|
|
3
|
+
import jwt from "jsonwebtoken";
|
|
4
|
+
|
|
5
|
+
export interface IAccessToken {
|
|
6
|
+
_id: string | mongoose.Types.ObjectId
|
|
7
|
+
sid: string
|
|
8
|
+
name: string
|
|
9
|
+
lastname: string
|
|
10
|
+
email: string
|
|
11
|
+
createToken?: number
|
|
12
|
+
exp?: number
|
|
13
|
+
iat?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface IRequestUser extends Request {
|
|
17
|
+
auth: IAccessToken
|
|
18
|
+
files: {
|
|
19
|
+
image: { path: string },
|
|
20
|
+
avatar: { path: string }
|
|
21
|
+
},
|
|
22
|
+
headers: {
|
|
23
|
+
authorization: string
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
interface CustomResponse extends ExpressResponse {
|
|
28
|
+
status(code: number): CustomResponse;
|
|
29
|
+
send(body?: any): CustomResponse;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const auth = ({ ssid }: { ssid: string }) => {
|
|
33
|
+
return async (req: IRequestUser, res: CustomResponse, next: NextFunction) => {
|
|
34
|
+
if (!req.headers.authorization) {
|
|
35
|
+
return res.status(403).send({ status: 'token-not-found', mdKey: 'ensure_auth' });
|
|
36
|
+
}
|
|
37
|
+
const token = req.headers.authorization.replace(/['"]+/g, "");
|
|
38
|
+
try {
|
|
39
|
+
const payload = jwt.verify(token, ssid as string) as IAccessToken;
|
|
40
|
+
req.auth = payload;
|
|
41
|
+
return next();
|
|
42
|
+
} catch (err) {
|
|
43
|
+
if (err && err?.message === "jwt expired") {
|
|
44
|
+
return res.status(500).send({ status: 'token-expired', message: 'El token ha expirado', error: err, mdKey: 'ensure_auth' });
|
|
45
|
+
}
|
|
46
|
+
return res.status(500).send({ status: 'token-invalid', message: 'El token no es válido', error: err, mdKey: 'ensure_auth' });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.auth = auth;
|