@forge/sql
4.0.5-next.14.0.5-next.1-experimental-e9e08bb
out/sql.js~
out/sql.jsModified+37−3
Index: package/out/sql.js
===================================================================
--- package/out/sql.js
+++ package/out/sql.js
@@ -10,17 +10,20 @@
EXECUTE_DDL: '/api/v1/execute/ddl'
};
class SqlClient {
async sendRequest(path, options) {
- const response = await (0, api_1.__fetchProduct)({ provider: 'app', remote: 'sql', type: 'sql' })(path, {
+ const requestOptions = {
...options,
redirect: 'follow',
headers: {
...options?.headers,
'Content-Type': 'application/json'
}
- });
- return response;
+ };
+ const localClient = getLocalSqlFetchClient();
+ if (localClient)
+ return localClient(path, requestOptions);
+ return (0, api_1.__fetchProduct)({ provider: 'app', remote: 'sql', type: 'sql' })(path, requestOptions);
}
async storageApi(query, params = [], method = 'all', endpoint = exports.SQL_API_ENDPOINTS.EXECUTE) {
const response = await this.sendRequest(endpoint, {
method: 'POST',
@@ -54,4 +57,35 @@
}
}
exports.SqlClient = SqlClient;
exports.sql = new SqlClient();
+function getLocalSqlFetchClient() {
+ if (process.env.FORGE_LOCAL_STORAGE !== '1')
+ return undefined;
+ const baseUrl = process.env.FORGE_LOCAL_SQL_URL;
+ const appId = process.env.FORGE_LOCAL_STORAGE_APP_ID;
+ const environmentId = process.env.FORGE_LOCAL_STORAGE_ENVIRONMENT_ID;
+ const installationId = process.env.FORGE_LOCAL_STORAGE_INSTALLATION_ID;
+ if (!baseUrl || !appId || !environmentId || !installationId) {
+ throw new Error('Forge local SQL routing is enabled but its local namespace is incomplete.');
+ }
+ if (baseUrl !== 'http://127.0.0.1:18091') {
+ throw new Error('Forge local SQL endpoint must be http://127.0.0.1:18091.');
+ }
+ const fetchImplementation = globalThis.__forge_local_fetch__;
+ if (typeof fetchImplementation !== 'function') {
+ throw new Error('Forge local SQL routing requires the tunnel local-fetch bridge.');
+ }
+ const endpoint = new URL(baseUrl);
+ return async (requestPath, options) => (await fetchImplementation(new URL(requestPath, endpoint), {
+ ...options,
+ headers: {
+ ...options?.headers,
+ 'x-forge-app-id': appId,
+ 'x-forge-environment-id': environmentId,
+ 'x-forge-installation-id': installationId,
+ 'x-atlassian-forgeapp-app-id': appId,
+ 'x-atlassian-forgeapp-environment-id': environmentId,
+ 'x-atlassian-forgeapp-installation-id': installationId
+ }
+ }));
+}