@telia-ace/alliance-portal 1.0.7-next.5 → 1.0.7
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/CHANGELOG.md +33 -0
- package/dist/app.controller.js +1 -1
- package/dist/app.controller.spec.js +1 -1
- package/dist/responses.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @telia-ace/alliance-portal
|
|
2
2
|
|
|
3
|
+
## 1.0.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c2335bc: Validate and define default values for environment config using Zod.
|
|
8
|
+
- c2335bc: Move health check endpoint to `/-/health`.
|
|
9
|
+
- c2335bc: Add 404 page for non existant Workspaces.
|
|
10
|
+
- c2335bc: Add support for `LANDING_PAGE` environment variable to display a landing page on the portal instance root.
|
|
11
|
+
- c2335bc: Respond with correct status code in endpoints.
|
|
12
|
+
- c2335bc: Add current Workspace name to Customer Portal page title.
|
|
13
|
+
- c2335bc: Define `HEALTHCHECK` in Dockerfile.
|
|
14
|
+
- c2335bc: Setup health checks for services (https://github.com/telia-company/ace-alliance-sdk/issues/388).
|
|
15
|
+
- c2335bc: Fully support portals with static Workspace and Customer.
|
|
16
|
+
- c2335bc: Include `skipGroupClaimCheck` environment variable value in trace log when user signs in.
|
|
17
|
+
- c2335bc: Ensure unnecessary files aren't copied into Docker images.
|
|
18
|
+
- c2335bc: Replace `ORIGIN_AS_ROOT_URL` with `ROOT_URL_SUB_PATH` to configure what sub path a Portal will be hosted on.
|
|
19
|
+
- c2335bc: Ensure workspace existence is verified in health check for specific workspaces.
|
|
20
|
+
- c2335bc: Support customer / workspace specific portals.
|
|
21
|
+
- Updated dependencies [c2335bc]
|
|
22
|
+
- Updated dependencies [c2335bc]
|
|
23
|
+
- Updated dependencies [c2335bc]
|
|
24
|
+
- Updated dependencies [c2335bc]
|
|
25
|
+
- Updated dependencies [c2335bc]
|
|
26
|
+
- Updated dependencies [c2335bc]
|
|
27
|
+
- Updated dependencies [c2335bc]
|
|
28
|
+
- @telia-ace/alliance-internal-node-utilities@1.0.4
|
|
29
|
+
|
|
30
|
+
## 1.0.7-next.6
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- 8434f9c: Ensure workspace existence is verified in health check for specific workspaces.
|
|
35
|
+
|
|
3
36
|
## 1.0.7-next.5
|
|
4
37
|
|
|
5
38
|
### Patch Changes
|
package/dist/app.controller.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"createAppController",{enumerable:true,get:function(){return createAppController}});const _axios=require("@nestjs/axios");const _common=require("@nestjs/common");const _config=require("@nestjs/config");const _terminus=require("@nestjs/terminus");const _allianceinternalnodeutilities=require("@telia-ace/alliance-internal-node-utilities");const _express=require("express");const _graphqlrequest=require("graphql-request");const _config1=require("./config");const _graphql=require("./graphql");const _html=require("./html");const _responses=require("./responses");function _ts_decorate(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(decorators,target,key,desc);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;return c>3&&r&&Object.defineProperty(target,key,r),r}function _ts_metadata(k,v){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(k,v)}function _ts_param(paramIndex,decorator){return function(target,key){decorator(target,key,paramIndex)}}function createAppController(){const environmentWorkspace=process.env[_config1.ConfigKeys.Workspace];let AppController=class AppController{async signin(){}async favicon(){return""}async health(){return this.healthService.check([()=>this.redisHealthCheck.isHealthy()])}async cookiePolicy(){const{data}=await this.httpService.axiosRef.get(this.wpPolicyUrl);return data}async index(req,res,workspaceParam){return this.portal(req,res,environmentWorkspace||workspaceParam)}async workspace(_1,res,_2){return res.status(_common.HttpStatus.NOT_FOUND).send("Not Available")}async portal(req,res,workspaceSlug){let existingWorkspace=null;try{const{workspace}=await (0,_graphqlrequest.request)(this.configService.getOrThrow(_allianceinternalnodeutilities.SharedConfigKeys.DbEndpoint),_graphql.GetWorkspaceDocument,{slug:workspaceSlug},{authorization:(0,_allianceinternalnodeutilities.createSystemUserToken)(this.configService)});existingWorkspace=workspace}catch(error){if(error?.code==="ECONNREFUSED"){return(0,_responses.dbError)(res)}}if(!existingWorkspace){return(0,_responses.workspaceNotFoundError)(res,workspaceSlug)}let userHasAccess=false;try{const objectId=req?.oidc?.user?.sub;const{user}=await (0,_graphqlrequest.request)(this.configService.getOrThrow(_allianceinternalnodeutilities.SharedConfigKeys.DbEndpoint),_graphql.GetUserDocument,{objectId,workspaceSlug},{authorization:(0,_allianceinternalnodeutilities.createSystemUserToken)(this.configService)});userHasAccess=!!user.id}catch{}if(!userHasAccess){return(0,_responses.unauthorizedError)(res,workspaceSlug)}this.logger.info("opening portal",{user:req.oidc.user,workspaceSlug});return(0,_responses.ok)(res,(0,_html.htmlTemplate)(existingWorkspace.slug==="system"?"ACE Enterprise Portal":`ACE Customer Portal - ${existingWorkspace.name}`,(0,_html.loaderHtml)(),(0,_html.globalVariables)(this.configService,workspaceSlug),(0,_html.embedScript)(this.wpUrl,!!req.query["wp-tag"]||!!req.query["wp-version"]?{}:{tag:this.wpTag})))}constructor(logger,configService,httpService,healthService,redisHealthCheck){this.logger=logger;this.configService=configService;this.httpService=httpService;this.healthService=healthService;this.redisHealthCheck=redisHealthCheck;this.wpUrl=this.configService.getOrThrow(_config1.ConfigKeys.WebprovisionsDistributionUrl);this.wpPolicyUrl=this.configService.get(_config1.ConfigKeys.WebprovisionsDistributionCookiePolicyUrl)||`${this.wpUrl}/cookie-policy.html`;this.wpTag=this.configService.get(_config1.ConfigKeys.WebprovisionsTag)}};_ts_decorate([(0,_common.Get)("/signin-oidc"),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],AppController.prototype,"signin",null);_ts_decorate([(0,_common.Get)("/favicon*"),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],AppController.prototype,"favicon",null);_ts_decorate([(0,_common.Get)(["/-/health","/:workspace/-/health"]),(0,_terminus.HealthCheck)(),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],AppController.prototype,"health",null);_ts_decorate([(0,_common.Get)(environmentWorkspace?"/cookie-policy":"/:workspace/cookie-policy"),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],AppController.prototype,"cookiePolicy",null);_ts_decorate([(0,_common.Get)(environmentWorkspace?"/*":"/:workspace*"),_ts_param(0,(0,_common.Req)()),_ts_param(1,(0,_common.Res)()),_ts_param(2,(0,_common.Param)("workspace")),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _express.Request==="undefined"?Object:_express.Request,typeof _express.Response==="undefined"?Object:_express.Response,String])],AppController.prototype,"index",null);_ts_decorate([_ts_param(0,(0,_common.Req)()),_ts_param(1,(0,_common.Res)()),_ts_param(2,(0,_common.Param)("workspace")),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _express.Request==="undefined"?Object:_express.Request,typeof _express.Response==="undefined"?Object:_express.Response,String])],AppController.prototype,"workspace",null);AppController=_ts_decorate([(0,_common.Controller)(),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _allianceinternalnodeutilities.LoggerService==="undefined"?Object:_allianceinternalnodeutilities.LoggerService,typeof _config.ConfigService==="undefined"?Object:_config.ConfigService,typeof _axios.HttpService==="undefined"?Object:_axios.HttpService,typeof _terminus.HealthCheckService==="undefined"?Object:_terminus.HealthCheckService,typeof _allianceinternalnodeutilities.RedisHealthIndicator==="undefined"?Object:_allianceinternalnodeutilities.RedisHealthIndicator])],AppController);if(!process.env[_config1.ConfigKeys.LandingPage]||process.env[_config1.ConfigKeys.LandingPage]==="true"){let AppControllerWithLandingPage=class AppControllerWithLandingPage extends AppController{async health(){return super.health()}async index(_,res){return(0,_responses.ok)(res,(0,_html.htmlTemplate)("ACE Customer Portal - Landing Page",(0,_html.loaderHtml)(),(0,_html.embedScript)("https://embed.webprovisions.io/resource/alliance/landing-page")))}async workspace(req,res,workspaceParam){return super.index(req,res,workspaceParam)}};_ts_decorate([(0,_common.Get)(["/-/health","/:workspace/-/health"]),(0,_terminus.HealthCheck)(),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],AppControllerWithLandingPage.prototype,"health",null);_ts_decorate([(0,_common.Get)("/"),_ts_param(0,(0,_common.Req)()),_ts_param(1,(0,_common.Res)()),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _express.Request==="undefined"?Object:_express.Request,typeof _express.Response==="undefined"?Object:_express.Response])],AppControllerWithLandingPage.prototype,"index",null);_ts_decorate([(0,_common.Get)("/:workspace*"),_ts_param(0,(0,_common.Req)()),_ts_param(1,(0,_common.Res)()),_ts_param(2,(0,_common.Param)("workspace")),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _express.Request==="undefined"?Object:_express.Request,typeof _express.Response==="undefined"?Object:_express.Response,String])],AppControllerWithLandingPage.prototype,"workspace",null);AppControllerWithLandingPage=_ts_decorate([(0,_common.Controller)()],AppControllerWithLandingPage);return AppControllerWithLandingPage}return AppController}
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});Object.defineProperty(exports,"createAppController",{enumerable:true,get:function(){return createAppController}});const _axios=require("@nestjs/axios");const _common=require("@nestjs/common");const _config=require("@nestjs/config");const _terminus=require("@nestjs/terminus");const _allianceinternalnodeutilities=require("@telia-ace/alliance-internal-node-utilities");const _express=require("express");const _graphqlrequest=require("graphql-request");const _config1=require("./config");const _graphql=require("./graphql");const _html=require("./html");const _responses=require("./responses");function _ts_decorate(decorators,target,key,desc){var c=arguments.length,r=c<3?target:desc===null?desc=Object.getOwnPropertyDescriptor(target,key):desc,d;if(typeof Reflect==="object"&&typeof Reflect.decorate==="function")r=Reflect.decorate(decorators,target,key,desc);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;return c>3&&r&&Object.defineProperty(target,key,r),r}function _ts_metadata(k,v){if(typeof Reflect==="object"&&typeof Reflect.metadata==="function")return Reflect.metadata(k,v)}function _ts_param(paramIndex,decorator){return function(target,key){decorator(target,key,paramIndex)}}function createAppController(){const environmentWorkspace=process.env[_config1.ConfigKeys.Workspace];let AppController=class AppController{async signin(){}async favicon(){return""}async health(workspace){const slug=environmentWorkspace||workspace;if(slug){let existingWorkspace=null;try{const{workspace}=await (0,_graphqlrequest.request)(this.configService.getOrThrow(_allianceinternalnodeutilities.SharedConfigKeys.DbEndpoint),_graphql.GetWorkspaceDocument,{slug},{authorization:(0,_allianceinternalnodeutilities.createSystemUserToken)(this.configService)});existingWorkspace=workspace}catch{}if(!existingWorkspace){throw new _common.NotFoundException}}return this.healthService.check([()=>this.redisHealthCheck.isHealthy()])}async cookiePolicy(){const{data}=await this.httpService.axiosRef.get(this.wpPolicyUrl);return data}async index(req,res,workspaceParam){return this.portal(req,res,environmentWorkspace||workspaceParam)}async workspace(_1,res,_2){return res.status(_common.HttpStatus.NOT_FOUND).send("Not Available")}async portal(req,res,workspaceSlug){let existingWorkspace=null;try{const{workspace}=await (0,_graphqlrequest.request)(this.configService.getOrThrow(_allianceinternalnodeutilities.SharedConfigKeys.DbEndpoint),_graphql.GetWorkspaceDocument,{slug:workspaceSlug},{authorization:(0,_allianceinternalnodeutilities.createSystemUserToken)(this.configService)});existingWorkspace=workspace}catch(error){if(error?.code==="ECONNREFUSED"){return(0,_responses.dbError)(res)}}if(!existingWorkspace){return(0,_responses.workspaceNotFoundError)(res,workspaceSlug)}let userHasAccess=false;try{const objectId=req?.oidc?.user?.sub;const{user}=await (0,_graphqlrequest.request)(this.configService.getOrThrow(_allianceinternalnodeutilities.SharedConfigKeys.DbEndpoint),_graphql.GetUserDocument,{objectId,workspaceSlug},{authorization:(0,_allianceinternalnodeutilities.createSystemUserToken)(this.configService)});userHasAccess=!!user.id}catch{}if(!userHasAccess){return(0,_responses.unauthorizedError)(res,workspaceSlug)}this.logger.info("opening portal",{user:req.oidc.user,workspaceSlug});return(0,_responses.ok)(res,(0,_html.htmlTemplate)(existingWorkspace.slug==="system"?"ACE Enterprise Portal":`ACE Customer Portal - ${existingWorkspace.name}`,(0,_html.loaderHtml)(),(0,_html.globalVariables)(this.configService,workspaceSlug),(0,_html.embedScript)(this.wpUrl,!!req.query["wp-tag"]||!!req.query["wp-version"]?{}:{tag:this.wpTag})))}constructor(logger,configService,httpService,healthService,redisHealthCheck){this.logger=logger;this.configService=configService;this.httpService=httpService;this.healthService=healthService;this.redisHealthCheck=redisHealthCheck;this.wpUrl=this.configService.getOrThrow(_config1.ConfigKeys.WebprovisionsDistributionUrl);this.wpPolicyUrl=this.configService.get(_config1.ConfigKeys.WebprovisionsDistributionCookiePolicyUrl)||`${this.wpUrl}/cookie-policy.html`;this.wpTag=this.configService.get(_config1.ConfigKeys.WebprovisionsTag)}};_ts_decorate([(0,_common.Get)("/signin-oidc"),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],AppController.prototype,"signin",null);_ts_decorate([(0,_common.Get)("/favicon*"),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],AppController.prototype,"favicon",null);_ts_decorate([(0,_common.Get)(["/-/health","/:workspace/-/health"]),(0,_terminus.HealthCheck)(),_ts_param(0,(0,_common.Param)("workspace")),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[String])],AppController.prototype,"health",null);_ts_decorate([(0,_common.Get)(environmentWorkspace?"/cookie-policy":"/:workspace/cookie-policy"),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[])],AppController.prototype,"cookiePolicy",null);_ts_decorate([(0,_common.Get)(environmentWorkspace?"/*":"/:workspace*"),_ts_param(0,(0,_common.Req)()),_ts_param(1,(0,_common.Res)()),_ts_param(2,(0,_common.Param)("workspace")),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _express.Request==="undefined"?Object:_express.Request,typeof _express.Response==="undefined"?Object:_express.Response,String])],AppController.prototype,"index",null);_ts_decorate([_ts_param(0,(0,_common.Req)()),_ts_param(1,(0,_common.Res)()),_ts_param(2,(0,_common.Param)("workspace")),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _express.Request==="undefined"?Object:_express.Request,typeof _express.Response==="undefined"?Object:_express.Response,String])],AppController.prototype,"workspace",null);AppController=_ts_decorate([(0,_common.Controller)(),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _allianceinternalnodeutilities.LoggerService==="undefined"?Object:_allianceinternalnodeutilities.LoggerService,typeof _config.ConfigService==="undefined"?Object:_config.ConfigService,typeof _axios.HttpService==="undefined"?Object:_axios.HttpService,typeof _terminus.HealthCheckService==="undefined"?Object:_terminus.HealthCheckService,typeof _allianceinternalnodeutilities.RedisHealthIndicator==="undefined"?Object:_allianceinternalnodeutilities.RedisHealthIndicator])],AppController);if(!process.env[_config1.ConfigKeys.LandingPage]||process.env[_config1.ConfigKeys.LandingPage]==="true"){let AppControllerWithLandingPage=class AppControllerWithLandingPage extends AppController{async health(workspace){return super.health(workspace)}async index(_,res){return(0,_responses.ok)(res,(0,_html.htmlTemplate)("ACE Customer Portal - Landing Page",(0,_html.loaderHtml)(),(0,_html.embedScript)("https://embed.webprovisions.io/resource/alliance/landing-page")))}async workspace(req,res,workspaceParam){return super.index(req,res,workspaceParam)}};_ts_decorate([(0,_common.Get)(["/-/health","/:workspace/-/health"]),(0,_terminus.HealthCheck)(),_ts_param(0,(0,_common.Param)("workspace")),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[String])],AppControllerWithLandingPage.prototype,"health",null);_ts_decorate([(0,_common.Get)("/"),_ts_param(0,(0,_common.Req)()),_ts_param(1,(0,_common.Res)()),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _express.Request==="undefined"?Object:_express.Request,typeof _express.Response==="undefined"?Object:_express.Response])],AppControllerWithLandingPage.prototype,"index",null);_ts_decorate([(0,_common.Get)("/:workspace*"),_ts_param(0,(0,_common.Req)()),_ts_param(1,(0,_common.Res)()),_ts_param(2,(0,_common.Param)("workspace")),_ts_metadata("design:type",Function),_ts_metadata("design:paramtypes",[typeof _express.Request==="undefined"?Object:_express.Request,typeof _express.Response==="undefined"?Object:_express.Response,String])],AppControllerWithLandingPage.prototype,"workspace",null);AppControllerWithLandingPage=_ts_decorate([(0,_common.Controller)()],AppControllerWithLandingPage);return AppControllerWithLandingPage}return AppController}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});const _axios=require("@nestjs/axios");const _config=require("@nestjs/config");const _terminus=require("@nestjs/terminus");const _testing=require("@nestjs/testing");const _allianceinternalnodeutilities=require("@telia-ace/alliance-internal-node-utilities");const _vitest=require("vitest");const _config1=require("./config");const _graphql=require("./graphql");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interop_require_wildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={__proto__:null};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}_vitest.vi.mock("graphql-request",async()=>{return{request:_vitest.vi.fn().mockImplementation(async(_1,_2,{slug,objectId})=>{if(objectId==="has-access"){return{user:{id:objectId}}}if(slug==="exists"){return{workspace:{slug,name:"Exists"}}}if(slug==="system"){return{workspace:{slug,name:"System"}}}return})}});(0,_vitest.describe)("AppController",()=>{const cfg={[_config1.ConfigKeys.AuthAuthority]:"test authority",[_config1.ConfigKeys.AuthClientSecret]:"test client secret",[_config1.ConfigKeys.AuthClientId]:"test client id",[_config1.ConfigKeys.ServiceBaseUrl]:"http://base-url",[_config1.ConfigKeys.WebprovisionsDistributionUrl]:"http://localhost:1234/distribution",[_config1.ConfigKeys.WebprovisionsDistributionCookiePolicyUrl]:"http://localhost:1234/cookie-policy.html",[_config1.ConfigKeys.WebprovisionsTag]:"the-tag",[_allianceinternalnodeutilities.SharedConfigKeys.DbEndpoint]:"http://localhost:1234/mocked-db"};let mock;async function setupMock(override={}){_vitest.vi.unstubAllEnvs();const{createAppController}=await Promise.resolve().then(()=>_interop_require_wildcard(require("./app.controller")));for(const[key,value]of Object.entries({...cfg,...override})){if(value){_vitest.vi.stubEnv(key,value)}}const AppController=createAppController();const module=await _testing.Test.createTestingModule({controllers:[AppController],providers:[_allianceinternalnodeutilities.RedisHealthIndicator],imports:[_config.ConfigModule.forRoot({isGlobal:true,validate:_config1.zConfig.parse,ignoreEnvFile:true}),_terminus.TerminusModule,_allianceinternalnodeutilities.LoggerModule.forRoot({logLevel:"silent"}),_axios.HttpModule]}).compile();return{ctrl:module.get(AppController),module}}(0,_vitest.beforeEach)(async()=>{mock=await setupMock()});(0,_vitest.afterEach)(async()=>{await mock.module.close()});(0,_vitest.it)("defines ctrl",()=>{(0,_vitest.expect)(mock.ctrl).toBeDefined()});(0,_vitest.describe)("cookiePolicy",()=>{(0,_vitest.it)("fetches using configured cookie policy url",async()=>{const http=mock.module.get(_axios.HttpService);const spy=_vitest.vi.spyOn(http.axiosRef,"get").mockResolvedValue({});await mock.ctrl.cookiePolicy();(0,_vitest.expect)(spy).toHaveBeenCalledWith("http://localhost:1234/cookie-policy.html")});(0,_vitest.it)("fetches using {WEBPROVISIONS_DISTRIBUTION_URL}/cookie-policy.html by default",async()=>{mock=await setupMock({[_config1.ConfigKeys.WebprovisionsDistributionCookiePolicyUrl]:undefined});const http=mock.module.get(_axios.HttpService);const spy=_vitest.vi.spyOn(http.axiosRef,"get").mockResolvedValue({});await mock.ctrl.cookiePolicy();(0,_vitest.expect)(spy).toHaveBeenCalledWith("http://localhost:1234/distribution/cookie-policy.html")})});(0,_vitest.describe)("health",()=>{(0,_vitest.it)("it calls health service check",async()=>{const health=mock.module.get(_terminus.HealthCheckService);const spy=_vitest.vi.spyOn(health,"check").mockResolvedValue({status:"ok",details:{}});await mock.ctrl.health();(0,_vitest.expect)(spy).toHaveBeenCalled()})});(0,_vitest.describe)("portal",async()=>{function mockReqRes({objectId,query={}}){const req={oidc:{user:{sub:objectId}},query};const res={statusCode:0,status:code=>{res.statusCode=code;return res},send:r=>r};return[req,res]}(0,_vitest.
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});const _axios=require("@nestjs/axios");const _common=require("@nestjs/common");const _config=require("@nestjs/config");const _terminus=require("@nestjs/terminus");const _testing=require("@nestjs/testing");const _allianceinternalnodeutilities=require("@telia-ace/alliance-internal-node-utilities");const _vitest=require("vitest");const _config1=require("./config");const _graphql=require("./graphql");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap;var cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interop_require_wildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj}}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj)}var newObj={__proto__:null};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc)}else{newObj[key]=obj[key]}}}newObj.default=obj;if(cache){cache.set(obj,newObj)}return newObj}_vitest.vi.mock("graphql-request",async()=>{return{request:_vitest.vi.fn().mockImplementation(async(_1,_2,{slug,objectId})=>{if(objectId==="has-access"){return{user:{id:objectId}}}if(slug==="exists"){return{workspace:{slug,name:"Exists"}}}if(slug==="system"){return{workspace:{slug,name:"System"}}}return})}});(0,_vitest.describe)("AppController",()=>{const cfg={[_config1.ConfigKeys.AuthAuthority]:"test authority",[_config1.ConfigKeys.AuthClientSecret]:"test client secret",[_config1.ConfigKeys.AuthClientId]:"test client id",[_config1.ConfigKeys.ServiceBaseUrl]:"http://base-url",[_config1.ConfigKeys.WebprovisionsDistributionUrl]:"http://localhost:1234/distribution",[_config1.ConfigKeys.WebprovisionsDistributionCookiePolicyUrl]:"http://localhost:1234/cookie-policy.html",[_config1.ConfigKeys.WebprovisionsTag]:"the-tag",[_allianceinternalnodeutilities.SharedConfigKeys.DbEndpoint]:"http://localhost:1234/mocked-db"};let mock;async function setupMock(override={}){_vitest.vi.unstubAllEnvs();const{createAppController}=await Promise.resolve().then(()=>_interop_require_wildcard(require("./app.controller")));for(const[key,value]of Object.entries({...cfg,...override})){if(value){_vitest.vi.stubEnv(key,value)}}const AppController=createAppController();const module=await _testing.Test.createTestingModule({controllers:[AppController],providers:[_allianceinternalnodeutilities.RedisHealthIndicator],imports:[_config.ConfigModule.forRoot({isGlobal:true,validate:_config1.zConfig.parse,ignoreEnvFile:true}),_terminus.TerminusModule,_allianceinternalnodeutilities.LoggerModule.forRoot({logLevel:"silent"}),_axios.HttpModule]}).compile();return{ctrl:module.get(AppController),module}}(0,_vitest.beforeEach)(async()=>{mock=await setupMock()});(0,_vitest.afterEach)(async()=>{await mock.module.close();_vitest.vi.clearAllMocks()});(0,_vitest.it)("defines ctrl",()=>{(0,_vitest.expect)(mock.ctrl).toBeDefined()});(0,_vitest.describe)("cookiePolicy",()=>{(0,_vitest.it)("fetches using configured cookie policy url",async()=>{const http=mock.module.get(_axios.HttpService);const spy=_vitest.vi.spyOn(http.axiosRef,"get").mockResolvedValue({});await mock.ctrl.cookiePolicy();(0,_vitest.expect)(spy).toHaveBeenCalledWith("http://localhost:1234/cookie-policy.html")});(0,_vitest.it)("fetches using {WEBPROVISIONS_DISTRIBUTION_URL}/cookie-policy.html by default",async()=>{mock=await setupMock({[_config1.ConfigKeys.WebprovisionsDistributionCookiePolicyUrl]:undefined});const http=mock.module.get(_axios.HttpService);const spy=_vitest.vi.spyOn(http.axiosRef,"get").mockResolvedValue({});await mock.ctrl.cookiePolicy();(0,_vitest.expect)(spy).toHaveBeenCalledWith("http://localhost:1234/distribution/cookie-policy.html")})});(0,_vitest.describe)("health",()=>{(0,_vitest.it)("it calls health service check",async()=>{const health=mock.module.get(_terminus.HealthCheckService);const spy=_vitest.vi.spyOn(health,"check").mockResolvedValue({status:"ok",details:{}});await mock.ctrl.health();(0,_vitest.expect)(spy).toHaveBeenCalled()});(0,_vitest.it)("calls graphql to check for workspace existance if present in url",async()=>{const{request}=await Promise.resolve().then(()=>_interop_require_wildcard(require("graphql-request")));const health=mock.module.get(_terminus.HealthCheckService);const spy=_vitest.vi.spyOn(health,"check").mockResolvedValue({status:"ok",details:{}});await mock.ctrl.health("exists");(0,_vitest.expect)(request).toHaveBeenCalled();(0,_vitest.expect)(spy).toHaveBeenCalled()});(0,_vitest.it)("returns 404 if does not exist",async()=>{await (0,_vitest.expect)(()=>mock.ctrl.health("doesnt exist")).rejects.toThrowError(_common.NotFoundException)})});(0,_vitest.describe)("portal",async()=>{function mockReqRes({objectId,query={}}){const req={oidc:{user:{sub:objectId}},query};const res={statusCode:0,status:code=>{res.statusCode=code;return res},send:r=>r};return[req,res]}(0,_vitest.it)("calls graphql",async()=>{const{request}=await Promise.resolve().then(()=>_interop_require_wildcard(require("graphql-request")));const[req,res]=mockReqRes({objectId:"guid"});await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(request).toHaveBeenCalledTimes(2);const[firstCall,secondCall]=request.mock.calls;const[firstUrl,firstDocument,firstArgs]=firstCall;const[_,secondDocument,secondArgs]=secondCall;(0,_vitest.expect)(firstUrl).toBe("http://localhost:1234/mocked-db");(0,_vitest.expect)(firstDocument).toEqual(_graphql.GetWorkspaceDocument);(0,_vitest.expect)(firstArgs).toEqual({slug:"exists"});(0,_vitest.expect)(secondDocument).toEqual(_graphql.GetUserDocument);(0,_vitest.expect)(secondArgs).toEqual({objectId:"guid",workspaceSlug:"exists"})});(0,_vitest.it)("returns 200 for authorized user",async()=>{const[req,res]=mockReqRes({objectId:"has-access"});const result=await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(result).toContain("http://localhost:1234/distribution");(0,_vitest.expect)(res.statusCode).toBe(200)});(0,_vitest.it)("returns 401 for unauthorized user",async()=>{const[req,res]=mockReqRes({objectId:"does-not-have-access"});const result=await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(result).toContain("You don't have access to the workspace");(0,_vitest.expect)(res.statusCode).toBe(401)});(0,_vitest.it)("returns 404 for non existant workspace",async()=>{const[req,res]=mockReqRes({objectId:"does-not-have-access"});const result=await mock.ctrl.portal(req,res,"doesnt-exist");(0,_vitest.expect)(result).toContain("The workspace 'doesnt-exist' does not exist");(0,_vitest.expect)(res.statusCode).toBe(404)});(0,_vitest.describe)("web page title",()=>{(0,_vitest.it)("correct for regular workspace",async()=>{const[req,res]=mockReqRes({objectId:"has-access"});const result=await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(result).toContain("<title>ACE Customer Portal - Exists</title>")});(0,_vitest.it)("correct for system",async()=>{const[req,res]=mockReqRes({objectId:"has-access"});const result=await mock.ctrl.portal(req,res,"system");(0,_vitest.expect)(result).toContain("<title>ACE Enterprise Portal</title>")})});(0,_vitest.describe)("webprovisions tags",()=>{(0,_vitest.it)("adds webprovisions tag if configured",async()=>{const[req,res]=mockReqRes({objectId:"has-access"});const result=await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(result).toContain('{"tag":"the-tag"}')});(0,_vitest.it)("does not add webprovisions tag if not configured",async()=>{mock=await setupMock({[_config1.ConfigKeys.WebprovisionsTag]:undefined});const[req,res]=mockReqRes({objectId:"has-access"});const result=await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(result).toContain("{}")});(0,_vitest.it)("does not add configured webprovisions tag when wp query strings are present",async()=>{let[req,res]=mockReqRes({objectId:"has-access",query:{"wp-tag":"some-tag"}});const withTagQuery=await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(withTagQuery).not.toContain('{"tag":"the-tag"}');[req,res]=mockReqRes({objectId:"has-access",query:{"wp-version":"some-version"}});const withVersionQuery=await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(withVersionQuery).not.toContain('{"tag":"the-tag"}')})});(0,_vitest.describe)("landing page",()=>{(0,_vitest.it)("returns landing page on url root by default",async()=>{const[req,res]=mockReqRes({objectId:"has-access"});const result=await mock.ctrl.index(req,res,"exists");(0,_vitest.expect)(result).toContain("https://embed.webprovisions.io/resource/alliance/landing-page")});(0,_vitest.it)("returns portal with landing page set to false",async()=>{mock=await setupMock({[_config1.ConfigKeys.LandingPage]:"false"});const[req,res]=mockReqRes({objectId:"has-access"});const result=await mock.ctrl.portal(req,res,"exists");(0,_vitest.expect)(result).toContain("http://localhost:1234/distribution")})})})});
|
package/dist/responses.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:all[name]})}_export(exports,{dbError:function(){return dbError},ok:function(){return ok},unauthorizedError:function(){return unauthorizedError},workspaceNotFoundError:function(){return workspaceNotFoundError}});const _common=require("@nestjs/common");const _html=require("./html");function dbError(res){return error(res,_common.HttpStatus.INTERNAL_SERVER_ERROR,"Error when contacting database.")}function unauthorizedError(res,workspaceSlug){return error(res,_common.HttpStatus.UNAUTHORIZED,`You don't have
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:true});function _export(target,all){for(var name in all)Object.defineProperty(target,name,{enumerable:true,get:all[name]})}_export(exports,{dbError:function(){return dbError},ok:function(){return ok},unauthorizedError:function(){return unauthorizedError},workspaceNotFoundError:function(){return workspaceNotFoundError}});const _common=require("@nestjs/common");const _html=require("./html");function dbError(res){return error(res,_common.HttpStatus.INTERNAL_SERVER_ERROR,"Error when contacting database.")}function unauthorizedError(res,workspaceSlug){return error(res,_common.HttpStatus.UNAUTHORIZED,`You don't have access to the workspace '${workspaceSlug}'.`)}function workspaceNotFoundError(res,workspaceSlug){return error(res,_common.HttpStatus.NOT_FOUND,`The workspace '${workspaceSlug}' does not exist.`)}function error(res,code,msg){return res.status(code).send((0,_html.htmlTemplate)(`ACE Portal - ${code}`,(0,_html.errorBody)(code,msg)))}function ok(res,content){return res.status(_common.HttpStatus.OK).send(content)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@telia-ace/alliance-portal",
|
|
3
|
-
"version": "1.0.7
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "ACE Alliance portal",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"author": "Telia Company AB",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"@nestjs/core": "^10.2.7",
|
|
20
20
|
"@nestjs/platform-express": "^10.2.7",
|
|
21
21
|
"@nestjs/terminus": "^10.1.1",
|
|
22
|
-
"@telia-ace/alliance-internal-node-utilities": "1.0.4
|
|
22
|
+
"@telia-ace/alliance-internal-node-utilities": "1.0.4",
|
|
23
23
|
"dotenv": "^16.3.1",
|
|
24
24
|
"express": "^4.18.2",
|
|
25
25
|
"graphql": "^16.8.1",
|