@dipansrimany/mlink-sdk 0.3.1 → 0.4.2
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/dist/adapters/express.d.mts +2 -2
- package/dist/adapters/express.d.ts +2 -2
- package/dist/adapters/express.js +117 -10
- package/dist/adapters/express.js.map +1 -1
- package/dist/adapters/express.mjs +117 -10
- package/dist/adapters/express.mjs.map +1 -1
- package/dist/adapters/next.d.mts +2 -2
- package/dist/adapters/next.d.ts +2 -2
- package/dist/adapters/next.js +117 -10
- package/dist/adapters/next.js.map +1 -1
- package/dist/adapters/next.mjs +117 -10
- package/dist/adapters/next.mjs.map +1 -1
- package/dist/builders-CLqoe2Kx.d.ts +245 -0
- package/dist/builders-pKj4NiIj.d.mts +245 -0
- package/dist/index.d.mts +1131 -24
- package/dist/index.d.ts +1131 -24
- package/dist/index.js +346 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +317 -21
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +43 -5
- package/dist/react/index.d.ts +43 -5
- package/dist/react/index.js +522 -37
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +522 -37
- package/dist/react/index.mjs.map +1 -1
- package/dist/styles.css +248 -0
- package/dist/types-DD9rJ58Y.d.mts +214 -0
- package/dist/types-DD9rJ58Y.d.ts +214 -0
- package/package.json +2 -2
- package/dist/builders-CJNt88dM.d.ts +0 -19
- package/dist/builders-CN5ijFpW.d.mts +0 -19
- package/dist/types-CAnUIaVe.d.mts +0 -68
- package/dist/types-CAnUIaVe.d.ts +0 -68
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import { g as ActionDefinition, d as ActionButton, o as ActionLinks, A as ActionMetadata, T as TransactionRequest, a as TransactionResponse, b as TypedActionParameter, L as LinkedAction, m as ActionParameterSelectable, l as ActionParameter, j as ActionParameterOption } from './types-DD9rJ58Y.mjs';
|
|
2
|
+
|
|
3
|
+
declare function button(config: {
|
|
4
|
+
label: string;
|
|
5
|
+
value: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
}): ActionButton;
|
|
8
|
+
declare function input(config: {
|
|
9
|
+
label: string;
|
|
10
|
+
placeholder?: string;
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}): ActionButton;
|
|
13
|
+
/**
|
|
14
|
+
* Create a linked action with optional parameters
|
|
15
|
+
* Uses Solana-style href templates with {parameter} placeholders
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* linkedAction({
|
|
20
|
+
* href: '/api/swap?amount={amount}&token={token}',
|
|
21
|
+
* label: 'Swap Tokens',
|
|
22
|
+
* parameters: [
|
|
23
|
+
* textParam({ name: 'amount', label: 'Amount', required: true }),
|
|
24
|
+
* selectParam({
|
|
25
|
+
* name: 'token',
|
|
26
|
+
* label: 'Token',
|
|
27
|
+
* options: [
|
|
28
|
+
* { label: 'USDC', value: '0x...' },
|
|
29
|
+
* { label: 'USDT', value: '0x...' }
|
|
30
|
+
* ]
|
|
31
|
+
* })
|
|
32
|
+
* ]
|
|
33
|
+
* })
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
declare function linkedAction(config: {
|
|
37
|
+
href: string;
|
|
38
|
+
label: string;
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
parameters?: TypedActionParameter[];
|
|
41
|
+
}): LinkedAction;
|
|
42
|
+
/**
|
|
43
|
+
* Create a simple linked action button (no parameters, just a static href)
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* actionButton({
|
|
48
|
+
* href: '/api/tip?amount=1',
|
|
49
|
+
* label: 'Tip 1 MNT'
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
declare function actionButton(config: {
|
|
54
|
+
href: string;
|
|
55
|
+
label: string;
|
|
56
|
+
disabled?: boolean;
|
|
57
|
+
}): LinkedAction;
|
|
58
|
+
/**
|
|
59
|
+
* Create a text parameter
|
|
60
|
+
*/
|
|
61
|
+
declare function textParam(config: {
|
|
62
|
+
name: string;
|
|
63
|
+
label?: string;
|
|
64
|
+
required?: boolean;
|
|
65
|
+
pattern?: string;
|
|
66
|
+
patternDescription?: string;
|
|
67
|
+
}): ActionParameter;
|
|
68
|
+
/**
|
|
69
|
+
* Create a number parameter
|
|
70
|
+
*/
|
|
71
|
+
declare function numberParam(config: {
|
|
72
|
+
name: string;
|
|
73
|
+
label?: string;
|
|
74
|
+
required?: boolean;
|
|
75
|
+
min?: number | string;
|
|
76
|
+
max?: number | string;
|
|
77
|
+
}): ActionParameter;
|
|
78
|
+
/**
|
|
79
|
+
* Create an amount parameter (for token/ETH amounts)
|
|
80
|
+
*/
|
|
81
|
+
declare function amountParam(config: {
|
|
82
|
+
name: string;
|
|
83
|
+
label?: string;
|
|
84
|
+
required?: boolean;
|
|
85
|
+
min?: number | string;
|
|
86
|
+
max?: number | string;
|
|
87
|
+
}): ActionParameter;
|
|
88
|
+
/**
|
|
89
|
+
* Create an address parameter (for wallet addresses)
|
|
90
|
+
*/
|
|
91
|
+
declare function addressParam(config: {
|
|
92
|
+
name: string;
|
|
93
|
+
label?: string;
|
|
94
|
+
required?: boolean;
|
|
95
|
+
}): ActionParameter;
|
|
96
|
+
/**
|
|
97
|
+
* Create a select dropdown parameter
|
|
98
|
+
*/
|
|
99
|
+
declare function selectParam(config: {
|
|
100
|
+
name: string;
|
|
101
|
+
label?: string;
|
|
102
|
+
required?: boolean;
|
|
103
|
+
options: ActionParameterOption[];
|
|
104
|
+
}): ActionParameterSelectable;
|
|
105
|
+
/**
|
|
106
|
+
* Create a radio button group parameter
|
|
107
|
+
*/
|
|
108
|
+
declare function radioParam(config: {
|
|
109
|
+
name: string;
|
|
110
|
+
label?: string;
|
|
111
|
+
required?: boolean;
|
|
112
|
+
options: ActionParameterOption[];
|
|
113
|
+
}): ActionParameterSelectable;
|
|
114
|
+
/**
|
|
115
|
+
* Create a checkbox parameter (multiple selection)
|
|
116
|
+
*/
|
|
117
|
+
declare function checkboxParam(config: {
|
|
118
|
+
name: string;
|
|
119
|
+
label?: string;
|
|
120
|
+
required?: boolean;
|
|
121
|
+
options: ActionParameterOption[];
|
|
122
|
+
}): ActionParameterSelectable;
|
|
123
|
+
/**
|
|
124
|
+
* Create a date parameter
|
|
125
|
+
*/
|
|
126
|
+
declare function dateParam(config: {
|
|
127
|
+
name: string;
|
|
128
|
+
label?: string;
|
|
129
|
+
required?: boolean;
|
|
130
|
+
min?: string;
|
|
131
|
+
max?: string;
|
|
132
|
+
}): ActionParameter;
|
|
133
|
+
/**
|
|
134
|
+
* Create a textarea parameter (multi-line text)
|
|
135
|
+
*/
|
|
136
|
+
declare function textareaParam(config: {
|
|
137
|
+
name: string;
|
|
138
|
+
label?: string;
|
|
139
|
+
required?: boolean;
|
|
140
|
+
}): ActionParameter;
|
|
141
|
+
/**
|
|
142
|
+
* Create an option for select/radio/checkbox parameters
|
|
143
|
+
*/
|
|
144
|
+
declare function option(label: string, value: string, selected?: boolean): ActionParameterOption;
|
|
145
|
+
/**
|
|
146
|
+
* Create a links object with actions array
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* createLinks([
|
|
151
|
+
* actionButton({ href: '/api/tip?amount=1', label: 'Tip 1 MNT' }),
|
|
152
|
+
* actionButton({ href: '/api/tip?amount=5', label: 'Tip 5 MNT' }),
|
|
153
|
+
* linkedAction({
|
|
154
|
+
* href: '/api/tip?amount={amount}',
|
|
155
|
+
* label: 'Custom Amount',
|
|
156
|
+
* parameters: [amountParam({ name: 'amount', required: true })]
|
|
157
|
+
* })
|
|
158
|
+
* ])
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
declare function createLinks(actions: LinkedAction[]): ActionLinks;
|
|
162
|
+
/**
|
|
163
|
+
* Replace placeholders in href template with parameter values
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* ```ts
|
|
167
|
+
* buildHref('/api/swap?amount={amount}&token={token}', { amount: '100', token: '0x...' })
|
|
168
|
+
* // Returns: '/api/swap?amount=100&token=0x...'
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
declare function buildHref(template: string, params: Record<string, string | string[]>): string;
|
|
172
|
+
/**
|
|
173
|
+
* Extract parameter names from href template
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* ```ts
|
|
177
|
+
* extractParams('/api/swap?amount={amount}&token={token}')
|
|
178
|
+
* // Returns: ['amount', 'token']
|
|
179
|
+
* ```
|
|
180
|
+
*/
|
|
181
|
+
declare function extractParams(template: string): string[];
|
|
182
|
+
/**
|
|
183
|
+
* Check if a linked action has parameters that need to be collected
|
|
184
|
+
*/
|
|
185
|
+
declare function hasParameters(action: LinkedAction): boolean;
|
|
186
|
+
/**
|
|
187
|
+
* Check if a parameter is selectable (select/radio/checkbox)
|
|
188
|
+
*/
|
|
189
|
+
declare function isSelectableParam(param: TypedActionParameter): param is ActionParameterSelectable;
|
|
190
|
+
interface Action {
|
|
191
|
+
getMetadata(): ActionMetadata;
|
|
192
|
+
handleRequest(request: TransactionRequest): Promise<TransactionResponse>;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Extended action definition that supports both legacy actions and linked actions
|
|
196
|
+
*/
|
|
197
|
+
interface ExtendedActionDefinition extends Omit<ActionDefinition, 'actions'> {
|
|
198
|
+
/** Primary button label */
|
|
199
|
+
label?: string;
|
|
200
|
+
/** Legacy actions array (backwards compatible) */
|
|
201
|
+
actions?: ActionButton[];
|
|
202
|
+
/** Solana-style linked actions */
|
|
203
|
+
links?: ActionLinks;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Create a complete action with support for both legacy and Solana-style linked actions
|
|
207
|
+
*
|
|
208
|
+
* @example Legacy style (backwards compatible):
|
|
209
|
+
* ```ts
|
|
210
|
+
* createAction({
|
|
211
|
+
* title: 'Tip',
|
|
212
|
+
* icon: 'https://...',
|
|
213
|
+
* description: 'Send a tip',
|
|
214
|
+
* actions: [
|
|
215
|
+
* button({ label: '1 MNT', value: '1' }),
|
|
216
|
+
* input({ label: 'Custom' })
|
|
217
|
+
* ],
|
|
218
|
+
* handler: async (ctx) => ({ transaction: {...} })
|
|
219
|
+
* })
|
|
220
|
+
* ```
|
|
221
|
+
*
|
|
222
|
+
* @example Solana-style linked actions:
|
|
223
|
+
* ```ts
|
|
224
|
+
* createAction({
|
|
225
|
+
* title: 'Swap Tokens',
|
|
226
|
+
* icon: 'https://...',
|
|
227
|
+
* description: 'Swap tokens on DEX',
|
|
228
|
+
* links: createLinks([
|
|
229
|
+
* actionButton({ href: '/api/swap?amount=10', label: 'Swap 10' }),
|
|
230
|
+
* linkedAction({
|
|
231
|
+
* href: '/api/swap?amount={amount}&token={token}',
|
|
232
|
+
* label: 'Custom Swap',
|
|
233
|
+
* parameters: [
|
|
234
|
+
* amountParam({ name: 'amount', required: true }),
|
|
235
|
+
* selectParam({ name: 'token', options: [...] })
|
|
236
|
+
* ]
|
|
237
|
+
* })
|
|
238
|
+
* ]),
|
|
239
|
+
* handler: async (ctx) => ({ transaction: {...} })
|
|
240
|
+
* })
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
243
|
+
declare function createAction(definition: ExtendedActionDefinition): Action;
|
|
244
|
+
|
|
245
|
+
export { type Action as A, type ExtendedActionDefinition as E, actionButton as a, button as b, createAction as c, createLinks as d, buildHref as e, extractParams as f, isSelectableParam as g, hasParameters as h, input as i, amountParam as j, addressParam as k, linkedAction as l, checkboxParam as m, numberParam as n, dateParam as o, textareaParam as p, option as q, radioParam as r, selectParam as s, textParam as t };
|