Add onConflict query parameter to POST /locations endpoint

Adds an optional `onConflict` query parameter to the location creation
endpoint. When set to 'refresh', a conflict due to an already-registered
location triggers a refresh of the existing location entity instead of
returning a 409 error. The default behavior ('reject') is unchanged.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Signed-off-by: Fredrik Adelöw <freben@spotify.com>
This commit is contained in:
Fredrik Adelöw
2026-03-09 15:35:33 +01:00
parent d0f4cd215b
commit 32e9499caf
13 changed files with 187 additions and 9 deletions
+1
View File
@@ -15,6 +15,7 @@ export type AddLocationRequest = {
type?: string;
target: string;
dryRun?: boolean;
onConflict?: 'refresh' | 'reject';
};
// @public
+5 -2
View File
@@ -567,12 +567,15 @@ export class CatalogClient implements CatalogApi {
request: AddLocationRequest,
options?: CatalogRequestOptions,
): Promise<AddLocationResponse> {
const { type = 'url', target, dryRun } = request;
const { type = 'url', target, dryRun, onConflict } = request;
const response = await this.apiClient.createLocation(
{
body: { type, target },
query: { dryRun: dryRun ? 'true' : undefined },
query: {
dryRun: dryRun ? 'true' : undefined,
onConflict,
},
},
options,
);
@@ -178,6 +178,7 @@ export type CreateLocation = {
body: CreateLocationRequest;
query: {
dryRun?: string;
onConflict?: 'refresh' | 'reject';
};
};
/**
@@ -592,6 +593,7 @@ export class DefaultApiClient {
* Create a location for a given target.
* @param createLocationRequest -
* @param dryRun -
* @param onConflict - Behavior when the location already exists. \&#39;reject\&#39; (default) returns a 409 error, \&#39;refresh\&#39; triggers a refresh of the existing location entity and returns 201.
*/
public async createLocation(
// @ts-ignore
@@ -600,7 +602,7 @@ export class DefaultApiClient {
): Promise<TypedResponse<CreateLocation201Response>> {
const baseUrl = await this.discoveryApi.getBaseUrl(pluginId);
const uriTemplate = `/locations{?dryRun}`;
const uriTemplate = `/locations{?dryRun,onConflict}`;
const uri = parser.parse(uriTemplate).expand({
...request.query,
+6
View File
@@ -396,6 +396,12 @@ export type AddLocationRequest = {
* contain the entities that match the given location.
*/
dryRun?: boolean;
/**
* Behavior when the location already exists. If set to `'reject'` (the
* default), a conflict error is returned. If set to `'refresh'`, the
* existing location entity is marked for refresh and a 201 is returned.
*/
onConflict?: 'refresh' | 'reject';
};
/**