Skip to content
| Marketplace
Sign in
Visual Studio Code>Other>Stryke CodeNew to Visual Studio Code? Get it now.
Stryke Code

Stryke Code

Stryke

|
80 installs
| (0) | Free
An extension to manage, upload, and execute your Stryke code.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Stryke Code

www.stryke.io

The Stryke Code extension allows you to work with your Stryke source code from your local VSC instance. Once you install Stryke Code, you will be able to retrieve and save scripts and templates as well as execute scripts and renter templates of any of your Stryke applications via VSC commands.

To configure which app instance the extension should connect to and setup any other parameters, you can use the Stryke settings found under user and workspace configurations (CMD + ,).

Stryke Code

Write code

Scripts are written in plain JavaScript (ECMAScript 2017) and run on a controlled Node environment. This environment provides a secure and fast way for your scripts to execute, with some handy Node features such as the ability to require some built in Node modules as well as some external ones. For a list of supported modules please check the Stryke Library reference.

Interacting with Stryke is done via the Stryke Library. Through the Stryke Library you can retrieve the current user, the record in context, perform CRUD and query operations. Documentation for the library can be found here: Stryke Library reference.

Resolve and Error functions

All scripts written for Stryke must be terminated via the execution of either a stryke.resolve() or stryke.error() functions. This allows for the execution of asynchronous code, such as any of the calls to retrieve or modify data in Stryke.

When stryke.resolve() is called the script execution is terminated successfully. Any argument passed to the resolve function will be returned by the script itself.

Alternatively, calling stryke.error()ends the script immediately with an error. An error message must be passed as an argument to describe the reason why the script terminated with an error.

Develop Templates

Templates are used to render the output of scripts (JSON) as rich HTML documents. Templates represent the HTML document in which the script result is injected. The JSON data returned by a script is injected in an HTML template via {{ }} syntax and follows the Mustache protocol.

Using Stryke Code you can develop the HTML templates for your application and render them locally to preview your work. The template that is being rendered locally can be injected with mock data following the data mocking process described below.

Commands

Stryke code offers the following set of commands which can be executed via the VSC command palette (CMD + Shift + P):

Commands

Login

This command authenticates you with Stryke using the username in the VSC configuration. When executed, it will prompt for a password in order to log in to Stryke. This command must be run before any other commands that interact with Stryke. It will maintain an open session with Stryke until the logout command is run.

Logout

Closes an open session with Stryke if the user has previously logged in.

Retrieve all Code

Retrieves all scripts and templates for the configured app instance (in the workspace configuration).

Files will be named after the record's name (eg: script name). If any files with the same names as any of the retrieved scripts exist in the local folder, they will be overwritten with the content coming from the server.

Retrieve Active File

Retrieves from Stryke the latest source code for the script or template in the active window.

The content of the source code will be overwritten with the content from the server.

Save Code

Saves the current (active in the VSC editor) script or template under the configured application instance in Stryke.

Script source code files are assumed to have a .js extension, while template files must have a .html extension.

The name of the local file will be used to identify the source code in Stryke (matching the name field).

In order to create a new script in Stryke, simply create a new file with a .js extension and call the save command. A new script with the same name as the file you just created will be saved to Stryke.

Similarly, to create a new template from VSC, create a new file with a .html xtension and run the save code command.

If the file already exists in Stryke, its content will be updated with the one in the local file.

Note that HTML templates are sanitized when saved to Stryke. The sanitized output will replace the content of the HTML template in the editor as soon as a template file is successfully saved in Stryke.

Execute Active Script

Executes the current (active in the VC editor) script in Stryke.

The script will be executed remotely on Stryke. The script record must exist in Stryke in order for it to be executed.

The script's result, execution times and log output can be viewed in the VSC output panel.

Render Active Template

Renders the current (active in the VC editor) HTML template locally. Stryke code will open a new window next to the HTML source code showing the HTML rendered. If a mock file is provided, the values from the mock data are injected where appropriate.

Once the command is executed, the template will be re-rendered everytime it is saved locally. This is independent from the autosave configuration, which if enabled will save the template file to Stryke when it is saved locally.

User impersonation

It is possible to execute a script on behalf of a specific user of the app instance. In order to do this, the username of this user needs to be set in the Stryke's configuration under the parameter "runas". Once the "runas" parameter is set, all scripts executed by the extension will be executed as if that user was running them. Code such as 'stryk.user' will return the details of the user being impersonated.

Mocking data for execution

When executing a script from VSC, it is possible to mock some of the data that is provided to the script at execution time.

Things such as the record in context to the script execution can be mocked by creating a mock data file in the same folder as the script file for which data is being mocked.

The mock data file must have the following naming:

[script file name].mock.json

The mock data file must contain a JSON with the following format

{ "mockData" : { "recordId" : "8ac3589b-63f9-4c97-8c4b-3f62ed7341b5" } }

Mocking options

  • Mock the record in context by ID

It is possible to specify an arbitrary record (which must exist in the app instance) that will be provided to the script at execution time as the record in context (through: stryke.data.record). This is done by using the record's ID using the following format:

{ "mockData" : { "recordId" : "8ac3589b-63f9-4c97-8c4b-3f62ed7341b5" } }

  • Mock request data

API and stand alone scripts can be passed JSON data in the request's payload when they are executed. This data is accessed via the Stryke library through: stryke.data.requestData.

Using the mockData, it is possible to provide this JSON data using the "requestData" field using the following format:

{ "mockData": { "requestData": { "test" : "some value" } } }

Render Template

Renders the HTML template that is currently active in the VSC editor in a side panel. The rendering is done locally and is refreshed everytime the HTML file is saved. Mock data can be injected in the template when it is rendered by defining a mock file as described below.

Mocking template data

Similarly to mocking data when executing a script, it is possible to mock data to be injected in a template that is rendered locally.

The mock data must be contained in a file with the following naming:

[template file name].mock.json

The format of the mock data must match the format of the JSON object that is returned by the script that is generating the data for the template. The content of the mock file should follow this format:

{ "mockData": { "templateData": { "test" : "some value" } } }

Configuration

Stryke Code requires setting of some configuration parameters. It is possible to set these parameters at both the User and Workspace level in VSC ((CMD + ,)).

It is assumed that a workspace contains files of a single app instance. It is possible to keep source code of multiple app instances in the same folder/workspace. However, only one app instance can be configured at a time for script CRUD and execution. Trying to retrieve, modify or execute a script that belongs to a different app instance than the one currently configured in the workspace settings will cause an error.

The following parameters are to be configured before starting to work with scripts.

Parameter Description Example
appInstanceName the name of the app instance to which the scripts belong to myapp
username the username of the Stryke user that will be used to login to Stryke. Note that this user must have access to the app instance with which we want to work me@myemail.com
runas an app instance user that will be impersonated when executing the scripts, so that they are executed on its behalf user@myapp.io
autosave saves the active file to Stryke automatically when it is saved to disk, without the need manually run the 'Save Code' command. true

Stryke Documentation

For more details and full documentation on how to develop scripts and templates, please visit the Stryke Docs page.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft