@rafads/plugin-openapi 1.5.38
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 +83 -0
- package/dist/AddOpenApiIntegration-JPAEXE56.js +512 -0
- package/dist/AddOpenApiIntegration-JPAEXE56.js.map +1 -0
- package/dist/OpenApiAccountsPanel-GZFDSTAU.js +106 -0
- package/dist/OpenApiAccountsPanel-GZFDSTAU.js.map +1 -0
- package/dist/UpdateSpecSection-KUSNI44Q.js +106 -0
- package/dist/UpdateSpecSection-KUSNI44Q.js.map +1 -0
- package/dist/api/group.d.ts +239 -0
- package/dist/api/handlers.d.ts +7 -0
- package/dist/api/index.d.ts +237 -0
- package/dist/chunk-6V45G2XQ.js +199 -0
- package/dist/chunk-6V45G2XQ.js.map +1 -0
- package/dist/chunk-CURJJXB3.js +132 -0
- package/dist/chunk-CURJJXB3.js.map +1 -0
- package/dist/chunk-CXFO6TLJ.js +39 -0
- package/dist/chunk-CXFO6TLJ.js.map +1 -0
- package/dist/chunk-HTHEUUJA.js +2873 -0
- package/dist/chunk-HTHEUUJA.js.map +1 -0
- package/dist/chunk-IG6QTTZB.js +79 -0
- package/dist/chunk-IG6QTTZB.js.map +1 -0
- package/dist/chunk-O2LMSZ2Z.js +120 -0
- package/dist/chunk-O2LMSZ2Z.js.map +1 -0
- package/dist/chunk-OR27BCXQ.js +956 -0
- package/dist/chunk-OR27BCXQ.js.map +1 -0
- package/dist/chunk-R7TVM3XD.js +275 -0
- package/dist/chunk-R7TVM3XD.js.map +1 -0
- package/dist/client.js +38 -0
- package/dist/client.js.map +1 -0
- package/dist/core.js +331 -0
- package/dist/core.js.map +1 -0
- package/dist/index.js +19 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/google/config.d.ts +34 -0
- package/dist/providers/google/discovery.d.ts +49 -0
- package/dist/providers/google/discovery.test.d.ts +1 -0
- package/dist/providers/google/index.d.ts +5 -0
- package/dist/providers/google/oauth-scopes.d.ts +3 -0
- package/dist/providers/google/oauth-scopes.test.d.ts +1 -0
- package/dist/providers/google/openapi-ownership-migration.d.ts +7 -0
- package/dist/providers/google/openapi-ownership-migration.test.d.ts +1 -0
- package/dist/providers/google/presets.d.ts +31 -0
- package/dist/providers/google/presets.test.d.ts +1 -0
- package/dist/providers/google/spec-format-adapter.d.ts +3 -0
- package/dist/providers/google/spec-format-adapter.test.d.ts +1 -0
- package/dist/providers/google.js +1446 -0
- package/dist/providers/google.js.map +1 -0
- package/dist/providers/microsoft/graph.d.ts +76 -0
- package/dist/providers/microsoft/graph.test.d.ts +1 -0
- package/dist/providers/microsoft/index.d.ts +3 -0
- package/dist/providers/microsoft/presets.d.ts +46 -0
- package/dist/providers/microsoft/presets.test.d.ts +1 -0
- package/dist/providers/microsoft/spec-format-adapter.d.ts +2 -0
- package/dist/providers/microsoft/spec-format-adapter.test.d.ts +1 -0
- package/dist/providers/microsoft.js +1056 -0
- package/dist/providers/microsoft.js.map +1 -0
- package/dist/react/AddOpenApiIntegration.d.ts +22 -0
- package/dist/react/AddOpenApiIntegration.test.d.ts +1 -0
- package/dist/react/OpenApiAccountsPanel.d.ts +6 -0
- package/dist/react/OpenApiIntegrationDetailsFields.d.ts +25 -0
- package/dist/react/UpdateSpecSection.d.ts +2 -0
- package/dist/react/atoms.d.ts +317 -0
- package/dist/react/auth-method-config.d.ts +18 -0
- package/dist/react/auth-method-config.test.d.ts +1 -0
- package/dist/react/client.d.ts +233 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/integration-plugin.d.ts +6 -0
- package/dist/react/plugin-client.d.ts +2 -0
- package/dist/sdk/backing.d.ts +188 -0
- package/dist/sdk/client-credentials-oauth.test.d.ts +1 -0
- package/dist/sdk/compiled-spec-cache.test.d.ts +1 -0
- package/dist/sdk/config.d.ts +81 -0
- package/dist/sdk/configure.test.d.ts +1 -0
- package/dist/sdk/definitions.d.ts +57 -0
- package/dist/sdk/derive-auth.d.ts +11 -0
- package/dist/sdk/describe-auth-methods.test.d.ts +1 -0
- package/dist/sdk/errors.d.ts +45 -0
- package/dist/sdk/extract.d.ts +157 -0
- package/dist/sdk/extract.test.d.ts +1 -0
- package/dist/sdk/form-urlencoded-body.test.d.ts +1 -0
- package/dist/sdk/index.d.ts +19 -0
- package/dist/sdk/index.test.d.ts +1 -0
- package/dist/sdk/invoke.d.ts +150 -0
- package/dist/sdk/migrate-config.d.ts +4 -0
- package/dist/sdk/migrate-config.test.d.ts +1 -0
- package/dist/sdk/multi-scope-bearer.test.d.ts +1 -0
- package/dist/sdk/multi-scope-oauth.test.d.ts +1 -0
- package/dist/sdk/ndjson-output-migration.d.ts +13 -0
- package/dist/sdk/ndjson-output-migration.test.d.ts +1 -0
- package/dist/sdk/non-json-body.test.d.ts +1 -0
- package/dist/sdk/oauth-refresh.test.d.ts +1 -0
- package/dist/sdk/openapi-utils.d.ts +65 -0
- package/dist/sdk/output-schema-migration.d.ts +21 -0
- package/dist/sdk/output-schema-migration.test.d.ts +1 -0
- package/dist/sdk/parse.d.ts +33 -0
- package/dist/sdk/parse.test.d.ts +1 -0
- package/dist/sdk/plugin.d.ts +109 -0
- package/dist/sdk/plugin.test.d.ts +1 -0
- package/dist/sdk/presets.d.ts +15 -0
- package/dist/sdk/preview-oauth2.test.d.ts +1 -0
- package/dist/sdk/preview.d.ts +514 -0
- package/dist/sdk/query-serialization.test.d.ts +1 -0
- package/dist/sdk/real-specs.test.d.ts +1 -0
- package/dist/sdk/request-user-agent.test.d.ts +1 -0
- package/dist/sdk/response-headers-timeout.test.d.ts +1 -0
- package/dist/sdk/server-url-resolution.test.d.ts +1 -0
- package/dist/sdk/spec-blob-migration.d.ts +7 -0
- package/dist/sdk/spec-blob.test.d.ts +1 -0
- package/dist/sdk/spec-format.d.ts +36 -0
- package/dist/sdk/spec-format.test.d.ts +1 -0
- package/dist/sdk/split.d.ts +84 -0
- package/dist/sdk/store.d.ts +49 -0
- package/dist/sdk/store.test.d.ts +1 -0
- package/dist/sdk/streaming-response.test.d.ts +1 -0
- package/dist/sdk/tool-row-projection.test.d.ts +1 -0
- package/dist/sdk/types.d.ts +352 -0
- package/dist/sdk/upstream-failures.test.d.ts +1 -0
- package/dist/sdk/usage-scope-isolation.test.d.ts +1 -0
- package/dist/testing/index.d.ts +177 -0
- package/dist/testing.js +454 -0
- package/dist/testing.js.map +1 -0
- package/dist/testing.test.d.ts +1 -0
- package/package.json +103 -0
package/dist/core.js
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import {
|
|
2
|
+
makeDefaultOpenapiStore,
|
|
3
|
+
openApiPlugin,
|
|
4
|
+
resolveSpecFormatAdapter
|
|
5
|
+
} from "./chunk-OR27BCXQ.js";
|
|
6
|
+
import "./chunk-CURJJXB3.js";
|
|
7
|
+
import "./chunk-O2LMSZ2Z.js";
|
|
8
|
+
import {
|
|
9
|
+
AuthStrategy,
|
|
10
|
+
DocResolver,
|
|
11
|
+
EncodingObject,
|
|
12
|
+
ExtractedOperation,
|
|
13
|
+
ExtractionResult,
|
|
14
|
+
HeaderPreset,
|
|
15
|
+
HttpMethod,
|
|
16
|
+
InvocationResult,
|
|
17
|
+
MediaBinding,
|
|
18
|
+
OAuth2AuthorizationCodeFlow,
|
|
19
|
+
OAuth2ClientCredentialsFlow,
|
|
20
|
+
OAuth2Flows,
|
|
21
|
+
OAuth2Preset,
|
|
22
|
+
OperationBinding,
|
|
23
|
+
OperationId,
|
|
24
|
+
OperationParameter,
|
|
25
|
+
OperationRequestBody,
|
|
26
|
+
ParameterLocation,
|
|
27
|
+
PreviewOperation,
|
|
28
|
+
RESPONSE_HEADERS_TIMEOUT_MS,
|
|
29
|
+
SecurityScheme,
|
|
30
|
+
ServerInfo,
|
|
31
|
+
ServerVariable,
|
|
32
|
+
SpecPreview,
|
|
33
|
+
TOKEN_VARIABLE,
|
|
34
|
+
annotationsForOperation,
|
|
35
|
+
buildDefsJsonStreaming,
|
|
36
|
+
buildRequest,
|
|
37
|
+
checkHealthOpenApi,
|
|
38
|
+
compileAndPersistOpenApiOperations,
|
|
39
|
+
compileAndPersistOpenApiSpec,
|
|
40
|
+
compileAndPersistOpenApiSpecStreaming,
|
|
41
|
+
compileOpenApiDocument,
|
|
42
|
+
compileOpenApiSpec,
|
|
43
|
+
extract,
|
|
44
|
+
extractOpenApiUpstreamMessage,
|
|
45
|
+
fetchSpecText,
|
|
46
|
+
invoke,
|
|
47
|
+
invokeOpenApiBackedTool,
|
|
48
|
+
invokeWithLayer,
|
|
49
|
+
listHealthCheckCandidatesOpenApi,
|
|
50
|
+
loadOpenApiSpecText,
|
|
51
|
+
normalizeOpenApiAuthInputs,
|
|
52
|
+
normalizeOpenApiRefs,
|
|
53
|
+
openApiStoredOperationsFromCompiled,
|
|
54
|
+
openApiToolDefsFromCompiled,
|
|
55
|
+
parse,
|
|
56
|
+
preferredContent,
|
|
57
|
+
previewSpec,
|
|
58
|
+
resolveOpenApiBackedAnnotations,
|
|
59
|
+
resolveOpenApiBackedTools,
|
|
60
|
+
resolveServerUrl,
|
|
61
|
+
resolveSpecText,
|
|
62
|
+
streamOperationBindingsFromStructure,
|
|
63
|
+
substituteUrlVariables,
|
|
64
|
+
validateOpenApiBackedToolArgs
|
|
65
|
+
} from "./chunk-HTHEUUJA.js";
|
|
66
|
+
import {
|
|
67
|
+
AuthenticationSchema,
|
|
68
|
+
OpenApiIntegrationConfigSchema,
|
|
69
|
+
collectReferencedSchemas,
|
|
70
|
+
decodeOpenApiIntegrationConfig,
|
|
71
|
+
indexSchemas,
|
|
72
|
+
isStreamableSpec,
|
|
73
|
+
parseEntry,
|
|
74
|
+
parseHead,
|
|
75
|
+
parseSmallComponents,
|
|
76
|
+
renderAuthTemplate,
|
|
77
|
+
structuralSplit
|
|
78
|
+
} from "./chunk-R7TVM3XD.js";
|
|
79
|
+
import {
|
|
80
|
+
OpenApiAuthRequiredError,
|
|
81
|
+
OpenApiExtractionError,
|
|
82
|
+
OpenApiInvocationError,
|
|
83
|
+
OpenApiOAuthError,
|
|
84
|
+
OpenApiParseError
|
|
85
|
+
} from "./chunk-CXFO6TLJ.js";
|
|
86
|
+
|
|
87
|
+
// src/sdk/index.ts
|
|
88
|
+
import { variable } from "@rafads/sdk/http-auth";
|
|
89
|
+
|
|
90
|
+
// src/sdk/migrate-config.ts
|
|
91
|
+
import { Option } from "effect";
|
|
92
|
+
import { apiKeyMethodFromLegacyTemplate, decodeLegacyApiKeyTemplate } from "@rafads/sdk/http-auth";
|
|
93
|
+
var isCanonicalEntry = (entry) => typeof entry === "object" && entry !== null && "kind" in entry && (entry.kind === "apikey" || entry.kind === "oauth2");
|
|
94
|
+
var isLegacyOAuthEntry = (entry) => typeof entry === "object" && entry !== null && "type" in entry && entry.type === "oauth";
|
|
95
|
+
var migrateEntry = (entry) => {
|
|
96
|
+
if (isCanonicalEntry(entry)) return entry;
|
|
97
|
+
if (isLegacyOAuthEntry(entry)) {
|
|
98
|
+
const { type: _type, ...rest } = entry;
|
|
99
|
+
return { ...rest, kind: "oauth2" };
|
|
100
|
+
}
|
|
101
|
+
const legacy = Option.getOrNull(decodeLegacyApiKeyTemplate(entry));
|
|
102
|
+
if (legacy !== null) return apiKeyMethodFromLegacyTemplate(legacy);
|
|
103
|
+
return null;
|
|
104
|
+
};
|
|
105
|
+
var migrateOpenApiAuthConfig = (config) => {
|
|
106
|
+
if (typeof config !== "object" || config === null) return null;
|
|
107
|
+
if (!("spec" in config) && !("specHash" in config)) return null;
|
|
108
|
+
if (!("authenticationTemplate" in config)) return null;
|
|
109
|
+
const entries = config.authenticationTemplate;
|
|
110
|
+
if (!Array.isArray(entries)) return null;
|
|
111
|
+
const migrated = entries.map(migrateEntry);
|
|
112
|
+
if (migrated.some((entry) => entry === null)) return null;
|
|
113
|
+
const changed = migrated.some((entry, index) => entry !== entries[index]);
|
|
114
|
+
if (!changed) return null;
|
|
115
|
+
const next = { ...config, authenticationTemplate: migrated };
|
|
116
|
+
return decodeOpenApiIntegrationConfig(next) !== null ? next : null;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// src/sdk/output-schema-migration.ts
|
|
120
|
+
import { Effect, Option as Option2, Schema } from "effect";
|
|
121
|
+
import { DataMigrationError } from "@rafads/sdk/core";
|
|
122
|
+
var MIGRATION_NAME = "2026-06-11-openapi-output-envelope-unwrap";
|
|
123
|
+
var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
124
|
+
var isEnvelopeStatusSchema = (value) => isRecord(value) && Object.keys(value).length === 1 && value.type === "integer";
|
|
125
|
+
var isEnvelopeHeadersSchema = (value) => isRecord(value) && Object.keys(value).length === 2 && value.type === "object" && isRecord(value.additionalProperties) && Object.keys(value.additionalProperties).length === 1 && value.additionalProperties.type === "string";
|
|
126
|
+
var unwrapOpenApiTransportEnvelope = (schema) => {
|
|
127
|
+
if (!isRecord(schema)) return void 0;
|
|
128
|
+
if (schema.type !== "object" || schema.additionalProperties !== false) return void 0;
|
|
129
|
+
const required = schema.required;
|
|
130
|
+
if (!Array.isArray(required) || required.length !== 3) return void 0;
|
|
131
|
+
if (!["status", "headers", "data"].every((key) => required.includes(key))) return void 0;
|
|
132
|
+
const properties = schema.properties;
|
|
133
|
+
if (!isRecord(properties) || !("data" in properties)) return void 0;
|
|
134
|
+
if (!isEnvelopeStatusSchema(properties.status)) return void 0;
|
|
135
|
+
if (!isEnvelopeHeadersSchema(properties.headers)) return void 0;
|
|
136
|
+
const data = properties.data;
|
|
137
|
+
const outputSchema = isRecord(data) && Object.keys(data).length === 0 ? null : data;
|
|
138
|
+
return { outputSchema };
|
|
139
|
+
};
|
|
140
|
+
var decodeJsonOption = Schema.decodeUnknownOption(Schema.UnknownFromJsonString);
|
|
141
|
+
var execute = (client, stmt) => Effect.tryPromise({
|
|
142
|
+
try: () => client.execute(stmt),
|
|
143
|
+
catch: (cause) => new DataMigrationError({ migration: MIGRATION_NAME, cause })
|
|
144
|
+
});
|
|
145
|
+
var runSqliteOpenApiOutputSchemaMigration = (client) => Effect.gen(function* () {
|
|
146
|
+
const exists = yield* execute(
|
|
147
|
+
client,
|
|
148
|
+
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'tool'"
|
|
149
|
+
);
|
|
150
|
+
if (exists.rows.length === 0) return 0;
|
|
151
|
+
const result = yield* execute(
|
|
152
|
+
client,
|
|
153
|
+
"SELECT row_id, output_schema FROM tool WHERE plugin_id = 'openapi' AND output_schema IS NOT NULL"
|
|
154
|
+
);
|
|
155
|
+
const updates = [];
|
|
156
|
+
for (const row of result.rows) {
|
|
157
|
+
if (typeof row.row_id !== "string" || typeof row.output_schema !== "string") continue;
|
|
158
|
+
const schema = decodeJsonOption(row.output_schema);
|
|
159
|
+
if (Option2.isNone(schema)) continue;
|
|
160
|
+
const unwrapped = unwrapOpenApiTransportEnvelope(schema.value);
|
|
161
|
+
if (unwrapped !== void 0) updates.push({ rowId: row.row_id, ...unwrapped });
|
|
162
|
+
}
|
|
163
|
+
if (updates.length === 0) return 0;
|
|
164
|
+
const applyAll = Effect.gen(function* () {
|
|
165
|
+
for (const update of updates) {
|
|
166
|
+
yield* execute(client, {
|
|
167
|
+
sql: "UPDATE tool SET output_schema = ? WHERE row_id = ?",
|
|
168
|
+
args: [
|
|
169
|
+
update.outputSchema === null ? null : JSON.stringify(update.outputSchema),
|
|
170
|
+
update.rowId
|
|
171
|
+
]
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
yield* execute(client, "COMMIT");
|
|
175
|
+
});
|
|
176
|
+
yield* execute(client, "BEGIN");
|
|
177
|
+
yield* applyAll.pipe(Effect.tapError(() => execute(client, "ROLLBACK").pipe(Effect.ignore)));
|
|
178
|
+
return updates.length;
|
|
179
|
+
});
|
|
180
|
+
var openApiOutputSchemaDataMigration = {
|
|
181
|
+
name: MIGRATION_NAME,
|
|
182
|
+
run: (client) => runSqliteOpenApiOutputSchemaMigration(client).pipe(Effect.asVoid)
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
// src/sdk/ndjson-output-migration.ts
|
|
186
|
+
import { Effect as Effect2 } from "effect";
|
|
187
|
+
import { DataMigrationError as DataMigrationError2 } from "@rafads/sdk/core";
|
|
188
|
+
var MIGRATION_NAME2 = "2026-07-09-openapi-ndjson-output-arrays";
|
|
189
|
+
var NDJSON_TYPE_PROBES = [
|
|
190
|
+
"application/stream+json",
|
|
191
|
+
"application/x-ndjson",
|
|
192
|
+
"application/jsonl"
|
|
193
|
+
];
|
|
194
|
+
var execute2 = (client, stmt) => Effect2.tryPromise({
|
|
195
|
+
try: () => client.execute(stmt),
|
|
196
|
+
catch: (cause) => new DataMigrationError2({ migration: MIGRATION_NAME2, cause })
|
|
197
|
+
});
|
|
198
|
+
var tableExists = (client, table) => Effect2.map(
|
|
199
|
+
execute2(client, {
|
|
200
|
+
sql: "SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?",
|
|
201
|
+
args: [table]
|
|
202
|
+
}),
|
|
203
|
+
(result) => result.rows.length > 0
|
|
204
|
+
);
|
|
205
|
+
var runSqliteNdjsonOutputMigration = (client) => Effect2.gen(function* () {
|
|
206
|
+
for (const table of ["connection", "plugin_storage"]) {
|
|
207
|
+
if (!(yield* tableExists(client, table))) return 0;
|
|
208
|
+
}
|
|
209
|
+
const probes = NDJSON_TYPE_PROBES.map(() => "ps.data LIKE ?").join(" OR ");
|
|
210
|
+
const affected = yield* execute2(client, {
|
|
211
|
+
sql: `SELECT DISTINCT ps.tenant AS tenant, json_extract(ps.data, '$.integration') AS integration
|
|
212
|
+
FROM plugin_storage ps
|
|
213
|
+
WHERE ps.collection = 'operation' AND (${probes})`,
|
|
214
|
+
args: NDJSON_TYPE_PROBES.map((probe) => `%${probe}%`)
|
|
215
|
+
});
|
|
216
|
+
let marked = 0;
|
|
217
|
+
for (const row of affected.rows) {
|
|
218
|
+
if (typeof row.tenant !== "string" || typeof row.integration !== "string") continue;
|
|
219
|
+
yield* execute2(client, {
|
|
220
|
+
sql: "UPDATE connection SET tools_synced_at = NULL WHERE tenant = ? AND integration = ?",
|
|
221
|
+
args: [row.tenant, row.integration]
|
|
222
|
+
});
|
|
223
|
+
marked += 1;
|
|
224
|
+
}
|
|
225
|
+
return marked;
|
|
226
|
+
});
|
|
227
|
+
var openApiNdjsonOutputDataMigration = {
|
|
228
|
+
name: MIGRATION_NAME2,
|
|
229
|
+
run: (client) => runSqliteNdjsonOutputMigration(client).pipe(Effect2.asVoid)
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// src/sdk/spec-blob-migration.ts
|
|
233
|
+
import { Effect as Effect3 } from "effect";
|
|
234
|
+
import { runSqliteConfigBlobMigration } from "@rafads/sdk/core";
|
|
235
|
+
var MIGRATION_NAME3 = "2026-06-12-openapi-spec-to-blob";
|
|
236
|
+
var openApiSpecBlobDataMigration = {
|
|
237
|
+
name: MIGRATION_NAME3,
|
|
238
|
+
run: (client) => runSqliteConfigBlobMigration(client, {
|
|
239
|
+
migrationName: MIGRATION_NAME3,
|
|
240
|
+
pluginId: "openapi",
|
|
241
|
+
inlineField: "spec",
|
|
242
|
+
hashField: "specHash",
|
|
243
|
+
blobKeyPrefix: "spec"
|
|
244
|
+
}).pipe(Effect3.asVoid)
|
|
245
|
+
};
|
|
246
|
+
export {
|
|
247
|
+
AuthStrategy,
|
|
248
|
+
AuthenticationSchema,
|
|
249
|
+
DocResolver,
|
|
250
|
+
EncodingObject,
|
|
251
|
+
ExtractedOperation,
|
|
252
|
+
ExtractionResult,
|
|
253
|
+
HeaderPreset,
|
|
254
|
+
HttpMethod,
|
|
255
|
+
InvocationResult,
|
|
256
|
+
MediaBinding,
|
|
257
|
+
OAuth2AuthorizationCodeFlow,
|
|
258
|
+
OAuth2ClientCredentialsFlow,
|
|
259
|
+
OAuth2Flows,
|
|
260
|
+
OAuth2Preset,
|
|
261
|
+
OpenApiAuthRequiredError,
|
|
262
|
+
OpenApiExtractionError,
|
|
263
|
+
OpenApiIntegrationConfigSchema,
|
|
264
|
+
OpenApiInvocationError,
|
|
265
|
+
OpenApiOAuthError,
|
|
266
|
+
OpenApiParseError,
|
|
267
|
+
OperationBinding,
|
|
268
|
+
OperationId,
|
|
269
|
+
OperationParameter,
|
|
270
|
+
OperationRequestBody,
|
|
271
|
+
ParameterLocation,
|
|
272
|
+
PreviewOperation,
|
|
273
|
+
RESPONSE_HEADERS_TIMEOUT_MS,
|
|
274
|
+
SecurityScheme,
|
|
275
|
+
ServerInfo,
|
|
276
|
+
ServerVariable,
|
|
277
|
+
SpecPreview,
|
|
278
|
+
TOKEN_VARIABLE,
|
|
279
|
+
annotationsForOperation,
|
|
280
|
+
buildDefsJsonStreaming,
|
|
281
|
+
buildRequest,
|
|
282
|
+
checkHealthOpenApi,
|
|
283
|
+
collectReferencedSchemas,
|
|
284
|
+
compileAndPersistOpenApiOperations,
|
|
285
|
+
compileAndPersistOpenApiSpec,
|
|
286
|
+
compileAndPersistOpenApiSpecStreaming,
|
|
287
|
+
compileOpenApiDocument,
|
|
288
|
+
compileOpenApiSpec,
|
|
289
|
+
decodeOpenApiIntegrationConfig,
|
|
290
|
+
extract,
|
|
291
|
+
extractOpenApiUpstreamMessage,
|
|
292
|
+
fetchSpecText,
|
|
293
|
+
indexSchemas,
|
|
294
|
+
invoke,
|
|
295
|
+
invokeOpenApiBackedTool,
|
|
296
|
+
invokeWithLayer,
|
|
297
|
+
isStreamableSpec,
|
|
298
|
+
listHealthCheckCandidatesOpenApi,
|
|
299
|
+
loadOpenApiSpecText,
|
|
300
|
+
makeDefaultOpenapiStore,
|
|
301
|
+
migrateOpenApiAuthConfig,
|
|
302
|
+
normalizeOpenApiAuthInputs,
|
|
303
|
+
normalizeOpenApiRefs,
|
|
304
|
+
openApiNdjsonOutputDataMigration,
|
|
305
|
+
openApiOutputSchemaDataMigration,
|
|
306
|
+
openApiPlugin,
|
|
307
|
+
openApiSpecBlobDataMigration,
|
|
308
|
+
openApiStoredOperationsFromCompiled,
|
|
309
|
+
openApiToolDefsFromCompiled,
|
|
310
|
+
parse,
|
|
311
|
+
parseEntry,
|
|
312
|
+
parseHead,
|
|
313
|
+
parseSmallComponents,
|
|
314
|
+
preferredContent,
|
|
315
|
+
previewSpec,
|
|
316
|
+
renderAuthTemplate,
|
|
317
|
+
resolveOpenApiBackedAnnotations,
|
|
318
|
+
resolveOpenApiBackedTools,
|
|
319
|
+
resolveServerUrl,
|
|
320
|
+
resolveSpecFormatAdapter,
|
|
321
|
+
resolveSpecText,
|
|
322
|
+
runSqliteNdjsonOutputMigration,
|
|
323
|
+
runSqliteOpenApiOutputSchemaMigration,
|
|
324
|
+
streamOperationBindingsFromStructure,
|
|
325
|
+
structuralSplit,
|
|
326
|
+
substituteUrlVariables,
|
|
327
|
+
unwrapOpenApiTransportEnvelope,
|
|
328
|
+
validateOpenApiBackedToolArgs,
|
|
329
|
+
variable
|
|
330
|
+
};
|
|
331
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/index.ts","../src/sdk/migrate-config.ts","../src/sdk/output-schema-migration.ts","../src/sdk/ndjson-output-migration.ts","../src/sdk/spec-blob-migration.ts"],"sourcesContent":["export { parse, resolveSpecText, fetchSpecText } from \"./parse\";\nexport { extract, streamOperationBindingsFromStructure } from \"./extract\";\nexport {\n structuralSplit,\n isStreamableSpec,\n indexSchemas,\n collectReferencedSchemas,\n parseEntry,\n parseHead,\n parseSmallComponents,\n type SpecStructure,\n type ByteRange,\n type KeepPathItem,\n} from \"./split\";\nexport {\n invoke,\n invokeWithLayer,\n buildRequest,\n annotationsForOperation,\n RESPONSE_HEADERS_TIMEOUT_MS,\n type InvokeOptions,\n} from \"./invoke\";\nexport {\n buildDefsJsonStreaming,\n checkHealthOpenApi,\n compileAndPersistOpenApiOperations,\n compileAndPersistOpenApiSpec,\n compileAndPersistOpenApiSpecStreaming,\n compileOpenApiDocument,\n compileOpenApiSpec,\n extractOpenApiUpstreamMessage,\n invokeOpenApiBackedTool,\n listHealthCheckCandidatesOpenApi,\n loadOpenApiSpecText,\n normalizeOpenApiRefs,\n openApiStoredOperationsFromCompiled,\n openApiToolDefsFromCompiled,\n resolveOpenApiBackedAnnotations,\n resolveOpenApiBackedTools,\n validateOpenApiBackedToolArgs,\n type CompiledOpenApiSpec,\n type OpenApiPersistResult,\n} from \"./backing\";\nexport type { ParsedDocument } from \"./parse\";\nexport {\n openApiPlugin,\n type OpenApiSpecConfig,\n type OpenApiConfigureInput,\n type OpenApiSpecInput,\n type OpenApiPreviewInput,\n type OpenApiPluginExtension,\n type OpenApiPluginOptions,\n} from \"./plugin\";\nexport {\n resolveSpecFormatAdapter,\n type ConvertedSpec,\n type DerivedIdentity,\n type SpecFetchCredentials,\n type SpecFetchInput,\n type SpecFormatAdapter,\n} from \"./spec-format\";\nexport { type OpenapiStore, type StoredOperation, makeDefaultOpenapiStore } from \"./store\";\nexport {\n decodeOpenApiIntegrationConfig,\n renderAuthTemplate,\n AuthenticationSchema,\n OpenApiIntegrationConfigSchema,\n type OpenApiIntegrationConfig,\n type RenderedAuth,\n} from \"./config\";\nexport {\n previewSpec,\n SecurityScheme,\n AuthStrategy,\n HeaderPreset,\n OAuth2Preset,\n OAuth2Flows,\n OAuth2AuthorizationCodeFlow,\n OAuth2ClientCredentialsFlow,\n PreviewOperation,\n SpecPreview,\n} from \"./preview\";\nexport {\n DocResolver,\n resolveServerUrl,\n substituteUrlVariables,\n preferredContent,\n} from \"./openapi-utils\";\n\nexport {\n OpenApiParseError,\n OpenApiExtractionError,\n OpenApiInvocationError,\n OpenApiOAuthError,\n OpenApiAuthRequiredError,\n} from \"./errors\";\n\nexport {\n EncodingObject,\n ExtractedOperation,\n ExtractionResult,\n InvocationResult,\n MediaBinding,\n OperationBinding,\n OperationParameter,\n OperationRequestBody,\n ServerInfo,\n ServerVariable,\n OperationId,\n HttpMethod,\n ParameterLocation,\n TOKEN_VARIABLE,\n normalizeOpenApiAuthInputs,\n type Authentication,\n type AuthenticationInput,\n type APIKeyAuthentication,\n} from \"./types\";\n// Request-shaped authoring: `headers: { Authorization: [\"Bearer \", variable(\"token\")] }`.\nexport { variable, type ApiKeyAuthTemplate } from \"@rafads/sdk/http-auth\";\n\nexport { migrateOpenApiAuthConfig } from \"./migrate-config\";\n\nexport {\n openApiOutputSchemaDataMigration,\n runSqliteOpenApiOutputSchemaMigration,\n unwrapOpenApiTransportEnvelope,\n} from \"./output-schema-migration\";\n\nexport {\n openApiNdjsonOutputDataMigration,\n runSqliteNdjsonOutputMigration,\n} from \"./ndjson-output-migration\";\n\nexport { openApiSpecBlobDataMigration } from \"./spec-blob-migration\";\n","// ---------------------------------------------------------------------------\n// One-off config migration — rewrite pre-canonical OpenAPI integration\n// `config` blobs into the canonical placements model. Runs once per database\n// (boot for local/selfhost, out-of-band script for cloud); runtime code\n// decodes ONLY the canonical shape (`decodeOpenApiIntegrationConfig`).\n//\n// The retired shape is the `variable()`-templated apiKey:\n// { slug, type: \"apiKey\", headers/queryParams: Record<name,\n// string | (string | {type:\"variable\", name})[]> }\n// Each entry becomes one placement: prefix = literals before the first\n// variable, the variable name preserved VERBATIM (it keys the connections'\n// stored `item_ids`; the canonical `token` is stored as absent), a\n// literal-only value becomes a `literal` placement. OAuth templates\n// re-key from the retired `type: \"oauth\"` spelling to `kind: \"oauth2\"`.\n// ---------------------------------------------------------------------------\n\nimport { Option } from \"effect\";\nimport { apiKeyMethodFromLegacyTemplate, decodeLegacyApiKeyTemplate } from \"@rafads/sdk/http-auth\";\n\nimport { decodeOpenApiIntegrationConfig } from \"./config\";\n\nconst isCanonicalEntry = (entry: unknown): boolean =>\n typeof entry === \"object\" &&\n entry !== null &&\n \"kind\" in entry &&\n ((entry as { kind: unknown }).kind === \"apikey\" ||\n (entry as { kind: unknown }).kind === \"oauth2\");\n\n/** The retired oauth spelling: `type: \"oauth\"` instead of `kind: \"oauth2\"`. */\nconst isLegacyOAuthEntry = (\n entry: unknown,\n): entry is { readonly type: \"oauth\" } & Record<string, unknown> =>\n typeof entry === \"object\" &&\n entry !== null &&\n \"type\" in entry &&\n (entry as { type: unknown }).type === \"oauth\";\n\nconst migrateEntry = (entry: unknown): unknown | null => {\n if (isCanonicalEntry(entry)) return entry;\n if (isLegacyOAuthEntry(entry)) {\n const { type: _type, ...rest } = entry;\n return { ...rest, kind: \"oauth2\" };\n }\n const legacy = Option.getOrNull(decodeLegacyApiKeyTemplate(entry));\n if (legacy !== null) return apiKeyMethodFromLegacyTemplate(legacy);\n return null;\n};\n\n/** Rewrite a stored OpenAPI integration config blob into the canonical shape.\n * Returns the rewritten config, or `null` when no rewrite is needed (already\n * canonical, no auth templates, or not this plugin's shape). Idempotent. */\nexport const migrateOpenApiAuthConfig = (config: unknown): unknown | null => {\n if (typeof config !== \"object\" || config === null) return null;\n if (!(\"spec\" in config) && !(\"specHash\" in config)) return null;\n if (!(\"authenticationTemplate\" in config)) return null;\n\n const entries = (config as { authenticationTemplate: unknown }).authenticationTemplate;\n if (!Array.isArray(entries)) return null;\n\n const migrated = entries.map(migrateEntry);\n if (migrated.some((entry) => entry === null)) return null;\n const changed = migrated.some((entry, index) => entry !== entries[index]);\n if (!changed) return null;\n\n const next = { ...config, authenticationTemplate: migrated };\n return decodeOpenApiIntegrationConfig(next) !== null ? next : null;\n};\n","// ---------------------------------------------------------------------------\n// Data migration: unwrap the retired {status, headers, data} transport\n// envelope from persisted OpenAPI tool output schemas. The runtime returns\n// the upstream payload as `data` (status/headers live in the ToolResult\n// `http` side channel), so persisted schemas must describe the payload\n// only — otherwise describe previews show an envelope invocations no\n// longer return. Mirrors the cloud drizzle migration\n// (apps/cloud/drizzle/0002_unwrap_openapi_output_envelope.sql) for the\n// libSQL-backed apps, where it runs once through the data-migration ledger.\n//\n// Idempotent: payload-shaped rows don't match the envelope signature, so\n// re-running plans zero updates.\n// ---------------------------------------------------------------------------\n\nimport { Effect, Option, Schema } from \"effect\";\nimport { DataMigrationError, type SqliteDataMigrationClient } from \"@rafads/sdk/core\";\n\nconst MIGRATION_NAME = \"2026-06-11-openapi-output-envelope-unwrap\";\n\nconst isRecord = (value: unknown): value is Record<string, unknown> =>\n typeof value === \"object\" && value !== null && !Array.isArray(value);\n\n// `{\"type\": \"integer\"}` — the envelope's `status` property schema, exactly.\nconst isEnvelopeStatusSchema = (value: unknown): boolean =>\n isRecord(value) && Object.keys(value).length === 1 && value.type === \"integer\";\n\n// `{\"type\": \"object\", \"additionalProperties\": {\"type\": \"string\"}}` — the\n// envelope's `headers` property schema, exactly.\nconst isEnvelopeHeadersSchema = (value: unknown): boolean =>\n isRecord(value) &&\n Object.keys(value).length === 2 &&\n value.type === \"object\" &&\n isRecord(value.additionalProperties) &&\n Object.keys(value.additionalProperties).length === 1 &&\n value.additionalProperties.type === \"string\";\n\n/**\n * If `schema` is the retired transport envelope, return the payload schema\n * to persist instead (`null` when the envelope carried an empty `{}` data\n * schema — the new producer persists no output schema for those). Returns\n * undefined when the schema is not an envelope and the row must be left\n * untouched.\n */\nexport const unwrapOpenApiTransportEnvelope = (\n schema: unknown,\n): { readonly outputSchema: unknown | null } | undefined => {\n if (!isRecord(schema)) return undefined;\n if (schema.type !== \"object\" || schema.additionalProperties !== false) return undefined;\n const required = schema.required;\n if (!Array.isArray(required) || required.length !== 3) return undefined;\n if (![\"status\", \"headers\", \"data\"].every((key) => required.includes(key))) return undefined;\n const properties = schema.properties;\n if (!isRecord(properties) || !(\"data\" in properties)) return undefined;\n if (!isEnvelopeStatusSchema(properties.status)) return undefined;\n if (!isEnvelopeHeadersSchema(properties.headers)) return undefined;\n const data = properties.data;\n const outputSchema = isRecord(data) && Object.keys(data).length === 0 ? null : data;\n return { outputSchema };\n};\n\nconst decodeJsonOption = Schema.decodeUnknownOption(Schema.UnknownFromJsonString);\n\nconst execute = (\n client: SqliteDataMigrationClient,\n stmt: string | { readonly sql: string; readonly args: readonly unknown[] },\n) =>\n Effect.tryPromise({\n try: () => client.execute(stmt),\n catch: (cause) => new DataMigrationError({ migration: MIGRATION_NAME, cause }),\n });\n\n/** Unwrap envelope-shaped openapi tool output schemas in a SQLite database.\n * Returns the number of rows rewritten. The `tool` table may not exist yet\n * on a fresh database — that counts as nothing to migrate. */\nexport const runSqliteOpenApiOutputSchemaMigration = (\n client: SqliteDataMigrationClient,\n): Effect.Effect<number, DataMigrationError> =>\n Effect.gen(function* () {\n const exists = yield* execute(\n client,\n \"SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'tool'\",\n );\n if (exists.rows.length === 0) return 0;\n\n const result = yield* execute(\n client,\n \"SELECT row_id, output_schema FROM tool WHERE plugin_id = 'openapi' AND output_schema IS NOT NULL\",\n );\n const updates: { readonly rowId: string; readonly outputSchema: unknown | null }[] = [];\n for (const row of result.rows) {\n if (typeof row.row_id !== \"string\" || typeof row.output_schema !== \"string\") continue;\n const schema = decodeJsonOption(row.output_schema);\n if (Option.isNone(schema)) continue;\n const unwrapped = unwrapOpenApiTransportEnvelope(schema.value);\n if (unwrapped !== undefined) updates.push({ rowId: row.row_id, ...unwrapped });\n }\n if (updates.length === 0) return 0;\n\n const applyAll = Effect.gen(function* () {\n for (const update of updates) {\n yield* execute(client, {\n sql: \"UPDATE tool SET output_schema = ? WHERE row_id = ?\",\n args: [\n update.outputSchema === null ? null : JSON.stringify(update.outputSchema),\n update.rowId,\n ],\n });\n }\n yield* execute(client, \"COMMIT\");\n });\n\n yield* execute(client, \"BEGIN\");\n yield* applyAll.pipe(Effect.tapError(() => execute(client, \"ROLLBACK\").pipe(Effect.ignore)));\n return updates.length;\n });\n\n/** Registry entry for the boot-time data-migration ledger. */\nexport const openApiOutputSchemaDataMigration = {\n name: MIGRATION_NAME,\n run: (client: SqliteDataMigrationClient) =>\n runSqliteOpenApiOutputSchemaMigration(client).pipe(Effect.asVoid),\n};\n","// ---------------------------------------------------------------------------\n// Data migration: rebuild tool catalogs whose operations return NDJSON.\n//\n// Extraction used to persist an NDJSON operation's PER-LINE response schema as\n// the tool's output schema, while the invoke path returns an ARRAY of parsed\n// lines, so describe previews promised a single object that invocations never\n// returned. The producer now wraps those schemas in an array; the per-line\n// shape can't be recognized from a persisted `tool` row alone (it's just a\n// JSON schema), but the stored operation bindings kept the response content\n// type, so the affected connections are findable and the catalog machinery\n// already knows how to rebuild them: stale-mark `tools_synced_at` and the next\n// read re-produces the rows through the fixed producer. Mirrors the cloud\n// drizzle migration (apps/cloud/drizzle/0010_ndjson_output_arrays.sql).\n//\n// Effectively idempotent: re-running re-marks the same connections, and a\n// rebuild from unchanged bindings writes identical rows.\n// ---------------------------------------------------------------------------\n\nimport { Effect } from \"effect\";\nimport { DataMigrationError, type SqliteDataMigrationClient } from \"@rafads/sdk/core\";\n\nconst MIGRATION_NAME = \"2026-07-09-openapi-ndjson-output-arrays\";\n\n// Substring probes for the NDJSON media types (NDJSON_MEDIA_TYPES in\n// openapi-utils.ts). The binding JSON inside `plugin_storage.data` may be a\n// nested object or a re-encoded string, so a LIKE over the raw row text is the\n// shape-agnostic match; false positives only cause a harmless extra rebuild.\nconst NDJSON_TYPE_PROBES = [\n \"application/stream+json\",\n \"application/x-ndjson\",\n \"application/jsonl\",\n] as const;\n\nconst execute = (\n client: SqliteDataMigrationClient,\n stmt: string | { readonly sql: string; readonly args: readonly unknown[] },\n) =>\n Effect.tryPromise({\n try: () => client.execute(stmt),\n catch: (cause) => new DataMigrationError({ migration: MIGRATION_NAME, cause }),\n });\n\nconst tableExists = (client: SqliteDataMigrationClient, table: string) =>\n Effect.map(\n execute(client, {\n sql: \"SELECT name FROM sqlite_master WHERE type = 'table' AND name = ?\",\n args: [table],\n }),\n (result) => result.rows.length > 0,\n );\n\n/** Stale-mark every connection whose integration has at least one stored\n * operation binding with an NDJSON response, so the next read rebuilds its\n * tool rows (with array-wrapped output schemas). Returns the number of\n * connections marked. Fresh databases may lack either table; nothing to\n * migrate. */\nexport const runSqliteNdjsonOutputMigration = (\n client: SqliteDataMigrationClient,\n): Effect.Effect<number, DataMigrationError> =>\n Effect.gen(function* () {\n for (const table of [\"connection\", \"plugin_storage\"]) {\n if (!(yield* tableExists(client, table))) return 0;\n }\n\n const probes = NDJSON_TYPE_PROBES.map(() => \"ps.data LIKE ?\").join(\" OR \");\n const affected = yield* execute(client, {\n sql: `SELECT DISTINCT ps.tenant AS tenant, json_extract(ps.data, '$.integration') AS integration\n FROM plugin_storage ps\n WHERE ps.collection = 'operation' AND (${probes})`,\n args: NDJSON_TYPE_PROBES.map((probe) => `%${probe}%`),\n });\n\n let marked = 0;\n for (const row of affected.rows) {\n if (typeof row.tenant !== \"string\" || typeof row.integration !== \"string\") continue;\n yield* execute(client, {\n sql: \"UPDATE connection SET tools_synced_at = NULL WHERE tenant = ? AND integration = ?\",\n args: [row.tenant, row.integration],\n });\n marked += 1;\n }\n return marked;\n });\n\n/** Registry entry for the boot-time data-migration ledger. */\nexport const openApiNdjsonOutputDataMigration = {\n name: MIGRATION_NAME,\n run: (client: SqliteDataMigrationClient) =>\n runSqliteNdjsonOutputMigration(client).pipe(Effect.asVoid),\n};\n","// ---------------------------------------------------------------------------\n// Data migration: move inline OpenAPI spec text out of `integration.config`\n// into the blob table (`spec/<sha256>`, config keeps `specHash`) — the\n// libSQL-ledger counterpart of cloud's out-of-band migrate-specs-to-blobs\n// script. Runs once per database through the data-migration ledger; the\n// shared body lives in @rafads/sdk (`runSqliteConfigBlobMigration`).\n// ---------------------------------------------------------------------------\n\nimport { Effect } from \"effect\";\nimport { runSqliteConfigBlobMigration, type SqliteDataMigrationClient } from \"@rafads/sdk/core\";\n\nconst MIGRATION_NAME = \"2026-06-12-openapi-spec-to-blob\";\n\n/** Registry entry for the boot-time data-migration ledger. */\nexport const openApiSpecBlobDataMigration = {\n name: MIGRATION_NAME,\n run: (client: SqliteDataMigrationClient) =>\n runSqliteConfigBlobMigration(client, {\n migrationName: MIGRATION_NAME,\n pluginId: \"openapi\",\n inlineField: \"spec\",\n hashField: \"specHash\",\n blobKeyPrefix: \"spec\",\n }).pipe(Effect.asVoid),\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,EAAE,KAAKF,QAAO,MAAM;AAC7D;;;ACjFA,SAAS,UAAAI,eAAc;AACvB,SAAS,oCAAoE;AAE7E,IAAMC,kBAAiB;AAGhB,IAAM,+BAA+B;AAAA,EAC1C,MAAMA;AAAA,EACN,KAAK,CAAC,WACJ,6BAA6B,QAAQ;AAAA,IACnC,eAAeA;AAAA,IACf,UAAU;AAAA,IACV,aAAa;AAAA,IACb,WAAW;AAAA,IACX,eAAe;AAAA,EACjB,CAAC,EAAE,KAAKD,QAAO,MAAM;AACzB;","names":["Option","Effect","DataMigrationError","MIGRATION_NAME","execute","Effect","MIGRATION_NAME"]}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
openApiPlugin
|
|
3
|
+
} from "./chunk-OR27BCXQ.js";
|
|
4
|
+
import "./chunk-CURJJXB3.js";
|
|
5
|
+
import "./chunk-O2LMSZ2Z.js";
|
|
6
|
+
import {
|
|
7
|
+
TOKEN_VARIABLE
|
|
8
|
+
} from "./chunk-HTHEUUJA.js";
|
|
9
|
+
import "./chunk-R7TVM3XD.js";
|
|
10
|
+
import "./chunk-CXFO6TLJ.js";
|
|
11
|
+
|
|
12
|
+
// src/promise.ts
|
|
13
|
+
import { variable } from "@rafads/sdk/http-auth";
|
|
14
|
+
export {
|
|
15
|
+
TOKEN_VARIABLE,
|
|
16
|
+
openApiPlugin,
|
|
17
|
+
variable
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/promise.ts"],"sourcesContent":["export { openApiPlugin } from \"./sdk/plugin\";\nexport type {\n OpenApiPluginOptions,\n OpenApiPluginExtension,\n OpenApiSpecConfig,\n OpenApiSpecInput,\n OpenApiPreviewInput,\n} from \"./sdk/plugin\";\n\n// Auth-template authoring helpers. Author apikey methods as canonical\n// placements, or request-shaped: `headers: { Authorization: [\"Bearer \",\n// variable(\"token\")] }` — both normalize to the same stored model.\nexport { TOKEN_VARIABLE } from \"./sdk/types\";\nexport type { Authentication, AuthenticationInput, APIKeyAuthentication } from \"./sdk/types\";\nexport { variable, type ApiKeyAuthTemplate } from \"@rafads/sdk/http-auth\";\n"],"mappings":";;;;;;;;;;;;AAcA,SAAS,gBAAyC;","names":[]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Schema } from "effect";
|
|
2
|
+
import type { Authentication } from "../../sdk/types";
|
|
3
|
+
export declare const GoogleIntegrationConfigSchema: Schema.Struct<{
|
|
4
|
+
readonly specHash: Schema.optional<Schema.String>;
|
|
5
|
+
readonly specUrl: Schema.optional<Schema.String>;
|
|
6
|
+
readonly googleDiscoveryUrls: Schema.optional<Schema.$Array<Schema.String>>;
|
|
7
|
+
readonly baseUrl: Schema.optional<Schema.String>;
|
|
8
|
+
readonly headers: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
9
|
+
readonly queryParams: Schema.optional<Schema.$Record<Schema.String, Schema.String>>;
|
|
10
|
+
readonly authenticationTemplate: Schema.optional<Schema.$Array<Schema.Union<readonly [Schema.Struct<{
|
|
11
|
+
readonly slug: Schema.String;
|
|
12
|
+
readonly kind: Schema.Literal<"oauth2">;
|
|
13
|
+
readonly authorizationUrl: Schema.String;
|
|
14
|
+
readonly tokenUrl: Schema.String;
|
|
15
|
+
readonly resource: Schema.optional<Schema.NullOr<Schema.String>>;
|
|
16
|
+
readonly scopes: Schema.$Array<Schema.String>;
|
|
17
|
+
readonly supportsClientIdMetadataDocument: Schema.optional<Schema.Boolean>;
|
|
18
|
+
}>, Schema.Struct<{
|
|
19
|
+
readonly slug: Schema.String;
|
|
20
|
+
readonly kind: Schema.Literal<"apikey">;
|
|
21
|
+
readonly label: Schema.optional<Schema.String>;
|
|
22
|
+
readonly placements: Schema.$Array<Schema.Struct<{
|
|
23
|
+
readonly carrier: Schema.Literals<readonly ["header", "query"]>;
|
|
24
|
+
readonly name: Schema.String;
|
|
25
|
+
readonly prefix: Schema.optional<Schema.String>;
|
|
26
|
+
readonly variable: Schema.optional<Schema.String>;
|
|
27
|
+
readonly literal: Schema.optional<Schema.String>;
|
|
28
|
+
}>>;
|
|
29
|
+
}>]>>>;
|
|
30
|
+
}>;
|
|
31
|
+
export type GoogleIntegrationConfig = Omit<typeof GoogleIntegrationConfigSchema.Type, "authenticationTemplate"> & {
|
|
32
|
+
readonly authenticationTemplate?: readonly Authentication[];
|
|
33
|
+
};
|
|
34
|
+
export declare const decodeGoogleIntegrationConfig: (value: unknown) => GoogleIntegrationConfig | null;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { HttpClient } from "effect/unstable/http";
|
|
3
|
+
import { OpenApiParseError } from "../../sdk/errors";
|
|
4
|
+
import type { Authentication } from "../../sdk/types";
|
|
5
|
+
interface SpecFetchCredentials {
|
|
6
|
+
readonly headers?: Record<string, string>;
|
|
7
|
+
readonly queryParams?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export interface GoogleDiscoveryOpenApiConversion {
|
|
10
|
+
readonly specText: string;
|
|
11
|
+
readonly baseUrl: string;
|
|
12
|
+
readonly title: string;
|
|
13
|
+
readonly service: string;
|
|
14
|
+
readonly version: string;
|
|
15
|
+
readonly discoveryUrls?: readonly string[];
|
|
16
|
+
/** The v2 oauth auth template the converted integration declares, when the
|
|
17
|
+
* Discovery document advertises OAuth2 scopes. */
|
|
18
|
+
readonly authenticationTemplate?: readonly Authentication[];
|
|
19
|
+
}
|
|
20
|
+
export declare const normalizeGoogleDiscoveryUrl: (discoveryUrl: string) => string | null;
|
|
21
|
+
export declare const isGoogleDiscoveryUrl: (url: string) => boolean;
|
|
22
|
+
export declare const fetchGoogleDiscoveryDocument: (discoveryUrl: string, credentials?: SpecFetchCredentials | undefined) => Effect.Effect<string, OpenApiParseError, HttpClient.HttpClient>;
|
|
23
|
+
export declare const convertGoogleDiscoveryToOpenApi: (input: {
|
|
24
|
+
readonly discoveryUrl: string;
|
|
25
|
+
readonly documentText: string;
|
|
26
|
+
}) => Effect.Effect<{
|
|
27
|
+
authenticationTemplate?: readonly Authentication[] | undefined;
|
|
28
|
+
specText: string;
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
title: string;
|
|
31
|
+
service: string;
|
|
32
|
+
version: string;
|
|
33
|
+
}, OpenApiParseError, never>;
|
|
34
|
+
export declare const convertGoogleDiscoveryBundleToOpenApi: (input: {
|
|
35
|
+
readonly documents: readonly {
|
|
36
|
+
readonly discoveryUrl: string;
|
|
37
|
+
readonly documentText: string;
|
|
38
|
+
}[];
|
|
39
|
+
readonly consentScopes?: readonly string[];
|
|
40
|
+
}) => Effect.Effect<{
|
|
41
|
+
authenticationTemplate?: readonly Authentication[] | undefined;
|
|
42
|
+
specText: string;
|
|
43
|
+
baseUrl: string;
|
|
44
|
+
title: string;
|
|
45
|
+
service: string;
|
|
46
|
+
version: string;
|
|
47
|
+
discoveryUrls: string[];
|
|
48
|
+
}, OpenApiParseError, never>;
|
|
49
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { convertGoogleDiscoveryBundleToOpenApi, convertGoogleDiscoveryToOpenApi, fetchGoogleDiscoveryDocument, isGoogleDiscoveryUrl, type GoogleDiscoveryOpenApiConversion, } from "./discovery";
|
|
2
|
+
export { googleOpenApiBundlePreset, googleCatalog, googleOpenApiPresets, googlePhotosOpenApiBundlePreset, googlePhotosOpenApiPresets, googlePhotosPresetIds, GOOGLE_PHOTOS_ICON, GOOGLE_PHOTOS_PRESET_ID, googleStandardUserOAuthPresets, googleOAuthConsentScopes, googleOAuthConsentScopesForPreset, googleServiceSlug, googleAudienceWarningsForUrls, googlePresetForDiscoveryUrl, type GoogleOpenApiOAuthAudience, type GoogleOpenApiPreset, type GooglePreset, } from "./presets";
|
|
3
|
+
export { compactGoogleOAuthScopes, filterGoogleUserConsentOAuthScopes, isGoogleUserConsentOAuthScope, } from "./oauth-scopes";
|
|
4
|
+
export { deriveGoogleDiscoveryIdentity, googleDiscoveryAdapter } from "./spec-format-adapter";
|
|
5
|
+
export { googleOpenApiOwnershipDataMigration, runSqliteGoogleOpenApiOwnershipMigration, } from "./openapi-ownership-migration";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Effect } from "effect";
|
|
2
|
+
import { DataMigrationError, type SqliteDataMigrationClient } from "@rafads/sdk/core";
|
|
3
|
+
export declare const runSqliteGoogleOpenApiOwnershipMigration: (client: SqliteDataMigrationClient) => Effect.Effect<number, DataMigrationError>;
|
|
4
|
+
export declare const googleOpenApiOwnershipDataMigration: {
|
|
5
|
+
name: string;
|
|
6
|
+
run: (client: SqliteDataMigrationClient) => Effect.Effect<void, DataMigrationError, never>;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { IntegrationPreset } from "@rafads/sdk/core";
|
|
2
|
+
export interface GooglePreset {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly summary: string;
|
|
6
|
+
readonly url?: string;
|
|
7
|
+
readonly icon?: string;
|
|
8
|
+
readonly featured?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export type GoogleOpenApiOAuthAudience = "standard-user" | "advanced-user" | "workspace-admin" | "unsupported-user";
|
|
11
|
+
export type GoogleOpenApiPreset = GooglePreset & {
|
|
12
|
+
readonly oauthAudience: GoogleOpenApiOAuthAudience;
|
|
13
|
+
};
|
|
14
|
+
export declare const GOOGLE_BUNDLE_PRESET_ID = "google";
|
|
15
|
+
export declare const GOOGLE_PHOTOS_PRESET_ID = "google-photos";
|
|
16
|
+
export declare const GOOGLE_PHOTOS_ICON = "https://www.gstatic.com/images/branding/product/2x/photos_96dp.png";
|
|
17
|
+
export declare const googleOpenApiBundlePreset: GooglePreset;
|
|
18
|
+
export declare const googlePhotosOpenApiBundlePreset: GooglePreset;
|
|
19
|
+
export declare const googleOpenApiPresets: readonly GoogleOpenApiPreset[];
|
|
20
|
+
export declare const googleStandardUserOAuthPresets: GoogleOpenApiPreset[];
|
|
21
|
+
export declare const googlePhotosPresetIds: readonly string[];
|
|
22
|
+
export declare const googlePhotosOpenApiPresets: readonly GoogleOpenApiPreset[];
|
|
23
|
+
export declare const googleOAuthConsentScopes: Readonly<Record<string, readonly string[]>>;
|
|
24
|
+
export declare const googleOAuthConsentScopesForPreset: (presetId: string) => readonly string[];
|
|
25
|
+
export declare const googleServiceSlug: (presetId: string) => string;
|
|
26
|
+
export declare const googleCatalog: readonly IntegrationPreset[];
|
|
27
|
+
export declare const googlePresetForDiscoveryUrl: (url: string) => GoogleOpenApiPreset | undefined;
|
|
28
|
+
/** The distinct caution-tier audiences (`workspace-admin`, `unsupported-user`)
|
|
29
|
+
* among the supplied Discovery URLs - the ones whose consent the user should be
|
|
30
|
+
* warned about. Returns `[]` when every URL is a standard/advanced API. */
|
|
31
|
+
export declare const googleAudienceWarningsForUrls: (urls: readonly string[]) => readonly GoogleOpenApiOAuthAudience[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|