-
Notifications
You must be signed in to change notification settings - Fork 2
feat: new js client #202
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
feat: new js client #202
Changes from all commits
4f4a448
d32d309
8cea1a5
d69b275
3e8fe5c
44bfccf
fbd6da8
2fa178f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| src/codegen |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # Functional Source License, Version 1.1, MIT Future License | ||
|
|
||
| ## Abbreviation | ||
|
|
||
| FSL-1.1-MIT | ||
|
|
||
| ## Notice | ||
|
|
||
| Copyright 2024 SettleMint | ||
|
|
||
| ## Terms and Conditions | ||
|
|
||
| ### Licensor ("We") | ||
|
|
||
| The party offering the Software under these Terms and Conditions. | ||
|
|
||
| ### The Software | ||
|
|
||
| The "Software" is each version of the software that we make available under | ||
| these Terms and Conditions, as indicated by our inclusion of these Terms and | ||
| Conditions with the Software. | ||
|
|
||
| ### License Grant | ||
|
|
||
| Subject to your compliance with this License Grant and the Patents, | ||
| Redistribution and Trademark clauses below, we hereby grant you the right to | ||
| use, copy, modify, create derivative works, publicly perform, publicly display | ||
| and redistribute the Software for any Permitted Purpose identified below. | ||
|
|
||
| ### Permitted Purpose | ||
|
|
||
| A Permitted Purpose is any purpose other than a Competing Use. A Competing Use | ||
| means making the Software available to others in a commercial product or | ||
| service that: | ||
|
|
||
| 1. substitutes for the Software; | ||
|
|
||
| 2. substitutes for any other product or service we offer using the Software | ||
| that exists as of the date we make the Software available; or | ||
|
|
||
| 3. offers the same or substantially similar functionality as the Software. | ||
|
|
||
| Permitted Purposes specifically include using the Software: | ||
|
|
||
| 1. for your internal use and access; | ||
|
|
||
| 2. for non-commercial education; | ||
|
|
||
| 3. for non-commercial research; and | ||
|
|
||
| 4. in connection with professional services that you provide to a licensee | ||
| using the Software in accordance with these Terms and Conditions. | ||
|
|
||
| ### Patents | ||
|
|
||
| To the extent your use for a Permitted Purpose would necessarily infringe our | ||
| patents, the license grant above includes a license under our patents. If you | ||
| make a claim against any party that the Software infringes or contributes to | ||
| the infringement of any patent, then your patent license to the Software ends | ||
| immediately. | ||
|
|
||
| ### Redistribution | ||
|
|
||
| The Terms and Conditions apply to all copies, modifications and derivatives of | ||
| the Software. | ||
|
|
||
| If you redistribute any copies, modifications or derivatives of the Software, | ||
| you must include a copy of or a link to these Terms and Conditions and not | ||
| remove any copyright notices provided in or with the Software. | ||
|
|
||
| ### Disclaimer | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR | ||
| PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT. | ||
|
|
||
| IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE | ||
| SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, | ||
| EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE. | ||
|
|
||
| ### Trademarks | ||
|
|
||
| Except for displaying the License Details and identifying us as the origin of | ||
| the Software, you have no right under these Terms and Conditions to use our | ||
| trademarks, trade names, service marks or product names. | ||
|
|
||
| ## Grant of Future License | ||
|
|
||
| We hereby irrevocably grant you an additional license to use the Software under | ||
| the MIT license that is effective on the second anniversary of the date we make | ||
| the Software available. On or after that date, you may use the Software under | ||
| the MIT license, in which case the following will apply: | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
| of the Software, and to permit persons to whom the Software is furnished to do | ||
| so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||
| <p align="center"> | ||||||
| <img src="https://github.com/settlemint/sdk/blob/main/logo.svg" width="200px" align="center" alt="SettleMint logo" /> | ||||||
| <h1 align="center">SettleMint SDK</h1> | ||||||
| <p align="center"> | ||||||
| ✨ <a href="https://settlemint.com">https://settlemint.com</a> ✨ | ||||||
| <br/> | ||||||
| Integrate SettleMint into your application with ease. | ||||||
| </p> | ||||||
| </p> | ||||||
| <br/> | ||||||
| <p align="center"> | ||||||
| <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> | ||||||
| <a href="https://fsl.software" rel="nofollow"><img src="https://img.shields.io/npm/l/@settlemint/sdk" alt="License"></a> | ||||||
| <a href="https://www.npmjs.com/package/@settlemint/sdk" rel="nofollow"><img src="https://img.shields.io/npm/dw/@settlemint/sdk" alt="npm"></a> | ||||||
| <a href="https://github.com/settlemint/sdk" rel="nofollow"><img src="https://img.shields.io/github/stars/settlemint/sdk" alt="stars"></a> | ||||||
| </p> | ||||||
|
|
||||||
| <div align="center"> | ||||||
| <a href="https://console.settlemint.com/documentation/">Documentation</a> | ||||||
| <span> • </span> | ||||||
| <a href="https://discord.com/invite/Mt5yqFrey9">Discord</a> | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (documentation): Consider using a permanent Discord invite link If possible, it might be beneficial to use a permanent invite link specific to the SettleMint community. This ensures the link won't expire.
Suggested change
|
||||||
| <span> • </span> | ||||||
| <a href="https://www.npmjs.com/package/@settlemint/sdk">NPM</a> | ||||||
| <span> • </span> | ||||||
| <a href="https://github.com/settlemint/sdk/issues">Issues</a> | ||||||
| <br /> | ||||||
| </div> | ||||||
|
|
||||||
| ## Getting started | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (documentation): Consider adding content to the 'Getting started' section This section could include basic installation instructions, a simple usage example, or links to more detailed guides. Basic usageimport { someFunction } from '@your-package-name';
// Use the package
someFunction();For more detailed guides, see our documentation. |
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| { | ||
| "$schema": "https://unpkg.com/knip@5/schema.json", | ||
| "ignoreDependencies": [], | ||
| "ignore": ["dist/**"], | ||
| "entry": ["src/settlemint.ts"] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| { | ||
| "name": "@settlemint/sdk-js", | ||
| "description": "SettleMint SDK, integrate SettleMint into your application with ease.", | ||
| "version": "0.0.1", | ||
| "type": "module", | ||
| "private": false, | ||
| "license": "FSL-1.1-MIT", | ||
| "author": { | ||
| "name": "SettleMint", | ||
| "email": "support@settlemint.com", | ||
| "url": "https://settlemint.com" | ||
| }, | ||
| "homepage": "https://github.com/settlemint/sdk/blob/main/packages/js/README.md", | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/settlemint/sdk.git", | ||
| "directory": "packages/js" | ||
| }, | ||
| "bugs": { | ||
| "url": "https://github.com/settlemint/sdk/issues", | ||
| "email": "support@settlemint.com" | ||
| }, | ||
| "files": ["dist"], | ||
| "exports": { | ||
| "./*": { | ||
| "import": { | ||
| "types": "./dist/*.d.ts", | ||
| "default": "./dist/*.mjs" | ||
| }, | ||
| "require": { | ||
| "types": "./dist/*.d.cts", | ||
| "default": "./dist/*.cjs" | ||
| } | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "build": "tsup-node", | ||
| "dev": "tsup-node --watch", | ||
| "publint": "publint run --strict", | ||
| "attw": "attw --pack .", | ||
| "test": "bun test", | ||
| "test:coverage": "bun test --coverage", | ||
| "typecheck": "tsc --noEmit" | ||
| }, | ||
| "devDependencies": {}, | ||
| "dependencies": { "zod": "^3.23.8" }, | ||
| "peerDependencies": {}, | ||
| "engines": { | ||
| "node": ">=20" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| interface CacheEntry<T> { | ||
| data: T; | ||
| expiry: number; | ||
| } | ||
|
|
||
| interface CacheOptions { | ||
| maxSize: number; | ||
| ttl: number; // Time-to-live in milliseconds | ||
| } | ||
|
|
||
| // biome-ignore lint/suspicious/noExplicitAny: the setters and getters handle the type safety | ||
| const cacheStore: Map<string, CacheEntry<any>> = new Map(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (performance): Consider using a more robust caching solution for production While the current implementation is a good start, for a production-grade SDK, consider using a well-tested caching library or implementing a more sophisticated caching strategy. This could include features like persistence across sessions or distributed caching for multi-instance deployments. |
||
|
|
||
| const DEFAULT_OPTIONS: CacheOptions = { | ||
| maxSize: 500, // Maximum number of items in the cache | ||
| ttl: 1000 * 60 * 60 * 24, // 24 hours in milliseconds | ||
| }; | ||
|
|
||
| /** | ||
| * Retrieves cached data if available and not expired. | ||
| * Updates the entry's position to mark it as recently used. | ||
| * @param key - The cache key. | ||
| * @param options - Optional cache configuration. | ||
| * @returns The cached data or null if not found/expired. | ||
| */ | ||
| export function getCache<T>(key: string): T | null { | ||
| const entry = cacheStore.get(key) as CacheEntry<T> | undefined; | ||
|
|
||
| if (!entry) { | ||
| return null; | ||
| } | ||
|
|
||
| const now = Date.now(); | ||
| if (now > entry.expiry) { | ||
| cacheStore.delete(key); | ||
| return null; | ||
| } | ||
|
|
||
| // Refresh the entry's position to mark it as recently used | ||
| cacheStore.delete(key); | ||
| cacheStore.set(key, entry); | ||
|
|
||
| return entry.data; | ||
| } | ||
|
|
||
| /** | ||
| * Stores data in the cache. | ||
| * Evicts the least recently used item if the cache exceeds maxSize. | ||
| * @param key - The cache key. | ||
| * @param data - The data to cache. | ||
| * @param options - Optional cache configuration. | ||
| */ | ||
| export function setCache<T>(key: string, data: T, options: Partial<CacheOptions> = {}): void { | ||
| const currentOptions = { ...DEFAULT_OPTIONS, ...options }; | ||
| const now = Date.now(); | ||
| const expiry = now + currentOptions.ttl; | ||
|
|
||
| if (cacheStore.has(key)) { | ||
| cacheStore.delete(key); | ||
| } else if (cacheStore.size >= currentOptions.maxSize) { | ||
| // Evict the least recently used (first) entry | ||
| const firstKey = cacheStore.keys().next().value; | ||
| if (firstKey) { | ||
| cacheStore.delete(firstKey); | ||
| } | ||
| } | ||
|
|
||
| cacheStore.set(key, { data, expiry }); | ||
| } | ||
|
|
||
| export function invalidateCache(key: string): void { | ||
| cacheStore.delete(key); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚨 suggestion (security): Consider enabling provenance for enhanced package security
Enabling provenance can provide better security guarantees for your published package. If there's a specific reason for disabling it, please document this decision.