Skip to main content
POST
/
apps
/
functions
/
test
Test a Function
curl --request POST \
  --url https://api.launchmystore.io/apps/functions/test \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "code": "<string>",
  "type": "<string>",
  "input": {},
  "timeoutMs": 123
}
'
{
  "data.success": true,
  "data.output": {},
  "data.executionTimeMs": 123,
  "data.compileTimeMs": 123,
  "data.sourceSize": 123,
  "data.wasmSize": 123,
  "data.logs": [
    {}
  ],
  "data.error": "<string>",
  "data.validationError": {}
}

Documentation Index

Fetch the complete documentation index at: https://docs.launchmystore.io/llms.txt

Use this file to discover all available pages before exploring further.

POST /apps/functions/test compiles a JavaScript function to WASM with Javy and runs it in the same sandboxed worker the production dispatcher uses — same per-type timeout, same output validator, same console.log forwarding — but nothing is persisted. No AppFunctionRuns row, no state change on any installation. Use it for:
  • Quick iteration in the developer dashboard’s “Try it” editor.
  • CI smoke-tests that compile and exercise a function against a known fixture.
  • Schema-conformance checks against the type-specific output validator.
Auth: merchant JWT (@Auth(MERCHANT)). The sandbox is rate-limited per calling account; abusive callers (excessive compile failures, sustained timeouts) are throttled.

Request

code
string
required
JavaScript source. Must export a top-level run (or main) function that accepts the input object and returns the type-specific output shape. Max 64 KB of source.
type
string
required
Function type — determines the input shape that will be passed and the output validator that will check the return value. One of: discount, shipping_rate, payment_customization, delivery_customization, order_validation, cart_transform, fulfillment_constraints, local_pickup_options, pickup_point_options.
input
object
required
Test input passed to run(input). Should match the input contract for the function type — see Function input fields.
timeoutMs
integer
Execution timeout in ms. Server-clamped to the per-type cap below (range: 50–5000). Omit to use the per-type default.

Per-type timeouts

Function typeDefault timeoutHard cap
discount500ms500ms
payment_customization500ms500ms
order_validation1000ms1000ms
cart_transform1000ms1000ms
delivery_customization1000ms1000ms
fulfillment_constraints1000ms1000ms
local_pickup_options1500ms1500ms
shipping_rate2000ms2000ms
pickup_point_options2000ms2000ms
Memory cap is 128 MB per execution. Output is capped at 20 KB serialized — larger outputs fail validation. See Functions overview for the full runtime spec.

Example: discount

curl -X POST "https://api.launchmystore.io/apps/functions/test" \
  -H "Authorization: Bearer <MERCHANT_JWT>" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "discount",
    "code": "function run(input) { if (input.cart.cost.subtotalAmount.amount >= 50) { return { discounts: [{ targets: [{ orderSubtotal: {} }], value: { percentage: { value: 10 } }, message: \"10% off $50+\" }] }; } return { discounts: [] }; }",
    "input": {
      "cart": {
        "cost": { "subtotalAmount": { "amount": 75, "currencyCode": "USD" } },
        "lines": [
          { "id": "line_1", "quantity": 3, "cost": { "amountPerQuantity": { "amount": 25, "currencyCode": "USD" } } }
        ]
      }
    }
  }'

Response

The response is always 200 OK — the function-execution outcome is encoded in the data body (success: true/false). Only auth / compile / quota errors surface as non-200.
data.success
boolean
true when the function ran AND its output passed validation.
data.output
object
The function’s return value, after validator normalization. null on hard failure.
data.executionTimeMs
integer
Wall-clock execution time inside the WASM worker.
data.compileTimeMs
integer
Time spent compiling source → WASM (typically 80-300ms).
data.sourceSize
integer
Source bytes after trimming.
data.wasmSize
integer
Compiled WASM bytes (~3 KB in dynamic mode + shared provider).
data.logs
array
Lines emitted by console.log inside the function (truncated at 32 lines).
data.error
string
Runtime error message when success: false. null otherwise.
data.validationError
object
Output validator error (when the function returned but its shape was wrong). null otherwise.

Example success

{
  "status": 200,
  "type": "success",
  "data": {
    "success": true,
    "output": {
      "discounts": [
        {
          "targets": [{ "orderSubtotal": {} }],
          "value": { "percentage": { "value": 10 } },
          "message": "10% off $50+"
        }
      ]
    },
    "executionTimeMs": 4,
    "compileTimeMs": 142,
    "sourceSize": 247,
    "wasmSize": 3014,
    "logs": []
  }
}

Example timeout

{
  "status": 200,
  "type": "success",
  "data": {
    "success": false,
    "error": "Function execution exceeded 500ms timeout",
    "executionTimeMs": 500,
    "compileTimeMs": 156,
    "output": null,
    "logs": ["starting expensive loop"]
  }
}

Example validation error

{
  "status": 200,
  "data": {
    "success": false,
    "error": "Output validation failed",
    "validationError": {
      "path": "discounts[0].value",
      "message": "exactly one of `percentage` or `fixedAmount` must be set"
    },
    "output": {
      "discounts": [{ "targets": [{ "orderSubtotal": {} }], "value": {} }]
    },
    "executionTimeMs": 3,
    "compileTimeMs": 138
  }
}

Error codes (non-200)

CodeDescription
400Unknown type — must be one of the nine FunctionType values.
400Compile failed (syntax error). data.message contains the Javy compiler error.
400code larger than 64 KB.
401Missing or invalid merchant JWT.
429Sandbox rate limit hit. Wait and retry.
503Sandbox compiler not available (Javy not installed on this host).