@archon-inc/sdk
Version:
Integrate easily to our government platform using this SDK. More info on https://archon.inc/sdk
20 lines (19 loc) • 878 B
JavaScript
import { Archon } from "../Archon.js";
/**
* This function creates a new Archon-managed resource for some object your software maintains.
* It returns an ARID that you can use to reference the resource in the future. You'll use the ARID to determine
* access to the resource, so make sure you store it on your end.
* @param options The options for the resource you're adding.
* @returns The ARID of the newly created resource.
*/
export default async function addResource(options) {
// If the type is a ResourceType object, convert it to a ResourceTypeName.
if (typeof options.type !== "string") {
options.type = options.type.name;
}
const response = await Archon.request("/policy/resource", "POST", options);
if (response.status !== 200) {
throw new Error(`Failed to add resource: ${response.data}`);
}
return response.data;
}