Skip to content

laylo/laylo

unversioned · 008fbbb1b367MIT

Skills for building with the Laylo API: set up and verify credentials, then answer questions about an account's drops, fans, and conversions with the Node SDK or plain HTTP.

@laylo.com/node

The official Node.js SDK for the Laylo public API.

npm version CI node license

Install

npm install @laylo.com/node
# or
pnpm add @laylo.com/node
# or
yarn add @laylo.com/node

Quickstart

import Laylo from "@laylo.com/node";

const laylo = new Laylo({
  userId: process.env.LAYLO_USER_ID,
  accessKey: process.env.LAYLO_ACCESS_KEY,
  secretKey: process.env.LAYLO_SECRET_KEY,
  apiKey: process.env.LAYLO_API_KEY,
});

await laylo.keys.verify();

const drops = await laylo.drops.list();
console.log(drops.map((drop) => drop.title));

Calling only your own account's data? The API key on its own is enough; see Using only an API key.

Using an AI assistant

This repo is also a plugin for AI coding assistants. It carries two Agent Skills that walk you through getting credentials into a .env and verifying them, help you choose between an API key and a creator id, and answer questions about an account ("how many SMS subscribers signed up in August?") by writing and running the call for you. Both ask before anything that writes fan data.

  • laylo-node uses this SDK.
  • laylo-api calls the HTTP API directly, for other languages or plain curl.

Installing the plugin gets you both; the assistant picks whichever fits the project.

Claude Code. Add the marketplace, then install the plugin:

claude plugin marketplace add Laylo/node
claude plugin install laylo@laylo-skills

Or from inside a session, run /plugin marketplace add Laylo/node and pick laylo from /plugin.

Codex. Add the marketplace, then install the plugin, and start a new thread:

codex plugin marketplace add Laylo/node
codex plugin add laylo@laylo-skills

Cursor. On a Teams or Enterprise plan, go to Dashboard → Plugins & MCPs → Team Marketplaces → Add Marketplace → Import from Repo and paste https://github.com/Laylo/node. On your own, clone the repo into Cursor's local plugins folder and run Developer: Reload Window:

git clone https://github.com/Laylo/node ~/.cursor/plugins/local/laylo

Anything else. The plugin follows the Agent Plugins layout, so tools that read it, such as GitHub Copilot and VS Code, can load this repo directly. For the skills on their own, npx skills add Laylo/node installs them into most assistants. skills/README.md covers the Claude desktop app, claude.ai, and copying the folders by hand.

Authentication

The SDK uses two kinds of credentials:

  • Integrator credentials — a userId, accessKey, and secretKey issued to your integration. The userId is the Laylo user id of the account the credentials were issued under. The SDK uses them to mint and refresh a bearer access token for you; you never handle the token directly.
  • Customer API key — the apiKey of the Laylo account you're acting on behalf of. Each customer generates their own under Settings → Integrations → API Keyring at laylo.com/settings?tab=Integrations and gives it to you. It's sent as the X-Api-Key header on every request.

Each falls back to an environment variable when omitted from the constructor: LAYLO_USER_ID, LAYLO_ACCESS_KEY, LAYLO_SECRET_KEY, and LAYLO_API_KEY. An integration acting for many customers needs the integrator credentials; a single account calling its own data can skip them and use only an API key.

Enterprise accounts have a third option for naming the customer. If the account you're acting on sits under your integration's own Laylo account, pass its user id as creatorId instead of collecting an API key from it. It's sent as the X-Creator-Id header, falls back to LAYLO_CREATOR_ID, and needs integrator credentials. Set one of apiKey or creatorId, not both — including in the environment, where having LAYLO_API_KEY and LAYLO_CREATOR_ID both set fails at construction rather than picking one. See Acting on accounts under your own.

import Laylo from "@laylo.com/node";

const laylo = new Laylo();

await laylo.keys.verify();

See developers.laylo.com/authentication for the full model.

