@novo-learning/service-lib 0.0.1 → 0.0.4
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/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/modules/clients/auth-api/auth-api.module.d.ts +4 -0
- package/dist/modules/clients/auth-api/auth-api.module.js +17 -0
- package/dist/modules/clients/auth-api/auth-api.module.js.map +1 -0
- package/dist/modules/clients/auth-api/auth.d.ts +7 -0
- package/dist/modules/clients/auth-api/auth.js +14 -0
- package/dist/modules/clients/auth-api/auth.js.map +1 -0
- package/dist/modules/clients/auth-api/auth.service.d.ts +13 -0
- package/dist/modules/clients/auth-api/auth.service.js +65 -0
- package/dist/modules/clients/auth-api/auth.service.js.map +1 -0
- package/dist/modules/clients/data-api/data-api.module.d.ts +4 -0
- package/dist/modules/clients/data-api/data-api.module.js +26 -0
- package/dist/modules/clients/data-api/data-api.module.js.map +1 -0
- package/dist/modules/clients/data-api/data.service.d.ts +11 -0
- package/dist/modules/clients/data-api/data.service.js +47 -0
- package/dist/modules/clients/data-api/data.service.js.map +1 -0
- package/dist/modules/clients/exercise-api/exercise-api.module.d.ts +4 -0
- package/dist/modules/clients/exercise-api/exercise-api.module.js +26 -0
- package/dist/modules/clients/exercise-api/exercise-api.module.js.map +1 -0
- package/dist/modules/clients/exercise-api/exercise.service.d.ts +21 -0
- package/dist/modules/clients/exercise-api/exercise.service.js +80 -0
- package/dist/modules/clients/exercise-api/exercise.service.js.map +1 -0
- package/dist/modules/clients/index.d.ts +10 -0
- package/dist/modules/clients/index.js +24 -0
- package/dist/modules/clients/index.js.map +1 -0
- package/dist/modules/clients/pronunciation-api/pronunciation-api.module.d.ts +5 -0
- package/dist/modules/clients/pronunciation-api/pronunciation-api.module.js +19 -0
- package/dist/modules/clients/pronunciation-api/pronunciation-api.module.js.map +1 -0
- package/dist/modules/clients/pronunciation-api/pronunciation.service.d.ts +12 -0
- package/dist/modules/clients/pronunciation-api/pronunciation.service.js +44 -0
- package/dist/modules/clients/pronunciation-api/pronunciation.service.js.map +1 -0
- package/dist/modules/clients/publisher-api/publisher-api.module.d.ts +4 -0
- package/dist/modules/clients/publisher-api/publisher-api.module.js +26 -0
- package/dist/modules/clients/publisher-api/publisher-api.module.js.map +1 -0
- package/dist/modules/clients/publisher-api/publisher.service.d.ts +27 -0
- package/dist/modules/clients/publisher-api/publisher.service.js +85 -0
- package/dist/modules/clients/publisher-api/publisher.service.js.map +1 -0
- package/dist/modules/nest/jwt/decorators/permission.decorator.d.ts +1 -1
- package/dist/modules/nest/jwt/entities/user-data.d.ts +1 -1
- package/dist/modules/nest/jwt/guards/has-permission.guard.js.map +1 -1
- package/dist/modules/nest/jwt/index.d.ts +0 -1
- package/dist/modules/nest/jwt/index.js +0 -1
- package/dist/modules/nest/jwt/index.js.map +1 -1
- package/dist/modules/nest/jwt/jwt.module.d.ts +2 -0
- package/dist/modules/nest/jwt/jwt.module.js +20 -26
- package/dist/modules/nest/jwt/jwt.module.js.map +1 -1
- package/dist/modules/nest/jwt/strategies/jwt.strategy.d.ts +3 -3
- package/dist/modules/nest/jwt/strategies/jwt.strategy.js +8 -5
- package/dist/modules/nest/jwt/strategies/jwt.strategy.js.map +1 -1
- package/package.json +59 -39
- package/dist/modules/nest/jwt/entities/permissions.d.ts +0 -7
- package/dist/modules/nest/jwt/entities/permissions.js +0 -12
- package/dist/modules/nest/jwt/entities/permissions.js.map +0 -1
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -10,5 +10,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./modules/clients"), exports);
|
|
13
14
|
__exportStar(require("./modules/nest/jwt"), exports);
|
|
14
15
|
//# 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":";;;;;;;;;;;;AAAA,qDAAmC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oDAAkC;AAClC,qDAAmC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthApiModule = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const auth_service_1 = require("./auth.service");
|
|
6
|
+
class AuthApiModule {
|
|
7
|
+
static forRoot(authApi) {
|
|
8
|
+
return {
|
|
9
|
+
module: AuthApiModule,
|
|
10
|
+
imports: [common_1.CacheModule.register()],
|
|
11
|
+
providers: [auth_service_1.AuthService, { provide: auth_service_1.AUTH_API, useValue: authApi }],
|
|
12
|
+
exports: [auth_service_1.AuthService],
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.AuthApiModule = AuthApiModule;
|
|
17
|
+
//# sourceMappingURL=auth-api.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-api.module.js","sourceRoot":"","sources":["../../../../src/modules/clients/auth-api/auth-api.module.ts"],"names":[],"mappings":";;;AAAA,2CAA4D;AAC5D,iDAAuD;AAEvD,MAAa,aAAa;IACxB,MAAM,CAAC,OAAO,CAAC,OAAe;QAC5B,OAAO;YACL,MAAM,EAAE,aAAa;YACrB,OAAO,EAAE,CAAC,oBAAW,CAAC,QAAQ,EAAE,CAAC;YACjC,SAAS,EAAE,CAAC,0BAAW,EAAE,EAAE,OAAO,EAAE,uBAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;YAClE,OAAO,EAAE,CAAC,0BAAW,CAAC;SACvB,CAAC;IACJ,CAAC;CACF;AATD,sCASC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Auth = void 0;
|
|
4
|
+
class Auth {
|
|
5
|
+
constructor(authData) {
|
|
6
|
+
this.authData = authData;
|
|
7
|
+
this.creationTimeAsMs = Date.now();
|
|
8
|
+
}
|
|
9
|
+
accessTokenValid() {
|
|
10
|
+
return this.creationTimeAsMs + this.authData.payload.access_token_expires_in > Date.now();
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.Auth = Auth;
|
|
14
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../../../src/modules/clients/auth-api/auth.ts"],"names":[],"mappings":";;;AAEA,MAAa,IAAI;IAKf,YAA4B,QAAiC;QAAjC,aAAQ,GAAR,QAAQ,CAAyB;QAJ7D,qBAAgB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAIkC,CAAC;IAE1D,gBAAgB;QACrB,OAAO,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,uBAAuB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC5F,CAAC;CACF;AAVD,oBAUC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AuthenticationDataDtoV1, PermissionType } from '@novo-learning/novo-sdk';
|
|
2
|
+
import { Cache } from 'cache-manager';
|
|
3
|
+
export declare const AUTH_API = "AUTH_API";
|
|
4
|
+
export declare class AuthService {
|
|
5
|
+
private readonly apiUrl;
|
|
6
|
+
private readonly cacheManager;
|
|
7
|
+
private makeKey;
|
|
8
|
+
private readonly api;
|
|
9
|
+
constructor(apiUrl: string, cacheManager: Cache);
|
|
10
|
+
login(id: string, token: string, permissions: PermissionType[]): Promise<AuthenticationDataDtoV1 | {
|
|
11
|
+
error: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var AuthService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.AuthService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const novo_sdk_1 = require("@novo-learning/novo-sdk");
|
|
19
|
+
const auth_1 = require("./auth");
|
|
20
|
+
let AuthService = AuthService_1 = class AuthService {
|
|
21
|
+
constructor(apiUrl, cacheManager) {
|
|
22
|
+
this.apiUrl = apiUrl;
|
|
23
|
+
this.cacheManager = cacheManager;
|
|
24
|
+
this.makeKey = (id) => `${AuthService_1.name}-${id}`;
|
|
25
|
+
const url = this.apiUrl.indexOf('https') > -1 ? this.apiUrl : `http://${this.apiUrl}`;
|
|
26
|
+
const config = new novo_sdk_1.AuthApiConfiguration();
|
|
27
|
+
config.formDataCtor = FormData;
|
|
28
|
+
this.api = new novo_sdk_1.AuthApi(config, url);
|
|
29
|
+
}
|
|
30
|
+
async login(id, token, permissions) {
|
|
31
|
+
const auth = await this.cacheManager.get(this.makeKey(id));
|
|
32
|
+
if (auth?.accessTokenValid()) {
|
|
33
|
+
return auth.authData;
|
|
34
|
+
}
|
|
35
|
+
if (this.apiUrl === undefined) {
|
|
36
|
+
return { error: 'Auth API not provided' };
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const sso = auth?.authData?.payload?.refresh_token
|
|
40
|
+
?
|
|
41
|
+
await this.api.refresh({ refresh_token: auth.authData.payload.refresh_token }, { headers: { Authorization: `Bearer ${auth?.authData?.payload?.token}` } })
|
|
42
|
+
:
|
|
43
|
+
await this.api.sso({
|
|
44
|
+
publisherId: id,
|
|
45
|
+
publisherToken: token,
|
|
46
|
+
userData: { userId: 'speech-api', permissions: permissions, publisherId: id },
|
|
47
|
+
}, { headers: { Authorization: `Bearer ${auth?.authData?.payload?.token}` } });
|
|
48
|
+
this.cacheManager.set(this.makeKey(id), new auth_1.Auth(sso.data.data), {
|
|
49
|
+
ttl: sso.data.data.payload.refresh_token_expires_in / 1000,
|
|
50
|
+
});
|
|
51
|
+
return sso.data.data;
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
return { error: `${AuthService_1.name}: ${err.code || err.response?.statusText}` };
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
AuthService = AuthService_1 = __decorate([
|
|
59
|
+
(0, common_1.Injectable)(),
|
|
60
|
+
__param(0, (0, common_1.Inject)(exports.AUTH_API)),
|
|
61
|
+
__param(1, (0, common_1.Inject)(common_1.CACHE_MANAGER)),
|
|
62
|
+
__metadata("design:paramtypes", [String, Object])
|
|
63
|
+
], AuthService);
|
|
64
|
+
exports.AuthService = AuthService;
|
|
65
|
+
//# sourceMappingURL=auth.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.js","sourceRo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
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var DataApiModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DataApiModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const data_service_1 = require("./data.service");
|
|
13
|
+
let DataApiModule = DataApiModule_1 = class DataApiModule {
|
|
14
|
+
static forRoot(dataApi) {
|
|
15
|
+
return {
|
|
16
|
+
module: DataApiModule_1,
|
|
17
|
+
providers: [{ provide: data_service_1.DATA_API, useValue: dataApi }, data_service_1.DataService],
|
|
18
|
+
exports: [data_service_1.DataService],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
DataApiModule = DataApiModule_1 = __decorate([
|
|
23
|
+
(0, common_1.Module)({})
|
|
24
|
+
], DataApiModule);
|
|
25
|
+
exports.DataApiModule = DataApiModule;
|
|
26
|
+
//# sourceMappingURL=data-api.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-api.module.js","sourceRoot":"","sources":["../../../../src/modules/clients/data-api/data-api.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,iDAAuD;AAGvD,IAAa,aAAa,qBAA1B,MAAa,aAAa;IACxB,MAAM,CAAC,OAAO,CAAC,OAAe;QAC5B,OAAO;YACL,MAAM,EAAE,eAAa;YACrB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,uBAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,0BAAW,CAAC;YAClE,OAAO,EAAE,CAAC,0BAAW,CAAC;SACvB,CAAC;IACJ,CAAC;CACF,CAAA;AARY,aAAa;IADzB,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,aAAa,CAQzB;AARY,sCAAa"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AttemptResponseDtoV1, CreateAttemptDtoV1 } from '@novo-learning/novo-sdk';
|
|
3
|
+
export declare const DATA_API = "DATA_API";
|
|
4
|
+
export declare class DataService {
|
|
5
|
+
private apiUrl;
|
|
6
|
+
private readonly api;
|
|
7
|
+
constructor(apiUrl: string);
|
|
8
|
+
writeAttempt(attempt: CreateAttemptDtoV1, audio: Buffer, accessToken: string): Promise<AttemptResponseDtoV1 | {
|
|
9
|
+
error: string;
|
|
10
|
+
}>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var DataService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.DataService = exports.DATA_API = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const novo_sdk_1 = require("@novo-learning/novo-sdk");
|
|
19
|
+
const FormData = require("form-data");
|
|
20
|
+
exports.DATA_API = 'DATA_API';
|
|
21
|
+
let DataService = DataService_1 = class DataService {
|
|
22
|
+
constructor(apiUrl) {
|
|
23
|
+
this.apiUrl = apiUrl;
|
|
24
|
+
const url = this.apiUrl.indexOf('https') > -1 ? this.apiUrl : `http://${this.apiUrl}`;
|
|
25
|
+
const config = new novo_sdk_1.DataApiConfiguration();
|
|
26
|
+
config.formDataCtor = FormData;
|
|
27
|
+
this.api = new novo_sdk_1.DataApi(config, url);
|
|
28
|
+
}
|
|
29
|
+
async writeAttempt(attempt, audio, accessToken) {
|
|
30
|
+
try {
|
|
31
|
+
const { data: response } = await this.api.createAttempt(JSON.stringify(attempt), audio, {
|
|
32
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
33
|
+
});
|
|
34
|
+
return response;
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
return { error: `${DataService_1.name}: ${err.code || err.message || err.response?.statusText}` };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
DataService = DataService_1 = __decorate([
|
|
42
|
+
(0, common_1.Injectable)(),
|
|
43
|
+
__param(0, (0, common_1.Inject)(exports.DATA_API)),
|
|
44
|
+
__metadata("design:paramtypes", [String])
|
|
45
|
+
], DataService);
|
|
46
|
+
exports.DataService = DataService;
|
|
47
|
+
//# sourceMappingURL=data.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data.service.js","sourceRoot":"","sources":["../../../../src/modules/clients/data-api/data.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,sDAAkH;AACl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
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var ExerciseApiModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.ExerciseApiModule = void 0;
|
|
11
|
+
const common_1 = require("@nestjs/common");
|
|
12
|
+
const exercise_service_1 = require("./exercise.service");
|
|
13
|
+
let ExerciseApiModule = ExerciseApiModule_1 = class ExerciseApiModule {
|
|
14
|
+
static forRoot(dataApi) {
|
|
15
|
+
return {
|
|
16
|
+
module: ExerciseApiModule_1,
|
|
17
|
+
providers: [{ provide: exercise_service_1.EXERCISE_API, useValue: dataApi }, exercise_service_1.ExerciseService],
|
|
18
|
+
exports: [exercise_service_1.ExerciseService],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
ExerciseApiModule = ExerciseApiModule_1 = __decorate([
|
|
23
|
+
(0, common_1.Module)({})
|
|
24
|
+
], ExerciseApiModule);
|
|
25
|
+
exports.ExerciseApiModule = ExerciseApiModule;
|
|
26
|
+
//# sourceMappingURL=exercise-api.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exercise-api.module.js","sourceRoot":"","sources":["../../../../src/modules/clients/exercise-api/exercise-api.module.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAuD;AACvD,yDAAmE;AAGnE,IAAa,iBAAiB,yBAA9B,MAAa,iBAAiB;IAC5B,MAAM,CAAC,OAAO,CAAC,OAAe;QAC5B,OAAO;YACL,MAAM,EAAE,mBAAiB;YACzB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,+BAAY,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE,kCAAe,CAAC;YAC1E,OAAO,EAAE,CAAC,kCAAe,CAAC;SAC3B,CAAC;IACJ,CAAC;CACF,CAAA;AARY,iBAAiB;IAD7B,IAAA,eAAM,EAAC,EAAE,CAAC;GACE,iBAAiB,CAQ7B;AARY,8CAAiB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Exercise, ExerciseDescriptorDtoV1, ExerciseType, LanguageCode } from '@novo-learning/novo-sdk';
|
|
2
|
+
export declare type ExerciseFilter = {
|
|
3
|
+
languageCode?: LanguageCode;
|
|
4
|
+
exerciseType?: ExerciseType;
|
|
5
|
+
customFilter?: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const EXERCISE_API = "EXERCISE_API";
|
|
8
|
+
export declare class ExerciseService {
|
|
9
|
+
private readonly apiUrl;
|
|
10
|
+
private readonly api;
|
|
11
|
+
constructor(apiUrl: string);
|
|
12
|
+
getExercises({ languageCode, exerciseType, customFilter }: ExerciseFilter, accessToken: string): Promise<ExerciseDescriptorDtoV1[] | {
|
|
13
|
+
error: string;
|
|
14
|
+
}>;
|
|
15
|
+
getExercise(id: string, accessToken: string): Promise<Exercise | {
|
|
16
|
+
error: string;
|
|
17
|
+
}>;
|
|
18
|
+
saveExercise(exercise: Exercise, accessToken: string): Promise<Exercise | {
|
|
19
|
+
error: string;
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var ExerciseService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.ExerciseService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const novo_sdk_1 = require("@novo-learning/novo-sdk");
|
|
19
|
+
let ExerciseService = ExerciseService_1 = class ExerciseService {
|
|
20
|
+
constructor(apiUrl) {
|
|
21
|
+
this.apiUrl = apiUrl;
|
|
22
|
+
const url = this.apiUrl.indexOf('https') > -1 ? this.apiUrl : `http://${this.apiUrl}`;
|
|
23
|
+
this.api = new novo_sdk_1.ExerciseApi(undefined, url);
|
|
24
|
+
}
|
|
25
|
+
async getExercises({ languageCode, exerciseType, customFilter }, accessToken) {
|
|
26
|
+
try {
|
|
27
|
+
const { data: exercises } = await this.api.getExerciseListV1(customFilter, exerciseType, languageCode, {
|
|
28
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
29
|
+
});
|
|
30
|
+
return exercises;
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
return { error: `${ExerciseService_1.name}: ${err.code || err.response?.statusText}` };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async getExercise(id, accessToken) {
|
|
37
|
+
try {
|
|
38
|
+
const { data: exercise } = await this.api.getExerciseV1(id, {
|
|
39
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
40
|
+
});
|
|
41
|
+
return {
|
|
42
|
+
...exercise,
|
|
43
|
+
publisherId: '',
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
return { error: `${ExerciseService_1.name}: ${err.code || err.response?.statusText}` };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async saveExercise(exercise, accessToken) {
|
|
51
|
+
try {
|
|
52
|
+
if (exercise.id === undefined) {
|
|
53
|
+
const { data: responseExercise } = await this.api.createExerciseV1(exercise, {
|
|
54
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
55
|
+
});
|
|
56
|
+
return {
|
|
57
|
+
...responseExercise,
|
|
58
|
+
publisherId: '',
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
const { data: responseExercise } = await this.api.replaceExerciseV1(exercise.id, exercise);
|
|
63
|
+
return {
|
|
64
|
+
...responseExercise,
|
|
65
|
+
publisherId: '',
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
return { error: `${ExerciseService_1.name}: ${err.code || err.response?.statusText}` };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
ExerciseService = ExerciseService_1 = __decorate([
|
|
75
|
+
(0, common_1.Injectable)(),
|
|
76
|
+
__param(0, (0, common_1.Inject)(exports.EXERCISE_API)),
|
|
77
|
+
__metadata("design:paramtypes", [String])
|
|
78
|
+
], ExerciseService);
|
|
79
|
+
exports.ExerciseService = ExerciseService;
|
|
80
|
+
//# sourceMappingURL=exercise.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exercise.service.js","sourceRoot":"","sources":["../../../../src/modules/clients/exercise-api/exercise.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,sDAAqH;AAOrH,IAAa,eAAe,uBAA5B,MAAa,e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AAC,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC;SACtF;IACH,CAAC;IAEM,KAAK,CAAC,YAAY,CAAC,QAAkB,EAAE,WAAmB;QAC/D,IAAI;YACF,IAAI,QAAQ,CAAC,EAAE,KAAK,SAAS,EAAE;gBAC7B,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,gBAAgB,CAAC,QAAQ,EAAE;oBAC3E,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE;iBACpD,CAAC,CAAC;gBACH,OAAO;oBACL,GAAG,gBAAgB;oBACnB,WAAW,EAAE,EAAE;iBAChB,CAAC;aACH;iBAAM;gBACL,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC;gBAC3F,OAAO;oBACL,GAAG,gBAAgB;oBACnB,WAAW,EAAE,EAAE;iBAChB,CAAC;aACH;SAGF;QAAC,OAAO,GAAQ,EAAE;YACjB,OAAO,EAAE,KAAK,EAAE,GAAG,iBAAe,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC;SACtF;IACH,CAAC;CACF,CAAA;AA9DY,eAAe;IAD3B,IAAA,mBAAU,GAAE;IAIE,WAAA,IAAA,eAAM,EAAC,oBAAY,CAAC,CAAA;;GAHtB,eAAe,CA8D3B;AA9DY,0CAAe"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { AuthApiModule } from './auth-api/auth-api.module';
|
|
2
|
+
export { AuthService } from './auth-api/auth.service';
|
|
3
|
+
export { DataApiModule } from './data-api/data-api.module';
|
|
4
|
+
export { DataService } from './data-api/data.service';
|
|
5
|
+
export { ExerciseApiModule } from './exercise-api/exercise-api.module';
|
|
6
|
+
export { ExerciseService } from './exercise-api/exercise.service';
|
|
7
|
+
export { PronunciationApiModule } from './pronunciation-api/pronunciation-api.module';
|
|
8
|
+
export { PronunciationService } from './pronunciation-api/pronunciation.service';
|
|
9
|
+
export { PublisherApiModule } from './publisher-api/publisher-api.module';
|
|
10
|
+
export { PublisherService } from './publisher-api/publisher.service';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PublisherService = exports.PublisherApiModule = exports.PronunciationService = exports.PronunciationApiModule = exports.ExerciseService = exports.ExerciseApiModule = exports.DataService = exports.DataApiModule = exports.AuthService = exports.AuthApiModule = void 0;
|
|
4
|
+
var auth_api_module_1 = require("./auth-api/auth-api.module");
|
|
5
|
+
Object.defineProperty(exports, "AuthApiModule", { enumerable: true, get: function () { return auth_api_module_1.AuthApiModule; } });
|
|
6
|
+
var auth_service_1 = require("./auth-api/auth.service");
|
|
7
|
+
Object.defineProperty(exports, "AuthService", { enumerable: true, get: function () { return auth_service_1.AuthService; } });
|
|
8
|
+
var data_api_module_1 = require("./data-api/data-api.module");
|
|
9
|
+
Object.defineProperty(exports, "DataApiModule", { enumerable: true, get: function () { return data_api_module_1.DataApiModule; } });
|
|
10
|
+
var data_service_1 = require("./data-api/data.service");
|
|
11
|
+
Object.defineProperty(exports, "DataService", { enumerable: true, get: function () { return data_service_1.DataService; } });
|
|
12
|
+
var exercise_api_module_1 = require("./exercise-api/exercise-api.module");
|
|
13
|
+
Object.defineProperty(exports, "ExerciseApiModule", { enumerable: true, get: function () { return exercise_api_module_1.ExerciseApiModule; } });
|
|
14
|
+
var exercise_service_1 = require("./exercise-api/exercise.service");
|
|
15
|
+
Object.defineProperty(exports, "ExerciseService", { enumerable: true, get: function () { return exercise_service_1.ExerciseService; } });
|
|
16
|
+
var pronunciation_api_module_1 = require("./pronunciation-api/pronunciation-api.module");
|
|
17
|
+
Object.defineProperty(exports, "PronunciationApiModule", { enumerable: true, get: function () { return pronunciation_api_module_1.PronunciationApiModule; } });
|
|
18
|
+
var pronunciation_service_1 = require("./pronunciation-api/pronunciation.service");
|
|
19
|
+
Object.defineProperty(exports, "PronunciationService", { enumerable: true, get: function () { return pronunciation_service_1.PronunciationService; } });
|
|
20
|
+
var publisher_api_module_1 = require("./publisher-api/publisher-api.module");
|
|
21
|
+
Object.defineProperty(exports, "PublisherApiModule", { enumerable: true, get: function () { return publisher_api_module_1.PublisherApiModule; } });
|
|
22
|
+
var publisher_service_1 = require("./publisher-api/publisher.service");
|
|
23
|
+
Object.defineProperty(exports, "PublisherService", { enumerable: true, get: function () { return publisher_service_1.PublisherService; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/clients/index.ts"],"names":[],"mappings":";;;AAAA,8DAA2D;AAAlD,gHAAA,aAAa,OAAA;AACtB,wDAAsD;AAA7C,2GAAA,WAAW,OAAA;AACpB,8DAA2D;AAAlD,gHAAA,aAAa,OAAA;AACtB,wDAAsD;AAA7C,2GAAA,WAAW,OAAA;AACpB,0EAAuE;AAA9D,wHAAA,iBAAiB,OAAA;AAC1B,oEAAkE;AAAzD,mHAAA,eAAe,OAAA;AACxB,yFAAsF;AAA7E,kIAAA,sBAAsB,OAAA;AAC/B,mFAAiF;AAAxE,6HAAA,oBAAoB,OAAA;AAC7B,6EAA0E;AAAjE,0HAAA,kBAAkB,OAAA;AAC3B,uEAAqE;AAA5D,qHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PronunciationApiModule = void 0;
|
|
4
|
+
const pronunciation_service_1 = require("./pronunciation.service");
|
|
5
|
+
class PronunciationApiModule {
|
|
6
|
+
static forRoot(pronunciationApi, phoneSet) {
|
|
7
|
+
return {
|
|
8
|
+
module: PronunciationApiModule,
|
|
9
|
+
providers: [
|
|
10
|
+
pronunciation_service_1.PronunciationService,
|
|
11
|
+
{ provide: pronunciation_service_1.PRONUNCIATION_API, useValue: pronunciationApi },
|
|
12
|
+
{ provide: pronunciation_service_1.PHONE_SET, useValue: phoneSet },
|
|
13
|
+
],
|
|
14
|
+
exports: [pronunciation_service_1.PronunciationService],
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.PronunciationApiModule = PronunciationApiModule;
|
|
19
|
+
//# sourceMappingURL=pronunciation-api.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pronunciation-api.module.js","sourceRoot":"","sources":["../../../../src/modules/clients/pronunciation-api/pronunciation-api.module.ts"],"names":[],"mappings":";;;AAEA,mEAA6F;AAE7F,MAAa,sBAAsB;IACjC,MAAM,CAAC,OAAO,CAAC,gBAAwB,EAAE,QAAkB;QACzD,OAAO;YACL,MAAM,EAAE,sBAAsB;YAC9B,SAAS,EAAE;gBACT,4CAAoB;gBACpB,EAAE,OAAO,EAAE,yCAAiB,EAAE,QAAQ,EAAE,gBAAgB,EAAE;gBAC1D,EAAE,OAAO,EAAE,iCAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE;aAC3C;YACD,OAAO,EAAE,CAAC,4CAAoB,CAAC;SAChC,CAAC;IACJ,CAAC;CACF;AAZD,wDAYC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PhoneSet, PhrasePronunciationDtoV1 } from '@novo-learning/novo-sdk';
|
|
2
|
+
export declare const PRONUNCIATION_API = "PRONUNCIATION_API";
|
|
3
|
+
export declare const PHONE_SET = "PHONE_SET";
|
|
4
|
+
export declare class PronunciationService {
|
|
5
|
+
private readonly apiUrl;
|
|
6
|
+
private readonly phoneSet;
|
|
7
|
+
private readonly api;
|
|
8
|
+
constructor(apiUrl: string, phoneSet: PhoneSet);
|
|
9
|
+
getPronunciation(phrase: string, accessToken: string): Promise<PhrasePronunciationDtoV1 | {
|
|
10
|
+
error: string;
|
|
11
|
+
}>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.PronunciationService = void 0;
|
|
16
|
+
const common_1 = require("@nestjs/common");
|
|
17
|
+
const novo_sdk_1 = require("@novo-learning/novo-sdk");
|
|
18
|
+
let PronunciationService = class PronunciationService {
|
|
19
|
+
constructor(apiUrl, phoneSet) {
|
|
20
|
+
this.apiUrl = apiUrl;
|
|
21
|
+
this.phoneSet = phoneSet;
|
|
22
|
+
const url = this.apiUrl.indexOf('https') > -1 ? this.apiUrl : `http://${this.apiUrl}`;
|
|
23
|
+
this.api = new novo_sdk_1.PronunciationApi(undefined, url);
|
|
24
|
+
}
|
|
25
|
+
async getPronunciation(phrase, accessToken) {
|
|
26
|
+
try {
|
|
27
|
+
const { data: pronunciation } = await this.api.getPronunciationsV1({
|
|
28
|
+
phrase: phrase,
|
|
29
|
+
targetLanguage: novo_sdk_1.PhoneSetToLanguageCodeMap[this.phoneSet].language,
|
|
30
|
+
}, { headers: { Authorization: `Bearer ${accessToken}` } });
|
|
31
|
+
return pronunciation;
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
return { error: `${PronunciationService.name}: ${err.code || err.response?.statusText}` };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
PronunciationService = __decorate([
|
|
39
|
+
__param(0, (0, common_1.Inject)(exports.PRONUNCIATION_API)),
|
|
40
|
+
__param(1, (0, common_1.Inject)(exports.PHONE_SET)),
|
|
41
|
+
__metadata("design:paramtypes", [String, String])
|
|
42
|
+
], PronunciationService);
|
|
43
|
+
exports.PronunciationService = PronunciationService;
|
|
44
|
+
//# sourceMappingURL=pronunciation.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pronunciation.service.js","sourceRoot":"","sources":["../../../../src/modules/clients/pronunciation-api/pronunciation.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAwC;AACxC,sDAKiC;AAKjC,IAAa,oBAAoB,GAAjC,MAAa,oBAAoB;IAG/B,YAC8C,MAAc,EACtB,QAAkB;QADV,WAAM,GAAN,MAAM,CAAQ;QACtB,aAAQ,GAAR,QAAQ,CAAU;QAEtD,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC;QACtF,IAAI,CAAC,GAAG,GAAG,IAAI,2BAAgB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAClD,CAAC;IAEM,KAAK,CAAC,gBAAgB,CAC3B,MAAc,EACd,WAAmB;QAEnB,IAAI;YACF,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAChE;gBACE,MAAM,EAAE,MAAM;gBACd,cAAc,EAAE,oCAAyB,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,QAAQ;aAClE,EACD,EAAE,OAAO,EAAE,EAAE,aAAa,EAAE,UAAU,WAAW,EAAE,EAAE,EAAE,CACxD,CAAC;YACF,OAAO,aAAa,CAAC;SAEtB;QAAC,OAAO,GAAQ,EAAE;YACjB,OAAO,EAAE,KAAK,EAAE,GAAG,oBAAoB,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,CAAC;SAC3F;IACH,CAAC;CACF,CAAA;AA7BY,oBAAoB;IAI5B,WAAA,IAAA,eAAM,EAAC,yBAAiB,CAAC,CAAA;IACzB,WAAA,IAAA,eAAM,EAAC,iBAAS,CAAC,CAAA;;GALT,oBAAoB,CA6BhC;AA7BY,oDAAoB"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PublisherApiModule = void 0;
|
|
4
|
+
const common_1 = require("@nestjs/common");
|
|
5
|
+
const auth_service_1 = require("../auth-api/auth.service");
|
|
6
|
+
const publisher_service_1 = require("./publisher.service");
|
|
7
|
+
class PublisherApiModule {
|
|
8
|
+
static forRoot(publisherApi, authApi, cache, ttl, publisherName, publisherToken) {
|
|
9
|
+
return {
|
|
10
|
+
module: PublisherApiModule,
|
|
11
|
+
providers: [
|
|
12
|
+
publisher_service_1.PublisherService,
|
|
13
|
+
auth_service_1.AuthService,
|
|
14
|
+
{ provide: publisher_service_1.PUBLISHER_API, useValue: publisherApi },
|
|
15
|
+
{ provide: auth_service_1.AUTH_API, useValue: authApi },
|
|
16
|
+
{ provide: common_1.CACHE_MANAGER, useValue: cache },
|
|
17
|
+
{ provide: publisher_service_1.PUBLISHER_CACHE_TTL, useValue: ttl },
|
|
18
|
+
{ provide: publisher_service_1.PUBLISHER_NAME, useValue: publisherName },
|
|
19
|
+
{ provide: publisher_service_1.PUBLISHER_TOKEN, useValue: publisherToken },
|
|
20
|
+
],
|
|
21
|
+
exports: [publisher_service_1.PublisherService],
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
exports.PublisherApiModule = PublisherApiModule;
|
|
26
|
+
//# sourceMappingURL=publisher-api.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publisher-api.module.js","sourceRoot":"","sources":["../../../../src/modules/clients/publisher-api/publisher-api.module.ts"],"names":[],"mappings":";;;AAAA,2CAA8D;AAC9D,2DAAiE;AACjE,2DAM6B;AAE7B,MAAa,kBAAkB;IAC7B,MAAM,CAAC,OAAO,CACZ,YAAoB,EACpB,OAAe,EACf,KAAY,EACZ,GAAW,EACX,aAAqB,EACrB,cAAsB;QAEtB,OAAO;YACL,MAAM,EAAE,kBAAkB;YAC1B,SAAS,EAAE;gBACT,oCAAgB;gBAChB,0BAAW;gBACX,EAAE,OAAO,EAAE,iCAAa,EAAE,QAAQ,EAAE,YAAY,EAAE;gBAClD,EAAE,OAAO,EAAE,uBAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE;gBACxC,EAAE,OAAO,EAAE,sBAAa,EAAE,QAAQ,EAAE,KAAK,EAAE;gBAC3C,EAAE,OAAO,EAAE,uCAAmB,EAAE,QAAQ,EAAE,GAAG,EAAE;gBAC/C,EAAE,OAAO,EAAE,kCAAc,EAAE,QAAQ,EAAE,aAAa,EAAE;gBACpD,EAAE,OAAO,EAAE,mCAAe,EAAE,QAAQ,EAAE,cAAc,EAAE;aACvD;YACD,OAAO,EAAE,CAAC,oCAAgB,CAAC;SAC5B,CAAC;IACJ,CAAC;CACF;AAxBD,gDAwBC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { LanguageCode, PublisherResponseDto } from '@novo-learning/novo-sdk';
|
|
2
|
+
import { Cache } from 'cache-manager';
|
|
3
|
+
import { AuthService } from '../auth-api/auth.service';
|
|
4
|
+
export declare const PUBLISHER_API = "PUBLISHER_API";
|
|
5
|
+
export declare const PUBLISHER_CACHE_TTL = "PUBLISHER_CACHE_TTL";
|
|
6
|
+
export declare const PUBLISHER_NAME = "PUBLISHER_NAME";
|
|
7
|
+
export declare const PUBLISHER_TOKEN = "PUBLISHER_TOKEN";
|
|
8
|
+
export declare class PublisherService {
|
|
9
|
+
private readonly authService;
|
|
10
|
+
private readonly apiUrl;
|
|
11
|
+
private readonly cacheManager;
|
|
12
|
+
private readonly cacheTtl;
|
|
13
|
+
private readonly name;
|
|
14
|
+
private readonly token;
|
|
15
|
+
private readonly api;
|
|
16
|
+
private logger;
|
|
17
|
+
private makeKey;
|
|
18
|
+
constructor(authService: AuthService, apiUrl: string, cacheManager: Cache, cacheTtl: number, name: string, token: string);
|
|
19
|
+
_getPublisher(id: string, accessToken: string): Promise<PublisherResponseDto | {
|
|
20
|
+
error: string;
|
|
21
|
+
}>;
|
|
22
|
+
getPublisher(id: string): Promise<PublisherResponseDto | {
|
|
23
|
+
error: string;
|
|
24
|
+
}>;
|
|
25
|
+
publisherAllowed(publisherId: string, languageCode: LanguageCode): Promise<boolean>;
|
|
26
|
+
private getReadonlyPublisherAccesstoken;
|
|
27
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
var PublisherService_1;
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.PublisherService = void 0;
|
|
17
|
+
const common_1 = require("@nestjs/common");
|
|
18
|
+
const novo_sdk_1 = require("@novo-learning/novo-sdk");
|
|
19
|
+
const auth_service_1 = require("../auth-api/auth.service");
|
|
20
|
+
let PublisherService = PublisherService_1 = class PublisherService {
|
|
21
|
+
constructor(authService, apiUrl, cacheManager, cacheTtl, name, token) {
|
|
22
|
+
this.authService = authService;
|
|
23
|
+
this.apiUrl = apiUrl;
|
|
24
|
+
this.cacheManager = cacheManager;
|
|
25
|
+
this.cacheTtl = cacheTtl;
|
|
26
|
+
this.name = name;
|
|
27
|
+
this.token = token;
|
|
28
|
+
this.logger = new common_1.Logger('PublisherService');
|
|
29
|
+
this.makeKey = (id) => `${PublisherService_1.name}-${id}`;
|
|
30
|
+
const url = this.apiUrl.indexOf('https') > -1 ? this.apiUrl : `http://${this.apiUrl}`;
|
|
31
|
+
this.api = new novo_sdk_1.PublisherApi(undefined, url);
|
|
32
|
+
}
|
|
33
|
+
async _getPublisher(id, accessToken) {
|
|
34
|
+
try {
|
|
35
|
+
const { data: publisher } = await this.api.getAndValidatePublisher(id, undefined, undefined, {
|
|
36
|
+
headers: { Authorization: `Bearer ${accessToken}` },
|
|
37
|
+
});
|
|
38
|
+
return publisher;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
return { error: `${PublisherService_1.name}: ${err.code || err.response?.statusText}` };
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
async getPublisher(id) {
|
|
45
|
+
const cachedPublisher = await this.cacheManager.get(this.makeKey(id));
|
|
46
|
+
if (cachedPublisher) {
|
|
47
|
+
return cachedPublisher;
|
|
48
|
+
}
|
|
49
|
+
const accessToken = await this.getReadonlyPublisherAccesstoken();
|
|
50
|
+
const newPublisher = await this._getPublisher(id, accessToken);
|
|
51
|
+
if ('error' in newPublisher || newPublisher === undefined) {
|
|
52
|
+
return newPublisher;
|
|
53
|
+
}
|
|
54
|
+
await this.cacheManager.set(this.makeKey(id), newPublisher, {
|
|
55
|
+
ttl: this.cacheTtl,
|
|
56
|
+
});
|
|
57
|
+
return newPublisher;
|
|
58
|
+
}
|
|
59
|
+
async publisherAllowed(publisherId, languageCode) {
|
|
60
|
+
const publisher = await this.getPublisher(publisherId);
|
|
61
|
+
if ('error' in publisher) {
|
|
62
|
+
this.logger.error(publisher.error);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return publisher.settings.allowedLanguages.includes(languageCode);
|
|
66
|
+
}
|
|
67
|
+
async getReadonlyPublisherAccesstoken() {
|
|
68
|
+
const authData = await this.authService.login(this.name, this.token, [novo_sdk_1.PermissionType.publisher_read]);
|
|
69
|
+
if ('error' in authData) {
|
|
70
|
+
throw new Error('error logging into auth API: ' + authData.error);
|
|
71
|
+
}
|
|
72
|
+
return authData.payload.token;
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
PublisherService = PublisherService_1 = __decorate([
|
|
76
|
+
(0, common_1.Injectable)(),
|
|
77
|
+
__param(1, (0, common_1.Inject)(exports.PUBLISHER_API)),
|
|
78
|
+
__param(2, (0, common_1.Inject)(common_1.CACHE_MANAGER)),
|
|
79
|
+
__param(3, (0, common_1.Inject)(exports.PUBLISHER_CACHE_TTL)),
|
|
80
|
+
__param(4, (0, common_1.Inject)(exports.PUBLISHER_NAME)),
|
|
81
|
+
__param(5, (0, common_1.Inject)(exports.PUBLISHER_TOKEN)),
|
|
82
|
+
__metadata("design:paramtypes", [auth_service_1.AuthService, String, Object, Number, String, String])
|
|
83
|
+
], PublisherService);
|
|
84
|
+
exports.PublisherService = PublisherService;
|
|
85
|
+
//# sourceMappingURL=publisher.service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publisher.service.js","sourceRoot":"","sources":["../../../../src/modules/clients/publisher-api/publisher.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAA2E;AAC3E,sDAA2G;AAE3G,2DAAuD;AAQvD,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;IAO3B,YACmB,WAAwB,EACD,MAAc,EACd,YAAmB,EACb,QAAgB,EACrB,IAAY,EACX,KAAa;QALtC,gBAAW,GAAX,WAAW,CAAa;QACD,WAAM,GAAN,MAAM,CAAQ;QACd,iBAAY,GAAZ,YAAY,CAAO;QACb,aAAQ,GAAR,QAAQ,CAAQ;QACrB,SAAI,GAAJ,IAAI,CAAQ;QACX,UAAK,GAAL,KAAK,CAAQ;QAVjD,WAAM,GAAW,IAAI,eAAM,CAAC,kBAAkB,CAAC,CAAC;QAEhD,YAAO,GAAG,CAAC,EAAU,EAAU,EAAE,CAAC,GAAG,kBAAgB,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC;QAUzE,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,MAAM,EAAE,CAAC;QACtF,IAAI,CAAC,GAAG,GAAG,IAAI,uBAAY,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IAC9C,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,EAAU,EAAE,WAAmB;QACxD,IAAI;YACF,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,uBAAuB,CAAC,EAAE,EAAE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,CAAC,QAAQ,CAAC,gBAAgB,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IACpE,CAAC;IAEO,KAAK,CAAC,+BAA+B;QAC3C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC,yBAAc,CAAC,cAAc,CAAC,CAAC,CAAC;QACtG,IAAI,OAAO,IAAI,QAAQ,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,+BAA+B,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;SACnE;QACD,OAAO,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC;IAChC,CAAC;CACF,CAAA;AApEY,gBAAgB;IAD5B,IAAA,mBAAU,GAAE;IAUR,WAAA,IAAA,eAAM,EAAC,qBAAa,CAAC,CAAA;IACrB,WAAA,IAAA,eAAM,EAAC,sBAAa,CAAC,CAAA;IACrB,WAAA,IAAA,eAAM,EAAC,2BAAmB,CAAC,CAAA;IAC3B,WAAA,IAAA,eAAM,EAAC,sBAAc,CAAC,CAAA;IACtB,WAAA,IAAA,eAAM,EAAC,uBAAe,CAAC,CAAA;qCALM,0BAAW;GARhC,gBAAgB,CAoE5B;AApEY,4CAAgB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { CustomDecorator } from '@nestjs/common';
|
|
2
|
-
import { PermissionType } from '
|
|
2
|
+
import { PermissionType } from '@novo-learning/novo-sdk';
|
|
3
3
|
export declare const HAS_PERMISSION = "hasPermission";
|
|
4
4
|
export declare const HasPermission: (...permissions: PermissionType[]) => CustomDecorator<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"has-permission.guard.js","sourceRoot":"","sources":["../../../../../src/modules/nest/jwt/guards/has-permission.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8D;AAC9D,uCAAyC;AACzC,+CAA6C;
|
|
1
|
+
{"version":3,"file":"has-permission.guard.js","sourceRoot":"","sources":["../../../../../src/modules/nest/jwt/guards/has-permission.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2CAA8D;AAC9D,uCAAyC;AACzC,+CAA6C;AAI7C,6EAAoE;AAGpE,IAAa,kBAAkB,GAA/B,MAAa,kBAAmB,SAAQ,IAAA,oBAAS,EAAC,gBAAgB,CAAC;IACjE,YAAoB,SAAoB;QACtC,KAAK,EAAE,CAAC;QADU,cAAS,GAAT,SAAS,CAAW;IAExC,CAAC;IAED,WAAW,CAAC,OAAyB;QACnC,MAAM,mBAAmB,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAmB,qCAAc,EAAE,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;QACvG,IAAI,CAAC,mBAAmB,EAAE;YACxB,OAAO,IAAI,CAAC;SACb;QACD,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAA0B,CAAC;QAC7E,MAAM,eAAe,GAAG,IAAI,EAAE,WAAW,CAAC;QAC1C,IAAI,eAAe,IAAI,IAAI,EAAE;YAC3B,OAAO,KAAK,CAAC;SACd;QACD,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;IACxF,CAAC;CACF,CAAA;AAjBY,kBAAkB;IAD9B,IAAA,mBAAU,GAAE;qCAEoB,gBAAS;GAD7B,kBAAkB,CAiB9B;AAjBY,gDAAkB"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export * from './authenticated-request';
|
|
2
2
|
export * from './decorators/permission.decorator';
|
|
3
3
|
export * from './decorators/public.decorator';
|
|
4
|
-
export * from './entities/permissions';
|
|
5
4
|
export * from './entities/user-data';
|
|
6
5
|
export * from './guards/has-permission.guard';
|
|
7
6
|
export * from './guards/jwt-auth.guard';
|
|
@@ -13,7 +13,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
13
13
|
__exportStar(require("./authenticated-request"), exports);
|
|
14
14
|
__exportStar(require("./decorators/permission.decorator"), exports);
|
|
15
15
|
__exportStar(require("./decorators/public.decorator"), exports);
|
|
16
|
-
__exportStar(require("./entities/permissions"), exports);
|
|
17
16
|
__exportStar(require("./entities/user-data"), exports);
|
|
18
17
|
__exportStar(require("./guards/has-permission.guard"), exports);
|
|
19
18
|
__exportStar(require("./guards/jwt-auth.guard"), exports);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/nest/jwt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAwC;AACxC,oEAAkD;AAClD,gEAA8C;AAC9C,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/modules/nest/jwt/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,0DAAwC;AACxC,oEAAkD;AAClD,gEAA8C;AAC9C,uDAAqC;AACrC,gEAA8C;AAC9C,0DAAwC;AACxC,+CAA6B;AAC7B,4DAA0C"}
|
|
@@ -1,36 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
-
};
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.JwtModule = void 0;
|
|
10
|
-
const common_1 = require("@nestjs/common");
|
|
11
|
-
const config_1 = require("@nestjs/config");
|
|
12
4
|
const core_1 = require("@nestjs/core");
|
|
13
5
|
const passport_1 = require("@nestjs/passport");
|
|
14
6
|
const jwt_auth_guard_1 = require("../jwt/guards/jwt-auth.guard");
|
|
15
7
|
const jwt_strategy_1 = require("../jwt/strategies/jwt.strategy");
|
|
16
8
|
const has_permission_guard_1 = require("./guards/has-permission.guard");
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
9
|
+
class JwtModule {
|
|
10
|
+
static forRoot(jwtSecret) {
|
|
11
|
+
return {
|
|
12
|
+
module: JwtModule,
|
|
13
|
+
imports: [passport_1.PassportModule],
|
|
14
|
+
providers: [
|
|
15
|
+
{
|
|
16
|
+
provide: core_1.APP_GUARD,
|
|
17
|
+
useClass: jwt_auth_guard_1.JwtAuthGuard,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
provide: core_1.APP_GUARD,
|
|
21
|
+
useClass: has_permission_guard_1.HasPermissionGuard,
|
|
22
|
+
},
|
|
23
|
+
jwt_strategy_1.JwtStrategy,
|
|
24
|
+
{ provide: jwt_strategy_1.JWT_SECRET, useValue: jwtSecret },
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
35
29
|
exports.JwtModule = JwtModule;
|
|
36
30
|
//# sourceMappingURL=jwt.module.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.module.js","sourceRoot":"","sources":["../../../../src/modules/nest/jwt/jwt.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jwt.module.js","sourceRoot":"","sources":["../../../../src/modules/nest/jwt/jwt.module.ts"],"names":[],"mappings":";;;AACA,uCAAyC;AACzC,+CAAkD;AAClD,iEAA4D;AAC5D,iEAAyE;AACzE,wEAAmE;AAEnE,MAAa,SAAS;IACpB,MAAM,CAAC,OAAO,CAAC,SAAiB;QAC9B,OAAO;YACL,MAAM,EAAE,SAAS;YACjB,OAAO,EAAE,CAAC,yBAAc,CAAC;YACzB,SAAS,EAAE;gBACT;oBACE,OAAO,EAAE,gBAAS;oBAClB,QAAQ,EAAE,6BAAY;iBACvB;gBACD;oBACE,OAAO,EAAE,gBAAS;oBAClB,QAAQ,EAAE,yCAAkB;iBAC7B;gBACD,0BAAW;gBACX,EAAE,OAAO,EAAE,yBAAU,EAAE,QAAQ,EAAE,SAAS,EAAE;aAC7C;SACF,CAAC;IACJ,CAAC;CACF;AAnBD,8BAmBC"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ConfigService } from '@nestjs/config';
|
|
2
1
|
import { Strategy } from 'passport-jwt';
|
|
3
2
|
import { UserData } from '../entities/user-data';
|
|
3
|
+
export declare const JWT_SECRET = "JWT_SECRET";
|
|
4
4
|
declare const JwtStrategy_base: new (...args: any[]) => Strategy;
|
|
5
5
|
export declare class JwtStrategy extends JwtStrategy_base {
|
|
6
|
-
readonly
|
|
7
|
-
constructor(
|
|
6
|
+
private readonly jwtSecret;
|
|
7
|
+
constructor(jwtSecret: string);
|
|
8
8
|
validate(payload: UserData): Promise<UserData>;
|
|
9
9
|
}
|
|
10
10
|
export {};
|
|
@@ -8,20 +8,22 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
exports.JwtStrategy = void 0;
|
|
13
16
|
const common_1 = require("@nestjs/common");
|
|
14
|
-
const config_1 = require("@nestjs/config");
|
|
15
17
|
const passport_1 = require("@nestjs/passport");
|
|
16
18
|
const passport_jwt_1 = require("passport-jwt");
|
|
17
19
|
let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(passport_jwt_1.Strategy) {
|
|
18
|
-
constructor(
|
|
20
|
+
constructor(jwtSecret) {
|
|
19
21
|
super({
|
|
20
22
|
jwtFromRequest: passport_jwt_1.ExtractJwt.fromAuthHeaderAsBearerToken(),
|
|
21
23
|
ignoreExpiration: false,
|
|
22
|
-
secretOrKey:
|
|
24
|
+
secretOrKey: jwtSecret,
|
|
23
25
|
});
|
|
24
|
-
this.
|
|
26
|
+
this.jwtSecret = jwtSecret;
|
|
25
27
|
}
|
|
26
28
|
async validate(payload) {
|
|
27
29
|
return payload;
|
|
@@ -29,7 +31,8 @@ let JwtStrategy = class JwtStrategy extends (0, passport_1.PassportStrategy)(pas
|
|
|
29
31
|
};
|
|
30
32
|
JwtStrategy = __decorate([
|
|
31
33
|
(0, common_1.Injectable)(),
|
|
32
|
-
|
|
34
|
+
__param(0, (0, common_1.Inject)(exports.JWT_SECRET)),
|
|
35
|
+
__metadata("design:paramtypes", [String])
|
|
33
36
|
], JwtStrategy);
|
|
34
37
|
exports.JwtStrategy = JwtStrategy;
|
|
35
38
|
//# sourceMappingURL=jwt.strategy.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jwt.strategy.js","sourceRoot":"","sources":["../../../../../src/modules/nest/jwt/strategies/jwt.strategy.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"jwt.strategy.js","sourceRoot":"","sources":["../../../../../src/modules/nest/jwt/strategies/jwt.strategy.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAoD;AACpD,+CAAoD;AACpD,+CAAoD;AAMpD,IAAa,WAAW,GAAxB,MAAa,WAAY,SAAQ,IAAA,2BAAgB,EAAC,uBAAQ,CAAC;IACzD,YAAiD,SAAiB;QAChE,KAAK,CAAC;YACJ,cAAc,EAAE,yBAAU,CAAC,2BAA2B,EAAE;YACxD,gBAAgB,EAAE,KAAK;YACvB,WAAW,EAAE,SAAS;SACvB,CAAC,CAAC;QAL4C,cAAS,GAAT,SAAS,CAAQ;IAMlE,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,OAAiB;QAC9B,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AAZY,WAAW;IADvB,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,eAAM,EAAC,kBAAU,CAAC,CAAA;;GADpB,WAAW,CAYvB;AAZY,kCAAW"}
|
package/package.json
CHANGED
|
@@ -1,39 +1,59 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@novo-learning/service-lib",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "Common components for Novo services",
|
|
5
|
-
"license": "UNLICENSED",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"files": [
|
|
8
|
-
"dist"
|
|
9
|
-
],
|
|
10
|
-
"scripts": {
|
|
11
|
-
"build": "tsc",
|
|
12
|
-
"lint": "eslint \"src/**/*.ts\" --fix",
|
|
13
|
-
"test": "jest --passWithNoTests"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"@
|
|
18
|
-
"@
|
|
19
|
-
"@
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
}
|
|
39
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@novo-learning/service-lib",
|
|
3
|
+
"version": "0.0.4",
|
|
4
|
+
"description": "Common components for Novo services",
|
|
5
|
+
"license": "UNLICENSED",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"build": "tsc",
|
|
12
|
+
"lint": "eslint \"src/**/*.ts\" --fix",
|
|
13
|
+
"test": "jest --passWithNoTests",
|
|
14
|
+
"test:debug": "node --inspect node_modules/.bin/jest --runInBand"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@babel/core": "^7.17.5",
|
|
18
|
+
"@babel/plugin-proposal-decorators": "^7.17.2",
|
|
19
|
+
"@babel/preset-env": "^7.16.11",
|
|
20
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
21
|
+
"@nestjs/common": "^8.2.4",
|
|
22
|
+
"@nestjs/core": "^8.2.4",
|
|
23
|
+
"@nestjs/passport": "^8.0.1",
|
|
24
|
+
"@novo-learning/novo-sdk": "^0.0.3",
|
|
25
|
+
"@types/validator": "^13.7.1",
|
|
26
|
+
"babel-jest": "^27.5.1",
|
|
27
|
+
"buffer": "^6.0.3",
|
|
28
|
+
"cache-manager": "^3.6.0",
|
|
29
|
+
"class-transformer": "^0.5.1",
|
|
30
|
+
"class-validator": "^0.13.2",
|
|
31
|
+
"form-data": "^4.0.0",
|
|
32
|
+
"passport": "^0.5.2",
|
|
33
|
+
"passport-jwt": "^4.0.0"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"rxjs": "^7.1.0",
|
|
37
|
+
"typescript": "^4.5.4"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@nestjs/microservices": "^8.4.3",
|
|
41
|
+
"@nestjs/platform-express": "^8.4.3",
|
|
42
|
+
"@nestjs/testing": "^8.0.6",
|
|
43
|
+
"@types/cache-manager": "^3.4.3",
|
|
44
|
+
"@types/jest": "^27.0.3",
|
|
45
|
+
"@types/passport": "^1.0.7",
|
|
46
|
+
"@types/passport-jwt": "^3.0.6",
|
|
47
|
+
"@typescript-eslint/eslint-plugin": "^5.8.0",
|
|
48
|
+
"eslint": "^8.4.1",
|
|
49
|
+
"eslint-config-prettier": "^8.3.0",
|
|
50
|
+
"eslint-plugin-prettier": "^4.0.0",
|
|
51
|
+
"generate-package-json-webpack-plugin": "^2.6.0",
|
|
52
|
+
"jest": "^27.4.5",
|
|
53
|
+
"prettier": "^2.5.1",
|
|
54
|
+
"ts-jest": "^27.1.2",
|
|
55
|
+
"ts-loader": "^9.2.8",
|
|
56
|
+
"webpack-cli": "^4.9.2",
|
|
57
|
+
"webpack-node-externals": "^3.0.0"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PermissionTypeName = exports.PermissionType = void 0;
|
|
4
|
-
var PermissionType;
|
|
5
|
-
(function (PermissionType) {
|
|
6
|
-
PermissionType["retrieve_asr_result"] = "retrieve_asr_result";
|
|
7
|
-
PermissionType["retrieve_audio"] = "retrieve_audio";
|
|
8
|
-
PermissionType["exercise_edit"] = "exercise_edit";
|
|
9
|
-
PermissionType["exercise_delete"] = "exercise_delete";
|
|
10
|
-
})(PermissionType = exports.PermissionType || (exports.PermissionType = {}));
|
|
11
|
-
exports.PermissionTypeName = 'PermissionType';
|
|
12
|
-
//# sourceMappingURL=permissions.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"permissions.js","sourceRoot":"","sources":["../../../../../src/modules/nest/jwt/entities/permissions.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,6DAA6C,CAAA;IAC7C,mDAAmC,CAAA;IACnC,iDAAiC,CAAA;IACjC,qDAAqC,CAAA;AACvC,CAAC,EALW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAKzB;AAEY,QAAA,kBAAkB,GAAG,gBAAgB,CAAC"}
|