@matatbread/matbot-plugin-api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +20 -0
- package/package.json +34 -0
- package/src/broadcast.ts +73 -0
- package/src/context-switch.ts +73 -0
- package/src/errors.ts +69 -0
- package/src/hooks.ts +185 -0
- package/src/index.ts +10 -0
- package/src/plugin.ts +498 -0
- package/src/principal-context.ts +85 -0
- package/src/store-query.ts +70 -0
- package/src/types.ts +704 -0
- package/src/vault.ts +21 -0
package/src/vault.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { VaultSpec } from './types.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `createSecret` policy, written once over the spec primitives so every backend behaves
|
|
5
|
+
* identically. A backend's `createSecret` is just `applyCreateSecret(this, name, value)`.
|
|
6
|
+
*
|
|
7
|
+
* The dedup step (returning an existing name for a value already stored) technically lets a
|
|
8
|
+
* caller confirm a name for a value they already hold — but holding the value already grants
|
|
9
|
+
* everything that confirmation would, so it leaks nothing.
|
|
10
|
+
*/
|
|
11
|
+
export async function applyCreateSecret(
|
|
12
|
+
spec: VaultSpec,
|
|
13
|
+
name: string,
|
|
14
|
+
value: string,
|
|
15
|
+
): Promise<string> {
|
|
16
|
+
if (spec.hasKey(value)) return value;
|
|
17
|
+
const existing = spec.findByValue?.(value);
|
|
18
|
+
if (existing !== undefined) return existing;
|
|
19
|
+
await spec.writeSecret(name, value);
|
|
20
|
+
return name;
|
|
21
|
+
}
|