@diviswap/sdk 1.7.6
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 +21 -0
- package/README.md +510 -0
- package/bin/create-diviswap-app.js +25 -0
- package/bin/diviswap-sdk.js +4 -0
- package/dist/cli/index.js +1888 -0
- package/dist/cli/templates/nextjs-app/actions.ts.hbs +259 -0
- package/dist/cli/templates/nextjs-app/api-hooks.ts.hbs +439 -0
- package/dist/cli/templates/nextjs-app/api-route.ts.hbs +502 -0
- package/dist/cli/templates/nextjs-app/auth-context.tsx.hbs +59 -0
- package/dist/cli/templates/nextjs-app/client.ts.hbs +116 -0
- package/dist/cli/templates/nextjs-app/dashboard-hooks.ts.hbs +180 -0
- package/dist/cli/templates/nextjs-app/example-page.tsx.hbs +276 -0
- package/dist/cli/templates/nextjs-app/hooks.ts.hbs +252 -0
- package/dist/cli/templates/nextjs-app/kyc-hooks.ts.hbs +87 -0
- package/dist/cli/templates/nextjs-app/kyc-wizard.css.hbs +433 -0
- package/dist/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +711 -0
- package/dist/cli/templates/nextjs-app/layout-wrapper.tsx.hbs +13 -0
- package/dist/cli/templates/nextjs-app/layout.tsx.hbs +13 -0
- package/dist/cli/templates/nextjs-app/middleware.ts.hbs +49 -0
- package/dist/cli/templates/nextjs-app/provider-wrapper.tsx.hbs +8 -0
- package/dist/cli/templates/nextjs-app/provider.tsx.hbs +408 -0
- package/dist/cli/templates/nextjs-app/setup-provider.tsx.hbs +25 -0
- package/dist/cli/templates/nextjs-app/types.ts.hbs +159 -0
- package/dist/cli/templates/react/api-client-wrapper.ts.hbs +89 -0
- package/dist/cli/templates/react/example.tsx.hbs +69 -0
- package/dist/cli/templates/react/tanstack-hooks.ts.hbs +185 -0
- package/dist/cli/templates/webhooks/nextjs.hbs +98 -0
- package/dist/index.d.mts +91 -0
- package/dist/index.d.ts +91 -0
- package/dist/index.js +2339 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2313 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react/index.d.mts +192 -0
- package/dist/react/index.d.ts +192 -0
- package/dist/react/index.js +1083 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/index.mjs +1064 -0
- package/dist/react/index.mjs.map +1 -0
- package/dist/wallet-BEGvzNtB.d.mts +1614 -0
- package/dist/wallet-BEGvzNtB.d.ts +1614 -0
- package/package.json +102 -0
- package/src/cli/templates/index.ts +65 -0
- package/src/cli/templates/nextjs-app/actions.ts.hbs +259 -0
- package/src/cli/templates/nextjs-app/api-hooks.ts.hbs +439 -0
- package/src/cli/templates/nextjs-app/api-route.ts.hbs +502 -0
- package/src/cli/templates/nextjs-app/auth-context.tsx.hbs +59 -0
- package/src/cli/templates/nextjs-app/client.ts.hbs +116 -0
- package/src/cli/templates/nextjs-app/dashboard-hooks.ts.hbs +180 -0
- package/src/cli/templates/nextjs-app/example-page.tsx.hbs +276 -0
- package/src/cli/templates/nextjs-app/hooks.ts.hbs +252 -0
- package/src/cli/templates/nextjs-app/kyc-hooks.ts.hbs +87 -0
- package/src/cli/templates/nextjs-app/kyc-wizard.css.hbs +433 -0
- package/src/cli/templates/nextjs-app/kyc-wizard.tsx.hbs +711 -0
- package/src/cli/templates/nextjs-app/layout-wrapper.tsx.hbs +13 -0
- package/src/cli/templates/nextjs-app/layout.tsx.hbs +13 -0
- package/src/cli/templates/nextjs-app/middleware.ts.hbs +49 -0
- package/src/cli/templates/nextjs-app/provider-wrapper.tsx.hbs +8 -0
- package/src/cli/templates/nextjs-app/provider.tsx.hbs +408 -0
- package/src/cli/templates/nextjs-app/setup-provider.tsx.hbs +25 -0
- package/src/cli/templates/nextjs-app/types.ts.hbs +159 -0
- package/src/cli/templates/react/api-client-wrapper.ts.hbs +89 -0
- package/src/cli/templates/react/example.tsx.hbs +69 -0
- package/src/cli/templates/react/tanstack-hooks.ts.hbs +185 -0
- package/src/cli/templates/shared/client.ts +78 -0
- package/src/cli/templates/webhooks/nextjs.hbs +98 -0
package/package.json
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@diviswap/sdk",
|
|
3
|
+
"version": "1.7.6",
|
|
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
|
+
"diviswap-sdk": "bin/diviswap-sdk.js",
|
|
10
|
+
"create-diviswap-app": "bin/create-diviswap-app.js"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"import": "./dist/index.mjs",
|
|
16
|
+
"require": "./dist/index.js"
|
|
17
|
+
},
|
|
18
|
+
"./react": {
|
|
19
|
+
"types": "./dist/react/index.d.ts",
|
|
20
|
+
"import": "./dist/react/index.mjs",
|
|
21
|
+
"require": "./dist/react/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./services": {
|
|
24
|
+
"types": "./dist/services/index.d.ts",
|
|
25
|
+
"import": "./dist/services/index.mjs",
|
|
26
|
+
"require": "./dist/services/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsup && node scripts/copy-templates.js",
|
|
31
|
+
"dev": "tsup --watch",
|
|
32
|
+
"dev:demo": "cd examples/nextjs-web3 && npm run dev",
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
35
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
36
|
+
"prepublishOnly": "npm run build"
|
|
37
|
+
},
|
|
38
|
+
"keywords": [
|
|
39
|
+
"diviswap",
|
|
40
|
+
"crypto",
|
|
41
|
+
"onramp",
|
|
42
|
+
"offramp",
|
|
43
|
+
"payments",
|
|
44
|
+
"sdk"
|
|
45
|
+
],
|
|
46
|
+
"author": "Diviswap <support@diviswap.io>",
|
|
47
|
+
"license": "MIT",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/diviswap/sdk.git"
|
|
51
|
+
},
|
|
52
|
+
"homepage": "https://github.com/diviswap/sdk#readme",
|
|
53
|
+
"bugs": {
|
|
54
|
+
"url": "https://github.com/diviswap/sdk/issues"
|
|
55
|
+
},
|
|
56
|
+
"files": [
|
|
57
|
+
"dist",
|
|
58
|
+
"bin",
|
|
59
|
+
"README.md",
|
|
60
|
+
"LICENSE",
|
|
61
|
+
"src/cli/templates"
|
|
62
|
+
],
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@types/node": "20.19.19",
|
|
65
|
+
"@types/react": "19.2.0",
|
|
66
|
+
"jest": "^29.7.0",
|
|
67
|
+
"prettier": "^3.4.2",
|
|
68
|
+
"tsup": "^8.0.0",
|
|
69
|
+
"typescript": "^5.7.3"
|
|
70
|
+
},
|
|
71
|
+
"dependencies": {
|
|
72
|
+
"@solana/wallet-adapter-base": "0.9.27",
|
|
73
|
+
"@solana/wallet-adapter-react": "0.15.39",
|
|
74
|
+
"@solana/wallet-adapter-react-ui": "0.9.39",
|
|
75
|
+
"@solana/wallet-adapter-wallets": "0.19.37",
|
|
76
|
+
"@solana/web3.js": "1.98.4",
|
|
77
|
+
"commander": "^11.1.0",
|
|
78
|
+
"handlebars": "^4.7.8",
|
|
79
|
+
"kleur": "^4.1.5",
|
|
80
|
+
"prompts": "^2.4.2",
|
|
81
|
+
"socket.io-client": "^4.7.0"
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": ">=18.0.0"
|
|
85
|
+
},
|
|
86
|
+
"peerDependencies": {
|
|
87
|
+
"react": ">=18.0.0",
|
|
88
|
+
"react-dom": ">=18.0.0"
|
|
89
|
+
},
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"react": {
|
|
92
|
+
"optional": true
|
|
93
|
+
},
|
|
94
|
+
"react-dom": {
|
|
95
|
+
"optional": true
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
"publishConfig": {
|
|
99
|
+
"access": "restricted",
|
|
100
|
+
"registry": "https://registry.npmjs.org/"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readFileSync, existsSync } from 'fs';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import Handlebars from 'handlebars';
|
|
4
|
+
import { getPackageRoot } from '../utils/get-package-root';
|
|
5
|
+
|
|
6
|
+
// Register helpers
|
|
7
|
+
Handlebars.registerHelper('includes', (array: string[], value: string) => {
|
|
8
|
+
return array && array.includes(value);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
Handlebars.registerHelper('json', (value: any) => {
|
|
12
|
+
return JSON.stringify(value, null, 2);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Template cache
|
|
16
|
+
const templateCache = new Map<string, HandlebarsTemplateDelegate>();
|
|
17
|
+
|
|
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
|
+
}
|
|
52
|
+
|
|
53
|
+
template = Handlebars.compile(templateSource);
|
|
54
|
+
templateCache.set(templateName, template);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return template(data);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function getInlineTemplateSource(templateName: string): string {
|
|
61
|
+
// Return empty string for templates that should be loaded from files
|
|
62
|
+
// This is just a fallback
|
|
63
|
+
console.warn(`Template ${templateName} not found in filesystem, returning empty template`);
|
|
64
|
+
return '// Template not found';
|
|
65
|
+
}
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
'use server';
|
|
2
|
+
|
|
3
|
+
import { Diviswap } from '@diviswap/sdk';
|
|
4
|
+
import type { Transaction, Payee } from '@diviswap/sdk';
|
|
5
|
+
import { revalidatePath } from 'next/cache';
|
|
6
|
+
import { cookies } from 'next/headers';
|
|
7
|
+
|
|
8
|
+
// Initialize Diviswap SDK
|
|
9
|
+
function getDiviswap() {
|
|
10
|
+
return Diviswap.init({
|
|
11
|
+
apiKey: process.env.DIVISWAP_API_KEY!,
|
|
12
|
+
clientId: process.env.DIVISWAP_CLIENT_ID!,
|
|
13
|
+
environment: (process.env.NEXT_PUBLIC_DIVISWAP_ENV as 'production' | 'sandbox') || 'production',
|
|
14
|
+
debug: true // Enable debug logging
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Helper to get session token from cookies
|
|
19
|
+
async function getSessionToken() {
|
|
20
|
+
const cookieStore = await cookies();
|
|
21
|
+
const session = cookieStore.get('diviswap_session');
|
|
22
|
+
return session?.value;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Transaction Server Actions
|
|
26
|
+
export async function createTransactionAction(data: {
|
|
27
|
+
type: 'onramp' | 'offramp';
|
|
28
|
+
amount: number;
|
|
29
|
+
currency?: string;
|
|
30
|
+
payeeId?: string;
|
|
31
|
+
paymentMethodId?: string;
|
|
32
|
+
// Required for offramp
|
|
33
|
+
fromAddress?: string;
|
|
34
|
+
chain?: string;
|
|
35
|
+
}) {
|
|
36
|
+
try {
|
|
37
|
+
const sessionToken = await getSessionToken();
|
|
38
|
+
if (!sessionToken) {
|
|
39
|
+
return { success: false, error: 'Not authenticated' };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const diviswap = getDiviswap();
|
|
43
|
+
|
|
44
|
+
// Use the appropriate method based on transaction type
|
|
45
|
+
let transaction;
|
|
46
|
+
if (data.type === 'onramp') {
|
|
47
|
+
// Note: Onramp is not yet available in v1 API
|
|
48
|
+
return { success: false, error: 'Onramp transactions are not yet available' };
|
|
49
|
+
} else {
|
|
50
|
+
transaction = await diviswap.transactions.offramp({
|
|
51
|
+
amount: data.amount,
|
|
52
|
+
currency: data.currency || 'USD',
|
|
53
|
+
payeeId: data.payeeId!,
|
|
54
|
+
fromAddress: data.fromAddress!, // Required for offramp
|
|
55
|
+
chain: data.chain || 'ethereum'
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
revalidatePath('/diviswap');
|
|
60
|
+
return { success: true, transaction };
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return {
|
|
63
|
+
success: false,
|
|
64
|
+
error: error instanceof Error ? error.message : 'Transaction creation failed'
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export async function getTransactionsAction(filters?: {
|
|
70
|
+
limit?: number;
|
|
71
|
+
offset?: number;
|
|
72
|
+
status?: 'pending' | 'processing' | 'completed' | 'failed';
|
|
73
|
+
type?: 'onramp' | 'offramp';
|
|
74
|
+
}) {
|
|
75
|
+
try {
|
|
76
|
+
const sessionToken = await getSessionToken();
|
|
77
|
+
if (!sessionToken) {
|
|
78
|
+
return { success: false, error: 'Not authenticated' };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const diviswap = getDiviswap();
|
|
82
|
+
const transactions = await diviswap.transactions.list(filters);
|
|
83
|
+
|
|
84
|
+
return { success: true, transactions };
|
|
85
|
+
} catch (error) {
|
|
86
|
+
return {
|
|
87
|
+
success: false,
|
|
88
|
+
error: error instanceof Error ? error.message : 'Failed to fetch transactions'
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Payee Server Actions
|
|
94
|
+
export async function getPayeesAction() {
|
|
95
|
+
try {
|
|
96
|
+
const sessionToken = await getSessionToken();
|
|
97
|
+
if (!sessionToken) {
|
|
98
|
+
return { success: false, error: 'Not authenticated' };
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const diviswap = getDiviswap();
|
|
102
|
+
const payees = await diviswap.payees.list();
|
|
103
|
+
|
|
104
|
+
return { success: true, payees };
|
|
105
|
+
} catch (error) {
|
|
106
|
+
return {
|
|
107
|
+
success: false,
|
|
108
|
+
error: error instanceof Error ? error.message : 'Failed to fetch payees'
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function createPayeeAction(data: {
|
|
114
|
+
nickname: string;
|
|
115
|
+
accountNumber: string;
|
|
116
|
+
routingNumber: string;
|
|
117
|
+
accountType: 'checking' | 'savings';
|
|
118
|
+
}) {
|
|
119
|
+
try {
|
|
120
|
+
const sessionToken = await getSessionToken();
|
|
121
|
+
if (!sessionToken) {
|
|
122
|
+
return { success: false, error: 'Not authenticated' };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const diviswap = getDiviswap();
|
|
126
|
+
const payee = await diviswap.payees.create({
|
|
127
|
+
nickname: data.nickname,
|
|
128
|
+
accountNumber: data.accountNumber,
|
|
129
|
+
routingNumber: data.routingNumber,
|
|
130
|
+
accountType: data.accountType,
|
|
131
|
+
setAsDefault: false
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
revalidatePath('/diviswap');
|
|
135
|
+
return { success: true, payee };
|
|
136
|
+
} catch (error) {
|
|
137
|
+
return {
|
|
138
|
+
success: false,
|
|
139
|
+
error: error instanceof Error ? error.message : 'Payee creation failed'
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export async function deletePayeeAction(payeeId: string) {
|
|
145
|
+
try {
|
|
146
|
+
const sessionToken = await getSessionToken();
|
|
147
|
+
if (!sessionToken) {
|
|
148
|
+
return { success: false, error: 'Not authenticated' };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const diviswap = getDiviswap();
|
|
152
|
+
await diviswap.payees.delete(payeeId);
|
|
153
|
+
|
|
154
|
+
revalidatePath('/diviswap');
|
|
155
|
+
return { success: true };
|
|
156
|
+
} catch (error) {
|
|
157
|
+
return {
|
|
158
|
+
success: false,
|
|
159
|
+
error: error instanceof Error ? error.message : 'Failed to delete payee'
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
{{#if (includes features "fees")}}
|
|
165
|
+
// Fee Calculation Server Actions
|
|
166
|
+
export async function calculateFeesAction(data: {
|
|
167
|
+
amount: number;
|
|
168
|
+
type: 'onramp' | 'offramp';
|
|
169
|
+
currency?: string;
|
|
170
|
+
}) {
|
|
171
|
+
try {
|
|
172
|
+
const diviswap = getDiviswap();
|
|
173
|
+
const fees = await diviswap.fees.calculateFees({
|
|
174
|
+
amount: data.amount,
|
|
175
|
+
userId: undefined // Optional: for per-user fees
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
return { success: true, fees };
|
|
179
|
+
} catch (error) {
|
|
180
|
+
return {
|
|
181
|
+
success: false,
|
|
182
|
+
error: error instanceof Error ? error.message : 'Fee calculation failed'
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function getIntegratorFeesAction() {
|
|
188
|
+
try {
|
|
189
|
+
const sessionToken = await getSessionToken();
|
|
190
|
+
if (!sessionToken) {
|
|
191
|
+
return { success: false, error: 'Not authenticated' };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const diviswap = getDiviswap();
|
|
195
|
+
const fees = await diviswap.fees.getFees();
|
|
196
|
+
|
|
197
|
+
return { success: true, fees };
|
|
198
|
+
} catch (error) {
|
|
199
|
+
return {
|
|
200
|
+
success: false,
|
|
201
|
+
error: error instanceof Error ? error.message : 'Failed to fetch integrator fees'
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export async function updateIntegratorFeeAction(data: {
|
|
207
|
+
percentage: number;
|
|
208
|
+
userId?: string;
|
|
209
|
+
}) {
|
|
210
|
+
try {
|
|
211
|
+
const sessionToken = await getSessionToken();
|
|
212
|
+
if (!sessionToken) {
|
|
213
|
+
return { success: false, error: 'Not authenticated' };
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const diviswap = getDiviswap();
|
|
217
|
+
const fee = await diviswap.fees.setFee(data);
|
|
218
|
+
|
|
219
|
+
revalidatePath('/diviswap');
|
|
220
|
+
return { success: true, fee };
|
|
221
|
+
} catch (error) {
|
|
222
|
+
return {
|
|
223
|
+
success: false,
|
|
224
|
+
error: error instanceof Error ? error.message : 'Failed to update fee'
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
{{/if}}
|
|
229
|
+
|
|
230
|
+
// Authentication Server Actions (for server components that need auth status)
|
|
231
|
+
export async function getCurrentUserAction() {
|
|
232
|
+
try {
|
|
233
|
+
const sessionToken = await getSessionToken();
|
|
234
|
+
if (!sessionToken) {
|
|
235
|
+
return { success: false, user: null };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const diviswap = getDiviswap();
|
|
239
|
+
const user = await diviswap.auth.getProfile();
|
|
240
|
+
|
|
241
|
+
return { success: true, user };
|
|
242
|
+
} catch (error) {
|
|
243
|
+
return { success: false, user: null };
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
// Utility action for checking API status
|
|
248
|
+
export async function checkApiStatusAction() {
|
|
249
|
+
try {
|
|
250
|
+
const diviswap = getDiviswap();
|
|
251
|
+
// Note: Health check endpoint not available in SDK
|
|
252
|
+
return { success: true, status: 'OK' };
|
|
253
|
+
} catch (error) {
|
|
254
|
+
return {
|
|
255
|
+
success: false,
|
|
256
|
+
error: error instanceof Error ? error.message : 'API health check failed'
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|