@prosopo/procaptcha-bundle 2.0.2 → 2.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 (120) hide show
  1. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts +1 -14
  2. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts.map +1 -1
  3. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js +18 -206
  4. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
  5. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/captchaType.test.d.ts +2 -0
  6. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/captchaType.test.d.ts.map +1 -0
  7. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/captchaType.test.js +36 -0
  8. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/captchaType.test.js.map +1 -0
  9. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/config.test.d.ts +2 -0
  10. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/config.test.d.ts.map +1 -0
  11. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/config.test.js +69 -0
  12. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/config.test.js.map +1 -0
  13. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captchaType.d.ts +2 -0
  14. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captchaType.d.ts.map +1 -0
  15. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captchaType.js +8 -0
  16. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captchaType.js.map +1 -0
  17. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/config.d.ts +8 -0
  18. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/config.d.ts.map +1 -0
  19. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/config.js +31 -0
  20. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/config.js.map +1 -0
  21. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/defaultCallbacks.d.ts +19 -0
  22. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/defaultCallbacks.d.ts.map +1 -0
  23. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/defaultCallbacks.js +147 -0
  24. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/defaultCallbacks.js.map +1 -0
  25. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/form.d.ts +2 -0
  26. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/form.d.ts.map +1 -0
  27. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/form.js +2 -0
  28. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/form.js.map +1 -0
  29. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.d.ts +3 -0
  30. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.d.ts.map +1 -0
  31. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.js +17 -0
  32. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.js.map +1 -0
  33. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/theme.d.ts +3 -0
  34. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/theme.d.ts.map +1 -0
  35. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/theme.js +9 -0
  36. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/theme.js.map +1 -0
  37. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.d.ts +3 -0
  38. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.d.ts.map +1 -0
  39. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.js +9 -0
  40. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.js.map +1 -0
  41. package/dist/bundle/ProcaptchaWidget-BZq2OhjK.js +615 -0
  42. package/dist/bundle/ProcaptchaWidget-b_oUhvT9.js +149 -0
  43. package/dist/bundle/index-Ck7UqzKB.js +19822 -0
  44. package/dist/bundle/index.d.ts +1 -14
  45. package/dist/bundle/index.d.ts.map +1 -1
  46. package/dist/bundle/procaptcha.bundle.js +1 -1
  47. package/dist/bundle/tests/captchaType.test.d.ts +2 -0
  48. package/dist/bundle/tests/captchaType.test.d.ts.map +1 -0
  49. package/dist/bundle/tests/config.test.d.ts +2 -0
  50. package/dist/bundle/tests/config.test.d.ts.map +1 -0
  51. package/dist/bundle/util/captchaType.d.ts +2 -0
  52. package/dist/bundle/util/captchaType.d.ts.map +1 -0
  53. package/dist/bundle/util/config.d.ts +8 -0
  54. package/dist/bundle/util/config.d.ts.map +1 -0
  55. package/dist/bundle/util/defaultCallbacks.d.ts +19 -0
  56. package/dist/bundle/util/defaultCallbacks.d.ts.map +1 -0
  57. package/dist/bundle/util/form.d.ts +2 -0
  58. package/dist/bundle/util/form.d.ts.map +1 -0
  59. package/dist/bundle/util/language.d.ts +3 -0
  60. package/dist/bundle/util/language.d.ts.map +1 -0
  61. package/dist/bundle/util/theme.d.ts +3 -0
  62. package/dist/bundle/util/theme.d.ts.map +1 -0
  63. package/dist/bundle/util/timeout.d.ts +3 -0
  64. package/dist/bundle/util/timeout.d.ts.map +1 -0
  65. package/dist/bundle/{utils-C4GbA2iF.js → utils-9IQXYrRR.js} +8183 -11782
  66. package/dist/cjs/index.cjs +30 -199
  67. package/dist/cjs/util/captchaType.cjs +12 -0
  68. package/dist/cjs/util/config.cjs +33 -0
  69. package/dist/cjs/util/defaultCallbacks.cjs +134 -0
  70. package/dist/cjs/util/form.cjs +4 -0
  71. package/dist/cjs/util/language.cjs +18 -0
  72. package/dist/cjs/util/theme.cjs +9 -0
  73. package/dist/cjs/util/timeout.cjs +14 -0
  74. package/dist/index.d.ts +1 -14
  75. package/dist/index.d.ts.map +1 -1
  76. package/dist/index.js +18 -206
  77. package/dist/index.js.map +1 -1
  78. package/dist/tests/captchaType.test.d.ts +2 -0
  79. package/dist/tests/captchaType.test.d.ts.map +1 -0
  80. package/dist/tests/captchaType.test.js +36 -0
  81. package/dist/tests/captchaType.test.js.map +1 -0
  82. package/dist/tests/config.test.d.ts +2 -0
  83. package/dist/tests/config.test.d.ts.map +1 -0
  84. package/dist/tests/config.test.js +69 -0
  85. package/dist/tests/config.test.js.map +1 -0
  86. package/dist/util/captchaType.d.ts +3 -0
  87. package/dist/util/captchaType.d.ts.map +1 -0
  88. package/dist/util/captchaType.js +8 -0
  89. package/dist/util/captchaType.js.map +1 -0
  90. package/dist/util/config.d.ts +8 -0
  91. package/dist/util/config.d.ts.map +1 -0
  92. package/dist/util/config.js +31 -0
  93. package/dist/util/config.js.map +1 -0
  94. package/dist/util/defaultCallbacks.d.ts +19 -0
  95. package/dist/util/defaultCallbacks.d.ts.map +1 -0
  96. package/dist/util/defaultCallbacks.js +147 -0
  97. package/dist/util/defaultCallbacks.js.map +1 -0
  98. package/dist/util/form.d.ts +2 -0
  99. package/dist/util/form.d.ts.map +1 -0
  100. package/dist/util/form.js +2 -0
  101. package/dist/util/form.js.map +1 -0
  102. package/dist/util/language.d.ts +3 -0
  103. package/dist/util/language.d.ts.map +1 -0
  104. package/dist/util/language.js +17 -0
  105. package/dist/util/language.js.map +1 -0
  106. package/dist/util/theme.d.ts +3 -0
  107. package/dist/util/theme.d.ts.map +1 -0
  108. package/dist/util/theme.js +9 -0
  109. package/dist/util/theme.js.map +1 -0
  110. package/dist/util/timeout.d.ts +3 -0
  111. package/dist/util/timeout.d.ts.map +1 -0
  112. package/dist/util/timeout.js +9 -0
  113. package/dist/util/timeout.js.map +1 -0
  114. package/package.json +64 -59
  115. package/stats.html +1 -1
  116. package/vite.config.ts +24 -24
  117. package/vite.test.config.ts +34 -0
  118. package/dist/bundle/ProcaptchaWidget-BfqnMHY0.js +0 -155
  119. package/dist/bundle/ProcaptchaWidget-DlGRz6Tc.js +0 -775
  120. package/dist/bundle/index-DU1XrpZS.js +0 -14976
