{"schemaVersion":"mappls.journey-workshop.v1","slug":"ios-geofence-draft","journeySlug":"ios-geofence-draft","title":"Build iOS geofence draft and publication boundary","summary":"An eight-lab, source-bounded workshop for the complete geofence draft lifecycle: exact commands and events, durable records, replay, concurrency, unknown outcomes, hostile fixtures, a maintained capstone, and production exit evidence.","duration":"2 hr 10 min","level":"Advanced","productSlug":"intouch-telematics","stateModel":"hybrid","aggregate":"geofence draft","actorCount":5,"stateCount":6,"transitionCount":6,"eventCount":6,"sourceGuideSlugs":["mappls-geofence-ui-ios-distribution","mappls-geofence-ui-ios-distribution-base"],"contractSlugs":[],"relatedTutorialSlugs":["ios-direction-geofence-handoffs"],"sample":{"slug":"deep-link-journey-host","name":"Deep-link & Native UI Journey Host","downloadPath":"/downloads/deep-link-journey-host.zip","checksumPath":"/downloads/deep-link-journey-host.zip.sha256","verifiedTestCount":11,"runCommand":"npm test --workspace @mappls-example/deep-link-journey-host"},"labs":[{"slug":"model-lifecycle","title":"Model the lifecycle before the UI","duration":"15 min","objective":"Turn the geofence draft blueprint into an explicit aggregate boundary owned by the application.","build":["draft: The host owns name, purpose, subject scope, rule intent, and geometry revision before opening the editor.","editing: One view and delegate generation owns mode, handles, slider, style, callbacks, dismissal, and cleanup.","candidate: Circle or polygon output has been copied into a portable geometry schema but is not yet an operational rule.","review_pending: Valid geometry, purpose, scope, schedule intent, and policy version await an attributable application review.","approved_draft: The application has a review-approved portable artifact ready for a separately selected and entitled rule-publication contract.","cancelled: The author ended editing without approving a new geometry revision and the UI lifecycle is fully disposed."],"prove":["Every persisted state exists in the reviewed blueprint.","Terminal states reject ordinary forward commands.","Recovery text is operational guidance, not another hidden state."]},{"slug":"command-event-contract","title":"Implement every command and event pair","duration":"20 min","objective":"Make intent, actor authority, allowed source state, committed state, and emitted fact reviewable together.","build":["create_geofence_draft by Host application: new aggregate → draft; emit geofence_draft.created.","open_editor by Operations author: draft | review_pending → editing; emit geofence_draft.editor_opened.","receive_geometry by MapplsGeofenceUI: editing → candidate; emit geofence_draft.geometry_received.","submit_for_review by Operations author: candidate → review_pending; emit geofence_draft.review_requested.","approve_draft by Geofence reviewer: review_pending → approved_draft; emit geofence_draft.approved.","cancel_edit by Operations author: draft | editing | candidate | review_pending → cancelled; emit geofence_draft.cancelled."],"prove":["create_geofence_draft resolves to ios-geofence-draft-geofence-draft-created without claiming a provider webhook payload.","open_editor resolves to ios-geofence-draft-geofence-draft-editor-opened without claiming a provider webhook payload.","receive_geometry resolves to ios-geofence-draft-geofence-draft-geometry-received without claiming a provider webhook payload.","submit_for_review resolves to ios-geofence-draft-geofence-draft-review-requested without claiming a provider webhook payload.","approve_draft resolves to ios-geofence-draft-geofence-draft-approved without claiming a provider webhook payload.","cancel_edit resolves to ios-geofence-draft-geofence-draft-cancelled without claiming a provider webhook payload."]},{"slug":"durable-records","title":"Persist restart-safe records","duration":"15 min","objective":"Separate business identity, provider evidence, command receipts, immutable facts, audit, and downstream delivery.","build":["Geofence draft: Host-owned intent, current revision, lifecycle state, policy, and optimistic version. Keys: draftId, externalId, purpose, scope, state, geometryRevision, version.","Geometry revision: Immutable canonical circle or polygon independent of UI lifetime. Keys: geometryId, mode, coordinates, radiusMeters, canonicalHash, sourceGeneration.","Review decision: Attributable approval or rework request for an exact geometry and policy version. Keys: reviewId, geometryId, reviewer, decision, reason, decidedAt.","Publication boundary: Selection record for a future provider rule adapter without inventing a rule ID. Keys: draftId, adapterStatus, entitlementReference, requiredContract, selectedAt."],"prove":["Process restart restores the same aggregate version and command result.","Opaque SDK or native UI objects are not durable records.","Provider evidence and application decisions remain distinguishable."]},{"slug":"concurrency-replay","title":"Make concurrency and replay deterministic","duration":"15 min","objective":"Apply optimistic expected versions and aggregate-scoped idempotency before executing effects.","build":["Editor output is an application candidate, not evidence of a published provider rule.","Only canonical validated circle or polygon geometry enters review.","Each geometry revision is immutable and linked to the editor generation that produced it.","Purpose, subject scope, schedule intent, and policy version travel with geometry review.","Publishing requires a separately documented, entitled rule contract and creates a separate provider identity mapping.","Provider views, delegates, map layers, credentials, and opaque callback objects are never persisted."],"prove":["An exact replay returns the first result without another event or version.","A reused key with different intent conflicts.","A stale expected version changes no durable truth."]},{"slug":"effects-reconciliation","title":"Control effects and unknown outcomes","duration":"15 min","objective":"Commit outbox intent atomically, execute effects outside the transaction, and reconcile ambiguous results.","build":["Editor returns invalid or unsafe geometry: detect with Canonical validation finds missing points, self-intersection, invalid radius, excessive area, or policy bounds failure. Recover with Keep the candidate uncommitted, explain the exact constraint, and reopen a new editor generation.","Callback arrives after view disposal: detect with The delegate generation is inactive or differs from the aggregate's editor generation. Recover with Ignore it and clean up provider resources without changing the current draft.","Two authors edit the same draft: detect with The submitted geometry references an older aggregate or geometry revision. Recover with Return a conflict with the current revision and require an intentional new edit.","No authoritative publication contract is available: detect with The selected environment lacks a documented provider command, entitlement, response, or rule identity contract. Recover with Keep the artifact approved_draft and route contract selection to an administrator; never fabricate publication success."],"prove":["A timeout remains an unknown outcome until identity-based reconciliation completes.","Retries are bounded and preserve the original business and command identities.","Dead-letter or manual review retains the entire attempt history."]},{"slug":"hostile-scenarios","title":"Run all hostile fixture scenarios","duration":"15 min","objective":"Exercise the success path plus replay, concurrency, state, and response-loss failures without an account.","build":["Complete journey: Commit the shortest reviewed success path to the journey-specific operating target.","Idempotent replay: Repeat one command identity and prove that version, event identity, and side effects do not duplicate.","Stale version: Reject a command based on an outdated aggregate version without changing durable truth.","Invalid transition: Reject a known command when the current state does not permit it.","Unknown outcome recovery: Reconcile after a lost response, then replay the original command identity safely."],"prove":["All fixture checks pass for all five scenarios.","Rejected commands emit no event and do not increment version.","The fixture makes zero provider calls and exposes no write tool."]},{"slug":"maintained-capstone","title":"Trace the Deep-link & Native UI Journey Host capstone","duration":"20 min","objective":"Follow the maintained source through domain rules, adapter seam, repository transaction, HTTP boundary, UI evidence, and restart test.","build":["Run the app's declared test suite (11 tests).","Run fixture mode without a credential.","Inspect audit and outbox evidence after each transition.","Restart the process and continue the same aggregate."],"prove":["The downloadable archive checksum verifies before execution.","The capstone covers the journey target without inventing provider completion.","Browser and HTTP surfaces report the same durable version."]},{"slug":"production-exit","title":"Qualify the real integration boundary","duration":"15 min","objective":"Replace only reviewed adapter seams and collect independent production evidence without weakening application invariants.","build":["Editor open, cancel, and result by component version and geometry mode","Validation failures by bounded reason","Geometry revision count and review turnaround","Stale generation and optimistic version conflicts","Approved drafts awaiting publication-contract selection","Publication adapter outcome only after a separate authoritative contract is configured","Audit and outbox delivery health"],"prove":["Exact product entitlement and regional behavior are validated separately.","Provider contract tests cover success, rejection, throttling, timeout, and unknown outcome.","Security, privacy, operations, rollback, and product owners approve exact evidence.","Fixture completion is never presented as provider or production completion."]}],"codeSamples":[{"language":"typescript","label":"TypeScript aggregate boundary","code":"type State = \"draft\" | \"editing\" | \"candidate\" | \"review_pending\" | \"approved_draft\" | \"cancelled\";\ntype CommandName = \"create_geofence_draft\" | \"open_editor\" | \"receive_geometry\" | \"submit_for_review\" | \"approve_draft\" | \"cancel_edit\";\n\ntype Command = {\n  name: CommandName;\n  aggregateId: string;\n  expectedVersion: number;\n  idempotencyKey: string;\n};\n\nconst transitions = {\n  \"create_geofence_draft\": { from: [null], to: \"draft\", event: \"geofence_draft.created\" },\n  \"open_editor\": { from: [\"draft\", \"review_pending\"], to: \"editing\", event: \"geofence_draft.editor_opened\" },\n  \"receive_geometry\": { from: [\"editing\"], to: \"candidate\", event: \"geofence_draft.geometry_received\" },\n  \"submit_for_review\": { from: [\"candidate\"], to: \"review_pending\", event: \"geofence_draft.review_requested\" },\n  \"approve_draft\": { from: [\"review_pending\"], to: \"approved_draft\", event: \"geofence_draft.approved\" },\n  \"cancel_edit\": { from: [\"draft\", \"editing\", \"candidate\", \"review_pending\"], to: \"cancelled\", event: \"geofence_draft.cancelled\" },\n} as const;\n\nexport function decide(current: { state: State | null; version: number }, command: Command) {\n  const rule = transitions[command.name];\n  if (command.expectedVersion !== current.version) throw new Error(\"version_conflict\");\n  if (!rule.from.includes(current.state as never)) throw new Error(\"invalid_transition\");\n  return {\n    state: rule.to as State,\n    version: current.version + 1,\n    event: rule.event,\n    idempotencyKey: command.idempotencyKey,\n  };\n}\n\n// Persist the result, immutable event, audit row, and outbox intent atomically.\n// Store the first result by idempotencyKey before executing another effect."},{"language":"sql","label":"SQL durability skeleton","code":"CREATE TABLE journey_ios_geofence_draft (\n  aggregate_id text PRIMARY KEY,\n  state text NOT NULL,\n  version bigint NOT NULL CHECK (version > 0),\n  updated_at timestamptz NOT NULL DEFAULT now()\n);\n\nCREATE TABLE journey_ios_geofence_draft_commands (\n  aggregate_id text NOT NULL REFERENCES journey_ios_geofence_draft(aggregate_id),\n  idempotency_key text NOT NULL,\n  request_hash text NOT NULL CHECK (length(request_hash) = 64),\n  committed_version bigint NOT NULL,\n  result_json jsonb NOT NULL,\n  PRIMARY KEY (aggregate_id, idempotency_key)\n);\n\nCREATE TABLE journey_ios_geofence_draft_outbox (\n  event_id text PRIMARY KEY,\n  aggregate_id text NOT NULL,\n  aggregate_version bigint NOT NULL,\n  event_type text NOT NULL,\n  payload jsonb NOT NULL,\n  published_at timestamptz\n);\n\n-- In one transaction: lock aggregate, compare version, decide, append audit/event,\n-- insert the outbox row, and remember the exact command result."},{"language":"curl","label":"Complete fixture journey","code":"curl --request POST 'https://developer.mappls.com/api/journey-simulator' \\\n+  --header 'content-type: application/json' \\\n+  --data '{\"journey\":\"ios-geofence-draft\",\"scenario\":\"complete-journey\"}'"},{"language":"curl","label":"Unknown-outcome drill","code":"curl --request POST 'https://developer.mappls.com/api/journey-simulator' \\\n+  --header 'content-type: application/json' \\\n+  --data '{\"journey\":\"ios-geofence-draft\",\"scenario\":\"unknown-outcome\"}'\n\n# Reconcile geofencedraft identity and the original idempotency key.\n# Never mint a replacement key merely because the response was lost."},{"language":"json","label":"First command envelope","code":"{\n  \"command\": \"create_geofence_draft\",\n  \"aggregateId\": \"fixture-ios-geofence-draft-001\",\n  \"expectedVersion\": 0,\n  \"idempotencyKey\": \"cmd_ios-geofence-draft_001\",\n  \"evidenceBoundary\": \"application-owned-workshop\"\n}"}],"simulationScenarios":[{"slug":"complete-journey","title":"Complete journey","outcome":"Commit the shortest reviewed success path to the journey-specific operating target.","href":"/tools/journey-lab?journey=ios-geofence-draft&scenario=complete-journey#lab"},{"slug":"idempotent-replay","title":"Idempotent replay","outcome":"Repeat one command identity and prove that version, event identity, and side effects do not duplicate.","href":"/tools/journey-lab?journey=ios-geofence-draft&scenario=idempotent-replay#lab"},{"slug":"stale-version","title":"Stale version","outcome":"Reject a command based on an outdated aggregate version without changing durable truth.","href":"/tools/journey-lab?journey=ios-geofence-draft&scenario=stale-version#lab"},{"slug":"invalid-transition","title":"Invalid transition","outcome":"Reject a known command when the current state does not permit it.","href":"/tools/journey-lab?journey=ios-geofence-draft&scenario=invalid-transition#lab"},{"slug":"unknown-outcome","title":"Unknown outcome recovery","outcome":"Reconcile after a lost response, then replay the original command identity safely.","href":"/tools/journey-lab?journey=ios-geofence-draft&scenario=unknown-outcome#lab"}],"acceptance":["All 6 reviewed transitions are implemented with actor and source-state checks.","All 6 application event identities are immutable and versioned.","Exact replay, idempotency conflict, stale version, invalid transition, and unknown outcome are tested.","Aggregate, event, audit, command result, and outbox intent commit atomically.","The Deep-link & Native UI Journey Host capstone passes 11 declared tests after archive checksum verification.","Provider entitlement, payload, callback, completion, and production behavior remain independently evidenced."],"sourceBoundary":["The journey blueprint and application event contracts are implementation guidance, not Mappls provider payload specifications.","Only linked normalized contracts and source guides may define provider request syntax; empty evidence is never backfilled.","The simulator and maintained capstone operate in explicit fixture mode and make no entitlement claim.","Credentials, precise production payloads, opaque native objects, and provider secrets stay outside workshop inputs and durable examples."],"releaseBoundary":"Workshop completion proves an application-owned reliability design only. Production still requires issued entitlement, exact adapter contract tests, regional and quota validation, security/privacy review, operational drills, and independent release approval.","websitePath":"/journeys/ios-geofence-draft/workshop","apiPath":"/api/journey-workshops?journey=ios-geofence-draft","providerCalls":0,"writesExposed":false}