farseer-cli 1.18.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.
- package/README.md +33 -10
- package/dist/commands/app.js +42 -3
- package/dist/commands/app.js.map +1 -2
- package/dist/commands/apps.js.map +0 -1
- package/dist/commands/cells.js +120 -85
- package/dist/commands/cells.js.map +1 -2
- package/dist/commands/code.js.map +0 -1
- package/dist/commands/config.js.map +0 -1
- package/dist/commands/dashboards.js +246 -12
- package/dist/commands/dashboards.js.map +1 -2
- package/dist/commands/diff.js.map +0 -1
- package/dist/commands/dimensions.js +52 -27
- package/dist/commands/dimensions.js.map +1 -2
- package/dist/commands/docs.js +82 -0
- package/dist/commands/docs.js.map +6 -0
- package/dist/commands/files.js +49 -0
- package/dist/commands/files.js.map +2 -3
- package/dist/commands/folders.js +76 -0
- package/dist/commands/folders.js.map +6 -0
- package/dist/commands/formula.js +38 -30
- package/dist/commands/formula.js.map +1 -2
- package/dist/commands/install.js +32 -30
- package/dist/commands/install.js.map +2 -3
- package/dist/commands/list.js.map +0 -1
- package/dist/commands/login.js +3 -3
- package/dist/commands/login.js.map +1 -2
- package/dist/commands/logout.js.map +0 -1
- package/dist/commands/mcp-server.js.map +0 -1
- package/dist/commands/model.js +30 -5
- package/dist/commands/model.js.map +2 -3
- package/dist/commands/pipeline.js.map +0 -1
- package/dist/commands/pull.js +1 -1
- package/dist/commands/pull.js.map +1 -2
- package/dist/commands/push.js +6 -4
- package/dist/commands/push.js.map +1 -2
- package/dist/commands/refresh.js.map +0 -1
- package/dist/commands/run.js.map +0 -1
- package/dist/commands/sheets.js +289 -52
- package/dist/commands/sheets.js.map +1 -2
- package/dist/commands/skills.js +157 -0
- package/dist/commands/skills.js.map +6 -0
- package/dist/commands/status.js.map +0 -1
- package/dist/commands/tool.js.map +0 -1
- package/dist/commands/variables.js +246 -82
- package/dist/commands/variables.js.map +1 -2
- package/dist/commands/whoami.js.map +0 -1
- package/dist/index.js +117 -23
- package/dist/index.js.map +1 -2
- package/dist/mcp/index.js.map +0 -1
- package/dist/mcp/prompts/workflows.js.map +0 -1
- package/dist/mcp/resources/documentation.js +19 -12
- package/dist/mcp/resources/documentation.js.map +1 -2
- package/dist/mcp/server.js.map +0 -1
- package/dist/mcp/skills.js.map +0 -1
- package/dist/mcp/tools/appTools.js +1 -7
- package/dist/mcp/tools/appTools.js.map +1 -2
- package/dist/mcp/tools/authTools.js +1 -1
- package/dist/mcp/tools/authTools.js.map +1 -2
- package/dist/mcp/tools/cellTools.js +6 -19
- package/dist/mcp/tools/cellTools.js.map +1 -2
- package/dist/mcp/tools/dashboardTools.js +30 -412
- package/dist/mcp/tools/dashboardTools.js.map +2 -3
- package/dist/mcp/tools/dataTools.js +15 -146
- package/dist/mcp/tools/dataTools.js.map +1 -2
- package/dist/mcp/tools/folderTools.js +12 -78
- package/dist/mcp/tools/folderTools.js.map +1 -2
- package/dist/mcp/tools/modelTools.js +23 -372
- package/dist/mcp/tools/modelTools.js.map +1 -2
- package/dist/mcp/tools/pipelineContract.js +5 -1
- package/dist/mcp/tools/pipelineContract.js.map +1 -2
- package/dist/mcp/tools/pipelineTools.js.map +0 -1
- package/dist/mcp/tools/runTools.js +8 -69
- package/dist/mcp/tools/runTools.js.map +1 -2
- package/dist/mcp/tools/sheetTools.js +14 -264
- package/dist/mcp/tools/sheetTools.js.map +1 -2
- package/dist/mcp/tools/syncTools.js +7 -3
- package/dist/mcp/tools/syncTools.js.map +1 -2
- package/dist/mcp/utils/helpers.js.map +0 -1
- package/dist/mcp/utils/launchPin.js.map +0 -1
- package/dist/mcp/utils/operationResponse.js +41 -0
- package/dist/mcp/utils/operationResponse.js.map +6 -0
- package/dist/mcp/utils/registerTool.js.map +0 -1
- package/dist/mcp/utils/session.js.map +0 -1
- package/dist/mcp/utils/tenantPin.js.map +0 -1
- package/dist/operations/cells.js +444 -0
- package/dist/operations/cells.js.map +6 -0
- package/dist/operations/dashboards.js +357 -0
- package/dist/operations/dashboards.js.map +6 -0
- package/dist/operations/data.js +206 -0
- package/dist/operations/data.js.map +6 -0
- package/dist/operations/errors.js +64 -0
- package/dist/operations/errors.js.map +6 -0
- package/dist/operations/exportModel.js +59 -0
- package/dist/operations/exportModel.js.map +6 -0
- package/dist/operations/folderPath.js +128 -0
- package/dist/operations/folderPath.js.map +6 -0
- package/dist/operations/folders.js +80 -0
- package/dist/operations/folders.js.map +6 -0
- package/dist/operations/install.js +109 -0
- package/dist/operations/install.js.map +6 -0
- package/dist/operations/model.js +271 -0
- package/dist/operations/model.js.map +6 -0
- package/dist/operations/sheets.js +428 -0
- package/dist/operations/sheets.js.map +6 -0
- package/dist/pipeline/compatibility.js.map +0 -1
- package/dist/pipeline/connect.js.map +0 -1
- package/dist/pipeline/create.js.map +0 -1
- package/dist/pipeline/errors.js.map +0 -1
- package/dist/pipeline/failStep.js +43 -0
- package/dist/pipeline/failStep.js.map +6 -0
- package/dist/pipeline/generated-reference.json +25 -13
- package/dist/pipeline/guide.js.map +0 -1
- package/dist/pipeline/init.js.map +0 -1
- package/dist/pipeline/operations.js.map +0 -1
- package/dist/pipeline/query.js.map +0 -1
- package/dist/pipeline/queryDownloads.js.map +0 -1
- package/dist/pipeline/queryWorker.js +3 -1
- package/dist/pipeline/queryWorker.js.map +1 -2
- package/dist/pipeline/readiness.js.map +0 -1
- package/dist/pipeline/reference.js.map +0 -1
- package/dist/pipeline/requests.js +3 -32
- package/dist/pipeline/requests.js.map +1 -2
- package/dist/pipeline/runArguments.js.map +0 -1
- package/dist/pipeline/runtime.js.map +0 -1
- package/dist/pipeline/service.js +46 -2
- package/dist/pipeline/service.js.map +1 -2
- package/dist/services/appSyncService.js +59 -9
- package/dist/services/appSyncService.js.map +1 -2
- package/dist/services/apps.js +10 -0
- package/dist/services/apps.js.map +1 -2
- package/dist/services/authErrors.js.map +0 -1
- package/dist/services/codefirst/api.js +38 -5
- package/dist/services/codefirst/api.js.map +1 -2
- package/dist/services/codefirst/binaryDisk.js.map +0 -1
- package/dist/services/codefirst/byteHashes.js +5 -0
- package/dist/services/codefirst/byteHashes.js.map +1 -2
- package/dist/services/codefirst/documents.js +41 -15
- package/dist/services/codefirst/documents.js.map +1 -2
- package/dist/services/codefirst/layoutBinaryProjection.js +24 -13
- package/dist/services/codefirst/layoutBinaryProjection.js.map +1 -2
- package/dist/services/codefirst/layoutCompose.js +44 -38
- package/dist/services/codefirst/layoutCompose.js.map +1 -2
- package/dist/services/codefirst/layoutCore.js +14 -1
- package/dist/services/codefirst/layoutCore.js.map +1 -2
- package/dist/services/codefirst/layoutPaths.js +80 -4
- package/dist/services/codefirst/layoutPaths.js.map +1 -2
- package/dist/services/codefirst/layoutProjection.js +73 -39
- package/dist/services/codefirst/layoutProjection.js.map +1 -2
- package/dist/services/codefirst/layoutReadback.js +357 -130
- package/dist/services/codefirst/layoutReadback.js.map +2 -3
- package/dist/services/codefirst/layoutReadbackPlacement.js +94 -57
- package/dist/services/codefirst/layoutReadbackPlacement.js.map +2 -3
- package/dist/services/codefirst/layoutReceipt.js +283 -243
- package/dist/services/codefirst/layoutReceipt.js.map +2 -3
- package/dist/services/codefirst/layoutScan.js +208 -110
- package/dist/services/codefirst/layoutScan.js.map +1 -2
- package/dist/services/codefirst/output.js +76 -10
- package/dist/services/codefirst/output.js.map +1 -2
- package/dist/services/codefirst/types.js.map +0 -1
- package/dist/services/codefirst/workflow.js +65 -29
- package/dist/services/codefirst/workflow.js.map +2 -3
- package/dist/services/codefirst/workspace.js.map +0 -1
- package/dist/services/codefirst/workspaceLock.js.map +0 -1
- package/dist/services/codefirst/workspaceRoot.js +2 -1
- package/dist/services/codefirst/workspaceRoot.js.map +1 -2
- package/dist/services/configService.js.map +0 -1
- package/dist/services/credentials.js.map +0 -1
- package/dist/services/farseerService.js +31 -7
- package/dist/services/farseerService.js.map +1 -2
- package/dist/services/httpError.js.map +0 -1
- package/dist/services/modelExport.js.map +0 -1
- package/dist/services/organisation.js.map +0 -1
- package/dist/services/preflight.js.map +0 -1
- package/dist/services/realms.js.map +0 -1
- package/dist/services/syncService.js +3 -3
- package/dist/services/syncService.js.map +1 -2
- package/dist/skills/bundled.js +106 -0
- package/dist/skills/bundled.js.map +6 -0
- package/dist/skills/install.js +257 -0
- package/dist/skills/install.js.map +6 -0
- package/dist/skills/pipeline.js +10 -18
- package/dist/skills/pipeline.js.map +1 -2
- package/dist/utils/agentSandbox.js +1 -1
- package/dist/utils/agentSandbox.js.map +0 -1
- package/dist/utils/cliOptions.js.map +0 -1
- package/dist/utils/constants.js.map +0 -1
- package/dist/utils/entityResolver.js +72 -25
- package/dist/utils/entityResolver.js.map +1 -2
- package/dist/utils/errorFormatter.js +72 -11
- package/dist/utils/errorFormatter.js.map +1 -2
- package/dist/utils/fileLogger.js.map +0 -1
- package/dist/utils/fileValidation.js.map +0 -1
- package/dist/utils/folderMatch.js.map +0 -1
- package/dist/utils/formulaFilters.js +11 -2
- package/dist/utils/formulaFilters.js.map +1 -2
- package/dist/utils/helpers.js.map +0 -1
- package/dist/utils/logger.js.map +0 -1
- package/dist/utils/nameResolver.js.map +0 -1
- package/dist/utils/operationCli.js +102 -0
- package/dist/utils/operationCli.js.map +6 -0
- package/dist/utils/packageManager.js.map +0 -1
- package/dist/utils/syncReporting.js.map +0 -1
- package/dist/utils/syncScope.js.map +0 -1
- package/dist/utils/updateCheck.js.map +0 -1
- package/dist/utils/variableValues.js.map +0 -1
- package/dist/utils/workspace.js.map +0 -1
- package/docs/cli-guide.md +182 -2
- package/docs/import-workflows.md +14 -14
- package/docs/new-app-template.md +1 -1
- package/docs/pipeline-client-guide.md +1 -1
- package/docs/pipeline-reference.md +304 -9
- package/docs/troubleshooting.md +18 -0
- package/package.json +2 -2
- package/skills/farseer-analysis/SKILL.md +132 -0
- package/skills/farseer-app-dev/SKILL.md +131 -0
- package/skills/farseer-app-dev/assignments.md +185 -0
- package/skills/farseer-app-dev/farseer-client-api-guide.md +907 -0
- package/skills/farseer-app-dev/farseer-client-release-notes.md +212 -0
- package/skills/farseer-app-dev/working-patterns.md +876 -0
- package/skills/farseer-authenticate-to-tenant/SKILL.md +60 -0
- package/skills/farseer-authenticate-to-tenant/app-authentication.md +91 -0
- package/skills/farseer-author-import-job/SKILL.md +114 -0
- package/skills/farseer-author-import-job/cell-writes.md +530 -0
- package/skills/farseer-author-import-job/deploying-a-farseer-app.md +383 -0
- package/skills/farseer-author-import-job/import-job-pattern.md +232 -0
- package/skills/farseer-build-model/SKILL.md +122 -0
- package/skills/farseer-build-model/formula-grain-alignment.md +612 -0
- package/skills/farseer-build-model/naming-conventions.md +435 -0
- package/skills/farseer-build-model/sparse-formulas-pattern.md +330 -0
- package/skills/farseer-build-pipeline/SKILL.md +190 -0
- package/skills/farseer-build-pipeline/erp-sales/README.md +108 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines.yaml +23 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_invoice_lines_raw.yaml +23 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map.yaml +17 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/bronze/erp_sales_item_product_map_raw.yaml +11 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/gold/erp_sales_cells.yaml +40 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_lines.yaml +35 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_recon.yaml +43 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/Models/silver/erp_sales_unmapped_items.yaml +28 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-etl/main.py +49 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells.yaml +17 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/in/erp_sales_cells_raw.yaml +14 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/Models/load/erp_sales_to_model.yaml +47 -0
- package/skills/farseer-build-pipeline/erp-sales/erp-sales-load/main.py +44 -0
- package/skills/farseer-build-pipeline/erp-sales/item_to_product.csv +5 -0
- package/skills/farseer-build-pipeline/pipeline-app-failure-report-pattern.md +103 -0
- package/skills/farseer-build-pipeline/pipeline-source-encoding.md +68 -0
- package/skills/farseer-dashboards/SKILL.md +40 -0
- package/skills/farseer-formulas/SKILL.md +165 -0
- package/skills/farseer-help-center/SKILL.md +66 -0
- package/skills/farseer-model/SKILL.md +119 -0
- package/skills/farseer-modify-model/SKILL.md +158 -0
- package/skills/farseer-modify-model/model-validation-pattern.md +251 -0
- package/skills/farseer-optimize-model/SKILL.md +314 -0
- package/skills/farseer-optimize-model/stats-dump.ts +139 -0
- package/skills/farseer-pnl/SKILL.md +220 -0
- package/skills/farseer-review-model/SKILL.md +172 -0
- package/skills/farseer-run-apps/SKILL.md +102 -0
- package/skills/pipeline-authoring/SKILL.md +7 -5
- package/skills/pipeline-authoring/practices.md +21 -8
- package/dist/services/agentApprovalFetch.js +0 -86
- package/dist/services/agentApprovalFetch.js.map +0 -7
|
@@ -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 |
|