-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prepare for react-native support.
- Loading branch information
Showing
101 changed files
with
794 additions
and
1,288 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
"packageManager": "[email protected]", | ||
"scripts": { | ||
"build": "yarn workspaces foreach -t run build", | ||
"clean": "yarn workspaces foreach -t run clean", | ||
"lint": "yarn workspaces foreach -t run lint", | ||
"test": "yarn workspaces foreach -t run test" | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": [ | ||
"../../.eslintrc.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
/test/** | ||
/src/** | ||
jasmine*.json | ||
tsconfig*.json | ||
.eslintrc.json | ||
typedoc.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Logion Client SDK (browser) | ||
|
||
This project provides a JS/TypeScript SDK enabling an application running in a browser to interact with a logion network. | ||
|
||
## Installation | ||
|
||
Use your favorite package manager (e.g. yarn) and install package `@logion/client-browser` in your JavaScript/TypeScript project. | ||
|
||
## Usage | ||
|
||
See [core client](../client/README.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"spec_dir": "test", | ||
"spec_files": [ | ||
"**/*.spec.ts" | ||
], | ||
"helpers": [ | ||
"../typescript.js" | ||
], | ||
"stopSpecOnExpectationFailure": false, | ||
"reporters": [ | ||
{ | ||
"name": "jasmine-spec-reporter#SpecReporter" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"name": "@logion/client-browser", | ||
"version": "0.1.0-1", | ||
"description": "logion SDK for client applications running in a browser", | ||
"main": "dist/index.js", | ||
"packageManager": "[email protected]", | ||
"type": "module", | ||
"scripts": { | ||
"build": "yarn lint && tsc -p tsconfig.json", | ||
"lint": "yarn eslint src/**", | ||
"test": "NODE_OPTIONS=--loader=ts-node/esm jasmine --config=jasmine.json", | ||
"clean": "rm -rf dist" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/logion-network/logion-api.git", | ||
"directory": "packages/client-browser" | ||
}, | ||
"keywords": [ | ||
"logion", | ||
"api", | ||
"client", | ||
"browser" | ||
], | ||
"author": "Logion Team", | ||
"license": "Apache-2.0", | ||
"dependencies": { | ||
"@logion/client": "workspace:^" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/logion-network/logion-api/issues" | ||
}, | ||
"homepage": "https://github.com/logion-network/logion-api/packages/client-browser#readme", | ||
"devDependencies": { | ||
"@tsconfig/node18": "^1.0.1", | ||
"@types/jasmine": "^4.0.3", | ||
"@types/node": "^18.6.1", | ||
"@typescript-eslint/eslint-plugin": "^6.9.1", | ||
"@typescript-eslint/parser": "^6.9.1", | ||
"eslint": "^8.20.0", | ||
"jasmine": "^4.3.0", | ||
"jasmine-spec-reporter": "^7.0.0", | ||
"moq.ts": "^9.0.2", | ||
"ts-node": "^10.9.1", | ||
"typescript": "^5.2.2" | ||
}, | ||
"engines": { | ||
"node": ">=18" | ||
}, | ||
"stableVersion": "0.1.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { Hash as Hasher } from 'fast-sha256'; | ||
import { AxiosFileUploader, File, FormDataLike, HashAndSize } from "@logion/client"; | ||
import { Hash } from "@logion/node-api"; | ||
|
||
export class BrowserFile extends File { | ||
|
||
constructor(file: Blob) { | ||
super(); | ||
this.file = file; | ||
} | ||
|
||
private file: Blob; | ||
|
||
async getHashAndSize(): Promise<HashAndSize> { | ||
const unknownStream: any = this.file.stream(); // eslint-disable-line @typescript-eslint/no-explicit-any | ||
const reader = unknownStream.getReader(); | ||
const digest = new Hasher(); | ||
let size = 0n; | ||
let chunk: {done: boolean, value: Buffer} = await reader.read(); | ||
while(!chunk.done) { | ||
size = size + BigInt(chunk.value.length); | ||
digest.update(chunk.value); | ||
chunk = await reader.read(); | ||
} | ||
return { | ||
hash: Hash.fromDigest(digest), | ||
size, | ||
}; | ||
} | ||
|
||
getBlob(): Blob { | ||
return this.file; | ||
} | ||
} | ||
|
||
export class BrowserAxiosFileUploader extends AxiosFileUploader { | ||
|
||
override buildFormData(): FormDataLike { | ||
return new FormData(); | ||
} | ||
|
||
override toFormDataValue(file: File): Promise<any> { // eslint-disable-line @typescript-eslint/no-explicit-any | ||
if(file instanceof BrowserFile) { | ||
return Promise.resolve(file.getBlob()); | ||
} else { | ||
return Promise.reject(new Error("Unsupported file type")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Hash } from "@logion/node-api"; | ||
import { Mock, PlayTimes } from "moq.ts"; | ||
import { BrowserFile } from "../src/index.js"; | ||
|
||
const TEST_HASH = Hash.fromHex("0x9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"); | ||
|
||
describe("BrowserFile", () => { | ||
|
||
it("gets hash and size", async () => { | ||
const file = new BrowserFile(BLOB_MOCK); | ||
const hashSize = await file.getHashAndSize(); | ||
expect(hashSize.hash).toEqual(TEST_HASH); | ||
expect(hashSize.size).toBe(4n); | ||
}); | ||
}); | ||
|
||
const READER_MOCK = new Mock<any>() | ||
.setup(instance => instance.read()) | ||
.play(PlayTimes.Once()) | ||
.returns({ done: true }) | ||
|
||
.setup(instance => instance.read()) | ||
.play(PlayTimes.Once()) | ||
.returns({ done: false, value: Buffer.from("test") }) | ||
|
||
.object(); | ||
|
||
const STREAM_MOCK = new Mock<any>() | ||
.setup(instance => instance.getReader()) | ||
.returns(READER_MOCK) | ||
.object(); | ||
|
||
const BLOB_MOCK = new Mock<Blob>() | ||
.setup(instance => instance.stream()) | ||
.returns(STREAM_MOCK) | ||
.object(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "./dist", | ||
"lib": ["dom"], | ||
"baseUrl": "." | ||
}, | ||
"include": [ | ||
"./src/**/*" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "Client (Browser)", | ||
"entryPoints": [ | ||
"./src/index.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"extends": [ | ||
"../../.eslintrc.json" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/test/** | ||
/integration/** | ||
/src/** | ||
/scripts/** | ||
docker-compose.yml | ||
front_config.js | ||
front_web*.conf | ||
jasmine*.json | ||
tsconfig*.json | ||
/config/** | ||
.eslintrc.json | ||
typedoc.json | ||
typescript.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Logion Client SDK (browser) | ||
|
||
This project provides a JS/TypeScript SDK enabling an application running in a browser to interact with a logion network. | ||
|
||
## Installation | ||
|
||
Use your favorite package manager (e.g. yarn) and install package `@logion/client-browser` in your JavaScript/TypeScript project. | ||
|
||
## Usage | ||
|
||
See [core client](../client/README.md). |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/client/integration/Fees.ts → packages/client-node/integration/Fees.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { ALICE } from "../test/Utils.js"; | ||
import { ALICE } from "./Utils.js"; | ||
import { State, REQUESTER_ADDRESS } from "./Utils.js"; | ||
|
||
export async function fees(state: State) { | ||
const client = state.client; | ||
const api = client.logionApi; | ||
const submittable = api.polkadot.tx.balances.transfer(ALICE.address, "10000000"); | ||
const submittable = api.polkadot.tx.balances.transfer(ALICE, "10000000"); | ||
const fees = await client.public.fees.estimateWithoutStorage({ origin: REQUESTER_ADDRESS, submittable }); | ||
expect(fees.totalFee).toBe(3085311440000000n); | ||
} |
5 changes: 2 additions & 3 deletions
5
packages/client/integration/LegalOfficer.ts → ...s/client-node/integration/LegalOfficer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.