@contractspec/lib.contracts-integrations 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3676 -0
- package/dist/integrations/binding.d.ts +14 -0
- package/dist/integrations/binding.js +1 -0
- package/dist/integrations/connection.d.ts +47 -0
- package/dist/integrations/connection.js +1 -0
- package/dist/integrations/docs/integrations.docblock.d.ts +2 -0
- package/dist/integrations/docs/integrations.docblock.js +110 -0
- package/dist/integrations/health.d.ts +17 -0
- package/dist/integrations/health.js +73 -0
- package/dist/integrations/health.test.d.ts +1 -0
- package/dist/integrations/index.d.ts +11 -0
- package/dist/integrations/index.js +3264 -0
- package/dist/integrations/integrations.capability.d.ts +1 -0
- package/dist/integrations/integrations.capability.js +18 -0
- package/dist/integrations/integrations.feature.d.ts +5 -0
- package/dist/integrations/integrations.feature.js +33 -0
- package/dist/integrations/meeting-recorder/contracts/index.d.ts +7 -0
- package/dist/integrations/meeting-recorder/contracts/index.js +474 -0
- package/dist/integrations/meeting-recorder/contracts/meetings.d.ts +451 -0
- package/dist/integrations/meeting-recorder/contracts/meetings.js +219 -0
- package/dist/integrations/meeting-recorder/contracts/transcripts.d.ts +166 -0
- package/dist/integrations/meeting-recorder/contracts/transcripts.js +287 -0
- package/dist/integrations/meeting-recorder/contracts/webhooks.d.ts +85 -0
- package/dist/integrations/meeting-recorder/contracts/webhooks.js +172 -0
- package/dist/integrations/meeting-recorder/meeting-recorder.capability.d.ts +1 -0
- package/dist/integrations/meeting-recorder/meeting-recorder.capability.js +18 -0
- package/dist/integrations/meeting-recorder/meeting-recorder.feature.d.ts +5 -0
- package/dist/integrations/meeting-recorder/meeting-recorder.feature.js +33 -0
- package/dist/integrations/meeting-recorder/models.d.ts +402 -0
- package/dist/integrations/meeting-recorder/models.js +122 -0
- package/dist/integrations/meeting-recorder/telemetry.d.ts +13 -0
- package/dist/integrations/meeting-recorder/telemetry.js +54 -0
- package/dist/integrations/openbanking/contracts/accounts.d.ts +282 -0
- package/dist/integrations/openbanking/contracts/accounts.js +328 -0
- package/dist/integrations/openbanking/contracts/balances.d.ts +158 -0
- package/dist/integrations/openbanking/contracts/balances.js +292 -0
- package/dist/integrations/openbanking/contracts/index.d.ts +7 -0
- package/dist/integrations/openbanking/contracts/index.js +644 -0
- package/dist/integrations/openbanking/contracts/transactions.d.ts +206 -0
- package/dist/integrations/openbanking/contracts/transactions.js +298 -0
- package/dist/integrations/openbanking/guards.d.ts +8 -0
- package/dist/integrations/openbanking/guards.js +42 -0
- package/dist/integrations/openbanking/guards.test.d.ts +1 -0
- package/dist/integrations/openbanking/models.d.ts +223 -0
- package/dist/integrations/openbanking/models.js +110 -0
- package/dist/integrations/openbanking/openbanking.capability.d.ts +1 -0
- package/dist/integrations/openbanking/openbanking.capability.js +18 -0
- package/dist/integrations/openbanking/openbanking.feature.d.ts +5 -0
- package/dist/integrations/openbanking/openbanking.feature.js +35 -0
- package/dist/integrations/openbanking/telemetry.d.ts +12 -0
- package/dist/integrations/openbanking/telemetry.js +51 -0
- package/dist/integrations/operations.d.ts +430 -0
- package/dist/integrations/operations.js +297 -0
- package/dist/integrations/operations.test.d.ts +1 -0
- package/dist/integrations/providers/analytics-reader.d.ts +103 -0
- package/dist/integrations/providers/analytics-reader.js +1 -0
- package/dist/integrations/providers/analytics-writer.d.ts +6 -0
- package/dist/integrations/providers/analytics-writer.js +1 -0
- package/dist/integrations/providers/analytics.d.ts +47 -0
- package/dist/integrations/providers/analytics.js +1 -0
- package/dist/integrations/providers/calendar.d.ts +75 -0
- package/dist/integrations/providers/calendar.js +1 -0
- package/dist/integrations/providers/database.d.ts +12 -0
- package/dist/integrations/providers/database.js +1 -0
- package/dist/integrations/providers/elevenlabs.d.ts +3 -0
- package/dist/integrations/providers/elevenlabs.js +86 -0
- package/dist/integrations/providers/email.d.ts +83 -0
- package/dist/integrations/providers/email.js +1 -0
- package/dist/integrations/providers/embedding.d.ts +21 -0
- package/dist/integrations/providers/embedding.js +1 -0
- package/dist/integrations/providers/fal.d.ts +3 -0
- package/dist/integrations/providers/fal.js +112 -0
- package/dist/integrations/providers/fathom.d.ts +3 -0
- package/dist/integrations/providers/fathom.js +126 -0
- package/dist/integrations/providers/fireflies.d.ts +3 -0
- package/dist/integrations/providers/fireflies.js +106 -0
- package/dist/integrations/providers/gcs-storage.d.ts +3 -0
- package/dist/integrations/providers/gcs-storage.js +97 -0
- package/dist/integrations/providers/gmail.d.ts +3 -0
- package/dist/integrations/providers/gmail.js +109 -0
- package/dist/integrations/providers/google-calendar.d.ts +3 -0
- package/dist/integrations/providers/google-calendar.js +92 -0
- package/dist/integrations/providers/gradium.d.ts +3 -0
- package/dist/integrations/providers/gradium.js +110 -0
- package/dist/integrations/providers/granola.d.ts +3 -0
- package/dist/integrations/providers/granola.js +107 -0
- package/dist/integrations/providers/index.d.ts +38 -0
- package/dist/integrations/providers/index.js +2094 -0
- package/dist/integrations/providers/jira.d.ts +3 -0
- package/dist/integrations/providers/jira.js +108 -0
- package/dist/integrations/providers/linear.d.ts +3 -0
- package/dist/integrations/providers/linear.js +107 -0
- package/dist/integrations/providers/llm.d.ts +79 -0
- package/dist/integrations/providers/llm.js +1 -0
- package/dist/integrations/providers/meeting-recorder.d.ts +129 -0
- package/dist/integrations/providers/meeting-recorder.js +1 -0
- package/dist/integrations/providers/mistral.d.ts +3 -0
- package/dist/integrations/providers/mistral.js +94 -0
- package/dist/integrations/providers/notion.d.ts +3 -0
- package/dist/integrations/providers/notion.js +113 -0
- package/dist/integrations/providers/openbanking.d.ts +125 -0
- package/dist/integrations/providers/openbanking.js +1 -0
- package/dist/integrations/providers/payments.d.ts +106 -0
- package/dist/integrations/providers/payments.js +1 -0
- package/dist/integrations/providers/posthog-llm-telemetry.d.ts +51 -0
- package/dist/integrations/providers/posthog-llm-telemetry.js +176 -0
- package/dist/integrations/providers/posthog.d.ts +3 -0
- package/dist/integrations/providers/posthog.js +106 -0
- package/dist/integrations/providers/postmark.d.ts +3 -0
- package/dist/integrations/providers/postmark.js +98 -0
- package/dist/integrations/providers/powens.d.ts +3 -0
- package/dist/integrations/providers/powens.js +124 -0
- package/dist/integrations/providers/project-management.d.ts +32 -0
- package/dist/integrations/providers/project-management.js +1 -0
- package/dist/integrations/providers/providers.test.d.ts +1 -0
- package/dist/integrations/providers/qdrant.d.ts +3 -0
- package/dist/integrations/providers/qdrant.js +101 -0
- package/dist/integrations/providers/registry.d.ts +6 -0
- package/dist/integrations/providers/registry.js +1878 -0
- package/dist/integrations/providers/sms.d.ts +31 -0
- package/dist/integrations/providers/sms.js +1 -0
- package/dist/integrations/providers/storage.d.ts +57 -0
- package/dist/integrations/providers/storage.js +1 -0
- package/dist/integrations/providers/stripe.d.ts +3 -0
- package/dist/integrations/providers/stripe.js +105 -0
- package/dist/integrations/providers/supabase-postgres.d.ts +3 -0
- package/dist/integrations/providers/supabase-postgres.js +87 -0
- package/dist/integrations/providers/supabase-vector.d.ts +3 -0
- package/dist/integrations/providers/supabase-vector.js +107 -0
- package/dist/integrations/providers/tldv.d.ts +3 -0
- package/dist/integrations/providers/tldv.js +106 -0
- package/dist/integrations/providers/twilio-sms.d.ts +3 -0
- package/dist/integrations/providers/twilio-sms.js +91 -0
- package/dist/integrations/providers/vector-store.d.ts +39 -0
- package/dist/integrations/providers/vector-store.js +1 -0
- package/dist/integrations/providers/voice.d.ts +31 -0
- package/dist/integrations/providers/voice.js +1 -0
- package/dist/integrations/runtime.d.ts +95 -0
- package/dist/integrations/runtime.js +209 -0
- package/dist/integrations/runtime.test.d.ts +1 -0
- package/dist/integrations/secrets/aws-secret-manager.d.ts +28 -0
- package/dist/integrations/secrets/aws-secret-manager.js +346 -0
- package/dist/integrations/secrets/env-secret-provider.d.ts +28 -0
- package/dist/integrations/secrets/env-secret-provider.js +159 -0
- package/dist/integrations/secrets/gcp-secret-manager.d.ts +29 -0
- package/dist/integrations/secrets/gcp-secret-manager.js +347 -0
- package/dist/integrations/secrets/index.d.ts +6 -0
- package/dist/integrations/secrets/index.js +1129 -0
- package/dist/integrations/secrets/manager.d.ts +44 -0
- package/dist/integrations/secrets/manager.js +183 -0
- package/dist/integrations/secrets/provider.d.ts +49 -0
- package/dist/integrations/secrets/provider.js +74 -0
- package/dist/integrations/secrets/provider.test.d.ts +1 -0
- package/dist/integrations/secrets/scaleway-secret-manager.d.ts +35 -0
- package/dist/integrations/secrets/scaleway-secret-manager.js +375 -0
- package/dist/integrations/secrets-types.d.ts +14 -0
- package/dist/integrations/secrets-types.js +1 -0
- package/dist/integrations/spec.d.ts +72 -0
- package/dist/integrations/spec.js +22 -0
- package/dist/integrations/spec.test.d.ts +1 -0
- package/dist/node/index.js +3675 -0
- package/dist/node/integrations/binding.js +0 -0
- package/dist/node/integrations/connection.js +0 -0
- package/dist/node/integrations/docs/integrations.docblock.js +109 -0
- package/dist/node/integrations/health.js +72 -0
- package/dist/node/integrations/index.js +3263 -0
- package/dist/node/integrations/integrations.capability.js +17 -0
- package/dist/node/integrations/integrations.feature.js +32 -0
- package/dist/node/integrations/meeting-recorder/contracts/index.js +473 -0
- package/dist/node/integrations/meeting-recorder/contracts/meetings.js +218 -0
- package/dist/node/integrations/meeting-recorder/contracts/transcripts.js +286 -0
- package/dist/node/integrations/meeting-recorder/contracts/webhooks.js +171 -0
- package/dist/node/integrations/meeting-recorder/meeting-recorder.capability.js +17 -0
- package/dist/node/integrations/meeting-recorder/meeting-recorder.feature.js +32 -0
- package/dist/node/integrations/meeting-recorder/models.js +121 -0
- package/dist/node/integrations/meeting-recorder/telemetry.js +53 -0
- package/dist/node/integrations/openbanking/contracts/accounts.js +327 -0
- package/dist/node/integrations/openbanking/contracts/balances.js +291 -0
- package/dist/node/integrations/openbanking/contracts/index.js +643 -0
- package/dist/node/integrations/openbanking/contracts/transactions.js +297 -0
- package/dist/node/integrations/openbanking/guards.js +41 -0
- package/dist/node/integrations/openbanking/models.js +109 -0
- package/dist/node/integrations/openbanking/openbanking.capability.js +17 -0
- package/dist/node/integrations/openbanking/openbanking.feature.js +34 -0
- package/dist/node/integrations/openbanking/telemetry.js +50 -0
- package/dist/node/integrations/operations.js +296 -0
- package/dist/node/integrations/providers/analytics-reader.js +0 -0
- package/dist/node/integrations/providers/analytics-writer.js +0 -0
- package/dist/node/integrations/providers/analytics.js +0 -0
- package/dist/node/integrations/providers/calendar.js +0 -0
- package/dist/node/integrations/providers/database.js +0 -0
- package/dist/node/integrations/providers/elevenlabs.js +85 -0
- package/dist/node/integrations/providers/email.js +0 -0
- package/dist/node/integrations/providers/embedding.js +0 -0
- package/dist/node/integrations/providers/fal.js +111 -0
- package/dist/node/integrations/providers/fathom.js +125 -0
- package/dist/node/integrations/providers/fireflies.js +105 -0
- package/dist/node/integrations/providers/gcs-storage.js +96 -0
- package/dist/node/integrations/providers/gmail.js +108 -0
- package/dist/node/integrations/providers/google-calendar.js +91 -0
- package/dist/node/integrations/providers/gradium.js +109 -0
- package/dist/node/integrations/providers/granola.js +106 -0
- package/dist/node/integrations/providers/index.js +2093 -0
- package/dist/node/integrations/providers/jira.js +107 -0
- package/dist/node/integrations/providers/linear.js +106 -0
- package/dist/node/integrations/providers/llm.js +0 -0
- package/dist/node/integrations/providers/meeting-recorder.js +0 -0
- package/dist/node/integrations/providers/mistral.js +93 -0
- package/dist/node/integrations/providers/notion.js +112 -0
- package/dist/node/integrations/providers/openbanking.js +0 -0
- package/dist/node/integrations/providers/payments.js +0 -0
- package/dist/node/integrations/providers/posthog-llm-telemetry.js +175 -0
- package/dist/node/integrations/providers/posthog.js +105 -0
- package/dist/node/integrations/providers/postmark.js +97 -0
- package/dist/node/integrations/providers/powens.js +123 -0
- package/dist/node/integrations/providers/project-management.js +0 -0
- package/dist/node/integrations/providers/qdrant.js +100 -0
- package/dist/node/integrations/providers/registry.js +1877 -0
- package/dist/node/integrations/providers/sms.js +0 -0
- package/dist/node/integrations/providers/storage.js +0 -0
- package/dist/node/integrations/providers/stripe.js +104 -0
- package/dist/node/integrations/providers/supabase-postgres.js +86 -0
- package/dist/node/integrations/providers/supabase-vector.js +106 -0
- package/dist/node/integrations/providers/tldv.js +105 -0
- package/dist/node/integrations/providers/twilio-sms.js +90 -0
- package/dist/node/integrations/providers/vector-store.js +0 -0
- package/dist/node/integrations/providers/voice.js +0 -0
- package/dist/node/integrations/runtime.js +208 -0
- package/dist/node/integrations/secrets/aws-secret-manager.js +345 -0
- package/dist/node/integrations/secrets/env-secret-provider.js +158 -0
- package/dist/node/integrations/secrets/gcp-secret-manager.js +346 -0
- package/dist/node/integrations/secrets/index.js +1128 -0
- package/dist/node/integrations/secrets/manager.js +182 -0
- package/dist/node/integrations/secrets/provider.js +73 -0
- package/dist/node/integrations/secrets/scaleway-secret-manager.js +374 -0
- package/dist/node/integrations/secrets-types.js +0 -0
- package/dist/node/integrations/spec.js +21 -0
- package/package.json +1029 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
// src/integrations/secrets/provider.ts
|
|
2
|
+
import { Buffer } from "node:buffer";
|
|
3
|
+
|
|
4
|
+
class SecretProviderError extends Error {
|
|
5
|
+
provider;
|
|
6
|
+
reference;
|
|
7
|
+
code;
|
|
8
|
+
cause;
|
|
9
|
+
constructor(params) {
|
|
10
|
+
super(params.message);
|
|
11
|
+
this.name = "SecretProviderError";
|
|
12
|
+
this.provider = params.provider;
|
|
13
|
+
this.reference = params.reference;
|
|
14
|
+
this.code = params.code ?? "UNKNOWN";
|
|
15
|
+
this.cause = params.cause;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function parseSecretUri(reference) {
|
|
19
|
+
if (!reference) {
|
|
20
|
+
throw new SecretProviderError({
|
|
21
|
+
message: "Secret reference cannot be empty",
|
|
22
|
+
provider: "unknown",
|
|
23
|
+
reference,
|
|
24
|
+
code: "INVALID"
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const [scheme, rest] = reference.split("://");
|
|
28
|
+
if (!scheme || !rest) {
|
|
29
|
+
throw new SecretProviderError({
|
|
30
|
+
message: `Invalid secret reference: ${reference}`,
|
|
31
|
+
provider: "unknown",
|
|
32
|
+
reference,
|
|
33
|
+
code: "INVALID"
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const queryIndex = rest.indexOf("?");
|
|
37
|
+
if (queryIndex === -1) {
|
|
38
|
+
return {
|
|
39
|
+
provider: scheme,
|
|
40
|
+
path: rest
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
const path = rest.slice(0, queryIndex);
|
|
44
|
+
const query = rest.slice(queryIndex + 1);
|
|
45
|
+
const extras = Object.fromEntries(query.split("&").filter(Boolean).map((pair) => {
|
|
46
|
+
const [keyRaw, valueRaw] = pair.split("=");
|
|
47
|
+
const key = keyRaw ?? "";
|
|
48
|
+
const value = valueRaw ?? "";
|
|
49
|
+
return [decodeURIComponent(key), decodeURIComponent(value)];
|
|
50
|
+
}));
|
|
51
|
+
return {
|
|
52
|
+
provider: scheme,
|
|
53
|
+
path,
|
|
54
|
+
extras
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function normalizeSecretPayload(payload) {
|
|
58
|
+
if (payload.data instanceof Uint8Array) {
|
|
59
|
+
return payload.data;
|
|
60
|
+
}
|
|
61
|
+
if (payload.encoding === "base64") {
|
|
62
|
+
return Buffer.from(payload.data, "base64");
|
|
63
|
+
}
|
|
64
|
+
if (payload.encoding === "binary") {
|
|
65
|
+
return Buffer.from(payload.data, "binary");
|
|
66
|
+
}
|
|
67
|
+
return Buffer.from(payload.data, "utf-8");
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/integrations/secrets/gcp-secret-manager.ts
|
|
71
|
+
import {
|
|
72
|
+
SecretManagerServiceClient
|
|
73
|
+
} from "@google-cloud/secret-manager";
|
|
74
|
+
var DEFAULT_REPLICATION = {
|
|
75
|
+
automatic: {}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
class GcpSecretManagerProvider {
|
|
79
|
+
id = "gcp-secret-manager";
|
|
80
|
+
client;
|
|
81
|
+
explicitProjectId;
|
|
82
|
+
replication;
|
|
83
|
+
constructor(options = {}) {
|
|
84
|
+
this.client = options.client ?? new SecretManagerServiceClient(options.clientOptions ?? {});
|
|
85
|
+
this.explicitProjectId = options.projectId;
|
|
86
|
+
this.replication = options.defaultReplication ?? DEFAULT_REPLICATION;
|
|
87
|
+
}
|
|
88
|
+
canHandle(reference) {
|
|
89
|
+
try {
|
|
90
|
+
const parsed = parseSecretUri(reference);
|
|
91
|
+
return parsed.provider === "gcp";
|
|
92
|
+
} catch {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
async getSecret(reference, options, callOptions) {
|
|
97
|
+
const location = this.parseReference(reference);
|
|
98
|
+
const secretVersionName = this.buildVersionName(location, options?.version);
|
|
99
|
+
try {
|
|
100
|
+
const response = await this.client.accessSecretVersion({
|
|
101
|
+
name: secretVersionName
|
|
102
|
+
}, callOptions ?? {});
|
|
103
|
+
const [result] = response;
|
|
104
|
+
const payload = result.payload;
|
|
105
|
+
if (!payload?.data) {
|
|
106
|
+
throw new SecretProviderError({
|
|
107
|
+
message: `Secret payload empty for ${secretVersionName}`,
|
|
108
|
+
provider: this.id,
|
|
109
|
+
reference,
|
|
110
|
+
code: "UNKNOWN"
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
const version = extractVersionFromName(result.name ?? secretVersionName);
|
|
114
|
+
return {
|
|
115
|
+
data: payload.data,
|
|
116
|
+
version,
|
|
117
|
+
metadata: payload.dataCrc32c ? { crc32c: payload.dataCrc32c.toString() } : undefined,
|
|
118
|
+
retrievedAt: new Date
|
|
119
|
+
};
|
|
120
|
+
} catch (error) {
|
|
121
|
+
throw toSecretProviderError({
|
|
122
|
+
error,
|
|
123
|
+
provider: this.id,
|
|
124
|
+
reference,
|
|
125
|
+
operation: "access"
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
async setSecret(reference, payload) {
|
|
130
|
+
const location = this.parseReference(reference);
|
|
131
|
+
const { secretName } = this.buildNames(location);
|
|
132
|
+
const data = normalizeSecretPayload(payload);
|
|
133
|
+
await this.ensureSecretExists(location, payload);
|
|
134
|
+
try {
|
|
135
|
+
const response = await this.client.addSecretVersion({
|
|
136
|
+
parent: secretName,
|
|
137
|
+
payload: {
|
|
138
|
+
data
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
if (!response) {
|
|
142
|
+
throw new SecretProviderError({
|
|
143
|
+
message: `No version returned when adding secret version for ${secretName}`,
|
|
144
|
+
provider: this.id,
|
|
145
|
+
reference,
|
|
146
|
+
code: "UNKNOWN"
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const [version] = response;
|
|
150
|
+
const versionName = version?.name ?? `${secretName}/versions/latest`;
|
|
151
|
+
return {
|
|
152
|
+
reference: `gcp://${versionName}`,
|
|
153
|
+
version: extractVersionFromName(versionName) ?? "latest"
|
|
154
|
+
};
|
|
155
|
+
} catch (error) {
|
|
156
|
+
throw toSecretProviderError({
|
|
157
|
+
error,
|
|
158
|
+
provider: this.id,
|
|
159
|
+
reference,
|
|
160
|
+
operation: "addSecretVersion"
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async rotateSecret(reference, payload) {
|
|
165
|
+
return this.setSecret(reference, payload);
|
|
166
|
+
}
|
|
167
|
+
async deleteSecret(reference) {
|
|
168
|
+
const location = this.parseReference(reference);
|
|
169
|
+
const { secretName } = this.buildNames(location);
|
|
170
|
+
try {
|
|
171
|
+
await this.client.deleteSecret({
|
|
172
|
+
name: secretName
|
|
173
|
+
});
|
|
174
|
+
} catch (error) {
|
|
175
|
+
throw toSecretProviderError({
|
|
176
|
+
error,
|
|
177
|
+
provider: this.id,
|
|
178
|
+
reference,
|
|
179
|
+
operation: "delete"
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
parseReference(reference) {
|
|
184
|
+
const parsed = parseSecretUri(reference);
|
|
185
|
+
if (parsed.provider !== "gcp") {
|
|
186
|
+
throw new SecretProviderError({
|
|
187
|
+
message: `Unsupported secret provider: ${parsed.provider}`,
|
|
188
|
+
provider: this.id,
|
|
189
|
+
reference,
|
|
190
|
+
code: "INVALID"
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
const segments = parsed.path.split("/").filter(Boolean);
|
|
194
|
+
if (segments.length < 4 || segments[0] !== "projects") {
|
|
195
|
+
throw new SecretProviderError({
|
|
196
|
+
message: `Expected secret reference format gcp://projects/{project}/secrets/{secret}[(/versions/{version})] but received "${parsed.path}"`,
|
|
197
|
+
provider: this.id,
|
|
198
|
+
reference,
|
|
199
|
+
code: "INVALID"
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
const projectIdCandidate = segments[1] ?? this.explicitProjectId;
|
|
203
|
+
if (!projectIdCandidate) {
|
|
204
|
+
throw new SecretProviderError({
|
|
205
|
+
message: `Unable to resolve project or secret from reference "${parsed.path}"`,
|
|
206
|
+
provider: this.id,
|
|
207
|
+
reference,
|
|
208
|
+
code: "INVALID"
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
const indexOfSecrets = segments.indexOf("secrets");
|
|
212
|
+
if (indexOfSecrets === -1 || indexOfSecrets + 1 >= segments.length) {
|
|
213
|
+
throw new SecretProviderError({
|
|
214
|
+
message: `Unable to resolve project or secret from reference "${parsed.path}"`,
|
|
215
|
+
provider: this.id,
|
|
216
|
+
reference,
|
|
217
|
+
code: "INVALID"
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
const resolvedProjectId = projectIdCandidate;
|
|
221
|
+
const secretIdCandidate = segments[indexOfSecrets + 1];
|
|
222
|
+
if (!secretIdCandidate) {
|
|
223
|
+
throw new SecretProviderError({
|
|
224
|
+
message: `Unable to resolve secret ID from reference "${parsed.path}"`,
|
|
225
|
+
provider: this.id,
|
|
226
|
+
reference,
|
|
227
|
+
code: "INVALID"
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
const secretId = secretIdCandidate;
|
|
231
|
+
const indexOfVersions = segments.indexOf("versions");
|
|
232
|
+
const version = parsed.extras?.version ?? (indexOfVersions !== -1 && indexOfVersions + 1 < segments.length ? segments[indexOfVersions + 1] : undefined);
|
|
233
|
+
return {
|
|
234
|
+
projectId: resolvedProjectId,
|
|
235
|
+
secretId,
|
|
236
|
+
version
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
buildNames(location) {
|
|
240
|
+
const projectId = location.projectId ?? this.explicitProjectId;
|
|
241
|
+
if (!projectId) {
|
|
242
|
+
throw new SecretProviderError({
|
|
243
|
+
message: "Project ID must be provided either in reference or provider configuration",
|
|
244
|
+
provider: this.id,
|
|
245
|
+
reference: `gcp://projects//secrets/${location.secretId}`,
|
|
246
|
+
code: "INVALID"
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
const projectParent = `projects/${projectId}`;
|
|
250
|
+
const secretName = `${projectParent}/secrets/${location.secretId}`;
|
|
251
|
+
return {
|
|
252
|
+
projectParent,
|
|
253
|
+
secretName
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
buildVersionName(location, explicitVersion) {
|
|
257
|
+
const { secretName } = this.buildNames(location);
|
|
258
|
+
const version = explicitVersion ?? location.version ?? "latest";
|
|
259
|
+
return `${secretName}/versions/${version}`;
|
|
260
|
+
}
|
|
261
|
+
async ensureSecretExists(location, payload) {
|
|
262
|
+
const { secretName, projectParent } = this.buildNames(location);
|
|
263
|
+
try {
|
|
264
|
+
await this.client.getSecret({ name: secretName });
|
|
265
|
+
} catch (error) {
|
|
266
|
+
const providerError = toSecretProviderError({
|
|
267
|
+
error,
|
|
268
|
+
provider: this.id,
|
|
269
|
+
reference: `gcp://${secretName}`,
|
|
270
|
+
operation: "getSecret",
|
|
271
|
+
suppressThrow: true
|
|
272
|
+
});
|
|
273
|
+
if (!providerError || providerError.code !== "NOT_FOUND") {
|
|
274
|
+
if (providerError) {
|
|
275
|
+
throw providerError;
|
|
276
|
+
}
|
|
277
|
+
throw error;
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
await this.client.createSecret({
|
|
281
|
+
parent: projectParent,
|
|
282
|
+
secretId: location.secretId,
|
|
283
|
+
secret: {
|
|
284
|
+
replication: this.replication,
|
|
285
|
+
labels: payload.labels
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
} catch (creationError) {
|
|
289
|
+
const creationProviderError = toSecretProviderError({
|
|
290
|
+
error: creationError,
|
|
291
|
+
provider: this.id,
|
|
292
|
+
reference: `gcp://${secretName}`,
|
|
293
|
+
operation: "createSecret"
|
|
294
|
+
});
|
|
295
|
+
throw creationProviderError;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function extractVersionFromName(name) {
|
|
301
|
+
const segments = name.split("/").filter(Boolean);
|
|
302
|
+
const index = segments.indexOf("versions");
|
|
303
|
+
if (index === -1 || index + 1 >= segments.length) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
return segments[index + 1];
|
|
307
|
+
}
|
|
308
|
+
function toSecretProviderError(params) {
|
|
309
|
+
const { error, provider, reference, operation, suppressThrow } = params;
|
|
310
|
+
if (error instanceof SecretProviderError) {
|
|
311
|
+
return error;
|
|
312
|
+
}
|
|
313
|
+
const code = deriveErrorCode(error);
|
|
314
|
+
const message = error instanceof Error ? error.message : `Unknown error during ${operation}`;
|
|
315
|
+
const providerError = new SecretProviderError({
|
|
316
|
+
message,
|
|
317
|
+
provider,
|
|
318
|
+
reference,
|
|
319
|
+
code,
|
|
320
|
+
cause: error
|
|
321
|
+
});
|
|
322
|
+
if (suppressThrow) {
|
|
323
|
+
return providerError;
|
|
324
|
+
}
|
|
325
|
+
throw providerError;
|
|
326
|
+
}
|
|
327
|
+
function deriveErrorCode(error) {
|
|
328
|
+
if (typeof error !== "object" || error === null) {
|
|
329
|
+
return "UNKNOWN";
|
|
330
|
+
}
|
|
331
|
+
const errorAny = error;
|
|
332
|
+
const code = errorAny.code;
|
|
333
|
+
if (code === 5 || code === "NOT_FOUND")
|
|
334
|
+
return "NOT_FOUND";
|
|
335
|
+
if (code === 6 || code === "ALREADY_EXISTS")
|
|
336
|
+
return "INVALID";
|
|
337
|
+
if (code === 7 || code === "PERMISSION_DENIED" || code === 403) {
|
|
338
|
+
return "FORBIDDEN";
|
|
339
|
+
}
|
|
340
|
+
if (code === 3 || code === "INVALID_ARGUMENT")
|
|
341
|
+
return "INVALID";
|
|
342
|
+
return "UNKNOWN";
|
|
343
|
+
}
|
|
344
|
+
export {
|
|
345
|
+
GcpSecretManagerProvider
|
|
346
|
+
};
|