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

Sei Actions API's #194

Closed
wants to merge 12 commits into from
5 changes: 5 additions & 0 deletions .changeset/fast-trees-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sei-js/actions': patch
---

Added chainType to individual action config interface, added EVm types to POST request response type
5 changes: 5 additions & 0 deletions .changeset/giant-badgers-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sei-js/actions': patch
---

Added newest types
6 changes: 6 additions & 0 deletions .changeset/healthy-icons-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@slinks/blink-ui': patch
'@sei-js/actions': patch
---

Release updated versions
5 changes: 5 additions & 0 deletions .changeset/rich-islands-arrive.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sei-js/create-sei': minor
---

Adds a new command to create an actions API express application
15 changes: 14 additions & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ flags:
registry:
paths:
- packages/registry/**

create-sei:
paths:
- packages/create-sei/**
actions:
paths:
- packages/actions/**
coverage:
status:
project:
Expand All @@ -31,3 +36,11 @@ coverage:
target: 80%
flags:
- registry
create-sei:
target: 80%
flags:
- create-sei
actions:
target: 80%
flags:
- actions
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"name": "sei-js",
"version": "2.0.0",
"private": true,
"license": "MIT",
"workspaces": [
"packages/*"
Expand Down
14 changes: 14 additions & 0 deletions packages/actions/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type {import('ts-jest').JestConfigWithTsJest} */
import { getJestProjects } from '@nx/jest';

export default {
projects: getJestProjects(),
preset: 'ts-jest',
testMatch: ['**/*.spec.ts', '**/*.spec.tsx'],
globals: {
'ts-jest': {
tsconfig: './tsconfig.json'
}
},
modulePathIgnorePatterns: ['<rootDir>/packages/*/dist/']
};
43 changes: 43 additions & 0 deletions packages/actions/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "@sei-js/actions",
"version": "1.0.0",
"description": "TypeScript library for the actions standard on Sei",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"sideEffects": false,
"files": [
"dist"
],
"scripts": {
"prebuild": "rimraf dist",
"build": "tsc --project tsconfig.json && yarn build:prettier",
"build:prettier": "prettier --write 'dist/**/*.js'",
"test": "jest",
"lint": "eslint --ext .ts"
},
"homepage": "https://github.com/sei-protocol/sei-js#readme",
"keywords": [
"sei",
"javascript",
"typescript",
"registry"
],
"repository": "[email protected]:sei-protocol/sei-js.git",
"license": "MIT",
"publishConfig": {
"access": "restricted"
},
"dependencies": {
"@ethersproject/abstract-provider": "^5.7.0"
},
"peerDependencies": {},
"devDependencies": {},
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
}
}
}
32 changes: 32 additions & 0 deletions packages/actions/src/__tests__/types.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { GetSeiActionResponse } from '../types';

describe('GetSeiActionResponse', () => {
it('should create a valid GetSeiActionResponse object', () => {
const response: GetSeiActionResponse = {
icon: 'https://example.com/icon.png',
label: 'Test Label',
title: 'Test Title',
description: 'Test Description',
transactionType: 'EVM',
links: {
actions: [
{
label: 'Test Action',
href: '/api/test-action',
parameters: [
{
type: 'text',
name: 'param1',
label: 'Param 1',
required: true
}
]
}
]
}
};

expect(response).toHaveProperty('icon', 'https://example.com/icon.png');
expect(response.links.transactionType).toBe('EVM');
});
});
1 change: 1 addition & 0 deletions packages/actions/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './types';
77 changes: 77 additions & 0 deletions packages/actions/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import type { TransactionRequest } from '@ethersproject/abstract-provider';

// Define the type for the actions.json file at the root of a domain
export interface SeiActionsJSON {
rules: Array<{
pathPattern: string;
apiPath: string;
}>;
}