Getting your keys

  1. Ask your Laylo account manager to turn on integrator access for your Laylo account. This is the one step you can't do yourself.
  2. Open laylo.com/settings?tab=Integrations and scroll to Integrator API Keys. The card shows your user ID; that's your userId.
  3. Create a key. The dialog shows your user ID, access key, and secret key together. Copy them into your .env now as LAYLO_USER_ID, LAYLO_ACCESS_KEY, and LAYLO_SECRET_KEY: the secret key is shown only once, and losing it means deleting the key and creating a new one.
  4. To test before you have a customer, generate a key in the API Keyring card on the same page and set it as LAYLO_API_KEY. Your integration then acts on your own Laylo account, so you can try it against your own drops and fans before onboarding anyone else.

Writes made this way are live. Integrator calls aren't limited by the key's permissions, so messages.sms.send texts your real fans, messages.segments texts or emails them, and fans.subscribe and conversions.events.track create real records. Stick to reads and dry runs, or send only to your own number, until you mean it.

Using only an API key

If you're a Laylo account calling your own data — a script, a backend for your own site — you don't need integrator credentials. Generate an API key at laylo.com/settings?tab=Integrations and pass it on its own, or set only LAYLO_API_KEY and call new Laylo():

import Laylo from "@laylo.com/node";

const laylo = new Laylo({ apiKey: process.env.LAYLO_API_KEY });

const drops = await laylo.drops.list();

The client works this way whenever none of userId, accessKey, and secretKey is set; setting some but not all of them still fails at construction. Naming any of the three in code, even as "", turns their environment variables off for all three, so new Laylo({ apiKey, userId: "" }) ignores a stray LAYLO_USER_ID. Passing them as undefined, as in the quickstart, counts as expecting integrator credentials: if none turn up in the environment either, construction fails rather than falling back to the API key alone. To act for several accounts this way, construct with one account's key and scope to the others with forCustomer(apiKey). Every request carries just the X-Api-Key header, with no access token. Compared with integrator credentials:

  • Requests are limited to 20 a minute per account by default; Laylo can raise the limit on a specific key, which then gets its own budget. Past that, a call throws RateLimitError, whose retryAfter says when to try again.
  • Only the key's own account can be acted on. creatorId isn't accepted — not in the constructor, LAYLO_CREATOR_ID, forCustomer, or a call's options — and throws LayloConfigurationError. Another customer's key still works through forCustomer(apiKey) or a call's apiKey.
  • customers.list() and auth.createToken() reject with LayloConfigurationError without sending a request, since there's no integrator roster to list or token to mint.
  • The key's own permissions apply. Writes (fans.subscribe, conversions.events.track, messages.sms.send, messages.segments.send, messages.segments.schedule) need "write"; everything else, including fans.isSubscribed and fans.isUnsubscribed, needs "read", except keys.verify(), which any valid key can call. The two are independent, so "write" doesn't grant "read". A key with no permissions stored can only read, and one stored with an empty list can't make any call but keys.verify(). A call the key isn't allowed to make throws PermissionError with a message such as This API key does not have the "write" permission.
  • Keys can't be granted "write" yet, so for now a client with only an API key is read-only: the three writes above throw PermissionError.

If you're building an integration that serves many customers, use integrator credentials instead.

Working with multiple customers

A single process can act for many Laylo accounts. There are three places to name the customer, in increasing order of precedence:

  1. The constructor's apiKey (or creatorId) — the default for every call this client makes.
  2. laylo.forCustomer(apiKey) — a view that shares the parent client's connections and access token but acts as a different customer. It also takes { apiKey } or { creatorId }.
  3. The trailing RequestOptions argument on any resource method — its apiKey or creatorId replaces the client's customer, for the one call.

A request handler serving several customers typically scopes per request:

import Laylo from "@laylo.com/node";

const laylo = new Laylo({
  userId: process.env.LAYLO_USER_ID,
  accessKey: process.env.LAYLO_ACCESS_KEY,
  secretKey: process.env.LAYLO_SECRET_KEY,
});

