@notionhq/client
Advanced tools
Comparing version 2.2.10 to 2.2.11
{ | ||
"name": "@notionhq/client", | ||
"version": "2.2.10", | ||
"version": "2.2.11", | ||
"description": "A simple and easy to use client for the Notion API", | ||
@@ -5,0 +5,0 @@ "engines": { |
@@ -5,3 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
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.oauthToken = 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 = { | ||
@@ -193,2 +193,9 @@ method: "get", | ||
}; | ||
exports.oauthToken = { | ||
method: "post", | ||
pathParams: [], | ||
queryParams: [], | ||
bodyParams: ["grant_type", "code", "redirect_uri", "external_account"], | ||
path: () => `oauth/token`, | ||
}; | ||
//# sourceMappingURL=api-endpoints.js.map |
@@ -5,3 +5,3 @@ /// <reference types="node" /> | ||
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, CreateCommentParameters, CreateCommentResponse, ListCommentsParameters, ListCommentsResponse } 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, OauthTokenResponse, OauthTokenParameters } from "./api-endpoints"; | ||
import { SupportedFetch } from "./fetch-types"; | ||
@@ -24,3 +24,11 @@ export interface ClientOptions { | ||
body?: Record<string, unknown>; | ||
auth?: string; | ||
/** | ||
* To authenticate using public API token, `auth` should be passed as a | ||
* string. If you are trying to complete OAuth, then `auth` should be an object | ||
* containing your integration's client ID and secret. | ||
*/ | ||
auth?: string | { | ||
client_id: string; | ||
client_secret: string; | ||
}; | ||
} | ||
@@ -137,2 +145,11 @@ export default class Client { | ||
search: (args: WithAuth<SearchParameters>) => Promise<SearchResponse>; | ||
readonly oauth: { | ||
/** | ||
* Get token | ||
*/ | ||
token: (args: OauthTokenParameters & { | ||
client_id: string; | ||
client_secret: string; | ||
}) => Promise<OauthTokenResponse>; | ||
}; | ||
/** | ||
@@ -139,0 +156,0 @@ * Emits a log message to the console. |
@@ -292,2 +292,19 @@ "use strict"; | ||
}; | ||
this.oauth = { | ||
/** | ||
* Get token | ||
*/ | ||
token: (args) => { | ||
return this.request({ | ||
path: api_endpoints_1.oauthToken.path(), | ||
method: api_endpoints_1.oauthToken.method, | ||
query: (0, utils_1.pick)(args, api_endpoints_1.oauthToken.queryParams), | ||
body: (0, utils_1.pick)(args, api_endpoints_1.oauthToken.bodyParams), | ||
auth: { | ||
client_id: args.client_id, | ||
client_secret: args.client_secret, | ||
}, | ||
}); | ||
}, | ||
}; | ||
__classPrivateFieldSet(this, _Client_auth, options === null || options === void 0 ? void 0 : options.auth, "f"); | ||
@@ -331,4 +348,18 @@ __classPrivateFieldSet(this, _Client_logLevel, (_a = options === null || options === void 0 ? void 0 : options.logLevel) !== null && _a !== void 0 ? _a : logging_1.LogLevel.WARN, "f"); | ||
} | ||
// Allow both client ID / client secret based auth as well as token based auth. | ||
let authorizationHeader; | ||
if (typeof auth === "object") { | ||
// Client ID and secret based auth is **ONLY** supported when using the | ||
// `/oauth/token` endpoint. If this is the case, handle formatting the | ||
// authorization header as required by `Basic` auth. | ||
const unencodedCredential = `${auth.client_id}:${auth.client_secret}`; | ||
const encodedCredential = Buffer.from(unencodedCredential).toString("base64"); | ||
authorizationHeader = { authorization: `Basic ${encodedCredential}` }; | ||
} | ||
else { | ||
// Otherwise format authorization header as `Bearer` token auth. | ||
authorizationHeader = this.authAsHeaders(auth); | ||
} | ||
const headers = { | ||
...this.authAsHeaders(auth), | ||
...authorizationHeader, | ||
"Notion-Version": __classPrivateFieldGet(this, _Client_notionVersion, "f"), | ||
@@ -335,0 +366,0 @@ "user-agent": __classPrivateFieldGet(this, _Client_userAgent, "f"), |
{ | ||
"name": "@notionhq/client", | ||
"version": "2.2.10", | ||
"version": "2.2.11", | ||
"description": "A simple and easy to use client for the Notion API", | ||
@@ -5,0 +5,0 @@ "engines": { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
910133
8748