Skip to content

Commit c45b0f0

Browse files
authored
Fix common-js build (Breaking Changes) (#437) RELEASE MINOR
* fix rollup * run build before test * move build to a step * readme
1 parent 3daaca9 commit c45b0f0

File tree

5 files changed

+23
-6
lines changed

5 files changed

+23
-6
lines changed

.github/workflows/ci.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ jobs:
9090
node-version: ${{ env.NODE_VERSION }}
9191
# Skip post-install scripts here, as a malicious
9292
# script could steal NODE_AUTH_TOKEN.
93-
- name: Install dependencies
94-
run: npm ci --ignore-scripts
93+
- name: Install dependencies and build
94+
run: npm ci --ignore-scripts && npm run build
9595
env:
9696
CI: true
9797
NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_READ_ORG }}

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,17 @@ Every `async` operation may fail. In case it does, there will be information reg
8989
A typical case of error handling might look something like:
9090

9191
```ts
92-
import { SdkResponse, descopeErrors } from '@descope/node-sdk';
92+
import DescopeClient, { SdkResponse } from '@descope/node-sdk';
93+
94+
const { DescopeErrors } = DescopeClient;
9395

9496
// ...
9597

9698
try {
9799
const resp = await sdk.otp.signIn.email(loginId);
98100
if (resp.error) {
99101
switch (resp.error.errorCode) {
100-
case descopeErrors.userNotFound:
102+
case DescopeErrors.userNotFound:
101103
// Handle specifically
102104
break;
103105
default:

lib/commonjs.test.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// this test requires to run `npm run build` before running the test
2+
3+
describe('commonjs build', () => {
4+
it('should default export a function with constants', () => {
5+
const DescopeClient = require('../dist/cjs/index.cjs.js') as any; // eslint-disable-line
6+
expect(typeof DescopeClient).toBe('function');
7+
// should have constants
8+
expect(DescopeClient.RefreshTokenCookieName).toBeTruthy();
9+
expect(DescopeClient.SessionTokenCookieName).toBeTruthy();
10+
expect(DescopeClient.DescopeErrors).toBeTruthy();
11+
});
12+
});
13+
14+
export {}; // eslint-disable-line

lib/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import fetch from './fetch-polyfill';
1515
import { getAuthorizationClaimItems, isUserAssociatedWithTenant, withCookie } from './helpers';
1616
import withManagement from './management';
1717
import { AuthenticationInfo } from './types';
18+
import descopeErrors from './errors';
1819

1920
declare const BUILD_VERSION: string;
2021

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

372373
nodeSdk.RefreshTokenCookieName = refreshTokenCookieName;
373374
nodeSdk.SessionTokenCookieName = sessionTokenCookieName;
375+
nodeSdk.DescopeErrors = descopeErrors;
374376

375377
export default nodeSdk;
376378
export type {
@@ -380,5 +382,4 @@ export type {
380382
ResponseData,
381383
SdkResponse,
382384
} from '@descope/core-js-sdk';
383-
export * as descopeErrors from './errors';
384385
export type { AuthenticationInfo };

rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default [
3434
file: packageJson.main,
3535
format: 'cjs',
3636
sourcemap: true,
37-
exports: 'auto',
37+
exports: 'default',
3838
},
3939
plugins,
4040
external,

0 commit comments

Comments
 (0)