@syncmatters/script-api 1.0.24 → 1.0.26

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/api.d.ts CHANGED
@@ -11,6 +11,8 @@ export * from "./lib/sync-group.js";
11
11
  export * from "./lib/utilities/kv-store/types.js";
12
12
  export * from "./lib/utilities/rate-limiter/rate-limiter.js";
13
13
  export type { HttpClient, HttpClientOptions, HttpFullResponse, HttpRequest, } from "./lib/utilities/http-client/types.js";
14
+ export { Redactor, defaultRedactKeys } from "./lib/utilities/redact/redact.js";
15
+ export type { RedactorOptions } from "./lib/utilities/redact/redact.js";
14
16
  export type JsonValuesReader = InstanceType<typeof JVR>;
15
17
  export type JsonValuesWriter = InstanceType<typeof JVW.JsonValuesWriter>;
16
18
  export type WriteBehaviour = JVW.WriteBehaviour;
@@ -1,3 +1,4 @@
1
+ import type { RedactorOptions } from "../redact/redact.js";
1
2
  import type { Buffer } from "node:buffer";
2
3
  import { RateLimiter } from "../rate-limiter/rate-limiter.js";
3
4
  export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
@@ -61,6 +62,12 @@ export interface HttpClientOptions {
61
62
  retryBackoffMs?: number;
62
63
  ca?: Buffer;
63
64
  errMessageFormat?: "default" | "concise";
65
+ /**
66
+ * Keys whose values are replaced with "***" in thrown error messages. `url` applies to query
67
+ * parameters, `body` to request/response bodies and error text. Omit a set to keep its default
68
+ * (see `defaultRedactKeys`); an array replaces that default rather than extending it.
69
+ */
70
+ redactKeys?: RedactorOptions;
64
71
  canRetry?: HttpCanRetry;
65
72
  onError?: (err: HttpError, method: HttpMethod, url: string, httpCode: number, reqJson?: unknown) => void;
66
73
  }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Keys redacted by default, split by where the value appears.
3
+ *
4
+ * - `url`: query-string parameters (what the HTTP client strips from the URL of a failed request).
5
+ * - `body`: request/response bodies and error text (JSON properties, XML elements, form pairs).
6
+ *
7
+ * A key matches case-insensitively and ignores `_` and `-`, so `api_key`, `apiKey`, `api-key` and
8
+ * `APIKEY` are all the same key. Matching is otherwise exact: `token` does not match `page_token`.
9
+ */
10
+ export declare const defaultRedactKeys: {
11
+ readonly url: readonly string[];
12
+ readonly body: readonly string[];
13
+ };
14
+ export interface RedactorOptions {
15
+ /**
16
+ * Query-string keys whose values are replaced with "***" by `redactUrl`. When omitted,
17
+ * `defaultRedactKeys.url` is used. An array replaces that default; it is not merged with it.
18
+ * An empty array turns URL redaction off.
19
+ */
20
+ url?: readonly string[];
21
+ /**
22
+ * Property/element keys whose values are replaced with "***" by `redactJSON` and `redactText`.
23
+ * When omitted, `defaultRedactKeys.body` is used. An array replaces that default; it is not
24
+ * merged with it. An empty array turns body redaction off.
25
+ */
26
+ body?: readonly string[];
27
+ }
28
+ /**
29
+ * Replaces values of sensitive keys so a URL, JSON value, or error text can stay in a log.
30
+ * Empty strings and null are left as they are, so a missing secret is still visible.
31
+ *
32
+ * `redactUrl` uses the `url` key set. `redactJSON` and the JSON/XML passes of `redactText` use the
33
+ * `body` key set. The `?`/`&` form-pair pass of `redactText` checks both sets, because error text
34
+ * can contain a URL as well as a form-encoded body.
35
+ */
36
+ export declare class Redactor {
37
+ #private;
38
+ constructor(options?: RedactorOptions);
39
+ /**
40
+ * Replaces sensitive query-parameter values using the `url` key set. Repeated parameters and
41
+ * their order are preserved. An unparseable URL is returned unchanged.
42
+ */
43
+ redactUrl(url: string): string;
44
+ /**
45
+ * Returns a copy with the values of sensitive keys (the `body` key set) replaced. The input is
46
+ * not modified. Arrays, plain objects and class instances are copied (a class instance becomes a
47
+ * plain object of its own enumerable properties, as JSON.stringify would see it). Built-in value
48
+ * types such as Date, RegExp, Map, Set and Buffer are returned by reference.
49
+ */
50
+ redactJSON<T>(value: T): T;
51
+ /**
52
+ * Redacts a string using the `body` key set. A JSON object or array is parsed and rewritten. Any
53
+ * other text keeps its shape: JSON properties, XML elements, and `?`/`&` form pairs for a
54
+ * sensitive key are replaced in place.
55
+ */
56
+ redactText(text: string): string;
57
+ }
@@ -1,3 +1,4 @@
1
+ import { Redactor, type RedactorOptions } from "./redact/redact.js";
1
2
  import { RateLimiterRolling } from "./rate-limiter/rate-limiter-rolling.js";
2
3
  import { RateLimiterConcurrent } from "./rate-limiter/rate-limiter-concurrent.js";
3
4
  import { RateLimiterOptions } from "./rate-limiter/rate-limiter.js";
@@ -12,6 +13,7 @@ import { XlsxWriter, XlsxWriterOptions } from "./xlsx-writer/xlsx-writer.js";
12
13
  import { emailCleanse } from "./www-utils/www-utils.js";
