@choiceapps/communityservices-sdk 0.5.0 → 0.7.0

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/browser/enrollment-workflow.d.mts +54 -4
  3. package/browser/enrollment-workflow.mjs +89 -33
  4. package/browser/entry-correction.mjs +53 -10
  5. package/browser/entry-row-registration.mjs +63 -0
  6. package/browser/household-enrollment-discovery.mjs +49 -0
  7. package/browser/index.d.mts +3 -1
  8. package/browser/playwright-session.mjs +4 -3
  9. package/browser/workflow-error-codes.mjs +198 -0
  10. package/dist/cjs/mobile-preflight.d.ts +19 -0
  11. package/dist/cjs/mobile-preflight.d.ts.map +1 -0
  12. package/dist/cjs/mobile-preflight.js +75 -0
  13. package/dist/cjs/mobile-preflight.js.map +1 -0
  14. package/dist/cjs/v2.d.ts +2 -0
  15. package/dist/cjs/v2.d.ts.map +1 -1
  16. package/dist/cjs/v2.js +2 -0
  17. package/dist/cjs/v2.js.map +1 -1
  18. package/dist/cjs/v3.d.ts +2 -0
  19. package/dist/cjs/v3.d.ts.map +1 -1
  20. package/dist/cjs/v3.js +2 -0
  21. package/dist/cjs/v3.js.map +1 -1
  22. package/dist/cjs/write-labels.d.ts +13 -0
  23. package/dist/cjs/write-labels.d.ts.map +1 -0
  24. package/dist/cjs/write-labels.js +68 -0
  25. package/dist/cjs/write-labels.js.map +1 -0
  26. package/dist/esm/mobile-preflight.d.ts +19 -0
  27. package/dist/esm/mobile-preflight.d.ts.map +1 -0
  28. package/dist/esm/mobile-preflight.js +70 -0
  29. package/dist/esm/mobile-preflight.js.map +1 -0
  30. package/dist/esm/v2.d.ts +2 -0
  31. package/dist/esm/v2.d.ts.map +1 -1
  32. package/dist/esm/v2.js +2 -0
  33. package/dist/esm/v2.js.map +1 -1
  34. package/dist/esm/v3.d.ts +2 -0
  35. package/dist/esm/v3.d.ts.map +1 -1
  36. package/dist/esm/v3.js +2 -0
  37. package/dist/esm/v3.js.map +1 -1
  38. package/dist/esm/write-labels.d.ts +13 -0
  39. package/dist/esm/write-labels.d.ts.map +1 -0
  40. package/dist/esm/write-labels.js +65 -0
  41. package/dist/esm/write-labels.js.map +1 -0
  42. package/docs/assessments.md +38 -1
  43. package/docs/browser-session.md +1 -1
  44. package/docs/capabilities.md +15 -2
  45. package/docs/enrollments.md +75 -3
  46. package/docs/reference.md +3 -2
  47. package/docs/troubleshooting.md +20 -0
  48. package/examples/README.md +2 -0
  49. package/examples/checked-assessment-writes.mts +14 -0
  50. package/examples/enrollment-discovery-and-correction.mts +19 -0
  51. package/examples/entry-correction-workflow.mts +8 -0
  52. package/package.json +1 -1
package/docs/reference.md CHANGED
@@ -8,13 +8,14 @@ Only the package export paths below are supported import entry points. Declarati
8
8
 
9
9
  Import from `@choiceapps/communityservices-sdk`, `@choiceapps/communityservices-sdk/v3`, or `@choiceapps/communityservices-sdk/v2`. The root selects V3 and also exports the testing helpers. Each version supplies its own generated HTTP models and fixed version header.
10
10
 
