diff --git a/packages/client/src/scw/locality.ts b/packages/client/src/scw/locality.ts index a9920b6be..4798ab4f2 100644 --- a/packages/client/src/scw/locality.ts +++ b/packages/client/src/scw/locality.ts @@ -13,3 +13,27 @@ export type Zone = | 'pl-waw-3' | (string & {}) /* eslint-enable @typescript-eslint/ban-types */ + +export type ApiLocality = + | { type: 'zone'; zones: Zone[] } + | { type: 'region'; regions: Region[] } + | { type: 'global' } + | { type: 'unspecified' } + + +export function toApiLocality( + legacy?: { zones?: Zone[]; regions?: Region[] } +): ApiLocality { + if (!legacy) { + return { type: 'unspecified' } + } + const { zones, regions } = legacy + if (zones && zones.length > 0) { + return { type: 'zone', zones } + } + if (regions && regions.length > 0) { + return { type: 'region', regions } + } + + return { type: 'global' } +}