diff --git a/packages/clients/src/api/ipfs/v1alpha1/api.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/api.gen.ts index ea266a15e..d618402dd 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/api.gen.ts @@ -8,15 +8,21 @@ import { waitForResource, } from '../../../bridge' import type { Region, WaitForOptions } from '../../../bridge' -import { PIN_TRANSIENT_STATUSES } from './content.gen' +import { NAME_TRANSIENT_STATUSES, PIN_TRANSIENT_STATUSES } from './content.gen' import { marshalCreatePinByCIDRequest, marshalCreatePinByURLRequest, marshalCreateVolumeRequest, + marshalIpnsApiCreateNameRequest, + marshalIpnsApiImportKeyNameRequest, + marshalIpnsApiUpdateNameRequest, marshalReplacePinRequest, marshalUpdateVolumeRequest, + unmarshalExportKeyNameResponse, + unmarshalListNamesResponse, unmarshalListPinsResponse, unmarshalListVolumesResponse, + unmarshalName, unmarshalPin, unmarshalReplacePinResponse, unmarshalVolume, @@ -27,12 +33,22 @@ import type { CreateVolumeRequest, DeletePinRequest, DeleteVolumeRequest, + ExportKeyNameResponse, GetPinRequest, GetVolumeRequest, + IpnsApiCreateNameRequest, + IpnsApiDeleteNameRequest, + IpnsApiExportKeyNameRequest, + IpnsApiGetNameRequest, + IpnsApiImportKeyNameRequest, + IpnsApiListNamesRequest, + IpnsApiUpdateNameRequest, + ListNamesResponse, ListPinsRequest, ListPinsResponse, ListVolumesRequest, ListVolumesResponse, + Name, Pin, ReplacePinRequest, ReplacePinResponse, @@ -328,3 +344,179 @@ export class API extends ParentAPI { urlParams: urlParams(['volume_id', request.volumeId]), }) } + +/** IPFS Naming service API. */ +export class IpnsAPI extends ParentAPI { + /** Lists the available regions of the API. */ + public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw'] + + /** + * Create a new name. You can use the `ipns key` command to list and generate + * more names and their respective keys. + * + * @param request - The request {@link IpnsApiCreateNameRequest} + * @returns A Promise of Name + */ + createName = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalIpnsApiCreateNameRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names`, + }, + unmarshalName, + ) + + /** + * Get information about a name. Retrieve information about a specific name. + * + * @param request - The request {@link IpnsApiGetNameRequest} + * @returns A Promise of Name + */ + getName = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names/${validatePathParam('nameId', request.nameId)}`, + }, + unmarshalName, + ) + + /** + * Waits for {@link Name} to be in a final state. + * + * @param request - The request {@link GetNameRequest} + * @param options - The waiting options + * @returns A Promise of Name + */ + waitForName = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => Promise.resolve(!NAME_TRANSIENT_STATUSES.includes(res.status))), + this.getName, + request, + options, + ) + + /** + * Delete an existing name. Delete a name by its ID. + * + * @param request - The request {@link IpnsApiDeleteNameRequest} + */ + deleteName = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names/${validatePathParam('nameId', request.nameId)}`, + }) + + protected pageOfListNames = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names`, + urlParams: urlParams( + ['order_by', request.orderBy ?? 'created_at_asc'], + ['organization_id', request.organizationId], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['project_id', request.projectId], + ), + }, + unmarshalListNamesResponse, + ) + + /** + * List all names by a Project ID. Retrieve information about all names from a + * Project ID. + * + * @param request - The request {@link IpnsApiListNamesRequest} + * @returns A Promise of ListNamesResponse + */ + listNames = (request: Readonly = {}) => + enrichForPagination('names', this.pageOfListNames, request) + + /** + * Update name information. Update name information (CID, tag, name...). + * + * @param request - The request {@link IpnsApiUpdateNameRequest} + * @returns A Promise of Name + */ + updateName = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalIpnsApiUpdateNameRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names/${validatePathParam('nameId', request.nameId)}`, + }, + unmarshalName, + ) + + /** + * Export your private key. Export a private key by its ID. + * + * @param request - The request {@link IpnsApiExportKeyNameRequest} + * @returns A Promise of ExportKeyNameResponse + */ + exportKeyName = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names/${validatePathParam('nameId', request.nameId)}/export-key`, + }, + unmarshalExportKeyNameResponse, + ) + + /** + * Import your private key. Import a private key. + * + * @param request - The request {@link IpnsApiImportKeyNameRequest} + * @returns A Promise of Name + */ + importKeyName = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalIpnsApiImportKeyNameRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names/import-key`, + }, + unmarshalName, + ) +} diff --git a/packages/clients/src/api/ipfs/v1alpha1/content.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/content.gen.ts index 0e003479e..703dee887 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/content.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/content.gen.ts @@ -1,6 +1,9 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. -import type { PinStatus } from './types.gen' +import type { NameStatus, PinStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link NameStatus}. */ +export const NAME_TRANSIENT_STATUSES: NameStatus[] = ['queued', 'publishing'] /** Lists transient statutes of the enum {@link PinStatus}. */ export const PIN_TRANSIENT_STATUSES: PinStatus[] = ['queued', 'pinning'] diff --git a/packages/clients/src/api/ipfs/v1alpha1/index.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/index.gen.ts index 75f4571bb..0db5bb1db 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/index.gen.ts @@ -1,6 +1,6 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. -export { API } from './api.gen' +export { API, IpnsAPI } from './api.gen' export * from './content.gen' export type { CreatePinByCIDRequest, @@ -8,14 +8,26 @@ export type { CreateVolumeRequest, DeletePinRequest, DeleteVolumeRequest, + ExportKeyNameResponse, GetPinRequest, GetVolumeRequest, + IpnsApiCreateNameRequest, + IpnsApiDeleteNameRequest, + IpnsApiExportKeyNameRequest, + IpnsApiGetNameRequest, + IpnsApiImportKeyNameRequest, + IpnsApiListNamesRequest, + IpnsApiUpdateNameRequest, + ListNamesRequestOrderBy, + ListNamesResponse, ListPinsRequest, ListPinsRequestOrderBy, ListPinsResponse, ListVolumesRequest, ListVolumesRequestOrderBy, ListVolumesResponse, + Name, + NameStatus, Pin, PinCID, PinCIDMeta, diff --git a/packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts index 5669009e4..3315cb3a0 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts @@ -10,8 +10,14 @@ import type { CreatePinByCIDRequest, CreatePinByURLRequest, CreateVolumeRequest, + ExportKeyNameResponse, + IpnsApiCreateNameRequest, + IpnsApiImportKeyNameRequest, + IpnsApiUpdateNameRequest, + ListNamesResponse, ListPinsResponse, ListVolumesResponse, + Name, Pin, PinCID, PinCIDMeta, @@ -64,6 +70,27 @@ const unmarshalPinInfo = (data: unknown) => { } as PinInfo } +export const unmarshalName = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Name' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + key: data.key, + name: data.name, + nameId: data.name_id, + projectId: data.project_id, + region: data.region, + status: data.status, + tags: data.tags, + updatedAt: unmarshalDate(data.updated_at), + value: data.value, + } as Name +} + export const unmarshalPin = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -101,6 +128,36 @@ export const unmarshalVolume = (data: unknown) => { } as Volume } +export const unmarshalExportKeyNameResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ExportKeyNameResponse' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + nameId: data.name_id, + privateKey: data.private_key, + projectId: data.project_id, + publicKey: data.public_key, + updatedAt: unmarshalDate(data.updated_at), + } as ExportKeyNameResponse +} + +export const unmarshalListNamesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListNamesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + names: unmarshalArrayOfObject(data.names, unmarshalName), + totalCount: data.total_count, + } as ListNamesResponse +} + export const unmarshalListPinsResponse = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -180,6 +237,34 @@ export const marshalCreateVolumeRequest = ( project_id: request.projectId ?? defaults.defaultProjectId, }) +export const marshalIpnsApiCreateNameRequest = ( + request: IpnsApiCreateNameRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + project_id: request.projectId ?? defaults.defaultProjectId, + value: request.value, +}) + +export const marshalIpnsApiImportKeyNameRequest = ( + request: IpnsApiImportKeyNameRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + private_key: request.privateKey, + project_id: request.projectId ?? defaults.defaultProjectId, + value: request.value, +}) + +export const marshalIpnsApiUpdateNameRequest = ( + request: IpnsApiUpdateNameRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + tags: request.tags, + value: request.value, +}) + export const marshalReplacePinRequest = ( request: ReplacePinRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/ipfs/v1alpha1/types.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/types.gen.ts index ad18ef3ba..cff9ebc3f 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/types.gen.ts @@ -2,10 +2,19 @@ // If you have any remark or suggestion do not hesitate to open an issue. import type { Region } from '../../../bridge' +export type ListNamesRequestOrderBy = 'created_at_asc' | 'created_at_desc' + export type ListPinsRequestOrderBy = 'created_at_asc' | 'created_at_desc' export type ListVolumesRequestOrderBy = 'created_at_asc' | 'created_at_desc' +export type NameStatus = + | 'unknown_status' + | 'queued' + | 'publishing' + | 'failed' + | 'published' + export type PinDetails = | 'unknown_details' | 'pinning_looking_for_provider' @@ -36,6 +45,20 @@ export type PinStatus = | 'failed' | 'pinned' +export interface ExportKeyNameResponse { + nameId: string + projectId: string + createdAt?: Date + updatedAt?: Date + publicKey: string + privateKey: string +} + +export interface ListNamesResponse { + names: Name[] + totalCount: number +} + export interface ListPinsResponse { totalCount: number pins: Pin[] @@ -46,6 +69,19 @@ export interface ListVolumesResponse { totalCount: number } +export interface Name { + nameId: string + projectId: string + createdAt?: Date + updatedAt?: Date + tags: string[] + name: string + key: string + status: NameStatus + value: string + region: Region +} + export interface Pin { pinId: string status: PinStatus @@ -256,3 +292,97 @@ export type DeletePinRequest = { /** Volume ID. */ volumeId: string } + +export type IpnsApiCreateNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Project ID. */ + projectId?: string + /** Name for your records. */ + name: string + /** Value you want to associate with your records, CID or IPNS key. */ + value: string +} + +export type IpnsApiGetNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Name ID whose information you want to retrieve. */ + nameId: string +} + +export type IpnsApiDeleteNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Name ID you wish to delete. */ + nameId: string +} + +export type IpnsApiListNamesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Project ID. */ + projectId?: string + /** Organization ID. */ + organizationId?: string + /** Sort the order of the returned names. */ + orderBy?: ListNamesRequestOrderBy + /** Page number. */ + page?: number + /** Maximum number of names to return per page. */ + pageSize?: number +} + +export type IpnsApiUpdateNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Name ID you wish to update. */ + nameId: string + /** New name you want to associate with your record. */ + name?: string + /** New tags you want to associate with your record. */ + tags?: string[] + /** Value you want to associate with your records, CID or IPNS key. */ + value?: string +} + +export type IpnsApiExportKeyNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Name ID whose keys you want to export. */ + nameId: string +} + +export type IpnsApiImportKeyNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Project ID. */ + projectId?: string + /** Name for your records. */ + name: string + /** Base64 private key. */ + privateKey: string + /** Value you want to associate with your records, CID or IPNS key. */ + value: string +}