Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/box/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Box

This is a small example Pack that demonstrates how to create an action formula that uploads a file to Box. The primary purpose of this example is to demonstrate how to use the `form-data` NPM library to send `multipart/form-data` payloads with the Fetcher.
This is a small example Plugin that demonstrates how to create an action formula that uploads a file to Box. The primary purpose of this example is to demonstrate how to use the `form-data` NPM library to send `multipart/form-data` payloads with the Fetcher.

## Setup

Expand All @@ -12,7 +12,7 @@ as your "Redirect URIs" in order to run these examples locally. To run them
on Coda after uploading & releasing, your authorization callback URL must change to be
**`https://coda.io/packsAuth/oauth2/{PACK_ID}`**.

Run `coda auth examples/box/pack.ts`. You'll be prompted to enter your client id
Run `packs auth examples/box/pack.ts`. You'll be prompted to enter your client id
and client secret, and then your browser will open and begin Box's OAuth flow.
After the flow completes, the access token for that account will saved locally
for use when executing formulas and syncs, so you only have to do this once. But you can
Expand All @@ -24,7 +24,7 @@ becomes invalid.
To upload a file run:

```bash
coda execute examples/box/pack.ts UploadFile "{FILE_URL}"
packs execute examples/box/pack.ts UploadFile "{FILE_URL}"
```

The file URL must be hosted on `codahosted.io`, which is where Coda stores uploaded files and images. You can test with this value:
Expand Down
8 changes: 4 additions & 4 deletions examples/box/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as ContentDisposition from "content-disposition";
import type {Folder} from "./types";
import type {User} from "./types";
import * as coda from "@superhuman/plugins-sdk";
import * as mime from "mime-types";
import * as sdk from "@superhuman/plugins-sdk";