package/vite.config.ts CHANGED
@@ -14,8 +14,8 @@
14
14
 
15
15
  import * as fs from "node:fs";
16
16
  import * as path from "node:path";
17
- import { loadEnv } from "@prosopo/dotenv";
18
17
  import { ViteFrontendConfig } from "@prosopo/config";
18
+ import { loadEnv } from "@prosopo/dotenv";
19
19
  import { defineConfig } from "vite";
20
20
 
21
21
  // load env using our util because vite loadEnv is not working for .env.development
@@ -30,36 +30,36 @@ const bundleName = "procaptcha";
30
30
  const packageName = "@prosopo/procaptcha-bundle";
31
31
  const entry = "./src/index.tsx";
32
32
  const copyOptions = copyTo
33
- ? {
34
- srcDir: "./dist/bundle",
35
- destDir: copyTo,
36
- }
37
- : undefined;
33
+ ? {
34
+ srcDir: "./dist/bundle",
35
+ destDir: copyTo,
36
+ }
37
+ : undefined;
38
38
  const tsConfigPaths = [path.resolve("./tsconfig.json")];
39
39
  const packagesDir = path.resolve("..");
40
40
  const workspaceRoot = path.resolve("../../");
41
41
  // Get all folders in packagesDir
42
42
  const packages = fs
43
- .readdirSync(packagesDir)
44
- .filter((f) => fs.statSync(path.join(packagesDir, f)).isDirectory());
43
+ .readdirSync(packagesDir)
44
+ .filter((f) => fs.statSync(path.join(packagesDir, f)).isDirectory());
45
45
  for (const packageName of packages) {
46
- // Add the tsconfig for each package to tsConfigPaths
47
- tsConfigPaths.push(path.resolve(`../${packageName}/tsconfig.json`));
46
+ // Add the tsconfig for each package to tsConfigPaths
47
+ tsConfigPaths.push(path.resolve(`../${packageName}/tsconfig.json`));
48
48
  }
49
49
  // Merge with generic frontend config
