cyperful 0.3.0 → 0.3.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/public/frame-agent.js +109 -105
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 928af50672505bb877c08f2ef62533dee16149822b591eb0d854b28235fcd207
4
- data.tar.gz: 8b3974789ec4d679fd6413fd5a8ac09b770e038487741871249da41815faeb1a
3
+ metadata.gz: f9f8d3ff27a617e78c9574d35c85d0f02dc0273de2e90c7773da683cd8750f5e
4
+ data.tar.gz: 2fb3db663142fcbc88cdd6961983f8c1a3df8f623dc5fbf8ed73e4a7256a6c1c
5
5
  SHA512:
6
- metadata.gz: '08d44698ee7d2e39c0b6cc36395d359983348e24378fa0f71a13c029d26cdeded6283828054498e524db52f39564214a33bb8f860ad857accaa4d22edd8c6a02'
7
- data.tar.gz: a3aa8baf3c5d3a12747e316aeff713b834cc0ef8ac1a784ab24ffc2c405fb4f60908f8109b2b0a24a504e8d66a3d71e620ad6cd02c11b53c9734b04e005f8b12
6
+ metadata.gz: 2887f50bf26d411114cd9152e233f9bc81f66425c173ed2550e19e867c0d4f2abe3811626f2918bc731d810e4ca2e683bf1d0144ae5f1cf13d324afd1ed45cfd
7
+ data.tar.gz: 74f2680a4ec70a3fe89291e84f81f3a682b5a6e7c2c1dd40f0031df3fb5720f0654d42b2e4eaf833f32913a3c5a381b1c2a66a58b0705f485e20abf4dc595932
@@ -5,168 +5,172 @@ function L() {
5
5
  return m;
6
6
  }
7
7
  let _ = 0;
8
- const p = (r, t, c = null) => {
9
- const { CYPERFUL_ORIGIN: s } = L();
10
- let n = null;
8
+ const u = (e, n, i = null) => {
9
+ const { CYPERFUL_ORIGIN: o } = L();
10
+ let r = null;
11
11
  try {
12
- const e = Date.now(), i = `${e}-${_++}`;
13
- if ("url" in t && t.url != null)
12
+ const t = Date.now(), a = `${t}-${_++}`;
13
+ if ("url" in n && n.url != null)
14
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);
15
+ const s = new URL(n.url, window.location.origin);
16
+ if (s.origin === o) return null;
17
+ s.origin === window.location.origin && (n.url = s.pathname + s.search + s.hash);
18
18
  } catch {
19
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);
20
+ r = {
21
+ type: e,
22
+ data: n,
23
+ id: a,
24
+ timestamp: t,
25
+ start_id: i ? i.id : void 0
26
+ }, window.parent.postMessage(r, o);
27
27
  } catch {
28
28
  }
29
- return n;
29
+ return r;
30
30
  };
