@flytedesk/app-kit 11.2.0 → 11.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,7 @@ Five subpath modules, one npm package:
11
11
  - `@flytedesk/app-kit/trace` — a Postgres-native trace/audit layer (HTTP request → job →
12
12
  DB write → logs, one queryable trace), buffered through Pub/Sub, with a scheduled
13
13
  retention/prune job.
14
+ - `@flytedesk/app-kit/csv` — RFC 4180 CSV quoting with the spreadsheet formula guard (`csvQuote`, `csvCell`, `csvLine`, `csvDocument`, `csvReadBackDocument`).
14
15
  - `@flytedesk/app-kit/rate-limit` — request rate-limiting and quota enforcement.
15
16
  - `@flytedesk/app-kit/profile` — user profile and preferences management.
16
17
  - `@flytedesk/app-kit/flags` — feature flags and A/B testing.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * CSV text, written once for every export in the app. RFC 4180 (CRLF between records, a field holding a comma, a quote or a
3
+ * line break is double-quoted, a quote inside it is doubled) plus the OWASP CSV-injection guard: a cell whose first character is
4
+ * `=`, `+`, `-`, `@`, a tab or a carriage return is a formula the moment a spreadsheet opens the file, so it gets a leading
5
+ * single quote that makes it plain text. The guard runs before the quoting, so a cell that is both a formula and holds a comma
6
+ * comes out defused and quoted.
7
+ */
8
+ /** One cell quoted as RFC 4180 asks, its text otherwise exactly as given: for a file our own code reads back, where the
9
+ * formula guard below would change the value (a phone number written `+1 555 ...` would be read as `'+1 555 ...`). */
10
+ export declare function csvQuote(value: string): string;
11
+ /** One cell, defused and quoted. */
12
+ export declare function csvCell(value: string): string;
13
+ /** One record, without its line break. */
14
+ export declare function csvLine(cells: readonly string[]): string;
15
+ /** A whole file: every record followed by CRLF, the last one included. */
16
+ export declare function csvDocument(records: readonly (readonly string[])[]): string;
17
+ /** A whole file for our own code to read back: the records and line breaks of `csvDocument`, its cells quoted by `csvQuote`
18
+ * alone so a value such as a phone number written `+1 555 ...` reaches the reader exactly as given. */
19
+ export declare function csvReadBackDocument(records: readonly (readonly string[])[]): string;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * CSV text, written once for every export in the app. RFC 4180 (CRLF between records, a field holding a comma, a quote or a
3
+ * line break is double-quoted, a quote inside it is doubled) plus the OWASP CSV-injection guard: a cell whose first character is
4
+ * `=`, `+`, `-`, `@`, a tab or a carriage return is a formula the moment a spreadsheet opens the file, so it gets a leading
5
+ * single quote that makes it plain text. The guard runs before the quoting, so a cell that is both a formula and holds a comma
6
+ * comes out defused and quoted.
7
+ */
8
+ const CSV_INJECTION_TRIGGER = /^[=+\-@\t\r]/;
9
+ const NEEDS_QUOTING = /[",\r\n]/;
10
+ /** One cell quoted as RFC 4180 asks, its text otherwise exactly as given: for a file our own code reads back, where the
11
+ * formula guard below would change the value (a phone number written `+1 555 ...` would be read as `'+1 555 ...`). */
12
+ export function csvQuote(value) {
13
+ if (!NEEDS_QUOTING.test(value))
14
+ return value;
15
+ return `"${value.replace(/"/g, '""')}"`;
16
+ }
17
+ /** One cell, defused and quoted. */
18
+ export function csvCell(value) {
19
+ return csvQuote(CSV_INJECTION_TRIGGER.test(value) ? `'${value}` : value);
20
+ }
21
+ /** One record, without its line break. */
22
+ export function csvLine(cells) {
23
+ return cells.map(csvCell).join(",");
24
+ }
25
+ /** A whole file from its rendered lines: every one followed by CRLF, the last one included. */
26
+ const csvLines = (lines) => lines.map((line) => `${line}\r\n`).join("");
27
+ /** A whole file: every record followed by CRLF, the last one included. */
28
+ export function csvDocument(records) {
29
+ return csvLines(records.map(csvLine));
30
+ }
31
+ /** A whole file for our own code to read back: the records and line breaks of `csvDocument`, its cells quoted by `csvQuote`
32
+ * alone so a value such as a phone number written `+1 555 ...` reaches the reader exactly as given. */
33
+ export function csvReadBackDocument(records) {
34
+ return csvLines(records.map((record) => record.map(csvQuote).join(",")));
35
+ }
36
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/csv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E,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flytedesk/app-kit",
3
- "version": "11.2.0",
3
+ "version": "11.3.0",
4
4
  "description": "Shared platform kit for flytedesk apps: flytedesk-id auth (BFF/OIDC client) and a Postgres-native trace/audit layer.",
5
5
  "type": "module",
6
6
  "license": "UNLICENSED",
@@ -67,6 +67,10 @@
67
67
  "types": "./dist/bigquery/index.d.ts",
68
68
  "import": "./dist/bigquery/index.js"
69
69
  },
70
+ "./csv": {
71
+ "types": "./dist/csv/index.d.ts",
72
+ "import": "./dist/csv/index.js"
73
+ },
70
74
  "./rate-limit": {
71
75
  "types": "./dist/rate-limit/index.d.ts",
72
76
  "import": "./dist/rate-limit/index.js"