13
14
  import { emailIsPublic } from "./www-utils/www-utils.js";
14
15
  import { domainParse } from "./www-utils/www-utils.js";
16
+ import { domainCleanse, domainCompare, domainIsShared } from "./www-utils/www-utils.js";
15
17
  import { xmlParse } from "./xml-utils/xml-utils.js";
16
18
  import { nameParser } from "./name-parser/name-parser.js";
17
19
  import { tempDir, tempFile } from "./file-utils/file-utils.js";
@@ -47,6 +49,9 @@ export declare const utilities: {
47
49
  emailCleanse: typeof emailCleanse;
48
50
  emailIsPublic: typeof emailIsPublic;
49
51
  domainParse: typeof domainParse;
52
+ domainCleanse: typeof domainCleanse;
53
+ domainCompare: typeof domainCompare;
54
+ domainIsShared: typeof domainIsShared;
50
55
  fileProvider: typeof fileProvider;
51
56
  gzip: {
52
57
  compressB64: typeof gzipB64;
@@ -76,6 +81,7 @@ export declare const utilities: {
76
81
  };
77
82
  kvStore: () => KvStore;
78
83
  nameParse: typeof nameParser;
84
+ redact: (options?: RedactorOptions) => Redactor;
79
85
  rateLimiter: (options: RateLimiterOptions) => RateLimiterRolling | RateLimiterConcurrent;
80
86
  setOfStr: typeof setOfStrings;
81
87
  setOfNum: typeof setOfNumbers;
@@ -4,7 +4,46 @@ interface ParsedDomain {
4
4
  tld: string;
5
5
  tldListed: boolean;
6
6
  }
7
+ /**
8
+ * Break a hostname or URL into its domain, subdomain and public suffix (tld). The parts of an
9
+ * internationalized name are returned in the form the value was written in: unicode for "münchen.de",
10
+ * punycode for "xn--mnchen-3ya.de".
11
+ */
7
12
  export declare function domainParse(hostname: string): ParsedDomain;
13
+ /** How far domainCleanse reduces a value: to the company's registered domain, or only to the host. */
14
+ export type DomainLevel = "company_domain" | "full_host";
15
+ /**
16
+ * Reduce a hostname or URL to a lowercased domain, dropping the scheme, port and path.
17
+ * - "company_domain" (the default) also drops every subdomain, leaving the registrable domain:
18
+ * "https://www.shop.Acme.co.uk/about" becomes "acme.co.uk".
19
+ * - "full_host" keeps the host and drops only a leading "www.": "shop.acme.co.uk".
20
+ *
21
+ * An internationalized name is returned in the form it was written in ("münchen.de" stays unicode,
22
+ * "xn--mnchen-3ya.de" stays punycode). Returns undefined when the value does not parse to a domain with a
23
+ * listed public suffix (e.g. "n/a", "john.smith").
24
+ */
25
+ export declare function domainCleanse(value: string | undefined, level?: DomainLevel): string | undefined;
26
+ /**
27
+ * Compare a stored domain or website value with the domain a domain[ci] match rule is looking for.
28
+ * - "host": the stored value is at exactly that host ("https://www.acme.com/about" and "acme.com").
29
+ * - "company": the domain sought has no subdomain and the stored value is on a subdomain of it
30
+ * ("https://portal.acme.com/login" and "acme.com").
31
+ * - undefined: no match, including when the stored value is a page or subdomain on a shared host
32
+ * ("facebook.com/acme"), which never identifies a company.
33
+ *
34
+ * A connector that finds candidates by a contains search keeps the "host" candidates when there are any,
35
+ * and otherwise may keep the "company" ones. Case and the unicode or punycode form of an internationalized
36
+ * name are ignored.
37
+ */
38
+ export declare function domainCompare(storedValue: string | undefined, matchDomain: string | undefined): "host" | "company" | undefined;
39
+ /**
40
+ * Whether a hostname or URL is a shared address rather than a company's own site, so it should not be used to
41
+ * identify a company: a page or subdomain on a shared host such as a social network, site builder, directory,
42
+ * URL shortener or public email provider ("facebook.com/acme", "sites.google.com/view/acme"). The shared
43
+ * host's own address ("facebook.com", "https://www.google.com/") is not shared: it belongs to that company.
44
+ * Pass the original value, not the result of domainCleanse.
45
+ */
46
+ export declare function domainIsShared(value: string | undefined): boolean;
8
47
  export declare function emailCleanse(email: string | undefined): string | undefined;
9
48
  export declare function emailIsPublic(email: string | undefined): boolean;
10
49
  export declare function tldCheck(tld: string | undefined): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@syncmatters/script-api",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "TypeScript type definitions for the SyncMatters script API (types only - scripts execute on the SyncMatters platform)",
5
5
  "types": "./index.d.ts",
6
6
  "exports": {
@@ -28,7 +28,7 @@
28
28
  "license": "MIT",
29
29
  "author": "SyncMatters",
30
30
  "homepage": "https://syncmatters.com",
31
- "typesContentHash": "f3ff131064f3d7de6653d9bb2a7766b1ea8e918cd38aacbf0f73e6b37dfe13f8",
31
+ "typesContentHash": "e1107c36df1d90ec0e202bf189253d7c3595fd242494f829a4b30b263f4060e7",
32
32
  "dependencies": {
33
33
  "@types/node": "*"
34
34
  }