@codeleap/auth 7.0.2 → 7.1.2
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/data.js +1 -4
- package/dist/AuthErrors/data.js.map +1 -1
- package/dist/AuthErrors/index.js +27 -37
- package/dist/AuthErrors/index.js.map +1 -1
- package/dist/AuthErrors/types.js +1 -2
- package/dist/index.js +1 -17
- package/dist/index.js.map +1 -1
- package/package.json +5 -4
package/dist/AuthErrors/data.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_AUTH_ERRORS = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Baseline error-code-to-message map shared across all apps.
|
|
6
3
|
* `social` keys are intentionally null — canceled/unspecified social flows are silently swallowed rather than surfaced to the user.
|
|
7
4
|
*/
|
|
8
|
-
|
|
5
|
+
export const DEFAULT_AUTH_ERRORS = {
|
|
9
6
|
'auth/wrong-password': 'Email or password is incorrect',
|
|
10
7
|
'auth/not-registered': 'This user is not registered',
|
|
11
8
|
'auth/requires-recent-login': 'You need to log in again to continue',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/AuthErrors/data.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/AuthErrors/data.ts"],"names":[],"mappings":"AACA;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG;IACjC,qBAAqB,EAAE,gCAAgC;IACvD,qBAAqB,EAAE,6BAA6B;IACpD,4BAA4B,EAAE,sCAAsC;IACpE,gCAAgC,EAAE,gCAAgC;IAClE,wBAAwB,EAAE,yFAAyF;IACnH,mBAAmB,EAAE,qCAAqC;IAC1D,sBAAsB,EAAE,gEAAgE;IACxF,2BAA2B,EAAE,qCAAqC;IAClE,oBAAoB,EAAE,gCAAgC;IACtD,oBAAoB,EAAE,yEAAyE;IAC/F,qBAAqB,EAAE,gCAAgC;IACvD,oBAAoB,EAAE,yEAAyE;IAE/F,QAAQ,EAAE;QACR,OAAO,EAAE,IAAI;QACb,cAAc,EAAE,IAAI;QACpB,yBAAyB,EAAE,IAAI;QAC/B,IAAI,EAAE,IAAI;QACV,MAAM,EAAE,IAAI;KACb;CACF,CAAA"}
|
package/dist/AuthErrors/index.js
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.AppAuthErrors = void 0;
|
|
18
|
-
const data_1 = require("./data");
|
|
19
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
import { DEFAULT_AUTH_ERRORS } from './data';
|
|
2
|
+
export * from './types';
|
|
20
3
|
/** Internal Error subclass that carries a typed `code` alongside the human-readable `msg` factory; not exported — consumers interact through `AppAuthErrors`. */
|
|
21
4
|
class AuthError extends Error {
|
|
5
|
+
code;
|
|
6
|
+
msg;
|
|
22
7
|
constructor(message, code) {
|
|
23
|
-
const _error = 'AuthError:' +
|
|
8
|
+
const _error = 'AuthError:' + code?.toLocaleUpperCase();
|
|
24
9
|
super(_error);
|
|
25
10
|
this.name = _error;
|
|
26
11
|
this.code = code;
|
|
@@ -31,13 +16,18 @@ class AuthError extends Error {
|
|
|
31
16
|
* Registry that merges app-specific error codes with the built-in defaults and wires them to a single `onError` handler.
|
|
32
17
|
* Social errors are kept in a separate namespace because their codes can collide with base error codes (e.g. numeric strings).
|
|
33
18
|
*/
|
|
34
|
-
class AppAuthErrors {
|
|
19
|
+
export class AppAuthErrors {
|
|
20
|
+
errors;
|
|
21
|
+
social;
|
|
22
|
+
onError;
|
|
23
|
+
defaultErrors = DEFAULT_AUTH_ERRORS;
|
|
24
|
+
socialKey = 'social';
|
|
35
25
|
constructor(newErrors, errorFunction) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
const defaultErrors = DEFAULT_AUTH_ERRORS;
|
|
27
|
+
const socialAuthErrors = {
|
|
28
|
+
...defaultErrors[this.socialKey],
|
|
29
|
+
...(newErrors?.[this.socialKey] ?? {}),
|
|
30
|
+
};
|
|
41
31
|
const socialErrors = this.registryErrors(socialAuthErrors);
|
|
42
32
|
this.social = socialErrors;
|
|
43
33
|
if (!!newErrors['social']) {
|
|
@@ -46,28 +36,29 @@ class AppAuthErrors {
|
|
|
46
36
|
if (!!defaultErrors['social']) {
|
|
47
37
|
defaultErrors['social'] = undefined;
|
|
48
38
|
}
|
|
49
|
-
const baseAuthErrors =
|
|
39
|
+
const baseAuthErrors = {
|
|
40
|
+
...defaultErrors,
|
|
41
|
+
...(newErrors ?? {}),
|
|
42
|
+
};
|
|
50
43
|
const authErrors = this.registryErrors(baseAuthErrors);
|
|
51
44
|
this.errors = authErrors;
|
|
52
45
|
this.registryErrorFunction(errorFunction);
|
|
53
46
|
}
|
|
54
47
|
getError(err) {
|
|
55
|
-
var _a, _b, _c, _d, _e, _f;
|
|
56
48
|
if (!err)
|
|
57
49
|
return null;
|
|
58
50
|
if (typeof err == 'string') {
|
|
59
|
-
return
|
|
51
|
+
return this.errors?.[err] ?? this.social?.[err];
|
|
60
52
|
}
|
|
61
53
|
const authError = err;
|
|
62
|
-
if (!!
|
|
63
|
-
return
|
|
54
|
+
if (!!authError?.code) {
|
|
55
|
+
return this.errors?.[authError?.code] ?? this.social?.[authError?.code];
|
|
64
56
|
}
|
|
65
57
|
return null;
|
|
66
58
|
}
|
|
67
59
|
isError(err, key) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
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;
|
|
71
62
|
}
|
|
72
63
|
verifyError(err) {
|
|
73
64
|
return !!(this.getError(err));
|
|
@@ -75,7 +66,7 @@ class AppAuthErrors {
|
|
|
75
66
|
exception(err) {
|
|
76
67
|
const _error = this.getError(err);
|
|
77
68
|
if (_error != null) {
|
|
78
|
-
throw new AuthError(_error
|
|
69
|
+
throw new AuthError(_error?.msg, _error?.code);
|
|
79
70
|
}
|
|
80
71
|
}
|
|
81
72
|
createAuthError(message, code) {
|
|
@@ -97,9 +88,8 @@ class AppAuthErrors {
|
|
|
97
88
|
registryErrorFunction(pureErrorFunction) {
|
|
98
89
|
this.onError = (err, module = undefined, args = {}) => {
|
|
99
90
|
const authError = this.getError(err);
|
|
100
|
-
pureErrorFunction
|
|
91
|
+
pureErrorFunction?.(authError, module, args);
|
|
101
92
|
};
|
|
102
93
|
}
|
|
103
94
|
}
|
|
104
|
-
exports.AppAuthErrors = AppAuthErrors;
|
|
105
95
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/AuthErrors/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/AuthErrors/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAA;AA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E,MAAM,EAAE,IAAI,CAAC,CAAA;QAChD,CAAC;IACH,CAAC;IAEM,eAAe,CAAC,OAA0B,EAAE,IAAwB;QACzE,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;IACrC,CAAC;IAEO,cAAc,CAAC,kBAAqB;QAC1C,MAAM,KAAK,GAA8B,EAAE,CAAA;QAE3C,KAAK,MAAM,QAAQ,IAAK,kBAA6B,EAAE,CAAC;YACtD,MAAM,QAAQ,GAAI,kBAA0C,CAAC,QAAQ,CAAW,CAAA;YAEhF,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;gBACrD,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,SAAS,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YAC3D,CAAC;iBAAM,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;gBAC1C,KAAK,CAAC,QAAQ,CAAC,GAAG,IAAI,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YACrD,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/dist/AuthErrors/types.js
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./AuthErrors"), exports);
|
|
1
|
+
export * from './AuthErrors';
|
|
18
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/auth",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "7.1.2",
|
|
4
5
|
"main": "dist/index.js",
|
|
5
6
|
"types": "dist/index.d.ts",
|
|
6
7
|
"exports": {
|
|
@@ -22,8 +23,8 @@
|
|
|
22
23
|
"directory": "packages/auth"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
|
-
"@codeleap/config": "7.
|
|
26
|
-
"@codeleap/types": "7.
|
|
26
|
+
"@codeleap/config": "7.1.1",
|
|
27
|
+
"@codeleap/types": "7.1.1",
|
|
27
28
|
"ts-node-dev": "1.1.8"
|
|
28
29
|
},
|
|
29
30
|
"scripts": {
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"typecheck": "bun tsc --noEmit -p ./tsconfig.json"
|
|
32
33
|
},
|
|
33
34
|
"peerDependencies": {
|
|
34
|
-
"@codeleap/types": "7.
|
|
35
|
+
"@codeleap/types": "7.1.1",
|
|
35
36
|
"typescript": "5.5.2"
|
|
36
37
|
}
|
|
37
38
|
}
|