Compare commits
146
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
24636c9a87 | ||
|
|
11f56cc54a | ||
|
|
2d31e5a8b9 | ||
|
|
cfd8f06435 | ||
|
|
a6a111db8a | ||
|
|
ca19dbaefb | ||
|
|
8418e0cb1d | ||
|
|
d301fc2b4d | ||
|
|
fbcde41321 | ||
|
|
53838036e6 | ||
|
|
b3b9755aa7 | ||
|
|
82a45b80b4 | ||
|
|
a8194d73e7 | ||
|
|
1dccf61f62 | ||
|
|
09f31ce6da | ||
|
|
90c937c32a | ||
|
|
d9bd46e97b | ||
|
|
55c38805d7 | ||
|
|
966dc072e0 | ||
|
|
81c725d10b | ||
|
|
34ff2ac8d0 | ||
|
|
1ad27d55f1 | ||
|
|
8fafeb7923 | ||
|
|
f797b1130a | ||
|
|
4137ebdf6b | ||
|
|
3380150d1c | ||
|
|
2d7df66fc2 | ||
|
|
efd2e18c7b | ||
|
|
7da29bdb11 | ||
|
|
8f12fe74a6 | ||
|
|
f4325b2056 | ||
|
|
cc68c218d8 | ||
|
|
d3b881fa85 | ||
|
|
e139c37fbf | ||
|
|
c4123e5c96 | ||
|
|
1ed31f2a49 | ||
|
|
25434b35b9 | ||
|
|
490d0137b9 | ||
|
|
f25ecd8828 | ||
|
|
c180934167 | ||
|
|
6e2548d78c | ||
|
|
94d2a7970e | ||
|
|
c0af86ef29 | ||
|
|
34bd6607c5 | ||
|
|
e4b04b1d44 | ||
|
|
fed0396737 | ||
|
|
4f7b845390 | ||
|
|
13c10be30f | ||
|
|
8e51fde524 | ||
|
|
4db8d62dca | ||
|
|
5d03164b6a | ||
|
|
c0bc87d331 | ||
|
|
d59ef44226 | ||
|
|
f213d24f09 | ||
|
|
20ba633087 | ||
|
|
a80927cbb6 | ||
|
|
cc2ff873fa | ||
|
|
a104f78645 | ||
|
|
3b9344cb60 | ||
|
|
0082828543 | ||
|
|
3595bb9499 | ||
|
|
ee52bb8967 | ||
|
|
18a16fcb06 | ||
|
|
d72e19a308 | ||
|
|
2cc8489892 | ||
|
|
1b1937bad8 | ||
|
|
b7d31066ae | ||
|
|
1f4aa6fcea | ||
|
|
a7bb13c3ae | ||
|
|
69b41559f7 | ||
|
|
917925f553 | ||
|
|
12091c4044 | ||
|
|
e69df3deb2 | ||
|
|
d0d17995d3 | ||
|
|
92d0d91440 | ||
|
|
9dab3d50ef | ||
|
|
f7db8719f5 | ||
|
|
772a359da7 | ||
|
|
1031ea7ed7 | ||
|
|
2dfeb02faf | ||
|
|
9deccd072d | ||
|
|
9023eb2a39 | ||
|
|
72484ae844 | ||
|
|
003550b965 | ||
|
|
45226e19d6 | ||
|
|
df2027dab6 | ||
|
|
6527c10f26 | ||
|
|
bf54a589f5 | ||
|
|
36963aa746 | ||
|
|
9b2e0df2b0 | ||
|
|
023c29f00f | ||
|
|
59e9e96f5a | ||
|
|
067c08765b | ||
|
|
9cd976495b | ||
|
|
9f4b357108 | ||
|
|
8209c1cb49 | ||
|
|
e15f2c2a34 | ||
|
|
c0fec25c4d | ||
|
|
41680e2ecc | ||
|
|
20a007622c | ||
|
|
5615e6b0db | ||
|
|
dc0f6a7baa | ||
|
|
fabb9e5bfd | ||
|
|
d57ae03fc4 | ||
|
|
7c33839b99 | ||
|
|
26b55b1bde | ||
|
|
e5a5bf2144 | ||
|
|
76bb83d860 | ||
|
|
5a44b2804f | ||
|
|
daacb49c8a | ||
|
|
1807d66ea1 | ||
|
|
84cce5eb0f | ||
|
|
aa4b3b94cd | ||
|
|
72cae704df | ||
|
|
0815fcea2c | ||
|
|
c07a01a38d | ||
|
|
eea9fbd938 | ||
|
|
9a1b7d0f52 | ||
|
|
1e516f4012 | ||
|
|
d0a7561f1a | ||
|
|
07d586da52 | ||
|
|
93a513a15f | ||
|
|
3c9eba4df4 | ||
|
|
48d06ec6a7 | ||
|
|
ff8f10d533 | ||
|
|
7d6dc652be | ||
|
|
f9d061c489 | ||
|
|
4d1bfa6343 | ||
|
|
d841163dd0 | ||
|
|
44aac556b9 | ||
|
|
3bf3bf0dde | ||
|
|
a501903e6d | ||
|
|
b9e4b2733f | ||
|
|
24e6297187 | ||
|
|
257f69ccc6 | ||
|
|
b88b22684a | ||
|
|
a8237b2881 | ||
|
|
fc6c9f844f | ||
|
|
74c38e1641 | ||
|
|
28104f83e1 | ||
|
|
ea05f07180 | ||
|
|
acb97f4bfb | ||
|
|
bb808617f4 | ||
|
|
4a8c39b4c0 | ||
|
|
69cfccd565 | ||
|
|
cbea04c8e1 |
@@ -0,0 +1,147 @@
|
||||
# Bitemporal Dataloader — Technical Deep Dive
|
||||
|
||||
This document explains how the Data Controller backend loads staged data into target tables: the load-type dispatch, the internals of the `%bitemporal_dataloader` macro, and a detailed description of the REPLACE load type. For user-facing load type documentation, see [docs.datacontroller.io](https://docs.datacontroller.io/).
|
||||
|
||||
## Overview
|
||||
|
||||
Every table registered for loading has a current record in `&mpelib..MPE_TABLES` with a `LOADTYPE` (selectbox values are seeded in `mpe_makedata.sas`):
|
||||
|
||||
| LOADTYPE | Loader used | History kept |
|
||||
|---|---|---|
|
||||
| `UPDATE` | `%bitemporal_dataloader` (no temporal vars) | None — changed records are deleted and re-appended |
|
||||
| `REPLACE` | Inline code in `%mpe_targetloader` (does **not** use `%bitemporal_dataloader`) | None — entire table wiped and reloaded |
|
||||
| `TXTEMPORAL` | `%bitemporal_dataloader` (technical time only) | SCD2-style, technical (transaction) time |
|
||||
| `BITEMPORAL` | `%bitemporal_dataloader` (business + technical time) | Full two-dimensional history |
|
||||
| `FORMAT_CAT` | `%mp_loadformat` | Format catalog load (table suffix `-FC`) |
|
||||
|
||||
The relevant `MPE_TABLES` columns read by the loader are: `LOADTYPE`, `BUSKEY` (primary key, space-separated, excluding temporal columns), `VAR_TXFROM` / `VAR_TXTO` (technical validity), `VAR_BUSFROM` / `VAR_BUSTO` (business validity), `VAR_PROCESSED` (processed timestamp column), `RK_UNDERLYING` (retained-key generation), `CLOSE_VARS`, and `AUDIT_LIBDS` (defaults to `&dclib..MPE_AUDIT`).
|
||||
|
||||
## Request Flow
|
||||
|
||||
```mermaid
|
||||
flowchart TD
|
||||
A[User submits changeset\neditors/stagedata.sas] --> B[Staging package written to\n&mpelocapprovals/&LOAD_REF\nCSV + jsdata]
|
||||
B --> C[Approval workflow\nMPE_SUBMIT / MPE_REVIEW]
|
||||
C --> D{auditors/postdata.sas}
|
||||
D -->|action=SHOW_DIFFS| E["%mpe_targetloader(LOADTARGET=NO)\nbuilds work.outds_add / outds_mod / outds_del\nfor the diff screen only"]
|
||||
D -->|action=APPROVE_TABLE| F["%mpe_targetloader(LOADTARGET=YES)\nactual load"]
|
||||
E --> G[Diff CSV + TEMPDIFFS stored\nin approval package]
|
||||
F --> H{LOADTYPE from\nMPE_TABLES}
|
||||
H -->|UPDATE / TXTEMPORAL / BITEMPORAL| I["%bitemporal_dataloader"]
|
||||
H -->|FORMAT_CAT| J["%mp_loadformat"]
|
||||
H -->|REPLACE| K[Inline delete-all + append\nin %mpe_targetloader]
|
||||
```
|
||||
|
||||
`%mpe_targetloader` (`sas/sasjs/macros/mpe_targetloader.sas`) is the single dispatch point. It reads the current `MPE_TABLES` record (`&dc_dttmtfmt. lt tx_to`), aborts if the table is not registered (or has duplicate config records), and routes to the loader. Note the two-phase design: `LOADTARGET=NO` prepares the intermediate `outds_*` tables so the approver can review diffs; `LOADTARGET=YES` performs the destructive load. Both phases run the same preparation logic, so the reviewed diffs correspond to what is actually applied.
|
||||
|
||||
## The Temporal Model
|
||||
|
||||
Bitemporal tables carry two independent time dimensions:
|
||||
|
||||
* **Business time** (`bus_from` / `bus_to`) — when the fact was true in the real world. Present on **both** staging and base tables.
|
||||
* **Technical time** (`tech_from` / `tech_to`, a.k.a. transaction time) — when the record was known to the database. Present on the **base table only**; the loader stamps these itself.
|
||||
|
||||
All validity is expressed with **half-open intervals** (`from <= t < to`). Queries against bitemporal tables need two conditions and must not use `BETWEEN` or `from LE t LE to` (the latter excludes boundary records — see the macro header for background):
|
||||
|
||||
```sas
|
||||
where &bus_from le [tstamp] lt &bus_to
|
||||
and &tx_from le [tstamp] lt &tx_to
|
||||
```
|
||||
|
||||
"Current" records have `tech_to` set to the high date (`'31DEC9999:23:59:59'dt` when called from `%mpe_targetloader`). Closing out a record means setting `tech_to = now` — records are never physically deleted from a temporal table, they are superseded.
|
||||
|
||||
## Key Components
|
||||
|
||||
| Component | Location | Role |
|
||||
|---|---|---|
|
||||
| `%mpe_targetloader` | `sas/sasjs/macros/mpe_targetloader.sas` | Reads `MPE_TABLES` config and dispatches per LOADTYPE; implements REPLACE inline |
|
||||
| `%bitemporal_dataloader` | `sas/sasjs/macros/bitemporal_dataloader.sas` | Generic loader for UPDATE / TXTEMPORAL / BITEMPORAL |
|
||||
| `%bitemporal_closeouts` | `sas/sasjs/macros/bitemporal_closeouts.sas` | Closes out (sets `tech_to=now`) live records matching a key |
|
||||
| `%mp_retainedkey` | SASjs core | Generates retained (surrogate) keys when `RK_UNDERLYING` is configured |
|
||||
| `%mp_rowhash` | SASjs core | MD5 hash of non-temporal columns, used for change detection |
|
||||
| `%mp_storediffs` | SASjs core | Writes row-level audit records to `AUDIT_LIBDS` |
|
||||
| `MPE_DATALOADS` | `&dclib` | Load log (counts, duration, macro version, user) — written only by `%bitemporal_dataloader` |
|
||||
| `MPE_LOCKANYTABLE` | `&dclib` | Lock control table used by `%mp_lockanytable` |
|
||||
|
||||
## `%bitemporal_dataloader` Execution Flow
|
||||
|
||||
The macro builds a series of `work.bitemp*` intermediate tables, then applies the changes in two target-table operations (closeout, then append) under a single lock.
|
||||
|
||||
### 1. Pre-checks and setup
|
||||
|
||||
* Early return if the staging table is empty; hard abort if `&syscc > 0`.
|
||||
* `CLOSE_VARS` is not supported on REDSHIFT / POSTGRES / SNOWFLAKE engines (returns with a NOTE).
|
||||
* A zero-row snapshot of the base table (`&basecopy`) is taken with `data ... set base; stop;` — this doubles as a lock check, since metadata functions fail against a locked table.
|
||||
* `proc contents` on the base table feeds column lists. Columns are split into character and numeric lists for hashing (`%mp_rowhash` hashes the two types via separate arrays). Temporal columns, the processed column, and the delete-flag column are excluded from the hash.
|
||||
* Table names containing `___TMP___` or `_____` are rejected (they would collide with generated temp columns).
|
||||
|
||||
### 2. Locking
|
||||
|
||||
For `LOADTARGET=YES`, the base table (and audit table, if configured) is locked via `%mp_lockanytable` before any staging prep, because the load is a two-part update (closeouts + append) and must not interleave with another load.
|
||||
|
||||
### 3. Staging preparation (`work.bitemp0_append`)
|
||||
|
||||
* If `RK_UNDERLYING` is configured, `%mp_retainedkey` maps business keys to retained keys (filtering the base lookup to live records, `&now < tech_to`, for temporal types); otherwise the staging table is used as-is.
|
||||
* `bus_from` / `bus_to` overrides are applied if provided; the processed column is stamped with the load timestamp (`now`). Even with `processed=0`, a column literally named `PROCESSED_DTTM` on the base table is used if present.
|
||||
* The MD5 change-detection hash is computed for every staged record.
|
||||
* If the staging table contains the delete-flag column (`_____DELETE__THIS__RECORD_____`), rows flagged `"Yes"` are diverted to `&outds_del` and closed out via `%bitemporal_closeouts` (PK is taken as `bus_from` + business key). The remaining rows continue as `bitemp0_append`.
|
||||
|
||||
### 4. CLOSE_VARS closeout
|
||||
|
||||
When `CLOSE_VARS` (a subset of the PK) is supplied, live base records whose CLOSE_VARS values appear in staging but whose full PK does **not** are closed out. This handles "this group was fully reloaded, so anything missing was removed" semantics without reloading the whole table.
|
||||
|
||||
### 5. Uniqueness check
|
||||
|
||||
If `CHECK_UNIQUENESS=YES` (the default) or business-date overrides are in play, the staging table is sorted `nodupkey` by the PK; a row-count mismatch aborts the load and releases the locks. The staging table must be a unique snapshot of the business key at one point in business time.
|
||||
|
||||
### 6. Base extract (`work.bitemp0_base`)
|
||||
|
||||
Only base records matching staged PKs are extracted — for temporal load types, only **currently live** records (`now < tech_to`). A left join from the staged keys to the base produces `___TMP___NEW_FLG` to identify brand-new keys. This is engine-specific:
|
||||
|
||||
* **OLEDB (SQL Server)** — staged keys are pushed to a `##global` temp table and joined via explicit pass-through.
|
||||
* **REDSHIFT / POSTGRES / SNOWFLAKE** — an in-database temp table is created `like` the base, stripped to PK + an added `md5 varchar(32)` column, loaded with staged keys, and joined via pass-through. Snowflake uses transient tables; Redshift gets `alter sortkey none` plus any `DCBL_REDSH` config options from `MPE_CONFIG`.
|
||||
* **CAS** — a FedSQL join against a CASUSER copy.
|
||||
* **BASE/other** — plain PROC SQL in SAS.
|
||||
|
||||
### 7. Change classification
|
||||
|
||||
* **`&outds_add`** — staged records flagged as new (no base match). They get `tech_from=now`, `tech_to=high_date`.
|
||||
* **`work.bitemp1_current`** — matched base records, re-hashed so hashes are comparable.
|
||||
* **Inserts (BITEMPORAL only)** — a staged record whose business range falls strictly *inside* an existing record's range splits the existing record into a "before" and "after" segment (`bitemp3_inserts` / `bitemp3a_inserts`). The split segments replace the original in the comparison set (`bitemp3b_newbase`).
|
||||
* **Updates (`bitemp4*`)** — staged records matching a base PK but with a different hash or different business dates. Base and staged versions are stacked, deduplicated, then aligned in **two passes** over the business timeline per key: a forward pass (carry `bus_from` forward across identical hashes; a staged record trims the preceding base record's range) and a reverse pass (carry `bus_to` back; records fully subsumed by the new version are deleted). Records that end up byte-identical to what is already stored are dropped via a hash lookup that includes the business dates (`bitemp5a_lkp` / `bitemp5b_updates`, BITEMPORAL only).
|
||||
|
||||
### 8. Closeout application
|
||||
|
||||
Changed records are closed out in the target before the new versions are appended. SAS SQL has no UPDATE-with-join, so a correlated `EXISTS` subquery against `work.bitemp5d_subquery` is used (pushed in-database as a temp table for OLEDB / REDSHIFT / POSTGRES / SNOWFLAKE):
|
||||
|
||||
* **BITEMPORAL** — per key, the closeout range is `min(bus_from)` / `max(bus_to)` of the changed records: `update base set tech_to=now (, processed=now) where tech_from <= now < tech_to and exists (key match and base.bus_from >= min and base.bus_to <= max)`.
|
||||
* **TXTEMPORAL** — same, on key only.
|
||||
* **UPDATE** — changed records are physically `delete`d (they are re-appended in the next step). On CAS this uses `table.deleteRows` with a whereTable; temporal types are not supported on CAS and abort.
|
||||
* **BUSTEMPORAL** — closeouts are not implemented; the macro aborts at this point ("BUSTEMPORAL NOT YET SUPPORTED").
|
||||
|
||||
### 9. Append, unlock, audit, log
|
||||
|
||||
* The union of modified + new records, deduplicated on all columns (`bitemp6_unique`), is appended to the base table (`proc append ... force nowarn`; CAS appends via a varchar-casting step; Redshift applies `DCBL_REDSH` options). Locks are then released.
|
||||
* If `outds_audit` is set (always, from `%mpe_targetloader` — `AUDIT_LIBDS` defaulting to `&dclib..MPE_AUDIT`), `%mp_storediffs` compares the pre-load snapshot with the applied changes and appends row-level audit records; modified-row entries with no actual value change are removed (`MOVE_TYPE="M" and IS_PK=0 and IS_DIFF=0`).
|
||||
* A summary row is inserted into `&dclib..MPE_DATALOADS` (libref, dsn, etlsource, loadtype, changed/new/deleted counts, duration, macro version, user, timestamp) unless `LOG=0`.
|
||||
|
||||
## REPLACE Load Type
|
||||
|
||||
REPLACE is the simplest load type and is deliberately **not** routed through `%bitemporal_dataloader` — it is implemented inline in `%mpe_targetloader` and simply wipes the target table (`delete * from`) and re-appends the staging table verbatim, with no history, change detection, key matching, audit rows, or `MPE_DATALOADS` logging. See [replace-load-type.md](replace-load-type.md) for the full deep dive.
|
||||
|
||||
## Supporting Tables
|
||||
|
||||
| Table | Role |
|
||||
|---|---|
|
||||
| `MPE_TABLES` | Per-table load configuration (loadtype, keys, temporal vars, audit target) |
|
||||
| `MPE_SELECTBOX` | Dropdown values, including the LOADTYPE list (seeded in `mpe_makedata.sas`) |
|
||||
| `MPE_SUBMIT` / `MPE_REVIEW` | Approval workflow state |
|
||||
| `MPE_LOADS` | Submission-level log of CSV package loads |
|
||||
| `MPE_DATALOADS` | Per-load statistics (temporal/UPDATE loads only) |
|
||||
| `MPE_AUDIT` (or `AUDIT_LIBDS`) | Row-level change audit (temporal/UPDATE/FORMAT_CAT loads only) |
|
||||
| `MPE_LOCKANYTABLE` | Lock control table |
|
||||
| `MPE_CONFIG` | Engine-specific config (e.g. `DCBL_REDSH` scope for Redshift bulk options) |
|
||||
|
||||
## Testing
|
||||
|
||||
Unit tests for the loaders live next to the macros: `sas/sasjs/macros/bitemporal_dataloader.test.[1-4].sas` and `sas/sasjs/macros/mpe_targetloader.test.sas` (REPLACE loadtype), executed as sasjs tests. See [testing.md](testing.md) for how to run them (`npm run 4gl` then `sasjs test -t 4gl` from the `sas/` directory), and remember `sasjs lint` after touching any `.sas` files.
|
||||
@@ -0,0 +1,28 @@
|
||||
# Releases and the CHANGELOG
|
||||
|
||||
**Do not edit `CHANGELOG.md` by hand, and do not bump the version in `package.json` yourself.** Both are generated automatically by the release pipeline. Manual edits produce duplicate/colliding version sections and merge conflicts, and they are pointless because the next release overwrites them anyway.
|
||||
|
||||
## How releases work
|
||||
|
||||
Releases are driven by [semantic-release](https://semantic-release.gitbook.io/) from the `release` job in `.gitea/workflows/release.yaml`, which runs on every push to `main` (after the build/test jobs pass). The configuration lives in `.releaserc` at the repo root.
|
||||
|
||||
The plugin chain (`.releaserc` `plugins`) does the following on each release:
|
||||
|
||||
1. `@semantic-release/commit-analyzer` - inspects Conventional Commit messages since the last tag to decide the next semantic version (`fix:` -> patch, `feat:` -> minor, breaking change -> major).
|
||||
2. `@semantic-release/release-notes-generator` - builds the release notes from those commits.
|
||||
3. `@semantic-release/changelog` - **writes the new section into `CHANGELOG.md`**.
|
||||
4. `@semantic-release/npm` - updates the `version` in `package.json` (it does not publish; the package is `private`).
|
||||
5. `@semantic-release/git` - commits `CHANGELOG.md` and `package.json` back to `main` as `chore(release): <version> [skip ci]` and tags it.
|
||||
6. `@saithodev/semantic-release-gitea` - creates the Gitea release.
|
||||
|
||||
The build assets (frontend zip, SAS 9 / Viya / SASjs Server deployment files) are attached to the release afterwards by the workflow's own `Upload assets to release` step using the Gitea API (`curl`), not by the plugin. Before creating the release the workflow first runs `semantic-release --dry-run` and aborts the job if there are no releasable changes since the last tag.
|
||||
|
||||
Because the changelog entry and version bump are committed by the pipeline (step 5), they must **not** exist in your working tree beforehand. If they do, the release commit collides with them.
|
||||
|
||||
## What this means for you
|
||||
|
||||
- Never add, remove, or reorder entries in `CHANGELOG.md`.
|
||||
- Never change `version` in `package.json`.
|
||||
- Control what appears in the changelog through your **commit messages** (Conventional Commits: `fix:`, `feat:`, `feat!:`/`BREAKING CHANGE:`, plus scopes like `fix(editor): ...`). The scope and description become the changelog line.
|
||||
- If you find hand-written entries in `CHANGELOG.md` in the working tree, revert them (`git checkout CHANGELOG.md`).
|
||||
- CI does not use any local release script - the pipeline installs and runs `semantic-release` directly.
|
||||
@@ -0,0 +1,97 @@
|
||||
# REPLACE Load Type — Technical Deep Dive
|
||||
|
||||
This document describes the REPLACE load type in detail. For the overall loader architecture, the temporal model, and the other load types, see [bitemporal-dataloader.md](bitemporal-dataloader.md).
|
||||
|
||||
## Overview
|
||||
|
||||
REPLACE is the simplest load type and is deliberately **not** routed through `%bitemporal_dataloader`. It is implemented inline in `%mpe_targetloader` (`sas/sasjs/macros/mpe_targetloader.sas`, search for `&loadtype=REPLACE`). There is no history, no change detection, no key matching — the target table is wiped and reloaded from the staging table verbatim.
|
||||
|
||||
## Actual load (`LOADTARGET=YES`)
|
||||
|
||||
```sas
|
||||
%mp_lockanytable(LOCK, lib=&lib, ds=&ds, ...)
|
||||
|
||||
data WORK.&STAGING_DS;
|
||||
set WORK.&STAGING_DS;
|
||||
/* only if the target contains the MPE_TABLES.VAR_PROCESSED variable: */
|
||||
&VAR_PROCESSED = &now;
|
||||
drop _____DELETE__THIS__RECORD_____;
|
||||
run;
|
||||
|
||||
%if &engine_type=CAS %then %do;
|
||||
/* prep first: cast varchar columns in a CASUSER copy of staging */
|
||||
proc contents noprint data=&libds out=work.rpl_base_cols(keep=name type);
|
||||
proc contents noprint data=WORK.&STAGING_DS out=work.rpl_stag_cols(keep=name type);
|
||||
/* work.rpl_vchars = columns that are varchar in target AND in staging */
|
||||
data casuser.&tmpds; /* temp copy with varchars casted */
|
||||
length <varchar col> varchar(*); ...
|
||||
set WORK.&STAGING_DS (rename=(<varchar col>=<tmp> ...));
|
||||
<varchar col>=<tmp>; ... drop <tmp> ...;
|
||||
run;
|
||||
/* unlock + abort if any error so far - nothing destructive done yet */
|
||||
%mp_abort(iftrue= (&syscc>0) ...)
|
||||
/* destructive step, deliberately last before the append */
|
||||
proc cas;
|
||||
table.deleteRows / table={caslib="&lib",name="&ds",where="1=1"};
|
||||
quit;
|
||||
data &libds (append=yes) / sessref=dcsession;
|
||||
set casuser.&tmpds;
|
||||
run;
|
||||
proc sql; drop table CASUSER.&tmpds; quit;
|
||||
%end;
|
||||
%else %do;
|
||||
/* unlock + abort if any error so far - nothing destructive done yet */
|
||||
%mp_abort(iftrue= (&syscc>0) ...)
|
||||
proc sql;
|
||||
delete * from &libds;
|
||||
quit;
|
||||
proc append base=&libds data=WORK.&STAGING_DS force nowarn; run;
|
||||
%end;
|
||||
|
||||
%mp_lockanytable(UNLOCK, lib=&lib, ds=&ds, ...)
|
||||
```
|
||||
|
||||
Step by step:
|
||||
|
||||
1. **Lock** — the target is locked via `%mp_lockanytable` (control table `&dclib..MPE_LOCKANYTABLE`). This is the only concurrency guard for the whole operation.
|
||||
2. **Staging recopy** — the staging dataset is rewritten in place: the processed-timestamp column is set to the approval timestamp **only if** the target table contains the variable named by `MPE_TABLES.VAR_PROCESSED` (unlike `%bitemporal_dataloader`, there is no `PROCESSED_DTTM` fallback). The delete-flag column `_____DELETE__THIS__RECORD_____` is unconditionally dropped — per-record delete semantics do not exist in REPLACE (everything is deleted anyway), so a delete flag submitted by the user is silently discarded (a `drop` of a non-existent variable just produces a warning).
|
||||
3. **Prepare the load (CAS only)** — fixed char variables cannot be appended to CAS varchar columns, so the staging table is first copied to a CASUSER temp table with every column that is varchar in the target (and present in staging) redeclared as `varchar(*)` via generated `length` / `rename` / assignment statements. This mirrors the CAS append in `%bitemporal_dataloader`.
|
||||
4. **Pre-destructive abort check** — if `&syscc > 0` after all preparation, the target is unlocked and the macro aborts via `%mp_abort`. Nothing destructive has happened at this point, so a failed prep leaves the target intact (and without a stale lock).
|
||||
5. **Delete all rows** — every row is removed from the target while preserving structure, indexes and metadata, deliberately as the last step before the append (to minimise the time the target sits empty). On most engines this is `proc sql; delete * from &libds;` (passed through as a `DELETE` on database libraries). CAS tables do not support SQL deletes, so on the CAS engine the table is truncated instead via the `table.deleteRows` action with `where="1=1"` (same approach as `%bitemporal_closeouts`), with the libref passed as the caslib.
|
||||
6. **Append staged rows** — the entire staging table is appended. On most engines this is `proc append ... force nowarn` (`force` allows the append to proceed despite attribute mismatches, so lengths/formats may be coerced or values truncated, and columns present in only one side are handled; `nowarn` suppresses the associated warnings). On CAS the pre-cast CASUSER temp table is appended with `data &libds (append=yes) / sessref=dcsession` and then dropped.
|
||||
7. **Unlock**.
|
||||
|
||||
## Diff screen (`LOADTARGET=NO`)
|
||||
|
||||
When the approver reviews a REPLACE submission, no real comparison is performed:
|
||||
|
||||
```sas
|
||||
/* is full replace so treat all staged records as new in diff screen */
|
||||
data work.outds_mod work.outds_add;
|
||||
set work.&staging_ds;
|
||||
output work.outds_add; /* every staged record is "NEW" */
|
||||
run; /* outds_mod stays empty */
|
||||
|
||||
/* previous table will be considered fully deleted */
|
||||
data work.outds_del;
|
||||
set &lib..&ds; /* every existing record is "DELETED" */
|
||||
run;
|
||||
```
|
||||
|
||||
The approval screen therefore always shows full-table turnover: the entire current table as deleted and the entire staging table as added, with no "modified" records and no original/current comparison.
|
||||
|
||||
## What REPLACE does not do
|
||||
|
||||
Because it bypasses `%bitemporal_dataloader`, none of the following apply to REPLACE:
|
||||
|
||||
* **No row-level audit** — nothing is written to `AUDIT_LIBDS` / `MPE_AUDIT`. The record of the change is the approval package itself (staged CSV and the `TEMPDIFFS` CSV stored under `&mpelocapprovals/&LOAD_REF`).
|
||||
* **No `MPE_DATALOADS` log entry** — the load-log insert lives inside `%bitemporal_dataloader`, so REPLACE loads do not appear in load history. (Consequently the SHOW_DIFFS timestamp lookup in `postdata.sas` finds no `MPE_DATALOADS` row for a REPLACE load and falls back to the current datetime.)
|
||||
* **No PK usage** — `BUSKEY` is ignored: no uniqueness check, no dedup, no join to existing data. Staged rows are loaded exactly as submitted, duplicates included.
|
||||
* **No temporal handling** — `VAR_TXFROM`/`VAR_TXTO`/`VAR_BUSFROM`/`VAR_BUSTO` and `CLOSE_VARS` are ignored. A REPLACE table should not be treated as temporal; querying it with the usual validity filters makes no sense.
|
||||
* **No retained-key handling** — `RK_UNDERLYING` is ignored.
|
||||
* **Minimal engine-specific handling** — unlike the temporal loaders, there is no pass-through/temp-table optimisation for OLEDB, Redshift, Postgres or Snowflake. The only engine conditional is CAS, where rows are removed via the `deleteRows` action and appended via a varchar-casting CASUSER temp table and a data-step append (SQL deletes and fixed-char-to-varchar appends are not possible on CAS).
|
||||
* **Not atomic** — the delete/truncate and append are separate steps with no transaction or rollback, so a session failure between them still leaves the target empty or partially loaded (recovery is a re-approval of the same or a previous staging package). The risk is mitigated by performing all preparation first, aborting on any error before the destructive step, and executing the delete/truncate immediately before the append.
|
||||
|
||||
## Interaction with Row Level Security
|
||||
|
||||
REPLACE is incompatible with `EDIT`-scope RLS rules (a full-table wipe cannot honour row-level write restrictions); this is enforced at edit time in both directions — see [row-level-security.md](row-level-security.md#incompatibility-with-replace-load-type) and [issue #211](https://git.datacontroller.io/dc/dc/issues/211). `VIEW`-scope rules remain compatible.
|
||||
@@ -0,0 +1,82 @@
|
||||
---
|
||||
name: dc-sas
|
||||
description: >
|
||||
Use this skill alongside the sasjs/skills collection (sas, sasjs-core, sasjs-cli) when working on
|
||||
Data Controller SAS code. Covers the repo-specific SAS knowledge that is NOT in those skills —
|
||||
DC test-state conventions (MPE control tables, dctest, %let syscc) and the chunked-deploy
|
||||
strategy for the huge generated build script (sasjsbuild/viya.sas). For general SAS language,
|
||||
@sasjs/core macro, and @sasjs/cli guidance, rely on the sas, sasjs-core and sasjs-cli skills.
|
||||
---
|
||||
|
||||
# SAS Development in Data Controller
|
||||
|
||||
The sas, sasjs-core and sasjs-cli skills cover general SAS language and SASjs conventions (macro
|
||||
quoting, `%mp_assert*` testing style, `sasjs lint`, `sasjs run`, `sasjsbuild/` being generated
|
||||
output). These notes only cover the parts specific to Data Controller.
|
||||
|
||||
|
||||
## Tests must be idempotent
|
||||
|
||||
A test file must pass when run repeatedly (including after a run that failed partway).
|
||||
|
||||
- Clean up **all** persistent DC state, not just the obvious one: `MPE_TABLES` registrations,
|
||||
`MPE_LOCKANYTABLE` lock records (a run dying between LOCK and UNLOCK leaves a stale `LOCKED`
|
||||
row), physical tables in `dctest` (`proc datasets ... delete`), and global macro variables
|
||||
created via `select ... into:` (`%symdel`).
|
||||
|
||||
## Chunked deploy to Viya
|
||||
|
||||
The full DC build script (`sasjsbuild/viya.sas`) is very large (11+ MB / 300k+ lines). The Viya
|
||||
compute API can hang or fail when submitting a file this size in a single request.
|
||||
|
||||
**Chunked deploy.** Split the build script at `%let path=<folder>` boundaries — these are clean
|
||||
section breaks between service/test folders (always preceded by blank lines, never inside a data
|
||||
step). Each sub-chunk must be prepended with the shared header (the first ~3827 lines containing
|
||||
macro definitions, `appLoc` setup, and logging options:
|
||||
|
||||
`options ps=max nonotes nosgen nomprint nomlogic nosource2 nosource noquotelenmax;`
|
||||
|
||||
Logging is already suppressed in the header — no extra action needed. Keep each chunk under ~1.5
|
||||
MB. The `tests/macros`, `tests/services`, and streaming-app tail sections are the largest and may
|
||||
need further sub-splitting at `%let service=` boundaries.
|
||||
|
||||
When splitting mid-folder (between services in the same folder), the sub-chunk that starts
|
||||
mid-folder must re-assert `%let path=<folder>;` before its first `%let service=` line — otherwise
|
||||
`&path` is unresolved and the `%mv_createwebservice(path=&appLoc/&path, ...)` call will abort with
|
||||
a recursive reference error.
|
||||
|
||||
Deploy each chunk in order with `sasjs run <chunk>.sas -t <target>`. After all chunks are
|
||||
deployed, run `sasjs request services/admin/makedata -d deploy/makeDataViya.json -t <target>` to
|
||||
create the database.
|
||||
|
||||
**Non-fatal errors.** `ERROR: Unauthorized` on `/dataSources/providers/Compute/` lines in the
|
||||
log are expected for non-admin Viya users — they come from the Data Sources API during
|
||||
lineage/catalog refresh and do not affect the deploy.
|
||||
|
||||
## Repo conventions for .sas files
|
||||
|
||||
- Test files are named `<thing>.test.sas` (or `<thing>.test.N.sas`) and run via
|
||||
`npm run 4gl && sasjs test -t 4gl` from `sas/` — see `.agents/docs/testing.md`.
|
||||
- `sas/sasjsbuild/` is generated build output — never hand-edit it; edit sources under
|
||||
`sas/sasjs/` only.
|
||||
|
||||
## Temp and scratch files stay out of the repo
|
||||
|
||||
Transient artifacts from manual test runs against sasjs-server — captured `_webout` JSON
|
||||
responses (e.g. `*_out.json`), request/response logs (e.g. `*.log`), and iteration snapshots
|
||||
(`vd_out2.json`, `stage_check2.json`, etc.) — must not be left in the working tree. They
|
||||
clutter `git status`, are never referenced by source or tests, and easily leak local
|
||||
filesystem paths (the sasjs-server session dir, `/home/.../sasjs_root/sessions/.../`) into
|
||||
committed history.
|
||||
|
||||
Write them to a gitignored tmp location instead. The repo already provides two:
|
||||
|
||||
- `tmp/` (gitignored at repo root) — general scratch space.
|
||||
- `sas/tmp/` (gitignored via the root `tmp/` rule) — for SAS-side artifacts.
|
||||
|
||||
If a helper script dumps captured output for comparison during a debug session, point it at
|
||||
`tmp/` (or `sas/tmp/` for SAS-local paths) rather than alongside the tracked mocks in
|
||||
`sas/mocks/`. The tracked mock fixtures live under `sas/mocks/sas9/` and
|
||||
`sas/mocks/sasjs/services/`; loose `*_out.json` / `*.log` files at the `sas/mocks/` root are
|
||||
not mocks, they are leftover captures — remove them with `git clean -fd sas/mocks/` or
|
||||
write to `tmp/` in the first place.
|
||||
@@ -0,0 +1,63 @@
|
||||
---
|
||||
name: sas
|
||||
description: Expert guidance for the SAS programming language — DATA step, PROC SQL, macro language, formats, ODS, and common procedures. Pure SAS syntax only, no SASjs-framework content. Use when writing, reviewing, or debugging .sas programs, or answering SAS language questions.
|
||||
---
|
||||
|
||||
# SAS Language
|
||||
|
||||
Write idiomatic, production-quality SAS code. This skill covers the SAS language itself, independent of any framework.
|
||||
|
||||
## Scope
|
||||
|
||||
- DATA step programming (SET/MERGE/BY, RETAIN, arrays, DO loops, hash objects, first./last. processing)
|
||||
- PROC SQL (joins, subqueries, views, pass-through with CONNECT TO)
|
||||
- Macro language (%macro/%mend, macro variables, %local/%global, conditional %IF logic, quoting functions %STR/%NRSTR/%BQUOTE, CALL SYMPUTX)
|
||||
- Common PROCs: SORT, MEANS/SUMMARY, FREQ, TRANSPOSE, REPORT, PRINT, CONTENTS, DATASETS, FORMAT, IMPORT/EXPORT
|
||||
- Formats and informats (user-defined via PROC FORMAT, picture formats)
|
||||
- ODS output (HTML, PDF, RTF, Excel, OUTPUT destination)
|
||||
- File I/O: LIBNAME, FILENAME, INFILE/INPUT, FILE/PUT
|
||||
|
||||
## Non-negotiable: no WARNINGs
|
||||
|
||||
Generated SAS code must run cleanly — **zero WARNINGs (and zero ERRORs) in the log**. Treat every `WARNING:` as a defect: uninitialized variables, implicit type conversions, truncation notes that should be warnings, "no observations", unresolved macro references, etc. If a warning is truly unavoidable, suppress it deliberately (e.g. an explicit option) and comment why. Likewise avoid superfluous NOTEs where reasonable.
|
||||
|
||||
## Style rules
|
||||
|
||||
These follow the @sasjs/core coding standards — apply them to all SAS code:
|
||||
|
||||
- One statement per line; indentation = 2 spaces, no tabs, no trailing whitespace
|
||||
- Lines no longer than 80 characters; unix (LF) line endings; UTF-8
|
||||
- Avoid non-ASCII / special characters entirely — maximum compatibility across SAS installations and encodings
|
||||
- Always end steps with `run;`; for `proc sql` (and CAS-connected procs) `quit;` is essential to avoid `WARNING: You cannot disconnect or terminate session ...` on Viya
|
||||
- All dataset references must be 2-level (`work.blah`, not `blah`) — protects against `DATASTMTCHK=ALLKEYWORDS` and an active `USER` library
|
||||
- Explicit `length` / `attrib` for character variables rather than relying on defaults (avoids implicit length=8 truncation)
|
||||
- Use literal suffixes for clarity (`'01JAN2020'd`, `'12:30't`)
|
||||
- Prefer `proc sort` with `nodupkey` over manual dedup logic
|
||||
- Macros:
|
||||
- Define with parentheses, even with no parameters: `%macro x();` not `%macro x;`
|
||||
- Closing `%mend;` must repeat the macro name
|
||||
- Macro calls are not terminated with a semicolon: `%my_macro()` not `%my_macro();`
|
||||
- Mandatory parameters positional; optional parameters keyword (`var=`) style
|
||||
- Macro names lowercase, verb-noun convention
|
||||
- Macro variables without trailing dot (`&var` not `&var.`) unless needed to prevent incorrect resolution
|
||||
- Macro variable NAMES are case-insensitive: `&Foo`, `&FOO`, and `&foo` all resolve to the same symbol (same for `%symexist`/`%superq`/`symget` arguments, which take a NAME not a value). Don't chase case mismatches as a bug — it's never the cause.
|
||||
- ALL macro variables must be `%local` unless deliberately global (globals should use an application prefix to avoid collisions); use `call symputx` (not `symput`) in DATA steps
|
||||
- Comment with `/* */` inside macros (asterisk comments are compiled into the macro)
|
||||
- Guard macro logic with `%length(&var)=0` checks rather than `&var=` (empty comparisons are unsafe)
|
||||
- Avoid naming collisions: use `%sysfunc`-/`&syslast`-based work tables (e.g. `data &output; set &syslast; run;`) rather than hard-coded names
|
||||
- No open (non-macro) conditional code: wrap platform-branching or conditionally-executed blocks (e.g. `%if %mf_getplatform()=VIYA %then %do; ... %end;`) in a `%macro ... %mend` and invoke the macro. Open `%if` at program level fails in some execution contexts (job/scheduler/test harnesses) and hides scope leaks.
|
||||
|
||||
## Portability awareness
|
||||
|
||||
- Note when code differs between SAS 9.4 and Viya (e.g. CAS actions vs procs, `proc casutil` for sashdat loading, no X command on locked-down servers)
|
||||
- Avoid hard-coded physical paths and engine-specific options unless asked
|
||||
- No open macro code with if/else logic: wrap branching blocks in `%macro ... %mend` and call them — open `%if`/`%else` does not behave as expected in all SAS environments.
|
||||
|
||||
## Common pitfalls to flag when reviewing
|
||||
|
||||
- Unintended many-to-many MERGEs
|
||||
- Automatic variable `_ERROR_` / implicit RETAIN surprises
|
||||
- Macro timing issues: referencing `¯ovar` before it exists, `%if` evaluating data-step variables (use `if`/`symget` instead)
|
||||
- Automatic macro variables (`&syscc`, `&syswarningtext`, `&syserrortext`, `&sysdate`, `&sysuserid`, etc.) are READ-ONLY — attempting to overwrite them (e.g. `%let syswarningtext=;` or `call symput('syscc',...)`) raises `ERROR: Unable to assign value to a macro variable that is read only` (or similar). Never try to "clear" them.
|
||||
- Truncation from implicit length=8 on first assignment
|
||||
- `proc sql` cartesian product warnings
|
||||
@@ -0,0 +1,68 @@
|
||||
---
|
||||
name: sasjs-adapter
|
||||
description: Frontend/Node integration with SAS backends using @sasjs/adapter — configuring the SASjs class, authentication (SAS 9, Viya, SASjs server), requests with input/output tables, file upload, and session management. Use when writing TypeScript/JavaScript that calls SAS services or jobs.
|
||||
---
|
||||
|
||||
# @sasjs/adapter
|
||||
|
||||
`@sasjs/adapter` is the TypeScript library for calling SAS services/jobs from browsers or Node, with a unified API across three server types: `SAS9`, `SASVIYA`, `SASJS`.
|
||||
|
||||
## Basic setup
|
||||
|
||||
```ts
|
||||
import SASjs from '@sasjs/adapter'
|
||||
|
||||
const sasjs = new SASjs({
|
||||
serverUrl: 'https://sas.example.com',
|
||||
serverType: 'SASVIYA', // SAS9 | SASVIYA | SASJS
|
||||
appLoc: '/Public/app/myapp', // root folder of deployed services
|
||||
contextName: 'SAS Job Execution compute context', // Viya only
|
||||
debug: false
|
||||
})
|
||||
```
|
||||
|
||||
## Executing a request
|
||||
|
||||
```ts
|
||||
const response = await sasjs.request('services/common/getdata', {
|
||||
mytable: [{ col1: 'value', col2: 42 }] // input tables as JS arrays of objects
|
||||
})
|
||||
// response.result contains output tables sent back from SAS (_webout JSON)
|
||||
```
|
||||
|
||||
- Input tables become SAS datasets via the `sasjs_tables` mechanism (work tables named after the JS keys).
|
||||
- The SAS service must write JSON to `_webout` — conventionally with the `mp_jsonout` macro from @sasjs/core, wrapped in `proc stp`-style begin/end macros.
|
||||
- Responses follow the `SASjsRequest`/`SASjsResponse` types; check `response.result` for tables and `response.log` where available.
|
||||
|
||||
## Authentication
|
||||
|
||||
- **SAS 9**: `sasjs.logIn(username, password)` (form-based against the stored process server). Session cookie is managed automatically.
|
||||
- **Viya**: OAuth client/secret (client credentials grant) or authorization code flow; tokens are refreshed automatically. Configure via CLI (`sasjs add cred`) for Node usage.
|
||||
- **SASJS server**: token-based auth against the sasjs/server API.
|
||||
|
||||
## Key classes / modules
|
||||
|
||||
- `SASjs` — main facade: `request()`, `logIn()/logOut()`, `uploadFile()`, `executeScript()`
|
||||
- `SessionManager` — Viya compute session lifecycle
|
||||
- `ContextManager` — Viya compute context selection
|
||||
- `SASViyaApiClient` / `SAS9ApiClient` / `SASjsApiClient` — low-level per-platform clients (rarely needed directly)
|
||||
- `file/` utilities — file upload to SAS (binary content handling)
|
||||
|
||||
## Tips
|
||||
|
||||
- Set `debug: true` to surface the SAS log in responses while developing.
|
||||
- Always handle `response.status` / error responses — SAS-side errors (e.g. from `%mp_abort`) come back in the JSON, not necessarily as HTTP errors.
|
||||
- For large payloads prefer CSV upload or streamed files over JSON input tables.
|
||||
- Keep `appLoc` consistent with the `appLoc` in `sasjsconfig.json` used to deploy.
|
||||
|
||||
## Important: request() inputs are ALWAYS tables
|
||||
|
||||
Every key in the `data` object of `sasjs.request(path, data)` is serialized via the `sasjs_tables` CSV mechanism and arrives in SAS as a **work dataset named after the key** — even scalar values. You cannot pass ad-hoc macro variables this way; services must read inputs from the work table (e.g. `data _null_; set work.config; call symputx('rootdir', rootdir); run;`). Output column names in `response.result.<table>` come back UPPERCASE (SAS dataset semantics).
|
||||
|
||||
## Using the adapter without a bundler (zero-build / strict CSP frontends)
|
||||
|
||||
The package root `index.js` is a UMD bundle exposing a global `SASjs`. Pattern (from the minimal seed app):
|
||||
|
||||
1. `"prepare": "cp node_modules/@sasjs/adapter/index.js src/sasjs.js"` in package.json (runs on `npm i`).
|
||||
2. `<script src="sasjs.js"></script>` before your app script.
|
||||
3. Configure via a hidden custom element: `<sasjs serverType="SASJS" appLoc="/Public/app/myapp" debug="false"></sasjs>` and read attributes with `document.querySelector('sasjs')`. When the app is streamed by SAS itself, omit `serverUrl` — same-origin requests just work (CSP `default-src 'self'` safe).
|
||||
@@ -0,0 +1,115 @@
|
||||
---
|
||||
name: sasjs-cli
|
||||
description: Using the SASjs CLI (@sasjs/cli) to create, compile, build, deploy, run, and test SASjs projects against SAS 9, Viya, and SASjs server targets. Use for any `sasjs <command>` usage, CI/CD pipelines, target/auth config, sasjsconfig.json, service packs, or frontend streaming builds.
|
||||
---
|
||||
|
||||
# @sasjs/cli
|
||||
|
||||
The SASjs CLI (`npm i -g @sasjs/cli`, invoked as `sasjs`) automates compiling, building, and deploying SAS projects. All commands support `-t <target>` to select a target from `sasjsconfig.json`.
|
||||
|
||||
## Targets and auth
|
||||
|
||||
- A **target** = `{ name, serverUrl, serverType, appLoc }`. `serverType` is one of `SAS9`, `SASVIYA`, `SASJS`.
|
||||
- Credentials: `sasjs add cred` (or `.env` file). Viya uses client/secret **or** `sasjs auth login` (user/pass, no client/secret needed — see below); SAS 9 uses user/pass; SASJS server uses an access token.
|
||||
- `sasjs context` manages Viya compute contexts; `sasjs add target` adds a new target.
|
||||
|
||||
## Core workflow
|
||||
|
||||
```
|
||||
sasjs create myapp # scaffold a new app (templates available)
|
||||
sasjs compile # gather macros/services/jobs into per-file build outputs (sasjsbuild/)
|
||||
sasjs build # produce deployable artefacts: JSON + .sas per target
|
||||
sasjs deploy # deploy compiled/built artefacts to the target server
|
||||
sasjs cbd # compile + build + deploy in one step (-t viya etc.)
|
||||
```
|
||||
|
||||
## Command reference
|
||||
|
||||
| Command | Purpose |
|
||||
|---|---|
|
||||
| `sasjs create / init` | Scaffold new app or add SASjs to existing repo |
|
||||
| `sasjs compile` | Resolve dependencies (`<h4> SAS Macros </h4>` etc.) into `sasjsbuild/` |
|
||||
| `sasjs build` | Create build JSON / service pack per target |
|
||||
| `sasjs deploy` / `cbd` | Deploy to server (servicepack or direct) |
|
||||
| `sasjs run <file.sas>` | Execute an arbitrary SAS file on the server, return log |
|
||||
| `sasjs request <path>` | Execute a deployed service/job with input data (`-d`) |
|
||||
| `sasjs job execute` | Run a deployed job |
|
||||
| `sasjs flow execute` | Run a sequence of jobs with dependencies (CSV-defined flows) |
|
||||
| `sasjs servicepack deploy` | Deploy from a JSON service pack |
|
||||
| `sasjs web` | Build the frontend and stream it into the SAS web root (streamConfig) |
|
||||
| `sasjs db` | Build database DDL/data load scripts from `sasjs/db` |
|
||||
| `sasjs doc` | Generate doxygen documentation + lineage |
|
||||
| `sasjs folder create/delete/move` | Manage folders in SAS metadata / SAS Drive |
|
||||
| `sasjs fs` | File-system operations against the server (sync folders) |
|
||||
| `sasjs test` | Execute tests defined in `sasjs/tests` with init/term programs |
|
||||
| `sasjs lint` | Lint `.sas` files per `.sasjslint` config |
|
||||
| `sasjs version` | Print/set version info |
|
||||
|
||||
## Conventions
|
||||
|
||||
- Test coverage is generated only from a `sasjs compile` (or `sasjs c`). It accepts a target (`-t <target>`), but nothing is deployed to that target — compilation and coverage are fully local/offline, so no server needs to be available or reachable. Missing macro dependencies (e.g. `mp_ds2csv.sas`) mean `@sasjs/core` isn't installed — run `npm i` first.
|
||||
|
||||
- Dependencies are declared in doxygen headers: `<h4> SAS Macros </h4>`, `<h4> SAS Files </h4>`, `<h4> SAS Folders </h4>`, and `@li item` entries — the CLI builds the dependency tree from these.
|
||||
- `sasjs compile` output goes to the `sasjsbuild/` folder (git-ignore it); `sasjsresults/` holds test/run outputs.
|
||||
- CI/CD: `sasjs cbd -t viya` is the standard deploy step; combine with `sasjs servicepack deploy` for artefact-based releases.
|
||||
- Exit codes are non-zero on failure — safe for pipelines.
|
||||
|
||||
## Gotchas
|
||||
|
||||
- Run `npm i` before `sasjs cb` — macro dependency resolution needs `node_modules/@sasjs/core` present, and `@sasjs/core` (and `@sasjs/adapter` if used) must be listed in `package.json`.
|
||||
- Credentials files are per-target: `.env.<targetname>` (e.g. `.env.server`) with `CLIENT`, `ACCESS_TOKEN`, `REFRESH_TOKEN`. Never commit them — gitignore `.env*`.
|
||||
|
||||
## Viya auth without a client/secret (`sasjs auth login`)
|
||||
|
||||
`sasjs auth login -t <target>` authenticates with a regular SAS username/password via the OAuth2 password grant against the built-in, secret-less `sas.cli` public client. No admin-registered OAuth client is needed — the fastest way to get `sasjs run`/`deploy` working on dev/demo estates. The password is never stored; the minted ACCESS_TOKEN/REFRESH_TOKEN pair is persisted to `.env.<target>` (local) or `~/.sasjsrc` (global) and verified via `/identities/users/@currentUser` (`Logged in as <id> (<name>)`). Bare `sasjs auth` is still an alias for `sasjs add cred`.
|
||||
|
||||
- Token expiry: the CLI silently refreshes via the stored refresh token (works with and without a client/secret), and re-persists the rotated pair — Viya refresh tokens are **single-use/rotating**, so this persistence is what keeps later invocations working. If refresh fails, re-run `sasjs auth login`.
|
||||
- Some estates give `sas.cli` a short access-token TTL (e.g. 1h); a refresh on most invocations is normal.
|
||||
- Opaque (non-JWT) tokens are treated as usable — the server is the authority on expiry.
|
||||
- Limitations: local/LDAP accounts only (no SSO/SAML/MFA estates); password grant must be enabled for `sas.cli` (default on Viya 3.5+/4); ROPC is deprecated in OAuth 2.1 — use a registered client/secret for CI/production.
|
||||
- `sasjs run` 403 on session creation = the account isn't authorised for the configured compute context — set `contextName: "SAS Studio compute context"` on the target. First run on a cold estate can take many minutes (compute pod spin-up) and may appear to hang.
|
||||
- Self-signed estates: use `--insecure` on `auth login`, or configure `httpsAgentOptions` on the target.
|
||||
|
||||
## Viya streaming apps (streamConfig.streamWeb)
|
||||
|
||||
With `streamWeb: true`, `sasjs web`/`cbd -t viya` deploys the frontend **into SAS Files Service**: a streaming job at `<appLoc>/services/<streamServiceName>.html` serves `index.html`, and assets land in `<appLoc>/services/web/...`. At build time every asset/script/css URL in the HTML is rewritten to `/SASJobExecution?_FILE=<appLoc>/services/web/...` and the adapter config element (`<sasjs apploc=...>`) is stamped with the target `appLoc`.
|
||||
|
||||
**Consequence: the app only works when served from the exact `appLoc` it was deployed against.** If the streaming HTML is placed anywhere else (e.g. manually uploaded to a user home folder like `/Users/<id>/myapp/...`), all rewritten `/Public/app/...` asset links 404 and the adapter calls the wrong service paths — the page renders with no CSS/JS and no backend. Fix by redeploying. The original build (`sasjs cb`) has the apploc from the sasjsconfig.json - when the app is deployed as a SAS program, the supplied `%let apploc = ` (runtime value) is swapped with the `compiled_apploc` (build time value) to allow apps to be dynamically deployed to a given apploc at deploy time.
|
||||
|
||||
### Verifying a Viya deployment headlessly (no browser)
|
||||
|
||||
1. Get a token (password grant works out of the box with the built-in `sas.ec` client, empty secret):
|
||||
`curl -X POST <server>/SASLogon/oauth/token -u 'sas.ec:' -d 'grant_type=password&username=U&password=P'`
|
||||
2. Fetch the app: `GET /SASJobExecution/?_FILE=<appLoc>/services/<name>.html` with `Authorization: Bearer` → expect `200` and the full `index.html`. `401` = auth, anything else = not deployed there.
|
||||
3. Fetch each asset the HTML references. Response tells you what's wrong:
|
||||
- `200` with file content → asset deployed correctly.
|
||||
- `202` + a tiny plain-text body (e.g. `Parameter Error\nFile error`) → **file does not exist at that Drive path** (classic appLoc-mismatch symptom). Note `_FILE` responses can be async: add `&_action=wait` to get content synchronously.
|
||||
- Services: `POST /SASJobExecution/?_program=<appLoc>/services/<svc>&_action=wait` → `Parameter Error / Unable to get job definition` means the service was never deployed as a JES job (files on Drive alone are not enough — only `sasjs deploy`/`cbd`/`servicepack deploy` registers them).
|
||||
|
||||
### Talking to SAS — ALWAYS use the adapter or the CLI
|
||||
|
||||
When executing a SAS service or job for any purpose (debugging, reproduction, CI), **always go through the `@sasjs/adapter` or `sasjs` CLI** — never hand-roll curl against `SASJobExecution`. The adapter and CLI handle the things that are trivial to get wrong by hand: the input-data CSV format (space-separated `name:$format.` headers, CRLF, double-quoted special values, `%nrstr(...)` wrapping), the execution-mode routing (`_executionTasks=true` reads `sasjs<N>data` as **macro variables**, not file uploads), the `_debug`/`>>weboutBEGIN<<`/`>>weboutEND<<` wrapper parsing, the token refresh, and the `_contextname` URL param. A hand-built comma-separated CSV will read as blanks, silently skip guarded macro blocks, and send you down a rabbit hole of phantom bugs.
|
||||
|
||||
- Build input data as a JSON file: `{ "<table>": [{ "<col>": "<val>", ... }] }`, e.g. `{ "config": [{ "rootdir": "/export/...", "runastask": "true", "usecomputeapi": "null", "contextname": "Compute Reusable" }] }`.
|
||||
- Run: `sasjs request '<appLoc>/services/common/<svc>' -t viya -d data.json -l <path>.log -o <path>.json`. The CLI hardcodes `debug: true`, so the `-l` flag always captures the full MPRINT/NOTE/`&syscc` log; `-o` saves the parsed webout. **Always pass `-l`** — reproducing a bug without the log means re-running the whole thing.
|
||||
- The Viya Folders/JES REST APIs ARE fine to hit directly with curl (token + `Authorization: Bearer`) for folder/file/member management and for `GET /SASJobExecution/?_FILE=...` asset checks — just not for *executing your own services with input data*.
|
||||
|
||||
#### Adapter execution-context and input-data facts
|
||||
|
||||
- The adapter automatically appends `_contextname=<value>` as a **URL parameter** to every Viya JES request (you do NOT need to pass it yourself). BUT JES request params are **NOT auto-promoted to SAS macro variables** — `%symexist(_contextname)` is false inside the service. If the service needs the chosen context name (e.g. to stamp it into the streamed HTML), pass it in the **input data table** (a `contextname` column) and read it with `call symputx` — that is the reliable channel.
|
||||
- The target's `contextName` in `sasjsconfig.json` decides which compute context the service runs under (and thus the `runAs` identity). The adapter's URL `_contextname` param is the same value. To reproduce a service under a batch/reusable context via `sasjs request`, set the target's `contextName` to that reusable context (e.g. `Compute Reusable`, runAs=sasbatch) — otherwise it runs as your own identity and write-test steps to batch-owned folders fail with `User does not have appropriate authorization level`.
|
||||
- Adapter CSV format (so you can read the `NOTE: The infile ... is:` RULE in the log correctly): row 1 is the header with `name:$informat.` pairs **space-separated**; data rows are **comma-separated** (CRLF), with values double-quoted only if they contain a special char (`,`, `"`, tab, newline). The sasjs/core webout reader reads it back with `dsd` + `firstobs=2` + an `input <name>:$informat.;` statement derived from the header.
|
||||
- `_executionTasks=true` (runAsTask) changes how input data arrives: as `sasjs<N>data` **macro variables** (chunked into `sasjs<N>data0..N`), NOT as `_WEBIN_FILE` uploads. The core webout `mv_webout` macro handles both, but it branches on `_EXECUTIONTASKS` — be aware when reading logs.
|
||||
|
||||
### Redeploying cleanly on Viya (the 409 Conflict problem)
|
||||
|
||||
Re-running `sasjs cbd`/`sasjs run viya.sas` against an **existing** appLoc often fails mid-deploy with `409 Conflict` (and an `mp_abort` → `abort cancel`): `mv_createfile` DELETEs the old file id then tries to recreate it, but when an intermediate **folder** already exists (e.g. `<appLoc>/services/web/js`) the recreate step conflicts and the whole deploy aborts — leaving a half-deployed app (services present, some assets missing). The `?recursive=true` folder DELETE also returns `409 You cannot delete the folder because it is not empty`, and individual member/folder DELETEs can return `403` even as the owner, so you cannot easily tear the tree down by hand.
|
||||
|
||||
The reliable workaround is to **move the top appLoc folder out of the way** and redeploy to the original path — the deploy creates a fresh folder tree with no conflicts, and the old folder is retained as a backup. This is far faster and more reliable than fighting per-member deletes, and is the recommended pre-deploy step for any non-CI redeploy on Viya. Two ways to move it:
|
||||
|
||||
- **Rename in place** (simplest): `PATCH /folders/folders/{id}` with `{"name":"<old>.bak.<ts>","version":2}` — frees the original name, keeps the old folder as a sibling backup.
|
||||
- **MOVE into a backup parent** (tidier — keeps all backups in one place): create (once) a backup parent folder e.g. `/Users/<id>/macrodash-backups`, then `POST /folders/folders/{backupParentId}/members/{appLocFolderId}?action=move` moves the whole tree (with contents) into it, freeing the original path for the fresh deploy.
|
||||
|
||||
(On sasjs/server just `sasjs fs delete` the appLoc first — Drive there supports clean recursive deletes.)
|
||||
|
||||
JES applies its own CSP header when streaming (includes `unsafe-inline`/`unsafe-eval`); a strict CSP meta tag in the app's HTML still applies and is the one that matters for the app code.
|
||||
@@ -0,0 +1,99 @@
|
||||
---
|
||||
name: sasjs-core
|
||||
description: Standards and conventions for the @sasjs/core SAS macro library (mf_*, mp_*, mm*, ms_*, mv_* macros). Use when writing or editing SAS macros in a sasjs/core-style repo, picking an existing macro over reinventing one, or the sasjs/core build, lint, doxygen, and testing conventions.
|
||||
---
|
||||
|
||||
# @sasjs/core — SAS Macro Library
|
||||
|
||||
@sasjs/core is an MIT-licensed library of production-quality SAS macros for SAS application development, portable across SAS 9 (meta), Viya, and SASjs server.
|
||||
|
||||
## Coding standards (mandatory)
|
||||
|
||||
- One macro per file; filename must match the macro name (lowercase, no spaces)
|
||||
- Macro definitions must use parentheses: `%macro x();` not `%macro x;`
|
||||
- Macro *calls* are NOT terminated with a semicolon: `%my_macro()` not `%my_macro();`
|
||||
- All macro variables must be declared `%local` to prevent scope leakage
|
||||
- Always use `mf_getuniquefileref` when assigning filerefs, and `mf_getuniquelibref` when assigning librefs (never hardcode or hand-roll unique references)
|
||||
- 2-space indentation, no tabs, no trailing spaces, no invisible characters, max line length 300 (hard lint limit) but keep lines to 80 chars max where possible
|
||||
- Every file must have a Doxygen header:
|
||||
|
||||
```sas
|
||||
/**
|
||||
@file
|
||||
@brief One-line description of the macro
|
||||
|
||||
<h4> SAS Macros </h4>
|
||||
@li mf_othermacro.sas
|
||||
|
||||
@param [in] paramname Description
|
||||
@param [out] outparam Description
|
||||
|
||||
<h4> Related Macros </h4>
|
||||
@li mp_related.sas
|
||||
|
||||
@version 9.4
|
||||
@author Your Name
|
||||
**/
|
||||
```
|
||||
|
||||
## Folder / prefix conventions
|
||||
|
||||
| Folder | Prefix | Platform |
|
||||
|---|---|---|
|
||||
| `base/` | `mf_` (function-style), `mp_` (procedure-style) | All platforms |
|
||||
| `meta/` | `mm_` | SAS 9 metadata |
|
||||
| `metax/` | `mmx_` | SAS 9 metadata (OS command dependent) |
|
||||
| `viya/` | `mv_` | Viya |
|
||||
| `server/` | `ms_` | SASjs server |
|
||||
| `xplatform/` | `mx_` | Runtime platform detection |
|
||||
| `fcmp/`, `lua/`, `ddl/` | — | PROC FCMP functions, LUA wrappers, DDL |
|
||||
|
||||
Use `mf_` macros when the macro returns a value usable in an expression; use `mp_` for procedural macros that generate code/statements.
|
||||
|
||||
**Cross-suite rule:** `mp_` macros must never reference `mx_` macros. Platform dispatching (SAS 9 / Viya / SASjs server) belongs in the `mx_` suite, which delegates to `ms_`/`mv_`/PROC STP per platform. If an `mp_` macro seems to need platform-specific behaviour, the macro itself belongs in `xplatform/` as an `mx_` macro instead.
|
||||
|
||||
## Reuse before writing
|
||||
|
||||
Before writing a new macro, check the library for an existing one — common utilities already exist, e.g. `mp_abort` (the deprecated `mf_abort` is retained for backwards compatibility — don't use it in new code), `mf_existds`, `mf_existvar`, `mf_existfileref`, `mf_getuser`, `mp_jsonout` (SAS datasets → JSON for `_webout`), `mp_ds2ddl`, `mp_hashdataset`. Platform-specific variants exist under `meta/`, `viya/`, `server/` and are selected at compile time by the CLI.
|
||||
|
||||
## Aborting safely
|
||||
|
||||
Never invoke `%mp_abort` from inside an `%if/%else` block — as a procedural macro, the macro processor can continue executing statements after it before the abort takes effect. Use the `iftrue=` condition parameter instead:
|
||||
|
||||
```sas
|
||||
%mp_abort(iftrue= (&syscc ne 0)
|
||||
,mac=&_program
|
||||
,msg=%str(Something went wrong)
|
||||
)
|
||||
```
|
||||
|
||||
When `%mp_abort` is called from within a `%include` block, SAS cannot exit cleanly (e.g. to `_webout`). Call `%mp_abort(mode=INCLUDE)` after the include (OUTSIDE any macro wrapper) — it checks `work.mp_abort_errds` for an abort status:
|
||||
|
||||
```sas
|
||||
%mp_abort(mode=INCLUDE)
|
||||
```
|
||||
|
||||
Note: `%include`s inside macros should be performed with `%mp_include()` so the `_SYSINCLUDEFILEDEVICE` indicator is set and the abort dataset (`work.mp_abort_errds`) is passed back to the calling program.
|
||||
|
||||
## Testing macros (mandatory conventions)
|
||||
|
||||
- **Always apply `%mp_assertscope` around the macro under test** to catch scope leakage (macro variables must stay `%local`):
|
||||
|
||||
```sas
|
||||
%mp_assertscope(SNAPSHOT)
|
||||
%mx_foo(args)
|
||||
%mp_assertscope(COMPARE,
|
||||
desc=Test 1: mx_foo does not leak scope,
|
||||
outds=work.test_results
|
||||
)
|
||||
```
|
||||
|
||||
- Assertions go to `work.test_results` via `%mp_assert(iftrue=(...), desc=..., outds=work.test_results)`.
|
||||
|
||||
## Lint and build
|
||||
|
||||
- Run `sasjs lint` after every change; do not consider work done until it passes
|
||||
- NEVER bump the version in `package.json` (semantic-release handles it)
|
||||
- Do NOT edit generated files by hand: `all.sas`, `mc_*.sas`, the `lua/` wrappers, and `sasjsbuild/` outputs are produced by the CI build
|
||||
- Markdown files: never hard-wrap; one paragraph per line
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
---
|
||||
name: sasjs-framework
|
||||
description: Building full SASjs applications — project structure, sasjsconfig.json, services/jobs/macros folders, multi-target (SAS 9 / Viya / SASjs server) configuration, streaming frontends, mocks and tests. Use when creating or modifying a SASjs app, editing sasjsconfig.json, or writing backend services returning JSON to a web frontend.
|
||||
---
|
||||
|
||||
# SASjs Framework — Building SASjs Applications
|
||||
|
||||
A SASjs app = a web frontend (any framework: Angular, React, vanilla) + SAS backend code organised in a standard layout, compiled and deployed by `@sasjs/cli` to SAS 9, Viya, or SASjs server. Frontend talks to SAS via `@sasjs/adapter`; backend services return JSON via `_webout`.
|
||||
|
||||
## Standard project layout
|
||||
|
||||
```
|
||||
sasjs/
|
||||
sasjsconfig.json # project + target configuration
|
||||
macros/ # project-specific macros (macroFolders)
|
||||
services/ # web services called from the frontend
|
||||
jobs/ # jobs (scheduled / flow / long-running)
|
||||
programs/ # plain programs (initProgram, termProgram, utilities)
|
||||
db/ # DDL + static data per library (sasjs db)
|
||||
tests/ # tests run by `sasjs test`
|
||||
mocks/ # mock responses for offline frontend dev (syncFolder)
|
||||
doxy/ # extra doxygen content for `sasjs doc`
|
||||
```
|
||||
|
||||
## sasjsconfig.json
|
||||
|
||||
Root config holds defaults; each entry in `targets[]` can override them. Key sections:
|
||||
|
||||
- `macroFolders`, `binaryFolders` — where the CLI finds macros/binaries
|
||||
- `serviceConfig.serviceFolders` — service source folders; `initProgram` runs before every service (set up libnames, options)
|
||||
- `jobConfig.jobFolders` — job source folders
|
||||
- `programFolders` — programs compiled/deployed with the app
|
||||
- `streamConfig` — `streamWeb: true` streams the built frontend into SAS so it is served by the platform itself (no separate web server needed); `webSourcePath` points at the frontend build output
|
||||
- `syncFolder` — folder synced to the server (e.g. mocks)
|
||||
- `testConfig` — init/term programs for `sasjs test`
|
||||
- `targets[]` — per-environment overrides: `serverUrl`, `serverType` (`SAS9`/`SASVIYA`/`SASJS`), `appLoc` (deploy root, e.g. `/Public/app/myapp`), target-specific macroFolders (e.g. `targets/viya/macros_viya` for platform shims), `httpsAgentOptions`, `deployConfig`
|
||||
|
||||
The full JSON schema is bundled at `sasjsconfig-schema.json` next to this file — validate config changes against it. Reference it with `"$schema": "https://cli.sasjs.io/sasjsconfig-schema.json"`.
|
||||
|
||||
## Streamed frontend files on Viya (mime types)
|
||||
|
||||
When `streamWeb: true`, the CLI uploads the frontend (`index.html`, renamed per `streamServiceName`, plus css/js) to the Viya Files service using the `%mv_createfile` macro. That macro creates the file in a very particular way to ensure it streams correctly:
|
||||
|
||||
- POSTs to `/files/files` with the content type derived from the extension (`%mf_mimetype`)
|
||||
- sets `typeDefName=file_html` (via `%mv_getViyaFileExtParms`) so the file is recognised as HTML
|
||||
- sends `Content-Disposition` **without** `attachment` for HTML/SVG so it renders in the browser
|
||||
|
||||
**Never update a streamed frontend file in place** with a `filename filesrvc` fileref + data step rewrite — the Files service then treats it as a generic blob and the mime type is lost, so the app no longer streams (browser downloads it or shows raw text). To modify a streamed file at runtime (eg patching the compute `contextname` in the html), read it (a `filesrvc` fileref is fine for *reading*), write the modified content to a temp fileref, and **re-create the file with `%mv_createfile(path=..., name=..., inref=...)`** (it deletes the old file and re-POSTs with the correct mime type).
|
||||
|
||||
## Service contract (frontend ↔ SAS)
|
||||
|
||||
1. Adapter POSTs to `services/<folder>/<name>` with input tables (arrays of objects) → work datasets named after the JS keys.
|
||||
2. Service SAS code runs after `initProgram`; it reads inputs, does work, and writes output JSON to `_webout`.
|
||||
3. Conventional pattern using @sasjs/core macros:
|
||||
|
||||
```sas
|
||||
/**
|
||||
@file
|
||||
@brief Example service returning data
|
||||
<h4> SAS Macros </h4>
|
||||
@li mp_jsonout.sas
|
||||
@li mp_abort.sas
|
||||
**/
|
||||
|
||||
/* validation / logic here */
|
||||
|
||||
%mp_jsonout(OPEN)
|
||||
%mp_jsonout(OBJ,results,dslabel=results)
|
||||
%mp_jsonout(CLOSE)
|
||||
```
|
||||
|
||||
4. On error, abort cleanly with `%mp_abort(...)` (`mf_abort` is deprecated) so the adapter receives a structured error in the JSON, not a half-written response. Do **not** call `%mp_abort` inside an `%if/%else` block — the macro processor may keep executing beyond the abort. Use the conditional `iftrue=` parameter instead, e.g.:
|
||||
|
||||
```sas
|
||||
%mp_abort(iftrue= (%mf_existds(work.results)=0)
|
||||
,mac=&_program
|
||||
,msg=%str(No results found)
|
||||
)
|
||||
```
|
||||
|
||||
If the abort happens inside a `%include` block, SAS cannot exit to `_webout` cleanly — after the include, call `%mp_abort(mode=INCLUDE)` (outside any macro wrapper), which checks `work.mp_abort_errds` for an abort status.
|
||||
|
||||
## Multi-target discipline
|
||||
|
||||
- Keep backend code platform-neutral in shared folders; put platform-specific shims in `targets/<name>/macros_*` folders and register them only on that target.
|
||||
- Platform capability macros exist in @sasjs/core (`mm_*` metadata, `mv_*` Viya, `ms_*` server) — don't branch on server type by hand.
|
||||
|
||||
## Quality gates (follow the conventions of mature apps like Data Controller)
|
||||
|
||||
- Run `sasjs lint` after touching any `.sas` file; fix all warnings in files you touched.
|
||||
- The linter enforces 2-space indentation everywhere, including continuation lines inside `/* ... */` block comments — never align comment text with 3+ spaces.
|
||||
- Add tests and run `sasjs test` for backend logic changes. When testing macros, always wrap the macro under test with `%mp_assertscope(SNAPSHOT)` / `%mp_assertscope(COMPARE, ...)` to catch macro-variable scope leakage, and wrap any platform-branching code in `%macro` wrappers (no open conditional macro code in test programs).
|
||||
- Provide mocks in `sasjs/mocks` so the frontend can be developed without a live SAS server.
|
||||
- Never auto-commit or bump versions; releases are pipeline-driven (conventional commits).
|
||||
- Markdown files: no hard wrapping — one paragraph per line.
|
||||
- Apps must work offline/on-prem: no external CDN assets in the frontend bundle.
|
||||
|
||||
## Reference implementations
|
||||
|
||||
Look at existing apps for patterns: folder layouts, `sasjsconfig.json` multi-target setups, service structure, streaming builds, and test/mock conventions, eg:
|
||||
* https://git.datacontroller.io/dc/dc
|
||||
* https://github.com/sasjs/react-seed-app
|
||||
* https://github.com/sasjs/macro-dash
|
||||
@@ -0,0 +1,966 @@
|
||||
{
|
||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||
"$id": "https://github.com/sasjs/utils/blob/main/src/types/sasjsconfig-schema.json",
|
||||
"type": "object",
|
||||
"title": "SASjs Config File",
|
||||
"description": "The SASjs Config file provides the settings and structure for your SASjs project. ",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"macroFolders": ["macros"],
|
||||
"programFolders": ["programs"],
|
||||
"binaryFolders": ["binaries"],
|
||||
"defaultTarget": "viya",
|
||||
"targets": [
|
||||
{
|
||||
"name": "viya",
|
||||
"serverType": "SASVIYA",
|
||||
"serverUrl": "https://sas.sasjs.com",
|
||||
"appLoc": "/Public/app",
|
||||
"contextName": "SAS Job Execution compute context",
|
||||
"deployConfig": {
|
||||
"deployServicePack": true,
|
||||
"deployScripts": ["sasjsbuild/myviyadeploy.sas"]
|
||||
},
|
||||
"serviceConfig": {
|
||||
"serviceFolders": ["targets/viya/services/admin"],
|
||||
"initProgram": "build/serviceinit.sas",
|
||||
"termProgram": "build/serviceinit.sas",
|
||||
"macroVars": {
|
||||
"name": "viyavalue",
|
||||
"extravar": "this too"
|
||||
}
|
||||
},
|
||||
"jobConfig": {
|
||||
"jobFolders": [],
|
||||
"initProgram": "",
|
||||
"termProgram": "",
|
||||
"macroVars": {}
|
||||
},
|
||||
"streamConfig": {
|
||||
"assetPaths": [],
|
||||
"streamWeb": false,
|
||||
"streamWebFolder": "webv",
|
||||
"webSourcePath": "dist"
|
||||
},
|
||||
"testConfig": {
|
||||
"initProgram": "sasjs/tests/testinit.sas",
|
||||
"termProgram": "sasjs/tests/testterm.sas",
|
||||
"macroVars": {
|
||||
"testVar": "testValue"
|
||||
},
|
||||
"testSetUp": "sasjs/tests/testsetup.sas",
|
||||
"testTearDown": "sasjs/tests/testteardown.sas"
|
||||
},
|
||||
"macroFolders": ["targets/viya/macros"],
|
||||
"programFolders": [],
|
||||
"binaryFolders": ["binaries"]
|
||||
},
|
||||
{
|
||||
"name": "sas9",
|
||||
"serverType": "SAS9",
|
||||
"serverUrl": "https://sas.sasjs.com:7980",
|
||||
"appLoc": "/User Folders/&sysuserid/My Folder",
|
||||
"serverName": "Foundation",
|
||||
"repositoryName": "SASApp",
|
||||
"buildConfig": {
|
||||
"buildOutputFileName": "mysas9deploy.sas",
|
||||
"initProgram": "",
|
||||
"termProgram": "",
|
||||
"macroVars": {}
|
||||
},
|
||||
"deployConfig": {
|
||||
"deployScripts": ["build/deploysas9.sh"],
|
||||
"deployServicePack": false
|
||||
},
|
||||
"serviceConfig": {
|
||||
"serviceFolders": ["targets/sas9/services/admin"],
|
||||
"initProgram": "",
|
||||
"termProgram": "build/servicetermother.sas",
|
||||
"macroVars": {}
|
||||
},
|
||||
"streamConfig": {
|
||||
"assetPaths": [],
|
||||
"streamWeb": false,
|
||||
"streamWebFolder": "web9",
|
||||
"webSourcePath": "dist"
|
||||
},
|
||||
"testConfig": {
|
||||
"initProgram": "sasjs/tests/testinit.sas",
|
||||
"termProgram": "sasjs/tests/testterm.sas",
|
||||
"macroVars": {
|
||||
"testVar": "testValue"
|
||||
},
|
||||
"testSetUp": "sasjs/tests/testsetup.sas",
|
||||
"testTearDown": "sasjs/tests/testteardown.sas"
|
||||
},
|
||||
"macroFolders": ["targets/sas9/macros"],
|
||||
"programFolders": [],
|
||||
"binaryFolders": ["binaries"]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"binaryFolders": {
|
||||
"$id": "#/properties/binaryFolders",
|
||||
"type": "array",
|
||||
"title": "The binaryFolders array",
|
||||
"description": "These local folders are searched for Binary Files when running sasjs compile. Folders are relative to the sasjs/sasjsconfig.json file.",
|
||||
"examples": [["binaries", "../../more_binaries"]]
|
||||
},
|
||||
"sasjsBuildFolder": {
|
||||
"$id": "#/properties/sasjsBuildFolder",
|
||||
"type": "string",
|
||||
"title": "sasjsBuildFolder",
|
||||
"description": "The name of the folder containing the compiled output. The `sasjs build` command will take all of the subfolders here as inputs to create the build pack. By default this will be named `sasjsbuild`. In global, the default is `~/.sasjsbuild`.",
|
||||
"default": "sasjsbuild",
|
||||
"examples": ["sasjsbuild", ".sasjsbuild"]
|
||||
},
|
||||
"sasjsResultsFolder": {
|
||||
"$id": "#/properties/sasjsResultsFolder",
|
||||
"type": "string",
|
||||
"title": "sasjsResultsFolder",
|
||||
"description": "The name of the folder containing the output (eg logs, ODS output) from `sasjs run`. By default this will be named `sasjsresults`. In global, the default is `~/.sasjsresults`.",
|
||||
"default": "sasjsresults",
|
||||
"examples": ["sasjsresults", ".sasjsresults"]
|
||||
},
|
||||
"defaultTarget": {
|
||||
"$id": "#/properties/defaultTarget",
|
||||
"type": "string",
|
||||
"title": "Default Target",
|
||||
"description": "If a target is not specified, this target is used by default. The default target must exist in the (local) targets array.",
|
||||
"default": "viya",
|
||||
"examples": ["viya"]
|
||||
},
|
||||
"docConfig": {
|
||||
"$id": "#/properties/docConfig",
|
||||
"type": "object",
|
||||
"title": "The docConfig schema",
|
||||
"description": "SASjs uses doxygen to auto-generate HTML documentation using the headers in your SAS programs, macros, services & jobs. For more info, see [https://cli.sasjs.io/doc](https://cli.sasjs.io/doc). Some properties are taken from package.json (such as the project Name).",
|
||||
"default": {
|
||||
"dataControllerUrl": "https://mysasserver.com/web/datacontroller/#",
|
||||
"enableLineage": true,
|
||||
"doxyContent": {
|
||||
"readMe": "../../README.md"
|
||||
}
|
||||
},
|
||||
"examples": [
|
||||
{
|
||||
"displayMacroCore": true,
|
||||
"outDirectory": "/some/output/directory",
|
||||
"dataControllerUrl": "https://mysasserver.com/web/datacontroller/#",
|
||||
"enableLineage": true,
|
||||
"doxyContent": {
|
||||
"readMe": "../../my/custom/homepage.md",
|
||||
"path": "my/custom/doxy/folder"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"displayMacroCore": {
|
||||
"$id": "#/properties/docConfig/properties/displayMacroCore",
|
||||
"type": "boolean",
|
||||
"title": "The displayMacroCore docConfig option",
|
||||
"description": "The CLI will autocompile macro dependencies that exist in the SASjs Macro Core library. These will also show in the documentation under 'node_modules'. If you'd prefer not to show these in the rendered docs, set this value to false.",
|
||||
"default": true,
|
||||
"examples": [true]
|
||||
},
|
||||
"outDirectory": {
|
||||
"$id": "#/properties/docConfig/properties/outDirectory",
|
||||
"type": "string",
|
||||
"title": "The outDirectory docConfig option",
|
||||
"description": "The location to which the generated HTML SAS documentation is written. If missing, or left blank, the files will be written to the `sasjsbuild/doc` directory (default behaviour).",
|
||||
"default": "sasjsbuild/doc",
|
||||
"examples": ["/my/preferred/docs/directory"]
|
||||
},
|
||||
"dataControllerUrl": {
|
||||
"$id": "#/properties/docConfig/properties/dataControllerUrl",
|
||||
"type": "string",
|
||||
"title": "The dataControllerUrl docConfig option",
|
||||
"description": "Provide the full URL to Data Controller so that `sasjs doc` can link the lineage diagram directly to the table viewer in [Data Controller](https://datacontroller.io).\nIf left blank, or undefined, no links will be generated.",
|
||||
"default": "",
|
||||
"examples": ["https://yourserver.co.uk/dcviya/#"]
|
||||
},
|
||||
"enableLineage": {
|
||||
"$id": "#/properties/docConfig/properties/enableLineage",
|
||||
"type": "boolean",
|
||||
"title": "Enable Lineage",
|
||||
"description": "If true, sasjs doc will generate and display Data Lineage from Jobs and Services.",
|
||||
"default": true
|
||||
},
|
||||
"doxyContent": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent",
|
||||
"type": "object",
|
||||
"title": "doxyContent",
|
||||
"description": "Configuration of the Doxyfile variables",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"favIcon": "favicon.ico",
|
||||
"footer": "new_footer.html",
|
||||
"header": "new_header.html",
|
||||
"layout": "DoxygenLayout.xml",
|
||||
"logo": "logo.png",
|
||||
"readMe": "../../README.md",
|
||||
"stylesheet": "new_stylesheet.css",
|
||||
"path": "sasjs/doxy"
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"favIcon": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent/properties/favIcon",
|
||||
"type": "string",
|
||||
"title": "Doxygen favicon",
|
||||
"description": "The favicon used in the doxygen documentation",
|
||||
"default": "favicon.ico"
|
||||
},
|
||||
"footer": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent/properties/footer",
|
||||
"type": "string",
|
||||
"title": "Doxygen footer",
|
||||
"description": "The footer HTML file used in the doxygen documentation",
|
||||
"default": "new_footer.html"
|
||||
},
|
||||
"header": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent/properties/header",
|
||||
"type": "string",
|
||||
"title": "Doxygen header",
|
||||
"description": "The header HTML file used in the doxygen documentation",
|
||||
"default": "new_header.html"
|
||||
},
|
||||
"layout": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent/properties/layout",
|
||||
"type": "string",
|
||||
"title": "Doxygen Layout XML File",
|
||||
"description": "The layout XML file used to build the doxygen documentation",
|
||||
"default": "DoxygenLayout.xml"
|
||||
},
|
||||
"logo": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent/properties/logo",
|
||||
"type": "string",
|
||||
"title": "Doxygen Logo",
|
||||
"description": "The logo file used by doxygen",
|
||||
"default": "logo.png"
|
||||
},
|
||||
"readMe": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent/properties/readMe",
|
||||
"type": "string",
|
||||
"title": "Doxygen Homepage",
|
||||
"description": "The file used to generate the doxygen homepage (defaults to the readme.md)",
|
||||
"default": "../../README.md"
|
||||
},
|
||||
"stylesheet": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent/properties/stylesheet",
|
||||
"type": "string",
|
||||
"title": "Doxygen CSS",
|
||||
"description": "The CSS file used to extend Doxygen",
|
||||
"default": "new_stylesheet.css"
|
||||
},
|
||||
"path": {
|
||||
"$id": "#/properties/docConfig/properties/doxyContent/properties/path",
|
||||
"type": "string",
|
||||
"title": "Doxygen Path",
|
||||
"description": "The path to the Doxygen configuration files (relative to sasjs/sasjsconfig.json)",
|
||||
"default": "sasjs/doxy"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"httpsAgentOptions": {
|
||||
"$id": "#/properties/httpsAgentOptions",
|
||||
"type": "object",
|
||||
"title": "httpsAgentOptions",
|
||||
"description": "Configure https agent by setting all supported attribute such as `key`, `cert`, `ca`, `rejectUnauthorized` and `requestCert`",
|
||||
"examples": [
|
||||
{
|
||||
"allowInsecureRequests": false,
|
||||
"caPath": "path/to/caFile",
|
||||
"keyPath": "path/to/keyFile",
|
||||
"certPath": "path/to/certFile",
|
||||
"requestCert": false,
|
||||
"rejectUnauthorized": true
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"allowInsecureRequests": {
|
||||
"$id": "#/properties/httpsAgentOptions/properties/allowInsecureRequests",
|
||||
"type": "boolean",
|
||||
"title": "allowInsecureRequests",
|
||||
"description": "If you are having certificate errors connecting to SAS, that cannot be properly resolved, try setting this value to true. This option only has an effect if rejectUnauthorized is not present.",
|
||||
"default": false,
|
||||
"examples": [true, false]
|
||||
},
|
||||
"caPath": {
|
||||
"$id": "#/properties/httpsAgentOptions/properties/caPath",
|
||||
"type": "string",
|
||||
"title": "caPath",
|
||||
"description": "Optionally override the trusted CA certificates. Default is to trust the well-known CAs curated by Mozilla. Mozilla's CAs are completely replaced when CAs are explicitly specified using this option.",
|
||||
"examples": ["path/to/caFile"]
|
||||
},
|
||||
"keyFile": {
|
||||
"$id": "#/properties/httpsAgentOptions/properties/keyFile",
|
||||
"type": "string",
|
||||
"title": "keyFile",
|
||||
"description": "Private keys in PEM format. PEM allows the option of private keys being encrypted. Encrypted keys will be decrypted with options.passphrase. Multiple keys using different algorithms can be provided either as an array of unencrypted key strings or buffers, or an array of objects in the form {pem: <string|buffer>[, passphrase: <string>]}. The object form can only occur in an array. object.passphrase is optional. Encrypted keys will be decrypted with object.passphrase if provided, or options.passphrase if it is not.",
|
||||
"examples": ["path/to/keyFile"]
|
||||
},
|
||||
"certFile": {
|
||||
"$id": "#/properties/httpsAgentOptions/properties/certFile",
|
||||
"type": "string",
|
||||
"title": "certFile",
|
||||
"description": "Cert chains in PEM format. One cert chain should be provided per private key. Each cert chain should consist of the PEM formatted certificate for a provided private key, followed by the PEM formatted intermediate certificates (if any), in order, and not including the root CA (the root CA must be pre-known to the peer, see ca). When providing multiple cert chains, they do not have to be in the same order as their private keys in key. If the intermediate certificates are not provided, the peer will not be able to validate the certificate, and the handshake will fail.",
|
||||
"examples": ["path/to/certFile"]
|
||||
},
|
||||
"requestCert": {
|
||||
"$id": "#/properties/httpsAgentOptions/properties/requestCert",
|
||||
"type": "boolean",
|
||||
"title": "requestCert",
|
||||
"description": "If true the server will request a certificate from clients that connect and attempt to verify that certificate. Defaults to false.",
|
||||
"default": false,
|
||||
"examples": [true, false]
|
||||
},
|
||||
"rejectUnauthorized": {
|
||||
"$id": "#/properties/httpsAgentOptions/properties/rejectUnauthorized",
|
||||
"type": "boolean",
|
||||
"title": "rejectUnauthorized",
|
||||
"description": "If true the server will reject any connection which is not authorized with the list of supplied CAs. This option only has an effect if requestCert is true.",
|
||||
"default": true,
|
||||
"examples": [true, false]
|
||||
}
|
||||
}
|
||||
},
|
||||
"buildConfig": {
|
||||
"$id": "#/properties/buildConfig",
|
||||
"type": "object",
|
||||
"title": "buildConfig",
|
||||
"description": "Dictates which files get compiled into the build program (.sas), used to deploy services into SAS 9 or Viya environments (without a client/secret). You may use this config to include build specific macros, programs or macro variables - which is run a single time, on deployment - for things like database creation, or exporting a SAS 9 SPK after service creation.",
|
||||
"examples": [
|
||||
{
|
||||
"initProgram": "build/buildinit.sas",
|
||||
"termProgram": "build/buildterm.sas",
|
||||
"macroVars": {
|
||||
"name": "value",
|
||||
"numvar": "42"
|
||||
},
|
||||
"buildOutputFileName": "buildpack.sas"
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"buildOutputFileName": {
|
||||
"$id": "#/properties/buildConfig/properties/buildOutputFileName",
|
||||
"type": "string",
|
||||
"title": "buildOutputFileName",
|
||||
"description": "The name of the generated .sas program, which can be used to deploy the app using only SAS Studio. By default, this will be the name of the target.",
|
||||
"examples": ["viya.sas", "sas9.sas"]
|
||||
},
|
||||
"initProgram": {
|
||||
"$id": "#/properties/buildConfig/properties/initProgram",
|
||||
"type": "string",
|
||||
"title": "The buildConfig initProgram",
|
||||
"description": "The path to a .sas program that will be inserted at the start of the build .sas program (created when running `sasjs build`).",
|
||||
"default": "sasjs/buildinit.sas"
|
||||
},
|
||||
"termProgram": {
|
||||
"$id": "#/properties/buildConfig/properties/termProgram",
|
||||
"type": "string",
|
||||
"title": "The buildConfig termProgram",
|
||||
"description": "The path to a .sas program that will be inserted at the end of the build .sas program (created when running `sasjs build`).",
|
||||
"default": "sasjs/buildterm.sas"
|
||||
},
|
||||
"macroVars": {
|
||||
"$id": "#/properties/buildConfig/properties/macroVars",
|
||||
"type": "object",
|
||||
"title": "The buildConfig macro variables",
|
||||
"description": "A series of name value pairs that will be turned into SAS macro variables in the build .sas program (generated when running `sasjs build`). The example provided will generate sas code as follows:\n```\n%let name=value;\n%let numvar=42;\n```",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"name": "value",
|
||||
"numvar": "42"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"deployConfig": {
|
||||
"$id": "#/properties/deployConfig",
|
||||
"type": "object",
|
||||
"title": "The deployConfig schema",
|
||||
"description": "The deployConfig object enables settings that relate to the deployment of a SAS app - be that Viya, or SAS 9, or a pure Base environment.",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"deployScripts": ["build/deployscript.sh"]
|
||||
},
|
||||
{
|
||||
"deployScripts": ["build/deployscript.sh"],
|
||||
"deployServicePack": true
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"deployScripts": {
|
||||
"$id": "#/properties/deployConfig/properties/deployScripts",
|
||||
"type": "array",
|
||||
"title": "The deployConfig deployScripts array",
|
||||
"description": "These scripts are executed when running `sasjs deploy`. If the file is a .sas file, it is executed on the SAS server (Viya only). Otherwise it is executed locally. These scripts are run AFTER the deployment of the servicepack, if `deployServicePack:true` (Viya only).",
|
||||
"default": [],
|
||||
"examples": [["build/deployscript.sh", "build/myprogram.sas"]]
|
||||
},
|
||||
"deployServicePack": {
|
||||
"$id": "#/properties/deployConfig/properties/deployServicePack",
|
||||
"type": "boolean",
|
||||
"title": "The deployConfig deployServicePack flag",
|
||||
"description": "If set to `true` the json pack produced by `sasjs build` will be auto-deployed to the `appLoc` of the specified target (creating all jobs and services in the SAS folder tree). Currently only Viya is supported for this flag.",
|
||||
"default": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"serviceConfig": {
|
||||
"$id": "#/properties/serviceConfig",
|
||||
"type": "object",
|
||||
"title": "The serviceConfig schema",
|
||||
"description": "The serviceConfig object defines how SASjs web services are compiled. Web services differ from jobs in that they include some fixed pre-code (eg the macros to stream out the result json).",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"serviceFolders": ["services/common", "services/admin"],
|
||||
"initProgram": "build/serviceinit.sas",
|
||||
"termProgram": "build/serviceterm.sas",
|
||||
"macroVars": {
|
||||
"mac1": "value",
|
||||
"mac2": "42"
|
||||
}
|
||||
}
|
||||
],
|
||||
"required": [],
|
||||
"properties": {
|
||||
"serviceFolders": {
|
||||
"$id": "#/properties/serviceConfig/properties/serviceFolders",
|
||||
"type": "array",
|
||||
"title": "The serviceConfig serviceFolders array",
|
||||
"description": "When running `sasjs compile`, all programs in the folders defined in this array are compiled and placed into same-named folders under `sasjsbuild/services`. They will be compiled as services (so, with the service pre-code). Folders can be absolute, or relative to the `sasjs` folder.",
|
||||
"default": [],
|
||||
"examples": [["services/common", "services/admin"]]
|
||||
},
|
||||
"initProgram": {
|
||||
"$id": "#/properties/serviceConfig/properties/initProgram",
|
||||
"type": "string",
|
||||
"title": "The serviceConfig initProgram",
|
||||
"description": "The serviceConfig `initProgram` is a .sas file that is inserted at the start of every SAS service (after compiled macros and any `macroVars`, and before the service itself). ",
|
||||
"default": "",
|
||||
"examples": ["build/serviceinit.sas"]
|
||||
},
|
||||
"termProgram": {
|
||||
"$id": "#/properties/serviceConfig/properties/termProgram",
|
||||
"type": "string",
|
||||
"title": "The serviceConfig termProgram",
|
||||
"description": "The serviceConfig termProgram is inserted at the end of every service as part of `sasjs compile`.",
|
||||
"default": "",
|
||||
"examples": ["build/serviceterm.sas"]
|
||||
},
|
||||
"macroVars": {
|
||||
"$id": "#/properties/serviceConfig/properties/macroVars",
|
||||
"type": "object",
|
||||
"title": "The `serviceConfig` macroVars",
|
||||
"description": "This object allows `sasjs compile` to insert specific macro variables at the start of every service. In this case, the code generated would be:\n```\n%let mac1=value;\n%let mac2=42;\n```",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"mac1": "value",
|
||||
"mac2": "42"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"jobConfig": {
|
||||
"$id": "#/properties/jobConfig",
|
||||
"type": "object",
|
||||
"title": "The jobConfig schema",
|
||||
"description": "The jobConfig object defines how SASjs Jobs are compiled. ",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"jobFolders": ["jobs/extract", "jobs/load"],
|
||||
"initProgram": "jobs/jobinit.sas",
|
||||
"termProgram": "jobs/jobterm.sas",
|
||||
"macroVars": {
|
||||
"mac1": "value",
|
||||
"mac2": "42"
|
||||
}
|
||||
}
|
||||
],
|
||||
"properties": {
|
||||
"jobFolders": {
|
||||
"$id": "#/properties/jobConfig/properties/jobFolders",
|
||||
"type": "array",
|
||||
"title": "The jobConfig jobFolders array",
|
||||
"description": "When running `sasjs compile`, all programs in the local folders defined in this array are compiled and placed into same-named folders under `sasjsbuild/jobs`. Folders can be absolute, or relative to the local project `/sasjs` folder.",
|
||||
"default": [],
|
||||
"examples": [["jobs/extract", "jobs/transform", "jobs/load"]]
|
||||
},
|
||||
"initProgram": {
|
||||
"$id": "#/properties/jobConfig/properties/initProgram",
|
||||
"type": "string",
|
||||
"title": "The jobConfig initProgram",
|
||||
"description": "The jobConfig `initProgram` is a local .sas file that is inserted at the start of every SAS Job (after compiled macros and any `macroVars`, and before the Job itself). ",
|
||||
"default": "",
|
||||
"examples": ["jobs/jobinit.sas"]
|
||||
},
|
||||
"termProgram": {
|
||||
"$id": "#/properties/jobConfig/properties/termProgram",
|
||||
"type": "string",
|
||||
"title": "The jobConfig termProgram",
|
||||
"description": "The jobConfig termProgram is inserted at the end of every Job as part of `sasjs compile`.",
|
||||
"default": "",
|
||||
"examples": ["jobs/jobterm.sas"]
|
||||
},
|
||||
"macroVars": {
|
||||
"$id": "#/properties/jobConfig/properties/macroVars",
|
||||
"type": "object",
|
||||
"title": "The `jobConfig` macroVars",
|
||||
"description": "This object allows `sasjs compile` to insert specific macro variables at the start of every Job. In this case, the code generated would be:\n```\n%let mac1=value;\n%let mac2=42;\n```",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"mac1": "value",
|
||||
"mac2": "42"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"streamConfig": {
|
||||
"$id": "#/properties/streamConfig",
|
||||
"type": "object",
|
||||
"title": "streamConfig",
|
||||
"description": "SASjs allows a local web app to be compiled such that all html, css, javascript, and other assets such as png or mp4 are converted into web services and streamed directly from SAS.\n\nThis approach is convenient as it bypasses the need to deploy to a web server. ",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"assetPaths": [],
|
||||
"streamWeb": false,
|
||||
"streamWebFolder": "webv",
|
||||
"webSourcePath": "dist",
|
||||
"streamLogo": "logo.png"
|
||||
}
|
||||
],
|
||||
"required": ["streamWeb"],
|
||||
"properties": {
|
||||
"assetPaths": {
|
||||
"$id": "#/properties/streamConfig/properties/assetPaths",
|
||||
"type": "array",
|
||||
"title": "The streamConfig assetPaths array",
|
||||
"description": "An array of local folders. All assets placed in these folders are converted into web services - example file types could be png, svg, mp3, mp4, excel - anything really.",
|
||||
"default": [],
|
||||
"examples": [["/myassets"]]
|
||||
},
|
||||
"streamLogo": {
|
||||
"$id": "#/properties/streamConfig/properties/streamLogo",
|
||||
"type": "string",
|
||||
"title": "Icon shown in AppStream (sasjs/server)",
|
||||
"description": "Provide the location of a square image, under the webSourcePath. Used as the display icon on the appStream page.",
|
||||
"default": "logo.png",
|
||||
"examples": ["logo.png", "favicon.ico"]
|
||||
},
|
||||
"streamWeb": {
|
||||
"$id": "#/properties/streamConfig/properties/streamWeb",
|
||||
"type": "boolean",
|
||||
"title": "The streamConfig streamWeb flag",
|
||||
"description": "When set to `true`, frontend files saved in the `webSourcePath` will be converted to streaming services in the `streamWebFolder` in SAS.",
|
||||
"default": false,
|
||||
"examples": [true]
|
||||
},
|
||||
"streamWebFolder": {
|
||||
"$id": "#/properties/streamConfig/properties/streamWebFolder",
|
||||
"type": "string",
|
||||
"title": "The streamConfig streamWebFolder",
|
||||
"description": "This is the target SAS folder (relative to the appLoc) where the compiled web assets will be created.",
|
||||
"default": "webv"
|
||||
},
|
||||
"webSourcePath": {
|
||||
"$id": "#/properties/streamConfig/properties/webSourcePath",
|
||||
"type": "string",
|
||||
"title": "The webSourcePath schema",
|
||||
"description": "Active when `streamConfig` is `true`. Is the source (or build, or dist) LOCAL folder, relative to the `sasjs` folder, which contains the frontend to be deployed. All assets (PNG, JS, CSS, HTML etc) are taken from here and converted to streaming services in `streamWebFolder`. In Viya and SAS 9, any relative URLS will be modified such that the links still work and the assets still load.",
|
||||
"default": "dist",
|
||||
"examples": ["dist", "build"]
|
||||
},
|
||||
"streamServiceName": {
|
||||
"$id": "#/properties/streamConfig/properties/streamServiceName",
|
||||
"type": "string",
|
||||
"title": "streamServiceName Schema",
|
||||
"description": "The name of the service containing the `index.html` for a streaming web app. Defaults to `clickme` and is always deployed under the appLoc/services SAS Folder.",
|
||||
"default": "clickme.sas"
|
||||
}
|
||||
}
|
||||
},
|
||||
"testConfig": {
|
||||
"$id": "#/properties/testConfig",
|
||||
"type": "object",
|
||||
"title": "testConfig",
|
||||
"description": "Create tests for Macros, Services & Jobs by simply adding a '.test.sas' extension. ",
|
||||
"default": {
|
||||
"initProgram": "sasjs/tests/testinit.sas",
|
||||
"termProgram": "sasjs/tests/testterm.sas",
|
||||
"macroVars": {
|
||||
"testVar": "testValue"
|
||||
},
|
||||
"testSetUp": "sasjs/tests/testsetup.sas",
|
||||
"testTearDown": "sasjs/tests/testteardown.sas"
|
||||
},
|
||||
"properties": {
|
||||
"initProgram": {
|
||||
"$id": "#/properties/testConfig/properties/initProgram",
|
||||
"type": "string",
|
||||
"title": "The jobConfig initProgram",
|
||||
"description": "The testConfig `initProgram` is a local .sas file that is inserted at the start of every Test (after compiled macros and any `macroVars`, and before the Test itself). ",
|
||||
"default": "",
|
||||
"examples": ["sasjs/tests/testinit.sas"]
|
||||
},
|
||||
"termProgram": {
|
||||
"$id": "#/properties/testConfig/properties/termProgram",
|
||||
"type": "string",
|
||||
"title": "The jobConfig termProgram",
|
||||
"description": "The testConfig termProgram is inserted at the end of every Test as part of `sasjs compile`.",
|
||||
"default": "",
|
||||
"examples": ["jobs/jobterm.sas"]
|
||||
},
|
||||
"macroVars": {
|
||||
"$id": "#/properties/testConfig/properties/macroVars",
|
||||
"type": "object",
|
||||
"title": "The `jobConfig` macroVars",
|
||||
"description": "This object allows `sasjs compile` to insert specific macro variables at the start of every Test. In this case, the code generated would be:\n```\n%let mac1=value;\n%let mac2=42;\n```",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"mac1": "value",
|
||||
"mac2": "42"
|
||||
}
|
||||
]
|
||||
},
|
||||
"testSetUp": {
|
||||
"$id": "#/properties/testConfig/properties/testsetup",
|
||||
"type": "string",
|
||||
"title": "The jobConfig testSetUp",
|
||||
"description": "This program is the first to execute as part of 'sasjs test'. It does not contain the testInit, testTerm or macroVariables. It IS compiled.",
|
||||
"default": "sasjs/tests/testsetup.sas",
|
||||
"examples": ["sasjs/tests/testsetup.sas"]
|
||||
},
|
||||
"testTearDown": {
|
||||
"$id": "#/properties/testConfig/properties/testTearDown",
|
||||
"type": "string",
|
||||
"title": "The jobConfig testTearDown",
|
||||
"description": "The last program to execute as part of 'sasjs test'.",
|
||||
"default": "sasjs/tests/testteardown.sas",
|
||||
"examples": ["sasjs/tests/testteardown.sas"]
|
||||
}
|
||||
}
|
||||
},
|
||||
"macroFolders": {
|
||||
"$id": "#/properties/macroFolders",
|
||||
"type": "array",
|
||||
"title": "The macroFolders array",
|
||||
"description": "These local folders are searched for SAS Macros when running `sasjs compile`. Folders are relative to the `sasjs/sasjsconfig.json` file.",
|
||||
"default": [],
|
||||
"examples": [["macros", "../../more_macros"]]
|
||||
},
|
||||
"programFolders": {
|
||||
"$id": "#/properties/programFolders",
|
||||
"type": "array",
|
||||
"title": "The programFolders array",
|
||||
"description": "These local folders are searched for SAS Programs when running `sasjs compile`. Folders are relative to the `sasjs/sasjsconfig.json` file.",
|
||||
"default": [],
|
||||
"examples": [["programs", "../../more_programs"]]
|
||||
},
|
||||
"syncFolder": {
|
||||
"$id": "#/properties/syncFolder",
|
||||
"type": "string",
|
||||
"title": "Sync Folder",
|
||||
"description": "The contents of this folder are simply copied to the sasjsbuild directory AFTER the rest of the project is compiled. Useful for synchronising random / generic content with SAS logical folders.",
|
||||
"default": "sasjs/static_files"
|
||||
},
|
||||
"syncDirectories": {
|
||||
"$id": "#/properties/syncDirectories",
|
||||
"type": "array",
|
||||
"title": "syncDirectories",
|
||||
"description": "Maps the local filesystem to remote (SAS) physical directories.",
|
||||
"examples": [
|
||||
[
|
||||
{
|
||||
"local": "C:\\temp\\local\\fs1",
|
||||
"remote": "/opt/data/fs1"
|
||||
},
|
||||
{
|
||||
"local": "C:\\temp\\elsewhere",
|
||||
"remote": "/opt/somewhere"
|
||||
}
|
||||
]
|
||||
]
|
||||
},
|
||||
"targets": {
|
||||
"$id": "#/properties/targets",
|
||||
"type": "array",
|
||||
"title": "The targets array",
|
||||
"description": "A target is an alias for a deployment location, and includes at a minimum, the `serverUrl`, `serverType` and `appLoc`. This array allows multiple targets to be defined (eg dev / test / prod). Any properties defined here will override same-named properties in the sasjsconfig root.",
|
||||
"default": [],
|
||||
"examples": [
|
||||
[
|
||||
{
|
||||
"name": "sas9target",
|
||||
"serverType": "SAS9",
|
||||
"serverUrl": "https://mysas9server",
|
||||
"appLoc": "/Shared Folders/myApp"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"name": "viya",
|
||||
"serverType": "SASVIYA",
|
||||
"serverUrl": "https://sas.sasjs.com",
|
||||
"appLoc": "/Public/app",
|
||||
"contextName": "SAS Job Execution compute context",
|
||||
"buildConfig": {
|
||||
"buildOutputFileName": "myviyadeploy.sas",
|
||||
"initProgram": "build/buildinitviya.sas",
|
||||
"termProgram": "targets/viya/viyabuildterm.sas",
|
||||
"macroVars": {
|
||||
"name": "viyavalue",
|
||||
"extravar": "this too"
|
||||
}
|
||||
},
|
||||
"deployConfig": {
|
||||
"deployServicePack": true,
|
||||
"deployScripts": ["sasjsbuild/myviyadeploy.sas"]
|
||||
},
|
||||
"serviceConfig": {
|
||||
"serviceFolders": ["targets/viya/services/admin"],
|
||||
"initProgram": "build/serviceinit.sas",
|
||||
"termProgram": "build/serviceinit.sas",
|
||||
"macroVars": {
|
||||
"name": "viyavalue",
|
||||
"extravar": "this too"
|
||||
}
|
||||
},
|
||||
"streamConfig": {
|
||||
"assetPaths": [],
|
||||
"streamWeb": false,
|
||||
"streamWebFolder": "webv",
|
||||
"webSourcePath": "dist"
|
||||
},
|
||||
"testConfig": {
|
||||
"initProgram": "sasjs/tests/testinit.sas",
|
||||
"termProgram": "sasjs/tests/testterm.sas",
|
||||
"macroVars": {
|
||||
"testVar": "testValue"
|
||||
},
|
||||
"testSetUp": "sasjs/tests/testsetup.sas",
|
||||
"testTearDown": "sasjs/tests/testteardown.sas"
|
||||
},
|
||||
"macroFolders": ["targets/viya/macros"]
|
||||
},
|
||||
{
|
||||
"name": "sas9",
|
||||
"serverType": "SAS9",
|
||||
"serverUrl": "https://sas.sasjs.com:7980",
|
||||
"appLoc": "/User Folders/&sysuserid/My Folder",
|
||||
"serverName": "Foundation",
|
||||
"repositoryName": "SASApp",
|
||||
"buildConfig": {
|
||||
"buildOutputFileName": "mysas9deploy.sas",
|
||||
"initProgram": "",
|
||||
"termProgram": "",
|
||||
"macroVars": {}
|
||||
},
|
||||
"deployConfig": {
|
||||
"deployScripts": ["build/deploysas9.sh"],
|
||||
"deployServicePack": false
|
||||
},
|
||||
"serviceConfig": {
|
||||
"serviceFolders": ["targets/sas9/services/admin"],
|
||||
"initProgram": "",
|
||||
"termProgram": "build/servicetermother.sas",
|
||||
"macroVars": {}
|
||||
},
|
||||
"streamConfig": {
|
||||
"assetPaths": [],
|
||||
"streamWeb": false,
|
||||
"streamWebFolder": "web9",
|
||||
"webSourcePath": "dist"
|
||||
},
|
||||
"testConfig": {
|
||||
"initProgram": "sasjs/tests/testinit.sas",
|
||||
"termProgram": "sasjs/tests/testterm.sas",
|
||||
"macroVars": {
|
||||
"testVar": "testValue"
|
||||
},
|
||||
"testSetUp": "sasjs/tests/testsetup.sas",
|
||||
"testTearDown": "sasjs/tests/testteardown.sas"
|
||||
},
|
||||
"macroFolders": ["targets/sas9/macros"],
|
||||
"programFolders": []
|
||||
}
|
||||
]
|
||||
],
|
||||
"items": {
|
||||
"$id": "#/properties/targets/items",
|
||||
"anyOf": [
|
||||
{
|
||||
"$id": "#/properties/targets/items/anyOf/0",
|
||||
"type": "object",
|
||||
"title": "SASjs Targets",
|
||||
"description": "A target provides the configuration specific to a particular deployment, eg DEV / TEST, or SAS9 / SASVIYA.",
|
||||
"default": {},
|
||||
"examples": [
|
||||
{
|
||||
"name": "viya",
|
||||
"serverType": "SASVIYA",
|
||||
"serverUrl": "https://sas.sasjs.com",
|
||||
"appLoc": "/Public/app",
|
||||
"contextName": "SAS Job Execution compute context",
|
||||
"buildConfig": {
|
||||
"buildOutputFileName": "myviyadeploy.sas",
|
||||
"initProgram": "build/buildinitviya.sas",
|
||||
"termProgram": "targets/viya/viyabuildterm.sas",
|
||||
"macroVars": {
|
||||
"name": "viyavalue",
|
||||
"extravar": "this too"
|
||||
}
|
||||
},
|
||||
"deployConfig": {
|
||||
"deployServicePack": true,
|
||||
"deployScripts": ["sasjsbuild/myviyadeploy.sas"]
|
||||
},
|
||||
"serviceConfig": {
|
||||
"serviceFolders": ["targets/viya/services/admin"],
|
||||
"initProgram": "build/serviceinit.sas",
|
||||
"termProgram": "build/serviceinit.sas",
|
||||
"macroVars": {
|
||||
"name": "viyavalue",
|
||||
"extravar": "this too"
|
||||
}
|
||||
},
|
||||
"jobConfig": {
|
||||
"jobFolders": [],
|
||||
"initProgram": "",
|
||||
"termProgram": "",
|
||||
"macroVars": {}
|
||||
},
|
||||
"streamConfig": {
|
||||
"assetPaths": [],
|
||||
"streamWeb": false,
|
||||
"streamWebFolder": "webv",
|
||||
"webSourcePath": "dist"
|
||||
},
|
||||
"testConfig": {
|
||||
"initProgram": "sasjs/tests/testinit.sas",
|
||||
"termProgram": "sasjs/tests/testterm.sas",
|
||||
"macroVars": {
|
||||
"testVar": "testValue"
|
||||
},
|
||||
"testSetUp": "sasjs/tests/testsetup.sas",
|
||||
"testTearDown": "sasjs/tests/testteardown.sas"
|
||||
},
|
||||
"macroFolders": ["targets/viya/macros"],
|
||||
"programFolders": []
|
||||
}
|
||||
],
|
||||
"required": ["name", "serverType", "appLoc"],
|
||||
"properties": {
|
||||
"name": {
|
||||
"$id": "#/properties/targets/items/anyOf/0/properties/name",
|
||||
"type": "string",
|
||||
"title": "Target name property",
|
||||
"description": "A target name can only contain alphanumeric characters and dashes. It cannot contain spaces. It is used as the alias when referencing the target using the `-t` attribute in many of the SASjs commands.",
|
||||
"default": "",
|
||||
"examples": ["viya"]
|
||||
},
|
||||
"serverType": {
|
||||
"$id": "#/properties/targets/items/anyOf/0/properties/serverType",
|
||||
"type": "string",
|
||||
"title": "The Target serverType",
|
||||
"description": "The serverType can be either SAS9, SASVIYA or SASJS.",
|
||||
"default": "",
|
||||
"examples": ["SASVIYA"]
|
||||
},
|
||||
"appLoc": {
|
||||
"$id": "#/properties/targets/items/anyOf/0/properties/appLoc",
|
||||
"type": "string",
|
||||
"title": "The Target appLoc",
|
||||
"description": "The appLoc provides the root SAS folder location under which all jobs and services are deployed and executed. The SAS folder could be metadata in SAS 9, or SAS Drive in Viya. ",
|
||||
"default": "",
|
||||
"examples": ["/Public/app"]
|
||||
},
|
||||
"binaryFolders": {
|
||||
"$ref": "#/properties/binaryFolders"
|
||||
},
|
||||
"buildConfig": {
|
||||
"$ref": "#/properties/buildConfig"
|
||||
},
|
||||
"contextName": {
|
||||
"$id": "#/properties/targets/items/anyOf/0/properties/contextName",
|
||||
"type": "string",
|
||||
"title": "The Target contextName",
|
||||
"description": "The name of the compute context used to execute SAS code. The context determines the way in which the SAS session is spawned (eg user credentials, autoexec code, system options etc).\nContexts can be created / modified / deleted using the `sasjs context` command.",
|
||||
"default": "SAS Job Execution compute context",
|
||||
"examples": ["SAS Job Execution compute context"]
|
||||
},
|
||||
"deployConfig": {
|
||||
"$ref": "#/properties/deployConfig"
|
||||
},
|
||||
"httpsAgentOptions": {
|
||||
"$ref": "#/properties/httpsAgentOptions"
|
||||
},
|
||||
"serverUrl": {
|
||||
"$id": "#/properties/targets/items/anyOf/0/properties/serverUrl",
|
||||
"type": "string",
|
||||
"title": "The Target serverUrl",
|
||||
"description": "The serverUrl is the location to which the app is deployed, and against which any server based operations are performed. If SAS is served from a particular port, that port should also be included here.",
|
||||
"default": "",
|
||||
"examples": [
|
||||
"https://sas.sasjs.com",
|
||||
"https://sas.sasjs.com:8080"
|
||||
]
|
||||
},
|
||||
"serviceConfig": {
|
||||
"$ref": "#/properties/serviceConfig"
|
||||
},
|
||||
"jobConfig": {
|
||||
"$ref": "#/properties/jobConfig"
|
||||
},
|
||||
"docConfig": {
|
||||
"$ref": "#/properties/docConfig"
|
||||
},
|
||||
"streamConfig": {
|
||||
"$ref": "#/properties/streamConfig"
|
||||
},
|
||||
"syncDirectories": {
|
||||
"$ref": "#/properties/syncDirectories"
|
||||
},
|
||||
"syncFolder": {
|
||||
"$ref": "#/properties/syncFolder"
|
||||
},
|
||||
"testConfig": {
|
||||
"$ref": "#/properties/testConfig"
|
||||
},
|
||||
"macroFolders": {
|
||||
"$ref": "#/properties/macroFolders"
|
||||
},
|
||||
"programFolders": {
|
||||
"$ref": "#/properties/programFolders"
|
||||
},
|
||||
"sasjsBuildFolder": {
|
||||
"$ref": "#properties/sasjsBuildFolder"
|
||||
},
|
||||
"sasjsResultsFolder": {
|
||||
"$ref": "#properties/sasjsResultsFolder"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
---
|
||||
name: sasjs-server
|
||||
description: Installing, configuring, and running @sasjs/server — the open-source NodeJS wrapper around the SAS binary that provides a REST API, filesystem (SASjs Drive), Stored Program execution, and web app streaming. Covers desktop vs server modes, runtimes (SAS/JS/Python/R), env vars, auth (tokens, LDAP), and mock servers. Use when deploying, troubleshooting, or developing against sasjs/server.
|
||||
---
|
||||
|
||||
# @sasjs/server
|
||||
|
||||
SASjs Server is an open-source NodeJS wrapper for calling the SAS binary executable. It runs on a real SAS server or a local desktop and provides:
|
||||
|
||||
- A filesystem (SASjs Drive) for storing SAS programs and content
|
||||
- Execution of Stored Programs from a URL (equivalent to SAS 9 Stored Processes / Viya Jobs)
|
||||
- Web app streaming (serve frontend apps straight from SAS content)
|
||||
- A REST API with Swagger docs
|
||||
- Portability: apps built for SASjs Server deploy unchanged to SAS 9 / Viya via @sasjs/cli
|
||||
|
||||
## Modes
|
||||
|
||||
- **Desktop mode** (`MODE=desktop`, default): single-user, no authentication, no database. CORS enabled by default.
|
||||
- **Server mode** (`MODE=server`): multi-user with authentication, requires a database (`DB_CONNECT`, `DB_TYPE=mongodb|cosmos_mongodb`). CORS disabled by default — configure `WHITELIST` if enabling.
|
||||
|
||||
## Installation
|
||||
|
||||
Download the relevant zip from GitHub releases and run the packaged executable (`api-linux`, etc.):
|
||||
|
||||
```bash
|
||||
curl -L https://github.com/sasjs/server/releases/latest/download/linux.zip > linux.zip
|
||||
unzip linux.zip && ./api-linux
|
||||
```
|
||||
|
||||
On first run it prompts (unless set as env vars) for the SAS executable path and the filesystem location for Stored Programs/temp files. Docker is also supported (`DockerfileApi`, docker-compose files in the repo).
|
||||
|
||||
## Configuration via environment variables
|
||||
|
||||
Set in `/etc/environment`, exported, prepended to the command, or in a `.env` file alongside the executable. Key variables:
|
||||
|
||||
| Variable | Purpose |
|
||||
|---|---|
|
||||
| `MODE` | `desktop` (default) or `server` |
|
||||
| `SAS_PATH` | Path to `sas.exe` / `sas.sh` |
|
||||
| `RUN_TIMES` | Comma-separated runtime priority, e.g. `sas,js,py` — options: `sas`, `js`, `py`, `r`. Each needs its path: `SAS_PATH`, `NODE_PATH`, `PYTHON_PATH`, `R_PATH` |
|
||||
| `SASJS_ROOT` | Working directory: SAS WORK, staged files, drive, config |
|
||||
| `DRIVE_LOCATION` | Location for files, sasjs packages, `appStreamConfig.json` |
|
||||
| `PROTOCOL` / `PORT` | `http` (default) or `https` (needs `PRIVATE_KEY`, `CERT_CHAIN`, optional `CA_ROOT`); default port 5000 |
|
||||
| `SAS_OPTIONS` / `SASV9_OPTIONS` | Extra SAS system options auto-applied to sessions (Windows vs Unix), e.g. `-NOXCMD` |
|
||||
| `DB_CONNECT` / `DB_TYPE` | MongoDB connection string / type — required for server mode |
|
||||
| `AUTH_PROVIDERS` + `LDAP_*` | LDAP auth: `LDAP_URL`, `LDAP_BIND_DN`, `LDAP_BIND_PASSWORD`, `LDAP_USERS_BASE_DN`, `LDAP_GROUPS_BASE_DN` |
|
||||
| `CORS` / `WHITELIST` | CORS is only applied when `CORS=enable`, and only origins in `WHITELIST` (space-separated) receive `Access-Control-Allow-Origin` — an empty whitelist means NO cross-origin calls work |
|
||||
| `MOCK_SERVERTYPE` / `STATIC_MOCK_LOCATION` | Emulate `sas9`/`sasviya` API responses for frontend testing against a sasjs server (static canned files only — no logic) |
|
||||
|
||||
## Developing against the API
|
||||
|
||||
- Server type for @sasjs/adapter / CLI targets is `SASJS` (`serverType: 'SASJS'`); auth is token-based.
|
||||
- The REST API is self-documented via Swagger on the running instance.
|
||||
- Server-side execution uses `ms_*` macros from @sasjs/core (e.g. `ms_createfile`, `ms_adduser2group`) — services/jobs deployed by the CLI work as on other platforms.
|
||||
- Repo layout (for contributors): `api/` (Express/TypeScript backend: controllers, routes, middlewares, model), `web/` (frontend), `restClient/` (REST examples), `mongo-seed/` (server-mode DB seed).
|
||||
|
||||
## Mock services with the JS runtime (no SAS required)
|
||||
|
||||
With `RUN_TIMES=js` (and `NODE_PATH` set), any `.js` file on SASjs Drive is an executable Stored Program — this is how react-seed-app / Data Controller provide **mock backends** for frontend development. Desktop mode (`MODE=desktop`) has no auth, which makes local mocking trivial.
|
||||
|
||||
Writing a JS stored program (docs: https://server.sasjs.io/storedprograms/#js-programs):
|
||||
|
||||
- The runtime template predeclares `const fs = require('fs')`, `_program`, `weboutPath`, `_SASJS_TOKENFILE`, `_SASJS_WEBOUT_HEADERS`, `_SASJS_USERNAME` / `_SASJS_USERID` / `_SASJS_DISPLAYNAME`, `_METAPERSON`, `_METAUSER`, `SASJSPROCESSMODE`. **Do NOT redeclare `fs`** — `const fs = require('fs')` in your program crashes it with `Identifier 'fs' has already been declared`.
|
||||
- Output: assign a JSON **string** to `_webout` (e.g. `_webout = JSON.stringify({...})`); it is written back only if non-empty. `console.log()` output is returned in the response `log` (like a SAS log). Custom response headers can be written as lines to the `_SASJS_WEBOUT_HEADERS` file.
|
||||
- Mimic real services by including the standard SASjs automatic fields in the JSON: `_PROGRAM` (from `_program`), `SYSDATE` / `SYSTIME` (format `DDMMMYY` / `HH:mm`), `_METAUSER`, `SASJSPROCESSMODE`.
|
||||
- URL/body parameters arrive as `const <name> = \`<value>\`` strings.
|
||||
- Input tables (the `sasjs_tables` mechanism) arrive **either** as an inline CSV const **or** — when the adapter sends multipart — as an uploaded `<name>.csv` file in the session folder, referenced by generated module-scope consts (handle BOTH):
|
||||
- `_WEBIN_FILE_COUNT` (always created), `_WEBIN_NAME<n>` (table/field name), `_WEBIN_FILENAME<n>` (original filename), `_WEBIN_FILEREF<n>` (file **contents**, a Buffer from `fs.readFileSync` — call `.toString('utf8')`)
|
||||
- these consts are **not on `globalThis`** — look them up with `typeof` guards or direct `eval()` in module scope (server-side JS, no CSP)
|
||||
- adapter CSV quirks: header row is **space-separated** `name:format.` entries (e.g. `rootdir:$char256.`) — strip the `:format` suffix; lines end CRLF; values containing special characters are wrapped in double quotes with `""` escaping
|
||||
- Adapter response shape: `sasjs.request()` resolves with the webout JSON **already unwrapped** — output tables are arrays of row objects directly on the response (`res.mytable[0].COL`). A table named `result` is perfectly fine (`res.result` is then that array); do NOT add your own `res.result`-unwrapping layer, it breaks exactly that case.
|
||||
- Third-party npm packages are NOT resolvable at runtime — bundle the service first (e.g. `npx webpack --mode none --target node --entry <file> --output-path sasjsbuild/... --output-filename <name>.js`), then `sasjs build` / `sasjs deploy`.
|
||||
|
||||
Deploying mocks:
|
||||
|
||||
- `sasjs fs sync` does NOT work on a JS-only server (it generates and executes SAS code to hash remote files). Upload files directly via the Drive API instead: `DELETE` then `POST /SASjsApi/drive/file?_filePath=<appLoc>/services/<folder>/<name>.js` (multipart `file` field). In desktop mode no auth headers are needed; in server mode read the `Authorization` header line from `_SASJS_TOKENFILE`.
|
||||
- Mocks can be stateful with the predeclared `fs`. Prefer real locations over `/tmp`: the SASjs Drive root is derivable from `weboutPath` (`<root>/sessions/<id>/webout.txt` → `path.resolve(weboutPath, '..', '..', '..', 'drive')`), and a mock `configure`-style service can treat a configured folder as a real local path (the server IS local). `require('path')` and other core modules work (only `fs` is predeclared).
|
||||
- A JS program can even call the server's own REST API (`http://127.0.0.1:$PORT/SASjsApi/...`) — e.g. to rewrite a streamed `index.html` on the Drive (`GET` + `PATCH /SASjsApi/drive/file`).
|
||||
|
||||
Gotchas:
|
||||
|
||||
- The packaged binaries (`api-linux` etc.) reject some globally-exported `NODE_OPTIONS` (e.g. `--network-family-autoselection`) — start with `NODE_OPTIONS="" ./api-linux`.
|
||||
- AppStream URLs redirect to a trailing slash (`/AppStream/MyApp` → 301 → `/AppStream/MyApp/`) — test/automation scripts should use the trailing-slash URL directly.
|
||||
+36
-11
@@ -3,6 +3,42 @@
|
||||
# Using `--silent` helps for showing any errs in the first line of the response
|
||||
# The first line is picked up by the VS Code GIT UI popup when rc is not 0
|
||||
|
||||
# Scan staged changes for secrets before anything else runs.
|
||||
# The binary is pinned by the @nogoo9/gitleaks devDependency and lands
|
||||
# in node_modules/.bin after npm i. Commits are blocked until it is
|
||||
# installed so no clone silently skips the secrets scan.
|
||||
gitleaks_bin=node_modules/.bin/gitleaks
|
||||
|
||||
if [ ! -x "$gitleaks_bin" ]; then
|
||||
echo "❌ gitleaks not found - run 'npm i' to install it"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! "$gitleaks_bin" protect --staged --redact; then
|
||||
echo "❌ gitleaks detected a potential secret in your staged changes"
|
||||
echo "Remove the secret, or add a .gitleaksignore entry if it is a false positive"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## Avoid large commits
|
||||
# https://www.backblaze.com/blog/how-many-bytes-are-in-a-megabyte-really/
|
||||
size_limit=$((2 * 1024 * 1024)) # 2MB
|
||||
# Sum the sizes of the blobs this commit would introduce: the staged
|
||||
# added/copied/modified/renamed/typechanged entries in the index.
|
||||
# https://git-scm.com/docs/git-cat-file#Documentation/git-cat-file.txt---batch-check
|
||||
# Renames are treated as add+delete (--no-renames) and pure mode changes
|
||||
# (same blob, different permissions) add no new blob, so both are safe.
|
||||
commit_size=$(git diff --cached --raw --no-renames --diff-filter=ACMRT |
|
||||
awk '$3 != $4 { print $4 }' |
|
||||
git cat-file --batch-check='%(objectsize)' |
|
||||
awk '{ s += $1 } END { print s + 0 }')
|
||||
|
||||
if [ "$commit_size" -ge "$size_limit" ]; then
|
||||
echo "Commit size is too large: $commit_size > $size_limit"
|
||||
echo "Force commit using --no-verify"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if npm run --silent lint:check:silent ; then
|
||||
exit 0
|
||||
else
|
||||
@@ -10,14 +46,3 @@ else
|
||||
echo "❌ Prettier check failed! We ran lint:fix for you. Please add & commit again."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## Avoid large commits
|
||||
# https://www.backblaze.com/blog/how-many-bytes-are-in-a-megabyte-really/
|
||||
size_limit=$((2 * 2**20)) # 2mbs
|
||||
# https://git-scm.com/docs/git-rev-list#Documentation/git-rev-list.txt---disk-usage
|
||||
commit_size=$(git rev-list --disk-usage HEAD^..HEAD)
|
||||
test "$commit_size" -lt "$size_limit" || (
|
||||
echo "Commit size is too large: $commit_size > $size_limit"
|
||||
echo "Force commit using --no-verify"
|
||||
exit 1
|
||||
)
|
||||
@@ -125,8 +125,16 @@ jobs:
|
||||
cd ./sas/mocks/sasjs
|
||||
npm install -g @sasjs/cli
|
||||
npm install -g replace-in-files-cli
|
||||
# Remove any previous deployment (drive folder delete API) so the
|
||||
# deploy and makedata start from a clean appLoc
|
||||
curl -sS -X DELETE "http://localhost:5000/SASjsApi/drive/folder/?_folderPath=/Public/app/dc"
|
||||
sasjs cbd -t server-ci
|
||||
# sasjs request services/admin/makedata -t server-ci -d ./deploy/makeData4GL.json -c ./deploy/requestConfig.json -o ./output.json
|
||||
# Seed the DC database (mock data files on the drive).
|
||||
# makedata replies with HTML (it is normally called as a URL redirect),
|
||||
# which the CLI reports as "invalid Json string" - ignore that.
|
||||
# NOTE: -d paths resolve from the sasjs project root (sas/mocks),
|
||||
# not the cwd (sas/mocks/sasjs).
|
||||
sasjs request services/admin/makedata -t server-ci -d deploy/makedata.json -o ./makedata_out.json || true
|
||||
|
||||
- name: Prepare and run frontend and cypress
|
||||
timeout-minutes: 35
|
||||
@@ -139,14 +147,14 @@ jobs:
|
||||
npm run postinstall
|
||||
# Prepare index.html to SASJS local
|
||||
replace-in-files --regex='serverUrl=".*?"' --replacement='serverUrl="http://localhost:5000"' ./src/index.html
|
||||
replace-in-files --regex='appLoc=".*?"' --replacement='appLoc="/Public/app/devtest"' ./src/index.html
|
||||
replace-in-files --regex='appLoc=".*?"' --replacement='appLoc="/Public/app/dc"' ./src/index.html
|
||||
replace-in-files --regex='serverType=".*?"' --replacement='serverType="SASJS"' ./src/index.html
|
||||
replace-in-files --regex='"hosturl".*' --replacement='hosturl:"http://localhost:4200",' ./cypress.config.ts
|
||||
cat ./cypress.config.ts
|
||||
# Start frontend and run cypress
|
||||
# timeout 1800: SIGTERM after 30 min so Cypress can flush video/screenshots
|
||||
# before the outer timeout-minutes hard-kills the step (avoids silent multi-hour hangs)
|
||||
npx ng serve --host 0.0.0.0 --port 4200 & npx wait-on http://localhost:4200 && timeout 1800 npx cypress run --browser chrome --spec "cypress/e2e/csv-limited.cy.ts,cypress/e2e/liveness.cy.ts,cypress/e2e/editor.cy.ts,cypress/e2e/excel-multi-load.cy.ts,cypress/e2e/excel.cy.ts,cypress/e2e/csv.cy.ts,cypress/e2e/filtering.cy.ts,cypress/e2e/licensing.cy.ts,cypress/e2e/viewer-labels.cy.ts,cypress/e2e/viewbox.cy.ts"
|
||||
npx ng serve --host 0.0.0.0 --port 4200 & npx wait-on http://localhost:4200 && timeout 1800 npx cypress run --browser chrome --spec "cypress/e2e/csv-limited.cy.ts,cypress/e2e/liveness.cy.ts,cypress/e2e/editor.cy.ts,cypress/e2e/excel-multi-load.cy.ts,cypress/e2e/excel.cy.ts,cypress/e2e/csv.cy.ts,cypress/e2e/filtering.cy.ts,cypress/e2e/licensing.cy.ts,cypress/e2e/viewer-labels.cy.ts,cypress/e2e/viewbox.cy.ts,cypress/e2e/stage.cy.ts"
|
||||
|
||||
- name: Zip Cypress videos
|
||||
if: always()
|
||||
|
||||
@@ -125,8 +125,16 @@ jobs:
|
||||
cd ./sas/mocks/sasjs
|
||||
npm install -g @sasjs/cli
|
||||
npm install -g replace-in-files-cli
|
||||
# Remove any previous deployment (drive folder delete API) so the
|
||||
# deploy and makedata start from a clean appLoc
|
||||
curl -sS -X DELETE "http://localhost:5000/SASjsApi/drive/folder/?_folderPath=/Public/app/dc"
|
||||
sasjs cbd -t server-ci
|
||||
# sasjs request services/admin/makedata -t server-ci -d ./deploy/makeData4GL.json -c ./deploy/requestConfig.json -o ./output.json
|
||||
# Seed the DC database (mock data files on the drive).
|
||||
# makedata replies with HTML (it is normally called as a URL redirect),
|
||||
# which the CLI reports as "invalid Json string" - ignore that.
|
||||
# NOTE: -d paths resolve from the sasjs project root (sas/mocks),
|
||||
# not the cwd (sas/mocks/sasjs).
|
||||
sasjs request services/admin/makedata -t server-ci -d deploy/makedata.json -o ./makedata_out.json || true
|
||||
|
||||
- name: Prepare and run frontend and cypress
|
||||
run: |
|
||||
@@ -138,12 +146,12 @@ jobs:
|
||||
npm run postinstall
|
||||
# Prepare index.html to SASJS local
|
||||
replace-in-files --regex='serverUrl=".*?"' --replacement='serverUrl="http://localhost:5000"' ./src/index.html
|
||||
replace-in-files --regex='appLoc=".*?"' --replacement='appLoc="/Public/app/devtest"' ./src/index.html
|
||||
replace-in-files --regex='appLoc=".*?"' --replacement='appLoc="/Public/app/dc"' ./src/index.html
|
||||
replace-in-files --regex='serverType=".*?"' --replacement='serverType="SASJS"' ./src/index.html
|
||||
replace-in-files --regex='"hosturl".*' --replacement='hosturl:"http://localhost:4200",' ./cypress.config.ts
|
||||
cat ./cypress.config.ts
|
||||
# Start frontend and run cypress
|
||||
npx ng serve --host 0.0.0.0 --port 4200 & npx wait-on http://localhost:4200 && npx cypress run --browser chrome --spec "cypress/e2e/csv-limited.cy.ts,cypress/e2e/liveness.cy.ts,cypress/e2e/editor.cy.ts,cypress/e2e/excel-multi-load.cy.ts,cypress/e2e/excel.cy.ts,cypress/e2e/csv.cy.ts,cypress/e2e/filtering.cy.ts,cypress/e2e/licensing.cy.ts,cypress/e2e/viewer-labels.cy.ts"
|
||||
npx ng serve --host 0.0.0.0 --port 4200 & npx wait-on http://localhost:4200 && npx cypress run --browser chrome --spec "cypress/e2e/csv-limited.cy.ts,cypress/e2e/liveness.cy.ts,cypress/e2e/editor.cy.ts,cypress/e2e/excel-multi-load.cy.ts,cypress/e2e/excel.cy.ts,cypress/e2e/csv.cy.ts,cypress/e2e/filtering.cy.ts,cypress/e2e/licensing.cy.ts,cypress/e2e/viewer-labels.cy.ts,cypress/e2e/viewbox.cy.ts,cypress/e2e/stage.cy.ts"
|
||||
|
||||
- name: Zip Cypress videos
|
||||
if: always()
|
||||
|
||||
+3
-1
@@ -22,4 +22,6 @@ sasjsresults
|
||||
.sasjsrc
|
||||
client/.npmrc
|
||||
*~
|
||||
.lighthouseci
|
||||
.lighthouseci
|
||||
audit.log
|
||||
tmp/
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
# Agent Instructions
|
||||
|
||||
Read **`CONTEXT.md`** at the repo root first - it is the domain glossary and orientation for Data Controller (roles, load types, MPE control tables, validations, security). Use its vocabulary in your output.
|
||||
|
||||
## Related repositories
|
||||
|
||||
Data Controller spans three sibling repos (usually checked out side by side):
|
||||
|
||||
- **`dc`** (this repo) - the product source (Angular client + SAS backend).
|
||||
- **`docs.datacontroller.io`** - the user-facing product documentation (MkDocs). User-facing behaviour is documented there; the `.agents/docs/` deep-dives here link out to it.
|
||||
- **`datacontroller.io`** - the marketing site, blog and feed (Gatsby).
|
||||
|
||||
## Git
|
||||
|
||||
Do NOT auto-commit. Never run `git commit` (or `git push`) unless the user explicitly asks. Leave changes in the working tree for the user to review and commit themselves.
|
||||
|
||||
## CHANGELOG and versioning
|
||||
|
||||
Do NOT edit `CHANGELOG.md` by hand, and do NOT bump the `version` in `package.json`. The release pipeline (semantic-release, in `.gitea/workflows/release.yaml`) generates both automatically from Conventional Commit messages on every push to `main`. Manual entries collide with the pipeline's release commit and are overwritten anyway. Control the changelog through your commit messages instead. See `.agents/docs/releases-and-changelog.md`.
|
||||
|
||||
## Markdown files
|
||||
|
||||
Do NOT hard-wrap Markdown files (no fixed-width line wrapping / carriage returns inside paragraphs). Each paragraph, list item, and heading should be a single logical line, regardless of length. Let the editor/viewer soft-wrap. This includes AGENTS.md itself.
|
||||
@@ -23,9 +37,11 @@ Never consider a change complete until the relevant linters pass on the files yo
|
||||
|
||||
Data Controller must run entirely locally (offline / on-prem, no internet access). The built product must never fetch assets from remote servers — no external fonts, images, scripts, stylesheets, CDN links, or remote URLs in meta tags (e.g. `og:image`, `og:url`, `itemprop="image"`). All assets must be bundled and served locally.
|
||||
|
||||
## The .agent folder
|
||||
## The .agents folder
|
||||
|
||||
Agent-related content lives in `.agent/`: technical/agent-facing documentation goes in `.agent/docs/` (not `docs/`), and skills in `.agent/skills/`. When writing explanatory or technical docs about the codebase, put them in `.agent/docs/`.
|
||||
Agent-related content lives in `.agents/`: technical/agent-facing documentation goes in `.agents/docs/` (not `docs/`), and skills in `.agents/skills/`. When writing explanatory or technical docs about the codebase, put them in `.agents/docs/`.
|
||||
|
||||
Skills installed via `npx skills add` are tracked in `skills-lock.json` and live under `.agents/skills/`. Repo-local custom skills (e.g. `dc-sas` for Data Controller SAS development, `handsontable`, `hyperformula`) are kept here too. Avoid editing npx-managed skill files directly — use `npx skills update` instead.
|
||||
|
||||
## Code comments and test names
|
||||
|
||||
|
||||
@@ -1,3 +1,97 @@
|
||||
# [7.14.0](https://git.datacontroller.io/dc/dc/compare/v7.13.0...v7.14.0) (2026-09-04)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **system:** show session timezone on system information screen ([966dc07](https://git.datacontroller.io/dc/dc/commit/966dc072e0cb8bb44bd93a7682c3d7335428d688))
|
||||
|
||||
# [7.13.0](https://git.datacontroller.io/dc/dc/compare/v7.12.0...v7.13.0) (2026-09-03)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* dynamic js mocks ([3b9344c](https://git.datacontroller.io/dc/dc/commit/3b9344cb602b609774737dcbb6df6756a2a08edb))
|
||||
* adding formula types ([c07a01a](https://git.datacontroller.io/dc/dc/commit/c07a01a38da6a6e4edaf014ef2fd4d2691b29698))
|
||||
* address hermes review feedback (formula quoting, cell revert, addRow guard) ([36963aa](https://git.datacontroller.io/dc/dc/commit/36963aa74627b861aee9ec91428a8dbee0946dfc))
|
||||
* agent skills and nextviya deploys ([f7db871](https://git.datacontroller.io/dc/dc/commit/f7db8719f5fe860605f4e6da81bad925d7412599))
|
||||
* bump core for mp_validate fix ([5a44b28](https://git.datacontroller.io/dc/dc/commit/5a44b2804feddbd616ece1d721865e02bfbedda8))
|
||||
* CAS support for REPLACE type plus docs ([ea05f07](https://git.datacontroller.io/dc/dc/commit/ea05f0718047a0ac54cffc58938b6d06f5a112e2))
|
||||
* clarify debug comment is permanent, extend ComputeContextDetails with Viya response fields ([72484ae](https://git.datacontroller.io/dc/dc/commit/72484ae8441715813983faa221be348cf421b735))
|
||||
* core major bump plus autofix of viya context on deploy ([6527c10](https://git.datacontroller.io/dc/dc/commit/6527c10f262249187c27723d983edd32c3848d72))
|
||||
* **core:** bump to v5 (breaking change) ([59e9e96](https://git.datacontroller.io/dc/dc/commit/59e9e96f5a6a6c9c0560cbb8387982611a0c8ca4))
|
||||
* **cypress:** correct mock data, test expectations, and abort modal ([13c10be](https://git.datacontroller.io/dc/dc/commit/13c10be30faae736d27b584e0507eaab702d2d32))
|
||||
* **cypress:** make licensing combined-key tests order-independent ([4db8d62](https://git.datacontroller.io/dc/dc/commit/4db8d62dca9257764438b00ef034103a0703111a))
|
||||
* **deploy:** Viya deploy checks, startup diagnostics, and chunked deploy script ([917925f](https://git.datacontroller.io/dc/dc/commit/917925f55393aca919c2a7c7cd7dbecadbc24ace)), closes [#303](https://git.datacontroller.io/dc/dc/issues/303) [#200](https://git.datacontroller.io/dc/dc/issues/200) [#125](https://git.datacontroller.io/dc/dc/issues/125)
|
||||
* **deps:** align @angular/* packages to the same lockstep version ([24e6297](https://git.datacontroller.io/dc/dc/commit/24e62971879e61eef0fc3ea9f07796b92231dbe3))
|
||||
* **deps:** override nanoid to 3.3.18 in sas/ ([d57ae03](https://git.datacontroller.io/dc/dc/commit/d57ae03fc44770f41de5dbe0389d33cd11fc0971))
|
||||
* **deps:** pin @handsontable/angular-wrapper to 18.0.0 ([2d7df66](https://git.datacontroller.io/dc/dc/commit/2d7df66fc28ffe07e859920c052b9818ed58647f))
|
||||
* **deps:** pin babel-loader to resolve an unresolvable peer conflict ([3bf3bf0](https://git.datacontroller.io/dc/dc/commit/3bf3bf0dde943246380528d5af7c46ad1f518c79))
|
||||
* **deps:** regenerate lockfile with Node 24 and pin handsontable to 18.0.0 ([7da29bd](https://git.datacontroller.io/dc/dc/commit/7da29bdb1180a9f50055380c1df3649283e9cdf6))
|
||||
* **deps:** regenerate lockfile with strict peer-dep resolution to fix npm ci in CI ([efd2e18](https://git.datacontroller.io/dc/dc/commit/efd2e18c7b09f80655528a2f6985034f5a41dcf3))
|
||||
* **deps:** regenerate package-lock.json to resolve npm ci sync errors ([a501903](https://git.datacontroller.io/dc/dc/commit/a501903e6d4276f1b4eba8f8ae0feccafcfbcf86))
|
||||
* **deps:** resolve npm audit findings and align @angular/* to the same lockstep version ([b9e4b27](https://git.datacontroller.io/dc/dc/commit/b9e4b2733fa01e2b8060dab54277000a2c6252b8))
|
||||
* **deps:** resolve npm audit findings via direct lockfile patch, not regeneration ([4d1bfa6](https://git.datacontroller.io/dc/dc/commit/4d1bfa6343342a167bdc315204866a18bcbca8ed))
|
||||
* **deps:** resolve npm audit vulnerabilities in production dependencies ([257f69c](https://git.datacontroller.io/dc/dc/commit/257f69ccc6dd070daf8c73f597a08d01e8ea6888))
|
||||
* **deps:** scope the brace-expansion override to its actual vulnerable chain ([f9d061c](https://git.datacontroller.io/dc/dc/commit/f9d061c48901d9ef131303940f0c2e2948b12fdf))
|
||||
* dynamic getdynamiccolvals.js ([d59ef44](https://git.datacontroller.io/dc/dc/commit/d59ef442266bd4823f5cad3f7f4985e3df9afb48))
|
||||
* **editor:** clear sort before reading cells to preserve on cancel ([4137ebd](https://git.datacontroller.io/dc/dc/commit/4137ebdf6b6563eeac4f805708c3b4ffcd099fb1))
|
||||
* **editor:** escape formula-looking values in uploaded Excel data ([e69df3d](https://git.datacontroller.io/dc/dc/commit/e69df3deb22d80b1371b63a5ae1c6a44538b00bc))
|
||||
* **editor:** fix formula $-substitution corruption and sorted-grid row/formula desync ([e139c37](https://git.datacontroller.io/dc/dc/commit/e139c37fbfe46123cce2cbfcf7e919bc68e19a2f))
|
||||
* **editor:** let the column info dropdown's text be selected and copied ([1e516f4](https://git.datacontroller.io/dc/dc/commit/1e516f4012947c3f42dec1f3a46fa364c39bfe3e))
|
||||
* **editor:** re-mark a reverted cell as auto-escaped so "Apply as formula" works again ([12091c4](https://git.datacontroller.io/dc/dc/commit/12091c4044b0982c36b7d6011b51625bfb6b8cb5))
|
||||
* **editor:** resolve a primary key's live formula to its computed value, not the raw formula text ([d72e19a](https://git.datacontroller.io/dc/dc/commit/d72e19a3086ef578a1304fe032e1088c6ef60cf7))
|
||||
* **editor:** resolve computed value for a live formula in numeric columns too ([2cc8489](https://git.datacontroller.io/dc/dc/commit/2cc8489892638aaf97fd5999ebc6086ffd674a76))
|
||||
* **editor:** restore multi-column sort with one call, not a loop ([8fafeb7](https://git.datacontroller.io/dc/dc/commit/8fafeb7923bc7dae178c4fed0898195d5b5825a6))
|
||||
* **editor:** size table-header buttons and title to content, not fixed grid thirds ([d0a7561](https://git.datacontroller.io/dc/dc/commit/d0a7561f1aeb67b214e6a473cc6235509daa80bb))
|
||||
* **editor:** stop dc.row_status from being submitted to the backend ([dc0f6a7](https://git.datacontroller.io/dc/dc/commit/dc0f6a7baa128e0b75d7341ac7c03dcd4b1ffee5))
|
||||
* **editor:** stop turning missing columns into undefined, and fix column lookup for sparse rows ([a104f78](https://git.datacontroller.io/dc/dc/commit/a104f78645bc7777fee672956d3f028ff52ed9ba))
|
||||
* **editor:** submit a live formula's computed value, not its raw text ([b7d3106](https://git.datacontroller.io/dc/dc/commit/b7d31066ae5272856ea442d0f76d2f0752015dbb))
|
||||
* ensure cleanup of casuser temp table in error condition ([c4123e5](https://git.datacontroller.io/dc/dc/commit/c4123e5c965ba3f78ec8cf32f915f263d218ca56))
|
||||
* ensuring formats arrive from backend in getstagetable.sas ([daacb49](https://git.datacontroller.io/dc/dc/commit/daacb49c8a2c6a266dd842a8b7ccdebaa992a1d7))
|
||||
* escape regex metacharacters in context name before prxchange ([9023eb2](https://git.datacontroller.io/dc/dc/commit/9023eb2a393ee8441bab5b9c5ff4f53b500e0e91))
|
||||
* failing test ([f213d24](https://git.datacontroller.io/dc/dc/commit/f213d24f096d814d286bfdac5a28748e97e7293f))
|
||||
* fixed npm vuln ([26b55b1](https://git.datacontroller.io/dc/dc/commit/26b55b1bde5e28afde2d4f9889cb452985410c1d))
|
||||
* **formulas:** avoid EDIT_STATUS colliding with a real column of that name ([acb97f4](https://git.datacontroller.io/dc/dc/commit/acb97f4bfb1c7d6a0b38dd33207170f6ec2bbd1d))
|
||||
* hardening following PR review feedback ([1f4aa6f](https://git.datacontroller.io/dc/dc/commit/1f4aa6fceafc4b51ecc5a19f4789cf5bd018a5d3))
|
||||
* history mock ([0082828](https://git.datacontroller.io/dc/dc/commit/00828285435a412e3e5dccb045b053c1096e8876))
|
||||
* **licensing:** bridge async proceed() through cy.then and replace Response.arrayBuffer with manual stream reader ([8e51fde](https://git.datacontroller.io/dc/dc/commit/8e51fde524e799652fbd1f0b0763d667cb3a4845))
|
||||
* **mocks:** add fixture staged data and MPE_SUBMIT row for stage.cy.ts ([6e2548d](https://git.datacontroller.io/dc/dc/commit/6e2548d78c613d684fc8d874ba11b30fc9b4e32e))
|
||||
* **mocks:** add LIBRARYNAME to startupservice, fix viewbox column order ([c0af86e](https://git.datacontroller.io/dc/dc/commit/c0af86ef297334ee531e979754d4d289ed3900ea))
|
||||
* **mocks:** limit stage fixture to 1 row, fix column order ([f25ecd8](https://git.datacontroller.io/dc/dc/commit/f25ecd88283433770f56167774617f0e2089c6ef))
|
||||
* **mocks:** look up PK_FIELDS from MPE_TABLES in viewdata, fallback for MPE_AUDIT ([94d2a79](https://git.datacontroller.io/dc/dc/commit/94d2a7970e49845b235c71523418e4a5d2a70396))
|
||||
* **mocks:** remove MPE_VALIDATIONS and MPE_ALERTS from DC996664 libref ([4f7b845](https://git.datacontroller.io/dc/dc/commit/4f7b845390d50db50114afa7fa851ddf3e853ed7))
|
||||
* **mocks:** remove shadowed saveTableData in rejection.js ([fed0396](https://git.datacontroller.io/dc/dc/commit/fed039673777659594feb9a92a5d9c2dca2cc544))
|
||||
* **mocks:** remove SOME_SHORTNUM HARDREGEX from MPE_VALIDATIONS ([34bd660](https://git.datacontroller.io/dc/dc/commit/34bd6607c547c3d40c1129395a28e4cbf0fa1475))
|
||||
* **mocks:** rename saveTableData in postdata.js to avoid shadowing ([e4b04b1](https://git.datacontroller.io/dc/dc/commit/e4b04b1d447640542c122dce93d65219719cb094))
|
||||
* **mocks:** SAS datetime format in getchangeinfo, login in stage.cy.ts ([c180934](https://git.datacontroller.io/dc/dc/commit/c1809341672ad51baa603f104176fdc302e4c0c1))
|
||||
* more mock improvements ([a80927c](https://git.datacontroller.io/dc/dc/commit/a80927cbb6c8a5ce26a1d251dc10cae4bae1eedd))
|
||||
* mp_execute dep ([023c29f](https://git.datacontroller.io/dc/dc/commit/023c29f00f74f964825e0ee01768baf44aead332))
|
||||
* pin fast-uri to 3.1.7 to close high-severity SSRF/host-confusion advisories ([f4325b2](https://git.datacontroller.io/dc/dc/commit/f4325b205699bf02158c232ffd8c279489778512)), closes [hi#severity](https://git.datacontroller.io/hi/issues/severity)
|
||||
* spy for startup ([69b4155](https://git.datacontroller.io/dc/dc/commit/69b41559f7aa66a537b685e26e00c44f1f2568c4))
|
||||
* **stage:** submit data via editor flow, use dynamic date assertion ([490d013](https://git.datacontroller.io/dc/dc/commit/490d0137b921c150b431083b847d471aa379bc42))
|
||||
* **startup:** show the real startupservice response text on a malformed reply ([9a1b7d0](https://git.datacontroller.io/dc/dc/commit/9a1b7d0f52eebe6bea229dedbcb8f5c19bc96141))
|
||||
* tests and realistic getcolvals.js ([5d03164](https://git.datacontroller.io/dc/dc/commit/5d03164b6a3245b47f1278fe962c537f72a8f473))
|
||||
* **tests:** new libref ([c0bc87d](https://git.datacontroller.io/dc/dc/commit/c0bc87d331b081d787b4ed3d04c639c139d0fa1b))
|
||||
* unnecessary getsubmits call removed ([cc2ff87](https://git.datacontroller.io/dc/dc/commit/cc2ff873fae58f41332dcbe725a49f0815b219b3))
|
||||
* using utility macro for webout ([3595bb9](https://git.datacontroller.io/dc/dc/commit/3595bb94993aa054235cce3f41b9d83711907c46))
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **editor:** color row-header status cells and switch modified symbol to ± ([e15f2c2](https://git.datacontroller.io/dc/dc/commit/e15f2c2a3488f43ed4e5814fdc22527961cc5c22))
|
||||
* **editor:** generalize cell revert to any overwritten value, not just formulas ([07d586d](https://git.datacontroller.io/dc/dc/commit/07d586da5235a2d94b2b689c774c40851b9a57e2))
|
||||
* **editor:** scope live formulas to character columns, not just HARDFORMULA/SOFTFORMULA ones ([92d0d91](https://git.datacontroller.io/dc/dc/commit/92d0d91440ff6d58d10f1af291386a1813cb07d4))
|
||||
* **editor:** translate column names to cell references on formula paste ([1031ea7](https://git.datacontroller.io/dc/dc/commit/1031ea7ed7b1a74ecc77bf155f6d329feeaf4b13))
|
||||
* **formulas:** flag formula-overwritten cells with revert, harden dc.row_status against SAS name collisions ([a8237b2](https://git.datacontroller.io/dc/dc/commit/a8237b2881b85854bb52c85ca2f17e3368f91f4a))
|
||||
* **formulas:** live DC.ROW_STATUS, insert-row formula fixes, UserService singleton fix ([4a8c39b](https://git.datacontroller.io/dc/dc/commit/4a8c39b4c0d6e0edb3493ac3d26d86788ebfdf90))
|
||||
* **formulas:** wire HyperFormula into HARDFORMULA/SOFTFORMULA rules ([cbea04c](https://git.datacontroller.io/dc/dc/commit/cbea04c8e129d7d28a626215aae3b67735a036d5))
|
||||
* functional JS mocks ([ee52bb8](https://git.datacontroller.io/dc/dc/commit/ee52bb8967e5bcdcfd17500678295e6bffbe2cf0))
|
||||
* **licensing:** support combined-key paste, object-format features, and a live key preview ([20ba633](https://git.datacontroller.io/dc/dc/commit/20ba63308717dbde929dbe5974b76f160343de29))
|
||||
* **licensing:** warn and block applying a licence key generated for the wrong protocol ([41680e2](https://git.datacontroller.io/dc/dc/commit/41680e2eccad82584bf9fd71a1efd1fd2d8f1a39))
|
||||
* **stage:** add Formatted/Unformatted toggle to the staging page ([74c38e1](https://git.datacontroller.io/dc/dc/commit/74c38e16416dcd8be20faa66d9f282a6438522b5))
|
||||
* updated configurator for Viya deploy ([df2027d](https://git.datacontroller.io/dc/dc/commit/df2027dab6ae51fb9cabf21e35d1fa5d6e1f7957))
|
||||
* **viewboxes:** add drag-to-resize on all four edges and corners ([e5a5bf2](https://git.datacontroller.io/dc/dc/commit/e5a5bf2144d7f35c62368924c7e59f55eeb246ad))
|
||||
|
||||
# [7.12.0](https://git.datacontroller.io/dc/dc/compare/v7.11.0...v7.12.0) (2026-07-28)
|
||||
|
||||
|
||||
|
||||
+93
@@ -0,0 +1,93 @@
|
||||
# Context: Data Controller for SAS®
|
||||
|
||||
Data Controller for SAS® is a web application that lets users safely add, modify and delete data in SAS datasets and databases. Every change is **staged** and **approved** before being applied to the **target table**, and the full history of the change is retained. It runs on SAS Viya, SAS 9 EBI, and [SASjs Server](https://server.sasjs.io), and must run entirely **on-prem / offline** (no external assets or network calls at runtime).
|
||||
|
||||
This file is the shared glossary and orientation for the repo. When your output names a domain concept, use the term as defined here rather than a synonym. Related repos: `docs.datacontroller.io` (user-facing docs) and `datacontroller.io` (marketing site).
|
||||
|
||||
## Repository layout
|
||||
|
||||
- `client/` - the Angular frontend (TypeScript). Uses [Handsontable](.agents/skills/handsontable/SKILL.md) for the editable grid and [HyperFormula](.agents/skills/hyperformula/SKILL.md) for Excel-formula support. Lint with `npm run lint:check` from `client/`.
|
||||
- `sas/` - the SAS backend. Services, macros, hooks and tests live under `sas/sasjs/**`; `sas/sasjsbuild/` is generated output (never hand-edit). Lint `.sas` files with `sasjs lint` from `sas/`.
|
||||
- `.agents/docs/` - technical deep-dives (see below). `.agents/skills/` - task skills (handsontable, hyperformula, dc-sas for Data Controller SAS development, plus npx-installed sasjs/ sas skills).
|
||||
|
||||
## Roles
|
||||
|
||||
The five user roles, in increasing privilege:
|
||||
|
||||
- **Viewer** - explores/links to data without locking datasets.
|
||||
- **Editor** - makes changes (add/modify/delete) and submits them for approval.
|
||||
- **Approver** - accepts or rejects staged changes; on acceptance the change is applied to the target table.
|
||||
- **Auditor** - reviews the history of changes to a table.
|
||||
- **Administrator** - registers tables and configures security (at metadata group level).
|
||||
|
||||
Admins are listed in `&mpeadmins`; admin membership bypasses Row Level Security.
|
||||
|
||||
## Core concepts
|
||||
|
||||
- **Target table** - the physical table (SAS dataset or database table) a user is changing. Its attributes (primary key, load type, library, SCD/temporal variables) are predefined by an administrator in `MPE_TABLES`.
|
||||
- **Submission** - the set of changed rows staged for approval. Submissions are *never* applied automatically; they always require one or more approvals. Three kinds: **Web submission** (only changed rows from the edited extract), **Excel submission** (whole Excel file staged with the file kept for audit; becomes a web submission if the rows are edited in the grid first), and **CSV submission** (all rows sent straight to staging, suitable for larger uploads).
|
||||
- **Staging area** - the secure location where submitted changes wait for approval before being loaded.
|
||||
- **Edit-Stage-Approve workflow** - the central flow: up to 500 rows edited in the web grid, staged, and applied to the target after approval.
|
||||
- **Changeset / diff** - new / modified / deleted rows computed for a submission; approvers review the diff before accepting.
|
||||
|
||||
## Load types
|
||||
|
||||
Set per table in `MPE_TABLES.LOADTYPE`. Determines the loader and how history is kept (see [.agents/docs/bitemporal-dataloader.md](.agents/docs/bitemporal-dataloader.md)):
|
||||
|
||||
- **UPDATE** - no history; changed records deleted and re-appended (via `%bitemporal_dataloader`).
|
||||
- **REPLACE** - no history; whole table wiped and reloaded. Implemented inline in `%mpe_targetloader`, deliberately *not* via `%bitemporal_dataloader` (see [.agents/docs/replace-load-type.md](.agents/docs/replace-load-type.md)).
|
||||
- **TXTEMPORAL** - SCD2-style history on technical (transaction) time.
|
||||
- **BITEMPORAL** - full two-dimensional history (business time + technical time).
|
||||
- **FORMAT_CAT** - format-catalog load (via `%mp_loadformat`).
|
||||
|
||||
**Bitemporal** = two independent time dimensions: **business time** (`VAR_BUSFROM`/`VAR_BUSTO`, when a fact is true in the real world) and **technical/transaction time** (`VAR_TXFROM`/`VAR_TXTO`, when the system knew it). **SCD2** = slowly changing dimension, type 2 (row-versioned history via open/close datetimes). **BUSKEY** = the business/primary key (space-separated columns, excluding temporal columns).
|
||||
|
||||
## MPE control tables
|
||||
|
||||
Configuration and state live in `MPE_*` tables (the "control tables") in the DC control library (`&mpelib` / `&dclib`). Key ones:
|
||||
|
||||
- `MPE_TABLES` - registered target tables and their load config (`LOADTYPE`, `BUSKEY`, temporal vars, etc.).
|
||||
- `MPE_VALIDATIONS` - point-of-entry data-quality rules (see below).
|
||||
- `MPE_ROW_LEVEL_SECURITY` - Row Level Security rules.
|
||||
- `MPE_COLUMN_LEVEL_SECURITY` - Column Level Security rules.
|
||||
- `MPE_SUBMIT` / `MPE_REVIEW` / `MPE_REQUESTS` - the approval workflow tables.
|
||||
- `MPE_AUDIT` - change history.
|
||||
- `MPE_XLMAP_INFO` / `MPE_XLMAP_RULES` / `MPE_XLMAP_DATA` - Excel-map (XLMAP) definitions for structured Excel uploads.
|
||||
- `MPE_CONFIG`, `MPE_GROUPS`, `MPE_SECURITY`, `MPE_EMAIL`, `MPE_LOCKANYTABLE`, and the `MPE_DATACATALOG_*` / `MPE_DATASTATUS_*` catalog tables.
|
||||
|
||||
Selectbox seed values for these tables are defined in `sas/sasjs/macros/mpe_makedata.sas`. User-facing documentation for each table is in the `docs.datacontroller.io` repo under `docs/tables/`.
|
||||
|
||||
## Validations
|
||||
|
||||
`MPE_VALIDATIONS` applies point-of-entry rules per `BASE_LIB`/`BASE_DS`/`BASE_COL` when `RULE_ACTIVE=1`. `RULE_TYPE` values include `CASE`, `NOTNULL`, `MINVAL`, `MAXVAL`, `READONLY`, `HIDDEN`, `ROUND`, `NUMBER_FORMAT`, `HARDREGEX`, `SOFTREGEX`, `HARDSELECT`, `SOFTSELECT`, `HARDSELECT_HOOK`, `SOFTSELECT_HOOK`.
|
||||
|
||||
- **HARDREGEX** - submission-blocking regex; failing cells are painted red and cannot be submitted.
|
||||
- **SOFTREGEX** - display-only warning regex; failing cells are painted yellow but submission is allowed.
|
||||
|
||||
Regex rule values are authored in SAS PRX form `/pattern/flags` and limited to 128 chars. See [.agents/docs/regex-validations.md](.agents/docs/regex-validations.md).
|
||||
|
||||
## Security
|
||||
|
||||
- **Row Level Security (RLS)** - server-side `WHERE`-clause generation via `%mpe_filtermaster` / `%mp_filtergenerate`; no data leaves SAS without passing the filter. Works on any engine because it's expressed as a standard SAS `WHERE`. On write, the *inverse* filter is applied to reject out-of-scope rows. See [.agents/docs/row-level-security.md](.agents/docs/row-level-security.md).
|
||||
- **Column Level Security (CLS)** - restricts visibility/editability at column level.
|
||||
|
||||
## Key macros / services
|
||||
|
||||
- `%mpe_targetloader` (`sas/sasjs/macros/mpe_targetloader.sas`) - the single load dispatch point; routes by `LOADTYPE`. Two-phase: `LOADTARGET=NO` builds diff tables for review, `LOADTARGET=YES` performs the destructive load.
|
||||
- `%bitemporal_dataloader` - the temporal loader for UPDATE / TXTEMPORAL / BITEMPORAL.
|
||||
- `%mpe_filtermaster` - builds the RLS filter for a request.
|
||||
|
||||
## Testing
|
||||
|
||||
Backend tests run with the sasjs CLI from `sas/`. `npm run 4gl` compiles+deploys+seeds then `sasjs test -t 4gl` runs tests. Assertions use `%mp_assert()`. See [.agents/docs/testing.md](.agents/docs/testing.md).
|
||||
|
||||
## Conventions
|
||||
|
||||
- Do not hard-wrap Markdown (one logical line per paragraph/list-item/heading).
|
||||
- Use regular dashes, not em-dashes.
|
||||
- No external assets - everything must be bundled and served locally.
|
||||
- Comments and test names must be self-contained (no "original bug", "this PR", etc.); the only exception is a literal issue-tracker link.
|
||||
- Do not auto-commit or push.
|
||||
- Never edit `CHANGELOG.md` or bump `package.json` version by hand - the release pipeline generates both from Conventional Commit messages. See [.agents/docs/releases-and-changelog.md](.agents/docs/releases-and-changelog.md).
|
||||
|
||||
See `AGENTS.md` for the full set of enforced rules (git, linting, no-wrap, no-external-assets, `.agents/` layout).
|
||||
@@ -4,6 +4,21 @@
|
||||
## Workflow guidelines
|
||||
[Wiki Page](https://git.datacontroller.io/dc/dc/wiki/Git-Workflow)
|
||||
|
||||
## Git hooks
|
||||
|
||||
The repo ships its own git hooks in [`.git-hooks/`](./.git-hooks):
|
||||
|
||||
- `pre-commit` - scans staged changes for secrets with gitleaks, blocks commits that would add more than 2MB of new blobs, and runs the prettier check (auto-fixing on failure)
|
||||
- `commit-msg` - verifies the commit message follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary) standard
|
||||
|
||||
The repo `.npmrc` sets `ignore-scripts=true`, so the `prepare` and `postinstall` lifecycle scripts that would normally set `core.hooksPath` during `npm i` never run. After cloning (or if your commits are not being checked), activate the hooks with a one-time command, run from the repo root:
|
||||
|
||||
```bash
|
||||
git config core.hooksPath ./.git-hooks
|
||||
```
|
||||
|
||||
The pre-commit hook requires the gitleaks binary provided by the root `@nogoo9/gitleaks` devDependency, so make sure `npm i` has run in the repo root before your first commit.
|
||||
|
||||
## Dependencies that requires licences
|
||||
|
||||
[SheetJS Pro Version](https://www.npmjs.com/package/sheetjs)
|
||||
@@ -54,6 +69,71 @@ cd client
|
||||
npm start
|
||||
```
|
||||
|
||||
## Mocked backend (frontend development without SAS)
|
||||
|
||||
Data Controller ships a full set of JS mock services under `sas/mocks/sasjs/` that mimic the SAS backend using [SASjs Server](https://server.sasjs.io) in JS-only mode. This lets you run the entire frontend (editor grid, approvals, viewer, admin, Excel maps, etc.) without a SAS licence or SAS server. The Cypress E2E tests and Lighthouse CI both run against this setup.
|
||||
|
||||
### Prerequisites
|
||||
|
||||
- Node.js (same version used for the frontend build)
|
||||
- The frontend dependencies installed (`cd client && npm ci` after decrypting sheet-crypto as described above)
|
||||
|
||||
### 1. Start SASjs Server
|
||||
|
||||
Download the latest Linux (or macOS/Windows) binary from [SASjs Server releases](https://github.com/sasjs/server/releases), unzip it, and create a `.env` file alongside the executable:
|
||||
|
||||
```
|
||||
RUN_TIMES=js
|
||||
NODE_PATH=node
|
||||
CORS=enable
|
||||
WHITELIST=http://localhost:4200
|
||||
```
|
||||
|
||||
`RUN_TIMES=js` means the server executes `.js` files as Stored Programs (no SAS binary needed). `CORS=enable` plus `WHITELIST` allows the Angular dev server on port 4200 to call the mock services on port 5000. Start the server:
|
||||
|
||||
```
|
||||
./api-linux # or api-macos / api-win.exe depending on your platform
|
||||
```
|
||||
|
||||
The server runs in desktop mode (no auth) on `http://localhost:5000` by default.
|
||||
|
||||
### 2. Deploy the mock services and streaming frontend
|
||||
|
||||
From `sas/mocks/sasjs/`:
|
||||
|
||||
```
|
||||
npm ci
|
||||
sasjs cbd -t server-ci
|
||||
```
|
||||
|
||||
This compiles, builds, and deploys the JS mock services plus the Angular frontend (as a streaming app) to the SASjs Server. The `server-ci` target in `sas/mocks/sasjs/sasjsconfig.json` points to `http://localhost:5000` with appLoc `/Public/app/dc` and stream service name `clickme`.
|
||||
|
||||
After deploy, the streamed app is available at: `http://localhost:5000/AppStream/clickme/`
|
||||
|
||||
### 3. Run the Angular dev server (optional, for hot reload)
|
||||
|
||||
For frontend development with live reload, point `client/src/index.html` at the local SASjs Server and start the dev server:
|
||||
|
||||
```
|
||||
cd client
|
||||
# Edit src/index.html: set serverUrl="http://localhost:5000", appLoc="/Public/app/dc", serverType="SASJS"
|
||||
npm start
|
||||
```
|
||||
|
||||
The app will be at `http://localhost:4200`. It calls the JS mock services on port 5000 via the SASjs adapter (CORS is enabled by the `.env` above).
|
||||
|
||||
### How the mocks work
|
||||
|
||||
Each `.js` file in `sas/mocks/sasjs/services/` corresponds to a real SAS service (e.g. `public/startupservice.js` mimics `services/public/startupservice.sas`). The JS runtime predeclares `fs` and `_webout`; the mock assigns a JSON string to `_webout` that matches the structure the real SAS service would return. Some mocks are stateful: they persist data to a `mock-storage/` folder on the SASjs Drive (e.g. `licence.json`, `users.json`, `filter.txt`) using the predeclared `fs` module.
|
||||
|
||||
The mock data includes sample tables (`DC996664.MPE_X_TEST`, `MPE_X_NEW`, `MPE_X_FORMULA_TEST`, etc.) with realistic columns, validation rules (HARDREGEX, SOFTREGEX, HARDSELECT, READONLY, HIDDEN, ROUND, NUMBER_FORMAT), and dropdown values. This is sufficient to exercise the full editor grid, approval workflow, viewer, and admin screens.
|
||||
|
||||
There is also a SAS 9 mock variant under `sas/mocks/sas9/` (target `sas9-mocks`) that mimics SAS 9 stored processes with the same JS approach but a different appLoc (`/User Folders/sasdemo/`).
|
||||
|
||||
### Re-deploying after changes
|
||||
|
||||
After changing mock services, re-run `sasjs cbd -t server-ci` from `sas/mocks/sasjs/`. After changing the frontend, rebuild (`cd client && npm run build`) then re-deploy so the streaming app picks up the new `client/dist/`. If you are using `ng serve` (step 3), only the mock services need re-deploying; the frontend hot-reloads automatically.
|
||||
|
||||
## GUI Elements
|
||||
|
||||
For documentation on the Clarity Design System, including a list of components and example usage, see [our website](https://vmware.github.io/clarity).
|
||||
|
||||
@@ -9,6 +9,7 @@ export default defineConfig({
|
||||
html: true,
|
||||
json: false
|
||||
},
|
||||
|
||||
viewportHeight: 900,
|
||||
viewportWidth: 1600,
|
||||
|
||||
@@ -24,7 +25,7 @@ export default defineConfig({
|
||||
serverType: 'SASJS',
|
||||
libraryToOpenIncludes_SASVIYA: 'viya',
|
||||
libraryToOpenIncludes_SAS9: 'dc',
|
||||
libraryToOpenIncludes_SASJS: 'dc',
|
||||
libraryToOpenIncludes_SASJS: 'dc_jslib',
|
||||
debug: false,
|
||||
screenshotOnRunFailure: false,
|
||||
longerCommandTimeout: 50000,
|
||||
|
||||
+1607
-16
File diff suppressed because it is too large
Load Diff
@@ -546,7 +546,7 @@ const checkResultOfFormulaUpload = (callback?: any) => {
|
||||
.find('tbody')
|
||||
.then((data) => {
|
||||
const cell: any = data[0].children[0].children[5]
|
||||
expect(cell.innerText).to.equal('=1+1')
|
||||
expect(cell.innerText).to.equal('2')
|
||||
if (callback) callback()
|
||||
})
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ context('filtering tests: ', function () {
|
||||
openFilterPopup(() => {
|
||||
setFilterWithValue('SOME_CHAR', 'this is dummy data', 'value', () => {
|
||||
checkInfoBarIncludes(
|
||||
`AND,AND,0,SOME_CHAR,=,"'this is dummy data'"`,
|
||||
`(( SOME_CHAR = 'this is dummy data' ))`,
|
||||
(includes: boolean) => {
|
||||
if (includes) done()
|
||||
}
|
||||
@@ -39,7 +39,7 @@ context('filtering tests: ', function () {
|
||||
|
||||
openFilterPopup(() => {
|
||||
setFilterWithValue('SOME_NUM', '42', 'value', () => {
|
||||
checkInfoBarIncludes(`AND,AND,0,SOME_NUM,=,42`, (includes: boolean) => {
|
||||
checkInfoBarIncludes(`(( SOME_NUM = 42 ))`, (includes: boolean) => {
|
||||
if (includes) done()
|
||||
})
|
||||
})
|
||||
@@ -51,12 +51,9 @@ context('filtering tests: ', function () {
|
||||
|
||||
openFilterPopup(() => {
|
||||
setFilterWithValue('SOME_TIME', '00:00:42', 'time', () => {
|
||||
checkInfoBarIncludes(
|
||||
`AND,AND,0,SOME_TIME,=,42`,
|
||||
(includes: boolean) => {
|
||||
if (includes) done()
|
||||
}
|
||||
)
|
||||
checkInfoBarIncludes(`(( SOME_TIME = 42 ))`, (includes: boolean) => {
|
||||
if (includes) done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -66,12 +63,9 @@ context('filtering tests: ', function () {
|
||||
|
||||
openFilterPopup(() => {
|
||||
setFilterWithValue('SOME_TIME', '42', 'value', () => {
|
||||
checkInfoBarIncludes(
|
||||
`AND,AND,0,SOME_TIME,=,42`,
|
||||
(includes: boolean) => {
|
||||
if (includes) done()
|
||||
}
|
||||
)
|
||||
checkInfoBarIncludes(`(( SOME_TIME = 42 ))`, (includes: boolean) => {
|
||||
if (includes) done()
|
||||
})
|
||||
})
|
||||
}, false)
|
||||
})
|
||||
@@ -81,12 +75,9 @@ context('filtering tests: ', function () {
|
||||
|
||||
openFilterPopup(() => {
|
||||
setFilterWithValue('SOME_DATE', '12/02/1960', 'date', () => {
|
||||
checkInfoBarIncludes(
|
||||
`AND,AND,0,SOME_DATE,=,42`,
|
||||
(includes: boolean) => {
|
||||
if (includes) done()
|
||||
}
|
||||
)
|
||||
checkInfoBarIncludes(`(( SOME_DATE = 42 ))`, (includes: boolean) => {
|
||||
if (includes) done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -96,12 +87,9 @@ context('filtering tests: ', function () {
|
||||
|
||||
openFilterPopup(() => {
|
||||
setFilterWithValue('SOME_DATE', '42', 'value', () => {
|
||||
checkInfoBarIncludes(
|
||||
`AND,AND,0,SOME_DATE,=,42`,
|
||||
(includes: boolean) => {
|
||||
if (includes) done()
|
||||
}
|
||||
)
|
||||
checkInfoBarIncludes(`(( SOME_DATE = 42 ))`, (includes: boolean) => {
|
||||
if (includes) done()
|
||||
})
|
||||
})
|
||||
}, false)
|
||||
})
|
||||
@@ -116,7 +104,7 @@ context('filtering tests: ', function () {
|
||||
'datetime',
|
||||
() => {
|
||||
checkInfoBarIncludes(
|
||||
`AND,AND,0,SOME_DATETIME,=,42`,
|
||||
`(( SOME_DATETIME = 42 ))`,
|
||||
(includes: boolean) => {
|
||||
if (includes) done()
|
||||
}
|
||||
@@ -132,7 +120,7 @@ context('filtering tests: ', function () {
|
||||
openFilterPopup(() => {
|
||||
setFilterWithValue('SOME_DATETIME', '42', 'value', () => {
|
||||
checkInfoBarIncludes(
|
||||
`AND,AND,0,SOME_DATETIME,=,42`,
|
||||
`(( SOME_DATETIME = 42 ))`,
|
||||
(includes: boolean) => {
|
||||
if (includes) done()
|
||||
}
|
||||
@@ -146,12 +134,9 @@ context('filtering tests: ', function () {
|
||||
|
||||
openFilterPopup(() => {
|
||||
setFilterWithValue('SOME_DATE', '', 'in', () => {
|
||||
checkInfoBarIncludes(
|
||||
`AND,AND,0,SOME_DATE,IN,(0)`,
|
||||
(includes: boolean) => {
|
||||
if (includes) done()
|
||||
}
|
||||
)
|
||||
checkInfoBarIncludes(`(( SOME_DATE IN (42) ))`, (includes: boolean) => {
|
||||
if (includes) done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -311,7 +296,11 @@ const setFilterWithValue = (
|
||||
})
|
||||
})
|
||||
|
||||
break
|
||||
// The IN clause is submitted by the modal footer button above; the
|
||||
// trailing tab/click sequence below is for the plain value fields and
|
||||
// must not run here (focus is gone once the modal closes and the
|
||||
// editor reloads with the stored filter).
|
||||
return
|
||||
}
|
||||
case 'between': {
|
||||
cy.focused().tab()
|
||||
|
||||
@@ -244,6 +244,294 @@ context('licensing tests: ', function () {
|
||||
})
|
||||
})
|
||||
|
||||
it('6 | pasting an HTTP-format key (identical licence/activation text) on this secure connection warns before applying', (done) => {
|
||||
visitPage('licensing/update')
|
||||
|
||||
cy.get('button').contains('Paste licence').click()
|
||||
|
||||
// Defaults to the combined single-field form - switch to the legacy
|
||||
// two-field layout, since this test targets that path specifically.
|
||||
cy.get('button').contains('Paste as two separate keys instead').click()
|
||||
|
||||
// HTTP-format keys are generated as the exact same string for both
|
||||
// fields (see detectLicenceKeyProtocolMismatch's own doc comment) -
|
||||
// any non-empty matching pair triggers the warning, no real key needed.
|
||||
// Cypress always runs against localhost, which browsers treat as a
|
||||
// secure connection even over plain http, so this is reachable without
|
||||
// stubbing anything - unlike the reverse case (an HTTPS-format key
|
||||
// where WebCrypto is unavailable), which is covered by
|
||||
// detectLicenceKeyProtocolMismatch.spec.ts's Karma tests instead.
|
||||
const httpFormatKey = 'same-text-for-both-fields'
|
||||
|
||||
cy.get('.license-key-form textarea', { timeout: longerCommandTimeout })
|
||||
.invoke('val', httpFormatKey)
|
||||
.trigger('input')
|
||||
cy.get('.activation-key-form textarea', { timeout: longerCommandTimeout })
|
||||
.invoke('val', httpFormatKey)
|
||||
.trigger('input')
|
||||
|
||||
cy.get('p.protocol-mismatch-warning')
|
||||
.should('contain', 'generated for an insecure (HTTP) connection')
|
||||
.then(() => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
|
||||
it('7 | Combined single-string key (default paste format) activates successfully', (done) => {
|
||||
let keyData = {
|
||||
valid_until: moment().add(1, 'year').format('YYYY-MM-DD'),
|
||||
users_allowed: 4,
|
||||
hot_license_key: '',
|
||||
demo: false,
|
||||
site_id: site_id
|
||||
}
|
||||
|
||||
generateKeys(keyData, (keysGen: any) => {
|
||||
cy.wait(2000)
|
||||
|
||||
// Navigate there explicitly rather than only acting when already on
|
||||
// the licensing page - earlier tests may have left the app on it (a
|
||||
// bad key) or already activated (a good one), and this test should
|
||||
// pass either way rather than silently no-op when it's the latter.
|
||||
isLicensingPage((result: boolean) => {
|
||||
const proceed = () =>
|
||||
generateCombinedKey(keysGen.licenseKey, keysGen.activationKey).then(
|
||||
(combinedKey) => {
|
||||
inputCombinedKeyPage(combinedKey)
|
||||
|
||||
cy.wait(2000)
|
||||
|
||||
acceptTermsIfPresented((termsResult: boolean) => {
|
||||
if (termsResult) {
|
||||
cy.wait(10000)
|
||||
}
|
||||
|
||||
visitPage('home')
|
||||
|
||||
cy.get('.nav-tree clr-tree > clr-tree-node', {
|
||||
timeout: longerCommandTimeout
|
||||
}).then(() => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
if (!result) {
|
||||
visitPage('licensing/update')
|
||||
cy.wait(2000)
|
||||
}
|
||||
|
||||
// proceed() generates the combined key asynchronously, then
|
||||
// enqueues the actual page commands only once its promise
|
||||
// resolves. Bridged through cy.then() so the command chain stays
|
||||
// open across that async gap: a bare proceed() call returns a
|
||||
// promise that nothing awaits, and once the surrounding queue
|
||||
// has drained, commands enqueued from that promise's continuation
|
||||
// are never run.
|
||||
cy.then(() => proceed())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('8 | Pasting a combined key into the legacy licence-key field alone still auto-detects and activates', (done) => {
|
||||
let keyData = {
|
||||
valid_until: moment().add(1, 'year').format('YYYY-MM-DD'),
|
||||
users_allowed: 4,
|
||||
hot_license_key: '',
|
||||
demo: false,
|
||||
site_id: site_id
|
||||
}
|
||||
|
||||
generateKeys(keyData, (keysGen: any) => {
|
||||
cy.wait(2000)
|
||||
|
||||
// Navigate there explicitly rather than only acting when already on
|
||||
// the licensing page - see test 7's own comment for why.
|
||||
isLicensingPage((result: boolean) => {
|
||||
const proceed = () =>
|
||||
generateCombinedKey(keysGen.licenseKey, keysGen.activationKey).then(
|
||||
(combinedKey) => {
|
||||
cy.get('button').contains('Paste licence').click()
|
||||
cy.get('button')
|
||||
.contains('Paste as two separate keys instead')
|
||||
.click()
|
||||
|
||||
// Only the licence-key field gets the combined string - the
|
||||
// activation-key field is left empty, proving the split
|
||||
// populates both fields from this one paste.
|
||||
cy.get('.license-key-form textarea', {
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
.invoke('val', combinedKey)
|
||||
.trigger('input')
|
||||
.trigger('mouseleave')
|
||||
|
||||
cy.get('.activation-key-form textarea', {
|
||||
timeout: longerCommandTimeout
|
||||
}).should(($textarea) => {
|
||||
expect($textarea.val()).to.equal(keysGen.activationKey)
|
||||
})
|
||||
|
||||
cy.get('button.apply-keys').click()
|
||||
|
||||
cy.wait(2000)
|
||||
|
||||
acceptTermsIfPresented((termsResult: boolean) => {
|
||||
if (termsResult) {
|
||||
cy.wait(10000)
|
||||
}
|
||||
|
||||
visitPage('home')
|
||||
|
||||
cy.get('.nav-tree clr-tree > clr-tree-node', {
|
||||
timeout: longerCommandTimeout
|
||||
}).then(() => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
// See test 7's own comment for why proceed() is bridged through
|
||||
// cy.then() rather than called as a plain statement.
|
||||
if (!result) {
|
||||
visitPage('licensing/update')
|
||||
cy.wait(2000)
|
||||
}
|
||||
cy.then(() => proceed())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('9 | Uploading a single-line combined-format file activates successfully', (done) => {
|
||||
let keyData = {
|
||||
valid_until: moment().add(1, 'year').format('YYYY-MM-DD'),
|
||||
users_allowed: 4,
|
||||
hot_license_key: '',
|
||||
demo: false,
|
||||
site_id: site_id
|
||||
}
|
||||
|
||||
generateKeys(keyData, (keysGen: any) => {
|
||||
cy.wait(2000)
|
||||
|
||||
// Navigate there explicitly rather than only acting when already on
|
||||
// the licensing page - see test 7's own comment for why.
|
||||
isLicensingPage((result: boolean) => {
|
||||
const proceed = () =>
|
||||
generateCombinedKey(keysGen.licenseKey, keysGen.activationKey).then(
|
||||
(combinedKey) => {
|
||||
cy.get('input[type="file"]').attachFile({
|
||||
fileContent: new Blob([combinedKey], { type: 'text/plain' }),
|
||||
fileName: 'datacontroller-licence-combined.txt',
|
||||
mimeType: 'text/plain'
|
||||
})
|
||||
|
||||
cy.get('button.apply-keys', {
|
||||
timeout: longerCommandTimeout
|
||||
}).click()
|
||||
|
||||
cy.wait(2000)
|
||||
|
||||
acceptTermsIfPresented((termsResult: boolean) => {
|
||||
if (termsResult) {
|
||||
cy.wait(10000)
|
||||
}
|
||||
|
||||
visitPage('home')
|
||||
|
||||
cy.get('.nav-tree clr-tree > clr-tree-node', {
|
||||
timeout: longerCommandTimeout
|
||||
}).then(() => {
|
||||
done()
|
||||
})
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
// See test 7's own comment for why proceed() is bridged through
|
||||
// cy.then() rather than called as a plain statement.
|
||||
if (!result) {
|
||||
visitPage('licensing/update')
|
||||
cy.wait(2000)
|
||||
}
|
||||
cy.then(() => proceed())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('10 | Key details preview shows for a validly-pasted key and disappears once the key input is cleared', (done) => {
|
||||
let keyData = {
|
||||
valid_until: moment().add(1, 'year').format('YYYY-MM-DD'),
|
||||
users_allowed: 4,
|
||||
hot_license_key: '',
|
||||
demo: false,
|
||||
site_id: site_id,
|
||||
// Kept to just the two enabled toggles (relying on
|
||||
// decodeLicenceFeatures' fallback for the rest) to keep the
|
||||
// encrypted payload well under this suite's RSA-OAEP plaintext
|
||||
// ceiling - see generateKeys' modulusLength below.
|
||||
features: { vb: true, fu: true }
|
||||
}
|
||||
|
||||
generateKeys(keyData, (keysGen: any) => {
|
||||
cy.wait(2000)
|
||||
|
||||
// Navigate there explicitly rather than only acting when already on
|
||||
// the licensing page - see test 7's own comment for why.
|
||||
isLicensingPage((result: boolean) => {
|
||||
const proceed = () =>
|
||||
generateCombinedKey(keysGen.licenseKey, keysGen.activationKey).then(
|
||||
(combinedKey) => {
|
||||
cy.get('button').contains('Paste licence').click()
|
||||
|
||||
cy.get('.combined-key-form textarea', {
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
.invoke('val', combinedKey)
|
||||
.trigger('input')
|
||||
.trigger('mouseleave')
|
||||
|
||||
cy.get('.key-details')
|
||||
.should('contain', 'Valid until:')
|
||||
.and('contain', 'Allowed users:')
|
||||
.and('contain', '4')
|
||||
.and('contain', 'Site ID(s) in this key:')
|
||||
.and('contain', 'Enabled features:')
|
||||
.and('contain', 'Viewbox')
|
||||
.and('contain', 'File Upload')
|
||||
.invoke('text')
|
||||
.then((text) => {
|
||||
expect(text).to.not.contain('Edit Record')
|
||||
expect(text).to.not.contain('Add Record')
|
||||
})
|
||||
|
||||
cy.get('.combined-key-form textarea')
|
||||
.invoke('val', '')
|
||||
.trigger('input')
|
||||
.trigger('mouseleave')
|
||||
|
||||
cy.get('.key-details')
|
||||
.should('not.exist')
|
||||
.then(() => {
|
||||
done()
|
||||
})
|
||||
}
|
||||
)
|
||||
|
||||
// See test 7's own comment for why this is chained via .then()
|
||||
// rather than called as the next plain statement.
|
||||
if (!result) {
|
||||
visitPage('licensing/update')
|
||||
cy.wait(2000).then(() => proceed())
|
||||
} else {
|
||||
proceed()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
if (testLicenceUserLimits) {
|
||||
it('4 | User try to register when limit is reached', (done) => {
|
||||
let keyData = {
|
||||
@@ -417,7 +705,7 @@ const verifyLicensingPage = (text: string, callback: any) => {
|
||||
cy.wait(1000)
|
||||
isLicensingPage((result: boolean) => {
|
||||
if (result) {
|
||||
cy.get('p.key-error')
|
||||
cy.get('.key-error')
|
||||
.should('contain', text)
|
||||
.then((treeNodes: any) => {
|
||||
callback(true)
|
||||
@@ -441,6 +729,10 @@ const verifyLicensingWarning = (text: string, callback: any) => {
|
||||
const inputLicenseKeyPage = (licenseKey: string, activationKey: string) => {
|
||||
cy.get('button').contains('Paste licence').click()
|
||||
|
||||
// Defaults to the combined single-field form - this helper exercises the
|
||||
// two-part path specifically, so switch to it first.
|
||||
cy.get('button').contains('Paste as two separate keys instead').click()
|
||||
|
||||
cy.get('.license-key-form textarea', { timeout: longerCommandTimeout })
|
||||
.invoke('val', licenseKey)
|
||||
.trigger('input')
|
||||
@@ -452,6 +744,30 @@ const inputLicenseKeyPage = (licenseKey: string, activationKey: string) => {
|
||||
cy.get('button.apply-keys').click()
|
||||
}
|
||||
|
||||
const inputCombinedKeyPage = (combinedKey: string) => {
|
||||
cy.get('button').contains('Paste licence').click()
|
||||
|
||||
// Combined is the default paste format - no toggle click needed here,
|
||||
// unlike inputLicenseKeyPage's legacy two-field path.
|
||||
cy.get('.combined-key-form textarea', { timeout: longerCommandTimeout })
|
||||
.invoke('val', combinedKey)
|
||||
.trigger('input')
|
||||
.trigger('mouseleave')
|
||||
.should('not.be.undefined')
|
||||
|
||||
// mouseleave's handler (onCombinedKeyInput) does async work - gzip
|
||||
// decompress the split, then decrypt for the key-details preview -
|
||||
// before licenceKeyValue/activationKeyValue are ready to submit.
|
||||
// Wait for that preview to land rather than racing "Apply licence
|
||||
// keys" against the still-in-flight promise.
|
||||
cy.get('.key-details', { timeout: longerCommandTimeout }).should(
|
||||
'contain',
|
||||
'Valid until:'
|
||||
)
|
||||
|
||||
cy.get('button.apply-keys').click()
|
||||
}
|
||||
|
||||
const updateUsersTable = (options: any, callback?: any) => {
|
||||
visitPage('home')
|
||||
openTableFromTree(libraryToOpenIncludes, 'mpe_users')
|
||||
@@ -596,6 +912,62 @@ const generateKeys = async (licenseData: any, resultCallback?: any) => {
|
||||
})
|
||||
}
|
||||
|
||||
// Mirrors dckey's own encodeCombinedKey()/gzipCompress() (main.js) and
|
||||
// DC's own splitCombinedLicenceKey() decode side, so this stays a genuine
|
||||
// end-to-end check of the real format rather than a fixture the app
|
||||
// happens to accept.
|
||||
const COMBINED_KEY_PREFIX = 'DCKEY1:'
|
||||
|
||||
// Reads a ReadableStream directly via its own reader, rather than through
|
||||
// `new Response(readable).arrayBuffer()` - Cypress patches fetch/Response
|
||||
// globally for its network-interception features, which appears to hang
|
||||
// a Response built locally around a stream that never touches the network
|
||||
// (writer.write()/close() resolve fine; only the Response-based read never
|
||||
// settles).
|
||||
const streamToArrayBuffer = async (
|
||||
readable: ReadableStream<Uint8Array>
|
||||
): Promise<ArrayBuffer> => {
|
||||
const reader = readable.getReader()
|
||||
const chunks: Uint8Array[] = []
|
||||
let totalLength = 0
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) break
|
||||
chunks.push(value)
|
||||
totalLength += value.length
|
||||
}
|
||||
|
||||
const result = new Uint8Array(totalLength)
|
||||
let offset = 0
|
||||
for (const chunk of chunks) {
|
||||
result.set(chunk, offset)
|
||||
offset += chunk.length
|
||||
}
|
||||
|
||||
return result.buffer
|
||||
}
|
||||
|
||||
const generateCombinedKey = async (
|
||||
licenseKey: string,
|
||||
activationKey: string
|
||||
): Promise<string> => {
|
||||
const payloadBytes = new TextEncoder().encode(
|
||||
`${licenseKey} ${activationKey}`
|
||||
)
|
||||
|
||||
const compressionStream = new CompressionStream('gzip')
|
||||
const writer = compressionStream.writable.getWriter()
|
||||
const [, compressedBuffer] = await Promise.all([
|
||||
writer.write(payloadBytes).then(() => writer.close()),
|
||||
streamToArrayBuffer(compressionStream.readable)
|
||||
])
|
||||
|
||||
const compressedBase64 = await arrayBufferToBase64(compressedBuffer)
|
||||
|
||||
return COMBINED_KEY_PREFIX + compressedBase64
|
||||
}
|
||||
|
||||
const editTableField = (edits: EditConfigTableCells[], callback?: any) => {
|
||||
cy.get('td').then((tdNodes: any) => {
|
||||
for (let edit of edits) {
|
||||
|
||||
@@ -0,0 +1,167 @@
|
||||
const username = Cypress.env('username')
|
||||
const password = Cypress.env('password')
|
||||
const hostUrl = Cypress.env('hosturl')
|
||||
const appLocation = Cypress.env('appLocation')
|
||||
const longerCommandTimeout = Cypress.env('longerCommandTimeout')
|
||||
const serverType = Cypress.env('serverType')
|
||||
const libraryToOpenIncludes = Cypress.env(`libraryToOpenIncludes_${serverType}`)
|
||||
const fixturePath = 'excels/'
|
||||
|
||||
context('stage tests: ', function () {
|
||||
this.beforeAll(() => {
|
||||
cy.visit(`${hostUrl}/SASLogon/logout`)
|
||||
cy.loginAndUpdateValidKey(true)
|
||||
})
|
||||
|
||||
this.beforeEach(() => {
|
||||
cy.visit(hostUrl + appLocation)
|
||||
|
||||
visitPage('home')
|
||||
})
|
||||
|
||||
it('1 | Formatted/Unformatted toggle switches between fmt_stagetable and stagetable, defaulting to formatted', () => {
|
||||
openTableFromTree(libraryToOpenIncludes, 'mpe_x_test')
|
||||
|
||||
attachExcelFile('regular_excel.xlsx', () => {
|
||||
submitExcel()
|
||||
|
||||
// The app navigates to /stage/{tableId}.
|
||||
cy.url({ timeout: longerCommandTimeout }).should('include', '/stage/')
|
||||
|
||||
cy.get('.app-loading', { timeout: longerCommandTimeout }).should(
|
||||
'not.exist'
|
||||
)
|
||||
|
||||
// Toggle to unformatted first to read the raw SOME_DATE value.
|
||||
cy.get('.formatted-values-toggle').click()
|
||||
|
||||
getCellByHeaderAndRow(0, 'SOME_DATE')
|
||||
.invoke('text')
|
||||
.then((rawText) => {
|
||||
const rawDate = parseInt(rawText, 10)
|
||||
|
||||
// Toggle back to formatted view.
|
||||
cy.get('.formatted-values-toggle').click()
|
||||
|
||||
// Compute the expected SAS date9. format from the raw value.
|
||||
const sasEpoch = new Date(Date.UTC(1960, 0, 1))
|
||||
const formatted = new Date(sasEpoch.getTime() + rawDate * 86400000)
|
||||
const months = [
|
||||
'JAN',
|
||||
'FEB',
|
||||
'MAR',
|
||||
'APR',
|
||||
'MAY',
|
||||
'JUN',
|
||||
'JUL',
|
||||
'AUG',
|
||||
'SEP',
|
||||
'OCT',
|
||||
'NOV',
|
||||
'DEC'
|
||||
]
|
||||
const expected =
|
||||
String(formatted.getUTCDate()).padStart(2, '0') +
|
||||
months[formatted.getUTCMonth()] +
|
||||
formatted.getUTCFullYear()
|
||||
|
||||
getCellByHeaderAndRow(0, 'SOME_DATE').should('have.text', expected)
|
||||
|
||||
// Toggle to unformatted again to verify round-trip.
|
||||
cy.get('.formatted-values-toggle').click()
|
||||
|
||||
getCellByHeaderAndRow(0, 'SOME_DATE').should(
|
||||
'have.text',
|
||||
String(rawDate)
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const visitPage = (url: string) => {
|
||||
cy.visit(`${hostUrl}${appLocation}/#/${url}`)
|
||||
}
|
||||
|
||||
const openTableFromTree = (libNameIncludes: string, tablename: string) => {
|
||||
cy.get('.app-loading', { timeout: longerCommandTimeout })
|
||||
.should('not.exist')
|
||||
.then(() => {
|
||||
cy.get('.nav-tree clr-tree > clr-tree-node', {
|
||||
timeout: longerCommandTimeout
|
||||
}).then((treeNodes: any) => {
|
||||
let viyaLib
|
||||
|
||||
for (let node of treeNodes) {
|
||||
if (node.innerText.toLowerCase().includes(libNameIncludes)) {
|
||||
viyaLib = node
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
cy.get(viyaLib).within(() => {
|
||||
cy.get('.clr-tree-node-content-container > button').click()
|
||||
|
||||
cy.get('.clr-treenode-link').then((innerNodes: any) => {
|
||||
for (let innerNode of innerNodes) {
|
||||
if (innerNode.innerText.toLowerCase().includes(tablename)) {
|
||||
innerNode.click()
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const attachExcelFile = (excelFilename: string, callback?: any) => {
|
||||
cy.get('.buttonBar button:last-child')
|
||||
.should('exist')
|
||||
.click()
|
||||
.then(() => {
|
||||
cy.get('input[type="file"]#file-upload')
|
||||
.attachFile(`/${fixturePath}/${excelFilename}`)
|
||||
.then(() => {
|
||||
cy.get('.clr-abort-modal .modal-title').then((modalTitle) => {
|
||||
if (!modalTitle[0].innerHTML.includes('Abort Message')) {
|
||||
cy.get('.modal-footer .btn.btn-primary').then((modalBtn) => {
|
||||
modalBtn.click()
|
||||
if (callback) callback()
|
||||
})
|
||||
} else {
|
||||
if (callback) callback()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
const submitExcel = (callback?: any) => {
|
||||
cy.get('.buttonBar button.preview-submit', { timeout: longerCommandTimeout })
|
||||
.click()
|
||||
.then(() => {
|
||||
if (callback) callback()
|
||||
})
|
||||
}
|
||||
|
||||
// Locates a body cell by its column's header text rather than a hardcoded
|
||||
// childNodes index - same helper as editor.cy.ts's own.
|
||||
const getCellByHeaderAndRow = (rowIndex: number, headerText: string) => {
|
||||
return cy
|
||||
.get('.ht_clone_top .htCore thead tr th')
|
||||
.should(($ths) => {
|
||||
const texts = [...$ths].map((th) => th.innerText.trim())
|
||||
expect(texts).to.include(headerText)
|
||||
})
|
||||
.then(($ths) => {
|
||||
const index = [...$ths].findIndex(
|
||||
(th) => th.innerText.trim() === headerText
|
||||
)
|
||||
|
||||
return cy
|
||||
.get('.ht_master tbody tr')
|
||||
.then((rows: any) => rows[rowIndex].childNodes[index])
|
||||
.then((cell) => cy.get(cell))
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
// Marks this file as an ES module (rather than a global script) so its
|
||||
// top-level consts don't collide, under the TS type-checker, with the same
|
||||
// names declared in other spec files — see e.g. stage.cy.ts, which gets
|
||||
// this for free via a real import.
|
||||
export {}
|
||||
|
||||
const hostUrl = Cypress.env('hosturl')
|
||||
const appLocation = Cypress.env('appLocation')
|
||||
const longerCommandTimeout = Cypress.env('longerCommandTimeout')
|
||||
|
||||
context('submitted-details tests: ', function () {
|
||||
this.beforeAll(() => {
|
||||
cy.loginAndUpdateValidKey(true)
|
||||
})
|
||||
|
||||
it('1 | clicking an open submit loads its diffs with a single postdata request', () => {
|
||||
// Count every STP request the app makes during the test.
|
||||
// The STP URL is `stp/execute/?_program=...` - glob segments don't match
|
||||
// past `execute/` with a single `*`, so keep the glob within the path.
|
||||
cy.intercept('POST', '**/SASjsApi/stp/**').as('stpExecute')
|
||||
|
||||
cy.visit(`${hostUrl}${appLocation}/#/review/submitted`)
|
||||
cy.get('.app-loading', { timeout: longerCommandTimeout }).should(
|
||||
'not.exist'
|
||||
)
|
||||
|
||||
// the SUBMIT queue list must be rendered with at least one row
|
||||
cy.get('app-submitter clr-datagrid clr-dg-row', {
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
.should('exist')
|
||||
.and('have.length.greaterThan', 0)
|
||||
|
||||
// route-based flow: clicking a row navigates to /review/submitted/:tableId
|
||||
// and triggers exactly one SHOW_DIFFS (auditors/postdata) request
|
||||
cy.get('app-submitter clr-datagrid clr-dg-row')
|
||||
.first()
|
||||
.click()
|
||||
.then(() => {
|
||||
cy.url().should('include', '/review/submitted/')
|
||||
})
|
||||
|
||||
// wait for the diff table to render (the response was applied)
|
||||
cy.get('app-approve-details .card', { timeout: longerCommandTimeout })
|
||||
.should('exist')
|
||||
.should('be.visible')
|
||||
|
||||
// give any (incorrect) duplicate request time to surface
|
||||
cy.wait(3000)
|
||||
|
||||
cy.get('@stpExecute.all').then((allRequests: any) => {
|
||||
// the adapter posts multipart form data, so match on the _program
|
||||
// query param rather than the request body
|
||||
const postdataRequests = allRequests.filter((req: any) =>
|
||||
JSON.stringify(req.request.query || {}).includes('auditors/postdata')
|
||||
)
|
||||
expect(
|
||||
postdataRequests.length,
|
||||
'exactly one auditors/postdata SHOW_DIFFS request'
|
||||
).to.equal(1)
|
||||
|
||||
// the submit queue was already fetched to render the list - opening a
|
||||
// row must not fetch it again
|
||||
const getsubmitsRequests = allRequests.filter((req: any) =>
|
||||
JSON.stringify(req.request.query || {}).includes('editors/getsubmits')
|
||||
)
|
||||
expect(
|
||||
getsubmitsRequests.length,
|
||||
'no editors/getsubmits request after opening a submit'
|
||||
).to.equal(1)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -353,6 +353,346 @@ context('editor tests: ', function () {
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('8 | Dragging a viewbox by its corner handle resizes it', () => {
|
||||
const viewbox_table = 'mpe_audit'
|
||||
|
||||
openTableFromTree(libraryToOpenIncludes, 'mpe_x_test')
|
||||
|
||||
cy.get('.viewbox-open').click()
|
||||
openTableFromViewboxTree(libraryToOpenIncludes, [viewbox_table])
|
||||
|
||||
cy.contains('.open-viewbox', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
// The Viewboxes picker modal is still open at this point, its backdrop
|
||||
// sitting above .viewboxes-container - a real click (unlike cy.find(),
|
||||
// which doesn't care what's visually on top) would land on the modal
|
||||
// instead of the handle underneath it, silently no-opping the drag.
|
||||
closeViewboxModal()
|
||||
|
||||
// Re-query by the title text rather than caching a reference, since
|
||||
// the viewbox can still be re-rendering its content right after
|
||||
// opening.
|
||||
cy.contains('.viewboxes-container .viewbox .table-title', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
.parents('.viewbox')
|
||||
.first()
|
||||
.as('viewboxEl')
|
||||
|
||||
// tableOnClick() calls snapToGrid() asynchronously right after its data
|
||||
// load resolves, which overwrites width/height/x/y for every open
|
||||
// viewbox via the [style.width.px]/[style.height.px] bindings - totally
|
||||
// independent of any drag. The table title above renders immediately
|
||||
// (before that data load finishes), so capturing initialRect right
|
||||
// after it appears races snapToGrid: the box can still silently resize
|
||||
// itself out from under the test between capturing initialRect and the
|
||||
// drag. Waiting for the table's own header cells (populated only once
|
||||
// that same data load - and so snapToGrid - has completed) closes that
|
||||
// race, same signal checkColumns() uses elsewhere in this file.
|
||||
cy.get('@viewboxEl').find('.ht_master.handsontable thead tr th', {
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
cy.get('@viewboxEl').then(($box) => {
|
||||
const initialRect = $box[0].getBoundingClientRect()
|
||||
|
||||
// Chained off one query, not re-queried between each step, so
|
||||
// cypress-real-events keeps operating on the same subject throughout.
|
||||
//
|
||||
// Dragging INWARD (negative offsets, shrinking) rather than outward:
|
||||
// a freshly opened viewbox starts flush against the right edge of the
|
||||
// viewport (x: window.innerWidth - defaultConfig.width, so
|
||||
// box.right === innerWidth exactly). realMouseMove's target
|
||||
// coordinate is computed as an absolute point on the page, so dragging
|
||||
// the corner outward/rightward to grow the box would target a point
|
||||
// past the viewport's right edge, outside the Cypress AUT iframe
|
||||
// entirely - Chrome never delivers a move event for a point outside
|
||||
// the iframe. Shrinking stays well within the box's own footprint
|
||||
// (500x300 default, 200x200 min per .viewbox's CSS), so the target
|
||||
// coordinate is always safely on-screen - same resize() code path,
|
||||
// just exercised in the direction that's actually simulatable.
|
||||
cy.get('@viewboxEl')
|
||||
.find('.dragHandle.corner')
|
||||
.realMouseDown({ button: 'left', position: 'center' })
|
||||
.realMouseMove(-100, -80, { position: 'topLeft' })
|
||||
.realMouseUp()
|
||||
|
||||
// A generous threshold, not an exact pixel match - real rendering has
|
||||
// its own small offsets (see setHandleTransform's "fine tune" +5).
|
||||
// The point is confirming the box actually resizes at all in response
|
||||
// to the drag.
|
||||
cy.get('@viewboxEl').should(($box) => {
|
||||
const rect = $box[0].getBoundingClientRect()
|
||||
|
||||
expect(rect.width, 'width after resize').to.be.lessThan(
|
||||
initialRect.width - 30
|
||||
)
|
||||
expect(rect.height, 'height after resize').to.be.lessThan(
|
||||
initialRect.height - 30
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('9 | Dragging a viewbox by its right-edge handle resizes width only', () => {
|
||||
const viewbox_table = 'mpe_audit'
|
||||
|
||||
openTableFromTree(libraryToOpenIncludes, 'mpe_x_test')
|
||||
|
||||
cy.get('.viewbox-open').click()
|
||||
openTableFromViewboxTree(libraryToOpenIncludes, [viewbox_table])
|
||||
|
||||
cy.contains('.open-viewbox', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
closeViewboxModal()
|
||||
|
||||
cy.contains('.viewboxes-container .viewbox .table-title', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
.parents('.viewbox')
|
||||
.first()
|
||||
.as('viewboxEl')
|
||||
|
||||
// See test 8's comment: snapToGrid() resizes every open viewbox
|
||||
// asynchronously right after its data load resolves, racing initialRect
|
||||
// capture if that happens right after the title (which renders before
|
||||
// the load finishes) appears. Wait for the table's own header cells
|
||||
// first, since those only populate once that same load has completed.
|
||||
cy.get('@viewboxEl').find('.ht_master.handsontable thead tr th', {
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
cy.get('@viewboxEl').then(($box) => {
|
||||
const initialRect = $box[0].getBoundingClientRect()
|
||||
|
||||
// Chained off one query - see test 8's comment on why re-querying
|
||||
// between down/move/up silently drops the move. Dragging INWARD
|
||||
// (negative offset, shrinking) rather than outward - see test 8's
|
||||
// comment: a freshly opened viewbox starts flush against the
|
||||
// viewport's right edge, so growing rightward would target a point
|
||||
// past the AUT iframe's edge, which Chrome never delivers a move
|
||||
// event for.
|
||||
cy.get('@viewboxEl')
|
||||
.find('.dragHandle.right')
|
||||
.realMouseDown({ button: 'left', position: 'center' })
|
||||
.realMouseMove(-100, 0, { position: 'topLeft' })
|
||||
.realMouseUp()
|
||||
|
||||
cy.get('@viewboxEl').should(($box) => {
|
||||
const rect = $box[0].getBoundingClientRect()
|
||||
|
||||
expect(rect.width, 'width after resize').to.be.lessThan(
|
||||
initialRect.width - 30
|
||||
)
|
||||
// This handle must only affect width - height (and the box's own
|
||||
// left edge) stay put.
|
||||
expect(rect.height, 'height unchanged').to.be.closeTo(
|
||||
initialRect.height,
|
||||
5
|
||||
)
|
||||
expect(rect.left, 'left edge unchanged').to.be.closeTo(
|
||||
initialRect.left,
|
||||
5
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('10 | Dragging a viewbox by its bottom-left corner handle resizes it and moves its left edge', () => {
|
||||
const viewbox_table = 'mpe_audit'
|
||||
|
||||
openTableFromTree(libraryToOpenIncludes, 'mpe_x_test')
|
||||
|
||||
cy.get('.viewbox-open').click()
|
||||
openTableFromViewboxTree(libraryToOpenIncludes, [viewbox_table])
|
||||
|
||||
cy.contains('.open-viewbox', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
closeViewboxModal()
|
||||
|
||||
cy.contains('.viewboxes-container .viewbox .table-title', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
.parents('.viewbox')
|
||||
.first()
|
||||
.as('viewboxEl')
|
||||
|
||||
// See test 8's comment: wait for snapToGrid()'s async resize to settle
|
||||
// before capturing initialRect, or the box can silently change size out
|
||||
// from under the test.
|
||||
cy.get('@viewboxEl').find('.ht_master.handsontable thead tr th', {
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
cy.get('@viewboxEl').then(($box) => {
|
||||
const initialRect = $box[0].getBoundingClientRect()
|
||||
|
||||
// Chained off one query - see test 8's comment on why re-querying
|
||||
// between down/move/up silently drops the move. Dragging this
|
||||
// handle right+down (only positive offsets are meaningful for
|
||||
// realMouseMove's position-anchored coordinates) shrinks width
|
||||
// while moving the box's own left edge right by the same amount,
|
||||
// and grows height - unlike every other handle here, this one is
|
||||
// expected to move the box (viewbox.x) as well as resize it, which
|
||||
// is the more error-prone half of this handler to cover.
|
||||
cy.get('@viewboxEl')
|
||||
.find('.dragHandle.corner-left')
|
||||
.realMouseDown({ button: 'left', position: 'center' })
|
||||
.realMouseMove(60, 80, { position: 'topLeft' })
|
||||
.realMouseUp()
|
||||
|
||||
cy.get('@viewboxEl').should(($box) => {
|
||||
const rect = $box[0].getBoundingClientRect()
|
||||
|
||||
expect(rect.width, 'width after resize').to.be.lessThan(
|
||||
initialRect.width - 30
|
||||
)
|
||||
expect(rect.left, 'left edge moved right').to.be.greaterThan(
|
||||
initialRect.left + 30
|
||||
)
|
||||
expect(rect.height, 'height after resize').to.be.greaterThan(
|
||||
initialRect.height + 30
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('11 | Dragging a viewbox by its left-edge handle resizes width and moves its left edge, leaving height alone', () => {
|
||||
const viewbox_table = 'mpe_audit'
|
||||
|
||||
openTableFromTree(libraryToOpenIncludes, 'mpe_x_test')
|
||||
|
||||
cy.get('.viewbox-open').click()
|
||||
openTableFromViewboxTree(libraryToOpenIncludes, [viewbox_table])
|
||||
|
||||
cy.contains('.open-viewbox', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
closeViewboxModal()
|
||||
|
||||
cy.contains('.viewboxes-container .viewbox .table-title', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
.parents('.viewbox')
|
||||
.first()
|
||||
.as('viewboxEl')
|
||||
|
||||
// See test 8's comment: wait for snapToGrid()'s async resize to settle
|
||||
// before capturing initialRect, or the box can silently change size out
|
||||
// from under the test.
|
||||
cy.get('@viewboxEl').find('.ht_master.handsontable thead tr th', {
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
cy.get('@viewboxEl').then(($box) => {
|
||||
const initialRect = $box[0].getBoundingClientRect()
|
||||
|
||||
// Chained off one query - see test 8's comment on why re-querying
|
||||
// between down/move/up silently drops the move. Dragging this
|
||||
// handle right (only positive offsets are meaningful for
|
||||
// realMouseMove's position-anchored coordinates) shrinks width
|
||||
// while moving the box's own left edge right by the same amount -
|
||||
// same viewbox.x-moving behavior as the bottom-left corner, minus
|
||||
// the height change.
|
||||
cy.get('@viewboxEl')
|
||||
.find('.dragHandle.left')
|
||||
.realMouseDown({ button: 'left', position: 'center' })
|
||||
.realMouseMove(60, 0, { position: 'topLeft' })
|
||||
.realMouseUp()
|
||||
|
||||
cy.get('@viewboxEl').should(($box) => {
|
||||
const rect = $box[0].getBoundingClientRect()
|
||||
|
||||
expect(rect.width, 'width after resize').to.be.lessThan(
|
||||
initialRect.width - 30
|
||||
)
|
||||
expect(rect.left, 'left edge moved right').to.be.greaterThan(
|
||||
initialRect.left + 30
|
||||
)
|
||||
expect(rect.height, 'height unchanged').to.be.closeTo(
|
||||
initialRect.height,
|
||||
5
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
it('12 | Dragging a viewbox by its bottom-edge handle resizes height only', () => {
|
||||
const viewbox_table = 'mpe_audit'
|
||||
|
||||
openTableFromTree(libraryToOpenIncludes, 'mpe_x_test')
|
||||
|
||||
cy.get('.viewbox-open').click()
|
||||
openTableFromViewboxTree(libraryToOpenIncludes, [viewbox_table])
|
||||
|
||||
cy.contains('.open-viewbox', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
closeViewboxModal()
|
||||
|
||||
cy.contains('.viewboxes-container .viewbox .table-title', viewbox_table, {
|
||||
matchCase: false,
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
.parents('.viewbox')
|
||||
.first()
|
||||
.as('viewboxEl')
|
||||
|
||||
// See test 8's comment: wait for snapToGrid()'s async resize to settle
|
||||
// before capturing initialRect, or the box can silently change size out
|
||||
// from under the test.
|
||||
cy.get('@viewboxEl').find('.ht_master.handsontable thead tr th', {
|
||||
timeout: longerCommandTimeout
|
||||
})
|
||||
|
||||
cy.get('@viewboxEl').then(($box) => {
|
||||
const initialRect = $box[0].getBoundingClientRect()
|
||||
|
||||
// Chained off one query - see test 8's comment on why re-querying
|
||||
// between down/move/up silently drops the move.
|
||||
cy.get('@viewboxEl')
|
||||
.find('.dragHandle.bottom')
|
||||
.realMouseDown({ button: 'left', position: 'center' })
|
||||
.realMouseMove(0, 100, { position: 'topLeft' })
|
||||
.realMouseUp()
|
||||
|
||||
cy.get('@viewboxEl').should(($box) => {
|
||||
const rect = $box[0].getBoundingClientRect()
|
||||
|
||||
expect(rect.height, 'height after resize').to.be.greaterThan(
|
||||
initialRect.height + 30
|
||||
)
|
||||
// This handle must only affect height - width (and the box's own
|
||||
// left edge) stay put.
|
||||
expect(rect.width, 'width unchanged').to.be.closeTo(
|
||||
initialRect.width,
|
||||
5
|
||||
)
|
||||
expect(rect.left, 'left edge unchanged').to.be.closeTo(
|
||||
initialRect.left,
|
||||
5
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
const removeAllColumns = () => {
|
||||
|
||||
Binary file not shown.
@@ -183,6 +183,12 @@ const isLicensingPage = (callback: any) => {
|
||||
|
||||
const inputLicenseKeyPage = (licenseKey: string, activationKey: string) => {
|
||||
cy.get('button').contains('Paste licence').click()
|
||||
|
||||
// Combined single-string paste is the default format now - switch to
|
||||
// the legacy two-field layout, since this helper fills licenseKey and
|
||||
// activationKey as two separate values.
|
||||
cy.get('button').contains('Paste as two separate keys instead').click()
|
||||
|
||||
cy.get('.license-key-form textarea', { timeout: longerCommandTimeout })
|
||||
.invoke('val', licenseKey)
|
||||
.trigger('input')
|
||||
|
||||
@@ -1,32 +1,30 @@
|
||||
import * as base64Converter from 'base64-arraybuffer'
|
||||
|
||||
export const base64ToArrayBuffer = (base64: string) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const dataUrl = "data:application/octet-binary;base64," + base64;
|
||||
|
||||
const dataUrl = 'data:application/octet-binary;base64,' + base64
|
||||
|
||||
fetch(dataUrl)
|
||||
.then(res => res.arrayBuffer())
|
||||
.then(buffer => {
|
||||
.then((res) => res.arrayBuffer())
|
||||
.then((buffer) => {
|
||||
resolve(new Uint8Array(buffer))
|
||||
}).catch((err) => {
|
||||
})
|
||||
.catch((err) => {
|
||||
reject(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
export const arrayBufferToBase64 = (arrayBuffer: any) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const blob = new Blob([arrayBuffer])
|
||||
|
||||
const reader = new FileReader();
|
||||
|
||||
reader.onload = async function(event){
|
||||
if (event.target) {
|
||||
var base64: any = event.target.result
|
||||
base64 = base64.substring(37, base64.length)
|
||||
|
||||
resolve(base64)
|
||||
}
|
||||
};
|
||||
|
||||
reader.readAsDataURL(blob);
|
||||
})
|
||||
}
|
||||
// Blob + FileReader.readAsDataURL (a natural alternative here) is
|
||||
// unreliable in the Cypress runner's iframe - onload/onerror can simply
|
||||
// never fire, leaving the promise permanently unsettled (a silent hang,
|
||||
// surfacing only as Mocha's "done() was never invoked" 30s later with no
|
||||
// clue why). base64-arraybuffer's encode() is synchronous and
|
||||
// dependency-free - no browser API involved, so this class of hang isn't
|
||||
// possible - and it's the same library the app itself uses for this exact
|
||||
// conversion.
|
||||
export const arrayBufferToBase64 = (
|
||||
arrayBuffer: ArrayBuffer
|
||||
): Promise<string> => {
|
||||
return Promise.resolve(base64Converter.encode(arrayBuffer))
|
||||
}
|
||||
|
||||
Generated
+1768
-1427
File diff suppressed because it is too large
Load Diff
+17
-13
@@ -41,22 +41,22 @@
|
||||
},
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"@angular/animations": "^20.3.26",
|
||||
"@angular/animations": "^20.3.27",
|
||||
"@angular/cdk": "^20.2.14",
|
||||
"@angular/common": "^20.3.26",
|
||||
"@angular/compiler": "^20.3.26",
|
||||
"@angular/core": "^20.3.26",
|
||||
"@angular/forms": "^20.3.26",
|
||||
"@angular/platform-browser": "^20.3.26",
|
||||
"@angular/platform-browser-dynamic": "^20.3.26",
|
||||
"@angular/router": "^20.3.26",
|
||||
"@angular/common": "^20.3.27",
|
||||
"@angular/compiler": "^20.3.27",
|
||||
"@angular/core": "^20.3.27",
|
||||
"@angular/forms": "^20.3.27",
|
||||
"@angular/platform-browser": "^20.3.27",
|
||||
"@angular/platform-browser-dynamic": "^20.3.27",
|
||||
"@angular/router": "^20.3.27",
|
||||
"@cds/core": "^6.15.1",
|
||||
"@clr/angular": "file:libraries/clr-angular-17.9.0.tgz",
|
||||
"@clr/icons": "^13.0.2",
|
||||
"@clr/ui": "file:libraries/clr-ui-17.9.0.tgz",
|
||||
"@handsontable/angular-wrapper": "^18.0.0",
|
||||
"@sasjs/adapter": "^4.17.3",
|
||||
"@sasjs/utils": "^3.5.9",
|
||||
"@handsontable/angular-wrapper": "18.0.0",
|
||||
"@sasjs/adapter": "^4.18.0",
|
||||
"@sasjs/utils": "^3.6.0",
|
||||
"@sheet/crypto": "file:libraries/sheet-crypto.tgz",
|
||||
"@types/d3-graphviz": "^2.6.7",
|
||||
"@types/text-encoding": "0.0.35",
|
||||
@@ -69,7 +69,7 @@
|
||||
"d3-graphviz": "^5.0.2",
|
||||
"exceljs": "^4.4.0",
|
||||
"fs-extra": "^7.0.1",
|
||||
"handsontable": "^18.0.0",
|
||||
"handsontable": "18.0.0",
|
||||
"https-browserify": "1.0.0",
|
||||
"hyperformula": "^2.5.0",
|
||||
"iconv-lite": "^0.5.0",
|
||||
@@ -100,7 +100,7 @@
|
||||
"@angular-eslint/schematics": "19.8.1",
|
||||
"@angular-eslint/template-parser": "19.8.1",
|
||||
"@angular/cli": "^20.3.32",
|
||||
"@angular/compiler-cli": "^20.3.26",
|
||||
"@angular/compiler-cli": "^20.3.27",
|
||||
"@babel/plugin-proposal-private-methods": "^7.18.6",
|
||||
"@compodoc/compodoc": "^2.0.0",
|
||||
"@cypress/webpack-preprocessor": "^5.17.1",
|
||||
@@ -148,6 +148,10 @@
|
||||
"ajv": "8.18.0",
|
||||
"uuid": "11.1.1",
|
||||
"lighthouse": "13.4.0",
|
||||
"fast-uri": "3.1.7",
|
||||
"readdir-glob": {
|
||||
"brace-expansion": "^5.0.9"
|
||||
},
|
||||
"exceljs": {
|
||||
"archiver": "^8.0.0",
|
||||
"unzipper": "^0.12.5"
|
||||
|
||||
@@ -130,25 +130,18 @@
|
||||
</div>
|
||||
}
|
||||
<div class="logo d-flex clr-align-items-center">
|
||||
@if (!router.url.includes('deploy')) {
|
||||
<a href="#" [routerLink]="['/']" class="nav-link">
|
||||
<img
|
||||
class="without-text d-block d-md-none"
|
||||
src="images/dc-logo.svg"
|
||||
alt="datacontroller logo without text"
|
||||
/>
|
||||
<img
|
||||
class="with-text d-none d-md-block"
|
||||
src="images/datacontroller.svg"
|
||||
alt="datacontroller logo"
|
||||
/>
|
||||
</a>
|
||||
}
|
||||
@if (router.url.includes('deploy')) {
|
||||
<a>
|
||||
<span class="clr-icon header-logo ml-10"></span>
|
||||
</a>
|
||||
}
|
||||
<a href="#" [routerLink]="['/']" class="nav-link">
|
||||
<img
|
||||
class="without-text d-block d-md-none"
|
||||
src="images/dc-logo.svg"
|
||||
alt="datacontroller logo without text"
|
||||
/>
|
||||
<img
|
||||
class="with-text d-none d-md-block"
|
||||
src="images/datacontroller.svg"
|
||||
alt="datacontroller logo"
|
||||
/>
|
||||
</a>
|
||||
</div>
|
||||
@if (
|
||||
!router.url.includes('deploy') && !router.url.includes('licensing')
|
||||
@@ -318,6 +311,45 @@
|
||||
<div class="subline dec"></div>
|
||||
</div>
|
||||
}
|
||||
@if (startupSteps.length > 0) {
|
||||
<div class="startup-checks">
|
||||
@for (step of startupSteps; track step.label) {
|
||||
<div
|
||||
class="startup-check"
|
||||
[class.startup-check--error]="step.status === 'error'"
|
||||
[class.startup-check--done]="step.status === 'done'"
|
||||
>
|
||||
@switch (step.status) {
|
||||
@case ('pending') {
|
||||
<clr-icon
|
||||
shape="circle"
|
||||
class="is-solid startup-check__icon--pending"
|
||||
></clr-icon>
|
||||
}
|
||||
@case ('in_progress') {
|
||||
<clr-spinner clrSmall></clr-spinner>
|
||||
}
|
||||
@case ('done') {
|
||||
<clr-icon
|
||||
shape="check-circle"
|
||||
class="is-solid startup-check__icon--done"
|
||||
></clr-icon>
|
||||
}
|
||||
@case ('error') {
|
||||
<clr-icon
|
||||
shape="exclamation-circle"
|
||||
class="is-solid startup-check__icon--error"
|
||||
></clr-icon>
|
||||
}
|
||||
}
|
||||
<span class="startup-check__label">{{ step.label }}</span>
|
||||
@if (step.detail) {
|
||||
<span class="startup-check__detail">{{ step.detail }}</span>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
}
|
||||
<!-- /App Loading Page -->
|
||||
|
||||
@@ -19,6 +19,10 @@ import { InfoModal } from './models/InfoModal'
|
||||
import { DcAdapterSettings } from './models/DcAdapterSettings'
|
||||
import { AppStoreService } from './services/app-store.service'
|
||||
import { LicenceService } from './services/licence.service'
|
||||
import {
|
||||
StartupCheckService,
|
||||
StartupStep
|
||||
} from './services/startup-check.service'
|
||||
import '@cds/core/icon/register.js'
|
||||
import {
|
||||
ClarityIcons,
|
||||
@@ -64,6 +68,7 @@ export class AppComponent {
|
||||
public requestsModal: boolean = false
|
||||
public showRegistration: boolean = true
|
||||
public startupDataLoaded: boolean = false
|
||||
public startupSteps: StartupStep[] = []
|
||||
public demoLimitNotice: { open: boolean; featureName: string } = {
|
||||
open: false,
|
||||
featureName: ''
|
||||
@@ -81,11 +86,16 @@ export class AppComponent {
|
||||
private location: Location,
|
||||
private eventService: EventService,
|
||||
private appStoreService: AppStoreService,
|
||||
private startupCheckService: StartupCheckService,
|
||||
private cdr: ChangeDetectorRef,
|
||||
private elementRef: ElementRef
|
||||
) {
|
||||
this.parseDcAdapterSettings()
|
||||
|
||||
this.startupCheckService.steps$.subscribe((steps) => {
|
||||
this.startupSteps = steps
|
||||
})
|
||||
|
||||
/**
|
||||
* Prints app info in the console such as:
|
||||
* - Adapter versions
|
||||
|
||||
@@ -21,8 +21,6 @@ export class DeployComponent implements OnInit {
|
||||
public step: number = 0
|
||||
public adminGroups: any = []
|
||||
|
||||
public client_id: string = ''
|
||||
public client_secret: string = ''
|
||||
public appLoc: string = ''
|
||||
public dcPath: string = ''
|
||||
public selectedAdminGroup: string = ''
|
||||
@@ -52,9 +50,6 @@ export class DeployComponent implements OnInit {
|
||||
this.sasJs = this.sasService.getSasjsInstance()
|
||||
this.sasJsConfig = this.sasService.getSasjsConfig()
|
||||
this.appLoc = this.dcAdapterSettings?.appLoc || ''
|
||||
this.client_id = localStorage.getItem('deploy_client_id') || ''
|
||||
this.client_secret = localStorage.getItem('deploy_secret_key') || ''
|
||||
this.dcPath = localStorage.getItem('deploy_dc_loc') || ''
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
|
||||
@@ -77,69 +77,173 @@
|
||||
}
|
||||
|
||||
<h4 class="text-center my-15">Viya Deploy</h4>
|
||||
<p class="deploy-intro">
|
||||
Configure and deploy Data Controller to your Viya environment. Deployment
|
||||
creates the backend SAS services and the control library used by the
|
||||
application.
|
||||
</p>
|
||||
<hr />
|
||||
<label for="dcloc" class="mt-20 clr-control-label">App Loc</label>
|
||||
<div class="mb-10 clr-control-container">
|
||||
<div class="clr-input-wrapper">
|
||||
<p class="mt-0">{{ appLoc }}</p>
|
||||
|
||||
<div class="deploy-field">
|
||||
<label class="clr-control-label">App Loc</label>
|
||||
<p class="deploy-field-description">
|
||||
The SAS drive folder in which the Data Controller frontend and services are
|
||||
deployed. Derived from your deployment configuration — it cannot be
|
||||
changed here.
|
||||
</p>
|
||||
<div class="clr-control-container">
|
||||
<div class="clr-input-wrapper">
|
||||
<p class="m-0">{{ appLoc }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label for="dcloc" class="mt-20 clr-control-label">DC Loc</label>
|
||||
<div class="mb-10 clr-control-container dc-loc-input-wrapper">
|
||||
<div class="clr-input-wrapper small-mt">
|
||||
<input clrInput name="dcloc" [(ngModel)]="dcPath" />
|
||||
<div class="deploy-field">
|
||||
<label for="dcloc" class="clr-control-label">DC Loc</label>
|
||||
<p class="deploy-field-description">
|
||||
A physical directory on the compute server to which the deployment user can
|
||||
write. Data Controller stores its control tables, staging area and audit
|
||||
history here.
|
||||
</p>
|
||||
<div class="clr-control-container dc-loc-input-wrapper">
|
||||
<div class="clr-input-wrapper small-mt">
|
||||
<input clrInput name="dcloc" [(ngModel)]="dcPath" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label for="dcloc" class="mt-20 clr-control-label">SAS Admin group</label>
|
||||
<div class="mb-10 clr-control-container">
|
||||
<div class="clr-input-wrapper small-mt">
|
||||
@if (!adminGroupsLoading) {
|
||||
<select clrSelect name="options" [(ngModel)]="selectedAdminGroup">
|
||||
@for (adminGroup of adminGroups; track adminGroup) {
|
||||
<option [value]="adminGroup.id">
|
||||
{{ adminGroup.name }}
|
||||
</option>
|
||||
<div class="deploy-field">
|
||||
<label for="adminGroup" class="clr-control-label">SAS Admin group</label>
|
||||
<p class="deploy-field-description">
|
||||
The group you select becomes the Data Controller Admin Group —
|
||||
everyone in it will have unrestricted access to Data Controller. By default
|
||||
the list is filtered to the groups your identity
|
||||
@if (currentUserInfo?.id) {
|
||||
(<strong>{{ currentUserInfo?.id }}</strong
|
||||
>)
|
||||
}
|
||||
is a member of. Toggle below to list every group on the Viya server.
|
||||
</p>
|
||||
<clr-toggle-container class="mt-0">
|
||||
<clr-toggle-wrapper>
|
||||
<input
|
||||
id="show-all-groups-toggle"
|
||||
type="checkbox"
|
||||
[(ngModel)]="showAllGroups"
|
||||
(ngModelChange)="onShowAllGroupsChange()"
|
||||
clrToggle
|
||||
/>
|
||||
<label for="show-all-groups-toggle">Show all groups</label>
|
||||
</clr-toggle-wrapper>
|
||||
</clr-toggle-container>
|
||||
<div class="clr-control-container">
|
||||
<div class="clr-input-wrapper small-mt">
|
||||
@if (!adminGroupsLoading) {
|
||||
<select clrSelect name="adminGroup" [(ngModel)]="selectedAdminGroup">
|
||||
@for (adminGroup of adminGroups; track adminGroup) {
|
||||
<option [value]="adminGroup.id">
|
||||
{{ adminGroup.name }}
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
@if (adminGroupsLoading) {
|
||||
<clr-spinner clrInline class="spinner-sm"></clr-spinner>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (!showAllContexts) {
|
||||
<div class="deploy-field">
|
||||
<label for="batchId" class="clr-control-label">Batch ID</label>
|
||||
<p class="deploy-field-description">
|
||||
The batch identity (<code>runServerAs</code>) under which Data Controller
|
||||
jobs will execute. It is used to filter the Compute Context dropdown below
|
||||
to only the contexts running as this identity.
|
||||
</p>
|
||||
<div class="clr-control-container">
|
||||
<div class="clr-input-wrapper small-mt">
|
||||
@if (!computeContextsLoading) {
|
||||
<select
|
||||
clrSelect
|
||||
name="batchId"
|
||||
[(ngModel)]="selectedBatchId"
|
||||
(ngModelChange)="onBatchIdChange()"
|
||||
>
|
||||
@for (batchId of batchIds; track batchId) {
|
||||
<option [value]="batchId">
|
||||
{{ batchId }}
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
@if (adminGroupsLoading) {
|
||||
<clr-spinner clrInline class="spinner-sm"></clr-spinner>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<label for="computeContext" class="mt-20 clr-control-label"
|
||||
>Compute Context</label
|
||||
>
|
||||
<div class="mb-10 clr-control-container">
|
||||
<div class="clr-input-wrapper small-mt">
|
||||
@if (!computeContextsLoading) {
|
||||
<select
|
||||
clrSelect
|
||||
name="options"
|
||||
(ngModelChange)="onComputeContextChange($event)"
|
||||
[(ngModel)]="selectedComputeContext"
|
||||
>
|
||||
@for (computeContext of computeContexts; track computeContext) {
|
||||
<option [value]="computeContext.id">
|
||||
{{ computeContext.name }}
|
||||
</option>
|
||||
@if (computeContextsLoading) {
|
||||
<clr-spinner clrInline class="spinner-sm"></clr-spinner>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
@if (computeContextsLoading) {
|
||||
<clr-spinner clrInline class="spinner-sm"></clr-spinner>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div class="deploy-field">
|
||||
<label for="computeContext" class="clr-control-label">Compute Context</label>
|
||||
<p class="deploy-field-description">
|
||||
The compute context used to run the Data Controller services (including the
|
||||
<code>makedata</code> deployment job). Only reusable contexts matching the
|
||||
selected Batch ID are shown, unless the toggle below is enabled.
|
||||
</p>
|
||||
<clr-toggle-container class="mt-0">
|
||||
<clr-toggle-wrapper>
|
||||
<input
|
||||
id="show-all-contexts-toggle"
|
||||
type="checkbox"
|
||||
[(ngModel)]="showAllContexts"
|
||||
(ngModelChange)="onShowAllContextsChange()"
|
||||
clrToggle
|
||||
/>
|
||||
<label for="show-all-contexts-toggle">Show all compute contexts</label>
|
||||
</clr-toggle-wrapper>
|
||||
</clr-toggle-container>
|
||||
<div class="clr-control-container">
|
||||
<div class="clr-input-wrapper small-mt">
|
||||
@if (!computeContextsLoading) {
|
||||
<select
|
||||
clrSelect
|
||||
name="computeContext"
|
||||
(ngModelChange)="onComputeContextChange($event)"
|
||||
[(ngModel)]="selectedComputeContext"
|
||||
>
|
||||
@for (
|
||||
computeContext of getFilteredComputeContexts();
|
||||
track computeContext
|
||||
) {
|
||||
<option [value]="computeContext.id">
|
||||
{{ computeContext.name }}
|
||||
</option>
|
||||
}
|
||||
</select>
|
||||
}
|
||||
@if (computeContextsLoading) {
|
||||
<clr-spinner clrInline class="spinner-sm"></clr-spinner>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (runningAsUser) {
|
||||
<label for="dcloc" class="mt-20 clr-control-label">Running as user:</label>
|
||||
<div class="mb-10 clr-control-container">
|
||||
<div class="clr-input-wrapper">
|
||||
<p class="mt-0">{{ runningAsUser }}</p>
|
||||
<div class="deploy-field">
|
||||
<label class="clr-control-label">Running as user</label>
|
||||
<p class="deploy-field-description">
|
||||
The identity under which Data Controller jobs will run with the selected
|
||||
compute context. This user must be able to write to the DC Loc above.
|
||||
</p>
|
||||
<div class="clr-control-container">
|
||||
<div class="clr-input-wrapper">
|
||||
<p class="m-0">
|
||||
<strong>{{ runningAsUser }}</strong>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@@ -25,6 +25,13 @@ import {
|
||||
Item as ComputeContextItem
|
||||
} from 'src/app/viya-api-explorer/models/viya-compute-contexts.model'
|
||||
|
||||
export interface ComputeContextInfo {
|
||||
id: string
|
||||
name: string
|
||||
runAs: string | null
|
||||
reusable: boolean
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-automatic-deploy',
|
||||
templateUrl: './automatic.component.html',
|
||||
@@ -60,6 +67,21 @@ export class AutomaticComponent implements OnInit {
|
||||
public currentUserInfoLoading: boolean = false
|
||||
public computeContextsLoading: boolean = false
|
||||
public adminGroups: { id: string; name: string }[] = []
|
||||
/** Compute contexts enriched with their batch identity and reusability */
|
||||
public computeContextInfos: ComputeContextInfo[] = []
|
||||
/** Distinct batch identities (runServerAs) across reusable contexts */
|
||||
public batchIds: string[] = []
|
||||
public selectedBatchId: string = ''
|
||||
/**
|
||||
* When enabled, any compute context can be chosen (the batch id dropdown
|
||||
* is hidden and no reusability / batch id filtering is applied)
|
||||
*/
|
||||
public showAllContexts: boolean = false
|
||||
/** All groups on the Viya server */
|
||||
public allAdminGroups: { id: string; name: string }[] = []
|
||||
/** Groups the current user is a member of */
|
||||
public memberAdminGroups: { id: string; name: string }[] = []
|
||||
public showAllGroups: boolean = false
|
||||
public runningAsUser: string | undefined
|
||||
public currentUserInfo: ViyaApiCurrentUser | null = null
|
||||
public computeContexts: ComputeContextItem[] = []
|
||||
@@ -104,9 +126,9 @@ export class AutomaticComponent implements OnInit {
|
||||
}
|
||||
|
||||
public async loadData() {
|
||||
await this.getCurrentUser()
|
||||
await this.getAdminGroups()
|
||||
await this.getComputeContexts()
|
||||
await this.getCurrentUser()
|
||||
|
||||
setTimeout(() => {
|
||||
if (this.selectedComputeContext) {
|
||||
@@ -120,20 +142,13 @@ export class AutomaticComponent implements OnInit {
|
||||
this.computeContextsLoading = true
|
||||
|
||||
this.sasViyaService.getComputeContexts().subscribe(
|
||||
(res: ViyaComputeContexts) => {
|
||||
this.computeContextsLoading = false
|
||||
|
||||
const defaultContext = res.items.find(
|
||||
(item: ComputeContextItem) =>
|
||||
item.name === 'SAS Job Execution compute context'
|
||||
)
|
||||
|
||||
if (defaultContext) {
|
||||
this.selectedComputeContext = defaultContext.id
|
||||
}
|
||||
|
||||
async (res: ViyaComputeContexts) => {
|
||||
this.computeContexts = res.items
|
||||
|
||||
await this.getComputeContextDetails()
|
||||
|
||||
this.computeContextsLoading = false
|
||||
|
||||
resolve()
|
||||
},
|
||||
(err) => {
|
||||
@@ -143,6 +158,137 @@ export class AutomaticComponent implements OnInit {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* The `/compute/contexts` list view is minimal, so each context is fetched
|
||||
* in full (in parallel) to pick up its batch identity (runServerAs) and
|
||||
* whether it reuses server processes. Only reusable contexts with a batch
|
||||
* identity feed the batch id dropdown.
|
||||
*/
|
||||
public async getComputeContextDetails() {
|
||||
const infos = await Promise.all(
|
||||
this.computeContexts.map(
|
||||
(context: ComputeContextItem) =>
|
||||
new Promise<ComputeContextInfo>((resolveInfo) => {
|
||||
this.sasViyaService.getComputeContextById(context.id).subscribe(
|
||||
(details: ComputeContextDetails) => {
|
||||
resolveInfo({
|
||||
id: context.id,
|
||||
name: context.name,
|
||||
runAs: this.extractRunAs(details),
|
||||
reusable: details.attributes?.reuseServerProcesses === 'true'
|
||||
})
|
||||
},
|
||||
(err: any) => {
|
||||
this.loggerService.error(
|
||||
`Error while getting compute context ${context.name}`,
|
||||
err
|
||||
)
|
||||
|
||||
resolveInfo({
|
||||
id: context.id,
|
||||
name: context.name,
|
||||
runAs: null,
|
||||
reusable: false
|
||||
})
|
||||
}
|
||||
)
|
||||
})
|
||||
)
|
||||
)
|
||||
|
||||
this.computeContextInfos = infos
|
||||
|
||||
this.batchIds = [
|
||||
...new Set(
|
||||
infos
|
||||
.filter((info) => info.reusable && info.runAs)
|
||||
.map((info) => info.runAs as string)
|
||||
)
|
||||
]
|
||||
|
||||
if (this.batchIds.length) {
|
||||
this.selectedBatchId = this.batchIds[0]
|
||||
}
|
||||
|
||||
const filteredContexts = this.getFilteredComputeContexts()
|
||||
|
||||
const defaultContext =
|
||||
filteredContexts.find(
|
||||
(info: ComputeContextInfo) =>
|
||||
info.name === 'SAS Job Execution compute context'
|
||||
) || filteredContexts[0]
|
||||
|
||||
if (defaultContext) {
|
||||
this.selectedComputeContext = defaultContext.id
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pulls the runAs (batch) identity out of a compute context. The batch user
|
||||
* is exposed as `attributes.runServerAs` in the Viya compute context API
|
||||
* response. Not all contexts expose one.
|
||||
*/
|
||||
public extractRunAs(details: ComputeContextDetails): string | null {
|
||||
return details.attributes?.runServerAs || null
|
||||
}
|
||||
|
||||
/**
|
||||
* The contexts offered in the dropdown. By default only reusable contexts
|
||||
* (`reuseServerProcesses`) matching the selected batch id are shown. When
|
||||
* the `showAllContexts` toggle is on, all contexts are shown.
|
||||
*/
|
||||
public getFilteredComputeContexts(): ComputeContextInfo[] {
|
||||
if (this.showAllContexts) {
|
||||
return this.computeContextInfos
|
||||
}
|
||||
|
||||
return this.computeContextInfos.filter(
|
||||
(info: ComputeContextInfo) =>
|
||||
info.reusable && info.runAs === this.selectedBatchId
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Changing the batch id re-filters the compute context dropdown and makes
|
||||
* sure the currently selected context exists in the displayed list.
|
||||
*/
|
||||
public onBatchIdChange() {
|
||||
this.ensureSelectedComputeContext()
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the compute context dropdown between contexts matching the
|
||||
* selected batch id and all contexts on the Viya server.
|
||||
*/
|
||||
public onShowAllContextsChange() {
|
||||
this.ensureSelectedComputeContext()
|
||||
}
|
||||
|
||||
private ensureSelectedComputeContext() {
|
||||
const filteredContexts = this.getFilteredComputeContexts()
|
||||
|
||||
const selectedContextExists = filteredContexts.some(
|
||||
(info: ComputeContextInfo) => info.id === this.selectedComputeContext
|
||||
)
|
||||
|
||||
if (!selectedContextExists) {
|
||||
this.selectedComputeContext = filteredContexts.length
|
||||
? filteredContexts[0].id
|
||||
: ''
|
||||
}
|
||||
|
||||
this.updateRunningAsUser()
|
||||
}
|
||||
|
||||
private updateRunningAsUser() {
|
||||
const selectedContext = this.computeContextInfos.find(
|
||||
(info: ComputeContextInfo) => info.id === this.selectedComputeContext
|
||||
)
|
||||
|
||||
this.runningAsUser =
|
||||
selectedContext?.runAs || this.currentUserInfo?.id || 'unknown'
|
||||
}
|
||||
|
||||
public async getCurrentUser() {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.currentUserInfoLoading = true
|
||||
@@ -170,16 +316,21 @@ export class AutomaticComponent implements OnInit {
|
||||
this.adminGroupsLoading = true
|
||||
;(this.sasViyaService
|
||||
.getAdminGroups()
|
||||
.subscribe((res: ViyaApiIdentities) => {
|
||||
this.adminGroupsLoading = false
|
||||
.subscribe(async (res: ViyaApiIdentities) => {
|
||||
// Map admin groups with only needed fields
|
||||
this.adminGroups = res.items.map((item: Item) => {
|
||||
this.allAdminGroups = res.items.map((item: Item) => {
|
||||
return {
|
||||
id: item.id,
|
||||
name: item.name
|
||||
}
|
||||
})
|
||||
|
||||
await this.getMemberAdminGroups()
|
||||
|
||||
this.applyAdminGroupFilter()
|
||||
|
||||
this.adminGroupsLoading = false
|
||||
|
||||
resolve()
|
||||
}),
|
||||
(err: any) => {
|
||||
@@ -192,16 +343,72 @@ export class AutomaticComponent implements OnInit {
|
||||
})
|
||||
}
|
||||
|
||||
public async onComputeContextChange(computeContextId: string) {
|
||||
this.sasViyaService
|
||||
.getComputeContextById(computeContextId)
|
||||
.subscribe((res: ComputeContextDetails) => {
|
||||
if (res.attributes && res.attributes.runServerAs) {
|
||||
this.runningAsUser = res.attributes.runServerAs
|
||||
} else {
|
||||
this.runningAsUser = this.currentUserInfo?.id || 'unknown'
|
||||
/**
|
||||
* Fetches the groups the current user is a member of, from the Viya
|
||||
* identities API. If the memberships cannot be fetched, the member list
|
||||
* falls back to all groups.
|
||||
*/
|
||||
public async getMemberAdminGroups() {
|
||||
return new Promise<void>((resolve) => {
|
||||
this.sasViyaService.getCurrentUserGroupMemberships().subscribe(
|
||||
(res: ViyaApiIdentities) => {
|
||||
const memberIds = res.items.map((item: Item) => item.id)
|
||||
|
||||
this.memberAdminGroups = this.allAdminGroups.filter(
|
||||
(group: { id: string; name: string }) =>
|
||||
memberIds.includes(group.id)
|
||||
)
|
||||
|
||||
resolve()
|
||||
},
|
||||
(err: any) => {
|
||||
this.loggerService.error(
|
||||
'Error while getting user group memberships',
|
||||
err
|
||||
)
|
||||
this.memberAdminGroups = this.allAdminGroups
|
||||
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the SAS Admin group dropdown between the groups the current user
|
||||
* is a member of and all groups on the Viya server.
|
||||
*/
|
||||
public onShowAllGroupsChange() {
|
||||
this.applyAdminGroupFilter()
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies the member/all groups filter to the dropdown and makes sure the
|
||||
* currently selected group exists in the displayed list.
|
||||
*/
|
||||
private applyAdminGroupFilter() {
|
||||
this.adminGroups =
|
||||
this.showAllGroups || !this.memberAdminGroups.length
|
||||
? this.allAdminGroups
|
||||
: this.memberAdminGroups
|
||||
|
||||
const selectedGroupExists = this.adminGroups.some(
|
||||
(group: { id: string; name: string }) =>
|
||||
group.id === this.selectedAdminGroup
|
||||
)
|
||||
|
||||
if (!selectedGroupExists && this.adminGroups.length) {
|
||||
this.selectedAdminGroup = this.adminGroups[0].id
|
||||
}
|
||||
}
|
||||
|
||||
public async onComputeContextChange(computeContextId: string) {
|
||||
// The explicit (ngModelChange) handler runs before the [(ngModel)]
|
||||
// assignment updates the field, so synchronise the selected context id
|
||||
// here before deriving the running user. Otherwise the displayed user
|
||||
// lags behind the dropdown by one change.
|
||||
this.selectedComputeContext = computeContextId
|
||||
this.updateRunningAsUser()
|
||||
}
|
||||
|
||||
public getComputeContextName(id: string): string | undefined {
|
||||
@@ -341,7 +548,8 @@ export class AutomaticComponent implements OnInit {
|
||||
this.eventService.showAbortModal('makedata', abortMsg, {
|
||||
SYSWARNINGTEXT: abortRes.SYSWARNINGTEXT,
|
||||
SYSERRORTEXT: abortRes.SYSERRORTEXT,
|
||||
MAC: macMsg
|
||||
MAC: macMsg,
|
||||
_PROGRAM: abortRes._PROGRAM
|
||||
})
|
||||
}
|
||||
|
||||
@@ -373,7 +581,9 @@ export class AutomaticComponent implements OnInit {
|
||||
let contextname = `&_contextname=${params.contextName}`
|
||||
let admin = `&admin=${params.admin}`
|
||||
let dcPath = `&dcpath=${params.dcPath}`
|
||||
let debug = this.sasService.getDebugUrlParam()
|
||||
// Debug is ALWAYS enabled for makedata — it runs only once during
|
||||
// deployment and the full log is needed to diagnose any issues.
|
||||
let debug = '&_debug=131'
|
||||
|
||||
let programUrl =
|
||||
serverUrl +
|
||||
@@ -387,6 +597,53 @@ export class AutomaticComponent implements OnInit {
|
||||
debug
|
||||
|
||||
window.open(programUrl)
|
||||
|
||||
// Poll for makedata completion. The makedata service self-deletes
|
||||
// when it finishes successfully, so we check if it's still present
|
||||
// in the admin folder. When it's gone, reload the app fresh.
|
||||
this.pollMakedataCompletion()
|
||||
}
|
||||
|
||||
private makedataPollInterval: any = null
|
||||
|
||||
private pollMakedataCompletion() {
|
||||
if (this.makedataPollInterval) {
|
||||
clearInterval(this.makedataPollInterval)
|
||||
}
|
||||
|
||||
let attempts = 0
|
||||
const maxAttempts = 120 // 10 minutes at 5s intervals
|
||||
|
||||
this.makedataPollInterval = setInterval(async () => {
|
||||
attempts++
|
||||
console.log(
|
||||
`pollMakedataCompletion: checking if makedata is gone (attempt ${attempts}/${maxAttempts})`
|
||||
)
|
||||
|
||||
try {
|
||||
const makedataGone = await this.sasService.viyaMakedataSuccessfull()
|
||||
if (makedataGone) {
|
||||
console.log(
|
||||
'pollMakedataCompletion: makedata job is gone, reloading app'
|
||||
)
|
||||
clearInterval(this.makedataPollInterval)
|
||||
this.makedataPollInterval = null
|
||||
|
||||
// Reload the app fresh from the SASJobExecution URL
|
||||
window.location.href = window.location.href.split('#')[0]
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('pollMakedataCompletion: error checking', err)
|
||||
}
|
||||
|
||||
if (attempts >= maxAttempts) {
|
||||
console.warn(
|
||||
'pollMakedataCompletion: timed out after 10 minutes, stopping poll'
|
||||
)
|
||||
clearInterval(this.makedataPollInterval)
|
||||
this.makedataPollInterval = null
|
||||
}
|
||||
}, 5000)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -428,9 +685,12 @@ export class AutomaticComponent implements OnInit {
|
||||
return
|
||||
}
|
||||
|
||||
/* Use a function replacement so $ in computeContextName is treated as a
|
||||
literal character. In a string replacement, $ has special meaning
|
||||
($&, $1, $` etc.); a function return value is used verbatim. */
|
||||
const updatedContent = indexHtmlContent.replace(
|
||||
/contextname="[^"]*"/g,
|
||||
`contextname="${computeContextName}"`
|
||||
() => `contextname="${computeContextName}"`
|
||||
)
|
||||
|
||||
await this.sasService
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import { ManualComponent } from './manual.component'
|
||||
|
||||
// validateDeploy() is fire-and-forget (doesn't return its own promise
|
||||
// chain), so tests need to wait for it to settle some other way. A
|
||||
// macrotask boundary guarantees every already-queued microtask (regardless
|
||||
// of how many .then() hops validateDeploy's chain has) has run first.
|
||||
const flushPromiseChain = () => new Promise((resolve) => setTimeout(resolve, 0))
|
||||
|
||||
/**
|
||||
* validateDeploy() only touches sasService.request, eventService.showInfoModal
|
||||
* and loggerService.log - these stubs cover exactly that surface, not the
|
||||
* full real services (no TestBed/DI needed, same plain-instantiation-with-
|
||||
* stubs precedent as app.service.spec.ts).
|
||||
*/
|
||||
const buildDeps = () => {
|
||||
const sasService: any = {
|
||||
request: jasmine.createSpy('request')
|
||||
}
|
||||
const eventService: any = {
|
||||
showInfoModal: jasmine.createSpy('showInfoModal')
|
||||
}
|
||||
const loggerService: any = {
|
||||
log: jasmine.createSpy('log')
|
||||
}
|
||||
const deployService: any = {}
|
||||
|
||||
return { sasService, eventService, loggerService, deployService }
|
||||
}
|
||||
|
||||
const buildManualComponent = (deps: ReturnType<typeof buildDeps>) =>
|
||||
new ManualComponent(
|
||||
deps.sasService,
|
||||
deps.eventService,
|
||||
deps.loggerService,
|
||||
deps.deployService
|
||||
)
|
||||
|
||||
describe('ManualComponent - validateDeploy', () => {
|
||||
it('sets validationState to success when saslibs is present on a normal object response', async () => {
|
||||
const deps = buildDeps()
|
||||
deps.sasService.request.and.resolveTo({
|
||||
adapterResponse: { saslibs: { SOME_LIB: ['SOME_TABLE'] } }
|
||||
})
|
||||
|
||||
const component = buildManualComponent(deps)
|
||||
component.validateDeploy()
|
||||
await flushPromiseChain()
|
||||
|
||||
expect(component.validationState).toBe('success')
|
||||
expect(deps.eventService.showInfoModal).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('sets validationState to error with no modal when saslibs is missing from an otherwise normal object response', async () => {
|
||||
const deps = buildDeps()
|
||||
deps.sasService.request.and.resolveTo({
|
||||
adapterResponse: { SYSSITE: 'SITE1' }
|
||||
// saslibs deliberately omitted
|
||||
})
|
||||
|
||||
const component = buildManualComponent(deps)
|
||||
component.validateDeploy()
|
||||
await flushPromiseChain()
|
||||
|
||||
expect(component.validationState).toBe('error')
|
||||
expect(deps.eventService.showInfoModal).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
// Same underlying bug as app.service.spec.ts's equivalent test: a
|
||||
// misconfigured Viya computeTasks deployment returns a raw "Job error"
|
||||
// text body, which the adapter resolves as adapterResponse verbatim.
|
||||
it('sets validationState to error and shows the real response text when adapterResponse is a raw string, not an object', async () => {
|
||||
const deps = buildDeps()
|
||||
const rawJobError = [
|
||||
'Job error',
|
||||
'The Compute service could not execute the task c74a707a-8b88-46a5-8f28-9a7694ad5e13 because the context 340cd3eb-72ae is not reusable. Please provide a reusable context or supply the ID of an existing session in the task request.',
|
||||
'path: /compute/tasks',
|
||||
'correlator: dc1a9fda-8f65-4f32-b4d4-2a70e02179b1;1bcb6a4c-8a16-4053-a790-292544c25a03'
|
||||
].join('\n')
|
||||
deps.sasService.request.and.resolveTo({ adapterResponse: rawJobError })
|
||||
|
||||
const component = buildManualComponent(deps)
|
||||
component.validateDeploy()
|
||||
await flushPromiseChain()
|
||||
|
||||
expect(component.validationState).toBe('error')
|
||||
expect(deps.eventService.showInfoModal).toHaveBeenCalledTimes(1)
|
||||
const [, message] = deps.eventService.showInfoModal.calls.mostRecent().args
|
||||
expect(message).toContain(rawJobError)
|
||||
})
|
||||
})
|
||||
@@ -13,6 +13,7 @@ import { DeployService } from 'src/app/services/deploy.service'
|
||||
import { EventService } from 'src/app/services/event.service'
|
||||
import { LoggerService } from 'src/app/services/logger.service'
|
||||
import { SasService } from 'src/app/services/sas.service'
|
||||
import { getMalformedAdapterResponseMessage } from 'src/app/shared/utils/get-malformed-adapter-response-message'
|
||||
|
||||
@Component({
|
||||
selector: 'app-manual-deploy',
|
||||
@@ -241,6 +242,9 @@ export class ManualComponent implements OnInit {
|
||||
*/
|
||||
public createDatabase(newTab: boolean = true) {
|
||||
if (newTab) {
|
||||
// Debug is ALWAYS enabled for makedata — it runs only once during
|
||||
// deployment and the full log is needed to diagnose any issues.
|
||||
const _debug = '&_debug=131'
|
||||
let url =
|
||||
this.sasService.getSasjsConfig().serverUrl +
|
||||
'/SASJobExecution/?_program=' +
|
||||
@@ -251,7 +255,7 @@ export class ManualComponent implements OnInit {
|
||||
this.selectedAdminGroup +
|
||||
'&DCPATH=' +
|
||||
this.dcPath +
|
||||
this.sasService.getDebugUrlParam()
|
||||
_debug
|
||||
|
||||
window.open(url, '_blank')
|
||||
|
||||
@@ -316,7 +320,13 @@ export class ManualComponent implements OnInit {
|
||||
.then((res: RequestWrapperResponse) => {
|
||||
this.loggerService.log(res.adapterResponse)
|
||||
|
||||
if (res.adapterResponse.saslibs) {
|
||||
const malformedMessage = getMalformedAdapterResponseMessage(
|
||||
res.adapterResponse
|
||||
)
|
||||
if (malformedMessage) {
|
||||
this.validationState = 'error'
|
||||
this.eventService.showInfoModal('Error', malformedMessage)
|
||||
} else if (res.adapterResponse.saslibs) {
|
||||
this.validationState = 'success'
|
||||
} else {
|
||||
this.validationState = 'error'
|
||||
|
||||
@@ -120,8 +120,10 @@ export class SasjsConfiguratorComponent implements OnInit {
|
||||
* Creating database
|
||||
*/
|
||||
makeData() {
|
||||
// const _debug = "&_debug=131"; //debug on
|
||||
const _debug = ' ' //debug off
|
||||
// Debug is ALWAYS enabled for this service. The makedata service runs only once
|
||||
// during deployment configuration, so full debug output (131) is always wanted
|
||||
// to help diagnose any issues. This is NOT temporary — do not remove or gate it.
|
||||
const _debug = '&_debug=131'
|
||||
|
||||
let executor = this.sasService.getExecutionPath()
|
||||
const root = this.sasJsConfig.appLoc
|
||||
|
||||
@@ -170,7 +170,7 @@
|
||||
class="card-header clr-row buttonBar headerBar clr-flex-md-row clr-justify-content-center clr-justify-content-lg-end"
|
||||
>
|
||||
@if (tableTrue && !embed) {
|
||||
<div class="clr-col-12 clr-col-md-3 clr-col-lg-4 backBtn">
|
||||
<div class="clr-col-12 clr-col-md-auto clr-col-lg-auto backBtn">
|
||||
<span
|
||||
class="btn icon-collapse btn-sm btn-icon btn-dimmed"
|
||||
[routerLink]="['/home']"
|
||||
@@ -198,7 +198,7 @@
|
||||
}
|
||||
|
||||
<div
|
||||
class="clr-col-12 clr-col-md-5 clr-col-lg-4 d-flex flex-column align-items-center"
|
||||
class="clr-col-12 clr-col-md clr-col-lg d-flex flex-column align-items-center"
|
||||
[class.clr-col-lg-12]="!tableTrue"
|
||||
>
|
||||
<h4
|
||||
@@ -258,12 +258,12 @@
|
||||
</h4>
|
||||
</div>
|
||||
@if (tableTrue) {
|
||||
<div class="clr-col-12 clr-col-md-4 clr-col-lg-4 btnCtrl">
|
||||
<div class="clr-col-12 clr-col-md-auto clr-col-lg-auto btnCtrl">
|
||||
@if (hotTable.readOnly && !uploadPreview) {
|
||||
@if (!isVaEmbed) {
|
||||
<button
|
||||
type="button"
|
||||
class="btnView btn icon-collapse btn-sm btn-icon btn-block btn-dimmed"
|
||||
class="btnView btn icon-collapse btn-sm btn-icon btn-dimmed"
|
||||
(click)="openQb()"
|
||||
>
|
||||
<clr-icon aria-hidden="true" shape="filter"></clr-icon>
|
||||
@@ -272,7 +272,7 @@
|
||||
}
|
||||
<button
|
||||
type="button"
|
||||
class="btn icon-collapse btn-sm btn-primary btn-block"
|
||||
class="btn icon-collapse btn-sm btn-primary"
|
||||
(click)="editTable()"
|
||||
>
|
||||
<clr-icon aria-hidden="true" shape="note"></clr-icon>
|
||||
@@ -282,7 +282,7 @@
|
||||
<button
|
||||
(click)="onShowUploadModal()"
|
||||
type="button"
|
||||
class="btn icon-collapse btn-sm btn-success btn-block mr-0"
|
||||
class="btn icon-collapse btn-sm btn-success mr-0"
|
||||
>
|
||||
<clr-icon aria-hidden="true" shape="upload"></clr-icon>
|
||||
<span class="text">Upload</span>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,77 @@
|
||||
import { classifyRow } from './classifyRow'
|
||||
import { EDIT_STATUS_COLUMN_NAME } from '../../shared/dc-validator/utils/editStatusColumnRule'
|
||||
|
||||
describe('classifyRow', () => {
|
||||
const headerPks = ['PRIMARY_KEY_FIELD']
|
||||
|
||||
it('is D when the row is marked for delete, regardless of other field changes', () => {
|
||||
const dataRow = {
|
||||
PRIMARY_KEY_FIELD: 1,
|
||||
SOME_CHAR: 'changed',
|
||||
_____DELETE__THIS__RECORD_____: 'Yes'
|
||||
}
|
||||
const dataSourceUnchanged = [
|
||||
{ PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'original' }
|
||||
]
|
||||
|
||||
expect(classifyRow(dataRow, dataSourceUnchanged, headerPks)).toEqual('D')
|
||||
})
|
||||
|
||||
it('is A when no row in dataSourceUnchanged matches the primary key(s)', () => {
|
||||
const dataRow = { PRIMARY_KEY_FIELD: 99, SOME_CHAR: 'new row' }
|
||||
const dataSourceUnchanged = [
|
||||
{ PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'original' }
|
||||
]
|
||||
|
||||
expect(classifyRow(dataRow, dataSourceUnchanged, headerPks)).toEqual('A')
|
||||
})
|
||||
|
||||
it('is M when a matching row exists but a field differs', () => {
|
||||
const dataRow = { PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'changed' }
|
||||
const dataSourceUnchanged = [
|
||||
{ PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'original' }
|
||||
]
|
||||
|
||||
expect(classifyRow(dataRow, dataSourceUnchanged, headerPks)).toEqual('M')
|
||||
})
|
||||
|
||||
it('is U when a matching row exists and nothing differs', () => {
|
||||
const dataRow = { PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'original' }
|
||||
const dataSourceUnchanged = [
|
||||
{ PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'original' }
|
||||
]
|
||||
|
||||
expect(classifyRow(dataRow, dataSourceUnchanged, headerPks)).toEqual('U')
|
||||
})
|
||||
|
||||
it('matches on all primary key columns for a composite key', () => {
|
||||
const headerPksComposite = ['LIB', 'ID']
|
||||
const dataRow = { LIB: 'WORK', ID: 1, SOME_CHAR: 'original' }
|
||||
const dataSourceUnchanged = [
|
||||
{ LIB: 'OTHER', ID: 1, SOME_CHAR: 'original' },
|
||||
{ LIB: 'WORK', ID: 1, SOME_CHAR: 'original' }
|
||||
]
|
||||
|
||||
// Same ID=1 exists under a different LIB - must not match that one.
|
||||
expect(
|
||||
classifyRow(dataRow, dataSourceUnchanged, headerPksComposite)
|
||||
).toEqual('U')
|
||||
})
|
||||
|
||||
it('ignores its own EDIT_STATUS column value when diffing, so writing the classification back never self-perpetuates a stale M', () => {
|
||||
const dataRow = {
|
||||
PRIMARY_KEY_FIELD: 1,
|
||||
SOME_CHAR: 'original',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'M'
|
||||
}
|
||||
const dataSourceUnchanged = [
|
||||
{
|
||||
PRIMARY_KEY_FIELD: 1,
|
||||
SOME_CHAR: 'original',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'U'
|
||||
}
|
||||
]
|
||||
|
||||
expect(classifyRow(dataRow, dataSourceUnchanged, headerPks)).toEqual('U')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,39 @@
|
||||
import { withoutEditStatus } from './withoutEditStatus'
|
||||
|
||||
export type RowEditStatus = 'M' | 'A' | 'D' | 'U'
|
||||
|
||||
/**
|
||||
* Classifies a single row as Modified/Added/Deleted/Unchanged against the
|
||||
* pre-edit snapshot (`dataSourceUnchanged`), PK-matched via `headerPks`.
|
||||
*
|
||||
* Extracted from editor.component.ts's getRowsSubmittingCount(), which used
|
||||
* this same logic inline, only at submit time. Kept here as a pure function
|
||||
* so it can run live (e.g. on every afterChange, for the EDIT_STATUS column)
|
||||
* without duplicating the diffing rules.
|
||||
*/
|
||||
export const classifyRow = (
|
||||
dataRow: any,
|
||||
dataSourceUnchanged: any[],
|
||||
headerPks: string[]
|
||||
): RowEditStatus => {
|
||||
if (dataRow._____DELETE__THIS__RECORD_____ === 'Yes') return 'D'
|
||||
|
||||
const dataRowUnchanged = dataSourceUnchanged.find((row: any) => {
|
||||
for (const pkCol of headerPks) {
|
||||
if (row[pkCol] !== dataRow[pkCol]) return false
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
if (!dataRowUnchanged) return 'A'
|
||||
|
||||
// EDIT_STATUS holds this very function's own prior output - comparing it
|
||||
// like any other field would self-perpetuate: once a row is written as
|
||||
// 'M', its EDIT_STATUS would forever differ from the unchanged snapshot's
|
||||
// 'U' even after the real edit is reverted, permanently stuck on 'M'.
|
||||
return JSON.stringify(withoutEditStatus(dataRow)) !==
|
||||
JSON.stringify(withoutEditStatus(dataRowUnchanged))
|
||||
? 'M'
|
||||
: 'U'
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
import { expandCellRanges } from './expandCellRanges'
|
||||
|
||||
describe('expandCellRanges', () => {
|
||||
it('expands a single-cell range', () => {
|
||||
expect(
|
||||
expandCellRanges(
|
||||
[{ from: { row: 1, col: 1 }, to: { row: 1, col: 1 } }],
|
||||
3,
|
||||
3
|
||||
)
|
||||
).toEqual([{ row: 1, col: 1 }])
|
||||
})
|
||||
|
||||
it('expands a rectangular multi-cell range', () => {
|
||||
expect(
|
||||
expandCellRanges(
|
||||
[{ from: { row: 0, col: 0 }, to: { row: 1, col: 1 } }],
|
||||
3,
|
||||
3
|
||||
)
|
||||
).toEqual([
|
||||
{ row: 0, col: 0 },
|
||||
{ row: 0, col: 1 },
|
||||
{ row: 1, col: 0 },
|
||||
{ row: 1, col: 1 }
|
||||
])
|
||||
})
|
||||
|
||||
it('normalizes a whole-row selection (from.col === -1) to every real column', () => {
|
||||
expect(
|
||||
expandCellRanges(
|
||||
[{ from: { row: 1, col: -1 }, to: { row: 1, col: 2 } }],
|
||||
3,
|
||||
3
|
||||
)
|
||||
).toEqual([
|
||||
{ row: 1, col: 0 },
|
||||
{ row: 1, col: 1 },
|
||||
{ row: 1, col: 2 }
|
||||
])
|
||||
})
|
||||
|
||||
it('normalizes a whole-column selection (from.row === -1) to every real row', () => {
|
||||
expect(
|
||||
expandCellRanges(
|
||||
[{ from: { row: -1, col: 1 }, to: { row: 2, col: 1 } }],
|
||||
3,
|
||||
3
|
||||
)
|
||||
).toEqual([
|
||||
{ row: 0, col: 1 },
|
||||
{ row: 1, col: 1 },
|
||||
{ row: 2, col: 1 }
|
||||
])
|
||||
})
|
||||
|
||||
it('expands every disjoint range when multiple are given (ctrl-click)', () => {
|
||||
expect(
|
||||
expandCellRanges(
|
||||
[
|
||||
{ from: { row: 0, col: 0 }, to: { row: 0, col: 0 } },
|
||||
{ from: { row: 2, col: 2 }, to: { row: 2, col: 2 } }
|
||||
],
|
||||
3,
|
||||
3
|
||||
)
|
||||
).toEqual([
|
||||
{ row: 0, col: 0 },
|
||||
{ row: 2, col: 2 }
|
||||
])
|
||||
})
|
||||
|
||||
it('treats a null row/col the same as -1 (Handsontable.CellRange types these as number | null)', () => {
|
||||
expect(
|
||||
expandCellRanges(
|
||||
[{ from: { row: 1, col: null }, to: { row: 1, col: 2 } }],
|
||||
3,
|
||||
3
|
||||
)
|
||||
).toEqual([
|
||||
{ row: 1, col: 0 },
|
||||
{ row: 1, col: 1 },
|
||||
{ row: 1, col: 2 }
|
||||
])
|
||||
})
|
||||
|
||||
it('handles from/to given in reverse order (drag selection upward/leftward)', () => {
|
||||
expect(
|
||||
expandCellRanges(
|
||||
[{ from: { row: 2, col: 2 }, to: { row: 1, col: 1 } }],
|
||||
3,
|
||||
3
|
||||
)
|
||||
).toEqual([
|
||||
{ row: 1, col: 1 },
|
||||
{ row: 1, col: 2 },
|
||||
{ row: 2, col: 1 },
|
||||
{ row: 2, col: 2 }
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,54 @@
|
||||
export interface SimpleCellRange {
|
||||
from: { row: number | null; col: number | null }
|
||||
to: { row: number | null; col: number | null }
|
||||
}
|
||||
|
||||
export interface SimpleCell {
|
||||
row: number
|
||||
col: number
|
||||
}
|
||||
|
||||
/**
|
||||
* Expands one or more Handsontable selection ranges (as returned by
|
||||
* getSelectedRange()/the context menu callback's selection argument) into
|
||||
* every individual (row, col) cell they cover. A whole-row selection (row
|
||||
* header click) reports col: -1 (Handsontable.CellRange itself types this
|
||||
* as number | null, so null is treated the same way here) on whichever end
|
||||
* is the "start" of the range; a whole-column selection reports row: -1
|
||||
* the same way - normalized here to the real 0..totalRows-1/0..totalCols-1
|
||||
* bounds, since neither -1 nor null is a usable index for anything
|
||||
* downstream (comments lookup, setDataAtRowProp, ...). Multiple ranges
|
||||
* (ctrl-click) are all expanded, not just the first.
|
||||
*/
|
||||
export const expandCellRanges = (
|
||||
ranges: SimpleCellRange[],
|
||||
totalRows: number,
|
||||
totalCols: number
|
||||
): SimpleCell[] => {
|
||||
const cells: SimpleCell[] = []
|
||||
|
||||
const normalizeRow = (row: number | null) =>
|
||||
row === -1 || row === null ? undefined : row
|
||||
const normalizeCol = (col: number | null) =>
|
||||
col === -1 || col === null ? undefined : col
|
||||
|
||||
for (const range of ranges) {
|
||||
const rowA = normalizeRow(range.from.row) ?? 0
|
||||
const rowB = normalizeRow(range.to.row) ?? totalRows - 1
|
||||
const colA = normalizeCol(range.from.col) ?? 0
|
||||
const colB = normalizeCol(range.to.col) ?? totalCols - 1
|
||||
|
||||
const startRow = Math.min(rowA, rowB)
|
||||
const endRow = Math.max(rowA, rowB)
|
||||
const startCol = Math.min(colA, colB)
|
||||
const endCol = Math.max(colA, colB)
|
||||
|
||||
for (let row = startRow; row <= endRow; row++) {
|
||||
for (let col = startCol; col <= endCol; col++) {
|
||||
cells.push({ row, col })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cells
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import { getEditStatusSymbol } from './getEditStatusSymbol'
|
||||
|
||||
describe('getEditStatusSymbol', () => {
|
||||
it("returns '+' for Added", () => {
|
||||
expect(getEditStatusSymbol('A')).toEqual('+')
|
||||
})
|
||||
|
||||
it("returns '-' for Deleted", () => {
|
||||
expect(getEditStatusSymbol('D')).toEqual('-')
|
||||
})
|
||||
|
||||
it("returns '±' for Modified", () => {
|
||||
expect(getEditStatusSymbol('M')).toEqual('±')
|
||||
})
|
||||
|
||||
it("returns '' for Unchanged", () => {
|
||||
expect(getEditStatusSymbol('U')).toEqual('')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,20 @@
|
||||
import { RowEditStatus } from './classifyRow'
|
||||
|
||||
/**
|
||||
* Maps a row's edit status to the symbol shown in the row-header gutter
|
||||
* (see editor.component.ts's rowHeaders callback). Unchanged renders as an
|
||||
* empty string rather than a letter, since it's the common case and would
|
||||
* otherwise clutter every untouched row.
|
||||
*/
|
||||
export const getEditStatusSymbol = (status: RowEditStatus): string => {
|
||||
switch (status) {
|
||||
case 'A':
|
||||
return '+'
|
||||
case 'D':
|
||||
return '-'
|
||||
case 'M':
|
||||
return '±'
|
||||
case 'U':
|
||||
return ''
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
import { normalizeSortConfig } from './normalizeSortConfig'
|
||||
|
||||
describe('normalizeSortConfig', () => {
|
||||
it('wraps a single config in an array', () => {
|
||||
const cfg = { column: 0, sortOrder: 'asc' as const }
|
||||
expect(normalizeSortConfig(cfg)).toEqual([cfg])
|
||||
})
|
||||
|
||||
it('passes an array of configs through unchanged', () => {
|
||||
const cfgs = [
|
||||
{ column: 0, sortOrder: 'asc' as const },
|
||||
{ column: 1, sortOrder: 'desc' as const }
|
||||
]
|
||||
expect(normalizeSortConfig(cfgs)).toEqual(cfgs)
|
||||
})
|
||||
|
||||
it('returns an empty array for undefined (nothing currently sorted)', () => {
|
||||
expect(normalizeSortConfig(undefined)).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* multiColumnSorting's getSortConfig() returns a single config, an array of
|
||||
* them, or undefined depending on how many columns are currently sorted -
|
||||
* normalizes all three shapes into one array so callers never need three
|
||||
* branches to handle it. `SortConfig` isn't part of Handsontable's public
|
||||
* API surface in this version (only re-exported internally), and its own
|
||||
* `.d.ts` shape isn't structurally assignable to `Record<string, unknown>`
|
||||
* either (a specific interface isn't assignable to an index-signature type
|
||||
* without one of its own), so `any` is the pragmatic choice here rather
|
||||
* than fighting the type system for a type this file can't even name.
|
||||
*/
|
||||
export const normalizeSortConfig = (cfg: any): any[] =>
|
||||
Array.isArray(cfg) ? cfg : cfg ? [cfg] : []
|
||||
@@ -0,0 +1,53 @@
|
||||
import { preventMenuItemAutoClose } from './preventMenuItemAutoClose'
|
||||
|
||||
describe('preventMenuItemAutoClose', () => {
|
||||
let parent: HTMLElement
|
||||
let child: HTMLElement
|
||||
|
||||
beforeEach(() => {
|
||||
parent = document.createElement('div')
|
||||
child = document.createElement('span')
|
||||
parent.appendChild(child)
|
||||
document.body.appendChild(parent)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(parent)
|
||||
})
|
||||
|
||||
const bubblingEvents = ['mousedown', 'mouseup', 'contextmenu', 'selectstart']
|
||||
|
||||
bubblingEvents.forEach((eventName) => {
|
||||
it(`stops a ${eventName} dispatched on the element from bubbling to its parent`, () => {
|
||||
let bubbledToParent = false
|
||||
parent.addEventListener(eventName, () => (bubbledToParent = true))
|
||||
|
||||
preventMenuItemAutoClose(child)
|
||||
child.dispatchEvent(new Event(eventName, { bubbles: true }))
|
||||
|
||||
expect(bubbledToParent).toBe(false)
|
||||
})
|
||||
|
||||
it(`still lets a ${eventName} dispatched directly on the parent reach the parent (propagation isn't globally broken)`, () => {
|
||||
let bubbledToParent = false
|
||||
parent.addEventListener(eventName, () => (bubbledToParent = true))
|
||||
|
||||
preventMenuItemAutoClose(child)
|
||||
parent.dispatchEvent(new Event(eventName, { bubbles: true }))
|
||||
|
||||
expect(bubbledToParent).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
it('does not call preventDefault on contextmenu, so the browser can still show its own menu', () => {
|
||||
preventMenuItemAutoClose(child)
|
||||
|
||||
const event = new Event('contextmenu', {
|
||||
bubbles: true,
|
||||
cancelable: true
|
||||
})
|
||||
child.dispatchEvent(event)
|
||||
|
||||
expect(event.defaultPrevented).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,23 @@
|
||||
// Handsontable's Menu widget (used by both dropdownMenu and contextMenu)
|
||||
// treats a click landing anywhere inside a non-passive item as "the item was
|
||||
// activated": mouseup auto-closes the menu, and contextmenu is
|
||||
// unconditionally preventDefault()'d, so the browser's own right-click menu
|
||||
// never appears - regardless of whether the item actually has a callback.
|
||||
// A custom-rendered, read-only item (plain informational text, nothing to
|
||||
// click) still gets this treatment, making its content impossible to select
|
||||
// or copy. Handsontable's own listeners are bubble-phase, attached on
|
||||
// ancestors of the rendered item element, so stopping propagation at the
|
||||
// item itself is enough to reach them before they run - no capture-phase
|
||||
// handling needed.
|
||||
const EVENTS_TO_ISOLATE = [
|
||||
'mousedown',
|
||||
'mouseup',
|
||||
'contextmenu',
|
||||
'selectstart'
|
||||
] as const
|
||||
|
||||
export const preventMenuItemAutoClose = (elem: HTMLElement): void => {
|
||||
for (const eventName of EVENTS_TO_ISOLATE) {
|
||||
elem.addEventListener(eventName, (event) => event.stopPropagation())
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,10 @@
|
||||
import Handsontable from 'handsontable'
|
||||
import { makeNumberFormatRenderer } from './renderers.utils'
|
||||
import {
|
||||
makeNumberFormatRenderer,
|
||||
errorRenderer,
|
||||
noSpinnerRenderer,
|
||||
spinnerRenderer
|
||||
} from './renderers.utils'
|
||||
|
||||
describe('makeNumberFormatRenderer', () => {
|
||||
it('renders a numeric cell as EUR currency without changing the value', () => {
|
||||
@@ -86,3 +91,67 @@ describe('makeNumberFormatRenderer', () => {
|
||||
container.remove()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* DOM-injection reproduction mirroring the editor's cell-render cycle.
|
||||
* During dynamic cell validation the editor applies one of the status
|
||||
* renderers to a cell via setCellMeta + hot.render(). Those renderers paint
|
||||
* the cell value with td.innerHTML, so a value containing markup is injected
|
||||
* and executed (the <img onerror> fires in the browser). The value can come
|
||||
* straight from a dataset row served by the getdata stored program, or from a
|
||||
* typed edit. These fail on the vulnerable implementation and pass once the
|
||||
* renderer escapes the value.
|
||||
*/
|
||||
describe('grid cell renderers do not inject raw HTML', () => {
|
||||
const maliciousValue = '<img src=x onerror=alert(1)>'
|
||||
|
||||
// Seed a real Handsontable grid with the payload as a loaded cell value,
|
||||
// then apply the given status renderer and render — exactly the sequence the
|
||||
// editor uses during the dynamic-validation cycle.
|
||||
const renderWith = (
|
||||
renderer: (
|
||||
i: any,
|
||||
td: any,
|
||||
r: number,
|
||||
c: number,
|
||||
p: any,
|
||||
v: any,
|
||||
cp: any
|
||||
) => any
|
||||
) => {
|
||||
const container = document.createElement('div')
|
||||
document.body.appendChild(container)
|
||||
const hot = new Handsontable(container, {
|
||||
data: [{ SOME_CHAR: maliciousValue }],
|
||||
columns: [{ data: 'SOME_CHAR', type: 'text' }],
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
})
|
||||
hot.render()
|
||||
hot.setCellMeta(0, 0, 'renderer', renderer)
|
||||
hot.render()
|
||||
const td: HTMLTableCellElement | null = hot.getCell(0, 0)
|
||||
hot.destroy()
|
||||
container.remove()
|
||||
return td
|
||||
}
|
||||
|
||||
// A vulnerable renderer turns the value into a real <img> element with an
|
||||
// onerror handler (proven by the browser firing alert(1)). A safe
|
||||
// renderer leaves no such element. Asserting on the parsed DOM rather
|
||||
// than the raw string avoids false passes from browser attribute normalising.
|
||||
const assertNoInjectedElement = (td: HTMLTableCellElement | null) => {
|
||||
expect(td?.querySelector('img[onerror]')).toBeNull()
|
||||
}
|
||||
|
||||
it('noSpinnerRenderer escapes rather than injecting the value', () => {
|
||||
assertNoInjectedElement(renderWith(noSpinnerRenderer))
|
||||
})
|
||||
|
||||
it('errorRenderer escapes rather than injecting the value', () => {
|
||||
assertNoInjectedElement(renderWith(errorRenderer))
|
||||
})
|
||||
|
||||
it('spinnerRenderer escapes rather than injecting the value', () => {
|
||||
assertNoInjectedElement(renderWith(spinnerRenderer))
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,23 @@
|
||||
import Handsontable from 'handsontable'
|
||||
|
||||
/**
|
||||
* Returns string-safe text of any value so it can be assigned to innerHTML.
|
||||
* The cell values painted by the status renderers are user/DB-controlled,
|
||||
* so they must never be parsed as HTML by the browser — escaping turns any
|
||||
* embedded markup into inert text.
|
||||
*/
|
||||
const escapeHtml = (value: any): string =>
|
||||
String(value ?? '').replace(/[&<>"']/g, (char) => {
|
||||
const entities: Record<string, string> = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": '''
|
||||
}
|
||||
return entities[char]
|
||||
})
|
||||
|
||||
/**
|
||||
* Builds a display-only HOT renderer that formats numeric cell values using
|
||||
* Intl.NumberFormat. The stored/submitted value is never changed — only the
|
||||
@@ -67,9 +85,7 @@ export const errorRenderer = (
|
||||
) => {
|
||||
addDarkClass(td)
|
||||
|
||||
td.innerHTML = `${
|
||||
value ? value.toString() : ''
|
||||
} <cds-icon shape="exclamation-triangle" status="warning"></cds-icon>`
|
||||
td.innerHTML = `${escapeHtml(value)} <cds-icon shape="exclamation-triangle" status="warning"></cds-icon>`
|
||||
|
||||
return td
|
||||
}
|
||||
@@ -89,7 +105,7 @@ export const noSpinnerRenderer = (
|
||||
) => {
|
||||
addDarkClass(td)
|
||||
|
||||
td.innerHTML = value ? value : ''
|
||||
td.innerHTML = escapeHtml(value)
|
||||
|
||||
return td
|
||||
}
|
||||
@@ -110,9 +126,7 @@ export const spinnerRenderer = (
|
||||
) => {
|
||||
addDarkClass(td)
|
||||
|
||||
td.innerHTML = `${
|
||||
value ? value.toString() : ''
|
||||
} <span class="spinner spinner-sm vertical-align-middle"></span>`
|
||||
td.innerHTML = `${escapeHtml(value)} <span class="spinner spinner-sm vertical-align-middle"></span>`
|
||||
|
||||
return td
|
||||
}
|
||||
|
||||
@@ -0,0 +1,540 @@
|
||||
import Handsontable from 'handsontable'
|
||||
import { HyperFormula } from 'hyperformula'
|
||||
import { classifyRow } from './classifyRow'
|
||||
import { normalizeSortConfig } from './normalizeSortConfig'
|
||||
import { EDIT_STATUS_COLUMN_NAME } from '../../shared/dc-validator/utils/editStatusColumnRule'
|
||||
import { parseFormulaRule } from '../../shared/dc-validator/utils/parseFormulaRule'
|
||||
import { getFormulaCellsToPreserveOnCancel } from '../../shared/dc-validator/utils/getFormulaCellsToPreserveOnCancel'
|
||||
|
||||
/**
|
||||
* afterChange delivers changes as [visualRow, prop, oldValue, newValue] -
|
||||
* Handsontable's own documented behaviour. Once multiColumnSorting reorders
|
||||
* the grid, visual row order no longer matches dataSource's physical order.
|
||||
* editor.component.ts's afterChange hook (the one syncing EDIT_STATUS and
|
||||
* the "overwritten" comment) passes that raw visual row straight into
|
||||
* updateEditStatusForRow/syncOverwrittenCommentForCell, both of which index
|
||||
* dataSource directly - the same [visualRow] shape the beforeChange hook a
|
||||
* few lines up in the same file already translates via
|
||||
* hot.toPhysicalRow(changeRow) before doing the same kind of dataSource
|
||||
* access.
|
||||
*
|
||||
* Mirrors the row extraction only (not the full hook), against a real
|
||||
* Handsontable + multiColumnSorting instance, since proving visual/physical
|
||||
* divergence requires an actual sort to have happened.
|
||||
*/
|
||||
describe('afterChange must translate the changed row to physical before indexing dataSource, on a sorted grid', () => {
|
||||
const setup = (): { hot: Handsontable; dataSource: any[] } => {
|
||||
// Physical row 0: PK=1. Physical row 1: PK=2.
|
||||
const dataSource = [
|
||||
{ PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'b' },
|
||||
{ PRIMARY_KEY_FIELD: 2, SOME_CHAR: 'a' }
|
||||
]
|
||||
const hot = new Handsontable(document.createElement('div'), {
|
||||
data: dataSource,
|
||||
columns: [{ data: 'PRIMARY_KEY_FIELD' }, { data: 'SOME_CHAR' }],
|
||||
multiColumnSorting: true,
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
})
|
||||
hot.render()
|
||||
|
||||
// Ascending by SOME_CHAR flips the order: physical row 1 (SOME_CHAR
|
||||
// 'a') becomes visual row 0; physical row 0 (SOME_CHAR 'b') becomes
|
||||
// visual row 1.
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
sortPlugin.sort({ column: 1, sortOrder: 'asc' })
|
||||
hot.render()
|
||||
|
||||
return { hot, dataSource }
|
||||
}
|
||||
|
||||
it('demonstrates the failure mode: indexing dataSource with the raw visual row reads the wrong row', () => {
|
||||
const { hot, dataSource } = setup()
|
||||
|
||||
// The user edits what they see as the FIRST row on screen - visual
|
||||
// row 0, which after sorting is physical row 1 (PK=2).
|
||||
const visualRow = 0
|
||||
|
||||
// Mirrors the current (buggy) afterChange hook: uses the visual row
|
||||
// straight from `changes` to index dataSource.
|
||||
const wronglyReadRow = dataSource[visualRow]
|
||||
expect(wronglyReadRow.PRIMARY_KEY_FIELD).not.toEqual(2)
|
||||
expect(wronglyReadRow.PRIMARY_KEY_FIELD).toEqual(1) // the OTHER row
|
||||
|
||||
// Mirrors the fix: translate visual -> physical first, matching
|
||||
// beforeChange's own hot.toPhysicalRow(changeRow) pattern.
|
||||
const physicalRow = hot.toPhysicalRow(visualRow)
|
||||
const correctlyReadRow = dataSource[physicalRow as number]
|
||||
expect(correctlyReadRow.PRIMARY_KEY_FIELD).toEqual(2)
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* updateEditStatusForRow/syncOverwrittenCommentForCell's own established
|
||||
* contract (per their other existing callers - addRow/insertRowAtPosition,
|
||||
* and syncOverwrittenComments()'s own `dataSource.forEach((_row, rowIndex)
|
||||
* => ...)`) is a PHYSICAL row index, used to index dataSource. But both
|
||||
* also call Handsontable APIs - hot.setDataAtRowProp/getDataAtRowProp
|
||||
* (updateEditStatusForRow) and the comments plugin's setCommentAtCell/
|
||||
* getCommentAtCell/removeCommentAtCell (syncOverwrittenCommentForCell) -
|
||||
* which Handsontable's own JSDoc documents as expecting the VISUAL row.
|
||||
* Passing the physical row straight through to those (the current code)
|
||||
* only happens to work when visual and physical coincide - i.e. an
|
||||
* unsorted grid. On a sorted one, translating the afterChange hook's own
|
||||
* row (see the describe block above) is necessary but not sufficient -
|
||||
* these two methods must also convert their own physical rowIndex
|
||||
* parameter to visual before calling any Handsontable API, or the fix
|
||||
* above just moves the bug rather than closing it.
|
||||
*/
|
||||
describe('updateEditStatusForRow resolves the correct visual cell on a sorted grid', () => {
|
||||
const headerPks = ['PRIMARY_KEY_FIELD']
|
||||
|
||||
const setup = (): { hot: Handsontable; dataSource: any[] } => {
|
||||
const dataSource = [
|
||||
{
|
||||
PRIMARY_KEY_FIELD: 1,
|
||||
SOME_CHAR: 'b',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'U'
|
||||
},
|
||||
{
|
||||
PRIMARY_KEY_FIELD: 2,
|
||||
SOME_CHAR: 'a',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'U'
|
||||
}
|
||||
]
|
||||
const hot = new Handsontable(document.createElement('div'), {
|
||||
data: dataSource,
|
||||
columns: [
|
||||
{ data: 'PRIMARY_KEY_FIELD' },
|
||||
{ data: 'SOME_CHAR' },
|
||||
{ data: EDIT_STATUS_COLUMN_NAME }
|
||||
],
|
||||
multiColumnSorting: true,
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
})
|
||||
hot.render()
|
||||
|
||||
// Ascending by SOME_CHAR: physical row 1 (PK=2) -> visual row 0;
|
||||
// physical row 0 (PK=1) -> visual row 1.
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
sortPlugin.sort({ column: 1, sortOrder: 'asc' })
|
||||
hot.render()
|
||||
|
||||
return { hot, dataSource }
|
||||
}
|
||||
|
||||
// Mirrors the CURRENT updateEditStatusForRow - uses the (correct,
|
||||
// physical) rowIndex directly for the Handsontable write too.
|
||||
const updateEditStatusForRowBuggy = (
|
||||
hot: Handsontable,
|
||||
dataSource: any[],
|
||||
dataSourceUnchanged: any[],
|
||||
rowIndex: number
|
||||
): void => {
|
||||
const dataRow = dataSource[rowIndex]
|
||||
if (!dataRow) return
|
||||
|
||||
const status = classifyRow(dataRow, dataSourceUnchanged, headerPks)
|
||||
hot.setDataAtRowProp(
|
||||
rowIndex,
|
||||
EDIT_STATUS_COLUMN_NAME,
|
||||
status,
|
||||
'editStatus'
|
||||
)
|
||||
}
|
||||
|
||||
// Mirrors the fix - dataSource access stays physical; the Handsontable
|
||||
// write is translated to visual first.
|
||||
const updateEditStatusForRowFixed = (
|
||||
hot: Handsontable,
|
||||
dataSource: any[],
|
||||
dataSourceUnchanged: any[],
|
||||
rowIndex: number
|
||||
): void => {
|
||||
const dataRow = dataSource[rowIndex]
|
||||
if (!dataRow) return
|
||||
|
||||
const status = classifyRow(dataRow, dataSourceUnchanged, headerPks)
|
||||
const visualRow = hot.toVisualRow(rowIndex)
|
||||
if (visualRow === null) return
|
||||
|
||||
hot.setDataAtRowProp(
|
||||
visualRow,
|
||||
EDIT_STATUS_COLUMN_NAME,
|
||||
status,
|
||||
'editStatus'
|
||||
)
|
||||
}
|
||||
|
||||
it('demonstrates the failure mode: the buggy version writes the status to the wrong cell', () => {
|
||||
const { hot, dataSource } = setup()
|
||||
// Physical row 1 (PK=2) is the one that actually changed vs its
|
||||
// unchanged baseline (SOME_CHAR 'a' vs 'ORIGINAL') - classifyRow
|
||||
// should mark it 'M'. It's currently displayed at visual row 0.
|
||||
const dataSourceUnchanged = [
|
||||
{
|
||||
PRIMARY_KEY_FIELD: 1,
|
||||
SOME_CHAR: 'b',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'U'
|
||||
},
|
||||
{
|
||||
PRIMARY_KEY_FIELD: 2,
|
||||
SOME_CHAR: 'ORIGINAL',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'U'
|
||||
}
|
||||
]
|
||||
|
||||
updateEditStatusForRowBuggy(hot, dataSource, dataSourceUnchanged, 1)
|
||||
|
||||
// Buggy: wrote 'M' to visual row 1 (PK=1's cell, unaffected), not
|
||||
// visual row 0 (PK=2's actual current position).
|
||||
expect(hot.getDataAtRowProp(1, EDIT_STATUS_COLUMN_NAME)).toEqual('M')
|
||||
expect(hot.getDataAtRowProp(0, EDIT_STATUS_COLUMN_NAME)).toEqual('U')
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
|
||||
it('writes the status to the correct (visually current) cell once fixed', () => {
|
||||
const { hot, dataSource } = setup()
|
||||
const dataSourceUnchanged = [
|
||||
{
|
||||
PRIMARY_KEY_FIELD: 1,
|
||||
SOME_CHAR: 'b',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'U'
|
||||
},
|
||||
{
|
||||
PRIMARY_KEY_FIELD: 2,
|
||||
SOME_CHAR: 'ORIGINAL',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'U'
|
||||
}
|
||||
]
|
||||
|
||||
updateEditStatusForRowFixed(hot, dataSource, dataSourceUnchanged, 1)
|
||||
|
||||
expect(hot.getDataAtRowProp(0, EDIT_STATUS_COLUMN_NAME)).toEqual('M')
|
||||
expect(hot.getDataAtRowProp(1, EDIT_STATUS_COLUMN_NAME)).toEqual('U')
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* Same physical/visual split as updateEditStatusForRow above, for the
|
||||
* comments plugin's own row-indexed API (setCommentAtCell/
|
||||
* getCommentAtCell/removeCommentAtCell all document a VISUAL row -
|
||||
* propToCol, unlike the row side, already returns a visual column, so
|
||||
* only the row needs translating).
|
||||
*/
|
||||
describe('syncOverwrittenCommentForCell resolves the correct visual cell on a sorted grid', () => {
|
||||
const setup = (): { hot: Handsontable } => {
|
||||
const dataSource = [
|
||||
{ PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'b' },
|
||||
{ PRIMARY_KEY_FIELD: 2, SOME_CHAR: 'a' }
|
||||
]
|
||||
const hot = new Handsontable(document.createElement('div'), {
|
||||
data: dataSource,
|
||||
columns: [{ data: 'PRIMARY_KEY_FIELD' }, { data: 'SOME_CHAR' }],
|
||||
multiColumnSorting: true,
|
||||
comments: true,
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
})
|
||||
hot.render()
|
||||
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
sortPlugin.sort({ column: 1, sortOrder: 'asc' })
|
||||
hot.render()
|
||||
|
||||
return { hot }
|
||||
}
|
||||
|
||||
it('demonstrates the failure mode: setCommentAtCell(physicalRow, ...) lands on the wrong visual cell', () => {
|
||||
const { hot } = setup()
|
||||
const commentsPlugin: any = hot.getPlugin('comments')
|
||||
|
||||
// Mirrors the buggy call: the established-physical rowIndex (1) used
|
||||
// directly against a Handsontable API that wants visual.
|
||||
commentsPlugin.setCommentAtCell(1, 1, 'Original value: b')
|
||||
|
||||
// Landed on visual row 1 (PK=1's cell), not visual row 0 (PK=2's
|
||||
// actual current position, physical row 1).
|
||||
expect(commentsPlugin.getCommentAtCell(1, 1)).toEqual('Original value: b')
|
||||
expect(commentsPlugin.getCommentAtCell(0, 1)).toBeUndefined()
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
|
||||
it('lands on the correct visual cell once translated to visual first', () => {
|
||||
const { hot } = setup()
|
||||
const commentsPlugin: any = hot.getPlugin('comments')
|
||||
|
||||
const visualRow = hot.toVisualRow(1)
|
||||
commentsPlugin.setCommentAtCell(visualRow, 1, 'Original value: a')
|
||||
|
||||
expect(commentsPlugin.getCommentAtCell(0, 1)).toEqual('Original value: a')
|
||||
expect(commentsPlugin.getCommentAtCell(1, 1)).toBeUndefined()
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* A genuine Handsontable multiColumnSorting + formulas plugin bug (not
|
||||
* specific to any of DC's own hooks): calling hot.updateSettings() - with
|
||||
* ANY settings, even a bare {} - while a sort is active corrupts formula
|
||||
* cell references, rendering '#REF!' instead of their computed value.
|
||||
* Reproduced directly: a no-op {} settings object alone is enough to
|
||||
* trigger it, independent of what it actually changes. editTable(),
|
||||
* cancelEdit(), and every other place editor.component.ts calls
|
||||
* updateSettings() after the grid could already be sorted (e.g. the user
|
||||
* sorted while still read-only, then clicked Edit) hits this. The fix
|
||||
* (updateSettingsSortSafe) clears the sort before the call and restores it
|
||||
* immediately afterward.
|
||||
*/
|
||||
describe('updateSettings must not run while a sort is active - it corrupts formula cell references', () => {
|
||||
const buildSortedGrid = (): Handsontable => {
|
||||
const columnNames = [
|
||||
'PRIMARY_KEY_FIELD',
|
||||
'A_COL',
|
||||
'B_COL',
|
||||
'FORMULA_HARD_COL',
|
||||
'PLAIN_TEXT_COL'
|
||||
]
|
||||
const data = Array.from({ length: 10 }, (_, i) => ({
|
||||
PRIMARY_KEY_FIELD: i + 1,
|
||||
A_COL: i + 1,
|
||||
B_COL: 10,
|
||||
FORMULA_HARD_COL: '',
|
||||
PLAIN_TEXT_COL: `note-${i + 1}`
|
||||
}))
|
||||
data.forEach((row: any, i) => {
|
||||
row.FORMULA_HARD_COL = parseFormulaRule('=A_COL * B_COL', {
|
||||
columnNames,
|
||||
rowIndex: i,
|
||||
userName: 'test',
|
||||
origValue: undefined
|
||||
})
|
||||
})
|
||||
|
||||
const hot = new Handsontable(document.createElement('div'), {
|
||||
data,
|
||||
columns: columnNames.map((c) => ({ data: c })),
|
||||
formulas: { engine: HyperFormula, licenseKey: 'gpl-v3' },
|
||||
multiColumnSorting: true,
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
})
|
||||
hot.render()
|
||||
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
sortPlugin.sort({
|
||||
column: columnNames.indexOf('PLAIN_TEXT_COL'),
|
||||
sortOrder: 'desc'
|
||||
})
|
||||
hot.render()
|
||||
|
||||
return hot
|
||||
}
|
||||
|
||||
const formulaHardColValues = (hot: Handsontable): any[] =>
|
||||
Array.from({ length: 10 }, (_, r) =>
|
||||
hot.getDataAtRowProp(r, 'FORMULA_HARD_COL')
|
||||
)
|
||||
|
||||
it('demonstrates the failure mode: updateSettings while sorted corrupts formula cells', () => {
|
||||
const hot = buildSortedGrid()
|
||||
|
||||
hot.updateSettings({}, false)
|
||||
hot.render()
|
||||
|
||||
expect(formulaHardColValues(hot)).toContain('#REF!')
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
|
||||
it('clearing the sort before updateSettings and restoring it after avoids the corruption', () => {
|
||||
const hot = buildSortedGrid()
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
const sortConfigs = normalizeSortConfig(sortPlugin.getSortConfig())
|
||||
|
||||
sortPlugin.clearSort()
|
||||
hot.updateSettings({}, false)
|
||||
hot.render()
|
||||
if (sortConfigs.length > 0) sortPlugin.sort(sortConfigs)
|
||||
hot.render()
|
||||
|
||||
expect(formulaHardColValues(hot)).not.toContain('#REF!')
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* multiColumnSorting's own JSDoc: "every call of `sort` function set an
|
||||
* entirely new sort order. Previous sort configs aren't preserved." A loop
|
||||
* calling sort() once per captured config - the shape editor.component.ts
|
||||
* used before this fix, in updateSettingsSortSafe/editTable/cancelEdit's
|
||||
* restore step - therefore doesn't accumulate a multi-column sort: each
|
||||
* call replaces the last, so only the FINAL config in the array survives.
|
||||
* Restoring a captured multi-column sort must pass the whole array to a
|
||||
* single sort() call instead.
|
||||
*/
|
||||
describe('restoring a multi-column sort must apply as a single call, not a loop', () => {
|
||||
const columnNames = ['PRIMARY_KEY_FIELD', 'GROUP_COL', 'VALUE_COL']
|
||||
|
||||
const buildGrid = (): Handsontable => {
|
||||
const data = [
|
||||
{ PRIMARY_KEY_FIELD: 1, GROUP_COL: 'B', VALUE_COL: 2 },
|
||||
{ PRIMARY_KEY_FIELD: 2, GROUP_COL: 'A', VALUE_COL: 1 },
|
||||
{ PRIMARY_KEY_FIELD: 3, GROUP_COL: 'A', VALUE_COL: 3 },
|
||||
{ PRIMARY_KEY_FIELD: 4, GROUP_COL: 'B', VALUE_COL: 4 }
|
||||
]
|
||||
const hot = new Handsontable(document.createElement('div'), {
|
||||
data,
|
||||
columns: columnNames.map((c) => ({ data: c })),
|
||||
multiColumnSorting: true,
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
})
|
||||
hot.render()
|
||||
|
||||
return hot
|
||||
}
|
||||
|
||||
// Sort by GROUP_COL asc, then VALUE_COL desc within each group.
|
||||
const sortConfigs = [
|
||||
{ column: 1, sortOrder: 'asc' },
|
||||
{ column: 2, sortOrder: 'desc' }
|
||||
]
|
||||
|
||||
const visiblePkOrder = (hot: Handsontable): number[] =>
|
||||
Array.from(
|
||||
{ length: 4 },
|
||||
(_, r) => hot.getDataAtRowProp(r, 'PRIMARY_KEY_FIELD') as number
|
||||
)
|
||||
|
||||
it('demonstrates the failure mode: looping sort() per column loses every column but the last', () => {
|
||||
const hot = buildGrid()
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
|
||||
for (const sc of sortConfigs) sortPlugin.sort(sc)
|
||||
hot.render()
|
||||
|
||||
// GROUP_COL asc got wiped out by the second call - only VALUE_COL desc
|
||||
// (the last config) survived, sorting the whole table by value alone.
|
||||
expect(visiblePkOrder(hot)).toEqual([4, 3, 1, 2])
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
|
||||
it('applying the full config array in one call restores the actual multi-column order', () => {
|
||||
const hot = buildGrid()
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
|
||||
sortPlugin.sort(sortConfigs)
|
||||
hot.render()
|
||||
|
||||
// Group A first (value desc: 3, 1), then group B (value desc: 4, 2).
|
||||
expect(visiblePkOrder(hot)).toEqual([3, 2, 4, 1])
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* getFormulaCellsToPreserveOnCancel's rowIndex parameter is established as
|
||||
* PHYSICAL (it iterates 0..dataSource.length, matching dataSource's own
|
||||
* order - see the file's own docblock). cancelEdit() passes that rowIndex
|
||||
* straight into commentsPlugin.getCommentAtCell and hot.getDataAtRowProp,
|
||||
* both of which - same as updateEditStatusForRow/syncOverwrittenCommentForCell
|
||||
* above - document a VISUAL row. On a sorted grid this both checks and
|
||||
* reads the wrong row's cell: a row that actually has a comment can go
|
||||
* unflagged while a different row gets wrongly flagged, carrying that other
|
||||
* row's live value onto its own prop - corrupting cancelEdit()'s restore
|
||||
* rather than just skipping it. The fix is to clear the sort before this
|
||||
* runs at all (cancelEdit() now does this - see its own comment), rather
|
||||
* than translate physical->visual per call, since dataSourceUnchanged's
|
||||
* restore right after also needs an unsorted physical dataSource to index
|
||||
* into.
|
||||
*/
|
||||
describe('getFormulaCellsToPreserveOnCancel callbacks resolve the correct cell on a sorted grid', () => {
|
||||
const formulaBaseCols = ['FORMULA_HARD_COL']
|
||||
|
||||
const setup = (): { hot: Handsontable } => {
|
||||
const dataSource = [
|
||||
{ PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'b', FORMULA_HARD_COL: 10 },
|
||||
{ PRIMARY_KEY_FIELD: 2, SOME_CHAR: 'a', FORMULA_HARD_COL: 20 }
|
||||
]
|
||||
const hot = new Handsontable(document.createElement('div'), {
|
||||
data: dataSource,
|
||||
columns: [
|
||||
{ data: 'PRIMARY_KEY_FIELD' },
|
||||
{ data: 'SOME_CHAR' },
|
||||
{ data: 'FORMULA_HARD_COL' }
|
||||
],
|
||||
multiColumnSorting: true,
|
||||
comments: true,
|
||||
licenseKey: 'non-commercial-and-evaluation'
|
||||
})
|
||||
hot.render()
|
||||
|
||||
// Physical row 0 (PK=1) has the comment/live value that must be
|
||||
// preserved. Ascending by SOME_CHAR flips it to visual row 1; physical
|
||||
// row 1 (PK=2, no comment) becomes visual row 0.
|
||||
const commentsPlugin: any = hot.getPlugin('comments')
|
||||
commentsPlugin.setCommentAtCell(0, 2, 'Original value: 5')
|
||||
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
sortPlugin.sort({ column: 1, sortOrder: 'asc' })
|
||||
hot.render()
|
||||
|
||||
return { hot }
|
||||
}
|
||||
|
||||
it('demonstrates the failure mode: physical rowIndex passed straight to visual-row APIs resolves the wrong cell', () => {
|
||||
const { hot } = setup()
|
||||
const commentsPlugin: any = hot.getPlugin('comments')
|
||||
|
||||
const toPreserve = getFormulaCellsToPreserveOnCancel(
|
||||
2,
|
||||
formulaBaseCols,
|
||||
(rowIndex, baseCol) =>
|
||||
!!commentsPlugin.getCommentAtCell(rowIndex, hot.propToCol(baseCol)),
|
||||
(rowIndex, prop) => hot.getDataAtRowProp(rowIndex, prop)
|
||||
)
|
||||
|
||||
// Physical row 0's comment lives at visual row 1 post-sort, but the
|
||||
// buggy call checked physical rowIndex 0 straight as a visual row -
|
||||
// landing on physical row 1's cell (no comment, value 20) instead.
|
||||
// rowIndex 1 then wrongly reads AS visual row 1, which is physical row
|
||||
// 0's actual commented cell (value 10) - so the wrong row (1, not 0)
|
||||
// gets flagged, carrying the wrong row's value.
|
||||
expect(toPreserve).toEqual([
|
||||
{ rowIndex: 1, prop: 'FORMULA_HARD_COL', value: 10 }
|
||||
])
|
||||
|
||||
hot.destroy()
|
||||
})
|
||||
|
||||
it('resolves the correct cell once the sort is cleared before reading', () => {
|
||||
const { hot } = setup()
|
||||
const commentsPlugin: any = hot.getPlugin('comments')
|
||||
const sortPlugin: any = hot.getPlugin('multiColumnSorting')
|
||||
const sortConfigs = normalizeSortConfig(sortPlugin.getSortConfig())
|
||||
|
||||
sortPlugin.clearSort()
|
||||
|
||||
const toPreserve = getFormulaCellsToPreserveOnCancel(
|
||||
2,
|
||||
formulaBaseCols,
|
||||
(rowIndex, baseCol) =>
|
||||
!!commentsPlugin.getCommentAtCell(rowIndex, hot.propToCol(baseCol)),
|
||||
(rowIndex, prop) => hot.getDataAtRowProp(rowIndex, prop)
|
||||
)
|
||||
|
||||
expect(toPreserve).toEqual([
|
||||
{ rowIndex: 0, prop: 'FORMULA_HARD_COL', value: 10 }
|
||||
])
|
||||
|
||||
for (const sc of sortConfigs) sortPlugin.sort(sc)
|
||||
hot.destroy()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,31 @@
|
||||
import { withoutEditStatus } from './withoutEditStatus'
|
||||
import { EDIT_STATUS_COLUMN_NAME } from '../../shared/dc-validator/utils/editStatusColumnRule'
|
||||
|
||||
describe('withoutEditStatus', () => {
|
||||
it('removes the EDIT_STATUS column from a row', () => {
|
||||
const row = {
|
||||
PRIMARY_KEY_FIELD: 1,
|
||||
SOME_CHAR: 'original',
|
||||
[EDIT_STATUS_COLUMN_NAME]: 'U'
|
||||
}
|
||||
|
||||
expect(withoutEditStatus(row)).toEqual({
|
||||
PRIMARY_KEY_FIELD: 1,
|
||||
SOME_CHAR: 'original'
|
||||
})
|
||||
})
|
||||
|
||||
it('leaves a row without the EDIT_STATUS column unchanged', () => {
|
||||
const row = { PRIMARY_KEY_FIELD: 1, SOME_CHAR: 'original' }
|
||||
|
||||
expect(withoutEditStatus(row)).toEqual(row)
|
||||
})
|
||||
|
||||
it('does not mutate the row passed in', () => {
|
||||
const row = { PRIMARY_KEY_FIELD: 1, [EDIT_STATUS_COLUMN_NAME]: 'U' }
|
||||
|
||||
withoutEditStatus(row)
|
||||
|
||||
expect(row[EDIT_STATUS_COLUMN_NAME]).toEqual('U')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,14 @@
|
||||
import { EDIT_STATUS_COLUMN_NAME } from '../../shared/dc-validator/utils/editStatusColumnRule'
|
||||
|
||||
/**
|
||||
* Returns a copy of row without the client-only EDIT_STATUS column (see
|
||||
* editStatusColumnRule.ts) - shared by classifyRow (which must ignore it
|
||||
* when diffing, or writing its own prior output back would self-perpetuate)
|
||||
* and by anywhere a row is sent to the backend (which must never receive
|
||||
* it at all).
|
||||
*/
|
||||
export const withoutEditStatus = (row: any): any => {
|
||||
const { [EDIT_STATUS_COLUMN_NAME]: _editStatus, ...rest } = row
|
||||
|
||||
return rest
|
||||
}
|
||||
@@ -5,6 +5,11 @@
|
||||
<div class="card-text">
|
||||
<ng-container *ngSwitchCase="'key'">
|
||||
<p class="key-error" *ngIf="!keyError">
|
||||
<clr-icon
|
||||
class="is-error"
|
||||
shape="exclamation-circle"
|
||||
size="26"
|
||||
></clr-icon>
|
||||
Licence key is invalid. We can't provide you more details at the
|
||||
moment
|
||||
</p>
|
||||
@@ -20,6 +25,11 @@
|
||||
|
||||
<ng-container *ngSwitchCase="'limit'">
|
||||
<p class="key-error">
|
||||
<clr-icon
|
||||
class="is-error"
|
||||
shape="exclamation-circle"
|
||||
size="26"
|
||||
></clr-icon>
|
||||
The registered number of users reached the limit specified for your
|
||||
licence. Please contact
|
||||
<contact-link classes="color-green" />
|
||||
@@ -34,9 +44,9 @@
|
||||
</p>
|
||||
</ng-container>
|
||||
|
||||
<p><strong>Protocol:</strong> {{ protocol }}</p>
|
||||
<p class="m-0 mt-10"><strong>Protocol:</strong> {{ protocol }}</p>
|
||||
|
||||
<p>
|
||||
<p class="m-0">
|
||||
<strong>SYSSITE:</strong>
|
||||
<span
|
||||
*ngFor="let id of syssite.value; let i = index"
|
||||
@@ -59,11 +69,6 @@
|
||||
</a>
|
||||
</p>
|
||||
|
||||
<p *ngIf="licenseKeyData && userCountLimitation" class="m-0">
|
||||
<strong>Allowed users:</strong>
|
||||
{{ licenseKeyData.users_allowed }}
|
||||
</p>
|
||||
|
||||
<clr-tabs>
|
||||
<clr-tab>
|
||||
<button clrTabLink>Upload licence</button>
|
||||
@@ -102,34 +107,102 @@
|
||||
<clr-tab>
|
||||
<button clrTabLink>Paste licence</button>
|
||||
<clr-tab-content>
|
||||
<form class="clr-form license-key-form">
|
||||
<p>Licence key:</p>
|
||||
<div class="clr-control-container">
|
||||
<textarea
|
||||
[(ngModel)]="licenceKeyValue"
|
||||
(mouseleave)="trimKeys()"
|
||||
name="license-key-area"
|
||||
placeholder="Paste licence key here"
|
||||
class="clr-textarea"
|
||||
></textarea>
|
||||
</div>
|
||||
</form>
|
||||
<ng-container *ngIf="keyFormat === 'combined'">
|
||||
<form class="clr-form combined-key-form">
|
||||
<p>Licence key:</p>
|
||||
<div class="clr-control-container">
|
||||
<textarea
|
||||
[(ngModel)]="combinedKeyValue"
|
||||
(mouseleave)="onCombinedKeyInput()"
|
||||
name="combined-key-area"
|
||||
placeholder="Paste licence key here"
|
||||
class="clr-textarea"
|
||||
></textarea>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form class="clr-form activation-key-form">
|
||||
<p>Activation key:</p>
|
||||
<div class="clr-control-container">
|
||||
<textarea
|
||||
[(ngModel)]="activationKeyValue"
|
||||
(mouseleave)="trimKeys()"
|
||||
name="activation-key-area"
|
||||
placeholder="Paste activation key here"
|
||||
class="clr-textarea"
|
||||
></textarea>
|
||||
</div>
|
||||
</form>
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm btn-link p-0"
|
||||
(click)="toggleKeyFormat()"
|
||||
>
|
||||
Paste as two separate keys instead
|
||||
</button>
|
||||
</ng-container>
|
||||
|
||||
<ng-container *ngIf="keyFormat === 'legacy'">
|
||||
<form class="clr-form license-key-form">
|
||||
<p>Licence key:</p>
|
||||
<div class="clr-control-container">
|
||||
<textarea
|
||||
[(ngModel)]="licenceKeyValue"
|
||||
(mouseleave)="trimKeys()"
|
||||
name="license-key-area"
|
||||
placeholder="Paste licence key here"
|
||||
class="clr-textarea"
|
||||
></textarea>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<form class="clr-form activation-key-form">
|
||||
<p>Activation key:</p>
|
||||
<div class="clr-control-container">
|
||||
<textarea
|
||||
[(ngModel)]="activationKeyValue"
|
||||
(mouseleave)="trimKeys()"
|
||||
name="activation-key-area"
|
||||
placeholder="Paste activation key here"
|
||||
class="clr-textarea"
|
||||
></textarea>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-sm btn-link p-0"
|
||||
(click)="toggleKeyFormat()"
|
||||
>
|
||||
Paste as a single key instead
|
||||
</button>
|
||||
</ng-container>
|
||||
</clr-tab-content>
|
||||
</clr-tab>
|
||||
</clr-tabs>
|
||||
|
||||
<!--
|
||||
licenseKeyData starts as whatever key is currently active (set once
|
||||
in ngOnInit), then live-updates to preview a pasted-but-not-yet-
|
||||
applied key's own details instead - see refreshKeyPreview().
|
||||
-->
|
||||
<div *ngIf="licenseKeyData" class="key-details">
|
||||
<h6 cds-text="subsection" class="mt-15 mb-10">Key Details</h6>
|
||||
|
||||
<p class="m-0">
|
||||
<strong>Valid until:</strong>
|
||||
{{ licenseKeyData.valid_until }}
|
||||
<span *ngIf="licenseKeyData.demo">(demo/free tier key)</span>
|
||||
</p>
|
||||
|
||||
<p class="m-0">
|
||||
<strong>Allowed users:</strong>
|
||||
{{ licenseKeyData.users_allowed }}
|
||||
</p>
|
||||
|
||||
<p class="m-0">
|
||||
<strong>Site ID(s) in this key:</strong>
|
||||
{{
|
||||
(licenseKeyData.site_id_multiple?.length
|
||||
? licenseKeyData.site_id_multiple
|
||||
: [licenseKeyData.site_id]
|
||||
).join(', ')
|
||||
}}
|
||||
</p>
|
||||
|
||||
<p *ngIf="enabledFeatures.length" class="m-0">
|
||||
<strong>Enabled features:</strong>
|
||||
{{ enabledFeatures.join(', ') }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-footer d-flex clr-align-items-center">
|
||||
@@ -150,6 +223,38 @@
|
||||
Continue with free tier
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<p
|
||||
class="key-error protocol-mismatch-warning"
|
||||
*ngIf="protocolMismatch === 'requiresHttps'"
|
||||
>
|
||||
<clr-icon
|
||||
class="color-orange"
|
||||
shape="exclamation-triangle"
|
||||
size="26"
|
||||
></clr-icon>
|
||||
This key was generated for a secure (HTTPS) connection, but DataController
|
||||
is currently running over HTTP - it will not activate here. Access
|
||||
DataController via HTTPS, or contact
|
||||
<contact-link classes="color-green" />
|
||||
for an HTTP-compatible key.
|
||||
</p>
|
||||
|
||||
<p
|
||||
class="key-error protocol-mismatch-warning"
|
||||
*ngIf="protocolMismatch === 'requiresHttp'"
|
||||
>
|
||||
<clr-icon
|
||||
class="color-orange"
|
||||
shape="exclamation-triangle"
|
||||
size="26"
|
||||
></clr-icon>
|
||||
This key was generated for an insecure (HTTP) connection, but this page is
|
||||
running in a secure browsing context (HTTPS, or localhost) - it will not
|
||||
activate here. Contact
|
||||
<contact-link classes="color-green" />
|
||||
for an HTTPS-compatible key.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
.key-error clr-icon {
|
||||
// clr-icon defaults to vertical-align: middle, which sits it noticeably
|
||||
// above the text baseline next to it - align its bottom edge with the
|
||||
// text's instead.
|
||||
vertical-align: bottom;
|
||||
margin-right: 10px;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
import { Component, OnInit, ViewEncapsulation } from '@angular/core'
|
||||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser'
|
||||
import { ActivatedRoute, Router } from '@angular/router'
|
||||
import { AppService, LicenceService, SasService } from '../services'
|
||||
import { LicenseKeyData } from '../models/LicenseKeyData'
|
||||
import { RequestWrapperResponse } from '../models/request-wrapper/RequestWrapperResponse'
|
||||
import {
|
||||
detectLicenceKeyProtocolMismatch,
|
||||
LicenceKeyProtocolMismatch
|
||||
} from './utils/detectLicenceKeyProtocolMismatch'
|
||||
import {
|
||||
isCombinedLicenceKey,
|
||||
splitCombinedLicenceKey
|
||||
} from './utils/combinedLicenceKey'
|
||||
import { getEnabledFeatureLabels } from './utils/getEnabledFeatureLabels'
|
||||
|
||||
enum LicenseActions {
|
||||
key = 'key',
|
||||
@@ -21,12 +31,19 @@ enum LicenseActions {
|
||||
export class LicensingComponent implements OnInit {
|
||||
public action: LicenseActions | null = null
|
||||
|
||||
public licenseErrors: { [key: string]: string } = {
|
||||
missing: `Licence key is missing - please contact <a class="color-green" href="mailto: support@datacontroller.io">support@datacontroller.io</a> and enter valid keys below.`,
|
||||
expired: `Licence key is expired - please contact <a class="color-green" href="mailto: support@datacontroller.io">support@datacontroller.io</a> and enter valid keys below.`,
|
||||
invalid: `Licence key is invalid - please contact <a class="color-green" href="mailto: support@datacontroller.io">support@datacontroller.io</a> and enter valid keys below.`,
|
||||
missmatch: `Your SYSSITE (below) is not found in the licence key - please contact <a class="color-green" href="mailto: support@datacontroller.io">support@datacontroller.io</a> and enter valid keys below.`
|
||||
}
|
||||
// Each message carries its own icon markup, rather than relying on a
|
||||
// sibling element in the template - these render via [innerHTML], which
|
||||
// replaces all of the host element's children, so a real <clr-icon>
|
||||
// placed in the template around the binding would never survive.
|
||||
private readonly errorIcon = `<clr-icon class="is-error" shape="exclamation-circle" size="26"></clr-icon>`
|
||||
|
||||
// SafeHtml, built via bypassSecurityTrustHtml in the constructor (needs
|
||||
// DomSanitizer, not yet available in a field initializer) - Angular's
|
||||
// default [innerHTML] sanitizer strips unrecognised tags like <clr-icon>
|
||||
// (a custom element, not on its standard-tags allowlist), even though it
|
||||
// leaves the plain <a> in these same strings alone. Safe to bypass since
|
||||
// this content is entirely hardcoded here, never derived from user input.
|
||||
public licenseErrors: { [key: string]: SafeHtml }
|
||||
|
||||
public keyError: string | undefined
|
||||
public errorDetails: string | undefined
|
||||
@@ -34,6 +51,12 @@ export class LicensingComponent implements OnInit {
|
||||
public licenceKeyValue: string = ''
|
||||
public activationKeyValue: string = ''
|
||||
|
||||
// Purely which INPUT LAYOUT is shown (one field vs two) - not a strict
|
||||
// parsing gate. Recognising a combined key doesn't depend on this: see
|
||||
// maybeSplitCombinedKey(), called from both layouts' own input handlers.
|
||||
public keyFormat: 'combined' | 'legacy' = 'combined'
|
||||
public combinedKeyValue: string = ''
|
||||
|
||||
public applyingKeys: boolean = false
|
||||
public protocol: string =
|
||||
location.protocol === 'https:'
|
||||
@@ -44,7 +67,6 @@ export class LicensingComponent implements OnInit {
|
||||
public currentLicenceKey = this.licenceService.licenceKey
|
||||
public currentActivationKey = this.licenceService.activationKey
|
||||
public isAppFreeTier = this.licenceService.isAppFreeTier
|
||||
public userCountLimitation = this.licenceService.userCountLimitation
|
||||
|
||||
public licenseKeyData: LicenseKeyData | null = null
|
||||
|
||||
@@ -60,8 +82,24 @@ export class LicensingComponent implements OnInit {
|
||||
private router: Router,
|
||||
private licenceService: LicenceService,
|
||||
private sasService: SasService,
|
||||
private appService: AppService
|
||||
) {}
|
||||
private appService: AppService,
|
||||
private sanitizer: DomSanitizer
|
||||
) {
|
||||
this.licenseErrors = {
|
||||
missing: this.sanitizer.bypassSecurityTrustHtml(
|
||||
`${this.errorIcon} Licence key is missing - please contact <a class="color-green" href="mailto: support@datacontroller.io">support@datacontroller.io</a> and enter valid keys below.`
|
||||
),
|
||||
expired: this.sanitizer.bypassSecurityTrustHtml(
|
||||
`${this.errorIcon} Licence key is expired - please contact <a class="color-green" href="mailto: support@datacontroller.io">support@datacontroller.io</a> and enter valid keys below.`
|
||||
),
|
||||
invalid: this.sanitizer.bypassSecurityTrustHtml(
|
||||
`${this.errorIcon} Licence key is invalid - please contact <a class="color-green" href="mailto: support@datacontroller.io">support@datacontroller.io</a> and enter valid keys below.`
|
||||
),
|
||||
missmatch: this.sanitizer.bypassSecurityTrustHtml(
|
||||
`${this.errorIcon} Your SYSSITE (below) is not found in the licence key - please contact <a class="color-green" href="mailto: support@datacontroller.io">support@datacontroller.io</a> and enter valid keys below.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.licenceKeyValue = this.currentLicenceKey || ''
|
||||
@@ -89,9 +127,73 @@ export class LicensingComponent implements OnInit {
|
||||
this.licenseKeyData = this.licenceService.getLicenseKeyData()
|
||||
}
|
||||
|
||||
public trimKeys() {
|
||||
public async trimKeys() {
|
||||
this.licenceKeyValue = this.licenceKeyValue.trim()
|
||||
this.activationKeyValue = this.activationKeyValue.trim()
|
||||
|
||||
// Auto-detect regardless of keyFormat - a combined key pasted into the
|
||||
// legacy "Licence key" field on its own still gets recognised and
|
||||
// splits into both fields, rather than requiring the toggle to match.
|
||||
await this.maybeSplitCombinedKey(this.licenceKeyValue)
|
||||
await this.refreshKeyPreview()
|
||||
}
|
||||
|
||||
public async onCombinedKeyInput() {
|
||||
this.combinedKeyValue = this.combinedKeyValue.trim()
|
||||
|
||||
// The combined field is the sole source of truth for
|
||||
// licenceKeyValue/activationKeyValue in this layout - if it's been
|
||||
// cleared (or isn't a recognisable combined key), there's no key data
|
||||
// to preview, so clear rather than leave a stale split from an earlier
|
||||
// paste (which would otherwise keep decrypting to that old key).
|
||||
const wasSplit = await this.maybeSplitCombinedKey(this.combinedKeyValue)
|
||||
if (!wasSplit) {
|
||||
this.licenceKeyValue = ''
|
||||
this.activationKeyValue = ''
|
||||
}
|
||||
|
||||
await this.refreshKeyPreview()
|
||||
}
|
||||
|
||||
// Decrypts whatever's currently in licenceKeyValue/activationKeyValue
|
||||
// purely to preview its details (valid_until, users_allowed, ...) before
|
||||
// the user ever clicks Apply - decryptLicenseKey() has no side effects,
|
||||
// so this is safe to call speculatively on every input change. Clears
|
||||
// rather than leaves stale data on failure/incomplete input, since
|
||||
// showing a previous key's details next to a since-changed paste would
|
||||
// be actively misleading, not just uninformative.
|
||||
private async refreshKeyPreview(): Promise<void> {
|
||||
if (!this.licenceKeyValue || !this.activationKeyValue) {
|
||||
this.licenseKeyData = null
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
this.licenseKeyData = await this.licenceService.decryptLicenseKey(
|
||||
this.licenceKeyValue,
|
||||
this.activationKeyValue
|
||||
)
|
||||
} catch {
|
||||
this.licenseKeyData = null
|
||||
}
|
||||
}
|
||||
|
||||
public toggleKeyFormat() {
|
||||
this.keyFormat = this.keyFormat === 'combined' ? 'legacy' : 'combined'
|
||||
}
|
||||
|
||||
// Shared by both input layouts' own handlers above - populates
|
||||
// licenceKeyValue/activationKeyValue when value is recognisably a
|
||||
// combined key, regardless of which field it was typed/pasted into.
|
||||
private async maybeSplitCombinedKey(value: string): Promise<boolean> {
|
||||
if (!isCombinedLicenceKey(value)) return false
|
||||
|
||||
const split = await splitCombinedLicenceKey(value)
|
||||
if (!split) return false
|
||||
|
||||
this.licenceKeyValue = split.licenceKey
|
||||
this.activationKeyValue = split.activationKey
|
||||
return true
|
||||
}
|
||||
|
||||
public copySyssite(copyIconRef: any, copyTooltip: any, syssite: string[]) {
|
||||
@@ -150,7 +252,7 @@ export class LicensingComponent implements OnInit {
|
||||
|
||||
const reader = new FileReader()
|
||||
|
||||
reader.onload = (evt) => {
|
||||
reader.onload = async (evt) => {
|
||||
this.licenceFileError = 'Error reading file.'
|
||||
|
||||
if (!evt || !evt.target) return
|
||||
@@ -160,9 +262,20 @@ export class LicensingComponent implements OnInit {
|
||||
|
||||
this.licenceFileLoading = false
|
||||
this.licenceFileError = undefined
|
||||
const fileArr = evt.target.result.toString().split('\n')
|
||||
this.activationKeyValue = fileArr[1]
|
||||
this.licenceKeyValue = fileArr[0]
|
||||
|
||||
const fileArr = evt.target.result.toString().trim().split('\n')
|
||||
|
||||
// A combined-key file is a single line - splits into both fields.
|
||||
// Anything else keeps the existing 2-line legacy file behaviour.
|
||||
if (
|
||||
fileArr.length !== 1 ||
|
||||
!(await this.maybeSplitCombinedKey(fileArr[0]))
|
||||
) {
|
||||
this.activationKeyValue = fileArr[1]
|
||||
this.licenceKeyValue = fileArr[0]
|
||||
}
|
||||
|
||||
await this.refreshKeyPreview()
|
||||
}
|
||||
|
||||
reader.readAsText(file)
|
||||
@@ -180,7 +293,29 @@ export class LicensingComponent implements OnInit {
|
||||
this.activationKeyValue === this.currentActivationKey
|
||||
)
|
||||
return true
|
||||
// A protocol mismatch is a deterministic predictor of decrypt failure
|
||||
// (see detectLicenceKeyProtocolMismatch's own doc comment) - submitting
|
||||
// anyway would just trade this specific warning for a generic "invalid
|
||||
// key" error after a round trip to the backend.
|
||||
if (this.protocolMismatch) return true
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Warns before the user even submits - covers both the file-upload and
|
||||
// paste tabs, since both feed licenceKeyValue/activationKeyValue. Passes
|
||||
// actual WebCrypto availability, not location.protocol - see
|
||||
// detectLicenceKeyProtocolMismatch's own doc comment for why (localhost
|
||||
// is a secure context even over http).
|
||||
get protocolMismatch(): LicenceKeyProtocolMismatch {
|
||||
return detectLicenceKeyProtocolMismatch(
|
||||
this.licenceKeyValue,
|
||||
this.activationKeyValue,
|
||||
!!(window.crypto && window.crypto.subtle)
|
||||
)
|
||||
}
|
||||
|
||||
get enabledFeatures(): string[] {
|
||||
return getEnabledFeatureLabels(this.licenseKeyData?.features)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
import * as base64Converter from 'base64-arraybuffer'
|
||||
import {
|
||||
COMBINED_KEY_PREFIX,
|
||||
isCombinedLicenceKey,
|
||||
splitCombinedLicenceKey
|
||||
} from './combinedLicenceKey'
|
||||
|
||||
// Mirrors dckey's own encodeCombinedKey() (main.js) exactly, so these tests
|
||||
// build fixtures the same way a real generated key would be produced,
|
||||
// rather than relying on a hardcoded string that could go stale if either
|
||||
// side's algorithm ever changes.
|
||||
const gzipCompress = async (bytes: Uint8Array): Promise<ArrayBuffer> => {
|
||||
const compressionStream = new CompressionStream('gzip')
|
||||
const writer = compressionStream.writable.getWriter()
|
||||
writer.write(new Uint8Array(bytes))
|
||||
writer.close()
|
||||
|
||||
return new Response(compressionStream.readable).arrayBuffer()
|
||||
}
|
||||
|
||||
const encodeCombinedLicenceKeyFixture = async (
|
||||
licenceKey: string,
|
||||
activationKey: string
|
||||
): Promise<string> => {
|
||||
const payloadBytes = new TextEncoder().encode(
|
||||
`${licenceKey} ${activationKey}`
|
||||
)
|
||||
const compressedBytes = await gzipCompress(payloadBytes)
|
||||
|
||||
return COMBINED_KEY_PREFIX + base64Converter.encode(compressedBytes)
|
||||
}
|
||||
|
||||
describe('isCombinedLicenceKey', () => {
|
||||
it('is true for prefixed text', () => {
|
||||
expect(isCombinedLicenceKey('DCKEY1:abc123')).toBeTrue()
|
||||
})
|
||||
|
||||
it('is false for a plain legacy key', () => {
|
||||
expect(isCombinedLicenceKey('some-legacy-licence-key')).toBeFalse()
|
||||
})
|
||||
|
||||
it('is false for an empty string', () => {
|
||||
expect(isCombinedLicenceKey('')).toBeFalse()
|
||||
})
|
||||
|
||||
it('is true even with leading/trailing whitespace around the prefix', () => {
|
||||
expect(isCombinedLicenceKey(' DCKEY1:abc123 ')).toBeTrue()
|
||||
})
|
||||
})
|
||||
|
||||
describe('splitCombinedLicenceKey', () => {
|
||||
it('round-trips a fixture built the same way dckey encodes one', async () => {
|
||||
const combined = await encodeCombinedLicenceKeyFixture(
|
||||
'licence-key-value',
|
||||
'activation-key-value'
|
||||
)
|
||||
|
||||
expect(await splitCombinedLicenceKey(combined)).toEqual({
|
||||
licenceKey: 'licence-key-value',
|
||||
activationKey: 'activation-key-value'
|
||||
})
|
||||
})
|
||||
|
||||
it('returns null for text without the prefix', async () => {
|
||||
expect(
|
||||
await splitCombinedLicenceKey('a-plain-legacy-licence-key')
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('rejects for prefixed text that is not valid compressed data', async () => {
|
||||
await expectAsync(
|
||||
splitCombinedLicenceKey('DCKEY1:not-valid-base64-gzip-data')
|
||||
).toBeRejected()
|
||||
})
|
||||
|
||||
it('splits on the first space only, not every space', async () => {
|
||||
// Not a real-world value today (licence/activation keys are base64,
|
||||
// which never contains a space) - guards the split logic itself rather
|
||||
// than that assumption.
|
||||
const combined = await encodeCombinedLicenceKeyFixture(
|
||||
'licence key with spaces',
|
||||
'activation-key-value'
|
||||
)
|
||||
|
||||
expect(await splitCombinedLicenceKey(combined)).toEqual({
|
||||
licenceKey: 'licence',
|
||||
activationKey: 'key with spaces activation-key-value'
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,83 @@
|
||||
import * as base64Converter from 'base64-arraybuffer'
|
||||
|
||||
/**
|
||||
* Format produced by dckey's own encodeCombinedKey() (main.js):
|
||||
* "DCKEY1:" + base64(gzip(licenceKey + " " + activationKey)). The prefix is
|
||||
* plain ASCII, not itself compressed/encoded - base64's alphabet never
|
||||
* contains ":", so it can never collide with the start of a legacy licence
|
||||
* key or activation key, making format detection unambiguous.
|
||||
*/
|
||||
export const COMBINED_KEY_PREFIX = 'DCKEY1:'
|
||||
|
||||
export const isCombinedLicenceKey = (text: string): boolean =>
|
||||
text.trim().startsWith(COMBINED_KEY_PREFIX)
|
||||
|
||||
const streamToArrayBuffer = async (
|
||||
readable: ReadableStream<Uint8Array>
|
||||
): Promise<ArrayBuffer> => {
|
||||
const reader = readable.getReader()
|
||||
const chunks: Uint8Array[] = []
|
||||
let totalLength = 0
|
||||
|
||||
while (true) {
|
||||
const { done, value } = await reader.read()
|
||||
if (done) break
|
||||
chunks.push(value)
|
||||
totalLength += value.length
|
||||
}
|
||||
|
||||
const result = new Uint8Array(totalLength)
|
||||
let offset = 0
|
||||
for (const chunk of chunks) {
|
||||
result.set(chunk, offset)
|
||||
offset += chunk.length
|
||||
}
|
||||
|
||||
return result.buffer
|
||||
}
|
||||
|
||||
const gzipDecompress = async (bytes: ArrayBuffer): Promise<ArrayBuffer> => {
|
||||
const decompressionStream = new DecompressionStream('gzip')
|
||||
const writer = decompressionStream.writable.getWriter()
|
||||
|
||||
// Awaited (unlike a fire-and-forget write) so invalid gzip data rejects
|
||||
// through this function's own returned promise, not as a separate
|
||||
// unhandled rejection racing the readable side below.
|
||||
const result = await Promise.all([
|
||||
writer.write(new Uint8Array(bytes)).then(() => writer.close()),
|
||||
streamToArrayBuffer(decompressionStream.readable)
|
||||
])
|
||||
|
||||
return result[1]
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a combined licence key back into its two parts. Returns null (not
|
||||
* a rejected promise) when text isn't a combined key at all, so callers can
|
||||
* use it as a "try this, then fall back to the legacy two-field input" check
|
||||
* without a try/catch for that common case - a prefixed-but-corrupted
|
||||
* string still rejects, since that's a real error, not a format mismatch.
|
||||
*/
|
||||
export const splitCombinedLicenceKey = async (
|
||||
text: string
|
||||
): Promise<{ licenceKey: string; activationKey: string } | null> => {
|
||||
const trimmed = text.trim()
|
||||
|
||||
if (!isCombinedLicenceKey(trimmed)) return null
|
||||
|
||||
const compressedBytes = base64Converter.decode(
|
||||
trimmed.slice(COMBINED_KEY_PREFIX.length)
|
||||
)
|
||||
const decompressedBytes = await gzipDecompress(compressedBytes)
|
||||
const payload = new TextDecoder().decode(decompressedBytes)
|
||||
const separatorIndex = payload.indexOf(' ')
|
||||
|
||||
if (separatorIndex === -1) {
|
||||
throw new Error('Invalid combined licence key: missing separator')
|
||||
}
|
||||
|
||||
return {
|
||||
licenceKey: payload.slice(0, separatorIndex),
|
||||
activationKey: payload.slice(separatorIndex + 1)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
import { detectLicenceKeyProtocolMismatch } from './detectLicenceKeyProtocolMismatch'
|
||||
|
||||
describe('detectLicenceKeyProtocolMismatch', () => {
|
||||
// A key generated for an insecure connection always carries the same
|
||||
// text in both fields; a key generated for a secure connection always
|
||||
// carries two different values.
|
||||
const httpsFormatLicenceKey = 'licence-key-value-abc123'
|
||||
const httpsFormatActivationKey = 'activation-key-value-xyz789'
|
||||
const httpFormatKey = 'same-value-for-both-fields'
|
||||
|
||||
it('flags an HTTPS-format key used where WebCrypto is unavailable', () => {
|
||||
expect(
|
||||
detectLicenceKeyProtocolMismatch(
|
||||
httpsFormatLicenceKey,
|
||||
httpsFormatActivationKey,
|
||||
false
|
||||
)
|
||||
).toEqual('requiresHttps')
|
||||
})
|
||||
|
||||
it('does not flag an HTTPS-format key where WebCrypto is available', () => {
|
||||
expect(
|
||||
detectLicenceKeyProtocolMismatch(
|
||||
httpsFormatLicenceKey,
|
||||
httpsFormatActivationKey,
|
||||
true
|
||||
)
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('flags an HTTP-format key where WebCrypto is available - e.g. localhost, which browsers always treat as a secure context even over plain http', () => {
|
||||
expect(
|
||||
detectLicenceKeyProtocolMismatch(httpFormatKey, httpFormatKey, true)
|
||||
).toEqual('requiresHttp')
|
||||
})
|
||||
|
||||
it('does not flag an HTTP-format key where WebCrypto is unavailable', () => {
|
||||
expect(
|
||||
detectLicenceKeyProtocolMismatch(httpFormatKey, httpFormatKey, false)
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('returns null when either key is empty', () => {
|
||||
expect(
|
||||
detectLicenceKeyProtocolMismatch('', httpsFormatActivationKey, false)
|
||||
).toBeNull()
|
||||
expect(
|
||||
detectLicenceKeyProtocolMismatch(httpsFormatLicenceKey, '', false)
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('trims whitespace before comparing', () => {
|
||||
expect(
|
||||
detectLicenceKeyProtocolMismatch(
|
||||
` ${httpFormatKey} `,
|
||||
`${httpFormatKey}\n`,
|
||||
true
|
||||
)
|
||||
).toEqual('requiresHttp')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
export type LicenceKeyProtocolMismatch = 'requiresHttps' | 'requiresHttp' | null
|
||||
|
||||
/**
|
||||
* Detects a licence key generated for one protocol (http/https) being
|
||||
* pasted/uploaded on a page where the other one is actually in effect -
|
||||
* before any decrypt attempt, purely from the raw key text.
|
||||
*
|
||||
* A key generated for an insecure connection always carries the same text
|
||||
* in both the licence key and activation key fields; a key generated for a
|
||||
* secure connection always carries two different values. That distinction
|
||||
* alone tells us which format a pasted key is, without needing to attempt
|
||||
* decryption first.
|
||||
*
|
||||
* This is a structural assumption about key-generation logic
|
||||
* (a separate repo) - if that ever changes to generate distinct values for
|
||||
* HTTP-format keys too, this detection would silently misclassify keys.
|
||||
*
|
||||
* isSecureContext must reflect whether this browsing context can actually
|
||||
* decrypt a secure-connection key (mirrors the check licence.service.ts's
|
||||
* own decryptLicenseKey() makes) - not simply `location.protocol ===
|
||||
* 'https:'`. Browsers treat localhost as a secure context even over plain
|
||||
* http, so a key meant for an insecure connection still fails to decrypt
|
||||
* there, exactly like it would on a real https page.
|
||||
*/
|
||||
export const detectLicenceKeyProtocolMismatch = (
|
||||
licenceKey: string,
|
||||
activationKey: string,
|
||||
isSecureContext: boolean
|
||||
): LicenceKeyProtocolMismatch => {
|
||||
const trimmedLicenceKey = licenceKey.trim()
|
||||
const trimmedActivationKey = activationKey.trim()
|
||||
|
||||
if (!trimmedLicenceKey || !trimmedActivationKey) return null
|
||||
|
||||
const isHttpsFormatKey = trimmedLicenceKey !== trimmedActivationKey
|
||||
|
||||
if (isHttpsFormatKey && !isSecureContext) return 'requiresHttps'
|
||||
if (!isHttpsFormatKey && isSecureContext) return 'requiresHttp'
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
import { getEnabledFeatureLabels } from './getEnabledFeatureLabels'
|
||||
|
||||
describe('getEnabledFeatureLabels', () => {
|
||||
it('returns an empty list when features is undefined', () => {
|
||||
expect(getEnabledFeatureLabels(undefined)).toEqual([])
|
||||
})
|
||||
|
||||
it('lists only the enabled toggle features from a new-format object', () => {
|
||||
expect(
|
||||
getEnabledFeatureLabels({
|
||||
vra: null,
|
||||
era: null,
|
||||
sra: null,
|
||||
hra: null,
|
||||
srl: null,
|
||||
till: null,
|
||||
vb: true,
|
||||
vbl: null,
|
||||
ldl: null,
|
||||
fu: false,
|
||||
er: true,
|
||||
ar: false
|
||||
})
|
||||
).toEqual(['Viewbox', 'Edit Record'])
|
||||
})
|
||||
|
||||
it('lists all four when every toggle is enabled', () => {
|
||||
expect(
|
||||
getEnabledFeatureLabels({
|
||||
vra: null,
|
||||
era: null,
|
||||
sra: null,
|
||||
hra: null,
|
||||
srl: null,
|
||||
till: null,
|
||||
vb: true,
|
||||
vbl: null,
|
||||
ldl: null,
|
||||
fu: true,
|
||||
er: true,
|
||||
ar: true
|
||||
})
|
||||
).toEqual(['Viewbox', 'File Upload', 'Edit Record', 'Add Record'])
|
||||
})
|
||||
|
||||
it('returns an empty list when every toggle is disabled', () => {
|
||||
expect(
|
||||
getEnabledFeatureLabels({
|
||||
vra: null,
|
||||
era: null,
|
||||
sra: null,
|
||||
hra: null,
|
||||
srl: null,
|
||||
till: null,
|
||||
vb: false,
|
||||
vbl: null,
|
||||
ldl: null,
|
||||
fu: false,
|
||||
er: false,
|
||||
ar: false
|
||||
})
|
||||
).toEqual([])
|
||||
})
|
||||
|
||||
it('decodes a legacy positional string the same way', () => {
|
||||
// viewbox=1 (position 6), fileUpload=0 (position 9), editRecord=1
|
||||
// (position 10), addRecord=0 (position 11) - see LicenceFeaturesMap.
|
||||
expect(getEnabledFeatureLabels('-,-,-,-,-,-,1,-,-,0,1,0')).toEqual([
|
||||
'Viewbox',
|
||||
'Edit Record'
|
||||
])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,24 @@
|
||||
import {
|
||||
decodeLicenceFeatures,
|
||||
LicenceFeaturesObject
|
||||
} from '../../services/utils/decodeLicenceFeatures'
|
||||
import { LicenceState } from '../../models/LicenceState'
|
||||
|
||||
const TOGGLE_FEATURE_LABELS: { key: keyof LicenceState; label: string }[] = [
|
||||
{ key: 'viewbox', label: 'Viewbox' },
|
||||
{ key: 'fileUpload', label: 'File Upload' },
|
||||
{ key: 'editRecord', label: 'Edit Record' },
|
||||
{ key: 'addRecord', label: 'Add Record' }
|
||||
]
|
||||
|
||||
export const getEnabledFeatureLabels = (
|
||||
features: string | LicenceFeaturesObject | undefined
|
||||
): string[] => {
|
||||
if (!features) return []
|
||||
|
||||
const decoded = decodeLicenceFeatures(features)
|
||||
|
||||
return TOGGLE_FEATURE_LABELS.filter(({ key }) => decoded[key]).map(
|
||||
({ label }) => label
|
||||
)
|
||||
}
|
||||
@@ -10,5 +10,6 @@ export class AbortDetails {
|
||||
SYSWARNINGTEXT?: string
|
||||
SYSERRORTEXT?: string
|
||||
MAC?: string
|
||||
_PROGRAM?: string
|
||||
LOG?: string
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ export interface LicenceState {
|
||||
}
|
||||
|
||||
/**
|
||||
* Legacy-format decode table only - newly-issued keys use a named
|
||||
* LicenceFeaturesObject instead (see decodeLicenceFeatures.ts). Kept
|
||||
* unchanged and permanently, since every already-issued key still relies
|
||||
* on these ordinal positions to decode.
|
||||
*
|
||||
* '-' means unset
|
||||
* '0' disabled
|
||||
* '1' enabled
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { LicenceFeaturesObject } from '../services/utils/decodeLicenceFeatures'
|
||||
|
||||
export interface LicenseKeyData {
|
||||
valid_until: string
|
||||
users_allowed: number
|
||||
@@ -5,5 +7,5 @@ export interface LicenseKeyData {
|
||||
site_id_multiple: string[]
|
||||
demo: boolean
|
||||
hot_license_key: string | undefined
|
||||
features?: string
|
||||
features?: string | LicenceFeaturesObject
|
||||
}
|
||||
|
||||
@@ -217,7 +217,9 @@ export class ApproveDetailsComponent implements AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
public calcDiff() {
|
||||
if (!this.response) return
|
||||
// params-only responses (e.g. already reviewed submissions) carry no diff
|
||||
// tables - nothing to calculate, the details header still renders
|
||||
if (!this.response || !this.response.cols) return
|
||||
|
||||
let news = this.response.new
|
||||
let updates = this.response.updates
|
||||
@@ -355,26 +357,6 @@ export class ApproveDetailsComponent implements AfterViewInit, OnDestroy {
|
||||
this.submitArr.push(item)
|
||||
}
|
||||
}
|
||||
|
||||
let diffs = {
|
||||
ACTION: 'SHOW_DIFFS',
|
||||
TABLE: this.tableId,
|
||||
DIFFTIME: new Date().toUTCString()
|
||||
}
|
||||
// show diffs and changes info in a same call
|
||||
this.sasStoreService
|
||||
.showDiffs(diffs, 'SASControlTable', 'auditors/postdata')
|
||||
.then((res: AuditorsPostdataSASResponse) => {
|
||||
let param = res.params[0]
|
||||
this.params = param
|
||||
this.response = res
|
||||
this.calcDiff()
|
||||
this.callChangesInfo(this.tableId)
|
||||
})
|
||||
.catch((err: any) => err)
|
||||
.finally(() => {
|
||||
this.loadingTable = true
|
||||
})
|
||||
}
|
||||
)
|
||||
if (typeof this.router.snapshot.params['tableId'] === 'undefined') {
|
||||
|
||||
@@ -68,6 +68,9 @@ export class SubmitterComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
|
||||
public goToDetails(table_id: any) {
|
||||
// the details URL re-creates this component - carry the queue payload
|
||||
// over so it is not fetched again on mount
|
||||
this.sasStoreService.handoffSubmits(this.submitData)
|
||||
this.router.navigateByUrl('/review/submitted/' + table_id)
|
||||
}
|
||||
|
||||
@@ -83,14 +86,19 @@ export class SubmitterComponent implements OnInit, AfterViewInit {
|
||||
|
||||
this.itemsNum = 10
|
||||
try {
|
||||
let res = await this.sasStoreService.getSubmitts()
|
||||
// navigating from the submit list to a details URL re-creates this
|
||||
// component - take the queue payload carried over by that navigation
|
||||
// instead of fetching it again
|
||||
let fromsas: any = this.sasStoreService.takeSubmitsHandoff()
|
||||
|
||||
this.remained = res.fromsas.length
|
||||
if (!fromsas) {
|
||||
fromsas = (await this.sasStoreService.getSubmitts()).fromsas
|
||||
}
|
||||
|
||||
this.remained = fromsas.length
|
||||
if (this.remained > 0) {
|
||||
this.submitter = res.fromsas[0].SUBMITTED_BY_NM
|
||||
let submitterList: SubmitterData[] = res.fromsas.map(function (
|
||||
item: any
|
||||
) {
|
||||
this.submitter = fromsas[0].SUBMITTED_BY_NM
|
||||
let submitterList: SubmitterData[] = fromsas.map(function (item: any) {
|
||||
return {
|
||||
tableId: item.TABLE_ID,
|
||||
base: item.BASE_TABLE,
|
||||
@@ -100,7 +108,7 @@ export class SubmitterComponent implements OnInit, AfterViewInit {
|
||||
}
|
||||
})
|
||||
this.submitterList = submitterList
|
||||
this.submitData = res.fromsas
|
||||
this.submitData = fromsas
|
||||
|
||||
// Details page
|
||||
if (typeof tableIdParam !== 'undefined') {
|
||||
|
||||
@@ -38,6 +38,9 @@ const buildDeps = () => {
|
||||
const appStoreService: any = {
|
||||
getDcAdapterSettings: () => undefined
|
||||
}
|
||||
const startupCheckService: any = {
|
||||
updateStep: jasmine.createSpy('updateStep')
|
||||
}
|
||||
|
||||
return {
|
||||
licenceService,
|
||||
@@ -46,7 +49,8 @@ const buildDeps = () => {
|
||||
loggerService,
|
||||
appSettingsService,
|
||||
router,
|
||||
appStoreService
|
||||
appStoreService,
|
||||
startupCheckService
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +62,8 @@ const buildAppService = (deps: ReturnType<typeof buildDeps>) =>
|
||||
deps.loggerService,
|
||||
deps.appSettingsService,
|
||||
deps.router,
|
||||
deps.appStoreService
|
||||
deps.appStoreService,
|
||||
deps.startupCheckService
|
||||
)
|
||||
|
||||
// Minimal valid startupservice payload — just enough to pass startUpData()'s
|
||||
@@ -138,4 +143,36 @@ describe('AppService - startup retry', () => {
|
||||
expect(deps.sasService.request).toHaveBeenCalledTimes(1)
|
||||
expect(deps.eventService.showInfoModal).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
// Reproduces a misconfigured Viya computeTasks deployment: the Compute
|
||||
// service returns a plain-text "Job error" body instead of JSON: the
|
||||
// adapter can't parse it and resolves with the raw text as adapterResponse
|
||||
// itself (see getMalformedAdapterResponseMessage's own doc comment).
|
||||
// "Globvars, Sasdatasets, Saslibs, XLMaps are not present" would also be
|
||||
// technically true here, but hides the real cause.
|
||||
it('shows the real response text (not the generic missing-props message) when adapterResponse is a raw string, not an object', async () => {
|
||||
const deps = buildDeps()
|
||||
const rawJobError = [
|
||||
'Job error',
|
||||
'The Compute service could not execute the task c74a707a-8b88-46a5-8f28-9a7694ad5e13 because the context 340cd3eb-72ae is not reusable. Please provide a reusable context or supply the ID of an existing session in the task request.',
|
||||
'path: /compute/tasks',
|
||||
'correlator: dc1a9fda-8f65-4f32-b4d4-2a70e02179b1;1bcb6a4c-8a16-4053-a790-292544c25a03'
|
||||
].join('\n')
|
||||
deps.sasService.request.and.resolveTo({ adapterResponse: rawJobError })
|
||||
|
||||
const appService = buildAppService(deps)
|
||||
;(appService as any).retryOptions = {
|
||||
wait: () => Promise.resolve(),
|
||||
random: () => 0
|
||||
}
|
||||
|
||||
await appService.startUpData()
|
||||
|
||||
expect(deps.sasService.request).toHaveBeenCalledTimes(1)
|
||||
expect(deps.eventService.showInfoModal).toHaveBeenCalledTimes(1)
|
||||
const [, message] = deps.eventService.showInfoModal.calls.mostRecent().args
|
||||
expect(message).toContain(rawJobError)
|
||||
expect(message).not.toContain('Globvars, Sasdatasets, Saslibs, XLMaps')
|
||||
expect(deps.licenceService.isAppActivated.value).toBeFalse()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -11,7 +11,9 @@ import { AppSettingsService } from './app-settings.service'
|
||||
import { AppThemes } from '../models/AppSettings'
|
||||
import { RequestWrapperResponse } from '../models/request-wrapper/RequestWrapperResponse'
|
||||
import { AppStoreService } from './app-store.service'
|
||||
import { StartupCheckService } from './startup-check.service'
|
||||
import { retryOnce, RetryOnceOptions } from '../shared/utils/retry-once'
|
||||
import { getMalformedAdapterResponseMessage } from '../shared/utils/get-malformed-adapter-response-message'
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
@@ -28,7 +30,8 @@ export class AppService {
|
||||
private loggerService: LoggerService,
|
||||
private appSettingsService: AppSettingsService,
|
||||
private router: Router,
|
||||
private appStoreService: AppStoreService
|
||||
private appStoreService: AppStoreService,
|
||||
private startupCheckService: StartupCheckService
|
||||
) {
|
||||
this.subscribe()
|
||||
|
||||
@@ -94,6 +97,22 @@ export class AppService {
|
||||
this.retryOptions
|
||||
)
|
||||
.then(async (res: RequestWrapperResponse) => {
|
||||
const malformedMessage = getMalformedAdapterResponseMessage(
|
||||
res.adapterResponse
|
||||
)
|
||||
if (malformedMessage) {
|
||||
startupServiceError = true
|
||||
console.error(
|
||||
'startUpData: startupservice returned malformed response:',
|
||||
malformedMessage
|
||||
)
|
||||
this.startupCheckService.updateStep(2, 'error', 'Malformed response')
|
||||
this.eventService.showInfoModal('Error', malformedMessage)
|
||||
this.licenceService.isAppActivated.next(false)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
this.syssite.next([res.adapterResponse.SYSSITE])
|
||||
|
||||
let missingProps: string[] = []
|
||||
@@ -109,6 +128,15 @@ export class AppService {
|
||||
|
||||
if (missingProps.length > 0) {
|
||||
startupServiceError = true
|
||||
console.error(
|
||||
'startUpData: startupservice missing properties:',
|
||||
missingProps.join(', ')
|
||||
)
|
||||
this.startupCheckService.updateStep(
|
||||
2,
|
||||
'error',
|
||||
`Missing: ${missingProps.join(', ')}`
|
||||
)
|
||||
this.eventService.showInfoModal(
|
||||
'Error',
|
||||
`${missingProps.join(', ')} are not present in the startupservice`
|
||||
@@ -132,6 +160,9 @@ export class AppService {
|
||||
SYSHOSTINFOLONG: res.adapterResponse.SYSHOSTINFOLONG,
|
||||
SYSENCODING: res.adapterResponse.SYSENCODING,
|
||||
AUTOEXEC: res.adapterResponse.AUTOEXEC,
|
||||
TIMEZONE: res.adapterResponse.globvars[0].TIMEZONE,
|
||||
SYSTIMEZONEIDENT: res.adapterResponse.globvars[0].SYSTIMEZONEIDENT,
|
||||
SYSTIMEZONEOFFSET: res.adapterResponse.globvars[0].SYSTIMEZONEOFFSET,
|
||||
ISADMIN: res.adapterResponse.globvars[0].ISADMIN,
|
||||
DC_ADMIN_GROUP: res.adapterResponse.globvars[0].DC_ADMIN_GROUP,
|
||||
APP_LOC: dcAdapterSettings?.appLoc
|
||||
@@ -186,6 +217,8 @@ export class AppService {
|
||||
})
|
||||
.catch((err: any) => {
|
||||
startupServiceError = true
|
||||
console.error('startUpData: startupservice request failed:', err)
|
||||
this.startupCheckService.updateStep(2, 'error', 'Request failed')
|
||||
this.eventService.showInfoModal(
|
||||
'Error',
|
||||
'There is an issue with startupservice response'
|
||||
|
||||
@@ -10,7 +10,8 @@ import { Globvar } from '../models/sas/public-startupservice.model'
|
||||
import { freeTierConfig } from '../free-tier.config'
|
||||
import { AppStoreService } from './app-store.service'
|
||||
import { HelperService } from './helper.service'
|
||||
import { LicenceFeaturesMap, LicenceState } from '../models/LicenceState'
|
||||
import { LicenceState } from '../models/LicenceState'
|
||||
import { decodeLicenceFeatures as decodeFeatures } from './utils/decodeLicenceFeatures'
|
||||
import { LoggerService } from './logger.service'
|
||||
import { EventService } from './event.service'
|
||||
|
||||
@@ -117,6 +118,13 @@ export class LicenceService {
|
||||
|
||||
let variables = globvars[0]
|
||||
|
||||
// Trim whitespace — the SAS makedata service initialises licence keys
|
||||
// as a single space, which is truthy in JS but not a valid key.
|
||||
if (variables.LICENCE_KEY)
|
||||
variables.LICENCE_KEY = variables.LICENCE_KEY.trim()
|
||||
if (variables.ACTIVATION_KEY)
|
||||
variables.ACTIVATION_KEY = variables.ACTIVATION_KEY.trim()
|
||||
|
||||
if (
|
||||
variables.LICENCE_KEY === undefined ||
|
||||
variables.ACTIVATION_KEY === undefined ||
|
||||
@@ -255,9 +263,9 @@ export class LicenceService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode and set features that are encoded in the key
|
||||
* featureValue - used as number/Infinity for limit set
|
||||
* featureToggle - used as boolean, based on 1 or 0 encoded in the key
|
||||
* Decode and set features that are encoded in the key - accepts either
|
||||
* an already-issued key's legacy positional string or a newly-issued
|
||||
* key's named object, see decodeLicenceFeatures for the format contract.
|
||||
* @param licenseData from the licence key
|
||||
*/
|
||||
private decodeLicenceFeatures(licenseData: LicenseKeyData) {
|
||||
@@ -270,72 +278,21 @@ export class LicenceService {
|
||||
}
|
||||
}
|
||||
|
||||
const featuresMap = licenseData.features.split(',')
|
||||
this._licenceState = {
|
||||
...this._licenceState,
|
||||
viewer_rows_allowed: this.parseFeatureValue(
|
||||
featuresMap[LicenceFeaturesMap.viewer_rows_allowed]
|
||||
),
|
||||
editor_rows_allowed: this.parseFeatureValue(
|
||||
featuresMap[LicenceFeaturesMap.editor_rows_allowed]
|
||||
),
|
||||
stage_rows_allowed: this.parseFeatureValue(
|
||||
featuresMap[LicenceFeaturesMap.stage_rows_allowed]
|
||||
),
|
||||
history_rows_allowed: this.parseFeatureValue(
|
||||
featuresMap[LicenceFeaturesMap.history_rows_allowed]
|
||||
),
|
||||
submit_rows_limit: this.parseFeatureValue(
|
||||
featuresMap[LicenceFeaturesMap.submit_rows_limit]
|
||||
),
|
||||
tables_in_library_limit: this.parseFeatureValue(
|
||||
featuresMap[LicenceFeaturesMap.tables_in_library_limit]
|
||||
),
|
||||
viewbox_limit: this.parseFeatureValue(
|
||||
featuresMap[LicenceFeaturesMap.viewbox_limit]
|
||||
),
|
||||
lineage_daily_limit: this.parseFeatureValue(
|
||||
featuresMap[LicenceFeaturesMap.lineage_daily_limit]
|
||||
),
|
||||
viewbox: this.parseFeatureToggle(featuresMap[LicenceFeaturesMap.viewbox]),
|
||||
fileUpload: this.parseFeatureToggle(
|
||||
featuresMap[LicenceFeaturesMap.fileUpload]
|
||||
),
|
||||
editRecord: this.parseFeatureToggle(
|
||||
featuresMap[LicenceFeaturesMap.editRecord]
|
||||
),
|
||||
addRecord: this.parseFeatureToggle(
|
||||
featuresMap[LicenceFeaturesMap.addRecord]
|
||||
)
|
||||
...decodeFeatures(licenseData.features)
|
||||
}
|
||||
|
||||
this.loggerService.log('Licence state:', this._licenceState)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts licence key feature code value to the number or Infinity
|
||||
* Used for limiting rows, submits etc.
|
||||
* @param codeBit from licence key encoded features. Every bit is separated by comma(,) Eg. 5,10,15
|
||||
* @returns number
|
||||
*/
|
||||
private parseFeatureValue(codeBit: string): number {
|
||||
if (codeBit === '-') return Infinity
|
||||
return parseInt(codeBit)
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts licence key feature code value to the boolean. Depending on if it's 0 or 1
|
||||
* @param codeBit from licence key encoded features. Every bit is separated by comma(,) Eg. 1,1,0
|
||||
* @returns boolean to turn on or off the value
|
||||
*/
|
||||
private parseFeatureToggle(codeBit: string): boolean {
|
||||
return !!parseInt(codeBit)
|
||||
}
|
||||
|
||||
/**
|
||||
* If decryption fails, key will be marked as invalid and app not activated.
|
||||
* Public (not just used internally by licensing()) since it's a pure
|
||||
* decrypt with no side effects - also used to preview a pasted key's
|
||||
* details before it's actually applied.
|
||||
*/
|
||||
private decryptLicenseKey(
|
||||
public decryptLicenseKey(
|
||||
licenseKey: string,
|
||||
activationKey: string
|
||||
): Promise<LicenseKeyData> {
|
||||
|
||||
@@ -35,6 +35,13 @@ export class SasStoreService {
|
||||
public setSubmit: Subject<any> = new Subject<any>()
|
||||
public setSubmitList: Subject<any> = new Subject<any>()
|
||||
|
||||
/**
|
||||
* Submit queue payload carried across the navigation from the submit
|
||||
* list to a details URL - the re-created list component renders it
|
||||
* without fetching the queue again.
|
||||
*/
|
||||
private submitsHandoff: Array<any> | null = null
|
||||
|
||||
constructor(
|
||||
private sasService: SasService,
|
||||
private helperService: HelperService,
|
||||
@@ -155,6 +162,24 @@ export class SasStoreService {
|
||||
.adapterResponse
|
||||
}
|
||||
|
||||
/**
|
||||
* Carries the fetched submit queue over to the details URL navigation,
|
||||
* so the re-created submit list component does not fetch it again.
|
||||
*/
|
||||
public handoffSubmits(fromsas: Array<any> | undefined) {
|
||||
this.submitsHandoff = fromsas || null
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the submit queue carried by the current navigation, if any,
|
||||
* and clears it - it is only valid for the navigation that set it.
|
||||
*/
|
||||
public takeSubmitsHandoff(): Array<any> | null {
|
||||
const fromsas = this.submitsHandoff
|
||||
this.submitsHandoff = null
|
||||
return fromsas
|
||||
}
|
||||
|
||||
private libsPromise: Promise<any> | null = null
|
||||
|
||||
/**
|
||||
|
||||
@@ -150,9 +150,12 @@ export class SasViyaService {
|
||||
)
|
||||
}
|
||||
|
||||
getFolderMembers(folderId: string): Observable<ViyaApiFolderMembers> {
|
||||
getFolderMembers(
|
||||
folderId: string,
|
||||
limit: number = 500
|
||||
): Observable<ViyaApiFolderMembers> {
|
||||
return this.get<ViyaApiFolderMembers>(
|
||||
`${this.serverUrl}/folders/folders/${folderId}/members`,
|
||||
`${this.serverUrl}/folders/folders/${folderId}/members?limit=${limit}`,
|
||||
{
|
||||
withCredentials: true
|
||||
}
|
||||
@@ -168,6 +171,20 @@ export class SasViyaService {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns The groups the current user is a member of
|
||||
*/
|
||||
getCurrentUserGroupMemberships(
|
||||
limit: number = 10000
|
||||
): Observable<ViyaApiIdentities> {
|
||||
return this.get<ViyaApiIdentities>(
|
||||
`${this.serverUrl}/identities/users/@currentUser/memberships?limit=${limit}`,
|
||||
{
|
||||
withCredentials: true
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
getCurrentUser(): Observable<ViyaApiCurrentUser> {
|
||||
return this.get<ViyaApiCurrentUser>(
|
||||
`${this.serverUrl}/identities/users/@currentUser`,
|
||||
|
||||
@@ -3,6 +3,7 @@ import { Injectable, EventEmitter } from '@angular/core'
|
||||
import SASjs, { UploadFile } from '@sasjs/adapter'
|
||||
import { BehaviorSubject } from 'rxjs'
|
||||
import { UserService } from '../shared/user.service'
|
||||
import { StartupCheckService } from './startup-check.service'
|
||||
|
||||
import { Router } from '@angular/router'
|
||||
import { EventService } from './event.service'
|
||||
@@ -43,6 +44,7 @@ export class SasService {
|
||||
private sasjsService: SasjsService,
|
||||
private sasViyaService: SasViyaService,
|
||||
private loggerService: LoggerService,
|
||||
private startupCheckService: StartupCheckService,
|
||||
private router: Router
|
||||
) {}
|
||||
|
||||
@@ -195,7 +197,8 @@ export class SasService {
|
||||
{
|
||||
SYSWARNINGTEXT: abortRes.SYSWARNINGTEXT,
|
||||
SYSERRORTEXT: abortRes.SYSERRORTEXT,
|
||||
MAC: macMsg
|
||||
MAC: macMsg,
|
||||
_PROGRAM: abortRes._PROGRAM
|
||||
}
|
||||
)
|
||||
}
|
||||
@@ -355,7 +358,10 @@ export class SasService {
|
||||
|
||||
this.sasjsService.getFolderContentsFromDrive(configuratorFolder).subscribe(
|
||||
(contents: SASjsApiDriveFolderContents) => {
|
||||
if (contents.files.includes('makedata.sas')) {
|
||||
if (
|
||||
contents.files.includes('makedata.sas') ||
|
||||
contents.files.includes('makedata.js')
|
||||
) {
|
||||
this.eventService.startupDataLoaded()
|
||||
this.router.navigateByUrl('/deploy')
|
||||
} else {
|
||||
@@ -417,7 +423,10 @@ export class SasService {
|
||||
.getFolderContentsFromDrive(configuratorFolder)
|
||||
.subscribe(
|
||||
(contents: SASjsApiDriveFolderContents) => {
|
||||
if (!contents.files.includes('makedata.sas')) {
|
||||
if (
|
||||
!contents.files.includes('makedata.sas') &&
|
||||
!contents.files.includes('makedata.js')
|
||||
) {
|
||||
resolve(true)
|
||||
} else {
|
||||
resolve(false)
|
||||
@@ -437,6 +446,9 @@ export class SasService {
|
||||
}
|
||||
|
||||
public async checkViyaDeploy(path: string) {
|
||||
console.log('checkViyaDeploy: checking appLoc', path)
|
||||
this.startupCheckService.updateStep(0, 'in_progress')
|
||||
|
||||
const getFolderExistsInAdapter =
|
||||
typeof this.sasjsAdapter.getFolder !== 'undefined'
|
||||
|
||||
@@ -452,25 +464,58 @@ export class SasService {
|
||||
appLocExists = await this.appLocCheckPreAxiosdAdapter(path)
|
||||
}
|
||||
|
||||
console.log(
|
||||
'checkViyaDeploy: appLoc exists?',
|
||||
appLocExists,
|
||||
'error?',
|
||||
errorMessage
|
||||
)
|
||||
|
||||
if (appLocExists) {
|
||||
this.startupCheckService.updateStep(0, 'done', path)
|
||||
|
||||
// Check if there is appLoc/services/admin/makedata.sas present
|
||||
// if yes, it needs to be run, so we redirect to /deploy
|
||||
// if not, we load the startup service
|
||||
|
||||
this.startupCheckService.updateStep(1, 'in_progress')
|
||||
this.viyaMakedataSuccessfull().then(
|
||||
(success: boolean) => {
|
||||
console.log(
|
||||
'checkViyaDeploy: makedata job already run?',
|
||||
success,
|
||||
success
|
||||
? '-> loading startupservice'
|
||||
: '-> redirecting to /deploy (setup screen)'
|
||||
)
|
||||
if (success) {
|
||||
this.startupCheckService.updateStep(1, 'done', 'makedata complete')
|
||||
this.startupCheckService.updateStep(2, 'in_progress')
|
||||
this.loadStartupServiceEmitter.emit()
|
||||
} else {
|
||||
this.startupCheckService.updateStep(
|
||||
1,
|
||||
'done',
|
||||
'makedata job found - setup needed'
|
||||
)
|
||||
this.eventService.startupDataLoaded()
|
||||
this.router.navigateByUrl('/deploy')
|
||||
}
|
||||
},
|
||||
(error: any) => {
|
||||
console.error('Error while looking for the file: makedata.sas', error)
|
||||
console.error(
|
||||
'checkViyaDeploy: error while looking for makedata job',
|
||||
error
|
||||
)
|
||||
this.startupCheckService.updateStep(1, 'error', String(error))
|
||||
}
|
||||
)
|
||||
} else {
|
||||
this.startupCheckService.updateStep(
|
||||
0,
|
||||
'error',
|
||||
errorMessage || 'not found'
|
||||
)
|
||||
const errorMessageToShow =
|
||||
(errorMessage ||
|
||||
'Viya services are not present on the current appLoc, or API not reachable. Check the ADAPTER configuration.') +
|
||||
@@ -480,43 +525,71 @@ export class SasService {
|
||||
}
|
||||
}
|
||||
|
||||
private async viyaMakedataSuccessfull(): Promise<boolean> {
|
||||
public async viyaMakedataSuccessfull(): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const sasjsConfig = this.getSasjsConfig()
|
||||
const configuratorFolder = `${sasjsConfig.appLoc}/services/admin`
|
||||
|
||||
console.log(
|
||||
'viyaMakedataSuccessfull: checking folder',
|
||||
configuratorFolder
|
||||
)
|
||||
|
||||
this.sasViyaService.getFolderByPath(configuratorFolder).subscribe(
|
||||
(folderInfo: ViyaApiFolder) => {
|
||||
const folderId = folderInfo.id
|
||||
|
||||
if (!folderId) {
|
||||
console.error(
|
||||
`Folder ID is not present. ${configuratorFolder}`,
|
||||
`viyaMakedataSuccessfull: folder ID not present for ${configuratorFolder}`,
|
||||
sasjsConfig
|
||||
)
|
||||
resolve(false)
|
||||
return
|
||||
}
|
||||
|
||||
this.sasViyaService.getFolderMembers(folderId).subscribe(
|
||||
(members: ViyaApiFolderMembers) => {
|
||||
if (
|
||||
!members.items.some((item: any) => item.name === 'makedata')
|
||||
) {
|
||||
// Makedata.sas is not present, which means it was run
|
||||
const memberNames = members.items.map((item: any) => item.name)
|
||||
const hasMakedata = members.items.some(
|
||||
(item: any) => item.name === 'makedata'
|
||||
)
|
||||
|
||||
console.log(
|
||||
'viyaMakedataSuccessfull: folder members:',
|
||||
memberNames.join(', ') || '(none)'
|
||||
)
|
||||
console.log(
|
||||
'viyaMakedataSuccessfull: makedata job present?',
|
||||
hasMakedata,
|
||||
hasMakedata
|
||||
? '-> setup needed (redirect to /deploy)'
|
||||
: '-> setup already done (load startupservice)'
|
||||
)
|
||||
|
||||
if (!hasMakedata) {
|
||||
resolve(true)
|
||||
} else {
|
||||
// Makedata.sas is present, which means it was not run
|
||||
resolve(false)
|
||||
}
|
||||
},
|
||||
(err: any) => {
|
||||
console.error('Error getting folder contents', err)
|
||||
reject()
|
||||
console.error(
|
||||
'viyaMakedataSuccessfull: error getting folder members for',
|
||||
configuratorFolder,
|
||||
err
|
||||
)
|
||||
// On error, assume setup is needed rather than skipping it
|
||||
resolve(false)
|
||||
}
|
||||
)
|
||||
},
|
||||
(err: any) => {
|
||||
console.warn('Error getting folder info', err)
|
||||
console.warn(
|
||||
'viyaMakedataSuccessfull: error getting folder info for',
|
||||
configuratorFolder,
|
||||
err
|
||||
)
|
||||
reject(err)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import { BehaviorSubject } from 'rxjs'
|
||||
|
||||
export type StartupStepStatus = 'pending' | 'in_progress' | 'done' | 'error'
|
||||
|
||||
export interface StartupStep {
|
||||
label: string
|
||||
status: StartupStepStatus
|
||||
detail?: string
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class StartupCheckService {
|
||||
private steps: StartupStep[] = [
|
||||
{ label: 'Checking app location', status: 'pending' },
|
||||
{ label: 'Checking Viya deploy', status: 'pending' },
|
||||
{ label: 'Loading startup service', status: 'pending' }
|
||||
]
|
||||
|
||||
public steps$ = new BehaviorSubject<StartupStep[]>([...this.steps])
|
||||
|
||||
public updateStep(index: number, status: StartupStepStatus, detail?: string) {
|
||||
if (index >= 0 && index < this.steps.length) {
|
||||
this.steps[index] = {
|
||||
...this.steps[index],
|
||||
status,
|
||||
detail: detail ?? this.steps[index].detail
|
||||
}
|
||||
this.steps$.next([...this.steps])
|
||||
}
|
||||
}
|
||||
|
||||
public setSteps(steps: StartupStep[]) {
|
||||
this.steps = steps
|
||||
this.steps$.next([...this.steps])
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
import { decodeLicenceFeatures } from './decodeLicenceFeatures'
|
||||
|
||||
describe('decodeLicenceFeatures', () => {
|
||||
// Positional order per LicenceFeaturesMap: viewer_rows_allowed,
|
||||
// editor_rows_allowed, stage_rows_allowed, history_rows_allowed,
|
||||
// submit_rows_limit, tables_in_library_limit, viewbox, viewbox_limit,
|
||||
// lineage_daily_limit, fileUpload, editRecord, addRecord.
|
||||
const legacyFeaturesString = '10,15,20,-,5,35,1,3,7,1,0,1'
|
||||
|
||||
const newFeaturesObject = {
|
||||
vra: 10,
|
||||
era: 15,
|
||||
sra: 20,
|
||||
hra: null,
|
||||
srl: 5,
|
||||
till: 35,
|
||||
vb: true,
|
||||
vbl: 3,
|
||||
ldl: 7,
|
||||
fu: true,
|
||||
er: false,
|
||||
ar: true
|
||||
}
|
||||
|
||||
const expectedDecodedState = {
|
||||
viewer_rows_allowed: 10,
|
||||
editor_rows_allowed: 15,
|
||||
stage_rows_allowed: 20,
|
||||
history_rows_allowed: Infinity,
|
||||
submit_rows_limit: 5,
|
||||
tables_in_library_limit: 35,
|
||||
viewbox: true,
|
||||
viewbox_limit: 3,
|
||||
lineage_daily_limit: 7,
|
||||
fileUpload: true,
|
||||
editRecord: false,
|
||||
addRecord: true
|
||||
}
|
||||
|
||||
it('decodes a legacy positional string exactly as before', () => {
|
||||
expect(decodeLicenceFeatures(legacyFeaturesString)).toEqual(
|
||||
expectedDecodedState
|
||||
)
|
||||
})
|
||||
|
||||
it('decodes a new named object', () => {
|
||||
expect(decodeLicenceFeatures(newFeaturesObject)).toEqual(
|
||||
expectedDecodedState
|
||||
)
|
||||
})
|
||||
|
||||
it('produces an identical result for the same licence expressed in either format', () => {
|
||||
expect(decodeLicenceFeatures(legacyFeaturesString)).toEqual(
|
||||
decodeLicenceFeatures(newFeaturesObject)
|
||||
)
|
||||
})
|
||||
|
||||
it('maps "-" in a legacy limit position to Infinity', () => {
|
||||
const result = decodeLicenceFeatures(legacyFeaturesString)
|
||||
expect(result.history_rows_allowed).toBe(Infinity)
|
||||
})
|
||||
|
||||
it('maps null in a new-format limit field to Infinity', () => {
|
||||
const result = decodeLicenceFeatures(newFeaturesObject)
|
||||
expect(result.history_rows_allowed).toBe(Infinity)
|
||||
})
|
||||
|
||||
it('maps "1"/"0" in legacy toggle positions to true/false', () => {
|
||||
const result = decodeLicenceFeatures(legacyFeaturesString)
|
||||
expect(result.viewbox).toBe(true)
|
||||
expect(result.editRecord).toBe(false)
|
||||
})
|
||||
|
||||
it('passes new-format boolean toggle fields straight through', () => {
|
||||
const result = decodeLicenceFeatures(newFeaturesObject)
|
||||
expect(result.viewbox).toBe(true)
|
||||
expect(result.editRecord).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,91 @@
|
||||
import { LicenceFeaturesMap, LicenceState } from '../../models/LicenceState'
|
||||
|
||||
// Field names are abbreviated on the wire to keep the RSA-OAEP-encrypted
|
||||
// payload small - see "Why abbreviated field names" in
|
||||
// licence-features-object-plan.md for the full name each one stands for
|
||||
// and why this is a fixed, append-only contract (same invariant as
|
||||
// LicenceFeaturesMap's ordinals).
|
||||
export type LicenceFeaturesObject = {
|
||||
vra: number | null // viewer_rows_allowed
|
||||
era: number | null // editor_rows_allowed
|
||||
sra: number | null // stage_rows_allowed
|
||||
hra: number | null // history_rows_allowed
|
||||
srl: number | null // submit_rows_limit
|
||||
till: number | null // tables_in_library_limit
|
||||
vb: boolean // viewbox
|
||||
vbl: number | null // viewbox_limit
|
||||
ldl: number | null // lineage_daily_limit
|
||||
fu: boolean // fileUpload
|
||||
er: boolean // editRecord
|
||||
ar: boolean // addRecord
|
||||
}
|
||||
|
||||
// Accepts either an already-issued key's positional string
|
||||
// ("-,-,-,-,-,-,1,-,-,1,1,1", decoded via LicenceFeaturesMap) or a
|
||||
// newly-issued key's named object - see licence-features-object-plan.md
|
||||
// for why these two shapes are how format versioning is done here (no
|
||||
// separate version field: the shapes are already distinguishable).
|
||||
export const decodeLicenceFeatures = (
|
||||
features: string | LicenceFeaturesObject
|
||||
): Partial<LicenceState> => {
|
||||
if (typeof features === 'object') {
|
||||
return decodeFeaturesObject(features)
|
||||
}
|
||||
|
||||
return decodeFeaturesString(features)
|
||||
}
|
||||
|
||||
const decodeFeaturesObject = (
|
||||
features: LicenceFeaturesObject
|
||||
): Partial<LicenceState> => ({
|
||||
viewer_rows_allowed: features.vra ?? Infinity,
|
||||
editor_rows_allowed: features.era ?? Infinity,
|
||||
stage_rows_allowed: features.sra ?? Infinity,
|
||||
history_rows_allowed: features.hra ?? Infinity,
|
||||
submit_rows_limit: features.srl ?? Infinity,
|
||||
tables_in_library_limit: features.till ?? Infinity,
|
||||
viewbox: features.vb,
|
||||
viewbox_limit: features.vbl ?? Infinity,
|
||||
lineage_daily_limit: features.ldl ?? Infinity,
|
||||
fileUpload: features.fu,
|
||||
editRecord: features.er,
|
||||
addRecord: features.ar
|
||||
})
|
||||
|
||||
// Existing positional-string decode, moved here unchanged from
|
||||
// LicenceService.decodeLicenceFeatures/parseFeatureValue/parseFeatureToggle.
|
||||
const decodeFeaturesString = (features: string): Partial<LicenceState> => {
|
||||
const featuresMap = features.split(',')
|
||||
const parseValue = (codeBit: string) =>
|
||||
codeBit === '-' ? Infinity : parseInt(codeBit)
|
||||
const parseToggle = (codeBit: string) => !!parseInt(codeBit)
|
||||
|
||||
return {
|
||||
viewer_rows_allowed: parseValue(
|
||||
featuresMap[LicenceFeaturesMap.viewer_rows_allowed]
|
||||
),
|
||||
editor_rows_allowed: parseValue(
|
||||
featuresMap[LicenceFeaturesMap.editor_rows_allowed]
|
||||
),
|
||||
stage_rows_allowed: parseValue(
|
||||
featuresMap[LicenceFeaturesMap.stage_rows_allowed]
|
||||
),
|
||||
history_rows_allowed: parseValue(
|
||||
featuresMap[LicenceFeaturesMap.history_rows_allowed]
|
||||
),
|
||||
submit_rows_limit: parseValue(
|
||||
featuresMap[LicenceFeaturesMap.submit_rows_limit]
|
||||
),
|
||||
tables_in_library_limit: parseValue(
|
||||
featuresMap[LicenceFeaturesMap.tables_in_library_limit]
|
||||
),
|
||||
viewbox_limit: parseValue(featuresMap[LicenceFeaturesMap.viewbox_limit]),
|
||||
lineage_daily_limit: parseValue(
|
||||
featuresMap[LicenceFeaturesMap.lineage_daily_limit]
|
||||
),
|
||||
viewbox: parseToggle(featuresMap[LicenceFeaturesMap.viewbox]),
|
||||
fileUpload: parseToggle(featuresMap[LicenceFeaturesMap.fileUpload]),
|
||||
editRecord: parseToggle(featuresMap[LicenceFeaturesMap.editRecord]),
|
||||
addRecord: parseToggle(featuresMap[LicenceFeaturesMap.addRecord])
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@
|
||||
</p>
|
||||
<p><strong>SYSERRORTEXT:</strong> {{ data.details.SYSERRORTEXT }}</p>
|
||||
<p><strong>MAC:</strong> {{ data.details.MAC }}</p>
|
||||
<p><strong>_PROGRAM:</strong> {{ data.details._PROGRAM }}</p>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
|
||||
@@ -19,6 +19,7 @@ import { getNotNullDefault } from './utils/getNotNullDefault'
|
||||
import { mergeColsRules } from './utils/mergeColsRules'
|
||||
import { parseColTypeRow } from './utils/parseColTypeRow'
|
||||
import { DELETE_RECORD_COLUMN_RULE } from './utils/deleteRecordColumnRule'
|
||||
import { EDIT_STATUS_COLUMN_RULE } from './utils/editStatusColumnRule'
|
||||
import { dqValidate } from './validations/dq-validation'
|
||||
import {
|
||||
datetimeValidator,
|
||||
@@ -84,6 +85,13 @@ export class DcValidator {
|
||||
this.rules = mergeColsRules(cols, this.rules, $dataFormats)
|
||||
this.rules = applyNumericFormats(this.rules)
|
||||
this.rules = mapIntlCellTypes(this.rules)
|
||||
|
||||
// EDIT_STATUS is appended last, always hidden - it's a purely
|
||||
// client-synthesized column (never in COLHEADERS) that gives
|
||||
// DC.ROW_STATUS a real cell to reference. See its own doc comment.
|
||||
this.rules.push({ ...EDIT_STATUS_COLUMN_RULE })
|
||||
this.hiddenColumns.push(this.rules.length - 1)
|
||||
|
||||
this.dqrules = dqRules
|
||||
this.dqdata = dqData
|
||||
this.primaryKeys = sasparams.PK.split(' ')
|
||||
@@ -229,6 +237,25 @@ export class DcValidator {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the RULE_VALUE of a HARDFORMULA/SOFTFORMULA rule on the given
|
||||
* column, for display in the column-header info dropdown. A column only
|
||||
* ever carries one of the two in practice (readonly-computed vs.
|
||||
* overridable-default aren't a meaningful combination), so unlike
|
||||
* getRegexRuleValues there's no need to distinguish which one this is.
|
||||
*
|
||||
* @param col column name
|
||||
*/
|
||||
getFormulaRuleValue(col: string): string | undefined {
|
||||
const formulaRule = this.dqrules.find(
|
||||
(rule: DQRule) =>
|
||||
rule.BASE_COL === col &&
|
||||
(rule.RULE_TYPE === 'HARDFORMULA' || rule.RULE_TYPE === 'SOFTFORMULA')
|
||||
)
|
||||
|
||||
return formulaRule?.RULE_VALUE
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves dropdown source for given dc validation rule
|
||||
* The values comes from MPE_SELECTBOX table
|
||||
@@ -439,6 +466,14 @@ export class DcValidator {
|
||||
this.rules[i].readOnly = true
|
||||
}
|
||||
|
||||
// HARDFORMULA: same read-only treatment as an explicit READONLY rule
|
||||
// - its value is always computed (see applyFormulaRules), never
|
||||
// user-editable. SOFTFORMULA deliberately does not set this: its
|
||||
// computed value is only a default, the user can overwrite it.
|
||||
if (this.hasDqRules(ruleColName, ['HARDFORMULA'])) {
|
||||
this.rules[i].readOnly = true
|
||||
}
|
||||
|
||||
// HIDDEN: hide column in HOT but keep its data (still submitted via hot.getData())
|
||||
if (this.hasDqRules(ruleColName, ['HIDDEN'])) {
|
||||
this.hiddenColumns.push(i)
|
||||
|
||||
@@ -20,3 +20,5 @@ export type DQRuleTypes =
|
||||
| 'NUMBER_FORMAT'
|
||||
| 'HARDREGEX'
|
||||
| 'SOFTREGEX'
|
||||
| 'HARDFORMULA'
|
||||
| 'SOFTFORMULA'
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user