@prosopo/load-balancer 2.8.13 → 2.9.10

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,5 +1,5 @@
1
1
 
2
- > @prosopo/load-balancer@2.8.13 build:cjs
2
+ > @prosopo/load-balancer@2.9.10 build:cjs
3
3
  > NODE_ENV=${NODE_ENV:-development}; vite build --config vite.cjs.config.ts --mode $NODE_ENV
4
4
 
5
5
  ViteCommonJSConfig: .
@@ -7,8 +7,9 @@ ViteCommonJSConfig: .
7
7
  tsConfigPaths: [
8
8
  '/home/runner/work/captcha/captcha/packages/common/tsconfig.json',
9
9
  '/home/runner/work/captcha/captcha/packages/locale/tsconfig.json',
10
- '/home/runner/work/captcha/captcha/packages/types/tsconfig.json',
10
+ '/home/runner/work/captcha/captcha/packages/logger/tsconfig.json',
11
11
  '/home/runner/work/captcha/captcha/packages/util/tsconfig.json',
12
+ '/home/runner/work/captcha/captcha/packages/types/tsconfig.json',
12
13
  '/home/runner/work/captcha/captcha/packages/util-crypto/tsconfig.json'
13
14
  ]
14
15
  }
@@ -16,8 +17,9 @@ ViteCommonJSConfig: .
16
17
  externals: [
17
18
  '@prosopo/common',
18
19
  '@prosopo/locale',
19
- '@prosopo/types',
20
+ '@prosopo/logger',
20
21
  '@prosopo/util',
22
+ '@prosopo/types',
21
23
  '@prosopo/util-crypto'
22
24
  ]
23
25
  }
@@ -27,7 +29,7 @@ transforming...
27
29
  Build end
28
30
  ✓ 3 modules transformed.
29
31
  rendering chunks...
30
- dist/cjs/index.cjs 0.53 kB
31
- dist/cjs/providers.cjs 1.39 kB
32
+ dist/cjs/index.cjs 0.64 kB
32
33
  dist/cjs/balancer.cjs 1.67 kB
33
- ✓ built in 189ms
34
+ dist/cjs/providers.cjs 2.10 kB
35
+ ✓ built in 166ms
@@ -0,0 +1,32 @@
1
+
2
+ > @prosopo/load-balancer@2.9.10 build:tsc
3
+ > tsc --build --verbose
4
+
5
+ 8:14:29 AM - Projects in this build:
6
+ * ../../dev/config/tsconfig.json
7
+ * ../locale/tsconfig.json
8
+ * ../util/tsconfig.json
9
+ * ../logger/tsconfig.json
10
+ * ../util-crypto/tsconfig.json
11
+ * ../types/tsconfig.json
12
+ * ../common/tsconfig.json
13
+ * tsconfig.json
14
+
15
+ 8:14:29 AM - Project '../../dev/config/tsconfig.json' is up to date because newest input '../../dev/config/src/webpack/webpack.config.ts' is older than output '../../dev/config/tsconfig.tsbuildinfo'
16
+
17
+ 8:14:29 AM - Project '../locale/tsconfig.json' is up to date because newest input '../locale/src/translationKey.ts' is older than output '../locale/tsconfig.tsbuildinfo'
18
+
19
+ 8:14:29 AM - Project '../util/tsconfig.json' is up to date because newest input '../util/src/url.ts' is older than output '../util/tsconfig.tsbuildinfo'
20
+
21
+ 8:14:29 AM - Project '../logger/tsconfig.json' is up to date because newest input '../logger/src/index.ts' is older than output '../logger/tsconfig.tsbuildinfo'
22
+
23
+ 8:14:29 AM - Project '../util-crypto/tsconfig.json' is up to date because newest input '../util-crypto/src/types.ts' is older than output '../util-crypto/tsconfig.tsbuildinfo'
24
+
25
+ 8:14:29 AM - Project '../types/tsconfig.json' is up to date because newest input '../types/src/procaptcha/api.ts' is older than output '../types/tsconfig.tsbuildinfo'
26
+
27
+ 8:14:29 AM - Project '../common/tsconfig.json' is up to date because newest input '../common/src/error.ts' is older than output '../common/tsconfig.tsbuildinfo'
28
+
29
+ 8:14:29 AM - Project 'tsconfig.json' is out of date because output file 'tsconfig.tsbuildinfo' does not exist
30
+
31
+ 8:14:29 AM - Building project '/home/runner/work/captcha/captcha/packages/load-balancer/tsconfig.json'...
32
+
@@ -1,14 +1,19 @@
1
1
 
2
- > @prosopo/load-balancer@2.8.13 build
3
- > NODE_ENV=${NODE_ENV:-development}; vite build --config vite.esm.config.ts --mode $NODE_ENV
2
+ > @prosopo/load-balancer@2.9.10 build
3
+ > npm run build:cross-env -- --mode ${NODE_ENV:-development}
4
+
5
+
6
+ > @prosopo/load-balancer@2.9.10 build:cross-env
7
+ > vite build --config vite.esm.config.ts --mode production
4
8
 
5
9
  ViteEsmConfig: .
6
10
  {
7
11
  tsConfigPaths: [
8
12
  '/home/runner/work/captcha/captcha/packages/common/tsconfig.json',
9
13
  '/home/runner/work/captcha/captcha/packages/locale/tsconfig.json',
10
- '/home/runner/work/captcha/captcha/packages/types/tsconfig.json',
14
+ '/home/runner/work/captcha/captcha/packages/logger/tsconfig.json',
11
15
  '/home/runner/work/captcha/captcha/packages/util/tsconfig.json',
16
+ '/home/runner/work/captcha/captcha/packages/types/tsconfig.json',
12
17
  '/home/runner/work/captcha/captcha/packages/util-crypto/tsconfig.json'
13
18
  ]
14
19
  }
@@ -16,8 +21,9 @@ ViteEsmConfig: .
16
21
  externals: [
17
22
  '@prosopo/common',
18
23
  '@prosopo/locale',
19
- '@prosopo/types',
24
+ '@prosopo/logger',
20
25
  '@prosopo/util',
26
+ '@prosopo/types',
21
27
  '@prosopo/util-crypto'
22
28
  ]
23
29
  }
@@ -27,7 +33,7 @@ transforming...
27
33
  Build end
28
34
  ✓ 3 modules transformed.
29
35
  rendering chunks...
30
- dist/index.js 0.33 kB
31
- dist/providers.js 1.22 kB
36
+ dist/index.js 0.41 kB
32
37
  dist/balancer.js 1.50 kB
33
- ✓ built in 188ms
38
+ dist/providers.js 1.88 kB
39
+ ✓ built in 167ms
package/CHANGELOG.md CHANGED
@@ -1,5 +1,312 @@
1
1
  # @prosopo/load-balancer
2
2
 
