Skip to content

Commit c556d16

Browse files
authored
pre-alpha: Add descope headers to node sdk, fix build, lint, fix examples (#70)
1. Add descope headers to node sdk 2. Fix build 3. Fix lint 4. Fix format 5. Add husky to commit 6. Fix examples
1 parent d2d0121 commit c556d16

29 files changed

+2703
-1093
lines changed

.eslintrc.cjs .eslintrc.json

+35-36
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
1-
const fs = require('fs');
2-
3-
module.exports = {
4-
root: true,
5-
extends: ['airbnb-base', 'prettier', 'plugin:jest/recommended', 'plugin:import/typescript', 'airbnb-typescript/base'],
6-
plugins: [
1+
{
2+
"root": true,
3+
"extends": [
4+
"airbnb-base",
5+
"prettier",
6+
"plugin:jest/recommended",
7+
"plugin:import/typescript",
8+
"airbnb-typescript/base"
9+
],
10+
"plugins": [
711
"@typescript-eslint",
812
"prettier",
913
"import",
1014
"prefer-arrow",
1115
"jest-dom",
1216
"jest",
1317
"jest-formatting",
14-
"no-only-tests"],
15-
parser: '@typescript-eslint/parser',
16-
parserOptions: {
17-
project: './tsconfig.json',
18+
"no-only-tests"
19+
],
20+
"parser": "@typescript-eslint/parser",
21+
"parserOptions": {
22+
"project": "./tsconfig.json"
1823
},
19-
env: {
20-
jest: true,
21-
node: true,
24+
"env": {
25+
"jest": true,
26+
"node": true
2227
},
23-
settings: {
28+
"settings": {
2429
"import/parsers": {
2530
"@typescript-eslint/parser": [".ts", ".tsx", ".js"]
2631
},
@@ -30,24 +35,20 @@ module.exports = {
3035
}
3136
}
3237
},
33-
rules: {
38+
"rules": {
39+
"semi": ["error", "always"],
3440
"no-tabs": ["error", { "allowIndentationTabs": true }],
3541
"@typescript-eslint/indent": ["off"],
36-
"quotes": [
37-
"error",
38-
"single",
39-
{ "avoidEscape": true, "allowTemplateLiterals": true }
40-
],
42+
"quotes": ["error", "single", { "avoidEscape": true, "allowTemplateLiterals": true }],
4143
"@typescript-eslint/quotes": [
4244
"error",
4345
"single",
4446
{ "avoidEscape": true, "allowTemplateLiterals": true }
4547
],
46-
"semi": ["error", "never"],
4748
"space-before-blocks": 2,
4849
"space-before-function-paren": 2,
4950
"no-multi-spaces": 2,
50-
"@typescript-eslint/semi": "off",
51+
"@typescript-eslint/semi": "error",
5152
"no-unexpected-multiline": "error",
5253
"@typescript-eslint/comma-dangle": ["off"],
5354
"comma-dangle": ["off"],
@@ -71,21 +72,19 @@ module.exports = {
7172
"import/no-extraneous-dependencies": [
7273
2,
7374
{
74-
"devDependencies": [
75-
"!./src/**/*"
76-
]
75+
"devDependencies": ["!./src/**/*"]
7776
}
7877
],
79-
'import/extensions': [
80-
'error',
81-
'ignorePackages',
78+
"import/extensions": [
79+
"error",
80+
"ignorePackages",
8281
{
83-
js: 'never',
84-
jsx: 'never',
85-
ts: 'never',
86-
tsx: 'never',
87-
},
88-
],
82+
"js": "never",
83+
"jsx": "never",
84+
"ts": "never",
85+
"tsx": "never"
86+
}
87+
]
8988
},
90-
ignorePatterns: ['.eslintrc.cjs', 'build/*', 'dist/*', 'coverage/*', '**/testutils/*'],
91-
};
89+
"ignorePatterns": [".eslintrc.cjs", "build/*", "dist/*", "coverage/*", "**/testutils/*"]
90+
}

.github/workflows/build_docker.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,21 @@ jobs:
3939
CI: true
4040

4141
- name: Build example
42-
run: npm run build
42+
run: npm run build
4343
working-directory: examples/es6
4444
env:
45-
CI: true
45+
CI: true
4646

4747
- name: Build example cert
48-
run: npm run generateCerts
48+
run: npm run generateCerts
4949
working-directory: examples/es6
5050
env:
51-
CI: true
51+
CI: true
5252

5353
- name: Build example docker image
5454
working-directory: examples/es6
5555
run: |
56-
docker build . --tag ${{ env.EXAMPLE_IMAGE_NAME }}
56+
docker build . --tag ${{ env.EXAMPLE_IMAGE_NAME }}
5757
5858
- name: Log in to the Container registry
5959
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
@@ -62,4 +62,4 @@ jobs:
6262
username: ${{ github.actor }}
6363
password: ${{ secrets.GITHUB_TOKEN }}
6464
- name: Push the tagged Docker image
65-
run: docker push ${{ env.EXAMPLE_IMAGE_NAME }}
65+
run: docker push ${{ env.EXAMPLE_IMAGE_NAME }}

.github/workflows/ci.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ jobs:
2727
run: npm run build
2828
env:
2929
NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_READ_ORG }}
30-
- name: Examples
31-
run: |
32-
(cd examples/es6 && npm i && npm run build)
33-
(cd examples/commonjs && npm i)
30+
- name: Examples - es6
31+
run: cd examples/es6 && npm i && npm run build
32+
- name: Examples - common
33+
run: cd examples/commonjs && npm i
3434

3535
eslint:
3636
name: 🪥 ESLint
@@ -49,7 +49,7 @@ jobs:
4949
env:
5050
CI: true
5151
NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_READ_ORG }}
52-
- run: npm run check-format
52+
- run: npm run format-check
5353
- run: npm run lint
5454

