@ptkl/sdk - v1.18.0
    Preparing search index...

    Base client for the platform API Classes that extend PlatformBaseClient have intentins of only working in platform context

    PlatformBaseClient

    The axios instance to use for the client

    // if sdk is used in the forge app that is running in the platform context
    const utils = new ComponentUtils()
    // this won't work outside of platform context because client needs authtorization to communicate with the API.

    Hierarchy (View Summary)

    Index

    Constructors

    • Parameters

      • Optionaloptions: { env?: string; host?: string; token?: string }

      Returns default

    Properties

    client: AxiosInstance
    env: null | string = null
    host: null | string = null
    token: null | string = null

    Methods

    • Set a single variable, preserving the rest.

      A read-modify-write over a replace-everything PATCH, so concurrent writers can lose each other's updates. Prefer updateVariables when setting more than one key.

      Parameters

      • key: string
      • value: any

      Returns Promise<any>

      await platform.forge().addVariable('WEBHOOK_URL', '...')
      await platform.forge().addVariable('storefront', 'WEBHOOK_URL', '...')
    • Set a single variable, preserving the rest.

      A read-modify-write over a replace-everything PATCH, so concurrent writers can lose each other's updates. Prefer updateVariables when setting more than one key.

      Parameters

      • ref: string
      • key: string
      • value: any

      Returns Promise<any>

      await platform.forge().addVariable('WEBHOOK_URL', '...')
      await platform.forge().addVariable('storefront', 'WEBHOOK_URL', '...')
    • Parameters

      • buffer: Buffer

      Returns Promise<any>

    • Read variables for the current environment (X-Project-Env, defaults to dev).

      With no argument this returns the CALLING APP's own variables and needs no permission at all. With a ref it reads that app's variables and needs manage forge.

      Parameters

      • Optionalref: string

        App uuid, name or tag. Omit for the current app.

      Returns Promise<any>

      const mine = await platform.forge().getVariables()
      const other = await platform.forge().getVariables('storefront')
    • Returns Promise<any>

    • Returns Promise<any>

    • Parameters

      • ref: string

      Returns Promise<any>

    • Parameters

      • ref: string
      • version: string

      Returns Promise<any>

    • Run a Forge service: runService(target, body?, { query?, headers? }). Mirrors axios.post(url, data, config) — the 2nd arg is the request payload.

      target is either:

      • a bare service name — runs that service on the CURRENT app; or
      • a service PRN prn:forge:{ref}:service/{name} — runs it on ANOTHER app, where ref is the app's name or uuid. A name is resolved by the runtime deterministically (marketplace → custom); use the uuid to pin a specific app. This is the addressing to use where there's no ambient "current app" — e.g. a workflow, which has no per-install uuid to hardcode.

      body is sent as the POST body; options.query / options.headers are optional.

      The current app's uuid (bare-name form) is resolved automatically from the platform context (FORGE_APP_UUID for public views, forge_app_uuid in sessionStorage for platform views), so app code never needs its own uuid.

      Resolving the app does NOT grant access. Execution is still authorized against the caller's permissions — for a platform-access service the caller must hold service::{name} forge::{appUuid}; public-access services require none. An app's own runtime token is implicitly granted this for all of its own services.

      Parameters

      • target: string
      • Optionalbody: any
      • Optionaloptions: { headers?: Record<string, string>; query?: Record<string, string> }

      Returns Promise<any>

    • Parameters

      • client: AxiosInstance

      Returns default

    • Replace the variable set for the current environment.

      This REPLACES the whole set for that environment — keys absent from variables are removed. The other environment is left untouched.

      The self form needs manage_variables forge, which only ever writes the calling app. Targeting another app by ref needs manage forge.

      Parameters

      Returns Promise<any>

      await platform.forge().updateVariables({ WEBHOOK_URL: '...' })
      await platform.forge().updateVariables('storefront', { WEBHOOK_URL: '...' })
    • Replace the variable set for the current environment.

      This REPLACES the whole set for that environment — keys absent from variables are removed. The other environment is left untouched.

      The self form needs manage_variables forge, which only ever writes the calling app. Targeting another app by ref needs manage forge.

      Parameters

      Returns Promise<any>

      await platform.forge().updateVariables({ WEBHOOK_URL: '...' })
      await platform.forge().updateVariables('storefront', { WEBHOOK_URL: '...' })