Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: run prettier on entire repo
  • Loading branch information
max-stytch committed Feb 14, 2023
commit a7a3827b90f23038bc1e81858d07e4b5ad7e4263
11 changes: 3 additions & 8 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
plugins: [
'@typescript-eslint',
],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
],
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
};
6 changes: 3 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Lint
on:
push:
branches: ['main']
branches: ["main"]
pull_request:

jobs:
Expand All @@ -12,7 +12,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
node-version: "16"
- run: npm install
- run: npm run lint

Expand All @@ -23,6 +23,6 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
node-version: "16"
- run: npm install
- run: npm run check-format
6 changes: 3 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Test
on:
push:
branches: ['main']
branches: ["main"]
pull_request:

jobs:
Expand All @@ -27,7 +27,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
node-version: "16"
- run: npm ci
- run: npm test
env:
Expand All @@ -46,7 +46,7 @@ jobs:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
node-version: "16"
- run: npm ci
- run: npm run build
- run: git diff --exit-code
22 changes: 11 additions & 11 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,21 @@ orientation.
Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
- The use of sexualized language or imagery and unwelcome sexual attention or
advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities
Expand Down
4 changes: 2 additions & 2 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Thanks for contributing to Stytch's Node library! If you run into trouble, find
## Setup

1. Install a supported stable release of [Node](https://nodejs.org/).
- You may find the currently supported Node version in this repo's `.nvmrc` file.
- You may find the currently supported Node version in this repo's `.nvmrc` file.
2. Clone this repo.
3. Run `npm install`.

Expand Down Expand Up @@ -45,4 +45,4 @@ If you have non-trivial changes you'd like us to incorporate, please open an iss

When you're ready for someone to look at your issue or PR, assign `@stytchauth/client-libraries` (GitHub should do this automatically). If we don't acknowledge it within one business day, please escalate it by tagging `@stytchauth/engineering` in a comment or letting us know in [Slack].

[Slack]: https://join.slack.com/t/stytch/shared_invite/zt-nil4wo92-jApJ9Cl32cJbEd9esKkvyg
[slack]: https://join.slack.com/t/stytch/shared_invite/zt-nil4wo92-jApJ9Cl32cJbEd9esKkvyg
38 changes: 23 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ yarn add stytch
You can find your API credentials in the [Stytch Dashboard](https://stytch.com/dashboard/api-keys).

This client library supports all of Stytch's live products:
- [x] [Email Magic Links](https://stytch.com/docs/api/send-by-email)
- [x] [Embeddable Magic Links](https://stytch.com/docs/api/create-magic-link-overview)
- [x] [OAuth logins](https://stytch.com/docs/api/oauth-overview)
- [x] [SMS passcodes](https://stytch.com/docs/api/send-otp-by-sms)
- [x] [WhatsApp passcodes](https://stytch.com/docs/api/whatsapp-send)
- [x] [Email passcodes](https://stytch.com/docs/api/send-otp-by-email)
- [x] [Session Management](https://stytch.com/docs/api/sessions-overview)
- [x] [WebAuthn](https://stytch.com/docs/api/webauthn-overview)
- [x] [User Management](https://stytch.com/docs/api/users)
- [x] [Time-based one-time passcodes (TOTPs)](https://stytch.com/docs/api/totps-overview)
- [x] [Crypto wallets](https://stytch.com/docs/api/crypto-wallet-overview)
- [x] [Passwords](https://stytch.com/docs/api/password-overview)

- [x] [Email Magic Links](https://stytch.com/docs/api/send-by-email)
- [x] [Embeddable Magic Links](https://stytch.com/docs/api/create-magic-link-overview)
- [x] [OAuth logins](https://stytch.com/docs/api/oauth-overview)
- [x] [SMS passcodes](https://stytch.com/docs/api/send-otp-by-sms)
- [x] [WhatsApp passcodes](https://stytch.com/docs/api/whatsapp-send)
- [x] [Email passcodes](https://stytch.com/docs/api/send-otp-by-email)
- [x] [Session Management](https://stytch.com/docs/api/sessions-overview)
- [x] [WebAuthn](https://stytch.com/docs/api/webauthn-overview)
- [x] [User Management](https://stytch.com/docs/api/users)
- [x] [Time-based one-time passcodes (TOTPs)](https://stytch.com/docs/api/totps-overview)
- [x] [Crypto wallets](https://stytch.com/docs/api/crypto-wallet-overview)
- [x] [Passwords](https://stytch.com/docs/api/password-overview)

### Example usage

Create an API client:

```javascript
const stytch = require("stytch");
// Or as an ES6 module:
Expand All @@ -47,6 +50,7 @@ const client = new stytch.Client({
```

Send a magic link by email:

```javascript
client.magicLinks.email
.loginOrCreate({
Expand All @@ -59,6 +63,7 @@ client.magicLinks.email
```

Authenticate the token from the magic link:

```javascript
client.magicLinks
.authenticate("DOYoip3rvIMMW5lgItikFK-Ak1CfMsgjuiCyI7uuU94=")
Expand All @@ -69,6 +74,7 @@ client.magicLinks
## Handling Errors

Stytch errors always include an `error_type` field you can use to identify them:

```javascript
client.magicLinks
.authenticate("not-a-token!")
Expand All @@ -79,16 +85,18 @@ client.magicLinks
}
});
```

Learn more about errors in the [docs](https://stytch.com/docs/api/errors).

## Customizing the HTTPS Agent
The Stytch client can be customized to use your own HTTPS agent.

The Stytch client can be customized to use your own HTTPS agent.
For example, you can enable HTTPS Keep-Alive to avoid the cost of establishing a new connection with the Stytch servers on every request.

```javascript
const agent = new https.Agent({
keepAlive: true
})
keepAlive: true,
});

const client = new stytch.Client({
project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317",
Expand Down
4 changes: 1 addition & 3 deletions babel.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@
"@babel/preset-typescript"
],
"targets": "node 14",
"ignore": [
"**/__mocks__/**"
]
"ignore": ["**/__mocks__/**"]
}
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
preset: "ts-jest",
testEnvironment: "node",
globals: {
'ts-jest': {
"ts-jest": {
// Setting this greatly speeds up test execution time
// https://stackoverflow.com/questions/45087018/jest-simple-tests-are-slow
isolatedModules: true,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
},
"scripts": {
"build": "rm -rf dist types && babel lib --out-dir dist --extensions '.ts' && tsc --declaration --outDir types --emitDeclarationOnly",
"format": "prettier --write lib",
"check-format": "prettier --check lib",
"format": "prettier --write .",
"check-format": "prettier --check .",
"lint": "eslint lib",
"test": "jest",
"test-packages": "./test-packages/test.sh"
Expand Down
1 change: 0 additions & 1 deletion test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ describe("config errors", () => {
}).toThrow(/Missing "env" in config/);
});
});

6 changes: 3 additions & 3 deletions test/crypto_wallets.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CryptoWallets } from "../lib/crypto_wallets";
import { MOCK_FETCH_CONFIG, mockRequest } from "./helpers";

jest.mock('../lib/shared');
jest.mock("../lib/shared");

describe("cryptowallets.authenticateStart", () => {
test("success", () => {
Expand All @@ -11,7 +11,7 @@ describe("cryptowallets.authenticateStart", () => {
path: "crypto_wallets/authenticate/start",
data: {
crypto_wallet_address: "0x1234567890123456789012345678901234567890",
crypto_wallet_type: "ethereum"
crypto_wallet_type: "ethereum",
},
});

Expand All @@ -28,7 +28,7 @@ describe("cryptowallets.authenticateStart", () => {
return expect(
cryptoWallets.authenticateStart({
crypto_wallet_address: "0x1234567890123456789012345678901234567890",
crypto_wallet_type: "ethereum"
crypto_wallet_type: "ethereum",
})
).resolves.toMatchObject({
request_id: "request-id-test-55555555-5555-4555-8555-555555555555",
Expand Down
34 changes: 19 additions & 15 deletions test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,28 @@ export const MOCK_FETCH_CONFIG = {
};

export function mockRequest(
handler: (config: Request) => Response,
handler: (config: Request) => Response
// eslint-disable-next-line @typescript-eslint/no-explicit-any
): void {
if (!(request as jest.Mock).mockImplementation) {
throw Error(`request() is not a jest mock. Be sure to call "jest.mock('../lib/shared');" before using this helper!`);
throw Error(
`request() is not a jest mock. Be sure to call "jest.mock('../lib/shared');" before using this helper!`
);
}
(request as jest.Mock).mockReset();
(request as jest.Mock).mockImplementation((_, requestConfig: requestConfig) => {
const request = {
method: requestConfig.method?.toString() || "",
path: requestConfig.url?.toString() || "",
params: requestConfig.params,
data: requestConfig.data,
};
const { status, data } = handler(request);
return Promise.resolve({
status,
...data,
});
});
(request as jest.Mock).mockImplementation(
(_, requestConfig: requestConfig) => {
const request = {
method: requestConfig.method?.toString() || "",
path: requestConfig.url?.toString() || "",
params: requestConfig.params,
data: requestConfig.data,
};
const { status, data } = handler(request);
return Promise.resolve({
status,
...data,
});
}
);
}
2 changes: 1 addition & 1 deletion test/magic_links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { MagicLinks } from "../lib/magic_links";
import { MOCK_FETCH_CONFIG } from "./helpers";
import { request } from "../lib/shared";

jest.mock('../lib/shared');
jest.mock("../lib/shared");
beforeEach(() => {
(request as jest.Mock).mockReset();
(request as jest.Mock).mockImplementation((_, config) => {
Expand Down
4 changes: 1 addition & 3 deletions test/oauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const oauth = new OAuth(MOCK_FETCH_CONFIG);

describe("oauth.authenticate", () => {
test("session", () => {
return expect(
oauth.authenticate("fake-token")
).resolves.toMatchObject({
return expect(oauth.authenticate("fake-token")).resolves.toMatchObject({
method: "POST",
path: "oauth/authenticate",
data: {
Expand Down
4 changes: 1 addition & 3 deletions test/otps.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

import { OTPs } from "../lib/otps";
import { MOCK_FETCH_CONFIG } from "./helpers";
import { request } from "../lib/shared";

jest.mock('../lib/shared');
jest.mock("../lib/shared");
beforeEach(() => {
(request as jest.Mock).mockReset();
(request as jest.Mock).mockImplementation((_, config) => {
Expand All @@ -16,7 +15,6 @@ beforeEach(() => {
});
});


const otps = new OTPs(MOCK_FETCH_CONFIG);

describe("otps.authenticate", () => {
Expand Down
Loading