@capillarytech/cap-ui-utils 3.0.20 → 3.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.
@@ -0,0 +1,46 @@
1
+ /**
2
+ * Env-driven kill-switch that lets a module's automation be turned off without a
3
+ * code change or a CI job edit. In prod the value is injected into the runner
4
+ * container as a plain environment variable (sourced from AWS); locally it comes
5
+ * from `.env` (loaded once via `import 'dotenv/config'` in test/wdio.conf.ts).
6
+ *
7
+ * AUTOMATION_BYPASS_MODULES is a JSON array of module names, e.g.
8
+ * AUTOMATION_BYPASS_MODULES=["garudaUI","loyalty"]
9
+ * following the existing MODULES_WITH_AUTOMATION_CLEANUP convention. When the
10
+ * running `module` is in that list, the module's wdio config swaps its specs for
11
+ * test/bypass/automationBypassed.ts, which just logs and passes.
12
+ *
13
+ * Note this is unrelated to src/utils/featureFlagUtil.ts, which reads the app's
14
+ * in-browser feature flags and needs a live session; this gate runs at config
15
+ * load time, before any browser exists.
16
+ */
17
+ class AutomationBypass {
18
+ /**
19
+ * Parse AUTOMATION_BYPASS_MODULES into a module-name list. A malformed value
20
+ * must never break a run, so anything unparseable is logged and treated as
21
+ * "nothing bypassed".
22
+ */
23
+ private getBypassedModules(): string[] {
24
+ const raw = (process.env.AUTOMATION_BYPASS_MODULES || '').trim();
25
+ if (!raw) return [];
26
+ try {
27
+ const parsed = JSON.parse(raw);
28
+ if (!Array.isArray(parsed)) {
29
+ console.log(`[automation-bypass] AUTOMATION_BYPASS_MODULES must be a JSON array, got: ${raw}`);
30
+ return [];
31
+ }
32
+ return parsed.map((m) => String(m).trim()).filter(Boolean);
33
+ } catch (error) {
34
+ console.log(`[automation-bypass] Could not parse AUTOMATION_BYPASS_MODULES (${raw}): ${error}`);
35
+ return [];
36
+ }
37
+ }
38
+
39
+ /** True when the given module's automation should be bypassed. */
40
+ isBypassed(module: string | undefined = process.env.module): boolean {
41
+ if (!module) return false;
42
+ return this.getBypassedModules().includes(module);
43
+ }
44
+ }
45
+
46
+ export default new AutomationBypass();
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Central gate for the FULL_DEBUG capture feature (request-payload + screenshot
3
+ * recording) and, indirectly, for whether the devtools automation protocol is
4
+ * registered at all (see wdio.conf.ts).
5
+ *
6
+ * Capture is enabled only when FULL_DEBUG_MODE=true AND, if the optional
7
+ * DEBUG_MODULES list is provided, the current `module` is in that list.
8
+ *
9
+ * DEBUG_MODULES is a comma-separated list of module names, e.g.
10
+ * FULL_DEBUG_MODE=true DEBUG_MODULES=engage,creatives module=engage npx wdio ...
11
+ * captures only for `engage` and `creatives`. When DEBUG_MODULES is empty/unset,
12
+ * capture applies to every module (falls back to FULL_DEBUG_MODE alone).
13
+ */
14
+ class DebugMode {
15
+ /** Parse DEBUG_MODULES into a trimmed, non-empty module-name list. */
16
+ private getDebugModules(): string[] {
17
+ return (process.env.DEBUG_MODULES || '')
18
+ .split(',')
19
+ .map((m) => m.trim())
20
+ .filter(Boolean);
21
+ }
22
+
23
+ /** True when request/screenshot capture should run for the current module. */
24
+ isCaptureEnabled(): boolean {
25
+ if (process.env.FULL_DEBUG_MODE !== 'true') return false;
26
+ const modules = this.getDebugModules();
27
+ if (modules.length === 0) return true;
28
+ return modules.includes(process.env.module || '');
29
+ }
30
+ }
31
+
32
+ export default new DebugMode();
@@ -0,0 +1,15 @@
1
+ class DeletionRegistry {
2
+ private deleted = new Set<string>();
3
+
4
+ has(name: string): boolean {
5
+ return this.deleted.has(name);
6
+ }
7
+
8
+ register(name: string): void {
9
+ this.deleted.add(name);
10
+ console.log(`DeletionRegistry: registered "${name}"`);
11
+ }
12
+ }
13
+
14
+ const deletionRegistry = new DeletionRegistry();
15
+ export default deletionRegistry;