api message project is added

This commit is contained in:
병준 박 2019-11-13 13:55:28 +09:00
parent 457c22390c
commit a33ee7c2ff
18 changed files with 341 additions and 1 deletions

View File

@ -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": { "ucap-webmessenger-api": {
"projectType": "library", "projectType": "library",
"root": "projects/ucap-webmessenger-api", "root": "projects/ucap-webmessenger-api",

View File

@ -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).

View File

@ -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
});
};

View File

@ -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"
}
}

View File

@ -0,0 +1,8 @@
{
"name": "@ucap-webmessenger/api-message",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^8.2.11",
"@angular/core": "^8.2.11"
}
}

View File

@ -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<UpdateInfoRequest> = (
req: UpdateInfoRequest
) => {
return ParameterUtil.encode(updateInfoEncodeMap, req);
};
export const decodeUpdateInfo: APIDecoder<UpdateInfoResponse> = (res: any) => {
return {
statusCode: res.StatusCode,
errorMessage: res.ErrorMessage,
appVersion: res.AppVer,
installUrl: res.InstallURL,
launcherAppVersion: res.LauncherAppVer,
launcherInstallUrl: res.LauncherInstallURL,
} as UpdateInfoResponse;
};

View File

@ -0,0 +1,5 @@
import { ModuleConfig as CoreModuleConfig } from '@ucap-webmessenger/core';
import { Urls } from './urls';
export interface ModuleConfig extends CoreModuleConfig<Urls> {}

View File

@ -0,0 +1,5 @@
import { InjectionToken } from '@angular/core';
export const _MODULE_CONFIG = new InjectionToken(
'@ucap-webmessenger/api-message config of module'
);

View File

@ -0,0 +1,3 @@
export interface Urls {
versionInfo2: string;
}

View File

@ -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();
});
});

View File

@ -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<UpdateInfoResponse> {
return this.httpClient
.post<any>(
this.urls.versionInfo2,
{},
{
params: encodeUpdateInfo(req),
}
)
.pipe(map(res => decodeUpdateInfo(res)));
}
}

View File

@ -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<UCapMessageApiModule> {
return {
ngModule: UCapMessageApiModule,
providers: [{ provide: _MODULE_CONFIG, useValue: config }, ...SERVICES],
};
}
}

View File

@ -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';

View File

@ -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);

View File

@ -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"
]
}

View File

@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

View File

@ -0,0 +1,17 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"ucapApiMessage",
"camelCase"
],
"component-selector": [
true,
"element",
"ucap-api-message",
"kebab-case"
]
}
}

View File

@ -30,6 +30,9 @@
"@ucap-webmessenger/api-external": [ "@ucap-webmessenger/api-external": [
"projects/ucap-webmessenger-api-external/src/public-api" "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/pi": ["projects/ucap-webmessenger-pi/src/public-api"],
"@ucap-webmessenger/ui": ["projects/ucap-webmessenger-ui/src/public-api"], "@ucap-webmessenger/ui": ["projects/ucap-webmessenger-ui/src/public-api"],
"@ucap-webmessenger/ui-account": [ "@ucap-webmessenger/ui-account": [
@ -126,7 +129,6 @@
"projects/ucap-webmessenger-util/src/public-api" "projects/ucap-webmessenger-util/src/public-api"
], ],
"@app/*": ["projects/ucap-webmessenger-app/src/app/*"], "@app/*": ["projects/ucap-webmessenger-app/src/app/*"],
"@ucap-webmessenger/electron-core": [ "@ucap-webmessenger/electron-core": [
"electron-projects/ucap-webmessenger-electron-core/src/public-api" "electron-projects/ucap-webmessenger-electron-core/src/public-api"
], ],