guard static method
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:
- 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.
}
- 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);
}