@sillsdev/docu-notion 0.13.2-alpha.2 → 0.13.2-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/plugins/ColumnTransformer.js +5 -2
- package/dist/pull.d.ts +1 -0
- package/dist/pull.js +42 -8
- package/package.json +2 -1
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.standardColumnTransformer = void 0;
|
|
13
13
|
const notion_client_1 = require("notion-client");
|
|
14
|
+
const pull_1 = require("../pull");
|
|
14
15
|
exports.standardColumnTransformer = {
|
|
15
16
|
name: "standardColumnTransformer",
|
|
16
17
|
notionToMarkdownTransforms: [
|
|
@@ -49,8 +50,10 @@ function getColumnWidth(block) {
|
|
|
49
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
51
|
const unofficialNotionClient = new notion_client_1.NotionAPI();
|
|
51
52
|
const blockId = block.id;
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
const recordMap = yield (0, pull_1.executeWithRateLimitAndRetries)(`unofficialNotionClient.getPage(${blockId}) in getColumnWidth()`, () => {
|
|
54
|
+
// Yes, it is odd to call 'getPage' for a block, but that's how we access the format info.
|
|
55
|
+
return unofficialNotionClient.getPage(blockId);
|
|
56
|
+
});
|
|
54
57
|
const blockResult = recordMap.block[blockId];
|
|
55
58
|
// ENHANCE: could we use https://github.com/NotionX/react-notion-x/tree/master/packages/notion-types
|
|
56
59
|
// to get away from "any", which might be particularly helpful in the future
|
package/dist/pull.d.ts
CHANGED
|
@@ -9,4 +9,5 @@ export type DocuNotionOptions = {
|
|
|
9
9
|
statusTag: string;
|
|
10
10
|
};
|
|
11
11
|
export declare function notionPull(options: DocuNotionOptions): Promise<void>;
|
|
12
|
+
export declare function executeWithRateLimitAndRetries<T>(label: string, asyncFunction: () => Promise<T>): Promise<T>;
|
|
12
13
|
export declare function initNotionClient(notionToken: string): Client;
|
package/dist/pull.js
CHANGED
|
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
-
exports.initNotionClient = exports.notionPull = void 0;
|
|
35
|
+
exports.initNotionClient = exports.executeWithRateLimitAndRetries = exports.notionPull = void 0;
|
|
36
36
|
const fs = __importStar(require("fs-extra"));
|
|
37
37
|
const notion_to_md_1 = require("notion-to-md");
|
|
38
38
|
const HierarchicalNamedLayoutStrategy_1 = require("./HierarchicalNamedLayoutStrategy");
|
|
@@ -188,12 +188,45 @@ const notionLimiter = new limiter_1.RateLimiter({
|
|
|
188
188
|
let notionClient;
|
|
189
189
|
function getPageMetadata(id) {
|
|
190
190
|
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
-
yield
|
|
192
|
-
|
|
193
|
-
|
|
191
|
+
return yield executeWithRateLimitAndRetries(`pages.retrieve(${id})`, () => {
|
|
192
|
+
return notionClient.pages.retrieve({
|
|
193
|
+
page_id: id,
|
|
194
|
+
});
|
|
194
195
|
});
|
|
195
196
|
});
|
|
196
197
|
}
|
|
198
|
+
// While everything works fine locally, on Github Actions we are getting a lot of timeouts, so
|
|
199
|
+
// we're trying this extra retry-able wrapper.
|
|
200
|
+
function executeWithRateLimitAndRetries(label, asyncFunction) {
|
|
201
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
202
|
+
yield rateLimit();
|
|
203
|
+
const kRetries = 10;
|
|
204
|
+
let lastException = undefined;
|
|
205
|
+
for (let i = 0; i < kRetries; i++) {
|
|
206
|
+
try {
|
|
207
|
+
return yield asyncFunction();
|
|
208
|
+
}
|
|
209
|
+
catch (e) {
|
|
210
|
+
lastException = e;
|
|
211
|
+
if ((e === null || e === void 0 ? void 0 : e.code) === "notionhq_client_request_timeout" ||
|
|
212
|
+
e.message.includes("timeout") ||
|
|
213
|
+
e.message.includes("Timeout") ||
|
|
214
|
+
e.message.includes("limit") ||
|
|
215
|
+
e.message.includes("Limit")) {
|
|
216
|
+
const secondsToWait = i + 1;
|
|
217
|
+
(0, log_1.info)(`While doing "${label}", got error "${e.message}". Will retry after ${secondsToWait}s...`);
|
|
218
|
+
yield new Promise(resolve => setTimeout(resolve, 1000 * secondsToWait));
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
throw e;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
(0, log_1.error)(`Error: could not complete "${label}" after ${kRetries} retries.`);
|
|
226
|
+
throw lastException;
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
exports.executeWithRateLimitAndRetries = executeWithRateLimitAndRetries;
|
|
197
230
|
function rateLimit() {
|
|
198
231
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
232
|
if (notionLimiter.getTokensRemaining() < 1) {
|
|
@@ -213,10 +246,11 @@ function getBlockChildren(id) {
|
|
|
213
246
|
// Note: there is a now a collectPaginatedAPI() in the notion client, so
|
|
214
247
|
// we could switch to using that (I don't know if it does rate limiting?)
|
|
215
248
|
do {
|
|
216
|
-
yield
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
249
|
+
const response = yield executeWithRateLimitAndRetries(`getBlockChildren(${id})`, () => {
|
|
250
|
+
return notionClient.blocks.children.list({
|
|
251
|
+
start_cursor: start_cursor,
|
|
252
|
+
block_id: id,
|
|
253
|
+
});
|
|
220
254
|
});
|
|
221
255
|
if (!overallResult) {
|
|
222
256
|
overallResult = response;
|
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
"// typescript check": "",
|
|
12
12
|
"tsc": "tsc",
|
|
13
13
|
"// test out with a private sample notion db": "",
|
|
14
|
+
"large-site-test": "npm run ts -- -n $SIL_BLOOM_DOCS_NOTION_TOKEN -r $SIL_BLOOM_DOCS_NOTION_ROOT_PAGE --locales en,fr",
|
|
14
15
|
"pull-test-tagged": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_TEST_ROOT_PAGE_ID --log-level debug --status-tag test",
|
|
15
16
|
"pull-sample-site": "npm run ts -- -n $DOCU_NOTION_INTEGRATION_TOKEN -r $DOCU_NOTION_SAMPLE_ROOT_PAGE --log-level debug",
|
|
16
17
|
"// test with a semi-stable/public site:": "",
|
|
@@ -89,5 +90,5 @@
|
|
|
89
90
|
"volta": {
|
|
90
91
|
"node": "18.16.0"
|
|
91
92
|
},
|
|
92
|
-
"version": "0.13.2-alpha.
|
|
93
|
+
"version": "0.13.2-alpha.3"
|
|
93
94
|
}
|