@showrun/core 0.1.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.
Files changed (74) hide show
  1. package/LICENSE +21 -0
  2. package/dist/__tests__/dsl-validation.test.d.ts +2 -0
  3. package/dist/__tests__/dsl-validation.test.d.ts.map +1 -0
  4. package/dist/__tests__/dsl-validation.test.js +203 -0
  5. package/dist/__tests__/pack-versioning.test.d.ts +2 -0
  6. package/dist/__tests__/pack-versioning.test.d.ts.map +1 -0
  7. package/dist/__tests__/pack-versioning.test.js +165 -0
  8. package/dist/__tests__/validator.test.d.ts +2 -0
  9. package/dist/__tests__/validator.test.d.ts.map +1 -0
  10. package/dist/__tests__/validator.test.js +149 -0
  11. package/dist/authResilience.d.ts +146 -0
  12. package/dist/authResilience.d.ts.map +1 -0
  13. package/dist/authResilience.js +378 -0
  14. package/dist/browserLauncher.d.ts +74 -0
  15. package/dist/browserLauncher.d.ts.map +1 -0
  16. package/dist/browserLauncher.js +159 -0
  17. package/dist/browserPersistence.d.ts +49 -0
  18. package/dist/browserPersistence.d.ts.map +1 -0
  19. package/dist/browserPersistence.js +143 -0
  20. package/dist/context.d.ts +10 -0
  21. package/dist/context.d.ts.map +1 -0
  22. package/dist/context.js +30 -0
  23. package/dist/dsl/builders.d.ts +340 -0
  24. package/dist/dsl/builders.d.ts.map +1 -0
  25. package/dist/dsl/builders.js +416 -0
  26. package/dist/dsl/conditions.d.ts +33 -0
  27. package/dist/dsl/conditions.d.ts.map +1 -0
  28. package/dist/dsl/conditions.js +169 -0
  29. package/dist/dsl/interpreter.d.ts +24 -0
  30. package/dist/dsl/interpreter.d.ts.map +1 -0
  31. package/dist/dsl/interpreter.js +491 -0
  32. package/dist/dsl/stepHandlers.d.ts +32 -0
  33. package/dist/dsl/stepHandlers.d.ts.map +1 -0
  34. package/dist/dsl/stepHandlers.js +787 -0
  35. package/dist/dsl/target.d.ts +28 -0
  36. package/dist/dsl/target.d.ts.map +1 -0
  37. package/dist/dsl/target.js +110 -0
  38. package/dist/dsl/templating.d.ts +21 -0
  39. package/dist/dsl/templating.d.ts.map +1 -0
  40. package/dist/dsl/templating.js +73 -0
  41. package/dist/dsl/types.d.ts +695 -0
  42. package/dist/dsl/types.d.ts.map +1 -0
  43. package/dist/dsl/types.js +7 -0
  44. package/dist/dsl/validation.d.ts +15 -0
  45. package/dist/dsl/validation.d.ts.map +1 -0
  46. package/dist/dsl/validation.js +974 -0
  47. package/dist/index.d.ts +20 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +20 -0
  50. package/dist/jsonPackValidator.d.ts +11 -0
  51. package/dist/jsonPackValidator.d.ts.map +1 -0
  52. package/dist/jsonPackValidator.js +61 -0
  53. package/dist/loader.d.ts +35 -0
  54. package/dist/loader.d.ts.map +1 -0
  55. package/dist/loader.js +107 -0
  56. package/dist/networkCapture.d.ts +107 -0
  57. package/dist/networkCapture.d.ts.map +1 -0
  58. package/dist/networkCapture.js +390 -0
  59. package/dist/packUtils.d.ts +36 -0
  60. package/dist/packUtils.d.ts.map +1 -0
  61. package/dist/packUtils.js +97 -0
  62. package/dist/packVersioning.d.ts +25 -0
  63. package/dist/packVersioning.d.ts.map +1 -0
  64. package/dist/packVersioning.js +137 -0
  65. package/dist/runner.d.ts +62 -0
  66. package/dist/runner.d.ts.map +1 -0
  67. package/dist/runner.js +170 -0
  68. package/dist/types.d.ts +336 -0
  69. package/dist/types.d.ts.map +1 -0
  70. package/dist/types.js +1 -0
  71. package/dist/validator.d.ts +20 -0
  72. package/dist/validator.d.ts.map +1 -0
  73. package/dist/validator.js +68 -0
  74. package/package.json +49 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Target resolution utilities
