@bitsocial/bitsocial-react-hooks 0.3.3 → 0.3.5
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/CHANGELOG.md +23 -0
- package/dist/hooks/accounts/accounts.d.ts.map +1 -1
- package/dist/hooks/accounts/accounts.js +10 -6
- package/dist/hooks/accounts/accounts.js.map +1 -1
- package/dist/hooks/actions/actions.d.ts +5 -3
- package/dist/hooks/actions/actions.d.ts.map +1 -1
- package/dist/hooks/actions/actions.js +128 -113
- package/dist/hooks/actions/actions.js.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.d.ts +2 -0
- package/dist/lib/pkc-js/pkc-js-mock.d.ts.map +1 -1
- package/dist/lib/pkc-js/pkc-js-mock.js +18 -0
- package/dist/lib/pkc-js/pkc-js-mock.js.map +1 -1
- package/dist/stores/accounts/accounts-actions.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-actions.js +119 -70
- package/dist/stores/accounts/accounts-actions.js.map +1 -1
- package/dist/stores/accounts/accounts-database.d.ts.map +1 -1
- package/dist/stores/accounts/accounts-database.js +3 -0
- package/dist/stores/accounts/accounts-database.js.map +1 -1
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
|
@@ -460,6 +460,48 @@ export const hasTerminalChallengeVerificationError = (challengeVerification) =>
|
|
|
460
460
|
return (!(challengeVerification === null || challengeVerification === void 0 ? void 0 : challengeVerification.challengeSuccess) &&
|
|
461
461
|
(hasChallengeErrors || Boolean(challengeVerification === null || challengeVerification === void 0 ? void 0 : challengeVerification.reason)));
|
|
462
462
|
};
|
|
463
|
+
// pkc-js stops a publication and sets its publishingState to "failed" before emitting the error that
|
|
464
|
+
// ends its publish, and over RPC an error the server ended its publish with ends it too, the test
|
|
465
|
+
// pkc-js makes itself (see its _handleIncomingErrorFromRpc). Its other errors did not end the
|
|
466
|
+
// publish: ones it recovers from while the publication keeps publishing, e.g. a challenge it cannot
|
|
467
|
+
// decrypt, or a pubsub unsubscribe that failed while a stopped publication was torn down
|
|
468
|
+
const isPublishEndingError = (publication, error) => {
|
|
469
|
+
var _a, _b;
|
|
470
|
+
return (publication === null || publication === void 0 ? void 0 : publication.state) === "stopped" &&
|
|
471
|
+
(publication.publishingState === "failed" ||
|
|
472
|
+
Boolean((_a = error === null || error === void 0 ? void 0 : error.details) === null || _a === void 0 ? void 0 : _a.publishThrowError) ||
|
|
473
|
+
((_b = error === null || error === void 0 ? void 0 : error.details) === null || _b === void 0 ? void 0 : _b.newState) === "stopped");
|
|
474
|
+
};
|
|
475
|
+
/**
|
|
476
|
+
* Reports the errors of one publication to a publish action's onError with whether each ended the
|
|
477
|
+
* publish, and runs onPublishEnd before reporting the one that did. Only the first error that ends
|
|
478
|
+
* it is final, none after its challenge verification decided it, and an error pkc-js both emits and
|
|
479
|
+
* rejects publish() with (when every pubsub provider threw or the community's challenge exchange is
|
|
480
|
+
* disabled) is reported once. A rejected publish() ends the publish, although pkc-js leaves the
|
|
481
|
+
* state "publishing" when it rejects before a challenge exchange exists (signing, the RPC call).
|
|
482
|
+
*/
|
|
483
|
+
const createPublicationErrorReporter = (publication, onError, onPublishEnd) => {
|
|
484
|
+
let publishEnded = false;
|
|
485
|
+
let lastReportedError;
|
|
486
|
+
const report = (error, endsPublish) => __awaiter(void 0, void 0, void 0, function* () {
|
|
487
|
+
if (error === lastReportedError)
|
|
488
|
+
return;
|
|
489
|
+
lastReportedError = error;
|
|
490
|
+
const final = endsPublish && !publishEnded;
|
|
491
|
+
if (final) {
|
|
492
|
+
publishEnded = true;
|
|
493
|
+
yield onPublishEnd();
|
|
494
|
+
}
|
|
495
|
+
onError === null || onError === void 0 ? void 0 : onError(error, publication, { final });
|
|
496
|
+
});
|
|
497
|
+
return {
|
|
498
|
+
reportErrorEvent: (error) => report(error, isPublishEndingError(publication, error)),
|
|
499
|
+
reportPublishRejection: (error) => report(error, true),
|
|
500
|
+
onChallengeVerification: () => {
|
|
501
|
+
publishEnded = true;
|
|
502
|
+
},
|
|
503
|
+
};
|
|
504
|
+
};
|
|
463
505
|
export const addStoredAccountEditToState = (accountsEdits, accountId, storedAccountEdit) => {
|
|
464
506
|
const accountEdits = accountsEdits[accountId] || {};
|
|
465
507
|
const editTarget = getStoredAccountEditTarget(storedAccountEdit);
|
|
@@ -1113,6 +1155,22 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1113
1155
|
return persistedIndex;
|
|
1114
1156
|
});
|
|
1115
1157
|
let createdAccountComment;
|
|
1158
|
+
// a reload cancels publishing, so the publication's states stay out of the database except a
|
|
1159
|
+
// failed end: without it, the reloaded row has no state and counts as pending until it expires
|
|
1160
|
+
const saveFailedAccountComment = (index) => {
|
|
1161
|
+
var _a;
|
|
1162
|
+
if (!((_a = accountsStore.getState().accountsComments[account.id]) === null || _a === void 0 ? void 0 : _a[index])) {
|
|
1163
|
+
return;
|
|
1164
|
+
}
|
|
1165
|
+
const failedAccountComment = addShortAddressesToAccountComment(sanitizeStoredAccountComment(Object.assign(Object.assign({}, createdAccountComment), { state: "stopped", publishingState: "failed" })));
|
|
1166
|
+
accountsDatabase
|
|
1167
|
+
.addAccountComment(account.id, failedAccountComment, index)
|
|
1168
|
+
.catch((error) => log.error("accountsActions.publishComment save failed account comment error", {
|
|
1169
|
+
accountId: account.id,
|
|
1170
|
+
accountCommentIndex: index,
|
|
1171
|
+
error,
|
|
1172
|
+
}));
|
|
1173
|
+
};
|
|
1116
1174
|
const reportOnPendingCommentError = (error, pendingCommentIndex) => {
|
|
1117
1175
|
log.error("accountsActions.publishComment onPendingComment callback error", {
|
|
1118
1176
|
accountId: account.id,
|
|
@@ -1196,7 +1254,7 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1196
1254
|
}
|
|
1197
1255
|
});
|
|
1198
1256
|
};
|
|
1199
|
-
const recordPublishCommentError = (rawError, activeComment) => {
|
|
1257
|
+
const recordPublishCommentError = (rawError, activeComment, final) => {
|
|
1200
1258
|
const error = normalizePublishError(rawError);
|
|
1201
1259
|
if (lastReportedPublishError === error) {
|
|
1202
1260
|
return error;
|
|
@@ -1211,21 +1269,27 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1211
1269
|
const errors = previousErrors[previousErrors.length - 1] === error
|
|
1212
1270
|
? previousErrors
|
|
1213
1271
|
: [...previousErrors, error];
|
|
1214
|
-
|
|
1272
|
+
// a final error ends the account comment failed, also when pkc-js left the publication
|
|
1273
|
+
// publishing, as it does when publish() rejects in pre-flight
|
|
1274
|
+
ac[currentIndex] = final
|
|
1275
|
+
? Object.assign(Object.assign({}, acc), { errors, error, state: "stopped", publishingState: "failed" }) : Object.assign(Object.assign({}, acc), { errors, error });
|
|
1215
1276
|
}));
|
|
1277
|
+
if (final) {
|
|
1278
|
+
saveFailedAccountComment(currentIndex);
|
|
1279
|
+
}
|
|
1216
1280
|
return error;
|
|
1217
1281
|
};
|
|
1218
|
-
const reportActivePublishCommentError = (rawError, activeComment,
|
|
1282
|
+
const reportActivePublishCommentError = (rawError, activeComment, final) => {
|
|
1219
1283
|
var _a;
|
|
1220
1284
|
if (!getActiveSessionForComment(activeComment))
|
|
1221
1285
|
return;
|
|
1222
|
-
const error = recordPublishCommentError(rawError, activeComment);
|
|
1223
|
-
//
|
|
1224
|
-
//
|
|
1225
|
-
if (
|
|
1286
|
+
const error = recordPublishCommentError(rawError, activeComment, final);
|
|
1287
|
+
// only an error that ended the publish ends the session: pkc-js keeps processing the exchange
|
|
1288
|
+
// after an error it recovers from
|
|
1289
|
+
if (final) {
|
|
1226
1290
|
queueCleanupFailedPublishSession(activeComment);
|
|
1227
1291
|
}
|
|
1228
|
-
(_a = publishCommentOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, error, activeComment);
|
|
1292
|
+
(_a = publishCommentOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, error, activeComment, { final });
|
|
1229
1293
|
};
|
|
1230
1294
|
// the options onBeforeRepublish returns go through the same pipeline as the first publish; resolves
|
|
1231
1295
|
// to false when the publish was abandoned while onBeforeRepublish ran
|
|
@@ -1263,7 +1327,7 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1263
1327
|
accountsStore.setState(({ accountsComments }) => maybeUpdateAccountComment(accountsComments, account.id, session.currentIndex, (ac, acc) => {
|
|
1264
1328
|
ac[session.currentIndex] = Object.assign(Object.assign({}, acc), { state: "stopped", publishingState: "failed" });
|
|
1265
1329
|
}));
|
|
1266
|
-
(_a = publishCommentOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, "failed");
|
|
1330
|
+
(_a = publishCommentOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, "failed", failedComment);
|
|
1267
1331
|
reportActivePublishCommentError(error, failedComment, true);
|
|
1268
1332
|
};
|
|
1269
1333
|
function publishAndRetryFailedChallengeVerification() {
|
|
@@ -1324,6 +1388,10 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1324
1388
|
if (!session || isPublishSessionAbandoned(publishSessionId))
|
|
1325
1389
|
return;
|
|
1326
1390
|
const hasCid = !!((_a = challengeVerification === null || challengeVerification === void 0 ? void 0 : challengeVerification.commentUpdate) === null || _a === void 0 ? void 0 : _a.cid);
|
|
1391
|
+
// a rejection ends the publish failed, e.g. the community's challenge exchange timed out
|
|
1392
|
+
if (!hasCid && !(challengeVerification === null || challengeVerification === void 0 ? void 0 : challengeVerification.challengeSuccess)) {
|
|
1393
|
+
saveFailedAccountComment(session.currentIndex);
|
|
1394
|
+
}
|
|
1327
1395
|
// once the publication's last state events ran, they and any later ones are ignored; with a
|
|
1328
1396
|
// cid the session stays registered until the cid is saved, so a deleteComment meanwhile still
|
|
1329
1397
|
// shifts or abandons its row
|
|
@@ -1379,24 +1447,21 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1379
1447
|
}
|
|
1380
1448
|
}));
|
|
1381
1449
|
activeComment.on("error", (error) => {
|
|
1382
|
-
|
|
1450
|
+
// an error after the verdict is not reported: the verdict ends or detaches the session
|
|
1451
|
+
reportActivePublishCommentError(error, activeComment, isPublishEndingError(activeComment, error));
|
|
1383
1452
|
});
|
|
1453
|
+
// the session ends with the publication's final error, its rejected publish() or its verdict,
|
|
1454
|
+
// not with a stopped and failed state: pkc-js stops a publication before emitting the error that
|
|
1455
|
+
// ends it, awaiting its teardown in between, and stops it before publish() rejects when the
|
|
1456
|
+
// community fails to load, so ending the session here dropped that error
|
|
1384
1457
|
activeComment.on("statechange", (state) => {
|
|
1385
1458
|
const session = getActiveSessionForComment(activeComment);
|
|
1386
1459
|
if (!session)
|
|
1387
1460
|
return;
|
|
1388
1461
|
const currentIndex = session.currentIndex;
|
|
1389
|
-
let hasTerminalFailedState = false;
|
|
1390
1462
|
accountsStore.setState(({ accountsComments }) => maybeUpdateAccountComment(accountsComments, account.id, currentIndex, (ac, acc) => {
|
|
1391
|
-
|
|
1392
|
-
ac[currentIndex] = nextAccountComment;
|
|
1393
|
-
hasTerminalFailedState =
|
|
1394
|
-
nextAccountComment.state === "stopped" &&
|
|
1395
|
-
nextAccountComment.publishingState === "failed";
|
|
1463
|
+
ac[currentIndex] = Object.assign(Object.assign({}, acc), { state });
|
|
1396
1464
|
}));
|
|
1397
|
-
if (hasTerminalFailedState) {
|
|
1398
|
-
queueCleanupFailedPublishSession(activeComment);
|
|
1399
|
-
}
|
|
1400
1465
|
});
|
|
1401
1466
|
activeComment.on("publishingstatechange", (publishingState) => __awaiter(this, void 0, void 0, function* () {
|
|
1402
1467
|
var _a;
|
|
@@ -1404,18 +1469,12 @@ export const publishComment = (publishCommentOptions, accountName) => __awaiter(
|
|
|
1404
1469
|
if (!session)
|
|
1405
1470
|
return;
|
|
1406
1471
|
const currentIndex = session.currentIndex;
|
|
1407
|
-
let hasTerminalFailedState = false;
|
|
1408
1472
|
accountsStore.setState(({ accountsComments }) => maybeUpdateAccountComment(accountsComments, account.id, currentIndex, (ac, acc) => {
|
|
1409
|
-
|
|
1410
|
-
ac[currentIndex] = nextAccountComment;
|
|
1411
|
-
hasTerminalFailedState =
|
|
1412
|
-
nextAccountComment.state === "stopped" &&
|
|
1413
|
-
nextAccountComment.publishingState === "failed";
|
|
1473
|
+
ac[currentIndex] = Object.assign(Object.assign({}, acc), { publishingState });
|
|
1414
1474
|
}));
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
(_a = publishCommentOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, publishingState);
|
|
1475
|
+
// the hooks read the publication's state: pkc-js also reports "failed" for an error it
|
|
1476
|
+
// recovers from, while the publication keeps publishing
|
|
1477
|
+
(_a = publishCommentOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentOptions, publishingState, activeComment);
|
|
1419
1478
|
}));
|
|
1420
1479
|
// set clients on account comment so the frontend can display it, dont persist in db because a reload cancels publishing
|
|
1421
1480
|
utils.clientsOnStateChange(activeComment.clients, (clientState, clientType, clientUrl, chainTicker) => {
|
|
@@ -1619,15 +1678,17 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1619
1678
|
return;
|
|
1620
1679
|
let lastChallenge;
|
|
1621
1680
|
const publishAndRetryFailedChallengeVerification = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1622
|
-
var _a;
|
|
1623
1681
|
const activeVote = vote;
|
|
1624
1682
|
votePublishSession.publications.add(vote);
|
|
1683
|
+
// only an error that ended the publish fails the vote
|
|
1684
|
+
const errorReporter = createPublicationErrorReporter(activeVote, publishVoteOptions.onError, () => endVotePublication(activeVote, false));
|
|
1625
1685
|
vote.once("challenge", (challenge) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1626
1686
|
lastChallenge = challenge;
|
|
1627
1687
|
publishVoteOptions.onChallenge(challenge, withPublishChallengeAnswersCompat(vote, challenge));
|
|
1628
1688
|
}));
|
|
1629
1689
|
vote.once("challengeverification", (challengeVerification) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1630
1690
|
var _a;
|
|
1691
|
+
errorReporter.onChallengeVerification();
|
|
1631
1692
|
publishVoteOptions.onChallengeVerification(challengeVerification, vote);
|
|
1632
1693
|
// same terminal short-circuit as publishComment/publishCommentEdit: never retry a rejection
|
|
1633
1694
|
if (!challengeVerification.challengeSuccess &&
|
|
@@ -1643,7 +1704,7 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1643
1704
|
// no retry was published, so the failed vote ends the burst like a rejected one
|
|
1644
1705
|
votePublishSession.failed = true;
|
|
1645
1706
|
yield endVotePublishSessionIfSettled();
|
|
1646
|
-
(_a = publishVoteOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishVoteOptions, error, activeVote);
|
|
1707
|
+
(_a = publishVoteOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishVoteOptions, error, activeVote, { final: true });
|
|
1647
1708
|
return;
|
|
1648
1709
|
}
|
|
1649
1710
|
if (!isVotePublishSessionActive())
|
|
@@ -1655,17 +1716,9 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1655
1716
|
yield endVotePublication(activeVote, challengeVerification.challengeSuccess);
|
|
1656
1717
|
}
|
|
1657
1718
|
}));
|
|
1658
|
-
vote.on("error",
|
|
1659
|
-
var _a;
|
|
1660
|
-
// pkc-js also emits errors it recovers from, e.g. a challenge it cannot decrypt, and stops
|
|
1661
|
-
// the publication before emitting the ones that end it
|
|
1662
|
-
if (activeVote.state === "stopped") {
|
|
1663
|
-
yield endVotePublication(activeVote, false);
|
|
1664
|
-
}
|
|
1665
|
-
(_a = publishVoteOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishVoteOptions, error, vote);
|
|
1666
|
-
}));
|
|
1719
|
+
vote.on("error", errorReporter.reportErrorEvent);
|
|
1667
1720
|
// TODO: add publishingState to account votes
|
|
1668
|
-
vote.on("publishingstatechange", (publishingState) => { var _a; return (_a = publishVoteOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishVoteOptions, publishingState); });
|
|
1721
|
+
vote.on("publishingstatechange", (publishingState) => { var _a; return (_a = publishVoteOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishVoteOptions, publishingState, activeVote); });
|
|
1669
1722
|
listeners.push(vote);
|
|
1670
1723
|
try {
|
|
1671
1724
|
// publish will resolve after the challenge request
|
|
@@ -1673,8 +1726,7 @@ export const publishVote = (publishVoteOptions, accountName) => __awaiter(void 0
|
|
|
1673
1726
|
yield vote.publish();
|
|
1674
1727
|
}
|
|
1675
1728
|
catch (error) {
|
|
1676
|
-
yield
|
|
1677
|
-
(_a = publishVoteOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishVoteOptions, error, vote);
|
|
1729
|
+
yield errorReporter.reportPublishRejection(error);
|
|
1678
1730
|
}
|
|
1679
1731
|
});
|
|
1680
1732
|
publishAndRetryFailedChallengeVerification();
|
|
@@ -1775,12 +1827,15 @@ export const publishCommentEdit = (publishCommentEditOptions, accountName) => __
|
|
|
1775
1827
|
return nextState;
|
|
1776
1828
|
});
|
|
1777
1829
|
const publishAndRetryFailedChallengeVerification = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1778
|
-
|
|
1830
|
+
const activeCommentEdit = commentEdit;
|
|
1831
|
+
// only an error that ended the publish rolls back the edit
|
|
1832
|
+
const errorReporter = createPublicationErrorReporter(activeCommentEdit, publishCommentEditOptions.onError, rollbackStoredCommentEdit);
|
|
1779
1833
|
commentEdit.once("challenge", (challenge) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1780
1834
|
lastChallenge = challenge;
|
|
1781
1835
|
publishCommentEditOptions.onChallenge(challenge, withPublishChallengeAnswersCompat(commentEdit, challenge));
|
|
1782
1836
|
}));
|
|
1783
1837
|
commentEdit.once("challengeverification", (challengeVerification) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1838
|
+
errorReporter.onChallengeVerification();
|
|
1784
1839
|
publishCommentEditOptions.onChallengeVerification(challengeVerification, commentEdit);
|
|
1785
1840
|
if (challengeVerification.challengeSuccess) {
|
|
1786
1841
|
challengeSucceeded = true;
|
|
@@ -1798,13 +1853,9 @@ export const publishCommentEdit = (publishCommentEditOptions, accountName) => __
|
|
|
1798
1853
|
publishAndRetryFailedChallengeVerification();
|
|
1799
1854
|
}
|
|
1800
1855
|
}));
|
|
1801
|
-
commentEdit.on("error",
|
|
1802
|
-
var _a;
|
|
1803
|
-
yield rollbackStoredCommentEdit();
|
|
1804
|
-
(_a = publishCommentEditOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommentEditOptions, error, commentEdit);
|
|
1805
|
-
}));
|
|
1856
|
+
commentEdit.on("error", errorReporter.reportErrorEvent);
|
|
1806
1857
|
// TODO: add publishingState to account edits
|
|
1807
|
-
commentEdit.on("publishingstatechange", (publishingState) => { var _a; return (_a = publishCommentEditOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentEditOptions, publishingState); });
|
|
1858
|
+
commentEdit.on("publishingstatechange", (publishingState) => { var _a; return (_a = publishCommentEditOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentEditOptions, publishingState, activeCommentEdit); });
|
|
1808
1859
|
listeners.push(commentEdit);
|
|
1809
1860
|
try {
|
|
1810
1861
|
// publish will resolve after the challenge request
|
|
@@ -1812,8 +1863,7 @@ export const publishCommentEdit = (publishCommentEditOptions, accountName) => __
|
|
|
1812
1863
|
yield commentEdit.publish();
|
|
1813
1864
|
}
|
|
1814
1865
|
catch (error) {
|
|
1815
|
-
yield
|
|
1816
|
-
(_a = publishCommentEditOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommentEditOptions, error, commentEdit);
|
|
1866
|
+
yield errorReporter.reportPublishRejection(error);
|
|
1817
1867
|
}
|
|
1818
1868
|
});
|
|
1819
1869
|
publishAndRetryFailedChallengeVerification();
|
|
@@ -1863,12 +1913,15 @@ export const publishCommentModeration = (publishCommentModerationOptions, accoun
|
|
|
1863
1913
|
return rollbackPendingEditPromise || Promise.resolve();
|
|
1864
1914
|
};
|
|
1865
1915
|
const publishAndRetryFailedChallengeVerification = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1866
|
-
|
|
1916
|
+
const activeCommentModeration = commentModeration;
|
|
1917
|
+
// only an error that ended the publish rolls back the moderation
|
|
1918
|
+
const errorReporter = createPublicationErrorReporter(activeCommentModeration, publishCommentModerationOptions.onError, rollbackStoredCommentModeration);
|
|
1867
1919
|
commentModeration.once("challenge", (challenge) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1868
1920
|
lastChallenge = challenge;
|
|
1869
1921
|
publishCommentModerationOptions.onChallenge(challenge, withPublishChallengeAnswersCompat(commentModeration, challenge));
|
|
1870
1922
|
}));
|
|
1871
1923
|
commentModeration.once("challengeverification", (challengeVerification) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1924
|
+
errorReporter.onChallengeVerification();
|
|
1872
1925
|
publishCommentModerationOptions.onChallengeVerification(challengeVerification, commentModeration);
|
|
1873
1926
|
if (challengeVerification.challengeSuccess) {
|
|
1874
1927
|
challengeSucceeded = true;
|
|
@@ -1886,13 +1939,12 @@ export const publishCommentModeration = (publishCommentModerationOptions, accoun
|
|
|
1886
1939
|
publishAndRetryFailedChallengeVerification();
|
|
1887
1940
|
}
|
|
1888
1941
|
}));
|
|
1889
|
-
commentModeration.on("error",
|
|
1890
|
-
var _a;
|
|
1891
|
-
yield rollbackStoredCommentModeration();
|
|
1892
|
-
(_a = publishCommentModerationOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommentModerationOptions, error, commentModeration);
|
|
1893
|
-
}));
|
|
1942
|
+
commentModeration.on("error", errorReporter.reportErrorEvent);
|
|
1894
1943
|
// TODO: add publishingState to account edits
|
|
1895
|
-
commentModeration.on("publishingstatechange", (publishingState) => {
|
|
1944
|
+
commentModeration.on("publishingstatechange", (publishingState) => {
|
|
1945
|
+
var _a;
|
|
1946
|
+
return (_a = publishCommentModerationOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommentModerationOptions, publishingState, activeCommentModeration);
|
|
1947
|
+
});
|
|
1896
1948
|
listeners.push(commentModeration);
|
|
1897
1949
|
try {
|
|
1898
1950
|
// publish will resolve after the challenge request
|
|
@@ -1900,8 +1952,7 @@ export const publishCommentModeration = (publishCommentModerationOptions, accoun
|
|
|
1900
1952
|
yield commentModeration.publish();
|
|
1901
1953
|
}
|
|
1902
1954
|
catch (error) {
|
|
1903
|
-
yield
|
|
1904
|
-
(_a = publishCommentModerationOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommentModerationOptions, error, commentModeration);
|
|
1955
|
+
yield errorReporter.reportPublishRejection(error);
|
|
1905
1956
|
}
|
|
1906
1957
|
});
|
|
1907
1958
|
publishAndRetryFailedChallengeVerification();
|
|
@@ -1987,12 +2038,15 @@ export const publishCommunityEdit = (communityAddress, publishCommunityEditOptio
|
|
|
1987
2038
|
let communityEdit = backfillPublicationCommunityAddress(yield createPkcCommunityEdit(account.pkc, createCommunityEditOptions), createCommunityEditOptions);
|
|
1988
2039
|
let lastChallenge;
|
|
1989
2040
|
const publishAndRetryFailedChallengeVerification = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
1990
|
-
|
|
2041
|
+
const activeCommunityEdit = communityEdit;
|
|
2042
|
+
// only an error that ended the publish rolls back the edit
|
|
2043
|
+
const errorReporter = createPublicationErrorReporter(activeCommunityEdit, publishCommunityEditOptions.onError, rollbackStoredCommunityEdit);
|
|
1991
2044
|
communityEdit.once("challenge", (challenge) => __awaiter(void 0, void 0, void 0, function* () {
|
|
1992
2045
|
lastChallenge = challenge;
|
|
1993
2046
|
publishCommunityEditOptions.onChallenge(challenge, withPublishChallengeAnswersCompat(communityEdit, challenge));
|
|
1994
2047
|
}));
|
|
1995
2048
|
communityEdit.once("challengeverification", (challengeVerification) => __awaiter(void 0, void 0, void 0, function* () {
|
|
2049
|
+
errorReporter.onChallengeVerification();
|
|
1996
2050
|
publishCommunityEditOptions.onChallengeVerification(challengeVerification, communityEdit);
|
|
1997
2051
|
if (challengeVerification.challengeSuccess) {
|
|
1998
2052
|
challengeSucceeded = true;
|
|
@@ -2010,13 +2064,9 @@ export const publishCommunityEdit = (communityAddress, publishCommunityEditOptio
|
|
|
2010
2064
|
publishAndRetryFailedChallengeVerification();
|
|
2011
2065
|
}
|
|
2012
2066
|
}));
|
|
2013
|
-
communityEdit.on("error",
|
|
2014
|
-
var _a;
|
|
2015
|
-
yield rollbackStoredCommunityEdit();
|
|
2016
|
-
(_a = publishCommunityEditOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommunityEditOptions, error, communityEdit);
|
|
2017
|
-
}));
|
|
2067
|
+
communityEdit.on("error", errorReporter.reportErrorEvent);
|
|
2018
2068
|
// TODO: add publishingState to account edits
|
|
2019
|
-
communityEdit.on("publishingstatechange", (publishingState) => { var _a; return (_a = publishCommunityEditOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommunityEditOptions, publishingState); });
|
|
2069
|
+
communityEdit.on("publishingstatechange", (publishingState) => { var _a; return (_a = publishCommunityEditOptions.onPublishingStateChange) === null || _a === void 0 ? void 0 : _a.call(publishCommunityEditOptions, publishingState, activeCommunityEdit); });
|
|
2020
2070
|
listeners.push(communityEdit);
|
|
2021
2071
|
try {
|
|
2022
2072
|
// publish will resolve after the challenge request
|
|
@@ -2024,8 +2074,7 @@ export const publishCommunityEdit = (communityAddress, publishCommunityEditOptio
|
|
|
2024
2074
|
yield communityEdit.publish();
|
|
2025
2075
|
}
|
|
2026
2076
|
catch (error) {
|
|
2027
|
-
yield
|
|
2028
|
-
(_a = publishCommunityEditOptions.onError) === null || _a === void 0 ? void 0 : _a.call(publishCommunityEditOptions, error, communityEdit);
|
|
2077
|
+
yield errorReporter.reportPublishRejection(error);
|
|
2029
2078
|
}
|
|
2030
2079
|
});
|
|
2031
2080
|
yield storePublishedCommunityEdit();
|