@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/package.json CHANGED
@@ -1,104 +1,105 @@
1
1
  {
2
- "name": "@diviswap/sdk",
3
- "version": "1.8.0",
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"
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
- "./react": {
20
- "types": "./dist/react/index.d.ts",
21
- "import": "./dist/react/index.mjs",
22
- "require": "./dist/react/index.js"
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
- "./services": {
25
- "types": "./dist/services/index.d.ts",
26
- "import": "./dist/services/index.mjs",
27
- "require": "./dist/services/index.js"
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
- "./package.json": "./package.json"
30
- },
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"
39
- },
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/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
- "react-dom": {
97
- "optional": true
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
- return array && array.includes(value);
8
+ return array && array.includes(value);
9
9
  });
10
10
 
11
11
  Handlebars.registerHelper('json', (value: any) => {
12
- return JSON.stringify(value, null, 2);
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
- 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(packageRoot, 'src', 'cli', 'templates', `${templateName}.ts.hbs`),
30
- join(packageRoot, 'src', 'cli', 'templates', `${templateName}.tsx.hbs`),
31
- // Production paths - try different extensions
32
- join(packageRoot, 'dist', 'cli', 'templates', `${templateName}.hbs`),
33
- join(packageRoot, 'dist', 'cli', 'templates', `${templateName}.ts.hbs`),
34
- join(packageRoot, 'dist', 'cli', 'templates', `${templateName}.tsx.hbs`),
35
- ];
36
-
37
- let templateSource: string | null = null;
38
-
39
- for (const path of possiblePaths) {
40
- if (existsSync(path)) {
41
- templateSource = readFileSync(path, 'utf-8');
42
- break;
43
- }
44
- }
45
-
46
- if (!templateSource) {
47
- console.error(`Template ${templateName} not found. Searched in:`);
48
- possiblePaths.forEach(p => console.error(` - ${p}`));
49
- // Fallback to inline templates
50
- templateSource = getInlineTemplateSource(templateName);
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
- // Escape JavaScript template literals to prevent Handlebars from interpreting them
54
- // Replace ${ with a placeholder, compile, then replace back
55
- const PLACEHOLDER = '__TEMPLATE_LITERAL_START__';
56
- templateSource = templateSource.replace(/\$\{/g, PLACEHOLDER);
69
+ for (const path of possiblePaths) {
70
+ if (existsSync(path)) {
71
+ templateSource = readFileSync(path, 'utf-8');
72
+ break;
73
+ }
74
+ }
57
75
 
58
- const compiledTemplate = Handlebars.compile(templateSource);
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
- // Wrap to restore ${ after compilation
61
- template = (data: any) => {
62
- const result = compiledTemplate(data);
63
- return result.replace(new RegExp(PLACEHOLDER, 'g'), '${');
64
- };
65
- templateCache.set(templateName, template);
66
- }
67
-
68
- return template(data);
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
- // Return empty string for templates that should be loaded from files
73
- // This is just a fallback
74
- console.warn(`Template ${templateName} not found in filesystem, returning empty template`);
75
- return '// Template not found';
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
- constructor(private baseUrl: string = '/api/liberex') {}
2
+ constructor(private baseUrl: string = '/api/liberex') {}
3
3
 
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
- });
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
- if (!response.ok) {
14
- const error = await response.json();
15
- throw new Error(error.message || 'Request failed');
16
- }
13
+ if (!response.ok) {
14
+ const error = await response.json();
15
+ throw new Error(error.message || 'Request failed');
16
+ }
17
17
 
18
- return response.json();
19
- }
18
+ return response.json();
19
+ }
20
20
 
21
- async login(email: string, password: string) {
22
- return this.request('', {
23
- method: 'POST',
24
- body: JSON.stringify({ action: 'login', email, password }),
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
- async logout() {
29
- return this.request('', {
30
- method: 'POST',
31
- body: JSON.stringify({ action: 'logout' }),
32
- });
33
- }
28
+ async logout() {
29
+ return this.request('', {
30
+ method: 'POST',
31
+ body: JSON.stringify({ action: 'logout' }),
32
+ });
33
+ }
34
34
 
35
- async register(data: any) {
36
- return this.request('', {
37
- method: 'POST',
38
- body: JSON.stringify({ action: 'register', ...data }),
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
- async checkSession() {
43
- try {
44
- return await this.request('?resource=session');
45
- } catch {
46
- return null;
42
+ async checkSession() {
43
+ try {
44
+ return await this.request('?resource=session');
45
+ } catch {
46
+ return null;
47
+ }
47
48
  }
48
- }
49
49
 
50
- async createTransaction(data: any) {
51
- return this.request('', {
52
- method: 'POST',
53
- body: JSON.stringify({ action: 'createTransaction', ...data }),
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
- async getPayees() {
58
- return this.request('?resource=payees');
59
- }
57
+ async getPayees() {
58
+ return this.request('?resource=payees');
59
+ }
60
60
 
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
- }
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
- 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
- }
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
+ }