Skip to content

Commit 138f0fe

Browse files
authored
feat: add the portal client and aling instance URI (#208)
## Summary by Sourcery Add a new SDK Portal package with client creation functions and update the CI workflow to publish this package. Simplify the GraphQL client instantiation in existing packages by aligning the instance URI format. Include detailed documentation for the new Portal package. New Features: - Introduce a new SDK Portal package to the project, including its publication in the CI workflow. - Add a new `createHasuraClient` function for client-side and server-side use in the Portal package. Enhancements: - Simplify the GraphQL client instantiation by removing the subgraph path from the instance URI in The Graph and Hasura packages. CI: - Update the CI workflow to include publishing the new SDK Portal package to npm. Documentation: - Add comprehensive documentation for the new Portal package, including installation, usage, API reference, examples, and contribution guidelines.
1 parent abe86e7 commit 138f0fe

File tree

13 files changed

+540
-13
lines changed

13 files changed

+540
-13
lines changed

.github/workflows/build.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ jobs:
162162
strategy: all
163163
tag: ${{ env.TAG }}
164164

165+
- name: Publish SDK Portal package
166+
uses: JS-DevTools/npm-publish@v3
167+
with:
168+
token: ${{ secrets.NPM_TOKEN }}
169+
package: ./packages/portal/package.json
170+
access: public
171+
provenance: false
172+
strategy: all
173+
tag: ${{ env.TAG }}
174+
165175
- name: Publish SDK The Graph package
166176
uses: JS-DevTools/npm-publish@v3
167177
with:
@@ -193,6 +203,7 @@ jobs:
193203
| ------- | -------------------- |
194204
| SDK Cli | `@settlemint/sdk-cli@${{ env.VERSION }}` |
195205
| SDK The Graph | `@settlemint/sdk-thegraph@${{ env.VERSION }}` |
206+
| SDK Portal | `@settlemint/sdk-portal@${{ env.VERSION }}` |
196207
| SDK Hasura | `@settlemint/sdk-hasura@${{ env.VERSION }}` |
197208
| SDK JS | `@settlemint/sdk-js@${{ env.VERSION }}` |
198209
| SDK Utils | `@settlemint/sdk-utils@${{ env.VERSION }}` |

packages/hasura/src/hasura.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import { ensureServer } from "@settlemint/sdk-utils/runtime";
22
import { validate } from "@settlemint/sdk-utils/validation";
33
import { type AbstractSetupSchema, initGraphQLTada } from "gql.tada";
44
import { GraphQLClient } from "graphql-request";
5-
import { type ClientOptions, ClientOptionsSchema, ServerClientOptionsSchema } from "./helpers/client-options.schema.js";
5+
import {
6+
type ClientOptions,
7+
ClientOptionsSchema,
8+
type ServerClientOptions,
9+
ServerClientOptionsSchema,
10+
} from "./helpers/client-options.schema.js";
611

712
export type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
813

@@ -63,7 +68,7 @@ export function createHasuraClient<const Setup extends AbstractSetupSchema>(
6368
* });
6469
*/
6570
export function createServerHasuraClient<const Setup extends AbstractSetupSchema>(
66-
options: ClientOptions,
71+
options: ServerClientOptions,
6772
requestConfig?: RequestConfig,
6873
) {
6974
ensureServer();
@@ -72,7 +77,7 @@ export function createServerHasuraClient<const Setup extends AbstractSetupSchema
7277
const graphql = initGraphQLTada<Setup>();
7378

7479
return {
75-
client: new GraphQLClient(`${validatedOptions.instance}/v1/graphql`, {
80+
client: new GraphQLClient(validatedOptions.instance, {
7681
...requestConfig,
7782
headers: {
7883
...requestConfig?.headers,

packages/portal/.gitignore

Whitespace-only changes.

packages/portal/LICENSE

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# Functional Source License, Version 1.1, MIT Future License
2+
3+
## Abbreviation
4+
5+
FSL-1.1-MIT
6+
7+
## Notice
8+
9+
Copyright 2024 SettleMint
10+
11+
## Terms and Conditions
12+
13+
### Licensor ("We")
14+
15+
The party offering the Software under these Terms and Conditions.
16+
17+
### The Software
18+
19+
The "Software" is each version of the software that we make available under
20+
these Terms and Conditions, as indicated by our inclusion of these Terms and
21+
Conditions with the Software.
22+
23+
### License Grant
24+
25+
Subject to your compliance with this License Grant and the Patents,
26+
Redistribution and Trademark clauses below, we hereby grant you the right to
27+
use, copy, modify, create derivative works, publicly perform, publicly display
28+
and redistribute the Software for any Permitted Purpose identified below.
29+
30+
### Permitted Purpose
31+
32+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33+
means making the Software available to others in a commercial product or
34+
service that:
35+
36+
1. substitutes for the Software;
37+
38+
2. substitutes for any other product or service we offer using the Software
39+
that exists as of the date we make the Software available; or
40+
41+
3. offers the same or substantially similar functionality as the Software.
42+
43+
Permitted Purposes specifically include using the Software:
44+
45+
1. for your internal use and access;
46+
47+
2. for non-commercial education;
48+
49+
3. for non-commercial research; and
50+
51+
4. in connection with professional services that you provide to a licensee
52+
using the Software in accordance with these Terms and Conditions.
53+
54+
### Patents
55+
56+
To the extent your use for a Permitted Purpose would necessarily infringe our
57+
patents, the license grant above includes a license under our patents. If you
58+
make a claim against any party that the Software infringes or contributes to
59+
the infringement of any patent, then your patent license to the Software ends
60+
immediately.
61+
62+
### Redistribution
63+
64+
The Terms and Conditions apply to all copies, modifications and derivatives of
65+
the Software.
66+
67+
If you redistribute any copies, modifications or derivatives of the Software,
68+
you must include a copy of or a link to these Terms and Conditions and not
69+
remove any copyright notices provided in or with the Software.
70+
71+
### Disclaimer
72+
73+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76+
77+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80+
81+
### Trademarks
82+
83+
Except for displaying the License Details and identifying us as the origin of
84+
the Software, you have no right under these Terms and Conditions to use our
85+
trademarks, trade names, service marks or product names.
86+
87+
## Grant of Future License
88+
89+
We hereby irrevocably grant you an additional license to use the Software under
90+
the MIT license that is effective on the second anniversary of the date we make
91+
the Software available. On or after that date, you may use the Software under
92+
the MIT license, in which case the following will apply:
93+
94+
Permission is hereby granted, free of charge, to any person obtaining a copy of
95+
this software and associated documentation files (the "Software"), to deal in
96+
the Software without restriction, including without limitation the rights to
97+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
98+
of the Software, and to permit persons to whom the Software is furnished to do
99+
so, subject to the following conditions:
100+
101+
The above copyright notice and this permission notice shall be included in all
102+
copies or substantial portions of the Software.
103+
104+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
105+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
106+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
107+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
108+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
109+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
110+
SOFTWARE.

packages/portal/README.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
<p align="center">
2+
<img src="https://github.com/settlemint/sdk/blob/main/logo.svg" width="200px" align="center" alt="SettleMint logo" />
3+
<h1 align="center">SettleMint SDK</h1>
4+
<p align="center">
5+
✨ <a href="https://settlemint.com">https://settlemint.com</a> ✨
6+
<br/>
7+
Integrate SettleMint into your application with ease.
8+
</p>
9+
</p>
10+
11+
<p align="center">
12+
<a href="https://github.com/settlemint/sdk/actions?query=branch%3Amain"><img src="https://github.com/settlemint/sdk/actions/workflows/build.yml/badge.svg?event=push&branch=main" alt="CI status" /></a>
13+
<a href="https://fsl.software" rel="nofollow"><img src="https://img.shields.io/npm/l/@settlemint/sdk-js" alt="License"></a>
14+
<a href="https://www.npmjs.com/package/@settlemint/sdk-js" rel="nofollow"><img src="https://img.shields.io/npm/dw/@settlemint/sdk-js" alt="npm"></a>
15+
<a href="https://github.com/settlemint/sdk" rel="nofollow"><img src="https://img.shields.io/github/stars/settlemint/sdk" alt="stars"></a>
16+
</p>
17+
18+
<div align="center">
19+
<a href="https://console.settlemint.com/documentation/">Documentation</a>
20+
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
21+
<a href="https://discord.com/invite/Mt5yqFrey9">Discord</a>
22+
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
23+
<a href="https://www.npmjs.com/package/@settlemint/sdk-js">NPM</a>
24+
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
25+
<a href="https://github.com/settlemint/sdk/issues">Issues</a>
26+
<br />
27+
</div>
28+
29+
## Table of Contents
30+
31+
- [Installation](#installation)
32+
- [Usage](#usage)
33+
- [API Reference](#api-reference)
34+
- [Examples](#examples)
35+
- [Contributing](#contributing)
36+
- [License](#license)
37+
38+
## Installation
39+
40+
To install the SettleMint SDK, you can use one of the following package managers:
41+
42+
```bash
43+
# Using npm
44+
npm install @settlemint/sdk
45+
46+
# Using yarn
47+
yarn add @settlemint/sdk
48+
49+
# Using pnpm
50+
pnpm add @settlemint/sdk
51+
52+
# Using Bun
53+
bun add @settlemint/sdk
54+
```
55+
56+
We recommend using Bun for faster installation and better performance.
57+
58+
## Usage
59+
60+
To use the SettleMint SDK in your Node.js application, follow these steps:
61+
62+
1. Import the SDK:
63+
64+
```javascript
65+
import { createSettleMintClient } from '@settlemint/sdk';
66+
```
67+
68+
2. Create a client instance:
69+
70+
```javascript
71+
const client = createSettleMintClient({
72+
accessToken: 'your_access_token',
73+
instance: 'https://console.settlemint.com'
74+
});
75+
```
76+
77+
3. Use the client to interact with SettleMint resources:
78+
79+
```javascript
80+
// Example: List workspaces
81+
const workspaces = await client.workspace.list();
82+
console.log(workspaces);
83+
```
84+
85+
## API Reference
86+
87+
The SettleMint SDK provides access to various resources. Here's an overview of the available methods:
88+
89+
### Workspace
90+
91+
- `workspace.list()`: List all workspaces and their applications
92+
- `workspace.read(workspaceId)`: Read a specific workspace and its applications
93+
94+
### Blockchain Network
95+
96+
- `blockchainNetwork.list(applicationId)`: List blockchain networks for a given application
97+
- `blockchainNetwork.read(blockchainNetworkId)`: Read a specific blockchain network
98+
99+
### Blockchain Node
100+
101+
- `blockchainNode.list(applicationId)`: List blockchain nodes for a given application
102+
- `blockchainNode.read(blockchainNodeId)`: Read a specific blockchain node
103+
104+
### Middleware
105+
106+
- `middleware.list(applicationId)`: List middlewares for a given application
107+
- `middleware.read(middlewareId)`: Read a specific middleware
108+
109+
### Integration Tool
110+
111+
- `integrationTool.list(applicationId)`: List integration tools for a given application
112+
- `integrationTool.read(integrationId)`: Read a specific integration tool
113+
114+
### Storage
115+
116+
- `storage.list(applicationId)`: List storage items for a given application
117+
- `storage.read(storageId)`: Read a specific storage item
118+
119+
### Private Key
120+
121+
- `privateKey.list(applicationId)`: List private keys for a given application
122+
- `privateKey.read(privateKeyId)`: Read a specific private key
123+
124+
### Insights
125+
126+
- `insights.list(applicationId)`: List insights for a given application
127+
- `insights.read(insightsId)`: Read a specific insight
128+
129+
## Examples
130+
131+
Here are some examples of how to use the SettleMint SDK:
132+
133+
### List Workspaces
134+
135+
```javascript
136+
const client = createSettleMintClient({
137+
accessToken: 'your_access_token',
138+
instance: 'https://console.settlemint.com'
139+
});
140+
141+
const workspaces = await client.workspace.list();
142+
console.log(workspaces);
143+
```
144+
145+
### Read a Specific Blockchain Network
146+
147+
```javascript
148+
const client = createSettleMintClient({
149+
accessToken: 'your_access_token',
150+
instance: 'https://console.settlemint.com'
151+
});
152+
153+
const networkId = 'your_network_id';
154+
const network = await client.blockchainNetwork.read(networkId);
155+
console.log(network);
156+
```
157+
158+
## Contributing
159+
160+
We welcome contributions to the SettleMint SDK! If you'd like to contribute, please follow these steps:
161+
162+
1. Fork the repository
163+
2. Create a new branch for your feature or bug fix
164+
3. Make your changes and commit them with a clear commit message
165+
4. Push your changes to your fork
166+
5. Create a pull request to the main repository
167+
168+
Please ensure that your code follows the existing style and includes appropriate tests and documentation.
169+
170+
## License
171+
172+
The SettleMint SDK is released under the [FSL Software License](https://fsl.software). See the [LICENSE](LICENSE) file for more details.

packages/portal/knip.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://unpkg.com/knip@5/schema.json",
3+
"ignoreDependencies": [],
4+
"ignore": ["dist/**"],
5+
"entry": ["src/settlemint.ts"]
6+
}

0 commit comments

Comments
 (0)