api message project is added
This commit is contained in:
parent
457c22390c
commit
a33ee7c2ff
34
angular.json
34
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",
|
||||
|
|
24
projects/ucap-webmessenger-api-message/README.md
Normal file
24
projects/ucap-webmessenger-api-message/README.md
Normal 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).
|
32
projects/ucap-webmessenger-api-message/karma.conf.js
Normal file
32
projects/ucap-webmessenger-api-message/karma.conf.js
Normal 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
|
||||
});
|
||||
};
|
7
projects/ucap-webmessenger-api-message/ng-package.json
Normal file
7
projects/ucap-webmessenger-api-message/ng-package.json
Normal 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"
|
||||
}
|
||||
}
|
8
projects/ucap-webmessenger-api-message/package.json
Normal file
8
projects/ucap-webmessenger-api-message/package.json
Normal 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"
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
|
@ -0,0 +1,5 @@
|
|||
import { ModuleConfig as CoreModuleConfig } from '@ucap-webmessenger/core';
|
||||
|
||||
import { Urls } from './urls';
|
||||
|
||||
export interface ModuleConfig extends CoreModuleConfig<Urls> {}
|
|
@ -0,0 +1,5 @@
|
|||
import { InjectionToken } from '@angular/core';
|
||||
|
||||
export const _MODULE_CONFIG = new InjectionToken(
|
||||
'@ucap-webmessenger/api-message config of module'
|
||||
);
|
|
@ -0,0 +1,3 @@
|
|||
export interface Urls {
|
||||
versionInfo2: string;
|
||||
}
|
|
@ -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();
|
||||
});
|
||||
});
|
|
@ -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)));
|
||||
}
|
||||
}
|
|
@ -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],
|
||||
};
|
||||
}
|
||||
}
|
11
projects/ucap-webmessenger-api-message/src/public-api.ts
Normal file
11
projects/ucap-webmessenger-api-message/src/public-api.ts
Normal 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';
|
21
projects/ucap-webmessenger-api-message/src/test.ts
Normal file
21
projects/ucap-webmessenger-api-message/src/test.ts
Normal 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);
|
26
projects/ucap-webmessenger-api-message/tsconfig.lib.json
Normal file
26
projects/ucap-webmessenger-api-message/tsconfig.lib.json
Normal 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"
|
||||
]
|
||||
}
|
17
projects/ucap-webmessenger-api-message/tsconfig.spec.json
Normal file
17
projects/ucap-webmessenger-api-message/tsconfig.spec.json
Normal 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"
|
||||
]
|
||||
}
|
17
projects/ucap-webmessenger-api-message/tslint.json
Normal file
17
projects/ucap-webmessenger-api-message/tslint.json
Normal file
|
@ -0,0 +1,17 @@
|
|||
{
|
||||
"extends": "../../tslint.json",
|
||||
"rules": {
|
||||
"directive-selector": [
|
||||
true,
|
||||
"attribute",
|
||||
"ucapApiMessage",
|
||||
"camelCase"
|
||||
],
|
||||
"component-selector": [
|
||||
true,
|
||||
"element",
|
||||
"ucap-api-message",
|
||||
"kebab-case"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
],
|
||||
|
|
Loading…
Reference in New Issue
Block a user