guard static method

Future<bool> guard(
  1. String ptr,
  2. List<LicenseUsecase> usecases, {
  3. List<String>? destinations = const [],
  4. String? origin,
  5. dynamic onPass()?,
  6. dynamic onFail(
    1. String
    )?,
})

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:
let pass = await `guard`(ptr: "example-ptr", usecases: [.attribution], destinations: ["https://example.com"])
if pass {
    // Perform the action allowed by the LicenseRecord.
}
  1. As a wrapper around a function:
`guard`(ptr: "example-ptr", usecases: [.attribution], destinations: ["https://example.com"], onPass: {
    // Perform the action allowed by the LicenseRecord.
}, onFail: { error in
    // Handle the error.
})
  • Parameters:

    • ptr: The pointer record for the asset. Used to locate the latest relevant LicenseRecord.
    • usecases: A list of usecases defining how the asset will be used.
    • destinations: A list of destinations defining where the asset will be used, often URLs.
    • onPass: A closure to execute automatically upon successfully resolving the LicenseRecord against the usecases and destinations.
    • onFail: A closure to execute automatically upon failure to resolve the LicenseRecord. Accepts an optional error message describing the reason for failure.
    • origin: An optional override of the default origin specified in the initializer.
  • Returns: true if the user has access, false otherwise.

Implementation

static Future<bool> guard(String ptr, List<LicenseUsecase> usecases,
    {List<String>? destinations = const [],
    String? origin,
    Function()? onPass,
    Function(String)? onFail}) async {
  return instance._core!.guard(ptr, usecases,
      destinations: destinations,
      origin: origin,
      onFail: onFail,
      onPass: onPass);
}