5555
gitleaks:
@@ -70,8 +70,7 @@ jobs:
7070
CI: true
7171
NODE_AUTH_TOKEN: ${{ secrets.CI_NPM_READ_ORG }}
7272
- name: Gitleaks
73-
run: |
74-
npm run leaks
73+
run: npm run leaks
7574
shell: bash
7675

7776
unit-test:

.github/workflows/publish.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: 📢 publish
22

33
on:
4-
create:
4+
push:
55
tags:
66
- 'release/**'
77

.husky/pre-commit

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
npm run format
2-
npm run lint
3-
npm run leaks
4-
npm test
1+
npm run format-lint

.npmrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# @descope:registry=https://npm.pkg.github.com
1+
@descope:registry=https://registry.npmjs.org

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"printWidth": 100,
33
"tabWidth": 2,
44
"useTabs": false,
5-
"semi": false,
5+
"semi": true,
66
"singleQuote": true,
77
"trailingComma": "all"
88
}

README.md

+19-18
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ npm i --save @descope/node-sdk
1414

1515
## What do you want to implement?
1616

17-
Click one of the following links to open the documentation for that specific functionality.
17+
Click one of the following links to open the documentation for that specific functionality.
1818

1919
- [x] [One time passwords (OTP)](./docs/otp.md)
2020
- [x] [Magic Links](./docs/magiclink.md)
@@ -26,7 +26,7 @@ Instantly run the end-to-end ExpresSDK for NodeJS examples, as shown below. The
2626

2727
### Prerequisites
2828

29-
Run the following commands in your project. Replace any instance of `<ProjectID>` in the code below with your company's Project ID, which can be found in the [Descope console](https://app.descope.com).
29+
Run the following commands in your project. Replace any instance of `<ProjectID>` in the code below with your company's Project ID, which can be found in the [Descope console](https://app.descope.com).
3030

3131
This commands will add the Descope NodeJS SDK as a project dependency, clone the SDK repository locally, and set the `DESCOPE_PROJECT_ID`.
3232

@@ -40,27 +40,28 @@ export DESCOPE_PROJECT_ID=<ProjectID>
4040
**TL;DR**: Run `npm run quick`
4141

4242
Run the following commands in the root of the project to build and run the examples.
43+
4344
1. Run this to start the ES6 typescript module example
4445

45-
```code bash
46-
npm i && \
47-
npm run build && \
48-
cd examples/es6 && \
49-
npm i && \
50-
npm run generateCerts && \
51-
npm start
52-
```
46+
```code bash
47+
npm i && \
48+
npm run build && \
49+
cd examples/es6 && \
50+
npm i && \
51+
npm run generateCerts && \
52+
npm start
53+
```
5354

5455
2. Run this to start the commonjs example
5556

56-
```code bash
57-
npm i && \
58-
npm run build && \
59-
cd examples/commonjs && \
60-
npm i && \
61-
npm run generateCerts && \
62-
npm start
63-
```
57+
```code bash
58+
npm i && \
59+
npm run build && \
60+
cd examples/commonjs && \
61+
npm i && \
62+
npm run generateCerts && \
63+
npm start
64+
```
6465

