MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.63k stars 138 forks source link

feat/helpers-export #142

Closed MasterKale closed 3 years ago

MasterKale commented 3 years ago

This PR exports of all current helpers for piecemeal use by those looking to leverage some of the conveniences hidden within the server library.

Addresses #140.

MasterKale commented 3 years ago

I've been having trouble pulling this off - the best I've been able to manage is an exported helpers object out of @simplewebauthn/server, but what I really want is to export everything in src/helpers/index.ts as @simplewebauthn/server/helpers.

@akanass Do you have any bundling advice on how to accomplish this?

akanass commented 3 years ago

@MasterKale thank you to involve me on this PR.

I am currently on holidays so I will check it ASAP and I hope to find something good to help you.

Cheers

MasterKale commented 3 years ago

I think I figured it out: a combination of "exports" and "typesVersions" in packages/server/package.json allowed me to create two files within the example/ project that had no problems importing from both @simplewebauthn/server and @simplewebauthn/server/helpers:

helpersTest.ts

import { generateChallenge } from '@simplewebauthn/server/helpers';
import { SettingsService } from '@simplewebauthn/server';

console.log(generateChallenge());
console.log(SettingsService.getRootCertificates({ identifier: 'mds' }));

helpersTest.js

const { generateChallenge } = require('@simplewebauthn/server/helpers');
const { SettingsService } = require('@simplewebauthn/server');

console.log(generateChallenge());
console.log(SettingsService.getRootCertificates({ identifier: 'mds' }));

I'm leaving a couple of links here that helped me get to this solution: