@clef-sh/runtime 0.1.6-beta.32
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/dist/decrypt.d.ts +25 -0
- package/dist/decrypt.d.ts.map +1 -0
- package/dist/decrypt.js +82 -0
- package/dist/decrypt.js.map +1 -0
- package/dist/disk-cache.d.ts +22 -0
- package/dist/disk-cache.d.ts.map +1 -0
- package/dist/disk-cache.js +113 -0
- package/dist/disk-cache.js.map +1 -0
- package/dist/index.d.ts +96 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +165 -0
- package/dist/index.js.map +1 -0
- package/dist/kms/aws.d.ts +15 -0
- package/dist/kms/aws.d.ts.map +1 -0
- package/dist/kms/aws.js +92 -0
- package/dist/kms/aws.js.map +1 -0
- package/dist/kms/azure.d.ts +16 -0
- package/dist/kms/azure.d.ts.map +1 -0
- package/dist/kms/azure.js +85 -0
- package/dist/kms/azure.js.map +1 -0
- package/dist/kms/gcp.d.ts +17 -0
- package/dist/kms/gcp.d.ts.map +1 -0
- package/dist/kms/gcp.js +87 -0
- package/dist/kms/gcp.js.map +1 -0
- package/dist/kms/index.d.ts +12 -0
- package/dist/kms/index.d.ts.map +1 -0
- package/dist/kms/index.js +29 -0
- package/dist/kms/index.js.map +1 -0
- package/dist/kms/types.d.ts +10 -0
- package/dist/kms/types.d.ts.map +1 -0
- package/dist/kms/types.js +3 -0
- package/dist/kms/types.js.map +1 -0
- package/dist/poller.d.ts +80 -0
- package/dist/poller.d.ts.map +1 -0
- package/dist/poller.js +329 -0
- package/dist/poller.js.map +1 -0
- package/dist/secrets-cache.d.ts +23 -0
- package/dist/secrets-cache.d.ts.map +1 -0
- package/dist/secrets-cache.js +51 -0
- package/dist/secrets-cache.js.map +1 -0
- package/dist/sources/file.d.ts +9 -0
- package/dist/sources/file.d.ts.map +1 -0
- package/dist/sources/file.js +53 -0
- package/dist/sources/file.js.map +1 -0
- package/dist/sources/http.d.ts +9 -0
- package/dist/sources/http.d.ts.map +1 -0
- package/dist/sources/http.js +24 -0
- package/dist/sources/http.js.map +1 -0
- package/dist/sources/index.d.ts +5 -0
- package/dist/sources/index.d.ts.map +1 -0
- package/dist/sources/index.js +10 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/types.d.ts +15 -0
- package/dist/sources/types.d.ts.map +1 -0
- package/dist/sources/types.js +3 -0
- package/dist/sources/types.js.map +1 -0
- package/dist/sources/vcs.d.ts +13 -0
- package/dist/sources/vcs.d.ts.map +1 -0
- package/dist/sources/vcs.js +25 -0
- package/dist/sources/vcs.js.map +1 -0
- package/dist/telemetry.d.ts +129 -0
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +192 -0
- package/dist/telemetry.js.map +1 -0
- package/dist/vcs/bitbucket.d.ts +11 -0
- package/dist/vcs/bitbucket.d.ts.map +1 -0
- package/dist/vcs/bitbucket.js +43 -0
- package/dist/vcs/bitbucket.js.map +1 -0
- package/dist/vcs/github.d.ts +11 -0
- package/dist/vcs/github.d.ts.map +1 -0
- package/dist/vcs/github.js +35 -0
- package/dist/vcs/github.js.map +1 -0
- package/dist/vcs/gitlab.d.ts +11 -0
- package/dist/vcs/gitlab.d.ts.map +1 -0
- package/dist/vcs/gitlab.js +36 -0
- package/dist/vcs/gitlab.js.map +1 -0
- package/dist/vcs/index.d.ts +8 -0
- package/dist/vcs/index.d.ts.map +1 -0
- package/dist/vcs/index.js +27 -0
- package/dist/vcs/index.js.map +1 -0
- package/dist/vcs/types.d.ts +29 -0
- package/dist/vcs/types.d.ts.map +1 -0
- package/dist/vcs/types.js +3 -0
- package/dist/vcs/types.js.map +1 -0
- package/package.json +41 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/** Base fields present on every telemetry event. */
|
|
2
|
+
interface TelemetryEventBase {
|
|
3
|
+
type: string;
|
|
4
|
+
timestamp: string;
|
|
5
|
+
agentId: string;
|
|
6
|
+
identity: string;
|
|
7
|
+
environment: string;
|
|
8
|
+
sourceType: string;
|
|
9
|
+
}
|
|
10
|
+
export interface AgentStartedEvent extends TelemetryEventBase {
|
|
11
|
+
type: "agent.started";
|
|
12
|
+
version: string;
|
|
13
|
+
}
|
|
14
|
+
export interface AgentStoppedEvent extends TelemetryEventBase {
|
|
15
|
+
type: "agent.stopped";
|
|
16
|
+
reason: "signal" | "error" | "lambda_shutdown";
|
|
17
|
+
uptimeSeconds: number;
|
|
18
|
+
}
|
|
19
|
+
export interface ArtifactRefreshedEvent extends TelemetryEventBase {
|
|
20
|
+
type: "artifact.refreshed";
|
|
21
|
+
revision: string;
|
|
22
|
+
keyCount: number;
|
|
23
|
+
kmsEnvelope: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface ArtifactRevokedEvent extends TelemetryEventBase {
|
|
26
|
+
type: "artifact.revoked";
|
|
27
|
+
revokedAt: string;
|
|
28
|
+
}
|
|
29
|
+
export interface ArtifactExpiredEvent extends TelemetryEventBase {
|
|
30
|
+
type: "artifact.expired";
|
|
31
|
+
expiresAt: string;
|
|
32
|
+
}
|
|
33
|
+
export interface FetchFailedEvent extends TelemetryEventBase {
|
|
34
|
+
type: "fetch.failed";
|
|
35
|
+
error: string;
|
|
36
|
+
diskCacheAvailable: boolean;
|
|
37
|
+
}
|
|
38
|
+
export interface CacheExpiredEvent extends TelemetryEventBase {
|
|
39
|
+
type: "cache.expired";
|
|
40
|
+
cacheTtlSeconds: number;
|
|
41
|
+
diskCachePurged: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface ArtifactInvalidEvent extends TelemetryEventBase {
|
|
44
|
+
type: "artifact.invalid";
|
|
45
|
+
reason: string;
|
|
46
|
+
error: string;
|
|
47
|
+
}
|
|
48
|
+
/** Discriminated union of all telemetry event types. */
|
|
49
|
+
export type TelemetryEvent = AgentStartedEvent | AgentStoppedEvent | ArtifactRefreshedEvent | ArtifactRevokedEvent | ArtifactExpiredEvent | FetchFailedEvent | CacheExpiredEvent | ArtifactInvalidEvent;
|
|
50
|
+
/** Configuration for the telemetry emitter. */
|
|
51
|
+
export interface TelemetryOptions {
|
|
52
|
+
/** OTLP HTTP endpoint (e.g. `http://localhost:4318/v1/logs`). */
|
|
53
|
+
url: string;
|
|
54
|
+
/** Custom HTTP headers for the OTLP endpoint (e.g. `{ Authorization: "Bearer ..." }` or `{ "DD-API-KEY": "..." }`). */
|
|
55
|
+
headers?: Record<string, string>;
|
|
56
|
+
/** Service version — used in OTLP resource and scope. */
|
|
57
|
+
version: string;
|
|
58
|
+
/** Unique agent/instance ID. */
|
|
59
|
+
agentId: string;
|
|
60
|
+
/** Service identity name. */
|
|
61
|
+
identity: string;
|
|
62
|
+
/** Target environment. */
|
|
63
|
+
environment: string;
|
|
64
|
+
/** Source type: `"vcs"`, `"http"`, or `"file"`. */
|
|
65
|
+
sourceType: string;
|
|
66
|
+
/** Flush interval in milliseconds. Default: 10_000 (10s). */
|
|
67
|
+
flushIntervalMs?: number;
|
|
68
|
+
/** Max buffered events before auto-flush. Default: 50. */
|
|
69
|
+
maxBufferSize?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Telemetry emitter that buffers events and delivers them as OTLP LogRecords
|
|
73
|
+
* via HTTP POST to any OTLP-compatible endpoint.
|
|
74
|
+
*
|
|
75
|
+
* Zero external dependencies — uses built-in `fetch()` and hand-constructed
|
|
76
|
+
* OTLP JSON (no protobuf, no SDK).
|
|
77
|
+
*
|
|
78
|
+
* All event methods are fire-and-forget — telemetry never disrupts the critical path.
|
|
79
|
+
*/
|
|
80
|
+
export declare class TelemetryEmitter {
|
|
81
|
+
private buffer;
|
|
82
|
+
private timer;
|
|
83
|
+
private readonly opts;
|
|
84
|
+
private readonly maxBufferSize;
|
|
85
|
+
constructor(options: TelemetryOptions);
|
|
86
|
+
agentStarted(fields: {
|
|
87
|
+
version: string;
|
|
88
|
+
}): void;
|
|
89
|
+
agentStopped(fields: {
|
|
90
|
+
reason: AgentStoppedEvent["reason"];
|
|
91
|
+
uptimeSeconds: number;
|
|
92
|
+
}): void;
|
|
93
|
+
artifactRefreshed(fields: {
|
|
94
|
+
revision: string;
|
|
95
|
+
keyCount: number;
|
|
96
|
+
kmsEnvelope: boolean;
|
|
97
|
+
}): void;
|
|
98
|
+
artifactRevoked(fields: {
|
|
99
|
+
revokedAt: string;
|
|
100
|
+
}): void;
|
|
101
|
+
artifactExpired(fields: {
|
|
102
|
+
expiresAt: string;
|
|
103
|
+
}): void;
|
|
104
|
+
fetchFailed(fields: {
|
|
105
|
+
error: string;
|
|
106
|
+
diskCacheAvailable: boolean;
|
|
107
|
+
}): void;
|
|
108
|
+
cacheExpired(fields: {
|
|
109
|
+
cacheTtlSeconds: number;
|
|
110
|
+
diskCachePurged: boolean;
|
|
111
|
+
}): void;
|
|
112
|
+
artifactInvalid(fields: {
|
|
113
|
+
reason: string;
|
|
114
|
+
error: string;
|
|
115
|
+
}): void;
|
|
116
|
+
/** Fire-and-forget flush of the current buffer. */
|
|
117
|
+
flush(): void;
|
|
118
|
+
/** Awaitable flush for graceful shutdown. */
|
|
119
|
+
flushAsync(): Promise<void>;
|
|
120
|
+
/** Stop the flush timer and fire-and-forget remaining events. */
|
|
121
|
+
stop(): void;
|
|
122
|
+
/** Stop the flush timer and await final flush. */
|
|
123
|
+
stopAsync(): Promise<void>;
|
|
124
|
+
private emit;
|
|
125
|
+
/** Convert a batch of TelemetryEvents to an OTLP ExportLogsServiceRequest JSON string. */
|
|
126
|
+
private toOtlpPayload;
|
|
127
|
+
}
|
|
128
|
+
export {};
|
|
129
|
+
//# sourceMappingURL=telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.d.ts","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,UAAU,kBAAkB;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAA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E,GAAG,IAAI;IAIpD,eAAe,CAAC,MAAM,EAAE;QAAE,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAIpD,WAAW,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,kBAAkB,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAIzE,YAAY,CAAC,MAAM,EAAE;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI;IAIjF,eAAe,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI;IAIhE,mDAAmD;IACnD,KAAK,IAAI,IAAI;IAcb,6CAA6C;IACvC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAgBjC,iEAAiE;IACjE,IAAI,IAAI,IAAI;IAQZ,kDAAkD;IAC5C,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC;IAQhC,OAAO,CAAC,IAAI;IAmBZ,0FAA0F;IAC1F,OAAO,CAAC,aAAa;CA+CtB"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TelemetryEmitter = void 0;
|
|
4
|
+
/** OTLP severity levels by event type. */
|
|
5
|
+
const SEVERITY = {
|
|
6
|
+
"agent.started": { number: 9, text: "INFO" },
|
|
7
|
+
"agent.stopped": { number: 9, text: "INFO" },
|
|
8
|
+
"artifact.refreshed": { number: 9, text: "INFO" },
|
|
9
|
+
"artifact.revoked": { number: 13, text: "WARN" },
|
|
10
|
+
"artifact.expired": { number: 13, text: "WARN" },
|
|
11
|
+
"fetch.failed": { number: 13, text: "WARN" },
|
|
12
|
+
"cache.expired": { number: 17, text: "ERROR" },
|
|
13
|
+
"artifact.invalid": { number: 17, text: "ERROR" },
|
|
14
|
+
};
|
|
15
|
+
/** Base fields that belong in the OTLP resource, not per-record attributes. */
|
|
16
|
+
const BASE_FIELDS = new Set([
|
|
17
|
+
"type",
|
|
18
|
+
"timestamp",
|
|
19
|
+
"agentId",
|
|
20
|
+
"identity",
|
|
21
|
+
"environment",
|
|
22
|
+
"sourceType",
|
|
23
|
+
]);
|
|
24
|
+
/** Convert a value to an OTLP typed attribute value. */
|
|
25
|
+
function otlpValue(v) {
|
|
26
|
+
if (typeof v === "boolean")
|
|
27
|
+
return { boolValue: v };
|
|
28
|
+
if (typeof v === "number")
|
|
29
|
+
return { intValue: String(v) };
|
|
30
|
+
return { stringValue: String(v) };
|
|
31
|
+
}
|
|
32
|
+
/** Convert ISO-8601 timestamp to nanosecond Unix epoch string. */
|
|
33
|
+
function isoToUnixNano(iso) {
|
|
34
|
+
return String(new Date(iso).getTime() * 1_000_000);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Telemetry emitter that buffers events and delivers them as OTLP LogRecords
|
|
38
|
+
* via HTTP POST to any OTLP-compatible endpoint.
|
|
39
|
+
*
|
|
40
|
+
* Zero external dependencies — uses built-in `fetch()` and hand-constructed
|
|
41
|
+
* OTLP JSON (no protobuf, no SDK).
|
|
42
|
+
*
|
|
43
|
+
* All event methods are fire-and-forget — telemetry never disrupts the critical path.
|
|
44
|
+
*/
|
|
45
|
+
class TelemetryEmitter {
|
|
46
|
+
buffer = [];
|
|
47
|
+
timer = null;
|
|
48
|
+
opts;
|
|
49
|
+
maxBufferSize;
|
|
50
|
+
constructor(options) {
|
|
51
|
+
this.opts = options;
|
|
52
|
+
this.maxBufferSize = options.maxBufferSize ?? 50;
|
|
53
|
+
const intervalMs = options.flushIntervalMs ?? 10_000;
|
|
54
|
+
this.timer = setInterval(() => this.flush(), intervalMs);
|
|
55
|
+
this.timer.unref();
|
|
56
|
+
}
|
|
57
|
+
agentStarted(fields) {
|
|
58
|
+
this.emit({ type: "agent.started", ...fields });
|
|
59
|
+
}
|
|
60
|
+
agentStopped(fields) {
|
|
61
|
+
this.emit({ type: "agent.stopped", ...fields });
|
|
62
|
+
}
|
|
63
|
+
artifactRefreshed(fields) {
|
|
64
|
+
this.emit({ type: "artifact.refreshed", ...fields });
|
|
65
|
+
}
|
|
66
|
+
artifactRevoked(fields) {
|
|
67
|
+
this.emit({ type: "artifact.revoked", ...fields });
|
|
68
|
+
}
|
|
69
|
+
artifactExpired(fields) {
|
|
70
|
+
this.emit({ type: "artifact.expired", ...fields });
|
|
71
|
+
}
|
|
72
|
+
fetchFailed(fields) {
|
|
73
|
+
this.emit({ type: "fetch.failed", ...fields });
|
|
74
|
+
}
|
|
75
|
+
cacheExpired(fields) {
|
|
76
|
+
this.emit({ type: "cache.expired", ...fields });
|
|
77
|
+
}
|
|
78
|
+
artifactInvalid(fields) {
|
|
79
|
+
this.emit({ type: "artifact.invalid", ...fields });
|
|
80
|
+
}
|
|
81
|
+
/** Fire-and-forget flush of the current buffer. */
|
|
82
|
+
flush() {
|
|
83
|
+
if (this.buffer.length === 0)
|
|
84
|
+
return;
|
|
85
|
+
const batch = this.buffer;
|
|
86
|
+
this.buffer = [];
|
|
87
|
+
fetch(this.opts.url, {
|
|
88
|
+
method: "POST",
|
|
89
|
+
headers: { "Content-Type": "application/json", ...this.opts.headers },
|
|
90
|
+
body: this.toOtlpPayload(batch),
|
|
91
|
+
}).catch(() => {
|
|
92
|
+
// Best-effort delivery — telemetry must never disrupt the critical path
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
/** Awaitable flush for graceful shutdown. */
|
|
96
|
+
async flushAsync() {
|
|
97
|
+
if (this.buffer.length === 0)
|
|
98
|
+
return;
|
|
99
|
+
const batch = this.buffer;
|
|
100
|
+
this.buffer = [];
|
|
101
|
+
try {
|
|
102
|
+
await fetch(this.opts.url, {
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: { "Content-Type": "application/json", ...this.opts.headers },
|
|
105
|
+
body: this.toOtlpPayload(batch),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// Best-effort delivery
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** Stop the flush timer and fire-and-forget remaining events. */
|
|
113
|
+
stop() {
|
|
114
|
+
if (this.timer) {
|
|
115
|
+
clearInterval(this.timer);
|
|
116
|
+
this.timer = null;
|
|
117
|
+
}
|
|
118
|
+
this.flush();
|
|
119
|
+
}
|
|
120
|
+
/** Stop the flush timer and await final flush. */
|
|
121
|
+
async stopAsync() {
|
|
122
|
+
if (this.timer) {
|
|
123
|
+
clearInterval(this.timer);
|
|
124
|
+
this.timer = null;
|
|
125
|
+
}
|
|
126
|
+
await this.flushAsync();
|
|
127
|
+
}
|
|
128
|
+
emit(fields) {
|
|
129
|
+
try {
|
|
130
|
+
const event = {
|
|
131
|
+
...fields,
|
|
132
|
+
timestamp: new Date().toISOString(),
|
|
133
|
+
agentId: this.opts.agentId,
|
|
134
|
+
identity: this.opts.identity,
|
|
135
|
+
environment: this.opts.environment,
|
|
136
|
+
sourceType: this.opts.sourceType,
|
|
137
|
+
};
|
|
138
|
+
this.buffer.push(event);
|
|
139
|
+
if (this.buffer.length >= this.maxBufferSize) {
|
|
140
|
+
this.flush();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// Telemetry must never disrupt the critical path
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Convert a batch of TelemetryEvents to an OTLP ExportLogsServiceRequest JSON string. */
|
|
148
|
+
toOtlpPayload(events) {
|
|
149
|
+
const first = events[0];
|
|
150
|
+
const resourceAttributes = [
|
|
151
|
+
{ key: "service.name", value: { stringValue: "clef-agent" } },
|
|
152
|
+
{ key: "service.version", value: { stringValue: this.opts.version } },
|
|
153
|
+
{ key: "clef.agent.id", value: { stringValue: first.agentId } },
|
|
154
|
+
{ key: "clef.identity", value: { stringValue: first.identity } },
|
|
155
|
+
{ key: "clef.environment", value: { stringValue: first.environment } },
|
|
156
|
+
{ key: "clef.source.type", value: { stringValue: first.sourceType } },
|
|
157
|
+
];
|
|
158
|
+
const logRecords = events.map((event) => {
|
|
159
|
+
const severity = SEVERITY[event.type] ?? { number: 9, text: "INFO" };
|
|
160
|
+
const attributes = [
|
|
161
|
+
{ key: "event.name", value: { stringValue: `clef.${event.type}` } },
|
|
162
|
+
];
|
|
163
|
+
for (const [key, val] of Object.entries(event)) {
|
|
164
|
+
if (BASE_FIELDS.has(key))
|
|
165
|
+
continue;
|
|
166
|
+
attributes.push({ key: `clef.${key}`, value: otlpValue(val) });
|
|
167
|
+
}
|
|
168
|
+
return {
|
|
169
|
+
timeUnixNano: isoToUnixNano(event.timestamp),
|
|
170
|
+
severityNumber: severity.number,
|
|
171
|
+
severityText: severity.text,
|
|
172
|
+
body: { stringValue: event.type },
|
|
173
|
+
attributes,
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
return JSON.stringify({
|
|
177
|
+
resourceLogs: [
|
|
178
|
+
{
|
|
179
|
+
resource: { attributes: resourceAttributes },
|
|
180
|
+
scopeLogs: [
|
|
181
|
+
{
|
|
182
|
+
scope: { name: "clef.runtime", version: this.opts.version },
|
|
183
|
+
logRecords,
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
exports.TelemetryEmitter = TelemetryEmitter;
|
|
192
|
+
//# sourceMappingURL=telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"telemetry.js","sourceRoot":"","sources":["../src/telemetry.ts"],"names":[],"mappings":";;;AAyFA,0CAA0C;AAC1C,MAAM,QAAQ,GAAqD;IACjE,eAAe,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5C,eAAe,EAAE,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;IAC5C,oBAAoB,EAAE,EAAE,MAAM,EAAE,CAAC,E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,EAAE,EAAE,WAAW,EAAE,KAAK,CAAC,IAAI,EAAE;gBACjC,UAAU;aACX,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,SAAS,CAAC;YACpB,YAAY,EAAE;gBACZ;oBACE,QAAQ,EAAE,EAAE,UAAU,EAAE,kBAAkB,EAAE;oBAC5C,SAAS,EAAE;wBACT;4BACE,KAAK,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;4BAC3D,UAAU;yBACX;qBACF;iBACF;aACF;SACF,CAAC,CAAC;IACL,CAAC;CACF;AApKD,4CAoKC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { VcsProvider, VcsProviderConfig, VcsFileResult } from "./types";
|
|
2
|
+
/** Bitbucket Source API provider. */
|
|
3
|
+
export declare class BitbucketProvider implements VcsProvider {
|
|
4
|
+
private readonly repo;
|
|
5
|
+
private readonly token;
|
|
6
|
+
private readonly ref;
|
|
7
|
+
private readonly apiUrl;
|
|
8
|
+
constructor(config: VcsProviderConfig);
|
|
9
|
+
fetchFile(path: string): Promise<VcsFileResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=bitbucket.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitbucket.d.ts","sourceRoot":"","sources":["../../src/vcs/bitbucket.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAMxE,qCAAqC;AACrC,qBAAa,iBAAkB,YAAW,WAAW;IACnD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,iBAAiB;IAO/B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAkCtD"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitbucketProvider = void 0;
|
|
4
|
+
/** Bitbucket Source API provider. */
|
|
5
|
+
class BitbucketProvider {
|
|
6
|
+
repo;
|
|
7
|
+
token;
|
|
8
|
+
ref;
|
|
9
|
+
apiUrl;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.repo = config.repo;
|
|
12
|
+
this.token = config.token;
|
|
13
|
+
this.ref = config.ref ?? "main";
|
|
14
|
+
this.apiUrl = config.apiUrl ?? "https://api.bitbucket.org";
|
|
15
|
+
}
|
|
16
|
+
async fetchFile(path) {
|
|
17
|
+
const baseUrl = `${this.apiUrl}/2.0/repositories/${this.repo}/src/${this.ref}/${path}`;
|
|
18
|
+
// Fetch metadata (JSON) for the commit hash
|
|
19
|
+
const metaRes = await fetch(baseUrl, {
|
|
20
|
+
headers: {
|
|
21
|
+
Authorization: `Bearer ${this.token}`,
|
|
22
|
+
Accept: "application/json",
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
if (!metaRes.ok) {
|
|
26
|
+
throw new Error(`Bitbucket API error: ${metaRes.status} fetching ${path} from ${this.repo}`);
|
|
27
|
+
}
|
|
28
|
+
const meta = (await metaRes.json());
|
|
29
|
+
// Fetch raw file content
|
|
30
|
+
const rawRes = await fetch(baseUrl, {
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: `Bearer ${this.token}`,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
if (!rawRes.ok) {
|
|
36
|
+
throw new Error(`Bitbucket API error: ${rawRes.status} fetching raw content of ${path} from ${this.repo}`);
|
|
37
|
+
}
|
|
38
|
+
const content = await rawRes.text();
|
|
39
|
+
return { content, sha: meta.commit.hash };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.BitbucketProvider = BitbucketProvider;
|
|
43
|
+
//# sourceMappingURL=bitbucket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bitbucket.js","sourceRoot":"","sources":["../../src/vcs/bitbucket.ts"],"names":[],"mappings":";;;AAMA,qCAAqC;AACrC,MAAa,iBAAiB;IACX,IAAI,CAAS;IACb,KAAK,CAAS;IACd,GAAG,CAAS;IACZ,MAAM,CAAS;IAEhC,YAAY,MAAyB;QACnC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,IAAI,MAAM,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,2BAA2B,CAAC;IAC7D,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAY;QAC1B,MAAM,OAAO,GAAG,GAAG,IAAI,CAAC,MAAM,qBAAqB,IAAI,CAAC,IAAI,QAAQ,IAAI,CAAC,GAAG,IAAI,IAAI,EAAE,CAAC;QAEvF,4CAA4C;QAC5C,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE;YACnC,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE;gBACrC,MAAM,EAAE,kBAAkB;aAC3B;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;YAChB,MAAM,IAAI,KAAK,CAAC,wBAAwB,OAAO,CAAC,MAAM,aAAa,IAAI,SAAS,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QAC/F,CAAC;QAED,MAAM,IAAI,GAA0B,CAAC,MAAM,OAAO,CAAC,IAAI,EAAE,CAA0B,CAAC;QAEpF,yBAAyB;QACzB,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,EAAE;YAClC,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,CAAC,KAAK,EAAE;aACtC;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,MAAM,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CACb,wBAAwB,MAAM,CAAC,MAAM,4BAA4B,IAAI,SAAS,IAAI,CAAC,IAAI,EAAE,CAC1F,CAAC;QACJ,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAEpC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5C,CAAC;CACF;AA/CD,8CA+CC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { VcsProvider, VcsProviderConfig, VcsFileResult } from "./types";
|
|
2
|
+
/** GitHub Contents API provider. */
|
|
3
|
+
export declare class GitHubProvider implements VcsProvider {
|
|
4
|
+
private readonly repo;
|
|
5
|
+
private readonly token;
|
|
6
|
+
private readonly ref?;
|
|
7
|
+
private readonly apiUrl;
|
|
8
|
+
constructor(config: VcsProviderConfig);
|
|
9
|
+
fetchFile(path: string): Promise<VcsFileResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=github.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../src/vcs/github.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAQxE,oCAAoC;AACpC,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,iBAAiB;IAO/B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAoBtD"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GitHubProvider = void 0;
|
|
4
|
+
/** GitHub Contents API provider. */
|
|
5
|
+
class GitHubProvider {
|
|
6
|
+
repo;
|
|
7
|
+
token;
|
|
8
|
+
ref;
|
|
9
|
+
apiUrl;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.repo = config.repo;
|
|
12
|
+
this.token = config.token;
|
|
13
|
+
this.ref = config.ref;
|
|
14
|
+
this.apiUrl = config.apiUrl ?? "https://api.github.com";
|
|
15
|
+
}
|
|
16
|
+
async fetchFile(path) {
|
|
17
|
+
const url = new URL(`/repos/${this.repo}/contents/${path}`, this.apiUrl);
|
|
18
|
+
if (this.ref)
|
|
19
|
+
url.searchParams.set("ref", this.ref);
|
|
20
|
+
const res = await fetch(url.toString(), {
|
|
21
|
+
headers: {
|
|
22
|
+
Authorization: `Bearer ${this.token}`,
|
|
23
|
+
Accept: "application/vnd.github+json",
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (!res.ok) {
|
|
27
|
+
throw new Error(`GitHub API error: ${res.status} fetching ${path} from ${this.repo}`);
|
|
28
|
+
}
|
|
29
|
+
const data = (await res.json());
|
|
30
|
+
const content = Buffer.from(data.content, "base64").toString("utf-8");
|
|
31
|
+
return { content, sha: data.sha };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.GitHubProvider = GitHubProvider;
|
|
35
|
+
//# sourceMappingURL=github.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"github.js","sourceRoot":"","sources":["../../src/vcs/github.ts"],"names":[],"mappings":";;;AAQA,oCAAoC;AACpC,MAAa,cAAc;IACR,IAAI,CAAS;IACb,KAAK,CAAS;IACd,GAAG,CAAU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,0 +1,11 @@
|
|
|
1
|
+
import { VcsProvider, VcsProviderConfig, VcsFileResult } from "./types";
|
|
2
|
+
/** GitLab Repository Files API provider. */
|
|
3
|
+
export declare class GitLabProvider implements VcsProvider {
|
|
4
|
+
private readonly repo;
|
|
5
|
+
private readonly token;
|
|
6
|
+
private readonly ref?;
|
|
7
|
+
private readonly apiUrl;
|
|
8
|
+
constructor(config: VcsProviderConfig);
|
|
9
|
+
fetchFile(path: string): Promise<VcsFileResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=gitlab.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitlab.d.ts","sourceRoot":"","sources":["../../src/vcs/gitlab.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAQxE,4CAA4C;AAC5C,qBAAa,cAAe,YAAW,WAAW;IAChD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAS;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;gBAEpB,MAAM,EAAE,iBAAiB;IAO/B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;CAwBtD"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GitLabProvider = void 0;
|
|
4
|
+
/** GitLab Repository Files API provider. */
|
|
5
|
+
class GitLabProvider {
|
|
6
|
+
repo;
|
|
7
|
+
token;
|
|
8
|
+
ref;
|
|
9
|
+
apiUrl;
|
|
10
|
+
constructor(config) {
|
|
11
|
+
this.repo = config.repo;
|
|
12
|
+
this.token = config.token;
|
|
13
|
+
this.ref = config.ref;
|
|
14
|
+
this.apiUrl = config.apiUrl ?? "https://gitlab.com";
|
|
15
|
+
}
|
|
16
|
+
async fetchFile(path) {
|
|
17
|
+
const encodedRepo = encodeURIComponent(this.repo);
|
|
18
|
+
const encodedPath = encodeURIComponent(path);
|
|
19
|
+
const url = new URL(`/api/v4/projects/${encodedRepo}/repository/files/${encodedPath}`, this.apiUrl);
|
|
20
|
+
if (this.ref)
|
|
21
|
+
url.searchParams.set("ref", this.ref);
|
|
22
|
+
const res = await fetch(url.toString(), {
|
|
23
|
+
headers: {
|
|
24
|
+
"PRIVATE-TOKEN": this.token,
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
if (!res.ok) {
|
|
28
|
+
throw new Error(`GitLab API error: ${res.status} fetching ${path} from ${this.repo}`);
|
|
29
|
+
}
|
|
30
|
+
const data = (await res.json());
|
|
31
|
+
const content = Buffer.from(data.content, "base64").toString("utf-8");
|
|
32
|
+
return { content, sha: data.blob_id };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.GitLabProvider = GitLabProvider;
|
|
36
|
+
//# sourceMappingURL=gitlab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"gitlab.js","sourceRoot":"","sources":["../../src/vcs/gitlab.ts"],"names":[],"mappings":";;;AAQA,4CAA4C;AAC5C,MAAa,cAAc;IACR,IAAI,CAAS;IACb,KAAK,CAAS;IACd,GAAG,CAAU;IACb,MAAM,CAAS;IAEhC,YAAY,MAAyB;QACnC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;QACxB,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;QAC1B,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;QACtB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,IAAI,oBAAoB,CAAC;IACtD,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAY;QAC1B,MAAM,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAClD,MAAM,WAAW,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;QAC7C,MAAM,GAAG,GAAG,IAAI,GAAG,CACjB,oBAAoB,WAAW,qBAAqB,WAAW,EAAE,EACjE,IAAI,CAAC,MAAM,CACZ,CAAC;QACF,IAAI,IAAI,CAAC,GAAG;YAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QAEpD,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,EAAE;YACtC,OAAO,EAAE;gBACP,eAAe,EAAE,IAAI,CAAC,KAAK;aAC5B;SACF,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,CAAC,MAAM,aAAa,IAAI,SAAS,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACxF,CAAC;QAED,MAAM,IAAI,GAAuB,CAAC,MAAM,GAAG,CAAC,IAAI,EAAE,CAAuB,CAAC;QAC1E,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAEtE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,CAAC;IACxC,CAAC;CACF;AArCD,wCAqCC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type { VcsProvider, VcsProviderConfig, VcsFileResult } from "./types";
|
|
2
|
+
export { GitHubProvider } from "./github";
|
|
3
|
+
export { GitLabProvider } from "./gitlab";
|
|
4
|
+
export { BitbucketProvider } from "./bitbucket";
|
|
5
|
+
import { VcsProvider, VcsProviderConfig } from "./types";
|
|
6
|
+
/** Create a VCS provider from configuration. */
|
|
7
|
+
export declare function createVcsProvider(config: VcsProviderConfig): VcsProvider;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vcs/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAKzD,gDAAgD;AAChD,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,iBAAiB,GAAG,WAAW,CAWxE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BitbucketProvider = exports.GitLabProvider = exports.GitHubProvider = void 0;
|
|
4
|
+
exports.createVcsProvider = createVcsProvider;
|
|
5
|
+
var github_1 = require("./github");
|
|
6
|
+
Object.defineProperty(exports, "GitHubProvider", { enumerable: true, get: function () { return github_1.GitHubProvider; } });
|
|
7
|
+
var gitlab_1 = require("./gitlab");
|
|
8
|
+
Object.defineProperty(exports, "GitLabProvider", { enumerable: true, get: function () { return gitlab_1.GitLabProvider; } });
|
|
9
|
+
var bitbucket_1 = require("./bitbucket");
|
|
10
|
+
Object.defineProperty(exports, "BitbucketProvider", { enumerable: true, get: function () { return bitbucket_1.BitbucketProvider; } });
|
|
11
|
+
const github_2 = require("./github");
|
|
12
|
+
const gitlab_2 = require("./gitlab");
|
|
13
|
+
const bitbucket_2 = require("./bitbucket");
|
|
14
|
+
/** Create a VCS provider from configuration. */
|
|
15
|
+
function createVcsProvider(config) {
|
|
16
|
+
switch (config.provider) {
|
|
17
|
+
case "github":
|
|
18
|
+
return new github_2.GitHubProvider(config);
|
|
19
|
+
case "gitlab":
|
|
20
|
+
return new gitlab_2.GitLabProvider(config);
|
|
21
|
+
case "bitbucket":
|
|
22
|
+
return new bitbucket_2.BitbucketProvider(config);
|
|
23
|
+
default:
|
|
24
|
+
throw new Error(`Unsupported VCS provider: ${config.provider}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/vcs/index.ts"],"names":[],"mappings":";;;AAWA,8CAWC;AArBD,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,mCAA0C;AAAjC,wGAAA,cAAc,OAAA;AACvB,yCAAgD;AAAvC,8GAAA,iBAAiB,OAAA;AAG1B,qCAA0C;AAC1C,qCAA0C;AAC1C,2CAAgD;AAEhD,gDAAgD;AAChD,SAAgB,iBAAiB,CAAC,MAAyB;IACzD,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,KAAK,QAAQ;YACX,OAAO,IAAI,uBAAc,CAAC,MAAM,CAAC,CAAC;QACpC,KAAK,QAAQ;YACX,OAAO,IAAI,uBAAc,CAAC,MAAM,CAAC,CAAC;QACpC,KAAK,WAAW;YACd,OAAO,IAAI,6BAAiB,CAAC,MAAM,CAAC,CAAC;QACvC;YACE,MAAM,IAAI,KAAK,CAAC,6BAA6B,MAAM,CAAC,QAAkB,EAAE,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Result of fetching a file from a VCS provider. */
|
|
2
|
+
export interface VcsFileResult {
|
|
3
|
+
/** Raw file content. */
|
|
4
|
+
content: string;
|
|
5
|
+
/** Git blob SHA for change detection. */
|
|
6
|
+
sha: string;
|
|
7
|
+
}
|
|
8
|
+
/** Configuration for a VCS provider. */
|
|
9
|
+
export interface VcsProviderConfig {
|
|
10
|
+
/** VCS platform. */
|
|
11
|
+
provider: "github" | "gitlab" | "bitbucket";
|
|
12
|
+
/** Repository identifier, e.g. "owner/repo". */
|
|
13
|
+
repo: string;
|
|
14
|
+
/** Authentication token. */
|
|
15
|
+
token: string;
|
|
16
|
+
/** Branch, tag, or commit SHA. Defaults to the repo's default branch. */
|
|
17
|
+
ref?: string;
|
|
18
|
+
/** Custom base URL for self-hosted instances (GHE, GitLab CE/EE, Bitbucket DC). */
|
|
19
|
+
apiUrl?: string;
|
|
20
|
+
}
|
|
21
|
+
/** Fetches files from a VCS provider API. */
|
|
22
|
+
export interface VcsProvider {
|
|
23
|
+
/**
|
|
24
|
+
* Fetch a single file by path from the repository.
|
|
25
|
+
* @param path - Repository-relative file path (e.g. `.clef/packed/api/production.age.json`).
|
|
26
|
+
*/
|
|
27
|
+
fetchFile(path: string): Promise<VcsFileResult>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/vcs/types.ts"],"names":[],"mappings":"AAAA,qDAAqD;AACrD,MAAM,WAAW,aAAa;IAC5B,wBAAwB;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,GAAG,EAAE,MAAM,CAAC;CACb;AAED,wCAAwC;AACxC,MAAM,WAAW,iBAAiB;IAChC,oBAAoB;IACpB,QAAQ,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC5C,gDAAgD;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,4BAA4B;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,yEAAyE;IACzE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,mFAAmF;IACnF,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,6CAA6C;AAC7C,MAAM,WAAW,WAAW;IAC1B;;;OAGG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/vcs/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@clef-sh/runtime",
|
|
3
|
+
"version": "0.1.6-beta.32",
|
|
4
|
+
"description": "Lightweight runtime secrets engine for Clef — VCS-native fetch, age decrypt, in-memory cache",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/clef-sh/clef",
|
|
8
|
+
"directory": "packages/runtime"
|
|
9
|
+
},
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"test": "jest",
|
|
18
|
+
"test:coverage": "jest --coverage"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"age-encryption": "^0.3.0"
|
|
22
|
+
},
|
|
23
|
+
"optionalDependencies": {
|
|
24
|
+
"@aws-sdk/client-kms": "^3.500.0",
|
|
25
|
+
"@azure/identity": "^4.0.0",
|
|
26
|
+
"@azure/keyvault-keys": "^4.8.0",
|
|
27
|
+
"@google-cloud/kms": "^4.0.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/jest": "^29.5.0",
|
|
31
|
+
"@types/node": "^20.11.0",
|
|
32
|
+
"jest": "^29.7.0",
|
|
33
|
+
"ts-jest": "^29.1.0",
|
|
34
|
+
"typescript": "^5.4.0"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public",
|
|
38
|
+
"provenance": true
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT"
|
|
41
|
+
}
|