-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(testing): Add test projects for Cloudflare Workers. Vercel Remix…
… + NextJS, Deno, and Bun (#252) Adds a new test-runtimes directory with setup instructions for various runtimes the Node SDK can be used in. Hopefully this will make it easier to test iterations of the Node SDK in different runtimes. Runtimes are not plug&play, developers will need to install various things, make accounts with providers, etc. The following runtimes are tested: cloudflare-workers remix nextjs serverless nextjs edge deno bun
- Loading branch information
1 parent
5b3e6d1
commit 2479bd3
Showing
45 changed files
with
1,636 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Exclude lockfiles for packaging tests to reduce file churn | ||
/*/package-lock.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
## Test Runtime Fixtures | ||
|
||
The Javascript language has a _LOT_ of runtimes. We try to support them all. If you're having trouble using Stytch due to | ||
a runtime-related reason, please [open an issue](https://github.com/stytchauth/stytch-node/issues/new) and we'll take a look. | ||
|
||
This directory contains test fixtures that make it easier to quickly use the `stytch` package in a number of locations. | ||
This directory is a scratch space - expect things to be slightly broken or cumbersome to use. For example, we don't have | ||
any CI/CD set up for these projects, and if you want to contribute you'll need to create your own credentials for use with | ||
various runtime providers. | ||
|
||
When adding a new runtime, try to keep the fixture as close to minimal as possible. For example, prefer a `npx create-project...` style command. | ||
|
||
Runtime validation is defined as: | ||
|
||
- The Stytch client can be successfully imported | ||
- The Stytch client can make a successful network request to the Stytch servers | ||
|
||
We can use the following project ID and secret, which are special values that return a pre-canned response from Stytch: | ||
|
||
```javascript | ||
// Find these values at https://stytch.com/dashboard/api-keys | ||
// These ones will trigger a well-known erorr message | ||
const client = new stytch.Client({ | ||
project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317", | ||
secret: "secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=", | ||
}); | ||
``` | ||
|
||
## Runtime Notes | ||
|
||
All Runtimes: | ||
|
||
- Each runtime maintains its own `package.json` and set of node modules. We'll use real workspaces SomeDay™️ | ||
- The `stytch` version in the package might need manual adjusting. It could be a prerelease version of something you'd like to check, or `../..` to use the local copy of `stytch`. | ||
- Local copies don't seem to work with Vercel production builds, only, well, locally | ||
|
||
### Cloudflare Workers | ||
|
||
- You'll need a Cloudflare account | ||
- `npm run start` for local development | ||
- `npm run deploy` will build and deploy the worker. The CLI should guide you through credential setupneed to publish a package | ||
|
||
### Remix | ||
|
||
- You'll need a Vercel account | ||
- `npm run dev` for local development | ||
- `npx vercel` to deploy to vercel | ||
|
||
## NextJS | ||
|
||
- You'll need a Vercel account | ||
- `npm run dev` for local development | ||
- `npx vercel` to deploy to vercel | ||
- `/api/hello` runs a serverless request | ||
- `/api/edge` runs an edge request | ||
|
||
## Deno | ||
|
||
TODO! | ||
|
||
## Bun | ||
|
||
TODO! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
# Based on https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore | ||
|
||
# Logs | ||
|
||
logs | ||
_.log | ||
npm-debug.log_ | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
.pnpm-debug.log* | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
|
||
report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json | ||
|
||
# Runtime data | ||
|
||
pids | ||
_.pid | ||
_.seed | ||
\*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
|
||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
|
||
coverage | ||
\*.lcov | ||
|
||
# nyc test coverage | ||
|
||
.nyc_output | ||
|
||
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) | ||
|
||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
|
||
bower_components | ||
|
||
# node-waf configuration | ||
|
||
.lock-wscript | ||
|
||
# Compiled binary addons (https://nodejs.org/api/addons.html) | ||
|
||
build/Release | ||
|
||
# Dependency directories | ||
|
||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Snowpack dependency directory (https://snowpack.dev/) | ||
|
||
web_modules/ | ||
|
||
# TypeScript cache | ||
|
||
\*.tsbuildinfo | ||
|
||
# Optional npm cache directory | ||
|
||
.npm | ||
|
||
# Optional eslint cache | ||
|
||
.eslintcache | ||
|
||
# Optional stylelint cache | ||
|
||
.stylelintcache | ||
|
||
# Microbundle cache | ||
|
||
.rpt2_cache/ | ||
.rts2_cache_cjs/ | ||
.rts2_cache_es/ | ||
.rts2_cache_umd/ | ||
|
||
# Optional REPL history | ||
|
||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
|
||
\*.tgz | ||
|
||
# Yarn Integrity file | ||
|
||
.yarn-integrity | ||
|
||
# dotenv environment variable files | ||
|
||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# parcel-bundler cache (https://parceljs.org/) | ||
|
||
.cache | ||
.parcel-cache | ||
|
||
# Next.js build output | ||
|
||
.next | ||
out | ||
|
||
# Nuxt.js build / generate output | ||
|
||
.nuxt | ||
dist | ||
|
||
# Gatsby files | ||
|
||
.cache/ | ||
|
||
# Comment in the public line in if your project uses Gatsby and not Next.js | ||
|
||
# https://nextjs.org/blog/next-9-1#public-directory-support | ||
|
||
# public | ||
|
||
# vuepress build output | ||
|
||
.vuepress/dist | ||
|
||
# vuepress v2.x temp and cache directory | ||
|
||
.temp | ||
.cache | ||
|
||
# Docusaurus cache and generated files | ||
|
||
.docusaurus | ||
|
||
# Serverless directories | ||
|
||
.serverless/ | ||
|
||
# FuseBox cache | ||
|
||
.fusebox/ | ||
|
||
# DynamoDB Local files | ||
|
||
.dynamodb/ | ||
|
||
# TernJS port file | ||
|
||
.tern-port | ||
|
||
# Stores VSCode versions used for testing VSCode extensions | ||
|
||
.vscode-test | ||
|
||
# yarn v2 | ||
|
||
.yarn/cache | ||
.yarn/unplugged | ||
.yarn/build-state.yml | ||
.yarn/install-state.gz | ||
.pnp.\* | ||
|
||
# IntelliJ based IDEs | ||
.idea | ||
|
||
# Finder (MacOS) folder config | ||
.DS_Store | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# bun | ||
|
||
To install dependencies: | ||
|
||
```bash | ||
bun install | ||
``` | ||
|
||
To run: | ||
|
||
```bash | ||
bun run index.ts | ||
``` | ||
|
||
This project was created using `bun init` in bun v1.0.4. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as stytch from "stytch"; | ||
|
||
export function doStytchRequest(): Promise<void> { | ||
// Find these values at https://stytch.com/dashboard/api-keys | ||
// These ones will trigger a well-known erorr message | ||
return new stytch.Client({ | ||
project_id: "project-live-c60c0abe-c25a-4472-a9ed-320c6667d317", | ||
secret: "secret-live-80JASucyk7z_G8Z-7dVwZVGXL5NT_qGAQ2I=", | ||
}).magicLinks | ||
.authenticate({ | ||
session_token: "WJtR5BCy38Szd5AfoDpf0iqFKEt4EE5JhjlWUY7l3FtY", | ||
}) | ||
.catch((err: unknown) => console.log(JSON.stringify(err))); | ||
} | ||
|
||
doStytchRequest(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "bun", | ||
"module": "index.ts", | ||
"type": "module", | ||
"devDependencies": { | ||
"bun-types": "latest" | ||
}, | ||
"peerDependencies": { | ||
"typescript": "^5.0.0" | ||
}, | ||
"dependencies": { | ||
"stytch": "next" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["ESNext"], | ||
"module": "esnext", | ||
"target": "esnext", | ||
"moduleResolution": "bundler", | ||
"moduleDetection": "force", | ||
"allowImportingTsExtensions": true, | ||
"noEmit": true, | ||
"composite": true, | ||
"strict": true, | ||
"downlevelIteration": true, | ||
"skipLibCheck": true, | ||
"jsx": "react-jsx", | ||
"allowSyntheticDefaultImports": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"allowJs": true, | ||
"types": [ | ||
"bun-types" // add Bun global | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# http://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
tab_width = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.yml] | ||
indent_style = space |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"printWidth": 140, | ||
"singleQuote": true, | ||
"semi": true, | ||
"useTabs": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "cloudflare-workers", | ||
"version": "0.0.0", | ||
"private": true, | ||
"scripts": { | ||
"deploy": "node_modules/.bin/wrangler deploy", | ||
"start": "node_modules/.bin/wrangler dev" | ||
}, | ||
"devDependencies": { | ||
"@cloudflare/workers-types": "^4.20230419.0", | ||
"typescript": "^5.0.4", | ||
"wrangler": "^3.0.0" | ||
}, | ||
"dependencies": { | ||
"stytch": "^9.0.0-rc.1" | ||
} | ||
} |
Oops, something went wrong.