// Copyright 2022 Luca Casonato. All rights reserved. MIT license. /** * Data Portability API Client for Deno * ==================================== * * The Data Portability API lets you build applications that request authorization from a user to move a copy of data from Google services into your application. This enables data portability and facilitates switching services. * * Docs: https://developers.google.com/data-portability * Source: https://googleapis.deno.dev/v1/dataportability:v1.ts */ import { auth, CredentialsClient, GoogleAuth, request } from "/_/base@v1/mod.ts"; export { auth, GoogleAuth }; export type { CredentialsClient }; /** * The Data Portability API lets you build applications that request * authorization from a user to move a copy of data from Google services into * your application. This enables data portability and facilitates switching * services. */ export class DataPortability { #client: CredentialsClient | undefined; #baseUrl: string; constructor(client?: CredentialsClient, baseUrl: string = "https://dataportability.googleapis.com/") { this.#client = client; this.#baseUrl = baseUrl; } /** * Retrieves the state of an Archive job for the Portability API. * * @param name Required. The archive job ID that is returned when you request the state of the job. The format is: archiveJobs/{archive_job}/portabilityArchiveState. archive_job is the job ID returned by the InitiatePortabilityArchiveResponse. */ async archiveJobsGetPortabilityArchiveState(name: string): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }`); const data = await request(url.href, { client: this.#client, method: "GET", }); return data as PortabilityArchiveState; } /** * Retries a failed Portability Archive job. * * @param name Required. The Archive job ID you're retrying. This is returned by the InitiatePortabilityArchiveResponse. Retrying is only executed if the initial job failed. */ async archiveJobsRetry(name: string, req: RetryPortabilityArchiveRequest): Promise { const url = new URL(`${this.#baseUrl}v1/${ name }:retry`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as RetryPortabilityArchiveResponse; } /** * Revokes OAuth tokens and resets exhausted scopes for a user/project pair. * This method allows you to initiate a request after a new consent is * granted. This method also indicates that previous archives can be garbage * collected. You should call this method when all jobs are complete and all * archives are downloaded. Do not call it only when you start a new job. * */ async authorizationReset(req: ResetAuthorizationRequest): Promise { const url = new URL(`${this.#baseUrl}v1/authorization:reset`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as Empty; } /** * Initiates a new Archive job for the Portability API. * */ async portabilityArchiveInitiate(req: InitiatePortabilityArchiveRequest): Promise { const url = new URL(`${this.#baseUrl}v1/portabilityArchive:initiate`); const body = JSON.stringify(req); const data = await request(url.href, { client: this.#client, method: "POST", body, }); return data as InitiatePortabilityArchiveResponse; } } /** * A generic empty message that you can re-use to avoid defining duplicated * empty messages in your APIs. A typical example is to use it as the request or * the response type of an API method. For instance: service Foo { rpc * Bar(google.protobuf.Empty) returns (google.protobuf.Empty); } */ export interface Empty { } /** * Request to kick off an Archive job. */ export interface InitiatePortabilityArchiveRequest { /** * The resources from which you're exporting data. These values have a 1:1 * correspondence with the OAuth scopes. */ resources?: string[]; } /** * Response from initiating an Archive job. */ export interface InitiatePortabilityArchiveResponse { /** * The archive job ID that is initiated in the API. This can be used to get * the state of the job. */ archiveJobId?: string; } /** * Resource that contains the state of an Archive job. */ export interface PortabilityArchiveState { /** * The resource name of ArchiveJob's PortabilityArchiveState singleton. The * format is: archiveJobs/{archive_job}/portabilityArchiveState. archive_job * is the job ID provided in the request. */ name?: string; /** * Resource that represents the state of the Archive job. */ state?: | "STATE_UNSPECIFIED" | "IN_PROGRESS" | "COMPLETE" | "FAILED" | "CANCELLED"; /** * If the state is complete, this method returns the signed URLs of the * objects in the Cloud Storage bucket. */ urls?: string[]; } /** * Request to reset exhausted OAuth scopes. */ export interface ResetAuthorizationRequest { } /** * Request to retry a failed Portability Archive job. */ export interface RetryPortabilityArchiveRequest { } /** * Response from retrying a Portability Archive. */ export interface RetryPortabilityArchiveResponse { /** * The archive job ID that is initiated by the retry endpoint. This can be * used to get the state of the new job. */ archiveJobId?: string; }