@wix/ditto-codegen-public 1.0.454 → 1.0.455
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/out.js +53 -11
- package/package.json +2 -2
package/dist/out.js
CHANGED
|
@@ -11049,7 +11049,7 @@ var require_CodeGenService = __commonJS({
|
|
|
11049
11049
|
"dist/services/CodeGenService.js"(exports2) {
|
|
11050
11050
|
"use strict";
|
|
11051
11051
|
Object.defineProperty(exports2, "__esModule", { value: true });
|
|
11052
|
-
exports2.CodeGenService = exports2.FETCH_TIMEOUT_MS = exports2.REQUEST_TIMEOUT_MS = exports2.JobsSortOrder = exports2.TaskKind = exports2.Status = void 0;
|
|
11052
|
+
exports2.CodeGenService = exports2.AUTH_REFRESH_COOLDOWN_MS = exports2.FETCH_TIMEOUT_MS = exports2.REQUEST_TIMEOUT_MS = exports2.JobsSortOrder = exports2.TaskKind = exports2.Status = void 0;
|
|
11053
11053
|
exports2.createCodeGenErrorHandler = createCodeGenErrorHandler;
|
|
11054
11054
|
var http_client_1 = require_index_node();
|
|
11055
11055
|
var http_1 = require_http_impl();
|
|
@@ -11141,6 +11141,8 @@ var require_CodeGenService = __commonJS({
|
|
|
11141
11141
|
}
|
|
11142
11142
|
exports2.REQUEST_TIMEOUT_MS = 12e4;
|
|
11143
11143
|
exports2.FETCH_TIMEOUT_MS = 3e4;
|
|
11144
|
+
var AUTH_FAILURE_STATUSES = /* @__PURE__ */ new Set([401, 403]);
|
|
11145
|
+
exports2.AUTH_REFRESH_COOLDOWN_MS = 6e4;
|
|
11144
11146
|
function isNotFound(error) {
|
|
11145
11147
|
return http_client_1.HttpClient.isHttpError(error) && error.response?.status === 404;
|
|
11146
11148
|
}
|
|
@@ -11151,21 +11153,25 @@ var require_CodeGenService = __commonJS({
|
|
|
11151
11153
|
constructor(projectId, httpClient) {
|
|
11152
11154
|
this.projectId = projectId;
|
|
11153
11155
|
this.accessToken = process.env.WIX_ACCESS_TOKEN;
|
|
11156
|
+
this.lastAuthRefreshAt = 0;
|
|
11157
|
+
this.isAuthRefreshFailing = false;
|
|
11154
11158
|
this.sandboxId = process.env.SANDBOX_ID;
|
|
11155
11159
|
this.refreshAccessToken = async () => {
|
|
11156
|
-
|
|
11157
|
-
|
|
11158
|
-
|
|
11160
|
+
if (!this.inFlightRefresh) {
|
|
11161
|
+
this.inFlightRefresh = this.mintAccessToken();
|
|
11162
|
+
}
|
|
11163
|
+
return this.inFlightRefresh;
|
|
11159
11164
|
};
|
|
11160
11165
|
this.request = async (req, timeout) => {
|
|
11161
11166
|
const build = () => this.withTimeout(this.withAuth(req), timeout);
|
|
11167
|
+
const attemptedToken = this.accessToken;
|
|
11162
11168
|
try {
|
|
11163
11169
|
return await this.httpClient.request(build());
|
|
11164
11170
|
} catch (err) {
|
|
11165
|
-
if (!this.
|
|
11171
|
+
if (!this.isAuthFailure(err))
|
|
11172
|
+
throw err;
|
|
11173
|
+
if (!await this.prepareAuthRetry(attemptedToken))
|
|
11166
11174
|
throw err;
|
|
11167
|
-
logger_12.logger.warn("[CodeGenService] 401 received, refreshing token and retrying once");
|
|
11168
|
-
await this.refreshAccessToken();
|
|
11169
11175
|
return await this.httpClient.request(build());
|
|
11170
11176
|
}
|
|
11171
11177
|
};
|
|
@@ -11379,13 +11385,49 @@ var require_CodeGenService = __commonJS({
|
|
|
11379
11385
|
}
|
|
11380
11386
|
setAccessToken(token) {
|
|
11381
11387
|
this.accessToken = token;
|
|
11388
|
+
this.onAccessTokenChanged?.(token);
|
|
11389
|
+
}
|
|
11390
|
+
/** Inverted wiring: `opencode-integration/config` imports this module. */
|
|
11391
|
+
setAccessTokenListener(listener) {
|
|
11392
|
+
this.onAccessTokenChanged = listener;
|
|
11393
|
+
}
|
|
11394
|
+
async mintAccessToken() {
|
|
11395
|
+
this.lastAuthRefreshAt = Date.now();
|
|
11396
|
+
try {
|
|
11397
|
+
const token = await (0, wixTokenRefresh_1.refreshWixAccessToken)();
|
|
11398
|
+
this.isAuthRefreshFailing = false;
|
|
11399
|
+
this.setAccessToken(token);
|
|
11400
|
+
return token;
|
|
11401
|
+
} catch (err) {
|
|
11402
|
+
this.isAuthRefreshFailing = true;
|
|
11403
|
+
throw err;
|
|
11404
|
+
} finally {
|
|
11405
|
+
this.inFlightRefresh = void 0;
|
|
11406
|
+
}
|
|
11382
11407
|
}
|
|
11383
|
-
|
|
11408
|
+
isAuthFailure(error) {
|
|
11384
11409
|
if (!http_client_1.HttpClient.isHttpError(error))
|
|
11385
11410
|
return false;
|
|
11386
11411
|
if (this.httpClient.isCancel(error))
|
|
11387
11412
|
return false;
|
|
11388
|
-
|
|
11413
|
+
const status = error.response?.status;
|
|
11414
|
+
return status !== void 0 && AUTH_FAILURE_STATUSES.has(status);
|
|
11415
|
+
}
|
|
11416
|
+
async prepareAuthRetry(attemptedToken) {
|
|
11417
|
+
if (this.accessToken !== attemptedToken)
|
|
11418
|
+
return true;
|
|
11419
|
+
if (this.inFlightRefresh) {
|
|
11420
|
+
await this.inFlightRefresh;
|
|
11421
|
+
return true;
|
|
11422
|
+
}
|
|
11423
|
+
const tokenAgeMs = Date.now() - this.lastAuthRefreshAt;
|
|
11424
|
+
if (tokenAgeMs < exports2.AUTH_REFRESH_COOLDOWN_MS) {
|
|
11425
|
+
logger_12.logger.warn(this.isAuthRefreshFailing ? "[CodeGenService] auth failure while token refresh is failing, not retrying" : "[CodeGenService] auth failure on a freshly refreshed token, not retrying", { tokenAgeMs });
|
|
11426
|
+
return false;
|
|
11427
|
+
}
|
|
11428
|
+
logger_12.logger.info("[CodeGenService] auth failure received, refreshing token and retrying once", { tokenAgeMs });
|
|
11429
|
+
await this.refreshAccessToken();
|
|
11430
|
+
return true;
|
|
11389
11431
|
}
|
|
11390
11432
|
withAuth(req) {
|
|
11391
11433
|
return mapRequest(req, (r) => ({
|
|
@@ -24676,8 +24718,7 @@ var runPendingJob = async (job, logPrefix) => {
|
|
|
24676
24718
|
}
|
|
24677
24719
|
const jobId = job.id;
|
|
24678
24720
|
logger_1.logger.info(`${logPrefix} Selected job`, { jobId });
|
|
24679
|
-
|
|
24680
|
-
(0, config_1.setCurrentAccessToken)(freshToken);
|
|
24721
|
+
await codeGenerationService_1.codeGenerationService.refreshAccessToken();
|
|
24681
24722
|
await codeGenerationService_1.codeGenerationService.markJobAsRuninng(jobId);
|
|
24682
24723
|
await processJob(job);
|
|
24683
24724
|
await codeGenerationService_1.codeGenerationService.markJobAsCompleted(jobId);
|
|
@@ -24741,6 +24782,7 @@ async function main(ctx) {
|
|
|
24741
24782
|
codeIdentifier: ctx.codeIdentifier,
|
|
24742
24783
|
metasiteId: ctx.metasiteId
|
|
24743
24784
|
});
|
|
24785
|
+
codeGenerationService_1.codeGenerationService.setAccessTokenListener(config_1.setCurrentAccessToken);
|
|
24744
24786
|
await initOpenCode();
|
|
24745
24787
|
const nudgeListenerServer = new nudge_listener_server_1.NudgeListenerServer({
|
|
24746
24788
|
fetchPendingJobs: () => codeGenerationService_1.codeGenerationService.fetchPendingJobs(),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/ditto-codegen-public",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.455",
|
|
4
4
|
"description": "AI-powered Wix CLI app generator - standalone executable",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "node build.mjs",
|
|
@@ -29,5 +29,5 @@
|
|
|
29
29
|
"esbuild": "^0.27.2",
|
|
30
30
|
"vitest": "^4.0.16"
|
|
31
31
|
},
|
|
32
|
-
"falconPackageHash": "
|
|
32
|
+
"falconPackageHash": "a0edc9a2e794342c1e253db70cf53c1ae6cd0ee627c755489f57a591"
|
|
33
33
|
}
|