@codeleap/auth 7.0.1 → 7.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AuthErrors/index.js +23 -15
- package/dist/AuthErrors/index.js.map +1 -1
- package/package.json +4 -4
package/dist/AuthErrors/index.js
CHANGED
|
@@ -2,8 +2,10 @@ import { DEFAULT_AUTH_ERRORS } from './data';
|
|
|
2
2
|
export * from './types';
|
|
3
3
|
/** Internal Error subclass that carries a typed `code` alongside the human-readable `msg` factory; not exported — consumers interact through `AppAuthErrors`. */
|
|
4
4
|
class AuthError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
msg;
|
|
5
7
|
constructor(message, code) {
|
|
6
|
-
const _error = 'AuthError:' +
|
|
8
|
+
const _error = 'AuthError:' + code?.toLocaleUpperCase();
|
|
7
9
|
super(_error);
|
|
8
10
|
this.name = _error;
|
|
9
11
|
this.code = code;
|
|
@@ -15,12 +17,17 @@ class AuthError extends Error {
|
|
|
15
17
|
* Social errors are kept in a separate namespace because their codes can collide with base error codes (e.g. numeric strings).
|
|
16
18
|
*/
|
|
17
19
|
export class AppAuthErrors {
|
|
20
|
+
errors;
|
|
21
|
+
social;
|
|
22
|
+
onError;
|
|
23
|
+
defaultErrors = DEFAULT_AUTH_ERRORS;
|
|
24
|
+
socialKey = 'social';
|
|
18
25
|
constructor(newErrors, errorFunction) {
|
|
19
|
-
var _a, _b;
|
|
20
|
-
this.defaultErrors = DEFAULT_AUTH_ERRORS;
|
|
21
|
-
this.socialKey = 'social';
|
|
22
26
|
const defaultErrors = DEFAULT_AUTH_ERRORS;
|
|
23
|
-
const socialAuthErrors =
|
|
27
|
+
const socialAuthErrors = {
|
|
28
|
+
...defaultErrors[this.socialKey],
|
|
29
|
+
...(newErrors?.[this.socialKey] ?? {}),
|
|
30
|
+
};
|
|
24
31
|
const socialErrors = this.registryErrors(socialAuthErrors);
|
|
25
32
|
this.social = socialErrors;
|
|
26
33
|
if (!!newErrors['social']) {
|
|
@@ -29,28 +36,29 @@ export class AppAuthErrors {
|
|
|
29
36
|
if (!!defaultErrors['social']) {
|
|
30
37
|
defaultErrors['social'] = undefined;
|
|
31
38
|
}
|
|
32
|
-
const baseAuthErrors =
|
|
39
|
+
const baseAuthErrors = {
|
|
40
|
+
...defaultErrors,
|
|
41
|
+
...(newErrors ?? {}),
|
|
42
|
+
};
|
|
33
43
|
const authErrors = this.registryErrors(baseAuthErrors);
|
|
34
44
|
this.errors = authErrors;
|
|
35
45
|
this.registryErrorFunction(errorFunction);
|
|
36
46
|
}
|
|
37
47
|
getError(err) {
|
|
38
|
-
var _a, _b, _c, _d, _e, _f;
|
|
39
48
|
if (!err)
|
|
40
49
|
return null;
|
|
41
50
|
if (typeof err == 'string') {
|
|
42
|
-
return
|
|
51
|
+
return this.errors?.[err] ?? this.social?.[err];
|
|
43
52
|
}
|
|
44
53
|
const authError = err;
|
|
45
|
-
if (!!
|
|
46
|
-
return
|
|
54
|
+
if (!!authError?.code) {
|
|
55
|
+
return this.errors?.[authError?.code] ?? this.social?.[authError?.code];
|
|
47
56
|
}
|
|
48
57
|
return null;
|
|
49
58
|
}
|
|
50
59
|
isError(err, key) {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return err == _error.code || (err === null || err === void 0 ? void 0 : err.code) == _error.code;
|
|
60
|
+
const _error = this.errors?.[key];
|
|
61
|
+
return err == _error.code || err?.code == _error.code;
|
|
54
62
|
}
|
|
55
63
|
verifyError(err) {
|
|
56
64
|
return !!(this.getError(err));
|
|
@@ -58,7 +66,7 @@ export class AppAuthErrors {
|
|
|
58
66
|
exception(err) {
|
|
59
67
|
const _error = this.getError(err);
|
|
60
68
|
if (_error != null) {
|
|
61
|
-
throw new AuthError(_error
|
|
69
|
+
throw new AuthError(_error?.msg, _error?.code);
|
|
62
70
|
}
|
|
63
71
|
}
|
|
64
72
|
createAuthError(message, code) {
|
|
@@ -80,7 +88,7 @@ export class AppAuthErrors {
|
|
|
80
88
|
registryErrorFunction(pureErrorFunction) {
|
|
81
89
|
this.onError = (err, module = undefined, args = {}) => {
|
|
82
90
|
const authError = this.getError(err);
|
|
83
|
-
pureErrorFunction
|
|
91
|
+
pureErrorFunction?.(authError, module, args);
|
|
84
92
|
};
|
|
85
93
|
}
|
|
86
94
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/AuthErrors/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAG5C,cAAc,SAAS,CAAA;AAEvB,iKAAiK;AACjK,MAAM,SAAU,SAAQ,KAAK;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/AuthErrors/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AAG5C,cAAc,SAAS,CAAA;AAEvB,iKAAiK;AACjK,MAAM,SAAU,SAAQ,KAAK;IAC3B,IAAI,CAAoB;IACxB,GAAG,CAAmB;IAEtB,YAAY,OAA0B,EAAE,IAAwB;QAC9D,MAAM,MAAM,GAAG,YAAY,GAAG,IAAI,EAAE,iBAAiB,EAAE,CAAA;QACvD,KAAK,CAAC,MAAM,CAAC,CAAA;QACb,IAAI,CAAC,IAAI,GAAG,MAAM,CAAA;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;QAChB,IAAI,CAAC,GAAG,GAAG,OAAO,CAAA;IACpB,CAAC;CACF;AAID;;;GAGG;AACH,MAAM,OAAO,aAAa;IACjB,MAAM,CAA+E;IAErF,MAAM,CAAmG;IAEzG,OAAO,CAAoB;IAE3B,aAAa,GAAG,mBAAmB,CAAA;IAElC,SAAS,GAAW,QAAQ,CAAA;IAEpC,YAAY,SAAY,EAAE,aAAgB;QACxC,MAAM,aAAa,GAAG,mBAAmB,CAAA;QAEzC,MAAM,gBAAgB,GAAG;YACvB,GAAI,aAAqC,CAAC,IAAI,CAAC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,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAEO,qBAAqB,CAAC,iBAA2B;QACvD,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,EAAE,IAAI,GAAG,EAAE,EAAE,EAAE;YACpD,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;YACpC,iBAAiB,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;QAC9C,CAAC,CAAA;IACH,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/auth",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
"directory": "packages/auth"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@codeleap/config": "7.0.
|
|
26
|
-
"@codeleap/types": "7.0.
|
|
25
|
+
"@codeleap/config": "7.0.2",
|
|
26
|
+
"@codeleap/types": "7.0.2",
|
|
27
27
|
"ts-node-dev": "1.1.8"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"typecheck": "bun tsc --noEmit -p ./tsconfig.json"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
|
-
"@codeleap/types": "7.0.
|
|
34
|
+
"@codeleap/types": "7.0.2",
|
|
35
35
|
"typescript": "5.5.2"
|
|
36
36
|
}
|
|
37
37
|
}
|