3
+ * Converts Target types to Playwright Locators
4
+ */
5
+ import type { Locator, Page, Frame } from 'playwright';
6
+ import type { Target, TargetOrAnyOf } from './types.js';
7
+ /**
8
+ * Type that can resolve locators (Page, Frame, or Locator)
9
+ */
10
+ export type LocatorSource = Page | Frame | Locator;
11
+ /**
12
+ * Resolves a single Target to a Playwright Locator
13
+ */
14
+ export declare function resolveTarget(source: LocatorSource, target: Target): Locator;
15
+ /**
16
+ * Resolves TargetOrAnyOf with fallback support
17
+ * Tries each target in order until one yields at least one element
18
+ */
19
+ export declare function resolveTargetWithFallback(source: LocatorSource, targetOrAnyOf: TargetOrAnyOf, scope?: Target): Promise<{
20
+ locator: Locator;
21
+ matchedTarget: Target;
22
+ matchedCount: number;
23
+ }>;
24
+ /**
25
+ * Converts legacy selector string to Target for backward compatibility
26
+ */
27
+ export declare function selectorToTarget(selector: string): Target;
28
+ //# sourceMappingURL=target.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"target.d.ts","sourceRoot":"","sources":["../../src/dsl/target.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAExD;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,IAAI,GAAG,KAAK,GAAG,OAAO,CAAC;AAgBnD;;GAEG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,aAAa,EACrB,MAAM,EAAE,MAAM,GACb,OAAO,CAmDT;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,MAAM,EAAE,aAAa,EACrB,aAAa,EAAE,aAAa,EAC5B,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC,CAgC5E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzD"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Target resolution utilities
3
+ * Converts Target types to Playwright Locators
4
+ */
5
+ /**
6
+ * Check if the source is a Page (has goto method)
7
+ */
8
+ function isPage(source) {
9
+ return 'goto' in source && typeof source.goto === 'function';
10
+ }
11
+ /**
12
+ * Check if the source is a Frame (has url method but not goto)
13
+ */
14
+ function isFrame(source) {
15
+ return 'url' in source && typeof source.url === 'function' && !('goto' in source);
16
+ }
17
+ /**
18
+ * Resolves a single Target to a Playwright Locator
19
+ */
20
+ export function resolveTarget(source, target) {
21
+ // Check if it's a Page or Frame (both have similar locator methods)
22
+ if (isPage(source) || isFrame(source)) {
23
+ switch (target.kind) {
24
+ case 'css':
25
+ return source.locator(target.selector);
26
+ case 'text':
27
+ return source.getByText(target.text, { exact: target.exact ?? false });
28
+ case 'role':
29
+ return source.getByRole(target.role, {
30
+ name: target.name,
31
+ exact: target.exact ?? false,
32
+ });
33
+ case 'label':
34
+ return source.getByLabel(target.text, { exact: target.exact ?? false });
35
+ case 'placeholder':
36
+ return source.getByPlaceholder(target.text, { exact: target.exact ?? false });
37
+ case 'altText':
38
+ return source.getByAltText(target.text, { exact: target.exact ?? false });
39
+ case 'testId':
40
+ return source.getByTestId(target.id);
41
+ default:
42
+ const _exhaustive = target;
43
+ throw new Error(`Unknown target kind: ${_exhaustive.kind}`);
44
+ }
45
+ }
46
+ else {
47
+ // It's a Locator
48
+ const locator = source;
49
+ switch (target.kind) {
50
+ case 'css':
51
+ return locator.locator(target.selector);
52
+ case 'text':
53
+ return locator.getByText(target.text, { exact: target.exact ?? false });
54
+ case 'role':
55
+ return locator.getByRole(target.role, {
56
+ name: target.name,
57
+ exact: target.exact ?? false,
58
+ });
59
+ case 'label':
60
+ return locator.getByLabel(target.text, { exact: target.exact ?? false });
61
+ case 'placeholder':
62
+ return locator.getByPlaceholder(target.text, { exact: target.exact ?? false });
63
+ case 'altText':
64
+ return locator.getByAltText(target.text, { exact: target.exact ?? false });
65
+ case 'testId':
66
+ return locator.getByTestId(target.id);
67
+ default:
68
+ const _exhaustive = target;
69
+ throw new Error(`Unknown target kind: ${_exhaustive.kind}`);
70
+ }
71
+ }
72
+ }
73
+ /**
74
+ * Resolves TargetOrAnyOf with fallback support
75
+ * Tries each target in order until one yields at least one element
76
+ */
77
+ export async function resolveTargetWithFallback(source, targetOrAnyOf, scope) {
78
+ // Resolve scope first if provided
79
+ const baseLocator = scope ? resolveTarget(source, scope) : source;
80
+ // Handle single target
81
+ if (!('anyOf' in targetOrAnyOf)) {
82
+ const locator = resolveTarget(baseLocator, targetOrAnyOf);
83
+ const count = await locator.count();
84
+ return { locator, matchedTarget: targetOrAnyOf, matchedCount: count };
85
+ }
86
+ // Handle anyOf fallback
87
+ const targets = targetOrAnyOf.anyOf;
88
+ let lastError = null;
89
+ for (const target of targets) {
90
+ try {
91
+ const locator = resolveTarget(baseLocator, target);
92
+ const count = await locator.count();
93
+ if (count > 0) {
94
+ return { locator, matchedTarget: target, matchedCount: count };
95
+ }
96
+ }
97
+ catch (error) {
98
+ lastError = error instanceof Error ? error : new Error(String(error));
99
+ // Continue to next target
100
+ }
101
+ }
102
+ // None matched
103
+ throw new Error(`No target matched. Tried ${targets.length} target(s). ${lastError ? `Last error: ${lastError.message}` : ''}`);
104
+ }
105
+ /**
106
+ * Converts legacy selector string to Target for backward compatibility
107
+ */
108
+ export function selectorToTarget(selector) {
109
+ return { kind: 'css', selector };
110
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Templating for DSL steps using Nunjucks renderString only.
3
+ * Supports {{inputs.key}} / {{vars.key}} and built-in filters (e.g. {{inputs.x | urlencode}}).
4
+ * Uses a minimal Environment with no loaders. Custom filters are limited to safe, pure functions.
5
+ */
6
+ import type { VariableContext } from './types.js';
7
+ /**
8
+ * Resolves a template string using variable context (Nunjucks renderString).
9
+ * Built-in filters available, e.g. {{ inputs.page | urlencode }}.
10
+ * Supports: {{inputs.x}}, {{vars.x}}, {{secret.x}}
11
+ */
12
+ export declare function resolveTemplate(template: string, context: VariableContext): string;
13
+ /**
14
+ * Recursively resolves templates in an object (strings use Nunjucks renderString).
15
+ */
16
+ export declare function resolveTemplates<T>(obj: T, context: VariableContext): T;
17
+ /**
18
+ * Checks if a string contains template syntax ({{ ... }}).
19
+ */
20
+ export declare function hasTemplate(str: string): boolean;
21
+ //# sourceMappingURL=templating.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/dsl/templating.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA0BlD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,GAAG,MAAM,CAWlF;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,GAAG,CAAC,CAkBvE;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAEhD"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Templating for DSL steps using Nunjucks renderString only.
3
+ * Supports {{inputs.key}} / {{vars.key}} and built-in filters (e.g. {{inputs.x | urlencode}}).
4
+ * Uses a minimal Environment with no loaders. Custom filters are limited to safe, pure functions.
5
+ */
6
+ import nunjucks from 'nunjucks';
7
+ import { authenticator } from 'otplib';
8
+ /** Minimal env: null loader (renderString only), allow undefined for optional inputs. */
9
+ const env = new nunjucks.Environment(null, {
10
+ autoescape: false,
11
+ throwOnUndefined: false, // Allow undefined values to render as empty string
12
+ });
13
+ /**
14
+ * TOTP filter: generates a 6-digit TOTP code from a base32 secret.
15
+ * Usage: {{secret.TOTP_KEY | totp}}
16
+ *
17
+ * This is a pure function (RFC 6238) - no code execution risk.
18
+ */
19
+ env.addFilter('totp', (secret) => {
20
+ if (!secret || typeof secret !== 'string') {
21
+ throw new Error('totp filter requires a non-empty string (base32 secret)');
22
+ }
23
+ try {
24
+ return authenticator.generate(secret.trim().replace(/\s/g, ''));
25
+ }
26
+ catch (err) {
27
+ const msg = err instanceof Error ? err.message : String(err);
28
+ throw new Error(`TOTP generation failed: ${msg}`);
29
+ }
30
+ });
31
+ /**
32
+ * Resolves a template string using variable context (Nunjucks renderString).
33
+ * Built-in filters available, e.g. {{ inputs.page | urlencode }}.
34
+ * Supports: {{inputs.x}}, {{vars.x}}, {{secret.x}}
35
+ */
36
+ export function resolveTemplate(template, context) {
37
+ try {
38
+ return env.renderString(template, {
39
+ inputs: context.inputs,
40
+ vars: context.vars,
41
+ secret: context.secrets || {},
42
+ });
43
+ }
44
+ catch (err) {
45
+ const msg = err instanceof Error ? err.message : String(err);
46
+ throw new Error(`Template resolution failed: ${msg}`);
47
+ }
48
+ }
49
+ /**
50
+ * Recursively resolves templates in an object (strings use Nunjucks renderString).
51
+ */
52
+ export function resolveTemplates(obj, context) {
53
+ if (typeof obj === 'string') {
54
+ return resolveTemplate(obj, context);
55
+ }
56
+ if (Array.isArray(obj)) {
57
+ return obj.map((item) => resolveTemplates(item, context));
58
+ }
59
+ if (obj && typeof obj === 'object') {
60
+ const resolved = {};
61
+ for (const [key, value] of Object.entries(obj)) {
62
+ resolved[key] = resolveTemplates(value, context);
63
+ }
64
+ return resolved;
65
+ }
66
+ return obj;
67
+ }
68
+ /**
69
+ * Checks if a string contains template syntax ({{ ... }}).
70
+ */
71
+ export function hasTemplate(str) {
72
+ return typeof str === 'string' && str.includes('{{');
73
+ }