@choiceapps/communityservices-sdk 0.6.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 (50) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/browser/enrollment-workflow.d.mts +25 -3
  3. package/browser/enrollment-workflow.mjs +75 -29
  4. package/browser/entry-correction.mjs +6 -4
  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 +31 -0
  43. package/docs/capabilities.md +13 -0
  44. package/docs/enrollments.md +38 -4
  45. package/docs/reference.md +3 -2
  46. package/docs/troubleshooting.md +17 -0
  47. package/examples/README.md +2 -0
  48. package/examples/checked-assessment-writes.mts +14 -0
  49. package/examples/enrollment-discovery-and-correction.mts +19 -0
  50. package/package.json +1 -1
@@ -0,0 +1,70 @@
1
+ import { ValidationError } from './errors.js';
2
+ import { parseRestInstant } from './encoding.js';
3
+ import { toItems } from './runtime.js';
4
+ import { isRecord } from './validation.js';
5
+ export class MobileAnswerPreflightError extends ValidationError {
6
+ code;
7
+ committed = false;
8
+ constructor(code, fields = [], cause) {
9
+ super('mobile assessment preflight', fields);
10
+ this.code = code;
11
+ this.name = 'MobileAnswerPreflightError';
12
+ if (cause !== undefined)
13
+ Object.defineProperty(this, 'cause', { value: cause, enumerable: false });
14
+ }
15
+ }
16
+ /** Read-before-write protection for scalar inserts, including questions shared by instruments.
17
+ * Does not journal, retry writes, or make the read/write pair atomic. */
18
+ export async function writeMobileAnswersChecked(api, options) {
19
+ function fail(code, fields = [], cause) { throw new MobileAnswerPreflightError(code, fields, cause); }
20
+ const checkSignal = () => { if (options.signal?.aborted)
21
+ fail('MOBILE_PREFLIGHT_CANCELLED', [], options.signal.reason); };
22
+ if (!options?.path || !Number.isSafeInteger(options.path.clientId) || options.path.clientId <= 0 || typeof options.path.assessmentCode !== 'string' || !options.path.assessmentCode.trim() || !Array.isArray(options.body) || !options.body.length || typeof options.query?.dateEffective !== 'string')
23
+ fail('MOBILE_PREFLIGHT_INPUT_INVALID');
24
+ const instant = options.query.dateEffective;
25
+ if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.000)?(?:Z|[+-]\d{2}:\d{2})$/.test(instant) || !Number.isFinite(parseRestInstant(instant)) || new Date(instant.slice(0, 19) + 'Z').toISOString().slice(0, 19) !== instant.slice(0, 19))
26
+ fail('MOBILE_PREFLIGHT_INPUT_INVALID', ['dateEffective']);
27
+ checkSignal();
28
+ const captured = { ...options, path: { ...options.path }, query: { ...options.query }, body: structuredClone(options.body) };
29
+ const scalars = [], seen = new Set(), ids = new Set();
30
+ for (const q of captured.body) {
31
+ if (!isRecord(q) || typeof q.question_type !== 'string' || typeof q.virt_field_name !== 'string' || !q.virt_field_name || typeof q.question_id !== 'number' || !Number.isSafeInteger(q.question_id) || q.question_id <= 0 || seen.has(q.virt_field_name) || ids.has(q.question_id))
32
+ fail('MOBILE_PREFLIGHT_INPUT_INVALID');
33
+ seen.add(q.virt_field_name);
34
+ ids.add(q.question_id);
35
+ if (q.question_type !== 'sub_assessment')
36
+ scalars.push({ id: q.question_id, field: q.virt_field_name, type: q.question_type });
37
+ }
38
+ if (scalars.length) {
39
+ let response;
40
+ try {
41
+ response = await api.assessments.get({ path: captured.path, query: { dateEffective: new Date(parseRestInstant(instant) + 1000).toISOString() }, ...(options.signal ? { signal: options.signal } : {}), ...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }), ...(options.correlationId === undefined ? {} : { correlationId: options.correlationId }) });
42
+ }
43
+ catch (cause) {
44
+ fail('MOBILE_PREFLIGHT_READ_FAILED', scalars.map(q => q.field), cause);
45
+ }
46
+ const rows = toItems(response), conflicts = [];
47
+ for (const q of scalars) {
48
+ const found = rows.filter(r => r.virt_field_name === q.field);
49
+ if (found.length !== 1 || found[0]?.question_id !== q.id || found[0]?.question_type !== q.type)
50
+ fail('MOBILE_PREFLIGHT_UNAVAILABLE', [q.field]);
51
+ const row = found[0];
52
+ if (!row)
53
+ fail('MOBILE_PREFLIGHT_UNAVAILABLE', [q.field]);
54
+ if (row.date_effective !== null && row.date_effective !== undefined && row.date_effective !== '') {
55
+ const recorded = parseRestInstant(row.date_effective);
56
+ if (!Number.isFinite(recorded) || recorded > parseRestInstant(instant))
57
+ fail('MOBILE_PREFLIGHT_UNAVAILABLE', [q.field]);
58
+ if (recorded === parseRestInstant(instant))
59
+ conflicts.push(q.field);
60
+ }
61
+ else if (row.answer_value !== null && row.answer_value !== undefined && row.answer_value !== '')
62
+ fail('MOBILE_PREFLIGHT_UNAVAILABLE', [q.field]);
63
+ }
64
+ if (conflicts.length)
65
+ fail('MOBILE_ANSWER_EXISTS', conflicts);
66
+ }
67
+ checkSignal();
68
+ return api.assessmentsMobile.addAnswer(captured);
69
+ }
70
+ //# sourceMappingURL=mobile-preflight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mobile-preflight.js","sourceRoot":"","sources":["../../src/mobile-preflight.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAC,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAKzC,MAAM,OAAO,0BAA2B,SAAQ,eAAe;IAEzC;IADZ,SAAS,GAAC,KAAK,CAAC;IACzB,YAAqB,IAAwB,EAAC,SAAyB,EAAE,EAAC,KAAc;QACvF,KAAK,CAAC,6BAA6B,EAAC,MAAM,CAAC,CAAC;QADxB,SAAI,GAAJ,IAAI,CAAoB;QACA,IAAI,CAAC,IAAI,GAAC,4BAA4B,CAAC;QACnF,IAAG,KAAK,KAAG,SAAS;YAAC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAC,OAAO,EAAC,EAAC,KAAK,EAAC,KAAK,EAAC,UAAU,EAAC,KAAK,EAAC,CAAC,CAAC;IACzF,CAAC;CACD;AAED;yEACyE;AACzE,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAC9C,GAAyD,EACzD,OAAiC;IAEjC,SAAS,IAAI,CAAC,IAAwB,EA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3.js';\nimport {ValidationError} from './errors.js';\nimport {parseRestInstant} from './encoding.js';\nimport {toItems} from './runtime.js';\nimport {isRecord} from './validation.js';\n\ntype RawMobileWrite = Parameters<WellSkyClient['assessmentsMobile']['addAnswer']>[0];\nexport type CheckedMobileWriteOptions = Omit<RawMobileWrite,'query'> & {query:{dateEffective:string}};\nexport type MobilePreflightCode = 'MOBILE_PREFLIGHT_INPUT_INVALID'|'MOBILE_PREFLIGHT_READ_FAILED'|'MOBILE_PREFLIGHT_UNAVAILABLE'|'MOBILE_ANSWER_EXISTS'|'MOBILE_PREFLIGHT_CANCELLED';\nexport class MobileAnswerPreflightError extends ValidationError {\n readonly committed=false;\n constructor(readonly code:MobilePreflightCode,fields:readonly string[]=[],cause?:unknown){\n super('mobile assessment preflight',fields);this.name='MobileAnswerPreflightError';\n if(cause!==undefined)Object.defineProperty(this,'cause',{value:cause,enumerable:false});\n }\n}\n\n/** Read-before-write protection for scalar inserts, including questions shared by instruments.\n * Does not journal, retry writes, or make the read/write pair atomic. */\nexport async function writeMobileAnswersChecked(\n api:Pick<WellSkyClient,'assessments'|'assessmentsMobile'>,\n options:CheckedMobileWriteOptions,\n):ReturnType<WellSkyClient['assessmentsMobile']['addAnswer']>{\n function fail(code:MobilePreflightCode,fields:readonly string[]=[],cause?:unknown):never{throw new MobileAnswerPreflightError(code,fields,cause);}\n const checkSignal=()=>{if(options.signal?.aborted)fail('MOBILE_PREFLIGHT_CANCELLED',[],options.signal.reason);};\n if(!options?.path||!Number.isSafeInteger(options.path.clientId)||options.path.clientId<=0||typeof options.path.assessmentCode!=='string'||!options.path.assessmentCode.trim()||!Array.isArray(options.body)||!options.body.length||typeof options.query?.dateEffective!=='string')fail('MOBILE_PREFLIGHT_INPUT_INVALID');\n const instant=options.query.dateEffective;\n if(!/^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(?:\\.000)?(?:Z|[+-]\\d{2}:\\d{2})$/.test(instant)||!Number.isFinite(parseRestInstant(instant))||new Date(instant.slice(0,19)+'Z').toISOString().slice(0,19)!==instant.slice(0,19))fail('MOBILE_PREFLIGHT_INPUT_INVALID',['dateEffective']);\n checkSignal();\n const captured={...options,path:{...options.path},query:{...options.query},body:structuredClone(options.body)};\n const scalars:Array<{id:number;field:string;type:string}>=[],seen=new Set<string>(),ids=new Set<number>();\n for(const q of captured.body){\n if(!isRecord(q)||typeof q.question_type!=='string'||typeof q.virt_field_name!=='string'||!q.virt_field_name||typeof q.question_id!=='number'||!Number.isSafeInteger(q.question_id)||q.question_id<=0||seen.has(q.virt_field_name)||ids.has(q.question_id))fail('MOBILE_PREFLIGHT_INPUT_INVALID');\n seen.add(q.virt_field_name);ids.add(q.question_id);\n if(q.question_type!=='sub_assessment')scalars.push({id:q.question_id,field:q.virt_field_name,type:q.question_type});\n }\n if(scalars.length){\n let response:Awaited<ReturnType<WellSkyClient['assessments']['get']>>;\n try{response=await api.assessments.get({path:captured.path,query:{dateEffective:new Date(parseRestInstant(instant)+1000).toISOString()},...(options.signal?{signal:options.signal}:{}),...(options.timeoutMs===undefined?{}:{timeoutMs:options.timeoutMs}),...(options.correlationId===undefined?{}:{correlationId:options.correlationId})});}\n catch(cause){fail('MOBILE_PREFLIGHT_READ_FAILED',scalars.map(q=>q.field),cause);}\n const rows=toItems<Operations['GET /assessments/{clientId}/{assessmentCode}']['item']>(response),conflicts:string[]=[];\n for(const q of scalars){\n const found=rows.filter(r=>r.virt_field_name===q.field);\n if(found.length!==1||found[0]?.question_id!==q.id||found[0]?.question_type!==q.type)fail('MOBILE_PREFLIGHT_UNAVAILABLE',[q.field]);\n const row=found[0];\n if(!row)fail('MOBILE_PREFLIGHT_UNAVAILABLE',[q.field]);\n if(row.date_effective!==null&&row.date_effective!==undefined&&row.date_effective!==''){\n const recorded=parseRestInstant(row.date_effective);\n if(!Number.isFinite(recorded)||recorded>parseRestInstant(instant))fail('MOBILE_PREFLIGHT_UNAVAILABLE',[q.field]);\n if(recorded===parseRestInstant(instant))conflicts.push(q.field);\n }else if(row.answer_value!==null&&row.answer_value!==undefined&&row.answer_value!=='')fail('MOBILE_PREFLIGHT_UNAVAILABLE',[q.field]);\n }\n if(conflicts.length)fail('MOBILE_ANSWER_EXISTS',conflicts);\n }\n checkSignal();\n return api.assessmentsMobile.addAnswer(captured);\n}\n"]}
package/dist/esm/v2.d.ts CHANGED
@@ -10,4 +10,6 @@ export * from "./subassessments.js";
10
10
  export * from "./enrollment-verifications.js";
