@riao/iam 1.0.0 → 2.0.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/auth/auth-migrations.d.ts +4 -0
- package/auth/auth-migrations.js +12 -0
- package/auth/auth-migrations.js.map +1 -0
- package/auth/auth.d.ts +11 -0
- package/auth/auth.js +18 -0
- package/auth/auth.js.map +1 -0
- package/auth/index.d.ts +1 -0
- package/auth/index.js +6 -0
- package/auth/index.js.map +1 -0
- package/auth/migrations/001-create-accounts-table.d.ts +5 -0
- package/auth/migrations/001-create-accounts-table.js +27 -0
- package/auth/migrations/001-create-accounts-table.js.map +1 -0
- package/authentication/authentication-base/authentication-base.d.ts +10 -0
- package/authentication/authentication-base/authentication-base.js +33 -0
- package/authentication/authentication-base/authentication-base.js.map +1 -0
- package/authentication/authentication-base/index.d.ts +1 -0
- package/authentication/authentication-base/index.js +6 -0
- package/authentication/authentication-base/index.js.map +1 -0
- package/authentication/authentication-fido2/authentication-fido2-migrations.d.ts +5 -0
- package/authentication/authentication-fido2/authentication-fido2-migrations.js +17 -0
- package/authentication/authentication-fido2/authentication-fido2-migrations.js.map +1 -0
- package/authentication/authentication-fido2/authentication-fido2.d.ts +58 -0
- package/authentication/authentication-fido2/authentication-fido2.js +260 -0
- package/authentication/authentication-fido2/authentication-fido2.js.map +1 -0
- package/authentication/authentication-fido2/index.d.ts +1 -0
- package/authentication/authentication-fido2/index.js +6 -0
- package/authentication/authentication-fido2/index.js.map +1 -0
- package/authentication/authentication-fido2/migrations/create-fido-challenges-table.d.ts +5 -0
- package/authentication/authentication-fido2/migrations/create-fido-challenges-table.js +61 -0
- package/authentication/authentication-fido2/migrations/create-fido-challenges-table.js.map +1 -0
- package/authentication/authentication-fido2/migrations/create-fido-credentials-table.d.ts +5 -0
- package/authentication/authentication-fido2/migrations/create-fido-credentials-table.js +68 -0
- package/authentication/authentication-fido2/migrations/create-fido-credentials-table.js.map +1 -0
- package/authentication/authentication-fido2/migrations/index.d.ts +2 -0
- package/authentication/authentication-fido2/migrations/index.js +6 -0
- package/authentication/authentication-fido2/migrations/index.js.map +1 -0
- package/authentication/authentication-magic-token/authentication-magic-token-migrations.d.ts +5 -0
- package/authentication/authentication-magic-token/authentication-magic-token-migrations.js +16 -0
- package/authentication/authentication-magic-token/authentication-magic-token-migrations.js.map +1 -0
- package/authentication/authentication-magic-token/authentication-magic-token.d.ts +25 -0
- package/authentication/authentication-magic-token/authentication-magic-token.js +76 -0
- package/authentication/authentication-magic-token/authentication-magic-token.js.map +1 -0
- package/authentication/authentication-magic-token/index.d.ts +1 -0
- package/authentication/authentication-magic-token/index.js +6 -0
- package/authentication/authentication-magic-token/index.js.map +1 -0
- package/authentication/authentication-magic-token/magic-token.d.ts +17 -0
- package/authentication/authentication-magic-token/magic-token.js +7 -0
- package/authentication/authentication-magic-token/magic-token.js.map +1 -0
- package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.d.ts +5 -0
- package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.js +44 -0
- package/authentication/authentication-magic-token/migrations/001-create-magic-token-table.js.map +1 -0
- package/authentication/authentication-password/authentication-password-migrations.d.ts +5 -0
- package/authentication/authentication-password/authentication-password-migrations.js +16 -0
- package/authentication/authentication-password/authentication-password-migrations.js.map +1 -0
- package/authentication/authentication-password/authentication-password.d.ts +8 -0
- package/authentication/authentication-password/authentication-password.js +28 -0
- package/authentication/authentication-password/authentication-password.js.map +1 -0
- package/authentication/authentication-password/index.d.ts +1 -0
- package/authentication/authentication-password/index.js +6 -0
- package/authentication/authentication-password/index.js.map +1 -0
- package/authentication/authentication-password/migrations/001-add-password-column.d.ts +5 -0
- package/authentication/authentication-password/migrations/001-add-password-column.js +21 -0
- package/authentication/authentication-password/migrations/001-add-password-column.js.map +1 -0
- package/encrypt.d.ts +6 -0
- package/encrypt.js +18 -0
- package/encrypt.js.map +1 -0
- package/hash.d.ts +5 -0
- package/hash.js +15 -0
- package/hash.js.map +1 -0
- package/index.d.ts +1 -2
- package/index.js +4 -18
- package/index.js.map +1 -1
- package/jwt.d.ts +26 -28
- package/jwt.js +54 -83
- package/jwt.js.map +1 -1
- package/keypair.d.ts +24 -24
- package/keypair.js +72 -70
- package/keypair.js.map +1 -1
- package/package.json +31 -10
- package/secret.d.ts +5 -5
- package/secret.js +2 -2
- package/auth.d.ts +0 -11
- package/auth.js +0 -16
- package/auth.js.map +0 -1
- package/authentication-base.d.ts +0 -12
- package/authentication-base.js +0 -48
- package/authentication-base.js.map +0 -1
- package/authentication-password.d.ts +0 -11
- package/authentication-password.js +0 -43
- package/authentication-password.js.map +0 -1
- package/authentication-passwordless.d.ts +0 -24
- package/authentication-passwordless.js +0 -55
- package/authentication-passwordless.js.map +0 -1
- package/authorization-abac.d.ts +0 -8
- package/authorization-abac.js +0 -33
- package/authorization-abac.js.map +0 -1
- package/authorization-base.d.ts +0 -17
- package/authorization-base.js +0 -30
- package/authorization-base.js.map +0 -1
- package/authorization-hmm.d.ts +0 -0
- package/authorization-hmm.js +0 -173
- package/authorization-hmm.js.map +0 -1
- package/authorization-rbac.d.ts +0 -14
- package/authorization-rbac.js +0 -61
- package/authorization-rbac.js.map +0 -1
- package/errors/authentication-error.d.ts +0 -3
- package/errors/authentication-error.js +0 -8
- package/errors/authentication-error.js.map +0 -1
- package/errors/authorization-error.d.ts +0 -3
- package/errors/authorization-error.js +0 -8
- package/errors/authorization-error.js.map +0 -1
- package/errors/error.d.ts +0 -2
- package/errors/error.js +0 -7
- package/errors/error.js.map +0 -1
- package/iam.d.ts +0 -40
- package/iam.js +0 -73
- package/iam.js.map +0 -1
- package/migrations/1725221752756-create-users-table.d.ts +0 -7
- package/migrations/1725221752756-create-users-table.js +0 -36
- package/migrations/1725221752756-create-users-table.js.map +0 -1
- package/migrations/1725221859886-create-roles-table.d.ts +0 -7
- package/migrations/1725221859886-create-roles-table.js +0 -36
- package/migrations/1725221859886-create-roles-table.js.map +0 -1
- package/migrations/1725221896876-create-permissions-table.d.ts +0 -7
- package/migrations/1725221896876-create-permissions-table.js +0 -41
- package/migrations/1725221896876-create-permissions-table.js.map +0 -1
- package/migrations/1725221935064-create-role-permissions-table.d.ts +0 -7
- package/migrations/1725221935064-create-role-permissions-table.js +0 -56
- package/migrations/1725221935064-create-role-permissions-table.js.map +0 -1
- package/migrations/1725221951873-create-user-roles-table.d.ts +0 -7
- package/migrations/1725221951873-create-user-roles-table.js +0 -56
- package/migrations/1725221951873-create-user-roles-table.js.map +0 -1
- package/migrations/index.d.ts +0 -5
- package/migrations/index.js +0 -22
- package/migrations/index.js.map +0 -1
- package/token.d.ts +0 -13
- package/token.js +0 -3
- package/token.js.map +0 -1
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AuthenticationPasswordless = exports.defaultTokenOptions = void 0;
|
|
13
|
-
const authentication_base_1 = require("./authentication-base");
|
|
14
|
-
const jwt_1 = require("./jwt");
|
|
15
|
-
const authentication_error_1 = require("./errors/authentication-error");
|
|
16
|
-
exports.defaultTokenOptions = {
|
|
17
|
-
expiresIn: '5m',
|
|
18
|
-
};
|
|
19
|
-
class AuthenticationPasswordless extends authentication_base_1.AuthenticationBase {
|
|
20
|
-
constructor(options) {
|
|
21
|
-
super(options);
|
|
22
|
-
this.jwt = new jwt_1.Jwt(options.jwt);
|
|
23
|
-
}
|
|
24
|
-
getMagicToken(credentials, options = exports.defaultTokenOptions) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
// Check user
|
|
27
|
-
const user = yield this.findActiveUser({
|
|
28
|
-
where: { [this.loginColumn]: credentials.login },
|
|
29
|
-
});
|
|
30
|
-
// Generate & return token
|
|
31
|
-
return yield this.jwt.generateToken({
|
|
32
|
-
type: 'magic-link',
|
|
33
|
-
userId: user.id,
|
|
34
|
-
}, {
|
|
35
|
-
expiresIn: options.expiresIn,
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
login(credentials) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
// Verify magic token
|
|
42
|
-
const data = yield this.jwt.decodeToken(credentials.token);
|
|
43
|
-
if (data.type !== 'magic-link') {
|
|
44
|
-
throw new authentication_error_1.AuthenticationError('Wrong type of token provided for this operation.');
|
|
45
|
-
}
|
|
46
|
-
// Check user
|
|
47
|
-
const user = yield this.findActiveUser({
|
|
48
|
-
where: { id: data.userId },
|
|
49
|
-
});
|
|
50
|
-
return user;
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
exports.AuthenticationPasswordless = AuthenticationPasswordless;
|
|
55
|
-
//# sourceMappingURL=authentication-passwordless.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-passwordless.js","sourceRoot":"","sources":["../../src/authentication-passwordless.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,+DAG+B;AAC/B,+BAA+C;AAC/C,wEAAoE;AAgBvD,QAAA,mBAAmB,GAAiB;IAChD,SAAS,EAAE,IAAI;CACf,CAAC;AAEF,MAAa,0BAEX,SAAQ,wCAAyB;IAGlC,YAAmB,OAA0C;QAC5D,KAAK,CAAC,OAAO,CAAC,CAAC;QAEf,IAAI,CAAC,GAAG,GAAG,IAAI,SAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAEY,aAAa,CACzB,WAA8B,EAC9B,UAAwB,2BAAmB;;YAE3C,aAAa;YACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;gBACtC,KAAK,EAAO,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,KAAK,EAAE;aACrD,CAAC,CAAC;YAEH,0BAA0B;YAC1B,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CAClC;gBACC,IAAI,EAAE,YAAY;gBAClB,MAAM,EAAE,IAAI,CAAC,EAAE;aACf,EACD;gBACC,SAAS,EAAE,OAAO,CAAC,SAAS;aAC5B,CACD,CAAC;QACH,CAAC;KAAA;IAEY,KAAK,CAAC,WAA8B;;YAChD,qBAAqB;YACrB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAE3D,IAAI,IAAI,CAAC,IAAI,KAAK,YAAY,EAAE;gBAC/B,MAAM,IAAI,0CAAmB,CAC5B,kDAAkD,CAClD,CAAC;aACF;YAED,aAAa;YACb,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC;gBACtC,KAAK,EAAO,EAAE,EAAE,EAAE,IAAI,CAAC,MAAM,EAAE;aAC/B,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC;QACb,CAAC;KAAA;CACD;AAjDD,gEAiDC"}
|
package/authorization-abac.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { AuthorizationBase, AuthorizationLookup } from './authorization-base';
|
|
2
|
-
import { AuthOptions } from './auth';
|
|
3
|
-
export type AttributeBasedAuthorizationOptions = AuthOptions;
|
|
4
|
-
export declare class AttributeBasedAuthorization extends AuthorizationBase {
|
|
5
|
-
constructor(options: AttributeBasedAuthorizationOptions);
|
|
6
|
-
checkQuery(lookup: AuthorizationLookup): Promise<boolean>;
|
|
7
|
-
check(lookup: AuthorizationLookup): Promise<void>;
|
|
8
|
-
}
|
package/authorization-abac.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AttributeBasedAuthorization = void 0;
|
|
13
|
-
const authorization_base_1 = require("./authorization-base");
|
|
14
|
-
const authorization_error_1 = require("./errors/authorization-error");
|
|
15
|
-
class AttributeBasedAuthorization extends authorization_base_1.AuthorizationBase {
|
|
16
|
-
constructor(options) {
|
|
17
|
-
super(options);
|
|
18
|
-
}
|
|
19
|
-
checkQuery(lookup) {
|
|
20
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
21
|
-
return false;
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
check(lookup) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
if (!(yield this.checkQuery(lookup))) {
|
|
27
|
-
throw new authorization_error_1.AuthorizationError();
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
exports.AttributeBasedAuthorization = AttributeBasedAuthorization;
|
|
33
|
-
//# sourceMappingURL=authorization-abac.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-abac.js","sourceRoot":"","sources":["../../src/authorization-abac.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,6DAA8E;AAC9E,sEAAkE;AAKlE,MAAa,2BAA4B,SAAQ,sCAAiB;IACjE,YAAmB,OAA2C;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAC;IAChB,CAAC;IAEY,UAAU,CAAC,MAA2B;;YAClD,OAAO,KAAK,CAAC;QACd,CAAC;KAAA;IAEY,KAAK,CAAC,MAA2B;;YAC7C,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE;gBACrC,MAAM,IAAI,wCAAkB,EAAE,CAAC;aAC/B;QACF,CAAC;KAAA;CACD;AAdD,kEAcC"}
|
package/authorization-base.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { DatabaseRecord, DatabaseRecordId } from '@riao/dbal';
|
|
2
|
-
import { AuthBase } from './auth';
|
|
3
|
-
export declare enum CrudActions {
|
|
4
|
-
CREATE = "c",
|
|
5
|
-
READ = "r",
|
|
6
|
-
UPDATE = "u",
|
|
7
|
-
DELETE = "d"
|
|
8
|
-
}
|
|
9
|
-
export type Action = string | CrudActions;
|
|
10
|
-
export interface AuthorizationLookup {
|
|
11
|
-
userId: DatabaseRecordId;
|
|
12
|
-
action: Action;
|
|
13
|
-
model?: string;
|
|
14
|
-
}
|
|
15
|
-
export declare abstract class AuthorizationBase<TUser extends DatabaseRecord = DatabaseRecord> extends AuthBase<TUser> {
|
|
16
|
-
check(lookup: AuthorizationLookup): Promise<void>;
|
|
17
|
-
}
|
package/authorization-base.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AuthorizationBase = exports.CrudActions = void 0;
|
|
13
|
-
const authorization_error_1 = require("./errors/authorization-error");
|
|
14
|
-
const auth_1 = require("./auth");
|
|
15
|
-
var CrudActions;
|
|
16
|
-
(function (CrudActions) {
|
|
17
|
-
CrudActions["CREATE"] = "c";
|
|
18
|
-
CrudActions["READ"] = "r";
|
|
19
|
-
CrudActions["UPDATE"] = "u";
|
|
20
|
-
CrudActions["DELETE"] = "d";
|
|
21
|
-
})(CrudActions = exports.CrudActions || (exports.CrudActions = {}));
|
|
22
|
-
class AuthorizationBase extends auth_1.AuthBase {
|
|
23
|
-
check(lookup) {
|
|
24
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
throw new authorization_error_1.AuthorizationError();
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.AuthorizationBase = AuthorizationBase;
|
|
30
|
-
//# sourceMappingURL=authorization-base.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-base.js","sourceRoot":"","sources":["../../src/authorization-base.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,sEAAkE;AAClE,iCAAkC;AAElC,IAAY,WAKX;AALD,WAAY,WAAW;IACtB,2BAAY,CAAA;IACZ,yBAAU,CAAA;IACV,2BAAY,CAAA;IACZ,2BAAY,CAAA;AACb,CAAC,EALW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAKtB;AAUD,MAAsB,iBAEpB,SAAQ,eAAe;IACX,KAAK,CAAC,MAA2B;;YAC7C,MAAM,IAAI,wCAAkB,EAAE,CAAC;QAChC,CAAC;KAAA;CACD;AAND,8CAMC"}
|
package/authorization-hmm.d.ts
DELETED
|
File without changes
|
package/authorization-hmm.js
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
// import {
|
|
2
|
-
// and,
|
|
3
|
-
// columnName,
|
|
4
|
-
// Database,
|
|
5
|
-
// DatabaseRecordId,
|
|
6
|
-
// DeleteOptions,
|
|
7
|
-
// InsertOptions,
|
|
8
|
-
// QueryRepository,
|
|
9
|
-
// or,
|
|
10
|
-
// SelectQuery,
|
|
11
|
-
// UpdateOptions,
|
|
12
|
-
// DatabaseRecord,
|
|
13
|
-
// } from '@riao/dbal';
|
|
14
|
-
// import { Action } from './action';
|
|
15
|
-
// import { ActionEnum } from './action';
|
|
16
|
-
// import { AuthorizationError } from './errors/authorization-error';
|
|
17
|
-
// export class Permission {
|
|
18
|
-
// // If the model is null, access is global (meaning access to all models)
|
|
19
|
-
// model?: string;
|
|
20
|
-
// // If the column is null, access is model-global (meaning access to all
|
|
21
|
-
// // columns on the model)
|
|
22
|
-
// column?: string;
|
|
23
|
-
// // The action, e.g. create, update, or a custom action
|
|
24
|
-
// action: Action;
|
|
25
|
-
// }
|
|
26
|
-
// export interface LookupInterface {
|
|
27
|
-
// userId: DatabaseRecordId;
|
|
28
|
-
// action: Action;
|
|
29
|
-
// model: string;
|
|
30
|
-
// column?: string;
|
|
31
|
-
// }
|
|
32
|
-
// export interface AuthorizationOptions {
|
|
33
|
-
// db: Database;
|
|
34
|
-
// }
|
|
35
|
-
// export abstract class AuthorizationBase {
|
|
36
|
-
// protected db: Database;
|
|
37
|
-
// public constructor(options: AuthorizationOptions) {
|
|
38
|
-
// this.db = options.db;
|
|
39
|
-
// }
|
|
40
|
-
// public async lookupPermissions(
|
|
41
|
-
// lookup: LookupInterface
|
|
42
|
-
// ): Promise<Permission[]> {
|
|
43
|
-
// return [];
|
|
44
|
-
// }
|
|
45
|
-
// protected async getColumnAccess(
|
|
46
|
-
// lookup: LookupInterface
|
|
47
|
-
// ): Promise<{ hasModelAccess: boolean; columns: string[] }> {
|
|
48
|
-
// // TODO: Only fetch necessary permission columns
|
|
49
|
-
// const permissions = await this.lookupPermissions(lookup);
|
|
50
|
-
// const columns: string[] = [];
|
|
51
|
-
// for (const permission of permissions) {
|
|
52
|
-
// if (
|
|
53
|
-
// permission.column === null &&
|
|
54
|
-
// (permission.model === null ||
|
|
55
|
-
// (lookup.model &&
|
|
56
|
-
// permission.model === lookup.model &&
|
|
57
|
-
// lookup.action === permission.action))
|
|
58
|
-
// ) {
|
|
59
|
-
// // User has permission globally or for all columns on model
|
|
60
|
-
// return { hasModelAccess: true, columns: [] };
|
|
61
|
-
// }
|
|
62
|
-
// else {
|
|
63
|
-
// // Append column to array, to check column by column later
|
|
64
|
-
// columns.push(permission.column);
|
|
65
|
-
// }
|
|
66
|
-
// }
|
|
67
|
-
// return { hasModelAccess: false, columns };
|
|
68
|
-
// }
|
|
69
|
-
// public async create(options: {
|
|
70
|
-
// userId: DatabaseRecordId;
|
|
71
|
-
// model: string;
|
|
72
|
-
// records: DatabaseRecord | DatabaseRecord[];
|
|
73
|
-
// }) {
|
|
74
|
-
// const { hasModelAccess, columns } = await this.getColumnAccess({
|
|
75
|
-
// model: options.model,
|
|
76
|
-
// userId: options.userId,
|
|
77
|
-
// action: ActionEnum.CREATE,
|
|
78
|
-
// });
|
|
79
|
-
// if (!hasModelAccess) {
|
|
80
|
-
// const records: DatabaseRecord[] = Array.isArray(options.records)
|
|
81
|
-
// ? options.records
|
|
82
|
-
// : [options.records];
|
|
83
|
-
// for (const record of records) {
|
|
84
|
-
// for (const key in record) {
|
|
85
|
-
// if (!columns.includes(key)) {
|
|
86
|
-
// this.fail({
|
|
87
|
-
// userId: options.userId,
|
|
88
|
-
// model: options.model,
|
|
89
|
-
// column: key,
|
|
90
|
-
// action: ActionEnum.CREATE,
|
|
91
|
-
// });
|
|
92
|
-
// }
|
|
93
|
-
// }
|
|
94
|
-
// }
|
|
95
|
-
// }
|
|
96
|
-
// return await this.db.query.insert({
|
|
97
|
-
// table: options.model, // TODO: Validate
|
|
98
|
-
// records: options.records,
|
|
99
|
-
// });
|
|
100
|
-
// }
|
|
101
|
-
// public async read(options: {
|
|
102
|
-
// userId: DatabaseRecordId;
|
|
103
|
-
// query: SelectQuery;
|
|
104
|
-
// }) {
|
|
105
|
-
// const { hasModelAccess, columns } = await this.getColumnAccess({
|
|
106
|
-
// model: options.query.table,
|
|
107
|
-
// userId: options.userId,
|
|
108
|
-
// action: ActionEnum.READ,
|
|
109
|
-
// });
|
|
110
|
-
// // Check columns
|
|
111
|
-
// for (const column of options.query.columns) {
|
|
112
|
-
// if (typeof column !== 'string') {
|
|
113
|
-
// throw new AuthorizationError('Can only select column names');
|
|
114
|
-
// }
|
|
115
|
-
// if (!hasModelAccess && !columns.includes(column)) {
|
|
116
|
-
// throw new AuthorizationError(
|
|
117
|
-
// 'Access denied on column ' + column
|
|
118
|
-
// );
|
|
119
|
-
// }
|
|
120
|
-
// }
|
|
121
|
-
// // TODO: Check Join
|
|
122
|
-
// for (const join of options.query.join) {
|
|
123
|
-
// // TODO: To join, the user must have access to:
|
|
124
|
-
// // 1. The relation column on the parent model
|
|
125
|
-
// // 2. Any/all columns on the joined table
|
|
126
|
-
// // 3. Columns in the `on` clause
|
|
127
|
-
// }
|
|
128
|
-
// // TODO: Where
|
|
129
|
-
// // TODO: Group by
|
|
130
|
-
// // TODO: Having
|
|
131
|
-
// // TODO: Order by
|
|
132
|
-
// // TODO: Schema permission check
|
|
133
|
-
// // TODO: Need to check all parts of query, e.g. grouping, order, etc.
|
|
134
|
-
// return await this.db.query.find(options.query);
|
|
135
|
-
// }
|
|
136
|
-
// public async readOne(options: {
|
|
137
|
-
// userId: DatabaseRecordId;
|
|
138
|
-
// update: UpdateOptions;
|
|
139
|
-
// }) {}
|
|
140
|
-
// public async update(options: {
|
|
141
|
-
// userId: DatabaseRecordId;
|
|
142
|
-
// update: UpdateOptions;
|
|
143
|
-
// }) {
|
|
144
|
-
// // TODO: Check model
|
|
145
|
-
// // TODO: Need to check all update options - e.g. join, etc.?
|
|
146
|
-
// // TODO: Check options.update.where, similar to read()
|
|
147
|
-
// // TODO: Check options.update.set, similar to insert()
|
|
148
|
-
// return await this.db.query.update(options.update);
|
|
149
|
-
// }
|
|
150
|
-
// public async delete(options: {
|
|
151
|
-
// userId: DatabaseRecordId;
|
|
152
|
-
// delete: DeleteOptions;
|
|
153
|
-
// }) {
|
|
154
|
-
// // TODO: Check model permission
|
|
155
|
-
// // TODO: Need to check all delete options - e.g. join, etc.?
|
|
156
|
-
// // TODO: Check options.update.where, similar to read()
|
|
157
|
-
// return await this.db.query.delete(options.delete);
|
|
158
|
-
// }
|
|
159
|
-
// public async getUserScopes(userId: DatabaseRecordId): Promise<string[]> {
|
|
160
|
-
// return [];
|
|
161
|
-
// }
|
|
162
|
-
// protected async fail(lookup: LookupInterface): Promise<void> {
|
|
163
|
-
// let message = `User "${lookup.userId}" cannot "${lookup.action}"`;
|
|
164
|
-
// if ('model' in lookup && 'column' in lookup) {
|
|
165
|
-
// message += ` on "${lookup.model}.${lookup.column}"`;
|
|
166
|
-
// }
|
|
167
|
-
// else if ('model' in lookup) {
|
|
168
|
-
// message += ` on model "${lookup.model}"`;
|
|
169
|
-
// }
|
|
170
|
-
// throw new Error(message);
|
|
171
|
-
// }
|
|
172
|
-
// }
|
|
173
|
-
//# sourceMappingURL=authorization-hmm.js.map
|
package/authorization-hmm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-hmm.js","sourceRoot":"","sources":["../../src/authorization-hmm.ts"],"names":[],"mappings":"AAAA,WAAW;AACX,QAAQ;AACR,eAAe;AACf,aAAa;AACb,qBAAqB;AACrB,kBAAkB;AAClB,kBAAkB;AAClB,oBAAoB;AACpB,OAAO;AACP,gBAAgB;AAChB,kBAAkB;AAClB,mBA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,QAAQ;AACR,KAAK;AAEL,gCAAgC;AAChC,8BAA8B;AAC9B,wBAAwB;AACxB,QAAQ;AACR,qEAAqE;AACrE,iCAAiC;AACjC,6BAA6B;AAC7B,8BAA8B;AAC9B,QAAQ;AAER,qBAAqB;AACrB,kDAAkD;AAClD,uCAAuC;AACvC,oEAAoE;AACpE,OAAO;AAEP,yDAAyD;AACzD,oCAAoC;AACpC,2CAA2C;AAC3C,SAAS;AACT,OAAO;AACP,MAAM;AAEN,wBAAwB;AACxB,6CAA6C;AAC7C,qDAAqD;AACrD,mDAAmD;AACnD,+CAA+C;AAC/C,uCAAuC;AACvC,MAAM;AAEN,mBAAmB;AACnB,sBAAsB;AACtB,oBAAoB;AACpB,sBAAsB;AAEtB,qCAAqC;AACrC,0EAA0E;AAE1E,oDAAoD;AACpD,KAAK;AAEL,mCAAmC;AACnC,8BAA8B;AAC9B,2BAA2B;AAC3B,SAAS;AAET,kCAAkC;AAClC,8BAA8B;AAC9B,2BAA2B;AAC3B,QAAQ;AACR,yBAAyB;AACzB,iEAAiE;AAEjE,2DAA2D;AAC3D,2DAA2D;AAE3D,uDAAuD;AACvD,KAAK;AAEL,kCAAkC;AAClC,8BAA8B;AAC9B,2BAA2B;AAC3B,QAAQ;AACR,oCAAoC;AACpC,iEAAiE;AAEjE,2DAA2D;AAE3D,uDAAuD;AACvD,KAAK;AAEL,6EAA6E;AAC7E,eAAe;AACf,KAAK;AAEL,kEAAkE;AAClE,uEAAuE;AAEvE,mDAAmD;AACnD,0DAA0D;AAC1D,MAAM;AACN,kCAAkC;AAClC,+CAA+C;AAC/C,MAAM;AAEN,8BAA8B;AAC9B,KAAK;AACL,IAAI"}
|
package/authorization-rbac.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { AuthorizationBase, AuthorizationLookup } from './authorization-base';
|
|
2
|
-
import { AuthOptions } from './auth';
|
|
3
|
-
export interface RoleBasedAuthorizationOptions extends AuthOptions {
|
|
4
|
-
permissionTable?: string;
|
|
5
|
-
userRoleTable?: string;
|
|
6
|
-
rolePermissionTable?: string;
|
|
7
|
-
}
|
|
8
|
-
export declare class RoleBasedAuthorization extends AuthorizationBase {
|
|
9
|
-
protected permissionTable: any;
|
|
10
|
-
protected userRoleTable: any;
|
|
11
|
-
protected rolePermissionTable: any;
|
|
12
|
-
constructor(options: RoleBasedAuthorizationOptions);
|
|
13
|
-
check(lookup: AuthorizationLookup): Promise<void>;
|
|
14
|
-
}
|
package/authorization-rbac.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.RoleBasedAuthorization = void 0;
|
|
13
|
-
const dbal_1 = require("@riao/dbal");
|
|
14
|
-
const authorization_base_1 = require("./authorization-base");
|
|
15
|
-
const authorization_error_1 = require("./errors/authorization-error");
|
|
16
|
-
class RoleBasedAuthorization extends authorization_base_1.AuthorizationBase {
|
|
17
|
-
constructor(options) {
|
|
18
|
-
var _a, _b, _c, _d, _e, _f;
|
|
19
|
-
super(options);
|
|
20
|
-
this.permissionTable =
|
|
21
|
-
(_b = (_a = options.permissionTable) !== null && _a !== void 0 ? _a : this.permissionTable) !== null && _b !== void 0 ? _b : 'permissions';
|
|
22
|
-
this.userRoleTable =
|
|
23
|
-
(_d = (_c = options.userRoleTable) !== null && _c !== void 0 ? _c : this.userRoleTable) !== null && _d !== void 0 ? _d : 'user_roles';
|
|
24
|
-
this.rolePermissionTable =
|
|
25
|
-
(_f = (_e = options.rolePermissionTable) !== null && _e !== void 0 ? _e : this.rolePermissionTable) !== null && _f !== void 0 ? _f : 'role_permissions';
|
|
26
|
-
}
|
|
27
|
-
check(lookup) {
|
|
28
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
-
const found = yield this.db.query.findOne({
|
|
30
|
-
table: this.permissionTable,
|
|
31
|
-
columns: [`${this.permissionTable}.id`],
|
|
32
|
-
join: [
|
|
33
|
-
{
|
|
34
|
-
type: 'INNER',
|
|
35
|
-
table: this.rolePermissionTable,
|
|
36
|
-
on: {
|
|
37
|
-
[`${this.rolePermissionTable}.permission_id`]: (0, dbal_1.columnName)(`${this.permissionTable}.id`),
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
type: 'INNER',
|
|
42
|
-
table: this.userRoleTable,
|
|
43
|
-
on: {
|
|
44
|
-
[`${this.userRoleTable}.role_id`]: (0, dbal_1.columnName)(`${this.rolePermissionTable}.role_id`),
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
],
|
|
48
|
-
where: {
|
|
49
|
-
[`${this.userRoleTable}.user_id`]: lookup.userId,
|
|
50
|
-
[`${this.permissionTable}.action`]: lookup.action,
|
|
51
|
-
[`${this.permissionTable}.model`]: lookup.model,
|
|
52
|
-
},
|
|
53
|
-
});
|
|
54
|
-
if (!found) {
|
|
55
|
-
throw new authorization_error_1.AuthorizationError();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.RoleBasedAuthorization = RoleBasedAuthorization;
|
|
61
|
-
//# sourceMappingURL=authorization-rbac.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-rbac.js","sourceRoot":"","sources":["../../src/authorization-rbac.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,EAAE,MAAM,CAAC,MAAM;oBAChD,CAAC,GAAG,IAAI,CAAC,eAAe,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM;oBACjD,CAAC,GAAG,IAAI,CAAC,eAAe,QAAQ,CAAC,EAAE,MAAM,CAAC,KAAK;iBAC/C;aACD,CAAC,CAAC;YAEH,IAAI,CAAC,KAAK,EAAE;gBACX,MAAM,IAAI,wCAAkB,EAAE,CAAC;aAC/B;QACF,CAAC;KAAA;CACD;AApDD,wDAoDC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthenticationError = void 0;
|
|
4
|
-
const error_1 = require("./error");
|
|
5
|
-
class AuthenticationError extends error_1.IamError {
|
|
6
|
-
}
|
|
7
|
-
exports.AuthenticationError = AuthenticationError;
|
|
8
|
-
//# sourceMappingURL=authentication-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authentication-error.js","sourceRoot":"","sources":["../../../src/errors/authentication-error.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAEnC,MAAa,mBAAoB,SAAQ,gBAAQ;CAAG;AAApD,kDAAoD"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AuthorizationError = void 0;
|
|
4
|
-
const error_1 = require("./error");
|
|
5
|
-
class AuthorizationError extends error_1.IamError {
|
|
6
|
-
}
|
|
7
|
-
exports.AuthorizationError = AuthorizationError;
|
|
8
|
-
//# sourceMappingURL=authorization-error.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"authorization-error.js","sourceRoot":"","sources":["../../../src/errors/authorization-error.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AAEnC,MAAa,kBAAmB,SAAQ,gBAAQ;CAAG;AAAnD,gDAAmD"}
|
package/errors/error.d.ts
DELETED
package/errors/error.js
DELETED
package/errors/error.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error.js","sourceRoot":"","sources":["../../../src/errors/error.ts"],"names":[],"mappings":";;;AAAA,MAAa,QAAS,SAAQ,KAAK;CAAG;AAAtC,4BAAsC"}
|
package/iam.d.ts
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { DatabaseRecordId } from '@riao/dbal';
|
|
2
|
-
import { Jwt } from './jwt';
|
|
3
|
-
import { AccessTokenPayload } from './token';
|
|
4
|
-
import { AuthenticationBase } from './authentication-base';
|
|
5
|
-
export interface IamOptions {
|
|
6
|
-
authn?: AuthenticationBase;
|
|
7
|
-
jwt?: Jwt;
|
|
8
|
-
accessTTL?: string;
|
|
9
|
-
refreshTTL?: string;
|
|
10
|
-
}
|
|
11
|
-
export interface LoginInterface {
|
|
12
|
-
login: string;
|
|
13
|
-
}
|
|
14
|
-
export declare class Iam<TLogin extends LoginInterface = LoginInterface> {
|
|
15
|
-
protected authn: AuthenticationBase;
|
|
16
|
-
protected jwt: Jwt;
|
|
17
|
-
protected accessTTL: string;
|
|
18
|
-
protected refreshTTL: string;
|
|
19
|
-
constructor(options?: IamOptions);
|
|
20
|
-
login(credentials: TLogin): Promise<{
|
|
21
|
-
userId: DatabaseRecordId;
|
|
22
|
-
access: import("./jwt").Token;
|
|
23
|
-
refresh: import("./jwt").Token;
|
|
24
|
-
}>;
|
|
25
|
-
verifyAccessToken(options: {
|
|
26
|
-
userId?: DatabaseRecordId;
|
|
27
|
-
accessToken: string;
|
|
28
|
-
}): Promise<Omit<AccessTokenPayload, 'type'>>;
|
|
29
|
-
refresh(userId: DatabaseRecordId, token: string): Promise<{
|
|
30
|
-
userId: DatabaseRecordId;
|
|
31
|
-
access: import("./jwt").Token;
|
|
32
|
-
}>;
|
|
33
|
-
protected getAccessToken(userId: DatabaseRecordId): Promise<import("./jwt").Token>;
|
|
34
|
-
protected getRefreshToken(userId: DatabaseRecordId): Promise<import("./jwt").Token>;
|
|
35
|
-
protected getAuthTokens(userId: DatabaseRecordId): Promise<{
|
|
36
|
-
userId: DatabaseRecordId;
|
|
37
|
-
access: import("./jwt").Token;
|
|
38
|
-
refresh: import("./jwt").Token;
|
|
39
|
-
}>;
|
|
40
|
-
}
|
package/iam.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.Iam = void 0;
|
|
13
|
-
const authentication_error_1 = require("./errors/authentication-error");
|
|
14
|
-
class Iam {
|
|
15
|
-
constructor(options = {}) {
|
|
16
|
-
var _a, _b, _c, _d;
|
|
17
|
-
this.accessTTL = '15m';
|
|
18
|
-
this.refreshTTL = '7d';
|
|
19
|
-
this.authn = (_a = options.authn) !== null && _a !== void 0 ? _a : this.authn;
|
|
20
|
-
this.jwt = (_b = options.jwt) !== null && _b !== void 0 ? _b : this.jwt;
|
|
21
|
-
this.accessTTL = (_c = options.accessTTL) !== null && _c !== void 0 ? _c : this.accessTTL;
|
|
22
|
-
this.refreshTTL = (_d = options.refreshTTL) !== null && _d !== void 0 ? _d : this.refreshTTL;
|
|
23
|
-
}
|
|
24
|
-
login(credentials) {
|
|
25
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
-
const user = yield this.authn.login(credentials);
|
|
27
|
-
return yield this.getAuthTokens(user.id);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
verifyAccessToken(options) {
|
|
31
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
-
const payload = (yield this.jwt.verifyAccessToken(options.accessToken));
|
|
33
|
-
if (options.userId && payload.userId !== options.userId) {
|
|
34
|
-
throw new authentication_error_1.AuthenticationError('Provided access token is not for this user');
|
|
35
|
-
}
|
|
36
|
-
return payload;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
refresh(userId, token) {
|
|
40
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
yield this.jwt.verifyRefreshToken(token);
|
|
42
|
-
yield this.authn.findActiveUser({ where: { id: userId } });
|
|
43
|
-
return {
|
|
44
|
-
userId,
|
|
45
|
-
access: yield this.getAccessToken(userId),
|
|
46
|
-
};
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
getAccessToken(userId) {
|
|
50
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
51
|
-
// Generate access token
|
|
52
|
-
return yield this.jwt.generateToken({
|
|
53
|
-
type: 'access',
|
|
54
|
-
userId,
|
|
55
|
-
scopes: [], // TODO: Fetch scopes?
|
|
56
|
-
}, { expiresIn: this.accessTTL });
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
getRefreshToken(userId) {
|
|
60
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
-
return yield this.jwt.generateToken({ type: 'refresh', userId }, { expiresIn: this.refreshTTL });
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
getAuthTokens(userId) {
|
|
65
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
-
const access = yield this.getAccessToken(userId);
|
|
67
|
-
const refresh = yield this.getRefreshToken(userId);
|
|
68
|
-
return { userId, access, refresh };
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|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AM,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,CAAC,CAAC;YAEzC,MAAM,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;YAE3D,OAAO;gBACN,MAAM;gBACN,MAAM,EAAE,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;aACzC,CAAC;QACH,CAAC;KAAA;IAEe,cAAc,CAAC,MAAwB;;YACtD,wBAAwB;YACxB,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CACd;gBACnB,IAAI,EAAE,QAAQ;gBACd,MAAM;gBACN,MAAM,EAAE,EAAE,EAAE,sBAAsB;aAClC,EACD,EAAE,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,CAC7B,CAAC;QACH,CAAC;KAAA;IAEe,eAAe,CAAC,MAAwB;;YACvD,OAAO,MAAM,IAAI,CAAC,GAAG,CAAC,aAAa,CAClC,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,EAC3B,EAAE,SAAS,EAAE,IAAI,CAAC,UAAU,EAAE,CAC9B,CAAC;QACH,CAAC;KAAA;IAEe,aAAa,CAAC,MAAwB;;YACrD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;YACjD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;YAEnD,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;QACpC,CAAC;KAAA;CACD;AAzED,kBAyEC"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.CreateUsersTable = void 0;
|
|
13
|
-
const dbal_1 = require("@riao/dbal");
|
|
14
|
-
const column_pack_1 = require("@riao/dbal/column-pack");
|
|
15
|
-
class CreateUsersTable extends dbal_1.Migration {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
this.tableName = 'users';
|
|
19
|
-
this.columns = [column_pack_1.BigIntKeyColumn, column_pack_1.EmailColumn];
|
|
20
|
-
}
|
|
21
|
-
up() {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
yield this.ddl.createTable({
|
|
24
|
-
name: this.tableName,
|
|
25
|
-
columns: this.columns,
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
down() {
|
|
30
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
31
|
-
yield this.ddl.dropTable({ tables: this.tableName });
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
exports.CreateUsersTable = CreateUsersTable;
|
|
36
|
-
//# sourceMappingURL=1725221752756-create-users-table.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"1725221752756-create-users-table.js","sourceRoot":"","sources":["../../../src/migrations/1725221752756-create-users-table.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,qCAAuC;AACvC,wDAIgC;AAEhC,MAAa,gBAAiB,SAAQ,gBAAS;IAA/C;;QACQ,cAAS,GAAG,OAAO,CAAC;QACpB,YAAO,GAAG,CAAC,6BAAe,EAAE,yBAAW,CAAC,CAAC;IAYjD,CAAC;IAVM,EAAE;;YACP,MAAM,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;gBAC1B,IAAI,EAAE,IAAI,CAAC,SAAS;gBACpB,OAAO,EAAE,IAAI,CAAC,OAAO;aACrB,CAAC,CAAC;QACJ,CAAC;KAAA;IAEK,IAAI;;YACT,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QACtD,CAAC;KAAA;CACD;AAdD,4CAcC"}
|