@vention/vention-cli 0.36.5 → 0.37.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/main.esm.js
CHANGED
|
@@ -4150,7 +4150,7 @@ $$y({ global: true, forced: globalThis$r.globalThis !== globalThis$r }, {
|
|
|
4150
4150
|
globalThis: globalThis$r
|
|
4151
4151
|
});
|
|
4152
4152
|
|
|
4153
|
-
var version = "0.
|
|
4153
|
+
var version = "0.37.0";
|
|
4154
4154
|
var packageJson$1 = {
|
|
4155
4155
|
version: version};
|
|
4156
4156
|
|
|
@@ -4186,6 +4186,263 @@ $$x({ target: 'Iterator', proto: true, real: true, forced: forEachWithoutClosing
|
|
|
4186
4186
|
}
|
|
4187
4187
|
});
|
|
4188
4188
|
|
|
4189
|
+
//#region src/bearer-strategy.ts
|
|
4190
|
+
var BearerStrategy = class {
|
|
4191
|
+
lastSent;
|
|
4192
|
+
lastRecoveryAt;
|
|
4193
|
+
now;
|
|
4194
|
+
cooldownMs;
|
|
4195
|
+
exchange;
|
|
4196
|
+
constructor(options) {
|
|
4197
|
+
this.now = options.now ?? Date.now;
|
|
4198
|
+
this.cooldownMs = options.cooldownMs ?? 5e3;
|
|
4199
|
+
this.exchange = options.exchange;
|
|
4200
|
+
}
|
|
4201
|
+
/** @inheritDoc */
|
|
4202
|
+
async attach(request) {
|
|
4203
|
+
const token = await this.exchange();
|
|
4204
|
+
this.lastSent = token;
|
|
4205
|
+
const headers = new Headers(request.headers);
|
|
4206
|
+
headers.set("Authorization", `Bearer ${token}`);
|
|
4207
|
+
return new Request(request, { headers });
|
|
4208
|
+
}
|
|
4209
|
+
/** @inheritDoc */
|
|
4210
|
+
async ensure() {
|
|
4211
|
+
await this.exchange();
|
|
4212
|
+
}
|
|
4213
|
+
/** @inheritDoc */
|
|
4214
|
+
async onUnauthorized(_response) {
|
|
4215
|
+
if (this.recoveredRecently()) return false;
|
|
4216
|
+
await this.exchange({ refused: this.lastSent });
|
|
4217
|
+
this.lastRecoveryAt = this.now();
|
|
4218
|
+
return true;
|
|
4219
|
+
}
|
|
4220
|
+
recoveredRecently() {
|
|
4221
|
+
return this.lastRecoveryAt !== void 0 && this.now() - this.lastRecoveryAt < this.cooldownMs;
|
|
4222
|
+
}
|
|
4223
|
+
};
|
|
4224
|
+
|
|
4225
|
+
//#region src/single-flight.ts
|
|
4226
|
+
/**
|
|
4227
|
+
* Shares one in-flight call. While a call is running, further callers get its promise instead
|
|
4228
|
+
* of starting their own; once it settles, the next caller starts a new one.
|
|
4229
|
+
*/
|
|
4230
|
+
function singleFlight(fn) {
|
|
4231
|
+
let inFlight;
|
|
4232
|
+
return (...args) => {
|
|
4233
|
+
if (inFlight) return inFlight;
|
|
4234
|
+
inFlight = fn(...args).finally(() => {
|
|
4235
|
+
inFlight = void 0;
|
|
4236
|
+
});
|
|
4237
|
+
return inFlight;
|
|
4238
|
+
};
|
|
4239
|
+
}
|
|
4240
|
+
|
|
4241
|
+
//#region src/tracked.ts
|
|
4242
|
+
/** Wraps an async function, counting settled calls and remembering how the last one settled. */
|
|
4243
|
+
function tracked(fn) {
|
|
4244
|
+
let completed = 0;
|
|
4245
|
+
let last;
|
|
4246
|
+
async function call(...args) {
|
|
4247
|
+
try {
|
|
4248
|
+
const value = await fn(...args);
|
|
4249
|
+
last = {
|
|
4250
|
+
settled: "fulfilled",
|
|
4251
|
+
value
|
|
4252
|
+
};
|
|
4253
|
+
return value;
|
|
4254
|
+
} catch (reason) {
|
|
4255
|
+
last = {
|
|
4256
|
+
settled: "rejected",
|
|
4257
|
+
reason
|
|
4258
|
+
};
|
|
4259
|
+
throw reason;
|
|
4260
|
+
} finally {
|
|
4261
|
+
completed += 1;
|
|
4262
|
+
}
|
|
4263
|
+
}
|
|
4264
|
+
return {
|
|
4265
|
+
call,
|
|
4266
|
+
getCompleted: () => completed,
|
|
4267
|
+
getLast: () => last
|
|
4268
|
+
};
|
|
4269
|
+
}
|
|
4270
|
+
|
|
4271
|
+
//#region src/with-auth-strategy.ts
|
|
4272
|
+
/** Sends a clone of the request through the strategy's `attach`, leaving the original replayable. */
|
|
4273
|
+
async function fetchWithAuth(authStrategy, fetch, request) {
|
|
4274
|
+
const clonedRequest = request.clone();
|
|
4275
|
+
return fetch(await authStrategy.attach(clonedRequest));
|
|
4276
|
+
}
|
|
4277
|
+
/** A 401 that lands after a recovery finished takes that recovery's decision: its error, or its verdict. */
|
|
4278
|
+
function inheritRecovery(outcome) {
|
|
4279
|
+
if (outcome?.settled === "rejected") throw outcome.reason;
|
|
4280
|
+
return outcome?.value ?? true;
|
|
4281
|
+
}
|
|
4282
|
+
/** A fetch that attaches through the strategy, and on a 401 recovers once and retries once. */
|
|
4283
|
+
function withAuthStrategy(authStrategy, fetch = globalThis.fetch) {
|
|
4284
|
+
const { call: recover, getCompleted: getRecoveryCount, getLast: getLastRecovery } = tracked((response) => authStrategy.onUnauthorized(response));
|
|
4285
|
+
const tryRecover = singleFlight(recover);
|
|
4286
|
+
return async (input, init) => {
|
|
4287
|
+
const request = new Request(input, init);
|
|
4288
|
+
const startRecoveryCount = getRecoveryCount();
|
|
4289
|
+
const response = await fetchWithAuth(authStrategy, fetch, request);
|
|
4290
|
+
if (response.status !== 401) return response;
|
|
4291
|
+
if (getRecoveryCount() > startRecoveryCount ? inheritRecovery(getLastRecovery()) : await tryRecover(response)) return fetchWithAuth(authStrategy, fetch, request);
|
|
4292
|
+
return response;
|
|
4293
|
+
};
|
|
4294
|
+
}
|
|
4295
|
+
|
|
4296
|
+
//#region src/errors/authorization-server-unavailable.ts
|
|
4297
|
+
var AuthorizationServerUnavailable = class extends Error {
|
|
4298
|
+
name = "AuthorizationServerUnavailable";
|
|
4299
|
+
};
|
|
4300
|
+
|
|
4301
|
+
//#region src/discovery.ts
|
|
4302
|
+
const REQUEST_TIMEOUT_MS$2 = 1e4;
|
|
4303
|
+
async function discoverAuthorizationServer(issuer, fetch = globalThis.fetch) {
|
|
4304
|
+
const metadata = await readMetadata(`${issuer}/.well-known/oauth-authorization-server`, fetch);
|
|
4305
|
+
return {
|
|
4306
|
+
tokenEndpoint: metadata.token_endpoint,
|
|
4307
|
+
identityProviderIssuer: metadata.vention_identity_provider_issuer,
|
|
4308
|
+
clients: metadata.vention_clients
|
|
4309
|
+
};
|
|
4310
|
+
}
|
|
4311
|
+
async function discoverOpenIdProvider(issuer, fetch = globalThis.fetch) {
|
|
4312
|
+
const url = `${issuer}/.well-known/openid-configuration`;
|
|
4313
|
+
const metadata = await readMetadata(url, fetch);
|
|
4314
|
+
if (metadata.issuer !== issuer) throw new AuthorizationServerUnavailable(`${url} names the issuer ${metadata.issuer}, not ${issuer}`);
|
|
4315
|
+
return {
|
|
4316
|
+
authorizationEndpoint: metadata.authorization_endpoint,
|
|
4317
|
+
tokenEndpoint: metadata.token_endpoint
|
|
4318
|
+
};
|
|
4319
|
+
}
|
|
4320
|
+
async function readMetadata(url, fetch) {
|
|
4321
|
+
const response = await fetch(url, {
|
|
4322
|
+
headers: { Accept: "application/json" },
|
|
4323
|
+
redirect: "error",
|
|
4324
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS$2)
|
|
4325
|
+
}).catch((error) => {
|
|
4326
|
+
throw new AuthorizationServerUnavailable(`Could not reach ${url}`, { cause: error });
|
|
4327
|
+
});
|
|
4328
|
+
if (!response.ok) throw new AuthorizationServerUnavailable(`${url} answered ${response.status}`);
|
|
4329
|
+
return response.json().catch((error) => {
|
|
4330
|
+
throw new AuthorizationServerUnavailable(`${url} did not answer with JSON`, { cause: error });
|
|
4331
|
+
});
|
|
4332
|
+
}
|
|
4333
|
+
|
|
4334
|
+
//#region src/errors/exchange-rejected.ts
|
|
4335
|
+
var ExchangeRejected = class extends Error {
|
|
4336
|
+
code;
|
|
4337
|
+
name = "ExchangeRejected";
|
|
4338
|
+
constructor(code) {
|
|
4339
|
+
super(`The authorization server refused the token exchange (${code})`);
|
|
4340
|
+
this.code = code;
|
|
4341
|
+
}
|
|
4342
|
+
};
|
|
4343
|
+
|
|
4344
|
+
//#region src/errors/login-required.ts
|
|
4345
|
+
var LoginRequired = class extends Error {
|
|
4346
|
+
name = "LoginRequired";
|
|
4347
|
+
};
|
|
4348
|
+
|
|
4349
|
+
//#region src/errors/login-timed-out.ts
|
|
4350
|
+
var LoginTimedOut = class extends Error {
|
|
4351
|
+
name = "LoginTimedOut";
|
|
4352
|
+
constructor() {
|
|
4353
|
+
super("Login timed out");
|
|
4354
|
+
}
|
|
4355
|
+
};
|
|
4356
|
+
|
|
4357
|
+
//#region src/oauth2-token-request.ts
|
|
4358
|
+
const REQUEST_TIMEOUT_MS$1 = 1e4;
|
|
4359
|
+
function exchangeForGatewayToken(tokenEndpoint, subjectToken, fetch, now) {
|
|
4360
|
+
return requestToken(tokenEndpoint, subjectToken, "urn:ietf:params:oauth:token-type:access_token", fetch, now);
|
|
4361
|
+
}
|
|
4362
|
+
function renewGatewayToken(tokenEndpoint, gatewayToken, fetch, now) {
|
|
4363
|
+
return requestToken(tokenEndpoint, gatewayToken, "urn:ietf:params:oauth:token-type:jwt", fetch, now);
|
|
4364
|
+
}
|
|
4365
|
+
async function requestToken(tokenEndpoint, subjectToken, subjectTokenType, fetch, now) {
|
|
4366
|
+
const response = await fetch(tokenEndpoint, {
|
|
4367
|
+
method: "POST",
|
|
4368
|
+
headers: {
|
|
4369
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
4370
|
+
Accept: "application/json"
|
|
4371
|
+
},
|
|
4372
|
+
body: new URLSearchParams({
|
|
4373
|
+
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
4374
|
+
subject_token: subjectToken,
|
|
4375
|
+
subject_token_type: subjectTokenType
|
|
4376
|
+
}),
|
|
4377
|
+
redirect: "error",
|
|
4378
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS$1)
|
|
4379
|
+
}).catch((error) => {
|
|
4380
|
+
throw new AuthorizationServerUnavailable("The authorization server could not be reached", { cause: error });
|
|
4381
|
+
});
|
|
4382
|
+
if (response.status >= 500 || response.status === 408 || response.status === 429) throw new AuthorizationServerUnavailable(`The authorization server answered ${response.status}`);
|
|
4383
|
+
if (!response.ok) {
|
|
4384
|
+
const refusal = await response.json().catch(() => void 0);
|
|
4385
|
+
throw new ExchangeRejected(refusal?.error ?? `http_${response.status}`);
|
|
4386
|
+
}
|
|
4387
|
+
return response.json().then((body) => toStoredGatewayToken(body, now())).catch(() => {
|
|
4388
|
+
throw new AuthorizationServerUnavailable("The authorization server returned an unusable token response");
|
|
4389
|
+
});
|
|
4390
|
+
}
|
|
4391
|
+
function toStoredGatewayToken({ access_token: token, expires_in: expiresIn }, receivedAt) {
|
|
4392
|
+
const payload = (token.split(".")[1] ?? "").replace(/-/g, "+").replace(/_/g, "/");
|
|
4393
|
+
const claims = JSON.parse(atob(payload));
|
|
4394
|
+
return {
|
|
4395
|
+
token,
|
|
4396
|
+
receivedAt,
|
|
4397
|
+
expiresAt: receivedAt + expiresIn * 1e3,
|
|
4398
|
+
capExpiresAt: receivedAt + (claims.cap_exp - claims.exp + expiresIn) * 1e3
|
|
4399
|
+
};
|
|
4400
|
+
}
|
|
4401
|
+
|
|
4402
|
+
//#region src/oauth2-token-exchange.ts
|
|
4403
|
+
function loginRequired() {
|
|
4404
|
+
return new LoginRequired("Session expired. Run 'vention login'.");
|
|
4405
|
+
}
|
|
4406
|
+
function outlivesMargin(expiresAt, now) {
|
|
4407
|
+
return expiresAt - now > 6e4;
|
|
4408
|
+
}
|
|
4409
|
+
function isFresh(token, now) {
|
|
4410
|
+
const halfLife = (token.expiresAt - token.receivedAt) / 2;
|
|
4411
|
+
return now - token.receivedAt < halfLife && outlivesMargin(token.expiresAt, now);
|
|
4412
|
+
}
|
|
4413
|
+
function oauth2TokenExchange({ issuer, store, now = Date.now, fetch = globalThis.fetch }) {
|
|
4414
|
+
const storedToken = async () => {
|
|
4415
|
+
const latest = await store.read();
|
|
4416
|
+
if (latest === void 0) throw loginRequired();
|
|
4417
|
+
return latest.token;
|
|
4418
|
+
};
|
|
4419
|
+
const renew = singleFlight(async (current) => {
|
|
4420
|
+
const beforeRenewal = await storedToken();
|
|
4421
|
+
if (beforeRenewal !== current.token) return beforeRenewal;
|
|
4422
|
+
const { tokenEndpoint } = await discoverAuthorizationServer(issuer, fetch);
|
|
4423
|
+
const renewed = await renewGatewayToken(tokenEndpoint, current.token, fetch, now).catch((error) => {
|
|
4424
|
+
throw error instanceof ExchangeRejected ? loginRequired() : error;
|
|
4425
|
+
});
|
|
4426
|
+
if (!outlivesMargin(renewed.expiresAt, now())) throw loginRequired();
|
|
4427
|
+
const beforeWrite = await storedToken();
|
|
4428
|
+
if (beforeWrite !== current.token) return beforeWrite;
|
|
4429
|
+
await store.write(renewed);
|
|
4430
|
+
return renewed.token;
|
|
4431
|
+
});
|
|
4432
|
+
return async (request) => {
|
|
4433
|
+
const current = await store.read();
|
|
4434
|
+
if (current === void 0 || now() >= current.capExpiresAt) throw loginRequired();
|
|
4435
|
+
const currentRefused = request?.refused === current.token;
|
|
4436
|
+
if (!currentRefused && isFresh(current, now())) return current.token;
|
|
4437
|
+
const token = await renew(current).catch((error) => {
|
|
4438
|
+
if (error instanceof AuthorizationServerUnavailable && !currentRefused && outlivesMargin(current.expiresAt, now())) return current.token;
|
|
4439
|
+
throw error;
|
|
4440
|
+
});
|
|
4441
|
+
if (token === request?.refused) throw loginRequired();
|
|
4442
|
+
return token;
|
|
4443
|
+
};
|
|
4444
|
+
}
|
|
4445
|
+
|
|
4189
4446
|
class ApiError extends Error {
|
|
4190
4447
|
constructor(message, status, statusText, responseBody, url) {
|
|
4191
4448
|
super(message);
|
|
@@ -4268,6 +4525,8 @@ const handleCommandError = (error, context) => {
|
|
|
4268
4525
|
console.error();
|
|
4269
4526
|
suggestions.forEach(msg => console.error(chalk.yellow(msg)));
|
|
4270
4527
|
}
|
|
4528
|
+
} else if (error instanceof LoginRequired) {
|
|
4529
|
+
console.error(chalk.red(error.message));
|
|
4271
4530
|
} else {
|
|
4272
4531
|
console.error(chalk.red(`Error: ${error instanceof Error ? error.message : String(error)}`));
|
|
4273
4532
|
}
|
|
@@ -4303,7 +4562,7 @@ const POSTHOG_PROJECT_TOKENS = {
|
|
|
4303
4562
|
};
|
|
4304
4563
|
const POSTHOG_FLAGS_URL = "https://us.i.posthog.com/flags?v=2";
|
|
4305
4564
|
const CACHE_TTL_MS = 15 * 60 * 1000;
|
|
4306
|
-
const REQUEST_TIMEOUT_MS
|
|
4565
|
+
const REQUEST_TIMEOUT_MS = 2000;
|
|
4307
4566
|
const FlagsResponseSchema = z.object({
|
|
4308
4567
|
flags: z.record(z.string(), z.object({
|
|
4309
4568
|
enabled: z.boolean()
|
|
@@ -4365,7 +4624,7 @@ const fetchFlags = async (projectToken, distinctId) => {
|
|
|
4365
4624
|
api_key: projectToken,
|
|
4366
4625
|
distinct_id: distinctId
|
|
4367
4626
|
}),
|
|
4368
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS
|
|
4627
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
4369
4628
|
});
|
|
4370
4629
|
if (!response.ok) {
|
|
4371
4630
|
return undefined;
|
|
@@ -4910,11 +5169,11 @@ var getInternalIteratorState = InternalStateModule$4.getterFor(URL_SEARCH_PARAMS
|
|
|
4910
5169
|
|
|
4911
5170
|
var nativeFetch = safeGetBuiltIn('fetch');
|
|
4912
5171
|
var NativeRequest = safeGetBuiltIn('Request');
|
|
4913
|
-
var Headers = safeGetBuiltIn('Headers');
|
|
5172
|
+
var Headers$1 = safeGetBuiltIn('Headers');
|
|
4914
5173
|
var RequestPrototype = NativeRequest && NativeRequest.prototype;
|
|
4915
|
-
var HeadersPrototype = Headers && Headers.prototype;
|
|
5174
|
+
var HeadersPrototype = Headers$1 && Headers$1.prototype;
|
|
4916
5175
|
var TypeError$5 = globalThis$q.TypeError;
|
|
4917
|
-
var encodeURIComponent$
|
|
5176
|
+
var encodeURIComponent$2 = globalThis$q.encodeURIComponent;
|
|
4918
5177
|
var fromCharCode = String.fromCharCode;
|
|
4919
5178
|
var fromCodePoint = getBuiltIn$1('String', 'fromCodePoint');
|
|
4920
5179
|
var $parseInt = parseInt;
|
|
@@ -5079,7 +5338,7 @@ var replacer = function (match) {
|
|
|
5079
5338
|
};
|
|
5080
5339
|
|
|
5081
5340
|
var serialize = function (it) {
|
|
5082
|
-
return replace$5(encodeURIComponent$
|
|
5341
|
+
return replace$5(encodeURIComponent$2(it), find, replacer);
|
|
5083
5342
|
};
|
|
5084
5343
|
|
|
5085
5344
|
var URLSearchParamsIterator = createIteratorConstructor(function Iterator(params, kind) {
|
|
@@ -5344,7 +5603,7 @@ $$v({ global: true, constructor: true, forced: !USE_NATIVE_URL$1 }, {
|
|
|
5344
5603
|
});
|
|
5345
5604
|
|
|
5346
5605
|
// Wrap `fetch` and `Request` for correct work with polyfilled `URLSearchParams`
|
|
5347
|
-
if (!USE_NATIVE_URL$1 && isCallable$4(Headers)) {
|
|
5606
|
+
if (!USE_NATIVE_URL$1 && isCallable$4(Headers$1)) {
|
|
5348
5607
|
var headersHas = uncurryThis$p(HeadersPrototype.has);
|
|
5349
5608
|
var headersSet = uncurryThis$p(HeadersPrototype.set);
|
|
5350
5609
|
|
|
@@ -5353,7 +5612,7 @@ if (!USE_NATIVE_URL$1 && isCallable$4(Headers)) {
|
|
|
5353
5612
|
var body = init.body;
|
|
5354
5613
|
var headers;
|
|
5355
5614
|
if (classof$8(body) === URL_SEARCH_PARAMS) {
|
|
5356
|
-
headers = init.headers ? new Headers(init.headers) : new Headers();
|
|
5615
|
+
headers = init.headers ? new Headers$1(init.headers) : new Headers$1();
|
|
5357
5616
|
if (!headersHas(headers, 'content-type')) {
|
|
5358
5617
|
headersSet(headers, 'content-type', 'application/x-www-form-urlencoded;charset=UTF-8');
|
|
5359
5618
|
}
|
|
@@ -5423,7 +5682,7 @@ var getInternalSearchParamsState = URLSearchParamsModule.getState;
|
|
|
5423
5682
|
|
|
5424
5683
|
var NativeURL = globalThis$p.URL;
|
|
5425
5684
|
var TypeError$4 = globalThis$p.TypeError;
|
|
5426
|
-
var encodeURIComponent = globalThis$p.encodeURIComponent;
|
|
5685
|
+
var encodeURIComponent$1 = globalThis$p.encodeURIComponent;
|
|
5427
5686
|
var parseInt$1 = globalThis$p.parseInt;
|
|
5428
5687
|
var floor$5 = Math.floor;
|
|
5429
5688
|
var pow$1 = Math.pow;
|
|
@@ -5673,7 +5932,7 @@ var userinfoPercentEncodeSet = assign({}, pathPercentEncodeSet, {
|
|
|
5673
5932
|
var percentEncode = function (chr, set) {
|
|
5674
5933
|
var code = codeAt(chr, 0);
|
|
5675
5934
|
// encodeURIComponent does not encode ', which is in the special-query percent-encode set
|
|
5676
|
-
return code >= 0x20 && code < 0x7F && !hasOwn$4(set, chr) ? chr : chr === "'" && hasOwn$4(set, chr) ? '%27' : encodeURIComponent(chr);
|
|
5935
|
+
return code >= 0x20 && code < 0x7F && !hasOwn$4(set, chr) ? chr : chr === "'" && hasOwn$4(set, chr) ? '%27' : encodeURIComponent$1(chr);
|
|
5677
5936
|
};
|
|
5678
5937
|
|
|
5679
5938
|
// https://url.spec.whatwg.org/#special-scheme
|
|
@@ -6851,104 +7110,6 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
6851
7110
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
6852
7111
|
};
|
|
6853
7112
|
|
|
6854
|
-
//#region src/errors/authorization-server-unavailable.ts
|
|
6855
|
-
var AuthorizationServerUnavailable = class extends Error {
|
|
6856
|
-
name = "AuthorizationServerUnavailable";
|
|
6857
|
-
};
|
|
6858
|
-
|
|
6859
|
-
//#region src/discovery.ts
|
|
6860
|
-
const REQUEST_TIMEOUT_MS$1 = 1e4;
|
|
6861
|
-
async function discoverAuthorizationServer(issuer, fetch = globalThis.fetch) {
|
|
6862
|
-
const metadata = await readMetadata(`${issuer}/.well-known/oauth-authorization-server`, fetch);
|
|
6863
|
-
return {
|
|
6864
|
-
tokenEndpoint: metadata.token_endpoint,
|
|
6865
|
-
identityProviderIssuer: metadata.vention_identity_provider_issuer,
|
|
6866
|
-
clients: metadata.vention_clients
|
|
6867
|
-
};
|
|
6868
|
-
}
|
|
6869
|
-
async function discoverOpenIdProvider(issuer, fetch = globalThis.fetch) {
|
|
6870
|
-
const url = `${issuer}/.well-known/openid-configuration`;
|
|
6871
|
-
const metadata = await readMetadata(url, fetch);
|
|
6872
|
-
if (metadata.issuer !== issuer) throw new AuthorizationServerUnavailable(`${url} names the issuer ${metadata.issuer}, not ${issuer}`);
|
|
6873
|
-
return {
|
|
6874
|
-
authorizationEndpoint: metadata.authorization_endpoint,
|
|
6875
|
-
tokenEndpoint: metadata.token_endpoint
|
|
6876
|
-
};
|
|
6877
|
-
}
|
|
6878
|
-
async function readMetadata(url, fetch) {
|
|
6879
|
-
const response = await fetch(url, {
|
|
6880
|
-
headers: { Accept: "application/json" },
|
|
6881
|
-
redirect: "error",
|
|
6882
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS$1)
|
|
6883
|
-
}).catch((error) => {
|
|
6884
|
-
throw new AuthorizationServerUnavailable(`Could not reach ${url}`, { cause: error });
|
|
6885
|
-
});
|
|
6886
|
-
if (!response.ok) throw new AuthorizationServerUnavailable(`${url} answered ${response.status}`);
|
|
6887
|
-
return response.json().catch((error) => {
|
|
6888
|
-
throw new AuthorizationServerUnavailable(`${url} did not answer with JSON`, { cause: error });
|
|
6889
|
-
});
|
|
6890
|
-
}
|
|
6891
|
-
|
|
6892
|
-
//#region src/errors/exchange-rejected.ts
|
|
6893
|
-
var ExchangeRejected = class extends Error {
|
|
6894
|
-
code;
|
|
6895
|
-
name = "ExchangeRejected";
|
|
6896
|
-
constructor(code) {
|
|
6897
|
-
super(`The authorization server refused the token exchange (${code})`);
|
|
6898
|
-
this.code = code;
|
|
6899
|
-
}
|
|
6900
|
-
};
|
|
6901
|
-
|
|
6902
|
-
//#region src/errors/login-timed-out.ts
|
|
6903
|
-
var LoginTimedOut = class extends Error {
|
|
6904
|
-
name = "LoginTimedOut";
|
|
6905
|
-
constructor() {
|
|
6906
|
-
super("Login timed out");
|
|
6907
|
-
}
|
|
6908
|
-
};
|
|
6909
|
-
|
|
6910
|
-
//#region src/oauth2-token-request.ts
|
|
6911
|
-
const REQUEST_TIMEOUT_MS = 1e4;
|
|
6912
|
-
function exchangeForGatewayToken(tokenEndpoint, subjectToken, fetch, now) {
|
|
6913
|
-
return requestToken(tokenEndpoint, subjectToken, "urn:ietf:params:oauth:token-type:access_token", fetch, now);
|
|
6914
|
-
}
|
|
6915
|
-
async function requestToken(tokenEndpoint, subjectToken, subjectTokenType, fetch, now) {
|
|
6916
|
-
const response = await fetch(tokenEndpoint, {
|
|
6917
|
-
method: "POST",
|
|
6918
|
-
headers: {
|
|
6919
|
-
"Content-Type": "application/x-www-form-urlencoded",
|
|
6920
|
-
Accept: "application/json"
|
|
6921
|
-
},
|
|
6922
|
-
body: new URLSearchParams({
|
|
6923
|
-
grant_type: "urn:ietf:params:oauth:grant-type:token-exchange",
|
|
6924
|
-
subject_token: subjectToken,
|
|
6925
|
-
subject_token_type: subjectTokenType
|
|
6926
|
-
}),
|
|
6927
|
-
redirect: "error",
|
|
6928
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
6929
|
-
}).catch((error) => {
|
|
6930
|
-
throw new AuthorizationServerUnavailable("The authorization server could not be reached", { cause: error });
|
|
6931
|
-
});
|
|
6932
|
-
if (response.status >= 500 || response.status === 408 || response.status === 429) throw new AuthorizationServerUnavailable(`The authorization server answered ${response.status}`);
|
|
6933
|
-
if (!response.ok) {
|
|
6934
|
-
const refusal = await response.json().catch(() => void 0);
|
|
6935
|
-
throw new ExchangeRejected(refusal?.error ?? `http_${response.status}`);
|
|
6936
|
-
}
|
|
6937
|
-
return response.json().then((body) => toStoredGatewayToken(body, now())).catch(() => {
|
|
6938
|
-
throw new AuthorizationServerUnavailable("The authorization server returned an unusable token response");
|
|
6939
|
-
});
|
|
6940
|
-
}
|
|
6941
|
-
function toStoredGatewayToken({ access_token: token, expires_in: expiresIn }, receivedAt) {
|
|
6942
|
-
const payload = (token.split(".")[1] ?? "").replace(/-/g, "+").replace(/_/g, "/");
|
|
6943
|
-
const claims = JSON.parse(atob(payload));
|
|
6944
|
-
return {
|
|
6945
|
-
token,
|
|
6946
|
-
receivedAt,
|
|
6947
|
-
expiresAt: receivedAt + expiresIn * 1e3,
|
|
6948
|
-
capExpiresAt: receivedAt + (claims.cap_exp - claims.exp + expiresIn) * 1e3
|
|
6949
|
-
};
|
|
6950
|
-
}
|
|
6951
|
-
|
|
6952
7113
|
//#region src/id-token.ts
|
|
6953
7114
|
const decodeClaims = (idToken = "") => {
|
|
6954
7115
|
const segments = idToken.split(".");
|
|
@@ -7043,6 +7204,7 @@ const startCallbackServer = async (expectedState, timeoutMs) => {
|
|
|
7043
7204
|
const close = () => {
|
|
7044
7205
|
clearTimeout(timer);
|
|
7045
7206
|
callbackServer.close();
|
|
7207
|
+
callbackServer.closeAllConnections();
|
|
7046
7208
|
};
|
|
7047
7209
|
const authorizationCodeReceived = new Promise((resolve, reject) => {
|
|
7048
7210
|
timer = setTimeout(() => {
|
|
@@ -7052,7 +7214,7 @@ const startCallbackServer = async (expectedState, timeoutMs) => {
|
|
|
7052
7214
|
callbackServer.on("request", (req, res) => {
|
|
7053
7215
|
const outcome = readCallback(req, res, expectedState);
|
|
7054
7216
|
if (outcome === void 0) return;
|
|
7055
|
-
close
|
|
7217
|
+
res.once("close", close);
|
|
7056
7218
|
if ("error" in outcome) reject(outcome.error);
|
|
7057
7219
|
else resolve(outcome.authorizationCode);
|
|
7058
7220
|
});
|
|
@@ -7083,7 +7245,7 @@ const redeemAuthorizationCode = async (options, authorizationCode, codeVerifier,
|
|
|
7083
7245
|
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
7084
7246
|
body,
|
|
7085
7247
|
redirect: "error",
|
|
7086
|
-
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS)
|
|
7248
|
+
signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS$1)
|
|
7087
7249
|
}).catch((error) => {
|
|
7088
7250
|
throw new Error("Could not reach the identity provider", { cause: error });
|
|
7089
7251
|
});
|
|
@@ -10952,585 +11114,1476 @@ const getDigitalTwinUrl = (environment, sessionId) => {
|
|
|
10952
11114
|
const rejectMissingSession = async () => {
|
|
10953
11115
|
throw new Error("Linked session token is not set");
|
|
10954
11116
|
};
|
|
10955
|
-
const buildConnection = (environment, designId, sessionId) => ({
|
|
11117
|
+
const buildConnection$1 = (environment, designId, sessionId) => ({
|
|
10956
11118
|
baseUrl: getDigitalTwinUrl(environment, sessionId),
|
|
10957
11119
|
headers: {
|
|
10958
11120
|
Cookie: `digital-twin-session-${designId}=s%3A${sessionId}.s`
|
|
10959
11121
|
},
|
|
10960
11122
|
fetch: sessionId ? fetchWithUserAgent : rejectMissingSession
|
|
10961
11123
|
});
|
|
10962
|
-
const resolveConnection = async (session, designId) => {
|
|
11124
|
+
const resolveConnection$1 = async (session, designId) => {
|
|
10963
11125
|
const allocations = await getUserAllocations(session);
|
|
10964
11126
|
const allocation = allocations.find(candidate => candidate.designId === designId);
|
|
10965
11127
|
if (!allocation) {
|
|
10966
11128
|
return undefined;
|
|
10967
11129
|
}
|
|
10968
|
-
return buildConnection(session.environment, designId, allocation.sessionId);
|
|
11130
|
+
return buildConnection$1(session.environment, designId, allocation.sessionId);
|
|
10969
11131
|
};
|
|
10970
|
-
const listDesigns = async session => {
|
|
11132
|
+
const listDesigns$2 = async session => {
|
|
10971
11133
|
const allocations = await getUserAllocations(session);
|
|
10972
11134
|
return allocations.map(allocation => ({
|
|
10973
11135
|
id: allocation.designId,
|
|
10974
11136
|
name: allocation.designName,
|
|
10975
|
-
connection: buildConnection(session.environment, allocation.designId, allocation.sessionId)
|
|
11137
|
+
connection: buildConnection$1(session.environment, allocation.designId, allocation.sessionId)
|
|
10976
11138
|
}));
|
|
10977
11139
|
};
|
|
10978
11140
|
|
|
10979
|
-
|
|
10980
|
-
|
|
10981
|
-
|
|
10982
|
-
|
|
10983
|
-
if (
|
|
10984
|
-
|
|
10985
|
-
console.error(chalk.red(`Application "${machineCodeAppDirectoryInfo.appName}" (ID: ${machineCodeAppDirectoryInfo.applicationId}) not found in the digital twin.`));
|
|
10986
|
-
process.exit(1);
|
|
10987
|
-
}
|
|
10988
|
-
return targetApp;
|
|
10989
|
-
};
|
|
10990
|
-
const getAvailableAppsFromDigitalTwin = async connection => {
|
|
10991
|
-
const allApplications = await getAllApplicationsWithSourceCode(connection);
|
|
10992
|
-
return allApplications.filter(app => app.type === "machine_code");
|
|
11141
|
+
var $TypeError$1 = TypeError;
|
|
11142
|
+
var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991
|
|
11143
|
+
|
|
11144
|
+
var doesNotExceedSafeInteger$1 = function (it) {
|
|
11145
|
+
if (it > MAX_SAFE_INTEGER) throw new $TypeError$1('Maximum allowed index exceeded');
|
|
11146
|
+
return it;
|
|
10993
11147
|
};
|
|
10994
|
-
|
|
10995
|
-
|
|
10996
|
-
|
|
10997
|
-
|
|
10998
|
-
|
|
10999
|
-
|
|
11000
|
-
|
|
11001
|
-
|
|
11002
|
-
|
|
11003
|
-
|
|
11004
|
-
|
|
11005
|
-
|
|
11006
|
-
|
|
11007
|
-
|
|
11008
|
-
|
|
11009
|
-
|
|
11010
|
-
|
|
11011
|
-
|
|
11012
|
-
|
|
11013
|
-
|
|
11014
|
-
|
|
11015
|
-
|
|
11016
|
-
|
|
11148
|
+
|
|
11149
|
+
var isArray = isArray$5;
|
|
11150
|
+
var lengthOfArrayLike$2 = lengthOfArrayLike$g;
|
|
11151
|
+
var doesNotExceedSafeInteger = doesNotExceedSafeInteger$1;
|
|
11152
|
+
var bind = functionBindContext;
|
|
11153
|
+
var createProperty = createProperty$6;
|
|
11154
|
+
|
|
11155
|
+
// `FlattenIntoArray` abstract operation
|
|
11156
|
+
// https://tc39.es/ecma262/#sec-flattenintoarray
|
|
11157
|
+
var flattenIntoArray$1 = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
|
|
11158
|
+
var targetIndex = start;
|
|
11159
|
+
var sourceIndex = 0;
|
|
11160
|
+
var mapFn = mapper ? bind(mapper, thisArg) : false;
|
|
11161
|
+
var element, elementLen;
|
|
11162
|
+
|
|
11163
|
+
while (sourceIndex < sourceLen) {
|
|
11164
|
+
if (sourceIndex in source) {
|
|
11165
|
+
element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
|
|
11166
|
+
|
|
11167
|
+
if (depth > 0 && isArray(element)) {
|
|
11168
|
+
elementLen = lengthOfArrayLike$2(element);
|
|
11169
|
+
targetIndex = flattenIntoArray$1(target, original, element, elementLen, targetIndex, depth - 1) - 1;
|
|
11170
|
+
} else {
|
|
11171
|
+
doesNotExceedSafeInteger(targetIndex + 1);
|
|
11172
|
+
createProperty(target, targetIndex, element);
|
|
11173
|
+
}
|
|
11174
|
+
|
|
11175
|
+
targetIndex++;
|
|
11176
|
+
}
|
|
11177
|
+
sourceIndex++;
|
|
11017
11178
|
}
|
|
11018
|
-
|
|
11019
|
-
await writeMachineCodeAppDirectoryInfo(appDirectoryPath, {
|
|
11020
|
-
appName: selectedApp.name,
|
|
11021
|
-
designId: selectedDesign.id,
|
|
11022
|
-
applicationId: selectedApp.id,
|
|
11023
|
-
lastPulledAt: new Date().toISOString(),
|
|
11024
|
-
environment: session.environment,
|
|
11025
|
-
uuid: selectedApp.uuid
|
|
11026
|
-
});
|
|
11027
|
-
console.log();
|
|
11028
|
-
console.log(chalk.green(`✅ Successfully pulled "${selectedApp.name}" to: ${appDirectoryPath}`));
|
|
11029
|
-
console.log(chalk.blue(`📁 To navigate to your project, run:`));
|
|
11030
|
-
console.log(chalk.cyan(`cd "${safeFileName}"`));
|
|
11031
|
-
console.log(chalk.blue("💡 You can now start working on your application!"));
|
|
11179
|
+
return targetIndex;
|
|
11032
11180
|
};
|
|
11033
|
-
|
|
11034
|
-
|
|
11035
|
-
|
|
11036
|
-
|
|
11037
|
-
|
|
11038
|
-
|
|
11039
|
-
|
|
11040
|
-
|
|
11041
|
-
|
|
11042
|
-
|
|
11043
|
-
|
|
11044
|
-
|
|
11045
|
-
|
|
11046
|
-
|
|
11047
|
-
|
|
11181
|
+
|
|
11182
|
+
var flattenIntoArray_1 = flattenIntoArray$1;
|
|
11183
|
+
|
|
11184
|
+
var $$8 = _export;
|
|
11185
|
+
var flattenIntoArray = flattenIntoArray_1;
|
|
11186
|
+
var aCallable$4 = aCallable$l;
|
|
11187
|
+
var toObject$1 = toObject$b;
|
|
11188
|
+
var lengthOfArrayLike$1 = lengthOfArrayLike$g;
|
|
11189
|
+
var arraySpeciesCreate = arraySpeciesCreate$2;
|
|
11190
|
+
|
|
11191
|
+
// `Array.prototype.flatMap` method
|
|
11192
|
+
// https://tc39.es/ecma262/#sec-array.prototype.flatmap
|
|
11193
|
+
$$8({ target: 'Array', proto: true }, {
|
|
11194
|
+
flatMap: function flatMap(callbackfn /* , thisArg */) {
|
|
11195
|
+
var O = toObject$1(this);
|
|
11196
|
+
var sourceLen = lengthOfArrayLike$1(O);
|
|
11197
|
+
var A;
|
|
11198
|
+
aCallable$4(callbackfn);
|
|
11199
|
+
A = arraySpeciesCreate(O, 0);
|
|
11200
|
+
flattenIntoArray(A, O, O, sourceLen, 0, 1, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
|
|
11201
|
+
return A;
|
|
11048
11202
|
}
|
|
11049
|
-
|
|
11050
|
-
|
|
11051
|
-
|
|
11052
|
-
|
|
11053
|
-
|
|
11054
|
-
|
|
11055
|
-
|
|
11203
|
+
});
|
|
11204
|
+
|
|
11205
|
+
var tryToString = tryToString$6;
|
|
11206
|
+
|
|
11207
|
+
var $TypeError = TypeError;
|
|
11208
|
+
|
|
11209
|
+
var deletePropertyOrThrow$1 = function (O, P) {
|
|
11210
|
+
if (!delete O[P]) throw new $TypeError('Cannot delete property ' + tryToString(P) + ' of ' + tryToString(O));
|
|
11056
11211
|
};
|
|
11057
|
-
|
|
11058
|
-
|
|
11059
|
-
|
|
11060
|
-
|
|
11061
|
-
|
|
11062
|
-
|
|
11063
|
-
|
|
11064
|
-
|
|
11065
|
-
applicationId: selectedApp.id,
|
|
11066
|
-
lastPulledAt: new Date().toISOString(),
|
|
11067
|
-
environment: session.environment,
|
|
11068
|
-
uuid: selectedApp.uuid
|
|
11212
|
+
|
|
11213
|
+
var fails$2 = fails$F;
|
|
11214
|
+
|
|
11215
|
+
var arrayMethodIsStrict$1 = function (METHOD_NAME, argument) {
|
|
11216
|
+
var method = [][METHOD_NAME];
|
|
11217
|
+
return !!method && fails$2(function () {
|
|
11218
|
+
// eslint-disable-next-line no-useless-call -- required for testing
|
|
11219
|
+
method.call(null, argument || function () { return 1; }, 1);
|
|
11069
11220
|
});
|
|
11070
|
-
console.log(chalk.green(`Successfully linked current directory to design "${selectedDesign.name}" (ID: ${selectedDesign.id})`));
|
|
11071
|
-
console.log(chalk.green(`Application: "${selectedApp.name}" (ID: ${selectedApp.id})`));
|
|
11072
|
-
return {
|
|
11073
|
-
selectedDesign,
|
|
11074
|
-
selectedApp
|
|
11075
|
-
};
|
|
11076
11221
|
};
|
|
11077
|
-
|
|
11078
|
-
|
|
11079
|
-
|
|
11080
|
-
|
|
11081
|
-
|
|
11082
|
-
|
|
11222
|
+
|
|
11223
|
+
var $$7 = _export;
|
|
11224
|
+
var uncurryThis$4 = functionUncurryThis;
|
|
11225
|
+
var aCallable$3 = aCallable$l;
|
|
11226
|
+
var toObject = toObject$b;
|
|
11227
|
+
var lengthOfArrayLike = lengthOfArrayLike$g;
|
|
11228
|
+
var deletePropertyOrThrow = deletePropertyOrThrow$1;
|
|
11229
|
+
var toString$4 = toString$j;
|
|
11230
|
+
var fails$1 = fails$F;
|
|
11231
|
+
var internalSort = arraySort$1;
|
|
11232
|
+
var arrayMethodIsStrict = arrayMethodIsStrict$1;
|
|
11233
|
+
var FF = environmentFfVersion;
|
|
11234
|
+
var IE_OR_EDGE = environmentIsIeOrEdge;
|
|
11235
|
+
var V8 = environmentV8Version;
|
|
11236
|
+
var WEBKIT = environmentWebkitVersion;
|
|
11237
|
+
|
|
11238
|
+
var test = [];
|
|
11239
|
+
var nativeSort = uncurryThis$4(test.sort);
|
|
11240
|
+
var push = uncurryThis$4(test.push);
|
|
11241
|
+
|
|
11242
|
+
// IE8-
|
|
11243
|
+
var FAILS_ON_UNDEFINED = fails$1(function () {
|
|
11244
|
+
test.sort(undefined);
|
|
11245
|
+
});
|
|
11246
|
+
// V8 bug
|
|
11247
|
+
var FAILS_ON_NULL = fails$1(function () {
|
|
11248
|
+
test.sort(null);
|
|
11249
|
+
});
|
|
11250
|
+
// Old WebKit
|
|
11251
|
+
var STRICT_METHOD = arrayMethodIsStrict('sort');
|
|
11252
|
+
|
|
11253
|
+
var STABLE_SORT = !fails$1(function () {
|
|
11254
|
+
// feature detection can be too slow, so check engines versions
|
|
11255
|
+
if (V8) return V8 < 70;
|
|
11256
|
+
if (FF && FF > 3) return;
|
|
11257
|
+
if (IE_OR_EDGE) return true;
|
|
11258
|
+
if (WEBKIT) return WEBKIT < 603;
|
|
11259
|
+
|
|
11260
|
+
var result = '';
|
|
11261
|
+
var code, chr, value, index;
|
|
11262
|
+
|
|
11263
|
+
// generate an array with more 512 elements (Chakra and old V8 fails only in this case)
|
|
11264
|
+
for (code = 65; code < 76; code++) {
|
|
11265
|
+
chr = String.fromCharCode(code);
|
|
11266
|
+
|
|
11267
|
+
switch (code) {
|
|
11268
|
+
case 66: case 69: case 70: case 72: value = 3; break;
|
|
11269
|
+
case 68: case 71: value = 4; break;
|
|
11270
|
+
default: value = 2;
|
|
11271
|
+
}
|
|
11272
|
+
|
|
11273
|
+
for (index = 0; index < 47; index++) {
|
|
11274
|
+
test.push({ k: chr + index, v: value });
|
|
11275
|
+
}
|
|
11083
11276
|
}
|
|
11084
|
-
|
|
11085
|
-
|
|
11086
|
-
|
|
11087
|
-
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
});
|
|
11091
|
-
const availableApps = await getAvailableAppsFromDigitalTwin(selectedDesign.connection);
|
|
11092
|
-
if (availableApps.length === 0) {
|
|
11093
|
-
console.log();
|
|
11094
|
-
console.log(chalk.yellow("No machine code applications found in the digital twin"));
|
|
11095
|
-
process.exit(1);
|
|
11277
|
+
|
|
11278
|
+
test.sort(function (a, b) { return b.v - a.v; });
|
|
11279
|
+
|
|
11280
|
+
for (index = 0; index < test.length; index++) {
|
|
11281
|
+
chr = test[index].k.charAt(0);
|
|
11282
|
+
if (result.charAt(result.length - 1) !== chr) result += chr;
|
|
11096
11283
|
}
|
|
11097
|
-
const selectedApp = await select({
|
|
11098
|
-
message: "Select an application:",
|
|
11099
|
-
choices: availableApps.map(app => ({
|
|
11100
|
-
name: app.name,
|
|
11101
|
-
value: app
|
|
11102
|
-
}))
|
|
11103
|
-
});
|
|
11104
|
-
return {
|
|
11105
|
-
selectedDesign,
|
|
11106
|
-
selectedApp
|
|
11107
|
-
};
|
|
11108
|
-
};
|
|
11109
11284
|
|
|
11110
|
-
|
|
11111
|
-
|
|
11112
|
-
try {
|
|
11113
|
-
const session = await loadSession();
|
|
11114
|
-
if (!session) {
|
|
11115
|
-
console.error(chalk.red("Not logged in. Please run 'vention login' first."));
|
|
11116
|
-
process.exit(1);
|
|
11117
|
-
}
|
|
11118
|
-
const currentDir = process.cwd();
|
|
11119
|
-
console.log();
|
|
11120
|
-
await linkDirectory(session, currentDir);
|
|
11121
|
-
console.log(chalk.blue("You can now use 'vention pull' to download app content or 'vention push' to upload local changes."));
|
|
11122
|
-
} catch (error) {
|
|
11123
|
-
handleCommandError(error, "Failed to link directory");
|
|
11124
|
-
}
|
|
11125
|
-
});
|
|
11126
|
-
}
|
|
11285
|
+
return result !== 'DGBEFHACIJK';
|
|
11286
|
+
});
|
|
11127
11287
|
|
|
11128
|
-
|
|
11129
|
-
|
|
11130
|
-
|
|
11131
|
-
|
|
11132
|
-
|
|
11133
|
-
|
|
11134
|
-
|
|
11135
|
-
|
|
11136
|
-
|
|
11137
|
-
|
|
11138
|
-
|
|
11139
|
-
|
|
11140
|
-
|
|
11141
|
-
|
|
11142
|
-
|
|
11143
|
-
|
|
11144
|
-
|
|
11145
|
-
|
|
11146
|
-
|
|
11147
|
-
|
|
11148
|
-
|
|
11149
|
-
|
|
11150
|
-
|
|
11151
|
-
|
|
11152
|
-
|
|
11153
|
-
|
|
11154
|
-
|
|
11155
|
-
|
|
11156
|
-
|
|
11157
|
-
selectedDesign
|
|
11158
|
-
} = await linkDirectory(session, currentDir);
|
|
11159
|
-
linkedConnection = selectedDesign.connection;
|
|
11160
|
-
console.log(chalk.blue("Continuing with push operation..."));
|
|
11161
|
-
}
|
|
11162
|
-
const updatedMachineCodeAppDirectoryInfo = await readMachineCodeAppDirectoryInfo(currentDir);
|
|
11163
|
-
if (!updatedMachineCodeAppDirectoryInfo) {
|
|
11164
|
-
console.log(chalk.red("Error reading directory metadata after linking."));
|
|
11165
|
-
process.exit(1);
|
|
11166
|
-
}
|
|
11167
|
-
console.log();
|
|
11168
|
-
console.log(chalk.blue(`Pushing changes for project: ${updatedMachineCodeAppDirectoryInfo.appName}`));
|
|
11169
|
-
console.log(chalk.blue(`Design ID: ${updatedMachineCodeAppDirectoryInfo.designId}, App ID: ${updatedMachineCodeAppDirectoryInfo.applicationId}`));
|
|
11170
|
-
const connection = linkedConnection !== null && linkedConnection !== void 0 ? linkedConnection : await resolveConnection(session, updatedMachineCodeAppDirectoryInfo.designId);
|
|
11171
|
-
if (!connection) {
|
|
11172
|
-
console.log();
|
|
11173
|
-
console.error(chalk.red("Sorry, it seems you do not have that design open with the MachineLogic tab selected."));
|
|
11174
|
-
console.error(chalk.red("Please go to your browser, open your design, and navigate to the MachineLogic page."));
|
|
11175
|
-
process.exit(1);
|
|
11176
|
-
}
|
|
11177
|
-
console.log();
|
|
11178
|
-
console.log(chalk.blue("Serializing local files..."));
|
|
11179
|
-
const ignorePatterns = getDefaultIgnorePatterns();
|
|
11180
|
-
const serializedSourceCode = serializeFileSystem(currentDir, ignorePatterns, true);
|
|
11181
|
-
const applicationToPush = {
|
|
11182
|
-
name: updatedMachineCodeAppDirectoryInfo.appName,
|
|
11183
|
-
id: updatedMachineCodeAppDirectoryInfo.applicationId,
|
|
11184
|
-
type: "machine_code",
|
|
11185
|
-
sourceCode: serializedSourceCode,
|
|
11186
|
-
uuid: updatedMachineCodeAppDirectoryInfo.uuid
|
|
11187
|
-
};
|
|
11188
|
-
console.log(chalk.blue("Pushing to digital twin..."));
|
|
11189
|
-
await pushApplicationToDigitalTwin(connection, applicationToPush);
|
|
11190
|
-
await writeMachineCodeAppDirectoryInfo(currentDir, Object.assign(Object.assign({}, updatedMachineCodeAppDirectoryInfo), {
|
|
11191
|
-
lastPushedAt: new Date().toISOString()
|
|
11192
|
-
}));
|
|
11193
|
-
console.log();
|
|
11194
|
-
console.log(chalk.green(`✅ Successfully pushed to digital twin`));
|
|
11195
|
-
console.log(chalk.blue("💡 Your changes have been uploaded!"));
|
|
11196
|
-
} catch (error) {
|
|
11197
|
-
handleCommandError(error, "Failed to push application");
|
|
11288
|
+
var FORCED$1 = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
|
|
11289
|
+
|
|
11290
|
+
var getSortCompare = function (comparefn) {
|
|
11291
|
+
return function (x, y) {
|
|
11292
|
+
if (y === undefined) return -1;
|
|
11293
|
+
if (x === undefined) return 1;
|
|
11294
|
+
if (comparefn !== undefined) return +comparefn(x, y) || 0;
|
|
11295
|
+
var xString = toString$4(x);
|
|
11296
|
+
var yString = toString$4(y);
|
|
11297
|
+
return xString === yString ? 0 : xString > yString ? 1 : -1;
|
|
11298
|
+
};
|
|
11299
|
+
};
|
|
11300
|
+
|
|
11301
|
+
// `Array.prototype.sort` method
|
|
11302
|
+
// https://tc39.es/ecma262/#sec-array.prototype.sort
|
|
11303
|
+
$$7({ target: 'Array', proto: true, forced: FORCED$1 }, {
|
|
11304
|
+
sort: function sort(comparefn) {
|
|
11305
|
+
if (comparefn !== undefined) aCallable$3(comparefn);
|
|
11306
|
+
|
|
11307
|
+
var array = toObject(this);
|
|
11308
|
+
|
|
11309
|
+
if (STABLE_SORT) return comparefn === undefined ? nativeSort(array) : nativeSort(array, comparefn);
|
|
11310
|
+
|
|
11311
|
+
var items = [];
|
|
11312
|
+
var arrayLength = lengthOfArrayLike(array);
|
|
11313
|
+
var itemsLength, index;
|
|
11314
|
+
|
|
11315
|
+
for (index = 0; index < arrayLength; index++) {
|
|
11316
|
+
if (index in array) push(items, array[index]);
|
|
11198
11317
|
}
|
|
11199
|
-
|
|
11318
|
+
|
|
11319
|
+
internalSort(items, getSortCompare(comparefn));
|
|
11320
|
+
|
|
11321
|
+
itemsLength = lengthOfArrayLike(items);
|
|
11322
|
+
index = 0;
|
|
11323
|
+
|
|
11324
|
+
while (index < itemsLength) array[index] = items[index++];
|
|
11325
|
+
while (index < arrayLength) deletePropertyOrThrow(array, index++);
|
|
11326
|
+
|
|
11327
|
+
return array;
|
|
11328
|
+
}
|
|
11329
|
+
});
|
|
11330
|
+
|
|
11331
|
+
// this method was added to unscopables after implementation
|
|
11332
|
+
// in popular engines, so it's moved to a separate module
|
|
11333
|
+
var addToUnscopables = addToUnscopables$3;
|
|
11334
|
+
|
|
11335
|
+
// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
|
|
11336
|
+
addToUnscopables('flatMap');
|
|
11337
|
+
|
|
11338
|
+
var call$2 = functionCall;
|
|
11339
|
+
var anObject$2 = anObject$q;
|
|
11340
|
+
var getIteratorDirect$2 = getIteratorDirect$8;
|
|
11341
|
+
var getIteratorMethod = getIteratorMethod$6;
|
|
11342
|
+
|
|
11343
|
+
var getIteratorFlattenable$1 = function (obj, stringHandling) {
|
|
11344
|
+
if (!stringHandling || typeof obj !== 'string') anObject$2(obj);
|
|
11345
|
+
var method = getIteratorMethod(obj);
|
|
11346
|
+
return getIteratorDirect$2(anObject$2(method !== undefined ? call$2(method, obj) : obj));
|
|
11347
|
+
};
|
|
11348
|
+
|
|
11349
|
+
var $$6 = _export;
|
|
11350
|
+
var call$1 = functionCall;
|
|
11351
|
+
var aCallable$2 = aCallable$l;
|
|
11352
|
+
var anObject$1 = anObject$q;
|
|
11353
|
+
var getIteratorDirect$1 = getIteratorDirect$8;
|
|
11354
|
+
var getIteratorFlattenable = getIteratorFlattenable$1;
|
|
11355
|
+
var createIteratorProxy = iteratorCreateProxy;
|
|
11356
|
+
var iteratorClose$1 = iteratorClose$d;
|
|
11357
|
+
var iteratorHelperThrowsOnInvalidIterator = iteratorHelperThrowsOnInvalidIterator$3;
|
|
11358
|
+
var iteratorHelperWithoutClosingOnEarlyError$1 = iteratorHelperWithoutClosingOnEarlyError$6;
|
|
11359
|
+
|
|
11360
|
+
// Should not throw an error for an iterator without `return` method. Fixed in Safari 26.2
|
|
11361
|
+
// https://bugs.webkit.org/show_bug.cgi?id=297532
|
|
11362
|
+
function throwsOnIteratorWithoutReturn() {
|
|
11363
|
+
try {
|
|
11364
|
+
// eslint-disable-next-line es/no-map, es/no-iterator, es/no-iterator-prototype-flatmap -- required for testing
|
|
11365
|
+
var it = Iterator.prototype.flatMap.call(new Map([[4, 5]]).entries(), function (v) { return v; });
|
|
11366
|
+
it.next();
|
|
11367
|
+
it['return']();
|
|
11368
|
+
} catch (error) {
|
|
11369
|
+
return true;
|
|
11370
|
+
}
|
|
11200
11371
|
}
|
|
11201
11372
|
|
|
11202
|
-
function
|
|
11203
|
-
|
|
11373
|
+
var FLAT_MAP_WITHOUT_THROWING_ON_INVALID_ITERATOR = !iteratorHelperThrowsOnInvalidIterator('flatMap', function () { /* empty */ });
|
|
11374
|
+
var flatMapWithoutClosingOnEarlyError = !FLAT_MAP_WITHOUT_THROWING_ON_INVALID_ITERATOR
|
|
11375
|
+
&& iteratorHelperWithoutClosingOnEarlyError$1('flatMap', TypeError);
|
|
11376
|
+
|
|
11377
|
+
var FORCED = FLAT_MAP_WITHOUT_THROWING_ON_INVALID_ITERATOR || flatMapWithoutClosingOnEarlyError
|
|
11378
|
+
|| throwsOnIteratorWithoutReturn();
|
|
11379
|
+
|
|
11380
|
+
var IteratorProxy = createIteratorProxy(function () {
|
|
11381
|
+
var iterator = this.iterator;
|
|
11382
|
+
var mapper = this.mapper;
|
|
11383
|
+
var result, inner;
|
|
11384
|
+
|
|
11385
|
+
while (true) {
|
|
11386
|
+
if (inner = this.inner) try {
|
|
11387
|
+
result = anObject$1(call$1(inner.next, inner.iterator));
|
|
11388
|
+
if (!result.done) return result.value;
|
|
11389
|
+
this.inner = null;
|
|
11390
|
+
} catch (error) { iteratorClose$1(iterator, 'throw', error); }
|
|
11391
|
+
|
|
11392
|
+
result = anObject$1(call$1(this.next, iterator));
|
|
11393
|
+
|
|
11394
|
+
if (this.done = !!result.done) return;
|
|
11395
|
+
|
|
11204
11396
|
try {
|
|
11205
|
-
|
|
11206
|
-
|
|
11207
|
-
|
|
11208
|
-
|
|
11209
|
-
}
|
|
11210
|
-
const currentDir = process.cwd();
|
|
11211
|
-
const machineCodeAppDirectoryInfo = await readMachineCodeAppDirectoryInfo(currentDir);
|
|
11212
|
-
if (machineCodeAppDirectoryInfo) {
|
|
11213
|
-
console.log(chalk.blue(`This directory is linked to app: ${machineCodeAppDirectoryInfo.appName}`));
|
|
11214
|
-
console.log(chalk.blue(`Pulling latest content from design ID: ${machineCodeAppDirectoryInfo.designId}`));
|
|
11215
|
-
await updateExistingAppDirectory(session, machineCodeAppDirectoryInfo, currentDir);
|
|
11216
|
-
} else {
|
|
11217
|
-
await createNewAppDirectory(session, currentDir);
|
|
11218
|
-
}
|
|
11219
|
-
} catch (error) {
|
|
11220
|
-
handleCommandError(error, "Failed to pull application");
|
|
11221
|
-
}
|
|
11222
|
-
});
|
|
11223
|
-
}
|
|
11397
|
+
this.inner = getIteratorFlattenable(mapper(result.value, this.counter++), false);
|
|
11398
|
+
} catch (error) { iteratorClose$1(iterator, 'throw', error); }
|
|
11399
|
+
}
|
|
11400
|
+
});
|
|
11224
11401
|
|
|
11225
|
-
|
|
11226
|
-
|
|
11402
|
+
// `Iterator.prototype.flatMap` method
|
|
11403
|
+
// https://tc39.es/ecma262/#sec-iterator.prototype.flatmap
|
|
11404
|
+
$$6({ target: 'Iterator', proto: true, real: true, forced: FORCED }, {
|
|
11405
|
+
flatMap: function flatMap(mapper) {
|
|
11406
|
+
anObject$1(this);
|
|
11227
11407
|
try {
|
|
11228
|
-
|
|
11229
|
-
if (!session) {
|
|
11230
|
-
console.error(chalk.red("Not logged in. Please run 'vention login' first."));
|
|
11231
|
-
process.exit(1);
|
|
11232
|
-
}
|
|
11233
|
-
const currentDir = process.cwd();
|
|
11234
|
-
const machineCodeAppDirectoryInfo = await readMachineCodeAppDirectoryInfo(currentDir);
|
|
11235
|
-
if (!machineCodeAppDirectoryInfo) {
|
|
11236
|
-
console.error(chalk.red("This directory is not linked to a Vention application."));
|
|
11237
|
-
console.error(chalk.red("Please run 'vention pull' or 'vention link' first."));
|
|
11238
|
-
process.exit(1);
|
|
11239
|
-
}
|
|
11240
|
-
const connection = await resolveConnection(session, machineCodeAppDirectoryInfo.designId);
|
|
11241
|
-
if (!connection) {
|
|
11242
|
-
console.error(chalk.red("Sorry, it seems you do not have that design open with the MachineLogic tab selected."));
|
|
11243
|
-
console.error(chalk.red("Please go to your browser, open your design, and navigate to the MachineLogic page."));
|
|
11244
|
-
process.exit(1);
|
|
11245
|
-
}
|
|
11246
|
-
const logs = await getApplicationLogs(connection, machineCodeAppDirectoryInfo.applicationId);
|
|
11247
|
-
console.log(logs);
|
|
11408
|
+
aCallable$2(mapper);
|
|
11248
11409
|
} catch (error) {
|
|
11249
|
-
|
|
11410
|
+
iteratorClose$1(this, 'throw', error);
|
|
11250
11411
|
}
|
|
11251
|
-
});
|
|
11252
|
-
}
|
|
11253
11412
|
|
|
11254
|
-
|
|
11255
|
-
var MAX_SAFE_INTEGER = 0x1FFFFFFFFFFFFF; // 2 ** 53 - 1 == 9007199254740991
|
|
11413
|
+
if (flatMapWithoutClosingOnEarlyError) return call$1(flatMapWithoutClosingOnEarlyError, this, mapper);
|
|
11256
11414
|
|
|
11257
|
-
|
|
11258
|
-
|
|
11259
|
-
|
|
11260
|
-
};
|
|
11415
|
+
return new IteratorProxy(getIteratorDirect$1(this), {
|
|
11416
|
+
mapper: mapper,
|
|
11417
|
+
inner: null
|
|
11418
|
+
});
|
|
11419
|
+
}
|
|
11420
|
+
});
|
|
11261
11421
|
|
|
11262
|
-
|
|
11263
|
-
|
|
11264
|
-
var doesNotExceedSafeInteger = doesNotExceedSafeInteger$1;
|
|
11265
|
-
var bind = functionBindContext;
|
|
11266
|
-
var createProperty = createProperty$6;
|
|
11422
|
+
//#region src/generated/core/bodySerializer.gen.ts
|
|
11423
|
+
const jsonBodySerializer = { bodySerializer: (body) => JSON.stringify(body, (_key, value) => typeof value === "bigint" ? value.toString() : value) };
|
|
11267
11424
|
|
|
11268
|
-
|
|
11269
|
-
|
|
11270
|
-
|
|
11271
|
-
|
|
11272
|
-
|
|
11273
|
-
|
|
11274
|
-
|
|
11425
|
+
//#region src/generated/core/pathSerializer.gen.ts
|
|
11426
|
+
const separatorArrayExplode = (style) => {
|
|
11427
|
+
switch (style) {
|
|
11428
|
+
case "label": return ".";
|
|
11429
|
+
case "matrix": return ";";
|
|
11430
|
+
case "simple": return ",";
|
|
11431
|
+
default: return "&";
|
|
11432
|
+
}
|
|
11433
|
+
};
|
|
11434
|
+
const separatorArrayNoExplode = (style) => {
|
|
11435
|
+
switch (style) {
|
|
11436
|
+
case "form": return ",";
|
|
11437
|
+
case "pipeDelimited": return "|";
|
|
11438
|
+
case "spaceDelimited": return "%20";
|
|
11439
|
+
default: return ",";
|
|
11440
|
+
}
|
|
11441
|
+
};
|
|
11442
|
+
const separatorObjectExplode = (style) => {
|
|
11443
|
+
switch (style) {
|
|
11444
|
+
case "label": return ".";
|
|
11445
|
+
case "matrix": return ";";
|
|
11446
|
+
case "simple": return ",";
|
|
11447
|
+
default: return "&";
|
|
11448
|
+
}
|
|
11449
|
+
};
|
|
11450
|
+
const serializeArrayParam = ({ allowReserved, explode, name, style, value }) => {
|
|
11451
|
+
if (!explode) {
|
|
11452
|
+
const joinedValues = (allowReserved ? value : value.map((v) => encodeURIComponent(v))).join(separatorArrayNoExplode(style));
|
|
11453
|
+
switch (style) {
|
|
11454
|
+
case "label": return `.${joinedValues}`;
|
|
11455
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
11456
|
+
case "simple": return joinedValues;
|
|
11457
|
+
default: return `${name}=${joinedValues}`;
|
|
11458
|
+
}
|
|
11459
|
+
}
|
|
11460
|
+
const separator = separatorArrayExplode(style);
|
|
11461
|
+
const joinedValues = value.map((v) => {
|
|
11462
|
+
if (style === "label" || style === "simple") return allowReserved ? v : encodeURIComponent(v);
|
|
11463
|
+
return serializePrimitiveParam({
|
|
11464
|
+
allowReserved,
|
|
11465
|
+
name,
|
|
11466
|
+
value: v
|
|
11467
|
+
});
|
|
11468
|
+
}).join(separator);
|
|
11469
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
11470
|
+
};
|
|
11471
|
+
const serializePrimitiveParam = ({ allowReserved, name, value }) => {
|
|
11472
|
+
if (value === void 0 || value === null) return "";
|
|
11473
|
+
if (typeof value === "object") throw new Error("Deeply-nested arrays/objects aren’t supported. Provide your own `querySerializer()` to handle these.");
|
|
11474
|
+
return `${name}=${allowReserved ? value : encodeURIComponent(value)}`;
|
|
11475
|
+
};
|
|
11476
|
+
const serializeObjectParam = ({ allowReserved, explode, name, style, value, valueOnly }) => {
|
|
11477
|
+
if (value instanceof Date) return valueOnly ? value.toISOString() : `${name}=${value.toISOString()}`;
|
|
11478
|
+
if (style !== "deepObject" && !explode) {
|
|
11479
|
+
let values = [];
|
|
11480
|
+
Object.entries(value).forEach(([key, v]) => {
|
|
11481
|
+
values = [
|
|
11482
|
+
...values,
|
|
11483
|
+
key,
|
|
11484
|
+
allowReserved ? v : encodeURIComponent(v)
|
|
11485
|
+
];
|
|
11486
|
+
});
|
|
11487
|
+
const joinedValues = values.join(",");
|
|
11488
|
+
switch (style) {
|
|
11489
|
+
case "form": return `${name}=${joinedValues}`;
|
|
11490
|
+
case "label": return `.${joinedValues}`;
|
|
11491
|
+
case "matrix": return `;${name}=${joinedValues}`;
|
|
11492
|
+
default: return joinedValues;
|
|
11493
|
+
}
|
|
11494
|
+
}
|
|
11495
|
+
const separator = separatorObjectExplode(style);
|
|
11496
|
+
const joinedValues = Object.entries(value).map(([key, v]) => serializePrimitiveParam({
|
|
11497
|
+
allowReserved,
|
|
11498
|
+
name: style === "deepObject" ? `${name}[${key}]` : key,
|
|
11499
|
+
value: v
|
|
11500
|
+
})).join(separator);
|
|
11501
|
+
return style === "label" || style === "matrix" ? separator + joinedValues : joinedValues;
|
|
11502
|
+
};
|
|
11503
|
+
|
|
11504
|
+
//#region src/generated/core/utils.gen.ts
|
|
11505
|
+
const PATH_PARAM_RE = /\{[^{}]+\}/g;
|
|
11506
|
+
const defaultPathSerializer = ({ path, url: _url }) => {
|
|
11507
|
+
let url = _url;
|
|
11508
|
+
const matches = _url.match(PATH_PARAM_RE);
|
|
11509
|
+
if (matches) for (const match of matches) {
|
|
11510
|
+
let explode = false;
|
|
11511
|
+
let name = match.substring(1, match.length - 1);
|
|
11512
|
+
let style = "simple";
|
|
11513
|
+
if (name.endsWith("*")) {
|
|
11514
|
+
explode = true;
|
|
11515
|
+
name = name.substring(0, name.length - 1);
|
|
11516
|
+
}
|
|
11517
|
+
if (name.startsWith(".")) {
|
|
11518
|
+
name = name.substring(1);
|
|
11519
|
+
style = "label";
|
|
11520
|
+
} else if (name.startsWith(";")) {
|
|
11521
|
+
name = name.substring(1);
|
|
11522
|
+
style = "matrix";
|
|
11523
|
+
}
|
|
11524
|
+
const value = path[name];
|
|
11525
|
+
if (value === void 0 || value === null) continue;
|
|
11526
|
+
if (Array.isArray(value)) {
|
|
11527
|
+
url = url.replace(match, serializeArrayParam({
|
|
11528
|
+
explode,
|
|
11529
|
+
name,
|
|
11530
|
+
style,
|
|
11531
|
+
value
|
|
11532
|
+
}));
|
|
11533
|
+
continue;
|
|
11534
|
+
}
|
|
11535
|
+
if (typeof value === "object") {
|
|
11536
|
+
url = url.replace(match, serializeObjectParam({
|
|
11537
|
+
explode,
|
|
11538
|
+
name,
|
|
11539
|
+
style,
|
|
11540
|
+
value,
|
|
11541
|
+
valueOnly: true
|
|
11542
|
+
}));
|
|
11543
|
+
continue;
|
|
11544
|
+
}
|
|
11545
|
+
if (style === "matrix") {
|
|
11546
|
+
url = url.replace(match, `;${serializePrimitiveParam({
|
|
11547
|
+
name,
|
|
11548
|
+
value
|
|
11549
|
+
})}`);
|
|
11550
|
+
continue;
|
|
11551
|
+
}
|
|
11552
|
+
const replaceValue = encodeURIComponent(style === "label" ? `.${value}` : value);
|
|
11553
|
+
url = url.replace(match, replaceValue);
|
|
11554
|
+
}
|
|
11555
|
+
return url;
|
|
11556
|
+
};
|
|
11557
|
+
const getUrl = ({ baseUrl, path, query, querySerializer, url: _url }) => {
|
|
11558
|
+
const pathUrl = _url.startsWith("/") ? _url : `/${_url}`;
|
|
11559
|
+
let url = (baseUrl ?? "") + pathUrl;
|
|
11560
|
+
if (path) url = defaultPathSerializer({
|
|
11561
|
+
path,
|
|
11562
|
+
url
|
|
11563
|
+
});
|
|
11564
|
+
let search = query ? querySerializer(query) : "";
|
|
11565
|
+
if (search.startsWith("?")) search = search.substring(1);
|
|
11566
|
+
if (search) url += `?${search}`;
|
|
11567
|
+
return url;
|
|
11568
|
+
};
|
|
11569
|
+
function getValidRequestBody(options) {
|
|
11570
|
+
const hasBody = options.body !== void 0;
|
|
11571
|
+
if (hasBody && options.bodySerializer) {
|
|
11572
|
+
if ("serializedBody" in options) return options.serializedBody !== void 0 && options.serializedBody !== "" ? options.serializedBody : null;
|
|
11573
|
+
return options.body !== "" ? options.body : null;
|
|
11574
|
+
}
|
|
11575
|
+
if (hasBody) return options.body;
|
|
11576
|
+
}
|
|
11275
11577
|
|
|
11276
|
-
|
|
11277
|
-
|
|
11278
|
-
|
|
11578
|
+
//#region src/generated/core/auth.gen.ts
|
|
11579
|
+
const getAuthToken = async (auth, callback) => {
|
|
11580
|
+
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
11581
|
+
if (!token) return;
|
|
11582
|
+
if (auth.scheme === "bearer") return `Bearer ${token}`;
|
|
11583
|
+
if (auth.scheme === "basic") return `Basic ${btoa(token)}`;
|
|
11584
|
+
return token;
|
|
11585
|
+
};
|
|
11586
|
+
|
|
11587
|
+
//#region src/generated/client/utils.gen.ts
|
|
11588
|
+
const createQuerySerializer = ({ parameters = {}, ...args } = {}) => {
|
|
11589
|
+
const querySerializer = (queryParams) => {
|
|
11590
|
+
const search = [];
|
|
11591
|
+
if (queryParams && typeof queryParams === "object") for (const name in queryParams) {
|
|
11592
|
+
const value = queryParams[name];
|
|
11593
|
+
if (value === void 0 || value === null) continue;
|
|
11594
|
+
const options = parameters[name] || args;
|
|
11595
|
+
if (Array.isArray(value)) {
|
|
11596
|
+
const serializedArray = serializeArrayParam({
|
|
11597
|
+
allowReserved: options.allowReserved,
|
|
11598
|
+
explode: true,
|
|
11599
|
+
name,
|
|
11600
|
+
style: "form",
|
|
11601
|
+
value,
|
|
11602
|
+
...options.array
|
|
11603
|
+
});
|
|
11604
|
+
if (serializedArray) search.push(serializedArray);
|
|
11605
|
+
} else if (typeof value === "object") {
|
|
11606
|
+
const serializedObject = serializeObjectParam({
|
|
11607
|
+
allowReserved: options.allowReserved,
|
|
11608
|
+
explode: true,
|
|
11609
|
+
name,
|
|
11610
|
+
style: "deepObject",
|
|
11611
|
+
value,
|
|
11612
|
+
...options.object
|
|
11613
|
+
});
|
|
11614
|
+
if (serializedObject) search.push(serializedObject);
|
|
11615
|
+
} else {
|
|
11616
|
+
const serializedPrimitive = serializePrimitiveParam({
|
|
11617
|
+
allowReserved: options.allowReserved,
|
|
11618
|
+
name,
|
|
11619
|
+
value
|
|
11620
|
+
});
|
|
11621
|
+
if (serializedPrimitive) search.push(serializedPrimitive);
|
|
11622
|
+
}
|
|
11623
|
+
}
|
|
11624
|
+
return search.join("&");
|
|
11625
|
+
};
|
|
11626
|
+
return querySerializer;
|
|
11627
|
+
};
|
|
11628
|
+
/**
|
|
11629
|
+
* Infers parseAs value from provided Content-Type header.
|
|
11630
|
+
*/
|
|
11631
|
+
const getParseAs = (contentType) => {
|
|
11632
|
+
if (!contentType) return "stream";
|
|
11633
|
+
const cleanContent = contentType.split(";")[0]?.trim();
|
|
11634
|
+
if (!cleanContent) return;
|
|
11635
|
+
if (cleanContent.startsWith("application/json") || cleanContent.endsWith("+json")) return "json";
|
|
11636
|
+
if (cleanContent === "multipart/form-data") return "formData";
|
|
11637
|
+
if ([
|
|
11638
|
+
"application/",
|
|
11639
|
+
"audio/",
|
|
11640
|
+
"image/",
|
|
11641
|
+
"video/"
|
|
11642
|
+
].some((type) => cleanContent.startsWith(type))) return "blob";
|
|
11643
|
+
if (cleanContent.startsWith("text/")) return "text";
|
|
11644
|
+
};
|
|
11645
|
+
const checkForExistence = (options, name) => {
|
|
11646
|
+
if (!name) return false;
|
|
11647
|
+
if (options.headers.has(name) || options.query?.[name] || options.headers.get("Cookie")?.includes(`${name}=`)) return true;
|
|
11648
|
+
return false;
|
|
11649
|
+
};
|
|
11650
|
+
async function setAuthParams(options) {
|
|
11651
|
+
for (const auth of options.security ?? []) {
|
|
11652
|
+
if (checkForExistence(options, auth.name)) continue;
|
|
11653
|
+
const token = await getAuthToken(auth, options.auth);
|
|
11654
|
+
if (!token) continue;
|
|
11655
|
+
const name = auth.name ?? "Authorization";
|
|
11656
|
+
switch (auth.in) {
|
|
11657
|
+
case "query":
|
|
11658
|
+
if (!options.query) options.query = {};
|
|
11659
|
+
options.query[name] = token;
|
|
11660
|
+
break;
|
|
11661
|
+
case "cookie":
|
|
11662
|
+
options.headers.append("Cookie", `${name}=${token}`);
|
|
11663
|
+
break;
|
|
11664
|
+
default: options.headers.set(name, token);
|
|
11665
|
+
}
|
|
11666
|
+
}
|
|
11667
|
+
}
|
|
11668
|
+
const buildUrl = (options) => getUrl({
|
|
11669
|
+
baseUrl: options.baseUrl,
|
|
11670
|
+
path: options.path,
|
|
11671
|
+
query: options.query,
|
|
11672
|
+
querySerializer: typeof options.querySerializer === "function" ? options.querySerializer : createQuerySerializer(options.querySerializer),
|
|
11673
|
+
url: options.url
|
|
11674
|
+
});
|
|
11675
|
+
const mergeConfigs = (a, b) => {
|
|
11676
|
+
const config = {
|
|
11677
|
+
...a,
|
|
11678
|
+
...b
|
|
11679
|
+
};
|
|
11680
|
+
if (config.baseUrl?.endsWith("/")) config.baseUrl = config.baseUrl.substring(0, config.baseUrl.length - 1);
|
|
11681
|
+
config.headers = mergeHeaders(a.headers, b.headers);
|
|
11682
|
+
return config;
|
|
11683
|
+
};
|
|
11684
|
+
const headersEntries = (headers) => {
|
|
11685
|
+
const entries = [];
|
|
11686
|
+
headers.forEach((value, key) => {
|
|
11687
|
+
entries.push([key, value]);
|
|
11688
|
+
});
|
|
11689
|
+
return entries;
|
|
11690
|
+
};
|
|
11691
|
+
const mergeHeaders = (...headers) => {
|
|
11692
|
+
const mergedHeaders = new Headers();
|
|
11693
|
+
for (const header of headers) {
|
|
11694
|
+
if (!header) continue;
|
|
11695
|
+
const iterator = header instanceof Headers ? headersEntries(header) : Object.entries(header);
|
|
11696
|
+
for (const [key, value] of iterator) if (value === null) mergedHeaders.delete(key);
|
|
11697
|
+
else if (Array.isArray(value)) for (const v of value) mergedHeaders.append(key, v);
|
|
11698
|
+
else if (value !== void 0) mergedHeaders.set(key, typeof value === "object" ? JSON.stringify(value) : value);
|
|
11699
|
+
}
|
|
11700
|
+
return mergedHeaders;
|
|
11701
|
+
};
|
|
11702
|
+
var Interceptors = class {
|
|
11703
|
+
fns = [];
|
|
11704
|
+
clear() {
|
|
11705
|
+
this.fns = [];
|
|
11706
|
+
}
|
|
11707
|
+
eject(id) {
|
|
11708
|
+
const index = this.getInterceptorIndex(id);
|
|
11709
|
+
if (this.fns[index]) this.fns[index] = null;
|
|
11710
|
+
}
|
|
11711
|
+
exists(id) {
|
|
11712
|
+
const index = this.getInterceptorIndex(id);
|
|
11713
|
+
return Boolean(this.fns[index]);
|
|
11714
|
+
}
|
|
11715
|
+
getInterceptorIndex(id) {
|
|
11716
|
+
if (typeof id === "number") return this.fns[id] ? id : -1;
|
|
11717
|
+
return this.fns.indexOf(id);
|
|
11718
|
+
}
|
|
11719
|
+
update(id, fn) {
|
|
11720
|
+
const index = this.getInterceptorIndex(id);
|
|
11721
|
+
if (this.fns[index]) {
|
|
11722
|
+
this.fns[index] = fn;
|
|
11723
|
+
return id;
|
|
11724
|
+
}
|
|
11725
|
+
return false;
|
|
11726
|
+
}
|
|
11727
|
+
use(fn) {
|
|
11728
|
+
this.fns.push(fn);
|
|
11729
|
+
return this.fns.length - 1;
|
|
11730
|
+
}
|
|
11731
|
+
};
|
|
11732
|
+
const createInterceptors = () => ({
|
|
11733
|
+
error: new Interceptors(),
|
|
11734
|
+
request: new Interceptors(),
|
|
11735
|
+
response: new Interceptors()
|
|
11736
|
+
});
|
|
11737
|
+
const defaultQuerySerializer = createQuerySerializer({
|
|
11738
|
+
allowReserved: false,
|
|
11739
|
+
array: {
|
|
11740
|
+
explode: true,
|
|
11741
|
+
style: "form"
|
|
11742
|
+
},
|
|
11743
|
+
object: {
|
|
11744
|
+
explode: true,
|
|
11745
|
+
style: "deepObject"
|
|
11746
|
+
}
|
|
11747
|
+
});
|
|
11748
|
+
const defaultHeaders = { "Content-Type": "application/json" };
|
|
11749
|
+
const createConfig = (override = {}) => ({
|
|
11750
|
+
...jsonBodySerializer,
|
|
11751
|
+
headers: defaultHeaders,
|
|
11752
|
+
parseAs: "auto",
|
|
11753
|
+
querySerializer: defaultQuerySerializer,
|
|
11754
|
+
...override
|
|
11755
|
+
});
|
|
11756
|
+
|
|
11757
|
+
//#region src/generated/core/serverSentEvents.gen.ts
|
|
11758
|
+
function createSseClient({ onRequest, onSseError, onSseEvent, responseTransformer, responseValidator, sseDefaultRetryDelay, sseMaxRetryAttempts, sseMaxRetryDelay, sseSleepFn, url, ...options }) {
|
|
11759
|
+
let lastEventId;
|
|
11760
|
+
const sleep = sseSleepFn ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
11761
|
+
const createStream = async function* () {
|
|
11762
|
+
let retryDelay = sseDefaultRetryDelay ?? 3e3;
|
|
11763
|
+
let attempt = 0;
|
|
11764
|
+
const signal = options.signal ?? new AbortController().signal;
|
|
11765
|
+
while (true) {
|
|
11766
|
+
if (signal.aborted) break;
|
|
11767
|
+
attempt++;
|
|
11768
|
+
const headers = options.headers instanceof Headers ? options.headers : new Headers(options.headers);
|
|
11769
|
+
if (lastEventId !== void 0) headers.set("Last-Event-ID", lastEventId);
|
|
11770
|
+
try {
|
|
11771
|
+
const requestInit = {
|
|
11772
|
+
redirect: "follow",
|
|
11773
|
+
...options,
|
|
11774
|
+
body: options.serializedBody,
|
|
11775
|
+
headers,
|
|
11776
|
+
signal
|
|
11777
|
+
};
|
|
11778
|
+
let request = new Request(url, requestInit);
|
|
11779
|
+
if (onRequest) request = await onRequest(url, requestInit);
|
|
11780
|
+
const response = await (options.fetch ?? globalThis.fetch)(request);
|
|
11781
|
+
if (!response.ok) throw new Error(`SSE failed: ${response.status} ${response.statusText}`);
|
|
11782
|
+
if (!response.body) throw new Error("No body in SSE response");
|
|
11783
|
+
const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
|
|
11784
|
+
let buffer = "";
|
|
11785
|
+
const abortHandler = () => {
|
|
11786
|
+
try {
|
|
11787
|
+
reader.cancel();
|
|
11788
|
+
} catch {}
|
|
11789
|
+
};
|
|
11790
|
+
signal.addEventListener("abort", abortHandler);
|
|
11791
|
+
try {
|
|
11792
|
+
while (true) {
|
|
11793
|
+
const { done, value } = await reader.read();
|
|
11794
|
+
if (done) break;
|
|
11795
|
+
buffer += value;
|
|
11796
|
+
buffer = buffer.replace(/\r\n?/g, "\n");
|
|
11797
|
+
const chunks = buffer.split("\n\n");
|
|
11798
|
+
buffer = chunks.pop() ?? "";
|
|
11799
|
+
for (const chunk of chunks) {
|
|
11800
|
+
const lines = chunk.split("\n");
|
|
11801
|
+
const dataLines = [];
|
|
11802
|
+
let eventName;
|
|
11803
|
+
for (const line of lines) if (line.startsWith("data:")) dataLines.push(line.replace(/^data:\s*/, ""));
|
|
11804
|
+
else if (line.startsWith("event:")) eventName = line.replace(/^event:\s*/, "");
|
|
11805
|
+
else if (line.startsWith("id:")) lastEventId = line.replace(/^id:\s*/, "");
|
|
11806
|
+
else if (line.startsWith("retry:")) {
|
|
11807
|
+
const parsed = Number.parseInt(line.replace(/^retry:\s*/, ""), 10);
|
|
11808
|
+
if (!Number.isNaN(parsed)) retryDelay = parsed;
|
|
11809
|
+
}
|
|
11810
|
+
let data;
|
|
11811
|
+
let parsedJson = false;
|
|
11812
|
+
if (dataLines.length) {
|
|
11813
|
+
const rawData = dataLines.join("\n");
|
|
11814
|
+
try {
|
|
11815
|
+
data = JSON.parse(rawData);
|
|
11816
|
+
parsedJson = true;
|
|
11817
|
+
} catch {
|
|
11818
|
+
data = rawData;
|
|
11819
|
+
}
|
|
11820
|
+
}
|
|
11821
|
+
if (parsedJson) {
|
|
11822
|
+
if (responseValidator) await responseValidator(data);
|
|
11823
|
+
if (responseTransformer) data = await responseTransformer(data);
|
|
11824
|
+
}
|
|
11825
|
+
onSseEvent?.({
|
|
11826
|
+
data,
|
|
11827
|
+
event: eventName,
|
|
11828
|
+
id: lastEventId,
|
|
11829
|
+
retry: retryDelay
|
|
11830
|
+
});
|
|
11831
|
+
if (dataLines.length) yield data;
|
|
11832
|
+
}
|
|
11833
|
+
}
|
|
11834
|
+
} finally {
|
|
11835
|
+
signal.removeEventListener("abort", abortHandler);
|
|
11836
|
+
reader.releaseLock();
|
|
11837
|
+
}
|
|
11838
|
+
break;
|
|
11839
|
+
} catch (error) {
|
|
11840
|
+
onSseError?.(error);
|
|
11841
|
+
if (sseMaxRetryAttempts !== void 0 && attempt >= sseMaxRetryAttempts) break;
|
|
11842
|
+
const backoff = Math.min(retryDelay * 2 ** (attempt - 1), sseMaxRetryDelay ?? 3e4);
|
|
11843
|
+
await sleep(backoff);
|
|
11844
|
+
}
|
|
11845
|
+
}
|
|
11846
|
+
};
|
|
11847
|
+
return { stream: createStream() };
|
|
11848
|
+
}
|
|
11279
11849
|
|
|
11280
|
-
|
|
11281
|
-
|
|
11282
|
-
|
|
11283
|
-
|
|
11284
|
-
|
|
11285
|
-
|
|
11286
|
-
|
|
11850
|
+
//#region src/generated/client/client.gen.ts
|
|
11851
|
+
const createClient$1 = (config = {}) => {
|
|
11852
|
+
let _config = mergeConfigs(createConfig(), config);
|
|
11853
|
+
const getConfig = () => ({ ..._config });
|
|
11854
|
+
const setConfig = (config) => {
|
|
11855
|
+
_config = mergeConfigs(_config, config);
|
|
11856
|
+
return getConfig();
|
|
11857
|
+
};
|
|
11858
|
+
const interceptors = createInterceptors();
|
|
11859
|
+
const beforeRequest = async (options) => {
|
|
11860
|
+
const opts = {
|
|
11861
|
+
..._config,
|
|
11862
|
+
...options,
|
|
11863
|
+
fetch: options.fetch ?? _config.fetch ?? globalThis.fetch,
|
|
11864
|
+
headers: mergeHeaders(_config.headers, options.headers),
|
|
11865
|
+
serializedBody: void 0
|
|
11866
|
+
};
|
|
11867
|
+
if (opts.security) await setAuthParams(opts);
|
|
11868
|
+
if (opts.requestValidator) await opts.requestValidator(opts);
|
|
11869
|
+
if (opts.body !== void 0 && opts.bodySerializer) opts.serializedBody = opts.bodySerializer(opts.body);
|
|
11870
|
+
if (opts.body === void 0 || opts.serializedBody === "") opts.headers.delete("Content-Type");
|
|
11871
|
+
const resolvedOpts = opts;
|
|
11872
|
+
return {
|
|
11873
|
+
opts: resolvedOpts,
|
|
11874
|
+
url: buildUrl(resolvedOpts)
|
|
11875
|
+
};
|
|
11876
|
+
};
|
|
11877
|
+
const request = async (options) => {
|
|
11878
|
+
const throwOnError = options.throwOnError ?? _config.throwOnError;
|
|
11879
|
+
const responseStyle = options.responseStyle ?? _config.responseStyle;
|
|
11880
|
+
let request;
|
|
11881
|
+
let response;
|
|
11882
|
+
try {
|
|
11883
|
+
const { opts, url } = await beforeRequest(options);
|
|
11884
|
+
const requestInit = {
|
|
11885
|
+
redirect: "follow",
|
|
11886
|
+
...opts,
|
|
11887
|
+
body: getValidRequestBody(opts)
|
|
11888
|
+
};
|
|
11889
|
+
request = new Request(url, requestInit);
|
|
11890
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
11891
|
+
const _fetch = opts.fetch;
|
|
11892
|
+
response = await _fetch(request);
|
|
11893
|
+
for (const fn of interceptors.response.fns) if (fn) response = await fn(response, request, opts);
|
|
11894
|
+
const result = {
|
|
11895
|
+
request,
|
|
11896
|
+
response
|
|
11897
|
+
};
|
|
11898
|
+
if (response.ok) {
|
|
11899
|
+
const parseAs = (opts.parseAs === "auto" ? getParseAs(response.headers.get("Content-Type")) : opts.parseAs) ?? "json";
|
|
11900
|
+
if (response.status === 204 || response.headers.get("Content-Length") === "0") {
|
|
11901
|
+
let emptyData;
|
|
11902
|
+
switch (parseAs) {
|
|
11903
|
+
case "arrayBuffer":
|
|
11904
|
+
case "blob":
|
|
11905
|
+
case "text":
|
|
11906
|
+
emptyData = await response[parseAs]();
|
|
11907
|
+
break;
|
|
11908
|
+
case "formData":
|
|
11909
|
+
emptyData = new FormData();
|
|
11910
|
+
break;
|
|
11911
|
+
case "stream":
|
|
11912
|
+
emptyData = response.body;
|
|
11913
|
+
break;
|
|
11914
|
+
default: emptyData = {};
|
|
11915
|
+
}
|
|
11916
|
+
return opts.responseStyle === "data" ? emptyData : {
|
|
11917
|
+
data: emptyData,
|
|
11918
|
+
...result
|
|
11919
|
+
};
|
|
11920
|
+
}
|
|
11921
|
+
let data;
|
|
11922
|
+
switch (parseAs) {
|
|
11923
|
+
case "arrayBuffer":
|
|
11924
|
+
case "blob":
|
|
11925
|
+
case "formData":
|
|
11926
|
+
case "text":
|
|
11927
|
+
data = await response[parseAs]();
|
|
11928
|
+
break;
|
|
11929
|
+
case "json": {
|
|
11930
|
+
const text = await response.text();
|
|
11931
|
+
data = text ? JSON.parse(text) : {};
|
|
11932
|
+
break;
|
|
11933
|
+
}
|
|
11934
|
+
case "stream": return opts.responseStyle === "data" ? response.body : {
|
|
11935
|
+
data: response.body,
|
|
11936
|
+
...result
|
|
11937
|
+
};
|
|
11938
|
+
}
|
|
11939
|
+
if (parseAs === "json") {
|
|
11940
|
+
if (opts.responseValidator) await opts.responseValidator(data);
|
|
11941
|
+
if (opts.responseTransformer) data = await opts.responseTransformer(data);
|
|
11942
|
+
}
|
|
11943
|
+
return opts.responseStyle === "data" ? data : {
|
|
11944
|
+
data,
|
|
11945
|
+
...result
|
|
11946
|
+
};
|
|
11947
|
+
}
|
|
11948
|
+
const textError = await response.text();
|
|
11949
|
+
let jsonError;
|
|
11950
|
+
try {
|
|
11951
|
+
jsonError = JSON.parse(textError);
|
|
11952
|
+
} catch {}
|
|
11953
|
+
throw jsonError ?? textError;
|
|
11954
|
+
} catch (error) {
|
|
11955
|
+
let finalError = error;
|
|
11956
|
+
for (const fn of interceptors.error.fns) if (fn) finalError = await fn(finalError, response, request, options);
|
|
11957
|
+
finalError = finalError || {};
|
|
11958
|
+
if (throwOnError) throw finalError;
|
|
11959
|
+
return responseStyle === "data" ? void 0 : {
|
|
11960
|
+
error: finalError,
|
|
11961
|
+
request,
|
|
11962
|
+
response
|
|
11963
|
+
};
|
|
11964
|
+
}
|
|
11965
|
+
};
|
|
11966
|
+
const makeMethodFn = (method) => (options) => request({
|
|
11967
|
+
...options,
|
|
11968
|
+
method
|
|
11969
|
+
});
|
|
11970
|
+
const makeSseFn = (method) => async (options) => {
|
|
11971
|
+
const { opts, url } = await beforeRequest(options);
|
|
11972
|
+
return createSseClient({
|
|
11973
|
+
...opts,
|
|
11974
|
+
body: opts.body,
|
|
11975
|
+
method,
|
|
11976
|
+
onRequest: async (url, init) => {
|
|
11977
|
+
let request = new Request(url, init);
|
|
11978
|
+
for (const fn of interceptors.request.fns) if (fn) request = await fn(request, opts);
|
|
11979
|
+
return request;
|
|
11980
|
+
},
|
|
11981
|
+
serializedBody: getValidRequestBody(opts),
|
|
11982
|
+
url
|
|
11983
|
+
});
|
|
11984
|
+
};
|
|
11985
|
+
const _buildUrl = (options) => buildUrl({
|
|
11986
|
+
..._config,
|
|
11987
|
+
...options
|
|
11988
|
+
});
|
|
11989
|
+
return {
|
|
11990
|
+
buildUrl: _buildUrl,
|
|
11991
|
+
connect: makeMethodFn("CONNECT"),
|
|
11992
|
+
delete: makeMethodFn("DELETE"),
|
|
11993
|
+
get: makeMethodFn("GET"),
|
|
11994
|
+
getConfig,
|
|
11995
|
+
head: makeMethodFn("HEAD"),
|
|
11996
|
+
interceptors,
|
|
11997
|
+
options: makeMethodFn("OPTIONS"),
|
|
11998
|
+
patch: makeMethodFn("PATCH"),
|
|
11999
|
+
post: makeMethodFn("POST"),
|
|
12000
|
+
put: makeMethodFn("PUT"),
|
|
12001
|
+
request,
|
|
12002
|
+
setConfig,
|
|
12003
|
+
sse: {
|
|
12004
|
+
connect: makeSseFn("CONNECT"),
|
|
12005
|
+
delete: makeSseFn("DELETE"),
|
|
12006
|
+
get: makeSseFn("GET"),
|
|
12007
|
+
head: makeSseFn("HEAD"),
|
|
12008
|
+
options: makeSseFn("OPTIONS"),
|
|
12009
|
+
patch: makeSseFn("PATCH"),
|
|
12010
|
+
post: makeSseFn("POST"),
|
|
12011
|
+
put: makeSseFn("PUT"),
|
|
12012
|
+
trace: makeSseFn("TRACE")
|
|
12013
|
+
},
|
|
12014
|
+
trace: makeMethodFn("TRACE")
|
|
12015
|
+
};
|
|
12016
|
+
};
|
|
12017
|
+
|
|
12018
|
+
//#region src/generated/sdk.gen.ts
|
|
12019
|
+
var HeyApiClient = class {
|
|
12020
|
+
client;
|
|
12021
|
+
constructor(args) {
|
|
12022
|
+
this.client = args.client;
|
|
12023
|
+
}
|
|
12024
|
+
};
|
|
12025
|
+
var HeyApiRegistry = class {
|
|
12026
|
+
defaultKey = "default";
|
|
12027
|
+
instances = /* @__PURE__ */ new Map();
|
|
12028
|
+
get(key) {
|
|
12029
|
+
const instance = this.instances.get(key ?? this.defaultKey);
|
|
12030
|
+
if (!instance) throw new Error(`No SDK client found. Create one with "new DigitalTwinApi()" to fix this error.`);
|
|
12031
|
+
return instance;
|
|
12032
|
+
}
|
|
12033
|
+
set(value, key) {
|
|
12034
|
+
this.instances.set(key ?? this.defaultKey, value);
|
|
12035
|
+
}
|
|
12036
|
+
};
|
|
12037
|
+
var DigitalTwinApi = class DigitalTwinApi extends HeyApiClient {
|
|
12038
|
+
static __registry = new HeyApiRegistry();
|
|
12039
|
+
constructor(args) {
|
|
12040
|
+
super(args);
|
|
12041
|
+
DigitalTwinApi.__registry.set(this, args.key);
|
|
12042
|
+
}
|
|
12043
|
+
/**
|
|
12044
|
+
* List the caller's digital twin instances
|
|
12045
|
+
*/
|
|
12046
|
+
listInstances(options) {
|
|
12047
|
+
return (options?.client ?? this.client).get({
|
|
12048
|
+
security: [{
|
|
12049
|
+
in: "cookie",
|
|
12050
|
+
name: "__Host-vention_auth",
|
|
12051
|
+
type: "apiKey"
|
|
12052
|
+
}, {
|
|
12053
|
+
scheme: "bearer",
|
|
12054
|
+
type: "http"
|
|
12055
|
+
}],
|
|
12056
|
+
url: "/api/instances",
|
|
12057
|
+
...options
|
|
12058
|
+
});
|
|
12059
|
+
}
|
|
12060
|
+
/**
|
|
12061
|
+
* Allocate a digital twin instance
|
|
12062
|
+
*/
|
|
12063
|
+
allocate(options) {
|
|
12064
|
+
return (options.client ?? this.client).post({
|
|
12065
|
+
security: [{
|
|
12066
|
+
in: "cookie",
|
|
12067
|
+
name: "__Host-vention_auth",
|
|
12068
|
+
type: "apiKey"
|
|
12069
|
+
}, {
|
|
12070
|
+
scheme: "bearer",
|
|
12071
|
+
type: "http"
|
|
12072
|
+
}],
|
|
12073
|
+
url: "/api/instances",
|
|
12074
|
+
...options,
|
|
12075
|
+
headers: {
|
|
12076
|
+
"Content-Type": "application/json",
|
|
12077
|
+
...options.headers
|
|
12078
|
+
}
|
|
12079
|
+
});
|
|
12080
|
+
}
|
|
12081
|
+
/**
|
|
12082
|
+
* Deallocate a digital twin instance
|
|
12083
|
+
*/
|
|
12084
|
+
deallocate(options) {
|
|
12085
|
+
return (options.client ?? this.client).delete({
|
|
12086
|
+
security: [{
|
|
12087
|
+
in: "cookie",
|
|
12088
|
+
name: "__Host-vention_auth",
|
|
12089
|
+
type: "apiKey"
|
|
12090
|
+
}, {
|
|
12091
|
+
scheme: "bearer",
|
|
12092
|
+
type: "http"
|
|
12093
|
+
}],
|
|
12094
|
+
url: "/api/instances/{instanceId}",
|
|
12095
|
+
...options
|
|
12096
|
+
});
|
|
12097
|
+
}
|
|
12098
|
+
/**
|
|
12099
|
+
* Get a single digital twin instance
|
|
12100
|
+
*/
|
|
12101
|
+
getInstance(options) {
|
|
12102
|
+
return (options.client ?? this.client).get({
|
|
12103
|
+
security: [{
|
|
12104
|
+
in: "cookie",
|
|
12105
|
+
name: "__Host-vention_auth",
|
|
12106
|
+
type: "apiKey"
|
|
12107
|
+
}, {
|
|
12108
|
+
scheme: "bearer",
|
|
12109
|
+
type: "http"
|
|
12110
|
+
}],
|
|
12111
|
+
url: "/api/instances/{instanceId}",
|
|
12112
|
+
...options
|
|
12113
|
+
});
|
|
12114
|
+
}
|
|
12115
|
+
/**
|
|
12116
|
+
* List the releases available to instantiate
|
|
12117
|
+
*/
|
|
12118
|
+
listReleases(options) {
|
|
12119
|
+
return (options?.client ?? this.client).get({
|
|
12120
|
+
security: [{
|
|
12121
|
+
in: "cookie",
|
|
12122
|
+
name: "__Host-vention_auth",
|
|
12123
|
+
type: "apiKey"
|
|
12124
|
+
}, {
|
|
12125
|
+
scheme: "bearer",
|
|
12126
|
+
type: "http"
|
|
12127
|
+
}],
|
|
12128
|
+
url: "/api/releases",
|
|
12129
|
+
...options
|
|
12130
|
+
});
|
|
12131
|
+
}
|
|
12132
|
+
/**
|
|
12133
|
+
* Get a release and the container images it ships
|
|
12134
|
+
*/
|
|
12135
|
+
getRelease(options) {
|
|
12136
|
+
return (options.client ?? this.client).get({
|
|
12137
|
+
security: [{
|
|
12138
|
+
in: "cookie",
|
|
12139
|
+
name: "__Host-vention_auth",
|
|
12140
|
+
type: "apiKey"
|
|
12141
|
+
}, {
|
|
12142
|
+
scheme: "bearer",
|
|
12143
|
+
type: "http"
|
|
12144
|
+
}],
|
|
12145
|
+
url: "/api/releases/{release}",
|
|
12146
|
+
...options
|
|
12147
|
+
});
|
|
12148
|
+
}
|
|
12149
|
+
/**
|
|
12150
|
+
* List the release channels available to instantiate from
|
|
12151
|
+
*/
|
|
12152
|
+
listChannels(options) {
|
|
12153
|
+
return (options?.client ?? this.client).get({
|
|
12154
|
+
security: [{
|
|
12155
|
+
in: "cookie",
|
|
12156
|
+
name: "__Host-vention_auth",
|
|
12157
|
+
type: "apiKey"
|
|
12158
|
+
}, {
|
|
12159
|
+
scheme: "bearer",
|
|
12160
|
+
type: "http"
|
|
12161
|
+
}],
|
|
12162
|
+
url: "/api/channels",
|
|
12163
|
+
...options
|
|
12164
|
+
});
|
|
12165
|
+
}
|
|
12166
|
+
};
|
|
11287
12167
|
|
|
11288
|
-
|
|
11289
|
-
|
|
11290
|
-
|
|
11291
|
-
|
|
11292
|
-
|
|
12168
|
+
//#region src/errors.ts
|
|
12169
|
+
/**
|
|
12170
|
+
* The wait ended without a ready instance. Carries the identifiers a caller needs to log the
|
|
12171
|
+
* failure or deallocate the twin, so none of it has to be dug back out of the response —
|
|
12172
|
+
* `response.statusText` is empty over HTTP/2 and tells a caller nothing.
|
|
12173
|
+
*/
|
|
12174
|
+
/** The instance is ready but does not expose the service the caller asked for. */
|
|
12175
|
+
var EndpointNotFoundError = class extends Error {
|
|
12176
|
+
instanceId;
|
|
12177
|
+
endpoint;
|
|
12178
|
+
available;
|
|
12179
|
+
constructor(instanceId, endpoint, available) {
|
|
12180
|
+
super(`Instance ${instanceId} exposed no endpoint named "${endpoint}" — it exposes ${available.length > 0 ? available.join(", ") : "none"}`);
|
|
12181
|
+
this.instanceId = instanceId;
|
|
12182
|
+
this.endpoint = endpoint;
|
|
12183
|
+
this.available = available;
|
|
12184
|
+
this.name = "EndpointNotFoundError";
|
|
12185
|
+
}
|
|
11293
12186
|
};
|
|
11294
12187
|
|
|
11295
|
-
|
|
12188
|
+
//#region src/find-endpoint.ts
|
|
12189
|
+
/**
|
|
12190
|
+
* Reads the URL of one of an instance's exposed services.
|
|
12191
|
+
*
|
|
12192
|
+
* @param instance A ready instance. Endpoints are absent until it is.
|
|
12193
|
+
* @param name The service to reach, as the release names it.
|
|
12194
|
+
* @returns The absolute URL serving that service, or an {@link EndpointNotFoundError} naming the services the instance
|
|
12195
|
+
* does expose.
|
|
12196
|
+
*/
|
|
12197
|
+
function findEndpoint(instance, name) {
|
|
12198
|
+
const endpoint = instance.endpoints?.find((candidate) => candidate.name === name);
|
|
12199
|
+
if (!endpoint) return {
|
|
12200
|
+
success: false,
|
|
12201
|
+
error: new EndpointNotFoundError(instance.id, name, instance.endpoints?.map((each) => each.name) ?? [])
|
|
12202
|
+
};
|
|
12203
|
+
return {
|
|
12204
|
+
success: true,
|
|
12205
|
+
url: endpoint.url
|
|
12206
|
+
};
|
|
12207
|
+
}
|
|
11296
12208
|
|
|
11297
|
-
|
|
11298
|
-
|
|
11299
|
-
|
|
11300
|
-
|
|
11301
|
-
|
|
11302
|
-
|
|
12209
|
+
//#region src/index.ts
|
|
12210
|
+
/**
|
|
12211
|
+
* Auth runs in the wrapped fetch, below the generated code. hey-api's own `auth` option stays
|
|
12212
|
+
* unset: it would turn the cookie scheme into a `Cookie` header browsers drop.
|
|
12213
|
+
*/
|
|
12214
|
+
function createDigitalTwinApi({ baseUrl, authStrategy, fetch = globalThis.fetch }) {
|
|
12215
|
+
const client = createClient$1(createConfig({
|
|
12216
|
+
baseUrl,
|
|
12217
|
+
fetch: authStrategy ? withAuthStrategy(authStrategy, fetch) : fetch
|
|
12218
|
+
}));
|
|
12219
|
+
return new DigitalTwinApi({ client });
|
|
12220
|
+
}
|
|
11303
12221
|
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
|
|
11307
|
-
|
|
11308
|
-
|
|
11309
|
-
|
|
11310
|
-
|
|
11311
|
-
|
|
11312
|
-
|
|
11313
|
-
|
|
11314
|
-
|
|
12222
|
+
const DIGITAL_TWIN_API_ORIGINS = {
|
|
12223
|
+
demo: "https://twins.vention.foo",
|
|
12224
|
+
prod: "https://twins.vention.com"
|
|
12225
|
+
};
|
|
12226
|
+
const getOrigin = environment => {
|
|
12227
|
+
var _a;
|
|
12228
|
+
return (_a = getOriginOverride("VENTION_CLI_DIGITAL_TWIN_API_ORIGIN")) !== null && _a !== void 0 ? _a : DIGITAL_TWIN_API_ORIGINS[environment];
|
|
12229
|
+
};
|
|
12230
|
+
const createClient = (session, origins) => {
|
|
12231
|
+
const strategy = new BearerStrategy({
|
|
12232
|
+
exchange: oauth2TokenExchange({
|
|
12233
|
+
issuer: origins.auth,
|
|
12234
|
+
store: gatewayTokenStore(session),
|
|
12235
|
+
fetch: fetchWithUserAgent
|
|
12236
|
+
})
|
|
12237
|
+
});
|
|
12238
|
+
return {
|
|
12239
|
+
api: createDigitalTwinApi({
|
|
12240
|
+
baseUrl: origins.api,
|
|
12241
|
+
authStrategy: strategy,
|
|
12242
|
+
fetch: fetchWithUserAgent
|
|
12243
|
+
}),
|
|
12244
|
+
fetch: withAuthStrategy(strategy, fetchWithUserAgent)
|
|
12245
|
+
};
|
|
12246
|
+
};
|
|
12247
|
+
const compareNewestFirst = (left, right) => Date.parse(right.createdAt) - Date.parse(left.createdAt);
|
|
12248
|
+
const listReadyInstances = async api => {
|
|
12249
|
+
const {
|
|
12250
|
+
data,
|
|
12251
|
+
error,
|
|
12252
|
+
response
|
|
12253
|
+
} = await api.listInstances();
|
|
12254
|
+
if (data !== undefined) {
|
|
12255
|
+
return data.filter(instance => instance.state === "ready").sort(compareNewestFirst);
|
|
12256
|
+
}
|
|
12257
|
+
if ((response === null || response === void 0 ? void 0 : response.ok) === false) {
|
|
12258
|
+
throw buildApiError(response, typeof error === "object" && error !== null && Object.keys(error).length === 0 ? null : error, response.url);
|
|
11315
12259
|
}
|
|
12260
|
+
throw error;
|
|
12261
|
+
};
|
|
12262
|
+
const buildConnection = (engineUrl, fetch) => ({
|
|
12263
|
+
baseUrl: engineUrl,
|
|
12264
|
+
headers: {},
|
|
12265
|
+
fetch
|
|
11316
12266
|
});
|
|
11317
|
-
|
|
11318
|
-
|
|
11319
|
-
|
|
11320
|
-
|
|
11321
|
-
|
|
11322
|
-
|
|
11323
|
-
|
|
12267
|
+
const listDesigns$1 = async (session, origins) => {
|
|
12268
|
+
const {
|
|
12269
|
+
api,
|
|
12270
|
+
fetch
|
|
12271
|
+
} = createClient(session, origins);
|
|
12272
|
+
const instances = await listReadyInstances(api);
|
|
12273
|
+
const newestInstancePerDesign = instances.filter((instance, index) => instances.findIndex(other => other.designId === instance.designId) === index);
|
|
12274
|
+
return newestInstancePerDesign.flatMap(instance => {
|
|
12275
|
+
const engineLookup = findEndpoint(instance, "execution-engine");
|
|
12276
|
+
return engineLookup.success ? [{
|
|
12277
|
+
id: instance.designId,
|
|
12278
|
+
name: instance.designName,
|
|
12279
|
+
connection: buildConnection(engineLookup.url, fetch)
|
|
12280
|
+
}] : [];
|
|
12281
|
+
});
|
|
12282
|
+
};
|
|
12283
|
+
const resolveConnection = async (session, origins, designId) => {
|
|
12284
|
+
var _a;
|
|
12285
|
+
const designs = await listDesigns$1(session, origins);
|
|
12286
|
+
return (_a = designs.find(design => design.id === designId)) === null || _a === void 0 ? void 0 : _a.connection;
|
|
11324
12287
|
};
|
|
11325
12288
|
|
|
11326
|
-
|
|
12289
|
+
const findDigitalTwinApiOrigins = session => {
|
|
12290
|
+
if (!isDigitalTwinV3Enabled(session)) {
|
|
12291
|
+
return undefined;
|
|
12292
|
+
}
|
|
12293
|
+
const auth = getPlatformAuthOrigin(session.environment);
|
|
12294
|
+
const api = getOrigin(session.environment);
|
|
12295
|
+
if (!auth || !api) {
|
|
12296
|
+
verboseLog(`${DIGITAL_TWIN_V3.key} is on but ${session.environment} has no digital twin API configured, using the Rails API path`);
|
|
12297
|
+
return undefined;
|
|
12298
|
+
}
|
|
12299
|
+
return {
|
|
12300
|
+
auth,
|
|
12301
|
+
api
|
|
12302
|
+
};
|
|
12303
|
+
};
|
|
12304
|
+
const resolveDigitalTwinConnection = async (session, designId) => {
|
|
12305
|
+
const origins = findDigitalTwinApiOrigins(session);
|
|
12306
|
+
return origins ? resolveConnection(session, origins, designId) : resolveConnection$1(session, designId);
|
|
12307
|
+
};
|
|
12308
|
+
const listDesigns = async session => {
|
|
12309
|
+
const origins = findDigitalTwinApiOrigins(session);
|
|
12310
|
+
return origins ? listDesigns$1(session, origins) : listDesigns$2(session);
|
|
12311
|
+
};
|
|
11327
12312
|
|
|
11328
|
-
|
|
11329
|
-
|
|
11330
|
-
|
|
11331
|
-
|
|
11332
|
-
|
|
12313
|
+
const getAppFromDigitalTwin = async (connection, machineCodeAppDirectoryInfo) => {
|
|
12314
|
+
console.log(chalk.blue("Fetching all applications with source code from digital twin..."));
|
|
12315
|
+
const allApplications = await getAllApplicationsWithSourceCode(connection);
|
|
12316
|
+
const targetApp = allApplications.find(app => app.id === machineCodeAppDirectoryInfo.applicationId);
|
|
12317
|
+
if (!targetApp) {
|
|
12318
|
+
console.log();
|
|
12319
|
+
console.error(chalk.red(`Application "${machineCodeAppDirectoryInfo.appName}" (ID: ${machineCodeAppDirectoryInfo.applicationId}) not found in the digital twin.`));
|
|
12320
|
+
process.exit(1);
|
|
12321
|
+
}
|
|
12322
|
+
return targetApp;
|
|
12323
|
+
};
|
|
12324
|
+
const getAvailableAppsFromDigitalTwin = async connection => {
|
|
12325
|
+
const allApplications = await getAllApplicationsWithSourceCode(connection);
|
|
12326
|
+
return allApplications.filter(app => app.type === "machine_code");
|
|
12327
|
+
};
|
|
12328
|
+
const createNewAppDirectory = async (session, currentDir) => {
|
|
12329
|
+
const {
|
|
12330
|
+
selectedDesign,
|
|
12331
|
+
selectedApp
|
|
12332
|
+
} = await selectDesignAndApp(session);
|
|
12333
|
+
if (!selectedApp.sourceCode) {
|
|
12334
|
+
console.log();
|
|
12335
|
+
console.log(chalk.yellow("No source code found for this application."));
|
|
12336
|
+
process.exit(1);
|
|
12337
|
+
}
|
|
12338
|
+
const appDirectoryExists = await checkIfAppDirectoryExists(selectedApp.name, currentDir);
|
|
12339
|
+
const safeFileName = sanitizeFileName(selectedApp.name);
|
|
12340
|
+
if (appDirectoryExists) {
|
|
12341
|
+
console.log();
|
|
12342
|
+
console.error(chalk.red(`You already have a directory with name "${safeFileName}" here.`));
|
|
12343
|
+
console.error(chalk.red("If that is the machine code app you are trying to pull, please navigate to the root folder of the app and run the 'vention pull' command from there."));
|
|
12344
|
+
console.error(chalk.red("If not, please rename that directory and try again."));
|
|
12345
|
+
process.exit(1);
|
|
12346
|
+
}
|
|
12347
|
+
const appDirectoryPath = await writeApplicationToDisk(selectedApp.name, selectedApp.sourceCode, currentDir);
|
|
12348
|
+
const [assets, mmConfiguration] = await Promise.all([getLibraryAssets(selectedDesign.connection), getMmConfiguration(selectedDesign.connection)]);
|
|
12349
|
+
if (assets !== undefined) {
|
|
12350
|
+
await writeReadonlyJsonFile(appDirectoryPath, ".vention-design-scene-assets.json", assets);
|
|
12351
|
+
}
|
|
12352
|
+
await writeReadonlyJsonFile(appDirectoryPath, ".vention-design-configuration.json", mmConfiguration);
|
|
12353
|
+
await writeMachineCodeAppDirectoryInfo(appDirectoryPath, {
|
|
12354
|
+
appName: selectedApp.name,
|
|
12355
|
+
designId: selectedDesign.id,
|
|
12356
|
+
applicationId: selectedApp.id,
|
|
12357
|
+
lastPulledAt: new Date().toISOString(),
|
|
12358
|
+
environment: session.environment,
|
|
12359
|
+
uuid: selectedApp.uuid
|
|
11333
12360
|
});
|
|
12361
|
+
console.log();
|
|
12362
|
+
console.log(chalk.green(`✅ Successfully pulled "${selectedApp.name}" to: ${appDirectoryPath}`));
|
|
12363
|
+
console.log(chalk.blue(`📁 To navigate to your project, run:`));
|
|
12364
|
+
console.log(chalk.cyan(`cd "${safeFileName}"`));
|
|
12365
|
+
console.log(chalk.blue("💡 You can now start working on your application!"));
|
|
11334
12366
|
};
|
|
11335
|
-
|
|
11336
|
-
|
|
11337
|
-
|
|
11338
|
-
|
|
11339
|
-
|
|
11340
|
-
|
|
11341
|
-
|
|
11342
|
-
|
|
11343
|
-
|
|
11344
|
-
var internalSort = arraySort$1;
|
|
11345
|
-
var arrayMethodIsStrict = arrayMethodIsStrict$1;
|
|
11346
|
-
var FF = environmentFfVersion;
|
|
11347
|
-
var IE_OR_EDGE = environmentIsIeOrEdge;
|
|
11348
|
-
var V8 = environmentV8Version;
|
|
11349
|
-
var WEBKIT = environmentWebkitVersion;
|
|
11350
|
-
|
|
11351
|
-
var test = [];
|
|
11352
|
-
var nativeSort = uncurryThis$4(test.sort);
|
|
11353
|
-
var push = uncurryThis$4(test.push);
|
|
11354
|
-
|
|
11355
|
-
// IE8-
|
|
11356
|
-
var FAILS_ON_UNDEFINED = fails$1(function () {
|
|
11357
|
-
test.sort(undefined);
|
|
11358
|
-
});
|
|
11359
|
-
// V8 bug
|
|
11360
|
-
var FAILS_ON_NULL = fails$1(function () {
|
|
11361
|
-
test.sort(null);
|
|
11362
|
-
});
|
|
11363
|
-
// Old WebKit
|
|
11364
|
-
var STRICT_METHOD = arrayMethodIsStrict('sort');
|
|
11365
|
-
|
|
11366
|
-
var STABLE_SORT = !fails$1(function () {
|
|
11367
|
-
// feature detection can be too slow, so check engines versions
|
|
11368
|
-
if (V8) return V8 < 70;
|
|
11369
|
-
if (FF && FF > 3) return;
|
|
11370
|
-
if (IE_OR_EDGE) return true;
|
|
11371
|
-
if (WEBKIT) return WEBKIT < 603;
|
|
11372
|
-
|
|
11373
|
-
var result = '';
|
|
11374
|
-
var code, chr, value, index;
|
|
11375
|
-
|
|
11376
|
-
// generate an array with more 512 elements (Chakra and old V8 fails only in this case)
|
|
11377
|
-
for (code = 65; code < 76; code++) {
|
|
11378
|
-
chr = String.fromCharCode(code);
|
|
11379
|
-
|
|
11380
|
-
switch (code) {
|
|
11381
|
-
case 66: case 69: case 70: case 72: value = 3; break;
|
|
11382
|
-
case 68: case 71: value = 4; break;
|
|
11383
|
-
default: value = 2;
|
|
11384
|
-
}
|
|
11385
|
-
|
|
11386
|
-
for (index = 0; index < 47; index++) {
|
|
11387
|
-
test.push({ k: chr + index, v: value });
|
|
11388
|
-
}
|
|
12367
|
+
const updateExistingAppDirectory = async (session, machineCodeAppDirectoryInfo, currentDir) => {
|
|
12368
|
+
console.log(chalk.blue(`Found existing project: ${machineCodeAppDirectoryInfo.appName}`));
|
|
12369
|
+
console.log(chalk.blue(`Design ID: ${machineCodeAppDirectoryInfo.designId}, App ID: ${machineCodeAppDirectoryInfo.applicationId}`));
|
|
12370
|
+
const connection = await resolveDigitalTwinConnection(session, machineCodeAppDirectoryInfo.designId);
|
|
12371
|
+
if (!connection) {
|
|
12372
|
+
console.log();
|
|
12373
|
+
console.error(chalk.red("Sorry, it seems you do not have that design open with the MachineLogic tab selected."));
|
|
12374
|
+
console.error(chalk.red("Please go to your browser, open your design, and navigate to the MachineLogic page."));
|
|
12375
|
+
process.exit(1);
|
|
11389
12376
|
}
|
|
11390
|
-
|
|
11391
|
-
|
|
11392
|
-
|
|
11393
|
-
|
|
11394
|
-
|
|
11395
|
-
if (result.charAt(result.length - 1) !== chr) result += chr;
|
|
12377
|
+
const appWithSourceCode = await getAppFromDigitalTwin(connection, machineCodeAppDirectoryInfo);
|
|
12378
|
+
await writeApplicationToDisk(appWithSourceCode.name, appWithSourceCode.sourceCode, currentDir, true);
|
|
12379
|
+
const [assets, mmConfiguration] = await Promise.all([getLibraryAssets(connection), getMmConfiguration(connection)]);
|
|
12380
|
+
if (assets !== undefined) {
|
|
12381
|
+
await writeReadonlyJsonFile(currentDir, ".vention-design-scene-assets.json", assets);
|
|
11396
12382
|
}
|
|
11397
|
-
|
|
11398
|
-
|
|
11399
|
-
|
|
11400
|
-
|
|
11401
|
-
|
|
11402
|
-
|
|
11403
|
-
|
|
11404
|
-
|
|
11405
|
-
|
|
11406
|
-
|
|
11407
|
-
|
|
11408
|
-
|
|
11409
|
-
|
|
11410
|
-
|
|
12383
|
+
await writeReadonlyJsonFile(currentDir, ".vention-design-configuration.json", mmConfiguration);
|
|
12384
|
+
await writeMachineCodeAppDirectoryInfo(currentDir, Object.assign(Object.assign({}, machineCodeAppDirectoryInfo), {
|
|
12385
|
+
lastPulledAt: new Date().toISOString()
|
|
12386
|
+
}));
|
|
12387
|
+
console.log();
|
|
12388
|
+
console.log(chalk.green(`✅ Successfully pulled "${appWithSourceCode.name}" to: ${currentDir}`));
|
|
12389
|
+
console.log(chalk.blue("💡 Your project has been updated with the latest changes!"));
|
|
12390
|
+
};
|
|
12391
|
+
const linkDirectory = async (session, currentDir) => {
|
|
12392
|
+
const {
|
|
12393
|
+
selectedDesign,
|
|
12394
|
+
selectedApp
|
|
12395
|
+
} = await selectDesignAndApp(session);
|
|
12396
|
+
await writeMachineCodeAppDirectoryInfo(currentDir, {
|
|
12397
|
+
appName: selectedApp.name,
|
|
12398
|
+
designId: selectedDesign.id,
|
|
12399
|
+
applicationId: selectedApp.id,
|
|
12400
|
+
lastPulledAt: new Date().toISOString(),
|
|
12401
|
+
environment: session.environment,
|
|
12402
|
+
uuid: selectedApp.uuid
|
|
12403
|
+
});
|
|
12404
|
+
console.log(chalk.green(`Successfully linked current directory to design "${selectedDesign.name}" (ID: ${selectedDesign.id})`));
|
|
12405
|
+
console.log(chalk.green(`Application: "${selectedApp.name}" (ID: ${selectedApp.id})`));
|
|
12406
|
+
return {
|
|
12407
|
+
selectedDesign,
|
|
12408
|
+
selectedApp
|
|
12409
|
+
};
|
|
12410
|
+
};
|
|
12411
|
+
const selectDesignAndApp = async session => {
|
|
12412
|
+
const designs = await listDesigns(session);
|
|
12413
|
+
if (designs.length === 0) {
|
|
12414
|
+
console.log();
|
|
12415
|
+
console.log(chalk.yellow("No active allocations found. Please open a design and navigate to the machine logic tab to activate a digital twin."));
|
|
12416
|
+
process.exit(1);
|
|
12417
|
+
}
|
|
12418
|
+
const selectedDesign = await select({
|
|
12419
|
+
message: "Select a design:",
|
|
12420
|
+
choices: designs.map(design => ({
|
|
12421
|
+
name: `${design.name} (ID: ${design.id})`,
|
|
12422
|
+
value: design
|
|
12423
|
+
}))
|
|
12424
|
+
});
|
|
12425
|
+
const availableApps = await getAvailableAppsFromDigitalTwin(selectedDesign.connection);
|
|
12426
|
+
if (availableApps.length === 0) {
|
|
12427
|
+
console.log();
|
|
12428
|
+
console.log(chalk.yellow("No machine code applications found in the digital twin"));
|
|
12429
|
+
process.exit(1);
|
|
12430
|
+
}
|
|
12431
|
+
const selectedApp = await select({
|
|
12432
|
+
message: "Select an application:",
|
|
12433
|
+
choices: availableApps.map(app => ({
|
|
12434
|
+
name: app.name,
|
|
12435
|
+
value: app
|
|
12436
|
+
}))
|
|
12437
|
+
});
|
|
12438
|
+
return {
|
|
12439
|
+
selectedDesign,
|
|
12440
|
+
selectedApp
|
|
11411
12441
|
};
|
|
11412
12442
|
};
|
|
11413
12443
|
|
|
11414
|
-
|
|
11415
|
-
|
|
11416
|
-
|
|
11417
|
-
|
|
11418
|
-
|
|
11419
|
-
|
|
11420
|
-
|
|
11421
|
-
|
|
11422
|
-
|
|
11423
|
-
|
|
11424
|
-
|
|
11425
|
-
|
|
11426
|
-
|
|
11427
|
-
|
|
11428
|
-
for (index = 0; index < arrayLength; index++) {
|
|
11429
|
-
if (index in array) push(items, array[index]);
|
|
12444
|
+
function createLinkCommand() {
|
|
12445
|
+
return new Command("link").description("Link current directory to a Vention design application").action(async () => {
|
|
12446
|
+
try {
|
|
12447
|
+
const session = await loadSession();
|
|
12448
|
+
if (!session) {
|
|
12449
|
+
console.error(chalk.red("Not logged in. Please run 'vention login' first."));
|
|
12450
|
+
process.exit(1);
|
|
12451
|
+
}
|
|
12452
|
+
const currentDir = process.cwd();
|
|
12453
|
+
console.log();
|
|
12454
|
+
await linkDirectory(session, currentDir);
|
|
12455
|
+
console.log(chalk.blue("You can now use 'vention pull' to download app content or 'vention push' to upload local changes."));
|
|
12456
|
+
} catch (error) {
|
|
12457
|
+
handleCommandError(error, "Failed to link directory");
|
|
11430
12458
|
}
|
|
11431
|
-
|
|
11432
|
-
internalSort(items, getSortCompare(comparefn));
|
|
11433
|
-
|
|
11434
|
-
itemsLength = lengthOfArrayLike(items);
|
|
11435
|
-
index = 0;
|
|
11436
|
-
|
|
11437
|
-
while (index < itemsLength) array[index] = items[index++];
|
|
11438
|
-
while (index < arrayLength) deletePropertyOrThrow(array, index++);
|
|
11439
|
-
|
|
11440
|
-
return array;
|
|
11441
|
-
}
|
|
11442
|
-
});
|
|
11443
|
-
|
|
11444
|
-
// this method was added to unscopables after implementation
|
|
11445
|
-
// in popular engines, so it's moved to a separate module
|
|
11446
|
-
var addToUnscopables = addToUnscopables$3;
|
|
11447
|
-
|
|
11448
|
-
// https://tc39.es/ecma262/#sec-array.prototype-@@unscopables
|
|
11449
|
-
addToUnscopables('flatMap');
|
|
11450
|
-
|
|
11451
|
-
var call$2 = functionCall;
|
|
11452
|
-
var anObject$2 = anObject$q;
|
|
11453
|
-
var getIteratorDirect$2 = getIteratorDirect$8;
|
|
11454
|
-
var getIteratorMethod = getIteratorMethod$6;
|
|
11455
|
-
|
|
11456
|
-
var getIteratorFlattenable$1 = function (obj, stringHandling) {
|
|
11457
|
-
if (!stringHandling || typeof obj !== 'string') anObject$2(obj);
|
|
11458
|
-
var method = getIteratorMethod(obj);
|
|
11459
|
-
return getIteratorDirect$2(anObject$2(method !== undefined ? call$2(method, obj) : obj));
|
|
11460
|
-
};
|
|
11461
|
-
|
|
11462
|
-
var $$6 = _export;
|
|
11463
|
-
var call$1 = functionCall;
|
|
11464
|
-
var aCallable$2 = aCallable$l;
|
|
11465
|
-
var anObject$1 = anObject$q;
|
|
11466
|
-
var getIteratorDirect$1 = getIteratorDirect$8;
|
|
11467
|
-
var getIteratorFlattenable = getIteratorFlattenable$1;
|
|
11468
|
-
var createIteratorProxy = iteratorCreateProxy;
|
|
11469
|
-
var iteratorClose$1 = iteratorClose$d;
|
|
11470
|
-
var iteratorHelperThrowsOnInvalidIterator = iteratorHelperThrowsOnInvalidIterator$3;
|
|
11471
|
-
var iteratorHelperWithoutClosingOnEarlyError$1 = iteratorHelperWithoutClosingOnEarlyError$6;
|
|
11472
|
-
|
|
11473
|
-
// Should not throw an error for an iterator without `return` method. Fixed in Safari 26.2
|
|
11474
|
-
// https://bugs.webkit.org/show_bug.cgi?id=297532
|
|
11475
|
-
function throwsOnIteratorWithoutReturn() {
|
|
11476
|
-
try {
|
|
11477
|
-
// eslint-disable-next-line es/no-map, es/no-iterator, es/no-iterator-prototype-flatmap -- required for testing
|
|
11478
|
-
var it = Iterator.prototype.flatMap.call(new Map([[4, 5]]).entries(), function (v) { return v; });
|
|
11479
|
-
it.next();
|
|
11480
|
-
it['return']();
|
|
11481
|
-
} catch (error) {
|
|
11482
|
-
return true;
|
|
11483
|
-
}
|
|
12459
|
+
});
|
|
11484
12460
|
}
|
|
11485
12461
|
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
&& iteratorHelperWithoutClosingOnEarlyError$1('flatMap', TypeError);
|
|
11489
|
-
|
|
11490
|
-
var FORCED = FLAT_MAP_WITHOUT_THROWING_ON_INVALID_ITERATOR || flatMapWithoutClosingOnEarlyError
|
|
11491
|
-
|| throwsOnIteratorWithoutReturn();
|
|
11492
|
-
|
|
11493
|
-
var IteratorProxy = createIteratorProxy(function () {
|
|
11494
|
-
var iterator = this.iterator;
|
|
11495
|
-
var mapper = this.mapper;
|
|
11496
|
-
var result, inner;
|
|
11497
|
-
|
|
11498
|
-
while (true) {
|
|
11499
|
-
if (inner = this.inner) try {
|
|
11500
|
-
result = anObject$1(call$1(inner.next, inner.iterator));
|
|
11501
|
-
if (!result.done) return result.value;
|
|
11502
|
-
this.inner = null;
|
|
11503
|
-
} catch (error) { iteratorClose$1(iterator, 'throw', error); }
|
|
11504
|
-
|
|
11505
|
-
result = anObject$1(call$1(this.next, iterator));
|
|
11506
|
-
|
|
11507
|
-
if (this.done = !!result.done) return;
|
|
11508
|
-
|
|
12462
|
+
function createPushCommand() {
|
|
12463
|
+
return new Command("push").description("Push local changes from this directory to the linked digital twin").action(async () => {
|
|
11509
12464
|
try {
|
|
11510
|
-
|
|
11511
|
-
|
|
11512
|
-
|
|
11513
|
-
|
|
12465
|
+
const session = await loadSession();
|
|
12466
|
+
if (!session) {
|
|
12467
|
+
console.error(chalk.red("Not logged in. Please run 'vention login' first."));
|
|
12468
|
+
process.exit(1);
|
|
12469
|
+
}
|
|
12470
|
+
const currentDir = process.cwd();
|
|
12471
|
+
const machineCodeAppDirectoryInfo = await readMachineCodeAppDirectoryInfo(currentDir);
|
|
12472
|
+
let linkedConnection;
|
|
12473
|
+
if (!machineCodeAppDirectoryInfo) {
|
|
12474
|
+
console.log();
|
|
12475
|
+
console.log(chalk.yellow("This directory is not linked to a Vention application."));
|
|
12476
|
+
const shouldLink = await select({
|
|
12477
|
+
message: "Would you like to link this directory to an application?",
|
|
12478
|
+
choices: [{
|
|
12479
|
+
name: "Yes, link this directory",
|
|
12480
|
+
value: true
|
|
12481
|
+
}, {
|
|
12482
|
+
name: "No, cancel push operation",
|
|
12483
|
+
value: false
|
|
12484
|
+
}]
|
|
12485
|
+
});
|
|
12486
|
+
if (!shouldLink) {
|
|
12487
|
+
console.log(chalk.blue("Push operation cancelled. Run 'vention link' when you're ready to link this directory."));
|
|
12488
|
+
process.exit(0);
|
|
12489
|
+
}
|
|
12490
|
+
const {
|
|
12491
|
+
selectedDesign
|
|
12492
|
+
} = await linkDirectory(session, currentDir);
|
|
12493
|
+
linkedConnection = selectedDesign.connection;
|
|
12494
|
+
console.log(chalk.blue("Continuing with push operation..."));
|
|
12495
|
+
}
|
|
12496
|
+
const updatedMachineCodeAppDirectoryInfo = await readMachineCodeAppDirectoryInfo(currentDir);
|
|
12497
|
+
if (!updatedMachineCodeAppDirectoryInfo) {
|
|
12498
|
+
console.log(chalk.red("Error reading directory metadata after linking."));
|
|
12499
|
+
process.exit(1);
|
|
12500
|
+
}
|
|
12501
|
+
console.log();
|
|
12502
|
+
console.log(chalk.blue(`Pushing changes for project: ${updatedMachineCodeAppDirectoryInfo.appName}`));
|
|
12503
|
+
console.log(chalk.blue(`Design ID: ${updatedMachineCodeAppDirectoryInfo.designId}, App ID: ${updatedMachineCodeAppDirectoryInfo.applicationId}`));
|
|
12504
|
+
const connection = linkedConnection !== null && linkedConnection !== void 0 ? linkedConnection : await resolveDigitalTwinConnection(session, updatedMachineCodeAppDirectoryInfo.designId);
|
|
12505
|
+
if (!connection) {
|
|
12506
|
+
console.log();
|
|
12507
|
+
console.error(chalk.red("Sorry, it seems you do not have that design open with the MachineLogic tab selected."));
|
|
12508
|
+
console.error(chalk.red("Please go to your browser, open your design, and navigate to the MachineLogic page."));
|
|
12509
|
+
process.exit(1);
|
|
12510
|
+
}
|
|
12511
|
+
console.log();
|
|
12512
|
+
console.log(chalk.blue("Serializing local files..."));
|
|
12513
|
+
const ignorePatterns = getDefaultIgnorePatterns();
|
|
12514
|
+
const serializedSourceCode = serializeFileSystem(currentDir, ignorePatterns, true);
|
|
12515
|
+
const applicationToPush = {
|
|
12516
|
+
name: updatedMachineCodeAppDirectoryInfo.appName,
|
|
12517
|
+
id: updatedMachineCodeAppDirectoryInfo.applicationId,
|
|
12518
|
+
type: "machine_code",
|
|
12519
|
+
sourceCode: serializedSourceCode,
|
|
12520
|
+
uuid: updatedMachineCodeAppDirectoryInfo.uuid
|
|
12521
|
+
};
|
|
12522
|
+
console.log(chalk.blue("Pushing to digital twin..."));
|
|
12523
|
+
await pushApplicationToDigitalTwin(connection, applicationToPush);
|
|
12524
|
+
await writeMachineCodeAppDirectoryInfo(currentDir, Object.assign(Object.assign({}, updatedMachineCodeAppDirectoryInfo), {
|
|
12525
|
+
lastPushedAt: new Date().toISOString()
|
|
12526
|
+
}));
|
|
12527
|
+
console.log();
|
|
12528
|
+
console.log(chalk.green(`✅ Successfully pushed to digital twin`));
|
|
12529
|
+
console.log(chalk.blue("💡 Your changes have been uploaded!"));
|
|
12530
|
+
} catch (error) {
|
|
12531
|
+
handleCommandError(error, "Failed to push application");
|
|
12532
|
+
}
|
|
12533
|
+
});
|
|
12534
|
+
}
|
|
11514
12535
|
|
|
11515
|
-
|
|
11516
|
-
|
|
11517
|
-
$$6({ target: 'Iterator', proto: true, real: true, forced: FORCED }, {
|
|
11518
|
-
flatMap: function flatMap(mapper) {
|
|
11519
|
-
anObject$1(this);
|
|
12536
|
+
function createPullCommand() {
|
|
12537
|
+
return new Command("pull").description("Pull an application from a design to this directory").action(async () => {
|
|
11520
12538
|
try {
|
|
11521
|
-
|
|
12539
|
+
const session = await loadSession();
|
|
12540
|
+
if (!session) {
|
|
12541
|
+
console.error(chalk.red("Not logged in. Please run 'vention login' first."));
|
|
12542
|
+
process.exit(1);
|
|
12543
|
+
}
|
|
12544
|
+
const currentDir = process.cwd();
|
|
12545
|
+
const machineCodeAppDirectoryInfo = await readMachineCodeAppDirectoryInfo(currentDir);
|
|
12546
|
+
if (machineCodeAppDirectoryInfo) {
|
|
12547
|
+
console.log(chalk.blue(`This directory is linked to app: ${machineCodeAppDirectoryInfo.appName}`));
|
|
12548
|
+
console.log(chalk.blue(`Pulling latest content from design ID: ${machineCodeAppDirectoryInfo.designId}`));
|
|
12549
|
+
await updateExistingAppDirectory(session, machineCodeAppDirectoryInfo, currentDir);
|
|
12550
|
+
} else {
|
|
12551
|
+
await createNewAppDirectory(session, currentDir);
|
|
12552
|
+
}
|
|
11522
12553
|
} catch (error) {
|
|
11523
|
-
|
|
12554
|
+
handleCommandError(error, "Failed to pull application");
|
|
11524
12555
|
}
|
|
12556
|
+
});
|
|
12557
|
+
}
|
|
11525
12558
|
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
}
|
|
12559
|
+
function createLogsCommand() {
|
|
12560
|
+
return new Command("logs").description("Fetch application logs from the linked digital twin").action(async () => {
|
|
12561
|
+
try {
|
|
12562
|
+
const session = await loadSession();
|
|
12563
|
+
if (!session) {
|
|
12564
|
+
console.error(chalk.red("Not logged in. Please run 'vention login' first."));
|
|
12565
|
+
process.exit(1);
|
|
12566
|
+
}
|
|
12567
|
+
const currentDir = process.cwd();
|
|
12568
|
+
const machineCodeAppDirectoryInfo = await readMachineCodeAppDirectoryInfo(currentDir);
|
|
12569
|
+
if (!machineCodeAppDirectoryInfo) {
|
|
12570
|
+
console.error(chalk.red("This directory is not linked to a Vention application."));
|
|
12571
|
+
console.error(chalk.red("Please run 'vention pull' or 'vention link' first."));
|
|
12572
|
+
process.exit(1);
|
|
12573
|
+
}
|
|
12574
|
+
const connection = await resolveDigitalTwinConnection(session, machineCodeAppDirectoryInfo.designId);
|
|
12575
|
+
if (!connection) {
|
|
12576
|
+
console.error(chalk.red("Sorry, it seems you do not have that design open with the MachineLogic tab selected."));
|
|
12577
|
+
console.error(chalk.red("Please go to your browser, open your design, and navigate to the MachineLogic page."));
|
|
12578
|
+
process.exit(1);
|
|
12579
|
+
}
|
|
12580
|
+
const logs = await getApplicationLogs(connection, machineCodeAppDirectoryInfo.applicationId);
|
|
12581
|
+
console.log(logs);
|
|
12582
|
+
} catch (error) {
|
|
12583
|
+
handleCommandError(error, "Failed to fetch application logs");
|
|
12584
|
+
}
|
|
12585
|
+
});
|
|
12586
|
+
}
|
|
11534
12587
|
|
|
11535
12588
|
var $$5 = _export;
|
|
11536
12589
|
var call = functionCall;
|