@eventcatalog/generator-apicurio 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.mts +16 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.js +150 -0
- package/dist/client.js.map +1 -0
- package/dist/client.mjs +115 -0
- package/dist/client.mjs.map +1 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4602 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4600 -0
- package/dist/index.mjs.map +1 -0
- package/dist/types.d.mts +139 -0
- package/dist/types.d.ts +139 -0
- package/dist/types.js +38 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +13 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ArtifactSearchResults, VersionSearchResults, ArtifactWithVersions } from './types.mjs';
|
|
2
|
+
|
|
3
|
+
declare class ApicurioClient {
|
|
4
|
+
private client;
|
|
5
|
+
private baseUrl;
|
|
6
|
+
constructor(baseUrl?: string);
|
|
7
|
+
searchArtifacts(limit?: number, offset?: number): Promise<ArtifactSearchResults>;
|
|
8
|
+
getArtifactMetadata(groupId: string, artifactId: string): Promise<any>;
|
|
9
|
+
getArtifactVersions(groupId: string, artifactId: string): Promise<VersionSearchResults>;
|
|
10
|
+
getArtifactVersionMetadata(groupId: string, artifactId: string, version: string): Promise<any>;
|
|
11
|
+
getArtifactContent(groupId: string, artifactId: string, version?: string): Promise<any>;
|
|
12
|
+
getArtifactByName(artifactId: string): Promise<ArtifactWithVersions | null>;
|
|
13
|
+
getArtifactByNameAndVersion(artifactId: string, version: string): Promise<ArtifactWithVersions | null>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { ApicurioClient };
|
package/dist/client.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ArtifactSearchResults, VersionSearchResults, ArtifactWithVersions } from './types.js';
|
|
2
|
+
|
|
3
|
+
declare class ApicurioClient {
|
|
4
|
+
private client;
|
|
5
|
+
private baseUrl;
|
|
6
|
+
constructor(baseUrl?: string);
|
|
7
|
+
searchArtifacts(limit?: number, offset?: number): Promise<ArtifactSearchResults>;
|
|
8
|
+
getArtifactMetadata(groupId: string, artifactId: string): Promise<any>;
|
|
9
|
+
getArtifactVersions(groupId: string, artifactId: string): Promise<VersionSearchResults>;
|
|
10
|
+
getArtifactVersionMetadata(groupId: string, artifactId: string, version: string): Promise<any>;
|
|
11
|
+
getArtifactContent(groupId: string, artifactId: string, version?: string): Promise<any>;
|
|
12
|
+
getArtifactByName(artifactId: string): Promise<ArtifactWithVersions | null>;
|
|
13
|
+
getArtifactByNameAndVersion(artifactId: string, version: string): Promise<ArtifactWithVersions | null>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export { ApicurioClient };
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/client.ts
|
|
31
|
+
var client_exports = {};
|
|
32
|
+
__export(client_exports, {
|
|
33
|
+
ApicurioClient: () => ApicurioClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(client_exports);
|
|
36
|
+
var import_axios = __toESM(require("axios"));
|
|
37
|
+
var ApicurioClient = class {
|
|
38
|
+
constructor(baseUrl = "http://localhost:8080") {
|
|
39
|
+
const normalizedUrl = baseUrl.replace(/\/$/, "");
|
|
40
|
+
const apiPath = "/apis/registry/v3";
|
|
41
|
+
this.baseUrl = normalizedUrl.includes("/apis/registry/") ? normalizedUrl : `${normalizedUrl}${apiPath}`;
|
|
42
|
+
const headers = {
|
|
43
|
+
"Content-Type": "application/json"
|
|
44
|
+
};
|
|
45
|
+
const accessToken = process.env.APICURIO_ACCESS_TOKEN;
|
|
46
|
+
if (accessToken) {
|
|
47
|
+
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
48
|
+
}
|
|
49
|
+
this.client = import_axios.default.create({
|
|
50
|
+
baseURL: this.baseUrl,
|
|
51
|
+
headers
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async searchArtifacts(limit = 100, offset = 0) {
|
|
55
|
+
const response = await this.client.get("/search/artifacts", {
|
|
56
|
+
params: { limit, offset }
|
|
57
|
+
});
|
|
58
|
+
return response.data;
|
|
59
|
+
}
|
|
60
|
+
async getArtifactMetadata(groupId, artifactId) {
|
|
61
|
+
const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}`);
|
|
62
|
+
return response.data;
|
|
63
|
+
}
|
|
64
|
+
async getArtifactVersions(groupId, artifactId) {
|
|
65
|
+
const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}/versions`);
|
|
66
|
+
return response.data;
|
|
67
|
+
}
|
|
68
|
+
async getArtifactVersionMetadata(groupId, artifactId, version) {
|
|
69
|
+
const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}/versions/${version}`);
|
|
70
|
+
return response.data;
|
|
71
|
+
}
|
|
72
|
+
async getArtifactContent(groupId, artifactId, version) {
|
|
73
|
+
const versionExpr = version || "branch=latest";
|
|
74
|
+
const url = `/groups/${groupId}/artifacts/${artifactId}/versions/${versionExpr}/content`;
|
|
75
|
+
const response = await this.client.get(url);
|
|
76
|
+
return response.data;
|
|
77
|
+
}
|
|
78
|
+
async getArtifactByName(artifactId) {
|
|
79
|
+
try {
|
|
80
|
+
let artifact = null;
|
|
81
|
+
let offset = 0;
|
|
82
|
+
const limit = 100;
|
|
83
|
+
while (!artifact) {
|
|
84
|
+
const searchResults = await this.searchArtifacts(limit, offset);
|
|
85
|
+
if (!searchResults.artifacts || searchResults.artifacts.length === 0) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
artifact = searchResults.artifacts.find((a) => (a.artifactId || a.id) === artifactId);
|
|
89
|
+
if (!artifact) {
|
|
90
|
+
if (searchResults.artifacts.length < limit) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
offset += limit;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const groupId = artifact.groupId || "default";
|
|
97
|
+
const resolvedArtifactId = artifact.artifactId || artifact.id || artifactId;
|
|
98
|
+
const versions = await this.getArtifactVersions(groupId, resolvedArtifactId);
|
|
99
|
+
const latestVersion = versions.versions?.length > 0 ? versions.versions[versions.versions.length - 1]?.version : "1";
|
|
100
|
+
const content = await this.getArtifactContent(groupId, resolvedArtifactId);
|
|
101
|
+
return {
|
|
102
|
+
artifact,
|
|
103
|
+
versions: versions.versions || [],
|
|
104
|
+
latestVersion,
|
|
105
|
+
content
|
|
106
|
+
};
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error(`Error fetching artifact ${artifactId}:`, error);
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async getArtifactByNameAndVersion(artifactId, version) {
|
|
113
|
+
try {
|
|
114
|
+
let artifact = null;
|
|
115
|
+
let offset = 0;
|
|
116
|
+
const limit = 100;
|
|
117
|
+
while (!artifact) {
|
|
118
|
+
const searchResults = await this.searchArtifacts(limit, offset);
|
|
119
|
+
if (!searchResults.artifacts || searchResults.artifacts.length === 0) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
artifact = searchResults.artifacts.find((a) => (a.artifactId || a.id) === artifactId);
|
|
123
|
+
if (!artifact) {
|
|
124
|
+
if (searchResults.artifacts.length < limit) {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
offset += limit;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const groupId = artifact.groupId || "default";
|
|
131
|
+
const resolvedArtifactId = artifact.artifactId || artifact.id || artifactId;
|
|
132
|
+
const versions = await this.getArtifactVersions(groupId, resolvedArtifactId);
|
|
133
|
+
const content = await this.getArtifactContent(groupId, resolvedArtifactId, version);
|
|
134
|
+
return {
|
|
135
|
+
artifact,
|
|
136
|
+
versions: versions.versions || [],
|
|
137
|
+
latestVersion: version,
|
|
138
|
+
content
|
|
139
|
+
};
|
|
140
|
+
} catch (error) {
|
|
141
|
+
console.error(`Error fetching artifact ${artifactId} version ${version}:`, error);
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
147
|
+
0 && (module.exports = {
|
|
148
|
+
ApicurioClient
|
|
149
|
+
});
|
|
150
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport { ArtifactSearchResults, VersionSearchResults, ArtifactWithVersions } from './types';\n\nexport class ApicurioClient {\n private client: AxiosInstance;\n private baseUrl: string;\n\n constructor(baseUrl: string = 'http://localhost:8080') {\n // Ensure the base URL ends with the v3 API path\n // Users can provide just the registry URL (e.g., http://localhost:8080)\n // and we'll append the API path automatically\n const normalizedUrl = baseUrl.replace(/\\/$/, ''); // Remove trailing slash\n const apiPath = '/apis/registry/v3';\n\n // Only append if not already present\n this.baseUrl = normalizedUrl.includes('/apis/registry/') ? normalizedUrl : `${normalizedUrl}${apiPath}`;\n\n // Build headers object\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Add Authorization header if APICURIO_ACCESS_TOKEN is set\n const accessToken = process.env.APICURIO_ACCESS_TOKEN;\n if (accessToken) {\n headers['Authorization'] = `Bearer ${accessToken}`;\n }\n\n this.client = axios.create({\n baseURL: this.baseUrl,\n headers,\n });\n }\n\n async searchArtifacts(limit: number = 100, offset: number = 0): Promise<ArtifactSearchResults> {\n const response = await this.client.get('/search/artifacts', {\n params: { limit, offset },\n });\n return response.data;\n }\n\n async getArtifactMetadata(groupId: string, artifactId: string): Promise<any> {\n // V3 API: metadata is at /groups/{groupId}/artifacts/{artifactId}\n const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}`);\n return response.data;\n }\n\n async getArtifactVersions(groupId: string, artifactId: string): Promise<VersionSearchResults> {\n const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}/versions`);\n return response.data;\n }\n\n async getArtifactVersionMetadata(groupId: string, artifactId: string, version: string): Promise<any> {\n // V3 API: version metadata is at /groups/{groupId}/artifacts/{artifactId}/versions/{versionExpression}\n const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}/versions/${version}`);\n return response.data;\n }\n\n async getArtifactContent(groupId: string, artifactId: string, version?: string): Promise<any> {\n // V3 API: content is at /groups/{groupId}/artifacts/{artifactId}/versions/{versionExpression}/content\n // Use 'branch=latest' to get the latest version\n const versionExpr = version || 'branch=latest';\n const url = `/groups/${groupId}/artifacts/${artifactId}/versions/${versionExpr}/content`;\n const response = await this.client.get(url);\n return response.data;\n }\n\n async getArtifactByName(artifactId: string): Promise<ArtifactWithVersions | null> {\n try {\n // Search for the artifact across all groups with pagination\n let artifact = null;\n let offset = 0;\n const limit = 100;\n\n while (!artifact) {\n const searchResults = await this.searchArtifacts(limit, offset);\n\n if (!searchResults.artifacts || searchResults.artifacts.length === 0) {\n // No more results, artifact not found\n return null;\n }\n\n // V3 uses 'artifactId', V2 uses 'id'\n artifact = searchResults.artifacts.find((a) => (a.artifactId || a.id) === artifactId);\n\n if (!artifact) {\n // Check if there are more results to fetch\n if (searchResults.artifacts.length < limit) {\n // Last page reached, artifact not found\n return null;\n }\n // Move to next page\n offset += limit;\n }\n }\n\n const groupId = artifact.groupId || 'default';\n const resolvedArtifactId = artifact.artifactId || artifact.id || artifactId;\n\n // Get all versions\n const versions = await this.getArtifactVersions(groupId, resolvedArtifactId);\n\n // V3: Get latest version from versions list instead of metadata\n const latestVersion = versions.versions?.length > 0 ? versions.versions[versions.versions.length - 1]?.version : '1';\n\n // Get latest content\n const content = await this.getArtifactContent(groupId, resolvedArtifactId);\n\n return {\n artifact,\n versions: versions.versions || [],\n latestVersion,\n content,\n };\n } catch (error) {\n console.error(`Error fetching artifact ${artifactId}:`, error);\n return null;\n }\n }\n\n async getArtifactByNameAndVersion(artifactId: string, version: string): Promise<ArtifactWithVersions | null> {\n try {\n // Search for the artifact with pagination\n let artifact = null;\n let offset = 0;\n const limit = 100;\n\n while (!artifact) {\n const searchResults = await this.searchArtifacts(limit, offset);\n\n if (!searchResults.artifacts || searchResults.artifacts.length === 0) {\n // No more results, artifact not found\n return null;\n }\n\n // V3 uses 'artifactId', V2 uses 'id'\n artifact = searchResults.artifacts.find((a) => (a.artifactId || a.id) === artifactId);\n\n if (!artifact) {\n // Check if there are more results to fetch\n if (searchResults.artifacts.length < limit) {\n // Last page reached, artifact not found\n return null;\n }\n // Move to next page\n offset += limit;\n }\n }\n\n const groupId = artifact.groupId || 'default';\n const resolvedArtifactId = artifact.artifactId || artifact.id || artifactId;\n\n // Get all versions\n const versions = await this.getArtifactVersions(groupId, resolvedArtifactId);\n\n // Get specific version content\n const content = await this.getArtifactContent(groupId, resolvedArtifactId, version);\n\n return {\n artifact,\n versions: versions.versions || [],\n latestVersion: version,\n content,\n };\n } catch (error) {\n console.error(`Error fetching artifact ${artifactId} version ${version}:`, error);\n return null;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAqC;AAG9B,IAAM,iBAAN,MAAqB;AAAA,EAI1B,YAAY,UAAkB,yBAAyB;AAIrD,UAAM,gBAAgB,QAAQ,QAAQ,OAAO,EAAE;AAC/C,UAAM,UAAU;AAGhB,SAAK,UAAU,cAAc,SAAS,iBAAiB,IAAI,gBAAgB,GAAG,aAAa,GAAG,OAAO;AAGrG,UAAM,UAAkC;AAAA,MACtC,gBAAgB;AAAA,IAClB;AAGA,UAAM,cAAc,QAAQ,IAAI;AAChC,QAAI,aAAa;AACf,cAAQ,eAAe,IAAI,UAAU,WAAW;AAAA,IAClD;AAEA,SAAK,SAAS,aAAAA,QAAM,OAAO;AAAA,MACzB,SAAS,KAAK;AAAA,MACd;AAAA,IACF,CAAC;AAAA,EACH;AAAA,EAEA,MAAM,gBAAgB,QAAgB,KAAK,SAAiB,GAAmC;AAC7F,UAAM,WAAW,MAAM,KAAK,OAAO,IAAI,qBAAqB;AAAA,MAC1D,QAAQ,EAAE,OAAO,OAAO;AAAA,IAC1B,CAAC;AACD,WAAO,SAAS;AAAA,EAClB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]}
|
package/dist/client.mjs
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// src/client.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
var ApicurioClient = class {
|
|
4
|
+
constructor(baseUrl = "http://localhost:8080") {
|
|
5
|
+
const normalizedUrl = baseUrl.replace(/\/$/, "");
|
|
6
|
+
const apiPath = "/apis/registry/v3";
|
|
7
|
+
this.baseUrl = normalizedUrl.includes("/apis/registry/") ? normalizedUrl : `${normalizedUrl}${apiPath}`;
|
|
8
|
+
const headers = {
|
|
9
|
+
"Content-Type": "application/json"
|
|
10
|
+
};
|
|
11
|
+
const accessToken = process.env.APICURIO_ACCESS_TOKEN;
|
|
12
|
+
if (accessToken) {
|
|
13
|
+
headers["Authorization"] = `Bearer ${accessToken}`;
|
|
14
|
+
}
|
|
15
|
+
this.client = axios.create({
|
|
16
|
+
baseURL: this.baseUrl,
|
|
17
|
+
headers
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async searchArtifacts(limit = 100, offset = 0) {
|
|
21
|
+
const response = await this.client.get("/search/artifacts", {
|
|
22
|
+
params: { limit, offset }
|
|
23
|
+
});
|
|
24
|
+
return response.data;
|
|
25
|
+
}
|
|
26
|
+
async getArtifactMetadata(groupId, artifactId) {
|
|
27
|
+
const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}`);
|
|
28
|
+
return response.data;
|
|
29
|
+
}
|
|
30
|
+
async getArtifactVersions(groupId, artifactId) {
|
|
31
|
+
const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}/versions`);
|
|
32
|
+
return response.data;
|
|
33
|
+
}
|
|
34
|
+
async getArtifactVersionMetadata(groupId, artifactId, version) {
|
|
35
|
+
const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}/versions/${version}`);
|
|
36
|
+
return response.data;
|
|
37
|
+
}
|
|
38
|
+
async getArtifactContent(groupId, artifactId, version) {
|
|
39
|
+
const versionExpr = version || "branch=latest";
|
|
40
|
+
const url = `/groups/${groupId}/artifacts/${artifactId}/versions/${versionExpr}/content`;
|
|
41
|
+
const response = await this.client.get(url);
|
|
42
|
+
return response.data;
|
|
43
|
+
}
|
|
44
|
+
async getArtifactByName(artifactId) {
|
|
45
|
+
try {
|
|
46
|
+
let artifact = null;
|
|
47
|
+
let offset = 0;
|
|
48
|
+
const limit = 100;
|
|
49
|
+
while (!artifact) {
|
|
50
|
+
const searchResults = await this.searchArtifacts(limit, offset);
|
|
51
|
+
if (!searchResults.artifacts || searchResults.artifacts.length === 0) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
artifact = searchResults.artifacts.find((a) => (a.artifactId || a.id) === artifactId);
|
|
55
|
+
if (!artifact) {
|
|
56
|
+
if (searchResults.artifacts.length < limit) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
offset += limit;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const groupId = artifact.groupId || "default";
|
|
63
|
+
const resolvedArtifactId = artifact.artifactId || artifact.id || artifactId;
|
|
64
|
+
const versions = await this.getArtifactVersions(groupId, resolvedArtifactId);
|
|
65
|
+
const latestVersion = versions.versions?.length > 0 ? versions.versions[versions.versions.length - 1]?.version : "1";
|
|
66
|
+
const content = await this.getArtifactContent(groupId, resolvedArtifactId);
|
|
67
|
+
return {
|
|
68
|
+
artifact,
|
|
69
|
+
versions: versions.versions || [],
|
|
70
|
+
latestVersion,
|
|
71
|
+
content
|
|
72
|
+
};
|
|
73
|
+
} catch (error) {
|
|
74
|
+
console.error(`Error fetching artifact ${artifactId}:`, error);
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async getArtifactByNameAndVersion(artifactId, version) {
|
|
79
|
+
try {
|
|
80
|
+
let artifact = null;
|
|
81
|
+
let offset = 0;
|
|
82
|
+
const limit = 100;
|
|
83
|
+
while (!artifact) {
|
|
84
|
+
const searchResults = await this.searchArtifacts(limit, offset);
|
|
85
|
+
if (!searchResults.artifacts || searchResults.artifacts.length === 0) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
artifact = searchResults.artifacts.find((a) => (a.artifactId || a.id) === artifactId);
|
|
89
|
+
if (!artifact) {
|
|
90
|
+
if (searchResults.artifacts.length < limit) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
offset += limit;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
const groupId = artifact.groupId || "default";
|
|
97
|
+
const resolvedArtifactId = artifact.artifactId || artifact.id || artifactId;
|
|
98
|
+
const versions = await this.getArtifactVersions(groupId, resolvedArtifactId);
|
|
99
|
+
const content = await this.getArtifactContent(groupId, resolvedArtifactId, version);
|
|
100
|
+
return {
|
|
101
|
+
artifact,
|
|
102
|
+
versions: versions.versions || [],
|
|
103
|
+
latestVersion: version,
|
|
104
|
+
content
|
|
105
|
+
};
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error(`Error fetching artifact ${artifactId} version ${version}:`, error);
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
export {
|
|
113
|
+
ApicurioClient
|
|
114
|
+
};
|
|
115
|
+
//# sourceMappingURL=client.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/client.ts"],"sourcesContent":["import axios, { AxiosInstance } from 'axios';\nimport { ArtifactSearchResults, VersionSearchResults, ArtifactWithVersions } from './types';\n\nexport class ApicurioClient {\n private client: AxiosInstance;\n private baseUrl: string;\n\n constructor(baseUrl: string = 'http://localhost:8080') {\n // Ensure the base URL ends with the v3 API path\n // Users can provide just the registry URL (e.g., http://localhost:8080)\n // and we'll append the API path automatically\n const normalizedUrl = baseUrl.replace(/\\/$/, ''); // Remove trailing slash\n const apiPath = '/apis/registry/v3';\n\n // Only append if not already present\n this.baseUrl = normalizedUrl.includes('/apis/registry/') ? normalizedUrl : `${normalizedUrl}${apiPath}`;\n\n // Build headers object\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n };\n\n // Add Authorization header if APICURIO_ACCESS_TOKEN is set\n const accessToken = process.env.APICURIO_ACCESS_TOKEN;\n if (accessToken) {\n headers['Authorization'] = `Bearer ${accessToken}`;\n }\n\n this.client = axios.create({\n baseURL: this.baseUrl,\n headers,\n });\n }\n\n async searchArtifacts(limit: number = 100, offset: number = 0): Promise<ArtifactSearchResults> {\n const response = await this.client.get('/search/artifacts', {\n params: { limit, offset },\n });\n return response.data;\n }\n\n async getArtifactMetadata(groupId: string, artifactId: string): Promise<any> {\n // V3 API: metadata is at /groups/{groupId}/artifacts/{artifactId}\n const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}`);\n return response.data;\n }\n\n async getArtifactVersions(groupId: string, artifactId: string): Promise<VersionSearchResults> {\n const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}/versions`);\n return response.data;\n }\n\n async getArtifactVersionMetadata(groupId: string, artifactId: string, version: string): Promise<any> {\n // V3 API: version metadata is at /groups/{groupId}/artifacts/{artifactId}/versions/{versionExpression}\n const response = await this.client.get(`/groups/${groupId}/artifacts/${artifactId}/versions/${version}`);\n return response.data;\n }\n\n async getArtifactContent(groupId: string, artifactId: string, version?: string): Promise<any> {\n // V3 API: content is at /groups/{groupId}/artifacts/{artifactId}/versions/{versionExpression}/content\n // Use 'branch=latest' to get the latest version\n const versionExpr = version || 'branch=latest';\n const url = `/groups/${groupId}/artifacts/${artifactId}/versions/${versionExpr}/content`;\n const response = await this.client.get(url);\n return response.data;\n }\n\n async getArtifactByName(artifactId: string): Promise<ArtifactWithVersions | null> {\n try {\n // Search for the artifact across all groups with pagination\n let artifact = null;\n let offset = 0;\n const limit = 100;\n\n while (!artifact) {\n const searchResults = await this.searchArtifacts(limit, offset);\n\n if (!searchResults.artifacts || searchResults.artifacts.length === 0) {\n // No more results, artifact not found\n return null;\n }\n\n // V3 uses 'artifactId', V2 uses 'id'\n artifact = searchResults.artifacts.find((a) => (a.artifactId || a.id) === artifactId);\n\n if (!artifact) {\n // Check if there are more results to fetch\n if (searchResults.artifacts.length < limit) {\n // Last page reached, artifact not found\n return null;\n }\n // Move to next page\n offset += limit;\n }\n }\n\n const groupId = artifact.groupId || 'default';\n const resolvedArtifactId = artifact.artifactId || artifact.id || artifactId;\n\n // Get all versions\n const versions = await this.getArtifactVersions(groupId, resolvedArtifactId);\n\n // V3: Get latest version from versions list instead of metadata\n const latestVersion = versions.versions?.length > 0 ? versions.versions[versions.versions.length - 1]?.version : '1';\n\n // Get latest content\n const content = await this.getArtifactContent(groupId, resolvedArtifactId);\n\n return {\n artifact,\n versions: versions.versions || [],\n latestVersion,\n content,\n };\n } catch (error) {\n console.error(`Error fetching artifact ${artifactId}:`, error);\n return null;\n }\n }\n\n async getArtifactByNameAndVersion(artifactId: string, version: string): Promise<ArtifactWithVersions | null> {\n try {\n // Search for the artifact with pagination\n let artifact = null;\n let offset = 0;\n const limit = 100;\n\n while (!artifact) {\n const searchResults = await this.searchArtifacts(limit, offset);\n\n if (!searchResults.artifacts || searchResults.artifacts.length === 0) {\n // No more results, artifact not found\n return null;\n }\n\n // V3 uses 'artifactId', V2 uses 'id'\n artifact = searchResults.artifacts.find((a) => (a.artifactId || a.id) === artifactId);\n\n if (!artifact) {\n // Check if there are more results to fetch\n if (searchResults.artifacts.length < limit) {\n // Last page reached, artifact not found\n return null;\n }\n // Move to next page\n offset += limit;\n }\n }\n\n const groupId = artifact.groupId || 'default';\n const resolvedArtifactId = artifact.artifactId || artifact.id || artifactId;\n\n // Get all versions\n const versions = await this.getArtifactVersions(groupId, resolvedArtifactId);\n\n // Get specific version content\n const content = await this.getArtifactContent(groupId, resolvedArtifactId, version);\n\n return {\n artifact,\n versions: versions.versions || [],\n latestVersion: version,\n content,\n };\n } catch (error) {\n console.error(`Error fetching artifact ${artifactId} version ${version}:`, error);\n return null;\n }\n }\n}\n"],"mappings":";AAAA,OAAO,WAA8B;AAG9B,IAAM,iBAAN,MAAqB;AAAA,EA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