RTSDK
    Preparing search index...

    Class AssetFactory

    Factory for creating Asset instances. Use this factory to create or upload assets in the Topia platform.

    This factory should be instantiated once per application and reused across your codebase.

    asset, factory, create, upload, instantiate, topia

    // In your initialization file (e.g., utils/topiaInit.ts)
    import { Topia, AssetFactory } from "@rtsdk/topia";
    const topia = new Topia({ config });
    export const Asset = new AssetFactory(topia);

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    credentials: undefined | InteractiveCredentials
    jwt?: string
    requestOptions: object
    topia: Topia

    Methods

    • Instantiate a new instance of Asset class with the specified asset id.

      Parameters

      Returns Asset

      Returns a new Asset object with the asset id.

      This method creates a new Asset controller instance that can be used to interact with an existing asset. It does not create a new asset in the database.

      create, instantiate, asset, initialize, get, instance

      // Import the pre-initialized factory from your app's initialization file
      import { Asset } from "utils/topiaInit.ts";

      // Create an Asset instance with credentials
      const assetInstance = await Asset.create(assetId, {
      credentials: {
      interactiveNonce,
      interactivePublicKey,
      assetId,
      urlSlug,
      visitorId
      }
      });

      // Use the instance to interact with the asset
      await assetInstance.fetchAssetById();
    • Standardized error handler for all SDK operations.

      Parameters

      • __namedParameters: { error?: unknown; message?: string; params?: object; sdkMethod?: string }

      Returns {
          data: {};
          message: string;
          method: string;
          params: object;
          sdkMethod: undefined | string;
          stack: string;
          stackTrace: Error;
          status: number;
          success: boolean;
          url: string;
      }

      Standardized error object with properties: data, message, method, params, sdkMethod, stack, status, success, url

      This method processes errors from API calls and formats them consistently across the SDK. It extracts relevant error information including:

      • HTTP status codes and response data
      • Error messages from API responses
      • Stack traces for debugging
      • Request details (URL, method, parameters)

      All errors thrown by SDK methods flow through this handler to ensure consistent error format.

      error, exception, handler, debugging, api error, http error

    • Returns the configured Axios instance for making API calls to Topia's Public API.

      Returns AxiosInstance

      The configured Axios client instance with authentication headers.

      All HTTP requests to the Topia API should use this method to ensure proper authentication headers and base URL configuration are applied.

      api, axios, http, request, client, public api

    • Upload a new Asset to the Topia platform and return a new instance of Asset class.

      Parameters

      Returns Promise<Asset>

      Returns a new Asset object with the asset details.

      This method both creates a new asset in the database and returns an Asset controller instance. A valid API key with appropriate permissions is required.

      upload, create, new, asset, add, store

      // Import the pre-initialized factory from your app's initialization file
      import { Asset } from "utils/topiaInit.ts";

      // Prepare the asset payload
      const assetPayload = {
      assetName: "My Decorative Asset",
      bottomLayerURL: "https://example.com/bottom-layer.png",
      creatorTags: { "decorations": true },
      tagJson: "[{"label":"decorations","value":"decorations"}]",
      isPublic: true,
      topLayerURL: "https://example.com/top-layer.png"
      };

      // Upload the asset using your API key
      const asset = await Asset.upload(assetPayload, apiKey);

      // Access the new asset's properties
      console.log(asset.id);