Function guard

  • Guard against an invalid LicenseRecord for a list of usecases and destinations.

    Use this method to verify that a non-expired LicenseRecord for the specified pointer record exists and permits the listed usecases and destinations.

    This method can be used in two ways:

    1. As an async traditional guard, returning a pass/fail boolean:
    const pass: boolean = await TikiSdk.guard("example-ptr", [TikiSdk.LicenseUsecase.attribution], ["https://example.com"]);
    if (pass) {
    // Perform the action allowed by the LicenseRecord.
    }
    1. As a wrapper around a function:
    TikiSdk.guard("example-ptr", [TikiSdk.LicenseUsecase.attribution], destinations: ["https://example.com"],
    () => {
    // Perform the action allowed by the LicenseRecord.
    },
    (reason) => {
    // Handle the error.
    });

    Parameters

    • ptr: string

      The pointer record for the asset. Used to locate the latest relevant LicenseRecord.

    • usecases: LicenseUsecase[]

      A list of usecases defining how the asset will be used.

    • Optional destinations: string[]

      A list of destinations defining where the asset will be used, often URLs.

    • Optional onPass: (() => void)

      A closure to execute automatically upon successfully resolving the LicenseRecord against the usecases and destinations.

        • (): void
        • Returns void

    • Optional onFail: ((reason) => void)

      A closure to execute automatically upon failure to resolve the LicenseRecord. Accepts an optional error message describing the reason for failure.

        • (reason): void
        • Parameters

          • reason: string

          Returns void

    • Optional origin: string

      An optional override of the default origin specified in initialize.

    Returns boolean