@open33/harness-credentials 0.0.0-stage → 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.
@@ -0,0 +1,213 @@
1
+ /**
2
+ * Service Definition for the credential-reference capability seam (`ctx.credentials`). Settings and composition files carry
3
+ * *references* to secrets — environment-variable names — while providers own
4
+ * the actual values and their storage. Consumers resolve a reference once per
5
+ * operation, so a changed credential reaches the next operation without any
6
+ * plugin restart, and configuration surfaces describe a reference without
7
+ * ever seeing its full value.
8
+ * @module @open33/harness-credentials
9
+ */
10
+ import { Context, Service } from '@open33/cordis';
11
+ import type { CredentialInfo, CredentialKey, CredentialRecord, CredentialRef } from './types.ts';
12
+ export type { ApiKeyRecord, CredentialInfo, CredentialKey, CredentialRecord, CredentialRef, GrantRecord, } from './types.ts';
13
+ /**
14
+ * Brand a raw string as a {@link CredentialRef}.
15
+ * @param value - candidate reference; a POSIX shell identifier such as `OPEN33_API_KEY`.
16
+ * @returns the branded reference.
17
+ */
18
+ export declare function credentialRef(value: string): CredentialRef;
19
+ /**
20
+ * Whether a raw string could name a reference at all. Consumers that receive
21
+ * environment-variable names from somewhere else — a provider library's own
22
+ * ambient discovery, a hook payload — ask this before resolving, because a name
23
+ * outside the grammar has no reference to miss and should read as "not set"
24
+ * rather than as a thrown error.
25
+ * @param value - candidate reference.
26
+ * @returns true when {@link credentialRef} would accept it.
27
+ */
28
+ export declare function isCredentialRefName(value: string): boolean;
29
+ /**
30
+ * Whether a raw string could be a {@link credentialKey} segment at all.
31
+ * Consumers whose addressing units come from somewhere else — a settings dict
32
+ * key, a library's own provider id — ask this before building a key, because a
33
+ * unit outside the grammar can never have stored a record and should read as
34
+ * "nothing stored" rather than as a thrown error.
35
+ * @param value - candidate segment.
36
+ * @returns true when {@link credentialKey} would accept it as either segment.
37
+ */
38
+ export declare function isCredentialKeySegment(value: string): boolean;
39
+ /**
40
+ * Brand a scope and an id as a {@link CredentialKey}.
41
+ * @param scope - the owning plugin's registered name, such as `llm-pi-ai`.
42
+ * @param id - that plugin's own addressing unit, such as a provider route key.
43
+ * @returns the branded key.
44
+ * @throws TypeError when either segment is not a lowercase hyphenated identifier.
45
+ */
46
+ export declare function credentialKey(scope: string, id: string): CredentialKey;
47
+ /**
48
+ * Brand a stored `<scope>/<id>` string as a {@link CredentialKey}. This is the
49
+ * read half of {@link credentialKey}, for a provider admitting keys off disk.
50
+ * @param value - candidate key in its joined form.
51
+ * @returns the branded key.
52
+ * @throws TypeError when the value is not exactly two valid segments.
53
+ */
54
+ export declare function parseCredentialKey(value: string): CredentialKey;
55
+ /**
56
+ * The owning plugin's name for one key. A record whose scope names no
57
+ * currently registered owner is an orphan, which a configuration surface must
58
+ * report as such rather than as a working credential.
59
+ * @param key - the key to read.
60
+ * @returns the scope segment.
61
+ */
62
+ export declare function credentialKeyScope(key: CredentialKey): string;
63
+ /**
64
+ * The owning plugin's own addressing unit for one key — the half that plugin
65
+ * chose, such as a provider route.
66
+ * @param key - the key to read.
67
+ * @returns the id segment.
68
+ */
69
+ export declare function credentialKeyId(key: CredentialKey): string;
70
+ /** One resolved credential value and the source layer that supplied it. */
71
+ export interface ResolvedCredential {
72
+ /** The non-empty secret value. */
73
+ value: string;
74
+ /** Provider-defined source layer id (the local provider uses `env`, `file`, `project-env`, and `user-env`). */
75
+ source: string;
76
+ }
77
+ /** Presence and writability facts for one record, safe for configuration UIs — never the value. */
78
+ export interface CredentialRecordInfo {
79
+ /**
80
+ * Whether a record is stored. Unlike a reference, presence alone answers
81
+ * this: an {@link ApiKeyRecord} carrying neither a key nor environment
82
+ * values states that its owner confirmed ambient authentication, which is
83
+ * configured, not blank.
84
+ */
85
+ configured: boolean;
86
+ /** Discriminant of the stored record; absent while none is stored. */
87
+ kind?: CredentialRecord['kind'];
88
+ /** Whether {@link CredentialProvider.modifyRecord} would currently succeed. */
89
+ writable: boolean;
90
+ }
91
+ /** One stored record's address and tag, for enumeration — never its value. */
92
+ export interface CredentialRecordEntry {
93
+ /** The record's address. */
94
+ key: CredentialKey;
95
+ /** Discriminant of the stored record. */
96
+ kind: CredentialRecord['kind'];
97
+ }
98
+ declare module '@open33/cordis' {
99
+ interface Context {
100
+ credentials: CredentialProvider;
101
+ }
102
+ }
103
+ /**
104
+ * Abstract credential service over two key spaces that answer two questions.
105
+ *
106
+ * A {@link CredentialRef} answers "what is behind this environment-variable
107
+ * name": the provider-managed store first, then ambient fallbacks such as the
108
+ * process environment and `.env` files. One seam-wide rule binds that half: an
109
+ * empty stored value is absent everywhere — `resolve` skips it, `describe`
110
+ * reports it unconfigured — so a blank never masquerades as a configured
111
+ * secret.
112
+ *
113
+ * A {@link CredentialKey} answers "what credential does this plugin hold for
114
+ * this id". Nothing can layer here — an authorization grant has no
115
+ * environment to be read from — so presence of the record is the whole fact,
116
+ * and {@link modifyRecord} is the only write path because a correct write
117
+ * depends on the current value (a token refresh is read-decide-replace under
118
+ * one lock).
119
+ */
120
+ export declare abstract class CredentialProvider extends Service {
121
+ constructor(ctx: Context);
122
+ /**
123
+ * Resolve one reference to its current value. Resolution is per call:
124
+ * consumers re-resolve at each operation and must not cache across
125
+ * operations — that per-operation read is what makes a changed credential
126
+ * reach the next operation without a restart.
127
+ * @param ref - the reference to resolve.
128
+ * @returns the value and its source, or `undefined` while unconfigured.
129
+ */
130
+ abstract resolve(ref: CredentialRef): Promise<ResolvedCredential | undefined>;
131
+ /**
132
+ * Describe one reference for configuration surfaces without exposing the
133
+ * full value.
134
+ * @param ref - the reference to describe.
135
+ * @returns configured state, supplying source, writability, and optional masked preview.
136
+ */
137
+ abstract describe(ref: CredentialRef): Promise<CredentialInfo>;
138
+ /**
139
+ * Durably store one value in the provider-managed writable source. The stored
140
+ * value takes precedence over ambient fallbacks, and empty values are
141
+ * rejected (use {@link unset}).
142
+ * @param ref - the reference to store.
143
+ * @param value - the non-empty secret value.
144
+ */
145
+ abstract set(ref: CredentialRef, value: string): Promise<void>;
146
+ /**
147
+ * Remove one reference from the provider-managed writable source; removing
148
+ * an absent reference is a no-op. Ambient fallback layers may become
149
+ * effective again after removal.
150
+ * @param ref - the reference to remove.
151
+ */
152
+ abstract unset(ref: CredentialRef): Promise<void>;
153
+ /**
154
+ * Read one stored record. The value is returned as its owner wrote it; a
155
+ * {@link GrantRecord} payload is not interpreted on the way out.
156
+ * @param key - the record to read.
157
+ * @returns the record, or `undefined` while none is stored.
158
+ */
159
+ abstract readRecord(key: CredentialKey): Promise<CredentialRecord | undefined>;
160
+ /**
161
+ * Describe one record for configuration surfaces without exposing its value.
162
+ * @param key - the record to describe.
163
+ * @returns presence, discriminant, and writability.
164
+ */
165
+ abstract describeRecord(key: CredentialKey): Promise<CredentialRecordInfo>;
166
+ /**
167
+ * Enumerate every stored record's address and tag. Unlike the reference
168
+ * half, which has no enumeration because configuration surfaces learn which
169
+ * references exist from settings schemas, records have no such discovery
170
+ * path: a surface that cannot list them cannot show what a user is
171
+ * authorized for, nor find an orphan left by an uninstalled plugin.
172
+ * @returns every stored record, values excluded.
173
+ */
174
+ abstract listRecords(): Promise<readonly CredentialRecordEntry[]>;
175
+ /**
176
+ * Serialized read-modify-write over one record — the only write path.
177
+ * `mutate` sees the record as it stands at the moment the write is
178
+ * exclusive, and returning `undefined` leaves the entry untouched. Exclusion
179
+ * holds across processes where the backing store supports it, which is what
180
+ * makes a token refresh safe: two processes rotating one refresh token
181
+ * concurrently would otherwise lose whichever wrote first.
182
+ * @param key - the record to modify.
183
+ * @param mutate - receives the current record and returns its replacement, or `undefined` to leave it.
184
+ * @returns the record after the write, or the current one when `mutate` declined.
185
+ */
186
+ abstract modifyRecord(key: CredentialKey, mutate: (current: CredentialRecord | undefined) => Promise<CredentialRecord | undefined>): Promise<CredentialRecord | undefined>;
187
+ /**
188
+ * Remove one record; removing an absent record is a no-op.
189
+ * @param key - the record to remove.
190
+ */
191
+ abstract deleteRecord(key: CredentialKey): Promise<void>;
192
+ /**
193
+ * Fan `credentials/reference-updated` out with contained listener failures: every
194
+ * listener runs, and a sync throw or async rejection is logged without
195
+ * changing the committed operation's outcome. Providers call this only after the write or
196
+ * reload actually committed, so a broken observer can never make a durable
197
+ * change look failed.
198
+ * @param ref - the reference whose stored value changed.
199
+ */
200
+ protected notifyUpdated(ref: CredentialRef): void;
201
+ /**
202
+ * Fan `credentials/record-updated` out on exactly the terms
203
+ * {@link notifyUpdated} documents, for the record half of the seam.
204
+ * @param key - the record whose stored value changed.
205
+ */
206
+ protected notifyRecordUpdated(key: CredentialKey): void;
207
+ /** The contained dispatch both notifications run through; see {@link notifyUpdated}. */
208
+ private fanOut;
209
+ /** Contained-listener diagnostic shared by the sync and async failure paths. */
210
+ private warnListenerFailure;
211
+ }
212
+ export default CredentialProvider;
213
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAEjD,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAEhG,YAAY,EACV,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,gBAAgB,EAAE,aAAa,EAAE,WAAW,GAC1F,MAAM,YAAY,CAAA;AAOnB;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAK1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE1D;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,aAAa,CAOtE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,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;;;;OAKG;IACH,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAEjD;;;;;OAKG;IACH,QAAQ,CAAC,UAAU,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAE9E;;;;OAIG;IACH,QAAQ,CAAC,cAAc,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAE1E;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,IAAI,OAAO,CAAC,SAAS,qBAAqB,EAAE,CAAC;IAEjE;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,YAAY,CACnB,GAAG,EAAE,aAAa,EAClB,MAAM,EAAE,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,KAAK,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC,GACvF,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAExC;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,GAAG,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;IAExD;;;;;;;OAOG;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI;IAIjD;;;;OAIG;IACH,SAAS,CAAC,mBAAmB,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI;IAOvD,wFAAwF;IACxF,OAAO,CAAC,MAAM;IAiBd,gFAAgF;IAChF,OAAO,CAAC,mBAAmB;CAI5B;AAED,eAAe,kBAAkB,CAAA"}
@@ -0,0 +1,169 @@
1
+ /**
2
+ * Service Definition for the credential-reference capability seam (`ctx.credentials`). Settings and composition files carry
3
+ * *references* to secrets — environment-variable names — while providers own
4
+ * the actual values and their storage. Consumers resolve a reference once per
5
+ * operation, so a changed credential reaches the next operation without any
6
+ * plugin restart, and configuration surfaces describe a reference without
7
+ * ever seeing its full value.
8
+ * @module @open33/harness-credentials
9
+ */
10
+ import { Service } from '@open33/cordis';
11
+ import { brandString } from '@open33/harness-brand';
12
+ const REF_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
13
+ /** Both halves of a {@link CredentialKey}; the `/` between them is what keeps it out of {@link REF_PATTERN}. */
14
+ const KEY_SEGMENT_PATTERN = /^[a-z][a-z0-9-]*$/;
15
+ /**
16
+ * Brand a raw string as a {@link CredentialRef}.
17
+ * @param value - candidate reference; a POSIX shell identifier such as `OPEN33_API_KEY`.
18
+ * @returns the branded reference.
19
+ */
20
+ export function credentialRef(value) {
21
+ if (!isCredentialRefName(value)) {
22
+ throw new TypeError(`credential ref "${value}" must match ${String(REF_PATTERN)}`);
23
+ }
24
+ return brandString(value);
25
+ }
26
+ /**
27
+ * Whether a raw string could name a reference at all. Consumers that receive
28
+ * environment-variable names from somewhere else — a provider library's own
29
+ * ambient discovery, a hook payload — ask this before resolving, because a name
30
+ * outside the grammar has no reference to miss and should read as "not set"
31
+ * rather than as a thrown error.
32
+ * @param value - candidate reference.
33
+ * @returns true when {@link credentialRef} would accept it.
34
+ */
35
+ export function isCredentialRefName(value) {
36
+ return REF_PATTERN.test(value);
37
+ }
38
+ /**
39
+ * Whether a raw string could be a {@link credentialKey} segment at all.
40
+ * Consumers whose addressing units come from somewhere else — a settings dict
41
+ * key, a library's own provider id — ask this before building a key, because a
42
+ * unit outside the grammar can never have stored a record and should read as
43
+ * "nothing stored" rather than as a thrown error.
44
+ * @param value - candidate segment.
45
+ * @returns true when {@link credentialKey} would accept it as either segment.
46
+ */
47
+ export function isCredentialKeySegment(value) {
48
+ return KEY_SEGMENT_PATTERN.test(value);
49
+ }
50
+ /**
51
+ * Brand a scope and an id as a {@link CredentialKey}.
52
+ * @param scope - the owning plugin's registered name, such as `llm-pi-ai`.
53
+ * @param id - that plugin's own addressing unit, such as a provider route key.
54
+ * @returns the branded key.
55
+ * @throws TypeError when either segment is not a lowercase hyphenated identifier.
56
+ */
57
+ export function credentialKey(scope, id) {
58
+ for (const segment of [scope, id]) {
59
+ if (!KEY_SEGMENT_PATTERN.test(segment)) {
60
+ throw new TypeError(`credential key segment "${segment}" must match ${String(KEY_SEGMENT_PATTERN)}`);
61
+ }
62
+ }
63
+ return brandString(`${scope}/${id}`);
64
+ }
65
+ /**
66
+ * Brand a stored `<scope>/<id>` string as a {@link CredentialKey}. This is the
67
+ * read half of {@link credentialKey}, for a provider admitting keys off disk.
68
+ * @param value - candidate key in its joined form.
69
+ * @returns the branded key.
70
+ * @throws TypeError when the value is not exactly two valid segments.
71
+ */
72
+ export function parseCredentialKey(value) {
73
+ const segments = value.split('/');
74
+ const [scope, id] = segments;
75
+ if (segments.length !== 2 || scope === undefined || id === undefined) {
76
+ throw new TypeError(`credential key "${value}" must be "<scope>/<id>"`);
77
+ }
78
+ return credentialKey(scope, id);
79
+ }
80
+ /**
81
+ * The owning plugin's name for one key. A record whose scope names no
82
+ * currently registered owner is an orphan, which a configuration surface must
83
+ * report as such rather than as a working credential.
84
+ * @param key - the key to read.
85
+ * @returns the scope segment.
86
+ */
87
+ export function credentialKeyScope(key) {
88
+ // The brand's only constructors both validate two segments, so the split
89
+ // cannot come back short here.
90
+ return key.slice(0, key.indexOf('/'));
91
+ }
92
+ /**
93
+ * The owning plugin's own addressing unit for one key — the half that plugin
94
+ * chose, such as a provider route.
95
+ * @param key - the key to read.
96
+ * @returns the id segment.
97
+ */
98
+ export function credentialKeyId(key) {
99
+ return key.slice(key.indexOf('/') + 1);
100
+ }
101
+ /**
102
+ * Abstract credential service over two key spaces that answer two questions.
103
+ *
104
+ * A {@link CredentialRef} answers "what is behind this environment-variable
105
+ * name": the provider-managed store first, then ambient fallbacks such as the
106
+ * process environment and `.env` files. One seam-wide rule binds that half: an
107
+ * empty stored value is absent everywhere — `resolve` skips it, `describe`
108
+ * reports it unconfigured — so a blank never masquerades as a configured
109
+ * secret.
110
+ *
111
+ * A {@link CredentialKey} answers "what credential does this plugin hold for
112
+ * this id". Nothing can layer here — an authorization grant has no
113
+ * environment to be read from — so presence of the record is the whole fact,
114
+ * and {@link modifyRecord} is the only write path because a correct write
115
+ * depends on the current value (a token refresh is read-decide-replace under
116
+ * one lock).
117
+ */
118
+ export class CredentialProvider extends Service {
119
+ constructor(ctx) {
120
+ super(ctx, 'credentials');
121
+ }
122
+ /**
123
+ * Fan `credentials/reference-updated` out with contained listener failures: every
124
+ * listener runs, and a sync throw or async rejection is logged without
125
+ * changing the committed operation's outcome. Providers call this only after the write or
126
+ * reload actually committed, so a broken observer can never make a durable
127
+ * change look failed.
128
+ * @param ref - the reference whose stored value changed.
129
+ */
130
+ notifyUpdated(ref) {
131
+ this.fanOut('credentials/reference-updated', ref);
132
+ }
133
+ /**
134
+ * Fan `credentials/record-updated` out on exactly the terms
135
+ * {@link notifyUpdated} documents, for the record half of the seam.
136
+ * @param key - the record whose stored value changed.
137
+ */
138
+ notifyRecordUpdated(key) {
139
+ this.fanOut('credentials/record-updated', key);
140
+ }
141
+ /* jscpd:ignore-start -- deliberate symmetry with the settings seam's commit
142
+ fan-out: the contained-dispatch shape is the reviewed listener-lifecycle
143
+ contract, and extracting it would couple the two seams' event semantics. */
144
+ /** The contained dispatch both notifications run through; see {@link notifyUpdated}. */
145
+ fanOut(event, subject) {
146
+ const args = [event, subject];
147
+ for (const listener of this.ctx.events.dispatch('emit', args)) {
148
+ try {
149
+ const returned = listener(subject);
150
+ if (returned != null && typeof returned.then === 'function') {
151
+ void Promise.resolve(returned).then(undefined, (error) => {
152
+ this.warnListenerFailure(event, subject, error);
153
+ });
154
+ }
155
+ }
156
+ catch (error) {
157
+ this.warnListenerFailure(event, subject, error);
158
+ }
159
+ }
160
+ }
161
+ /* jscpd:ignore-end */
162
+ /** Contained-listener diagnostic shared by the sync and async failure paths. */
163
+ warnListenerFailure(event, subject, error) {
164
+ this.ctx.logger.warn('credentials: a %s listener for "%s" failed', event, subject);
165
+ this.ctx.logger.warn(error);
166
+ }
167
+ }
168
+ export default CredentialProvider;
169
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1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,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAC7B,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAmD,EAAE,CAAC;YAChH,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAA;gBAClC,IAAI,QAAQ,IAAI,IAAI,IAAI,OAAQ,QAAiC,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;oBACtF,KAAK,OAAO,CAAC,OAAO,CAAC,QAAgC,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,KAAc,EAAE,EAAE;wBACxF,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;oBACjD,CAAC,CAAC,CAAA;gBACJ,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,CAAA;YACjD,CAAC;QACH,CAAC;IACH,CAAC;IACD,sBAAsB;IAEtB,gFAAgF;IACxE,mBAAmB,CAAC,KAAa,EAAE,OAAe,EAAE,KAAc;QACxE,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,4CAA4C,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;QAClF,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAC7B,CAAC;CACF;AAED,eAAe,kBAAkB,CAAA"}
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Client-safe type surface of the credential seam: the two key brands, the
3
+ * stored-record union, the reference view crossing the Remote wire, and the
4
+ * seam's Cordis event declarations. Types only — no runtime code, and nothing
5
+ * here reaches a Host-only symbol, so a Client compilation face reads exactly
6
+ * the signature the Host emits.
7
+ *
8
+ * @module @open33/harness-credentials/types
9
+ */
10
+ import type { Branded } from '@open33/harness-brand';
11
+ /** Nominal reference to one credential: a POSIX-style environment-variable name. */
12
+ export type CredentialRef = Branded<'CredentialRef'>;
13
+ /**
14
+ * Nominal address of one stored credential record: `<scope>/<id>`, where
15
+ * `scope` is the registered name of the plugin that owns the record and `id`
16
+ * is that plugin's own addressing unit (an LLM adapter uses its provider route
17
+ * key).
18
+ *
19
+ * The scope is the owner rather than the domain because a record's payload is
20
+ * written in its owner's format: two plugins serving the same provider name
21
+ * would otherwise read each other's payload, and a record left behind by an
22
+ * uninstalled plugin could not be told apart from a live one. The `/` also
23
+ * keeps this grammar disjoint from {@link CredentialRef}, so the two key
24
+ * spaces can never collide.
25
+ */
26
+ export type CredentialKey = Branded<'CredentialKey'>;
27
+ /**
28
+ * A credential the harness itself understands: an api key, provider
29
+ * environment values, or both. Either field may be absent — a record carrying
30
+ * neither states that the owner confirmed this route authenticates from its
31
+ * own ambient discovery, which is a different fact from having no record.
32
+ */
33
+ export interface ApiKeyRecord {
34
+ /** Discriminant. */
35
+ readonly kind: 'api-key';
36
+ /** The non-empty secret value, when this credential is a key at all. */
37
+ readonly key?: string;
38
+ /** Provider environment values such as `AWS_PROFILE`; names are POSIX identifiers. */
39
+ readonly env?: Readonly<Record<string, string>>;
40
+ }
41
+ /**
42
+ * The product of one authorization grant, kept verbatim for its owner. The
43
+ * seam never reads, validates, or reshapes {@link payload}: it is written in
44
+ * the owning plugin's format and only that plugin can interpret it. The single
45
+ * constraint is that it survives a JSON round trip.
46
+ */
47
+ export interface GrantRecord {
48
+ /** Discriminant. */
49
+ readonly kind: 'grant';
50
+ /** Owner-defined JSON value; opaque to the seam and to every other plugin. */
51
+ readonly payload: unknown;
52
+ }
53
+ /** One durable credential record, tagged by what the seam may do with it. */
54
+ export type CredentialRecord = ApiKeyRecord | GrantRecord;
55
+ /**
56
+ * Configuration facts and an optional provider-masked preview for one
57
+ * reference. The full credential is never part of this view.
58
+ */
59
+ export interface CredentialInfo {
60
+ /** Whether resolving the reference would currently return a value. */
61
+ configured: boolean;
62
+ /** Source layer currently supplying the value; absent while unconfigured. */
63
+ source?: string;
64
+ /** Whether the active provider can write this reference. */
65
+ writable: boolean;
66
+ /** Provider-generated masked preview of a stored value; never the full value. */
67
+ masked?: string;
68
+ }
69
+ declare module '@open33/cordis' {
70
+ interface Events {
71
+ /**
72
+ * Committed change to a provider-managed credential source: a `set`, an
73
+ * `unset`, or an external edit observed in storage. Ambient
74
+ * process-environment changes are not observable and never emit. Listener
75
+ * failures are contained and logged — a sync throw and an async rejection
76
+ * alike — without changing the committed operation's outcome.
77
+ * @param ref - the reference whose stored value changed.
78
+ * @mode emit
79
+ */
80
+ 'credentials/reference-updated'(ref: CredentialRef): void;
81
+ /**
82
+ * Committed change to a stored credential record: a `modifyRecord` that
83
+ * wrote, a `deleteRecord` that removed, or an external edit observed in
84
+ * storage. Separate from `credentials/reference-updated` because the two key
85
+ * grammars are disjoint — a listener that received both on one event could
86
+ * not tell which space a subject belongs to. Listener failures are
87
+ * contained on the same terms as `credentials/reference-updated`.
88
+ * @param key - the record whose stored value changed.
89
+ * @mode emit
90
+ */
91
+ 'credentials/record-updated'(key: CredentialKey): void;
92
+ }
93
+ }
94
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAEpD,oFAAoF;AACpF,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAEpD;;;;;;;;;;;;GAYG;AACH,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAEpD;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,oBAAoB;IACpB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;IACxB,wEAAwE;IACxE,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAA;IACrB,sFAAsF;IACtF,QAAQ,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAChD;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,oBAAoB;IACpB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;IACtB,8EAA8E;IAC9E,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;CAC1B;AAED,6EAA6E;AAC7E,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG,WAAW,CAAA;AAEzD;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,sEAAsE;IACtE,UAAU,EAAE,OAAO,CAAA;IACnB,6EAA6E;IAC7E,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,4DAA4D;IAC5D,QAAQ,EAAE,OAAO,CAAA;IACjB,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,OAAO,QAAQ,gBAAgB,CAAC;IAC9B,UAAU,MAAM;QACd;;;;;;;;WAQG;QACH,+BAA+B,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAAA;QAEzD;;;;;;;;;WASG;QACH,4BAA4B,CAAC,GAAG,EAAE,aAAa,GAAG,IAAI,CAAA;KACvD;CACF"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Client-safe type surface of the credential seam: the two key brands, the
3
+ * stored-record union, the reference view crossing the Remote wire, and the
4
+ * seam's Cordis event declarations. Types only — no runtime code, and nothing
5
+ * here reaches a Host-only symbol, so a Client compilation face reads exactly
6
+ * the signature the Host emits.
7
+ *
8
+ * @module @open33/harness-credentials/types
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
2
  "name": "@open33/harness-credentials",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "description": "Abstract credential seam (ctx.credentials): settings carry references to secrets, providers own the values",
