Skip to content

Commit

Permalink
Platform agnostic sdk (#278)
Browse files Browse the repository at this point in the history
* Remove JSON-RPC

* Remove grpc-v1 from nodejs sdk

* Remove types associated only with v1 api

* Explicitly state version of types versioned by node protocol version

* update changelogs

* Cleanup

* Lint fix

* Create grpc client from common with grpcweb transport

* Create subclasses for transport layers

* Undo rename

* Add wallet functionality to common

* Move nodejs specific client to subpath

* Remove unused packages

* Fix example sdk imports

* Ensure rust-bindings exposes target compatible with bundling for nodejs

* Expose esm web target

* Configure browser map

* Fix failing tests

* Include tests depending on node connection (though not for CI)

* Adapt documentation

* Fix documentation links

* Update readmes

* Fix changelog

* Add entries in documentation per pub module

* Fix failing tests

* Fix examples

* Upgrade bs58check to get browser compatibility

* Move nodejs crypto dependants to nodejs subpath

* Remove fetch type def

* Fix tests

* Apply suggestions from code review

Co-authored-by: Emil Holm Gjørup <[email protected]>

* Clean up based on PR review

---------

Co-authored-by: Emil Holm Gjørup <[email protected]>
  • Loading branch information
soerenbf and limemloh authored Oct 4, 2023
1 parent f0942d2 commit 065e221
Show file tree
Hide file tree
Showing 354 changed files with 1,203 additions and 4,504 deletions.
12 changes: 3 additions & 9 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ module.exports = {
tsconfigRootDir: __dirname,
project: [
'./packages/**/tsconfig.json',
'./packages/**/tsconfig.eslint.json',
'./tsconfig.eslint.json',
'./examples/tsconfig.eslint.json',
'./docs/**/tsconfig.json',
'**/tsconfig.eslint.json',
],
},
plugins: ['@typescript-eslint', 'import'],
Expand All @@ -33,12 +32,7 @@ module.exports = {
'import/no-unresolved': [
2,
{
ignore: [
'@concordium/rust-bindings',
'@concordium/common-sdk',
'@concordium/node-sdk',
'grpc-api',
],
ignore: ['@concordium/rust-bindings', 'grpc-api'],
},
],
'import/no-extraneous-dependencies': [
Expand Down
16 changes: 3 additions & 13 deletions .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ jobs:
uses: actions/cache@v3
with:
path: |
./packages/common/src/grpc-api
./packages/nodejs/src/grpc-api
./packages/sdk/src/grpc-api
key: ${{ runner.os }}-grpc-${{ hashFiles('deps/concordium-base/concordium-grpc-api') }}
restore-keys: ${{ runner.os }}-grpc

Expand All @@ -79,9 +78,8 @@ jobs:
with:
name: build-release
path: |
packages/common/lib
packages/nodejs/lib
packages/web/lib
packages/sdk/lib
packages/sdk/src
packages/rust-bindings/lib/**/index*
packages/*/package.json
packages/*/README.md
Expand All @@ -102,14 +100,6 @@ jobs:
with:
name: build-release

- name: Restore grpc
uses: actions/cache/restore@v3
with:
path: |
./packages/common/src/grpc-api
./packages/nodejs/src/grpc-api
key: ${{ runner.os }}-grpc

- name: Restore cached dependencies
uses: actions/cache/restore@v3
with:
Expand Down
46 changes: 11 additions & 35 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ name: Build, lint and typecheck examples
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [main, release**]
branches: [ main, release** ]
pull_request:
branches: [main, release**]
branches: [ main, release** ]
# Don't run on draft PR's, see: https://github.com/orgs/community/discussions/25722#discussioncomment-3248917
types: [opened, synchronize, reopened, ready_for_review]
types: [ opened, synchronize, reopened, ready_for_review ]
# Allows us to run the workflow manually from the Actions tab
workflow_dispatch:


env:
DUMMY: 1 # For cache busting.
NODE_VERSION: 18.16.0
Expand Down Expand Up @@ -64,8 +65,7 @@ jobs:
uses: actions/cache@v3
with:
path: |
./packages/common/src/grpc-api
./packages/nodejs/src/grpc-api
./packages/sdk/src/grpc-api
key: ${{ runner.os }}-grpc-${{ hashFiles('deps/concordium-base/concordium-grpc-api') }}-${{ env.DUMMY }}
restore-keys: ${{ runner.os }}-grpc

Expand Down Expand Up @@ -107,11 +107,11 @@ jobs:
uses: ./.github/actions/upload-artifact
with:
name: build-debug
# sdk/src is needed here because of sdk/src/grpc-api
path: |
./packages/rust-bindings/lib
./packages/common/lib
./packages/web/lib
./packages/nodejs/lib
./packages/sdk/lib
./packages/sdk/src
./packages/ccd-js-gen/lib
typecheck-examples:
Expand Down Expand Up @@ -141,12 +141,12 @@ jobs:
- name: Typecheck examples
run: yarn workspace @concordium/examples typecheck

common-tests:
tests:
runs-on: ubuntu-22.04
needs: build
defaults:
run:
working-directory: packages/common
working-directory: packages/sdk
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -166,21 +166,13 @@ jobs:
./docs/node_modules
key: ${{ runner.os }}-yarn

- name: Restore grpc
uses: actions/cache/restore@v3
with:
path: |
./packages/common/src/grpc-api
./packages/nodejs/src/grpc-api
key: ${{ runner.os }}-grpc

- name: Get build-debug
uses: ./.github/actions/download-artifact
with:
name: build-debug

- name: Run Tests
run: yarn test
run: yarn test-ci

typedoc:
runs-on: ubuntu-22.04
Expand All @@ -201,14 +193,6 @@ jobs:
./docs/node_modules
key: ${{ runner.os }}-yarn

- name: Restore grpc
uses: actions/cache/restore@v3
with:
path: |
./packages/common/src/grpc-api
./packages/nodejs/src/grpc-api
key: ${{ runner.os }}-grpc

- name: Get build-debug
uses: ./.github/actions/download-artifact
with:
Expand Down Expand Up @@ -237,14 +221,6 @@ jobs:
./docs/node_modules
key: ${{ runner.os }}-yarn

- name: Restore grpc
uses: actions/cache/restore@v3
with:
path: |
./packages/common/src/grpc-api
./packages/nodejs/src/grpc-api
key: ${{ runner.os }}-grpc

- name: Get build-debug
uses: ./.github/actions/download-artifact
with:
Expand Down
10 changes: 5 additions & 5 deletions .markdown-linkcheck.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"ignorePatterns": [
{
"pattern": "classes/Common_GRPC_Client.ConcordiumGRPCClient.html"
}
]
"ignorePatterns": [
{
"pattern": "classes/grpc.ConcordiumGRPCClient.html"
}
]
}
4 changes: 2 additions & 2 deletions .markdownlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ MD035:
style: "consistent"

# MD036/no-emphasis-as-heading/no-emphasis-as-header - Emphasis used instead of a heading
MD036:
MD036: false
# Punctuation characters
punctuation: ".,;:!?。,;:!?"
# punctuation: ".,;:!?。,;:!?"

# MD037/no-space-in-emphasis - Spaces inside emphasis markers
MD037: true
Expand Down
82 changes: 15 additions & 67 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,15 @@ Wrappers for interacting with the Concordium node.
- [Concordium SDK for Javascript](#concordium-sdk-for-javascript)
- [Documentation](#documentation)
- [Packages](#packages)
- [Nodejs package](#nodejs-package)
- [Web package](#web-package)
- [Common package](#common-package)
- [SDK package](#sdk-package)
- [Rust-bindings package](#rust-bindings-package)
- [Install/updating dependencies](#installupdating-dependencies)
- [MacOS arm64](#macos-arm64)
- [Build](#build)
- [Building for a release](#building-for-a-release)
- [Building for development](#building-for-development)
- [Making a new release](#making-a-new-release)
- [common](#common)
- [nodejs](#nodejs)
- [web](#web)
- [SDK](#sdk)
- [rust-bindings](#rust-bindings)
- [Test](#test)
<!--toc:end-->
Expand All @@ -37,27 +33,16 @@ for more information

Contains the different packages for the JS-SDKs.

### Nodejs package
### SDK package

The [Nodejs package](./packages/nodejs) contains the Nodejs SDK, particularly
the client that wraps the GRPC calls to the node, is located here.

### Web package

The [Web package](./packages/web) contains the Web SDK, which can used in
a web environment.

### Common package

The [common package](./packages/common) contains the shared library for the
Nodejs and Web SDK's. The GRPC-client, all serialization and most utility
functions are located in this package.
The [SDK](./packages/sdk) contains the actual SDK, which can used in
both a web and NodeJS environment.

### Rust-bindings package

The [common package](./packages/common) contains bindings for Rust code,
which is used by the common package. This package is a utility package that
should not be used directly, only through the usage of the common package.
The [rust-bindings](./packages/rust-bindings) contains bindings for Rust code,
which is used by the SDK through WASM. This package is a utility package that
should not be used directly, only through the usage of the SDK.

## Install/updating dependencies

Expand Down Expand Up @@ -96,9 +81,6 @@ yarn build

This will build all the subprojects.

Note that you must have [wasm-pack](https://rustwasm.github.io/wasm-pack/)
installed to build the project.

### Building for development

To build the project quickly during development run
Expand All @@ -115,60 +97,26 @@ Note that this skips generating the grpc API and optimizing the wasm modules.
The following describes the requirements for creating a new release for
each of the packages contained in this repository.

### common
### SDK

- Bump the version in [package.json](./packages/common/package.json).
- Update the [CHANGELOG](./packages/common/CHANGELOG.md) describing the
- Bump the version in [package.json](./packages/sdk/package.json).
- Update the [CHANGELOG](./packages/sdk/CHANGELOG.md) describing the
changes made.
- Update the dependency to common in the [web](./packages/web/package.json)
and [nodejs](./packages/nodejs/package.json) packages.
- Update the CHANGELOG in the [web](./packages/web/CHANGELOG.md) and
[nodejs](./packages/nodejs/CHANGELOG.md) packages.
- Add a change entry: Bumped @concordium/common-sdk to x.y.z.
- Commit and tag the release.
- Tag should be `common/x.y.z`.
- Tag should be `sdk/x.y.z`.
- Run the deploy workflow.
- Under github actions, run the "deploy" workflow and download the
`build-release` artifact. Unpack this file and use it for the release.
- Publish the release to NPM.
- From the common package directory (packages/common) run `yarn npm publish`

### nodejs

- Bump the version in [package.json](./packages/nodejs/package.json).
- Update the [CHANGELOG](./packages/nodejs/CHANGELOG.md) describing the
changes made.
- Commit and tag the release.
- Tag should be `nodejs/x.y.z`.
- Build the release.
- Under github actions, run the "deploy" workflow and download the
`build-release` artifact. Unpack this file and use it for the release.
- Publish the release to NPM.
- From the nodejs package directory (packages/nodejs) run `yarn npm publish`

### web

- Bump the version in [package.json](./packages/web/package.json).
- Update the [CHANGELOG](./packages/web/CHANGELOG.md) describing the
changes made.
- Commit and tag the release.
- Tag should be `web/x.y.z`.
- Build the release.
- Under github actions, run the "deploy" workflow and download the
`build-release` artifact. Unpack this file and use it for the release.
- Publish the release to NPM.
- From the web package directory (packages/web) run `yarn npm publish`
- From the sdk package directory (packages/sdk) run `yarn npm publish`

### rust-bindings

- Bump the version in [package.json](./packages/rust-bindings/package.json).
- Update the [CHANGELOG](./packages/rust-bindings/CHANGELOG.md) describing
the changes made.
- Update the dependency to rust-bindings in the
[common](./packages/common/package.json) and
[web](./packages/web/package.json) packages.
- Update the CHANGELOG in the [common](./packages/common/CHANGELOG.md) and
[web](./packages/web/CHANGELOG.md) packages.
- Update the dependency to rust-bindings in the [sdk](./packages/sdk/package.json)
- Update the CHANGELOG in the [sdk](./packages/sdk/CHANGELOG.md)
- Add a change entry: Bumped @concordium/rust-bindings to x.y.z.
- Commit and tag the release.
- Tag should be `rust-bindings/x.y.z`.
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/cis2-contracts.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ This document describes the helper class for working with CIS-2 contracts
## CIS2Contract

The CIS2Contract class wraps the
[ConcordiumGRPCClient](../classes/Common_GRPC_Client.ConcordiumGRPCClient.html),
[ConcordiumGRPCClient](../classes/grpc.ConcordiumGRPCClient.html),
defining an interface matching the [CIS-2
standard](https://proposals.concordium.software/CIS/cis-2.html).

Expand Down
15 changes: 7 additions & 8 deletions docs/pages/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ This is the documentation for the Concordium Javascript SDK. Here we cover
the JS wrappers for interacting with the Concordium nodes.

Most functionality is provideded by the
[GRPC-Client](../classes/Common_GRPC_Client.ConcordiumGRPCClient.html)
[GRPC-Client](../classes/grpc.ConcordiumGRPCClient.html)
however there exists additional helper functions, for example to help with
creating {@page transactions.md transactions}, or {@page identity-proofs.md
creating identity proof statements}, or {@page utility-functions.md general
Expand All @@ -11,26 +11,25 @@ utility functions}.
A good way to get started is to check out the {@page runnable-examples.md
runnable examples}.

To create a GRPC-Client in NodeJS-SDK:
To create a GRPC-Client for use with nodeJS:

```ts
import { credentials } from '@grpc/grpc-js/';
import { createConcordiumClient } from '@concordium/node-sdk';
import { ConcordiumGRPCNodeClient, credentials } from '@concordium/web-sdk/nodejs';
...
return createConcordiumClient(
return new ConcordiumGRPCNodeClient(
address,
port,
credentials.createSsl(),
{ timeout: 15000 }
);
```

To create a GRPC-Client in the Web-SDK:
To create a GRPC-Client for use in a browser (requires GRPC-web enabled on the node):

```ts
import { createConcordiumClient } from '@concordium/web-sdk';
import { ConcordiumGRPCWebClient } from '@concordium/web-sdk';
...
return createConcordiumClient(
return new ConcordiumGRPCWebClient(
address,
port,
{ timeout: 15000 }
Expand Down
Loading

0 comments on commit 065e221

Please sign in to comment.