ssb-submissions v2.0.0
ssb-submissions
An ssb-server plugin for creating, reading and updating submissions in scuttlebutt
Modules
- ssb-submissions
Submissions
A submission is a request for another record to be created, updated, or tombstoned, that is stored using ssb.
A (the root message)
|
B (approveing or rejecting the proposal A)
/ \
C D (two concurrent approves/rejects after B)Because there might be multiple offline approves/rejects to a submission which didn't know about one-another, it's possible for divergence to happen:
C and D wont know about each other.
A submission is an Object which maps the key of each latest edit to the state it perceives the submission to be in:
// submission for the example above
{
key: MessageId, // submissionId supplied, the root message of the submission
states: [
{ head: C, state: stateC },
{ head: D, state: stateD },
]
}and the state is an Object which looks like the following:
{
// static fields
sourceId: msgId,
targetType: String,
details: Object,
source: RecordSource,
//
targetId: msgId,
approvedBy: SimpleSet of feedIds,
rejectedBy: SimpleSet of feedIds,
comments: OverWriteFields of feedIds: String
}where:
sourceId- is the original record e.g.profileId, the submission proposal is about. E.g. if we are proposing to edit a profile, thesourceIdwould be the profile we are updating. If we are proposing a new profile, thesourceIdis always empty.targetId- is the "result" record after a submission has been executed. E.g. if we have proposed and executed a submission for a new profile, thetargetIdis theprofileIdof the new profile that was created. If we have proposed and executed a submission for an edit to a profile, thetargetIdis themsgId(profileId) of the update message to that profile.targetType- is thetypeof record we are proposing, and thetypeof record we will get in the result oftargetIdafter weexecutethe proposal.details- is the proposed fields we wish to include in the type of record we are creating or updating. E.g. If we are proposing a newprofile, thedetailswill befieldsaccepted on the record typeprofile/person.sourceRecordSource (ahau|webForm) tells us where a record, in this case asubmission, came from. E.g.ahau- a record was made in ahau,webForma record was made from a web registration form
API
server.submissions.registerHandler(crut)
In order to check that the proposals are valid, begin by registering a crut that contains:
spec.typeString - the type of the target record TODO:isValidFunction - allows you to check the validity of the proposal.
Important: currently uses an extended CRUT, by adding ...crut to the Methods of the desired record. Example use case:
server.submissions.registerHandler(server.profile.person.public)server.submissions.findHandler(content) => crut
server.submissions.proposeNew(recordTypeContent, recordDetails, submissionDetails, cb)
Creates a new submission record and describes details you'd like to have on a new type of record
recordTypeContentObject - content for the type of record you would like to create- e.g. for a
profile/personrecord:
recordTypeContent = { type: 'profile/person' }- e.g. for a
recordDetailsObject - allows you to propose fields for new record.e.g. for a
profile/personrecord:// for profile/person { preferredName: 'Colin' }
NOTE: the fields will be validated against the spec for that type of record using the
recordTypeContentsubmissionDetailsObject - additional details you can add to the submissioncommentString - allows you to add an optional comment to the submission.sourceRecordSource (ahau|webForm) - specify where the submission is being created, e.g. fromahauor from a web registration formwebFormmoreInfoObject - specify additional information to be saved to the submission.{ [key]: [ { label: String, value: String } ] }NOTE: This is currently the only format that is supported. If more formats are needed, they can be added
recpsString - Who is allowed to see this submission. The new record may have different recps. // TODO: Submissions should only be seen by kaitiaki group
cbFunction - a callback with signature (err, submissionId)
server.submissions.proposeEdit(recordId, recordDetails, submissionDetails, cb)
Creates a new submission record and describes details you'd like to have updated on an existing record
recordIdString - the cypherlink for the target record (themsgIdof the root message for the record)recordDetailsObject - allows you to propose fields for new record.e.g. for a
profile/personrecord:// for profile/person { preferredName: 'Colin' }
NOTE: the fields will be validated against the spec for that type of record that recordId points to
submissionDetailsObject - additional details you can add to the submissioncommentString - allows you to add an optional comment to the submission.recpsString - Who is allowed to see this submission. The target record may have different recps. // TODO: Submissions should only be seen by kaitiaki group
cbFunction - a callback with signature (err, submissionId)
server.submissions.proposeTombstone(recordId, submissionDetails, cb)
Creates a new submission record about which existing record you want tombstoned
recordIdString - the cypherlink for the target record (themsgIdof the root message for the record)submissionDetailsObject - additional details you can add to the submissioncomment{ String } - allows you to add an optional comment to the submission.
cbFunction - a callback with signature(err, submissionId)
server.submissions.approve(submissionId, submissionDetails, cb)
Updates a submission record by setting server.id to approvedBy and adding the comment
submissionIdString - the cypherlink for the target submission (themsgIdof the root message for the submission)submissionDetailsObject - additional details you can add to the submissiontargetIdString - specify the ID of a message. E.g. the message that was saved upon approval.commentString - allows you to add an optional comment to the submission.
cbFunction - a callback with signature(err, submissionId)
server.submissions.executeAndApprove(submissionId, approvedRecordDetails, submissionDetails, cb)
Handles executing a proposal by either creating or updating the record, with the fields passed in to approvedRecordDetails. It then calls the approve method.
submissionIdString - the cypherlink for the target submission (themsgIdof the root message for the submission)approvedRecordDetailsObject - similar to recordDetails in the propose methods, but it only holds fields and values that have been approved. These will be saved to the record being created or updated.submissionDetailsObject - additional details you can add to the submissioncommentString - allows you to add an optional comment to the submission.
cbFunction - a callback with signature(err, submissionId)
server.submissions.reject(submissionId, { comment }, cb)
Updates a submission record by setting server.id to rejectedBy and adding the comment
submissionIdString - the cypherlink for the target submission (themsgIdof the root message for the submission)comment{ String } - allows you to add an optional comment to the submission.cbFunction - a callback with signature(err, submissionId)
server.submissions.get(submissionId, cb)
Retrieves the submission record.
submissionIdString - the cypherlink for the target submission (themsgIdof the root message for the submission)cbFunction - a callback with signature(err, data)
server.submissions.tombstone(submissionId, { reason, allowPublic, undo }, cb)
Tombstones the submission record.
submissionIdString - the cypherlink for the target submission (themsgIdof the root message for the submission)cbFunction - a callback with signature(err, root)