@diviswap/sdk 1.8.0 → 1.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +73 -82
- package/bin/create-diviswap-app.js +5 -5
- package/dist/cli/index.js +438 -185
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +302 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +302 -178
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +260 -183
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +260 -183
- package/dist/react/index.mjs.map +1 -1
- package/dist/{wallet-DZymADRo.d.mts → wallet-Ca1U51kT.d.mts} +1 -1
- package/dist/{wallet-DZymADRo.d.ts → wallet-Ca1U51kT.d.ts} +1 -1
- package/package.json +98 -97
- package/src/cli/templates/index.ts +86 -54
- package/src/cli/templates/shared/client.ts +65 -65
package/package.json
CHANGED
|
@@ -1,104 +1,105 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
},
|
|
13
|
-
"exports": {
|
|
14
|
-
".": {
|
|
15
|
-
"types": "./dist/index.d.ts",
|
|
16
|
-
"import": "./dist/index.mjs",
|
|
17
|
-
"require": "./dist/index.js"
|
|
2
|
+
"name": "@diviswap/sdk",
|
|
3
|
+
"version": "1.8.1",
|
|
4
|
+
"description": "Official Diviswap SDK - Crypto rails made simple",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"bin": {
|
|
9
|
+
"sdk": "bin/diviswap-sdk.js",
|
|
10
|
+
"diviswap-sdk": "bin/diviswap-sdk.js",
|
|
11
|
+
"create-diviswap-app": "bin/create-diviswap-app.js"
|
|
18
12
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.mjs",
|
|
17
|
+
"require": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./react": {
|
|
20
|
+
"types": "./dist/react/index.d.ts",
|
|
21
|
+
"import": "./dist/react/index.mjs",
|
|
22
|
+
"require": "./dist/react/index.js"
|
|
23
|
+
},
|
|
24
|
+
"./services": {
|
|
25
|
+
"types": "./dist/services/index.d.ts",
|
|
26
|
+
"import": "./dist/services/index.mjs",
|
|
27
|
+
"require": "./dist/services/index.js"
|
|
28
|
+
},
|
|
29
|
+
"./package.json": "./package.json"
|
|
23
30
|
},
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
31
|
+
"scripts": {
|
|
32
|
+
"build": "tsup && node scripts/copy-templates.js",
|
|
33
|
+
"dev": "tsup --watch",
|
|
34
|
+
"dev:demo": "cd examples/nextjs-web3 && npm run dev",
|
|
35
|
+
"test": "jest",
|
|
36
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
37
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
38
|
+
"prepublishOnly": "npm run build"
|
|
28
39
|
},
|
|
29
|
-
"
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"crypto",
|
|
43
|
-
"onramp",
|
|
44
|
-
"offramp",
|
|
45
|
-
"payments",
|
|
46
|
-
"sdk"
|
|
47
|
-
],
|
|
48
|
-
"author": "Diviswap <support@diviswap.io>",
|
|
49
|
-
"license": "MIT",
|
|
50
|
-
"repository": {
|
|
51
|
-
"type": "git",
|
|
52
|
-
"url": "git+https://github.com/diviswap/sdk.git"
|
|
53
|
-
},
|
|
54
|
-
"homepage": "https://github.com/diviswap/sdk#readme",
|
|
55
|
-
"bugs": {
|
|
56
|
-
"url": "https://github.com/diviswap/sdk/issues"
|
|
57
|
-
},
|
|
58
|
-
"files": [
|
|
59
|
-
"dist",
|
|
60
|
-
"bin",
|
|
61
|
-
"README.md",
|
|
62
|
-
"LICENSE",
|
|
63
|
-
"src/cli/templates"
|
|
64
|
-
],
|
|
65
|
-
"devDependencies": {
|
|
66
|
-
"@types/node": "20.19.19",
|
|
67
|
-
"@types/react": "19.2.0",
|
|
68
|
-
"jest": "^29.7.0",
|
|
69
|
-
"prettier": "^3.4.2",
|
|
70
|
-
"tsup": "^8.0.0",
|
|
71
|
-
"typescript": "^5.7.3"
|
|
72
|
-
},
|
|
73
|
-
"dependencies": {
|
|
74
|
-
"@solana/wallet-adapter-base": "0.9.27",
|
|
75
|
-
"@solana/wallet-adapter-react": "0.15.39",
|
|
76
|
-
"@solana/wallet-adapter-react-ui": "0.9.39",
|
|
77
|
-
"@solana/wallet-adapter-wallets": "0.19.37",
|
|
78
|
-
"@solana/web3.js": "1.98.4",
|
|
79
|
-
"commander": "^11.1.0",
|
|
80
|
-
"handlebars": "^4.7.8",
|
|
81
|
-
"kleur": "^4.1.5",
|
|
82
|
-
"prompts": "^2.4.2",
|
|
83
|
-
"socket.io-client": "^4.7.0"
|
|
84
|
-
},
|
|
85
|
-
"engines": {
|
|
86
|
-
"node": ">=18.0.0"
|
|
87
|
-
},
|
|
88
|
-
"peerDependencies": {
|
|
89
|
-
"react": ">=18.0.0",
|
|
90
|
-
"react-dom": ">=18.0.0"
|
|
91
|
-
},
|
|
92
|
-
"peerDependenciesMeta": {
|
|
93
|
-
"react": {
|
|
94
|
-
"optional": true
|
|
40
|
+
"keywords": [
|
|
41
|
+
"diviswap",
|
|
42
|
+
"crypto",
|
|
43
|
+
"onramp",
|
|
44
|
+
"offramp",
|
|
45
|
+
"payments",
|
|
46
|
+
"sdk"
|
|
47
|
+
],
|
|
48
|
+
"author": "Diviswap <support@diviswap.io>",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "git+https://github.com/liberex-sv/diviswap-sdk.git"
|
|
95
53
|
},
|
|
96
|
-
"
|
|
97
|
-
|
|
54
|
+
"homepage": "https://github.com/liberex-sv/diviswap-sdk#readme",
|
|
55
|
+
"bugs": {
|
|
56
|
+
"url": "https://github.com/liberex-sv/diviswap-sdk/issues"
|
|
57
|
+
},
|
|
58
|
+
"files": [
|
|
59
|
+
"dist",
|
|
60
|
+
"bin",
|
|
61
|
+
"README.md",
|
|
62
|
+
"LICENSE",
|
|
63
|
+
"src/cli/templates"
|
|
64
|
+
],
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@types/node": "20.19.19",
|
|
67
|
+
"@types/prompts": "2.4.9",
|
|
68
|
+
"@types/react": "19.2.0",
|
|
69
|
+
"jest": "^29.7.0",
|
|
70
|
+
"prettier": "^3.4.2",
|
|
71
|
+
"tsup": "^8.0.0",
|
|
72
|
+
"typescript": "^5.7.3"
|
|
73
|
+
},
|
|
74
|
+
"dependencies": {
|
|
75
|
+
"@solana/wallet-adapter-base": "0.9.27",
|
|
76
|
+
"@solana/wallet-adapter-react": "0.15.39",
|
|
77
|
+
"@solana/wallet-adapter-react-ui": "0.9.39",
|
|
78
|
+
"@solana/wallet-adapter-wallets": "0.19.37",
|
|
79
|
+
"@solana/web3.js": "1.98.4",
|
|
80
|
+
"commander": "^11.1.0",
|
|
81
|
+
"handlebars": "^4.7.8",
|
|
82
|
+
"kleur": "^4.1.5",
|
|
83
|
+
"prompts": "^2.4.2",
|
|
84
|
+
"socket.io-client": "^4.7.0"
|
|
85
|
+
},
|
|
86
|
+
"engines": {
|
|
87
|
+
"node": ">=18.0.0"
|
|
88
|
+
},
|
|
89
|
+
"peerDependencies": {
|
|
90
|
+
"react": ">=18.0.0",
|
|
91
|
+
"react-dom": ">=18.0.0"
|
|
92
|
+
},
|
|
93
|
+
"peerDependenciesMeta": {
|
|
94
|
+
"react": {
|
|
95
|
+
"optional": true
|
|
96
|
+
},
|
|
97
|
+
"react-dom": {
|
|
98
|
+
"optional": true
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
"publishConfig": {
|
|
102
|
+
"access": "public",
|
|
103
|
+
"registry": "https://registry.npmjs.org/"
|
|
98
104
|
}
|
|
99
|
-
},
|
|
100
|
-
"publishConfig": {
|
|
101
|
-
"access": "restricted",
|
|
102
|
-
"registry": "https://registry.npmjs.org/"
|
|
103
|
-
}
|
|
104
105
|
}
|
|
@@ -5,72 +5,104 @@ import { getPackageRoot } from '../utils/get-package-root';
|
|
|
5
5
|
|
|
6
6
|
// Register helpers
|
|
7
7
|
Handlebars.registerHelper('includes', (array: string[], value: string) => {
|
|
8
|
-
|
|
8
|
+
return array && array.includes(value);
|
|
9
9
|
});
|
|
10
10
|
|
|
11
11
|
Handlebars.registerHelper('json', (value: any) => {
|
|
12
|
-
|
|
12
|
+
return JSON.stringify(value, null, 2);
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
// Template cache
|
|
16
16
|
const templateCache = new Map<string, HandlebarsTemplateDelegate>();
|
|
17
17
|
|
|
18
18
|
export function getTemplate(templateName: string, data: any): string {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
19
|
+
let template = templateCache.get(templateName);
|
|
20
|
+
|
|
21
|
+
if (!template) {
|
|
22
|
+
const packageRoot = getPackageRoot();
|
|
23
|
+
|
|
24
|
+
// Try to read from file system first
|
|
25
|
+
// Note: template files have different extensions like .ts.hbs, .tsx.hbs
|
|
26
|
+
const possiblePaths = [
|
|
27
|
+
// Development paths - try different extensions
|
|
28
|
+
join(packageRoot, 'src', 'cli', 'templates', `${templateName}.hbs`),
|
|
29
|
+
join(
|
|
30
|
+
packageRoot,
|
|
31
|
+
'src',
|
|
32
|
+
'cli',
|
|
33
|
+
'templates',
|
|
34
|
+
`${templateName}.ts.hbs`
|
|
35
|
+
),
|
|
36
|
+
join(
|
|
37
|
+
packageRoot,
|
|
38
|
+
'src',
|
|
39
|
+
'cli',
|
|
40
|
+
'templates',
|
|
41
|
+
`${templateName}.tsx.hbs`
|
|
42
|
+
),
|
|
43
|
+
// Production paths - try different extensions
|
|
44
|
+
join(
|
|
45
|
+
packageRoot,
|
|
46
|
+
'dist',
|
|
47
|
+
'cli',
|
|
48
|
+
'templates',
|
|
49
|
+
`${templateName}.hbs`
|
|
50
|
+
),
|
|
51
|
+
join(
|
|
52
|
+
packageRoot,
|
|
53
|
+
'dist',
|
|
54
|
+
'cli',
|
|
55
|
+
'templates',
|
|
56
|
+
`${templateName}.ts.hbs`
|
|
57
|
+
),
|
|
58
|
+
join(
|
|
59
|
+
packageRoot,
|
|
60
|
+
'dist',
|
|
61
|
+
'cli',
|
|
62
|
+
'templates',
|
|
63
|
+
`${templateName}.tsx.hbs`
|
|
64
|
+
),
|
|
65
|
+
];
|
|
66
|
+
|
|
67
|
+
let templateSource: string | null = null;
|
|
52
68
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
69
|
+
for (const path of possiblePaths) {
|
|
70
|
+
if (existsSync(path)) {
|
|
71
|
+
templateSource = readFileSync(path, 'utf-8');
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
57
75
|
|
|
58
|
-
|
|
76
|
+
if (!templateSource) {
|
|
77
|
+
console.error(`Template ${templateName} not found. Searched in:`);
|
|
78
|
+
possiblePaths.forEach((p) => console.error(` - ${p}`));
|
|
79
|
+
// Fallback to inline templates
|
|
80
|
+
templateSource = getInlineTemplateSource(templateName);
|
|
81
|
+
}
|
|
59
82
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
83
|
+
// Escape JavaScript template literals to prevent Handlebars from interpreting them
|
|
84
|
+
// Replace ${ with a placeholder, compile, then replace back
|
|
85
|
+
const PLACEHOLDER = '__TEMPLATE_LITERAL_START__';
|
|
86
|
+
templateSource = templateSource.replace(/\$\{/g, PLACEHOLDER);
|
|
87
|
+
|
|
88
|
+
const compiledTemplate = Handlebars.compile(templateSource);
|
|
89
|
+
|
|
90
|
+
// Wrap to restore ${ after compilation
|
|
91
|
+
template = (data: any) => {
|
|
92
|
+
const result = compiledTemplate(data);
|
|
93
|
+
return result.replace(new RegExp(PLACEHOLDER, 'g'), '${');
|
|
94
|
+
};
|
|
95
|
+
templateCache.set(templateName, template);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return template(data);
|
|
69
99
|
}
|
|
70
100
|
|
|
71
101
|
function getInlineTemplateSource(templateName: string): string {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
102
|
+
// Return empty string for templates that should be loaded from files
|
|
103
|
+
// This is just a fallback
|
|
104
|
+
console.warn(
|
|
105
|
+
`Template ${templateName} not found in filesystem, returning empty template`
|
|
106
|
+
);
|
|
107
|
+
return '// Template not found';
|
|
108
|
+
}
|
|
@@ -1,78 +1,78 @@
|
|
|
1
1
|
export class LiberExClient {
|
|
2
|
-
|
|
2
|
+
constructor(private baseUrl: string = '/api/liberex') {}
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
private async request(endpoint: string, options: RequestInit = {}) {
|
|
5
|
+
const response = await fetch(`${this.baseUrl}${endpoint}`, {
|
|
6
|
+
...options,
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
...options.headers,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
if (!response.ok) {
|
|
14
|
+
const error = await response.json();
|
|
15
|
+
throw new Error(error.message || 'Request failed');
|
|
16
|
+
}
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
return response.json();
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
async login(email: string, password: string) {
|
|
22
|
+
return this.request('', {
|
|
23
|
+
method: 'POST',
|
|
24
|
+
body: JSON.stringify({ action: 'login', email, password }),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
async logout() {
|
|
29
|
+
return this.request('', {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body: JSON.stringify({ action: 'logout' }),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
async register(data: any) {
|
|
36
|
+
return this.request('', {
|
|
37
|
+
method: 'POST',
|
|
38
|
+
body: JSON.stringify({ action: 'register', ...data }),
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
async checkSession() {
|
|
43
|
+
try {
|
|
44
|
+
return await this.request('?resource=session');
|
|
45
|
+
} catch {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
47
48
|
}
|
|
48
|
-
}
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
async createTransaction(data: any) {
|
|
51
|
+
return this.request('', {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
body: JSON.stringify({ action: 'createTransaction', ...data }),
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
async getPayees() {
|
|
58
|
+
return this.request('?resource=payees');
|
|
59
|
+
}
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
61
|
+
async getTransactions(params?: { limit?: number; offset?: number }) {
|
|
62
|
+
const searchParams = new URLSearchParams({
|
|
63
|
+
resource: 'transactions',
|
|
64
|
+
...(params && {
|
|
65
|
+
limit: params.limit?.toString() || '10',
|
|
66
|
+
offset: params.offset?.toString() || '0',
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
return this.request(`?${searchParams}`);
|
|
70
|
+
}
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
72
|
+
async calculateFees(data: { amount: number; type: 'onramp' | 'offramp' }) {
|
|
73
|
+
return this.request('', {
|
|
74
|
+
method: 'POST',
|
|
75
|
+
body: JSON.stringify({ action: 'calculateFees', ...data }),
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
}
|