Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/client/src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1179,3 +1179,28 @@ describe('HTTP error shaping', () => {
expect(caught.httpStatus).toBe(500);
});
});

describe('packages.install', () => {
const MANIFEST = { id: 'com.acme.crm', name: 'Acme CRM', version: '1.0.0', type: 'app' };

it('POSTs the manifest and omits `overwrite` unless requested', async () => {
const { client, fetchMock } = createMockClient({ success: true, data: { package: { manifest: MANIFEST } } });
await client.packages.install(MANIFEST, { enableOnInstall: true });

expect(fetchMock).toHaveBeenCalledWith('http://localhost:3000/api/v1/packages', expect.any(Object));
const body = JSON.parse(fetchMock.mock.calls[0][1].body);
expect(body.manifest).toEqual(MANIFEST);
expect(body.enableOnInstall).toBe(true);
// Duplicate-id guard semantics: never send `overwrite` implicitly —
// the server must keep 409ing on an existing id by default.
expect('overwrite' in body).toBe(false);
});

it('passes `overwrite: true` through for intentional upgrade / re-install', async () => {
const { client, fetchMock } = createMockClient({ success: true, data: { package: { manifest: MANIFEST } } });
await client.packages.install(MANIFEST, { overwrite: true });

const body = JSON.parse(fetchMock.mock.calls[0][1].body);
expect(body.overwrite).toBe(true);
});
});
13 changes: 11 additions & 2 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -592,15 +592,24 @@ export class ObjectStackClient {

/**
* Install a new package from its manifest.
*/
install: async (manifest: any, options?: { settings?: Record<string, any>; enableOnInstall?: boolean }) => {
*
* By default the server rejects a manifest whose `id` is already
* installed with **409 Conflict** (duplicate-id guard) instead of
* silently overwriting the existing package. Intentional upgrade /
* re-install flows opt back in with `overwrite: true`.
*/
install: async (
manifest: any,
options?: { settings?: Record<string, any>; enableOnInstall?: boolean; overwrite?: boolean },
) => {
const route = this.getRoute('packages');
const res = await this.fetch(`${this.baseUrl}${route}`, {
method: 'POST',
body: JSON.stringify({
manifest,
settings: options?.settings,
enableOnInstall: options?.enableOnInstall,
...(options?.overwrite !== undefined ? { overwrite: options.overwrite } : {}),
}),
});
return this.unwrapResponse<{ package: any; message?: string }>(res);
Expand Down