Skip to content

Latest commit

 

History

History
900 lines (682 loc) · 60.2 KB

README.md

File metadata and controls

900 lines (682 loc) · 60.2 KB

Marketplace

(marketplace)

Overview

Available Operations

getAccountInfo

Fetches the best account or user’s contact info

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.marketplace.getAccountInfo({
    integrationConfigurationId: "<id>",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceGetAccountInfo } from "@vercel/sdk/funcs/marketplaceGetAccountInfo.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await marketplaceGetAccountInfo(vercel, {
    integrationConfigurationId: "<id>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request models.GetAccountInfoRequest ✔️ 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<models.GetAccountInfoResponseBody>

Errors

Error Type Status Code Content Type
models.VercelBadRequestError 400 application/json
models.VercelForbiddenError 401 application/json
models.SDKError 4XX, 5XX */*

getMember

Returns the member role and other information for a given member ID ("user_id" claim in the SSO OIDC token).

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.marketplace.getMember({
    integrationConfigurationId: "<id>",
    memberId: "<id>",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceGetMember } from "@vercel/sdk/funcs/marketplaceGetMember.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await marketplaceGetMember(vercel, {
    integrationConfigurationId: "<id>",
    memberId: "<id>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request models.GetMemberRequest ✔️ 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<models.GetMemberResponseBody>

Errors

Error Type Status Code Content Type
models.VercelBadRequestError 400 application/json
models.VercelForbiddenError 401 application/json
models.VercelNotFoundError 404 application/json
models.SDKError 4XX, 5XX */*

createEvent

Partner notifies Vercel of any changes made to an Installation or a Resource. Vercel is expected to use list-resources and other read APIs to get the new state.

resource.updated event should be dispatched when any state of a resource linked to Vercel is modified by the partner.

Use cases:

- The user renames a database in the partner’s application. The partner should dispatch a resource.updated event to notify Vercel to update the resource in Vercel’s datastores.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  await vercel.marketplace.createEvent({
    integrationConfigurationId: "<id>",
    requestBody: {
      event: {
        type: "installation.updated",
      },
    },
  });


}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceCreateEvent } from "@vercel/sdk/funcs/marketplaceCreateEvent.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await marketplaceCreateEvent(vercel, {
    integrationConfigurationId: "<id>",
    requestBody: {
      event: {
        type: "installation.updated",
      },
    },
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  
}

run();

Parameters

Parameter Type Required Description
request models.CreateEventRequest ✔️ 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
models.VercelBadRequestError 400 application/json
models.VercelForbiddenError 401 application/json
models.SDKError 4XX, 5XX */*

submitBillingData

Sends the billing and usage data. The partner should do this at least once a day and ideally once per hour.
Use the credentials.access_token we provided in the Upsert Installation body to authorize this request.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  await vercel.marketplace.submitBillingData({
    integrationConfigurationId: "<id>",
    requestBody: {
      timestamp: new Date("2024-09-29T02:38:01.476Z"),
      eod: new Date("2022-12-28T23:46:57.523Z"),
      period: {
        start: new Date("2022-06-25T19:04:50.518Z"),
        end: new Date("2023-10-18T01:18:36.230Z"),
      },
      billing: {
        items: [
          {
            billingPlanId: "<id>",
            name: "<value>",
            price: "330.95",
            quantity: 5852.75,
            units: "<value>",
            total: "<value>",
          },
        ],
      },
      usage: [
        {
          resourceId: "<id>",
          name: "<value>",
          type: "rate",
          units: "<value>",
          dayValue: 9439.21,
          periodValue: 6958.71,
        },
        {
          resourceId: "<id>",
          name: "<value>",
          type: "total",
          units: "<value>",
          dayValue: 9892.22,
          periodValue: 4749.62,
        },
        {
          resourceId: "<id>",
          name: "<value>",
          type: "rate",
          units: "<value>",
          dayValue: 7119.53,
          periodValue: 6310.47,
        },
      ],
    },
  });


}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceSubmitBillingData } from "@vercel/sdk/funcs/marketplaceSubmitBillingData.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await marketplaceSubmitBillingData(vercel, {
    integrationConfigurationId: "<id>",
    requestBody: {
      timestamp: new Date("2024-09-29T02:38:01.476Z"),
      eod: new Date("2022-12-28T23:46:57.523Z"),
      period: {
        start: new Date("2022-06-25T19:04:50.518Z"),
        end: new Date("2023-10-18T01:18:36.230Z"),
      },
      billing: [
        {
          billingPlanId: "<id>",
          name: "<value>",
          price: "495.99",
          quantity: 8962.85,
          units: "<value>",
          total: "<value>",
        },
      ],
      usage: [
        {
          resourceId: "<id>",
          name: "<value>",
          type: "rate",
          units: "<value>",
          dayValue: 9439.21,
          periodValue: 6958.71,
        },
        {
          resourceId: "<id>",
          name: "<value>",
          type: "total",
          units: "<value>",
          dayValue: 9892.22,
          periodValue: 4749.62,
        },
        {
          resourceId: "<id>",
          name: "<value>",
          type: "rate",
          units: "<value>",
          dayValue: 7119.53,
          periodValue: 6310.47,
        },
      ],
    },
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  
}

run();

Parameters

Parameter Type Required Description
request models.SubmitBillingDataRequest ✔️ 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
models.VercelBadRequestError 400 application/json
models.VercelForbiddenError 401 application/json
models.SDKError 4XX, 5XX */*

