Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.0-alpha-3 #25

Merged
merged 30 commits into from Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1d207b3
PLT-7308 - Initial documentation around the wallet package
hrajchert Sep 6, 2023
31c34a9
PLT-6951 - Add method to get available wallets
hrajchert Sep 6, 2023
ec62d4a
Update changelog management
hrajchert Sep 6, 2023
63f8d30
link to marlowe-payouts
bjornkihlberg Sep 7, 2023
2ece18d
PLT-7308 - remove fp-ts from wallet package
hrajchert Sep 7, 2023
98c1236
PLT-7309 Remove fp-ts from the lifecycle package
hrajchert Sep 8, 2023
362c30a
PLT-7308 Remove fp-ts from getAddressesAndCollaterals
hrajchert Sep 11, 2023
e389b0d
Add api.md
hrajchert Sep 12, 2023
4f1280d
PLT-7498 Improve SDK imports
hrajchert Sep 12, 2023
f0e7aa9
Add default npm importmap to project root
hrajchert Sep 18, 2023
8065f62
Pair programming improvements
nhenin Sep 18, 2023
33d9117
Fix e2e module name mapper
hrajchert Sep 18, 2023
29ee661
Improved documentation
hrajchert Sep 18, 2023
09a13e9
Merge pull request #27 from input-output-hk/hrajchert/PLT-7498-improv…
nhenin Sep 19, 2023
6207544
Fix inter-package typedoc links
hrajchert Sep 19, 2023
37a7eb1
Fix inter-package typedoc links
hrajchert Sep 19, 2023
f5e462c
[runtime-lifecycle] removed classes/cleaned interfaces & doc
nhenin Sep 22, 2023
5d8702f
[wallet] renamed createBrowserWallet to mkBrowserWallet
nhenin Sep 25, 2023
16c7f61
[bug] fixed issues related to the use of object for the walletAPI imp…
nhenin Sep 25, 2023
499952b
bumped to "0.2.0-alpha-1"
nhenin Sep 25, 2023
2ac2ac0
added change log
nhenin Sep 25, 2023
c792293
Merge pull request #29 from input-output-hk/PLT-7597
nhenin Sep 25, 2023
ce23d58
Add mkFlatRestAPI to runtime-rest-client
hrajchert Sep 20, 2023
92a6282
Renamed RestAPI to FPTSRestAPI
hrajchert Sep 25, 2023
dafdaf9
Bump alpha version
hrajchert Sep 25, 2023
53a6f58
Add getContractById to RestAPI
hrajchert Sep 26, 2023
1ba5f02
Merge pull request #28 from hrajchert/hrajchert/PLT-7501-remove-fpts-…
nhenin Sep 26, 2023
47c3c83
bumped to 0.2.0-alpha-3
nhenin Sep 26, 2023
4c97b32
Merge pull request #30 from input-output-hk/bumped-0.2.-alpha-3
nhenin Sep 26, 2023
3b204fd
Fix npm importmap
hrajchert Sep 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -18,9 +18,11 @@ source
dist
test-dist

.cache
.local
package-lock.json
yarn.lock
# nixago: ignore-linked-files
/lefthook.yml
/.editorconfig
/treefmt.toml
/treefmt.toml
3 changes: 3 additions & 0 deletions .vscode/settings.json
@@ -0,0 +1,3 @@
{
"typescript.tsdk": "node_modules/typescript/lib"
}
61 changes: 17 additions & 44 deletions Readme.md
@@ -1,5 +1,5 @@
<div align="left">
<img src="./doc/image/logo.svg" alt="Logo" width="100" height="100">
<img src="./doc/image/logo.svg" alt="Logo" width="100" height="100">
</div>

Official Links
Expand All @@ -14,68 +14,41 @@ Official Links

# Overview

`marlowe-ts-sdk` is a suite of **TypeScript/JavaScript** libraries for Web Cardano Dapp Development using Marlowe Technologies.

It is composed of the following [npm workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces) :

