🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

notion-client

Package Overview
Dependencies
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

notion-client - npm Package Compare versions

Comparing version

to
2.2.3

16

build/cjs/index.js
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
function __export(m) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
exports.__esModule = true;
__exportStar(require("./notion-api"), exports);
__exportStar(require("./types"), exports);
__export(require("./notion-api"));
//# sourceMappingURL=index.js.map

@@ -53,3 +53,2 @@ "use strict";

exports.__esModule = true;
exports.NotionAPI = void 0;
var got_1 = __importDefault(require("got"));

@@ -67,20 +66,20 @@ var p_map_1 = __importDefault(require("p-map"));

NotionAPI.prototype.getPage = function (pageId, _a) {
var _b, _c, _d;
var _e = _a === void 0 ? {} : _a, _f = _e.concurrency, concurrency = _f === void 0 ? 3 : _f, _g = _e.fetchCollections, fetchCollections = _g === void 0 ? true : _g, _h = _e.signFileUrls, signFileUrls = _h === void 0 ? true : _h;
var _b = _a === void 0 ? {} : _a, _c = _b.concurrency, concurrency = _c === void 0 ? 3 : _c, _d = _b.fetchCollections, fetchCollections = _d === void 0 ? true : _d, _e = _b.signFileUrls, signFileUrls = _e === void 0 ? true : _e;
var _f, _g, _h, _j, _k;
return __awaiter(this, void 0, void 0, function () {
var page, recordMap, pendingBlockIds, newBlocks, contentBlockIds, allCollectionInstances, allFileInstances, signedUrls, i, file, signedUrl, err_1;
var _this = this;
return __generator(this, function (_j) {
switch (_j.label) {
return __generator(this, function (_l) {
switch (_l.label) {
case 0: return [4 /*yield*/, this.getPageRaw(pageId)];
case 1:
page = _j.sent();
recordMap = page === null || page === void 0 ? void 0 : page.recordMap;
if (!(recordMap === null || recordMap === void 0 ? void 0 : recordMap.block)) {
page = _l.sent();
recordMap = (_f = page) === null || _f === void 0 ? void 0 : _f.recordMap;
if (!((_g = recordMap) === null || _g === void 0 ? void 0 : _g.block)) {
throw new Error("Notion page not found \"" + notion_utils_1.uuidToId(pageId) + "\"");
}
// ensure that all top-level maps exist
recordMap.collection = (_b = recordMap.collection) !== null && _b !== void 0 ? _b : {};
recordMap.collection_view = (_c = recordMap.collection_view) !== null && _c !== void 0 ? _c : {};
recordMap.notion_user = (_d = recordMap.notion_user) !== null && _d !== void 0 ? _d : {};
recordMap.collection = (_h = recordMap.collection, (_h !== null && _h !== void 0 ? _h : {}));
recordMap.collection_view = (_j = recordMap.collection_view, (_j !== null && _j !== void 0 ? _j : {}));
recordMap.notion_user = (_k = recordMap.notion_user, (_k !== null && _k !== void 0 ? _k : {}));
// additional mappings added for convenience

@@ -90,3 +89,3 @@ // note: these are not native notion objects

recordMap.signed_urls = {};
_j.label = 2;
_l.label = 2;
case 2:

@@ -100,3 +99,3 @@ if (!true) return [3 /*break*/, 4];

case 3:
newBlocks = _j.sent();
newBlocks = _l.sent();
recordMap.block = __assign(__assign({}, recordMap.block), newBlocks);

@@ -125,15 +124,15 @@ return [3 /*break*/, 2];

var _a;
var _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
var _b, _c, _d, _e, _f, _g, _h, _j;
return __generator(this, function (_k) {
switch (_k.label) {
case 0:
collectionId = collectionInstance.collectionId, collectionViewId = collectionInstance.collectionViewId;
collectionView = (_b = recordMap.collection_view[collectionViewId]) === null || _b === void 0 ? void 0 : _b.value;
_e.label = 1;
_k.label = 1;
case 1:
_e.trys.push([1, 3, , 4]);
_k.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.getCollectionData(collectionId, collectionViewId, {
type: collectionView === null || collectionView === void 0 ? void 0 : collectionView.type,
query: (collectionView === null || collectionView === void 0 ? void 0 : collectionView.query2) || (collectionView === null || collectionView === void 0 ? void 0 : collectionView.query),
groups: ((_c = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _c === void 0 ? void 0 : _c.board_groups2) || ((_d = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _d === void 0 ? void 0 : _d.board_groups)
type: (_c = collectionView) === null || _c === void 0 ? void 0 : _c.type,
query: ((_d = collectionView) === null || _d === void 0 ? void 0 : _d.query2) || ((_e = collectionView) === null || _e === void 0 ? void 0 : _e.query),
groups: ((_g = (_f = collectionView) === null || _f === void 0 ? void 0 : _f.format) === null || _g === void 0 ? void 0 : _g.board_groups2) || ((_j = (_h = collectionView) === null || _h === void 0 ? void 0 : _h.format) === null || _j === void 0 ? void 0 : _j.board_groups)
})

@@ -146,3 +145,3 @@ // await fs.writeFile(

case 2:
collectionData = _e.sent();
collectionData = _k.sent();
// await fs.writeFile(

@@ -159,3 +158,3 @@ // `${collectionId}-${collectionViewId}.json`,

case 3:
err_2 = _e.sent();
err_2 = _k.sent();
// It's possible for public pages to link to private collections, in which case

@@ -173,4 +172,4 @@ // Notion returns a 400 error

// fetch data for all collection view instances
_j.sent();
_j.label = 6;
_l.sent();
_l.label = 6;
case 6:

@@ -199,8 +198,8 @@ if (!signFileUrls) return [3 /*break*/, 10];

if (!(allFileInstances.length > 0)) return [3 /*break*/, 10];
_j.label = 7;
_l.label = 7;
case 7:
_j.trys.push([7, 9, , 10]);
_l.trys.push([7, 9, , 10]);
return [4 /*yield*/, this.getSignedFileUrls(allFileInstances)];
case 8:
signedUrls = (_j.sent()).signedUrls;
signedUrls = (_l.sent()).signedUrls;
if (signedUrls.length === allFileInstances.length) {

@@ -215,3 +214,3 @@ for (i = 0; i < allFileInstances.length; ++i) {

case 9:
err_1 = _j.sent();
err_1 = _l.sent();
console.warn('NotionAPI getSignedfileUrls error', err_1);

@@ -345,3 +344,3 @@ return [3 /*break*/, 10];

return __awaiter(this, void 0, void 0, function () {
var headers;
var headers, url;
return __generator(this, function (_b) {

@@ -352,5 +351,7 @@ headers = {};

}
url = this._apiBaseUrl + "/" + endpoint;
console.log('got', { url: url });
return [2 /*return*/, got_1["default"]
.post(endpoint, {
prefixUrl: this._apiBaseUrl,
.post(url, {
// prefixUrl: this._apiBaseUrl,
json: body,

@@ -357,0 +358,0 @@ headers: headers

export * from './notion-api';
export * from './types';
//# sourceMappingURL=index.js.map

@@ -60,20 +60,20 @@ var __assign = (this && this.__assign) || function () {

NotionAPI.prototype.getPage = function (pageId, _a) {
var _b, _c, _d;
var _e = _a === void 0 ? {} : _a, _f = _e.concurrency, concurrency = _f === void 0 ? 3 : _f, _g = _e.fetchCollections, fetchCollections = _g === void 0 ? true : _g, _h = _e.signFileUrls, signFileUrls = _h === void 0 ? true : _h;
var _b = _a === void 0 ? {} : _a, _c = _b.concurrency, concurrency = _c === void 0 ? 3 : _c, _d = _b.fetchCollections, fetchCollections = _d === void 0 ? true : _d, _e = _b.signFileUrls, signFileUrls = _e === void 0 ? true : _e;
var _f, _g, _h, _j, _k;
return __awaiter(this, void 0, void 0, function () {
var page, recordMap, pendingBlockIds, newBlocks, contentBlockIds, allCollectionInstances, allFileInstances, signedUrls, i, file, signedUrl, err_1;
var _this = this;
return __generator(this, function (_j) {
switch (_j.label) {
return __generator(this, function (_l) {
switch (_l.label) {
case 0: return [4 /*yield*/, this.getPageRaw(pageId)];
case 1:
page = _j.sent();
recordMap = page === null || page === void 0 ? void 0 : page.recordMap;
if (!(recordMap === null || recordMap === void 0 ? void 0 : recordMap.block)) {
page = _l.sent();
recordMap = (_f = page) === null || _f === void 0 ? void 0 : _f.recordMap;
if (!((_g = recordMap) === null || _g === void 0 ? void 0 : _g.block)) {
throw new Error("Notion page not found \"" + uuidToId(pageId) + "\"");
}
// ensure that all top-level maps exist
recordMap.collection = (_b = recordMap.collection) !== null && _b !== void 0 ? _b : {};
recordMap.collection_view = (_c = recordMap.collection_view) !== null && _c !== void 0 ? _c : {};
recordMap.notion_user = (_d = recordMap.notion_user) !== null && _d !== void 0 ? _d : {};
recordMap.collection = (_h = recordMap.collection, (_h !== null && _h !== void 0 ? _h : {}));
recordMap.collection_view = (_j = recordMap.collection_view, (_j !== null && _j !== void 0 ? _j : {}));
recordMap.notion_user = (_k = recordMap.notion_user, (_k !== null && _k !== void 0 ? _k : {}));
// additional mappings added for convenience

@@ -83,3 +83,3 @@ // note: these are not native notion objects

recordMap.signed_urls = {};
_j.label = 2;
_l.label = 2;
case 2:

@@ -93,3 +93,3 @@ if (!true) return [3 /*break*/, 4];

case 3:
newBlocks = _j.sent();
newBlocks = _l.sent();
recordMap.block = __assign(__assign({}, recordMap.block), newBlocks);

@@ -118,15 +118,15 @@ return [3 /*break*/, 2];

var _a;
var _b, _c, _d;
return __generator(this, function (_e) {
switch (_e.label) {
var _b, _c, _d, _e, _f, _g, _h, _j;
return __generator(this, function (_k) {
switch (_k.label) {
case 0:
collectionId = collectionInstance.collectionId, collectionViewId = collectionInstance.collectionViewId;
collectionView = (_b = recordMap.collection_view[collectionViewId]) === null || _b === void 0 ? void 0 : _b.value;
_e.label = 1;
_k.label = 1;
case 1:
_e.trys.push([1, 3, , 4]);
_k.trys.push([1, 3, , 4]);
return [4 /*yield*/, this.getCollectionData(collectionId, collectionViewId, {
type: collectionView === null || collectionView === void 0 ? void 0 : collectionView.type,
query: (collectionView === null || collectionView === void 0 ? void 0 : collectionView.query2) || (collectionView === null || collectionView === void 0 ? void 0 : collectionView.query),
groups: ((_c = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _c === void 0 ? void 0 : _c.board_groups2) || ((_d = collectionView === null || collectionView === void 0 ? void 0 : collectionView.format) === null || _d === void 0 ? void 0 : _d.board_groups)
type: (_c = collectionView) === null || _c === void 0 ? void 0 : _c.type,
query: ((_d = collectionView) === null || _d === void 0 ? void 0 : _d.query2) || ((_e = collectionView) === null || _e === void 0 ? void 0 : _e.query),
groups: ((_g = (_f = collectionView) === null || _f === void 0 ? void 0 : _f.format) === null || _g === void 0 ? void 0 : _g.board_groups2) || ((_j = (_h = collectionView) === null || _h === void 0 ? void 0 : _h.format) === null || _j === void 0 ? void 0 : _j.board_groups)
})

@@ -139,3 +139,3 @@ // await fs.writeFile(

case 2:
collectionData = _e.sent();
collectionData = _k.sent();
// await fs.writeFile(

@@ -152,3 +152,3 @@ // `${collectionId}-${collectionViewId}.json`,

case 3:
err_2 = _e.sent();
err_2 = _k.sent();
// It's possible for public pages to link to private collections, in which case

@@ -166,4 +166,4 @@ // Notion returns a 400 error

// fetch data for all collection view instances
_j.sent();
_j.label = 6;
_l.sent();
_l.label = 6;
case 6:

@@ -192,8 +192,8 @@ if (!signFileUrls) return [3 /*break*/, 10];

if (!(allFileInstances.length > 0)) return [3 /*break*/, 10];
_j.label = 7;
_l.label = 7;
case 7:
_j.trys.push([7, 9, , 10]);
_l.trys.push([7, 9, , 10]);
return [4 /*yield*/, this.getSignedFileUrls(allFileInstances)];
case 8:
signedUrls = (_j.sent()).signedUrls;
signedUrls = (_l.sent()).signedUrls;
if (signedUrls.length === allFileInstances.length) {

@@ -208,3 +208,3 @@ for (i = 0; i < allFileInstances.length; ++i) {

case 9:
err_1 = _j.sent();
err_1 = _l.sent();
console.warn('NotionAPI getSignedfileUrls error', err_1);

@@ -338,3 +338,3 @@ return [3 /*break*/, 10];

return __awaiter(this, void 0, void 0, function () {
var headers;
var headers, url;
return __generator(this, function (_b) {

@@ -345,5 +345,7 @@ headers = {};

}
url = this._apiBaseUrl + "/" + endpoint;
console.log('got', { url: url });
return [2 /*return*/, got
.post(endpoint, {
prefixUrl: this._apiBaseUrl,
.post(url, {
// prefixUrl: this._apiBaseUrl,
json: body,

@@ -350,0 +352,0 @@ headers: headers

@@ -1,2 +0,1 @@

export {};
//# sourceMappingURL=types.js.map

@@ -11,4 +11,5 @@ const { NotionAPI } = require('./build/cjs')

// const output = await api.getPage('b21b2ed02ad446b2af74ee6e262e2124')
// const output = await api.getPage('3f759cf9d8fe44a5988e0c3b6903e224')
try {
const output = await api.getPage('3f759cf9d8fe44a5988e0c3b6903e224')
const output = await api.getPage('067dd719a912471ea9a3ac10710e7fdf')

@@ -15,0 +16,0 @@ // collection example

{
"name": "notion-client",
"version": "2.2.2",
"version": "2.2.3",
"description": "Robust TypeScript client for the unofficial Notion API.",

@@ -18,5 +18,5 @@ "repository": "NotionX/notion-kit",

"dependencies": {
"got": "^11.5.2",
"got": "^11.6.0",
"notion-types": "^2.2.1",
"notion-utils": "^2.2.2",
"notion-utils": "^2.2.3",
"p-map": "^4.0.0"

@@ -27,3 +27,3 @@ },

},
"gitHead": "4099715bc8cfebeba960bd77158c66f27e7d533a"
"gitHead": "5f022591c762a285e015b31444a6488b6a3a81c7"
}

@@ -368,5 +368,7 @@ import got from 'got'

const url = `${this._apiBaseUrl}/${endpoint}`
console.log('got', { url })
return got
.post(endpoint, {
prefixUrl: this._apiBaseUrl,
.post(url, {
// prefixUrl: this._apiBaseUrl,
json: body,

@@ -373,0 +375,0 @@ headers

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