main
/**
* Remotes domain: remote CRUD plus fetch / push / mirror-import.
* Tokens are per-request only — the server never stores them.
*/
import { unwrapApi } from '@app/lib'
import type {
EnvelopeFetchResultDto,
EnvelopeImportResultDto,
EnvelopePushResultDto,
EnvelopeVecRemoteDto,
} from '@app/services/api'
import Apis from '@app/services/api'
export type RemoteRow = NonNullable<EnvelopeVecRemoteDto['data']>[number]
export type FetchResult = NonNullable<EnvelopeFetchResultDto['data']>
export type PushResult = NonNullable<EnvelopePushResultDto['data']>
export type ImportResult = NonNullable<EnvelopeImportResultDto['data']>
export const listRemotes = (space: string, repo: string) =>
unwrapApi<RemoteRow[]>(Apis.remotes.list_remotes({ pathParams: { space_name: space, repo_name: repo } }))
export const upsertRemote = (space: string, repo: string, name: string, url: string) =>
unwrapApi<null>(
Apis.remotes.upsert_remote({
pathParams: { space_name: space, repo_name: repo, name },
data: { url },
}),
)
export const removeRemote = (space: string, repo: string, name: string) =>
unwrapApi<null>(Apis.remotes.remove({ pathParams: { space_name: space, repo_name: repo, name } }))
/** `token` is sent per request only — it is never stored on the server. */
export const fetchRemote = (space: string, repo: string, name: string, token?: string) =>
unwrapApi<FetchResult>(
Apis.remotes.fetch({
pathParams: { space_name: space, repo_name: repo },
data: { remote: name, auth: token ? { token } : null },
}),
)
export const pushRemote = (space: string, repo: string, name: string, refspec?: string, token?: string) =>
unwrapApi<PushResult>(
Apis.remotes.push({
pathParams: { space_name: space, repo_name: repo },
data: { remote: name, refspec: refspec || null, auth: token ? { token } : null },
}),
)
/** Mirror-import every ref from an external URL into this repo. */
export const importRemote = (space: string, repo: string, url: string, token?: string) =>
unwrapApi<ImportResult>(
Apis.remotes.clone_import({
pathParams: { space_name: space, repo_name: repo },
data: { url, auth: token ? { token } : null },
}),
)