Skip to content

Commit

Permalink
Fix common-js build (Breaking Changes) (#437) RELEASE MINOR
Browse files Browse the repository at this point in the history
* fix rollup

* run build before test

* move build to a step

* readme
  • Loading branch information
asafshen authored Feb 20, 2025
1 parent 3daaca9 commit c45b0f0
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ jobs:
node-version: ${{ env.NODE_VERSION }}
# Skip post-install scripts here, as a malicious
# script could steal NODE_AUTH_TOKEN.
- name: Install dependencies
run: npm ci --ignore-scripts
- name: Install dependencies and build
run: npm ci --ignore-scripts && npm run build
env:
CI: true
NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_READ_ORG }}
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,17 @@ Every `async` operation may fail. In case it does, there will be information reg
A typical case of error handling might look something like:

```ts
import { SdkResponse, descopeErrors } from '@descope/node-sdk';
import DescopeClient, { SdkResponse } from '@descope/node-sdk';

const { DescopeErrors } = DescopeClient;

// ...

try {
const resp = await sdk.otp.signIn.email(loginId);
if (resp.error) {
switch (resp.error.errorCode) {
case descopeErrors.userNotFound:
case DescopeErrors.userNotFound:
// Handle specifically
break;
default:
Expand Down
14 changes: 14 additions & 0 deletions lib/commonjs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// this test requires to run `npm run build` before running the test

describe('commonjs build', () => {
it('should default export a function with constants', () => {
const DescopeClient = require('../dist/cjs/index.cjs.js') as any; // eslint-disable-line
expect(typeof DescopeClient).toBe('function');
// should have constants
expect(DescopeClient.RefreshTokenCookieName).toBeTruthy();
expect(DescopeClient.SessionTokenCookieName).toBeTruthy();
expect(DescopeClient.DescopeErrors).toBeTruthy();
});
});

export {}; // eslint-disable-line
3 changes: 2 additions & 1 deletion lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import fetch from './fetch-polyfill';
import { getAuthorizationClaimItems, isUserAssociatedWithTenant, withCookie } from './helpers';
import withManagement from './management';
import { AuthenticationInfo } from './types';
import descopeErrors from './errors';

declare const BUILD_VERSION: string;

Expand Down Expand Up @@ -371,6 +372,7 @@ const nodeSdk = ({ managementKey, publicKey, ...config }: NodeSdkArgs) => {

nodeSdk.RefreshTokenCookieName = refreshTokenCookieName;
nodeSdk.SessionTokenCookieName = sessionTokenCookieName;
nodeSdk.DescopeErrors = descopeErrors;

export default nodeSdk;
export type {
Expand All @@ -380,5 +382,4 @@ export type {
ResponseData,
SdkResponse,
} from '@descope/core-js-sdk';
export * as descopeErrors from './errors';
export type { AuthenticationInfo };
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default [
file: packageJson.main,
format: 'cjs',
sourcemap: true,
exports: 'auto',
exports: 'default',
},
plugins,
external,
Expand Down

0 comments on commit c45b0f0

Please sign in to comment.