11
- Runtime exports at the root: `AmbiguousCommitError`, `AssessmentMetadata`, `AuthError`, `CooldownError`, `DefinitionDriftError`, `FakeControl`, `FakeWellSkyClient`, `GwtEnrollmentConflictError`, `GwtEnrollmentHelpers`, `SubassessmentEditor`, `TenantMismatchError`, `ThrottledError`, `UnknownPicklistValueError`, `UpstreamError`, `ValidationError`, `WellSkyClient`, `WellSkyError`, `apiVersion`, `buildAssessmentDefinition`, `compareDefinition`, `createFakeWellSkyClient`, `createInMemoryGwtMutationStore`, `createWellSkyClient`, `encodeAnswers`, `encodeNewSubassessmentRow`, `flattenQuestions`, `mapBulk`, `operationRoutes`, `parseRestInstant`, `readEnrollmentVerifications`, `readOutcome`, `readProgramCatalog`, `resolvePicklistOption`, `semanticHash`, `specSha256`, `toItems`, `verifyWrite`.
11
+ Runtime exports at the root: `MobileAnswerPreflightError`, `writeMobileAnswersChecked`, `createReadBackWriteLabelResolver`, `AmbiguousCommitError`, `AssessmentMetadata`, `AuthError`, `CooldownError`, `DefinitionDriftError`, `FakeControl`, `FakeWellSkyClient`, `GwtEnrollmentConflictError`, `GwtEnrollmentHelpers`, `SubassessmentEditor`, `TenantMismatchError`, `ThrottledError`, `UnknownPicklistValueError`, `UpstreamError`, `ValidationError`, `WellSkyClient`, `WellSkyError`, `apiVersion`, `buildAssessmentDefinition`, `compareDefinition`, `createFakeWellSkyClient`, `createInMemoryGwtMutationStore`, `createWellSkyClient`, `encodeAnswers`, `encodeNewSubassessmentRow`, `flattenQuestions`, `mapBulk`, `operationRoutes`, `parseRestInstant`, `readEnrollmentVerifications`, `readOutcome`, `readProgramCatalog`, `resolvePicklistOption`, `semanticHash`, `specSha256`, `toItems`, `verifyWrite`.
12
12
 
13
13
  | Contract | Declaration | Guide |
14
14
  | --- | --- | --- |
15
15
  | HTTP clients and generated models | [V3](../dist/esm/generated/v3.d.ts), [V2](../dist/esm/generated/v2.d.ts) | [REST](rest-client.md), [API table](../API.md) |
16
16
  | Authentication, transport, responses and errors | [Runtime](../dist/esm/runtime.d.ts) | [Configuration](configuration.md), [recovery](troubleshooting.md) |
17
17
  | Metadata and picklists | [Metadata](../dist/esm/metadata.d.ts) | [Assessments](assessments.md) |
18
+ | Checked mobile inserts and exact lookup labels | [Preflight](../dist/esm/mobile-preflight.d.ts), [labels](../dist/esm/write-labels.d.ts) | [Assessments](assessments.md) |
18
19
  | Answer encoding | [Encoding](../dist/esm/encoding.d.ts) | [Dates and answers](dates-and-answers.md) |
19
20
  | Write verification | [Verification](../dist/esm/verification.d.ts) | [REST](rest-client.md) |
20
21
  | Program catalog | [Program discovery](../dist/esm/program-discovery.d.ts) | [Enrollments](enrollments.md) |
@@ -36,7 +37,7 @@ Runtime exports: `AttachmentConflictError`, `CoordinatedEntryEventConflictError`
36
37
  | Profile fields and Sex | [Client profile](../browser/client-profile.d.mts) | `read`, `update` |
37
38
  | Calendar DOB | [Birth dates](../browser/date-of-birth.d.mts) | `read`, `validate`, `verify`, `update` |
38
39
  | Provider assessment defaults | [Discovery](../browser/program-discovery.d.mts) | `listAssessments`, `getProviderAssessments` |
39
- | Enrollment and household lifecycle | [Workflow](../browser/enrollment-workflow.d.mts) | Discovery, entry, `correctEntry`, `adoptEnrollment`, `adoptHouseholdEnrollment`, member additions, interim, `exitEnrollment`, `exitHousehold`, journal status; `EntryExitType` and per-type `assessmentLocations` in [enrollments](enrollments.md) |
40
+ | Enrollment and household lifecycle | [Workflow](../browser/enrollment-workflow.d.mts) | Discovery, entry, `correctEntry`, `resolveEntryCorrection`, `adoptEnrollment`, `adoptHouseholdEnrollment`, `discoverHouseholdEnrollment`, `registerEntryRows`, member additions, interim, `exitEnrollment`, `exitHousehold`, journal status; `EntryExitType` and per-type `assessmentLocations` in [enrollments](enrollments.md) |
40
41
  | Entry-date and exit UI ports | [Member entry](../browser/member-entry-date.d.mts), [exit](../browser/household-exit.d.mts) | Fresh reads and targeted completion |
41
42
  | Services and recovery diagnostics | [Service recording](../browser/service-recording.d.mts) | `record`, `recordBulk`, Funding Sources, `RecoveryDiagnostic` |
42
43
  | SSVF conditional rules | [SSVF types](../browser/ssvf-rules.d.mts) | [Field rules](../SSVF.md) and dated option snapshots |
@@ -28,6 +28,9 @@ Successful adoption of an existing record also needs its journal. Retain it even
28
28
  | `DefinitionDriftError`, `UnknownPicklistValueError` | Metadata or lookup assumption changed | Refresh/review definitions and application mapping. Do not guess a numeric option |
