-
Notifications
You must be signed in to change notification settings - Fork 29
feat(testing): Add test projects for Cloudflare Workers. Vercel Remix + NextJS, Deno, and Bun #252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d2bbb64
1a6c863
c1e87ca
db5fdad
39ed165
c124cfe
3be46f0
145933b
af3e418
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
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! |
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 | ||
|
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. |
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this this Promise be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bun does some magic! Bun won't end the process until the microtask queue is empty. No top-level await nesc. |
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" | ||
} | ||
} |
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 | ||
] | ||
} | ||
} |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"printWidth": 140, | ||
"singleQuote": true, | ||
"semi": true, | ||
"useTabs": true | ||
} |
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" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a preference for this over
.nvmrc
for each project and checking inpackage-lock.json
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.nvcmrc
for each project would mean many versions of Node, which we don't need... yet