3
+ ## 2.9.10
4
+ ### Patch Changes
5
+
6
+ - Updated dependencies [a1d60db]
7
+ - Updated dependencies [2392aaf]
8
+ - @prosopo/types@4.3.0
9
+ - @prosopo/common@3.1.38
10
+
11
+ ## 2.9.9
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [6c26669]
15
+ - Updated dependencies [f7f9ec5]
16
+ - @prosopo/types@4.2.1
17
+
18
+ ## 2.9.8
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies [0fd81af]
22
+ - @prosopo/common@3.1.37
23
+
24
+ ## 2.9.7
25
+ ### Patch Changes
26
+
27
+ - Updated dependencies [20cae63]
28
+ - Updated dependencies [4d9923e]
29
+ - @prosopo/types@4.2.0
30
+
31
+ ## 2.9.6
32
+ ### Patch Changes
33
+
34
+ - Updated dependencies [d351362]
35
+ - @prosopo/types@4.1.4
36
+
37
+ ## 2.9.5
38
+ ### Patch Changes
39
+
40
+ - Updated dependencies [e2711ae]
41
+ - Updated dependencies [5786629]
42
+ - @prosopo/types@4.1.3
43
+ - @prosopo/common@3.1.36
44
+
45
+ ## 2.9.4
46
+ ### Patch Changes
47
+
48
+ - @prosopo/types@4.1.2
49
+
50
+ ## 2.9.3
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies [91958da]
54
+ - @prosopo/types@4.1.1
55
+ - @prosopo/common@3.1.35
56
+
57
+ ## 2.9.2
58
+ ### Patch Changes
59
+
60
+ - Updated dependencies [6a741ce]
61
+ - @prosopo/types@4.1.0
62
+
63
+ ## 2.9.1
64
+ ### Patch Changes
65
+
66
+ - 4aae4e6: Pull the frictionless POST critical path down by ~340ms on the test
67
+ hardware via four focused changes:
68
+
69
+ - **Inline Signer.** `@polkadot/extension-base/page/Signer` is now a
70
+ static import in `ExtensionWeb2`. It's 0.5KB on disk but its dynamic
71
+ import was costing ~190ms of network round-trip; inlining removes
72
+ one separate chunk fetch + parse from the critical path.
73
+
74
+ - **Pre-warm the CryptoWorker.** `CryptoWorkerManager` gains a public
75
+ `prewarm()` that actually spawns the Worker and lets its script
76
+ parse during chunk-load time. Previously the call at module load
77
+ only instantiated the manager class; the worker itself spun up
78
+ lazily on the first `runTask`, putting the ~500ms worker module-eval
79
+ inside the first `createAccount()` call. Now it overlaps with chunk
80
+ loading and is hot by the time it's needed.
81
+
82
+ - **Prefetch providers at module load with an env-keyed cache.**
83
+ `prefetchProviders` and `getRandomActiveProvider` share an in-flight
84
+ `Promise<HardcodedProvider[]>` keyed by environment, so a module-load
85
+ prefetch and the later `customDetectBot` Promise.all reuse the same
86
+ network call. `procaptcha-frictionless` triggers the prefetch from
87
+ module-import time using `PROSOPO_DEFAULT_ENVIRONMENT` (browser-safe
88
+ `typeof process` guard + `EnvironmentTypesSchema.safeParse`), so the
89
+ HTTP fetch overlaps with chunk download instead of running as part
90
+ of the detection Promise.all.
91
+
92
+ - **Lazy-load the three captcha solvers.** `ProcaptchaFrictionless`
93
+ no longer statically imports `Procaptcha`, `ProcaptchaPuzzle`, and
94
+ `ProcaptchaPow`; each is `await import(...)` at the point the
95
+ frictionless response picks a type. Two of the three wrappers used
96
+ to be dead weight in the initial bundle; now only the chosen solver
97
+ is downloaded, after the frictionless POST has fired. Pulls ~64KB
98
+ of solver UI (chosen wrapper + Emotion dev runtime + builder + lazy
99
+ shim) out of the initial captchaRenderer chunk.
100
+
101
+ Combined with the earlier worker-related changes, the frictionless POST
102
+ on the puzzle-implicit test page is now ~1290ms vs ~1630ms before this
103
+ batch, and ~6500ms in the original baseline. The remaining floor is
104
+ dominated by the BotScoreWorker's obfuscated bundle parse + run.
105
+ - Updated dependencies [3c0be68]
106
+ - Updated dependencies [f9ea09d]
107
+ - Updated dependencies [d865319]
108
+ - Updated dependencies [753304b]
109
+ - Updated dependencies [8bb7286]
110
+ - Updated dependencies [f9ea09d]
111
+ - Updated dependencies [4aae4e6]
112
+ - Updated dependencies [4993813]
113
+ - @prosopo/types@4.0.0
114
+ - @prosopo/common@3.1.34
115
+
116
+ ## 2.9.0
117
+ ### Minor Changes
118
+
119
+ - 33a6c57: Provider speed ups
120
+
121
+ ### Patch Changes
122
+
123
+ - Updated dependencies [819ed95]
124
+ - @prosopo/types@3.16.1
125
+
126
+ ## 2.8.40
127
+ ### Patch Changes
128
+
129
+ - Updated dependencies [f6a4402]
130
+ - Updated dependencies [99dfb44]
131
+ - @prosopo/types@3.16.0
132
+
133
+ ## 2.8.39
134
+ ### Patch Changes
135
+
136
+ - Updated dependencies [3e54c0a]
137
+ - @prosopo/types@3.15.0
138
+
139
+ ## 2.8.38
140
+ ### Patch Changes
141
+
142
+ - Updated dependencies [946a8ba]
143
+ - Updated dependencies [5614814]
144
+ - @prosopo/types@3.14.1
145
+ - @prosopo/common@3.1.33
146
+
147
+ ## 2.8.37
148
+ ### Patch Changes
149
+
150
+ - Updated dependencies [fc514dd]
151
+ - Updated dependencies [42650db]
152
+ - @prosopo/types@3.14.0
153
+ - @prosopo/common@3.1.32
154
+
155
+ ## 2.8.36
156
+ ### Patch Changes
157
+
158
+ - Updated dependencies [4a9c518]
159
+ - @prosopo/common@3.1.31
160
+
161
+ ## 2.8.35
162
+ ### Patch Changes
163
+
164
+ - @prosopo/types@3.13.3
165
+
166
+ ## 2.8.34
167
+ ### Patch Changes
168
+
169
+ - @prosopo/types@3.13.2
170
+
171
+ ## 2.8.33
172
+ ### Patch Changes
173
+
174
+ - @prosopo/types@3.13.1
175
+
176
+ ## 2.8.32
177
+ ### Patch Changes
178
+
179
+ - Updated dependencies [e6d9553]
180
+ - @prosopo/types@3.13.0
181
+
182
+ ## 2.8.31
183
+ ### Patch Changes
184
+
185
+ - 730c61e: Speed up captcha
186
+ - Updated dependencies [d5082a9]
187
+ - Updated dependencies [e1ea65f]
188
+ - Updated dependencies [c316257]
189
+ - @prosopo/types@3.12.3
190
+
191
+ ## 2.8.30
192
+ ### Patch Changes
193
+
194
+ - Updated dependencies [adb89a6]
195
+ - @prosopo/types@3.12.2
196
+ - @prosopo/common@3.1.30
197
+
198
+ ## 2.8.29
199
+ ### Patch Changes
200
+
201
+ - Updated dependencies [c5ee492]
202
+ - Updated dependencies [a90eb54]
203
+ - @prosopo/common@3.1.29
204
+ - @prosopo/types@3.12.1
205
+
206
+ ## 2.8.28
207
+ ### Patch Changes
208
+
209
+ - 676c5f2: Use HTTPS in developmentwq
210
+ - Updated dependencies [676c5f2]
211
+ - Updated dependencies [feaca02]
212
+ - @prosopo/types@3.12.0
213
+
214
+ ## 2.8.27
215
+ ### Patch Changes
216
+
217
+ - Updated dependencies [8148587]
218
+ - @prosopo/types@3.11.1
219
+
220
+ ## 2.8.26
221
+ ### Patch Changes
222
+
223
+ - Updated dependencies [7f6ffc5]
224
+ - @prosopo/types@3.11.0
225
+
226
+ ## 2.8.25
227
+ ### Patch Changes
228
+
229
+ - Updated dependencies [93fa086]
230
+ - @prosopo/types@3.10.2
231
+
232
+ ## 2.8.24
233
+ ### Patch Changes
234
+
235
+ - Updated dependencies [cde7550]
236
+ - @prosopo/types@3.10.1
237
+
238
+ ## 2.8.23
239
+ ### Patch Changes
240
+
241
+ - Updated dependencies [ad6d622]
242
+ - @prosopo/types@3.10.0
243
+
244
+ ## 2.8.22
245
+ ### Patch Changes
246
+
247
+ - Updated dependencies [ff58a70]
248
+ - @prosopo/types@3.9.0
249
+
250
+ ## 2.8.21
251
+ ### Patch Changes
252
+
253
+ - Updated dependencies [d2431cd]
254
+ - @prosopo/types@3.8.4
255
+
256
+ ## 2.8.20
257
+ ### Patch Changes
258
+
259
+ - Updated dependencies [bd6995b]
260
+ - @prosopo/types@3.8.3
261
+
262
+ ## 2.8.19
263
+ ### Patch Changes
264
+
265
+ - Updated dependencies [9633e58]
266
+ - @prosopo/types@3.8.2
267
+
268
+ ## 2.8.18
269
+ ### Patch Changes
270
+
271
+ - Updated dependencies [f52a5c1]
272
+ - @prosopo/types@3.8.1
273
+
274
+ ## 2.8.17
275
+ ### Patch Changes
276
+
277
+ - 0a38892: feat/cross-os-testing
278
+ - a8faa9a: bump license year
279
+ - 3acc333: Release 3.3.0
280
+ - Updated dependencies [3acc333]
281
+ - Updated dependencies [0a38892]
282
+ - Updated dependencies [1ee3d80]
283
+ - Updated dependencies [a8faa9a]
284
+ - Updated dependencies [7543d17]
285
+ - Updated dependencies [3acc333]
286
+ - @prosopo/types@3.8.0
287
+ - @prosopo/common@3.1.28
288
+
289
+ ## 2.8.16
290
+ ### Patch Changes
291
+
292
+ - Updated dependencies [141e462]
293
+ - @prosopo/types@3.7.2
294
+
295
+ ## 2.8.15
296
+ ### Patch Changes
297
+
298
+ - Updated dependencies [345b25b]
299
+ - @prosopo/types@3.7.1
300
+
301
+ ## 2.8.14
302
+ ### Patch Changes
303
+
304
+ - Updated dependencies [ce70a2b]
305
+ - Updated dependencies [c2b940f]
306
+ - Updated dependencies [f6b5094]
307
+ - @prosopo/types@3.7.0
308
+ - @prosopo/common@3.1.27
309
+
3
310
  ## 2.8.13
