@lssm/integration.runtime 1.41.1 → 1.42.1
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 +21 -0
- package/README.md +4 -1
- package/dist/health.d.ts +22 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +70 -0
- package/dist/health.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +9 -0
- package/dist/runtime.d.ts +100 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +187 -0
- package/dist/runtime.js.map +1 -0
- package/dist/secrets/env-secret-provider.d.ts +32 -0
- package/dist/secrets/env-secret-provider.d.ts.map +1 -0
- package/dist/secrets/env-secret-provider.js +82 -0
- package/dist/secrets/env-secret-provider.js.map +1 -0
- package/dist/secrets/gcp-secret-manager.d.ts +33 -0
- package/dist/secrets/gcp-secret-manager.d.ts.map +1 -0
- package/dist/secrets/gcp-secret-manager.js +230 -0
- package/dist/secrets/gcp-secret-manager.js.map +1 -0
- package/dist/secrets/index.d.ts +5 -0
- package/dist/secrets/index.js +6 -0
- package/dist/secrets/manager.d.ts +48 -0
- package/dist/secrets/manager.d.ts.map +1 -0
- package/dist/secrets/manager.js +104 -0
- package/dist/secrets/manager.js.map +1 -0
- package/dist/secrets/provider.d.ts +53 -0
- package/dist/secrets/provider.d.ts.map +1 -0
- package/dist/secrets/provider.js +59 -0
- package/dist/secrets/provider.js.map +1 -0
- package/package.json +23 -16
- package/dist/index.d.mts +0 -267
- package/dist/index.mjs +0 -714
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Chaman Ventures, SASU
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
package/dist/health.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { IntegrationContext, IntegrationTelemetryEmitter } from "./runtime.js";
|
|
2
|
+
import { IntegrationConnectionHealth } from "@lssm/lib.contracts/integrations/connection";
|
|
3
|
+
|
|
4
|
+
//#region src/health.d.ts
|
|
5
|
+
interface IntegrationHealthCheckResult extends IntegrationConnectionHealth {
|
|
6
|
+
metadata?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
type IntegrationHealthCheckExecutor = (context: IntegrationContext) => Promise<void>;
|
|
9
|
+
interface IntegrationHealthServiceOptions {
|
|
10
|
+
telemetry?: IntegrationTelemetryEmitter;
|
|
11
|
+
now?: () => Date;
|
|
12
|
+
}
|
|
13
|
+
declare class IntegrationHealthService {
|
|
14
|
+
private readonly telemetry?;
|
|
15
|
+
private readonly nowFn;
|
|
16
|
+
constructor(options?: IntegrationHealthServiceOptions);
|
|
17
|
+
check(context: IntegrationContext, executor: IntegrationHealthCheckExecutor): Promise<IntegrationHealthCheckResult>;
|
|
18
|
+
private emitTelemetry;
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { IntegrationHealthCheckExecutor, IntegrationHealthCheckResult, IntegrationHealthService, IntegrationHealthServiceOptions };
|
|
22
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","names":[],"sources":["../src/health.ts"],"sourcesContent":[],"mappings":";;;;UAQiB,4BAAA,SAAqC;aACzC;AADb;AAIY,KAAA,8BAAA,GAA8B,CAAA,OAC/B,EAAA,kBACN,EAAA,GAAA,OAAO,CAAA,IAAA,CAAA;AAEK,UAAA,+BAAA,CACH;EAID,SAAA,CAAA,EAJC,2BAIuB;EAId,GAAA,CAAA,EAAA,GAAA,GAPT,IAOS;;AAOT,cAXD,wBAAA,CAWC;EACD,iBAAA,SAAA;EAAR,iBAAA,KAAA;EAAO,WAAA,CAAA,OAAA,CAAA,EARW,+BAQX;iBAFC,8BACC,iCACT,QAAQ"}
|
package/dist/health.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
//#region src/health.ts
|
|
2
|
+
var IntegrationHealthService = class {
|
|
3
|
+
telemetry;
|
|
4
|
+
nowFn;
|
|
5
|
+
constructor(options = {}) {
|
|
6
|
+
this.telemetry = options.telemetry;
|
|
7
|
+
this.nowFn = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
8
|
+
}
|
|
9
|
+
async check(context, executor) {
|
|
10
|
+
const start = this.nowFn();
|
|
11
|
+
try {
|
|
12
|
+
await executor(context);
|
|
13
|
+
const end = this.nowFn();
|
|
14
|
+
const result = {
|
|
15
|
+
status: "connected",
|
|
16
|
+
checkedAt: end,
|
|
17
|
+
latencyMs: end.getTime() - start.getTime()
|
|
18
|
+
};
|
|
19
|
+
this.emitTelemetry(context, result, "success");
|
|
20
|
+
return result;
|
|
21
|
+
} catch (error) {
|
|
22
|
+
const end = this.nowFn();
|
|
23
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
24
|
+
const code = extractErrorCode(error);
|
|
25
|
+
const result = {
|
|
26
|
+
status: "error",
|
|
27
|
+
checkedAt: end,
|
|
28
|
+
latencyMs: end.getTime() - start.getTime(),
|
|
29
|
+
errorMessage: message,
|
|
30
|
+
errorCode: code
|
|
31
|
+
};
|
|
32
|
+
this.emitTelemetry(context, result, "error", code, message);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
emitTelemetry(context, result, status, errorCode, errorMessage) {
|
|
37
|
+
if (!this.telemetry) return;
|
|
38
|
+
this.telemetry.record({
|
|
39
|
+
tenantId: context.tenantId,
|
|
40
|
+
appId: context.appId,
|
|
41
|
+
environment: context.environment,
|
|
42
|
+
slotId: context.slotId,
|
|
43
|
+
integrationKey: context.spec.meta.key,
|
|
44
|
+
integrationVersion: context.spec.meta.version,
|
|
45
|
+
connectionId: context.connection.meta.id,
|
|
46
|
+
status,
|
|
47
|
+
durationMs: result.latencyMs,
|
|
48
|
+
errorCode,
|
|
49
|
+
errorMessage,
|
|
50
|
+
occurredAt: result.checkedAt ?? this.nowFn(),
|
|
51
|
+
metadata: {
|
|
52
|
+
...context.trace ? {
|
|
53
|
+
blueprint: `${context.trace.blueprintName}.v${context.trace.blueprintVersion}`,
|
|
54
|
+
configVersion: context.trace.configVersion
|
|
55
|
+
} : {},
|
|
56
|
+
status: result.status
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
function extractErrorCode(error) {
|
|
62
|
+
if (!error || typeof error !== "object") return void 0;
|
|
63
|
+
const candidate = error;
|
|
64
|
+
if (candidate.code == null) return void 0;
|
|
65
|
+
return String(candidate.code);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
//#endregion
|
|
69
|
+
export { IntegrationHealthService };
|
|
70
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","names":["result: IntegrationHealthCheckResult"],"sources":["../src/health.ts"],"sourcesContent":["import type { IntegrationConnectionHealth } from '@lssm/lib.contracts/integrations/connection';\n\nimport type {\n IntegrationContext,\n IntegrationInvocationStatus,\n IntegrationTelemetryEmitter,\n} from './runtime';\n\nexport interface IntegrationHealthCheckResult extends IntegrationConnectionHealth {\n metadata?: Record<string, string>;\n}\n\nexport type IntegrationHealthCheckExecutor = (\n context: IntegrationContext\n) => Promise<void>;\n\nexport interface IntegrationHealthServiceOptions {\n telemetry?: IntegrationTelemetryEmitter;\n now?: () => Date;\n}\n\nexport class IntegrationHealthService {\n private readonly telemetry?: IntegrationTelemetryEmitter;\n private readonly nowFn: () => Date;\n\n constructor(options: IntegrationHealthServiceOptions = {}) {\n this.telemetry = options.telemetry;\n this.nowFn = options.now ?? (() => new Date());\n }\n\n async check(\n context: IntegrationContext,\n executor: IntegrationHealthCheckExecutor\n ): Promise<IntegrationHealthCheckResult> {\n const start = this.nowFn();\n try {\n await executor(context);\n const end = this.nowFn();\n const result: IntegrationHealthCheckResult = {\n status: 'connected',\n checkedAt: end,\n latencyMs: end.getTime() - start.getTime(),\n };\n this.emitTelemetry(context, result, 'success');\n return result;\n } catch (error) {\n const end = this.nowFn();\n const message = error instanceof Error ? error.message : 'Unknown error';\n const code = extractErrorCode(error);\n const result: IntegrationHealthCheckResult = {\n status: 'error',\n checkedAt: end,\n latencyMs: end.getTime() - start.getTime(),\n errorMessage: message,\n errorCode: code,\n };\n this.emitTelemetry(context, result, 'error', code, message);\n return result;\n }\n }\n\n private emitTelemetry(\n context: IntegrationContext,\n result: IntegrationHealthCheckResult,\n status: IntegrationInvocationStatus,\n errorCode?: string,\n errorMessage?: string\n ) {\n if (!this.telemetry) return;\n this.telemetry.record({\n tenantId: context.tenantId,\n appId: context.appId,\n environment: context.environment,\n slotId: context.slotId,\n integrationKey: context.spec.meta.key,\n integrationVersion: context.spec.meta.version,\n connectionId: context.connection.meta.id,\n status,\n durationMs: result.latencyMs,\n errorCode,\n errorMessage,\n occurredAt: result.checkedAt ?? this.nowFn(),\n metadata: {\n ...(context.trace\n ? {\n blueprint: `${context.trace.blueprintName}.v${context.trace.blueprintVersion}`,\n configVersion: context.trace.configVersion,\n }\n : {}),\n status: result.status,\n },\n });\n }\n}\n\nfunction extractErrorCode(error: unknown): string | undefined {\n if (!error || typeof error !== 'object') return undefined;\n const candidate = error as { code?: string | number };\n if (candidate.code == null) return undefined;\n return String(candidate.code);\n}\n"],"mappings":";AAqBA,IAAa,2BAAb,MAAsC;CACpC,AAAiB;CACjB,AAAiB;CAEjB,YAAY,UAA2C,EAAE,EAAE;AACzD,OAAK,YAAY,QAAQ;AACzB,OAAK,QAAQ,QAAQ,8BAAc,IAAI,MAAM;;CAG/C,MAAM,MACJ,SACA,UACuC;EACvC,MAAM,QAAQ,KAAK,OAAO;AAC1B,MAAI;AACF,SAAM,SAAS,QAAQ;GACvB,MAAM,MAAM,KAAK,OAAO;GACxB,MAAMA,SAAuC;IAC3C,QAAQ;IACR,WAAW;IACX,WAAW,IAAI,SAAS,GAAG,MAAM,SAAS;IAC3C;AACD,QAAK,cAAc,SAAS,QAAQ,UAAU;AAC9C,UAAO;WACA,OAAO;GACd,MAAM,MAAM,KAAK,OAAO;GACxB,MAAM,UAAU,iBAAiB,QAAQ,MAAM,UAAU;GACzD,MAAM,OAAO,iBAAiB,MAAM;GACpC,MAAMA,SAAuC;IAC3C,QAAQ;IACR,WAAW;IACX,WAAW,IAAI,SAAS,GAAG,MAAM,SAAS;IAC1C,cAAc;IACd,WAAW;IACZ;AACD,QAAK,cAAc,SAAS,QAAQ,SAAS,MAAM,QAAQ;AAC3D,UAAO;;;CAIX,AAAQ,cACN,SACA,QACA,QACA,WACA,cACA;AACA,MAAI,CAAC,KAAK,UAAW;AACrB,OAAK,UAAU,OAAO;GACpB,UAAU,QAAQ;GAClB,OAAO,QAAQ;GACf,aAAa,QAAQ;GACrB,QAAQ,QAAQ;GAChB,gBAAgB,QAAQ,KAAK,KAAK;GAClC,oBAAoB,QAAQ,KAAK,KAAK;GACtC,cAAc,QAAQ,WAAW,KAAK;GACtC;GACA,YAAY,OAAO;GACnB;GACA;GACA,YAAY,OAAO,aAAa,KAAK,OAAO;GAC5C,UAAU;IACR,GAAI,QAAQ,QACR;KACE,WAAW,GAAG,QAAQ,MAAM,cAAc,IAAI,QAAQ,MAAM;KAC5D,eAAe,QAAQ,MAAM;KAC9B,GACD,EAAE;IACN,QAAQ,OAAO;IAChB;GACF,CAAC;;;AAIN,SAAS,iBAAiB,OAAoC;AAC5D,KAAI,CAAC,SAAS,OAAO,UAAU,SAAU,QAAO;CAChD,MAAM,YAAY;AAClB,KAAI,UAAU,QAAQ,KAAM,QAAO;AACnC,QAAO,OAAO,UAAU,KAAK"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ParsedSecretUri, SecretFetchOptions, SecretPayloadEncoding, SecretProvider, SecretProviderError, SecretReference, SecretRotationResult, SecretValue, SecretWritePayload, normalizeSecretPayload, parseSecretUri } from "./secrets/provider.js";
|
|
2
|
+
import { IntegrationCallContext, IntegrationCallError, IntegrationCallGuard, IntegrationCallGuardOptions, IntegrationCallResult, IntegrationContext, IntegrationInvocationStatus, IntegrationTelemetryEmitter, IntegrationTelemetryEvent, IntegrationTraceMetadata, connectionStatusLabel, ensureConnectionReady } from "./runtime.js";
|
|
3
|
+
import { IntegrationHealthCheckExecutor, IntegrationHealthCheckResult, IntegrationHealthService, IntegrationHealthServiceOptions } from "./health.js";
|
|
4
|
+
import { GcpSecretManagerProvider } from "./secrets/gcp-secret-manager.js";
|
|
5
|
+
import { EnvSecretProvider } from "./secrets/env-secret-provider.js";
|
|
6
|
+
import { SecretProviderManager, SecretProviderManagerOptions } from "./secrets/manager.js";
|
|
7
|
+
import "./secrets/index.js";
|
|
8
|
+
export { EnvSecretProvider, GcpSecretManagerProvider, IntegrationCallContext, IntegrationCallError, IntegrationCallGuard, IntegrationCallGuardOptions, IntegrationCallResult, IntegrationContext, IntegrationHealthCheckExecutor, IntegrationHealthCheckResult, IntegrationHealthService, IntegrationHealthServiceOptions, IntegrationInvocationStatus, IntegrationTelemetryEmitter, IntegrationTelemetryEvent, IntegrationTraceMetadata, ParsedSecretUri, SecretFetchOptions, SecretPayloadEncoding, SecretProvider, SecretProviderError, SecretProviderManager, SecretProviderManagerOptions, SecretReference, SecretRotationResult, SecretValue, SecretWritePayload, connectionStatusLabel, ensureConnectionReady, normalizeSecretPayload, parseSecretUri };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IntegrationHealthService } from "./health.js";
|
|
2
|
+
import { IntegrationCallGuard, connectionStatusLabel, ensureConnectionReady } from "./runtime.js";
|
|
3
|
+
import { SecretProviderError, normalizeSecretPayload, parseSecretUri } from "./secrets/provider.js";
|
|
4
|
+
import { GcpSecretManagerProvider } from "./secrets/gcp-secret-manager.js";
|
|
5
|
+
import { EnvSecretProvider } from "./secrets/env-secret-provider.js";
|
|
6
|
+
import { SecretProviderManager } from "./secrets/manager.js";
|
|
7
|
+
import "./secrets/index.js";
|
|
8
|
+
|
|
9
|
+
export { EnvSecretProvider, GcpSecretManagerProvider, IntegrationCallGuard, IntegrationHealthService, SecretProviderError, SecretProviderManager, connectionStatusLabel, ensureConnectionReady, normalizeSecretPayload, parseSecretUri };
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { SecretProvider } from "./secrets/provider.js";
|
|
2
|
+
import { ConnectionStatus, IntegrationConnection } from "@lssm/lib.contracts/integrations/connection";
|
|
3
|
+
import { ResolvedAppConfig, ResolvedIntegration } from "@lssm/lib.contracts/app-config/runtime";
|
|
4
|
+
import { IntegrationSpec } from "@lssm/lib.contracts/integrations/spec";
|
|
5
|
+
|
|
6
|
+
//#region src/runtime.d.ts
|
|
7
|
+
interface IntegrationTraceMetadata {
|
|
8
|
+
blueprintName: string;
|
|
9
|
+
blueprintVersion: number;
|
|
10
|
+
configVersion: number;
|
|
11
|
+
}
|
|
12
|
+
interface IntegrationTelemetryEvent {
|
|
13
|
+
tenantId: string;
|
|
14
|
+
appId: string;
|
|
15
|
+
environment?: string;
|
|
16
|
+
slotId?: string;
|
|
17
|
+
integrationKey: string;
|
|
18
|
+
integrationVersion: number;
|
|
19
|
+
connectionId: string;
|
|
20
|
+
status: 'success' | 'error';
|
|
21
|
+
durationMs?: number;
|
|
22
|
+
errorCode?: string;
|
|
23
|
+
errorMessage?: string;
|
|
24
|
+
occurredAt: Date;
|
|
25
|
+
metadata?: Record<string, string | number | boolean>;
|
|
26
|
+
}
|
|
27
|
+
interface IntegrationTelemetryEmitter {
|
|
28
|
+
record(event: IntegrationTelemetryEvent): Promise<void> | void;
|
|
29
|
+
}
|
|
30
|
+
type IntegrationInvocationStatus = 'success' | 'error';
|
|
31
|
+
interface IntegrationContext {
|
|
32
|
+
tenantId: string;
|
|
33
|
+
appId: string;
|
|
34
|
+
environment?: string;
|
|
35
|
+
slotId?: string;
|
|
36
|
+
spec: IntegrationSpec;
|
|
37
|
+
connection: IntegrationConnection;
|
|
38
|
+
secretProvider: SecretProvider;
|
|
39
|
+
secretReference: string;
|
|
40
|
+
trace: IntegrationTraceMetadata;
|
|
41
|
+
config?: Record<string, unknown>;
|
|
42
|
+
}
|
|
43
|
+
interface IntegrationCallContext {
|
|
44
|
+
tenantId: string;
|
|
45
|
+
appId: string;
|
|
46
|
+
environment?: string;
|
|
47
|
+
blueprintName: string;
|
|
48
|
+
blueprintVersion: number;
|
|
49
|
+
configVersion: number;
|
|
50
|
+
slotId: string;
|
|
51
|
+
operation: string;
|
|
52
|
+
}
|
|
53
|
+
interface IntegrationCallError {
|
|
54
|
+
code: string;
|
|
55
|
+
message: string;
|
|
56
|
+
retryable: boolean;
|
|
57
|
+
cause?: unknown;
|
|
58
|
+
}
|
|
59
|
+
interface IntegrationCallResult<T> {
|
|
60
|
+
success: boolean;
|
|
61
|
+
data?: T;
|
|
62
|
+
error?: IntegrationCallError;
|
|
63
|
+
metadata: {
|
|
64
|
+
latencyMs: number;
|
|
65
|
+
connectionId: string;
|
|
66
|
+
ownershipMode: IntegrationConnection['ownershipMode'];
|
|
67
|
+
attempts: number;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
interface IntegrationCallGuardOptions {
|
|
71
|
+
telemetry?: IntegrationTelemetryEmitter;
|
|
72
|
+
maxAttempts?: number;
|
|
73
|
+
backoffMs?: number;
|
|
74
|
+
shouldRetry?: (error: unknown, attempt: number) => boolean;
|
|
75
|
+
sleep?: (ms: number) => Promise<void>;
|
|
76
|
+
now?: () => Date;
|
|
77
|
+
}
|
|
78
|
+
declare class IntegrationCallGuard {
|
|
79
|
+
private readonly secretProvider;
|
|
80
|
+
private readonly telemetry?;
|
|
81
|
+
private readonly maxAttempts;
|
|
82
|
+
private readonly backoffMs;
|
|
83
|
+
private readonly shouldRetry;
|
|
84
|
+
private readonly sleep;
|
|
85
|
+
private readonly now;
|
|
86
|
+
constructor(secretProvider: SecretProvider, options?: IntegrationCallGuardOptions);
|
|
87
|
+
executeWithGuards<T>(slotId: string, operation: string, _input: unknown, resolvedConfig: ResolvedAppConfig, executor: (connection: IntegrationConnection, secrets: Record<string, string>) => Promise<T>): Promise<IntegrationCallResult<T>>;
|
|
88
|
+
private findIntegration;
|
|
89
|
+
private fetchSecrets;
|
|
90
|
+
private parseSecret;
|
|
91
|
+
private emitTelemetry;
|
|
92
|
+
private failure;
|
|
93
|
+
private makeContext;
|
|
94
|
+
private errorCodeFor;
|
|
95
|
+
}
|
|
96
|
+
declare function ensureConnectionReady(integration: ResolvedIntegration): void;
|
|
97
|
+
declare function connectionStatusLabel(status: ConnectionStatus): string;
|
|
98
|
+
//#endregion
|
|
99
|
+
export { IntegrationCallContext, IntegrationCallError, IntegrationCallGuard, IntegrationCallGuardOptions, IntegrationCallResult, IntegrationContext, IntegrationInvocationStatus, IntegrationTelemetryEmitter, IntegrationTelemetryEvent, IntegrationTraceMetadata, connectionStatusLabel, ensureConnectionReady };
|
|
100
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","names":[],"sources":["../src/runtime.ts"],"sourcesContent":[],"mappings":";;;;;;UAaiB,wBAAA;;EAAA,gBAAA,EAAA,MAAA;EAMA,aAAA,EAAA,MAAA;AAgBjB;AAIY,UApBK,yBAAA,CAoBsB;EAEtB,QAAA,EAAA,MAAA;EAKT,KAAA,EAAA,MAAA;EACM,WAAA,CAAA,EAAA,MAAA;EACI,MAAA,CAAA,EAAA,MAAA;EAET,cAAA,EAAA,MAAA;EACE,kBAAA,EAAA,MAAA;EAAM,YAAA,EAAA,MAAA;EAGA,MAAA,EAAA,SAAA,GAAA,OAAsB;EAWtB,UAAA,CAAA,EAAA,MAAA;EAOA,SAAA,CAAA,EAAA,MAAA;EAER,YAAA,CAAA,EAAA,MAAA;EACC,UAAA,EA5CI,IA4CJ;EAIS,QAAA,CAAA,EA/CN,MA+CM,CAAA,MAAA,EAAA,MAAA,GAAA,MAAA,GAAA,OAAA,CAAA;;AAKF,UAjDA,2BAAA,CAiD2B;EAC9B,MAAA,CAAA,KAAA,EAjDE,yBAiDF,CAAA,EAjD8B,OAiD9B,CAAA,IAAA,CAAA,GAAA,IAAA;;AAKA,KAnDF,2BAAA,GAmDE,SAAA,GAAA,OAAA;AAAI,UAjDD,kBAAA,CAiDC;EAML,QAAA,EAAA,MAAA;EASwB,KAAA,EAAA,MAAA;EACxB,WAAA,CAAA,EAAA,MAAA;EAyBO,MAAA,CAAA,EAAA,MAAA;EAEF,IAAA,EAvFV,eAuFU;EACH,UAAA,EAvFD,qBAuFC;EACE,cAAA,EAvFC,cAuFD;EAAR,eAAA,EAAA,MAAA;EAC0B,KAAA,EAtF1B,wBAsF0B;EAAtB,MAAA,CAAA,EArFF,MAqFE,CAAA,MAAA,EAAA,OAAA,CAAA;;AAAD,UAlFK,sBAAA,CAkFL;EAiPI,QAAA,EAAA,MAAA;EASA,KAAA,EAAA,MAAA;;;;;;;;UAjUC,oBAAA;;;;;;UAOA;;SAER;UACC;;;;mBAIS;;;;UAKF,2BAAA;cACH;;;;0BAIY;cACZ;;cAMD,oBAAA;;;;;;;;8BASwB,0BACxB;2FAyBO,0CAEF,gCACH,2BACN,QAAQ,KACZ,QAAQ,sBAAsB;;;;;;;;;iBAiPnB,qBAAA,cAAmC;iBASnC,qBAAA,SAA8B"}
|
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { performance } from "node:perf_hooks";
|
|
2
|
+
|
|
3
|
+
//#region src/runtime.ts
|
|
4
|
+
const DEFAULT_MAX_ATTEMPTS = 3;
|
|
5
|
+
const DEFAULT_BACKOFF_MS = 250;
|
|
6
|
+
var IntegrationCallGuard = class {
|
|
7
|
+
telemetry;
|
|
8
|
+
maxAttempts;
|
|
9
|
+
backoffMs;
|
|
10
|
+
shouldRetry;
|
|
11
|
+
sleep;
|
|
12
|
+
now;
|
|
13
|
+
constructor(secretProvider, options = {}) {
|
|
14
|
+
this.secretProvider = secretProvider;
|
|
15
|
+
this.telemetry = options.telemetry;
|
|
16
|
+
this.maxAttempts = Math.max(1, options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);
|
|
17
|
+
this.backoffMs = options.backoffMs ?? DEFAULT_BACKOFF_MS;
|
|
18
|
+
this.shouldRetry = options.shouldRetry ?? ((error) => typeof error === "object" && error !== null && "retryable" in error && Boolean(error.retryable));
|
|
19
|
+
this.sleep = options.sleep ?? ((ms) => ms <= 0 ? Promise.resolve() : new Promise((resolve) => setTimeout(resolve, ms)));
|
|
20
|
+
this.now = options.now ?? (() => /* @__PURE__ */ new Date());
|
|
21
|
+
}
|
|
22
|
+
async executeWithGuards(slotId, operation, _input, resolvedConfig, executor) {
|
|
23
|
+
const integration = this.findIntegration(slotId, resolvedConfig);
|
|
24
|
+
if (!integration) return this.failure({
|
|
25
|
+
tenantId: resolvedConfig.tenantId,
|
|
26
|
+
appId: resolvedConfig.appId,
|
|
27
|
+
environment: resolvedConfig.environment,
|
|
28
|
+
blueprintName: resolvedConfig.blueprintName,
|
|
29
|
+
blueprintVersion: resolvedConfig.blueprintVersion,
|
|
30
|
+
configVersion: resolvedConfig.configVersion,
|
|
31
|
+
slotId,
|
|
32
|
+
operation
|
|
33
|
+
}, void 0, {
|
|
34
|
+
code: "SLOT_NOT_BOUND",
|
|
35
|
+
message: `Integration slot "${slotId}" is not bound for tenant "${resolvedConfig.tenantId}".`,
|
|
36
|
+
retryable: false
|
|
37
|
+
}, 0);
|
|
38
|
+
const status = integration.connection.status;
|
|
39
|
+
if (status === "disconnected" || status === "error") return this.failure(this.makeContext(slotId, operation, resolvedConfig), integration, {
|
|
40
|
+
code: "CONNECTION_NOT_READY",
|
|
41
|
+
message: `Integration connection "${integration.connection.meta.label}" is in status "${status}".`,
|
|
42
|
+
retryable: false
|
|
43
|
+
}, 0);
|
|
44
|
+
const secrets = await this.fetchSecrets(integration.connection);
|
|
45
|
+
let attempt = 0;
|
|
46
|
+
const started = performance.now();
|
|
47
|
+
while (attempt < this.maxAttempts) {
|
|
48
|
+
attempt += 1;
|
|
49
|
+
try {
|
|
50
|
+
const data = await executor(integration.connection, secrets);
|
|
51
|
+
const duration = performance.now() - started;
|
|
52
|
+
this.emitTelemetry(this.makeContext(slotId, operation, resolvedConfig), integration, "success", duration);
|
|
53
|
+
return {
|
|
54
|
+
success: true,
|
|
55
|
+
data,
|
|
56
|
+
metadata: {
|
|
57
|
+
latencyMs: duration,
|
|
58
|
+
connectionId: integration.connection.meta.id,
|
|
59
|
+
ownershipMode: integration.connection.ownershipMode,
|
|
60
|
+
attempts: attempt
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
} catch (error) {
|
|
64
|
+
const duration = performance.now() - started;
|
|
65
|
+
this.emitTelemetry(this.makeContext(slotId, operation, resolvedConfig), integration, "error", duration, this.errorCodeFor(error), error instanceof Error ? error.message : String(error));
|
|
66
|
+
const retryable = this.shouldRetry(error, attempt);
|
|
67
|
+
if (!retryable || attempt >= this.maxAttempts) return {
|
|
68
|
+
success: false,
|
|
69
|
+
error: {
|
|
70
|
+
code: this.errorCodeFor(error),
|
|
71
|
+
message: error instanceof Error ? error.message : String(error),
|
|
72
|
+
retryable,
|
|
73
|
+
cause: error
|
|
74
|
+
},
|
|
75
|
+
metadata: {
|
|
76
|
+
latencyMs: duration,
|
|
77
|
+
connectionId: integration.connection.meta.id,
|
|
78
|
+
ownershipMode: integration.connection.ownershipMode,
|
|
79
|
+
attempts: attempt
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
await this.sleep(this.backoffMs);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
success: false,
|
|
87
|
+
error: {
|
|
88
|
+
code: "UNKNOWN_ERROR",
|
|
89
|
+
message: "Integration call failed after retries.",
|
|
90
|
+
retryable: false
|
|
91
|
+
},
|
|
92
|
+
metadata: {
|
|
93
|
+
latencyMs: performance.now() - started,
|
|
94
|
+
connectionId: integration.connection.meta.id,
|
|
95
|
+
ownershipMode: integration.connection.ownershipMode,
|
|
96
|
+
attempts: this.maxAttempts
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
findIntegration(slotId, config) {
|
|
101
|
+
return config.integrations.find((integration) => integration.slot.slotId === slotId);
|
|
102
|
+
}
|
|
103
|
+
async fetchSecrets(connection) {
|
|
104
|
+
if (!this.secretProvider.canHandle(connection.secretRef)) throw new Error(`Secret provider "${this.secretProvider.id}" cannot handle reference "${connection.secretRef}".`);
|
|
105
|
+
const secret = await this.secretProvider.getSecret(connection.secretRef);
|
|
106
|
+
return this.parseSecret(secret);
|
|
107
|
+
}
|
|
108
|
+
parseSecret(secret) {
|
|
109
|
+
const text = new TextDecoder().decode(secret.data);
|
|
110
|
+
try {
|
|
111
|
+
const parsed = JSON.parse(text);
|
|
112
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
113
|
+
const entries = Object.entries(parsed).filter(([, value]) => typeof value === "string" || typeof value === "number" || typeof value === "boolean");
|
|
114
|
+
return Object.fromEntries(entries.map(([key, value]) => [key, String(value)]));
|
|
115
|
+
}
|
|
116
|
+
} catch {}
|
|
117
|
+
return { secret: text };
|
|
118
|
+
}
|
|
119
|
+
emitTelemetry(context, integration, status, durationMs, errorCode, errorMessage) {
|
|
120
|
+
if (!this.telemetry || !integration) return;
|
|
121
|
+
this.telemetry.record({
|
|
122
|
+
tenantId: context.tenantId,
|
|
123
|
+
appId: context.appId,
|
|
124
|
+
environment: context.environment,
|
|
125
|
+
slotId: context.slotId,
|
|
126
|
+
integrationKey: integration.connection.meta.integrationKey,
|
|
127
|
+
integrationVersion: integration.connection.meta.integrationVersion,
|
|
128
|
+
connectionId: integration.connection.meta.id,
|
|
129
|
+
status,
|
|
130
|
+
durationMs,
|
|
131
|
+
errorCode,
|
|
132
|
+
errorMessage,
|
|
133
|
+
occurredAt: this.now(),
|
|
134
|
+
metadata: {
|
|
135
|
+
blueprint: `${context.blueprintName}.v${context.blueprintVersion}`,
|
|
136
|
+
configVersion: context.configVersion,
|
|
137
|
+
operation: context.operation
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
failure(context, integration, error, attempts) {
|
|
142
|
+
if (integration) this.emitTelemetry(context, integration, "error", 0, error.code, error.message);
|
|
143
|
+
return {
|
|
144
|
+
success: false,
|
|
145
|
+
error,
|
|
146
|
+
metadata: {
|
|
147
|
+
latencyMs: 0,
|
|
148
|
+
connectionId: integration?.connection.meta.id ?? "unknown",
|
|
149
|
+
ownershipMode: integration?.connection.ownershipMode ?? "managed",
|
|
150
|
+
attempts
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
makeContext(slotId, operation, config) {
|
|
155
|
+
return {
|
|
156
|
+
tenantId: config.tenantId,
|
|
157
|
+
appId: config.appId,
|
|
158
|
+
environment: config.environment,
|
|
159
|
+
blueprintName: config.blueprintName,
|
|
160
|
+
blueprintVersion: config.blueprintVersion,
|
|
161
|
+
configVersion: config.configVersion,
|
|
162
|
+
slotId,
|
|
163
|
+
operation
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
errorCodeFor(error) {
|
|
167
|
+
if (typeof error === "object" && error !== null && "code" in error && typeof error.code === "string") return error.code;
|
|
168
|
+
return "PROVIDER_ERROR";
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
function ensureConnectionReady(integration) {
|
|
172
|
+
const status = integration.connection.status;
|
|
173
|
+
if (status === "disconnected" || status === "error") throw new Error(`Integration connection "${integration.connection.meta.label}" is in status "${status}".`);
|
|
174
|
+
}
|
|
175
|
+
function connectionStatusLabel(status) {
|
|
176
|
+
switch (status) {
|
|
177
|
+
case "connected": return "connected";
|
|
178
|
+
case "disconnected": return "disconnected";
|
|
179
|
+
case "error": return "error";
|
|
180
|
+
case "unknown":
|
|
181
|
+
default: return "unknown";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
export { IntegrationCallGuard, connectionStatusLabel, ensureConnectionReady };
|
|
187
|
+
//# sourceMappingURL=runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.js","names":["secretProvider: SecretProvider"],"sources":["../src/runtime.ts"],"sourcesContent":["import { performance } from 'node:perf_hooks';\n\nimport type {\n ResolvedAppConfig,\n ResolvedIntegration,\n} from '@lssm/lib.contracts/app-config/runtime';\nimport type {\n ConnectionStatus,\n IntegrationConnection,\n} from '@lssm/lib.contracts/integrations/connection';\nimport type { IntegrationSpec } from '@lssm/lib.contracts/integrations/spec';\nimport type { SecretProvider, SecretValue } from './secrets/provider';\n\nexport interface IntegrationTraceMetadata {\n blueprintName: string;\n blueprintVersion: number;\n configVersion: number;\n}\n\nexport interface IntegrationTelemetryEvent {\n tenantId: string;\n appId: string;\n environment?: string;\n slotId?: string;\n integrationKey: string;\n integrationVersion: number;\n connectionId: string;\n status: 'success' | 'error';\n durationMs?: number;\n errorCode?: string;\n errorMessage?: string;\n occurredAt: Date;\n metadata?: Record<string, string | number | boolean>;\n}\n\nexport interface IntegrationTelemetryEmitter {\n record(event: IntegrationTelemetryEvent): Promise<void> | void;\n}\n\nexport type IntegrationInvocationStatus = 'success' | 'error';\n\nexport interface IntegrationContext {\n tenantId: string;\n appId: string;\n environment?: string;\n slotId?: string;\n spec: IntegrationSpec;\n connection: IntegrationConnection;\n secretProvider: SecretProvider;\n secretReference: string;\n trace: IntegrationTraceMetadata;\n config?: Record<string, unknown>;\n}\n\nexport interface IntegrationCallContext {\n tenantId: string;\n appId: string;\n environment?: string;\n blueprintName: string;\n blueprintVersion: number;\n configVersion: number;\n slotId: string;\n operation: string;\n}\n\nexport interface IntegrationCallError {\n code: string;\n message: string;\n retryable: boolean;\n cause?: unknown;\n}\n\nexport interface IntegrationCallResult<T> {\n success: boolean;\n data?: T;\n error?: IntegrationCallError;\n metadata: {\n latencyMs: number;\n connectionId: string;\n ownershipMode: IntegrationConnection['ownershipMode'];\n attempts: number;\n };\n}\n\nexport interface IntegrationCallGuardOptions {\n telemetry?: IntegrationTelemetryEmitter;\n maxAttempts?: number;\n backoffMs?: number;\n shouldRetry?: (error: unknown, attempt: number) => boolean;\n sleep?: (ms: number) => Promise<void>;\n now?: () => Date;\n}\n\nconst DEFAULT_MAX_ATTEMPTS = 3;\nconst DEFAULT_BACKOFF_MS = 250;\n\nexport class IntegrationCallGuard {\n private readonly telemetry?: IntegrationTelemetryEmitter;\n private readonly maxAttempts: number;\n private readonly backoffMs: number;\n private readonly shouldRetry: (error: unknown, attempt: number) => boolean;\n private readonly sleep: (ms: number) => Promise<void>;\n private readonly now: () => Date;\n\n constructor(\n private readonly secretProvider: SecretProvider,\n options: IntegrationCallGuardOptions = {}\n ) {\n this.telemetry = options.telemetry;\n this.maxAttempts = Math.max(1, options.maxAttempts ?? DEFAULT_MAX_ATTEMPTS);\n this.backoffMs = options.backoffMs ?? DEFAULT_BACKOFF_MS;\n this.shouldRetry =\n options.shouldRetry ??\n ((error: unknown) =>\n typeof error === 'object' &&\n error !== null &&\n 'retryable' in error &&\n Boolean((error as { retryable?: unknown }).retryable));\n this.sleep =\n options.sleep ??\n ((ms: number) =>\n ms <= 0\n ? Promise.resolve()\n : new Promise((resolve) => setTimeout(resolve, ms)));\n this.now = options.now ?? (() => new Date());\n }\n\n async executeWithGuards<T>(\n slotId: string,\n operation: string,\n _input: unknown,\n resolvedConfig: ResolvedAppConfig,\n executor: (\n connection: IntegrationConnection,\n secrets: Record<string, string>\n ) => Promise<T>\n ): Promise<IntegrationCallResult<T>> {\n const integration = this.findIntegration(slotId, resolvedConfig);\n if (!integration) {\n return this.failure(\n {\n tenantId: resolvedConfig.tenantId,\n appId: resolvedConfig.appId,\n environment: resolvedConfig.environment,\n blueprintName: resolvedConfig.blueprintName,\n blueprintVersion: resolvedConfig.blueprintVersion,\n configVersion: resolvedConfig.configVersion,\n slotId,\n operation,\n },\n undefined,\n {\n code: 'SLOT_NOT_BOUND',\n message: `Integration slot \"${slotId}\" is not bound for tenant \"${resolvedConfig.tenantId}\".`,\n retryable: false,\n },\n 0\n );\n }\n\n const status = integration.connection.status;\n if (status === 'disconnected' || status === 'error') {\n return this.failure(\n this.makeContext(slotId, operation, resolvedConfig),\n integration,\n {\n code: 'CONNECTION_NOT_READY',\n message: `Integration connection \"${integration.connection.meta.label}\" is in status \"${status}\".`,\n retryable: false,\n },\n 0\n );\n }\n\n const secrets = await this.fetchSecrets(integration.connection);\n\n let attempt = 0;\n const started = performance.now();\n while (attempt < this.maxAttempts) {\n attempt += 1;\n try {\n const data = await executor(integration.connection, secrets);\n const duration = performance.now() - started;\n this.emitTelemetry(\n this.makeContext(slotId, operation, resolvedConfig),\n integration,\n 'success',\n duration\n );\n return {\n success: true,\n data,\n metadata: {\n latencyMs: duration,\n connectionId: integration.connection.meta.id,\n ownershipMode: integration.connection.ownershipMode,\n attempts: attempt,\n },\n };\n } catch (error) {\n const duration = performance.now() - started;\n this.emitTelemetry(\n this.makeContext(slotId, operation, resolvedConfig),\n integration,\n 'error',\n duration,\n this.errorCodeFor(error),\n error instanceof Error ? error.message : String(error)\n );\n const retryable = this.shouldRetry(error, attempt);\n if (!retryable || attempt >= this.maxAttempts) {\n return {\n success: false,\n error: {\n code: this.errorCodeFor(error),\n message: error instanceof Error ? error.message : String(error),\n retryable,\n cause: error,\n },\n metadata: {\n latencyMs: duration,\n connectionId: integration.connection.meta.id,\n ownershipMode: integration.connection.ownershipMode,\n attempts: attempt,\n },\n };\n }\n await this.sleep(this.backoffMs);\n }\n }\n\n return {\n success: false,\n error: {\n code: 'UNKNOWN_ERROR',\n message: 'Integration call failed after retries.',\n retryable: false,\n },\n metadata: {\n latencyMs: performance.now() - started,\n connectionId: integration.connection.meta.id,\n ownershipMode: integration.connection.ownershipMode,\n attempts: this.maxAttempts,\n },\n };\n }\n\n private findIntegration(\n slotId: string,\n config: ResolvedAppConfig\n ): ResolvedIntegration | undefined {\n return config.integrations.find(\n (integration) => integration.slot.slotId === slotId\n );\n }\n\n private async fetchSecrets(\n connection: IntegrationConnection\n ): Promise<Record<string, string>> {\n if (!this.secretProvider.canHandle(connection.secretRef)) {\n throw new Error(\n `Secret provider \"${this.secretProvider.id}\" cannot handle reference \"${connection.secretRef}\".`\n );\n }\n const secret = await this.secretProvider.getSecret(connection.secretRef);\n return this.parseSecret(secret);\n }\n\n private parseSecret(secret: SecretValue): Record<string, string> {\n const text = new TextDecoder().decode(secret.data);\n try {\n const parsed = JSON.parse(text);\n if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {\n const entries = Object.entries(parsed).filter(\n ([, value]) =>\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n );\n return Object.fromEntries(\n entries.map(([key, value]) => [key, String(value)])\n );\n }\n } catch {\n // raw secret fallback\n }\n return { secret: text };\n }\n\n private emitTelemetry(\n context: IntegrationCallContext,\n integration: ResolvedIntegration | undefined,\n status: 'success' | 'error',\n durationMs: number,\n errorCode?: string,\n errorMessage?: string\n ) {\n if (!this.telemetry || !integration) return;\n this.telemetry.record({\n tenantId: context.tenantId,\n appId: context.appId,\n environment: context.environment,\n slotId: context.slotId,\n integrationKey: integration.connection.meta.integrationKey,\n integrationVersion: integration.connection.meta.integrationVersion,\n connectionId: integration.connection.meta.id,\n status,\n durationMs,\n errorCode,\n errorMessage,\n occurredAt: this.now(),\n metadata: {\n blueprint: `${context.blueprintName}.v${context.blueprintVersion}`,\n configVersion: context.configVersion,\n operation: context.operation,\n },\n });\n }\n\n private failure<T>(\n context: IntegrationCallContext,\n integration: ResolvedIntegration | undefined,\n error: IntegrationCallError,\n attempts: number\n ): IntegrationCallResult<T> {\n if (integration) {\n this.emitTelemetry(\n context,\n integration,\n 'error',\n 0,\n error.code,\n error.message\n );\n }\n return {\n success: false,\n error,\n metadata: {\n latencyMs: 0,\n connectionId: integration?.connection.meta.id ?? 'unknown',\n ownershipMode: integration?.connection.ownershipMode ?? 'managed',\n attempts,\n },\n };\n }\n\n private makeContext(\n slotId: string,\n operation: string,\n config: ResolvedAppConfig\n ): IntegrationCallContext {\n return {\n tenantId: config.tenantId,\n appId: config.appId,\n environment: config.environment,\n blueprintName: config.blueprintName,\n blueprintVersion: config.blueprintVersion,\n configVersion: config.configVersion,\n slotId,\n operation,\n };\n }\n\n private errorCodeFor(error: unknown): string {\n if (\n typeof error === 'object' &&\n error !== null &&\n 'code' in error &&\n typeof (error as { code?: unknown }).code === 'string'\n ) {\n return (error as { code: string }).code;\n }\n return 'PROVIDER_ERROR';\n }\n}\n\nexport function ensureConnectionReady(integration: ResolvedIntegration): void {\n const status = integration.connection.status;\n if (status === 'disconnected' || status === 'error') {\n throw new Error(\n `Integration connection \"${integration.connection.meta.label}\" is in status \"${status}\".`\n );\n }\n}\n\nexport function connectionStatusLabel(status: ConnectionStatus): string {\n switch (status) {\n case 'connected':\n return 'connected';\n case 'disconnected':\n return 'disconnected';\n case 'error':\n return 'error';\n case 'unknown':\n default:\n return 'unknown';\n }\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { SecretProvider, SecretReference, SecretRotationResult, SecretValue, SecretWritePayload } from "./provider.js";
|
|
2
|
+
|
|
3
|
+
//#region src/secrets/env-secret-provider.d.ts
|
|
4
|
+
interface EnvSecretProviderOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Optional map to alias secret references to environment variable names.
|
|
7
|
+
* Useful when referencing secrets from other providers (e.g. gcp://...)
|
|
8
|
+
* while still allowing local overrides.
|
|
9
|
+
*/
|
|
10
|
+
aliases?: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Environment-variable backed secret provider. Read-only by design.
|
|
14
|
+
* Allows overriding other secret providers by deriving environment variable
|
|
15
|
+
* names from secret references (or by using explicit aliases).
|
|
16
|
+
*/
|
|
17
|
+
declare class EnvSecretProvider implements SecretProvider {
|
|
18
|
+
readonly id = "env";
|
|
19
|
+
private readonly aliases;
|
|
20
|
+
constructor(options?: EnvSecretProviderOptions);
|
|
21
|
+
canHandle(reference: SecretReference): boolean;
|
|
22
|
+
getSecret(reference: SecretReference): Promise<SecretValue>;
|
|
23
|
+
setSecret(reference: SecretReference, _payload: SecretWritePayload): Promise<SecretRotationResult>;
|
|
24
|
+
rotateSecret(reference: SecretReference, _payload: SecretWritePayload): Promise<SecretRotationResult>;
|
|
25
|
+
deleteSecret(reference: SecretReference): Promise<void>;
|
|
26
|
+
private resolveEnvKey;
|
|
27
|
+
private deriveEnvKey;
|
|
28
|
+
private forbiddenError;
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { EnvSecretProvider };
|
|
32
|
+
//# sourceMappingURL=env-secret-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-secret-provider.d.ts","names":[],"sources":["../../src/secrets/env-secret-provider.ts"],"sourcesContent":[],"mappings":";;;UASU,wBAAA;;AAHU;AAiBpB;;;EAc6B,OAAA,CAAA,EAtBjB,MAsBiB,CAAA,MAAA,EAAA,MAAA,CAAA;;;;;;;AAwCd,cAtDF,iBAAA,YAA6B,cAsD3B,CAAA;EACD,SAAA,EAAA,GAAA,KAAA;EACD,iBAAA,OAAA;EAAR,WAAA,CAAA,OAAA,CAAA,EAnDkB,wBAmDlB;EAI2B,SAAA,CAAA,SAAA,EAnDT,eAmDS,CAAA,EAAA,OAAA;EAAkB,SAAA,CAAA,SAAA,EA9CrB,eA8CqB,CAAA,EA9CH,OA8CG,CA9CK,WA8CL,CAAA;EA5DR,SAAA,CAAA,SAAA,EA+C3B,eA/C2B,EAAA,QAAA,EAgD5B,kBAhD4B,CAAA,EAiDrC,OAjDqC,CAiD7B,oBAjD6B,CAAA;EAAc,YAAA,CAAA,SAAA,EAsDzC,eAtDyC,EAAA,QAAA,EAuD1C,kBAvD0C,CAAA,EAwDnD,OAxDmD,CAwD3C,oBAxD2C,CAAA;0BA4DxB,kBAAkB"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { SecretProviderError, parseSecretUri } from "./provider.js";
|
|
2
|
+
|
|
3
|
+
//#region src/secrets/env-secret-provider.ts
|
|
4
|
+
/**
|
|
5
|
+
* Environment-variable backed secret provider. Read-only by design.
|
|
6
|
+
* Allows overriding other secret providers by deriving environment variable
|
|
7
|
+
* names from secret references (or by using explicit aliases).
|
|
8
|
+
*/
|
|
9
|
+
var EnvSecretProvider = class {
|
|
10
|
+
id = "env";
|
|
11
|
+
aliases;
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.aliases = options.aliases ?? {};
|
|
14
|
+
}
|
|
15
|
+
canHandle(reference) {
|
|
16
|
+
const envKey = this.resolveEnvKey(reference);
|
|
17
|
+
return envKey !== void 0 && process.env[envKey] !== void 0;
|
|
18
|
+
}
|
|
19
|
+
async getSecret(reference) {
|
|
20
|
+
const envKey = this.resolveEnvKey(reference);
|
|
21
|
+
if (!envKey) throw new SecretProviderError({
|
|
22
|
+
message: `Unable to resolve environment variable for reference "${reference}".`,
|
|
23
|
+
provider: this.id,
|
|
24
|
+
reference,
|
|
25
|
+
code: "INVALID"
|
|
26
|
+
});
|
|
27
|
+
const value = process.env[envKey];
|
|
28
|
+
if (value === void 0) throw new SecretProviderError({
|
|
29
|
+
message: `Environment variable "${envKey}" not found for reference "${reference}".`,
|
|
30
|
+
provider: this.id,
|
|
31
|
+
reference,
|
|
32
|
+
code: "NOT_FOUND"
|
|
33
|
+
});
|
|
34
|
+
return {
|
|
35
|
+
data: Buffer.from(value, "utf-8"),
|
|
36
|
+
version: "current",
|
|
37
|
+
metadata: {
|
|
38
|
+
source: "env",
|
|
39
|
+
envKey
|
|
40
|
+
},
|
|
41
|
+
retrievedAt: /* @__PURE__ */ new Date()
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
async setSecret(reference, _payload) {
|
|
45
|
+
throw this.forbiddenError("setSecret", reference);
|
|
46
|
+
}
|
|
47
|
+
async rotateSecret(reference, _payload) {
|
|
48
|
+
throw this.forbiddenError("rotateSecret", reference);
|
|
49
|
+
}
|
|
50
|
+
async deleteSecret(reference) {
|
|
51
|
+
throw this.forbiddenError("deleteSecret", reference);
|
|
52
|
+
}
|
|
53
|
+
resolveEnvKey(reference) {
|
|
54
|
+
if (!reference) return;
|
|
55
|
+
if (this.aliases[reference]) return this.aliases[reference];
|
|
56
|
+
if (!reference.includes("://")) return reference;
|
|
57
|
+
try {
|
|
58
|
+
const parsed = parseSecretUri(reference);
|
|
59
|
+
if (parsed.provider === "env") return parsed.path;
|
|
60
|
+
if (parsed.extras?.env) return parsed.extras.env;
|
|
61
|
+
return this.deriveEnvKey(parsed.path);
|
|
62
|
+
} catch {
|
|
63
|
+
return reference;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
deriveEnvKey(path) {
|
|
67
|
+
if (!path) return void 0;
|
|
68
|
+
return path.split(/[/:\-.]/).filter(Boolean).map((segment) => segment.replace(/[^a-zA-Z0-9]/g, "_").replace(/_{2,}/g, "_").toUpperCase()).join("_");
|
|
69
|
+
}
|
|
70
|
+
forbiddenError(operation, reference) {
|
|
71
|
+
return new SecretProviderError({
|
|
72
|
+
message: `EnvSecretProvider is read-only. "${operation}" is not allowed for ${reference}.`,
|
|
73
|
+
provider: this.id,
|
|
74
|
+
reference,
|
|
75
|
+
code: "FORBIDDEN"
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
//#endregion
|
|
81
|
+
export { EnvSecretProvider };
|
|
82
|
+
//# sourceMappingURL=env-secret-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-secret-provider.js","names":[],"sources":["../../src/secrets/env-secret-provider.ts"],"sourcesContent":["import type {\n SecretProvider,\n SecretReference,\n SecretRotationResult,\n SecretValue,\n SecretWritePayload,\n} from './provider';\nimport { parseSecretUri, SecretProviderError } from './provider';\n\ninterface EnvSecretProviderOptions {\n /**\n * Optional map to alias secret references to environment variable names.\n * Useful when referencing secrets from other providers (e.g. gcp://...)\n * while still allowing local overrides.\n */\n aliases?: Record<string, string>;\n}\n\n/**\n * Environment-variable backed secret provider. Read-only by design.\n * Allows overriding other secret providers by deriving environment variable\n * names from secret references (or by using explicit aliases).\n */\nexport class EnvSecretProvider implements SecretProvider {\n readonly id = 'env';\n\n private readonly aliases: Record<string, string>;\n\n constructor(options: EnvSecretProviderOptions = {}) {\n this.aliases = options.aliases ?? {};\n }\n\n canHandle(reference: SecretReference): boolean {\n const envKey = this.resolveEnvKey(reference);\n return envKey !== undefined && process.env[envKey] !== undefined;\n }\n\n async getSecret(reference: SecretReference): Promise<SecretValue> {\n const envKey = this.resolveEnvKey(reference);\n if (!envKey) {\n throw new SecretProviderError({\n message: `Unable to resolve environment variable for reference \"${reference}\".`,\n provider: this.id,\n reference,\n code: 'INVALID',\n });\n }\n\n const value = process.env[envKey];\n if (value === undefined) {\n throw new SecretProviderError({\n message: `Environment variable \"${envKey}\" not found for reference \"${reference}\".`,\n provider: this.id,\n reference,\n code: 'NOT_FOUND',\n });\n }\n\n return {\n data: Buffer.from(value, 'utf-8'),\n version: 'current',\n metadata: {\n source: 'env',\n envKey,\n },\n retrievedAt: new Date(),\n };\n }\n\n async setSecret(\n reference: SecretReference,\n _payload: SecretWritePayload\n ): Promise<SecretRotationResult> {\n throw this.forbiddenError('setSecret', reference);\n }\n\n async rotateSecret(\n reference: SecretReference,\n _payload: SecretWritePayload\n ): Promise<SecretRotationResult> {\n throw this.forbiddenError('rotateSecret', reference);\n }\n\n async deleteSecret(reference: SecretReference): Promise<void> {\n throw this.forbiddenError('deleteSecret', reference);\n }\n\n private resolveEnvKey(reference: SecretReference): string | undefined {\n if (!reference) {\n return undefined;\n }\n\n if (this.aliases[reference]) {\n return this.aliases[reference];\n }\n\n if (!reference.includes('://')) {\n return reference;\n }\n\n try {\n const parsed = parseSecretUri(reference);\n if (parsed.provider === 'env') {\n return parsed.path;\n }\n\n if (parsed.extras?.env) {\n return parsed.extras.env;\n }\n\n return this.deriveEnvKey(parsed.path);\n } catch {\n return reference;\n }\n }\n\n private deriveEnvKey(path: string): string | undefined {\n if (!path) return undefined;\n return path\n .split(/[/:\\-.]/)\n .filter(Boolean)\n .map((segment) =>\n segment\n .replace(/[^a-zA-Z0-9]/g, '_')\n .replace(/_{2,}/g, '_')\n .toUpperCase()\n )\n .join('_');\n }\n\n private forbiddenError(\n operation: string,\n reference: SecretReference\n ): SecretProviderError {\n return new SecretProviderError({\n message: `EnvSecretProvider is read-only. \"${operation}\" is not allowed for ${reference}.`,\n provider: this.id,\n reference,\n code: 'FORBIDDEN',\n });\n }\n}\n"],"mappings":";;;;;;;;AAuBA,IAAa,oBAAb,MAAyD;CACvD,AAAS,KAAK;CAEd,AAAiB;CAEjB,YAAY,UAAoC,EAAE,EAAE;AAClD,OAAK,UAAU,QAAQ,WAAW,EAAE;;CAGtC,UAAU,WAAqC;EAC7C,MAAM,SAAS,KAAK,cAAc,UAAU;AAC5C,SAAO,WAAW,UAAa,QAAQ,IAAI,YAAY;;CAGzD,MAAM,UAAU,WAAkD;EAChE,MAAM,SAAS,KAAK,cAAc,UAAU;AAC5C,MAAI,CAAC,OACH,OAAM,IAAI,oBAAoB;GAC5B,SAAS,yDAAyD,UAAU;GAC5E,UAAU,KAAK;GACf;GACA,MAAM;GACP,CAAC;EAGJ,MAAM,QAAQ,QAAQ,IAAI;AAC1B,MAAI,UAAU,OACZ,OAAM,IAAI,oBAAoB;GAC5B,SAAS,yBAAyB,OAAO,6BAA6B,UAAU;GAChF,UAAU,KAAK;GACf;GACA,MAAM;GACP,CAAC;AAGJ,SAAO;GACL,MAAM,OAAO,KAAK,OAAO,QAAQ;GACjC,SAAS;GACT,UAAU;IACR,QAAQ;IACR;IACD;GACD,6BAAa,IAAI,MAAM;GACxB;;CAGH,MAAM,UACJ,WACA,UAC+B;AAC/B,QAAM,KAAK,eAAe,aAAa,UAAU;;CAGnD,MAAM,aACJ,WACA,UAC+B;AAC/B,QAAM,KAAK,eAAe,gBAAgB,UAAU;;CAGtD,MAAM,aAAa,WAA2C;AAC5D,QAAM,KAAK,eAAe,gBAAgB,UAAU;;CAGtD,AAAQ,cAAc,WAAgD;AACpE,MAAI,CAAC,UACH;AAGF,MAAI,KAAK,QAAQ,WACf,QAAO,KAAK,QAAQ;AAGtB,MAAI,CAAC,UAAU,SAAS,MAAM,CAC5B,QAAO;AAGT,MAAI;GACF,MAAM,SAAS,eAAe,UAAU;AACxC,OAAI,OAAO,aAAa,MACtB,QAAO,OAAO;AAGhB,OAAI,OAAO,QAAQ,IACjB,QAAO,OAAO,OAAO;AAGvB,UAAO,KAAK,aAAa,OAAO,KAAK;UAC/B;AACN,UAAO;;;CAIX,AAAQ,aAAa,MAAkC;AACrD,MAAI,CAAC,KAAM,QAAO;AAClB,SAAO,KACJ,MAAM,UAAU,CAChB,OAAO,QAAQ,CACf,KAAK,YACJ,QACG,QAAQ,iBAAiB,IAAI,CAC7B,QAAQ,UAAU,IAAI,CACtB,aAAa,CACjB,CACA,KAAK,IAAI;;CAGd,AAAQ,eACN,WACA,WACqB;AACrB,SAAO,IAAI,oBAAoB;GAC7B,SAAS,oCAAoC,UAAU,uBAAuB,UAAU;GACxF,UAAU,KAAK;GACf;GACA,MAAM;GACP,CAAC"}
|