@ptkl/sdk - v1.3.4
    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

    Properties

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

    Methods

    • Execute aggregate pipeline with optional streaming support

      Returns a chainable object that allows both buffered and streaming modes. Call .onData() to enable streaming mode, or await directly for buffered mode.

      Parameters

      Returns AggregateChainable

      Chainable object with streaming methods and Promise interface

      // Buffered response (default, up to 5K documents)
      const result = await component.aggregate([{ $match: { status: 'active' } }]);
      console.log(result.data); // All results at once

      // Streaming response (up to 25K documents)
      await component.aggregate([{ $match: { status: 'active' } }])
      .onData((doc) => console.log('Received:', doc))
      .onError((err) => console.error('Error:', err))
      .onEnd(() => console.log('Stream complete'));
    • Concurrent update model by uuid with optimistic locking

      Uses version-based concurrency control — the update will fail with a conflict error if the document has been modified since the provided version. Supports inline update operators in the data payload.

      Parameters

      • uuid: string

        The uuid of the model

      • version: number

        The expected version of the model

      • data: Record<string, any>

        Fields to update, optionally including update operators

      • options: UpdateOptions

        Update options

      Returns Promise<AxiosResponse<any, any>>

      The updated model

      await component.concurrentUpdate(uuid, model.__version__, {
      status: "processed",
      $inc: { retry_count: 1 }
      }, opts)
    • Parameters

      • model: Record<string, any>

      Returns Promise<AxiosResponse<any, any>>

    • Create many models

      Parameters

      Returns Promise<AxiosResponse<any, any>>

    • Parameters

      • uuid: string

      Returns Promise<AxiosResponse<any, any>>

    • Delete an extension from the component

      Parameters

      • name: string

        The name of the extension to delete

      • version: string

        The component version

      Returns Promise<AxiosResponse<any, any>>

      Updated component settings

      await component.deleteExtension('shipping_tracker', '0.1.0')
      
    • Delete a policy from the component

      Parameters

      • name: string

        The name of the policy to delete

      • version: string

        The component version

      Returns Promise<AxiosResponse<any, any>>

      Updated component settings

      await component.deletePolicy('restrict_email', '0.1.0')
      
    • Find method to search for models

      Parameters

      • filters: FindParams

        The filters to apply to the search

      • Optionalopts: FindOptions

        The options to apply to the search

      Returns Promise<AxiosResponse<FindResponse, any>>

      • The result of the search
      platform.component(name).find({
      currentPage: 1,
      perPage: 10,
      })

      // advanced search
      platform.component(name).find({
      $adv: {
      name: "John Doe",
      }
      )
    • FindOne method to search for a single model

      Parameters

      Returns Promise<null | Model>

      • The result of the search
      platform.component(name).findOne({
      name: "John Doe",
      })
    • Parameters

      • name: string
      • input: any

      Returns Promise<AxiosResponse<any, any>>

    • Get model by uuid

      Parameters

      • uuid: string

        string - The uuid of the model

      Returns Promise<AxiosResponse<Model, any>>

      (Promise)

    • Get a single extension by name from the component

      Parameters

      • name: string

        The name of the extension to retrieve

      • version: string

        The component version

      Returns Promise<AxiosResponse<any, any>>

      The extension object

      const extension = await component.getExtension('shipping_tracker', '0.1.0')
      
    • Get a single policy by name from the component

      Parameters

      • name: string

        The name of the policy to retrieve

      • version: string

        The component version

      Returns Promise<AxiosResponse<any, any>>

      The policy object

      const policy = await component.getPolicy('restrict_email', '0.1.0')
      
    • Install a new extension on the component

      Parameters

      • extension: Extension

        The extension definition to install

      • version: string

        The component version to install the extension on

      Returns Promise<AxiosResponse<any, any>>

      Updated component settings

      await component.installExtension({
      name: 'shipping_tracker',
      is_active: true,
      fields: [...],
      config: { api_key: 'key' }
      }, '0.1.0')
    • Install a new policy on the component

      Parameters

      • policy: Policy

        The policy definition to install

      • version: string

        The component version to install the policy on

      Returns Promise<AxiosResponse<any, any>>

      Updated component settings

      await component.installPolicy({
      type: 'field_access',
      name: 'restrict_email',
      enabled: true,
      priority: 1,
      config: { fields: ['email'], actions: ['see'], roles: ['role-uuid'] }
      }, '0.1.0')
    • Modify models by filters

      Updates all models matching the given filters. Supports inline update operators in the data payload for granular operations.

      Parameters

      • filters: Record<string, any>

        Query filters to match models

      • data: Record<string, any>

        Fields to update, optionally including update operators

      • options: ModifyOptions

        Modify options (e.g. upsert)

      Returns Promise<AxiosResponse<any, any>>

      The modified models

      await component.modify(
      { status: "active" },
      { $inc: { impression_count: 1 }, $addToSet: { viewers: "user-1" } },
      { upsert: false }
      )
    • Parameters

      • version: string
      • env: string

      Returns Promise<AxiosResponse<any, any>>

    • Parameters

      • uuid: string

      Returns Promise<AxiosResponse<any, any>>

    • Parameters

      • settings: any
      • version: string

      Returns Promise<AxiosResponse<any, any>>

    • Parameters

      • version: string
      • sdkVersion: string
      • engine: string
      • dist: Record<string, string>

      Returns Promise<any>

    • Parameters

      • client: AxiosInstance

      Returns default

    • Returns Promise<AxiosResponse<any, any>>

    • Parameters

      • version: string

      Returns Promise<AxiosResponse<any, any>>

    • Update model by uuid

      Regular fields in data are applied via $set. You can include MongoDB update operators (prefixed with $) directly in the data object for granular updates like incrementing, pushing to arrays, etc.

      Parameters

      • uuid: string

        The uuid of the model to update

      • data: Record<string, any>

        Fields to update, optionally including update operators

      • options: UpdateOptions

        Update options

      Returns Promise<AxiosResponse<any, any>>

      The updated model

      // Simple update (backwards compatible)
      await component.update(uuid, { name: "John" }, opts)

      // With update operators
      await component.update(uuid, {
      name: "John",
      $inc: { login_count: 1 },
      $push: { tags: "verified" },
      $addToSet: { roles: "admin" }
      }, opts)
    • Update an existing extension on the component

      Parameters

      • name: string

        The name of the extension to update

      • version: string

        The component version

      • data: Partial<Extension>

        Partial extension data to update

      Returns Promise<AxiosResponse<any, any>>

      Updated component settings

      await component.updateExtension('shipping_tracker', '0.1.0', {
      is_active: false,
      config: { api_key: 'new-key' }
      })
    • Update many models

      Parameters

      Returns Promise<AxiosResponse<any, any>>

    • Update an existing policy on the component

      Parameters

      • name: string

        The name of the policy to update

      • version: string

        The component version

      • data: Partial<Policy>

        Partial policy data to update

      Returns Promise<AxiosResponse<any, any>>

      Updated component settings

      await component.updatePolicy('restrict_email', '0.1.0', {
      enabled: false,
      priority: 2
      })
    • Parameters

      • event: string
      • input: any

      Returns Promise<AxiosResponse<any, any>>