const handleRequest = async (customerApiKey: string) => {
  const customer = laylo.forCustomer(customerApiKey);
  return customer.drops.list();
};

await handleRequest("customer-api-key");

Acting on accounts under your own

If your integration was issued under an enterprise Laylo account, any account on that roster can be named by its Laylo user id rather than by an API key. It works at any depth of sub-account nesting, and your own account's id is accepted too. It's the same set of accounts you can switch between when you log in to Laylo on the web.

import Laylo from "@laylo.com/node";

const laylo = new Laylo({
  userId: process.env.LAYLO_USER_ID,
  accessKey: process.env.LAYLO_ACCESS_KEY,
  secretKey: process.env.LAYLO_SECRET_KEY,
});

const artist = laylo.forCustomer({ creatorId: "artist-user-id" });
const drops = await artist.drops.list();

An id outside your roster throws PermissionError. An id on your roster whose account no longer exists throws AuthenticationError, the same answer an API key gives when its account is gone. keys.verify() still works for a creator-id customer, but since there's no key to check it resolves with apiKeyStatus: "not_provided".

Resources

Every resource method's last argument is an optional RequestOptions for per-call overrides (auth.createToken is the one exception — it only accepts signal).

keys

  • keys.verify(options?) — checks that a customer API key is valid; the way to validate a key a customer just gave you before you store it. For a customer named by creatorId there is no key to check, so it confirms the account is on your roster and resolves with apiKeyStatus: "not_provided".

    import Laylo, { AuthenticationError } from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
    });
    
    try {
      await laylo.keys.verify({ apiKey: "untrusted-key" });
    } catch (error) {
      if (
        error instanceof AuthenticationError &&
        error.apiKeyStatus === "invalid"
      ) {
        console.log("reject the key");
      } else {
        throw error;
      }
    }
    

customers

  • customers.list(options?) — lists the accounts under your integration's own Laylo account. Each entry's id is the creatorId that forCustomer({ creatorId }) accepts, so one customer is enough to discover the rest. The list is scoped to your integration, not to the customer the client is acting as, but a customer must still be named like on every other call. It needs integrator credentials; a client with only an API key gets PermissionError.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const customers = await laylo.customers.list();
    for (const customer of customers) {
      const drops = await laylo
        .forCustomer({ creatorId: customer.id })
        .drops.list();
      console.log(customer.displayName, drops.length);
    }
    

drops

  • drops.list(options?) — lists the customer's active public drops.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const drops = await laylo.drops.list();
    for (const drop of drops) {
      console.log(drop.title, new Date(drop.createdAt));
    }
    

conversions

  • conversions.list(params?, options?) — lists the customer's conversion definitions, optionally filtered by action and/or relatedProductId.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const purchases = await laylo.conversions.list({
      action: ["TICKET_PURCHASE", "STORE_PURCHASE"],
    });
    
  • conversions.counts.list(params?, options?) — counts the customer's conversion events per action over a window, with a daily series for each, the way the dashboard's Fan Activity chart does. Filter by action and bound the window with startDate and endDate, which accept a Date or an ISO 8601 string carrying an explicit UTC offset. The window defaults to the last 28 days.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const report = await laylo.conversions.counts.list({
      action: ["TICKET_PURCHASE", "RSVP"],
      startDate: new Date("2026-08-01T00:00:00Z"),
      endDate: new Date(),
    });
    for (const { action, total } of report.counts) {
      console.log(action, total);
    }
    
  • conversions.events.track(event, options?) — tracks a conversion event for a fan. Repeated events with the same metadata.uniqueId are merged, so retrying is safe.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const { status, tracked } = await laylo.conversions.events.track({
      action: "TICKET_PURCHASE",
      name: "VIP ticket",
      timestamp: new Date(),
      metadata: { uniqueId: "order_123", currency: "USD", totalPrice: 59.5 },
      user: { email: "fan@example.com", emailMarketingConsent: true },
    });
    if (status === "failure") {
      console.log("queue for retry", tracked);
    }
    