4
+ "version": "0.1.0",
5
+ "publishConfig": {
6
+ "access": "public"
7
+ },
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/open33ofc/open33.git",
11
+ "directory": "packages/credentials/credentials"
12
+ },
13
+ "type": "module",
14
+ "main": "lib/index.js",
15
+ "types": "lib/types/index.d.ts",
16
+ "exports": {
17
+ ".": {
18
+ "types": "./lib/types/index.d.ts",
19
+ "default": "./lib/index.js"
20
+ },
21
+ "./types": {
22
+ "types": "./lib/types/types.d.ts",
23
+ "default": "./lib/types/types.js"
24
+ },
25
+ "./src/*": "./src/*",
26
+ "./package.json": "./package.json"
27
+ },
28
+ "files": [
29
+ "lib/index.js",
30
+ "lib/types/**/*.js",
31
+ "lib/types/**/*.d.ts",
32
+ "lib/types/**/*.d.ts.map",
33
+ "lib/**/*.js.map",
34
+ "src"
35
+ ],
36
+ "license": "MIT",
37
+ "peerDependencies": {
38
+ "@open33/cordis": "~4.1.0"
39
+ },
40
+ "devDependencies": {
41
+ "@open33/cordis": "~4.1.0"
42
+ },
43
+ "dependencies": {
44
+ "@open33/harness-brand": "0.1.0"
45
+ }
6
46
  }