Skip to content

Commit

Permalink
Merge pull request #14 from digital-asset/publish-package
Browse files Browse the repository at this point in the history
Publish package
  • Loading branch information
alexmatson-da authored Feb 23, 2021
2 parents d10d0e1 + ef28664 commit 121fef8
Show file tree
Hide file tree
Showing 5 changed files with 376 additions and 305 deletions.
45 changes: 40 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
version: 2.1
orbs:
node: circleci/[email protected]
jobs:
test:
executor:
name: node/default

commands:
test_steps:
steps:
- checkout
- node/install-packages:
Expand All @@ -13,7 +12,43 @@ jobs:
command: yarn test
name: Run tests via yarn

jobs:
test:
executor:
name: node/default
steps:
- test_steps

test_build_and_publish:
executor:
name: node/default
steps:
- test_steps
- run:
command: yarn build
name: Compile TS to JS
- run:
name: Authenticate with registry
command: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
- run:
name: Publish package
command: npm publish --access public

workflows:
test_my_app:
jobs:
- test
- test:
filters:
tags:
ignore: /^v.*/

publish:
jobs:
- test_build_and_publish:
context:
- npm-automation
filters:
tags:
only: /^v.*/
branches:
ignore: /.*/
9 changes: 4 additions & 5 deletions PublicLedger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test('PublicLedger', async () => {
fetchMock.mockResponse(JSON.stringify({access_token:PUBLIC_TOKEN}));
const {result, waitForValueToChange} = renderPublicLedgerHook(() => { return 'we-have-a-token'; });
expect(fetchMock.mock.calls.length).toEqual(1);
expect(result.current).toEqual(null);
expect(result.current).toEqual(undefined);
await waitForValueToChange(() => result.current);
expect(result.current).toEqual('we-have-a-token');
});
Expand All @@ -38,7 +38,7 @@ test('usePartyAsPublic', async () => {
fetchMock.mockResponse(JSON.stringify({access_token:PUBLIC_TOKEN}));
const {result, waitForValueToChange} = renderPublicLedgerHook(() => { return usePartyAsPublic(); });
expect(fetchMock.mock.calls.length).toEqual(1);
expect(result.current).toEqual(null);
expect(result.current).toEqual(undefined);
await waitForValueToChange(() => result.current);
expect(result.current).toEqual(PUBLIC_PARTY);
})
Expand All @@ -47,7 +47,7 @@ test('useLedgerAsPublic', async () => {
fetchMock.mockResponse(JSON.stringify({access_token:PUBLIC_TOKEN}));
const {result, waitForValueToChange} = renderPublicLedgerHook(() => { return useLedgerAsPublic(); });
expect(fetchMock.mock.calls.length).toEqual(1);
expect(result.current).toEqual(null);
expect(result.current).toEqual(undefined);
await waitForValueToChange(() => result.current);
expect(result.current).toHaveProperty('token');
})
Expand All @@ -58,9 +58,8 @@ test('useQueryAsPublic', () => {
fetchMock.mockResponse(JSON.stringify({access_token:PUBLIC_TOKEN}));
const {result} = renderPublicLedgerHook(() => { return useQueryAsPublic(Foo); });
expect(fetchMock.mock.calls.length).toEqual(1);
expect(result.current).toEqual(null);
expect(result.current).toEqual(undefined);
// TODO. Currently fails because of async time out.
//await waitForValueToChange(() => result.current);
//expect(result.current).toStrictEqual({contracts:[],loading:true});
});

34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @daml/dabl-react
# @daml/hub-react

