farseer-cli 1.19.0 → 1.20.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 (155) hide show
  1. package/README.md +31 -8
  2. package/dist/commands/app.js +42 -3
  3. package/dist/commands/app.js.map +1 -1
  4. package/dist/commands/cells.js +120 -85
  5. package/dist/commands/cells.js.map +1 -1
  6. package/dist/commands/dashboards.js +246 -12
  7. package/dist/commands/dashboards.js.map +1 -1
  8. package/dist/commands/dimensions.js +52 -27
  9. package/dist/commands/dimensions.js.map +1 -1
  10. package/dist/commands/docs.js +82 -0
  11. package/dist/commands/docs.js.map +6 -0
  12. package/dist/commands/files.js +49 -0
  13. package/dist/commands/files.js.map +2 -2
  14. package/dist/commands/folders.js +76 -0
  15. package/dist/commands/folders.js.map +6 -0
  16. package/dist/commands/formula.js +38 -30
  17. package/dist/commands/formula.js.map +1 -1
  18. package/dist/commands/install.js +32 -30
  19. package/dist/commands/install.js.map +2 -2
  20. package/dist/commands/model.js +30 -5
  21. package/dist/commands/model.js.map +2 -2
  22. package/dist/commands/push.js +5 -3
  23. package/dist/commands/push.js.map +1 -1
  24. package/dist/commands/sheets.js +289 -52
  25. package/dist/commands/sheets.js.map +1 -1
  26. package/dist/commands/skills.js +157 -0
  27. package/dist/commands/skills.js.map +6 -0
  28. package/dist/commands/variables.js +246 -82
  29. package/dist/commands/variables.js.map +1 -1
  30. package/dist/index.js +93 -13
  31. package/dist/index.js.map +1 -1
  32. package/dist/mcp/resources/documentation.js +19 -12
  33. package/dist/mcp/resources/documentation.js.map +1 -1
  34. package/dist/mcp/tools/appTools.js +1 -7
  35. package/dist/mcp/tools/appTools.js.map +1 -1
  36. package/dist/mcp/tools/cellTools.js +6 -19
  37. package/dist/mcp/tools/cellTools.js.map +1 -1
  38. package/dist/mcp/tools/dashboardTools.js +30 -412
  39. package/dist/mcp/tools/dashboardTools.js.map +2 -2
  40. package/dist/mcp/tools/dataTools.js +15 -146
  41. package/dist/mcp/tools/dataTools.js.map +1 -1
  42. package/dist/mcp/tools/folderTools.js +12 -78
  43. package/dist/mcp/tools/folderTools.js.map +1 -1
  44. package/dist/mcp/tools/modelTools.js +23 -372
  45. package/dist/mcp/tools/modelTools.js.map +1 -1
  46. package/dist/mcp/tools/pipelineContract.js +5 -1
  47. package/dist/mcp/tools/pipelineContract.js.map +1 -1
  48. package/dist/mcp/tools/runTools.js +8 -69
  49. package/dist/mcp/tools/runTools.js.map +1 -1
  50. package/dist/mcp/tools/sheetTools.js +14 -264
  51. package/dist/mcp/tools/sheetTools.js.map +1 -1
  52. package/dist/mcp/tools/syncTools.js +5 -1
  53. package/dist/mcp/tools/syncTools.js.map +1 -1
  54. package/dist/mcp/utils/operationResponse.js +41 -0
  55. package/dist/mcp/utils/operationResponse.js.map +6 -0
  56. package/dist/operations/cells.js +444 -0
  57. package/dist/operations/cells.js.map +6 -0
  58. package/dist/operations/dashboards.js +357 -0
  59. package/dist/operations/dashboards.js.map +6 -0
  60. package/dist/operations/data.js +206 -0
  61. package/dist/operations/data.js.map +6 -0
  62. package/dist/operations/errors.js +64 -0
  63. package/dist/operations/errors.js.map +6 -0
  64. package/dist/operations/exportModel.js +59 -0
  65. package/dist/operations/exportModel.js.map +6 -0
  66. package/dist/operations/folderPath.js +128 -0
  67. package/dist/operations/folderPath.js.map +6 -0
  68. package/dist/operations/folders.js +80 -0
  69. package/dist/operations/folders.js.map +6 -0
  70. package/dist/operations/install.js +109 -0
  71. package/dist/operations/install.js.map +6 -0
  72. package/dist/operations/model.js +271 -0
  73. package/dist/operations/model.js.map +6 -0
  74. package/dist/operations/sheets.js +428 -0
  75. package/dist/operations/sheets.js.map +6 -0
  76. package/dist/pipeline/failStep.js +43 -0
  77. package/dist/pipeline/failStep.js.map +6 -0
  78. package/dist/pipeline/generated-reference.json +10 -10
  79. package/dist/pipeline/queryWorker.js +3 -1
  80. package/dist/pipeline/queryWorker.js.map +1 -1
  81. package/dist/pipeline/requests.js +3 -32
  82. package/dist/pipeline/requests.js.map +1 -1
  83. package/dist/pipeline/service.js +46 -2
  84. package/dist/pipeline/service.js.map +1 -1
  85. package/dist/services/appSyncService.js +59 -9
  86. package/dist/services/appSyncService.js.map +1 -1
  87. package/dist/services/apps.js +10 -0
  88. package/dist/services/apps.js.map +1 -1
  89. package/dist/services/farseerService.js +28 -6
  90. package/dist/services/farseerService.js.map +1 -1
  91. package/dist/skills/bundled.js +106 -0
  92. package/dist/skills/bundled.js.map +6 -0
  93. package/dist/skills/install.js +257 -0
  94. package/dist/skills/install.js.map +6 -0
  95. package/dist/skills/pipeline.js +10 -18
  96. package/dist/skills/pipeline.js.map +1 -1
  97. package/dist/utils/agentSandbox.js +1 -1
  98. package/dist/utils/entityResolver.js +72 -25
  99. package/dist/utils/entityResolver.js.map +1 -1
  100. package/dist/utils/errorFormatter.js +13 -0
  101. package/dist/utils/errorFormatter.js.map +1 -1
  102. package/dist/utils/formulaFilters.js +11 -2
  103. package/dist/utils/formulaFilters.js.map +1 -1
  104. package/dist/utils/operationCli.js +102 -0
  105. package/dist/utils/operationCli.js.map +6 -0
  106. package/docs/cli-guide.md +181 -1
  107. package/docs/pipeline-reference.md +13 -7
  108. package/docs/troubleshooting.md +18 -0
  109. package/package.json +1 -1
  110. package/skills/farseer-app-dev/SKILL.md +131 -0
  111. package/skills/farseer-app-dev/assignments.md +185 -0
  112. package/skills/farseer-app-dev/farseer-client-api-guide.md +907 -0
  113. package/skills/farseer-app-dev/farseer-client-release-notes.md +212 -0
  114. package/skills/farseer-app-dev/working-patterns.md +876 -0
  115. package/skills/farseer-authenticate-to-tenant/SKILL.md +60 -0
  116. package/skills/farseer-authenticate-to-tenant/app-authentication.md +91 -0
  117. package/skills/farseer-author-import-job/SKILL.md +114 -0
  118. package/skills/farseer-author-import-job/cell-writes.md +530 -0
  119. package/skills/farseer-author-import-job/deploying-a-farseer-app.md +383 -0
  120. package/skills/farseer-author-import-job/import-job-pattern.md +232 -0
  121. package/skills/farseer-build-model/SKILL.md +122 -0
  122. package/skills/farseer-build-model/formula-grain-alignment.md +612 -0
  123. package/skills/farseer-build-model/naming-conventions.md +435 -0
  124. package/skills/farseer-build-model/sparse-formulas-pattern.md +330 -0
  125. package/skills/farseer-build-pipeline/SKILL.md +190 -0
  126. package/skills/farseer-build-pipeline/erp-sales/README.md +108 -0
  127. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines.yaml +23 -0
  128. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines_raw.yaml +23 -0
  129. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map.yaml +17 -0
  130. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map_raw.yaml +11 -0
  131. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/gold/erp_sales_cells.yaml +40 -0
  132. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_lines.yaml +35 -0
  133. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_recon.yaml +43 -0
  134. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_unmapped_items.yaml +28 -0
  135. package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/main.py +49 -0
  136. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells.yaml +17 -0
  137. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells_raw.yaml +14 -0
  138. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/load/erp_sales_to_model.yaml +47 -0
  139. package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/main.py +44 -0
  140. package/skills/farseer-build-pipeline/erp-sales/item_to_product.csv +5 -0
  141. package/skills/farseer-build-pipeline/pipeline-app-failure-report-pattern.md +103 -0
  142. package/skills/farseer-build-pipeline/pipeline-source-encoding.md +68 -0
  143. package/skills/farseer-dashboards/SKILL.md +1 -1
  144. package/skills/farseer-help-center/SKILL.md +66 -0
  145. package/skills/farseer-modify-model/SKILL.md +158 -0
  146. package/skills/farseer-modify-model/model-validation-pattern.md +251 -0
  147. package/skills/farseer-optimize-model/SKILL.md +314 -0
  148. package/skills/farseer-optimize-model/stats-dump.ts +139 -0
  149. package/skills/farseer-pnl/SKILL.md +220 -0
  150. package/skills/farseer-review-model/SKILL.md +172 -0
  151. package/skills/farseer-run-apps/SKILL.md +102 -0
  152. package/skills/pipeline-authoring/SKILL.md +4 -4
  153. package/skills/pipeline-authoring/practices.md +15 -3
  154. package/dist/services/agentApprovalFetch.js +0 -90
  155. package/dist/services/agentApprovalFetch.js.map +0 -6
