What changed in pkc-js
pkc-js now validates community.settings.challenges[i] in two layers, on the edit, community-creation and start paths. Merged in pkcprotocol/pkc-js#288 (commit d9028724e), shipping in the first release after v0.0.84.
Layer 1, core, no challenge code involved. options and publicOptions are checked against the optionInputs your ChallengeFileFactory returns:
| Check |
Error code |
An options key that no optionInputs entry declares |
ERR_CHALLENGE_OPTION_NOT_DECLARED_IN_OPTION_INPUTS |
A missing option whose optionInputs entry has required: true |
ERR_CHALLENGE_REQUIRED_OPTION_MISSING |
A publicOptions entry that no optionInputs entry declares |
ERR_CHALLENGE_PUBLIC_OPTION_NOT_DECLARED_IN_OPTION_INPUTS |
Layer 2, the new optional validateChallengeSettings hook, for semantic checks only this package can make:
validateChallengeSettings?: (args: { challengeSettings: CommunityChallengeSetting }) => void
- Optional. Omit it if there is nothing semantic to check.
- Sync, and no network. It runs on every community start, so an async validator hitting a third party would turn that outage into a startup problem.
- Rejection is a throw of anything, including a plain
new Error("..."). No pkc-js import needed. Core wraps it with code ERR_CHALLENGE_SETTINGS_VALIDATION_FAILED, keeping the original as cause and your message in details.validationError.
- Keep the factory itself cheap and non-throwing: it runs on load as well as on edit, so a throwing factory fails community startup rather than the offending edit.
Full guide: docs/protocol/challenge-authoring.md
What this package needs
@bitsocial/flags-challenge currently pins @pkcprotocol/pkc-js at 0.0.37.
No option in src/schema.ts is marked required: true. Core's new required check therefore does nothing for this package until you declare it. serviceUrl and issuer look like genuine requirements.
Suggested validateChallengeSettings checks:
serviceUrl parses with new URL() and uses http: or https:. A malformed URL here means every author is rejected by a service that was never reachable.
allowedFlags parses into the list shape the challenge expects, and is non-empty if an empty list would reject everyone.
emitFlair is a boolean string.
namespace and profile match whatever format the issuer service requires.
Do not call serviceUrl from the hook to check reachability; that belongs in getChallenge().
Worth considering: publicOptions
pkc-js also gained owner-controlled publicOptions (pkcprotocol/pkc-js#287), letting a community owner publish named options into the community record. If a client needs to read allowedFlags to produce a publishable comment, this challenge is a candidate for requiring that option to be listed in publicOptions, throwing from the hook when it is not. Unpublished rules mean authors are rejected by a rule they cannot see.
Tasks
What changed in pkc-js
pkc-js now validates
community.settings.challenges[i]in two layers, on the edit, community-creation and start paths. Merged in pkcprotocol/pkc-js#288 (commitd9028724e), shipping in the first release after v0.0.84.Layer 1, core, no challenge code involved.
optionsandpublicOptionsare checked against theoptionInputsyourChallengeFileFactoryreturns:optionskey that nooptionInputsentry declaresERR_CHALLENGE_OPTION_NOT_DECLARED_IN_OPTION_INPUTSoptionInputsentry hasrequired: trueERR_CHALLENGE_REQUIRED_OPTION_MISSINGpublicOptionsentry that nooptionInputsentry declaresERR_CHALLENGE_PUBLIC_OPTION_NOT_DECLARED_IN_OPTION_INPUTSLayer 2, the new optional
validateChallengeSettingshook, for semantic checks only this package can make:new Error("..."). No pkc-js import needed. Core wraps it with codeERR_CHALLENGE_SETTINGS_VALIDATION_FAILED, keeping the original ascauseand your message indetails.validationError.Full guide:
docs/protocol/challenge-authoring.mdWhat this package needs
@bitsocial/flags-challengecurrently pins@pkcprotocol/pkc-jsat 0.0.37.No option in
src/schema.tsis markedrequired: true. Core's new required check therefore does nothing for this package until you declare it.serviceUrlandissuerlook like genuine requirements.Suggested
validateChallengeSettingschecks:serviceUrlparses withnew URL()and useshttp:orhttps:. A malformed URL here means every author is rejected by a service that was never reachable.allowedFlagsparses into the list shape the challenge expects, and is non-empty if an empty list would reject everyone.emitFlairis a boolean string.namespaceandprofilematch whatever format the issuer service requires.Do not call
serviceUrlfrom the hook to check reachability; that belongs ingetChallenge().Worth considering:
publicOptionspkc-js also gained owner-controlled
publicOptions(pkcprotocol/pkc-js#287), letting a community owner publish named options into the community record. If a client needs to readallowedFlagsto produce a publishable comment, this challenge is a candidate for requiring that option to be listed inpublicOptions, throwing from the hook when it is not. Unpublished rules mean authors are rejected by a rule they cannot see.Tasks
@pkcprotocol/pkc-jsto the release named aboverequired: truevalidateChallengeSettingscovering the checks abovepublicOptions