@pkcprotocol/pkc-js 0.0.145 → 0.0.147
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/README.md +88 -55
- package/dist/browser/clients/base-client-manager.js +14 -2
- package/dist/browser/clients/base-client-manager.js.map +1 -1
- package/dist/browser/errors.d.ts +3 -0
- package/dist/browser/errors.js +3 -0
- package/dist/browser/errors.js.map +1 -1
- package/dist/browser/generated-version.d.ts +1 -1
- package/dist/browser/generated-version.js +1 -1
- package/dist/browser/pkc-error.d.ts +1 -1
- package/dist/browser/publications/comment/comment-client-manager.d.ts +15 -3
- package/dist/browser/publications/comment/comment-client-manager.js +221 -10
- package/dist/browser/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/browser/publications/comment/comment.js +1 -0
- package/dist/browser/publications/comment/comment.js.map +1 -1
- package/dist/browser/publications/publication.d.ts +1 -0
- package/dist/browser/publications/publication.js +24 -5
- package/dist/browser/publications/publication.js.map +1 -1
- package/dist/browser/runtime/node/community/challenges/index.js +14 -0
- package/dist/browser/runtime/node/community/challenges/index.js.map +1 -1
- package/dist/browser/runtime/node/community/db-handler.d.ts +5 -1
- package/dist/browser/runtime/node/community/db-handler.js +64 -12
- package/dist/browser/runtime/node/community/db-handler.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/db-state.d.ts +3 -1
- package/dist/browser/runtime/node/community/local-community/db-state.js +104 -16
- package/dist/browser/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/defaults.d.ts +1 -0
- package/dist/browser/runtime/node/community/local-community/defaults.js +5 -0
- package/dist/browser/runtime/node/community/local-community/defaults.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/editing.js +121 -24
- package/dist/browser/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js +2 -1
- package/dist/browser/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community/lifecycle.d.ts +2 -0
- package/dist/browser/runtime/node/community/local-community/lifecycle.js +153 -30
- package/dist/browser/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/browser/runtime/node/community/local-community.d.ts +5 -0
- package/dist/browser/runtime/node/community/local-community.js +10 -1
- package/dist/browser/runtime/node/community/local-community.js.map +1 -1
- package/dist/browser/runtime/node/util.d.ts +9 -0
- package/dist/browser/runtime/node/util.js +141 -25
- package/dist/browser/runtime/node/util.js.map +1 -1
- package/dist/browser/test/test-util.d.ts +7 -1
- package/dist/browser/test/test-util.js +45 -16
- package/dist/browser/test/test-util.js.map +1 -1
- package/dist/bundled/bundle-manifest.json +40 -40
- package/dist/bundled/challenges.js +1 -1
- package/dist/bundled/chunks/{helia-for-pkc-7vdzP67t.js → helia-for-pkc-jM3y3OXF.js} +2 -2
- package/dist/bundled/chunks/{local-community-UB_rVgR9.js → local-community-5X7bvOoN.js} +332 -70
- package/dist/bundled/chunks/{local-community-Bi1JGMMa.js → local-community-P9e5jksW.js} +1 -1
- package/dist/bundled/chunks/{node-BT3m9Nml.js → node-By3og2hw.js} +173 -17
- package/dist/bundled/chunks/{page-sort-scoring-Bsc4MAy1.js → page-sort-scoring-DwYGP_0d.js} +1 -1
- package/dist/bundled/chunks/{rpc-local-community-DVykDP0T.js → rpc-local-community-WnhiTbxm.js} +132 -29
- package/dist/bundled/chunks/{util-BxfB5cRB.js → util-7QtFMzpc.js} +1 -1
- package/dist/bundled/chunks/{util-D6z8nIoj.js → util-DMr7Hj-w.js} +4 -1
- package/dist/bundled/chunks/{validate-package-factories-CiY6DjnH.js → validate-package-factories-TwRblx9f.js} +2 -2
- package/dist/bundled/index.js +1 -1
- package/dist/bundled/page-sorts.js +1 -1
- package/dist/bundled/rpc/src/index.js +4 -4
- package/dist/node/clients/base-client-manager.js +14 -2
- package/dist/node/clients/base-client-manager.js.map +1 -1
- package/dist/node/errors.d.ts +3 -0
- package/dist/node/errors.js +3 -0
- package/dist/node/errors.js.map +1 -1
- package/dist/node/generated-version.d.ts +1 -1
- package/dist/node/generated-version.js +1 -1
- package/dist/node/pkc-error.d.ts +1 -1
- package/dist/node/publications/comment/comment-client-manager.d.ts +15 -3
- package/dist/node/publications/comment/comment-client-manager.js +221 -10
- package/dist/node/publications/comment/comment-client-manager.js.map +1 -1
- package/dist/node/publications/comment/comment.js +1 -0
- package/dist/node/publications/comment/comment.js.map +1 -1
- package/dist/node/publications/publication.d.ts +1 -0
- package/dist/node/publications/publication.js +24 -5
- package/dist/node/publications/publication.js.map +1 -1
- package/dist/node/runtime/node/community/challenges/index.js +14 -0
- package/dist/node/runtime/node/community/challenges/index.js.map +1 -1
- package/dist/node/runtime/node/community/db-handler.d.ts +5 -1
- package/dist/node/runtime/node/community/db-handler.js +64 -12
- package/dist/node/runtime/node/community/db-handler.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/db-state.d.ts +3 -1
- package/dist/node/runtime/node/community/local-community/db-state.js +104 -16
- package/dist/node/runtime/node/community/local-community/db-state.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/defaults.d.ts +1 -0
- package/dist/node/runtime/node/community/local-community/defaults.js +5 -0
- package/dist/node/runtime/node/community/local-community/defaults.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/editing.js +121 -24
- package/dist/node/runtime/node/community/local-community/editing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js +2 -1
- package/dist/node/runtime/node/community/local-community/ipns-publishing.js.map +1 -1
- package/dist/node/runtime/node/community/local-community/lifecycle.d.ts +2 -0
- package/dist/node/runtime/node/community/local-community/lifecycle.js +153 -30
- package/dist/node/runtime/node/community/local-community/lifecycle.js.map +1 -1
- package/dist/node/runtime/node/community/local-community.d.ts +5 -0
- package/dist/node/runtime/node/community/local-community.js +10 -1
- package/dist/node/runtime/node/community/local-community.js.map +1 -1
- package/dist/node/runtime/node/util.d.ts +9 -0
- package/dist/node/runtime/node/util.js +141 -25
- package/dist/node/runtime/node/util.js.map +1 -1
- package/dist/node/test/test-util.d.ts +7 -1
- package/dist/node/test/test-util.js +45 -16
- package/dist/node/test/test-util.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -43,13 +43,14 @@ Comment extends Publication /* (IPFS file) */ {
|
|
|
43
43
|
quotedCids?: string[] // CIDs of comments being quoted/referenced in this reply
|
|
44
44
|
crosspost?: {cid: string, comment: Comment} // this comment IS a repost of the embedded comment, which is stored verbatim so the crossposting community can moderate it independently
|
|
45
45
|
gallery?: GalleryItem[] // several images, videos or audio files, shown after the link card if both are set. Never empty, absent when there is no gallery. A gallery alone counts as content
|
|
46
|
+
postCid?: string // required on replies, helps faster loading post info for reply direct linking, undefined for posts, a post can't know its own CID
|
|
46
47
|
// below are added by community owner, not author
|
|
47
48
|
previousCid?: string // each comment/post is a linked list of other comments/posts with same comment.depth and comment.parentCid, undefined if first comment in list
|
|
48
|
-
postCid?: string // helps faster loading post info for reply direct linking, undefined for posts, a post can't know its own CID
|
|
49
49
|
depth: number // 0 = post, 1 = top level reply, 2+ = nested reply
|
|
50
50
|
thumbnailUrl?: string // optionally fetched by community owner, some web pages have thumbnail urls in their meta tags https://moz.com/blog/meta-data-templates-123
|
|
51
51
|
thumbnailUrlWidth?: number // community owner can optionally provide dimensions of thumbails which helps UI clients with infinite scrolling feeds
|
|
52
52
|
thumbnailUrlHeight?: number
|
|
53
|
+
pseudonymityMode?: 'per-post' | 'per-reply' | 'per-author' // the community.features.pseudonymityMode this comment was pseudonymized under, undefined if the community had none when it was published
|
|
53
54
|
}
|
|
54
55
|
GalleryItem { // other props are kept as signed, since a later protocol version may add some
|
|
55
56
|
url: string // 1-2000 chars. The community requires an https url whose path ends in an image, video or audio extension
|
|
@@ -122,8 +123,10 @@ CommentUpdate /* (IPFS file) */ {
|
|
|
122
123
|
lastChildCid?: string // the CID of the most recent direct reply that childCount counts
|
|
123
124
|
}
|
|
124
125
|
Author {
|
|
125
|
-
address: string
|
|
126
|
+
address: string // not part of IPFS files, added to `Author` instance as convenience: author.name if there is one, else author.publicKey
|
|
127
|
+
publicKey: string // not part of IPFS files, added to `Author` instance as convenience, derived from the publication's signature.publicKey
|
|
126
128
|
shortAddress: string // not part of IPFS files, added to `Author` instance as convenience. Copy address, if address is a hash, remove hash prefix and trim to 12 first chars
|
|
129
|
+
nameResolved?: boolean // not part of IPFS files, whether author.name resolved to the signing key
|
|
127
130
|
name?: string // author chosen username
|
|
128
131
|
previousCommentCid?: string // linked list of the author's comments
|
|
129
132
|
displayName?: string
|
|
@@ -168,7 +171,9 @@ Signer {
|
|
|
168
171
|
ipfsKey?: IpfsKey // a Key object used for importing into IpfsHttpClient https://docs.ipfs.io/reference/cli/#ipfs-key-import
|
|
169
172
|
}
|
|
170
173
|
Community /* (IPNS record, identified by community's public key) */ {
|
|
171
|
-
address: string // instance-only convenience property, not part of the IPNS record. Validate community address in signature to prevent a crypto domain resolving to an impersonated community
|
|
174
|
+
address: string // instance-only convenience property, not part of the IPNS record: community.name if there is one, else community.publicKey. Validate community address in signature to prevent a crypto domain resolving to an impersonated community
|
|
175
|
+
publicKey: string // instance-only convenience property, not part of the IPNS record: the IPNS name derived from the record's signature.publicKey
|
|
176
|
+
name?: string // optional crypto domain name of the community (e.g. 'memes.bso')
|
|
172
177
|
title?: string
|
|
173
178
|
description?: string
|
|
174
179
|
roles?: {[authorAddress: string]: CommunityRole} // each author address can be mapped to 1 CommunityRole
|
|
@@ -176,6 +181,11 @@ Community /* (IPNS record, identified by community's public key) */ {
|
|
|
176
181
|
lastPostCid?: string // the most recent post in the linked list of posts
|
|
177
182
|
lastCommentCid?: string // the most recent comment (posts and replies included), last comment is often displayed with a list of forums
|
|
178
183
|
posts?: Pages // only preload page 1 sorted by 'hot', might preload more later, comments should include Comment + CommentUpdate data
|
|
184
|
+
modQueue?: Pages // pageCids only (e.g. community.modQueue.pageCids.pendingApproval), the comments waiting for a mod's approval
|
|
185
|
+
postUpdates?: {[bucket: string]: string} // CIDs of the folders that hold each post's CommentUpdate, posts are grouped into time-based buckets, see docs/protocol/comment-lifecycle.md
|
|
186
|
+
challenges: CommunityChallenge[] // public description of the challenges an author has to pass, without the private settings.challenges options
|
|
187
|
+
pageSorts?: CommunityPageSorts // present when settings.pages is set, the public config of each page sort, see docs/protocol/page-sorts.md
|
|
188
|
+
anchor?: {publicKey: string} // present exactly when the community is delegated, see docs/protocol/delegated-ipns.md
|
|
179
189
|
statsCid?: string
|
|
180
190
|
createdAt: number
|
|
181
191
|
updatedAt: number
|
|
@@ -243,7 +253,7 @@ CommunityEncryption {
|
|
|
243
253
|
publicKey: string // 32 bytes base64 string
|
|
244
254
|
}
|
|
245
255
|
CommunityRole {
|
|
246
|
-
role: 'owner' | 'admin' | 'moderator'
|
|
256
|
+
role: 'owner' | 'admin' | 'moderator' // any other non-empty string is accepted as a custom role, with no built-in permissions
|
|
247
257
|
// TODO: custom roles with other props
|
|
248
258
|
}
|
|
249
259
|
Flair {
|
|
@@ -253,15 +263,15 @@ Flair {
|
|
|
253
263
|
expiresAt?: number // timestamp in seconds, a flair assigned to an author by a mod will follow the author in future comments, unless it expires
|
|
254
264
|
}
|
|
255
265
|
Pages {
|
|
256
|
-
pages: {[key: PostsSortType | RepliesSortType]: Page} // e.g. community.posts.pages.hot.comments[0].cid = '
|
|
257
|
-
pageCids
|
|
266
|
+
pages: {[key: PostsSortType | RepliesSortType]: Page} // e.g. community.posts.pages.hot.comments[0].cid = 'Qm...'
|
|
267
|
+
pageCids?: {[key: PostsSortType | RepliesSortType]: pageCid} // e.g. community.posts.pageCids.topAll = 'Qm...', absent when everything fits in the preloaded page
|
|
258
268
|
}
|
|
259
269
|
Page {
|
|
260
|
-
nextCid
|
|
270
|
+
nextCid?: string // get next page (sorted by the same sort type), undefined on the last page
|
|
261
271
|
comments: Comment[] // Comments should include merged Comment and CommentUpdate
|
|
262
272
|
}
|
|
263
273
|
PageIpfs /* (IPFS file) */ {
|
|
264
|
-
nextCid
|
|
274
|
+
nextCid?: string // get next page (sorted by the same sort type), undefined on the last page
|
|
265
275
|
comments: PageIpfsComment[] // PageIpfs is fetched from IPFS, then Comments and CommentUpdates are merged to create the Page instance
|
|
266
276
|
}
|
|
267
277
|
PageIpfsComment {
|
|
@@ -327,7 +337,7 @@ PubsubMessage: {
|
|
|
327
337
|
userAgent: `/pkc-js:${require('./package.json').version}/` // client name and version using this standard https://en.bitcoin.it/wiki/BIP_0014#Proposal
|
|
328
338
|
}
|
|
329
339
|
ChallengeRequestMessage extends PubsubMessage /* (sent by post author) */ {
|
|
330
|
-
acceptedChallengeTypes
|
|
340
|
+
acceptedChallengeTypes?: string[] // list of challenge types the client can do, for example cli clients or old clients won't do all types
|
|
331
341
|
encrypted: Encrypted
|
|
332
342
|
/* ChallengeRequestMessage.encrypted.ciphertext decrypts to JSON {
|
|
333
343
|
comment?: Comment
|
|
@@ -338,7 +348,7 @@ ChallengeRequestMessage extends PubsubMessage /* (sent by post author) */ {
|
|
|
338
348
|
challengeAnswers?: string[] // some challenges might be included in community.challenges and can be pre-answered
|
|
339
349
|
challengeCommentCids?: string[] // some challenges could require including comment cids in other communities, like friendly community karma challenges
|
|
340
350
|
}
|
|
341
|
-
pkc-js should decrypt the encrypted fields when possible, and add `ChallengeRequestMessage.
|
|
351
|
+
pkc-js should decrypt the encrypted fields when possible, and add them to the message for convenience, e.g. `ChallengeRequestMessage.comment` or `ChallengeRequestMessage.vote` (not part of the broadcasted pubsub message) */
|
|
342
352
|
}
|
|
343
353
|
ChallengeMessage extends PubsubMessage /* (sent by community owner) */ {
|
|
344
354
|
encrypted: Encrypted
|
|
@@ -358,12 +368,12 @@ ChallengeVerificationMessage extends PubsubMessage /* (sent by community owner)
|
|
|
358
368
|
challengeSuccess: bool // true if the challenge was successfully completed by the requester
|
|
359
369
|
challengeErrors?: {[challengeIndex: string]: string} // challenge index => challenge error, tell the user which challenge failed and why
|
|
360
370
|
reason?: string // reason for failed verification, for example post content is too long. could also be used for successful verification that bypass the challenge, for example because an author has good history
|
|
361
|
-
encrypted
|
|
371
|
+
encrypted?: Encrypted // only when a comment was published successfully
|
|
362
372
|
/* ChallengeVerificationMessage.encrypted.ciphertext decrypts to JSON {
|
|
363
|
-
comment
|
|
364
|
-
commentUpdate
|
|
373
|
+
comment: Comment // must contain missing props from comment publication, like depth, previousCid, etc
|
|
374
|
+
commentUpdate: CommentUpdate // only cid, signature, protocolVersion, author, number, postNumber and pendingApproval
|
|
365
375
|
}
|
|
366
|
-
pkc-js should decrypt the encrypted fields when possible, and add `ChallengeVerificationMessage.
|
|
376
|
+
pkc-js should decrypt the encrypted fields when possible, and add `ChallengeVerificationMessage.comment` and `ChallengeVerificationMessage.commentUpdate` properties for convenience (not part of the broadcasted pubsub message) */
|
|
367
377
|
}
|
|
368
378
|
Challenge {
|
|
369
379
|
type: 'image/png' | 'text/plain' | 'chain/<chainTicker>' // tells the client how to display the challenge, start with implementing image and text only first
|
|
@@ -410,12 +420,15 @@ PubsubSignature {
|
|
|
410
420
|
- `pkc.clients`
|
|
411
421
|
- [`pkc.getDefaults()`](#pkcgetdefaults) *(not yet implemented)*
|
|
412
422
|
- `pkc.fetchCid({cid})`
|
|
413
|
-
- `pkc.
|
|
414
|
-
- `
|
|
423
|
+
- `pkc.resolveAuthorName({name})`
|
|
424
|
+
- `pkc.destroy()`
|
|
425
|
+
- `PKC.getShortAddress({name})`
|
|
415
426
|
- `PKC.getShortCid({cid})`
|
|
416
427
|
- `PKC.setNativeFunctions(nativeFunctions)`
|
|
417
428
|
- `PKC.nativeFunctions`
|
|
418
429
|
- `PKC.challenges`
|
|
430
|
+
- `PKC.pageSorts`
|
|
431
|
+
- `PKC.createAnchorIpnsRecord({anchorSigner, minterIpnsName, sequence})`
|
|
419
432
|
- [PKC Events](#pkc-events)
|
|
420
433
|
- [`communitieschange`](#communitieschange)
|
|
421
434
|
- `error`
|
|
@@ -489,7 +502,6 @@ PubsubSignature {
|
|
|
489
502
|
- `comment.shortCid`
|
|
490
503
|
- `(only available after first update event)`
|
|
491
504
|
- `comment.edit`
|
|
492
|
-
- `comment.original`
|
|
493
505
|
- `comment.upvoteCount`
|
|
494
506
|
- `comment.downvoteCount`
|
|
495
507
|
- `comment.updatedAt`
|
|
@@ -519,8 +531,8 @@ PubsubSignature {
|
|
|
519
531
|
- `client.settings`
|
|
520
532
|
- `client.setSettings(pkcRpcSettings)`
|
|
521
533
|
- `client.rpcCall(method, params)`
|
|
522
|
-
- `client.getPeers()`
|
|
523
|
-
- `client.getStats()`
|
|
534
|
+
- `client.getPeers()` *(not yet implemented)*
|
|
535
|
+
- `client.getStats()` *(not yet implemented)*
|
|
524
536
|
- [Client Events](#client-events)
|
|
525
537
|
- [`statechange`](#statechange-2)
|
|
526
538
|
- [`settingschange`](#settingschange)
|
|
@@ -567,15 +579,22 @@ An object which may have the following keys:
|
|
|
567
579
|
#### Example
|
|
568
580
|
|
|
569
581
|
```js
|
|
570
|
-
|
|
582
|
+
import PKC from '@pkcprotocol/pkc-js'
|
|
571
583
|
const options = {
|
|
572
584
|
kuboRpcClientsOptions: ['http://localhost:5001/api/v0'], // optional, must run an IPFS node to use localhost:5001/api/v0
|
|
573
|
-
dataPath:
|
|
585
|
+
dataPath: import.meta.dirname
|
|
574
586
|
}
|
|
575
587
|
const pkc = await PKC(options) // should be independent instance, not singleton
|
|
576
588
|
pkc.on('error', console.log)
|
|
577
589
|
```
|
|
578
590
|
|
|
591
|
+
`pkc-js` is an ES module. From CommonJS, `require()` returns the module namespace, so the factory is on `.default` (calling the namespace itself throws `TypeError: PKC is not a function`):
|
|
592
|
+
|
|
593
|
+
```js
|
|
594
|
+
const PKC = require('@pkcprotocol/pkc-js').default
|
|
595
|
+
const { getShortAddress, getShortCid } = require('@pkcprotocol/pkc-js') // the named exports are on the namespace
|
|
596
|
+
```
|
|
597
|
+
|
|
579
598
|
### Error handling
|
|
580
599
|
|
|
581
600
|
A pkc instance is an EventEmitter, and so are the publications, communities, and comments it produces. Internal child objects forward their unhandled errors up to the pkc instance, but the pkc instance itself has no default error listener.
|
|
@@ -672,7 +691,9 @@ console.log(communityList.communities.map(entry => entry.address))
|
|
|
672
691
|
|
|
673
692
|
| Name | Type | Description |
|
|
674
693
|
| ---- | ---- | ----------- |
|
|
675
|
-
| address | `string` | The `Address` of the community |
|
|
694
|
+
| address | `string` or `undefined` | The `Address` of the community. At least one of `address`, `name` or `publicKey` is required |
|
|
695
|
+
| name | `string` or `undefined` | Domain name of the community, e.g. `'memes.bso'` |
|
|
696
|
+
| publicKey | `string` or `undefined` | IPNS public key of the community. Passing it with `name` loads without waiting on a name resolver |
|
|
676
697
|
| abortSignal | `AbortSignal` | Optional. Cancels the fetch instead of waiting out the `community-ipns` timeout. Rejects with `ERR_GET_COMMUNITY_ABORTED`. |
|
|
677
698
|
|
|
678
699
|
#### Returns
|
|
@@ -829,7 +850,9 @@ An object which may have the following keys:
|
|
|
829
850
|
|
|
830
851
|
| Name | Type | Default | Description |
|
|
831
852
|
| ---- | ---- | ------- | ----------- |
|
|
832
|
-
| address | `string` or `undefined` | `undefined` | `Address` of
|
|
853
|
+
| address | `string` or `undefined` | `undefined` | `Address` of an existing community, either its domain name or its public key |
|
|
854
|
+
| name | `string` or `undefined` | `undefined` | Domain name of an existing community, e.g. `'memes.bso'`, or the name to give a new one |
|
|
855
|
+
| publicKey | `string` or `undefined` | `undefined` | IPNS public key of an existing community |
|
|
833
856
|
| signer | `Signer` or `undefined` | `undefined` | (Community owners only) Optional `Signer` of the community to create a community with a specific private key |
|
|
834
857
|
| anchor | `{publicKey: string}` or `undefined` | `undefined` | (Community owners only) Create a **delegated** community: the community's identity is this anchor IPNS name, whose private key you keep, and the node generates its own signing (minter) key. Mutually exclusive with `signer`. Every record the community publishes advertises this anchor in a signed `anchor` field, so readers who reach the record through the minter recover the identity. See [docs/protocol/delegated-ipns.md](docs/protocol/delegated-ipns.md) |
|
|
835
858
|
| ...community | `any` | `undefined` | `CreateCommunityOptions` can also initialize any property on the `Community` instance |
|
|
@@ -843,10 +866,10 @@ An object which may have the following keys:
|
|
|
843
866
|
#### Example
|
|
844
867
|
|
|
845
868
|
```js
|
|
846
|
-
|
|
869
|
+
import PKC from '@pkcprotocol/pkc-js'
|
|
847
870
|
const pkcOptions = {
|
|
848
871
|
kuboRpcClientsOptions: ['http://localhost:5001/api/v0'], // optional, must run an IPFS node to use localhost:5001/api/v0
|
|
849
|
-
dataPath:
|
|
872
|
+
dataPath: import.meta.dirname
|
|
850
873
|
}
|
|
851
874
|
const pkc = await PKC(pkcOptions)
|
|
852
875
|
pkc.on('error', console.log)
|
|
@@ -886,7 +909,7 @@ await community.edit({
|
|
|
886
909
|
pubsubTopic: '12D3KooW...'
|
|
887
910
|
})
|
|
888
911
|
|
|
889
|
-
// start publishing updates
|
|
912
|
+
// start publishing updates
|
|
890
913
|
await community.start()
|
|
891
914
|
|
|
892
915
|
// instantiate an already existing community instance and initialize any property on it
|
|
@@ -973,11 +996,14 @@ An object which may have the following keys:
|
|
|
973
996
|
| author | `Author` | Author of the comment |
|
|
974
997
|
| signer | `Signer` | Signer of the comment |
|
|
975
998
|
| parentCid | `string` or `undefined` | The parent comment CID, undefined if comment is a post, same as postCid if comment is top level |
|
|
999
|
+
| postCid | `string` or `undefined` | The CID of the post the reply is under, required when `parentCid` is set, undefined if comment is a post |
|
|
976
1000
|
| content | `string` or `undefined` | Content of the comment, link posts have no content |
|
|
977
1001
|
| title | `string` or `undefined` | If comment is a post, it needs a title |
|
|
978
1002
|
| link | `string` or `undefined` | If comment is a post, it might be a link post |
|
|
979
1003
|
| spoiler | `boolean` or `undefined` | Hide the comment thumbnail behind spoiler warning |
|
|
1004
|
+
| nsfw | `boolean` or `undefined` | Mark the comment as not safe for work |
|
|
980
1005
|
| flairs | `Flair[]` or `undefined` | Author or mod chosen colored labels for the comment |
|
|
1006
|
+
| linkWidth, linkHeight, linkHtmlTagName, quotedCids, crosspost, gallery | | See `Comment` in the [schema](#schema) |
|
|
981
1007
|
| challengeRequest | `ChallengeRequest` or `undefined` | Optional properties to pass to `ChallengeRequestPubsubMessage` |
|
|
982
1008
|
| cid | `string` or `undefined` | (Not for publishing) Gives access to `Comment.on('update')` for a comment already fetched |
|
|
983
1009
|
| ...comment | `any` | `CreateCommentOptions` can also initialize any property on the `Comment` instance |
|
|
@@ -1057,6 +1083,7 @@ An object which may have the following keys:
|
|
|
1057
1083
|
| deleted | `boolean` or `undefined` | Edited deleted status of the comment |
|
|
1058
1084
|
| flairs | `Flair[]` or `undefined` | Edited flairs of the comment |
|
|
1059
1085
|
| spoiler | `boolean` or `undefined` | Edited spoiler of the comment |
|
|
1086
|
+
| nsfw | `boolean` or `undefined` | Edited nsfw status of the comment |
|
|
1060
1087
|
| reason | `string` or `undefined` | Reason of the edit |
|
|
1061
1088
|
| challengeRequest | `ChallengeRequest` or `undefined` | Optional properties to pass to `ChallengeRequestPubsubMessage` |
|
|
1062
1089
|
|
|
@@ -1292,13 +1319,13 @@ The PKC events.
|
|
|
1292
1319
|
|
|
1293
1320
|
### `communitieschange`
|
|
1294
1321
|
|
|
1295
|
-
> `
|
|
1322
|
+
> `pkc.communities` property changed: a community was created, deleted, renamed, started or stopped.
|
|
1296
1323
|
|
|
1297
1324
|
#### Emits
|
|
1298
1325
|
|
|
1299
1326
|
| Type | Description |
|
|
1300
1327
|
| -------- | -------- |
|
|
1301
|
-
| `{ communities: { name?: string, publicKey: string, address: string, started: boolean }[] }` | The new `
|
|
1328
|
+
| `{ communities: { name?: string, publicKey: string, address: string, started: boolean }[] }` | The new `pkc.communities` property |
|
|
1302
1329
|
|
|
1303
1330
|
## Community API
|
|
1304
1331
|
The community API for getting community updates, or creating, editing, running a community as an owner.
|
|
@@ -1345,19 +1372,17 @@ An object which may have the following keys:
|
|
|
1345
1372
|
| ---- | ---- | ----------- |
|
|
1346
1373
|
| name | `string` or `undefined` | Crypto domain of the community, e.g. `'memes.bso'`. Changing it renames the community (its address, DB and start lock move to the new name) and hides the comments signed with the old name; `undefined` drops the name and the address becomes the public key, see [Changing a community's name](docs/protocol/names-and-addresses.md#changing-a-communitys-name). Owner-only over pubsub, see [Community roles and permissions](#community-roles-and-permissions) |
|
|
1347
1374
|
| address | `string` or `undefined` | Legacy alias of `name`, kept for backward compatibility: a domain passed here is applied as `name`, the community's public key drops the name. Passing both `name` and `address` with different values throws `ERR_COMMUNITY_EDIT_NAME_AND_ADDRESS_MISMATCH`, see [Changing a community's name](docs/protocol/names-and-addresses.md#changing-a-communitys-name) |
|
|
1348
|
-
| signer | `Signer` or `undefined` | Signer of the community, useful to change the private if the owner gets hacked, but still has his crypto domain
|
|
1349
1375
|
| title | `string` or `undefined` | Title of the community |
|
|
1350
1376
|
| description | `string` or `undefined` | Description of the community |
|
|
1351
1377
|
| rules | `string[]` or `undefined` | Rules of the community |
|
|
1352
1378
|
| roles | `{[authorAddress: string]: CommunityRole}` or `undefined` | Author identities assigned `owner`, `admin`, or `moderator`; see [Community roles and permissions](#community-roles-and-permissions) |
|
|
1353
|
-
| lastPostCid | `string` or `undefined` | The most recent post in the linked list of posts |
|
|
1354
|
-
| posts | `Pages` or `undefined` | Only preload page 1 sorted by 'hot', might preload more later, should include some child comments and vote counts for each post |
|
|
1355
1379
|
| pubsubTopic | `string` or `undefined` | The string to publish to in the pubsub, a public key of the community owner's choice |
|
|
1356
1380
|
| features | `CommunityFeatures` or `undefined` | The features of the community |
|
|
1357
1381
|
| suggested | `CommunitySuggested` or `undefined` | The suggested client settings for the community |
|
|
1358
1382
|
| flairs | `{[key: 'post' or 'author']: Flair[]}` or `undefined` | The list of flairs (colored labels for comments or authors) authors or mods can choose from |
|
|
1359
1383
|
| settings | `CommunitySettings` or `undefined` | The private community.settings property of the community, not shared in the community IPNS |
|
|
1360
|
-
|
|
1384
|
+
|
|
1385
|
+
`community.pageSorts` is read-only and cannot be passed to `community.edit()`: it is what the community publishes about its configured page sorts (`settings.pages`), keyed by sort name per scope: `{ posts?: {[sortName]: { name?, description?, publicOptions? }}, replies?: ... }`. `publicOptions` is the full option set the sort runs with (reserved options included) minus `privateOptions`, so a client that installed the same package can re-sort a page locally with its `score` (see "Client side" in [docs/protocol/page-sorts.md](docs/protocol/page-sorts.md)). Absent when `settings.pages` is unset.
|
|
1361
1386
|
|
|
1362
1387
|
##### CommunitySettings
|
|
1363
1388
|
|
|
@@ -1367,6 +1392,9 @@ An object which may have the following keys:
|
|
|
1367
1392
|
| ---- | ---- | ----------- |
|
|
1368
1393
|
| fetchThumbnailUrls | `boolean` or `undefined` | Fetch the thumbnail URLs of comments `comment.link` property, could reveal the IP address of the community node |
|
|
1369
1394
|
| fetchThumbnailUrlsProxyUrl | `string` or `undefined` | The HTTP proxy URL used to fetch thumbnail URLs |
|
|
1395
|
+
| challenges | `CommunityChallengeSetting[]` or `undefined` | The challenges an author has to pass to publish, an empty array removes all challenges. See [docs/protocol/challenge-settings.md](docs/protocol/challenge-settings.md) |
|
|
1396
|
+
| maxPendingApprovalCount | `number` or `undefined` | Most comments kept waiting for a mod's approval, the oldest is dropped once the count is hit. Defaults to `500` |
|
|
1397
|
+
| purgeDisapprovedCommentsOlderThan | `number` or `undefined` | Seconds after which a disapproved comment is purged from the community |
|
|
1370
1398
|
| disablePubsubChallengeExchange | `boolean` or `undefined` | Make the community read-only over the network. The node stops subscribing to the challenge/publication pubsub topic and the published record omits `pubsubTopic`, so clients know not to attempt a challenge exchange and fail fast with `ERR_COMMUNITY_CHALLENGE_EXCHANGE_DISABLED`. The owner can still publish through the local shortcut (same process or through the RPC server running the community). The configured `community.pubsubTopic` is kept while the setting is on, including across a restart, and is published again as-is when the setting is turned off |
|
|
1371
1399
|
| pages | `CommunityPagesSettings` or `undefined` | Which page sorts to generate and which to embed in the record, per scope: `{ posts?: CommunityPageSortSetting[], replies?: CommunityPageSortSetting[] }`. Unset generates today's default sorts. Any change regenerates every CommentUpdate. See [docs/protocol/page-sorts.md](docs/protocol/page-sorts.md) |
|
|
1372
1400
|
|
|
@@ -1391,7 +1419,7 @@ One entry of `settings.pages.posts` / `settings.pages.replies`, mirroring `Commu
|
|
|
1391
1419
|
|
|
1392
1420
|
### `community.start()`
|
|
1393
1421
|
|
|
1394
|
-
> Start listening for new posts on the pubsub, and publishing them
|
|
1422
|
+
> Start listening for new posts on the pubsub, and publishing them in the community's IPNS record. Only usable if the community database corresponding to `community.address` exists locally (ie. you are the community owner).
|
|
1395
1423
|
|
|
1396
1424
|
#### Example
|
|
1397
1425
|
|
|
@@ -1412,7 +1440,7 @@ await community.start()
|
|
|
1412
1440
|
|
|
1413
1441
|
### `community.stop()`
|
|
1414
1442
|
|
|
1415
|
-
> Stop polling the network for new community updates started by community.update(). Also stop listening for new posts on the pubsub started by community.start(), and stop publishing them
|
|
1443
|
+
> Stop polling the network for new community updates started by community.update(). Also stop listening for new posts on the pubsub started by community.start(), and stop publishing them.
|
|
1416
1444
|
|
|
1417
1445
|
### `community.update()`
|
|
1418
1446
|
|
|
@@ -1503,7 +1531,7 @@ community.on('update', (updatedCommunity) => console.log(updatedCommunity))
|
|
|
1503
1531
|
community.update()
|
|
1504
1532
|
|
|
1505
1533
|
// stop updating in 10 minutes
|
|
1506
|
-
setTimeout(() => community.stop(),
|
|
1534
|
+
setTimeout(() => community.stop(), 600000)
|
|
1507
1535
|
```
|
|
1508
1536
|
|
|
1509
1537
|
### `challengerequest`
|
|
@@ -1530,7 +1558,7 @@ Object is of the form:
|
|
|
1530
1558
|
|
|
1531
1559
|
### `challengeanswer`
|
|
1532
1560
|
|
|
1533
|
-
> After receiving a `Challenge`, the user
|
|
1561
|
+
> After receiving a `Challenge`, the user will send back a `challengeanswer`.
|
|
1534
1562
|
|
|
1535
1563
|
#### Emits
|
|
1536
1564
|
|
|
@@ -1562,7 +1590,7 @@ Object is of the form:
|
|
|
1562
1590
|
|
|
1563
1591
|
| Type | Description |
|
|
1564
1592
|
| -------- | -------- |
|
|
1565
|
-
| `'stopped' \| 'resolving-
|
|
1593
|
+
| `'stopped' \| 'resolving-name' \| 'fetching-ipns' \| 'fetching-ipfs' \| 'publishing-ipns' \| 'waiting-retry' \| 'failed' \| 'succeeded'` | The `Community.updatingState` property |
|
|
1566
1594
|
|
|
1567
1595
|
### `startedstatechange`
|
|
1568
1596
|
|
|
@@ -1572,10 +1600,10 @@ Object is of the form:
|
|
|
1572
1600
|
|
|
1573
1601
|
| Type | Description |
|
|
1574
1602
|
| -------- | -------- |
|
|
1575
|
-
| `'stopped' \| '
|
|
1603
|
+
| `'stopped' \| 'publishing-ipns' \| 'failed' \| 'succeeded'` | The `Community.startedState` property |
|
|
1576
1604
|
|
|
1577
1605
|
## Comment API
|
|
1578
|
-
The comment API for publishing a comment as an author, or getting comment updates. `Comment`, `Vote` and `CommentEdit` inherit `Publication` class and all have a similar API. A `Comment` updates
|
|
1606
|
+
The comment API for publishing a comment as an author, or getting comment updates. `Comment`, `Vote` and `CommentEdit` inherit `Publication` class and all have a similar API. A `Comment` updates itself on update events after `Comment.update()` is called if `Comment.cid` exists.
|
|
1579
1607
|
|
|
1580
1608
|
### `comment.publish()`
|
|
1581
1609
|
|
|
@@ -1617,7 +1645,7 @@ await comment.publish()
|
|
|
1617
1645
|
|
|
1618
1646
|
### `comment.update()`
|
|
1619
1647
|
|
|
1620
|
-
> Start polling the network for comment updates (replies, upvotes, edits, etc), update itself and emit the update event. Only usable if comment.cid
|
|
1648
|
+
> Start polling the network for comment updates (replies, upvotes, edits, etc), update itself and emit the update event. Only usable if comment.cid exists.
|
|
1621
1649
|
|
|
1622
1650
|
#### Example
|
|
1623
1651
|
|
|
@@ -1674,7 +1702,7 @@ comment.on('update', (updatedComment) => {
|
|
|
1674
1702
|
comment.update()
|
|
1675
1703
|
|
|
1676
1704
|
// stop looking for updates after 10 minutes
|
|
1677
|
-
setTimeout(() => comment.stop(),
|
|
1705
|
+
setTimeout(() => comment.stop(), 600000)
|
|
1678
1706
|
```
|
|
1679
1707
|
|
|
1680
1708
|
### `challenge`
|
|
@@ -1731,7 +1759,7 @@ comment.on('challenge', async (challengeMessage) => {
|
|
|
1731
1759
|
const challengeAnswers = await askUserForChallengeAnswers(challengeMessage.challenges)
|
|
1732
1760
|
comment.publishChallengeAnswers({ challengeAnswers })
|
|
1733
1761
|
})
|
|
1734
|
-
comment.on('challengeverification', (challengeVerification) => console.log('published post cid is', challengeVerification?.
|
|
1762
|
+
comment.on('challengeverification', (challengeVerification) => console.log('published post cid is', challengeVerification.commentUpdate?.cid))
|
|
1735
1763
|
await comment.publish()
|
|
1736
1764
|
```
|
|
1737
1765
|
|
|
@@ -1753,7 +1781,7 @@ await comment.publish()
|
|
|
1753
1781
|
|
|
1754
1782
|
| Type | Description |
|
|
1755
1783
|
| -------- | -------- |
|
|
1756
|
-
| `'stopped' \| 'resolving-author-
|
|
1784
|
+
| `'stopped' \| 'resolving-author-name' \| 'fetching-ipfs' \| 'fetching-update-ipfs' \| 'resolving-community-name' \| 'fetching-community-ipns' \| 'fetching-community-ipfs' \| 'waiting-retry' \| 'failed' \| 'succeeded'` | The `Comment.updatingState` property |
|
|
1757
1785
|
|
|
1758
1786
|
### `publishingstatechange`
|
|
1759
1787
|
|
|
@@ -1763,7 +1791,7 @@ await comment.publish()
|
|
|
1763
1791
|
|
|
1764
1792
|
| Type | Description |
|
|
1765
1793
|
| -------- | -------- |
|
|
1766
|
-
| `'stopped' \| 'resolving-community-
|
|
1794
|
+
| `'stopped' \| 'resolving-community-name' \| 'fetching-community-ipns' \| 'fetching-community-ipfs' \| 'publishing-challenge-request' \| 'waiting-challenge' \| 'waiting-challenge-answers' \| 'publishing-challenge-answer' \| 'waiting-challenge-verification' \| 'failed' \| 'succeeded'` | The `Comment.publishingState` property |
|
|
1767
1795
|
|
|
1768
1796
|
## Pages API
|
|
1769
1797
|
The pages API for scrolling pages of a community or replies to a post/comment. `Community.posts` and `Comment.replies` are `Pages` instances. `Community.posts.pages.hot` is a `Page` instance.
|
|
@@ -1823,25 +1851,30 @@ The client events.
|
|
|
1823
1851
|
|
|
1824
1852
|
| Type | Description |
|
|
1825
1853
|
| -------- | -------- |
|
|
1826
|
-
| `'stopped' \| 'resolving-author-
|
|
1854
|
+
| `'stopped' \| 'resolving-author-name' \| 'fetching-ipfs' \| 'fetching-update-ipfs' \| 'resolving-community-name' \| 'fetching-community-ipns' \| 'fetching-community-ipfs' \| 'fetching-ipns' \| 'publishing-ipns' \| 'subscribing-pubsub' \| 'publishing-challenge-request' \| 'waiting-challenge' \| 'waiting-challenge-answers' \| 'publishing-challenge-answer' \| 'waiting-challenge-verification' \| 'waiting-challenge-requests' \| 'publishing-challenge' \| 'publishing-challenge-verification' \| 'connecting' \| 'connected' \| 'failed'` | The `Client.state` property. Which states a client goes through depends on its kind and on whether it belongs to a comment, a community or the pkc instance |
|
|
1827
1855
|
|
|
1828
1856
|
#### Example
|
|
1829
1857
|
|
|
1830
1858
|
```js
|
|
1831
1859
|
const onStateChange = (state) => console.log('client state changed:', state)
|
|
1832
|
-
|
|
1833
|
-
|
|
1860
|
+
const { clients } = comment
|
|
1861
|
+
for (const clientUrl in clients.ipfsGateways) {
|
|
1862
|
+
clients.ipfsGateways[clientUrl].on('statechange', onStateChange)
|
|
1834
1863
|
}
|
|
1835
|
-
for (const clientUrl in clients
|
|
1836
|
-
|
|
1864
|
+
for (const clientUrl in clients.kuboRpcClients) {
|
|
1865
|
+
clients.kuboRpcClients[clientUrl].on('statechange', onStateChange)
|
|
1837
1866
|
}
|
|
1838
|
-
for (const clientUrl in clients
|
|
1839
|
-
|
|
1867
|
+
for (const clientUrl in clients.pubsubKuboRpcClients) {
|
|
1868
|
+
clients.pubsubKuboRpcClients[clientUrl].on('statechange', onStateChange)
|
|
1840
1869
|
}
|
|
1841
|
-
for (const
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1870
|
+
for (const clientKey in clients.libp2pJsClients) {
|
|
1871
|
+
clients.libp2pJsClients[clientKey].on('statechange', onStateChange)
|
|
1872
|
+
}
|
|
1873
|
+
for (const clientUrl in clients.pkcRpcClients) {
|
|
1874
|
+
clients.pkcRpcClients[clientUrl].on('statechange', onStateChange)
|
|
1875
|
+
}
|
|
1876
|
+
for (const resolverKey in clients.nameResolvers) {
|
|
1877
|
+
clients.nameResolvers[resolverKey].on('statechange', onStateChange)
|
|
1845
1878
|
}
|
|
1846
1879
|
```
|
|
1847
1880
|
|
|
@@ -51,6 +51,14 @@ const GATEWAYS_THAT_SUPPORT_SUBDOMAIN_RESOLUTION = {}; // gateway url -> whether
|
|
|
51
51
|
// 100 sits above the realistic batch window, so coalescing survives, and caps the burst for the
|
|
52
52
|
// resolvers that do not batch.
|
|
53
53
|
const MAX_CONCURRENT_AUTHOR_NAME_RESOLUTIONS = 100;
|
|
54
|
+
// Whether a path resolve failed because a directory on the way was read and has no entry of that name. Kubo's RPC
|
|
55
|
+
// reports it as an HTTP 500 whose message is `no link named "<name>" under <cid>`, with no code of its own, and helia's
|
|
56
|
+
// unixfs throws DoesNotExistError. A directory that could not be loaded fails differently (a timeout, no providers)
|
|
57
|
+
function isIpfsPathNotInFolderError(error) {
|
|
58
|
+
if (!(error instanceof Error))
|
|
59
|
+
return false;
|
|
60
|
+
return error.name === "DoesNotExistError" || (error.name === "HTTPError" && /^no link named /.test(error.message));
|
|
61
|
+
}
|
|
54
62
|
// Waits for a resolve another caller started. A resolve is bounded only by its owner's signal, so the wait
|
|
55
63
|
// ends as soon as the joiner is stopped and leaves nothing on the resolve: a stopped Comment or community must
|
|
56
64
|
// not stay referenced through its onResolved until someone else's resolve settles.
|
|
@@ -688,8 +696,10 @@ export class BaseClientsManager {
|
|
|
688
696
|
// The cid an /ipfs/ path names, as CIDv1, or undefined when it cannot be told. Files are content-addressed, so a
|
|
689
697
|
// caller comparing it with the cid it last fetched can skip an unchanged file without reading it (issue #312).
|
|
690
698
|
// Kubo and helia walk only the directory blocks on the way, which an unchanged path already has locally. Undefined
|
|
691
|
-
// with only gateways. Throws
|
|
692
|
-
//
|
|
699
|
+
// with only gateways. Throws ERR_FETCH_CID_P2P_TIMEOUT when the walk could not reach the path's blocks in time: a
|
|
700
|
+
// fetch of the path would walk the same blocks. Throws ERR_IPFS_PATH_NOT_IN_FOLDER when the walk read the folder and
|
|
701
|
+
// it has no such entry: the folder is named by its cid, so that answer does not change and a fetch would only
|
|
702
|
+
// repeat it. Any other failure is undefined, and the caller fetches anyway.
|
|
693
703
|
async _resolveIpfsPathToCid({ root, path, timeoutMs, abortSignal, log, bitswapSessionSeedScopeIpnsPubsubTopic }) {
|
|
694
704
|
try {
|
|
695
705
|
if (keys(this._pkc.clients.kuboRpcClients).length > 0 || keys(this._pkc.clients.libp2pJsClients).length > 0) {
|
|
@@ -716,6 +726,8 @@ export class BaseClientsManager {
|
|
|
716
726
|
throw e; // helia's own timeout
|
|
717
727
|
if (e instanceof Error && e.name === "TimeoutError" && !abortSignal?.aborted)
|
|
718
728
|
throw new PKCError("ERR_FETCH_CID_P2P_TIMEOUT", { ipfsPath: `/ipfs/${root}/${path}`, timeoutMs, error: e });
|
|
729
|
+
if (isIpfsPathNotInFolderError(e))
|
|
730
|
+
throw new PKCError("ERR_IPFS_PATH_NOT_IN_FOLDER", { ipfsPath: `/ipfs/${root}/${path}`, error: e });
|
|
719
731
|
log.trace("Could not resolve", `${root}/${path}`, "to a cid, the caller will fetch it", e);
|
|
720
732
|
return undefined;
|
|
721
733
|
}
|