Skip to content

Conversation

@Smeagolworms4
Copy link

  • Add ESM Module version cross build commonjs.
  • Update to fetch 3 (compatibility commonjs)

@Smeagolworms4
Copy link
Author

All test work.

@adohertyTS
Copy link
Contributor

@Smeagolworms4 can you explain to me a little more what is the purpose of this pull request? What is the problem you are trying to solve?

@Smeagolworms4
Copy link
Author

Smeagolworms4 commented Apr 16, 2025

The current version of telesign doesn't work with an esmodule environment. Ans, version 3 of fetch is necessarily esmodule. The pull request I'm sending you allows you to generate a commonjs + esmodule version. And all the tests are up to date. There's even an action that runs them.

@Smeagolworms4
Copy link
Author

also it adds typescript typing (even if it is a basic version)

@Smeagolworms4 Smeagolworms4 force-pushed the master branch 3 times, most recently from 77bdcf1 to 4727149 Compare April 16, 2025 18:43
@Smeagolworms4
Copy link
Author

In package.json:

Add ESM and CJS version of module (it's retrocompatible) :

"main": "dist/cjs/TeleSign.js",
  "module": "dist/esm/TeleSign.js",  // ESM
  "types": "dist/types/TeleSign.d.ts", // Typing Typescript
  "exports": {
    ".": {
      "require": "./dist/cjs/TeleSign.js", // CJS
      "import": "./dist/esm/TeleSign.js" // ESM
    }
  },

Depencency fetch 2 and 3 :

  "peerDependencies": {
    "node-fetch": "^2.6.0 || ^3.0.0"
  }

This code use fetch on global or window if already loaded.
else load fetch from node_modules with 2 and 3 version.

async function fetchWithTimeout(url, options) {
  /** @type {any} */
  let fetch = (typeof window !== 'undefined' ? window : global).fetch || null;
  if (!fetch) {
    fetch = await import('node-fetch').then(m => m.default ?? m);
  }
  return await Promise.race([
    fetch(url, options),
    new Promise((_, reject) => setTimeout(() => reject({ code: 408, message: 'Timeout' }), options.timeout))
  ]);
}

@adohertyTS
Copy link
Contributor

@Smeagolworms4 thanks for the clarification. I'll pass this along to the relevant product team to review.

@Smeagolworms4
Copy link
Author

Fix last rebase main version

@Smeagolworms4
Copy link
Author

Any news? As long as it's not merged, it's going to accumulate conflicts. The current version doesn't support esm and fetch 3. And this version has basic ts typing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants