Return the annotations of each given policy, grouped by policy ID. It is
the loss-free companion to annotationsMap. Unknown policy IDs are
silently skipped.
policy_ids - List of policy IDs whose annotations should be returned
grouped by policy ID. Typically result.response.diagnostics.reason from
an authorization result.const byPolicy = cedarling.annotationsByPolicy(result.response.diagnostics.reason);
// { "5": { redirect: "/upgrade", tier: "premium" } }
Merge the annotations (@key("value")) of the given policies into a single object.
Intended for resolving the determining policies of an authorization decision:
pass result.response.diagnostics.reason.
Lossy: if the same annotation key appears on several policies, one value wins
arbitrarily. Use annotationValues / annotationsByPolicy when duplicates
matter. Unknown policy IDs are silently skipped.
policy_ids - List of policy IDs whose annotations should be merged into
a single object. Typically result.response.diagnostics.reason from an
authorization result.const annotations = cedarling.annotationsMap(result.response.diagnostics.reason);
// { redirect: "/upgrade", tier: "premium" }
Collect every value of the annotation key across the given policies,
preserving duplicates. Unknown policy IDs are silently skipped.
policy_ids - List of policy IDs to search. Typically
result.response.diagnostics.reason from an authorization result.key - The annotation key to collect values for (e.g. "redirect").const redirects = cedarling.annotationValues(
result.response.diagnostics.reason,
"redirect",
);
// ["/upgrade"]
Authorize multi-issuer request. Makes authorization decision based on multiple JWT tokens from different issuers.
request - JSON string representation of [AuthorizeMultiIssuerRequest].const result = await cedarling.authorizeMultiIssuer(JSON.stringify(request));
Authorize a batch of multi-issuer requests against one shared token set.
Tokens are validated and token/issuer entities are built once, then
each item is evaluated in input order. Batch-level failures (validation,
JWT verification, status-list refresh) reject the whole call; per-item
failures are returned as BatchItemError results and exposed by WASM
with is_ok=false and error, while genuine Cedar denials remain
AuthorizeResult values with decision=false.
request - JSON string representation of [BatchAuthorizeMultiIssuerRequest].const result = await cedarling.authorizeMultiIssuerBatch(JSON.stringify(batchRequest));
Authorize an unsigned request carrying an optional single principal.
Makes an authorization decision based on the [RequestUnsigned].
When principal is omitted / null on the JS side the core uses Cedar
partial evaluation; residual-dependent requests fail closed with
Decision::Deny and surface residual policy ids in
response.diagnostics.reason.
request - JSON string representation of [RequestUnsigned].const result = await cedarling.authorizeUnsigned(JSON.stringify(request));
Authorize a batch of unsigned requests against one shared principal.
Setup work (principal build + pushed-data snapshot) runs once and each
item is evaluated in input order. Results are returned inside a
[BatchAuthorizeUnsignedResponse] carrying the shared batch_id.
Batch-level failures (validation, principal parse) reject the whole
call; per-item failures are returned as BatchItemError results and
exposed by WASM with is_ok=false and error, while genuine Cedar
denials remain AuthorizeResult values with decision=false.
request - JSON string representation of [BatchAuthorizeUnsignedRequest].const result = await cedarling.authorizeUnsignedBatch(JSON.stringify(batchRequest));
Destructive read: returns the telemetry metrics snapshot and resets the counters for the next interval.
Fails when CEDARLING_METRICS_COLLECTION is disabled or whenever
CEDARLING_LOCK_TELEMETRY_INTERVAL is set (even if the Lock server
has no telemetry endpoint). interval_secs is fractional seconds,
so sub-second intervals are reported exactly.
const snapshot = cedarling.drainMetrics();
console.log(`Requests: ${snapshot.operational_stats.get("authz.requests_total")}`);
Get a value from the data store by key. Returns null if the key doesn't exist or the entry has expired.
key - A string key for the data entry to retrieveconst value = cedarling.getDataCtx("user:123");
if (value !== null) {
console.log(value.name); // "John"
}
Get a data entry with full metadata by key. Returns undefined if the key doesn't exist or the entry has expired.
key - A string key for the data entry to retrieveconst entry = cedarling.getDataEntryCtx("user:123");
if (entry !== undefined) {
console.log(entry.key); // "user:123"
console.log(entry.value()); // { name: "John", age: 30 }
console.log(entry.data_type); // "Record"
console.log(entry.created_at); // "2024-01-01T12:00:00Z"
console.log(entry.access_count); // 5
}
Returns retained memory logs matching one request ID and indexed value.
requestId - The request identifier to match.tag - A log kind ("System", "Decision", or "Metric") or a
system-log level such as "DEBUG".const logs = cedarling.getLogsByRequestIdAndTag("request-id", "System");
Get statistics about the data store.
None.
const stats = cedarling.getStatsCtx();
console.log(`Entries: ${stats.entry_count}/${stats.max_entries || 'unlimited'}`);
console.log(`Capacity: ${stats.capacity_usage_percent.toFixed(2)}%`);
console.log(`Total size: ${stats.total_size_bytes} bytes`);
Push a value into the data store with an optional TTL. If the key already exists, the value will be replaced. If TTL is not provided, the default TTL from configuration is used.
key - A string key for the data entry (must not be empty)value - The value to store (any JSON-serializable JavaScript value: object, array, string, number, boolean)ttl_secs - Optional TTL in seconds (undefined/null uses default from config)cedarling.pushDataCtx("user:123", { name: "John", age: 30 }, 3600);
cedarling.pushDataCtx("config", { setting: "value" }); // Uses default TTL
Optionalttl_secs: bigint | nullRemove a value from the data store by key. Returns true if the key existed and was removed, false otherwise.
key - A string key for the data entry to removeconst removed = cedarling.removeDataCtx("user:123");
if (removed) {
console.log("Entry was successfully removed");
}
StaticnewCreates a Cedarling application from bootstrap properties.
config - A plain object of Cedarling bootstrap-property names and values.await initWasm();
const cedarling = await Cedarling.new({
CEDARLING_APPLICATION_NAME: "task-api",
CEDARLING_POLICY_STORE_URI: "https://example.com/policy-store.cjar",
CEDARLING_LOG_TYPE: "memory",
CEDARLING_LOG_TTL: 120,
});
StaticnewCreates a new Cedarling application from a JavaScript Map.
config - A Map of Cedarling bootstrap-property names and values.await initWasm();
const cedarling = await Cedarling.newFromMap(new Map([
["CEDARLING_APPLICATION_NAME", "task-api"],
["CEDARLING_POLICY_STORE_URI", "https://example.com/policy-store.cjar"],
["CEDARLING_LOG_TYPE", "memory"],
["CEDARLING_LOG_TTL", 120],
]));
The instance of the Cedarling application.