4
311
  ### Patch Changes
5
312
 
@@ -0,0 +1,25 @@
1
+ import type { EnvironmentTypes } from "@prosopo/types";
2
+ import { z } from "zod";
3
+ declare const HardcodedProviderSchema: z.ZodObject<{
4
+ address: z.ZodString;
5
+ url: z.ZodString;
6
+ datasetId: z.ZodString;
7
+ weight: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodNumber>>, number, number | undefined>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ address: string;
10
+ url: string;
11
+ datasetId: string;
12
+ weight: number;
13
+ }, {
14
+ address: string;
15
+ url: string;
16
+ datasetId: string;
17
+ weight?: number | undefined;
18
+ }>;
19
+ export type HardcodedProvider = z.infer<typeof HardcodedProviderSchema>;
20
+ type hostedProviders = Record<string, unknown>;
21
+ export declare const convertHostedProvider: (provider: hostedProviders) => HardcodedProvider[];
22
+ export declare const getLoadBalancerUrl: (environment: EnvironmentTypes) => string;
23
+ export declare const loadBalancer: (environment: EnvironmentTypes) => Promise<HardcodedProvider[]>;
24
+ export {};
25
+ //# sourceMappingURL=balancer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balancer.d.ts","sourceRoot":"","sources":["../src/balancer.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;;EAa3B,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAExE,KAAK,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAE/C,eAAO,MAAM,qBAAqB,aACvB,eAAe,KACvB,iBAAiB,EAKnB,CAAC;AAEF,eAAO,MAAM,kBAAkB,gBAAiB,gBAAgB,KAAG,MAUlE,CAAC;AAEF,eAAO,MAAM,YAAY,gBACX,gBAAgB,KAC3B,OAAO,CAAC,iBAAiB,EAAE,CAqB7B,CAAC"}
package/dist/balancer.js CHANGED
@@ -31,8 +31,8 @@ const loadBalancer = async (environment) => {
31
31
  return [
32
32
  {
33
33
  address: "5EjTA28bKSbFPPyMbUjNtArxyqjwq38r1BapVmLZShaqEedV",
34
- url: "http://localhost:9229",
35
- datasetId: "0x9f460e81ac9c71b486f796a21bb36e2263694756a6621134d110da217fd3ef25",
34
+ url: "https://localhost:9229",
35
+ datasetId: "0x7984714b92d61fd92fd6a7bc9b56b729481470bcc771c19c382ec679acf02e67",
36
36
  weight: 1
37
37
  }
38
38
  ];
@@ -0,0 +1 @@
1
+ {"version":3,"file":"balancer.js","sourceRoot":"","sources":["../src/balancer.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE;IACrB,MAAM,EAAE,CAAC;SACP,MAAM,EAAE;SACR,QAAQ,EAAE;SACV,OAAO,CAAC,CAAC,CAAC;SACV,SAAS,CAAC,CAAC,GAAG,EAAE,EAAE;QAElB,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC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AAE,EAAE,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAC5B,OAAO,qBAAqB,CAAC,SAAS,CAAC,CAAC;AACzC,CAAC,CAAC"}
@@ -33,8 +33,8 @@ const loadBalancer = async (environment) => {
33
33
  return [
34
34
  {
35
35
  address: "5EjTA28bKSbFPPyMbUjNtArxyqjwq38r1BapVmLZShaqEedV",
36
- url: "http://localhost:9229",
37
- datasetId: "0x9f460e81ac9c71b486f796a21bb36e2263694756a6621134d110da217fd3ef25",
36
+ url: "https://localhost:9229",
37
+ datasetId: "0x7984714b92d61fd92fd6a7bc9b56b729481470bcc771c19c382ec679acf02e67",
38
38
  weight: 1
39
39
  }
40
40
  ];
@@ -4,7 +4,9 @@ const providers = require("./providers.cjs");
4
4
  const balancer = require("./balancer.cjs");
5
5
  exports._resetCache = providers._resetCache;
6
6
  exports.getRandomActiveProvider = providers.getRandomActiveProvider;
7
+ exports.prefetchProviders = providers.prefetchProviders;
7
8
  exports.selectWeightedProvider = providers.selectWeightedProvider;
9
+ exports.setProviderLoader = providers.setProviderLoader;
8
10
  exports.convertHostedProvider = balancer.convertHostedProvider;
9
11
  exports.getLoadBalancerUrl = balancer.getLoadBalancerUrl;
10
12
  exports.loadBalancer = balancer.loadBalancer;
@@ -2,9 +2,13 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  require("./index.cjs");
4
4
  const balancer = require("./balancer.cjs");
5
- let cachedProviders = [];
5
+ const providerPromiseCache = /* @__PURE__ */ new Map();
6
+ let customProviderLoader = null;
7
+ function setProviderLoader(loader) {
8
+ customProviderLoader = loader;
9
+ }
6
10
  function _resetCache() {
7
- cachedProviders = [];
11
+ providerPromiseCache.clear();
8
12
  }
9
13
  function selectWeightedProvider(providers, entropy) {
10
14
  if (providers.length === 0) {
@@ -25,11 +29,28 @@ function selectWeightedProvider(providers, entropy) {
25
29
  }
26
30
  return selectedProvider;
27
31
  }
28
- const getRandomActiveProvider = async (env, entropy) => {
29
- if (cachedProviders.length === 0) {
30
- cachedProviders = await balancer.loadBalancer(env);
32
+ const loadProviders = async (env) => {
33
+ if (customProviderLoader) {
34
+ return customProviderLoader(env);
31
35
  }
32
- const randomProviderObj = selectWeightedProvider(cachedProviders, entropy);
36
+ return balancer.loadBalancer(env);
37
+ };
38
+ const getProvidersPromise = (env) => {
39
+ const existing = providerPromiseCache.get(env);
40
+ if (existing) return existing;
41
+ const promise = loadProviders(env).catch((err) => {
42
+ providerPromiseCache.delete(env);
43
+ throw err;
44
+ });
45
+ providerPromiseCache.set(env, promise);
46
+ return promise;
47
+ };
48
+ const prefetchProviders = async (env) => {
49
+ await getProvidersPromise(env);
50
+ };
51
+ const getRandomActiveProvider = async (env, entropy) => {
52
+ const providers = await getProvidersPromise(env);
53
+ const randomProviderObj = selectWeightedProvider(providers, entropy);
33
54
  return {
34
55
  providerAccount: randomProviderObj.address,
35
56
  provider: {
@@ -40,4 +61,6 @@ const getRandomActiveProvider = async (env, entropy) => {
40
61
  };
41
62
  exports._resetCache = _resetCache;
42
63
  exports.getRandomActiveProvider = getRandomActiveProvider;
64
+ exports.prefetchProviders = prefetchProviders;
43
65
  exports.selectWeightedProvider = selectWeightedProvider;
66
+ exports.setProviderLoader = setProviderLoader;
@@ -0,0 +1,3 @@
1
+ export * from "./providers.js";
2
+ export * from "./balancer.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { _resetCache, getRandomActiveProvider, selectWeightedProvider } from "./providers.js";
1
+ import { _resetCache, getRandomActiveProvider, prefetchProviders, selectWeightedProvider, setProviderLoader } from "./providers.js";
2
2
  import { convertHostedProvider, getLoadBalancerUrl, loadBalancer } from "./balancer.js";
3
3
  export {
4
4
  _resetCache,
@@ -6,5 +6,7 @@ export {
6
6
  getLoadBalancerUrl,
7
7
  getRandomActiveProvider,
8
8
  loadBalancer,
9
- selectWeightedProvider
9
+ prefetchProviders,
10
+ selectWeightedProvider,
11
+ setProviderLoader
10
12
  };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { EnvironmentTypes, RandomProvider } from "@prosopo/types";
2
+ import { type HardcodedProvider } from "./index.js";
3
+ export declare function setProviderLoader(loader: (env: EnvironmentTypes) => Promise<HardcodedProvider[]>): void;
4
+ export declare function _resetCache(): void;
5
+ export declare function selectWeightedProvider(providers: HardcodedProvider[], entropy: number): HardcodedProvider;
6
+ export declare const prefetchProviders: (env: EnvironmentTypes) => Promise<void>;
7
+ export declare const getRandomActiveProvider: (env: EnvironmentTypes, entropy: number) => Promise<RandomProvider>;
8
+ //# sourceMappingURL=providers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"providers.d.ts","sourceRoot":"","sources":["../src/providers.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,KAAK,iBAAiB,EAAgB,MAAM,YAAY,CAAC;AAkBlE,wBAAgB,iBAAiB,CAChC,MAAM,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,iBAAiB,EAAE,CAAC,GAC7D,IAAI,CAEN;AAED,wBAAgB,WAAW,SAE1B;AAUD,wBAAgB,sBAAsB,CACrC,SAAS,EAAE,iBAAiB,EAAE,EAC9B,OAAO,EAAE,MAAM,GACb,iBAAiB,CAyBnB;AA+BD,eAAO,MAAM,iBAAiB,QACxB,gBAAgB,KACnB,OAAO,CAAC,IAAI,CAEd,CAAC;AAEF,eAAO,MAAM,uBAAuB,QAC9B,gBAAgB,WACZ,MAAM,KACb,OAAO,CAAC,cAAc,CAWxB,CAAC"}
package/dist/providers.js CHANGED
@@ -1,8 +1,12 @@
1
1
  import "./index.js";
2
2
  import { loadBalancer } from "./balancer.js";
3
- let cachedProviders = [];
3
+ const providerPromiseCache = /* @__PURE__ */ new Map();
4
+ let customProviderLoader = null;
5
+ function setProviderLoader(loader) {
6
+ customProviderLoader = loader;
7
+ }
4
8
  function _resetCache() {
5
- cachedProviders = [];
9
+ providerPromiseCache.clear();
6
10
  }
7
11
  function selectWeightedProvider(providers, entropy) {
8
12
  if (providers.length === 0) {
@@ -23,11 +27,28 @@ function selectWeightedProvider(providers, entropy) {
23
27
  }
24
28
  return selectedProvider;
25
29
  }
26
- const getRandomActiveProvider = async (env, entropy) => {
27
- if (cachedProviders.length === 0) {
28
- cachedProviders = await loadBalancer(env);
30
+ const loadProviders = async (env) => {
31
+ if (customProviderLoader) {
32
+ return customProviderLoader(env);
29
33
  }
30
- const randomProviderObj = selectWeightedProvider(cachedProviders, entropy);
34
+ return loadBalancer(env);
35
+ };
36
+ const getProvidersPromise = (env) => {
37
+ const existing = providerPromiseCache.get(env);
38
+ if (existing) return existing;
39
+ const promise = loadProviders(env).catch((err) => {
40
+ providerPromiseCache.delete(env);
41
+ throw err;
42
+ });
43
+ providerPromiseCache.set(env, promise);
44
+ return promise;
45
+ };
46
+ const prefetchProviders = async (env) => {
47
+ await getProvidersPromise(env);
48
+ };
49
+ const getRandomActiveProvider = async (env, entropy) => {
50
+ const providers = await getProvidersPromise(env);
51
+ const randomProviderObj = selectWeightedProvider(providers, entropy);
31
52
  return {
32
53
  providerAccount: randomProviderObj.address,
33
54
  provider: {
@@ -39,5 +60,7 @@ const getRandomActiveProvider = async (env, entropy) => {
39
60
  export {
40
61
  _resetCache,
41
62
  getRandomActiveProvider,
42
- selectWeightedProvider
63
+ prefetchProviders,
64
+ selectWeightedProvider,
65
+ setProviderLoader
43
66
  };
@@ -0,0 +1 @@
1
+ {"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":"providers.unit.test.d.ts","sourceRoot":"","sources":["../../src/tests/providers.unit.test.ts"],"names":[],"mappings":""}