@codeleap/auth 7.0.0 → 7.0.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 +29 -0
- package/dist/AuthErrors/data.js.map +1 -0
- package/dist/AuthErrors/index.js +105 -0
- package/dist/AuthErrors/index.js.map +1 -0
- package/dist/AuthErrors/types.js +3 -0
- package/dist/AuthErrors/types.js.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DEFAULT_AUTH_ERRORS = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Baseline error-code-to-message map shared across all apps.
|
|
6
|
+
* `social` keys are intentionally null — canceled/unspecified social flows are silently swallowed rather than surfaced to the user.
|
|
7
|
+
*/
|
|
8
|
+
exports.DEFAULT_AUTH_ERRORS = {
|
|
9
|
+
'auth/wrong-password': 'Email or password is incorrect',
|
|
10
|
+
'auth/not-registered': 'This user is not registered',
|
|
11
|
+
'auth/requires-recent-login': 'You need to log in again to continue',
|
|
12
|
+
'auth/invalid-login-credentials': 'Email or password is incorrect',
|
|
13
|
+
'auth/too-many-requests': 'Access to this account has been temporarily disabled due to many failed login attempts.',
|
|
14
|
+
'auth/email-in-use': 'This email address is already taken',
|
|
15
|
+
'auth/email-not-found': 'Could not find an account matching the specified email address',
|
|
16
|
+
'auth/email-already-in-use': 'This email address is already taken',
|
|
17
|
+
'auth/invalid-email': 'Email or password is incorrect',
|
|
18
|
+
'auth/user-disabled': 'Could not find an account with the specified email address and password',
|
|
19
|
+
'auth/user-not-found': 'Email or password is incorrect',
|
|
20
|
+
'auth/missing-email': 'Could not find an account with the specified email address and password',
|
|
21
|
+
'social': {
|
|
22
|
+
'12501': null,
|
|
23
|
+
'EUNSPECIFIED': null,
|
|
24
|
+
'facebook-login-canceled': null,
|
|
25
|
+
'-5': null,
|
|
26
|
+
'1001': null,
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.js","sourceRoot":"","sources":["../../src/AuthErrors/data.ts"],"names":[],"mappings":";;;AACA;;;GAGG;AACU,QAAA,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"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
exports.AppAuthErrors = void 0;
|
|
18
|
+
const data_1 = require("./data");
|
|
19
|
+
__exportStar(require("./types"), exports);
|
|
20
|
+
/** Internal Error subclass that carries a typed `code` alongside the human-readable `msg` factory; not exported — consumers interact through `AppAuthErrors`. */
|
|
21
|
+
class AuthError extends Error {
|
|
22
|
+
constructor(message, code) {
|
|
23
|
+
const _error = 'AuthError:' + (code === null || code === void 0 ? void 0 : code.toLocaleUpperCase());
|
|
24
|
+
super(_error);
|
|
25
|
+
this.name = _error;
|
|
26
|
+
this.code = code;
|
|
27
|
+
this.msg = message;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Registry that merges app-specific error codes with the built-in defaults and wires them to a single `onError` handler.
|
|
32
|
+
* Social errors are kept in a separate namespace because their codes can collide with base error codes (e.g. numeric strings).
|
|
33
|
+
*/
|
|
34
|
+
class AppAuthErrors {
|
|
35
|
+
constructor(newErrors, errorFunction) {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
this.defaultErrors = data_1.DEFAULT_AUTH_ERRORS;
|
|
38
|
+
this.socialKey = 'social';
|
|
39
|
+
const defaultErrors = data_1.DEFAULT_AUTH_ERRORS;
|
|
40
|
+
const socialAuthErrors = Object.assign(Object.assign({}, defaultErrors[this.socialKey]), ((_a = newErrors === null || newErrors === void 0 ? void 0 : newErrors[this.socialKey]) !== null && _a !== void 0 ? _a : {}));
|
|
41
|
+
const socialErrors = this.registryErrors(socialAuthErrors);
|
|
42
|
+
this.social = socialErrors;
|
|
43
|
+
if (!!newErrors['social']) {
|
|
44
|
+
delete newErrors['social'];
|
|
45
|
+
}
|
|
46
|
+
if (!!defaultErrors['social']) {
|
|
47
|
+
defaultErrors['social'] = undefined;
|
|
48
|
+
}
|
|
49
|
+
const baseAuthErrors = Object.assign(Object.assign({}, defaultErrors), ((_b = newErrors) !== null && _b !== void 0 ? _b : {}));
|
|
50
|
+
const authErrors = this.registryErrors(baseAuthErrors);
|
|
51
|
+
this.errors = authErrors;
|
|
52
|
+
this.registryErrorFunction(errorFunction);
|
|
53
|
+
}
|
|
54
|
+
getError(err) {
|
|
55
|
+
var _a, _b, _c, _d, _e, _f;
|
|
56
|
+
if (!err)
|
|
57
|
+
return null;
|
|
58
|
+
if (typeof err == 'string') {
|
|
59
|
+
return (_b = (_a = this.errors) === null || _a === void 0 ? void 0 : _a[err]) !== null && _b !== void 0 ? _b : (_c = this.social) === null || _c === void 0 ? void 0 : _c[err];
|
|
60
|
+
}
|
|
61
|
+
const authError = err;
|
|
62
|
+
if (!!(authError === null || authError === void 0 ? void 0 : authError.code)) {
|
|
63
|
+
return (_e = (_d = this.errors) === null || _d === void 0 ? void 0 : _d[authError === null || authError === void 0 ? void 0 : authError.code]) !== null && _e !== void 0 ? _e : (_f = this.social) === null || _f === void 0 ? void 0 : _f[authError === null || authError === void 0 ? void 0 : authError.code];
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
isError(err, key) {
|
|
68
|
+
var _a;
|
|
69
|
+
const _error = (_a = this.errors) === null || _a === void 0 ? void 0 : _a[key];
|
|
70
|
+
return err == _error.code || (err === null || err === void 0 ? void 0 : err.code) == _error.code;
|
|
71
|
+
}
|
|
72
|
+
verifyError(err) {
|
|
73
|
+
return !!(this.getError(err));
|
|
74
|
+
}
|
|
75
|
+
exception(err) {
|
|
76
|
+
const _error = this.getError(err);
|
|
77
|
+
if (_error != null) {
|
|
78
|
+
throw new AuthError(_error === null || _error === void 0 ? void 0 : _error.msg, _error === null || _error === void 0 ? void 0 : _error.code);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
createAuthError(message, code) {
|
|
82
|
+
return new AuthError(message, code);
|
|
83
|
+
}
|
|
84
|
+
registryErrors(unregisteredErrors) {
|
|
85
|
+
const state = {};
|
|
86
|
+
for (const errorKey in unregisteredErrors) {
|
|
87
|
+
const errorMsg = unregisteredErrors[errorKey];
|
|
88
|
+
if (typeof errorMsg === 'string' || errorMsg == null) {
|
|
89
|
+
state[errorKey] = new AuthError(() => errorMsg, errorKey);
|
|
90
|
+
}
|
|
91
|
+
else if (typeof errorMsg === 'function') {
|
|
92
|
+
state[errorKey] = new AuthError(errorMsg, errorKey);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return state;
|
|
96
|
+
}
|
|
97
|
+
registryErrorFunction(pureErrorFunction) {
|
|
98
|
+
this.onError = (err, module = undefined, args = {}) => {
|
|
99
|
+
const authError = this.getError(err);
|
|
100
|
+
pureErrorFunction === null || pureErrorFunction === void 0 ? void 0 : pureErrorFunction(authError, module, args);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.AppAuthErrors = AppAuthErrors;
|
|
105
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/AuthErrors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AACA,iCAA4C;AAG5C,0CAAuB;AAEvB,iKAAiK;AACjK,MAAM,SAAU,SAAQ,KAAK;IAI3B,YAAY,OAA0B,EAAE,IAAwB;QAC9D,MAAM,MAAM,GAAG,YAAY,IAAG,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,iBAAiB,EAAE,CAAA,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,MAAa,aAAa;IAWxB,YAAY,SAAY,EAAE,aAAgB;;QAJnC,kBAAa,G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,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,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAG,SAAS,EAAE,MAAM,EAAE,IAAI,CAAC,CAAA;QAC9C,CAAC,CAAA;IACH,CAAC;CACF;AArGD,sCAqGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/AuthErrors/types.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
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);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA4B"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codeleap/auth",
|
|
3
|
-
"version": "7.0.
|
|
4
|
-
"main": "
|
|
3
|
+
"version": "7.0.2",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
@@ -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.1",
|
|
26
|
+
"@codeleap/types": "7.0.1",
|
|
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.1",
|
|
35
35
|
"typescript": "5.5.2"
|
|
36
36
|
}
|
|
37
37
|
}
|