// Type for the GET response for a given action
export interface GetSeiActionResponse {
icon: string; // URL pointing to an image describing the action.
label: string; // Text to be displayed on the button used to execute the action.
title: string; // The title of the action.
description: string; // A brief description of the action.
disabled?: boolean; // Optional flag to disable all buttons associated with the action.
transactionType: 'EVM' | 'COSMOS'; // The type of blockchain transaction to be executed.
links: {
actions: SeiActionConfig[]; // An array of SeiActionConfig objects defining the actions available.
};
error?: SeiActionError; // Error message intended to be displayed to the user.
}

export interface SeiActionConfig {
label: string;
href: string;
parameters?: (SeiActionParameter | SeiActionParameterSelectable)[];
}

export type SeiActionParameterType = 'text' | 'address' | 'email' | 'url' | 'number' | 'date' | 'datetime-local' | 'checkbox' | 'radio' | 'textarea' | 'select';

export type SeiActionParameter = {
name: string;
type: SeiActionParameterType;
label: string;
required?: boolean;
/** regular expression pattern to validate user input client side */
pattern?: string;
/** human-readable description of the `type` and/or `pattern`, represents a caption and error, if value doesn't match */
patternDescription?: string;
/** the minimum value allowed based on the `type` */
min?: string | number;
/** the maximum value allowed based on the `type` */
max?: string | number;
};

// Used if parameter is type 'select', 'radio', or 'checkbox'
export interface SeiActionParameterSelectable extends SeiActionParameter {
options: Array<{
/** displayed UI label of this selectable option */
label: string;
/** value of this selectable option */
value: string;
/** whether or not this option should be selected by default */
selected?: boolean;
}>;
}

// Define the type for the POST requests to a given action
export interface PostSeiActionRequest {
sender: string;
[key: string]: unknown;
}

export interface SeiActionError {
/** non-fatal error message to be displayed to the user */
message: string;
}

export type SeiActionSuccessResponse = {
transaction: TransactionRequest | any;
message?: string;
};

// Define the type for the POST response for a given action
export type PostSeiActionResponse = SeiActionSuccessResponse | SeiActionError;
9 changes: 9 additions & 0 deletions packages/actions/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "../../tsconfig.base.json",
"include": ["./src/**/*"],
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"declaration": true,
}
}
36 changes: 36 additions & 0 deletions packages/blink-ui/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "@slinks/blink-ui",
"version": "1.0.0",
"description": "A javascript library for rendering Blink UI components for Sei.",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/index.d.ts",
"author": "carson",
"license": "MIT",
"scripts": {
"prebuild": "rimraf dist",
"build": "rollup -c"
},
"peerDependencies": {
"react": ">=17.0.0 <19.0.0",
"react-dom": ">=17.0.0 <19.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^14.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"@rollup/plugin-typescript": "^11.1.6",
"@types/react": "^18.3.4",
"rollup": "^4.21.1",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-peer-deps-external": "^2.2.4",
"rollup-plugin-terser": "^7.0.2",
"tslib": "^2.7.0"
},
"dependencies": {
"@mantine/core": "^7.12.1",
"@mantine/hooks": "^7.12.1",
"@sei-js/actions": "^1.0.0",
"@tabler/icons-react": "^3.13.0",
"url-pattern": "^1.0.3"
}
}
37 changes: 37 additions & 0 deletions packages/blink-ui/rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import external from 'rollup-plugin-peer-deps-external';
import dts from 'rollup-plugin-dts';

import packageJson from './package.json' assert { type: 'json' };

export default [
{
input: 'src/index.ts',
output: [
{
file: packageJson.main,
format: 'cjs',
sourcemap: true,
name: packageJson.name
},
{
file: packageJson.module,
format: 'esm',
sourcemap: true
}
],
plugins: [
external(), // To prevent bundling peerDependencies
resolve(), // Resolve third party dependencies in node_modules
commonjs(), // To convert commonjs modules into ES6
typescript({ tsconfig: './tsconfig.json' }) // To transpile our Typescript code in JS
],
},
{
input: 'dist/esm/types/index.d.ts',
output: [{ file: packageJson.types, format: "esm" }],
plugins: [dts()],
}
]
Loading
Loading