Skip to content

Commit e4b2620

Browse files
authored
feat: new js client (#202)
<!-- Generated by sourcery-ai[bot]: start summary --> ## Summary by Sourcery Add a new JavaScript client to the SettleMint SDK, enabling integration with SettleMint services. Update the build process to publish the SDK package to npm and enhance the configuration schema by removing an unnecessary field. Include documentation for the new package. New Features: - Introduce a new JavaScript client for the SettleMint SDK, providing a structured way to interact with various SettleMint services such as blockchain networks, nodes, middleware, integration tools, storage, private keys, insights, and custom deployments. Enhancements: - Remove the 'framework' field from the main configuration schema, simplifying the configuration structure. Build: - Add a new step in the GitHub Actions workflow to publish the JavaScript SDK package to npm, ensuring the package is publicly accessible. Documentation: - Add a README file for the JavaScript package, providing an overview of the SettleMint SDK, links to documentation, and other resources. <!-- Generated by sourcery-ai[bot]: end summary -->
1 parent 5a7b42d commit e4b2620

File tree

14 files changed

+766
-1
lines changed

14 files changed

+766
-1
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ jobs:
128128
env:
129129
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
130130

131+
- name: Publish SDK JS package
132+
uses: JS-DevTools/npm-publish@v3
133+
with:
134+
token: ${{ secrets.NPM_TOKEN }}
135+
package: ./packages/js/package.json
136+
access: public
137+
provenance: false
138+
strategy: all
139+
tag: ${{ env.TAG }}
140+
131141
- name: Publish SDK Next package
132142
uses: JS-DevTools/npm-publish@v3
133143
with:

bun.lockb

0 Bytes
Binary file not shown.

packages/config/src/schemas.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const ApplicationConfigSchema = z.object({
2626
* Schema for the main configuration.
2727
*/
2828
export const ConfigSchema = z.object({
29-
framework: z.string(),
3029
instance: z.string().url(),
3130
workspace: z.object({
3231
id: z.string(),

packages/js/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src/codegen

packages/js/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/js/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
<br/>
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" alt="License"></a>
14+
<a href="https://www.npmjs.com/package/@settlemint/sdk" rel="nofollow"><img src="https://img.shields.io/npm/dw/@settlemint/sdk" 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">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+
## Getting started

packages/js/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+
}

packages/js/package.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"name": "@settlemint/sdk-js",
3+
"description": "SettleMint SDK, integrate SettleMint into your application with ease.",
4+
"version": "0.0.1",
5+
"type": "module",
6+
"private": false,
7+
"license": "FSL-1.1-MIT",
8+
"author": {
9+
"name": "SettleMint",
10+
"email": "support@settlemint.com",
11+
"url": "https://settlemint.com"
12+
},
13+
"homepage": "https://github.com/settlemint/sdk/blob/main/packages/js/README.md",
14+
"repository": {
15+
"type": "git",
16+
"url": "git+https://github.com/settlemint/sdk.git",
17+
"directory": "packages/js"
18+
},
19+
"bugs": {
20+
"url": "https://github.com/settlemint/sdk/issues",
21+
"email": "support@settlemint.com"
22+
},
23+
"files": ["dist"],
24+
"exports": {
25+
"./*": {
26+
"import": {
27+
"types": "./dist/*.d.ts",
28+
"default": "./dist/*.mjs"
29+
},
30+
"require": {
31+
"types": "./dist/*.d.cts",
32+
"default": "./dist/*.cjs"
33+
}
34+
}
35+
},
36+
"scripts": {
37+
"build": "tsup-node",
38+
"dev": "tsup-node --watch",
39+
"publint": "publint run --strict",
40+
"attw": "attw --pack .",
41+
"test": "bun test",
42+
"test:coverage": "bun test --coverage",
43+
"typecheck": "tsc --noEmit"
44+
},
45+
"devDependencies": {},
46+
"dependencies": { "zod": "^3.23.8" },
47+
"peerDependencies": {},
48+
"engines": {
49+
"node": ">=20"
50+
}
51+
}

packages/js/src/helpers/cache.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
interface CacheEntry<T> {
2+
data: T;
3+
expiry: number;
4+
}
5+
6+
interface CacheOptions {
7+
maxSize: number;
8+
ttl: number; // Time-to-live in milliseconds
9+
}
10+
11+
// biome-ignore lint/suspicious/noExplicitAny: the setters and getters handle the type safety
12+
const cacheStore: Map<string, CacheEntry<any>> = new Map();
13+
14+
const DEFAULT_OPTIONS: CacheOptions = {
15+
maxSize: 500, // Maximum number of items in the cache
16+
ttl: 1000 * 60 * 60 * 24, // 24 hours in milliseconds
17+
};
18+
19+
/**
20+
* Retrieves cached data if available and not expired.
21+
* Updates the entry's position to mark it as recently used.
22+
* @param key - The cache key.
23+
* @param options - Optional cache configuration.
24+
* @returns The cached data or null if not found/expired.
25+
*/
26+
export function getCache<T>(key: string): T | null {
27+
const entry = cacheStore.get(key) as CacheEntry<T> | undefined;
28+
29+
if (!entry) {
30+
return null;
31+
}
32+
33+
const now = Date.now();
34+
if (now > entry.expiry) {
35+
cacheStore.delete(key);
36+
return null;
37+
}
38+
39+
// Refresh the entry's position to mark it as recently used
40+
cacheStore.delete(key);
41+
cacheStore.set(key, entry);
42+
43+
return entry.data;
44+
}
45+
46+
/**
47+
* Stores data in the cache.
48+
* Evicts the least recently used item if the cache exceeds maxSize.
49+
* @param key - The cache key.
50+
* @param data - The data to cache.
51+
* @param options - Optional cache configuration.
52+
*/
53+
export function setCache<T>(key: string, data: T, options: Partial<CacheOptions> = {}): void {
54+
const currentOptions = { ...DEFAULT_OPTIONS, ...options };
55+
const now = Date.now();
56+
const expiry = now + currentOptions.ttl;
57+
58+
if (cacheStore.has(key)) {
59+
cacheStore.delete(key);
60+
} else if (cacheStore.size >= currentOptions.maxSize) {
61+
// Evict the least recently used (first) entry
62+
const firstKey = cacheStore.keys().next().value;
63+
if (firstKey) {
64+
cacheStore.delete(firstKey);
65+
}
66+
}
67+
68+
cacheStore.set(key, { data, expiry });
69+
}
70+
71+
export function invalidateCache(key: string): void {
72+
cacheStore.delete(key);
73+
}

0 commit comments

Comments
 (0)