@base44-preview/cli 0.0.22-pr.134.259538d → 0.0.22-pr.135.f4b78d8
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/index.js +45 -24
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -16693,16 +16693,13 @@ async function readAllEntities(entitiesDir) {
|
|
|
16693
16693
|
async function syncEntities(entities) {
|
|
16694
16694
|
const appClient = getAppClient();
|
|
16695
16695
|
const schemaSyncPayload = Object.fromEntries(entities.map((entity) => [entity.name, entity]));
|
|
16696
|
-
|
|
16697
|
-
json: { entityNameToSchema: schemaSyncPayload }
|
|
16698
|
-
|
|
16699
|
-
})
|
|
16700
|
-
|
|
16701
|
-
|
|
16702
|
-
if (response.status === 428) throw new Error(`Failed to delete entity: ${formatApiError(errorJson)}`);
|
|
16703
|
-
throw new Error(`Error occurred while syncing entities: ${formatApiError(errorJson)}`);
|
|
16696
|
+
try {
|
|
16697
|
+
const response = await appClient.put("entity-schemas", { json: { entityNameToSchema: schemaSyncPayload } });
|
|
16698
|
+
return SyncEntitiesResponseSchema.parse(await response.json());
|
|
16699
|
+
} catch (error) {
|
|
16700
|
+
if (error instanceof HTTPError && error.response.status === 428) throw new Error(`Failed to delete entity: ${error instanceof Error ? error.message : String(error)}`);
|
|
16701
|
+
throw new Error(`Error occurred while syncing entities: ${error instanceof Error ? error.message : String(error)}`);
|
|
16704
16702
|
}
|
|
16705
|
-
return SyncEntitiesResponseSchema.parse(await response.json());
|
|
16706
16703
|
}
|
|
16707
16704
|
|
|
16708
16705
|
//#endregion
|
|
@@ -16877,23 +16874,22 @@ async function writeAgents(agentsDir, remoteAgents) {
|
|
|
16877
16874
|
//#endregion
|
|
16878
16875
|
//#region src/core/resources/agent/api.ts
|
|
16879
16876
|
async function pushAgents(agents) {
|
|
16880
|
-
const
|
|
16881
|
-
|
|
16882
|
-
|
|
16883
|
-
|
|
16884
|
-
|
|
16885
|
-
|
|
16886
|
-
throw new Error(`Error occurred while syncing agents: ${formatApiError(errorJson)}`);
|
|
16877
|
+
const appClient = getAppClient();
|
|
16878
|
+
try {
|
|
16879
|
+
const response = await appClient.put("agent-configs", { json: agents });
|
|
16880
|
+
return SyncAgentsResponseSchema.parse(await response.json());
|
|
16881
|
+
} catch (error) {
|
|
16882
|
+
throw new Error(`Error occurred while syncing agents: ${error instanceof Error ? error.message : String(error)}`);
|
|
16887
16883
|
}
|
|
16888
|
-
return SyncAgentsResponseSchema.parse(await response.json());
|
|
16889
16884
|
}
|
|
16890
16885
|
async function fetchAgents() {
|
|
16891
|
-
const
|
|
16892
|
-
|
|
16893
|
-
const
|
|
16894
|
-
|
|
16886
|
+
const appClient = getAppClient();
|
|
16887
|
+
try {
|
|
16888
|
+
const response = await appClient.get("agent-configs");
|
|
16889
|
+
return ListAgentsResponseSchema.parse(await response.json());
|
|
16890
|
+
} catch (error) {
|
|
16891
|
+
throw new Error(`Error occurred while fetching agents: ${error instanceof Error ? error.message : String(error)}`);
|
|
16895
16892
|
}
|
|
16896
|
-
return ListAgentsResponseSchema.parse(await response.json());
|
|
16897
16893
|
}
|
|
16898
16894
|
|
|
16899
16895
|
//#endregion
|
|
@@ -30694,6 +30690,10 @@ async function readAppConfig(projectRoot) {
|
|
|
30694
30690
|
* Authenticated HTTP client for Base44 API.
|
|
30695
30691
|
* Automatically handles token refresh and retry on 401 responses.
|
|
30696
30692
|
*/
|
|
30693
|
+
/**
|
|
30694
|
+
* Formats API error responses into human-readable strings.
|
|
30695
|
+
* Internal utility used by error handling hooks.
|
|
30696
|
+
*/
|
|
30697
30697
|
function formatApiError(errorJson) {
|
|
30698
30698
|
const error = errorJson;
|
|
30699
30699
|
const content = error?.message ?? error?.detail ?? errorJson;
|
|
@@ -30713,8 +30713,28 @@ async function handleUnauthorized(request, _options, response) {
|
|
|
30713
30713
|
return distribution_default(request, { headers: { Authorization: `Bearer ${newAccessToken}` } });
|
|
30714
30714
|
}
|
|
30715
30715
|
/**
|
|
30716
|
-
*
|
|
30716
|
+
* Handles HTTPErrors by formatting the API error response into a readable message.
|
|
30717
|
+
* This hook runs before ky throws the error, allowing us to customize the error message.
|
|
30718
|
+
*/
|
|
30719
|
+
async function handleApiErrors(error) {
|
|
30720
|
+
if (error.name !== "HTTPError") return error;
|
|
30721
|
+
const httpError = error;
|
|
30722
|
+
if (!httpError.response) return error;
|
|
30723
|
+
try {
|
|
30724
|
+
const formattedMessage = formatApiError(await httpError.response.clone().json());
|
|
30725
|
+
const newError = new Error(formattedMessage);
|
|
30726
|
+
newError.name = error.name;
|
|
30727
|
+
newError.stack = error.stack;
|
|
30728
|
+
newError.response = httpError.response;
|
|
30729
|
+
return newError;
|
|
30730
|
+
} catch {
|
|
30731
|
+
return error;
|
|
30732
|
+
}
|
|
30733
|
+
}
|
|
30734
|
+
/**
|
|
30735
|
+
* Base44 API client with automatic authentication and error handling.
|
|
30717
30736
|
* Use this for general API calls that require authentication.
|
|
30737
|
+
* All non-OK responses are automatically caught and formatted into Error objects.
|
|
30718
30738
|
*/
|
|
30719
30739
|
const base44Client = distribution_default.create({
|
|
30720
30740
|
prefixUrl: getBase44ApiUrl(),
|
|
@@ -30733,7 +30753,8 @@ const base44Client = distribution_default.create({
|
|
|
30733
30753
|
request.headers.set("Authorization", `Bearer ${auth.accessToken}`);
|
|
30734
30754
|
} catch {}
|
|
30735
30755
|
}],
|
|
30736
|
-
afterResponse: [handleUnauthorized]
|
|
30756
|
+
afterResponse: [handleUnauthorized],
|
|
30757
|
+
beforeError: [handleApiErrors]
|
|
30737
30758
|
}
|
|
30738
30759
|
});
|
|
30739
30760
|
/**
|