submitInvoice

This endpoint allows the partner to submit an invoice to Vercel. The invoice is created in Vercel's billing system and sent to the customer. Depending on the type of billing plan, the invoice can be sent at a time of signup, at the start of the billing period, or at the end of the billing period.

Use the credentials.access_token we provided in the Upsert Installation body to authorize this request.
There are several limitations to the invoice submission:

1. A resource can only be billed once per the billing period and the billing plan.
2. The billing plan used to bill the resource must have been active for this resource during the billing period.
3. The billing plan used must be a subscription plan.
4. The interim usage data must be sent hourly for all types of subscriptions. See Send subscription billing and usage data API on how to send interim billing and usage data.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.marketplace.submitInvoice({
    integrationConfigurationId: "<id>",
    requestBody: {
      invoiceDate: new Date("2022-06-05T08:54:16.353Z"),
      period: {
        start: new Date("2022-07-26T14:15:15.601Z"),
        end: new Date("2024-10-08T09:35:48.520Z"),
      },
      items: [
        {
          billingPlanId: "<id>",
          name: "<value>",
          price: "905.89",
          quantity: 1684.76,
          units: "<value>",
          total: "<value>",
        },
        {
          billingPlanId: "<id>",
          name: "<value>",
          price: "84.05",
          quantity: 9130.94,
          units: "<value>",
          total: "<value>",
        },
      ],
    },
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceSubmitInvoice } from "@vercel/sdk/funcs/marketplaceSubmitInvoice.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await marketplaceSubmitInvoice(vercel, {
    integrationConfigurationId: "<id>",
    requestBody: {
      invoiceDate: new Date("2022-06-05T08:54:16.353Z"),
      period: {
        start: new Date("2022-07-26T14:15:15.601Z"),
        end: new Date("2024-10-08T09:35:48.520Z"),
      },
      items: [
        {
          billingPlanId: "<id>",
          name: "<value>",
          price: "905.89",
          quantity: 1684.76,
          units: "<value>",
          total: "<value>",
        },
        {
          billingPlanId: "<id>",
          name: "<value>",
          price: "84.05",
          quantity: 9130.94,
          units: "<value>",
          total: "<value>",
        },
      ],
    },
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request models.SubmitInvoiceRequest ✔️ 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<models.SubmitInvoiceResponseBody>

Errors

Error Type Status Code Content Type
models.VercelBadRequestError 400 application/json
models.VercelForbiddenError 401 application/json
models.SDKError 4XX, 5XX */*

getInvoice

Get Invoice details and status for a given invoice ID.

See Billing Events with Webhooks documentation on how to receive invoice events. This endpoint is used to retrieve the invoice details.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const result = await vercel.marketplace.getInvoice({
    integrationConfigurationId: "<id>",
    invoiceId: "<id>",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceGetInvoice } from "@vercel/sdk/funcs/marketplaceGetInvoice.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await marketplaceGetInvoice(vercel, {
    integrationConfigurationId: "<id>",
    invoiceId: "<id>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request models.GetInvoiceRequest ✔️ 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<models.GetInvoiceResponseBody>

Errors

Error Type Status Code Content Type
models.VercelBadRequestError 400 application/json
models.VercelForbiddenError 401 application/json
models.VercelNotFoundError 404 application/json
models.SDKError 4XX, 5XX */*

updateInvoice

This endpoint allows the partner to request a refund for an invoice to Vercel. The invoice is created using the Submit Invoice API.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  await vercel.marketplace.updateInvoice({
    integrationConfigurationId: "<id>",
    invoiceId: "<id>",
    requestBody: {
      action: "refund",
      reason: "<value>",
      total: "<value>",
    },
  });


}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceUpdateInvoice } from "@vercel/sdk/funcs/marketplaceUpdateInvoice.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await marketplaceUpdateInvoice(vercel, {
    integrationConfigurationId: "<id>",
    invoiceId: "<id>",
    requestBody: {
      action: "refund",
      reason: "<value>",
      total: "<value>",
    },
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  
}

