@forge/sql
4.0.5-next.14.0.5-next.1-experimental-e9e08bb
~
Modified (5 files)
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
+ }
+ }));
+} Index: package/out/__test__/sql.test.js
===================================================================
--- package/out/__test__/sql.test.js
+++ package/out/__test__/sql.test.js
@@ -8,8 +8,11 @@
describe('SqlClient', () => {
let sqlClient;
let mockFetch;
beforeEach(() => {
+ for (const key of Object.keys(process.env).filter((key) => key.startsWith('FORGE_LOCAL_')))
+ delete process.env[key];
+ delete global.__forge_local_fetch__;
sqlClient = new sql_1.SqlClient();
mockFetch = jest.fn();
api_1.__fetchProduct.mockReturnValue(mockFetch);
jest.clearAllMocks();
@@ -106,8 +109,59 @@
const path = '/api/v1/execute';
await expect(sqlClient['sendRequest'](path)).rejects.toThrow(mockError);
expect(mockFetch).toHaveBeenCalledWith(path, expect.any(Object));
});
+ it('routes local-storage requests directly to loopback without calling hosted Forge SQL', async () => {
+ Object.assign(process.env, {
+ FORGE_LOCAL_STORAGE: '1',
+ FORGE_LOCAL_SQL_URL: 'http://127.0.0.1:18091',
+ FORGE_LOCAL_STORAGE_APP_ID: 'local-app',
+ FORGE_LOCAL_STORAGE_ENVIRONMENT_ID: 'local-environment',
+ FORGE_LOCAL_STORAGE_INSTALLATION_ID: 'local-installation'
+ });
+ const localFetch = jest.fn().mockResolvedValue(new Response(JSON.stringify({ rows: [] }), { status: 200 }));
+ global.__forge_local_fetch__ = localFetch;
+ await sqlClient['sendRequest']('/api/v1/execute', { method: 'POST' });
+ expect(localFetch).toHaveBeenCalledWith(new URL('http://127.0.0.1:18091/api/v1/execute'), expect.objectContaining({
+ method: 'POST',
+ headers: expect.objectContaining({
+ 'x-forge-app-id': 'local-app',
+ 'x-forge-environment-id': 'local-environment',
+ 'x-forge-installation-id': 'local-installation',
+ 'x-atlassian-forgeapp-app-id': 'local-app',
+ 'x-atlassian-forgeapp-environment-id': 'local-environment',
+ 'x-atlassian-forgeapp-installation-id': 'local-installation'
+ })
+ }));
+ expect(api_1.__fetchProduct).not.toHaveBeenCalled();
+ delete global.__forge_local_fetch__;
+ });
+ it('fails closed for incomplete or non-loopback local SQL routing', async () => {
+ process.env.FORGE_LOCAL_STORAGE = '1';
+ process.env.FORGE_LOCAL_SQL_URL = 'http://127.0.0.1:18091';
+ await expect(sqlClient['sendRequest']('/api/v1/execute')).rejects.toThrow('local namespace is incomplete');
+ expect(api_1.__fetchProduct).not.toHaveBeenCalled();
+ Object.assign(process.env, {
+ FORGE_LOCAL_STORAGE_APP_ID: 'local-app',
+ FORGE_LOCAL_STORAGE_ENVIRONMENT_ID: 'local-environment',
+ FORGE_LOCAL_STORAGE_INSTALLATION_ID: 'local-installation',
+ FORGE_LOCAL_SQL_URL: 'https://example.com'
+ });
+ await expect(sqlClient['sendRequest']('/api/v1/execute')).rejects.toThrow('must be http://127.0.0.1:18091');
+ expect(api_1.__fetchProduct).not.toHaveBeenCalled();
+ });
+ it('fails closed when local SQL routing has no tunnel local-fetch bridge', async () => {
+ Object.assign(process.env, {
+ FORGE_LOCAL_STORAGE: '1',
+ FORGE_LOCAL_SQL_URL: 'http://127.0.0.1:18091',
+ FORGE_LOCAL_STORAGE_APP_ID: 'local-app',
+ FORGE_LOCAL_STORAGE_ENVIRONMENT_ID: 'local-environment',
+ FORGE_LOCAL_STORAGE_INSTALLATION_ID: 'local-installation'
+ });
+ delete global.__forge_local_fetch__;
+ await expect(sqlClient['sendRequest']('/api/v1/execute')).rejects.toThrow('requires the tunnel local-fetch bridge');
+ expect(api_1.__fetchProduct).not.toHaveBeenCalled();
+ });
});
describe('prepare', () => {
it('should return a SqlStatement instance with query', () => {
const statement = sqlClient.prepare('INSERT INTO test VALUES (?, ?)'); Index: package/package.json
===================================================================
--- package/package.json
+++ package/package.json
@@ -1,7 +1,7 @@
{
"name": "@forge/sql",
- "version": "4.0.5-next.1",
+ "version": "4.0.5-next.1-experimental-e9e08bb",
"description": "Forge SQL sdk",
"author": "Atlassian",
"license": "SEE LICENSE IN LICENSE.txt",
"main": "out/index.js",
@@ -17,9 +17,9 @@
"jest-when": "^3.6.0",
"typescript": "5.9.2"
},
"dependencies": {
- "@forge/api": "^8.0.5-next.0"
+ "@forge/api": "^8.0.5-next.1-experimental-e9e08bb"
},
"publishConfig": {
"registry": "https://packages.atlassian.com/api/npm/npm-public/"
}, Index: package/out/sql.d.ts.map
===================================================================
--- package/out/sql.d.ts.map
+++ package/out/sql.d.ts.map
@@ -1,1 +1,1 @@
-{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAgC,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI7E,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,KAAK,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAElF,qBAAa,SAAS;YACN,WAAW;YAYX,UAAU;YAsBV,qBAAqB;IAYnC,OAAO,CAAC,QAAQ,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,eAA2C,GACpD,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAU3B,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAQ9D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;CAGrE;AAED,eAAO,MAAM,GAAG,WAAkB,CAAC"}
\ No newline at end of file
+{"version":3,"file":"sql.d.ts","sourceRoot":"","sources":["../src/sql.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,EAAgC,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI7E,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX,KAAK,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAElF,qBAAa,SAAS;YACN,WAAW;YAcX,UAAU;YAsBV,qBAAqB;IAYnC,OAAO,CAAC,QAAQ,EACd,KAAK,EAAE,MAAM,EACb,QAAQ,GAAE,eAA2C,GACpD,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAU3B,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;IAQ9D,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAY3B,UAAU,CAAC,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;CAGrE;AAED,eAAO,MAAM,GAAG,WAAkB,CAAC"}
\ No newline at end of file Index: package/CHANGELOG.md
===================================================================
--- package/CHANGELOG.md
+++ package/CHANGELOG.md
@@ -1,6 +1,16 @@
# @forge/sql
+## 4.0.5-next.1-experimental-e9e08bb
+
+### Patch Changes
+
+- 067c20a: Add manifest-driven Docker local storage, seeding, reset, status, persistent lifecycle, and local
+ SDK routing for Forge tunnels. Simplify `forge storage entities indexes list` to
+ `forge storage indexes list`.
+- 01e9f12: Include package changelogs in published artifacts.
+ - @forge/[email protected]
+
## 4.0.5-next.1
### Patch Changes