~james/core

core/web/src/lib/api/secrets.ts -rw-r--r-- 1.4 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { ok } from "@atcute/client";
import type { OAuthUserAgent } from "@atcute/oauth-browser-client";
import { spindleXrpc, type SpindleTarget } from "#lib/api/spindlewrite.ts";
import { mainSchema as addSecretSchema } from "#lib/api/lexicons/types/org/tangled/secret/addSecret.ts";
import {
	mainSchema as listSecretsSchema,
	type Secret
} from "#lib/api/lexicons/types/org/tangled/secret/listSecrets.ts";
import { mainSchema as removeSecretSchema } from "#lib/api/lexicons/types/org/tangled/secret/removeSecret.ts";

export type { Secret };

export const listSecrets = async (
	agent: OAuthUserAgent,
	spindle: URL,
	target: SpindleTarget
): Promise<Secret[]> => {
	const { secrets } = await ok(
		(await spindleXrpc(agent, spindle, target)).call(listSecretsSchema, {
			params: { repo: target.repoDid }
		})
	);
	return secrets;
};

export const addSecret = async (
	agent: OAuthUserAgent,
	spindle: URL,
	target: SpindleTarget,
	key: string,
	value: string
): Promise<void> => {
	await ok(
		(await spindleXrpc(agent, spindle, target)).call(addSecretSchema, {
			input: { repo: target.repoDid, key, value }
		})
	);
};

export const removeSecret = async (
	agent: OAuthUserAgent,
	spindle: URL,
	target: SpindleTarget,
	key: string
): Promise<void> => {
	await ok(
		(await spindleXrpc(agent, spindle, target)).call(removeSecretSchema, {
			input: { repo: target.repoDid, key }
		})
	);
};