fans

  • fans.isSubscribed(contact, options?) — checks whether a contact (an email or an E.164 phone number) currently subscribes to the customer. Pass an array of up to 500 emails or phone numbers to check them in one request; it resolves to a boolean[] in the same order.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const isSubscribed = await laylo.fans.isSubscribed({ phone: "+12025550100" });
    
    const phones = ["+12025550100", "+12025550101"];
    const answers = await laylo.fans.isSubscribed({ phone: phones });
    const subscribed = phones.filter((_, index) => answers[index]);
    
  • fans.isUnsubscribed(contact, options?) — checks whether a contact subscribed at some point and has since unsubscribed. Like isSubscribed, it takes an array of up to 500 emails or phone numbers and resolves to a boolean[] in the same order.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const isUnsubscribed = await laylo.fans.isUnsubscribed({
      email: "fan@example.com",
    });
    
  • fans.subscribe(fan, options?) — subscribes a fan to the customer by email, an E.164 phone, or both. Given both, each is subscribed and the two records are linked as the same person; the result carries a separate emailFanId and phoneFanId, and if only one subscribes, the other comes back in rejected. The fan's sign-up time is the time of the call. A blank email or phone throws rather than being skipped. Pass dropId to also RSVP them to one of the customer's drops. This is a write, so it isn't retried on a server error.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const { emailFanId, rsvp } = await laylo.fans.subscribe({
      email: "fan@example.com",
      dropId: "drop_123",
    });
    console.log(emailFanId, rsvp?.status);
    
  • fans.segments.count(filters, options?) — counts the customer's fans matching a segment, like the dashboard's audience builder. signUpType ("sms" or "email") is required; narrow further by drops purchased, conversions, locations, and sign-up time, where signedUpAfter and signedUpBefore accept a Date or an ISO 8601 string carrying an explicit UTC offset. An empty array is left out of the request, so it switches that filter off rather than matching no fan.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const smsFans = await laylo.fans.segments.count({
      signUpType: "sms",
      dropIds: ["drop_123"],
      locations: [{ country: "US" }],
      signedUpAfter: new Date("2026-01-01T00:00:00Z"),
    });
    

