Skip to content
Draft
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
23 changes: 0 additions & 23 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
#### Bundle Vars

#### PRODUCTION
PROD_IFRAME_URL=https://iframe.string-api.xyz
PROD_API_URL=https://api.string-api.xyz

#### DEVELOPMENT
DEV_IFRAME_URL=https://iframe-app.dev.string-api.xyz
DEV_API_URL=https://string-api.dev.string-api.xyz

#### SANDBOX
SBOX_IFRAME_URL=https://iframe-app.dev.string-api.xyz
SBOX_API_URL=https://api.sandbox.string-api.xyz

#### LOCAL
LOCAL_IFRAME_URL=http://localhost:4040
LOCAL_API_URL=http://localhost:5555

VITE_ANALYTICS_LIB_PK=
VITE_ANALYTICS_SUBDOMAIN_URL=https://metrics.string.xyz


#### Test Page Vars

VITE_IPFS_GATEWAY=https://nftstorage.link/ipfs/
VITE_IPFS_CID=bafybeieqi56p6vlxofj6wkoort2m5r72ajhtikpzo53wnyze5isvn34fze

VITE_STRING_API_KEY=str...

40 changes: 18 additions & 22 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
plugins: ['svelte3', '@typescript-eslint'],
ignorePatterns: ['*.cjs'],
overrides: [{ files: ['*.svelte'], processor: 'svelte3/svelte3' }],
settings: {
'svelte3/typescript': () => require('typescript')
},
parserOptions: {
sourceType: 'module',
ecmaVersion: 2020
},
env: {
browser: true,
es2017: true,
node: true
},
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
}
root: true,
parser: "@typescript-eslint/parser",
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
plugins: ["@typescript-eslint"],
ignorePatterns: ["*.cjs"],
parserOptions: {
sourceType: "module",
ecmaVersion: 2020,
},
env: {
browser: true,
es2017: true,
node: true,
},
rules: {
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-empty-function": "off",
},
};
72 changes: 22 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,69 +1,41 @@
{
"name": "@stringpay/sdk",
"version": "0.2.3",
"main": "./src/index.ts",
"license": "Apache-2.0",
"description": "String Checkout SDK",
"author": "string.xyz",
"main": "./src/lib/index.ts",
"types": "dist/index.d.ts",
"files": [
"dist/**/*"
],
"scripts": {
"dev": "yarn bundle && vite dev",
"package": "svelte-kit sync && svelte-package",
"bundle": "rm -rf ./dist; rollup -c",
"copy": "mkdir -p ../demo/dist && cp ./dist/* ../demo/dist && echo Copied to demo",
"release:demo": "yarn bundle && yarn copy",
"test:unit": "vitest run --coverage",
"coverage": "c8 report --check-coverage",
"test": "jest --coverage",
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
"lint": "eslint ."
"bundle": "tsup",
"dev:types": "yarn build:types -w",
"compile:lib": "tsup --format esm,cjs",

"build:lib": "yarn compile:lib --minify",
"build": "yarn lint && yarn build:lib && yarn build:types",
"prepublish": "yarn build",
"release": "npm run build && npm publish",

"lint": "eslint .",
"test": "jest --coverage"
},
"devDependencies": {
"@fingerprintjs/fingerprintjs-pro": "^3.8.1",
"@fontsource/lora": "^4.5.12",
"@rollup/plugin-commonjs": "^24.0.0",
"@rollup/plugin-json": "^6.0.0",
"@rollup/plugin-node-resolve": "^15.0.1",
"@rollup/plugin-replace": "^5.0.0",
"@rollup/plugin-typescript": "^9.0.2",
"@sveltejs/adapter-node": "^1.2.3",
"@sveltejs/kit": "^1.15.7",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/svelte": "^3.2.2",
"@types/jest": "^29.5.1",
"@typescript-eslint/eslint-plugin": "^5.27.0",
"@typescript-eslint/parser": "^5.27.0",
"@vitest/coverage-c8": "^0.24.3",
"autoprefixer": "^10.4.12",
"cssnano": "^5.1.13",
"daisyui": "^2.31.0",
"dotenv": "^16.0.3",
"eslint": "^8.16.0",
"eslint-plugin-svelte3": "^4.0.0",
"ethers": "^5.7.2",
"@types/jest": "^29.5.2",
"@typescript-eslint/eslint-plugin": "^5.60.0",
"@typescript-eslint/parser": "^5.60.0",
"eslint": "^8.43.0",
"jest": "^29.5.0",
"jsdom": "^20.0.1",
"postcss": "^8.4.16",
"redaxios": "^0.5.1",
"rollup": "^3.1.0",
"rollup-plugin-copy": "^3.4.0",
"rollup-plugin-dotenv": "^0.4.0",
"rollup-plugin-terser": "^7.0.2",
"svelte": "^3.58.0",
"svelte-check": "^3.2.0",
"svelte-preprocess": "^5.0.3",
"typescript": "^5.0.4",
"vite": "^4.3.1",
"vitest": "^0.30.1",
"ts-jest": "^29.1.0",
"tslib": "^2.3.1"
"tsup": "^7.1.0",
"typescript": "^5.1.3"
},
"dependencies": {
"@fingerprintjs/fingerprintjs-pro": "^3.8.1",
"redaxios": "0.5.1"
},
"type": "module",
"dependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/String-xyz/string-sdk.git"
Expand Down
7 changes: 0 additions & 7 deletions postcss.config.cjs

This file was deleted.

71 changes: 0 additions & 71 deletions rollup.config.js

This file was deleted.

91 changes: 91 additions & 0 deletions src/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import type { Config, StringPay, StringIframe, ExecutionRequest, Quote, TransactionRequest } from "@src/types";
import type { Services } from "./services/index";

export function createStringPay(iframe: StringIframe, config: Config, services: Services): StringPay {
const events = services.events;

async function loadIframe() {
return iframe.load();
}

async function setStyle(style: any) {
iframe.setStyle(style);
}

async function authorizeUser(): Promise<User> {
const walletAddress = await services.wallet.getWalletAddress();
if (!walletAddress) {
throw new Error("Wallet address not found");
}

return (await services.auth.authorizeUser(walletAddress)).user;
}

async function verifyEmail(userId: string, email: string) {
return services.auth.emailVerification(userId, email);
}

async function verifyDevice() {
const walletAddress = await services.wallet.getWalletAddress();
return services.auth.deviceVerification(walletAddress);
}

async function getQuote(): Promise<Quote> {
const payload = <ExecutionRequest>config.payload;
return services.quote.getQuote(payload);
}

/**
* Notify the payment iframe to submit the card details
* @returns {Promise<string>} - A promise that resolves to the card token
*/
async function submitCard() {
return new Promise<string>((resolve, reject) => {
iframe.submitCard();

events.once(events.CARD_TOKENIZED, (token: string) => {
return resolve(token);
});

events.once(events.CARD_TOKENIZE_FAILED, (error) => {
return reject(error);
});
});
}

async function submitTransaction(request: TransactionRequest) {
return services.apiClient.transact(request);
}

function subscribeToQuote(callback: (quote: Quote) => void) {
const payload = <ExecutionRequest>config.payload;
services.quote.startQuote(payload, callback);
}

function unsubscribeFromQuote() {
services.quote.stopQuote();
}

function subscribeTo(eventName: string, callback: (data: any) => void) {
events.on(eventName, callback);
}

function unsubscribeFrom(eventName: string, callback: (data: any) => void) {
events.unsubscribeFrom(eventName, callback);
}

return {
loadIframe,
authorizeUser,
verifyEmail,
verifyDevice,
getQuote,
subscribeToQuote,
unsubscribeFromQuote,
subscribeTo,
unsubscribeFrom,
submitCard,
submitTransaction,
setStyle,
};
}
8 changes: 0 additions & 8 deletions src/app.css

This file was deleted.

9 changes: 0 additions & 9 deletions src/app.d.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/app.html

This file was deleted.

Loading