31
- function R(r) {
31
+ function q(e) {
32
32
  try {
33
- if (typeof r == "string") return JSON.parse(r);
33
+ if (typeof e == "string") return JSON.parse(e);
34
34
  } catch {
35
- return r;
35
+ return e;
36
36
  }
37
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;
38
+ function R(e) {
39
+ const n = {};
40
+ for (const [i, o] of e.entries())
41
+ o instanceof Blob ? n[i] = `[[ Blob: ${o.size} bytes ]]` : n[i] = o.toString();
42
+ return n;
43
+ }
44
+ const H = (e) => e instanceof ArrayBuffer;
45
+ function g(e, n) {
46
+ return e == null ? e : e instanceof FormData ? R(e) : e instanceof Blob ? `[[ ${e.constructor.name}: ${e.size} bytes ]]` : H(e) ? `[[ ${e.constructor.name}: ${e.byteLength} bytes ]]` : e instanceof URLSearchParams ? e.toString() : typeof e == "object" || typeof e == "function" ? `[[ ${e.constructor.name} ]]` : typeof e == "string" && (n != null && n.match(/[+/]json\b/)) ? q(e) : e;
43
47
  }
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;
48
+ const $ = () => {
49
+ const e = window.fetch;
50
+ window.fetch = (...n) => {
51
+ var y;
52
+ const [i, o = {}] = typeof n[0] == "string" || n[0] instanceof URL ? [n[0], n[1]] : [n[0].url, n[0]], r = ((y = o.method) == null ? void 0 : y.toUpperCase()) ?? "GET", t = o.body, s = new Headers(o.headers).get("content-type") || void 0;
53
+ let l;
50
54
  try {
51
- d = e instanceof FormData ? y(e) : o != null && o.match(/[+/]json\b/) ? R(e) : e;
55
+ l = g(t, s);
52
56
  } catch {
53
57
  }
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;
58
+ const p = u("fetch", {
59
+ method: r,
60
+ url: i.toString(),
61
+ body: l,
62
+ bodyType: s
63
+ }), h = e(...n);
64
+ return h.then(async (f) => {
65
+ const c = f.headers.get("content-type") || void 0, S = f.headers.get("content-length") || void 0;
66
+ let d;
63
67
  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>"} ]]`;
68
+ const w = f.clone();
69
+ c != null && c.match(/\bform-data|\bapplication\/x-www-form-urlencoded\b/) && (d = R(await w.formData())), c != null && c.match(/[+/]json\b/) ? d = await w.json() : c != null && c.match(/\btext[+/]/) ? d = await w.text() : d = `[[ Unhandled content-type ${c || "<empty>"} (size: ${S ?? "<unknown>"} bytes) ]]`;
66
70
  } catch {
67
71
  }
68
- a && p(
72
+ p && u(
69
73
  "fetch:finished",
70
74
  {
71
- status: h.status,
72
- responseType: l,
73
- response: f
75
+ status: f.status,
76
+ responseType: c,
77
+ response: d
74
78
  },
75
- a
79
+ p
76
80
  );
77
- }).catch((h) => {
78
- a && p(
81
+ }).catch((f) => {
82
+ p && u(
79
83
  "fetch:finished",
80
84
  {
81
85
  status: 0,
82
- response: `[caught error] ${h.message || "Unknown error"}`
86
+ response: `[caught error] ${f.message || "Unknown error"}`
83
87
  },
84
- a
88
+ p
85
89
  );
86
- }), u;
90
+ }), h;
87
91
  };
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) {
92
+ }, B = () => {
93
+ const e = window.XMLHttpRequest.prototype.open, n = window.XMLHttpRequest.prototype.send, i = window.XMLHttpRequest.prototype.setRequestHeader;
94
+ window.XMLHttpRequest.prototype.open = function(...r) {
91
95
  return this._requestMeta = {
92
- method: n[0],
93
- url: n[1].toString(),
96
+ method: r[0],
97
+ url: r[1].toString(),
94
98
  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;
99
+ }, e.apply(this, r);
100
+ }, window.XMLHttpRequest.prototype.setRequestHeader = function(r, t) {
101
+ const a = this._requestMeta;
102
+ return a && (a.headers[r.toLowerCase()] = t), i.apply(this, [r, t]);
103
+ }, window.XMLHttpRequest.prototype.send = function(r) {
104
+ const t = this._requestMeta, a = t == null ? void 0 : t.headers["content-type"];
105
+ let s;
102
106
  try {
103
- o = n instanceof FormData ? y(n) : i != null && i.match(/[+/]json\b/) ? R(n) : n;
107
+ s = g(r, a);
104
108
  } catch {
105
109
  }
106
- const d = e ? p("xhr", {
107
- method: e.method,
108
- url: e.url,
109
- body: o,
110
- bodyType: i
110
+ const l = t ? u("xhr", {
111
+ method: t.method,
112
+ url: t.url,
113
+ body: s,
114
+ bodyType: a
111
115
  }) : null;
112
116
  return this.addEventListener("load", async () => {
113
- if (!d) return;
114
- const a = this.getResponseHeader("content-type") || void 0;
115
- let u;
117
+ if (!l) return;
118
+ const p = this.getResponseHeader("content-type") || void 0;
119
+ let h;
116
120
  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>"} ]]`;
121
+ h = g(this.response, p);
118
122
  } catch {
119
123
  }
120
- p(
124
+ u(
121
125
  "xhr:finished",
122
126
  {
123
127
  status: this.status,
124
- response: u,
125
- responseType: a
128
+ response: h,
129
+ responseType: p
126
130
  },
127
- d
131
+ l
128
132
  );
129
133
  }), this.addEventListener("error", () => {
130
- d && p(
134
+ l && u(
131
135
  "xhr:finished",
132
136
  {
133
137
  status: 0,
134
138
  response: `[caught error] ${this.status ?? 0} - ${this.statusText || "Unknown error"}`
135
139
  },
136
- d
140
+ l
137
141
  );
138
- }), t.apply(this, [n]);
142
+ }), n.apply(this, [r]);
139
143
  };
140
- }, H = () => {
144
+ }, C = () => {
141
145
  if (window.__cyperfulAgentInitialized) return;
142
146
  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?)");
147
+ const e = console.log, n = (...t) => e("[Cyperful Agent]", ...t);
148
+ n("Loading...");
149
+ const { CYPERFUL_ORIGIN: i } = L();
150
+ if (window.location.origin === i) {
151
+ n("Ignoring parent frame (Why are we here?)");
148
152
  return;
149
153
  }
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
+ $(), B(), window.addEventListener("error", (t) => {
155
+ u("global_error", { message: t.error.toString() });
156
+ }), window.addEventListener("unhandledrejection", (t) => {
157
+ u("unhandledrejection", { message: t.reason.toString() });
154
158
  });
155
- const s = history.pushState;
156
- history.pushState = (...e) => {
157
- s.apply(history, e), p("client_navigate", {
159
+ const o = history.pushState;
160
+ history.pushState = (...t) => {
161
+ o.apply(history, t), u("client_navigate", {
158
162
  url: location.href,
159
163
  replace: !1
160
164
  });
161
165
  };
162
- const n = history.replaceState;
163
- history.replaceState = (...e) => {
164
- n.apply(history, e), p("client_navigate", {
166
+ const r = history.replaceState;
167
+ history.replaceState = (...t) => {
168
+ r.apply(history, t), u("client_navigate", {
165
169
  url: location.href,
166
170
  replace: !0
167
171
  });
168
172
  };
169
- for (const e of [
173
+ for (const t of [
170
174
  "log",
171
175
  "error",
172
176
  "warn",
@@ -174,15 +178,15 @@ const S = () => {
174
178
  "dir",
175
179
  "debug"
176
180
  ]) {
177
- const i = console[e];
178
- i && (console[e] = (...o) => {
179
- i.apply(console, o), p("log", { level: e, args: o });
181
+ const a = console[t];
182
+ a && (console[t] = (...s) => {
183
+ a.apply(console, s), u("log", { level: t, args: s });
180
184
  });
181
185
  }
182
- t("Loaded.");
186
+ n("Loaded.");
183
187
  };
184
188
  try {
185
- H();
186
- } catch (r) {
187
- console.error("Cyperful Agent failed to load", r);
189
+ C();
190
+ } catch (e) {
191
+ console.error("Cyperful Agent failed to load", e);
188
192
  }
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.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wyatt Ades
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-08 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara