Services class
📖 Description
The services class implements the connection between a client and the Studio back-end. To create a new instance, use the static init
function.
🆕 constructor
Creates a new services instance with the specified properties.
The token of a form can be obtained from the share panel of the Studio application. Open your form in the Studio and then click the Share
button.
Signature
constructor(
properties: {
token?: string;
url?: string;
filestoreUrl?: string
}
): Services
Properties
Name | Type | Optional | Description |
---|---|---|---|
token | string | No | Specifies the token. |
url | string | Yes | Specifies the URL of the server. If omitted the default URL will be used. |
filestoreUrl | string | Yes | Specifies the URL of the filestore service (used for file uploads). If omitted the default URL will be used. |
Return value
Returns a reference to the new services instance.
📌 Statics
🔧 init
Initializes a new services instance with the specified properties.
The token of a form can be obtained from the share panel of the Studio application. Open your form in the Studio and then click the Share
button.
Signature
init(
properties: {
token?: string;
url?: string;
filestoreUrl?: string
}
): Services
Properties
Name | Type | Optional | Description |
---|---|---|---|
token | string | No | Specifies the token. |
url | string | Yes | Specifies the URL of the server. If omitted the default URL will be used. |
filestoreUrl | string | Yes | Specifies the URL of the filestore service (used for file uploads). If omitted the default URL will be used. |
Return value
Returns a reference to the new services instance.
Example
import { run } from "tripetto-runner-autoscroll";
import { Services } from "tripetto-services";
const { definition, onSubmit } = Services.init({
// You can obtain the token of a form in the share panel of the Studio
token: "a-valid-tripetto-token"
});
run({
definition,
onSubmit
});
🗃️ Fields
🏷️ attachments
Retrieves the attachments object that holds the endpoints for file upload store.
For more information how this field is used in a runner, take a look at the attachments
property of the Autoscroll stock runner.
Type
🏷️ definition
Fetches the form definition from the server. Returns a promise that resolves with the form definition (or undefined
if the definition was not found).
Type
Promise<IDefinition | undefined>
🏷️ l10n
Fetches the form localization and translation data from the server. Returns a promise that resolves with the data (or undefined
if no data was found).
For more information how this field is used in a runner, take a look at the l10n
property of the Autoscroll stock runner.
Type
Promise<TL10n | undefined>
🏷️ locale
Retrieves the locale function used to retrieve locale data.
For more information how this field is used in a runner, take a look at the locale
property of the Autoscroll stock runner.
Type
(locale: "auto" | string) => Promise<L10n.ILocale | undefined>
🏷️ snapshot
Fetches the form snapshot from the server. Returns a promise that resolves with the form snapshot (or undefined
if no snapshot was found).
Type
Promise<ISnapshot | undefined>
🏷️ styles
Fetches the form styles from the server. Returns a promise that resolves with the form styles (or undefined
if no styles were found).
The form styles object differs per runner. For example, when the Autoscroll stock runner is used, this property returns an IAutoscrollStyles
object.
Type
Promise<TStyles | undefined>
🏷️ translations
Retrieves the translation function used to retrieve translation data.
For more information how this field is used in a runner, take a look at the translations
property of the Autoscroll stock runner.
Type
(language: "auto" | string, context: string) => Promise<L10n.TTranslation | L10n.TTranslation[] | undefined>
📢 Events
🏷️ onPause
Retrieves the pause function that is invoked when a form is paused.
Signature
{
recipe: "email";
onPause: (
emailAddress: string,
snapshot: ISnapshot,
language: string,
locale: string,
namespace: string
) => Promise<void>;
}
Parameters
Name | Type | Optional | Description |
---|---|---|---|
emailAddress | string | No | Contains the email address. |
snapshot | ISnapshot | No | Contains the snapshot data. |
language | string | No | Contains the language used in the runner (default is en ). |
locale | string | No | Contains the locale identifier used in the runner (default is en ). |
namespace | string | No | Contains the namespace identifier for the runner. |
Return value
Returns a Promise
that resolves in case the pause succeeded or rejects in case of an error.
🏷️ onReload
Retrieves the reload function that is invoked when a form definition should reload from the server.
Signature
() => Promise<IDefinition>
Return value
Returns a Promise
that resolves with the IDefinition
.
🏷️ onSubmit
Retrieves the submit function that is invoked when a form response is submitted to the server.
Signature
(instance: Instance, language: string, locale: string, namespace: string) =>
Promise<string | undefined>
Parameters
Name | Type | Optional | Description |
---|---|---|---|
instance | Instance | No | Reference to the runner instance. |
language | string | No | Contains the language used in the runner (default is en ). |
locale | string | No | Contains the locale identifier used in the runner (default is en ). |
namespace | string | No | Contains the namespace identifier for the runner. |
Return value
Returns a Promise
that resolves with an optional reference string (in case it succeeds) or rejects (in case of an error).