messages

  • messages.sms.send(sms, options?) — texts message from the customer's Laylo number to to, one E.164 phone number or an array of up to 200. Only numbers that currently subscribe to the customer get the text. It resolves to { queued, skipped }, where skipped lists each recipient that wasn't texted by its index in to, with a reason of "not_subscribed", "duplicate", or "queue_failed". An invalid number rejects the whole request. This is a write, so it isn't retried on a server error.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const to = ["+12025550100", "+12025550101"];
    const { queued, skipped } = await laylo.messages.sms.send({
      message: "Presale starts now: https://laylo.com/example",
      to,
    });
    for (const { index, reason } of skipped) {
      console.log(to[index], reason);
    }
    
  • messages.segments.send(input, options?) — sends message to every fan in segment within the next few minutes. The segment takes the same filters as fans.segments.count. An "sms" segment is texted to fans currently subscribed by SMS. An "email" segment also needs email: { subject, ctaUrl?, ctaText? }: Laylo lays the email out from message, its links become buttons, and ctaUrl with ctaText adds a main button. timezone is the IANA zone the message is written in, one of the zones in SegmentMessageTimezone. Recipients are worked out when the message sends. It resolves to { id, note, sendAt, dryRun, estimate }, with sendAt in UTC and estimate giving the recipients, credits, and costUsd from the fans who match right now. costUsd doesn't subtract free or prepaid credits, and fans with both a phone number and an email address are counted under emails as well as a text channel, so it errs high. Pass dryRun: true to get that estimate without sending anything; id is then null.

  • messages.segments.schedule(input, options?) — the same, sent at sendAt: a local date and time in timezone with no offset, like "2026-11-20T19:00", at least 5 minutes and at most 2 years away. It's rounded up to the next five-minute mark.

    Both are writes, so they aren't retried on a server error or a dropped connection unless you pass an idempotencyKey in the options. With one, a repeat within 24 hours returns the first response instead of sending the message twice, and the SDK retries server errors and dropped connections itself. A timeout isn't retried; call again with the same key. A ConflictError with a key means the first attempt is still running and will probably send, so don't retry under a new key. If that attempt never finishes, the key frees up after a minute and a call with it sends again. A dry run ignores the key, so the real send can reuse it, and is retried like a read. signedUpAfter and signedUpBefore can't be combined when messaging.

    import Laylo, { type ScheduleSegmentMessageInput } from "@laylo.com/node";
    
    const laylo = new Laylo({
      userId: process.env.LAYLO_USER_ID,
      accessKey: process.env.LAYLO_ACCESS_KEY,
      secretKey: process.env.LAYLO_SECRET_KEY,
      apiKey: process.env.LAYLO_API_KEY,
    });
    
    const message: ScheduleSegmentMessageInput = {
      message: "Tickets go on sale tomorrow: https://laylo.com/example",
      segment: { signUpType: "sms", dropIds: ["drop_123"] },
      sendAt: "2026-11-20T19:00",
      timezone: "America/New_York",
    };
    
    const { estimate } = await laylo.messages.segments.schedule({
      ...message,
      dryRun: true,
    });
    console.log(
      `About ${String(estimate.recipients)} fans, $${String(estimate.costUsd)}`,
    );
    console.log(estimate.disclaimer);
    
    const { sendAt } = await laylo.messages.segments.schedule(message, {
      idempotencyKey: "tour-onsale-2026-11-20",
    });
    
    await laylo.messages.segments.schedule(
      {
        ...message,
        segment: { signUpType: "email", dropIds: ["drop_123"] },
        email: {
          subject: "Tickets go on sale tomorrow",
          ctaUrl: "https://tickets.example.com/tour",
          ctaText: "Get Tickets",
        },
      },
      { idempotencyKey: "tour-onsale-email-2026-11-20" },
    );
    

The SDK mints and refreshes access tokens for you, but laylo.auth.createToken() is available if you need a raw bearer token to call the API outside the SDK. It needs integrator credentials; with only an API key, send the key as X-Api-Key and no token.

billing

  • billing.creditUsage.get(params?, options?) — the message credits the customer used over a window of UTC days, per channel, with a series bucketed by interval ("day", the default, "week", or "month"). startDate and endDate are inclusive and take a UTC day as a "YYYY-MM-DD" string, not a Date. endDate defaults to today and startDate to the first of endDate's month, and the window can span at most 366 days. Every bucket in the window is in series, empty ones included. count is billed units, not messages: most texts count once per segment. Credits are priced at the customer's current rates, and costUsd is credits / creditsPerDollar rounded to the cent. This is usage, not an invoice: the window isn't tied to the billing period, and prepaid and free credits aren't applied.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({ apiKey: process.env.LAYLO_API_KEY });
    
    const usage = await laylo.billing.creditUsage.get({
      startDate: "2026-09-01",
      endDate: "2026-09-30",
      interval: "week",
    });
    for (const week of usage.series) {
      console.log(week.start, week.credits, week.costUsd);
    }
    console.log(usage.total.channels.domesticSms.count);
    
  • billing.creditUsage.getForProducts(params, options?) — the same report for specific drops and segment messages, summed together. Pass 1 to 50 distinct ids as productIds; repeats are sent once, and the report lists the ids it summed. A drop includes its sub-drops, and a product named twice counts once. The report is summed, so call once per product for a per-product breakdown. A product that isn't the customer's throws NotFoundError, and drops that expand to more than 200 products with their sub-drops throw BadRequestError.

    import Laylo from "@laylo.com/node";
    
    const laylo = new Laylo({ apiKey: process.env.LAYLO_API_KEY });
    
    const usage = await laylo.billing.creditUsage.getForProducts({
      productIds: ["drop_123", "message_456"],
      interval: "month",
    });
    console.log(usage.productIds, usage.total.credits);
    

