@fluixi/ts-plugin 0.1.0-alpha.9 → 1.0.0-alpha.100
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 +1 -1
- package/README.md +45 -14
- package/dist/auto-import.d.ts +43 -0
- package/dist/auto-import.d.ts.map +1 -0
- package/dist/cache.d.ts +29 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/collect.d.ts +33 -0
- package/dist/collect.d.ts.map +1 -0
- package/dist/completion.d.ts +11 -0
- package/dist/completion.d.ts.map +1 -0
- package/dist/diagnostics.d.ts +23 -0
- package/dist/diagnostics.d.ts.map +1 -0
- package/dist/elements.d.ts +21 -0
- package/dist/elements.d.ts.map +1 -0
- package/dist/fixes.d.ts +19 -0
- package/dist/fixes.d.ts.map +1 -0
- package/dist/hover.d.ts +11 -0
- package/dist/hover.d.ts.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1231 -385
- package/dist/infer.d.ts +45 -0
- package/dist/infer.d.ts.map +1 -0
- package/dist/navigation.d.ts +48 -0
- package/dist/navigation.d.ts.map +1 -0
- package/dist/pieces.d.ts +20 -0
- package/dist/pieces.d.ts.map +1 -0
- package/dist/props.d.ts +19 -0
- package/dist/props.d.ts.map +1 -0
- package/dist/rules.d.ts +49 -0
- package/dist/rules.d.ts.map +1 -0
- package/dist/rules.js +417 -0
- package/dist/tsconfig.lib.tsbuildinfo +1 -0
- package/package.json +16 -7
package/dist/infer.d.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type inference for callback parameters inside html`` templates.
|
|
3
|
+
*
|
|
4
|
+
* A template is an opaque string to TypeScript, so a callback like
|
|
5
|
+
* `${(it) => it.label}` (an each render fn) or `${(e) => …}` (an event handler)
|
|
6
|
+
* gets no contextual type: `it`/`e` are implicit `any`. We recover the type the
|
|
7
|
+
* way JSX would infer it, by understanding the template STRUCTURE:
|
|
8
|
+
*
|
|
9
|
+
* - `<li each=${items}>${(it) => …}</li>` → `it` is the element type of `items`
|
|
10
|
+
* - `<button @click=${(e) => …}>` → `e` is the DOM event type (MouseEvent…)
|
|
11
|
+
*
|
|
12
|
+
* The arrow/function expression in a `${…}` is a REAL TS node (a template-span
|
|
13
|
+
* expression), so once we know the role of its hole we can compute the parameter
|
|
14
|
+
* type from the checker and surface it (hover now; completion/checking next).
|
|
15
|
+
*/
|
|
16
|
+
import type * as TS from 'typescript';
|
|
17
|
+
export interface ParamTypeInfo {
|
|
18
|
+
paramName: string;
|
|
19
|
+
/** The rendered type string, e.g. `{ id: number; label: string }` or `MouseEvent`. */
|
|
20
|
+
typeText: string;
|
|
21
|
+
/** The resolved type, when available: used for member completion (`param.` → members). */
|
|
22
|
+
type?: TS.Type;
|
|
23
|
+
/** The param identifier's span (for the hover range). */
|
|
24
|
+
start: number;
|
|
25
|
+
length: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* If `position` is on a callback parameter inside an html`` template whose type
|
|
29
|
+
* we can infer, return the parameter name + inferred type string.
|
|
30
|
+
*/
|
|
31
|
+
export declare function inferParamAt(ts: typeof TS, program: TS.Program, sf: TS.SourceFile, position: number): ParamTypeInfo | undefined;
|
|
32
|
+
/** A callback parameter inside a template whose type we could infer. */
|
|
33
|
+
export interface InferredParam {
|
|
34
|
+
fn: TS.ArrowFunction | TS.FunctionExpression;
|
|
35
|
+
paramName: string;
|
|
36
|
+
type: TS.Type;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Every inferable callback parameter in the file's templates. Position-independent,
|
|
40
|
+
* so a whole-file pass (diagnostics) can use the same inference hover uses.
|
|
41
|
+
*/
|
|
42
|
+
export declare function inferParamsIn(ts: typeof TS, program: TS.Program, sf: TS.SourceFile): InferredParam[];
|
|
43
|
+
/** Build a QuickInfo for an inferred callback parameter, or undefined. */
|
|
44
|
+
export declare function paramQuickInfo(ts: typeof TS, ls: TS.LanguageService, fileName: string, position: number): TS.QuickInfo | undefined;
|
|
45
|
+
//# sourceMappingURL=infer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer.d.ts","sourceRoot":"","sources":["../src/infer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AA6FtC,MAAM,WAAW,aAAa;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,QAAQ,EAAE,MAAM,CAAC;IACjB,0FAA0F;IAC1F,IAAI,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC;IACf,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAiBD;;;GAGG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,OAAO,EAAE,EACb,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,EAAE,EAAE,EAAE,CAAC,UAAU,EACjB,QAAQ,EAAE,MAAM,GACf,aAAa,GAAG,SAAS,CA+B3B;AAwCD,wEAAwE;AACxE,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,EAAE,CAAC,aAAa,GAAG,EAAE,CAAC,kBAAkB,CAAC;IAC7C,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC;CACf;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,GAAG,aAAa,EAAE,CAwBpG;AAED,0EAA0E;AAC1E,wBAAgB,cAAc,CAC5B,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,SAAS,GAAG,SAAS,CAsB1B"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Go To Definition, Find References and Rename for component tags in templates.
|
|
3
|
+
*
|
|
4
|
+
* A `${…}` hole is a real expression, so TypeScript already answers all three for
|
|
5
|
+
* it: the plugin just has to stop shadowing those methods. The synthetic part is
|
|
6
|
+
* the tag name: `<UserCard>` is text inside a string literal, invisible to the
|
|
7
|
+
* checker.
|
|
8
|
+
*
|
|
9
|
+
* So the whole job is mapping a tag name to the binding it names, and back. That
|
|
10
|
+
* makes rename CORRECT rather than convenient: renaming a component today leaves
|
|
11
|
+
* every template silently broken, because nothing rewrites the tags.
|
|
12
|
+
*
|
|
13
|
+
* Both the opening and closing tag are collected. Rewriting only `<Tag>` and
|
|
14
|
+
* leaving `</Tag>` would produce a mismatched template, worse than not renaming.
|
|
15
|
+
*/
|
|
16
|
+
import type * as TS from 'typescript';
|
|
17
|
+
/** A tag-name occurrence in a template: where it is, and what it names. */
|
|
18
|
+
export interface TagSpan {
|
|
19
|
+
/** Root name: `Ctx.Provider` is keyed by `Ctx`, which is the binding. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Offset of the root name itself. */
|
|
22
|
+
start: number;
|
|
23
|
+
length: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Every component-tag occurrence in a file, opening and closing. Cached on the
|
|
27
|
+
* SourceFile, which TypeScript replaces on edit, so it invalidates itself.
|
|
28
|
+
*/
|
|
29
|
+
export declare function tagSpans(ts: typeof TS, sf: TS.SourceFile): TagSpan[];
|
|
30
|
+
/** The tag occurrence under `position`, if the position is on one. */
|
|
31
|
+
export declare function tagAt(ts: typeof TS, sf: TS.SourceFile, position: number): TagSpan | undefined;
|
|
32
|
+
/** Go To Definition from a component tag. */
|
|
33
|
+
export declare function templateDefinition(ts: typeof TS, ls: TS.LanguageService, host: TS.ModuleResolutionHost, fileName: string, position: number): TS.DefinitionInfo[] | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Every template tag across the program that resolves to the same symbol.
|
|
36
|
+
*
|
|
37
|
+
* Files are pre-filtered on the literal `html\`` before anything is parsed, so a
|
|
38
|
+
* project without templates costs one string search per file.
|
|
39
|
+
*/
|
|
40
|
+
export declare function tagOccurrences(ts: typeof TS, program: TS.Program, host: TS.ModuleResolutionHost, symbol: TS.Symbol, name: string): Array<{
|
|
41
|
+
fileName: string;
|
|
42
|
+
span: TS.TextSpan;
|
|
43
|
+
}>;
|
|
44
|
+
/** Template tag references to merge into the real reference list. */
|
|
45
|
+
export declare function templateReferences(ts: typeof TS, ls: TS.LanguageService, host: TS.ModuleResolutionHost, fileName: string, position: number): TS.ReferenceEntry[];
|
|
46
|
+
/** Template tag locations to merge into a rename, so `</Tag>` is rewritten too. */
|
|
47
|
+
export declare function templateRenameLocations(ts: typeof TS, ls: TS.LanguageService, host: TS.ModuleResolutionHost, fileName: string, position: number): TS.RenameLocation[];
|
|
48
|
+
//# sourceMappingURL=navigation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.d.ts","sourceRoot":"","sources":["../src/navigation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAKtC,2EAA2E;AAC3E,MAAM,WAAW,OAAO;IACtB,yEAAyE;IACzE,IAAI,EAAE,MAAM,CAAC;IACb,sCAAsC;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAID;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,GAAG,OAAO,EAAE,CA8BpE;AAYD,sEAAsE;AACtE,wBAAgB,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAG7F;AAsCD,6CAA6C;AAC7C,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,cAAc,EAAE,GAAG,SAAS,CAuCjC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,OAAO,EAAE,EACb,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,MAAM,EAAE,EAAE,CAAC,MAAM,EACjB,IAAI,EAAE,MAAM,GACX,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAA;CAAE,CAAC,CAmBhD;AAuCD,qEAAqE;AACrE,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,cAAc,EAAE,CAcrB;AAED,mFAAmF;AACnF,wBAAgB,uBAAuB,CACrC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,cAAc,EAAE,CAYrB"}
|
package/dist/pieces.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build position-carrying parser pieces from a TS template literal, so the
|
|
3
|
+
* Template AST's spans map back to real offsets in the source file (needed for
|
|
4
|
+
* hover/definition, which must point at the exact tag in the template).
|
|
5
|
+
*
|
|
6
|
+
* The text comes from the source, **not** from `node.text`. `node.text` is the *cooked*
|
|
7
|
+
* value, where an escape like `` \` `` is one character while the source spends two, so
|
|
8
|
+
* every span after an escape is reported short, and hover, completion and diagnostics all
|
|
9
|
+
* land on the wrong offset. A single `` html`\`\`` `` in a file was enough to move a tag's
|
|
10
|
+
* attribute area two characters left, which is exactly the sort of thing that looks like
|
|
11
|
+
* "autocomplete just doesn't work here".
|
|
12
|
+
*
|
|
13
|
+
* Raw text keeps offsets aligned, and the difference is invisible to the parser's job:
|
|
14
|
+
* an escape sequence inside template markup is content, so it changes what a text node
|
|
15
|
+
* contains but never the structure spans are computed from.
|
|
16
|
+
*/
|
|
17
|
+
import type * as TS from 'typescript';
|
|
18
|
+
import type { Piece } from '@fluixi/template-parser';
|
|
19
|
+
export declare function templatePieces(ts: typeof TS, tpl: TS.TemplateLiteral, sf: TS.SourceFile): Piece[];
|
|
20
|
+
//# sourceMappingURL=pieces.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pieces.d.ts","sourceRoot":"","sources":["../src/pieces.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAerD,wBAAgB,cAAc,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,EAAE,CAAC,eAAe,EAAE,EAAE,EAAE,EAAE,CAAC,UAAU,GAAG,KAAK,EAAE,CAiBjG"}
|
package/dist/props.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prop-name completion for component tags inside html`` templates.
|
|
3
|
+
*
|
|
4
|
+
* The virtual document (see ./virtual) already gives prop HOVER and value
|
|
5
|
+
* type-checking via `__fxProps`, but object-literal key completion is awkward
|
|
6
|
+
* for a half-typed name. So when the cursor sits in a component tag's attribute
|
|
7
|
+
* area, we compute the component's prop names straight from the checker and
|
|
8
|
+
* return them as completion entries: reliable and independent of the virtual
|
|
9
|
+
* document.
|
|
10
|
+
*/
|
|
11
|
+
import type * as TS from 'typescript';
|
|
12
|
+
export declare function componentPropCompletions(ts: typeof TS, ls: TS.LanguageService, host: TS.ModuleResolutionHost, fileName: string, position: number): TS.CompletionEntry[] | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* Hover for a component prop NAME (e.g. the cursor on `header` in `<Card header=…>`).
|
|
15
|
+
* Resolves the prop's type from the component's props for user components, or a
|
|
16
|
+
* known signature for the auto-imported control-flow ones.
|
|
17
|
+
*/
|
|
18
|
+
export declare function componentPropHover(ts: typeof TS, ls: TS.LanguageService, host: TS.ModuleResolutionHost, fileName: string, position: number): TS.QuickInfo | undefined;
|
|
19
|
+
//# sourceMappingURL=props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../src/props.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAKtC,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,eAAe,EAAE,GAAG,SAAS,CAuClC;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,OAAO,EAAE,EACb,EAAE,EAAE,EAAE,CAAC,eAAe,EACtB,IAAI,EAAE,EAAE,CAAC,oBAAoB,EAC7B,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,EAAE,CAAC,SAAS,GAAG,SAAS,CA6C1B"}
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Env and auth mistakes, reported while the code is written.
|
|
3
|
+
*
|
|
4
|
+
* The build already refuses a secret read in browser code; this says so at the keystroke, next
|
|
5
|
+
* to the line, with the same words. The auth rules catch configurations that work in a demo and
|
|
6
|
+
* fail in a way nobody notices: a verifier that accepts tokens minted for another client, a
|
|
7
|
+
* secret in a browser bundle, a cookie key short enough to guess.
|
|
8
|
+
*
|
|
9
|
+
* Calls are recognised through their imports, so only the framework's own functions are judged:
|
|
10
|
+
* an admin form with a `clientSecret` field of its own is none of this module's business.
|
|
11
|
+
*
|
|
12
|
+
* "Browser code" is a guess here, since the editor sees one file and not the import graph: every
|
|
13
|
+
* file except a `.server` file, an API route, middleware, `app.config.server.ts` and the config
|
|
14
|
+
* files, minus a `"use server"` body and a branch only the server takes. Rules resting on that
|
|
15
|
+
* guess are warnings; the build is the authority.
|
|
16
|
+
*/
|
|
17
|
+
import type * as TS from 'typescript';
|
|
18
|
+
export declare const RULE: {
|
|
19
|
+
readonly envNotPublic: 9101;
|
|
20
|
+
readonly serverReadInBrowser: 9102;
|
|
21
|
+
readonly importMetaEnv: 9103;
|
|
22
|
+
readonly secretInEnvPublic: 9104;
|
|
23
|
+
readonly secretInBrowser: 9105;
|
|
24
|
+
readonly audienceUnchecked: 9106;
|
|
25
|
+
readonly weakAlgorithm: 9107;
|
|
26
|
+
readonly dpopBareVerify: 9108;
|
|
27
|
+
readonly guardWithoutRoles: 9109;
|
|
28
|
+
readonly weakCookie: 9110;
|
|
29
|
+
readonly localStorageTokens: 9111;
|
|
30
|
+
};
|
|
31
|
+
/** Files that never run in a browser: server code, build-time config and tests. */
|
|
32
|
+
export declare function isServerFile(fileName: string): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* The names `env.public` declares, as the type checker sees them: the generated
|
|
35
|
+
* `src/fluixi-env-vars.d.ts` fills `PublicEnv` in. Null when the app declares none, which turns
|
|
36
|
+
* the env-name rule off, as the build does.
|
|
37
|
+
*/
|
|
38
|
+
export declare function publicEnvNames(ts: typeof TS, program: TS.Program, fileName: string, host: TS.ModuleResolutionHost | undefined): Set<string> | null;
|
|
39
|
+
/** Every env and auth finding in one file. */
|
|
40
|
+
export declare function envAuthDiagnostics(ts: typeof TS, program: TS.Program, fileName: string, host?: TS.ModuleResolutionHost): TS.Diagnostic[];
|
|
41
|
+
/**
|
|
42
|
+
* "Add NAME to env.public": the quick fix for an env read the browser cannot satisfy.
|
|
43
|
+
*
|
|
44
|
+
* Edits `fluixi.config.*` in place, after the last entry, in the list's own layout. Offered only
|
|
45
|
+
* when that list exists, since creating an `env` block would be a decision about the whole app,
|
|
46
|
+
* and never for a name that reads like a secret: publishing it is exactly the mistake to avoid.
|
|
47
|
+
*/
|
|
48
|
+
export declare function envPublicFix(ts: typeof TS, program: TS.Program, fileName: string, position: number, host: TS.ModuleResolutionHost): TS.CodeFixAction | null;
|
|
49
|
+
//# sourceMappingURL=rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../src/rules.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAEtC,eAAO,MAAM,IAAI;;;;;;;;;;;;CAYP,CAAC;AAKX,mFAAmF;AACnF,wBAAgB,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAYtD;AAsFD;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,OAAO,EAAE,EACb,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,EAAE,CAAC,oBAAoB,GAAG,SAAS,GACxC,GAAG,CAAC,MAAM,CAAC,GAAG,IAAI,CAapB;AAwBD,8CAA8C;AAC9C,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,OAAO,EAAE,EACb,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,QAAQ,EAAE,MAAM,EAChB,IAAI,CAAC,EAAE,EAAE,CAAC,oBAAoB,GAC7B,EAAE,CAAC,UAAU,EAAE,CAyNjB;AAeD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC1B,EAAE,EAAE,OAAO,EAAE,EACb,OAAO,EAAE,EAAE,CAAC,OAAO,EACnB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,EAAE,CAAC,oBAAoB,GAC5B,EAAE,CAAC,aAAa,GAAG,IAAI,CA2DzB"}
|
package/dist/rules.js
ADDED
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/rules.ts
|
|
21
|
+
var rules_exports = {};
|
|
22
|
+
__export(rules_exports, {
|
|
23
|
+
RULE: () => RULE,
|
|
24
|
+
envAuthDiagnostics: () => envAuthDiagnostics,
|
|
25
|
+
envPublicFix: () => envPublicFix,
|
|
26
|
+
isServerFile: () => isServerFile,
|
|
27
|
+
publicEnvNames: () => publicEnvNames
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(rules_exports);
|
|
30
|
+
var RULE = {
|
|
31
|
+
envNotPublic: 9101,
|
|
32
|
+
serverReadInBrowser: 9102,
|
|
33
|
+
importMetaEnv: 9103,
|
|
34
|
+
secretInEnvPublic: 9104,
|
|
35
|
+
secretInBrowser: 9105,
|
|
36
|
+
audienceUnchecked: 9106,
|
|
37
|
+
weakAlgorithm: 9107,
|
|
38
|
+
dpopBareVerify: 9108,
|
|
39
|
+
guardWithoutRoles: 9109,
|
|
40
|
+
weakCookie: 9110,
|
|
41
|
+
localStorageTokens: 9111
|
|
42
|
+
};
|
|
43
|
+
var SECRETISH = /(SECRET|PASSWORD|PASSWD|PRIVATE_KEY|CLIENT_SECRET|CREDENTIALS?)($|_)/;
|
|
44
|
+
var VITE_BUILTINS = /* @__PURE__ */ new Set(["DEV", "PROD", "SSR", "MODE", "BASE_URL"]);
|
|
45
|
+
function isServerFile(fileName) {
|
|
46
|
+
const f = fileName.replace(/\\/g, "/");
|
|
47
|
+
return /\.server\.[cm]?[jt]sx?$/.test(f) || /\/src\/api\//.test(f) || /\/src\/middleware\.[cm]?[jt]s$/.test(f) || /\/(fluixi|vite)\.config\.[cm]?[jt]s$/.test(f) || /\/src\/entry-server\.[cm]?[jt]sx?$/.test(f) || // Tests run under Node, never in a page.
|
|
48
|
+
/\.(spec|test)\.[cm]?[jt]sx?$/.test(f) || /\/(tests?|__tests__)\//.test(f);
|
|
49
|
+
}
|
|
50
|
+
function importsOf(ts, sf) {
|
|
51
|
+
const out = /* @__PURE__ */ new Map();
|
|
52
|
+
for (const stmt of sf.statements) {
|
|
53
|
+
if (!ts.isImportDeclaration(stmt) || !ts.isStringLiteral(stmt.moduleSpecifier)) continue;
|
|
54
|
+
const bindings = stmt.importClause?.namedBindings;
|
|
55
|
+
if (!bindings || !ts.isNamedImports(bindings)) continue;
|
|
56
|
+
for (const el of bindings.elements) {
|
|
57
|
+
out.set(el.name.text, { module: stmt.moduleSpecifier.text, name: (el.propertyName ?? el.name).text });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
function sideOf(ts, test) {
|
|
63
|
+
if (ts.isParenthesizedExpression(test)) return sideOf(ts, test.expression);
|
|
64
|
+
if (ts.isPrefixUnaryExpression(test) && test.operator === ts.SyntaxKind.ExclamationToken) {
|
|
65
|
+
const inner = sideOf(ts, test.operand);
|
|
66
|
+
return inner === "server" ? "browser" : inner === "browser" ? "server" : null;
|
|
67
|
+
}
|
|
68
|
+
if (ts.isPropertyAccessExpression(test) && test.name.text === "SSR" && ts.isPropertyAccessExpression(test.expression) && test.expression.name.text === "env" && ts.isMetaProperty(test.expression.expression)) {
|
|
69
|
+
return "server";
|
|
70
|
+
}
|
|
71
|
+
if (ts.isBinaryExpression(test)) {
|
|
72
|
+
const op = test.operatorToken.kind;
|
|
73
|
+
const eq = op === ts.SyntaxKind.EqualsEqualsEqualsToken || op === ts.SyntaxKind.EqualsEqualsToken;
|
|
74
|
+
const ne = op === ts.SyntaxKind.ExclamationEqualsEqualsToken || op === ts.SyntaxKind.ExclamationEqualsToken;
|
|
75
|
+
if (!eq && !ne) return null;
|
|
76
|
+
const typeofGlobal = (n) => ts.isTypeOfExpression(n) && ts.isIdentifier(n.expression) && ["window", "document"].includes(n.expression.text);
|
|
77
|
+
const undef = (n) => ts.isStringLiteral(n) && n.text === "undefined";
|
|
78
|
+
if (typeofGlobal(test.left) && undef(test.right) || typeofGlobal(test.right) && undef(test.left)) {
|
|
79
|
+
return eq ? "server" : "browser";
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
var isUseServer = (ts, body) => {
|
|
85
|
+
if (!body || !ts.isBlock(body)) return false;
|
|
86
|
+
const first = body.statements[0];
|
|
87
|
+
return !!first && ts.isExpressionStatement(first) && ts.isStringLiteral(first.expression) && first.expression.text === "use server";
|
|
88
|
+
};
|
|
89
|
+
function inServerContext(ts, node, sf) {
|
|
90
|
+
const first = sf.statements[0];
|
|
91
|
+
if (first && ts.isExpressionStatement(first) && ts.isStringLiteral(first.expression) && first.expression.text === "use server") {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
for (let child = node, parent = node.parent; parent; child = parent, parent = parent.parent) {
|
|
95
|
+
if ((ts.isFunctionDeclaration(parent) || ts.isFunctionExpression(parent) || ts.isArrowFunction(parent)) && isUseServer(ts, parent.body)) {
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
if (ts.isIfStatement(parent) || ts.isConditionalExpression(parent)) {
|
|
99
|
+
const side = sideOf(ts, ts.isIfStatement(parent) ? parent.expression : parent.condition);
|
|
100
|
+
const whenTrue = ts.isIfStatement(parent) ? parent.thenStatement : parent.whenTrue;
|
|
101
|
+
const whenFalse = ts.isIfStatement(parent) ? parent.elseStatement : parent.whenFalse;
|
|
102
|
+
if (side === "server" && child === whenTrue) return true;
|
|
103
|
+
if (side === "browser" && child === whenFalse) return true;
|
|
104
|
+
}
|
|
105
|
+
if (ts.isBinaryExpression(parent) && parent.operatorToken.kind === ts.SyntaxKind.AmpersandAmpersandToken && child === parent.right && sideOf(ts, parent.left) === "server") {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
function publicEnvNames(ts, program, fileName, host) {
|
|
112
|
+
const checker = program.getTypeChecker();
|
|
113
|
+
let moduleSymbol;
|
|
114
|
+
if (host) {
|
|
115
|
+
const resolved = ts.resolveModuleName("@fluixi/start/env", fileName, program.getCompilerOptions(), host).resolvedModule;
|
|
116
|
+
const target = resolved && program.getSourceFile(resolved.resolvedFileName);
|
|
117
|
+
if (target) moduleSymbol = checker.getSymbolAtLocation(target);
|
|
118
|
+
}
|
|
119
|
+
moduleSymbol ??= checker.getAmbientModules().find((m) => m.name.replace(/"/g, "") === "@fluixi/start/env");
|
|
120
|
+
const iface = moduleSymbol && checker.getExportsOfModule(moduleSymbol).find((s) => s.name === "PublicEnv");
|
|
121
|
+
if (!iface) return null;
|
|
122
|
+
const names = checker.getPropertiesOfType(checker.getDeclaredTypeOfSymbol(iface)).map((p) => p.name);
|
|
123
|
+
return names.length ? new Set(names) : null;
|
|
124
|
+
}
|
|
125
|
+
var propsOf = (ts, obj) => {
|
|
126
|
+
const map = /* @__PURE__ */ new Map();
|
|
127
|
+
for (const p of obj.properties) {
|
|
128
|
+
if (ts.isPropertyAssignment(p) && (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name))) map.set(p.name.text, p);
|
|
129
|
+
}
|
|
130
|
+
return map;
|
|
131
|
+
};
|
|
132
|
+
var isFalse = (ts, e) => !!e && e.kind === ts.SyntaxKind.FalseKeyword;
|
|
133
|
+
var OAUTH_CONFIG_CALLS = /* @__PURE__ */ new Set([
|
|
134
|
+
"createAuthService",
|
|
135
|
+
"createBrowserClient",
|
|
136
|
+
"createServerClient",
|
|
137
|
+
"createServiceClient",
|
|
138
|
+
"createTokenIntrospector",
|
|
139
|
+
"oauthRoutes",
|
|
140
|
+
"authServerModule",
|
|
141
|
+
"sessionLocals"
|
|
142
|
+
]);
|
|
143
|
+
function envAuthDiagnostics(ts, program, fileName, host) {
|
|
144
|
+
const sf = program.getSourceFile(fileName);
|
|
145
|
+
if (!sf || sf.isDeclarationFile || /[\\/]node_modules[\\/]/.test(fileName)) return [];
|
|
146
|
+
const text = sf.text;
|
|
147
|
+
const isConfig = /[\\/]fluixi\.config\.[cm]?[jt]s$/.test(fileName);
|
|
148
|
+
if (!isConfig && !/fluixi|\$env|import\.meta\.env|process\.env/.test(text)) return [];
|
|
149
|
+
const out = [];
|
|
150
|
+
const add = (node, code, category, messageText) => out.push({ start: node.getStart(sf), length: node.getWidth(sf), code, category, messageText, source: "fluixi" });
|
|
151
|
+
const imports = importsOf(ts, sf);
|
|
152
|
+
const serverFile = isServerFile(fileName);
|
|
153
|
+
const browserSide = (node) => !serverFile && !inServerContext(ts, node, sf);
|
|
154
|
+
const fromModule = (callee, prefix) => {
|
|
155
|
+
if (!ts.isIdentifier(callee)) return null;
|
|
156
|
+
const hit = imports.get(callee.text);
|
|
157
|
+
return hit && (hit.module === prefix || hit.module.startsWith(prefix + "/")) ? hit.name : null;
|
|
158
|
+
};
|
|
159
|
+
let publicNames;
|
|
160
|
+
const isPublic = (key) => {
|
|
161
|
+
if (publicNames === void 0) publicNames = publicEnvNames(ts, program, fileName, host);
|
|
162
|
+
return publicNames === null || publicNames.has(key) || key.startsWith("VITE_");
|
|
163
|
+
};
|
|
164
|
+
const envNotPublic = (lit) => {
|
|
165
|
+
if (!browserSide(lit) || isPublic(lit.text)) return;
|
|
166
|
+
add(
|
|
167
|
+
lit,
|
|
168
|
+
RULE.envNotPublic,
|
|
169
|
+
ts.DiagnosticCategory.Warning,
|
|
170
|
+
`${lit.text} is not in env.public, so the browser has no value for it, and the build refuses this read in browser code. If it is public, add it to env.public in fluixi.config.ts. If it is a secret, read it on the server and pass the page what it needs.`
|
|
171
|
+
);
|
|
172
|
+
};
|
|
173
|
+
const dpopVerifiers = /* @__PURE__ */ new Set();
|
|
174
|
+
const guardsWithoutRoles = /* @__PURE__ */ new Set();
|
|
175
|
+
const visit = (node) => {
|
|
176
|
+
if (ts.isCallExpression(node)) {
|
|
177
|
+
const callee = node.expression;
|
|
178
|
+
const envFn = ts.isIdentifier(callee) && callee.text === "$env" ? "env" : fromModule(callee, "@fluixi/start");
|
|
179
|
+
const oauthFn = fromModule(callee, "@fluixi/oauth2");
|
|
180
|
+
const sessionFn = fromModule(callee, "@fluixi/session");
|
|
181
|
+
const arg0 = node.arguments[0];
|
|
182
|
+
if (envFn === "env" && arg0 && ts.isStringLiteral(arg0)) envNotPublic(arg0);
|
|
183
|
+
if (envFn === "pickEnv" && arg0 && ts.isObjectLiteralExpression(arg0)) {
|
|
184
|
+
for (const p of arg0.properties) {
|
|
185
|
+
if (!ts.isPropertyAssignment(p)) continue;
|
|
186
|
+
if (ts.isStringLiteral(p.initializer)) envNotPublic(p.initializer);
|
|
187
|
+
else if (ts.isObjectLiteralExpression(p.initializer)) {
|
|
188
|
+
const key = propsOf(ts, p.initializer).get("key")?.initializer;
|
|
189
|
+
if (key && ts.isStringLiteral(key)) envNotPublic(key);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (envFn === "serverEnv" && browserSide(node)) {
|
|
194
|
+
add(
|
|
195
|
+
callee,
|
|
196
|
+
RULE.serverReadInBrowser,
|
|
197
|
+
ts.DiagnosticCategory.Warning,
|
|
198
|
+
'serverEnv() in code the browser runs throws there: server-only values are not in the bundle. Read it in an API route, middleware or a "use server" function.'
|
|
199
|
+
);
|
|
200
|
+
}
|
|
201
|
+
if (ts.isIdentifier(callee) && dpopVerifiers.has(callee.text)) {
|
|
202
|
+
add(
|
|
203
|
+
callee,
|
|
204
|
+
RULE.dpopBareVerify,
|
|
205
|
+
ts.DiagnosticCategory.Error,
|
|
206
|
+
`${callee.text} requires DPoP, and a bare token carries no proof, so every call is refused. Use ${callee.text}.fromRequest(request).`
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
if (ts.isIdentifier(callee) && guardsWithoutRoles.has(callee.text)) {
|
|
210
|
+
const req = node.arguments[1];
|
|
211
|
+
if (req && ts.isObjectLiteralExpression(req)) {
|
|
212
|
+
const props = propsOf(ts, req);
|
|
213
|
+
const role = props.get("role") ?? props.get("allRoles");
|
|
214
|
+
if (role) {
|
|
215
|
+
add(
|
|
216
|
+
role.name,
|
|
217
|
+
RULE.guardWithoutRoles,
|
|
218
|
+
ts.DiagnosticCategory.Error,
|
|
219
|
+
`${callee.text} was built without \`roles\`, so a role requirement throws on the first request. Pass one of rolesFrom to createApiGuard.`
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const configs = [];
|
|
225
|
+
if (oauthFn && OAUTH_CONFIG_CALLS.has(oauthFn) || oauthFn === "createTokenVerifier" || sessionFn === "createSessionCookie") {
|
|
226
|
+
if (arg0 && ts.isObjectLiteralExpression(arg0)) {
|
|
227
|
+
configs.push(arg0);
|
|
228
|
+
const nested = propsOf(ts, arg0).get("config")?.initializer;
|
|
229
|
+
if (oauthFn === "createAuthService" && nested && ts.isObjectLiteralExpression(nested)) configs.push(nested);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const obj of configs) {
|
|
233
|
+
const props = propsOf(ts, obj);
|
|
234
|
+
const tokens = props.get("tokens")?.initializer;
|
|
235
|
+
const browserTokens = tokens && ts.isStringLiteral(tokens) && tokens.text === "browser" || oauthFn === "createBrowserClient";
|
|
236
|
+
for (const secret of ["clientSecret", "privateKey"]) {
|
|
237
|
+
const p = props.get(secret);
|
|
238
|
+
if (p && (browserTokens || browserSide(p) && oauthFn !== "createTokenVerifier")) {
|
|
239
|
+
add(
|
|
240
|
+
p.name,
|
|
241
|
+
RULE.secretInBrowser,
|
|
242
|
+
ts.DiagnosticCategory.Error,
|
|
243
|
+
`${secret} in ${browserTokens ? "a tokens: 'browser' client" : "code the browser runs"} ships to every visitor, and anything shipped to a browser is not a secret. A browser client uses PKCE without one; keep ${secret} on the server.`
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
if (oauthFn === "createTokenVerifier") {
|
|
248
|
+
const audience = props.get("audience");
|
|
249
|
+
if (audience && isFalse(ts, audience.initializer) && !props.has("authorizedParty") && !props.has("require")) {
|
|
250
|
+
add(
|
|
251
|
+
audience,
|
|
252
|
+
RULE.audienceUnchecked,
|
|
253
|
+
ts.DiagnosticCategory.Warning,
|
|
254
|
+
"audience: false with no authorizedParty or require accepts a token minted for any client of the same issuer. Pin authorizedParty to your client id, or check a claim in require."
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
const algs = props.get("algorithms")?.initializer;
|
|
258
|
+
if (algs && ts.isArrayLiteralExpression(algs)) {
|
|
259
|
+
for (const el of algs.elements) {
|
|
260
|
+
if (ts.isStringLiteral(el) && (/^HS/.test(el.text) || el.text === "none")) {
|
|
261
|
+
add(
|
|
262
|
+
el,
|
|
263
|
+
RULE.weakAlgorithm,
|
|
264
|
+
ts.DiagnosticCategory.Error,
|
|
265
|
+
el.text === "none" ? '"none" accepts an unsigned token as valid.' : `${el.text} verifies with a shared secret; with a provider's public key it lets anyone who has that key sign tokens. Use RS256 or ES256.`
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
const cookieKey = props.get(sessionFn === "createSessionCookie" ? "secret" : "cookieSecret");
|
|
272
|
+
if (cookieKey && ts.isStringLiteral(cookieKey.initializer) && cookieKey.initializer.text.length < 32) {
|
|
273
|
+
add(
|
|
274
|
+
cookieKey.initializer,
|
|
275
|
+
RULE.weakCookie,
|
|
276
|
+
ts.DiagnosticCategory.Error,
|
|
277
|
+
"The session cookie is encrypted with a key derived from this, and under 32 characters it is short enough to guess. Read a long random value with serverEnv."
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
const secure = props.get(sessionFn === "createSessionCookie" ? "secure" : "secureCookie");
|
|
281
|
+
if (secure && isFalse(ts, secure.initializer)) {
|
|
282
|
+
add(
|
|
283
|
+
secure,
|
|
284
|
+
RULE.weakCookie,
|
|
285
|
+
ts.DiagnosticCategory.Warning,
|
|
286
|
+
"The session cookie will also be sent over plain http. Keep this for local work only: derive it, e.g. from whether the app URL is https."
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
const storage = props.get("storage")?.initializer;
|
|
290
|
+
if (storage && ts.isStringLiteral(storage) && storage.text === "local" && browserTokens) {
|
|
291
|
+
add(
|
|
292
|
+
storage,
|
|
293
|
+
RULE.localStorageTokens,
|
|
294
|
+
ts.DiagnosticCategory.Suggestion,
|
|
295
|
+
"storage: 'local' keeps the refresh token after the tab closes, so injected script can reach it for longer. 'session', the default, ends with the tab."
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
301
|
+
const obj = node.expression;
|
|
302
|
+
if (ts.isIdentifier(obj) && obj.text === "process" && node.name.text === "env" && browserSide(node)) {
|
|
303
|
+
add(
|
|
304
|
+
node,
|
|
305
|
+
RULE.serverReadInBrowser,
|
|
306
|
+
ts.DiagnosticCategory.Warning,
|
|
307
|
+
"process.env does not exist in the browser. Use $env('NAME'), which reads the public set there and anything on the server."
|
|
308
|
+
);
|
|
309
|
+
}
|
|
310
|
+
if (ts.isPropertyAccessExpression(obj) && obj.name.text === "env" && ts.isMetaProperty(obj.expression) && !VITE_BUILTINS.has(node.name.text) && !node.name.text.startsWith("VITE_")) {
|
|
311
|
+
add(
|
|
312
|
+
node,
|
|
313
|
+
RULE.importMetaEnv,
|
|
314
|
+
ts.DiagnosticCategory.Warning,
|
|
315
|
+
`import.meta.env.${node.name.text} is undefined in the browser: Vite only defines VITE_ names there. Use $env('${node.name.text}') and declare it in env.public if it is public.`
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (/[\\/]fluixi\.config\.[cm]?[jt]s$/.test(fileName) && ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "public" && ts.isArrayLiteralExpression(node.initializer) && ts.isObjectLiteralExpression(node.parent) && ts.isPropertyAssignment(node.parent.parent) && ts.isIdentifier(node.parent.parent.name) && node.parent.parent.name.text === "env") {
|
|
320
|
+
for (const el of node.initializer.elements) {
|
|
321
|
+
if (ts.isStringLiteral(el) && SECRETISH.test(el.text)) {
|
|
322
|
+
add(
|
|
323
|
+
el,
|
|
324
|
+
RULE.secretInEnvPublic,
|
|
325
|
+
ts.DiagnosticCategory.Error,
|
|
326
|
+
`${el.text} reads like a secret, and env.public puts its value in the browser bundle; the build refuses it. Remove it and read it with serverEnv() on the server. If the name only looks like a secret, set FLUIXI_ALLOW_PUBLIC_SECRETS=true.`
|
|
327
|
+
);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
ts.forEachChild(node, visit);
|
|
332
|
+
};
|
|
333
|
+
const collect = (node) => {
|
|
334
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name) && node.initializer && ts.isCallExpression(node.initializer)) {
|
|
335
|
+
const fn = fromModule(node.initializer.expression, "@fluixi/oauth2");
|
|
336
|
+
const opts = node.initializer.arguments[0];
|
|
337
|
+
if (opts && ts.isObjectLiteralExpression(opts)) {
|
|
338
|
+
const props = propsOf(ts, opts);
|
|
339
|
+
if (fn === "createTokenVerifier" && props.get("dpop")?.initializer.kind === ts.SyntaxKind.TrueKeyword) dpopVerifiers.add(node.name.text);
|
|
340
|
+
if (fn === "createApiGuard" && !props.has("roles") && !opts.properties.some((p) => ts.isSpreadAssignment(p))) {
|
|
341
|
+
guardsWithoutRoles.add(node.name.text);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
ts.forEachChild(node, collect);
|
|
346
|
+
};
|
|
347
|
+
collect(sf);
|
|
348
|
+
visit(sf);
|
|
349
|
+
return out.map((d) => ({ ...d, file: sf }));
|
|
350
|
+
}
|
|
351
|
+
var CONFIG_NAMES = ["fluixi.config.ts", "fluixi.config.mts", "fluixi.config.js", "fluixi.config.mjs"];
|
|
352
|
+
function findConfig(fileName, host) {
|
|
353
|
+
let dir = fileName.replace(/\\/g, "/").replace(/\/[^/]*$/, "");
|
|
354
|
+
for (; ; ) {
|
|
355
|
+
for (const name of CONFIG_NAMES) if (host.fileExists(`${dir}/${name}`)) return `${dir}/${name}`;
|
|
356
|
+
const up = dir.replace(/\/[^/]*$/, "");
|
|
357
|
+
if (!up || up === dir) return null;
|
|
358
|
+
dir = up;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
function envPublicFix(ts, program, fileName, position, host) {
|
|
362
|
+
const sf = program.getSourceFile(fileName);
|
|
363
|
+
if (!sf) return null;
|
|
364
|
+
let literal;
|
|
365
|
+
const find = (node) => {
|
|
366
|
+
if (literal || position < node.getFullStart() || position > node.getEnd()) return;
|
|
367
|
+
if (ts.isStringLiteral(node) && position >= node.getStart(sf) && position <= node.getEnd()) literal = node;
|
|
368
|
+
else ts.forEachChild(node, find);
|
|
369
|
+
};
|
|
370
|
+
find(sf);
|
|
371
|
+
if (!literal || SECRETISH.test(literal.text)) return null;
|
|
372
|
+
const configPath = findConfig(fileName, host);
|
|
373
|
+
const configText = configPath && host.readFile(configPath);
|
|
374
|
+
if (!configPath || !configText) return null;
|
|
375
|
+
const config = ts.createSourceFile(configPath, configText, ts.ScriptTarget.Latest, true);
|
|
376
|
+
let list;
|
|
377
|
+
const search = (node) => {
|
|
378
|
+
if (ts.isPropertyAssignment(node) && ts.isIdentifier(node.name) && node.name.text === "public" && ts.isArrayLiteralExpression(node.initializer) && ts.isPropertyAssignment(node.parent.parent) && ts.isIdentifier(node.parent.parent.name) && node.parent.parent.name.text === "env") {
|
|
379
|
+
list = node.initializer;
|
|
380
|
+
}
|
|
381
|
+
if (!list) ts.forEachChild(node, search);
|
|
382
|
+
};
|
|
383
|
+
search(config);
|
|
384
|
+
if (!list) return null;
|
|
385
|
+
const quote = list.elements.find(ts.isStringLiteral)?.getText(config).startsWith('"') ? '"' : "'";
|
|
386
|
+
const entry = `${quote}${literal.text}${quote}`;
|
|
387
|
+
const last = list.elements[list.elements.length - 1];
|
|
388
|
+
let change;
|
|
389
|
+
if (!last) {
|
|
390
|
+
change = { span: { start: list.getStart(config) + 1, length: 0 }, newText: entry };
|
|
391
|
+
} else {
|
|
392
|
+
const multiline = configText.slice(list.getStart(config), last.getStart(config)).includes("\n");
|
|
393
|
+
const lineStart = configText.lastIndexOf("\n", last.getStart(config)) + 1;
|
|
394
|
+
const indent = configText.slice(lineStart, last.getStart(config));
|
|
395
|
+
const trailingComma = list.elements.hasTrailingComma;
|
|
396
|
+
const at = trailingComma ? configText.indexOf(",", last.getEnd()) + 1 : last.getEnd();
|
|
397
|
+
const lead = trailingComma ? "" : ",";
|
|
398
|
+
change = {
|
|
399
|
+
span: { start: at, length: 0 },
|
|
400
|
+
newText: multiline ? `${lead}
|
|
401
|
+
${indent}${entry}${trailingComma ? "," : ""}` : `${lead} ${entry}`
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
return {
|
|
405
|
+
fixName: "fluixiAddEnvPublic",
|
|
406
|
+
description: `Add ${literal.text} to env.public`,
|
|
407
|
+
changes: [{ fileName: configPath, textChanges: [change] }]
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
411
|
+
0 && (module.exports = {
|
|
412
|
+
RULE,
|
|
413
|
+
envAuthDiagnostics,
|
|
414
|
+
envPublicFix,
|
|
415
|
+
isServerFile,
|
|
416
|
+
publicEnvNames
|
|
417
|
+
});
|