pmxtjs 2.49.10 → 2.50.2

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 (42) hide show
  1. package/dist/esm/generated/src/apis/DefaultApi.d.ts +28 -0
  2. package/dist/esm/generated/src/apis/DefaultApi.js +28 -0
  3. package/dist/esm/index.d.ts +4 -3
  4. package/dist/esm/index.js +4 -3
  5. package/dist/esm/pmxt/client.d.ts +37 -25
  6. package/dist/esm/pmxt/client.js +117 -202
  7. package/dist/esm/pmxt/constants.d.ts +4 -0
  8. package/dist/esm/pmxt/constants.js +6 -0
  9. package/dist/esm/pmxt/hosted-routing.js +1 -0
  10. package/dist/esm/pmxt/hosted-typed-data.d.ts +1 -1
  11. package/dist/esm/pmxt/hosted-typed-data.js +53 -12
  12. package/dist/esm/pmxt/models.d.ts +1 -0
  13. package/dist/esm/pmxt/router.js +12 -3
  14. package/dist/esm/pmxt/signers.d.ts +7 -0
  15. package/dist/esm/pmxt/signers.js +30 -8
  16. package/dist/generated/src/apis/DefaultApi.d.ts +28 -0
  17. package/dist/generated/src/apis/DefaultApi.js +28 -0
  18. package/dist/index.d.ts +4 -3
  19. package/dist/index.js +6 -1
  20. package/dist/pmxt/client.d.ts +37 -25
  21. package/dist/pmxt/client.js +116 -200
  22. package/dist/pmxt/constants.d.ts +4 -0
  23. package/dist/pmxt/constants.js +7 -1
  24. package/dist/pmxt/hosted-routing.js +1 -0
  25. package/dist/pmxt/hosted-typed-data.d.ts +1 -1
  26. package/dist/pmxt/hosted-typed-data.js +53 -12
  27. package/dist/pmxt/models.d.ts +1 -0
  28. package/dist/pmxt/router.js +12 -3
  29. package/dist/pmxt/signers.d.ts +7 -0
  30. package/dist/pmxt/signers.js +31 -8
  31. package/generated/docs/DefaultApi.md +56 -56
  32. package/generated/package.json +1 -1
  33. package/generated/src/apis/DefaultApi.ts +28 -0
  34. package/index.ts +12 -3
  35. package/package.json +2 -2
  36. package/pmxt/client.ts +123 -219
  37. package/pmxt/constants.ts +7 -0
  38. package/pmxt/hosted-routing.ts +1 -0
  39. package/pmxt/hosted-typed-data.ts +67 -17
  40. package/pmxt/models.ts +3 -0
  41. package/pmxt/router.ts +14 -3
  42. package/pmxt/signers.ts +28 -7
package/pmxt/signers.ts CHANGED
@@ -38,6 +38,33 @@ export interface Signer {
38
38
  const ETHERS_INSTALL_HINT =
39
39
  "hosted trading requires the optional 'ethers' peer dependency. Install with: npm install ethers";
40
40
 
41
+ /**
42
+ * Load ethers lazily in BOTH module systems. The CJS build has native
43
+ * `require`; the ESM build does not — bare `require("ethers")` there threw
44
+ * ReferenceError, which callers swallowed, silently dropping the signer and
45
+ * killing every hosted write with "hosted write requires a signer".
46
+ */
47
+ export function loadEthers(installHint: string = ETHERS_INSTALL_HINT): any {
48
+ if (typeof require === "function") {
49
+ try {
50
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
51
+ return require("ethers");
52
+ } catch {
53
+ throw new Error(installHint);
54
+ }
55
+ }
56
+ // ESM: synthesize a require. getBuiltinModule is sync-safe in both
57
+ // module systems (Node >= 20.16).
58
+ const nodeModule = (globalThis as any).process?.getBuiltinModule?.("node:module");
59
+ const req = nodeModule?.createRequire?.(`${process.cwd()}/__pmxt_resolver__.js`);
60
+ if (!req) throw new Error(installHint);
61
+ try {
62
+ return req("ethers");
63
+ } catch {
64
+ throw new Error(installHint);
65
+ }
66
+ }
67
+
41
68
  /**
42
69
  * Built-in signer backed by an ethers `Wallet`.
43
70
  *
@@ -49,13 +76,7 @@ export class EthersSigner implements Signer {
49
76
  readonly address: string;
50
77
 
51
78
  constructor(privateKey: string) {
52
- let ethers: any;
53
- try {
54
- // eslint-disable-next-line @typescript-eslint/no-require-imports
55
- ethers = require("ethers");
56
- } catch {
57
- throw new Error(ETHERS_INSTALL_HINT);
58
- }
79
+ const ethers = loadEthers();
59
80
  this._wallet = new ethers.Wallet(privateKey);
60
81
  this.address = this._wallet.address;
61
82
  }