@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/cjs/index.cjs
CHANGED
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
var yargs = require('yargs');
|
|
4
4
|
var helpers = require('yargs/helpers');
|
|
5
5
|
var process$1 = require('process');
|
|
6
|
-
var
|
|
7
|
-
var legacyClient = require('@osdk/legacy-client');
|
|
6
|
+
var shared_net = require('@osdk/shared.net');
|
|
8
7
|
var generator = require('@osdk/generator');
|
|
9
8
|
var promises = require('fs/promises');
|
|
10
9
|
var path = require('path');
|
|
@@ -44,237 +43,6 @@ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
|
44
43
|
|
|
45
44
|
// src/cli/foundrySdkGeneratorCli.ts
|
|
46
45
|
|
|
47
|
-
// src/net/Constants.ts
|
|
48
|
-
var API_BASE_URL = (host) => {
|
|
49
|
-
if (host.startsWith("http") || host.startsWith("https")) {
|
|
50
|
-
return `${host}`;
|
|
51
|
-
}
|
|
52
|
-
return `https://${host}`;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
// src/net/fetch/authenticatedFetch.ts
|
|
56
|
-
var AuthenticatedFetch = class {
|
|
57
|
-
constructor(fetchFunction, auth) {
|
|
58
|
-
this.fetchFunction = fetchFunction;
|
|
59
|
-
this.auth = auth;
|
|
60
|
-
}
|
|
61
|
-
getFetch() {
|
|
62
|
-
return (input, init) => {
|
|
63
|
-
return this.auth.executeWithToken((token) => {
|
|
64
|
-
return this.fetchFunction(input, {
|
|
65
|
-
...init,
|
|
66
|
-
headers: {
|
|
67
|
-
// Don't override auth headers if they are already set
|
|
68
|
-
Authorization: `Bearer ${token.accessToken}`,
|
|
69
|
-
...init?.headers
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
// src/net/fetch/retryingFetch.ts
|
|
78
|
-
var RetryingFetch = class {
|
|
79
|
-
constructor(fetchFunction, initialDelay = 1e3, jitterFactor = 0.5, maxRetries = 3) {
|
|
80
|
-
this.fetchFunction = fetchFunction;
|
|
81
|
-
this.initialDelay = initialDelay;
|
|
82
|
-
this.jitterFactor = jitterFactor;
|
|
83
|
-
this.maxRetries = maxRetries;
|
|
84
|
-
}
|
|
85
|
-
SERVICE_UNAVAILABLE = 503;
|
|
86
|
-
TOO_MANY_REQUESTS = 429;
|
|
87
|
-
getFetch() {
|
|
88
|
-
return this.retryWithBackoff.bind(this, 0);
|
|
89
|
-
}
|
|
90
|
-
async retryWithBackoff(retries, url, init) {
|
|
91
|
-
let response;
|
|
92
|
-
let backoffDelay;
|
|
93
|
-
try {
|
|
94
|
-
response = await this.fetchFunction(url, init);
|
|
95
|
-
if (response.ok) {
|
|
96
|
-
return response;
|
|
97
|
-
}
|
|
98
|
-
backoffDelay = this.calculateBackoffDelay(retries, response.status);
|
|
99
|
-
if (!backoffDelay) {
|
|
100
|
-
return response;
|
|
101
|
-
}
|
|
102
|
-
} catch (error) {
|
|
103
|
-
backoffDelay = this.calculateBackoffDelay(retries);
|
|
104
|
-
if (!backoffDelay) {
|
|
105
|
-
throw error;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
await new Promise((resolve) => setTimeout(resolve, backoffDelay));
|
|
109
|
-
return this.retryWithBackoff(retries + 1, url, init);
|
|
110
|
-
}
|
|
111
|
-
calculateBackoffDelay(retries, status) {
|
|
112
|
-
if (retries >= this.maxRetries) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (status && status !== this.SERVICE_UNAVAILABLE && status !== this.TOO_MANY_REQUESTS) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const delay = this.initialDelay * 2 ** retries;
|
|
119
|
-
const jitter = delay * this.jitterFactor * (Math.random() * 2 - 1);
|
|
120
|
-
return delay + jitter;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
// src/net/fetch/fetchFactory.ts
|
|
125
|
-
var FetchFactory = class {
|
|
126
|
-
constructor(fetchFunction) {
|
|
127
|
-
this.fetchFunction = fetchFunction;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Creates a fetch instance with authentication, error handling, and retrying.
|
|
131
|
-
*
|
|
132
|
-
* @returns A fetch instance
|
|
133
|
-
*/
|
|
134
|
-
getDefaultFetch(auth) {
|
|
135
|
-
const authenticatedFetch = new AuthenticatedFetch(this.baseFetch, auth);
|
|
136
|
-
const retryingFetch = new RetryingFetch(authenticatedFetch.getFetch());
|
|
137
|
-
return retryingFetch.getFetch();
|
|
138
|
-
}
|
|
139
|
-
baseFetch = (input, auth) => {
|
|
140
|
-
const fetchFunction = this.fetchFunction ?? globalThis.fetch;
|
|
141
|
-
return fetchFunction(input, auth);
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// src/net/MediaType.ts
|
|
146
|
-
var MediaType = /* @__PURE__ */ function(MediaType2) {
|
|
147
|
-
MediaType2["APPLICATION_JSON"] = "application/json";
|
|
148
|
-
MediaType2["APPLICATION_OCTET_STREAM"] = "application/octet-stream";
|
|
149
|
-
MediaType2["APPLICATION_X_WWW_FORM_URLENCODED"] = "application/x-www-form-urlencoded";
|
|
150
|
-
MediaType2["MULTIPART_FORM_DATA"] = "multipart/form-data";
|
|
151
|
-
MediaType2["TEXT_PLAIN"] = "text/plain";
|
|
152
|
-
return MediaType2;
|
|
153
|
-
}({});
|
|
154
|
-
|
|
155
|
-
// src/net/ResponseType.ts
|
|
156
|
-
var ResponseType = /* @__PURE__ */ function(ResponseType2) {
|
|
157
|
-
ResponseType2[ResponseType2["JSON"] = 0] = "JSON";
|
|
158
|
-
ResponseType2[ResponseType2["BLOB"] = 1] = "BLOB";
|
|
159
|
-
ResponseType2[ResponseType2["TEXT"] = 2] = "TEXT";
|
|
160
|
-
ResponseType2[ResponseType2["STREAM"] = 3] = "STREAM";
|
|
161
|
-
return ResponseType2;
|
|
162
|
-
}({});
|
|
163
|
-
|
|
164
|
-
// src/net/FetchClient.ts
|
|
165
|
-
function getApiRequestFunction(auth, url, userAgent, contextPath = "/api", fetchFunction) {
|
|
166
|
-
const fetchClient = new FetchClient(auth, url, userAgent, contextPath, fetchFunction);
|
|
167
|
-
return (method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType) => fetchClient.request(method, endpointPath, data, queryArguments, headers, requestMediaType, responseMediaType);
|
|
168
|
-
}
|
|
169
|
-
var FetchClient = class {
|
|
170
|
-
constructor(auth, url, userAgent, contextPath = "/api", fetchFunction) {
|
|
171
|
-
this.userAgent = userAgent;
|
|
172
|
-
this.contextPath = contextPath;
|
|
173
|
-
const fetchFactory = new FetchFactory(fetchFunction);
|
|
174
|
-
this.fetchFunction = fetchFactory.getDefaultFetch(auth);
|
|
175
|
-
this.url = API_BASE_URL(url);
|
|
176
|
-
}
|
|
177
|
-
async request(method, endpointPath, data, queryArguments, headers, _requestMediaType = "application/json", responseMediaType = "application/json", responseAsStream) {
|
|
178
|
-
const url = new URL(`${this.contextPath}${endpointPath}`, `${this.url}`);
|
|
179
|
-
for (const [queryArgumentName, queryArgumentValue] of Object.entries(queryArguments || {})) {
|
|
180
|
-
if (queryArgumentValue) {
|
|
181
|
-
if (queryArgumentValue.constructor === Array) {
|
|
182
|
-
for (const value of queryArgumentValue) {
|
|
183
|
-
url.searchParams.append(queryArgumentName, value);
|
|
184
|
-
}
|
|
185
|
-
continue;
|
|
186
|
-
} else {
|
|
187
|
-
url.searchParams.append(queryArgumentName, queryArgumentValue);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
const headersInit = {};
|
|
192
|
-
Object.entries(headers || {}).forEach(([key, value]) => {
|
|
193
|
-
if (value != null) {
|
|
194
|
-
headersInit[key] = value.toString();
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
const response = await this.fetchWithContentType(url, {
|
|
198
|
-
method,
|
|
199
|
-
body: data,
|
|
200
|
-
headers: headersInit
|
|
201
|
-
});
|
|
202
|
-
if (responseAsStream && response.body) {
|
|
203
|
-
return response.body;
|
|
204
|
-
}
|
|
205
|
-
if (responseMediaType === MediaType.APPLICATION_JSON) {
|
|
206
|
-
return response.json();
|
|
207
|
-
} else if (responseMediaType === "*/*") {
|
|
208
|
-
return response.blob();
|
|
209
|
-
}
|
|
210
|
-
return response.json();
|
|
211
|
-
}
|
|
212
|
-
async callAPI(url, method = "GET", body, responseType = ResponseType.JSON) {
|
|
213
|
-
const response = await this.fetchWithContentType(url, {
|
|
214
|
-
method,
|
|
215
|
-
body
|
|
216
|
-
});
|
|
217
|
-
const contentType = response.headers.get("Content-Type") != null ? response.headers.get("Content-Type") : "";
|
|
218
|
-
let bodyPromise;
|
|
219
|
-
if (responseType === ResponseType.BLOB) {
|
|
220
|
-
bodyPromise = response.blob();
|
|
221
|
-
} else if (contentType.includes(MediaType.APPLICATION_JSON)) {
|
|
222
|
-
bodyPromise = response.json();
|
|
223
|
-
} else if (contentType.includes(MediaType.APPLICATION_OCTET_STREAM)) {
|
|
224
|
-
bodyPromise = response.blob();
|
|
225
|
-
} else {
|
|
226
|
-
bodyPromise = response.text();
|
|
227
|
-
}
|
|
228
|
-
const responseBody = await bodyPromise;
|
|
229
|
-
return responseBody;
|
|
230
|
-
}
|
|
231
|
-
async fetchWithContentType(url, init) {
|
|
232
|
-
if (!init?.body) {
|
|
233
|
-
return this.fetchFunction(url.toString(), {
|
|
234
|
-
...init,
|
|
235
|
-
headers: this.getHeaders(init?.headers)
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
const contentType = this.getContentTypeForBody(init.body);
|
|
239
|
-
return this.fetchFunction(url.toString(), {
|
|
240
|
-
...init,
|
|
241
|
-
headers: this.getHeaders(init?.headers, contentType),
|
|
242
|
-
body: this.getBodyForContentType(init.body)
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
getContentTypeForBody(body) {
|
|
246
|
-
if (globalThis.Blob && body instanceof globalThis.Blob) {
|
|
247
|
-
return body.type;
|
|
248
|
-
}
|
|
249
|
-
if (typeof body === "string") {
|
|
250
|
-
return MediaType.TEXT_PLAIN;
|
|
251
|
-
}
|
|
252
|
-
if (globalThis.ArrayBuffer && (globalThis.ArrayBuffer.isView(body) || body instanceof globalThis.ArrayBuffer)) {
|
|
253
|
-
return MediaType.APPLICATION_OCTET_STREAM;
|
|
254
|
-
}
|
|
255
|
-
if (globalThis.Uint8Array && body instanceof globalThis.Uint8Array) {
|
|
256
|
-
return MediaType.APPLICATION_OCTET_STREAM;
|
|
257
|
-
}
|
|
258
|
-
return MediaType.APPLICATION_JSON;
|
|
259
|
-
}
|
|
260
|
-
getBodyForContentType(body) {
|
|
261
|
-
if (!body) {
|
|
262
|
-
return void 0;
|
|
263
|
-
}
|
|
264
|
-
if (globalThis.Blob && body instanceof globalThis.Blob) {
|
|
265
|
-
return body;
|
|
266
|
-
}
|
|
267
|
-
return JSON.stringify(body);
|
|
268
|
-
}
|
|
269
|
-
getHeaders(init, contentType = MediaType.APPLICATION_JSON) {
|
|
270
|
-
return {
|
|
271
|
-
"Content-Type": contentType,
|
|
272
|
-
"Fetch-User-Agent": this.userAgent,
|
|
273
|
-
...init
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
|
|
278
46
|
// src/ontologyMetadata/Result.ts
|
|
279
47
|
var Ok = class {
|
|
280
48
|
constructor(value) {
|
|
@@ -353,10 +121,8 @@ var OntologyMetadataResolver = class {
|
|
|
353
121
|
this.stackName = stackName;
|
|
354
122
|
this.#authToken = authToken;
|
|
355
123
|
}
|
|
356
|
-
|
|
357
|
-
return
|
|
358
|
-
userToken: this.#authToken
|
|
359
|
-
}), this.stackName, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`, "/api");
|
|
124
|
+
getClientContext() {
|
|
125
|
+
return shared_net.createClientContext(this.stackName, () => this.#authToken, `foundry-typescript-osdk-generator/${process.env.npm_package_version}`);
|
|
360
126
|
}
|
|
361
127
|
filterMetadata(ontologyFullMetadata, expectedEntities) {
|
|
362
128
|
const filteredObjectTypes = Object.fromEntries(Object.entries(ontologyFullMetadata.objectTypes).filter(([objectTypeApiName]) => expectedEntities.objectTypes.has(objectTypeApiName.toLowerCase())));
|
|
@@ -387,12 +153,18 @@ var OntologyMetadataResolver = class {
|
|
|
387
153
|
}
|
|
388
154
|
async getWireOntologyDefinition(ontologyRid, entities) {
|
|
389
155
|
let ontology;
|
|
156
|
+
const {
|
|
157
|
+
Ontologies
|
|
158
|
+
} = await import('@osdk/internal.foundry.ontologies');
|
|
159
|
+
const {
|
|
160
|
+
OntologiesV2
|
|
161
|
+
} = await import('@osdk/internal.foundry.ontologiesv2');
|
|
390
162
|
try {
|
|
391
|
-
ontology = await
|
|
163
|
+
ontology = await Ontologies.getOntology(this.getClientContext(), ontologyRid);
|
|
392
164
|
} catch (e) {
|
|
393
165
|
return Result.err([`Unable to load the specified Ontology with network error: ${JSON.stringify(e)}`]);
|
|
394
166
|
}
|
|
395
|
-
const ontologyFullMetadata = await
|
|
167
|
+
const ontologyFullMetadata = await OntologiesV2.getOntologyFullMetadata(this.getClientContext(), ontology.rid);
|
|
396
168
|
if (ontologyFullMetadata.errorName != null) {
|
|
397
169
|
return Result.err([`Unable to load the specified Ontology metadata.
|
|
398
170
|
${JSON.stringify(ontologyFullMetadata, null, 2)}`]);
|
|
@@ -584,7 +356,7 @@ function isValidSemver(semverString) {
|
|
|
584
356
|
}
|
|
585
357
|
|
|
586
358
|
// src/utils/UserAgent.ts
|
|
587
|
-
var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.
|
|
359
|
+
var USER_AGENT = `typescript-sdk-generator/${"2.0.0-beta.7"}`;
|
|
588
360
|
async function createRollupBuild(absolutePackagePath, packageName) {
|
|
589
361
|
const inputPath = `${absolutePackagePath}/${packageName}/index.js`;
|
|
590
362
|
const {
|