Skip to content

Latest commit

 

History

History
459 lines (349 loc) · 30.7 KB

File metadata and controls

459 lines (349 loc) · 30.7 KB

Files

Overview

Available Operations

list

List files.

Scopes: files:read files:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.files.list({
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
  });

  for await (const page of result) {
    console.log(page);
  }
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { filesList } from "@polar-sh/sdk/funcs/filesList.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await filesList(polar, {
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
  });
  if (res.ok) {
    const { value: result } = res;
    for await (const page of result) {
    console.log(page);
  }
  } else {
    console.log("filesList failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.FilesListRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<operations.FilesListResponse>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

create

Create a file.

Scopes: files:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.files.create({
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    name: "<value>",
    mimeType: "<value>",
    size: 612128,
    upload: {
      parts: [],
    },
    service: "downloadable",
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { filesCreate } from "@polar-sh/sdk/funcs/filesCreate.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await filesCreate(polar, {
    organizationId: "1dbfc517-0bbf-4301-9ba8-555ca42b9737",
    name: "<value>",
    mimeType: "<value>",
    size: 612128,
    upload: {
      parts: [],
    },
    service: "downloadable",
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("filesCreate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request components.FileCreate ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.FileUpload>

Errors

Error Type Status Code Content Type
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

uploaded

Complete a file upload.

Scopes: files:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.files.uploaded({
    id: "<value>",
    fileUploadCompleted: {
      id: "<id>",
      path: "/boot",
      parts: [
        {
          number: 979613,
          checksumEtag: "<value>",
          checksumSha256Base64: "<value>",
        },
        {
          number: 979613,
          checksumEtag: "<value>",
          checksumSha256Base64: "<value>",
        },
        {
          number: 979613,
          checksumEtag: "<value>",
          checksumSha256Base64: "<value>",
        },
      ],
    },
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { filesUploaded } from "@polar-sh/sdk/funcs/filesUploaded.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await filesUploaded(polar, {
    id: "<value>",
    fileUploadCompleted: {
      id: "<id>",
      path: "/boot",
      parts: [
        {
          number: 979613,
          checksumEtag: "<value>",
          checksumSha256Base64: "<value>",
        },
        {
          number: 979613,
          checksumEtag: "<value>",
          checksumSha256Base64: "<value>",
        },
        {
          number: 979613,
          checksumEtag: "<value>",
          checksumSha256Base64: "<value>",
        },
      ],
    },
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("filesUploaded failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.FilesUploadedRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.FileRead>

Errors

Error Type Status Code Content Type
errors.NotPermitted 403 application/json
errors.ResourceNotFound 404 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

delete

Delete a file.

Scopes: files:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  await polar.files.delete({
    id: "<value>",
  });


}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { filesDelete } from "@polar-sh/sdk/funcs/filesDelete.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await filesDelete(polar, {
    id: "<value>",
  });
  if (res.ok) {
    const { value: result } = res;
    
  } else {
    console.log("filesDelete failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.FilesDeleteRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<void>

Errors

Error Type Status Code Content Type
errors.NotPermitted 403 application/json
errors.ResourceNotFound 404 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*

update

Update a file.

Scopes: files:write

Example Usage

import { Polar } from "@polar-sh/sdk";

const polar = new Polar({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const result = await polar.files.update({
    id: "<value>",
    filePatch: {},
  });

  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { PolarCore } from "@polar-sh/sdk/core.js";
import { filesUpdate } from "@polar-sh/sdk/funcs/filesUpdate.js";

// Use `PolarCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const polar = new PolarCore({
  accessToken: process.env["POLAR_ACCESS_TOKEN"] ?? "",
});

async function run() {
  const res = await filesUpdate(polar, {
    id: "<value>",
    filePatch: {},
  });
  if (res.ok) {
    const { value: result } = res;
    console.log(result);
  } else {
    console.log("filesUpdate failed:", res.error);
  }
}

run();

Parameters

Parameter Type Required Description
request operations.FilesUpdateRequest ✔️ The request object to use for the request.
options RequestOptions Used to set various options for making HTTP requests.
options.fetchOptions RequestInit Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed.
options.retries RetryConfig Enables retrying HTTP requests under certain failure conditions.

Response

Promise<components.FileRead>

Errors

Error Type Status Code Content Type
errors.NotPermitted 403 application/json
errors.ResourceNotFound 404 application/json
errors.HTTPValidationError 422 application/json
errors.SDKError 4XX, 5XX */*