@graphql-markdown/telemetry 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +135 -2
- package/dist/ci.d.ts +7 -0
- package/dist/ci.d.ts.map +1 -0
- package/dist/ci.js +43 -0
- package/dist/config-dir.d.ts +9 -0
- package/dist/config-dir.d.ts.map +1 -0
- package/dist/config-dir.js +29 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +17 -0
- package/dist/disclaimer.d.ts +17 -0
- package/dist/disclaimer.d.ts.map +1 -0
- package/dist/disclaimer.js +49 -0
- package/dist/enabled.d.ts +23 -0
- package/dist/enabled.d.ts.map +1 -0
- package/dist/enabled.js +48 -0
- package/dist/error-type.d.ts +13 -0
- package/dist/error-type.d.ts.map +1 -0
- package/dist/error-type.js +47 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/loader.d.ts +6 -0
- package/dist/loader.d.ts.map +1 -0
- package/dist/loader.js +79 -0
- package/dist/payload.d.ts +25 -0
- package/dist/payload.d.ts.map +1 -0
- package/dist/payload.js +133 -0
- package/dist/sanitize.d.ts +41 -0
- package/dist/sanitize.d.ts.map +1 -0
- package/dist/sanitize.js +276 -0
- package/dist/schema.d.ts +36 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +122 -0
- package/dist/state.d.ts +22 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +77 -0
- package/dist/track.d.ts +19 -0
- package/dist/track.d.ts.map +1 -0
- package/dist/track.js +83 -0
- package/package.json +87 -4
package/dist/loader.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maskPointer = exports.classifyPointer = void 0;
|
|
4
|
+
const classifyScheme = (p) => {
|
|
5
|
+
if (/^https?:\/\//i.test(p)) {
|
|
6
|
+
return "url";
|
|
7
|
+
}
|
|
8
|
+
if (/^github:/i.test(p)) {
|
|
9
|
+
return "github";
|
|
10
|
+
}
|
|
11
|
+
if (/^git:/i.test(p)) {
|
|
12
|
+
return "git";
|
|
13
|
+
}
|
|
14
|
+
return undefined;
|
|
15
|
+
};
|
|
16
|
+
const isInlineSdl = (p) => {
|
|
17
|
+
return (/\b(type|schema|interface|enum|input|union|scalar|extend|directive)\b[^\n]*[{@]/.test(p) && /\s/.test(p));
|
|
18
|
+
};
|
|
19
|
+
const classifyPath = (p) => {
|
|
20
|
+
if (/[*?{}[\]!]/.test(p)) {
|
|
21
|
+
return "glob";
|
|
22
|
+
}
|
|
23
|
+
if (/\.json$/i.test(p)) {
|
|
24
|
+
return "file-json";
|
|
25
|
+
}
|
|
26
|
+
if (/\.(graphqls?|gql|sdl)$/i.test(p)) {
|
|
27
|
+
return "file-sdl";
|
|
28
|
+
}
|
|
29
|
+
if (/\.(m?[jt]sx?|cjs|cts|vue|svelte|astro)$/i.test(p)) {
|
|
30
|
+
return "code-file";
|
|
31
|
+
}
|
|
32
|
+
return "unknown";
|
|
33
|
+
};
|
|
34
|
+
const classifyOne = (pointer) => {
|
|
35
|
+
if (typeof pointer !== "string") {
|
|
36
|
+
return "unknown";
|
|
37
|
+
}
|
|
38
|
+
const p = pointer.trim();
|
|
39
|
+
return classifyScheme(p) ?? (isInlineSdl(p) ? "inline-sdl" : classifyPath(p));
|
|
40
|
+
};
|
|
41
|
+
const classifyEntry = (pointer) => {
|
|
42
|
+
if (typeof pointer === "object" &&
|
|
43
|
+
pointer !== null &&
|
|
44
|
+
!Array.isArray(pointer)) {
|
|
45
|
+
// Object form `{ "<pointer>": { headers, ... } }`: options are ignored.
|
|
46
|
+
return Object.keys(pointer).map(classifyOne);
|
|
47
|
+
}
|
|
48
|
+
return [classifyOne(pointer)];
|
|
49
|
+
};
|
|
50
|
+
/** Classifies a schema pointer; the pointer itself is never returned. */
|
|
51
|
+
const classifyPointer = (pointer) => {
|
|
52
|
+
if (Array.isArray(pointer)) {
|
|
53
|
+
return pointer.flatMap(classifyEntry);
|
|
54
|
+
}
|
|
55
|
+
const kinds = classifyEntry(pointer);
|
|
56
|
+
return kinds.length === 1 ? kinds[0] : kinds;
|
|
57
|
+
};
|
|
58
|
+
exports.classifyPointer = classifyPointer;
|
|
59
|
+
const MASKS = {
|
|
60
|
+
url: "<url>",
|
|
61
|
+
git: "<git>",
|
|
62
|
+
github: "<github>",
|
|
63
|
+
"file-sdl": "<file:sdl>",
|
|
64
|
+
"file-json": "<file:json>",
|
|
65
|
+
"code-file": "<file:code>",
|
|
66
|
+
glob: "<glob>",
|
|
67
|
+
"inline-sdl": "<inline-sdl>",
|
|
68
|
+
unknown: "<unknown>",
|
|
69
|
+
};
|
|
70
|
+
/** Classifies a schema pointer into mask token(s) for the config slot. */
|
|
71
|
+
const maskPointer = (pointer) => {
|
|
72
|
+
const kinds = (0, exports.classifyPointer)(pointer);
|
|
73
|
+
return Array.isArray(kinds)
|
|
74
|
+
? kinds.map((k) => {
|
|
75
|
+
return MASKS[k];
|
|
76
|
+
})
|
|
77
|
+
: MASKS[kinds];
|
|
78
|
+
};
|
|
79
|
+
exports.maskPointer = maskPointer;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CliOptions, ConfigOptions, TelemetryEvent, TelemetryPayload, TelemetryTrigger } from "@graphql-markdown/types";
|
|
2
|
+
export interface PayloadInput {
|
|
3
|
+
event?: TelemetryEvent;
|
|
4
|
+
trigger: TelemetryTrigger;
|
|
5
|
+
pkg: string;
|
|
6
|
+
pkgVersion: string;
|
|
7
|
+
/** `versionInfo.major` of the loaded `graphql`. */
|
|
8
|
+
graphqlMajor?: unknown;
|
|
9
|
+
config?: ConfigOptions;
|
|
10
|
+
cli?: CliOptions;
|
|
11
|
+
/** Create events only. */
|
|
12
|
+
target?: string;
|
|
13
|
+
mode?: "scaffold" | "wire";
|
|
14
|
+
/** Generate events only. */
|
|
15
|
+
pages?: number;
|
|
16
|
+
durationMs?: number;
|
|
17
|
+
errorType?: string;
|
|
18
|
+
/** True only when no state file existed before this run. */
|
|
19
|
+
noStateBefore?: boolean;
|
|
20
|
+
env?: NodeJS.ProcessEnv;
|
|
21
|
+
}
|
|
22
|
+
export declare const buildPayload: (input: PayloadInput) => TelemetryPayload;
|
|
23
|
+
/** SHA-256 of the canonical sorted-key JSON, excluding `firstRun`. */
|
|
24
|
+
export declare const fingerprint: (payload: TelemetryPayload) => string;
|
|
25
|
+
//# sourceMappingURL=payload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../src/payload.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AAMjC,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,EAAE,MAAM,CAAC;IACnB,mDAAmD;IACnD,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,GAAG,CAAC,EAAE,UAAU,CAAC;IACjB,0BAA0B;IAC1B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAC3B,4BAA4B;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,4DAA4D;IAC5D,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC;CACzB;AAkED,eAAO,MAAM,YAAY,UAAW,YAAY,KAAG,gBAmDlD,CAAC;AA0BF,sEAAsE;AACtE,eAAO,MAAM,WAAW,YAAa,gBAAgB,KAAG,MAMvD,CAAC"}
|
package/dist/payload.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fingerprint = exports.buildPayload = void 0;
|
|
4
|
+
const node_crypto_1 = require("node:crypto");
|
|
5
|
+
const node_fs_1 = require("node:fs");
|
|
6
|
+
const ci_ts_1 = require("./ci.js");
|
|
7
|
+
const loader_ts_1 = require("./loader.js");
|
|
8
|
+
const sanitize_ts_1 = require("./sanitize.js");
|
|
9
|
+
const detectPm = (env) => {
|
|
10
|
+
const name = /^(npm|pnpm|yarn|bun)\//.exec(env.npm_config_user_agent ?? "");
|
|
11
|
+
return name?.[1] ?? "unknown";
|
|
12
|
+
};
|
|
13
|
+
const isWsl = (env) => {
|
|
14
|
+
if (env.WSL_DISTRO_NAME) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
try {
|
|
18
|
+
return (0, node_fs_1.readFileSync)("/proc/version", "utf8")
|
|
19
|
+
.toLowerCase()
|
|
20
|
+
.includes("microsoft");
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const isContainer = (env) => {
|
|
27
|
+
return ((0, node_fs_1.existsSync)("/.dockerenv") ||
|
|
28
|
+
env.CODESPACES !== undefined ||
|
|
29
|
+
env.REMOTE_CONTAINERS !== undefined);
|
|
30
|
+
};
|
|
31
|
+
const applySanitizedSection = (payload, section, source, rules) => {
|
|
32
|
+
const result = (0, sanitize_ts_1.sanitizeConfig)(source, rules);
|
|
33
|
+
if (section === "config") {
|
|
34
|
+
payload.config = result.value;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
payload.cli = result.value;
|
|
38
|
+
}
|
|
39
|
+
if (payload.loader === undefined && source.schema !== undefined) {
|
|
40
|
+
payload.loader = (0, loader_ts_1.classifyPointer)(source.schema);
|
|
41
|
+
}
|
|
42
|
+
return result.unknownKeys;
|
|
43
|
+
};
|
|
44
|
+
const applyGenerateFields = (payload, input) => {
|
|
45
|
+
const { pages, durationMs, errorType } = input;
|
|
46
|
+
if (typeof pages === "number" && Number.isInteger(pages) && pages >= 0) {
|
|
47
|
+
payload.pages = pages;
|
|
48
|
+
}
|
|
49
|
+
if (typeof durationMs === "number" &&
|
|
50
|
+
Number.isFinite(durationMs) &&
|
|
51
|
+
durationMs >= 0) {
|
|
52
|
+
payload.durationMs = Math.round(durationMs / 100) * 100;
|
|
53
|
+
}
|
|
54
|
+
if (typeof errorType === "string" && errorType !== "") {
|
|
55
|
+
payload.errorType = errorType;
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const buildPayload = (input) => {
|
|
59
|
+
const env = input.env ?? process.env;
|
|
60
|
+
const { ci, ciProvider } = (0, ci_ts_1.detectCi)(env);
|
|
61
|
+
const major = input.graphqlMajor;
|
|
62
|
+
const payload = {
|
|
63
|
+
v: 1,
|
|
64
|
+
event: input.event ?? "config",
|
|
65
|
+
pkg: input.pkg,
|
|
66
|
+
pkgVersion: input.pkgVersion,
|
|
67
|
+
nodeMajor: Number.parseInt(process.versions.node, 10),
|
|
68
|
+
graphqlMajor: typeof major === "number" &&
|
|
69
|
+
Number.isInteger(major) &&
|
|
70
|
+
major >= 0 &&
|
|
71
|
+
major < 100
|
|
72
|
+
? major
|
|
73
|
+
: "unknown",
|
|
74
|
+
os: process.platform,
|
|
75
|
+
ci,
|
|
76
|
+
pm: detectPm(env),
|
|
77
|
+
firstRun: !ci && input.noStateBefore === true,
|
|
78
|
+
trigger: input.trigger,
|
|
79
|
+
container: isContainer(env),
|
|
80
|
+
wsl: isWsl(env),
|
|
81
|
+
};
|
|
82
|
+
if (ciProvider) {
|
|
83
|
+
payload.ciProvider = ciProvider;
|
|
84
|
+
}
|
|
85
|
+
let unknownKeys = 0;
|
|
86
|
+
if (input.config) {
|
|
87
|
+
unknownKeys += applySanitizedSection(payload, "config", input.config, sanitize_ts_1.CONFIG_RULES);
|
|
88
|
+
}
|
|
89
|
+
if (input.cli) {
|
|
90
|
+
unknownKeys += applySanitizedSection(payload, "cli", input.cli, sanitize_ts_1.CLI_RULES);
|
|
91
|
+
}
|
|
92
|
+
if (unknownKeys > 0) {
|
|
93
|
+
payload.unknownKeys = unknownKeys;
|
|
94
|
+
}
|
|
95
|
+
if (input.target !== undefined) {
|
|
96
|
+
payload.target = input.target;
|
|
97
|
+
}
|
|
98
|
+
if (input.mode !== undefined) {
|
|
99
|
+
payload.mode = input.mode;
|
|
100
|
+
}
|
|
101
|
+
applyGenerateFields(payload, input);
|
|
102
|
+
return payload;
|
|
103
|
+
};
|
|
104
|
+
exports.buildPayload = buildPayload;
|
|
105
|
+
/** Locale-independent code-unit comparison, so fingerprints are deterministic. */
|
|
106
|
+
const compareKeys = (a, b) => {
|
|
107
|
+
if (a === b) {
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
return a < b ? -1 : 1;
|
|
111
|
+
};
|
|
112
|
+
const canonical = (value) => {
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
return value.map(canonical);
|
|
115
|
+
}
|
|
116
|
+
if (typeof value === "object" && value !== null) {
|
|
117
|
+
return Object.fromEntries(Object.keys(value)
|
|
118
|
+
.sort(compareKeys)
|
|
119
|
+
.map((k) => {
|
|
120
|
+
return [k, canonical(value[k])];
|
|
121
|
+
}));
|
|
122
|
+
}
|
|
123
|
+
return value;
|
|
124
|
+
};
|
|
125
|
+
/** SHA-256 of the canonical sorted-key JSON, excluding `firstRun`. */
|
|
126
|
+
const fingerprint = (payload) => {
|
|
127
|
+
const rest = { ...payload };
|
|
128
|
+
delete rest.firstRun;
|
|
129
|
+
return (0, node_crypto_1.createHash)("sha256")
|
|
130
|
+
.update(JSON.stringify(canonical(rest)))
|
|
131
|
+
.digest("hex");
|
|
132
|
+
};
|
|
133
|
+
exports.fingerprint = fingerprint;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { CliOptions, ConfigOptions } from "@graphql-markdown/types";
|
|
2
|
+
export type Rule = {
|
|
3
|
+
kind: "any";
|
|
4
|
+
} | {
|
|
5
|
+
kind: "enum";
|
|
6
|
+
values: readonly string[];
|
|
7
|
+
} | {
|
|
8
|
+
kind: "formatter";
|
|
9
|
+
} | {
|
|
10
|
+
kind: "loaders";
|
|
11
|
+
} | {
|
|
12
|
+
kind: "map";
|
|
13
|
+
value: Rule;
|
|
14
|
+
} | {
|
|
15
|
+
kind: "object";
|
|
16
|
+
fields: Record<string, Rule>;
|
|
17
|
+
} | {
|
|
18
|
+
kind: "opaque";
|
|
19
|
+
} | {
|
|
20
|
+
kind: "path";
|
|
21
|
+
} | {
|
|
22
|
+
kind: "pointer";
|
|
23
|
+
} | {
|
|
24
|
+
kind: "scalar";
|
|
25
|
+
} | {
|
|
26
|
+
kind: "string";
|
|
27
|
+
} | {
|
|
28
|
+
kind: "url";
|
|
29
|
+
};
|
|
30
|
+
export interface SanitizeResult {
|
|
31
|
+
value: Record<string, unknown>;
|
|
32
|
+
unknownKeys: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const CONFIG_RULES: Readonly<Record<keyof ConfigOptions, Rule>>;
|
|
35
|
+
export declare const CLI_RULES: Readonly<Record<keyof CliOptions, Rule>>;
|
|
36
|
+
/**
|
|
37
|
+
* Sanitizes a config source. Top-level keys without a rule are dropped and
|
|
38
|
+
* counted in `unknownKeys`.
|
|
39
|
+
*/
|
|
40
|
+
export declare const sanitizeConfig: (value: unknown, rules: Record<string, Rule>) => SanitizeResult;
|
|
41
|
+
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../src/sanitize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,aAAa,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, "__esModule", { value: true });
|
|
3
|
+
exports.sanitizeConfig = exports.CLI_RULES = exports.CONFIG_RULES = void 0;
|
|
4
|
+
const loader_ts_1 = require("./loader.js");
|
|
5
|
+
const schema_ts_1 = require("./schema.js");
|
|
6
|
+
const MAX_DEPTH = 8;
|
|
7
|
+
const FORMATTER_PACKAGE = /^@graphql-markdown\/[a-z0-9-]+(\/[a-z0-9-]+)*$/;
|
|
8
|
+
/**
|
|
9
|
+
* `graphql-config`'s `project.extension()` decorates the returned extension
|
|
10
|
+
* object with these project-level fields (schema, documents, include,
|
|
11
|
+
* exclude) regardless of whether the user's config sets them. `schema` is a
|
|
12
|
+
* real graphql-markdown option and has its own rule; the other three are
|
|
13
|
+
* graphql-config plumbing, not graphql-markdown options, so they are dropped
|
|
14
|
+
* silently here rather than inflating `unknownKeys` on every run.
|
|
15
|
+
*/
|
|
16
|
+
const GRAPHQL_CONFIG_PROJECT_KEYS = new Set([
|
|
17
|
+
"documents",
|
|
18
|
+
"include",
|
|
19
|
+
"exclude",
|
|
20
|
+
]);
|
|
21
|
+
const scalar = { kind: "scalar" };
|
|
22
|
+
const string = { kind: "string" };
|
|
23
|
+
const path = { kind: "path" };
|
|
24
|
+
const url = { kind: "url" };
|
|
25
|
+
const any = { kind: "any" };
|
|
26
|
+
const formatter = { kind: "formatter" };
|
|
27
|
+
const pointer = { kind: "pointer" };
|
|
28
|
+
const enumOf = (values) => {
|
|
29
|
+
return { kind: "enum", values };
|
|
30
|
+
};
|
|
31
|
+
const deprecated = enumOf(schema_ts_1.DEPRECATED_OPTIONS);
|
|
32
|
+
exports.CONFIG_RULES = {
|
|
33
|
+
baseURL: url,
|
|
34
|
+
customDirective: { kind: "map", value: any },
|
|
35
|
+
decorators: { kind: "map", value: any },
|
|
36
|
+
diffMethod: enumOf(schema_ts_1.DIFF_METHODS),
|
|
37
|
+
docOptions: {
|
|
38
|
+
kind: "object",
|
|
39
|
+
fields: {
|
|
40
|
+
frontMatter: { kind: "map", value: any },
|
|
41
|
+
index: scalar,
|
|
42
|
+
generatorFrameworkName: string,
|
|
43
|
+
generatorFrameworkVersion: string,
|
|
44
|
+
categorySort: { kind: "enum", values: ["natural"] },
|
|
45
|
+
sectionHeaderId: scalar,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
force: scalar,
|
|
49
|
+
groupByDirective: {
|
|
50
|
+
kind: "object",
|
|
51
|
+
fields: { directive: string, field: string, fallback: string },
|
|
52
|
+
},
|
|
53
|
+
homepage: path,
|
|
54
|
+
id: string,
|
|
55
|
+
linkRoot: path,
|
|
56
|
+
loaders: { kind: "loaders" },
|
|
57
|
+
formatter,
|
|
58
|
+
mdxParser: formatter,
|
|
59
|
+
metatags: { kind: "map", value: string },
|
|
60
|
+
onlyDocDirective: string,
|
|
61
|
+
outputAdapter: { kind: "opaque" },
|
|
62
|
+
pretty: scalar,
|
|
63
|
+
printTypeOptions: {
|
|
64
|
+
kind: "object",
|
|
65
|
+
fields: {
|
|
66
|
+
deprecated,
|
|
67
|
+
exampleSection: { kind: "map", value: string },
|
|
68
|
+
hierarchy: enumOf(schema_ts_1.HIERARCHIES),
|
|
69
|
+
parentTypePrefix: scalar,
|
|
70
|
+
typeBadges: scalar,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
rootPath: path,
|
|
74
|
+
schema: pointer,
|
|
75
|
+
skipDocDirective: string,
|
|
76
|
+
telemetry: scalar,
|
|
77
|
+
tmpDir: path,
|
|
78
|
+
};
|
|
79
|
+
exports.CLI_RULES = {
|
|
80
|
+
base: url,
|
|
81
|
+
config: scalar,
|
|
82
|
+
deprecated,
|
|
83
|
+
diff: enumOf(schema_ts_1.DIFF_METHODS),
|
|
84
|
+
force: scalar,
|
|
85
|
+
groupByDirective: string,
|
|
86
|
+
homepage: path,
|
|
87
|
+
index: scalar,
|
|
88
|
+
link: path,
|
|
89
|
+
hierarchy: enumOf(schema_ts_1.HIERARCHIES),
|
|
90
|
+
formatter,
|
|
91
|
+
mdxParser: formatter,
|
|
92
|
+
noParentType: scalar,
|
|
93
|
+
noTypeBadges: scalar,
|
|
94
|
+
noSectionId: scalar,
|
|
95
|
+
pretty: scalar,
|
|
96
|
+
root: path,
|
|
97
|
+
schema: pointer,
|
|
98
|
+
skip: string,
|
|
99
|
+
only: string,
|
|
100
|
+
tmp: path,
|
|
101
|
+
telemetry: scalar,
|
|
102
|
+
};
|
|
103
|
+
/** Masks a string by its shape: url, path or generic string. */
|
|
104
|
+
const maskString = (value) => {
|
|
105
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(value)) {
|
|
106
|
+
return "<url>";
|
|
107
|
+
}
|
|
108
|
+
if (/[/\\]/.test(value) || value.startsWith(".")) {
|
|
109
|
+
return "<path>";
|
|
110
|
+
}
|
|
111
|
+
return "<string>";
|
|
112
|
+
};
|
|
113
|
+
const isPlainObject = (value) => {
|
|
114
|
+
const proto = Object.getPrototypeOf(value);
|
|
115
|
+
return proto === Object.prototype || proto === null;
|
|
116
|
+
};
|
|
117
|
+
const sanitizeFormatter = (value) => {
|
|
118
|
+
if (schema_ts_1.FORMATTER_PRESETS.includes(value) ||
|
|
119
|
+
FORMATTER_PACKAGE.test(value)) {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
return "<custom-formatter>";
|
|
123
|
+
};
|
|
124
|
+
const sanitizeLoaderName = (value) => {
|
|
125
|
+
return schema_ts_1.KNOWN_LOADERS.includes(value)
|
|
126
|
+
? value
|
|
127
|
+
: "<custom-loader>";
|
|
128
|
+
};
|
|
129
|
+
/* eslint-disable @typescript-eslint/no-use-before-define -- mutual recursion */
|
|
130
|
+
const sanitizeLoaderEntry = (item, depth) => {
|
|
131
|
+
if (typeof item === "object" && item !== null && isPlainObject(item)) {
|
|
132
|
+
const cfg = item;
|
|
133
|
+
return {
|
|
134
|
+
...(cfg.module !== undefined && {
|
|
135
|
+
module: sanitizeLoaders(cfg.module, depth + 2),
|
|
136
|
+
}),
|
|
137
|
+
...(cfg.options !== undefined && {
|
|
138
|
+
options: sanitizeValue(cfg.options, { kind: "map", value: any }, depth + 2),
|
|
139
|
+
}),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return sanitizeLoaders(item, depth + 1);
|
|
143
|
+
};
|
|
144
|
+
const sanitizeLoaders = (value, depth) => {
|
|
145
|
+
if (typeof value === "string") {
|
|
146
|
+
return sanitizeLoaderName(value);
|
|
147
|
+
}
|
|
148
|
+
if (Array.isArray(value)) {
|
|
149
|
+
return value.map((item) => {
|
|
150
|
+
return sanitizeLoaders(item, depth + 1);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
if (typeof value === "object" && value !== null && isPlainObject(value)) {
|
|
154
|
+
const out = {};
|
|
155
|
+
for (const [key, item] of Object.entries(value)) {
|
|
156
|
+
out[sanitizeLoaderName(key)] = sanitizeLoaderEntry(item, depth);
|
|
157
|
+
}
|
|
158
|
+
return out;
|
|
159
|
+
}
|
|
160
|
+
return sanitizeValue(value, any, depth);
|
|
161
|
+
};
|
|
162
|
+
const sanitizeStringByRule = (value, rule) => {
|
|
163
|
+
switch (rule.kind) {
|
|
164
|
+
case "enum":
|
|
165
|
+
return rule.values.includes(value) ? value : maskString(value);
|
|
166
|
+
case "url":
|
|
167
|
+
return "<url>";
|
|
168
|
+
case "path":
|
|
169
|
+
return "<path>";
|
|
170
|
+
case "formatter":
|
|
171
|
+
return sanitizeFormatter(value);
|
|
172
|
+
default:
|
|
173
|
+
return rule.kind === "string" ? "<string>" : maskString(value);
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
const sanitizeObjectByRule = (value, rule, depth) => {
|
|
177
|
+
if (!isPlainObject(value)) {
|
|
178
|
+
return "<object>";
|
|
179
|
+
}
|
|
180
|
+
const entries = Object.entries(value);
|
|
181
|
+
const out = {};
|
|
182
|
+
let n = 0;
|
|
183
|
+
for (const [key, item] of entries) {
|
|
184
|
+
if (rule.kind === "object" && Object.hasOwn(rule.fields, key)) {
|
|
185
|
+
const next = sanitizeValue(item, rule.fields[key], depth + 1);
|
|
186
|
+
if (next !== undefined) {
|
|
187
|
+
out[key] = next;
|
|
188
|
+
}
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
const itemRule = rule.kind === "map" ? rule.value : any;
|
|
192
|
+
const next = sanitizeValue(item, itemRule, depth + 1);
|
|
193
|
+
if (next !== undefined) {
|
|
194
|
+
out[`<key:${n}>`] = next;
|
|
195
|
+
n += 1;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return out;
|
|
199
|
+
};
|
|
200
|
+
const sanitizePrimitive = (value) => {
|
|
201
|
+
if (value === null || typeof value === "boolean") {
|
|
202
|
+
return { handled: true, value };
|
|
203
|
+
}
|
|
204
|
+
if (typeof value === "number") {
|
|
205
|
+
return { handled: true, value: Number.isFinite(value) ? value : null };
|
|
206
|
+
}
|
|
207
|
+
if (typeof value === "function") {
|
|
208
|
+
return { handled: true, value: "<function>" };
|
|
209
|
+
}
|
|
210
|
+
if (value === undefined) {
|
|
211
|
+
return { handled: true, value: undefined };
|
|
212
|
+
}
|
|
213
|
+
if (typeof value === "symbol" || typeof value === "bigint") {
|
|
214
|
+
return { handled: true, value: "<object>" };
|
|
215
|
+
}
|
|
216
|
+
return { handled: false };
|
|
217
|
+
};
|
|
218
|
+
const sanitizeValue = (value, rule, depth) => {
|
|
219
|
+
const primitive = sanitizePrimitive(value);
|
|
220
|
+
if (primitive.handled) {
|
|
221
|
+
return primitive.value;
|
|
222
|
+
}
|
|
223
|
+
if (depth > MAX_DEPTH || rule.kind === "opaque") {
|
|
224
|
+
return typeof value === "string" ? "<string>" : "<object>";
|
|
225
|
+
}
|
|
226
|
+
return sanitizeByRule(value, rule, depth);
|
|
227
|
+
};
|
|
228
|
+
const sanitizeByRule = (value, rule, depth) => {
|
|
229
|
+
if (rule.kind === "pointer") {
|
|
230
|
+
return (0, loader_ts_1.maskPointer)(value);
|
|
231
|
+
}
|
|
232
|
+
if (rule.kind === "loaders") {
|
|
233
|
+
return sanitizeLoaders(value, depth);
|
|
234
|
+
}
|
|
235
|
+
if (typeof value === "string") {
|
|
236
|
+
return sanitizeStringByRule(value, rule);
|
|
237
|
+
}
|
|
238
|
+
return sanitizeCollection(value, rule, depth);
|
|
239
|
+
};
|
|
240
|
+
const sanitizeCollection = (value, rule, depth) => {
|
|
241
|
+
if (Array.isArray(value)) {
|
|
242
|
+
return value.map((item) => {
|
|
243
|
+
return sanitizeValue(item, rule, depth + 1);
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
if (typeof value === "object" && value !== null) {
|
|
247
|
+
return sanitizeObjectByRule(value, rule, depth);
|
|
248
|
+
}
|
|
249
|
+
return "<object>";
|
|
250
|
+
};
|
|
251
|
+
/* eslint-enable @typescript-eslint/no-use-before-define */
|
|
252
|
+
/**
|
|
253
|
+
* Sanitizes a config source. Top-level keys without a rule are dropped and
|
|
254
|
+
* counted in `unknownKeys`.
|
|
255
|
+
*/
|
|
256
|
+
const sanitizeConfig = (value, rules) => {
|
|
257
|
+
const result = { value: {}, unknownKeys: 0 };
|
|
258
|
+
if (typeof value !== "object" || value === null) {
|
|
259
|
+
return result;
|
|
260
|
+
}
|
|
261
|
+
for (const [key, item] of Object.entries(value)) {
|
|
262
|
+
if (GRAPHQL_CONFIG_PROJECT_KEYS.has(key)) {
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
if (!Object.hasOwn(rules, key)) {
|
|
266
|
+
result.unknownKeys += 1;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const next = sanitizeValue(item, rules[key], 0);
|
|
270
|
+
if (next !== undefined) {
|
|
271
|
+
result.value[key] = next;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return result;
|
|
275
|
+
};
|
|
276
|
+
exports.sanitizeConfig = sanitizeConfig;
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Allowlist of every string a payload may carry, as plain data: enums plus
|
|
3
|
+
* mask tokens. Shared with the Worker, which rejects anything else.
|
|
4
|
+
*/
|
|
5
|
+
export declare const EVENTS: readonly ["config", "create_scaffold", "create_wire"];
|
|
6
|
+
export declare const TRIGGERS: readonly ["cli", "create", "docusaurus", "nuxt", "programmatic"];
|
|
7
|
+
export declare const CI_PROVIDERS: readonly ["github-actions", "gitlab", "circleci", "azure-pipelines", "jenkins", "bitbucket", "buildkite", "travis", "vercel", "netlify", "cloudflare-pages", "aws-codebuild", "teamcity", "appveyor", "drone", "render", "other"];
|
|
8
|
+
export declare const PACKAGE_MANAGERS: readonly ["npm", "pnpm", "yarn", "bun", "unknown"];
|
|
9
|
+
export declare const LOADER_KINDS: readonly ["url", "file-sdl", "file-json", "git", "github", "glob", "code-file", "inline-sdl", "unknown"];
|
|
10
|
+
export declare const MODES: readonly ["scaffold", "wire"];
|
|
11
|
+
export declare const DIFF_METHODS: readonly ["FORCE", "NONE"];
|
|
12
|
+
export declare const DEPRECATED_OPTIONS: readonly ["default", "group", "skip"];
|
|
13
|
+
export declare const HIERARCHIES: readonly ["api", "entity", "flat"];
|
|
14
|
+
export declare const FORMATTER_PRESETS: readonly ["docfx", "docusaurus", "fumadocs", "honkit", "hugo", "mdbook", "mdx", "mkdocs", "starlight", "vocs"];
|
|
15
|
+
export declare const KNOWN_LOADERS: readonly ["UrlLoader", "JsonFileLoader", "GraphQLFileLoader", "CodeFileLoader", "GitLoader", "GithubLoader", "ApolloEngineLoader", "PrismaLoader", "@graphql-tools/url-loader", "@graphql-tools/json-file-loader", "@graphql-tools/graphql-file-loader", "@graphql-tools/code-file-loader", "@graphql-tools/git-loader", "@graphql-tools/github-loader", "@graphql-tools/apollo-engine-loader", "@graphql-tools/prisma-loader"];
|
|
16
|
+
export declare const MASK_TOKENS: readonly ["<url>", "<path>", "<string>", "<function>", "<object>", "<custom-loader>", "<custom-formatter>", "<git>", "<github>", "<file:sdl>", "<file:json>", "<file:code>", "<glob>", "<inline-sdl>", "<unknown>"];
|
|
17
|
+
/** Pattern of masked object keys, e.g. `<key:0>`. */
|
|
18
|
+
export declare const KEY_TOKEN_PATTERN: string;
|
|
19
|
+
export declare const ALLOWLIST: {
|
|
20
|
+
readonly events: typeof EVENTS;
|
|
21
|
+
readonly triggers: typeof TRIGGERS;
|
|
22
|
+
readonly ciProviders: typeof CI_PROVIDERS;
|
|
23
|
+
readonly packageManagers: typeof PACKAGE_MANAGERS;
|
|
24
|
+
readonly loaderKinds: typeof LOADER_KINDS;
|
|
25
|
+
readonly modes: typeof MODES;
|
|
26
|
+
readonly diffMethods: typeof DIFF_METHODS;
|
|
27
|
+
readonly deprecatedOptions: typeof DEPRECATED_OPTIONS;
|
|
28
|
+
readonly hierarchies: typeof HIERARCHIES;
|
|
29
|
+
readonly formatterPresets: typeof FORMATTER_PRESETS;
|
|
30
|
+
readonly formatterPackagePattern: "^@graphql-markdown/[a-z0-9-]+(/[a-z0-9-]+)*$";
|
|
31
|
+
readonly knownLoaders: typeof KNOWN_LOADERS;
|
|
32
|
+
readonly maskTokens: typeof MASK_TOKENS;
|
|
33
|
+
readonly keyTokenPattern: typeof KEY_TOKEN_PATTERN;
|
|
34
|
+
readonly graphqlMajorUnknown: "unknown";
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,MAAM,YAAI,QAAQ,EAAE,iBAAiB,EAAE,aAAa,CAAU,CAAC;AAC5E,eAAO,MAAM,QAAQ,YACnB,KAAK,EACL,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,cAAc,CACN,CAAC;AACX,eAAO,MAAM,YAAY,YACvB,gBAAgB,EAChB,QAAQ,EACR,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,WAAW,EACX,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,SAAS,E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