50
50
  export default defineConfig(async ({ command, mode }) => {
51
- const frontendConfig = await ViteFrontendConfig(
52
- packageName,
53
- bundleName,
54
- path.resolve(),
55
- entry,
56
- command,
57
- mode,
58
- copyOptions,
59
- tsConfigPaths,
60
- workspaceRoot,
61
- );
62
- return {
63
- ...frontendConfig,
64
- };
51
+ const frontendConfig = await ViteFrontendConfig(
52
+ packageName,
53
+ bundleName,
54
+ path.resolve(),
55
+ entry,
56
+ command,
57
+ mode,
58
+ copyOptions,
59
+ tsConfigPaths,
60
+ workspaceRoot,
61
+ );
62
+ return {
63
+ ...frontendConfig,
64
+ };
65
65
  });
@@ -0,0 +1,34 @@
1
+ // Copyright 2021-2024 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ import fs from "node:fs";
16
+ import path from "node:path";
17
+ import { ViteTestConfig } from "@prosopo/config";
18
+ import dotenv from "dotenv";
19
+
20
+ process.env.NODE_ENV = "test";
21
+ // if .env.test exists at this level, use it, otherwise use the one at the root
22
+ const envFile = `.env.${process.env.NODE_ENV || "development"}`;
23
+ let envPath = envFile;
24
+ if (fs.existsSync(envFile)) {
25
+ envPath = path.resolve(envFile);
26
+ } else if (fs.existsSync(`../../${envFile}`)) {
27
+ envPath = path.resolve(`../../${envFile}`);
28
+ } else {
29
+ throw new Error(`No ${envFile} file found`);
30
+ }
31
+
32
+ dotenv.config({ path: envPath });
33
+
34
+ export default ViteTestConfig;
@@ -1,155 +0,0 @@
1
- import { A as a, e as H, a as L, P as O, r as w, j as n, W as k, C as j, c as M, b as R, f as U, g as B, h as F, i as X, k as K, L as V, m as Y, n as q, o as $, l as z, d as J } from "./index-DU1XrpZS.js";
2
- import { v as Q, k as _, n as Z, f as E, o as ee, s as te, p as ne, l as N, E as oe, q as ae, t as se, C as re } from "./utils-C4GbA2iF.js";
3
- const ce = (r, e) => {
4
- let s = 0;
5
- const c = "0".repeat(e);
6
- for (; ; ) {
7
- const p = new TextEncoder().encode(s + r);
8
- if (ie(Q(p)).startsWith(c))
9
- return s;
10
- s += 1;
11
- }
12
- }, ie = (r) => Array.from(r).map((e) => e.toString(16).padStart(2, "0")).join(""), le = (r, e, s, c) => {
13
- const p = _(s, e, c), i = () => ({
14
- showModal: !1,
15
- loading: !1,
16
- index: 0,
17
- challenge: void 0,
18
- solutions: void 0,
19
- isHuman: !1,
20
- captchaApi: void 0,
21
- account: void 0
22
- }), T = () => {
23
- window.clearTimeout(e.timeout), o({ timeout: void 0 });
24
- }, b = () => {
25
- window.clearTimeout(e.successfullChallengeTimeout), o({ successfullChallengeTimeout: void 0 });
26
- }, l = () => {
27
- const t = {
28
- userAccountAddress: "",
29
- ...r
30
- };
31
- return e.account && (t.userAccountAddress = e.account.account.address), O.parse(t);
32
- }, g = () => {
33
- if (!e.account)
34
- throw new E("GENERAL.ACCOUNT_NOT_FOUND", {
35
- context: { error: "Account not loaded" }
36
- });
37
- return { account: e.account };
38
- }, d = () => {
39
- if (!e.dappAccount)
40
- throw new E("GENERAL.SITE_KEY_MISSING");
41
- return e.dappAccount;
42
- }, o = N(e, s), v = () => {
43
- T(), b(), o(i());
44
- }, P = () => {
45
- const t = l().captchas.pow.solutionTimeout, f = setTimeout(() => {
46
- o({ isHuman: !1 }), p.onExpired();
47
- }, t);
48
- o({ successfullChallengeTimeout: f });
49
- }, W = async () => {
50
- var D;
51
- if (e.loading || e.isHuman)
52
- return;
53
- v(), o({
54
- loading: !0
55
- });
56
- const t = l(), f = t.web2 ? new oe() : new ae(), h = t.userAccountAddress || (await f.getAccount(t)).account.address;
57
- if (o({
58
- account: { account: { address: h } }
59
- }), o({ dappAccount: t.account.address }), await Z(100), !t.web2 && !t.userAccountAddress)
60
- throw new E("GENERAL.ACCOUNT_NOT_FOUND", {
61
- context: { error: "Account address has not been set for web3 mode" }
62
- });
63
- const m = G(), A = _(s, e, c), x = m.provider.url, I = new ee(x, d()), u = await I.getPowCaptchaChallenge(h, d()), S = ce(u.challenge, u.difficulty), C = (D = (await f.getAccount(l())).extension) == null ? void 0 : D.signer;
64
- if (!C || !C.signRaw)
65
- throw new E("GENERAL.CANT_FIND_KEYRINGPAIR", {
66
- context: {
67
- error: "Signer is not defined, cannot sign message to prove account ownership"
68
- }
69
- });
70
- const y = await C.signRaw({
71
- address: h,
72
- data: te(u[a.timestamp].toString()),
73
- type: "bytes"
74
- });
75
- (await I.submitPowCaptchaSolution(u, g().account.account.address, d(), S, y.signature.toString(), t.captchas.pow.verifiedTimeout))[a.verified] && (o({
76
- isHuman: !0,
77
- loading: !1
78
- }), A.onHuman(H({
79
- [a.providerUrl]: x,
80
- [a.user]: g().account.account.address,
81
- [a.dapp]: d(),
82
- [a.challenge]: u.challenge,
83
- [a.nonce]: S,
84
- [a.timestamp]: u.timestamp,
85
- [a.signature]: {
86
- [a.provider]: u.signature.provider,
87
- [a.user]: {
88
- [a.timestamp]: y.signature.toString()
89
- }
90
- }
91
- })), P());
92
- }, G = () => {
93
- const t = (A, x) => Math.floor(Math.random() * (x - A + 1) + A), f = l().defaultEnvironment, h = ne(f), m = L(h, t(0, h.length - 1));
94
- return {
95
- providerAccount: m.address,
96
- provider: {
97
- url: m.url,
98
- datasetId: m.datasetId,
99
- datasetIdContent: m.datasetIdContent
100
- }
101
- };
102
- };
103
- return {
104
- start: W,
105
- resetState: v
106
- };
107
- }, me = (r) => {
108
- const e = r.config, s = e.theme === "light" ? "light" : "dark", c = r.config.theme === "light" ? z : J, p = r.callbacks || {}, [i, T] = se(w.useState, w.useRef), b = N(i, T), l = w.useRef(le(e, i, b, p)), g = w.useRef(null);
109
- return w.useEffect(() => {
110
- const d = g.current;
111
- if (!d)
112
- return;
113
- const o = d.closest("form");
114
- if (!o)
115
- return;
116
- const v = () => {
117
- l.current.resetState();
118
- };
119
- return o.addEventListener("submit", v), () => {
120
- o.removeEventListener("submit", v);
121
- };
122
- }, []), n("div", { ref: g, children: n("div", { style: {
123
- maxWidth: k,
124
- maxHeight: "100%",
125
- overflowX: "auto"
126
- }, children: n(j, { children: n(M, { children: R("div", { style: U, "data-cy": "button-human", children: [" ", R("div", { style: {
127
- padding: B,
128
- border: F,
129
- backgroundColor: c.palette.background.default,
130
- borderColor: c.palette.grey[300],
131
- borderRadius: X,
132
- display: "flex",
133
- alignItems: "center",
134
- flexWrap: "wrap",
135
- justifyContent: "space-between",
136
- minHeight: `${K}px`,
137
- overflow: "hidden"
138
- }, children: [n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("div", { style: {
139
- display: "flex",
140
- justifyContent: "flex-start",
141
- alignItems: "center",
142
- flexWrap: "wrap"
143
- }, children: n("div", { style: {
144
- display: "flex",
145
- alignItems: "center",
146
- justifyContent: "center",
147
- flexDirection: "column",
148
- verticalAlign: "middle"
149
- }, children: n("div", { style: {
150
- display: "flex"
151
- }, children: n("div", { style: { flex: 1 }, children: i.loading ? n(V, { themeColor: s, "aria-label": "Loading spinner" }) : n(re, { checked: i.isHuman, onChange: l.current.start, themeColor: s, labelText: "I am human", "aria-label": "human checkbox" }) }) }) }) }) }), n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("a", { href: Y, target: "_blank", "aria-label": q, rel: "noreferrer", children: n("div", { style: { flex: 1 }, children: n($, { themeColor: s, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) }) }) });
152
- };
153
- export {
154
- me as default
155
- };