Skip to content

Commit f8ea30c

Browse files
committed
Refactored NetworkClient
1 parent 01371a6 commit f8ea30c

10 files changed

+425
-339
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v1.0.1
4+
5+
* Refactored NetworkClient to make it more versatile
6+
* Export AddressHelper class from @iota-pico/business
7+
* Webpack bundling switch from Uglify to Terser
8+
39
## v1.0.0
410

511
* Final 1.0.0 Release

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@iota-pico/lib-browser",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "IOTA Pico Framework Library for Browser",
55
"main": "pkg/iota-pico-lib-browser.js",
66
"typings": "pkg/iota-pico-lib-browser.d.ts",
@@ -66,15 +66,15 @@
6666
"devDependencies": {
6767
"@types/emscripten": "0.0.31",
6868
"@types/jws": "^3.1.1",
69-
"@types/node": "^10.5.4",
69+
"@types/node": "^10.11.2",
7070
"cross-env": "^5.2.0",
7171
"ncp": "^2.0.0",
7272
"npm-run-all": "^4.1.3",
7373
"replace-in-file": "^3.4.2",
7474
"rimraf": "^2.6.2",
75-
"typescript": "^3.0.3",
76-
"uglifyjs-webpack-plugin": "^1.2.7",
77-
"webpack": "^4.16.3",
78-
"webpack-cli": "^3.1.0"
75+
"terser-webpack-plugin": "^1.1.0",
76+
"typescript": "^3.1.1",
77+
"webpack": "^4.20.2",
78+
"webpack-cli": "^3.1.1"
7979
}
8080
}

pkg/iota-pico-lib-browser-none.js

Lines changed: 118 additions & 94 deletions
Large diffs are not rendered by default.

pkg/iota-pico-lib-browser-none.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/iota-pico-lib-browser-webgl.js

Lines changed: 118 additions & 94 deletions
Large diffs are not rendered by default.