11
11
  export * from "./gwt-enrollments.js";
12
12
  export * from "./program-discovery.js";
13
+ export * from "./mobile-preflight.js";
14
+ export * from "./write-labels.js";
13
15
  //# sourceMappingURL=v2.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../../src/v2.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../../src/v2.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
package/dist/esm/v2.js CHANGED
@@ -10,4 +10,6 @@ export * from "./subassessments.js";
10
10
  export * from "./enrollment-verifications.js";
11
11
  export * from "./gwt-enrollments.js";
12
12
  export * from "./program-discovery.js";
13
+ export * from "./mobile-preflight.js";
14
+ export * from "./write-labels.js";
13
15
  //# sourceMappingURL=v2.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"v2.js","sourceRoot":"","sources":["../../src/v2.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from \"./generated/v2.js\";\nexport * from \"./generated/v2-models.js\";\nexport * from \"./runtime.js\";\nexport * from \"./metadata.js\";\nexport * from \"./errors.js\";\nexport * from \"./encoding.js\";\nexport * from \"./verification.js\";\nexport * from \"./bulk.js\";\nexport * from \"./subassessments.js\";\nexport * from \"./enrollment-verifications.js\";\n\nexport * from \"./gwt-enrollments.js\";\nexport * from \"./program-discovery.js\";\n"]}
