From a33ee7c2ff6bf6b89a6934f2f214773b11e73b17 Mon Sep 17 00:00:00 2001 From: Richard Park Date: Wed, 13 Nov 2019 13:55:28 +0900 Subject: [PATCH] api message project is added --- angular.json | 34 ++++++++++++ .../ucap-webmessenger-api-message/README.md | 24 +++++++++ .../karma.conf.js | 32 ++++++++++++ .../ng-package.json | 7 +++ .../package.json | 8 +++ .../src/lib/apis/update-info.ts | 40 ++++++++++++++ .../src/lib/config/module-config.ts | 5 ++ .../src/lib/config/token.ts | 5 ++ .../src/lib/config/urls.ts | 3 ++ .../lib/services/message-api.service.spec.ts | 12 +++++ .../src/lib/services/message-api.service.ts | 52 +++++++++++++++++++ .../src/lib/ucap-message-api.module.ts | 24 +++++++++ .../src/public-api.ts | 11 ++++ .../ucap-webmessenger-api-message/src/test.ts | 21 ++++++++ .../tsconfig.lib.json | 26 ++++++++++ .../tsconfig.spec.json | 17 ++++++ .../ucap-webmessenger-api-message/tslint.json | 17 ++++++ tsconfig.json | 4 +- 18 files changed, 341 insertions(+), 1 deletion(-) create mode 100644 projects/ucap-webmessenger-api-message/README.md create mode 100644 projects/ucap-webmessenger-api-message/karma.conf.js create mode 100644 projects/ucap-webmessenger-api-message/ng-package.json create mode 100644 projects/ucap-webmessenger-api-message/package.json create mode 100644 projects/ucap-webmessenger-api-message/src/lib/apis/update-info.ts create mode 100644 projects/ucap-webmessenger-api-message/src/lib/config/module-config.ts create mode 100644 projects/ucap-webmessenger-api-message/src/lib/config/token.ts create mode 100644 projects/ucap-webmessenger-api-message/src/lib/config/urls.ts create mode 100644 projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.spec.ts create mode 100644 projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.ts create mode 100644 projects/ucap-webmessenger-api-message/src/lib/ucap-message-api.module.ts create mode 100644 projects/ucap-webmessenger-api-message/src/public-api.ts create mode 100644 projects/ucap-webmessenger-api-message/src/test.ts create mode 100644 projects/ucap-webmessenger-api-message/tsconfig.lib.json create mode 100644 projects/ucap-webmessenger-api-message/tsconfig.spec.json create mode 100644 projects/ucap-webmessenger-api-message/tslint.json diff --git a/angular.json b/angular.json index beec10fe..9ad4430a 100644 --- a/angular.json +++ b/angular.json @@ -359,6 +359,40 @@ } } }, + "ucap-webmessenger-api-message": { + "projectType": "library", + "root": "projects/ucap-webmessenger-api-message", + "sourceRoot": "projects/ucap-webmessenger-api-message/src", + "prefix": "ucap-api-message", + "architect": { + "build": { + "builder": "@angular-devkit/build-ng-packagr:build", + "options": { + "tsConfig": "projects/ucap-webmessenger-api-message/tsconfig.lib.json", + "project": "projects/ucap-webmessenger-api-message/ng-package.json" + } + }, + "test": { + "builder": "@angular-devkit/build-angular:karma", + "options": { + "main": "projects/ucap-webmessenger-api-message/src/test.ts", + "tsConfig": "projects/ucap-webmessenger-api-message/tsconfig.spec.json", + "karmaConfig": "projects/ucap-webmessenger-api-message/karma.conf.js" + } + }, + "lint": { + "builder": "@angular-devkit/build-angular:tslint", + "options": { + "tsConfig": [ + "projects/ucap-webmessenger-api-message/tsconfig.lib.json", + "projects/ucap-webmessenger-api-message/tsconfig.spec.json" + ], + "exclude": ["**/node_modules/**"] + } + } + } + }, + "ucap-webmessenger-api": { "projectType": "library", "root": "projects/ucap-webmessenger-api", diff --git a/projects/ucap-webmessenger-api-message/README.md b/projects/ucap-webmessenger-api-message/README.md new file mode 100644 index 00000000..8265c6ca --- /dev/null +++ b/projects/ucap-webmessenger-api-message/README.md @@ -0,0 +1,24 @@ +# UcapWebmessengerApiMessage + +This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 8.2.11. + +## Code scaffolding + +Run `ng generate component component-name --project ucap-webmessenger-api-message` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project ucap-webmessenger-api-message`. +> Note: Don't forget to add `--project ucap-webmessenger-api-message` or else it will be added to the default project in your `angular.json` file. + +## Build + +Run `ng build ucap-webmessenger-api-message` to build the project. The build artifacts will be stored in the `dist/` directory. + +## Publishing + +After building your library with `ng build ucap-webmessenger-api-message`, go to the dist folder `cd dist/ucap-webmessenger-api-message` and run `npm publish`. + +## Running unit tests + +Run `ng test ucap-webmessenger-api-message` to execute the unit tests via [Karma](https://karma-runner.github.io). + +## Further help + +To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). diff --git a/projects/ucap-webmessenger-api-message/karma.conf.js b/projects/ucap-webmessenger-api-message/karma.conf.js new file mode 100644 index 00000000..30ab22f9 --- /dev/null +++ b/projects/ucap-webmessenger-api-message/karma.conf.js @@ -0,0 +1,32 @@ +// Karma configuration file, see link for more information +// https://karma-runner.github.io/1.0/config/configuration-file.html + +module.exports = function (config) { + config.set({ + basePath: '', + frameworks: ['jasmine', '@angular-devkit/build-angular'], + plugins: [ + require('karma-jasmine'), + require('karma-chrome-launcher'), + require('karma-jasmine-html-reporter'), + require('karma-coverage-istanbul-reporter'), + require('@angular-devkit/build-angular/plugins/karma') + ], + client: { + clearContext: false // leave Jasmine Spec Runner output visible in browser + }, + coverageIstanbulReporter: { + dir: require('path').join(__dirname, '../../coverage/ucap-webmessenger-api-message'), + reports: ['html', 'lcovonly', 'text-summary'], + fixWebpackSourcePaths: true + }, + reporters: ['progress', 'kjhtml'], + port: 9876, + colors: true, + logLevel: config.LOG_INFO, + autoWatch: true, + browsers: ['Chrome'], + singleRun: false, + restartOnFileChange: true + }); +}; diff --git a/projects/ucap-webmessenger-api-message/ng-package.json b/projects/ucap-webmessenger-api-message/ng-package.json new file mode 100644 index 00000000..7b43c75e --- /dev/null +++ b/projects/ucap-webmessenger-api-message/ng-package.json @@ -0,0 +1,7 @@ +{ + "$schema": "../../node_modules/ng-packagr/ng-package.schema.json", + "dest": "../../dist/ucap-webmessenger-api-message", + "lib": { + "entryFile": "src/public-api.ts" + } +} \ No newline at end of file diff --git a/projects/ucap-webmessenger-api-message/package.json b/projects/ucap-webmessenger-api-message/package.json new file mode 100644 index 00000000..2bc9d394 --- /dev/null +++ b/projects/ucap-webmessenger-api-message/package.json @@ -0,0 +1,8 @@ +{ + "name": "@ucap-webmessenger/api-message", + "version": "0.0.1", + "peerDependencies": { + "@angular/common": "^8.2.11", + "@angular/core": "^8.2.11" + } +} diff --git a/projects/ucap-webmessenger-api-message/src/lib/apis/update-info.ts b/projects/ucap-webmessenger-api-message/src/lib/apis/update-info.ts new file mode 100644 index 00000000..4a1cfea9 --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/lib/apis/update-info.ts @@ -0,0 +1,40 @@ +import { DeviceType } from '@ucap-webmessenger/core'; +import { + APIRequest, + APIResponse, + APIEncoder, + APIDecoder, + ParameterUtil, +} from '@ucap-webmessenger/api'; + +export interface UpdateInfoRequest extends APIRequest { + deviceType: DeviceType; +} + +export interface UpdateInfoResponse extends APIResponse { + appVersion?: string; + installUrl?: string; + launcherAppVersion?: string; + launcherInstallUrl?: string; +} + +const updateInfoEncodeMap = { + deviceType: 'p_device_type', +}; + +export const encodeUpdateInfo: APIEncoder = ( + req: UpdateInfoRequest +) => { + return ParameterUtil.encode(updateInfoEncodeMap, req); +}; + +export const decodeUpdateInfo: APIDecoder = (res: any) => { + return { + statusCode: res.StatusCode, + errorMessage: res.ErrorMessage, + appVersion: res.AppVer, + installUrl: res.InstallURL, + launcherAppVersion: res.LauncherAppVer, + launcherInstallUrl: res.LauncherInstallURL, + } as UpdateInfoResponse; +}; diff --git a/projects/ucap-webmessenger-api-message/src/lib/config/module-config.ts b/projects/ucap-webmessenger-api-message/src/lib/config/module-config.ts new file mode 100644 index 00000000..8e49cd75 --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/lib/config/module-config.ts @@ -0,0 +1,5 @@ +import { ModuleConfig as CoreModuleConfig } from '@ucap-webmessenger/core'; + +import { Urls } from './urls'; + +export interface ModuleConfig extends CoreModuleConfig {} diff --git a/projects/ucap-webmessenger-api-message/src/lib/config/token.ts b/projects/ucap-webmessenger-api-message/src/lib/config/token.ts new file mode 100644 index 00000000..6cb383dd --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/lib/config/token.ts @@ -0,0 +1,5 @@ +import { InjectionToken } from '@angular/core'; + +export const _MODULE_CONFIG = new InjectionToken( + '@ucap-webmessenger/api-message config of module' +); diff --git a/projects/ucap-webmessenger-api-message/src/lib/config/urls.ts b/projects/ucap-webmessenger-api-message/src/lib/config/urls.ts new file mode 100644 index 00000000..36063b65 --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/lib/config/urls.ts @@ -0,0 +1,3 @@ +export interface Urls { + versionInfo2: string; +} diff --git a/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.spec.ts b/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.spec.ts new file mode 100644 index 00000000..bf2baaeb --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.spec.ts @@ -0,0 +1,12 @@ +import { TestBed } from '@angular/core/testing'; + +import { MessageApiService } from './message-api.service'; + +describe('MessageApiService', () => { + beforeEach(() => TestBed.configureTestingModule({})); + + it('should be created', () => { + const service: MessageApiService = TestBed.get(MessageApiService); + expect(service).toBeTruthy(); + }); +}); diff --git a/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.ts b/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.ts new file mode 100644 index 00000000..35f0dc6d --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/lib/services/message-api.service.ts @@ -0,0 +1,52 @@ +import { Injectable, Inject } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; + +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; + +import { + VersionInfo2Request, + VersionInfo2Response, + encodeVersionInfo2, + decodeVersionInfo2, +} from '../apis/version-info2'; +import { + UpdateInfoRequest, + UpdateInfoResponse, + encodeUpdateInfo, + decodeUpdateInfo, +} from '../apis/update-info'; + +import { _MODULE_CONFIG } from '../config/token'; +import { ModuleConfig } from '../config/module-config'; +import { UrlConfig } from '@ucap-webmessenger/core'; +import { Urls } from '../config/urls'; + +@Injectable({ + providedIn: 'root', +}) +export class MessageApiService { + readonly urls: Urls; + + constructor( + @Inject(_MODULE_CONFIG) private moduleConfig: ModuleConfig, + private httpClient: HttpClient + ) { + this.urls = UrlConfig.getUrls( + this.moduleConfig.hostConfig, + this.moduleConfig.urls + ); + } + + public updateInfo(req: UpdateInfoRequest): Observable { + return this.httpClient + .post( + this.urls.versionInfo2, + {}, + { + params: encodeUpdateInfo(req), + } + ) + .pipe(map(res => decodeUpdateInfo(res))); + } +} diff --git a/projects/ucap-webmessenger-api-message/src/lib/ucap-message-api.module.ts b/projects/ucap-webmessenger-api-message/src/lib/ucap-message-api.module.ts new file mode 100644 index 00000000..601084a8 --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/lib/ucap-message-api.module.ts @@ -0,0 +1,24 @@ +import { NgModule, ModuleWithProviders } from '@angular/core'; + +import { MessageApiService } from './services/message-api.service'; + +import { _MODULE_CONFIG } from './config/token'; +import { ModuleConfig } from './config/module-config'; + +const SERVICES = [MessageApiService]; + +@NgModule({ + declarations: [], + imports: [], + exports: [], +}) +export class UCapMessageApiModule { + public static forRoot( + config: ModuleConfig + ): ModuleWithProviders { + return { + ngModule: UCapMessageApiModule, + providers: [{ provide: _MODULE_CONFIG, useValue: config }, ...SERVICES], + }; + } +} diff --git a/projects/ucap-webmessenger-api-message/src/public-api.ts b/projects/ucap-webmessenger-api-message/src/public-api.ts new file mode 100644 index 00000000..4be0924f --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/public-api.ts @@ -0,0 +1,11 @@ +/* + * Public API Surface of ucap-webmessenger-api-message + */ +export * from './lib/apis/update-info'; + +export * from './lib/services/message-api.service'; + +export * from './lib/ucap-message-api.module'; + +export * from './lib/config/urls'; +export * from './lib/config/module-config'; diff --git a/projects/ucap-webmessenger-api-message/src/test.ts b/projects/ucap-webmessenger-api-message/src/test.ts new file mode 100644 index 00000000..978c64fb --- /dev/null +++ b/projects/ucap-webmessenger-api-message/src/test.ts @@ -0,0 +1,21 @@ +// This file is required by karma.conf.js and loads recursively all the .spec and framework files + +import 'zone.js/dist/zone'; +import 'zone.js/dist/zone-testing'; +import { getTestBed } from '@angular/core/testing'; +import { + BrowserDynamicTestingModule, + platformBrowserDynamicTesting +} from '@angular/platform-browser-dynamic/testing'; + +declare const require: any; + +// First, initialize the Angular testing environment. +getTestBed().initTestEnvironment( + BrowserDynamicTestingModule, + platformBrowserDynamicTesting() +); +// Then we find all the tests. +const context = require.context('./', true, /\.spec\.ts$/); +// And load the modules. +context.keys().map(context); diff --git a/projects/ucap-webmessenger-api-message/tsconfig.lib.json b/projects/ucap-webmessenger-api-message/tsconfig.lib.json new file mode 100644 index 00000000..bd23948e --- /dev/null +++ b/projects/ucap-webmessenger-api-message/tsconfig.lib.json @@ -0,0 +1,26 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/lib", + "target": "es2015", + "declaration": true, + "inlineSources": true, + "types": [], + "lib": [ + "dom", + "es2018" + ] + }, + "angularCompilerOptions": { + "annotateForClosureCompiler": true, + "skipTemplateCodegen": true, + "strictMetadataEmit": true, + "fullTemplateTypeCheck": true, + "strictInjectionParameters": true, + "enableResourceInlining": true + }, + "exclude": [ + "src/test.ts", + "**/*.spec.ts" + ] +} diff --git a/projects/ucap-webmessenger-api-message/tsconfig.spec.json b/projects/ucap-webmessenger-api-message/tsconfig.spec.json new file mode 100644 index 00000000..16da33db --- /dev/null +++ b/projects/ucap-webmessenger-api-message/tsconfig.spec.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "../../out-tsc/spec", + "types": [ + "jasmine", + "node" + ] + }, + "files": [ + "src/test.ts" + ], + "include": [ + "**/*.spec.ts", + "**/*.d.ts" + ] +} diff --git a/projects/ucap-webmessenger-api-message/tslint.json b/projects/ucap-webmessenger-api-message/tslint.json new file mode 100644 index 00000000..75be226f --- /dev/null +++ b/projects/ucap-webmessenger-api-message/tslint.json @@ -0,0 +1,17 @@ +{ + "extends": "../../tslint.json", + "rules": { + "directive-selector": [ + true, + "attribute", + "ucapApiMessage", + "camelCase" + ], + "component-selector": [ + true, + "element", + "ucap-api-message", + "kebab-case" + ] + } +} diff --git a/tsconfig.json b/tsconfig.json index 16f61b0d..d45269df 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -30,6 +30,9 @@ "@ucap-webmessenger/api-external": [ "projects/ucap-webmessenger-api-external/src/public-api" ], + "@ucap-webmessenger/api-message": [ + "projects/ucap-webmessenger-api-message/src/public-api" + ], "@ucap-webmessenger/pi": ["projects/ucap-webmessenger-pi/src/public-api"], "@ucap-webmessenger/ui": ["projects/ucap-webmessenger-ui/src/public-api"], "@ucap-webmessenger/ui-account": [ @@ -126,7 +129,6 @@ "projects/ucap-webmessenger-util/src/public-api" ], "@app/*": ["projects/ucap-webmessenger-app/src/app/*"], - "@ucap-webmessenger/electron-core": [ "electron-projects/ucap-webmessenger-electron-core/src/public-api" ],