pkg/iota-pico-lib-browser-webgl.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/iota-pico-lib-browser.d.ts

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -347,43 +347,37 @@ export interface ILogger {
347347
export interface INetworkClient {
348348
/**
349349
* Get data asynchronously.
350+
* @param data The data to send.
350351
* @param additionalPath An additional path append to the endpoint path.
351352
* @param additionalHeaders Extra headers to send with the request.
352353
* @returns Promise which resolves to the object returned or rejects with error.
353354
*/
354-
get(additionalPath?: string, additionalHeaders?: {
355+
get(data: {
356+
[key: string]: any;
357+
}, additionalPath?: string, additionalHeaders?: {
355358
[header: string]: string;
356359
}): Promise<string>;
357360
/**
358361
* Post data asynchronously.
359-
* @param additionalPath An additional path append to the endpoint path.
360362
* @param data The data to send.
363+
* @param additionalPath An additional path append to the endpoint path.
361364
* @param additionalHeaders Extra headers to send with the request.
362365
* @returns Promise which resolves to the object returned or rejects with error.
363366
*/
364367
post(data: string, additionalPath?: string, additionalHeaders?: {
365368
[header: string]: string;
366369
}): Promise<string>;
367370
/**
368-
* Get data as JSON asynchronously.
369-
* @typeparam U The generic type for the returned object.
370-
* @param additionalPath An additional path append to the endpoint path.
371-
* @param additionalHeaders Extra headers to send with the request.
372-
* @returns Promise which resolves to the object returned or rejects with error.
373-
*/
374-
getJson<U>(additionalPath?: string, additionalHeaders?: {
375-
[header: string]: string;
376-
}): Promise<U>;
377-
/**
378-
* Post data as JSON asynchronously.
371+
* Request data as JSON asynchronously.
379372
* @typeparam T The generic type for the object to send.
380373
* @typeparam U The generic type for the returned object.
381-
* @param data The data to send.
374+
* @param data The data to send as the JSON body.
375+
* @param method The method to send with the request.
382376
* @param additionalPath An additional path append to the endpoint path.
383377
* @param additionalHeaders Extra headers to send with the request.
384378
* @returns Promise which resolves to the object returned or rejects with error.
385379
*/
386-
postJson<T, U>(data: T, additionalPath?: string, additionalHeaders?: {
380+
json<T, U>(data?: T, method?: NetworkMethod, additionalPath?: string, additionalHeaders?: {
387381
[header: string]: string;
388382
}): Promise<U>;
389383
/**
@@ -511,6 +505,11 @@ export interface ITimeService {
511505
msSinceEpoch(): number;
512506
}
513507

508+
/**
509+
* Represents the http request methods.
510+
*/
511+
export type NetworkMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
512+
514513
/**
515514
* Represents the protocols for communicating.
516515
*/
@@ -608,6 +607,12 @@ export class NetworkEndPoint implements INetworkEndPoint {
608607
* @param rootPath The path to the endpoint.
609608
*/
610609
constructor(protocol: NetworkProtocol, host: string, port: number, rootPath?: string);
610+
/**
611+
* Create a network endpoint by parsing a uri.
612+
* @param uri The uri to parse.
613+
* @returns The network endpoint.
614+
*/
615+
static fromUri(uri: string): INetworkEndPoint;
611616
/**
612617
* The protocol to access the endpoint with.
613618
* @returns The protocol.
@@ -2348,7 +2353,19 @@ export class BusinessError extends CoreError {
23482353
}, innerError?: Error);
23492354
}
23502355

2351-
export {};
2356+
/**
2357+
* Helper class for address signing.
2358+
* Original https://github.com/iotaledger/iota.lib.js/blob/master/lib/crypto/signing/signing.js
2359+
*/
2360+
export class AddressHelper {
2361+
/**
2362+
* Create a checksum for the trits.
2363+
* @param trits The trits to create the checksum for.
2364+
* @param checksumLength The length of the checksum.
2365+
* @returns the checksum as trytes.
2366+
*/
2367+
static createChecksum(trits: Int8Array, checksumLength: number): string;
2368+
}
23522369

23532370
/**
23542371
* Helper class for signing bundles.
@@ -3045,11 +3062,14 @@ export class NetworkClient implements INetworkClient {
30453062
constructor(networkEndPoint: INetworkEndPoint, logger?: ILogger, timeoutMs?: number);
30463063
/**
30473064
* Get data asynchronously.
3065+
* @param data The data to send.
30483066
* @param additionalPath An additional path append to the endpoint path.
30493067
* @param additionalHeaders Extra headers to send with the request.
30503068
* @returns Promise which resolves to the object returned or rejects with error.
30513069
*/
3052-
get(additionalPath?: string, additionalHeaders?: {
3070+
get(data: {
3071+
[key: string]: any;
3072+
}, additionalPath?: string, additionalHeaders?: {
30533073
[header: string]: string;
30543074
}): Promise<string>;
30553075
/**
@@ -3063,25 +3083,16 @@ export class NetworkClient implements INetworkClient {
30633083
[header: string]: string;
30643084
}): Promise<string>;
30653085
/**
3066-
* Get data as JSON asynchronously.
3067-
* @typeparam U The generic type for the returned object.
3068-
* @param additionalPath An additional path append to the endpoint path.
3069-
* @param additionalHeaders Extra headers to send with the request.
3070-
* @returns Promise which resolves to the object returned or rejects with error.
3071-
*/
3072-
getJson<U>(additionalPath?: string, additionalHeaders?: {
3073-
[header: string]: string;
3074-
}): Promise<U>;
3075-
/**
3076-
* Post data as JSON asynchronously.
3086+
* Request data as JSON asynchronously.
30773087
* @typeparam T The generic type for the object to send.
30783088
* @typeparam U The generic type for the returned object.
3079-
* @param data The data to send.
3089+
* @param data The data to send as the JSON body.
3090+
* @param method The method to send with the request.
30803091
* @param additionalPath An additional path append to the endpoint path.
30813092
* @param additionalHeaders Extra headers to send with the request.
30823093
* @returns Promise which resolves to the object returned or rejects with error.
30833094
*/
3084-
postJson<T, U>(data: T, additionalPath?: string, additionalHeaders?: {
3095+
json<T, U>(data?: T, method?: NetworkMethod, additionalPath?: string, additionalHeaders?: {
30853096
[header: string]: string;
30863097
}): Promise<U>;
30873098
/**

pkg/iota-pico-lib-browser.js

Lines changed: 123 additions & 99 deletions
Large diffs are not rendered by default.

pkg/iota-pico-lib-browser.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webpack.config.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path');
22
const fs = require('fs');
3-
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
3+
const TerserJsPlugin = require('terser-webpack-plugin');
44

55
const pkgFolder = path.join(__dirname, './pkg');
66
const bootstrapFile = path.join(pkgFolder, 'bootstrap.js');
@@ -17,11 +17,6 @@ if (!isDir) {
1717
}
1818
fs.writeFileSync(bootstrapFile, `exports.default = require("../dist/index-${process.env.LIB_VER}");`);
1919

20-
const plugins = [];
21-
if (isProd) {
22-
plugins.push(new UglifyJsPlugin());
23-
}
24-
2520
module.exports = {
2621
entry: bootstrapFile,
2722
output: {
@@ -59,5 +54,7 @@ module.exports = {
5954
Buffer: true,
6055
setImmediate: false
6156
},
62-
plugins
57+
optimization: {
58+
minimizer: isProd ? [ new TerserJsPlugin() ] : []
59+
}
6360
};

0 commit comments

Comments
 (0)