1
+ {"version":3,"file":"v2.js","sourceRoot":"","sources":["../../src/v2.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./generated/v2.js\";\nexport * from \"./generated/v2-models.js\";\nexport * from \"./runtime.js\";\nexport * from \"./metadata.js\";\nexport * from \"./errors.js\";\nexport * from \"./encoding.js\";\nexport * from \"./verification.js\";\nexport * from \"./bulk.js\";\nexport * from \"./subassessments.js\";\nexport * from \"./enrollment-verifications.js\";\n\nexport * from \"./gwt-enrollments.js\";\nexport * from \"./program-discovery.js\";\nexport * from \"./mobile-preflight.js\";\nexport * from \"./write-labels.js\";\n"]}
package/dist/esm/v3.d.ts CHANGED
@@ -10,4 +10,6 @@ export * from "./subassessments.js";
10
10
  export * from "./enrollment-verifications.js";
11
11
  export * from "./gwt-enrollments.js";
12
12
  export * from "./program-discovery.js";
13
+ export * from "./mobile-preflight.js";
14
+ export * from "./write-labels.js";
13
15
  //# sourceMappingURL=v3.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"v3.d.ts","sourceRoot":"","sources":["../../src/v3.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC"}
1
+ {"version":3,"file":"v3.d.ts","sourceRoot":"","sources":["../../src/v3.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC"}
package/dist/esm/v3.js CHANGED
@@ -10,4 +10,6 @@ export * from "./subassessments.js";
10
10
  export * from "./enrollment-verifications.js";
11
11
  export * from "./gwt-enrollments.js";
12
12
  export * from "./program-discovery.js";
13
+ export * from "./mobile-preflight.js";
14
+ export * from "./write-labels.js";
13
15
  //# sourceMappingURL=v3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"v3.js","sourceRoot":"","sources":["../../src/v3.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC","sourcesContent":["export * from \"./generated/v3.js\";\nexport * from \"./generated/v3-models.js\";\nexport * from \"./runtime.js\";\nexport * from \"./metadata.js\";\nexport * from \"./errors.js\";\nexport * from \"./encoding.js\";\nexport * from \"./verification.js\";\nexport * from \"./bulk.js\";\nexport * from \"./subassessments.js\";\nexport * from \"./enrollment-verifications.js\";\n\nexport * from \"./gwt-enrollments.js\";\nexport * from \"./program-discovery.js\";\n"]}
1
+ {"version":3,"file":"v3.js","sourceRoot":"","sources":["../../src/v3.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,WAAW,CAAC;AAC1B,cAAc,qBAAqB,CAAC;AACpC,cAAc,+BAA+B,CAAC;AAE9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC","sourcesContent":["export * from \"./generated/v3.js\";\nexport * from \"./generated/v3-models.js\";\nexport * from \"./runtime.js\";\nexport * from \"./metadata.js\";\nexport * from \"./errors.js\";\nexport * from \"./encoding.js\";\nexport * from \"./verification.js\";\nexport * from \"./bulk.js\";\nexport * from \"./subassessments.js\";\nexport * from \"./enrollment-verifications.js\";\n\nexport * from \"./gwt-enrollments.js\";\nexport * from \"./program-discovery.js\";\nexport * from \"./mobile-preflight.js\";\nexport * from \"./write-labels.js\";\n"]}
@@ -0,0 +1,13 @@
1
+ import type { AssessmentDefinition } from './metadata.js';
2
+ import type { EncodingOptions } from './encoding.js';
3
+ export interface WriteLabelObservation {
4
+ tenant: string;
5
+ response: unknown;
6
+ }
7
+ export type ReadBackWriteLabelResolver = NonNullable<EncodingOptions['writeLabel']> & {
8
+ readonly tenant: string;
9
+ };
10
+ /** Builds labels only from exact readback evidence. It never infers HUD suffixes.
11
+ * Unobserved or changed options return undefined, so the standard encoder refuses them. */
12
+ export declare function createReadBackWriteLabelResolver(definition: AssessmentDefinition, observations: readonly WriteLabelObservation[]): ReadBackWriteLabelResolver;
13
+ //# sourceMappingURL=write-labels.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-labels.d.ts","sourceRoot":"","sources":["../../src/write-labels.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,oBAAoB,EAAmC,MAAM,eAAe,CAAC;AAE1F,OAAO,KAAK,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAInD,MAAM,WAAW,qBAAqB;IAAE,MAAM,EAAC,MAAM,CAAC;IAAA,QAAQ,EAAC,OAAO,CAAC;CAAC;AACxE,MAAM,MAAM,0BAA0B,GAAG,WAAW,CAAC,eAAe,CAAC,YAAY,CAAC,CAAC,GAAG;IAAC,QAAQ,CAAC,MAAM,EAAC,MAAM,CAAA;CAAC,CAAC;AAE/G;2FAC2F;AAC3F,wBAAgB,gCAAgC,CAC/C,UAAU,EAAC,oBAAoB,EAC/B,YAAY,EAAC,SAAS,qBAAqB,EAAE,GAC5C,0BAA0B,CA2C3B"}
@@ -0,0 +1,65 @@
1
+ import { flattenQuestions } from './metadata.js';
2
+ import { ValidationError } from './errors.js';
3
+ import { isRecord } from './validation.js';
4
+ /** Builds labels only from exact readback evidence. It never infers HUD suffixes.
5
+ * Unobserved or changed options return undefined, so the standard encoder refuses them. */
6
+ export function createReadBackWriteLabelResolver(definition, observations) {
7
+ const questions = new Map();
8
+ for (const { question } of flattenQuestions(definition.questions)) {
9
+ if (question.questionType !== 'lookup')
10
+ continue;
11
+ const prior = questions.get(question.questionId);
12
+ if (prior && JSON.stringify(prior) !== JSON.stringify(question))
13
+ throw new ValidationError('ambiguous write-label question');
14
+ questions.set(question.questionId, structuredClone(question));
15
+ }
16
+ const labels = new Map();
17
+ const identity = (questionId, optionId) => JSON.stringify([questionId, optionId]);
18
+ const visit = (value, depth = 0) => {
19
+ if (depth > 40)
20
+ throw new ValidationError('write-label observation exceeds nesting limit');
21
+ if (Array.isArray(value)) {
22
+ for (const child of value)
23
+ visit(child, depth + 1);
24
+ return;
25
+ }
26
+ if (!isRecord(value))
27
+ return;
28
+ if (value.question_type === 'lookup' && typeof value.question_id === 'number') {
29
+ const question = questions.get(value.question_id);
30
+ if (question) {
31
+ if (value.virt_field_name !== question.fieldName)
32
+ throw new ValidationError('write-label question identity mismatch');
33
+ const raw = value.answer_value;
34
+ const id = typeof raw === 'number' ? raw : typeof raw === 'string' && /^\d+$/.test(raw) ? Number(raw) : null;
35
+ if (id !== null && Number.isSafeInteger(id) && typeof value.answer_value_text === 'string' && value.answer_value_text.trim()) {
36
+ const options = question.options.filter(option => option.id === id);
37
+ if (options.length !== 1)
38
+ throw new ValidationError('write-label option identity mismatch', [question.fieldName ?? String(question.questionId)]);
39
+ const key = identity(question.questionId, id), prior = labels.get(key);
40
+ if (prior !== undefined && prior !== value.answer_value_text)
41
+ throw new ValidationError('conflicting write-label observations', [question.fieldName ?? String(question.questionId)]);
42
+ labels.set(key, value.answer_value_text);
43
+ }
44
+ }
45
+ }
46
+ // Traverse known response/assessment containers only. Do not interpret arbitrary strings as data.
47
+ for (const key of ['value', 'values', 'sub_assessment_question_list', 'sub_assessment_answer_list', 'sub_assessment_list'])
48
+ if (value[key] !== undefined)
49
+ visit(value[key], depth + 1);
50
+ };
51
+ for (const observation of observations) {
52
+ if (observation.tenant !== definition.tenant)
53
+ throw new ValidationError('write-label observation tenant mismatch');
54
+ visit(observation.response);
55
+ }
56
+ const sameOption = (a, b) => a.id === b.id && a.picklistId === b.picklistId && a.code === b.code && a.picklistCode === b.picklistCode && a.name === b.name && a.hudVisibility === b.hudVisibility;
57
+ const resolver = (question, option) => {
58
+ const known = questions.get(question.questionId);
59
+ if (!known || known.fieldName !== question.fieldName || question.questionType !== 'lookup' || !known.options.some(o => sameOption(o, option)))
60
+ return undefined;
61
+ return labels.get(identity(question.questionId, option.id));
62
+ };
63
+ return Object.freeze(Object.assign(resolver, { tenant: definition.tenant }));
64
+ }
65
+ //# sourceMappingURL=write-labels.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write-labels.js","sourceRoot":"","sources":["../../src/write-labels.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,gBAAgB,EAAC,MAAM,eAAe,CAAC;AAE/C,OAAO,EAAC,eAAe,EAAC,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAC,QAAQ,EAAC,MAAM,iBAAiB,CAAC;AAKzC;2FAC2F;AAC3F,MAAM,UAAU,gCAAgC,CAC/C,UAA+B,EAC/B,YAA6C;IAE7C,MAAM,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IAAE,QAAQ,CAAC,YAAY,KAAG,QAAQ,IAAE,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAA,EAAE,CAAA,UAAU,CAAC,CAAC,EAAC,MAAM,CAAC,CAAC;YAAC,OAAO,SAAS,CAAC;QACjJ,OAAO,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,UAAU,EAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAC,EAAC,MAAM,EAAC,UAAU,CAAC,MAAM,EAAC,CAAC,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import type {AssessmentDefinition,PicklistOption,QuestionDefinition} from './metadata.js';\nimport {flattenQuestions} from './metadata.js';\nimport type {EncodingOptions} from './encoding.js';\nimport {ValidationError} from './errors.js';\nimport {isRecord} from './validation.js';\n\nexport interface WriteLabelObservation {tenant:string;response:unknown;}\nexport type ReadBackWriteLabelResolver = NonNullable<EncodingOptions['writeLabel']> & {readonly tenant:string};\n\n/** Builds labels only from exact readback evidence. It never infers HUD suffixes.\n * Unobserved or changed options return undefined, so the standard encoder refuses them. */\nexport function createReadBackWriteLabelResolver(\n definition:AssessmentDefinition,\n observations:readonly WriteLabelObservation[],\n):ReadBackWriteLabelResolver{\n const questions=new Map<number,QuestionDefinition>();\n for(const {question} of flattenQuestions(definition.questions)){\n if(question.questionType!=='lookup')continue;\n const prior=questions.get(question.questionId);\n if(prior&&JSON.stringify(prior)!==JSON.stringify(question))throw new ValidationError('ambiguous write-label question');\n questions.set(question.questionId,structuredClone(question));\n }\n const labels=new Map<string,string>();\n const identity=(questionId:number,optionId:number)=>JSON.stringify([questionId,optionId]);\n const visit=(value:unknown,depth=0):void=>{\n if(depth>40)throw new ValidationError('write-label observation exceeds nesting limit');\n if(Array.isArray(value)){for(const child of value)visit(child,depth+1);return;}\n if(!isRecord(value))return;\n if(value.question_type==='lookup'&&typeof value.question_id==='number'){\n const question=questions.get(value.question_id);\n if(question){\n if(value.virt_field_name!==question.fieldName)throw new ValidationError('write-label question identity mismatch');\n const raw=value.answer_value;\n const id=typeof raw==='number'?raw:typeof raw==='string'&&/^\\d+$/.test(raw)?Number(raw):null;\n if(id!==null&&Number.isSafeInteger(id)&&typeof value.answer_value_text==='string'&&value.answer_value_text.trim()){\n const options=question.options.filter(option=>option.id===id);\n if(options.length!==1)throw new ValidationError('write-label option identity mismatch',[question.fieldName??String(question.questionId)]);\n const key=identity(question.questionId,id),prior=labels.get(key);\n if(prior!==undefined&&prior!==value.answer_value_text)throw new ValidationError('conflicting write-label observations',[question.fieldName??String(question.questionId)]);\n labels.set(key,value.answer_value_text);\n }\n }\n }\n // Traverse known response/assessment containers only. Do not interpret arbitrary strings as data.\n for(const key of ['value','values','sub_assessment_question_list','sub_assessment_answer_list','sub_assessment_list'])if(value[key]!==undefined)visit(value[key],depth+1);\n };\n for(const observation of observations){\n if(observation.tenant!==definition.tenant)throw new ValidationError('write-label observation tenant mismatch');\n visit(observation.response);\n }\n const sameOption=(a:PicklistOption,b:PicklistOption)=>a.id===b.id&&a.picklistId===b.picklistId&&a.code===b.code&&a.picklistCode===b.picklistCode&&a.name===b.name&&a.hudVisibility===b.hudVisibility;\n const resolver=(question:QuestionDefinition,option:PicklistOption)=>{\n const known=questions.get(question.questionId);\n if(!known||known.fieldName!==question.fieldName||question.questionType!=='lookup'||!known.options.some(o=>sameOption(o,option)))return undefined;\n return labels.get(identity(question.questionId,option.id));\n };\n return Object.freeze(Object.assign(resolver,{tenant:definition.tenant}));\n}\n"]}
@@ -31,6 +31,22 @@ WellSky requires a client context and known assessment code for these reads. The
31
31
 
32
32
  Use the raw `assessments.get`, `assessmentsMobile.getAnswers`, and `enrollments.getAssessment` methods for recorded answers. Use `encodeAnswers` and `encodeNewSubassessmentRow` for endpoint-specific encoding. Mobile lookups use option IDs; standalone/enrollment lookups require an explicit `writeLabel` resolver with tenant-verified labels. Raw option names are not assumed to be valid write labels. Some HUD-marked choices require `(HUD)` in the full write label even when metadata `name` omits it. Do not infer this from trailing whitespace or append the suffix to every option. Continue supplying tenant-verified labels until a label resolver has authoritative metadata; recorded `answer_value_text` is useful evidence for the corresponding option. Provider answers are refused for mobile writes because that endpoint can silently discard them. Answer-state code mappings and multi-value serialization are caller-supplied; a refusal is never converted to `No`.
33
33
 
34
+ ## Resolve exact lookup write labels from readback
35
+
36
+ `createReadBackWriteLabelResolver` preserves the exact `answer_value_text` for an observed question/option pair, including a HUD suffix and whitespace. It does not infer labels from trailing spaces or `hudVisibility`: retained readbacks include suffixed and unsuffixed labels with the same visibility flag.
37
+
38
+ ```ts
39
+ import {createReadBackWriteLabelResolver} from '@choiceapps/communityservices-sdk';
40
+ const writeLabel = createReadBackWriteLabelResolver(definition, [
41
+ {tenant: api.tenant, response: recordedAnswers},
42
+ ]);
43
+ // Supply writeLabel to encodeAnswers or createEnrollmentWorkflow.
44
+ ```
45
+
46
+ Supply authorized assessment reads from the definition's tenant. The helper matches question ID, field name and option ID, rejects conflicting labels and mixed tenants, and returns an immutable resolver tagged with its tenant. The enrollment workflow checks that tenant. The resolver returns `undefined` for unobserved or changed options, so normal encoding refuses them. Refresh the definition and observations after metadata changes.
47
+
48
+ This is an evidence-backed resolver, not a complete label catalog. Unobserved options still need an authoritative readback or another independently verified resolver. Do not write answers merely to discover labels. See [the typed example](../examples/checked-assessment-writes.mts).
49
+
34
50
  ## Yes/no answer acceptance
35
51
 
36
52
  `encodeAnswers` encodes a `yes_no` value of `true` or `"Yes"` as `"Yes"`, and `false` or `"No"` as `"No"`. Which endpoint persists that value matters more than the encoding.
@@ -54,6 +70,21 @@ An entry assessment and a standalone form can reference the same stored question
54
70
 
55
71
  Read the existing answer before planning a mobile scalar insert. If it already exists at that instant with another value, use a supported standard correction/update path after resolving the original operation; do not move its timestamp to evade the collision. Raw `assessmentsMobile.addAnswer` remains a raw write and performs no implicit read or cross-form collision check. Never switch endpoints to retry an uncertain batch.
56
72
 
73
+ Use `writeMobileAnswersChecked(api, request)` for an explicit scalar collision check before a raw mobile batch. It accepts the ordinary mobile request with a required timezone-qualified, whole-second `query.dateEffective`. It reads the supplied instrument one second after that instant so yes/no rows are visible, then matches question identity and effective date. A row at the target instant blocks the entire batch even when its value is identical or empty. Missing, invalid or newer readback evidence also blocks the write. Older answers allow the insert.
74
+
75
+ ```ts
76
+ import {writeMobileAnswersChecked, MobileAnswerPreflightError} from '@choiceapps/communityservices-sdk';
77
+ await writeMobileAnswersChecked(api, {
78
+ path: {clientId, assessmentCode},
79
+ query: {dateEffective: originalEffectiveInstant},
80
+ body: encodedMobileAnswers,
81
+ });
82
+ ```
83
+
84
+ `MobileAnswerPreflightError` has a stable `code`, affected `fields`, and `committed: false`. A collision uses `MOBILE_ANSWER_EXISTS`; unavailable evidence uses `MOBILE_PREFLIGHT_UNAVAILABLE`. The helper checks scalars, including questions shared across instruments, but does not detect duplicate subassessment rows. It makes one write after a successful preflight and does not retry or journal it. An error from that write retains its original type and possible uncertain outcome. Reads and writes are not atomic against other users. Pass the original instant; the SDK transport applies any configured mobile date correction.
85
+
86
+ New enrollment workflow plans also check scalar collisions before creating an enrollment or sending a mobile batch. Existing pending journal operations retain their reconciliation behavior.
87
+
57
88
  ## Race and ethnicity combinations
58
89
 
59
90
  `encodeAnswers` recognizes the standard `HUD_RACEETHNICITY` field. It resolves single-category and multiple-category answers to the tenant's `RACE_ETH_COMBO_*` option IDs. A single White answer uses `RACE_ETH_COMBO_WHI`, even when the caller supplies `RACE_ETH_WHI`. Atomic option IDs can read back with a label while appearing blank in the UI.
@@ -86,3 +86,16 @@ The integrator reported these results using SDK 0.4.1 in the training tenant. Th
86
86
  - After those household exits, both re-enrollment attempts failed on the pre-create REST list with HTTP 400 from the grouped-enrollment `42703` gap. This confirms that an exited household enrollment can still break that REST list.
87
87
 
88
88
  The GWT catalog correction has regression coverage for individual creation, household heads and member preflight, failed-read classification and re-enrollment. Same-date entry corrections and adoption of manual enrollments have synthetic coverage. These newer paths have not been independently verified live.
89
+
90
+ ## Integrator-reported SDK 0.6.0 acceptance
91
+
92
+ The integrator reports these training-tenant results on November 10 and 11, 2026; the SDK team has not independently rerun them:
93
+
94
+ - GWT `listEnrollments` succeeded for a household client whose REST list returned HTTP 400.
95
+ - Standalone `adoptEnrollment` followed by `createInterim`, and single-person same-day `correctEntry`, succeeded. Same-key repeats made no writes.
96
+ - Three pending 0.5.0 corrections were refused without confirmation and resolved as `rejected` with confirmation.
97
+ - Earlier 0.5.0 runs verified individual/household adoption followed by exit, household re-enrollment after exit, and path corrections in both directions for individuals and households, with no-write same-key repeats.
98
+
99
+ The integrator has not tested household adoption followed by `createHouseholdInterim`, scalar correction on an adopted enrollment, or a new correction key after resolution. Synthetic tests do not replace that acceptance.
100
+
101
+ The 0.7.0 label resolver, group flags, household discovery, row registration, error codes and mobile collision preflight have local regression coverage, not new live tenant acceptance. Full write labels remain unresolved for unobserved options. Household discovery refuses ambiguous current-membership matches. Yes/no blanking remains unsupported; no alternative route has been verified.
@@ -148,7 +148,7 @@ const corrected = await workflow.correctEntry({
148
148
  });
149
149
  ```
150
150
 
151
- `answers` uses the ordinary answer and option selectors. `clear` explicitly removes a recorded value; an omitted field stays unchanged. Yes/no fields cannot appear in `clear`: the SDK throws `UNSUPPORTED_YES_NO_CLEAR`, with the affected `fields`, before any correction write or new journal record. Use `{value: false}` to answer `No`; it does not mean blank. No alternative yes/no blanking route has been verified. Do not use `notApplicable` to clear an old answer. Every row key must identify an existing row returned by the original entry operation. The correction never creates a second row, deletes a row, or changes the enrollment date.
151
+ `answers` uses the ordinary answer and option selectors. `clear` explicitly removes a recorded value; an omitted field stays unchanged. Yes/no fields cannot appear in `clear`: the SDK throws `UNSUPPORTED_YES_NO_CLEAR`, with the affected `fields`, before any correction write or new journal record. Use `{value: false}` to answer `No`; it does not mean blank. No alternative yes/no blanking route has been verified. Do not use `notApplicable` to clear an old answer. Every row key must identify an existing row returned by the original entry operation or explicitly bound with `registerEntryRows`. The correction never creates a second row, deletes a row, or changes the enrollment date.
152
152
 
153
153
  Scalars use the standard assessment endpoint, which supports same-date updates. The batch includes every mandatory scalar, preserving its current value unless the patch explicitly answers or clears it. Missing mandatory values require an explicit answer, or an explicit clear for a supported non-yes/no type; lookup values require verified write labels. Readback checks one second after the original instant so stored yes/no values are visible.
154
154
 
@@ -176,7 +176,7 @@ await workflow.resolveEntryCorrection({
176
176
 
177
177
  The SDK verifies the complete saved pre-write state before and after confirmation and rechecks enrollment context. A partial application, changed state or unavailable read prevents resolution. Successful resolution marks the correction `rejected` while retaining its original intent, attempted steps, diagnostics and evidence reference. It makes no SDK record writes to WellSky. Repeating the same resolution returns `already-rejected`; submitting that correction key again throws `ENTRY_CORRECTION_REJECTED`. Use a new correction key for the corrected intent only after resolution. A verified successful correction cannot be rejected.
178
178
 
179
- This also supports pending 0.5.0 journals, including those without failure metadata, when the required independent evidence exists. A new validation failure that occurs before journaling needs no resolution.
179
+ This also supports pending 0.5.0 journals, including those without failure metadata, when the required independent evidence exists. For these journals the callback can receive only a step name and state, with no failure kind or status. The caller must retain its own original failure evidence; the SDK cannot reconstruct it and must not resend the write to obtain diagnostics. A new validation failure that occurs before journaling needs no resolution.
180
180
 
181
181
  ## Household enrollment and interim assessments
182
182
 
@@ -232,7 +232,7 @@ const detail = await session.enrollmentSession.readEnrollment({
232
232
  // detail.members contains the complete linked clientId/enrollmentId pairs.
233
233
  ```
234
234
 
235
- Use the session returned by `openEnrollmentSession`. Lists include open and exited entries, validate complete counts, and refuse more than 1,000 records. The detail read currently exposes `householdClientIds`, not `householdId`; these client IDs and the enrollment's group are not interchangeable with a household ID. Household adoption still requires an explicitly verified household ID.
235
+ Use the session returned by `openEnrollmentSession`. Lists include open and exited entries, validate complete counts, and refuse more than 1,000 records. List rows and details include `groupId` and `grouped`. The flag describes a stored group link, including a group with one participant; it is not a member count and requires no per-row detail reads. These fields are required on managed catalog rows and optional on custom detail-reader contracts for compatibility. `groupId` is never a household ID. For a verified household match from a head enrollment, use `discoverHouseholdEnrollment` below.
236
236
 
237
237
  ## Individual enrollment exits
238
238
 
@@ -264,7 +264,41 @@ Use `adoptEnrollment({key, clientId, enrollmentId})` for a standalone enrollment
264
264
 
265
265
  Adoption writes only to the local durable journal. It does not create, attach, exit or modify an HMIS record. Later entrants retain their own original entry dates. An enrollment already tracked under another entry key is rejected; use its existing key. Retry an interrupted adoption with the same inputs and store.
266
266
 
267
- After standalone adoption, its key can be used as `enrollmentKey` for `createInterim`, scalar-only `correctEntry`, or `exitEnrollment`. After household adoption, the group key works with `createHouseholdInterim` and `exitHousehold`; use the returned member's `key` for that person's scalar-only `correctEntry`. Correction still requires an open entry without reviews or exits. Do not use an all-not-applicable `createEnrollment` call merely to link an existing entry: it can create an enrollment when no match exists. Exit assessment plans and normal household head rules still apply. Adoption records existing enrollment identities, not historical subassessment row-key mappings, so its returned `recordsetIds` is empty. It cannot identify rows for `correctEntry` by a new invented key. See [manual-entry exit examples](../examples/existing-enrollment-exits.mts).
267
+ After standalone adoption, its key can be used as `enrollmentKey` for `createInterim`, scalar-only `correctEntry`, or `exitEnrollment`. After household adoption, the group key works with `createHouseholdInterim` and `exitHousehold`; use the returned member's `key` for that person's scalar-only `correctEntry`. Correction still requires an open entry without reviews or exits. Do not use an all-not-applicable `createEnrollment` call merely to link an existing entry: it can create an enrollment when no match exists. Exit assessment plans and normal household head rules still apply. Adoption initially returns empty `recordsetIds`. Use `registerEntryRows` below to bind verified existing recordsets before row corrections; a new invented key alone cannot identify a historical row. See [manual-entry exit examples](../examples/existing-enrollment-exits.mts).
268
+
269
+ ### Discover a household from its head enrollment
270
+
271
+ ```ts
272
+ const discovered = await workflow.discoverHouseholdEnrollment({
273
+ headClientId, headEnrollmentId,
274
+ });
275
+ // discovered: householdId, householdSource, providerId, type, members
276
+ const adopted = await workflow.adoptHouseholdEnrollment({
277
+ key: sourceEnrollmentKey, headClientId, headEnrollmentId,
278
+ });
279
+ ```
280
+
281
+ Discovery reads the linked enrollment cohort through GWT and matches it against complete current household membership reads. It requires one household containing the cohort, the same head, and membership dates covering each entry. It verifies that household again before returning `householdSource: 'verified-membership'`. This is a verified membership match, not a native historical household pointer on the enrollment. Zero matches, multiple matches, incomplete reads or changed relationships fail without adopting. Historical households that no longer match require the existing explicit adoption inputs and their validation. No record is written to WellSky during discovery or adoption.
282
+
283
+ ### Register existing entry rows
284
+
285
+ ```ts
286
+ await workflow.registerEntryRows({
287
+ key: sourceRegistrationKey,
288
+ enrollmentKey: adoptedEntryKey,
289
+ clientId,
290
+ rows: [{key: 'entry-ce', parentField, recordsetId: existingRecordsetId}],
291
+ });
292
+ // correctEntry can now reference key: 'entry-ce' with the same parentField.
293
+ ```
294
+
295
+ Select explicit recordset IDs from authorized assessment reads. Registration verifies the enrollment, question definition, and each row's presence in both entry-time and current reads. It stores immutable key/parent/recordset bindings in the local journal and makes no WellSky record writes. Same-key repeats return `already-present`; duplicate aliases, absent rows, rebinding, and pending operations are refused. Native entry row keys already work without registration. For household adoption, use each returned member's entry `key` and register that member's rows separately. Registration does not establish who originally created a row or make later edits eligible: `correctEntry` still enforces open-entry and no-review rules. See [the typed example](../examples/enrollment-discovery-and-correction.mts).
296
+
297
+ ### Classify workflow failures
298
+
299
+ `EnrollmentWorkflowError` exposes a stable `code`, `operation`, and `committed`. Classify by code instead of message text. Pre-write validation, discovery and adoption failures report `committed: false`. Any attempted write, relevant prior attempt, or unreadable prior outcome remains `'unknown'`. The marker describes WellSky record writes for that operation, not local journal changes. `cause` preserves the original error where available.
300
+
301
+ A failed `resolveEntryCorrection` can have `committed: false` because resolution itself writes no WellSky records, while `originalCommitted: 'unknown'` describes the original correction. Never use a resolution error's marker to infer non-application of the original write. See [error codes and recovery](troubleshooting.md#workflow-error-codes).
268
302
 
269
303
  ## Household exits
270
304
 
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`, `resolveEntryCorrection`, `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 |
@@ -46,6 +46,23 @@ Successful adoption of an existing record also needs its journal. Retain it even
46
46
 
47
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.
48
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
+
49
66
  ## Inspect an upstream error privately
50
67
 
51
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@choiceapps/communityservices-sdk",
3
- "version": "0.6.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",