notion-client
Advanced tools
Comparing version 4.8.6 to 4.9.2
@@ -11,5 +11,4 @@ import { OptionsOfJSONResponseBody } from 'got'; | ||
private readonly _activeUser?; | ||
private readonly _userLocale; | ||
private readonly _userTimeZone; | ||
constructor({ apiBaseUrl, authToken, activeUser, userLocale, userTimeZone }?: { | ||
constructor({ apiBaseUrl, authToken, activeUser, userTimeZone }?: { | ||
apiBaseUrl?: string; | ||
@@ -28,3 +27,3 @@ authToken?: string; | ||
getPageRaw(pageId: string, gotOptions?: OptionsOfJSONResponseBody): Promise<notion.PageChunk>; | ||
getCollectionData(collectionId: string, collectionViewId: string, { type, query, groups, limit, searchQuery, userTimeZone, userLocale, loadContentCover, gotOptions }?: { | ||
getCollectionData(collectionId: string, collectionViewId: string, { type, groups, limit, searchQuery, userTimeZone, loadContentCover, gotOptions }?: { | ||
type?: notion.CollectionViewType; | ||
@@ -31,0 +30,0 @@ query?: any; |
@@ -62,7 +62,6 @@ "use strict"; | ||
function NotionAPI(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.apiBaseUrl, apiBaseUrl = _c === void 0 ? 'https://www.notion.so/api/v3' : _c, authToken = _b.authToken, activeUser = _b.activeUser, _d = _b.userLocale, userLocale = _d === void 0 ? 'en' : _d, _e = _b.userTimeZone, userTimeZone = _e === void 0 ? 'America/New_York' : _e; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.apiBaseUrl, apiBaseUrl = _c === void 0 ? 'https://www.notion.so/api/v3' : _c, authToken = _b.authToken, activeUser = _b.activeUser, _d = _b.userTimeZone, userTimeZone = _d === void 0 ? 'America/New_York' : _d; | ||
this._apiBaseUrl = apiBaseUrl; | ||
this._authToken = authToken; | ||
this._activeUser = activeUser; | ||
this._userLocale = userLocale; | ||
this._userTimeZone = userTimeZone; | ||
@@ -126,11 +125,11 @@ } | ||
var _a; | ||
var _b, _c, _d, _e; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
var _b, _c, _d, _e, _f, _g; | ||
return __generator(this, function (_h) { | ||
switch (_h.label) { | ||
case 0: | ||
collectionId = collectionInstance.collectionId, collectionViewId = collectionInstance.collectionViewId; | ||
collectionView = (_b = recordMap.collection_view[collectionViewId]) === null || _b === void 0 ? void 0 : _b.value; | ||
_f.label = 1; | ||
_h.label = 1; | ||
case 1: | ||
_f.trys.push([1, 3, , 4]); | ||
_h.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.getCollectionData(collectionId, collectionViewId, { | ||
@@ -150,3 +149,3 @@ type: collectionView === null || collectionView === void 0 ? void 0 : collectionView.type, | ||
case 2: | ||
collectionData = _f.sent(); | ||
collectionData = _h.sent(); | ||
// await fs.writeFile( | ||
@@ -160,6 +159,6 @@ // `${collectionId}-${collectionViewId}.json`, | ||
recordMap.notion_user = __assign(__assign({}, recordMap.notion_user), collectionData.recordMap.notion_user); | ||
recordMap.collection_query[collectionId] = __assign(__assign({}, recordMap.collection_query[collectionId]), (_a = {}, _a[collectionViewId] = collectionData.result, _a)); | ||
recordMap.collection_query[collectionId] = __assign(__assign({}, recordMap.collection_query[collectionId]), (_a = {}, _a[collectionViewId] = (_g = (_f = collectionData.result) === null || _f === void 0 ? void 0 : _f.reducerResults) === null || _g === void 0 ? void 0 : _g.collection_group_results, _a)); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_2 = _f.sent(); | ||
err_2 = _h.sent(); | ||
// It's possible for public pages to link to private collections, in which case | ||
@@ -255,6 +254,6 @@ // Notion returns a 400 error | ||
NotionAPI.prototype.getCollectionData = function (collectionId, collectionViewId, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.type, type = _c === void 0 ? 'table' : _c, _d = _b.query, query = _d === void 0 ? { aggregations: [{ property: 'title', aggregator: 'count' }] } : _d, _e = _b.groups, groups = _e === void 0 ? undefined : _e, _f = _b.limit, limit = _f === void 0 ? 999999 : _f, _g = _b.searchQuery, searchQuery = _g === void 0 ? '' : _g, _h = _b.userTimeZone, userTimeZone = _h === void 0 ? this._userTimeZone : _h, _j = _b.userLocale, userLocale = _j === void 0 ? this._userLocale : _j, _k = _b.loadContentCover, loadContentCover = _k === void 0 ? true : _k, gotOptions = _b.gotOptions; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.type, type = _c === void 0 ? 'table' : _c, _d = _b.groups, groups = _d === void 0 ? undefined : _d, _e = _b.limit, limit = _e === void 0 ? 999999 : _e, _f = _b.searchQuery, searchQuery = _f === void 0 ? '' : _f, _g = _b.userTimeZone, userTimeZone = _g === void 0 ? this._userTimeZone : _g, _h = _b.loadContentCover, loadContentCover = _h === void 0 ? true : _h, gotOptions = _b.gotOptions; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var loader; | ||
return __generator(this, function (_l) { | ||
return __generator(this, function (_j) { | ||
// TODO: All other collection types queries fail with 400 errors. | ||
@@ -268,8 +267,19 @@ // My guess is that they require slightly different query params, but since | ||
loader = { | ||
type: type, | ||
limit: limit, | ||
type: "reducer", | ||
reducers: { | ||
collection_group_results: { | ||
type: "results", | ||
limit: limit, | ||
loadContentCover: loadContentCover | ||
}, | ||
"table:uncategorized:title:count": { | ||
type: "aggregation", | ||
aggregation: { | ||
property: "title", | ||
aggregator: "count" | ||
} | ||
} | ||
}, | ||
searchQuery: searchQuery, | ||
userTimeZone: userTimeZone, | ||
userLocale: userLocale, | ||
loadContentCover: loadContentCover | ||
userTimeZone: userTimeZone | ||
}; | ||
@@ -281,3 +291,3 @@ if (groups) { | ||
// useful for debugging collection queries | ||
// console.log(JSON.stringify('queryCollection', { collectionId, collectionViewId, query, loader }, null, 2)) | ||
// console.log('queryCollection', JSON.stringify( { collectionId, collectionViewId, query, loader}, null, 2)) | ||
return [2 /*return*/, this.fetch({ | ||
@@ -288,3 +298,2 @@ endpoint: 'queryCollection', | ||
collectionViewId: collectionViewId, | ||
query: query, | ||
loader: loader | ||
@@ -291,0 +300,0 @@ }, |
@@ -11,5 +11,4 @@ import { OptionsOfJSONResponseBody } from 'got'; | ||
private readonly _activeUser?; | ||
private readonly _userLocale; | ||
private readonly _userTimeZone; | ||
constructor({ apiBaseUrl, authToken, activeUser, userLocale, userTimeZone }?: { | ||
constructor({ apiBaseUrl, authToken, activeUser, userTimeZone }?: { | ||
apiBaseUrl?: string; | ||
@@ -28,3 +27,3 @@ authToken?: string; | ||
getPageRaw(pageId: string, gotOptions?: OptionsOfJSONResponseBody): Promise<notion.PageChunk>; | ||
getCollectionData(collectionId: string, collectionViewId: string, { type, query, groups, limit, searchQuery, userTimeZone, userLocale, loadContentCover, gotOptions }?: { | ||
getCollectionData(collectionId: string, collectionViewId: string, { type, groups, limit, searchQuery, userTimeZone, loadContentCover, gotOptions }?: { | ||
type?: notion.CollectionViewType; | ||
@@ -31,0 +30,0 @@ query?: any; |
@@ -56,7 +56,6 @@ var __assign = (this && this.__assign) || function () { | ||
function NotionAPI(_a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.apiBaseUrl, apiBaseUrl = _c === void 0 ? 'https://www.notion.so/api/v3' : _c, authToken = _b.authToken, activeUser = _b.activeUser, _d = _b.userLocale, userLocale = _d === void 0 ? 'en' : _d, _e = _b.userTimeZone, userTimeZone = _e === void 0 ? 'America/New_York' : _e; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.apiBaseUrl, apiBaseUrl = _c === void 0 ? 'https://www.notion.so/api/v3' : _c, authToken = _b.authToken, activeUser = _b.activeUser, _d = _b.userTimeZone, userTimeZone = _d === void 0 ? 'America/New_York' : _d; | ||
this._apiBaseUrl = apiBaseUrl; | ||
this._authToken = authToken; | ||
this._activeUser = activeUser; | ||
this._userLocale = userLocale; | ||
this._userTimeZone = userTimeZone; | ||
@@ -120,11 +119,11 @@ } | ||
var _a; | ||
var _b, _c, _d, _e; | ||
return __generator(this, function (_f) { | ||
switch (_f.label) { | ||
var _b, _c, _d, _e, _f, _g; | ||
return __generator(this, function (_h) { | ||
switch (_h.label) { | ||
case 0: | ||
collectionId = collectionInstance.collectionId, collectionViewId = collectionInstance.collectionViewId; | ||
collectionView = (_b = recordMap.collection_view[collectionViewId]) === null || _b === void 0 ? void 0 : _b.value; | ||
_f.label = 1; | ||
_h.label = 1; | ||
case 1: | ||
_f.trys.push([1, 3, , 4]); | ||
_h.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.getCollectionData(collectionId, collectionViewId, { | ||
@@ -144,3 +143,3 @@ type: collectionView === null || collectionView === void 0 ? void 0 : collectionView.type, | ||
case 2: | ||
collectionData = _f.sent(); | ||
collectionData = _h.sent(); | ||
// await fs.writeFile( | ||
@@ -154,6 +153,6 @@ // `${collectionId}-${collectionViewId}.json`, | ||
recordMap.notion_user = __assign(__assign({}, recordMap.notion_user), collectionData.recordMap.notion_user); | ||
recordMap.collection_query[collectionId] = __assign(__assign({}, recordMap.collection_query[collectionId]), (_a = {}, _a[collectionViewId] = collectionData.result, _a)); | ||
recordMap.collection_query[collectionId] = __assign(__assign({}, recordMap.collection_query[collectionId]), (_a = {}, _a[collectionViewId] = (_g = (_f = collectionData.result) === null || _f === void 0 ? void 0 : _f.reducerResults) === null || _g === void 0 ? void 0 : _g.collection_group_results, _a)); | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_2 = _f.sent(); | ||
err_2 = _h.sent(); | ||
// It's possible for public pages to link to private collections, in which case | ||
@@ -249,6 +248,6 @@ // Notion returns a 400 error | ||
NotionAPI.prototype.getCollectionData = function (collectionId, collectionViewId, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.type, type = _c === void 0 ? 'table' : _c, _d = _b.query, query = _d === void 0 ? { aggregations: [{ property: 'title', aggregator: 'count' }] } : _d, _e = _b.groups, groups = _e === void 0 ? undefined : _e, _f = _b.limit, limit = _f === void 0 ? 999999 : _f, _g = _b.searchQuery, searchQuery = _g === void 0 ? '' : _g, _h = _b.userTimeZone, userTimeZone = _h === void 0 ? this._userTimeZone : _h, _j = _b.userLocale, userLocale = _j === void 0 ? this._userLocale : _j, _k = _b.loadContentCover, loadContentCover = _k === void 0 ? true : _k, gotOptions = _b.gotOptions; | ||
var _b = _a === void 0 ? {} : _a, _c = _b.type, type = _c === void 0 ? 'table' : _c, _d = _b.groups, groups = _d === void 0 ? undefined : _d, _e = _b.limit, limit = _e === void 0 ? 999999 : _e, _f = _b.searchQuery, searchQuery = _f === void 0 ? '' : _f, _g = _b.userTimeZone, userTimeZone = _g === void 0 ? this._userTimeZone : _g, _h = _b.loadContentCover, loadContentCover = _h === void 0 ? true : _h, gotOptions = _b.gotOptions; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var loader; | ||
return __generator(this, function (_l) { | ||
return __generator(this, function (_j) { | ||
// TODO: All other collection types queries fail with 400 errors. | ||
@@ -262,8 +261,19 @@ // My guess is that they require slightly different query params, but since | ||
loader = { | ||
type: type, | ||
limit: limit, | ||
type: "reducer", | ||
reducers: { | ||
collection_group_results: { | ||
type: "results", | ||
limit: limit, | ||
loadContentCover: loadContentCover | ||
}, | ||
"table:uncategorized:title:count": { | ||
type: "aggregation", | ||
aggregation: { | ||
property: "title", | ||
aggregator: "count" | ||
} | ||
} | ||
}, | ||
searchQuery: searchQuery, | ||
userTimeZone: userTimeZone, | ||
userLocale: userLocale, | ||
loadContentCover: loadContentCover | ||
userTimeZone: userTimeZone | ||
}; | ||
@@ -275,3 +285,3 @@ if (groups) { | ||
// useful for debugging collection queries | ||
// console.log(JSON.stringify('queryCollection', { collectionId, collectionViewId, query, loader }, null, 2)) | ||
// console.log('queryCollection', JSON.stringify( { collectionId, collectionViewId, query, loader}, null, 2)) | ||
return [2 /*return*/, this.fetch({ | ||
@@ -282,3 +292,2 @@ endpoint: 'queryCollection', | ||
collectionViewId: collectionViewId, | ||
query: query, | ||
loader: loader | ||
@@ -285,0 +294,0 @@ }, |
{ | ||
"name": "notion-client", | ||
"version": "4.8.6", | ||
"version": "4.9.2", | ||
"description": "Robust TypeScript client for the unofficial Notion API.", | ||
@@ -28,3 +28,3 @@ "repository": "NotionX/react-notion-x", | ||
}, | ||
"gitHead": "e0b8f112d99b086cd72858c2d7d3882029c6ead9" | ||
"gitHead": "694716ee5ba6b1747b18141aabe6f1b83b572953" | ||
} |
@@ -16,3 +16,2 @@ import got, { OptionsOfJSONResponseBody } from 'got' | ||
private readonly _activeUser?: string | ||
private readonly _userLocale: string | ||
private readonly _userTimeZone: string | ||
@@ -24,3 +23,2 @@ | ||
activeUser, | ||
userLocale = 'en', | ||
userTimeZone = 'America/New_York' | ||
@@ -37,3 +35,2 @@ }: { | ||
this._activeUser = activeUser | ||
this._userLocale = userLocale | ||
this._userTimeZone = userTimeZone | ||
@@ -162,6 +159,5 @@ } | ||
} | ||
recordMap.collection_query![collectionId] = { | ||
...recordMap.collection_query![collectionId], | ||
[collectionViewId]: collectionData.result | ||
[collectionViewId]: (collectionData.result as any)?.reducerResults?.collection_group_results | ||
} | ||
@@ -273,3 +269,2 @@ } catch (err) { | ||
type = 'table', | ||
query = { aggregations: [{ property: 'title', aggregator: 'count' }] }, | ||
groups = undefined, | ||
@@ -279,3 +274,2 @@ limit = 999999, | ||
userTimeZone = this._userTimeZone, | ||
userLocale = this._userLocale, | ||
loadContentCover = true, | ||
@@ -304,8 +298,19 @@ gotOptions | ||
const loader: any = { | ||
type, | ||
limit, | ||
type: "reducer", | ||
reducers: { | ||
collection_group_results: { | ||
type: "results", | ||
limit, | ||
loadContentCover | ||
}, | ||
"table:uncategorized:title:count": { | ||
type: "aggregation", | ||
aggregation: { | ||
property: "title", | ||
aggregator: "count" | ||
} | ||
} | ||
}, | ||
searchQuery, | ||
userTimeZone, | ||
userLocale, | ||
loadContentCover | ||
userTimeZone | ||
} | ||
@@ -319,3 +324,3 @@ | ||
// useful for debugging collection queries | ||
// console.log(JSON.stringify('queryCollection', { collectionId, collectionViewId, query, loader }, null, 2)) | ||
// console.log('queryCollection', JSON.stringify( { collectionId, collectionViewId, query, loader}, null, 2)) | ||
@@ -327,3 +332,2 @@ return this.fetch<notion.CollectionInstance>({ | ||
collectionViewId, | ||
query, | ||
loader | ||
@@ -330,0 +334,0 @@ }, |
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
970273
11836