> React functions for DAML applications running on [projectDABL](https://projectdabl.com/).
> React functions for Daml applications running on [projectDABL](https://projectdabl.com/).
Copyright 2020 Digital Asset (Switzerland) GmbH and/or its affiliates. All Rights Reserved. SPDX-License-Identifier: Apache-2.0

Expand All @@ -10,11 +10,13 @@ This library aims to complement [@daml/react](`https://www.npmjs.com/package/@da
to make it easier to write [React](https://reactjs.org/) applications on DABL specifically.
To that end we provide for convenience.

This library exports Typescript declarations, and should work in a Typescript project out of the box.

## Usage

### Well Known End point

DABL provides an `.well-known` endpoint ([see](https://docs.projectdabl.com/api/iam/#listening-for-new-users)), that provides the identity of Party's who can run automation or
DABL provides an `.well-known` endpoint ([see](https://docs.projectdabl.com/api/iam/#listening-for-new-users)), that provides the identity of Parties who can run automation or
observe common information for your application.

```typescript
Expand All @@ -41,16 +43,28 @@ One of the Well Known parties, is the **Public** party that can be used to discl
</PublicLedger>
```

### Information within the JWT.
### Parties Login

For standard applications, we recommend using the login with button endpoint, a simple anchor tag that links to the DABL login endpoint (as described [here](https://docs.projectdabl.com/api/iam/#the-login-in-with-dabl-button)). The endpoint will redirect back to your application with a JWT access token and party ID, and is the right way for **real production users** to log in to your application.

For development purposes, it may be useful to be able to supply a list of party credentials for easy login, to test your app from the point-of-view of different parties. You can do so with the `DablPartiesInput` component, which allows you to load in the `parties.json` file. This file can be downloaded from the Users tab of the ledger in the project:DABL management console.

The file is not uploaded anywhere, but is parsed in-browser via the [FileReader APIs](https://developer.mozilla.org/en-US/docs/Web/API/FileReader). Note that access tokens expire every 24 hours.

```typescript
let usersPartyName = partyName(token);
let needToResetLogin = expiredToken(token);
<DablPartiesInput
ledgerId='ledger-xyz'
onLoad={
parties => parties.map(p => console.log(`Party ID: ${p.party}, party token: ${p.token}`))
}
/>
```

## Using
### JWT Utilities.

At the current moment, this library is *not* deployed to npm. To use:
Ledger access tokens come in the form of JSON Web Tokens, and this library provides functions to extract information out of issued JWTs.

1. `make build`
2. Then `yarn link file:path-to-generated-lib-directory` in your project.
```typescript
let usersPartyName = partyName(token);
let needToResetLogin = expiredToken(token);
```
28 changes: 18 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,43 @@
{
"name": "@daml/dabl-react",
"version": "1.0.0",
"description": "DAML React functions for DABL.",
"name": "@daml/hub-react",
"version": "0.1.0",
"description": "Daml React functions for Daml Hub.",
"homepage": "https://projectdabl.com",
"keywords": [
"dabl",
"daml hub",
"daml",
"react",
"client",
"API"
],
"main": "lib/index.js",
"license": "0BSD",
"types": "lib/index.d.js",
"files": [
"lib/**/*"
],
"license": "Apache-2.0",
"dependencies": {
"@daml/react": "1.7.0",
"@daml/types": "1.7.0",
"@daml/react": "1.9.0",
"@daml/ledger": "1.9.0",
"@mojotech/json-type-validation": "^3.1.0",
"@types/jsonwebtoken": "^8.5.0",
"jsonwebtoken": "^8.5.1",
"react": "^16.12.0"
},
"repository": "github:digital-asset/dabl-react",
"scripts": {
"build": "tsc --build",
"build:watch": "tsc --build --watch",
"test": "jest",
"lint": "eslint --ext .ts --ignore-pattern lib/ --max-warnings 0 ./"
},
"devDependencies": {
"@daml/ledger": "1.7.0",
"@testing-library/react-hooks": "^3.3.0",
"@daml/types": "1.9.0",
"@testing-library/react-hooks": "^5.0.3",
"@types/jest": "^24.0.23",
"@types/jsonwebtoken": "^8.5.0",
"@types/node": "^14.0.14",
"@types/react": "^16.9.20",
"@types/testing-library__react-hooks": "^3.2.0",
"@typescript-eslint/eslint-plugin": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"eslint": "^6.8.0",
Expand All @@ -42,6 +47,9 @@
"ts-jest": "^26.1.1",
"typescript": "~3.8.3"
},
"resolutions": {
"@types/react": "^16.9.20"
},
"jest": {
"testEnvironment": "jsdom",
"testMatch": [
Expand Down
Loading

0 comments on commit 121fef8

Please sign in to comment.