Errors

Every error the SDK throws is a subclass of LayloError. A failed API response throws LayloAPIError, whose subclass is picked from the HTTP status:

ClassStatusWhen
BadRequestError400The request was malformed or failed validation.
AuthenticationError401Credentials are missing, expired, or invalid.
PermissionError403Authenticated, but not allowed to perform this action.
NotFoundError404The resource does not exist or isn't visible to you.
MethodNotAllowedError405The HTTP method isn't supported on this route.
ConflictError409The request conflicts with the resource's current state.
RateLimitError429Too many requests; see retryAfter.
NotImplementedError501The endpoint exists but isn't available yet.
ServerError5xxSomething went wrong on Laylo's side.

Two more LayloError subclasses don't carry a status because they're never an API response: LayloConnectionError (the request never got a response) and LayloTimeoutError (the request exceeded its timeout). A fourth, LayloConfigurationError, is thrown before any request is made, for a misconfigured client or call.

import Laylo, { LayloAPIError, RateLimitError } from "@laylo.com/node";

const laylo = new Laylo({
  userId: process.env.LAYLO_USER_ID,
  accessKey: process.env.LAYLO_ACCESS_KEY,
  secretKey: process.env.LAYLO_SECRET_KEY,
  apiKey: process.env.LAYLO_API_KEY,
});

try {
  await laylo.drops.list();
} catch (error) {
  if (error instanceof RateLimitError) {
    console.log(`retry after ${String(error.retryAfter)}s`);
  } else if (error instanceof LayloAPIError) {
    console.error(error.status, error.code, error.message);
  } else {
    throw error;
  }
}

Retries & timeouts

A response with status 408, 429, 500, 502, 503, or 504 is retried automatically with exponential backoff, up to DEFAULT_MAX_RETRIES (2) times. A 429 is retried regardless of method; the other statuses are only retried for idempotent requests — reads, and writes the SDK itself marks idempotent, such as fans.isSubscribed and fans.isUnsubscribed, and messages.segments calls given an idempotencyKey (which also retry a 409 from an attempt that hasn't finished). A non-idempotent write like conversions.events.track or fans.subscribe is not replayed on a 5xx, since the server may already have applied it. Each request also has a DEFAULT_TIMEOUT_MS (30,000ms) timeout.

maxRetries and the default timeoutMs are set once, on the client. Per call, you can override the timeout, disable retries for just that call with retry: false, or abort it with an AbortSignal:

import Laylo from "@laylo.com/node";

const laylo = new Laylo({
  userId: process.env.LAYLO_USER_ID,
  accessKey: process.env.LAYLO_ACCESS_KEY,
  secretKey: process.env.LAYLO_SECRET_KEY,
  apiKey: process.env.LAYLO_API_KEY,
  maxRetries: 5,
  timeoutMs: 10_000,
});

const controller = new AbortController();
await laylo.drops.list({
  timeoutMs: 5_000,
  retry: false,
  signal: controller.signal,
});

TypeScript

Import types alongside the client:

import Laylo, { type Drop, type Conversion } from "@laylo.com/node";

const laylo = new Laylo({
  userId: process.env.LAYLO_USER_ID,
  accessKey: process.env.LAYLO_ACCESS_KEY,
  secretKey: process.env.LAYLO_SECRET_KEY,
  apiKey: process.env.LAYLO_API_KEY,
});

const describeDrop = (drop: Drop): string => drop.title;
const drops: Drop[] = await laylo.drops.list();
console.log(drops.map(describeDrop));

const purchases: Conversion[] = await laylo.conversions.list({
  action: "TICKET_PURCHASE",
});
console.log(purchases.map((conversion) => conversion.name));

ConversionAction is a string literal union, so your editor autocompletes the valid actions wherever one is expected.

Both module systems are supported:

import Laylo from "@laylo.com/node";
const { Laylo } = require("@laylo.com/node");

Requirements

  • Node.js 20 or later

Support

License

MIT