export async function searchFolders(
context: coda.ExecutionContext,
context: sdk.ExecutionContext,
search: string,
): Promise<Folder[]> {
let url = coda.withQueryParams("https://api.box.com/2.0/search", {
let url = sdk.withQueryParams("https://api.box.com/2.0/search", {
type: "folder",
// If no query has been entered, search for "folder" to find all folders.
query: search || "folder",
Expand All @@ -22,7 +22,7 @@ export async function searchFolders(
return response.body.entries;
}

export async function getUser(context: coda.ExecutionContext): Promise<User> {
export async function getUser(context: sdk.ExecutionContext): Promise<User> {
let response = await context.fetcher.fetch({
method: "GET",
url: "https://api.box.com/2.0/users/me",
Expand Down
20 changes: 10 additions & 10 deletions examples/box/pack.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import FormData from "form-data";
import * as coda from "@superhuman/plugins-sdk";
import {getFilename} from "./helpers";
import {getUser} from "./helpers";
import * as sdk from "@superhuman/plugins-sdk";
import {searchFolders} from "./helpers";

export const pack = coda.newPack();
export const pack = sdk.newPack();

pack.addNetworkDomain("box.com");

pack.setUserAuthentication({
type: coda.AuthenticationType.OAuth2,
type: sdk.AuthenticationType.OAuth2,
authorizationUrl: "https://account.box.com/api/oauth2/authorize",
tokenUrl: "https://api.box.com/oauth2/token",
getConnectionName: async function (context) {
Expand All @@ -22,20 +22,20 @@ pack.addFormula({
name: "UploadFile",
description: "Uploads a file to Box.",
parameters: [
coda.makeParameter({
type: coda.ParameterType.File,
sdk.makeParameter({
type: sdk.ParameterType.File,
name: "file",
description: "The file to upload.",
}),
coda.makeParameter({
type: coda.ParameterType.String,
sdk.makeParameter({
type: sdk.ParameterType.String,
name: "filename",
description:
"The filename to upload to. Default: the original filename of the file.",
optional: true,
}),
coda.makeParameter({
type: coda.ParameterType.String,
sdk.makeParameter({
type: sdk.ParameterType.String,
name: "folderId",
description:
"The ID of the folder to upload to. Default: the root folder.",
Expand All @@ -51,7 +51,7 @@ pack.addFormula({
},
}),
],
resultType: coda.ValueType.String,
resultType: sdk.ValueType.String,
isAction: true,
execute: async function (args, context) {
let [fileUrl, filename, folderId = "0"] = args;
Expand Down
8 changes: 4 additions & 4 deletions examples/dictionary/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ with Merriam-Webster.

## Running the Example

Run `coda auth examples/dictionary/pack.ts` and enter your API key.
Run `packs auth examples/dictionary/pack.ts` and enter your API key.

Then run `coda execute examples/dictionary/pack.ts Define coda` to look
Then run `packs execute examples/dictionary/pack.ts Define coda` to look
up definitions for a word, in this case `coda`.

## Running the Tests

Run the unittests just for this Pack by using:
Run the unittests just for this Plugin by using:

```bash
mocha --require ts-node/register examples/dictionary/test/dictionary_test.ts
Expand All @@ -24,7 +24,7 @@ The unittests use a mock http fetcher and do not connect to a real API.

There is also an integration test, which makes real http requests to the API.
To run successfully, this test requires that you've set up an API key already
using `coda auth examples/dictionary/pack.ts`.
using `packs auth examples/dictionary/pack.ts`.

```bash
mocha --require ts-node/register examples/dictionary/test/dictionary_integration.ts
Expand Down
4 changes: 2 additions & 2 deletions examples/dictionary/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type * as coda from "@superhuman/plugins-sdk";
import type * as sdk from "@superhuman/plugins-sdk";
import type * as types from "./types";

const API_VERSION = "v3";

export async function lookupDefinition(
context: coda.ExecutionContext,
context: sdk.ExecutionContext,
word: string,
): Promise<types.CodaDefinition[]> {
let escapedWord = encodeURIComponent(word);
Expand Down
22 changes: 11 additions & 11 deletions examples/dictionary/pack.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import * as coda from "@superhuman/plugins-sdk";
import * as helpers from "./helpers";
import * as schemas from "./schemas";
import * as sdk from "@superhuman/plugins-sdk";

export const pack = coda.newPack();
export const pack = sdk.newPack();

// The Merriam-Webster API uses an API token, which should be included in
// request urls in a "key=" parameter, so we configure that here. When
// running `coda auth examples/dictionary/pack.ts` you will be prompted
// to enter your API key to use when using `coda execute` to exercise formulas
// in this pack. Users would be prompted to enter an API key when installing
// this pack in the Coda UI.
// running `packs auth examples/dictionary/pack.ts` you will be prompted
// to enter your API key to use when using `packs execute` to exercise formulas
// in this plugin. Users would be prompted to enter an API key when installing
// this plugin in the Coda UI.
pack.setUserAuthentication({
type: coda.AuthenticationType.QueryParamToken,
type: sdk.AuthenticationType.QueryParamToken,
paramName: "key",
});

// This tells Coda which domain the pack make requests to. Any fetcher
// This tells Coda which domain the plugin make requests to. Any fetcher
// requests to other domains won't be allowed.
pack.addNetworkDomain("dictionaryapi.com");

pack.addFormula({
resultType: coda.ValueType.Object,
resultType: sdk.ValueType.Object,
name: "Define",
description: "Returns the definition and other metadata for a given word.",
parameters: [
coda.makeParameter({
type: coda.ParameterType.String,
sdk.makeParameter({
type: sdk.ParameterType.String,
name: "word",
description: "A word to define.",
}),
Expand Down
24 changes: 12 additions & 12 deletions examples/dictionary/schemas.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import * as coda from "@superhuman/plugins-sdk";
import * as sdk from "@superhuman/plugins-sdk";

export const DefinitionSchema = coda.makeObjectSchema({
export const DefinitionSchema = sdk.makeObjectSchema({
properties: {
id: {type: coda.ValueType.String, required: true},
id: {type: sdk.ValueType.String, required: true},
definitions: {
type: coda.ValueType.Array,
items: {type: coda.ValueType.String},
type: sdk.ValueType.Array,
items: {type: sdk.ValueType.String},
required: true,
},
headword: {type: coda.ValueType.String, required: true},
partOfSpeech: {type: coda.ValueType.String},
firstUse: {type: coda.ValueType.String},
offensive: {type: coda.ValueType.Boolean, required: true},
headword: {type: sdk.ValueType.String, required: true},
partOfSpeech: {type: sdk.ValueType.String},
firstUse: {type: sdk.ValueType.String},
offensive: {type: sdk.ValueType.Boolean, required: true},
},
// The display property tells Coda which of your object's properties
// should be used as a label for your object. Pack objects will be rendered
// should be used as a label for your object. Plugin objects will be rendered
// as a chip showing the label, and the rest of the fields will show up
// when hovering over the chip.
displayProperty: "headword",
});

export const DefinitionArraySchema = coda.makeSchema({
type: coda.ValueType.Array,
export const DefinitionArraySchema = sdk.makeSchema({
type: sdk.ValueType.Array,
items: DefinitionSchema,
});
6 changes: 3 additions & 3 deletions examples/dictionary/test/dictionary_integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {executeFormulaFromPackDef} from "@superhuman/plugins-sdk/dist/developmen
import {it} from "mocha";
import {pack} from "../pack";

describe("Dictionary pack integration test", () => {
describe("Dictionary plugin integration test", () => {
it("executes Define", async () => {
// Here we execute the formula using a real http fetcher. Since this pack
// Here we execute the formula using a real http fetcher. Since this plugin
// requires authentication, this requires that you've already run
// `coda auth examples/dictionary/pack.ts` to set up an API key.
// `packs auth examples/dictionary/pack.ts` to set up an API key.
let response = await executeFormulaFromPackDef<any[]>(
pack,
"Define",
Expand Down
6 changes: 3 additions & 3 deletions examples/dictionary/test/dictionary_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {newMockExecutionContext} from "@superhuman/plugins-sdk/dist/development"
import {pack} from "../pack";
import * as sinon from "sinon";

describe("Dictionary pack", () => {
describe("Dictionary plugin", () => {
let context: MockExecutionContext;

beforeEach(() => {
Expand Down Expand Up @@ -48,7 +48,7 @@ describe("Dictionary pack", () => {
assert.equal(1, response.length);
// The response object has gone through normalization, standardizing the
// capitalization and formatting of object propery names to be consistent
// across packs.
// across plugins.
assert.deepEqual(response[0], {
Id: "foo",
Definitions: ["definition of foo"],
Expand All @@ -63,7 +63,7 @@ describe("Dictionary pack", () => {
});
});

// It's important to verify how your pack behaves in edges cases. We've
// It's important to verify how your plugin behaves in edges cases. We've
// checked that the real API returns an empty list as a response when it
// cannot find the input word, so we simulate that here, and make sure
// that our implementation doesn't throw any errors.
Expand Down
4 changes: 2 additions & 2 deletions examples/dictionary/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// A single response entry as described at https://dictionaryapi.com/products/json.
// The http response from the API consists of an array of these objects.
// For simplicity, we only include the subset of fields that care about for
// this pack.
// this plugin.
export interface APIEntry {
// One or more practical definitions of the word.
shortdef: string[];
Expand All @@ -29,7 +29,7 @@ export interface APIEntry {
}

/**
* Type definitions for the transformed objects returned by the pack.
* Type definitions for the transformed objects returned by the plugin.
* Generally these types match the schema(s) you define in schemas.ts.
*/

Expand Down
14 changes: 7 additions & 7 deletions examples/github/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# GitHub

This is a more substantive example Pack that connects to GitHub using OAuth2 authentication,
This is a more substantive example Plugin that connects to GitHub using OAuth2 authentication,
and implements a table that syncs various pull requests for one or more repos that the
user has access to, as well as an action formula to post a pull request review.

Expand All @@ -15,7 +15,7 @@ on Coda after uploading & releasing, your authorization callback URL must change

## Running the Example

Run `coda auth examples/github/pack.ts`. You'll be prompted to enter you client id
Run `packs auth examples/github/pack.ts`. You'll be prompted to enter you client id
and client secret, and then your browser will open and begin GitHub's OAuth flow.
After the flow completes, the access token for that account will saved locally
for use when executing formulas and syncs, so you only have to do this once. But you can
Expand All @@ -25,13 +25,13 @@ becomes invalid.
To sync pull requests and output them to the console, you can run:

```bash
coda execute examples/github/pack.ts PullRequests https://github.com/<your-org>/<your-repo>
packs execute examples/github/pack.ts PullRequests https://github.com/<your-org>/<your-repo>
```

To create a review on a pull request, you can run:

```bash
coda execute examples/github/pack.ts ReviewPullRequest https://github.com/<your-org>/<your-repo>/pull/<your-pr> COMMENT "Some comment"
packs execute examples/github/pack.ts ReviewPullRequest https://github.com/<your-org>/<your-repo>/pull/<your-pr> COMMENT "Some comment"
```

Note that this will actually update your pull request in GitHub! So be careful and make
Expand All @@ -40,7 +40,7 @@ sure you don't inadvertently e.g. approve a real PR if you're just exploring.
To execute the example `PullRequests` table sync, run:

```bash
coda execute examples/github/pack.ts PullRequests https://github.com/<your-org>/<your-repo>
packs execute examples/github/pack.ts PullRequests https://github.com/<your-org>/<your-repo>
```

This will fetch all of the pull requests in that repo, using multiple requests if there are multiple result
Expand All @@ -51,7 +51,7 @@ parameter to the sync.)

## Running the Tests

Run the unittests just for this Pack by using:
Run the unittests just for this Plugin by using:

```bash
mocha --require ts-node/register examples/github/test/github_test.ts
Expand All @@ -61,7 +61,7 @@ The unittests use a mock http fetcher and do not connect to a real API.

There is also an integration test, which makes real http requests to the API.
To run successfully, this test requires that you've already setup an access token
using `coda auth examples/github/pack.ts`.
using `packs auth examples/github/pack.ts`.

```bash
mocha --require ts-node/register examples/github/test/github_integration.ts
Expand Down
Loading
Loading