6566
## License
6667

docs/magiclink.md

+25-23
Original file line numberDiff line numberDiff line change
@@ -11,52 +11,54 @@ flowchart LR
1111

1212
### Prerequisites
1313

14-
Replace any instance of `<ProjectID>` in the code below with your company's Project ID, which can be found in the [Descope console](https://app.descope.com).
14+
Replace any instance of `<ProjectID>` in the code below with your company's Project ID, which can be found in the [Descope console](https://app.descope.com).
1515

16-
* Run the following commands in your project
16+
- Run the following commands in your project
1717

18-
These commands will add the Descope NodeJS SDK as a project dependency.
18+
These commands will add the Descope NodeJS SDK as a project dependency.
1919

20-
```bash
21-
npm i --save @descope/node-sdk
22-
```
20+
```bash
21+
npm i --save @descope/node-sdk
22+
```
2323

24-
* Import and initialize the ExpresSDK for NodeJS client in your source code
24+
- Import and initialize the ExpresSDK for NodeJS client in your source code
2525

26-
```javascript
27-
import DescopeClient from '@descope/node-sdk';
28-
const descopeClient = DescopeClient({ projectId: <ProjectID> });
29-
```
30-
or
26+
```javascript
27+
import DescopeClient from '@descope/node-sdk';
28+
const descopeClient = DescopeClient({ projectId: <ProjectID> });
29+
```
3130

32-
```javascript
33-
const sdk = require('@descope/node-sdk');
34-
const descopeClient = sdk({ projectId: <ProjectID> });
35-
```
31+
or
32+
33+
```javascript
34+
const sdk = require('@descope/node-sdk');
35+
const descopeClient = sdk({ projectId: <ProjectID> });
36+
```
3637

3738
### 1. Customer Sign-up
3839

3940
In your sign-up route using magic link (for example, `myapp.com/signup`) generate a sign-up request and send the magic link via the selected delivery method. In the example below an email is sent to "[email protected]" containing the magic link and the link will automatically return back to the provided URL ("https://mydomain.com/verify"). In additon, optional user data (for exmaple, a custom username in the code sample below) can be gathered during the sign-up process.
4041

4142
```javascript
42-
await descopeClient.magiclink.signUp.email("[email protected]", { name: "custom name" })
43+
await descopeClient.magiclink.signUp.email('[email protected]', { name: 'custom name' });
4344
```
4445

4546
### 2. Customer Sign-in
46-
In your sign-in route using magic link (for exmaple, `myapp.com/login`) generate a sign-in request send the magic link via the selected delivery method. In the example below an email is sent to "[email protected]" containing the magic link and the link will automatically return back to the provided URL ("https://mydomain.com/verify").
47+
48+
In your sign-in route using magic link (for exmaple, `myapp.com/login`) generate a sign-in request send the magic link via the selected delivery method. In the example below an email is sent to "[email protected]" containing the magic link and the link will automatically return back to the provided URL ("https://mydomain.com/verify").
4749

4850
```javascript
49-
await descopeClient.magiclink.signIn.email("[email protected]")
51+
await descopeClient.magiclink.signIn.email('[email protected]');
5052
```
5153

5254
### 3. Customer Verification
5355

5456
In your verify customer route for magic link (for example, `mydomain.com/verify`) verify the token from either a customer sign-up or sign-in.
5557

5658
```javascript
57-
const out = await descopeClient.magiclink.verify(token)
59+
const out = await descopeClient.magiclink.verify(token);
5860
if (out.data.cookies) {
59-
res.set('Set-Cookie', out.data.cookies)
61+
res.set('Set-Cookie', out.data.cookies);
6062
}
6163
```
6264

@@ -65,8 +67,8 @@ if (out.data.cookies) {
6567
Session validation checks to see that the visitor to your website or application is who they say they are, by comparing the value in the validation variables against the session data that is already stored.
6668

6769
```javascript
68-
const out = await descopeClient.validateSession(session_jwt, refresh_jwt)
70+
const out = await descopeClient.validateSession(session_jwt, refresh_jwt);
6971
if (out?.cookies) {
70-
res.set('Set-Cookie', out.cookies)
72+
res.set('Set-Cookie', out.cookies);
7173
}
7274
```

0 commit comments

Comments
 (0)