@@ -18,6 +18,16 @@ to a decentralized app; in Discord, a bot might expand the blink into an
18
18
interactive set of buttons. This pushes the ability to interact on-chain to any
19
19
web surface capable of displaying a URL.
20
20
21
+ ## Simplified Type Definitions
22
+
23
+ The types and interfaces declared within this readme files are often the
24
+ simplified version of the types to aid in readability.
25
+
26
+ For better type safety and improved developer experience, the
27
+ ` @solana/actions-spec ` package contains more complex type definitions. You can
28
+ find the
29
+ [ source code for them here] ( https://github.com/solana-developers/solana-actions/blob/main/packages/actions-spec/index.d.ts ) .
30
+
21
31
## Contributing
22
32
23
33
If you would like to propose an update the Solana Actions specification, please
@@ -224,21 +234,169 @@ export interface LinkedAction {
224
234
href: string ;
225
235
/** button text rendered to the user */
226
236
label: string ;
227
- /** Parameter to accept user input within an action */
228
- parameters? : [ActionParameter ];
237
+ /**
238
+ * Parameters to accept user input within an action
239
+ * @see {ActionParameter}
240
+ * @see {ActionParameterSelectable}
241
+ */
242
+ parameters? : Array <TypedActionParameter >;
229
243
}
244
+ ```
230
245
231
- /** Parameter to accept user input within an action */
246
+ The ` ActionParameter ` allows declaring what input the Action API is requesting
247
+ from the user:
248
+
249
+ ``` ts filename="ActionParameter"
250
+ /**
251
+ * Parameter to accept user input within an action
252
+ * note: for ease of reading, this is a simplified type of the actual
253
+ */
232
254
export interface ActionParameter {
255
+ /** input field type */
256
+ type? : ActionParameterType ;
233
257
/** parameter name in url */
234
258
name: string ;
235
259
/** placeholder text for the user input field */
236
260
label? : string ;
237
261
/** declare if this field is required (defaults to `false`) */
238
262
required? : boolean ;
263
+ /** regular expression pattern to validate user input client side */
264
+ pattern? : string ;
265
+ /** human-readable description of the `type` and/or `pattern`, represents a caption and error, if value doesn't match */
266
+ patternDescription? : string ;
267
+ /** the minimum value allowed based on the `type` */
268
+ min? : string | number ;
269
+ /** the maximum value allowed based on the `type` */
270
+ max? : string | number ;
239
271
}
240
272
```
241
273
274
+ The ` pattern ` should be a string equivalent of a valid regular expression. This
275
+ regular expression pattern should by used by blink-clients to validate user
276
+ input before before making the POST request. If the ` pattern ` is not a valid
277
+ regular expression, it should be ignored by clients.
278
+
279
+ The ` patternDescription ` is a human readable description of the expected input
280
+ requests from the user. If ` pattern ` is provided, the ` patternDescription ` is
281
+ required to be provided.
282
+
283
+ The ` min ` and ` max ` values allows the input to set a lower and/or upper bounds
284
+ of the input requested from the user (i.e. min/max number and or min/max
285
+ character length), and should be used for client side validation. For input
286
+ ` type ` s of ` date ` or ` datetime-local ` , these values should be a string dates.
287
+ For other string based input ` type ` s, the values should be numbers representing
288
+ their min/max character length.
289
+
290
+ If the user input value is not considered valid per the ` pattern ` , the user
291
+ should receive a client side error message indicating the input field is not
292
+ valid and displayed the ` patternDescription ` string.
293
+
294
+ The ` type ` field allows the Action API to declare more specific user input
295
+ fields, providing better client side validation and improving the user
296
+ experience. In many cases, this type will resemble the standard
297
+ [ HTML input element] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input ) .
298
+
299
+ The ` ActionParameterType ` can be simplified to the following type:
300
+
301
+ ``` ts filename="ActionParameterType"
302
+ /**
303
+ * Input field type to present to the user
304
+ * @default `text`
305
+ */
306
+ export type ActionParameterType =
307
+ | " text"
308
+ | " email"
309
+ | " url"
310
+ | " number"
311
+ | " date"
312
+ | " datetime-local"
313
+ | " checkbox"
314
+ | " radio"
315
+ | " textarea"
316
+ | " select" ;
317
+ ```
318
+
319
+ Each of the ` type ` values should normally result in a user input field that
320
+ resembles a standard HTML ` input ` element of the corresponding ` type ` (i.e.
321
+ ` <input type="email" /> ` ) to provide better client side validation and user
322
+ experience:
323
+
324
+ - ` text ` - equivalent of HTML
325
+ [ “text” input] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text )
326
+ element
327
+ - ` email ` - equivalent of HTML
328
+ [ “email” input] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/email )
329
+ element
330
+ - ` url ` - equivalent of HTML
331
+ [ “url” input] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/url )
332
+ element
333
+ - ` number ` - equivalent of HTML
334
+ [ “number” input] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number )
335
+ element
336
+ - ` date ` - equivalent of HTML
337
+ [ “date” input] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date )
338
+ element
339
+ - ` datetime-local ` - equivalent of HTML
340
+ [ “datetime-local” input] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/datetime-local )
341
+ element
342
+ - ` checkbox ` - equivalent to a grouping of standard HTML
343
+ [ “checkbox” input] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox )
344
+ elements. The Action API should return ` options ` as detailed below. The user
345
+ should be able to select multiple of the provided checkbox options.
346
+ - ` radio ` - equivalent to a grouping of standard HTML
347
+ [ “radio” input] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio )
348
+ elements. The Action API should return ` options ` as detailed below. The user
349
+ should be able to select only one of the provided radio options.
350
+ - Other HTML input type equivalents not specified above (` hidden ` , ` button ` ,
351
+ ` submit ` , ` file ` , etc) are not supported at this time.
352
+
353
+ In addition to the elements resembling HTML input types above, the following
354
+ user input elements are also supported:
355
+
356
+ - ` textarea ` - equivalent of HTML
357
+ [ textarea element] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea ) .
358
+ Allowing the user provide multi-line input.
359
+ - ` select ` - equivalent of HTML
360
+ [ select element] ( https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select ) ,
361
+ allowing the user to experience a “dropdown” style field. The Action API
362
+ should return ` options ` as detailed below.
363
+
364
+ When ` type ` is set as ` select ` , ` checkbox ` , or ` radio ` then the Action API
365
+ should include an array of ` options ` that each provide a ` label ` and ` value ` at
366
+ a minimum. Each option may also have a ` selected ` value to inform the
367
+ blink-client which of the options should be selected by default for the user
368
+ (see ` checkbox ` and ` radio ` for differences).
369
+
370
+ This ` ActionParameterSelectable ` can be simplified to the following type
371
+ definition:
372
+
373
+ ``` ts filename="ActionParameterSelectable"
374
+ /**
375
+ * note: for ease of reading, this is a simplified type of the actual
376
+ */
377
+ interface ActionParameterSelectable extends ActionParameter {
378
+ options: Array <{
379
+ /** displayed UI label of this selectable option */
380
+ label: string ;
381
+ /** value of this selectable option */
382
+ value: string ;
383
+ /** whether or not this option should be selected by default */
384
+ selected? : boolean ;
385
+ }>;
386
+ }
387
+ ```
388
+
389
+ If no ` type ` is set or an unknown/unsupported value is set, blink-client should
390
+ default to ` text ` and render a simple text input.
391
+
392
+ The Action API is still responsible to validate and sanitize all data from the
393
+ user input parameters, enforcing any “required” user input as necessary.
394
+
395
+ For platforms other that HTML/web based ones (like native mobile), the
396
+ equivalent native user input component should be used to achieve the equivalent
397
+ experience and client side validation as the HTML/web input types described
398
+ above.
399
+
242
400
### POST Request
243
401
244
402
The client must make an HTTP ` POST ` JSON request to the action URL with a body
0 commit comments