Socket
Socket
Sign inDemoInstall

@notionhq/client

Package Overview
Dependencies
Maintainers
13
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@notionhq/client - npm Package Compare versions

Comparing version 2.0.0 to 2.1.0

build/src/utils.d.ts

9

build/package.json
{
"name": "@notionhq/client",
"version": "2.0.0",
"version": "2.1.0",
"description": "A simple and easy to use client for the Notion API",

@@ -30,3 +30,3 @@ "engines": {

"lint": "prettier --check . && eslint . --ext .ts && cspell '**/*' ",
"test": "ava",
"test": "jest ./test",
"check-links": "git ls-files | grep md$ | xargs -n 1 markdown-link-check",

@@ -48,12 +48,13 @@ "prebuild": "npm run clean",

"devDependencies": {
"@ava/typescript": "^2.0.0",
"@types/jest": "^28.1.4",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"ava": "^3.15.0",
"cspell": "^5.4.1",
"eslint": "^7.24.0",
"jest": "^28.1.2",
"markdown-link-check": "^3.8.7",
"prettier": "^2.3.0",
"ts-jest": "^28.0.5",
"typescript": "^4.2.4"
}
}

@@ -5,3 +5,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.search = exports.createDatabase = exports.listDatabases = exports.queryDatabase = exports.updateDatabase = exports.getDatabase = exports.appendBlockChildren = exports.listBlockChildren = exports.deleteBlock = exports.updateBlock = exports.getBlock = exports.getPageProperty = exports.updatePage = exports.getPage = exports.createPage = exports.listUsers = exports.getUser = exports.getSelf = void 0;
exports.listComments = exports.createComment = exports.search = exports.createDatabase = exports.listDatabases = exports.queryDatabase = exports.updateDatabase = exports.getDatabase = exports.appendBlockChildren = exports.listBlockChildren = exports.deleteBlock = exports.updateBlock = exports.getBlock = exports.getPageProperty = exports.updatePage = exports.getPage = exports.createPage = exports.listUsers = exports.getUser = exports.getSelf = void 0;
exports.getSelf = {

@@ -179,2 +179,16 @@ method: "get",

};
exports.createComment = {
method: "post",
pathParams: [],
queryParams: [],
bodyParams: ["parent", "rich_text", "discussion_id"],
path: () => `comments`,
};
exports.listComments = {
method: "get",
pathParams: [],
queryParams: ["block_id", "start_cursor", "page_size"],
bodyParams: [],
path: () => `comments`,
};
//# sourceMappingURL=api-endpoints.js.map
/// <reference types="node" />
import type { Agent } from "http";
import { Logger, LogLevel } from "./logging";
import { GetBlockParameters, GetBlockResponse, UpdateBlockParameters, UpdateBlockResponse, DeleteBlockParameters, DeleteBlockResponse, AppendBlockChildrenParameters, AppendBlockChildrenResponse, ListBlockChildrenParameters, ListBlockChildrenResponse, ListDatabasesParameters, ListDatabasesResponse, GetDatabaseParameters, GetDatabaseResponse, QueryDatabaseParameters, QueryDatabaseResponse, CreateDatabaseParameters, CreateDatabaseResponse, UpdateDatabaseParameters, UpdateDatabaseResponse, CreatePageParameters, CreatePageResponse, GetPageParameters, GetPageResponse, UpdatePageParameters, UpdatePageResponse, GetUserParameters, GetUserResponse, ListUsersParameters, ListUsersResponse, SearchParameters, SearchResponse, GetSelfParameters, GetSelfResponse, GetPagePropertyParameters, GetPagePropertyResponse } from "./api-endpoints";
import { GetBlockParameters, GetBlockResponse, UpdateBlockParameters, UpdateBlockResponse, DeleteBlockParameters, DeleteBlockResponse, AppendBlockChildrenParameters, AppendBlockChildrenResponse, ListBlockChildrenParameters, ListBlockChildrenResponse, ListDatabasesParameters, ListDatabasesResponse, GetDatabaseParameters, GetDatabaseResponse, QueryDatabaseParameters, QueryDatabaseResponse, CreateDatabaseParameters, CreateDatabaseResponse, UpdateDatabaseParameters, UpdateDatabaseResponse, CreatePageParameters, CreatePageResponse, GetPageParameters, GetPageResponse, UpdatePageParameters, UpdatePageResponse, GetUserParameters, GetUserResponse, ListUsersParameters, ListUsersResponse, SearchParameters, SearchResponse, GetSelfParameters, GetSelfResponse, GetPagePropertyParameters, GetPagePropertyResponse, CreateCommentParameters, CreateCommentResponse, ListCommentsParameters, ListCommentsResponse } from "./api-endpoints";
import { SupportedFetch } from "./fetch-types";

@@ -120,2 +120,12 @@ export interface ClientOptions {

};
readonly comments: {
/**
* Create a comment
*/
create: (args: WithAuth<CreateCommentParameters>) => Promise<CreateCommentResponse>;
/**
* List comments
*/
list: (args: WithAuth<ListCommentsParameters>) => Promise<ListCommentsResponse>;
};
/**

@@ -122,0 +132,0 @@ * Search

@@ -17,3 +17,3 @@ "use strict";

const errors_1 = require("./errors");
const helpers_1 = require("./helpers");
const utils_1 = require("./utils");
const api_endpoints_1 = require("./api-endpoints");

@@ -45,4 +45,4 @@ const node_fetch_1 = require("node-fetch");

method: api_endpoints_1.getBlock.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.getBlock.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.getBlock.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.getBlock.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.getBlock.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -58,4 +58,4 @@ });

method: api_endpoints_1.updateBlock.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.updateBlock.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.updateBlock.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.updateBlock.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.updateBlock.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -71,4 +71,4 @@ });

method: api_endpoints_1.deleteBlock.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.deleteBlock.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.deleteBlock.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.deleteBlock.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.deleteBlock.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -85,4 +85,4 @@ });

method: api_endpoints_1.appendBlockChildren.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.appendBlockChildren.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.appendBlockChildren.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.appendBlockChildren.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.appendBlockChildren.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -98,4 +98,4 @@ });

method: api_endpoints_1.listBlockChildren.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.listBlockChildren.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.listBlockChildren.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.listBlockChildren.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.listBlockChildren.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -116,4 +116,4 @@ });

method: api_endpoints_1.listDatabases.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.listDatabases.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.listDatabases.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.listDatabases.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.listDatabases.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -129,4 +129,4 @@ });

method: api_endpoints_1.getDatabase.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.getDatabase.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.getDatabase.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.getDatabase.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.getDatabase.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -142,4 +142,4 @@ });

method: api_endpoints_1.queryDatabase.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.queryDatabase.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.queryDatabase.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.queryDatabase.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.queryDatabase.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -155,4 +155,4 @@ });

method: api_endpoints_1.createDatabase.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.createDatabase.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.createDatabase.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.createDatabase.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.createDatabase.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -168,4 +168,4 @@ });

method: api_endpoints_1.updateDatabase.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.updateDatabase.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.updateDatabase.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.updateDatabase.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.updateDatabase.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -183,4 +183,4 @@ });

method: api_endpoints_1.createPage.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.createPage.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.createPage.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.createPage.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.createPage.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -196,4 +196,4 @@ });

method: api_endpoints_1.getPage.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.getPage.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.getPage.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.getPage.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.getPage.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -209,4 +209,4 @@ });

method: api_endpoints_1.updatePage.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.updatePage.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.updatePage.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.updatePage.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.updatePage.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -223,4 +223,4 @@ });

method: api_endpoints_1.getPageProperty.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.getPageProperty.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.getPageProperty.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.getPageProperty.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.getPageProperty.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -239,4 +239,4 @@ });

method: api_endpoints_1.getUser.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.getUser.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.getUser.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.getUser.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.getUser.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -252,4 +252,4 @@ });

method: api_endpoints_1.listUsers.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.listUsers.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.listUsers.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.listUsers.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.listUsers.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -265,4 +265,4 @@ });

method: api_endpoints_1.getSelf.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.getSelf.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.getSelf.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.getSelf.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.getSelf.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -272,2 +272,28 @@ });

};
this.comments = {
/**
* Create a comment
*/
create: (args) => {
return this.request({
path: api_endpoints_1.createComment.path(),
method: api_endpoints_1.createComment.method,
query: (0, utils_1.pick)(args, api_endpoints_1.createComment.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.createComment.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,
});
},
/**
* List comments
*/
list: (args) => {
return this.request({
path: api_endpoints_1.listComments.path(),
method: api_endpoints_1.listComments.method,
query: (0, utils_1.pick)(args, api_endpoints_1.listComments.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.listComments.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,
});
},
};
__classPrivateFieldSet(this, _Client_auth, options === null || options === void 0 ? void 0 : options.auth, "f");

@@ -316,3 +342,3 @@ __classPrivateFieldSet(this, _Client_logLevel, (_a = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _a !== void 0 ? _a : logging_1.LogLevel.WARN, "f");

const response = await errors_1.RequestTimeoutError.rejectAfterTimeout(__classPrivateFieldGet(this, _Client_fetch, "f").call(this, url.toString(), {
method,
method: method.toUpperCase(),
headers,

@@ -355,4 +381,4 @@ body: bodyAsJsonString,

method: api_endpoints_1.search.method,
query: (0, helpers_1.pick)(args, api_endpoints_1.search.queryParams),
body: (0, helpers_1.pick)(args, api_endpoints_1.search.bodyParams),
query: (0, utils_1.pick)(args, api_endpoints_1.search.queryParams),
body: (0, utils_1.pick)(args, api_endpoints_1.search.bodyParams),
auth: args === null || args === void 0 ? void 0 : args.auth,

@@ -359,0 +385,0 @@ });

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildRequestError = exports.APIResponseError = exports.UnknownHTTPResponseError = exports.isHTTPResponseError = exports.RequestTimeoutError = exports.isNotionClientError = exports.ClientErrorCode = exports.APIErrorCode = void 0;
const helpers_1 = require("./helpers");
const utils_1 = require("./utils");
/**

@@ -40,3 +40,3 @@ * Error codes returned in responses from the API.

function isNotionClientError(error) {
return (0, helpers_1.isObject)(error) && error instanceof NotionClientErrorBase;
return (0, utils_1.isObject)(error) && error instanceof NotionClientErrorBase;
}

@@ -190,3 +190,3 @@ exports.isNotionClientError = isNotionClientError;

}
if (!(0, helpers_1.isObject)(parsed) ||
if (!(0, utils_1.isObject)(parsed) ||
typeof parsed["message"] !== "string" ||

@@ -193,0 +193,0 @@ !isAPIErrorCode(parsed["code"])) {

/// <reference lib="dom" />
import type { Await } from "./type-utils";
import type { RequestInit as NodeRequestInit, Response as NodeResponse } from "node-fetch";
declare type FetchFn = typeof fetch;
declare type FetchResponse = Await<ReturnType<FetchFn>>;
declare type FetchResponse = Awaited<ReturnType<FetchFn>>;
declare type RequestInit = NonNullable<Parameters<FetchFn>[1]>;

@@ -7,0 +6,0 @@ export declare type SupportedRequestInfo = string;

@@ -0,13 +1,71 @@

import { BlockObjectResponse, CommentObjectResponse, DatabaseObjectResponse, PageObjectResponse, PartialBlockObjectResponse, PartialCommentObjectResponse, PartialDatabaseObjectResponse, PartialPageObjectResponse, PartialUserObjectResponse, UserObjectResponse } from "./api-endpoints";
interface PaginatedArgs {
start_cursor?: string;
}
interface PaginatedList<T> {
object: "list";
results: T[];
next_cursor: string | null;
has_more: boolean;
}
/**
* Utility for enforcing exhaustiveness checks in the type system.
* Returns an async iterator over the results of any paginated Notion API.
*
* @see https://basarat.gitbook.io/typescript/type-system/discriminated-unions#throw-in-exhaustive-checks
* Example (given a notion Client called `notion`):
*
* @param value The variable with no remaining values
* ```
* for await (const block of iteratePaginatedAPI(notion.blocks.children.list, {
* block_id: parentBlockId,
* })) {
* // Do something with block.
* }
* ```
*
* @param listFn A bound function on the Notion client that represents a conforming paginated
* API. Example: `notion.blocks.children.list`.
* @param firstPageArgs Arguments that should be passed to the API on the first and subsequent
* calls to the API. Any necessary `next_cursor` will be automatically populated by
* this function. Example: `{ block_id: "<my block id>" }`
*/
export declare function assertNever(value: never): never;
declare type AllKeys<T> = T extends unknown ? keyof T : never;
export declare function pick<O extends unknown, K extends AllKeys<O>>(base: O, keys: readonly K[]): Pick<O, K>;
export declare function isObject(o: unknown): o is Record<PropertyKey, unknown>;
export declare function iteratePaginatedAPI<Args extends PaginatedArgs, Item>(listFn: (args: Args) => Promise<PaginatedList<Item>>, firstPageArgs: Args): AsyncIterableIterator<Item>;
/**
* Collect all of the results of paginating an API into an in-memory array.
*
* Example (given a notion Client called `notion`):
*
* ```
* const blocks = collectPaginatedAPI(notion.blocks.children.list, {
* block_id: parentBlockId,
* })
* // Do something with blocks.
* ```
*
* @param listFn A bound function on the Notion client that represents a conforming paginated
* API. Example: `notion.blocks.children.list`.
* @param firstPageArgs Arguments that should be passed to the API on the first and subsequent
* calls to the API. Any necessary `next_cursor` will be automatically populated by
* this function. Example: `{ block_id: "<my block id>" }`
*/
export declare function collectPaginatedAPI<Args extends PaginatedArgs, Item>(listFn: (args: Args) => Promise<PaginatedList<Item>>, firstPageArgs: Args): Promise<Item[]>;
/**
* @returns `true` if `response` is a full `BlockObjectResponse`.
*/
export declare function isFullBlock(response: BlockObjectResponse | PartialBlockObjectResponse): response is BlockObjectResponse;
/**
* @returns `true` if `response` is a full `PageObjectResponse`.
*/
export declare function isFullPage(response: PageObjectResponse | PartialPageObjectResponse): response is PageObjectResponse;
/**
* @returns `true` if `response` is a full `DatabaseObjectResponse`.
*/
export declare function isFullDatabase(response: DatabaseObjectResponse | PartialDatabaseObjectResponse): response is DatabaseObjectResponse;
/**
* @returns `true` if `response` is a full `UserObjectResponse`.
*/
export declare function isFullUser(response: UserObjectResponse | PartialUserObjectResponse): response is UserObjectResponse;
/**
* @returns `true` if `response` is a full `CommentObjectResponse`.
*/
export declare function isFullComment(response: CommentObjectResponse | PartialCommentObjectResponse): response is CommentObjectResponse;
export {};
//# sourceMappingURL=helpers.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isObject = exports.pick = exports.assertNever = void 0;
exports.isFullComment = exports.isFullUser = exports.isFullDatabase = exports.isFullPage = exports.isFullBlock = exports.collectPaginatedAPI = exports.iteratePaginatedAPI = void 0;
/**
* Utility for enforcing exhaustiveness checks in the type system.
* Returns an async iterator over the results of any paginated Notion API.
*
* @see https://basarat.gitbook.io/typescript/type-system/discriminated-unions#throw-in-exhaustive-checks
* Example (given a notion Client called `notion`):
*
* @param value The variable with no remaining values
* ```
* for await (const block of iteratePaginatedAPI(notion.blocks.children.list, {
* block_id: parentBlockId,
* })) {
* // Do something with block.
* }
* ```
*
* @param listFn A bound function on the Notion client that represents a conforming paginated
* API. Example: `notion.blocks.children.list`.
* @param firstPageArgs Arguments that should be passed to the API on the first and subsequent
* calls to the API. Any necessary `next_cursor` will be automatically populated by
* this function. Example: `{ block_id: "<my block id>" }`
*/
function assertNever(value) {
throw new Error(`Unexpected value should never occur: ${value}`);
async function* iteratePaginatedAPI(listFn, firstPageArgs) {
let nextCursor = firstPageArgs.start_cursor;
do {
const response = await listFn({
...firstPageArgs,
start_cursor: nextCursor,
});
yield* response.results;
nextCursor = response.next_cursor;
} while (nextCursor);
}
exports.assertNever = assertNever;
function pick(base, keys) {
const entries = keys.map(key => [key, base === null || base === void 0 ? void 0 : base[key]]);
return Object.fromEntries(entries);
exports.iteratePaginatedAPI = iteratePaginatedAPI;
/**
* Collect all of the results of paginating an API into an in-memory array.
*
* Example (given a notion Client called `notion`):
*
* ```
* const blocks = collectPaginatedAPI(notion.blocks.children.list, {
* block_id: parentBlockId,
* })
* // Do something with blocks.
* ```
*
* @param listFn A bound function on the Notion client that represents a conforming paginated
* API. Example: `notion.blocks.children.list`.
* @param firstPageArgs Arguments that should be passed to the API on the first and subsequent
* calls to the API. Any necessary `next_cursor` will be automatically populated by
* this function. Example: `{ block_id: "<my block id>" }`
*/
async function collectPaginatedAPI(listFn, firstPageArgs) {
const results = [];
for await (const item of iteratePaginatedAPI(listFn, firstPageArgs)) {
results.push(item);
}
return results;
}
exports.pick = pick;
function isObject(o) {
return typeof o === "object" && o !== null;
exports.collectPaginatedAPI = collectPaginatedAPI;
/**
* @returns `true` if `response` is a full `BlockObjectResponse`.
*/
function isFullBlock(response) {
return "type" in response;
}
exports.isObject = isObject;
exports.isFullBlock = isFullBlock;
/**
* @returns `true` if `response` is a full `PageObjectResponse`.
*/
function isFullPage(response) {
return "url" in response;
}
exports.isFullPage = isFullPage;
/**
* @returns `true` if `response` is a full `DatabaseObjectResponse`.
*/
function isFullDatabase(response) {
return "title" in response;
}
exports.isFullDatabase = isFullDatabase;
/**
* @returns `true` if `response` is a full `UserObjectResponse`.
*/
function isFullUser(response) {
return "type" in response;
}
exports.isFullUser = isFullUser;
/**
* @returns `true` if `response` is a full `CommentObjectResponse`.
*/
function isFullComment(response) {
return "created_by" in response;
}
exports.isFullComment = isFullComment;
//# sourceMappingURL=helpers.js.map
export { default as Client } from "./Client";
export { LogLevel, Logger } from "./logging";
export { NotionErrorCode, APIErrorCode, ClientErrorCode, NotionClientError, APIResponseError, UnknownHTTPResponseError, RequestTimeoutError, isNotionClientError, } from "./errors";
export { collectPaginatedAPI, iteratePaginatedAPI, isFullBlock, isFullDatabase, isFullPage, isFullUser, isFullComment, } from "./helpers";
//# sourceMappingURL=index.d.ts.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isNotionClientError = exports.RequestTimeoutError = exports.UnknownHTTPResponseError = exports.APIResponseError = exports.ClientErrorCode = exports.APIErrorCode = exports.LogLevel = exports.Client = void 0;
exports.isFullComment = exports.isFullUser = exports.isFullPage = exports.isFullDatabase = exports.isFullBlock = exports.iteratePaginatedAPI = exports.collectPaginatedAPI = exports.isNotionClientError = exports.RequestTimeoutError = exports.UnknownHTTPResponseError = exports.APIResponseError = exports.ClientErrorCode = exports.APIErrorCode = exports.LogLevel = exports.Client = void 0;
var Client_1 = require("./Client");

@@ -16,2 +16,10 @@ Object.defineProperty(exports, "Client", { enumerable: true, get: function () { return Client_1.default; } });

Object.defineProperty(exports, "isNotionClientError", { enumerable: true, get: function () { return errors_1.isNotionClientError; } });
var helpers_1 = require("./helpers");
Object.defineProperty(exports, "collectPaginatedAPI", { enumerable: true, get: function () { return helpers_1.collectPaginatedAPI; } });
Object.defineProperty(exports, "iteratePaginatedAPI", { enumerable: true, get: function () { return helpers_1.iteratePaginatedAPI; } });
Object.defineProperty(exports, "isFullBlock", { enumerable: true, get: function () { return helpers_1.isFullBlock; } });
Object.defineProperty(exports, "isFullDatabase", { enumerable: true, get: function () { return helpers_1.isFullDatabase; } });
Object.defineProperty(exports, "isFullPage", { enumerable: true, get: function () { return helpers_1.isFullPage; } });
Object.defineProperty(exports, "isFullUser", { enumerable: true, get: function () { return helpers_1.isFullUser; } });
Object.defineProperty(exports, "isFullComment", { enumerable: true, get: function () { return helpers_1.isFullComment; } });
//# sourceMappingURL=index.js.map
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.logLevelSeverity = exports.makeConsoleLogger = exports.LogLevel = void 0;
const helpers_1 = require("./helpers");
const utils_1 = require("./utils");
var LogLevel;

@@ -32,3 +32,3 @@ (function (LogLevel) {

default:
return (0, helpers_1.assertNever)(level);
return (0, utils_1.assertNever)(level);
}

@@ -35,0 +35,0 @@ }

@@ -5,8 +5,2 @@ /**

/**
* Unwrap the type of a promise
*/
export declare type Await<T> = T extends {
then(onfulfilled?: (value: infer U) => unknown): unknown;
} ? U : T;
/**
* Assert U is assignable to T.

@@ -13,0 +7,0 @@ */

{
"name": "@notionhq/client",
"version": "2.0.0",
"version": "2.1.0",
"description": "A simple and easy to use client for the Notion API",

@@ -30,3 +30,3 @@ "engines": {

"lint": "prettier --check . && eslint . --ext .ts && cspell '**/*' ",
"test": "ava",
"test": "jest ./test",
"check-links": "git ls-files | grep md$ | xargs -n 1 markdown-link-check",

@@ -48,12 +48,13 @@ "prebuild": "npm run clean",

"devDependencies": {
"@ava/typescript": "^2.0.0",
"@types/jest": "^28.1.4",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"ava": "^3.15.0",
"cspell": "^5.4.1",
"eslint": "^7.24.0",
"jest": "^28.1.2",
"markdown-link-check": "^3.8.7",
"prettier": "^2.3.0",
"ts-jest": "^28.0.5",
"typescript": "^4.2.4"
}
}

@@ -74,3 +74,3 @@ <div align="center">

property: "Landmark",
text: {
rich_text: {
contains: "Bridge",

@@ -96,3 +96,3 @@ },

property: "Landmark",
text: {
rich_text: {
contains: "Bridge",

@@ -146,3 +146,4 @@ },

This package contains type definitions for **all request parameters and responses**.
This package contains type definitions for all request parameters and responses,
as well as some useful sub-objects from those entities.

@@ -182,2 +183,89 @@ Because errors in TypeScript start with type `any` or `unknown`, you should use

#### Type guards
There are several [type guards](https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-guards-and-differentiating-types)
provided to distinguish between full and partial API responses.
| Type guard function | Purpose |
| ------------------- | -------------------------------------------------------------- |
| `isFullPage` | Determine whether an object is a full `PageObjectResponse` |
| `isFullBlock` | Determine whether an object is a full `BlockObjectResponse` |
| `isFullDatabase` | Determine whether an object is a full `DatabaseObjectResponse` |
| `isFullUser` | Determine whether an object is a full `UserObjectResponse` |
| `isFullComment` | Determine whether an object is a full `CommentObjectResponse` |
Here is an example of using a type guard:
```typescript
const fullOrPartialPages = await notion.databases.query({
database_id: "897e5a76-ae52-4b48-9fdf-e71f5945d1af",
})
for (const page of fullOrPartialPages) {
if (!isFullPage(page)) {
continue
}
// The page variable has been narrowed from PageObjectResponse | PartialPageObjectResponse to PageObjectResponse.
console.log("Created at:", page.created_time)
}
```
### Utility functions
This package also exports a few utility functions that are helpful for dealing with
any of our paginated APIs.
#### `iteratePaginatedAPI(listFn, firstPageArgs)`
This utility turns any paginated API into an async iterator.
**Parameters:**
- `listFn`: Any function on the Notion client that represents a paginated API (i.e. accepts
`start_cursor`.) Example: `notion.blocks.children.list`.
- `firstPageArgs`: Arguments that should be passed to the API on the first and subsequent calls
to the API, for example a `block_id`.
**Returns:**
An [async iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols)
over results from the API.
**Example:**
```javascript
for await (const block of iteratePaginatedAPI(notion.blocks.children.list, {
block_id: parentBlockId,
})) {
// Do something with block.
}
```
#### `collectPaginatedAPI(listFn, firstPageArgs)`
This utility accepts the same arguments as `iteratePaginatedAPI`, but collects
the results into an in-memory array.
Before using this utility, check that the data you are dealing with is
small enough to fit in memory.
**Parameters:**
- `listFn`: Any function on the Notion client that represents a paginated API (i.e. accepts
`start_cursor`.) Example: `notion.blocks.children.list`.
- `firstPageArgs`: Arguments that should be passed to the API on the first and subsequent calls
to the API, for example a `block_id`.
**Returns:**
An array with results from the API.
**Example:**
```javascript
const blocks = collectPaginatedAPI(notion.blocks.children.list, {
block_id: parentBlockId,
})
// Do something with blocks.
```
## Requirements

@@ -184,0 +272,0 @@

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc