Remember, all data stored on Context is public. Avoid storing any secrets or private information without additional measures to protect confidentiality.
Fetch Documents
Fetch a specific document or template or asset, from any domain:
// Fetch a specific documentconstdocument=awaitctx.document("contextprotocol.startup/myframe"); // "domain/path/to/file"
You can fetch a specific version of a document in two different ways:
// By using the version method of the document:constdocument=awaitctx.document("document_path");constdocumentVersion=awaitdocument.data.getVersion("X.Y.Z");// By specifying the version directly the document path:constdocumentInVersionXYZ=awaitctx.document("document_path?v=X.Y.Z");
Create a Document
Steps to create a new document within a domain:
constdata=YOUR_JSON_DATA; // JSON data for the documentconsttemplates= ["template_path"]; // Optional array of template pathsconst metadata = { name: "Document Name", description: "Document Description", readme: "ctx:domain/files/my_markdown" }; // Optional metadata
constdocumentPath="mypath/files/document";constnewDocument=awaitctx.createDocument(documentPath, data, templates, metadata);
You can add metadata to a document using the addMetadata method. The metadata object should contain the following (optional) fields: name, description, and readme as shown below: