-module(possum). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/possum.gleam"). -export([get_plc_data/1, resolve_well_known_did/1, resolve_handle/2, create_session/5, authorized/2, refresh_session/2, get_session_info/1, describe_repository/2, create_record/7, get_record/5, list_records/6, delete_record/6, put_record/8, get_blob/3]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC( " ## PDS (Personal Data Server)\n" "\n" " A PDS, or Personal Data Server, is a server that hosts a user, it will\n" " always store the user's data repo and signing keys. It may also assign\n" " the user a handle and a DID. Many PDSes will host multiple users.\n" "\n" " A PDS doesn't typically run any applications itself, though it will have\n" " general account management interfaces such as the OAuth login screen.\n" " PDSes actively sync their data repos with Relays.\n" "\n" " ## Lexicon\n" "\n" " Lexicon is a schema language. It's used in the Atmosphere to describe data\n" " records and HTTP APIs. Functionally it's very similar to JSON-Schema and OpenAPI.\n" " Lexicon's sole purpose is to help developers build compatible software.\n" "\n" " ## Record Keys\n" "\n" " A record key (sometimes shortened to \"rkey\") is used to name and reference an individual\n" " record within the same collection of an atproto repository.\n" " It ends up as a segment in AT URIs, and in the repo MST path.\n" "\n" " ## CID (Content ID)\n" "\n" " CIDs, or Content Identifiers, are cryptographic hashes of records.\n" " They are used to track specific versions of records.\n" "\n" " CIDs include a metadata code which indicates whether it links to a node\n" " or arbitrary binary data. In atproto, object nodes often include a string\n" " field `$type` that specifies their Lexicon schema. \n" ). -file("src/possum.gleam", 99). ?DOC( " Get current PLC Data for the indicated DID,\n" " this returns information about a Decentralized Identifier (DID),\n" " including their handle and service endpoint.\n" "\n" " PLC is a persistent global identifier system, stands for\n" " \"Public Ledger of Credentials\".\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/did\n" " import possum\n" "\n" " let assert Ok(did) = did.parse(\"did:plc:z72i7hdynmk6r22z27h6tvur\")\n" " let request = possum.get_plc_data(did)\n" "\n" " // You can use this decoder to extract the server endpoint\n" " let decoder = decode.at([\"services\", \"atproto_pds\", \"endpoint\"], decode.string)\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"did\": \"string\",\n" " \"verificationMethods\": {\n" " \"atproto\": \"string\"\n" " },\n" " \"rotationKeys\": [\n" " \"string\",\n" " \"string\"\n" " ],\n" " \"alsoKnownAs\": [\n" " \"string\"\n" " ],\n" " \"services\": {\n" " \"atproto_pds\": {\n" " \"type\": \"string\",\n" " \"endpoint\": \"string\"\n" " }\n" " }\n" " ```\n" "\n" " Documentation: [DID PLC Directory](https://web.plc.directory/)\n" ). -spec get_plc_data(possum@did:did()) -> gleam@http@request:request(binary()). get_plc_data(Did) -> {request, get, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}], <<""/utf8>>, https, <<"plc.directory"/utf8>>, none, <<(possum@did:to_string(Did))/binary, "/data"/utf8>>, none}. -file("src/possum.gleam", 130). ?DOC( " Resolves a handle to a DID using a HTTPS `/.well-known/` URL path,\n" " it looks for a file called \"atproto-did\" that contains the user DID.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import possum\n" "\n" " let request = possum.resolve_well_known_did(host: \"gleam.run\")\n" " ```\n" "\n" " ## Response\n" "\n" " ```txt\n" " did:plc:k5vecqzf4d5mdvkcu3mx6l5g\n" " ```\n" "\n" " Documentation: [HTTPS well-known Method](https://atproto.com/specs/handle#https-well-known-method)\n" ). -spec resolve_well_known_did(binary()) -> gleam@http@request:request(binary()). resolve_well_known_did(Host) -> {request, get, [], <<""/utf8>>, https, Host, none, <<".well-known/atproto-did"/utf8>>, none}. -file("src/possum.gleam", 169). ?DOC( " Resolves an atproto handle (hostname) to a DID.\n" " Does not necessarily bi-directionally verify against the the DID document.\n" "\n" " You can use projects like [Slingshot](https://slingshot.microcosm.blue)\n" " for easy access to cached data.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/handle\n" " import possum\n" "\n" " let assert Ok(handle) = handle.parse(\"gleam.run\")\n" " let request = possum.resolve_handle(handle, pds: \"slingshot.microcosm.blue\")\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"did\": \"string\"\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.identity.resolveHandle](https://endpoints.bsky.app/#bluesky-app/tag/comatprotoidentity/GET/xrpc/com.atproto.identity.resolveHandle)\n" ). -spec resolve_handle(possum@handle:handle(), binary()) -> gleam@http@request:request(binary()). resolve_handle(Handle, Host) -> _pipe = {request, get, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}], <<""/utf8>>, https, Host, none, <<"xrpc/com.atproto.identity"/utf8, ".resolveHandle"/utf8>>, none}, gleam@http@request:set_query( _pipe, [{<<"handle"/utf8>>, possum@handle:to_string(Handle)}] ). -file("src/possum.gleam", 234). ?DOC( " Create an authentication session.\n" " An **App Password** can be generated in your Bluesky settings.\n" "\n" " ## Body\n" "\n" " - **password**: App password\n" " - **allowTakendown**: When true, instead of throwing error for takendown accounts,\n" " a valid response with a narrow scoped token will be returned\n" " - **authFactorToken**: Used during the authentication process to handle\n" " Two-Factor Authentication\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/did\n" " import possum\n" "\n" " let assert Ok(did) = did.parse(\"did:plc:ewvi7nxzyoun6zhxrhs64oiz\")\n" "\n" " let request =\n" " possum.create_session(\n" " did,\n" " pds: \"personal.data-server.pds\",\n" " app_password: \"bsky-app-password\",\n" " allow_takendown: option.None,\n" " auth_factor_token: option.None\n" " )\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"did\": \"string\",\n" " \"email\": \"string\",\n" " \"active\": true,\n" " \"didDoc\": null,\n" " \"handle\": \"string\",\n" " \"status\": \"takendown\",\n" " \"accessJwt\": \"string\",\n" " \"refreshJwt\": \"string\",\n" " \"emailConfirmed\": true,\n" " \"emailAuthFactor\": true\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.server.createSession](https://endpoints.bsky.app/#bluesky-app/tag/comatprotoserver/POST/xrpc/com.atproto.server.createSession)\n" ). -spec create_session( possum@did:did(), binary(), binary(), gleam@option:option(boolean()), gleam@option:option(binary()) ) -> gleam@http@request:request(binary()). create_session(Did, Host, App_password, Allow_takendown, Auth_factor_token) -> Values = [{<<"identifier"/utf8>>, gleam@json:string(possum@did:to_string(Did))}, {<<"password"/utf8>>, gleam@json:string(App_password)}], Values@1 = case Allow_takendown of {some, Value} -> [{<<"allowTakendown"/utf8>>, gleam@json:bool(Value)} | Values]; none -> Values end, Values@2 = case Auth_factor_token of {some, Value@1} -> [{<<"authFactorToken"/utf8>>, gleam@json:string(Value@1)} | Values@1]; none -> Values@1 end, {request, post, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}, {<<"content-type"/utf8>>, <<"application/json"/utf8>>}], gleam@json:to_string(gleam@json:object(Values@2)), https, Host, none, <<"xrpc/com.atproto.server"/utf8, ".createSession"/utf8>>, none}. -file("src/possum.gleam", 377). ?DOC( " Include a access token in the request's headers.\n" " Tokens can be acquired with `create_session`.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum\n" "\n" " let request =\n" " request.new()\n" " |> possum.authorized(access_token: \"access-token\")\n" "\n" " assert request.headers != []\n" " ```\n" ). -spec authorized(gleam@http@request:request(binary()), binary()) -> gleam@http@request:request(binary()). authorized(Request, Token) -> gleam@http@request:prepend_header( Request, <<"authorization"/utf8>>, <<"bearer "/utf8, Token/binary>> ). -file("src/possum.gleam", 301). ?DOC( " Refresh an authentication session.\n" " Requires auth using the 'refreshJwt' (not the 'accessJwt').\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import possum\n" "\n" " let request =\n" " possum.refresh_session(\"refresh-token\", pds: \"personal.data-server.pds\")\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"did\": \"string\",\n" " \"email\": \"string\",\n" " \"active\": true,\n" " \"didDoc\": null,\n" " \"handle\": \"string\",\n" " \"status\": \"takendown\",\n" " \"accessJwt\": \"string\",\n" " \"refreshJwt\": \"string\",\n" " \"emailConfirmed\": true,\n" " \"emailAuthFactor\": true\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.server.refreshSession](https://endpoints.bsky.app/#bluesky-app/tag/comatprotoserver/POST/xrpc/com.atproto.server.refreshSession)\n" ). -spec refresh_session(binary(), binary()) -> gleam@http@request:request(binary()). refresh_session(Token, Host) -> _pipe = {request, post, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}], <<""/utf8>>, https, Host, none, <<"xrpc/com.atproto.server"/utf8, ".refreshSession"/utf8>>, none}, authorized(_pipe, Token). -file("src/possum.gleam", 348). ?DOC( " Get information about the current auth session.\n" " Requires auth.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum\n" "\n" " let request =\n" " possum.get_session_info(pds: \"personal.data-server.pds\")\n" " |> possum.authorized(\"access-token\")\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"did\": \"string\",\n" " \"email\": \"string\",\n" " \"active\": true,\n" " \"didDoc\": null,\n" " \"handle\": \"string\",\n" " \"status\": \"takendown\",\n" " \"emailConfirmed\": true,\n" " \"emailAuthFactor\": true\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.server.getSession](https://endpoints.bsky.app/#bluesky-app/tag/comatprotoserver/POST/xrpc/com.atproto.server.getSession)\n" ). -spec get_session_info(binary()) -> gleam@http@request:request(binary()). get_session_info(Host) -> {request, get, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}], <<""/utf8>>, https, Host, none, <<"xrpc/com.atproto.server"/utf8, ".getSession"/utf8>>, none}. -file("src/possum.gleam", 413). ?DOC( " Get information about an account and repository, including the list of collections.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/did\n" " import possum\n" "\n" " let assert Ok(did) = did.parse(\"did:plc:ewvi7nxzyoun6zhxrhs64oiz\")\n" " let request =\n" " possum.describe_repository(did, pds: \"personal.data-server.pds\")\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"did\": \"string\",\n" " \"didDoc\": null,\n" " \"handle\": \"string\",\n" " \"collections\": [\n" " \"string\"\n" " ],\n" " \"handleIsCorrect\": true\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.repo.describeRepo](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/GET/xrpc/com.atproto.repo.describeRepo)\n" ). -spec describe_repository(possum@did:did(), binary()) -> gleam@http@request:request(binary()). describe_repository(Did, Host) -> _pipe = {request, get, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}], <<""/utf8>>, https, Host, none, <<"xrpc/com.atproto.repo"/utf8, ".describeRepo"/utf8>>, none}, gleam@http@request:set_query( _pipe, [{<<"repo"/utf8>>, possum@did:to_string(Did)}] ). -file("src/possum.gleam", 482). ?DOC( " Create a single new repository record.\n" " Requires auth, implemented by PDS.\n" " \n" " ## Body\n" " \n" " - **collection**: The NSID of the record collection.\n" " - **repo**: The handle or DID of the repo (aka, current account).\n" " - **rkey**: The Record Key.\n" " - **swapCommit**: Compare and swap with the previous commit by CID.\n" " - **validate**: Can be set to `option.Some(False)` to skip Lexicon schema validation\n" " of record data, `option.Some(True)` to require it, or leave unset to validate only\n" " for known Lexicons.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/nsid\n" " import possum/did\n" " import possum\n" "\n" " let assert Ok(did) = did.parse(\"did:plc:k5vecqzf4d5mdvkcu3mx6l5g\")\n" " let assert Ok(collection) = nsid.parse(\"wibble.wobble.woo\")\n" "\n" " let request =\n" " possum.create_record(\n" " did,\n" " pds: \"personal.data-server.pds\",\n" " collection:,\n" " rkey: \"wibble\",\n" " record: [],\n" " swap_commit: option.None,\n" " validate: option.None,\n" " )\n" " |> possum.authorized(\"access-token\")\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"cid\": \"string\",\n" " \"uri\": \"string\",\n" " \"commit\": {\n" " \"cid\": \"string\",\n" " \"rev\": \"string\"\n" " },\n" " \"validationStatus\": \"valid\"\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.repo.createRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/POST/xrpc/com.atproto.repo.createRecord)\n" ). -spec create_record( possum@did:did(), binary(), possum@nsid:nsid(), gleam@option:option(binary()), list({binary(), gleam@json:json()}), gleam@option:option(binary()), gleam@option:option(boolean()) ) -> gleam@http@request:request(binary()). create_record(Did, Host, Nsid, Rkey, Record, Swap_commit, Validate) -> Body = [{<<"collection"/utf8>>, gleam@json:string(possum@nsid:to_string(Nsid))}, {<<"record"/utf8>>, gleam@json:object(Record)}, {<<"repo"/utf8>>, gleam@json:string(possum@did:to_string(Did))}], Body@1 = case Rkey of {some, Value} -> [{<<"rkey"/utf8>>, gleam@json:string(Value)} | Body]; none -> Body end, Body@2 = case Swap_commit of {some, Value@1} -> [{<<"swapCommit"/utf8>>, gleam@json:string(Value@1)} | Body@1]; none -> Body@1 end, Body@3 = case Validate of {some, Value@2} -> [{<<"validate"/utf8>>, gleam@json:bool(Value@2)} | Body@2]; none -> Body@2 end, {request, post, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}, {<<"content-type"/utf8>>, <<"application/json"/utf8>>}], gleam@json:to_string(gleam@json:object(Body@3)), https, Host, none, <<"xrpc/com.atproto.repo"/utf8, ".createRecord"/utf8>>, none}. -file("src/possum.gleam", 564). ?DOC( " Get a single record from a repository. Does not require auth.\n" "\n" " You can use projects like [Slingshot](https://slingshot.microcosm.blue)\n" " for easy access to cached data.\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/did\n" " import possum/nsid\n" " import possum\n" "\n" " let assert Ok(did) = did.parse(\"did:plc:k5vecqzf4d5mdvkcu3mx6l5g\")\n" " let assert Ok(collection) = nsid.parse(\"site.standard.document\")\n" "\n" " let request =\n" " possum.get_record(\n" " did,\n" " pds: \"slingshot.microcosm.blue\",\n" " collection:,\n" " rkey: \"mn6n3lvibc2b\",\n" " cursor: option.None,\n" " cid: option.None,\n" " )\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"cid\": \"string\",\n" " \"uri\": \"string\",\n" " \"value\": null\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.repo.getRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/GET/xrpc/com.atproto.repo.getRecord)\n" " Documentation: [atproto.com](https://atproto.com/specs/record-key)\n" ). -spec get_record( possum@did:did(), binary(), possum@nsid:nsid(), binary(), gleam@option:option(binary()) ) -> gleam@http@request:request(binary()). get_record(Did, Host, Nsid, Rkey, Cid) -> Query = [{<<"repo"/utf8>>, possum@did:to_string(Did)}, {<<"rkey"/utf8>>, Rkey}, {<<"collection"/utf8>>, possum@nsid:to_string(Nsid)}], Query@1 = case Cid of {some, Cid@1} -> [{<<"cid"/utf8>>, Cid@1} | Query]; none -> Query end, _pipe = {request, get, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}], <<""/utf8>>, https, Host, none, <<"xrpc/com.atproto.repo"/utf8, ".getRecord"/utf8>>, none}, gleam@http@request:set_query(_pipe, Query@1). -file("src/possum.gleam", 635). ?DOC( " List a range of records in a repository, matching a specific collection.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/did\n" " import possum/nsid\n" " import possum\n" "\n" " let assert Ok(did) = did.parse(\"did:plc:ewvi7nxzyoun6zhxrhs64oiz\")\n" " let assert Ok(collection) = nsid.parse(\"site.standard.document\")\n" "\n" " let request =\n" " possum.list_records(\n" " did,\n" " pds: \"personal.data-server.pds\",\n" " collection:,\n" " limit: option.Some(3),\n" " cursor: option.None,\n" " reverse: option.None,\n" " )\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"cursor\": \"string\",\n" " \"records\": [\n" " {\n" " \"cid\": \"string\",\n" " \"uri\": \"string\",\n" " \"value\": null\n" " }\n" " ]\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.repo.listRecords](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/GET/xrpc/com.atproto.repo.listRecords)\n" ). -spec list_records( possum@did:did(), binary(), possum@nsid:nsid(), gleam@option:option(integer()), gleam@option:option(binary()), gleam@option:option(boolean()) ) -> gleam@http@request:request(binary()). list_records(Did, Host, Nsid, Limit, Cursor, Reverse) -> Query = [{<<"repo"/utf8>>, possum@did:to_string(Did)}, {<<"collection"/utf8>>, possum@nsid:to_string(Nsid)}], Query@1 = case Limit of {some, Value} -> [{<<"limit"/utf8>>, erlang:integer_to_binary(Value)} | Query]; none -> Query end, Query@2 = case Cursor of {some, Value@1} -> [{<<"cursor"/utf8>>, Value@1} | Query@1]; none -> Query@1 end, Query@3 = case Reverse of {some, Value@2} -> [{<<"reverse"/utf8>>, gleam@bool:to_string(Value@2)} | Query@2]; none -> Query@2 end, _pipe = {request, get, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}], <<""/utf8>>, https, Host, none, <<"xrpc/com.atproto.repo"/utf8, ".listRecords"/utf8>>, none}, gleam@http@request:set_query(_pipe, Query@3). -file("src/possum.gleam", 720). ?DOC( " Delete a repository record, or ensure it doesn't exist.\n" " Requires auth, implemented by PDS.\n" "\n" " - **collection**: The NSID of the record collection.\n" " - **repo**: The handle or DID of the repo (aka, current account).\n" " - **rkey**: The Record Key.\n" " - **swapCommit**: Compare and swap with the previous commit by CID.\n" " - **swapRecord**: Compare and swap with the previous record by CID.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/did\n" " import possum/nsid\n" " import possum\n" " \n" " let assert Ok(did) = did.parse(\"did:plc:k5vecqzf4d5mdvkcu3mx6l5g\")\n" " let assert Ok(collection) = nsid.parse(\"wibble.wobble.woo\")\n" " \n" " let request =\n" " possum.delete_record(\n" " did,\n" " pds: \"personal.data-server.pds\"\n" " collection:,\n" " rkey: \"wibble-wobble\",\n" " swap_commit: option.None,\n" " swap_record: option.None,\n" " )\n" " |> possum.authorized(\"access-token\")\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"commit\": {\n" " \"cid\": \"string\",\n" " \"rev\": \"string\"\n" " }\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.repo.deleteRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/POST/xrpc/com.atproto.repo.deleteRecord)\n" ). -spec delete_record( possum@did:did(), binary(), possum@nsid:nsid(), binary(), gleam@option:option(binary()), gleam@option:option(binary()) ) -> gleam@http@request:request(binary()). delete_record(Did, Host, Nsid, Rkey, Swap_commit, Swap_record) -> Body = [{<<"repo"/utf8>>, gleam@json:string(possum@did:to_string(Did))}, {<<"collection"/utf8>>, gleam@json:string(possum@nsid:to_string(Nsid))}, {<<"rkey"/utf8>>, gleam@json:string(Rkey)}], Body@1 = case Swap_commit of {some, Value} -> [{<<"swapCommit"/utf8>>, gleam@json:string(Value)} | Body]; none -> Body end, Body@2 = case Swap_record of {some, Value@1} -> [{<<"swapRecord"/utf8>>, gleam@json:string(Value@1)} | Body@1]; none -> Body@1 end, {request, post, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}, {<<"content-type"/utf8>>, <<"application/json"/utf8>>}], gleam@json:to_string(gleam@json:object(Body@2)), https, Host, none, <<"xrpc/com.atproto.repo"/utf8, ".deleteRecord"/utf8>>, none}. -file("src/possum.gleam", 813). ?DOC( " Write a repository record, creating or updating it as needed.\n" " Requires auth, implemented by PDS.\n" "\n" " ## Body\n" " \n" " - **collection**: The NSID of the record collection.\n" " - **repo**: The handle or DID of the repo (aka, current account).\n" " - **rkey**: The Record Key.\n" " - **swapCommit**: Compare and swap with the previous commit by CID.\n" " - **swapRecord**: Compare and swap with the previous record by CID.\n" " - **validate**: Can be set to `option.Some(False)` to skip Lexicon schema validation\n" " of record data, `option.Some(True)` to require it, or leave unset to validate only\n" " for known Lexicons.\n" "\n" " ## Examples\n" "\n" " ```gleam\n" " import gleam/http/request\n" " import possum/did\n" " import possum/nsid\n" " import possum\n" " \n" " let assert Ok(did) = did.parse(\"did:plc:k5vecqzf4d5mdvkcu3mx6l5g\")\n" " let assert Ok(collection) = nsid.parse(\"target.collection.data\")\n" "\n" " let request =\n" " possum.put_record(\n" " did,\n" " pds: \"personal.data-server.pds\",\n" " collection:,\n" " rkey: \"wibble-wobble\",\n" " record: [],\n" " swap_commit: option.None,\n" " swap_record: option.None,\n" " validate: option.None,\n" " )\n" " |> possum.authorized(\"access-token\")\n" " ```\n" "\n" " ## Response\n" "\n" " ```json\n" " {\n" " \"cid\": \"string\",\n" " \"uri\": \"string\",\n" " \"commit\": {\n" " \"cid\": \"string\",\n" " \"rev\": \"string\"\n" " },\n" " \"validationStatus\": \"valid\"\n" " }\n" " ```\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.repo.putRecord](https://endpoints.bsky.app/#bluesky-app/tag/comatprotorepo/POST/xrpc/com.atproto.repo.putRecord)\n" ). -spec put_record( possum@did:did(), binary(), possum@nsid:nsid(), binary(), list({binary(), gleam@json:json()}), gleam@option:option(binary()), gleam@option:option(binary()), gleam@option:option(boolean()) ) -> gleam@http@request:request(binary()). put_record(Did, Host, Nsid, Rkey, Record, Swap_commit, Swap_record, Validate) -> Body = [{<<"collection"/utf8>>, gleam@json:string(possum@nsid:to_string(Nsid))}, {<<"record"/utf8>>, gleam@json:object(Record)}, {<<"repo"/utf8>>, gleam@json:string(possum@did:to_string(Did))}, {<<"rkey"/utf8>>, gleam@json:string(Rkey)}], Body@1 = case Swap_commit of {some, Value} -> [{<<"swapCommit"/utf8>>, gleam@json:string(Value)} | Body]; none -> Body end, Body@2 = case Swap_record of {some, Value@1} -> [{<<"swapRecord"/utf8>>, gleam@json:string(Value@1)} | Body@1]; none -> Body@1 end, Body@3 = case Validate of {some, Value@2} -> [{<<"validate"/utf8>>, gleam@json:bool(Value@2)} | Body@2]; none -> Body@2 end, {request, post, [{<<"accept"/utf8>>, <<"application/json"/utf8>>}, {<<"content-type"/utf8>>, <<"application/json"/utf8>>}], gleam@json:to_string(gleam@json:object(Body@3)), https, Host, none, <<"xrpc/com.atproto.repo"/utf8, ".putRecord"/utf8>>, none}. -file("src/possum.gleam", 865). ?DOC( " Get a blob associated with a given account.\n" " Returns the full blob as originally uploaded.\n" " Does not require auth; implemented by PDS.\n" "\n" " Endpoint Docs: [/xrpc/com.atproto.sync.getBlob](https://endpoints.bsky.app/#bluesky-app/tag/comatprotosync/GET/xrpc/com.atproto.sync.getBlob)\n" ). -spec get_blob(possum@did:did(), binary(), binary()) -> gleam@http@request:request(bitstring()). get_blob(Did, Cid, Host) -> Query = [{<<"did"/utf8>>, possum@did:to_string(Did)}, {<<"cid"/utf8>>, Cid}], _pipe = {request, get, [{<<"accept"/utf8>>, <<"*/*"/utf8>>}], <<>>, https, Host, none, <<"xrpc/com.atproto.sync"/utf8, ".getBlob"/utf8>>, none}, gleam@http@request:set_query(_pipe, Query).