- Language
- [@marlowe.io/language-core-v1](./packages/language/core/v1/)
- Marlowe Core V1 constructs
- JSON Codec
- Cardano Wallet
- [@marlowe.io/wallet](./packages/runtime/core/)
- Wallet Extension Capabalities (Browser / CIP-30)
- Single Wallet Address Capabalities(NodeJS / Version used for e2e tests only)
- Runtime
- [@marlowe.io/runtime-lifecycle](./packages/runtime/lifecycle/) : Entry Point for Running remotely Marlowe Contracts over a backend instance of the runtime using a connected wallet.
- Marlowe Tx Commands
- Create
- Applying Inputs
- Withdraws
- Query capabilities for supporting these commands
- [@marlowe.io/runtime-core](./packages/runtime/core/) : core concepts used throughout the runtime libraries.
- [@marlowe.io/runtime-rest-client](./packages/runtime/client/rest/) : client of the runtime rest api.
- Infrastruture Supporting SubDomains
- [@marlowe.io/adapter](./packages/adapter) : supporting set of libraries for Marlowe and Runtime Core Domains.

# Get Started
The **Marlowe TS-SDK** is a suite of _TypeScript/JavaScript_ libraries for developing Web-Dapp in the Cardano Blockchain using Marlowe Technologies.

It is composed of several npm packages documented in the [API reference](https://input-output-hk.github.io/marlowe-ts-sdk/) page.

## Prerequesites

- Runtime instance available : How to ? (TODO)
- Wallet Extension installed : (TODO)
In order to start working with the Marlowe SDK you need to have a URL to a running instance of the Marlowe Runtime and one of the supported wallet extensions installed in your browser.

To get a running instance of the Runtime, it is recommended to check out the instructions on the [Marlowe Starter Kit](https://github.com/input-output-hk/marlowe-starter-kit)

## Wallet Extensions

### Compatible

- Nami
- Eternl
- [Nami](https://namiwallet.io/)
- [Eternl](https://eternl.io/)

### Non Compatiible
### Non Compatible

- Lace
- Lace: TODO: add github issue with the current problem

### Non Tested

- TODO

## NPM

```bash
npm install @marlowe.io/adapter @marlowe.io/wallet @marlowe.io/language-core-v1 @marlowe.io/runtime @marlowe.io/runtime-core @marlowe.io/runtime-rest-client
```

## Examples

- TODO
Inside the [pocs folder](./pocs/Readme.md) you can find a set of minimal examples on how to use different packages of the SDK.

- [wallet flow](./pocs/wallet-flow.html): Simple example on how to use the `@marlowe.io/wallet` package to connect to a wallet extension and get basic info.

## Basic usage
More elaborate examples can be found in the following repositories:

```
TODO
```
- [marlowe-payouts](https://github.com/input-output-hk/marlowe-payouts)

# Development

see documentation [here](./doc/howToDevelop.md).
To help in the development of this SDK, please refer to [this document](./doc/howToDevelop.md).
@@ -1,3 +1,3 @@
### Changed
### General

- Reformat code with [prettier](https://prettier.io/) and [alejandra](https://github.com/kamadorueda/alejandra) using the [treefmt](https://github.com/numtide/treefmt-nix) tool
@@ -0,0 +1,4 @@
### @marlowe.io/wallet

- Added typedoc documentation.
- Renamed the `pocs/runtimeCIP30Flow.html` to `pocs/wallet-flow.html` and modified it to highlight the wallet capabilities.
@@ -0,0 +1,4 @@
### @marlowe.io/wallet

- **BREAKING CHANGE:** Removed `fp-ts` from the user facing API.
- **BREAKING CHANGE:** In the browser module `getExtensionInstance` was renamed to `createBrowserWallet`
@@ -0,0 +1,3 @@
### @marlowe.io/runtime-lifecycle

- **BREAKING CHANGE:** Removed `fp-ts` from the user facing API
@@ -0,0 +1,3 @@
### General

- Improved the way the SDK gets imported in the browser by the use of importmaps. Included import documentation in each package.
7 changes: 7 additions & 0 deletions changelog.d/20230925_144650_nicolas.henin.md
@@ -0,0 +1,7 @@
### @marlowe.io/wallet

- renamed renamed createBrowserWallet to mkBrowserWallet

### @marlowe.io/runtime-lifecycle

- Fixed `this undefined` issues when calling `mkRuntimeLifecycle`
@@ -0,0 +1,3 @@
### @marlowe.io/runtime-rest-client

- BREAKING CHANGE: Replaced mkRestClient interface for a flat API that resembles the backend documentation structure.
2 changes: 1 addition & 1 deletion changelog.d/scriv.ini
@@ -1,3 +1,3 @@
[scriv]
format = md
version = 1.0.0.0
categories = General, @marlowe.io/wallet, @marlowe.io/adapter, @marlowe.io/language-core-v1, @marlowe.io/runtime-rest-client, @marlowe.io/runtime-core, @marlowe.io/runtime-lifecycle
58 changes: 58 additions & 0 deletions doc/howToDevelop.md
Expand Up @@ -94,3 +94,61 @@ $ scriv create
```

edit the new file with appropriate content for your PR and commit it. Read [the documentation for scriv](https://scriv.readthedocs.io/en) to learn more about how to use this tool.

To collect all changelog entries into a single file, execute `std` from the nix shell and run the `build-changelog` script. This command will delete all entries from the `changelog.d` folder and update the `CHANGELOG.md` file.

## Publish

For the moment the SDK is manually published to npm. Task PLT-6939 captures the work to automate this process through the CI.

Before publishing it is convinient to check that the artifacts works as expected :

- Clean & Build

```bash
$ npm run clean && npm run build
```

- Test

```bash
$ npm t && npm run test:e2e
```

- Check the packages
To test this you can pack all the different packages into tarballs using

```bash
$ npm --workspaces pack --pack-destination dist
```

And in a separate project you can install the tarballs using a file url when declaring the dependency

```json
{
"dependencies": {
"@marlowe.io/runtime-lifecycle": "file:<path-to-dist>/marlowe.io-runtime-lifecycle-0.2.0-alpha-3.tgz",
"@marlowe.io/runtime-rest-client": "file:<path-to-dist>/marlowe.io-runtime-rest-client-0.2.0-alpha-3.tgz",
"@marlowe.io/adapter": "file:<path-to-dist>/marlowe.io-adapter-0.2.0-alpha-3.tgz",
"@marlowe.io/runtime-core": "file:<path-to-dist>/marlowe.io-runtime-core-0.2.0-alpha-3.tgz",
"@marlowe.io/language-core-v1": "file:<path-to-dist>/marlowe.io-language-core-v1-0.2.0-alpha-3.tgz",
"@marlowe.io/wallet": "file:<path-to-dist>/marlowe.io-wallet-0.2.0-alpha-3.tgz"
}
}
```

TODO [[Publish pre-check]] Local map and this pack instructions
TODO instructions on how to manually publish
In order to check that the export/import mechanism works on the browser using import maps you can:

1. Create a testing branch in a fork of the repo
1. Clean and build the project `npm run clean && npm run build`
1. Remove `dist` from `.gitignore`
1. Commit the `dist` folders of the different packages
1. Get the full git hash of the commit using `git rev-parse HEAD`
1. Publish the branch in your fork
1. Modify `rollup/config.mjs` and set the correct `owner` and `version` when we build the import map for jsdelivr-gh.
1. Rebuild the project `npm run build`
1. Modify the html in the `pocs` folder to use `/dist/jsdelivr-gh-importmap.js`
1. From the root folder run `npx http-server --port 1337 -c-1 -o ./`
1. Verify that each poc example works properly.
27 changes: 27 additions & 0 deletions doc/modules-system.md
@@ -0,0 +1,27 @@
# Modules System

Javascript didn't have an official module support until ESM was introduced in 2015, in 2020 all the major browsers implemented it. By 2023, the community is still in the process of migrating from CommonJS, UMD, etc to ESM, and different tools and libraries have varying support for it.

## ESM

The Marlowe SDK is built using ESM modules but one of its dependencies (fp-ts) doesn't [correctly implement it](https://github.com/gcanti/fp-ts/issues/1777) in its current version. For that reason, we use [rollup](https://rollupjs.org/) to generate a ESM bundle that includes fp-ts. To ease development, we also generate [import maps](https://github.com/WICG/import-maps#import-maps) that tell the browser where to find the different modules.

In most packages documentation you'll find something like:

```html
<script src="https://cdn.jsdelivr.net/gh/input-output-hk/marlowe-ts-sdk/jsdelivr-npm-importmap.js"></script>
<script type="module">
import * as wallet from "@marlowe.io/wallet";
// ...
</script>
```

If you are using a bundler you don't need the import map as each `package.json`` correctly points to a module using the [exports property](https://webpack.js.org/guides/package-exports/).

> NOTE: Because of how `fp-ts` is bundled, it is included (and tree-shaked) in all the SDK bundled packages, so using your own bundling step can help you reduce the size of the downloaded code.

## CommonJS

> NOTE: [[CommonJS exports problem]]

This repository configures how to be imported using `ESM` and `CJS` modules, but the latter is currently not working because one of the dependencies [does not support CJS](https://github.com/spacebudz/lucid#compatibility). We need to re-assess if we can use an alternative that does support CJS so that it is easier to import the SDK from older setups.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 1 addition & 12 deletions flake.nix
Expand Up @@ -16,24 +16,13 @@
} @ inputs:
std.growOn {
inherit inputs;
# 1. Each folder inside `cellsFrom` becomes a "Cell"
# Run for example: 'mkdir nix/mycell'
# 2. Each <block>.nix or <block>/default.nix within it becomes a "Cell Block"
# Run for example: '$EDITOR nix/mycell/packages.nix' - see example content below
cellsFrom = ./nix;
# 3. Only blocks with these names [here: "packages" & "shells"] are picked up by Standard
# It's a bit like the output type system of your flake project (hint: CLI & TUI!!)
cellBlocks = with std.blockTypes; [
(installables "packages" {ci.build = true;})
(runnables "scripts")
(nixago "configs")
(devshells "shells" {ci.build = true;})
];
}
# 4. Run 'nix run github:divnix/std'
# 'growOn' ... Soil:
# - here, compat for the Nix CLI
# - but can use anything that produces flake outputs (e.g. flake-parts or flake-utils)
# 5. Run: nix run .
{
devShells = std.harvest self ["ts-sdk" "shells"];
packages = std.harvest self ["ts-sdk" "packages"];
Expand Down
63 changes: 63 additions & 0 deletions jsdelivr-npm-importmap.js
@@ -0,0 +1,63 @@
const importMap = {
imports: {
"@marlowe.io/adapter":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/adapter@0.2.0-alpha-3/dist/bundled/esm/adapter.js",
"@marlowe.io/adapter/codec":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/adapter@0.2.0-alpha-3/dist/bundled/esm/codec.js",
"@marlowe.io/adapter/file":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/adapter@0.2.0-alpha-3/dist/bundled/esm/file.js",
"@marlowe.io/adapter/fp-ts":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/adapter@0.2.0-alpha-3/dist/bundled/esm/fp-ts.js",
"@marlowe.io/adapter/http":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/adapter@0.2.0-alpha-3/dist/bundled/esm/http.js",
"@marlowe.io/adapter/time":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/adapter@0.2.0-alpha-3/dist/bundled/esm/time.js",
"@marlowe.io/language-core-v1":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/language-core-v1.js",
"@marlowe.io/language-core-v1/environment":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/environment.js",
"@marlowe.io/language-core-v1/examples":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/examples.js",
"@marlowe.io/language-core-v1/next":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/next.js",
"@marlowe.io/language-core-v1/state":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/state.js",
"@marlowe.io/language-core-v1/token":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/token.js",
"@marlowe.io/language-core-v1/tokenValue":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/tokenValue.js",
"@marlowe.io/language-core-v1/version":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/language-core-v1@0.2.0-alpha-3/dist/bundled/esm/version.js",
"@marlowe.io/token-metadata-client":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/token-metadata-client@0.2.0-alpha-3/dist/bundled/esm/token-metadata-client.js",
"@marlowe.io/wallet":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/wallet@0.2.0-alpha-3/dist/bundled/esm/wallet.js",
"@marlowe.io/wallet/api":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/wallet@0.2.0-alpha-3/dist/bundled/esm/api.js",
"@marlowe.io/wallet/browser":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/wallet@0.2.0-alpha-3/dist/bundled/esm/browser.js",
"@marlowe.io/wallet/nodejs":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/wallet@0.2.0-alpha-3/dist/bundled/esm/nodejs.js",
"@marlowe.io/runtime-rest-client":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/runtime-rest-client@0.2.0-alpha-3/dist/bundled/esm/runtime-rest-client.js",
"@marlowe.io/runtime-rest-client/transaction":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/runtime-rest-client@0.2.0-alpha-3/dist/bundled/esm/transaction.js",
"@marlowe.io/runtime-rest-client/withdrawal":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/runtime-rest-client@0.2.0-alpha-3/dist/bundled/esm/withdrawal.js",
"@marlowe.io/runtime-core":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/runtime-core@0.2.0-alpha-3/dist/bundled/esm/runtime-core.js",
"@marlowe.io/runtime-lifecycle":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/runtime-lifecycle@0.2.0-alpha-3/dist/bundled/esm/runtime-lifecycle.js",
"@marlowe.io/runtime-lifecycle/api":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/runtime-lifecycle@0.2.0-alpha-3/dist/bundled/esm/api.js",
"@marlowe.io/runtime-lifecycle/browser":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/runtime-lifecycle@0.2.0-alpha-3/dist/bundled/esm/browser.js",
"@marlowe.io/runtime-lifecycle/generic":
"https:/cdn.jsdelivr.net/npm/@marlowe.io/runtime-lifecycle@0.2.0-alpha-3/dist/bundled/esm/generic.js",
"lucid-cardano": "https://unpkg.com/lucid-cardano@0.10.7/web/mod.js",
},
};
const im = document.createElement("script");
im.type = "importmap";
im.textContent = JSON.stringify(importMap);
document.currentScript.after(im);
1 change: 0 additions & 1 deletion nix/ts-sdk/configs.nix
Expand Up @@ -100,5 +100,4 @@ A: (1) dotfile proliferation
};
};
};

}
7 changes: 0 additions & 7 deletions nix/ts-sdk/packages.nix

This file was deleted.

19 changes: 19 additions & 0 deletions nix/ts-sdk/scripts.nix
@@ -0,0 +1,19 @@
{
inputs,
cell,
}: let
pkgs = inputs.nixpkgs;
in {
build-changelog = inputs.std.lib.ops.mkOperable {
package = pkgs.scriv;
runtimeScript = ''
VERSION=$(jq ".version" package.json)
echo "Writting changelog for version $VERSION"
scriv collect --version "$VERSION"
'';
runtimeInputs = [inputs.nixpkgs.jq];
meta = {
description = "Makes a changelog release from the changelog.d fragments";
};
};
}
6 changes: 1 addition & 5 deletions nix/ts-sdk/shells.nix
Expand Up @@ -30,13 +30,9 @@
package = nixpkgs.nodePackages.prettier;
category = "JavaScript";
}
{
package = nixpkgs.treefmt;
category = "std";
}
{
package = std.cli.default;
category = "std";
category = "general commands";
}
];
};
Expand Down