run();

Parameters

Parameter Type Required Description
request models.UpdateInvoiceRequest ✔️ 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
models.VercelBadRequestError 400 application/json
models.VercelForbiddenError 401 application/json
models.VercelNotFoundError 404 application/json
models.SDKError 4XX, 5XX */*

updateResourceSecrets

This endpoint updates the secrets of a resource. If a resource has projects connected, the connected secrets are updated with the new secrets. The old secrets may still be used by existing connected projects because they are not automatically redeployed. Redeployment is a manual action and must be completed by the user. All new project connections will use the new secrets.

Use cases for this endpoint:

- Resetting the credentials of a database in the partner. If the user requests the credentials to be updated in the partner’s application, the partner post the new set of secrets to Vercel, the user should redeploy their application and the expire the old credentials.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  await vercel.marketplace.updateResourceSecrets({
    integrationConfigurationId: "<id>",
    integrationProductIdOrSlug: "<value>",
    resourceId: "<id>",
    requestBody: {
      secrets: [
        {
          name: "<value>",
          value: "<value>",
        },
      ],
    },
  });


}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceUpdateResourceSecrets } from "@vercel/sdk/funcs/marketplaceUpdateResourceSecrets.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore({
  bearerToken: "<YOUR_BEARER_TOKEN_HERE>",
});

async function run() {
  const res = await marketplaceUpdateResourceSecrets(vercel, {
    integrationConfigurationId: "<id>",
    integrationProductIdOrSlug: "<value>",
    resourceId: "<id>",
    requestBody: {
      secrets: [
        {
          name: "<value>",
          value: "<value>",
        },
      ],
    },
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  
}

run();

Parameters

Parameter Type Required Description
request models.UpdateResourceSecretsRequest ✔️ 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
models.VercelBadRequestError 400 application/json
models.VercelForbiddenError 401 application/json
models.VercelNotFoundError 404 application/json
models.SDKError 4XX, 5XX */*

exchangeSsoToken

During the autorization process, Vercel sends the user to the provider redirectLoginUrl, that includes the OAuth authorization code parameter. The provider then calls the SSO Token Exchange endpoint with the sent code and receives the OIDC token. They log the user in based on this token and redirects the user back to the Vercel account using deep-link parameters included the redirectLoginUrl. This is used to verify the identity of the user during the Open in Provider flow. Providers should not persist the returned id_token in a database since the token will expire.

Example Usage

import { Vercel } from "@vercel/sdk";

const vercel = new Vercel();

async function run() {
  const result = await vercel.marketplace.exchangeSsoToken({
    code: "<value>",
    clientId: "<id>",
    clientSecret: "<value>",
  });

  // Handle the result
  console.log(result);
}

run();

Standalone function

The standalone function version of this method:

import { VercelCore } from "@vercel/sdk/core.js";
import { marketplaceExchangeSsoToken } from "@vercel/sdk/funcs/marketplaceExchangeSsoToken.js";

// Use `VercelCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const vercel = new VercelCore();

async function run() {
  const res = await marketplaceExchangeSsoToken(vercel, {
    code: "<value>",
    clientId: "<id>",
    clientSecret: "<value>",
  });

  if (!res.ok) {
    throw res.error;
  }

  const { value: result } = res;

  // Handle the result
  console.log(result);
}

run();

Parameters

Parameter Type Required Description
request models.ExchangeSsoTokenRequestBody ✔️ 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<models.ExchangeSsoTokenResponseBody>

Errors

Error Type Status Code Content Type
models.VercelBadRequestError 400 application/json
models.VercelNotFoundError 404 application/json
models.SDKError 4XX, 5XX */*