notion-client
Advanced tools
Comparing version 4.9.9 to 4.9.10
@@ -25,2 +25,7 @@ import { OptionsOfJSONResponseBody } from 'got'; | ||
}): Promise<notion.ExtendedRecordMap>; | ||
addSignedUrls({ recordMap, contentBlockIds, gotOptions }: { | ||
recordMap: notion.ExtendedRecordMap; | ||
contentBlockIds?: string[]; | ||
gotOptions?: OptionsOfJSONResponseBody; | ||
}): Promise<void>; | ||
getPageRaw(pageId: string, gotOptions?: OptionsOfJSONResponseBody): Promise<notion.PageChunk>; | ||
@@ -27,0 +32,0 @@ getCollectionData(collectionId: string, collectionViewId: string, { type, query, groups, limit, searchQuery, userTimeZone, loadContentCover, gotOptions }?: { |
@@ -72,3 +72,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var page, recordMap, pendingBlockIds, newBlocks, contentBlockIds, allCollectionInstances, allFileInstances, signedUrls, i, file, signedUrl, err_1; | ||
var page, recordMap, pendingBlockIds, newBlocks, contentBlockIds, allCollectionInstances; | ||
var _this = this; | ||
@@ -123,3 +123,3 @@ return __generator(this, function (_j) { | ||
return [4 /*yield*/, p_map_1["default"](allCollectionInstances, function (collectionInstance) { return __awaiter(_this, void 0, void 0, function () { | ||
var collectionId, collectionViewId, collectionView, collectionData, err_2; | ||
var collectionId, collectionViewId, collectionView, collectionData, err_1; | ||
var _a; | ||
@@ -163,6 +163,6 @@ var _b, _c, _d, _e, _f, _g, _h, _j; | ||
case 3: | ||
err_2 = _k.sent(); | ||
err_1 = _k.sent(); | ||
// It's possible for public pages to link to private collections, in which case | ||
// Notion returns a 400 error | ||
console.warn('NotionAPI collectionQuery error', err_2.message); | ||
console.warn('NotionAPI collectionQuery error', err_1.message); | ||
return [3 /*break*/, 4]; | ||
@@ -180,3 +180,23 @@ case 4: return [2 /*return*/]; | ||
case 6: | ||
if (!signFileUrls) return [3 /*break*/, 10]; | ||
if (!signFileUrls) return [3 /*break*/, 8]; | ||
return [4 /*yield*/, this.addSignedUrls({ recordMap: recordMap, contentBlockIds: contentBlockIds, gotOptions: gotOptions })]; | ||
case 7: | ||
_j.sent(); | ||
_j.label = 8; | ||
case 8: return [2 /*return*/, recordMap]; | ||
} | ||
}); | ||
}); | ||
}; | ||
NotionAPI.prototype.addSignedUrls = function (_a) { | ||
var recordMap = _a.recordMap, contentBlockIds = _a.contentBlockIds, _b = _a.gotOptions, gotOptions = _b === void 0 ? {} : _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var allFileInstances, signedUrls, i, file, signedUrl, err_2; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
recordMap.signed_urls = {}; | ||
if (!contentBlockIds) { | ||
contentBlockIds = notion_utils_1.getPageContentBlockIds(recordMap); | ||
} | ||
allFileInstances = contentBlockIds.flatMap(function (blockId) { | ||
@@ -194,4 +214,3 @@ var _a, _b, _c, _d; | ||
if (source) { | ||
if (source.indexOf('youtube') >= 0 || | ||
source.indexOf('vimeo') >= 0) { | ||
if (source.indexOf('youtube') >= 0 || source.indexOf('vimeo') >= 0) { | ||
return []; | ||
@@ -210,9 +229,9 @@ } | ||
}); | ||
if (!(allFileInstances.length > 0)) return [3 /*break*/, 10]; | ||
_j.label = 7; | ||
case 7: | ||
_j.trys.push([7, 9, , 10]); | ||
if (!(allFileInstances.length > 0)) return [3 /*break*/, 4]; | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.getSignedFileUrls(allFileInstances, gotOptions)]; | ||
case 8: | ||
signedUrls = (_j.sent()).signedUrls; | ||
case 2: | ||
signedUrls = (_c.sent()).signedUrls; | ||
if (signedUrls.length === allFileInstances.length) { | ||
@@ -225,8 +244,8 @@ for (i = 0; i < allFileInstances.length; ++i) { | ||
} | ||
return [3 /*break*/, 10]; | ||
case 9: | ||
err_1 = _j.sent(); | ||
console.warn('NotionAPI getSignedfileUrls error', err_1); | ||
return [3 /*break*/, 10]; | ||
case 10: return [2 /*return*/, recordMap]; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_2 = _c.sent(); | ||
console.warn('NotionAPI getSignedfileUrls error', err_2); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -233,0 +252,0 @@ }); |
@@ -25,2 +25,7 @@ import { OptionsOfJSONResponseBody } from 'got'; | ||
}): Promise<notion.ExtendedRecordMap>; | ||
addSignedUrls({ recordMap, contentBlockIds, gotOptions }: { | ||
recordMap: notion.ExtendedRecordMap; | ||
contentBlockIds?: string[]; | ||
gotOptions?: OptionsOfJSONResponseBody; | ||
}): Promise<void>; | ||
getPageRaw(pageId: string, gotOptions?: OptionsOfJSONResponseBody): Promise<notion.PageChunk>; | ||
@@ -27,0 +32,0 @@ getCollectionData(collectionId: string, collectionViewId: string, { type, query, groups, limit, searchQuery, userTimeZone, loadContentCover, gotOptions }?: { |
@@ -66,3 +66,3 @@ var __assign = (this && this.__assign) || function () { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var page, recordMap, pendingBlockIds, newBlocks, contentBlockIds, allCollectionInstances, allFileInstances, signedUrls, i, file, signedUrl, err_1; | ||
var page, recordMap, pendingBlockIds, newBlocks, contentBlockIds, allCollectionInstances; | ||
var _this = this; | ||
@@ -117,3 +117,3 @@ return __generator(this, function (_j) { | ||
return [4 /*yield*/, pMap(allCollectionInstances, function (collectionInstance) { return __awaiter(_this, void 0, void 0, function () { | ||
var collectionId, collectionViewId, collectionView, collectionData, err_2; | ||
var collectionId, collectionViewId, collectionView, collectionData, err_1; | ||
var _a; | ||
@@ -157,6 +157,6 @@ var _b, _c, _d, _e, _f, _g, _h, _j; | ||
case 3: | ||
err_2 = _k.sent(); | ||
err_1 = _k.sent(); | ||
// It's possible for public pages to link to private collections, in which case | ||
// Notion returns a 400 error | ||
console.warn('NotionAPI collectionQuery error', err_2.message); | ||
console.warn('NotionAPI collectionQuery error', err_1.message); | ||
return [3 /*break*/, 4]; | ||
@@ -174,3 +174,23 @@ case 4: return [2 /*return*/]; | ||
case 6: | ||
if (!signFileUrls) return [3 /*break*/, 10]; | ||
if (!signFileUrls) return [3 /*break*/, 8]; | ||
return [4 /*yield*/, this.addSignedUrls({ recordMap: recordMap, contentBlockIds: contentBlockIds, gotOptions: gotOptions })]; | ||
case 7: | ||
_j.sent(); | ||
_j.label = 8; | ||
case 8: return [2 /*return*/, recordMap]; | ||
} | ||
}); | ||
}); | ||
}; | ||
NotionAPI.prototype.addSignedUrls = function (_a) { | ||
var recordMap = _a.recordMap, contentBlockIds = _a.contentBlockIds, _b = _a.gotOptions, gotOptions = _b === void 0 ? {} : _b; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var allFileInstances, signedUrls, i, file, signedUrl, err_2; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
recordMap.signed_urls = {}; | ||
if (!contentBlockIds) { | ||
contentBlockIds = getPageContentBlockIds(recordMap); | ||
} | ||
allFileInstances = contentBlockIds.flatMap(function (blockId) { | ||
@@ -188,4 +208,3 @@ var _a, _b, _c, _d; | ||
if (source) { | ||
if (source.indexOf('youtube') >= 0 || | ||
source.indexOf('vimeo') >= 0) { | ||
if (source.indexOf('youtube') >= 0 || source.indexOf('vimeo') >= 0) { | ||
return []; | ||
@@ -204,9 +223,9 @@ } | ||
}); | ||
if (!(allFileInstances.length > 0)) return [3 /*break*/, 10]; | ||
_j.label = 7; | ||
case 7: | ||
_j.trys.push([7, 9, , 10]); | ||
if (!(allFileInstances.length > 0)) return [3 /*break*/, 4]; | ||
_c.label = 1; | ||
case 1: | ||
_c.trys.push([1, 3, , 4]); | ||
return [4 /*yield*/, this.getSignedFileUrls(allFileInstances, gotOptions)]; | ||
case 8: | ||
signedUrls = (_j.sent()).signedUrls; | ||
case 2: | ||
signedUrls = (_c.sent()).signedUrls; | ||
if (signedUrls.length === allFileInstances.length) { | ||
@@ -219,8 +238,8 @@ for (i = 0; i < allFileInstances.length; ++i) { | ||
} | ||
return [3 /*break*/, 10]; | ||
case 9: | ||
err_1 = _j.sent(); | ||
console.warn('NotionAPI getSignedfileUrls error', err_1); | ||
return [3 /*break*/, 10]; | ||
case 10: return [2 /*return*/, recordMap]; | ||
return [3 /*break*/, 4]; | ||
case 3: | ||
err_2 = _c.sent(); | ||
console.warn('NotionAPI getSignedfileUrls error', err_2); | ||
return [3 /*break*/, 4]; | ||
case 4: return [2 /*return*/]; | ||
} | ||
@@ -227,0 +246,0 @@ }); |
{ | ||
"name": "notion-client", | ||
"version": "4.9.9", | ||
"version": "4.9.10", | ||
"description": "Robust TypeScript client for the unofficial Notion API.", | ||
@@ -28,3 +28,3 @@ "repository": "NotionX/react-notion-x", | ||
}, | ||
"gitHead": "8b611e82add7650bac9381c0d250bc0789757f08" | ||
"gitHead": "4c63a3d4b7d2cad460e7b76ad0199122f994a984" | ||
} |
@@ -182,59 +182,74 @@ import got, { OptionsOfJSONResponseBody } from 'got' | ||
if (signFileUrls) { | ||
const allFileInstances = contentBlockIds.flatMap((blockId) => { | ||
const block = recordMap.block[blockId].value | ||
await this.addSignedUrls({ recordMap, contentBlockIds, gotOptions }) | ||
} | ||
if ( | ||
block && | ||
(block.type === 'pdf' || | ||
block.type === 'audio' || | ||
(block.type === 'image' && block.file_ids?.length) || | ||
block.type === 'video' || | ||
block.type === 'file') | ||
) { | ||
const source = block.properties?.source?.[0]?.[0] | ||
// console.log(block, source) | ||
return recordMap | ||
} | ||
if (source) { | ||
if ( | ||
source.indexOf('youtube') >= 0 || | ||
source.indexOf('vimeo') >= 0 | ||
) { | ||
return [] | ||
} | ||
public async addSignedUrls({ | ||
recordMap, | ||
contentBlockIds, | ||
gotOptions = {} | ||
}: { | ||
recordMap: notion.ExtendedRecordMap | ||
contentBlockIds?: string[] | ||
gotOptions?: OptionsOfJSONResponseBody | ||
}) { | ||
recordMap.signed_urls = {} | ||
return { | ||
permissionRecord: { | ||
table: 'block', | ||
id: block.id | ||
}, | ||
url: source | ||
} | ||
if (!contentBlockIds) { | ||
contentBlockIds = getPageContentBlockIds(recordMap) | ||
} | ||
const allFileInstances = contentBlockIds.flatMap((blockId) => { | ||
const block = recordMap.block[blockId].value | ||
if ( | ||
block && | ||
(block.type === 'pdf' || | ||
block.type === 'audio' || | ||
(block.type === 'image' && block.file_ids?.length) || | ||
block.type === 'video' || | ||
block.type === 'file') | ||
) { | ||
const source = block.properties?.source?.[0]?.[0] | ||
// console.log(block, source) | ||
if (source) { | ||
if (source.indexOf('youtube') >= 0 || source.indexOf('vimeo') >= 0) { | ||
return [] | ||
} | ||
return { | ||
permissionRecord: { | ||
table: 'block', | ||
id: block.id | ||
}, | ||
url: source | ||
} | ||
} | ||
} | ||
return [] | ||
}) | ||
return [] | ||
}) | ||
if (allFileInstances.length > 0) { | ||
try { | ||
const { signedUrls } = await this.getSignedFileUrls( | ||
allFileInstances, | ||
gotOptions | ||
) | ||
if (allFileInstances.length > 0) { | ||
try { | ||
const { signedUrls } = await this.getSignedFileUrls( | ||
allFileInstances, | ||
gotOptions | ||
) | ||
if (signedUrls.length === allFileInstances.length) { | ||
for (let i = 0; i < allFileInstances.length; ++i) { | ||
const file = allFileInstances[i] | ||
const signedUrl = signedUrls[i] | ||
if (signedUrls.length === allFileInstances.length) { | ||
for (let i = 0; i < allFileInstances.length; ++i) { | ||
const file = allFileInstances[i] | ||
const signedUrl = signedUrls[i] | ||
recordMap.signed_urls[file.permissionRecord.id] = signedUrl | ||
} | ||
recordMap.signed_urls[file.permissionRecord.id] = signedUrl | ||
} | ||
} catch (err) { | ||
console.warn('NotionAPI getSignedfileUrls error', err) | ||
} | ||
} catch (err) { | ||
console.warn('NotionAPI getSignedfileUrls error', err) | ||
} | ||
} | ||
return recordMap | ||
} | ||
@@ -449,4 +464,4 @@ | ||
let query = collectionView?.query2 || collectionView?.query | ||
if(!query) return undefined | ||
if (!query) return undefined | ||
const groupBy = collectionView?.format?.board_columns_by | ||
@@ -453,0 +468,0 @@ ? collectionView?.format?.board_columns_by?.property |
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
992007
12226