Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ jobs:
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}

- name: Publish SDK JS package
uses: JS-DevTools/npm-publish@v3
with:
token: ${{ secrets.NPM_TOKEN }}
package: ./packages/js/package.json
access: public
provenance: false
Copy link
Contributor

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.

Suggested change
provenance: false
provenance: true

strategy: all
tag: ${{ env.TAG }}

- name: Publish SDK Next package
uses: JS-DevTools/npm-publish@v3
with:
Expand Down
Binary file modified bun.lockb
Binary file not shown.
1 change: 0 additions & 1 deletion packages/config/src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const ApplicationConfigSchema = z.object({
* Schema for the main configuration.
*/
export const ConfigSchema = z.object({
framework: z.string(),
instance: z.string().url(),
workspace: z.object({
id: z.string(),
Expand Down
1 change: 1 addition & 0 deletions packages/js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/codegen
110 changes: 110 additions & 0 deletions packages/js/LICENSE
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.
29 changes: 29 additions & 0 deletions packages/js/README.md
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>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://discord.com/invite/Mt5yqFrey9">Discord</a>
Copy link
Contributor

Choose a reason for hiding this comment

The 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
<a href="https://discord.com/invite/Mt5yqFrey9">Discord</a>
<a href="https://discord.gg/settlemint">Discord</a>

<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://www.npmjs.com/package/@settlemint/sdk">NPM</a>
<span>&nbsp;&nbsp;&nbsp;&nbsp;</span>
<a href="https://github.com/settlemint/sdk/issues">Issues</a>
<br />
</div>

## Getting started
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

## Getting started

### Installation
```bash
npm install @your-package-name

Basic usage

import { someFunction } from '@your-package-name';

// Use the package
someFunction();

For more detailed guides, see our documentation.

6 changes: 6 additions & 0 deletions packages/js/knip.json
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"]
}
51 changes: 51 additions & 0 deletions packages/js/package.json
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"
}
}
73 changes: 73 additions & 0 deletions packages/js/src/helpers/cache.ts
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();
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

import NodeCache from 'node-cache';

const cacheStore = new NodeCache({
  stdTTL: 600, // 10 minutes default TTL
  checkperiod: 120, // Check for expired keys every 2 minutes
  useClones: false, // For better performance
});


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);
}
Loading