@@ -1,4 +1,4 @@
1
- # Pipeline YAML reference: engine 3.2.1
1
+ # Pipeline YAML reference: engine 3.3.0
2
2
 
3
3
  Generated file. Regenerate with `tools/pipeline/generate_docs.py`.
4
4
 
@@ -131,7 +131,7 @@ Unknown fields are rejected.
131
131
  | `name` | string | yes | none | |
132
132
  | `type` | [StepType](#steptype) | yes | none | |
133
133
  | `deps` | array of string | no | none | |
134
- | `description` | string | no | `""` | |
134
+ | `description` | string | no | `""` | For the client, who reads it in the step's panel on the Pipeline tab: what the step does, and any rule needed to judge its result. Plain words, at most about 300 characters, no build details. |
135
135
  | `extract` | [ExtractConfig](#extractconfig) or null | no | `null` | |
136
136
  | `parse` | [ParseConfig](#parseconfig) or null | no | `null` | |
137
137
  | `transform` | [TransformConfig](#transformconfig) or null | no | `null` | |
@@ -141,6 +141,8 @@ Unknown fields are rejected.
141
141
  | `quality_rules` | array of [QualityRuleEntry](#qualityruleentry) | no | none | |
142
142
  | `write_mode` | [WriteMode](#writemode) | no | `"overwrite"` | |
143
143
  | `merge_keys` | array of string | no | none | |
144
+ | `sort_by` | array of string | no | none | |
145
+ | `max_file_size` | string or integer or null | no | `null` | |
144
146
 
145
147
  Runtime-derived; do not set in YAML: `qualified_name`, `namespace`, `source_path`, `render_context`.
146
148
 
@@ -1965,9 +1967,10 @@ after-image delta process may, can keep the older one. It is wrong for
1965
1967
  sources that send differences. `key` has to equal the `merge_keys` of the
1966
1968
  parse step reading the extract.
1967
1969
 
1968
- `deletes` is the rule for SAP's delete records. `ignore` is the only rule
1969
- for now: they are dropped and counted, so an archived document stays in
1970
- the dataset, as it does with the cursor.
1970
+ `deletes` is the rule for SAP's delete records. `apply` is the default: a
1971
+ delete removes the keyed row, so the dataset mirrors the source's current
1972
+ state. `ignore` drops the delete and counts it and keeps the row, for
1973
+ retaining history the source purges, as the cursor does.
1971
1974
 
1972
1975
  `reset_subscription_until` and `release_until` are lifecycle steps, each
1973
1976
  in effect until the instant it names and refused after it, so a copied
@@ -1985,7 +1988,7 @@ Unknown fields are rejected.
1985
1988
  | YAML field | Type | Required | Default | Constraints / description |
1986
1989
  | --- | --- | --- | --- | --- |
1987
1990
  | `key` | array of string | yes | none | minItems=`1` |
1988
- | `deletes` | `"ignore"` | yes | none | |
1991
+ | `deletes` | `"ignore"`, `"apply"` | no | `"apply"` | |
1989
1992
  | `reset_subscription_until` | string or null | no | `null` | string: format=`"date-time"` |
1990
1993
  | `release_until` | string or null | no | `null` | string: format=`"date-time"` |
1991
1994
 
@@ -2251,7 +2254,10 @@ For `engine: duckdb`:
2251
2254
  the SQL as views named by their leaf name. Output is always parquet.
2252
2255
  `sql_file` (a `.sql` file in `Code/`) exists for engine-run pipelines but
2253
2256
  is refused for authored pipelines, which are validated before any source
2254
- is read; use `query`.
2257
+ is read; use `query`. A query that should stop because the data isn't
2258
+ what the step needs calls `fail_step('…')` with what is wrong and what the
2259
+ client does next, not `error()`: the client reads `fail_step`'s message as
2260
+ the step's failure, and `error()` only as the app's own code failing.
2255
2261
 
2256
2262
  For `engine: ibis`:
2257
2263
 
@@ -108,6 +108,24 @@ const transformed = table.derive({
108
108
 
109
109
  ---
110
110
 
111
+ ## Sync and authentication
112
+
113
+ When `farseer pull`, `push` or `status` does not do what you expect:
114
+
115
+ 1. `farseer whoami`: is the login still valid, and which tenant does this shell target (the argument, else `FARSEER_TENANT`)?
116
+ 2. `farseer status <tenant>`: which files are modified, local-only or remote-only.
117
+ 3. `farseer diff <tenant> [file]`: what differs, before you decide between pulling (keep remote) and pushing (keep local).
118
+
119
+ | Message | What to do |
120
+ |---|---|
121
+ | `Authentication required.` | `farseer login`, or `farseer config set <tenant> --api-key KEY` |
122
+ | `Remote has changes for N file(s) since last pull` | `farseer pull`, then `farseer push` |
123
+ | Apps not syncing over MCP (`farseer_pull`, `farseer_push`) | Those tools sync apps only with a browser login: `farseer login`. The CLI's `pull` and `push` sync apps with an API key as well. |
124
+
125
+ Without `--force`, pull asks how to resolve each conflict and push refuses while the remote has changes (`farseer docs cli-guide` describes the choices). `farseer pull --force` makes local match remote and `farseer push --force` makes remote match local; both also delete what the other side does not have, and both ask first. If the sync baseline drifts out of step, `farseer refresh <tenant>` rebuilds it.
126
+
127
+ ---
128
+
111
129
  ## Debugging Tips
112
130
 
113
131
  ### Check existing dimension members
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "farseer-cli",
3
- "version": "1.19.0",
3
+ "version": "1.20.0",
4
4
  "description": "CLI tool for syncing Farseer App scripts between local folder and Farseer instances",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -0,0 +1,131 @@
1
+ ---
2
+ name: farseer-app-dev
3
+ description: >-
4
+ Use when the user asks to write, modify, or refactor a Farseer app (TypeScript using the `farseer-client` SDK) — import jobs, exports, transforms, reports. Inspects live model via explicit-tenant CLI reads first, follows the SDK working patterns (optimistic auth resolution — never prompt "OAuth or API key?", `error.text()` catch, `exportModel` excluding CELL, named `toRow` helper, validation-before-mutation), tests incrementally. Triggers (match by MEANING, in ANY language): "write a Farseer app", "modify the import script", "I need an app that…".
5
+ metadata:
6
+ version: "1"
7
+ domain: modeling
8
+ ---
9
+
10
+ # Write or Modify a Farseer App
11
+
12
+ ## When this skill applies
13
+
14
+ Use for any TypeScript app using the `farseer-client` SDK. A **new recurring import** is not an app: build it as a Simple Pipeline with [`farseer-build-pipeline`](../farseer-build-pipeline/SKILL.md); existing import apps are maintained here. Do not use for model changes or for one-off SQL / data investigations.
15
+
16
+ ## Inputs to gather first
17
+
18
+ 1. **Farseer CLI logged in** — confirm with `farseer whoami`
19
+ 2. **Explicit-tenant reads work** — `farseer model --tables <tenant>` returns data (MCP `farseer_*` last resort only)
20
+ 3. **Target tenant** — the tenant the user names (e.g. `acme-dev`)
21
+ 4. **App purpose** — import / export / transform / report — and what data it touches
22
+ 5. **SDK pin** — a new app installs `"farseer-client": "npm:@farseerdev/farseer-client@1.18.1"`. If an existing app's `package.json` points `farseer-client` at a `storage.googleapis.com` tarball or at `"*"`, fix that first: [the npm move](farseer-client-release-notes.md#an-existing-app-still-on-the-bucket-or-on---fixing-it)
23
+ 6. **Reference docs:**
24
+ - [`working-patterns.md`](working-patterns.md) — canonical SDK patterns
25
+ - [`assignments.md`](assignments.md) — data-entry Assignments + labels (per-market rollouts, approver flows)
26
+ - [`farseer-client-api-guide.md`](farseer-client-api-guide.md) — full team guide
27
+ - [`app-authentication.md`](../farseer-authenticate-to-tenant/app-authentication.md) — auth model
28
+ - Existing apps in the same project for style
29
+
30
+ ## Procedure
31
+
32
+ ### 1. Inspect the current model (explicit-tenant CLI)
33
+ - `farseer model --variables <tenant>` — find target variables
34
+ - `farseer model --variable "<Var>" <tenant>` — get dimensions for each
35
+ - `farseer model --tables <tenant>` — confirm dimension structure + master data tables
36
+ - `farseer model --table "<Dim>" <tenant>` — one dim's members (incl. system dims)
37
+
38
+ ### 2. Design the app
39
+ - What inputs does it read (file / variable export / external API)?
40
+ - What transformations apply?
41
+ - What outputs (variable import / file / data quality report)?
42
+ - Idempotency: what does re-running it do?
43
+
44
+ ### 3. Follow SDK conventions
45
+
46
+ - **Auth — resolve it silently, in this order. Never ask the user "OAuth or API key?"**
47
+
48
+ 1. **Environment first.** `TENANT_ID` set → the app runs under a runner (the tenant's job runner, `farseer run`, `farseer run-script`) → `new FarseerClient()` with **no arguments**; the SDK reads `TENANT_ID` / `FARSEER_URL` / the credential from the environment. Read the tenant from `TENANT_ID` — **no runner sets `FARSEER_TENANT`**.
49
+ 2. **Not set → throw**, naming where you looked. No literal tenant default (not even `?? "<dev-tenant>"`), no prompt. On a laptop, run the app through `farseer run` or `farseer run-script`, which set that environment.
50
+
51
+ **Mismatch guard:** if two or more sources name a tenant (env `TENANT_ID`, a requested/confirm tenant, a config file's tenant) and they differ → throw before the first read or write; after constructing the client, print the tenant it is bound to, not the one the code meant.
52
+
53
+ The convention is **optimistic**: take the first source that resolves, transparently, and say nothing about it. Surface a problem **only if none resolves** or the guard fires. Presenting the choice to the user is a **regression** — the user has no basis on which to pick an auth mechanism, and being asked reads as the tooling not knowing its own conventions. Never hand-edit a `.env` for Farseer credentials, and never commit a key. Auth model: [`app-authentication.md`](../farseer-authenticate-to-tenant/app-authentication.md).
54
+ - **Catch block** — Farseer errors carry their message in a lazy `.text()`. Every `main().catch(...)` must call `await error.text()` when present.
55
+ - **Model export** — exclude `CELL` from whole-model exports: `types: ["DTAB", "DMEM", "VAR"] as any`. Including `CELL` fails with "Invalid string length".
56
+ - **Validation before mutation** — every write app first calls `exportModel()` and confirms target variables and dimensions exist with the expected shape. Fail loudly rather than silently create the wrong thing.
57
+ - **Import jobs** — column order in `columns` must match `addRow([...])` order. Use a named `toRow(record): unknown[]` helper. For a **recurring, audited data load** (locked `IMPORT_` targets, scope-encoding labels, idempotent revert-then-commit re-runs), don't hand-roll it here — use the [`farseer-author-import-job`](../farseer-author-import-job/SKILL.md) skill.
58
+ - **Dimension discrimination** — when one source column targets a specific dimension member, use `{ type: "VARIABLE", variableName, dimensionsNames: [{ tableName: "Dim", memberName: "Member" }] }`.
59
+ - **Name matching is case-sensitive** — including spaces, ` IN`/` OUT` suffixes, special characters.
60
+ - **Logging** — structured, step-based.
61
+ - **Dry-run** — support `DRY_RUN=true` to preview without committing. Honour it
62
+ only as the literal `true`/`false`; anything else stays in preview. Print the
63
+ resolved mode before the first write.
64
+ - **Manifest arguments are read BY NAME** from the `FARSEER_ARGS` JSON blob, with the 4-line reader in
65
+ [`deploying-a-farseer-app.md`](../farseer-author-import-job/deploying-a-farseer-app.md#1b-never-read-a-manifest-argument-by-position)
66
+ carried in the app's own files (a tenant app can import only `farseer-client`
67
+ and its own scripts, the ones `farseer app show` lists),
68
+ never off
69
+ `process.argv` by position; fall back only to env vars named after the
70
+ manifest's declared arguments, so the env-var fallback
71
+ cannot sweep credentials out of the environment (`run-script` itself passes
72
+ no arguments; local `farseer run` passes positional argv only — the full
73
+ contract is in [`deploying-a-farseer-app.md`](../farseer-author-import-job/deploying-a-farseer-app.md) "App arguments end to end"). `farseer run` drops an empty optional argument
74
+ from argv instead of passing `""`, so positional reads shift silently — a
75
+ 2026-09-20 field report has an explicit `DRY_RUN=false` landing in a
76
+ threshold slot, the app previewing instead of writing, and no diagnostic
77
+ anywhere. Optional arguments go last; names are plain identifiers (no
78
+ spaces, parentheses or `=` — such a name is never passed, silently).
79
+
80
+ ### 4. Write the code
81
+
82
+ **File layout**:
83
+ - `app.ts` — main code
84
+ - `README.md` — purpose, inputs, outputs, how to run
85
+ - Optional: helpers, types, tests
86
+
87
+ ### 5. Test incrementally
88
+ After the user gives the go-ahead:
89
+ - 10 rows → 100 → 1000 → full dataset
90
+ - `DRY_RUN=true` first
91
+ - `npx tsx app.ts` to run
92
+ - **Definition of done for an app with arguments: one run from the platform
93
+ UI** after deploy, with non-default values (one containing a space), and
94
+ check the arguments it prints. Local runs (`run-script`, `farseer run`) and a
95
+ no-argument schedule never build `FARSEER_ARGS`, so they cannot catch an
96
+ argument-read bug — three production incidents passed them. Locally,
97
+ export the blob yourself — `FARSEER_ARGS='{"Year":"2026"}' farseer run
98
+ <tenant> "<App>"` reaches the script byte-identical (measured 2026-10-15); spell out
99
+ every argument (nothing fills defaults locally) and never send `""`.
100
+ - Entrypoint name unique on the tenant; after the first deploy, `farseer app
101
+ show` must mark it ▶ and list only the app's own scripts.
102
+
103
+ ### 6. Push only after explicit confirmation
104
+
105
+ Push to a Farseer tenant only after the user explicitly confirms the push.
106
+
107
+ Mechanics worth flagging:
108
+ - `farseer push` is for tenant-hosted apps.
109
+ - Remote jobs require running the matching `upload*.ts` script — a local edit to `remoteJob*.ts` is not enough.
110
+
111
+ ## Tools to invoke
112
+
113
+ - `Bash` for explicit-tenant reads: `farseer model --variables` / `--variable "<Var>"` / `--tables` / `--table "<Dim>"` (+ `<tenant>`), `farseer app list --details` (MCP `farseer_*` last resort only)
114
+ - `Read` on [`working-patterns.md`](working-patterns.md) (mandatory before writing)
115
+ - `Read` on existing apps in the project for style consistency
116
+ - `Bash` to run `npx tsx`, `farseer run`, `farseer push`
117
+ - Check `node_modules/farseer-client/dist/generated/apis/` for SDK methods you're not sure exist
118
+
119
+ ## Expected output
120
+
121
+ - The app code (`app.ts` and helpers)
122
+ - README documenting purpose, inputs, outputs, run instructions
123
+ - Explicit request for user confirmation before any push / write operation
124
+
125
+ ## Constraints
126
+
127
+ - Do **not** push or run destructive operations without explicit user confirmation.
128
+ - Do **not** guess SDK method names — check `node_modules/farseer-client/dist/generated/apis/` or the team guide.
129
+ - Do **not** commit hard-coded credentials or a hard-coded tenant. Auth resolves from the env vars — see the Auth bullet in step 3.
130
+ - Do **not** ask the user which auth path to use. Resolve it silently; only speak up if nothing resolves or the tenant mismatch guard fires.
131
+ - Do **not** include real data in `app.ts` for testing.
@@ -0,0 +1,185 @@
1
+ # Assignments via the Farseer Client SDK
2
+
3
+ Reference for creating **Assignments** programmatically — structured data-entry tasks that grant a user or user group entry access to a sheet, with an approver, a time interval, and a version scope. Typical use: a per-market / per-entity planning rollout where each market's sheets are duplicated, filtered, shared with the market's user group, and assigned for data entry (see §8).
4
+
5
+ Verified live against a dev tenant on 2026-07-21 with `farseer-client` 1.4.5 (surface identical in 1.8.4). Each claim below is tagged **[live]** (executed against the API) or **[types]** (read from the generated OpenAPI `.d.ts` — trustworthy for shape, not behaviour).
6
+
7
+ > **TL;DR — four things the OpenAPI types don't tell you:**
8
+ >
9
+ > 1. **`useRestrictions: false` is rejected** with a cryptic 400 (`"Share id N is not an assignment…"`) — on `create` *and* on a later `update`. If you don't want time restrictions, you still must send `useRestrictions: true` and simply make the interval as wide as the planning horizon. **[live]**
10
+ > 2. There is **no `Draft` status**. `AssignmentStatus` is `Shared | InProgress | Submitted | Approved | Archived`. Create with `Shared` (immediately visible to the assignee) — older internal notes mentioning `Draft` are wrong. **[live + types]**
11
+ > 3. `itemNodeId` is the **folder item** id of the sheet (from `folders.search` / `getFolderItem`), **not** the sheet id. The folder item's `reference` field holds the sheet id — don't confuse the two. **[live]**
12
+ > 4. A failed `create` is **not atomic** — the error `"Share id N is not an assignment"` means the server already created a plain `DATA_ENTRY` **share** (with `restrictions.active: false`) before the assignment-layer validation failed. The dangling share stays on the sheet; clean it up with `client.shares.deleteBatch({ ids: [N] })` — see §7. Prefer validating inputs up front over create-and-retry loops. **[live]**
13
+
14
+ ---
15
+
16
+ ## 1. Concept
17
+
18
+ An Assignment defines:
19
+
20
+ | What | Field | Notes |
21
+ |---|---|---|
22
+ | Who enters data | `assignee` | `USER`, `USER_GROUP`, or `PUBLIC_KEY` (external link) |
23
+ | Who approves | `approver` | `USER` or `USER_GROUP` |
24
+ | Which sheet | `itemNodeId` | folder item id — see TL;DR #3 |
25
+ | Which period | `data.intervalStart/End` | `M/YYYY`, no leading zero — `'1/2026'`, `'12/2026'` |
26
+ | Which version(s) | `data.versionIds` | DMEM ids from the `Versions` dim table |
27
+ | Categorisation | `labelIds` | labels must exist first — §2 |
28
+ | Auto-expiry | `expirationTime` | JS `Date` |
29
+ | Visibility | `status` | create with `AssignmentStatus.Shared` |
30
+
31
+ The client accessors are `client.assignments` (`AssignmentsApi`) and `client.assignmentLabels` (`AssignmentLabelsApi`). Full method surface **[types]**:
32
+
33
+ - `assignments`: `create`, `createBatch`, `get`, `getByPublicKey`, `search`, `update`, `updateBatch`, `submit`, `approve`, `reject`, `archive`, `remove`, `removeBatch`, `getStats`, `regeneratePublicKeys`
34
+ - `assignmentLabels`: `create`, `createBatch`, `findAll`, `get`, `getBatch`, `update`, `updateBatch`, `remove`, `removeBatch`
35
+
36
+ ## 2. Labels — create before you attach **[live]**
37
+
38
+ Labels are name+colour tags used to filter the Assignments view. They must exist before an assignment references them; `findAll` + create-if-missing keeps this idempotent:
39
+
40
+ ```ts
41
+ const allLabels = await client.assignmentLabels.findAll();
42
+ let label = allLabels.find(l => l.name === 'North');
43
+ if (!label) {
44
+ label = await client.assignmentLabels.create({ name: 'North', hexColor: '#3A86FF' });
45
+ }
46
+ ```
47
+
48
+ In a market rollout you typically want two label axes: one label per market ("North", "South", …) and one per sheet type ("Sales", "Promotion", "Market OPEX", …), and attach one of each to every assignment.
49
+
50
+ ## 3. Resolving the prerequisite IDs **[live]**
51
+
52
+ ```ts
53
+ // assignee group + approver user
54
+ const groups = await client.userGroups.list();
55
+ const group = groups.find(g => g.name === 'North');
56
+
57
+ const users = await client.users.list();
58
+ const approver = users.find(u => u.email === 'approver@company.com');
59
+
60
+ // version DMEM id
61
+ const version = await client.getDimensionMember('Versions', 'Plan');
62
+
63
+ // folder item of the target sheet — NOT the sheet id
64
+ const [sheetItem] = await client.folders.search({
65
+ name: 'Market Sales plan', // `name` is required on SearchFolderRequest
66
+ types: [farseer.FolderItemType.Sheet],
67
+ limit: 1,
68
+ });
69
+ // sheetItem.id → itemNodeId; sheetItem.reference → the sheet id (for sheets.get)
70
+ ```
71
+
72
+ `folders.search` with `name: ''` lists all items of the given types — handy for discovery. `client.getFolderItem(folderId, name)` is the alternative when you already hold the parent folder.
73
+
74
+ ## 4. Creating an assignment **[live]**
75
+
76
+ ```ts
77
+ await client.assignments.create({
78
+ name: `North - Market Sales plan`,
79
+ assignee: { type: 'USER_GROUP', userGroupId: group.id }, // or { type: 'USER', userId }
80
+ approver: { type: 'USER', userId: approver.id }, // or { type: 'USER_GROUP', userGroupId }
81
+ itemNodeId: sheetItem.id,
82
+ data: {
83
+ type: 'SHEET',
84
+ createdCellCount: 0, // always 0 on creation
85
+ intervalStart: '1/2026', // M/YYYY, no leading zero
86
+ intervalEnd: '12/2026',
87
+ versionIds: [version.id],
88
+ useRestrictions: true, // MUST be true — see TL;DR #1
89
+ },
90
+ labelIds: [marketLabel.id, typeLabel.id], // [] is fine
91
+ expirationTime: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000),
92
+ status: farseer.AssignmentStatus.Shared,
93
+ });
94
+ ```
95
+
96
+ Both assignee shapes verified live (`USER` and `USER_GROUP`). Two representation quirks to expect in the response **[live]**:
97
+
98
+ - the echoed `assignee` on a `USER_GROUP` create can come back as `{ type: 'PUBLIC_KEY', publicKey: '<uuid>' }` — every assignment carries a public key; don't treat the echoed type as a validation of what you sent;
99
+ - `data.allowEntryOnPropertyColumns?: boolean` exists as an optional extra **[types]**.
100
+
101
+ For bulk rollouts use `createBatch(requests[])` — same request shape, array in/out **[types]**.
102
+
103
+ ## 5. Reading back — `get` and `search` **[live for get; types for search shape]**
104
+
105
+ ```ts
106
+ const a = await client.assignments.get(assignmentId);
107
+
108
+ const res = await client.assignments.search({
109
+ pageIndex: 0,
110
+ pageSize: 50,
111
+ groupBy: farseer.AssignmentGroupingOption.None, // None | Assignee | Approver | Status | Label
112
+ // optional filters:
113
+ nameSearch: 'North',
114
+ itemNodeIds: [sheetItem.id],
115
+ assignmentLabelIds: [label.id],
116
+ statuses: [farseer.AssignmentStatus.Shared],
117
+ });
118
+ const assignments = (res.groups ?? []).flatMap(g => g.items ?? []);
119
+ ```
120
+
121
+ The grouped response nests results under `groups[].items` (not `groups[].assignments`); with `groupBy: None` there is a single group.
122
+
123
+ ## 6. Update and lifecycle
124
+
125
+ `update` takes the **full** request back (no PATCH semantics) — fetch, spread, override **[live]**:
126
+
127
+ ```ts
128
+ const cur = await client.assignments.get(id);
129
+ await client.assignments.update(id, {
130
+ name: cur.name,
131
+ assignee: cur.assignee,
132
+ approver: cur.approver,
133
+ data: { ...cur.data, intervalEnd: '12/2027' },
134
+ labelIds: cur.labelIds,
135
+ expirationTime: cur.expirationTime,
136
+ status: cur.status,
137
+ });
138
+ ```
139
+
140
+ Lifecycle verbs `submit(id)` → `reject(id)` / `approve(id)`, plus `archive(id)` and `remove(id)` **[types; remove live]**. Status flow: `Shared → InProgress → Submitted → Approved/rejected-back`, `Archived` for retirement.
141
+
142
+ ⚠️ Caution: in our live probe, calling `submit` via an API key on a group-assigned assignment returned the same `"Share id N is not an assignment"` 400 — the submit/approve verbs appear to be meant for the assignee/approver session flow, not for admin scripts. Treat scripted submit/approve as unverified; test on a dev tenant before relying on it.
143
+
144
+ ## 7. Cleanup / teardown **[live]**
145
+
146
+ `assignments.remove(id)` and `assignmentLabels.remove(id)` both hard-delete. Our teardown removed assignments first, then labels — that order is verified; removing a still-attached label was not tested.
147
+
148
+ **Dangling shares from failed creates** (TL;DR #4) don't show up in `assignments.search` — they're plain shares. Inspect and delete them via the shares API **[live]**:
149
+
150
+ ```ts
151
+ const s = await client.shares.getSingle(shareId); // 404 once gone
152
+ // s: { id, active, type: 'DATA_ENTRY', itemNode: {...}, restrictions: { active: false, ... }, ... }
153
+ await client.shares.deleteBatch({ ids: [134, 136] }); // HTTP DELETE /shares/mutateBatch → 204
154
+ ```
155
+
156
+ This also reveals what an Assignment *is* under the hood: a `DATA_ENTRY` share whose restrictions/status/expiration/metadata are all active — which is exactly why the server rejects `useRestrictions: false` (TL;DR #1) instead of storing a restriction-less assignment.
157
+
158
+ ## 8. The full rollout pattern
159
+
160
+ The full pattern automates, per market:
161
+
162
+ 1. Duplicate a template folder of planning sheets (`sheets.duplicate` into a new `folders.create`).
163
+ 2. Rewrite each copy's row filters so it's pre-filtered to the market / company / market-type (`sheets.get` → mutate `rows.filters[].dimensionIds` → `sheets.update`).
164
+ 3. Share the new folder hierarchy with the market's user group (`folders.shareHierarchy` + `userGroups.addPermissions` with `ENTITY.ITEM_NODE.VIEW` on ancestor folders so the group can navigate down).
165
+ 4. Create one assignment per sheet: assignee = market group, approver = the owner of the plan, labels = market + sheet type, interval = the planning year.
166
+
167
+ Flow summary:
168
+
169
+ ```text
170
+ assignmentLabels.findAll / create → labels exist
171
+ users.list / userGroups.list → approver + assignee ids
172
+ getDimensionMember('Versions', name) → version id
173
+ folders.search (type Sheet) → itemNodeId
174
+ assignments.create / createBatch → the assignment
175
+ assignments.search → verify / monitor
176
+ assignments.remove → teardown
177
+ ```
178
+
179
+ ## 9. Errors seen live
180
+
181
+ | Symptom | Cause |
182
+ |---|---|
183
+ | 400 `"Share id N is not an assignment - it needs to have status, expiration time, restrictions and assignment metadata"` on create/update | `useRestrictions: false` — send `true` (TL;DR #1). On create this also leaves a dangling share id N — remove it via `shares.deleteBatch` (§7) |
184
+ | Same 400 on `submit`/`approve` from a script | admin API-key session driving the assignee/approver flow — see §6 caution |
185
+ | Generic 400 on `folders.search` | missing `name` — it's required; use `''` to match all |