@osdk/foundry-sdk-generator 2.0.0-beta.6 → 2.0.0-beta.7
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/CHANGELOG.md +20 -0
- package/build/browser/index.js +12 -240
- package/build/browser/index.js.map +1 -1
- package/build/cjs/index.cjs +12 -240
- package/build/cjs/index.cjs.map +1 -1
- package/build/cjs/ontologyMetadata/ontologyMetadataResolver.d.cts +1 -1
- package/build/cjs/ontologyMetadata/ontologyMetadataResolver.d.ts.map +1 -1
- package/build/esm/index.js +12 -240
- package/build/esm/index.js.map +1 -1
- package/build/esm/ontologyMetadata/ontologyMetadataResolver.d.ts +1 -1
- package/build/esm/ontologyMetadata/ontologyMetadataResolver.d.ts.map +1 -1
- package/package.json +11 -8
- package/build/cjs/net/FetchClient.d.cts +0 -23
- package/build/cjs/net/FetchClient.d.ts.map +0 -1
- package/build/esm/net/FetchClient.d.ts +0 -23
- package/build/esm/net/FetchClient.d.ts.map +0 -1
package/build/esm/index.js
CHANGED
|
@@ -4,8 +4,7 @@ import path2__default, { join, isAbsolute, normalize } from 'path';
|
|
|
4
4
|
import yargs from 'yargs';
|
|
5
5
|
import { hideBin } from 'yargs/helpers';
|
|
6
6
|
import { exit } from 'process';
|
|
7
|
-
import {
|
|
8
|
-
import { UserTokenAuth } from '@osdk/legacy-client';
|
|
7
|
+
import { createClientContext } from '@osdk/shared.net';
|
|
9
8
|
import { generateClientSdkVersionTwoPointZero } from '@osdk/generator';
|
|
10
9
|
import { mkdir, writeFile, readFile, readdir } from 'fs/promises';
|
|
11
10
|
import commonjs from '@rollup/plugin-commonjs';
|
|
@@ -21,237 +20,6 @@ var getFilename = () => fileURLToPath(import.meta.url);
|
|
|
21
20
|
var getDirname = () => path2__default.dirname(getFilename());
|
|
22
21
|
var __dirname = /* @__PURE__ */ getDirname();
|
|
23
22
|
|
|
24
|
-
// src/net/Constants.ts
|
|
25
|
-
var API_BASE_URL = (host) => {
|
|
26
|
-
if (host.startsWith("http") || host.startsWith("https")) {
|
|
27
|
-
return `${host}`;
|
|
28
|
-
}
|
|
29
|
-
return `https://${host}`;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
// src/net/fetch/authenticatedFetch.ts
|
|
33
|
-
var AuthenticatedFetch = class {
|
|
34
|
-
constructor(fetchFunction, auth) {
|
|
35
|
-
this.fetchFunction = fetchFunction;
|
|
36
|
-
this.auth = auth;
|
|
37
|
-
}
|
|
38
|
-
getFetch() {
|
|
39
|
-
return (input, init) => {
|
|
40
|
-
return this.auth.executeWithToken((token) => {
|
|
41
|
-
return this.fetchFunction(input, {
|
|
42
|
-
...init,
|
|
43
|
-
headers: {
|
|
44
|
-
// Don't override auth headers if they are already set
|
|
45
|
-
Authorization: `Bearer ${token.accessToken}`,
|
|
46
|
-
...init?.headers
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
// src/net/fetch/retryingFetch.ts
|
|
55
|
-
var RetryingFetch = class {
|
|
56
|
-
constructor(fetchFunction, initialDelay = 1e3, jitterFactor = 0.5, maxRetries = 3) {
|
|
57
|
-
this.fetchFunction = fetchFunction;
|
|
58
|
-
this.initialDelay = initialDelay;
|
|
59
|
-
this.jitterFactor = jitterFactor;
|
|
60
|
-
this.maxRetries = maxRetries;
|
|
61
|
-
}
|
|
62
|
-
SERVICE_UNAVAILABLE = 503;
|
|
63
|
-
TOO_MANY_REQUESTS = 429;
|
|
64
|
-
getFetch() {
|
|
65
|
-
return this.retryWithBackoff.bind(this, 0);
|
|
66
|
-
}
|
|
67
|
-
async retryWithBackoff(retries, url, init) {
|
|
68
|
-
let response;
|
|
69
|
-
let backoffDelay;
|
|
70
|
-
try {
|
|
71
|
-
response = await this.fetchFunction(url, init);
|
|
72
|
-
if (response.ok) {
|
|
73
|
-
return response;
|
|
74
|
-
}
|
|
75
|
-
backoffDelay = this.calculateBackoffDelay(retries, response.status);
|
|
76
|
-
if (!backoffDelay) {
|
|
77
|
-
return response;
|
|
78
|
-
}
|
|
79
|
-
} catch (error) {
|
|
80
|
-
backoffDelay = this.calculateBackoffDelay(retries);
|
|
81
|
-
if (!backoffDelay) {
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
|
86
|
-
return this.retryWithBackoff(retries + 1, url, init);
|
|
87
|
-
}
|
|
88
|
-
calculateBackoffDelay(retries, status) {
|
|
89
|
-
if (retries >= this.maxRetries) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (status && status !== this.SERVICE_UNAVAILABLE && status !== this.TOO_MANY_REQUESTS) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
const delay = this.initialDelay * 2 ** retries;
|
|
96
|
-
const jitter = delay * this.jitterFactor * (Math.random() * 2 - 1);
|
|
97
|
-
return delay + jitter;
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
// src/net/fetch/fetchFactory.ts
|
|
102
|
-
var FetchFactory = class {
|
|
103
|
-
constructor(fetchFunction) {
|
|
104
|
-
this.fetchFunction = fetchFunction;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Creates a fetch instance with authentication, error handling, and retrying.
|
|
108
|
-
*
|
|
109
|
-
* @returns A fetch instance
|
|
110
|
-
*/
|
|
111
|
-
getDefaultFetch(auth) {
|
|
112
|
-
const authenticatedFetch = new AuthenticatedFetch(this.baseFetch, auth);
|
|
113
|
-
const retryingFetch = new RetryingFetch(authenticatedFetch.getFetch());
|
|
114
|
-
return retryingFetch.getFetch();
|
|
115
|
-
}
|
|
116
|
-
baseFetch = (input, auth) => {
|
|
117
|
-
const fetchFunction = this.fetchFunction ?? globalThis.fetch;
|
|
118
|
-
return fetchFunction(input, auth);
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
// src/net/MediaType.ts
|
|
123
|
-
var MediaType = /* @__PURE__ */ function(MediaType2) {
|
|
124
|
-
MediaType2["APPLICATION_JSON"] = "application/json";
|
|
125
|
-
MediaType2["APPLICATION_OCTET_STREAM"] = "application/octet-stream";
|
|
126
|
-
MediaType2["APPLICATION_X_WWW_FORM_URLENCODED"] = "application/x-www-form-urlencoded";
|
|
127
|
-
MediaType2["MULTIPART_FORM_DATA"] = "multipart/form-data";
|
|
128
|
-
MediaType2["TEXT_PLAIN"] = "text/plain";
|
|
129
|
-
return MediaType2;
|
|
130
|
-
}({});
|
|
131
|
-
|
|
132
|
-
// src/net/ResponseType.ts
|
|
133
|
-
var ResponseType = /* @__PURE__ */ function(ResponseType2) {
|
|
134
|
-
ResponseType2[ResponseType2["JSON"] = 0] = "JSON";
|
|
135
|
-
ResponseType2[ResponseType2["BLOB"] = 1] = "BLOB";
|
|
136
|
-
ResponseType2[ResponseType2["TEXT"] = 2] = "TEXT";
|
|
137
|
-
ResponseType2[ResponseType2["STREAM"] = 3] = "STREAM";
|
|
138
|
-
return ResponseType2;
|
|
139
|
-
}({});
|
|
140
|
-
|
|
141
|
-
// src/net/FetchClient.ts
|
|
142
|
-
function getApiRequestFunction(auth, url, userAgent, contextPath = "/api", fetchFunction) {
|
|
143
|
-
const fetchClient = new FetchClient(auth, url, userAgent, contextPath, fetchFunction);
|
|
144
|
-
return (method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType) => fetchClient.request(method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType);
|
|
145
|
-
}
|
|
146
|
-
var FetchClient = class {
|
|
147
|
-
constructor(auth, url, userAgent, contextPath = "/api", fetchFunction) {
|
|
148
|
-
this.userAgent = userAgent;
|
|
149
|
-
this.contextPath = contextPath;
|
|
150
|
-
const fetchFactory = new FetchFactory(fetchFunction);
|
|
151
|
-
this.fetchFunction = fetchFactory.getDefaultFetch(auth);
|
|
152
|
-
this.url = API_BASE_URL(url);
|
|
153
|
-
}
|
|
154
|
-
async request(method, endpointPath, data, queryArguments, headers, _requestMediaType = "application/json", responseMediaType = "application/json", responseAsStream) {
|
|
155
|
-
const url = new URL(`${this.contextPath}${endpointPath}`, `${this.url}`);
|
|
156
|
-
for (const [queryArgumentName, queryArgumentValue] of Object.entries(queryArguments || {})) {
|
|
157
|
-
if (queryArgumentValue) {
|
|
158
|
-
if (queryArgumentValue.constructor === Array) {
|
|
159
|
-
for (const value of queryArgumentValue) {
|
|
160
|
-
url.searchParams.append(queryArgumentName, value);
|
|
161
|
-
}
|
|
162
|
-
continue;
|
|
163
|
-
} else {
|
|
164
|
-
url.searchParams.append(queryArgumentName, queryArgumentValue);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
const headersInit = {};
|
|
169
|
-
Object.entries(headers || {}).forEach(([key, value]) => {
|
|
170
|
-
if (value != null) {
|
|
171
|
-
headersInit[key] = value.toString();
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
const response = await this.fetchWithContentType(url, {
|
|
175
|
-
method,
|
|
176
|
-
body: data,
|
|
177
|
-
headers: headersInit
|
|
178
|
-
});
|
|
179
|
-
if (responseAsStream && response.body) {
|
|
180
|
-
return response.body;
|
|
181
|
-
}
|
|
182
|
-
if (responseMediaType === MediaType.APPLICATION_JSON) {
|
|
183
|
-
return response.json();
|
|
184
|
-
} else if (responseMediaType === "*/*") {
|
|
185
|
-
return response.blob();
|
|
186
|
-
}
|
|
187
|
-
return response.json();
|
|
188
|
-
}
|
|
189
|
-
async callAPI(url, method = "GET", body, responseType = ResponseType.JSON) {
|
|
190
|
-
const response = await this.fetchWithContentType(url, {
|
|
191
|
-
method,
|
|
192
|
-
body
|
|
193
|
-
});
|
|
194
|
-
const contentType = response.headers.get("Content-Type") != null ? response.headers.get("Content-Type") : "";
|
|
195
|
-
let bodyPromise;
|
|
196
|
-
if (responseType === ResponseType.BLOB) {
|
|
197
|
-
bodyPromise = response.blob();
|
|
198
|
-
} else if (contentType.includes(MediaType.APPLICATION_JSON)) {
|
|
199
|
-
bodyPromise = response.json();
|
|
200
|
-
} else if (contentType.includes(MediaType.APPLICATION_OCTET_STREAM)) {
|
|
201
|
-
bodyPromise = response.blob();
|
|
202
|
-
} else {
|
|
203
|
-
bodyPromise = response.text();
|
|
204
|
-
}
|
|
205
|
-
const responseBody = await bodyPromise;
|
|
206
|
-
return responseBody;
|
|
207
|
-
}
|
|
208
|
-
async fetchWithContentType(url, init) {
|
|
209
|
-
if (!init?.body) {
|
|
210
|
-
return this.fetchFunction(url.toString(), {
|
|
211
|
-
...init,
|
|
212
|
-
headers: this.getHeaders(init?.headers)
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
const contentType = this.getContentTypeForBody(init.body);
|
|
216
|
-
return this.fetchFunction(url.toString(), {
|
|
217
|
-
...init,
|
|
218
|
-
headers: this.getHeaders(init?.headers, contentType),
|
|
219
|
-
body: this.getBodyForContentType(init.body)
|
|
220
|
-
});
|
|
221
|
-
}
|
|
222
|
-
getContentTypeForBody(body) {
|
|
223
|
-
if (globalThis.Blob && body instanceof globalThis.Blob) {
|
|
224
|
-
return body.type;
|
|
225
|
-
}
|
|
226
|
-
if (typeof body === "string") {
|
|
227
|
-
return MediaType.TEXT_PLAIN;
|
|
228
|
-
}
|
|
229
|
-
if (globalThis.ArrayBuffer && (globalThis.ArrayBuffer.isView(body) || body instanceof globalThis.ArrayBuffer)) {
|
|
230
|
-
return MediaType.APPLICATION_OCTET_STREAM;
|
|
231
|
-
}
|
|
232
|
-
if (globalThis.Uint8Array && body instanceof globalThis.Uint8Array) {
|
|
233
|
-
return MediaType.APPLICATION_OCTET_STREAM;
|
|
234
|
-
}
|
|
235
|
-
return MediaType.APPLICATION_JSON;
|
|
236
|
-
}
|
|
237
|
-
getBodyForContentType(body) {
|
|
238
|
-
if (!body) {
|
|
239
|
-
return void 0;
|
|
240
|
-
}
|
|
241
|
-
if (globalThis.Blob && body instanceof globalThis.Blob) {
|
|
242
|
-
return body;
|
|
243
|
-
}
|
|
244
|
-
return JSON.stringify(body);
|
|
245
|
-
}
|
|
246
|
-
getHeaders(init, contentType = MediaType.APPLICATION_JSON) {
|
|
247
|
-
return {
|
|
248
|
-
"Content-Type": contentType,
|
|
249
|
-
"Fetch-User-Agent": this.userAgent,
|
|
250
|
-
...init
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
|
|
255
23
|
// src/ontologyMetadata/Result.ts
|
|
256
24
|
var Ok = class {
|
|
257
25
|
constructor(value) {
|
|
@@ -330,10 +98,8 @@ var OntologyMetadataResolver = class {
|
|
|
330
98
|
this.stackName = stackName;
|
|
331
99
|
this.#authToken = authToken;
|
|
332
100
|
}
|
|
333
|
-
|
|
334
|
-
return
|
|
335
|
-
userToken: this.#authToken
|
|
336
|
-
}), this.stackName, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`, "/api");
|
|
101
|
+
getClientContext() {
|
|
102
|
+
return createClientContext(this.stackName, () => this.#authToken, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`);
|
|
337
103
|
}
|
|
338
104
|
filterMetadata(ontologyFullMetadata, expectedEntities) {
|
|
339
105
|
const filteredObjectTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.objectTypes).filter(([objectTypeApiName]) => expectedEntities.objectTypes.has(objectTypeApiName.toLowerCase())));
|
|
@@ -364,12 +130,18 @@ var OntologyMetadataResolver = class {
|
|
|
364
130
|
}
|
|
365
131
|
async getWireOntologyDefinition(ontologyRid, entities) {
|
|
366
132
|
let ontology;
|
|
133
|
+
const {
|
|
134
|
+
Ontologies
|
|
135
|
+
} = await import('@osdk/internal.foundry.ontologies');
|
|
136
|
+
const {
|
|
137
|
+
OntologiesV2
|
|
138
|
+
} = await import('@osdk/internal.foundry.ontologiesv2');
|
|
367
139
|
try {
|
|
368
|
-
ontology = await
|
|
140
|
+
ontology = await Ontologies.getOntology(this.getClientContext(), ontologyRid);
|
|
369
141
|
} catch (e) {
|
|
370
142
|
return Result.err([`Unable to load the specified Ontology with network error: ${JSON.stringify(e)}`]);
|
|
371
143
|
}
|
|
372
|
-
const ontologyFullMetadata = await
|
|
144
|
+
const ontologyFullMetadata = await OntologiesV2.getOntologyFullMetadata(this.getClientContext(), ontology.rid);
|
|
373
145
|
if (ontologyFullMetadata.errorName != null) {
|
|
374
146
|
return Result.err([`Unable to load the specified Ontology metadata.
|
|
375
147
|
${JSON.stringify(ontologyFullMetadata, null, 2)}`]);
|
|
@@ -561,7 +333,7 @@ function isValidSemver(semverString) {
|
|
|
561
333
|
}
|
|
562
334
|
|
|
563
335
|
// src/utils/UserAgent.ts
|
|
564
|
-
var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.
|
|
336
|
+
var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.7"}`;
|
|
565
337
|
async function createRollupBuild(absolutePackagePath, packageName) {
|
|
566
338
|
const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
|
|
567
339
|
const {
|