cyperful 0.2.0 → 0.3.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.
@@ -1,123 +1,188 @@
1
- (() => {
2
- if (window.__cyperfulAgentInitialized)
3
- return;
4
- window.__cyperfulAgentInitialized = !0;
5
- const f = console.log, d = (...t) => f("[Cyperful Agent]", ...t);
6
- d("Loading...");
7
- const { CYPERFUL_ORIGIN: u } = __CYPERFUL_CONFIG__;
8
- if (window.location.origin === u) {
9
- d("Ignoring parent frame (Why are we here?)");
10
- return;
1
+ const m = __CYPERFUL_CONFIG__;
2
+ function L() {
3
+ if (!m)
4
+ throw new Error("Cyperful Agent config not initialized");
5
+ return m;
6
+ }
7
+ let _ = 0;
8
+ const p = (r, t, c = null) => {
9
+ const { CYPERFUL_ORIGIN: s } = L();
10
+ let n = null;
11
+ try {
12
+ const e = Date.now(), i = `${e}-${_++}`;
13
+ if ("url" in t && t.url != null)
14
+ try {
15
+ const o = new URL(t.url, window.location.origin);
16
+ if (o.origin === s) return null;
17
+ o.origin === window.location.origin && (t.url = o.pathname + o.search + o.hash);
18
+ } catch {
19
+ }
20
+ n = {
21
+ type: r,
22
+ data: t,
23
+ id: i,
24
+ timestamp: e,
25
+ start_id: c ? c.id : void 0
26
+ }, window.parent.postMessage(n, s);
27
+ } catch {
11
28
  }
12
- let y = 0;
13
- const s = (t, e, n = null) => {
14
- let i = null;
29
+ return n;
30
+ };
31
+ function R(r) {
32
+ try {
33
+ if (typeof r == "string") return JSON.parse(r);
34
+ } catch {
35
+ return r;
36
+ }
37
+ }
38
+ function y(r) {
39
+ const t = {};
40
+ for (const [c, s] of r.entries())
41
+ s instanceof Blob ? t[c] = `[[ Blob: ${s.size} bytes ]]` : t[c] = s.toString();
42
+ return t;
43
+ }
44
+ const S = () => {
45
+ const r = window.fetch;
46
+ window.fetch = (...t) => {
47
+ var g;
48
+ const [c, s = {}] = typeof t[0] == "string" || t[0] instanceof URL ? [t[0], t[1]] : [t[0].url, t[0]], n = ((g = s.method) == null ? void 0 : g.toUpperCase()) ?? "GET", e = s.body, o = new Headers(s.headers).get("content-type") || void 0;
49
+ let d;
15
50
  try {
16
- const r = Date.now(), c = `${r}-${y++}`;
17
- if ("url" in e && e.url != null)
18
- try {
19
- const o = new URL(e.url, window.location.origin);
20
- if (o.origin === u)
21
- return null;
22
- o.origin === window.location.origin && (e.url = o.pathname + o.search + o.hash);
23
- } catch {
24
- }
25
- i = {
26
- type: t,
27
- data: e,
28
- id: c,
29
- timestamp: r,
30
- start_id: n ? n.id : void 0
31
- }, window.parent.postMessage(i, u);
51
+ d = e instanceof FormData ? y(e) : o != null && o.match(/[+/]json\b/) ? R(e) : e;
32
52
  } catch {
33
53
  }
34
- return i;
54
+ const a = p("fetch", {
55
+ method: n,
56
+ url: c.toString(),
57
+ body: d,
58
+ bodyType: o
59
+ }), u = r(...t);
60
+ return u.then(async (h) => {
61
+ const l = h.headers.get("content-type") || void 0;
62
+ let f;
63
+ try {
64
+ const w = h.clone();
65
+ l != null && l.match(/\bform-data\b/) && (f = y(await w.formData())), l != null && l.match(/[+/]json\b/) ? f = await w.json() : l != null && l.match(/\btext[+/]/) ? f = await w.text() : f = `[[ Unhandled content-type: ${l || "<empty>"} ]]`;
66
+ } catch {
67
+ }
68
+ a && p(
69
+ "fetch:finished",
70
+ {
71
+ status: h.status,
72
+ responseType: l,
73
+ response: f
74
+ },
75
+ a
76
+ );
77
+ }).catch((h) => {
78
+ a && p(
79
+ "fetch:finished",
80
+ {
81
+ status: 0,
82
+ response: `[caught error] ${h.message || "Unknown error"}`
83
+ },
84
+ a
85
+ );
86
+ }), u;
35
87
  };
36
- for (const t of [
37
- "log",
38
- "error",
39
- "warn",
40
- "info",
41
- "dir",
42
- "debug"
43
- ]) {
44
- const e = console[t];
45
- e && (console[t] = (...n) => {
46
- e.apply(console, n), s("log", { level: t, args: n });
47
- });
48
- }
49
- window.addEventListener("error", (t) => {
50
- s("global_error", { message: t.error.toString() });
51
- }), window.addEventListener("unhandledrejection", (t) => {
52
- s("unhandledrejection", { message: t.reason.toString() });
53
- });
54
- function w(t) {
88
+ }, q = () => {
89
+ const r = window.XMLHttpRequest.prototype.open, t = window.XMLHttpRequest.prototype.send, c = window.XMLHttpRequest.prototype.setRequestHeader;
90
+ window.XMLHttpRequest.prototype.open = function(...n) {
91
+ return this._requestMeta = {
92
+ method: n[0],
93
+ url: n[1].toString(),
94
+ headers: {}
95
+ }, r.apply(this, n);
96
+ }, window.XMLHttpRequest.prototype.setRequestHeader = function(n, e) {
97
+ const i = this._requestMeta;
98
+ return i && (i.headers[n.toLowerCase()] = e), c.apply(this, [n, e]);
99
+ }, window.XMLHttpRequest.prototype.send = function(n) {
100
+ const e = this._requestMeta, i = e == null ? void 0 : e.headers["content-type"];
101
+ let o;
55
102
  try {
56
- if (typeof t == "string")
57
- return JSON.parse(t);
103
+ o = n instanceof FormData ? y(n) : i != null && i.match(/[+/]json\b/) ? R(n) : n;
58
104
  } catch {
59
- return t;
60
105
  }
61
- }
62
- function g(t) {
63
- const e = {};
64
- for (const [n, i] of t.entries())
65
- i instanceof Blob ? e[n] = `[[ Blob: ${i.size} bytes ]]` : e[n] = i.toString();
66
- return e;
67
- }
68
- const _ = window.XMLHttpRequest;
69
- function m() {
70
- const t = new _(), e = t.open;
71
- return t.open = (...n) => {
72
- const [i, r, c] = n, o = s("xhr", {
73
- method: i,
74
- url: r
75
- // body,
76
- });
77
- return t.addEventListener("load", () => {
78
- o && s(
79
- "xhr:finished",
80
- { status: t.status, response: t.response },
81
- o
82
- );
83
- }), e.apply(this, n);
84
- }, t;
85
- }
86
- window.XMLHttpRequest = m;
87
- const L = window.fetch;
88
- window.fetch = (...t) => {
89
- const [e, n = {}] = typeof t[0] == "string" || t[0] instanceof URL ? [t[0], t[1]] : [t[0].url, t[0]], i = n.method ?? "GET", r = n.body, c = n.headers || {}, o = c["content-type"] || c["Content-Type"] || void 0, R = r instanceof FormData ? g(r) : o != null && o.includes("application/json") ? w(r) : r, p = s("fetch", {
90
- method: i,
91
- url: e.toString(),
92
- body: R,
93
- bodyType: o
94
- }), h = L(...t);
95
- return h.then(async (l) => {
96
- const a = l.headers.get("content-type") || "", v = a.includes("application/json") ? await l.clone().json() : a.includes("text/") ? await l.clone().text() : `[[ Unhandled content-type: ${a || "<empty>"} ]]`;
97
- p && s(
98
- "fetch:finished",
106
+ const d = e ? p("xhr", {
107
+ method: e.method,
108
+ url: e.url,
109
+ body: o,
110
+ bodyType: i
111
+ }) : null;
112
+ return this.addEventListener("load", async () => {
113
+ if (!d) return;
114
+ const a = this.getResponseHeader("content-type") || void 0;
115
+ let u;
116
+ try {
117
+ u = a != null && a.match(/[+/]json\b/) ? await this.response.clone().json() : a != null && a.match(/\btext[+/]/) ? await this.response.clone().text() : `[[ Unhandled content-type: ${a || "<empty>"} ]]`;
118
+ } catch {
119
+ }
120
+ p(
121
+ "xhr:finished",
99
122
  {
100
- status: l.status,
101
- responseType: a || void 0,
102
- response: v
123
+ status: this.status,
124
+ response: u,
125
+ responseType: a
103
126
  },
104
- p
127
+ d
105
128
  );
106
- }).catch(() => {
107
- }), h;
129
+ }), this.addEventListener("error", () => {
130
+ d && p(
131
+ "xhr:finished",
132
+ {
133
+ status: 0,
134
+ response: `[caught error] ${this.status ?? 0} - ${this.statusText || "Unknown error"}`
135
+ },
136
+ d
137
+ );
138
+ }), t.apply(this, [n]);
108
139
  };
109
- const S = history.pushState;
110
- history.pushState = (...t) => {
111
- S.apply(history, t), s("client_navigate", {
140
+ }, H = () => {
141
+ if (window.__cyperfulAgentInitialized) return;
142
+ window.__cyperfulAgentInitialized = !0;
143
+ const r = console.log, t = (...e) => r("[Cyperful Agent]", ...e);
144
+ t("Loading...");
145
+ const { CYPERFUL_ORIGIN: c } = L();
146
+ if (window.location.origin === c) {
147
+ t("Ignoring parent frame (Why are we here?)");
148
+ return;
149
+ }
150
+ S(), q(), window.addEventListener("error", (e) => {
151
+ p("global_error", { message: e.error.toString() });
152
+ }), window.addEventListener("unhandledrejection", (e) => {
153
+ p("unhandledrejection", { message: e.reason.toString() });
154
+ });
155
+ const s = history.pushState;
156
+ history.pushState = (...e) => {
157
+ s.apply(history, e), p("client_navigate", {
112
158
  url: location.href,
113
159
  replace: !1
114
160
  });
115
161
  };
116
- const b = history.replaceState;
117
- history.replaceState = (...t) => {
118
- b.apply(history, t), s("client_navigate", {
162
+ const n = history.replaceState;
163
+ history.replaceState = (...e) => {
164
+ n.apply(history, e), p("client_navigate", {
119
165
  url: location.href,
120
166
  replace: !0
121
167
  });
122
- }, d("Loaded.");
123
- })();
168
+ };
169
+ for (const e of [
170
+ "log",
171
+ "error",
172
+ "warn",
173
+ "info",
174
+ "dir",
175
+ "debug"
176
+ ]) {
177
+ const i = console[e];
178
+ i && (console[e] = (...o) => {
179
+ i.apply(console, o), p("log", { level: e, args: o });
180
+ });
181
+ }
182
+ t("Loaded.");
183
+ };
184
+ try {
185
+ H();
186
+ } catch (r) {
187
+ console.error("Cyperful Agent failed to load", r);
188
+ }
data/public/index.html CHANGED
@@ -5,8 +5,8 @@
5
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
6
  <link rel="icon" href="/assets/favicon-DMdBZQlK.ico" />
7
7
  <title>Cyperful</title>
8
- <script type="module" crossorigin src="/assets/index-Bcd7GDsE.js"></script>
9
- <link rel="stylesheet" crossorigin href="/assets/index-D7cO27Pa.css">
8
+ <script type="module" crossorigin src="/assets/index-DQa6Blo_.js"></script>
9
+ <link rel="stylesheet" crossorigin href="/assets/index-DqywWqA7.css">
10
10
  </head>
11
11
  <body class="bg-stone-900 text-slate-100">
12
12
  <div id="root"></div>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyperful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wyatt Ades
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-15 00:00:00.000000000 Z
11
+ date: 2025-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.0.3
61
+ version: 0.0.4
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.0.3
68
+ version: 0.0.4
69
69
  description:
70
70
  email:
71
71
  executables: []
@@ -84,9 +84,9 @@ files:
84
84
  - lib/cyperful/test_parser.rb
85
85
  - lib/cyperful/ui_server.rb
86
86
  - public/assets/favicon-DMdBZQlK.ico
87
- - public/assets/index-Bcd7GDsE.js
88
- - public/assets/index-D7cO27Pa.css
89
- - public/assets/syntax-highlighter-worker-Cumko8SL.js
87
+ - public/assets/index-DQa6Blo_.js
88
+ - public/assets/index-DqywWqA7.css
89
+ - public/assets/syntax-highlighter-worker-BezFv5DT.js
90
90
  - public/frame-agent.js
91
91
  - public/index.html
92
92
  homepage: https://github.com/stepful/cyperful
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  requirements: []
111
- rubygems_version: 3.5.6
111
+ rubygems_version: 3.5.16
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Interactive test debugger for Capybara tests