29
29
  | `AmbiguousCommitError` | Mutation outcome not established | Keep journal pending; re-read through the workflow's authoritative path |
30
30
  | `GwtEnrollmentConflictError` | Duplicate/partial/conflicting enrollment or review | Inspect membership and review instant. Do not replay the captured request |
31
+ | `UNSUPPORTED_YES_NO_CLEAR` | A correction attempted to blank a yes/no field | Fix the plan before any write; `No` and blank are different states |
32
+ | `ENTRY_CORRECTION_UNCERTAIN` | An attempted correction is not verified | Inspect `status`, `cause`, and journal step diagnostics; use [explicit resolution](enrollments.md#resolve-a-rejected-correction) only with independent non-application evidence |
33
+ | `ENTRY_CORRECTION_REJECTED` | The old correction key was resolved as not applied | Keep its audit record and use a new key for corrected intent |
31
34
  | `EnrollmentWorkflowError` | Invalid plan, missing head, schema drift, conflict, or unresolved stage | Inspect the specific reason and local status; fix application inputs only before reservation, otherwise reconcile original intent |
32
35
  | `SessionInterruptedError`, `SESSION_INTERRUPTED` | Managed page operation ended around session expiry | Check `reauthenticated`; retry the original workflow call, never its prepared RPC |
33
36
  | `LoginError`, `PASSWORD_EXPIRED` | Expiration detected with recovery disabled | Use the documented recovery option or resolve the password outside the helper |
@@ -43,6 +46,23 @@ Successful adoption of an existing record also needs its journal. Retain it even
43
46
 
44
47
  Not every browser helper error is a `WellSkyError`; some validation/UI failures are ordinary `Error` objects. `verifyWrite` returns a discriminated result rather than using a thrown error as its success contract. Its `unverified` result may already be committed.
45
48
 
49
+ ## Workflow error codes
50
+
51
+ Enrollment workflow errors expose stable `code` values. Common actionable codes include:
52
+
53
+ | Code | Meaning |
54
+ | --- | --- |
55
+ | `ADOPTION_HOUSEHOLD_HEAD_MISMATCH` | The supplied head does not match the verified enrollment cohort |
56
+ | `INDEPENDENT_CONFIRMATION_REQUIRED` | Resolution lacks independent confirmation of non-application |
57
+ | `UNSUPPORTED_YES_NO_CLEAR` | A correction requests blanking a yes/no answer; no supported route is verified |
58
+ | `ENTRY_CORRECTION_UNCERTAIN` | An attempted correction needs reconciliation; never resend it blindly |
59
+ | `MOBILE_ANSWER_EXISTS` | A scalar row already occupies the requested mobile effective instant |
60
+ | `MOBILE_PREFLIGHT_UNAVAILABLE` | The read cannot establish whether a scalar insert is safe |
61
+
62
+ The [workflow code table](../browser/workflow-error-codes.mjs) maps existing reasons to codes; new guards supply explicit codes. `committed: false` identifies a pre-write refusal for the named operation. `'unknown'` requires journal/readback reconciliation. Resolution errors separately retain `originalCommitted: 'unknown'` for the original correction. HTTP status and causes are exposed where captured; they are not proof of non-application.
63
+
64
+ Pending 0.5.0 corrections may have no saved `failure` kind or status. Keep your own original failure evidence for the confirmation callback. Do not repeat the write to recover missing diagnostics.
65
+
46
66
  ## Inspect an upstream error privately
47
67
 
48
68
  By default the transport discards HTTP error bodies because they can contain client data or credentials. For a controlled diagnostic session, construct `WellSkyClient` with `captureErrorBody: true`. An `UpstreamError` then exposes `responseBody` and `responseBodyTruncated`. The body is capped at 16,384 characters, retained in memory, and excluded from the error's enumerable properties, JSON serialization, and transport hooks/logger events. HTTP 401, 403, 429 and SetAuthKey authentication responses are excluded even with capture enabled. Raw bodies can still contain private information; inspect them through an access-controlled debugger or application diagnostic sink, not ordinary logs.
@@ -15,6 +15,8 @@ Every file here ships with the package and imports the public `@choiceapps/commu
15
15
  | [program-discovery.ts](program-discovery.ts) | Program and VA-entry assessment discovery | Exported function; authenticated page required |
16
16
  | [enrollment-workflow.mts](enrollment-workflow.mts) | Single entry and interim assessment plans | Exported function; caller supplies plans and dependencies |
17
17
  | [individual-exit-workflow.mts](individual-exit-workflow.mts) | Standalone program enrollment exit and assessment | Verified entry key, enrollment reader, exit UI port and durable store required |
18
+ | [checked-assessment-writes.mts](checked-assessment-writes.mts) | Exact readback lookup labels and checked mobile scalar inserts | Unobserved labels remain unresolved; preflight does not make writes atomic |
19
+ | [enrollment-discovery-and-correction.mts](enrollment-discovery-and-correction.mts) | Discover/adopt from the head and bind existing correction rows | Explicit row IDs and unique verified household membership required |
18
20
  | [entry-correction-workflow.mts](entry-correction-workflow.mts) | Same-date scalar clears and existing row edits | Original entry/row keys, verified lookup labels and durable store required |
19
21
  | [existing-enrollment-exits.mts](existing-enrollment-exits.mts) | Adopt manual individual or household entries, then exit | Explicit enrollment identities and original household head required |
20
22
  | [household-enrollment-workflow.mts](household-enrollment-workflow.mts) | Per-member enrollment and review | Existing household and per-member answer plans required |
@@ -0,0 +1,14 @@
1
+ import {
2
+ createReadBackWriteLabelResolver,writeMobileAnswersChecked,
3
+ type AssessmentDefinition,type WriteLabelObservation,type CheckedMobileWriteOptions,type WellSkyClient,
4
+ } from '@choiceapps/communityservices-sdk';
5
+
6
+ /** Observations must come from the definition's tenant. Unobserved options stay unresolved. */
7
+ export function exactWriteLabels(definition:AssessmentDefinition,observations:WriteLabelObservation[]){
8
+ return createReadBackWriteLabelResolver(definition,observations);
9
+ }
10
+
11
+ /** Pass the original requested instant; the SDK transport owns any configured mobile date correction. */
12
+ export async function insertMobileAnswers(api:WellSkyClient,input:CheckedMobileWriteOptions){
13
+ return writeMobileAnswersChecked(api,input);
14
+ }
@@ -0,0 +1,19 @@
1
+ import {createEnrollmentWorkflow,type EnrollmentWorkflowOptions,type EntryCorrectionInput} from '@choiceapps/communityservices-sdk/browser';
2
+
3
+ /** The head's explicit target identifies a cohort; ambiguous household matches fail. */
4
+ export async function adoptFromHead(dependencies:EnrollmentWorkflowOptions,input:{key:string;headClientId:number;headEnrollmentId:number}){
5
+ const workflow=createEnrollmentWorkflow(dependencies);
6
+ const discovery=await workflow.discoverHouseholdEnrollment({headClientId:input.headClientId,headEnrollmentId:input.headEnrollmentId});
7
+ const adopted=await workflow.adoptHouseholdEnrollment(input);
8
+ return {discovery,adopted};
9
+ }
10
+
11
+ /** Select IDs from an authorized assessment read. The SDK never guesses a row by date/value. */
12
+ export async function bindAndCorrectManualRows(
13
+ dependencies:EnrollmentWorkflowOptions,
14
+ input:{registrationKey:string;correction:EntryCorrectionInput;rows:Array<{key:string;parentField:string;recordsetId:number}>},
15
+ ){
16
+ const workflow=createEnrollmentWorkflow(dependencies),{clientId,enrollmentKey}=input.correction;
17
+ await workflow.registerEntryRows({key:input.registrationKey,clientId,enrollmentKey,rows:input.rows});
18
+ return workflow.correctEntry(input.correction);
19
+ }
@@ -2,6 +2,7 @@ import {
2
2
  createEnrollmentWorkflow,
3
3
  type EnrollmentWorkflowOptions,
4
4
  type EntryCorrectionInput,
5
+ type ResolveEntryCorrectionInput,
5
6
  } from '@choiceapps/communityservices-sdk/browser';
6
7
 
7
8
  /** The application supplies explicit answers, clears and original row keys.
@@ -12,3 +13,10 @@ export async function correctOriginalEntry(dependencies:EnrollmentWorkflowOption
12
13
  const workflow=createEnrollmentWorkflow(dependencies);
13
14
  return workflow.correctEntry(input);
14
15
  }
16
+
17
+ /** The confirmation callback must use independent server or administrative evidence.
18
+ * The SDK also checks the complete pre-write state before and after that callback.
19
+ * Retain the rejected key; submit a corrected request under a new key afterward. */
20
+ export async function resolveRejectedCorrection(dependencies:EnrollmentWorkflowOptions,input:ResolveEntryCorrectionInput){
21
+ return createEnrollmentWorkflow(dependencies).resolveEntryCorrection(input);
22
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@choiceapps/communityservices-sdk",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "SDK for WellSky Community Services (HMIS), formerly ServicePoint, Client API V2 and V3",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",