Skip to content
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

jb/update docs for running tjs and epic-react in dev #1449

Merged
merged 4 commits into from Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 17 additions & 20 deletions apps/epic-react/README.md
Expand Up @@ -48,7 +48,11 @@ Copy the template `.env.local.template` file to `.env.local` and `.env.template`
- `CONVERTKIT_API_SECRET`: not required for local development unless actively working on ConvertKit integration. Can be found in 1password.
- `POSTMARK_KEY`: not required to run in dev, but enables email sending from local environment. Can be found in 1password.
- `STRIPE_SECRET_TOKEN`: Not required unless you need to make an end to end purchase. Can be found in 1password.
- `STRIPE_WEBHOOK_SECRET`: Not required unless you need to make a purchase. This value can be acquired by running `pnpm dev:stripe` and observing it there. The value is stable for your local `stripe` cli installation.
- `SKILL_SECRET`: Required for interaction with any access-protected API
skill-api endpoint, such as `webhook/stripe-internal` used for any Stripe
interaction like making purchases. Add to `.env.local` using whatever secret
value (recommended: generate a value with this command `echo "sks_$(uuidgen |
tr '[:upper:]' '[:lower:]')"`).

👋 `.env` is **required by Prisma** and **only** contains `DATABASE_URL`. The full contents
of this file by default are are:
Expand Down Expand Up @@ -167,27 +171,20 @@ A Postmark API key is required to send email from your local environment. It is

### Stripe CLI

#### Installation
This app works in coordination with `epic-web`'s stripe webhook handling API.
In order to go through a full purchase flow, process refunds, etc., the
`epic-web` app will also need to be running (`cd ../epic-web; pnpm dev`). The
`epic-web` `pnpm dev` command will run both the Next.js dev server (running its
API) and a local Stripe webhook listener. Any Epic React Stripe events will hit
the `epic-web` webhook endpoint and will be forwarded to `epic-react`'s
`api/skill/webhook/stripe-internal` endpoint.

You'll need to install the [Stripe CLI](https://stripe.com/docs/stripe-cli) to capture web hooks locally and make test purchases.
Prerequisites:

#### Login

If you've just installed the Stripe CLI (or just been granted access to this Stripe account), you'll need to login via the commandline. Run `stripe login` and follow the prompts to connect your `stripe` CLI to the epic-react Stripe account. To confirm your connection, you should see a _Restricted Keys_ entry for your machine in the _Developers_ > _API Keys_ section of the Stripe Dashboard.

#### Listening to Webhook Events

Listen to webhook:

```shell
pnpm dev:stripe
```

The `dev:stripe` node script is a shorthand for `stripe listen --forward-to localhost:3024/api/skill/webhook/stripe`.

`pnpm dev:stripe` starts listening for Stripe Webhook events. When it first starts, it will output a _webhook signing secret_ (`whsec_....`). You'll need to copy and paste this value into `.env.local` as the `STRIPE_WEBHOOK_SECRET`. It is required to make test purchases

👋 If you aren't listening to webhooks you can still make a purchase but your local environment will not be notified!
- Have `epic-web` fully setup and running locally
- Set the `SKILL_SECRET` value for this app in `.env.local`
- Use that same `SKILL_SECRET` value in `epic-web`'s `.env.development.local`
with the key `ER_SKILL_SECRET`

### Connect to the Planetscale database

Expand Down
2 changes: 1 addition & 1 deletion apps/epic-react/package.json
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"dev": "next dev -p 3024",
"dev:sanity": "sanity dev",
"dev:stripe": "./scripts/check-stripe && stripe listen --forward-to localhost:3024/api/skill/webhook/stripe",
"dev:stripe": "echo 'Run epic-web `pnpm dev` to handle stripe webhooks for kcd-products' && exit 1",
"build": "next build",
"postbuild": "NODE_ENV=production next-sitemap",
"start": "next start -p 3024",
Expand Down
1 change: 1 addition & 0 deletions apps/epic-web/.env.development
Expand Up @@ -48,3 +48,4 @@ SENTRY_IGNORE_API_RESOLUTION_ERROR=1
NEXT_PUBLIC_DEFAULT_PRODUCT_ID=kcd_product_dbf94bf0-66b0-11ee-8c99-0242ac120002

TESTING_JAVASCRIPT_INTERNAL_STRIPE_URL='http://localhost:3018/api/skill/webhook/stripe-internal'
EPIC_REACT_INTERNAL_STRIPE_URL='http://localhost:3024/api/skill/webhook/stripe-internal'
1 change: 1 addition & 0 deletions apps/epic-web/.env.production
Expand Up @@ -50,3 +50,4 @@ NEXT_PUBLIC_AXIOM_DATASET=epic-web
NEXT_PUBLIC_AXIOM_TOKEN=xaat-db4f77ec-21b0-42e8-b6c5-fd91ce7ce479

TESTING_JAVASCRIPT_INTERNAL_STRIPE_URL='https://testingjavascript.com/api/skill/webhook/stripe-internal'
EPIC_REACT_INTERNAL_STRIPE_URL='https://epicreact.dev/api/skill/webhook/stripe-internal'
1 change: 1 addition & 0 deletions apps/epic-web/README.md
Expand Up @@ -7,6 +7,7 @@ It was generated using `create-skill-app` and is meant as a starting point for a
Both `.env.development` and `.env.production` files are used to store environment variables. They have some basic default values that need to be updated for the product and client. This would be a lot better if they were generated with the answers to questions when you run `create-skill-app`, but that isn't the case today. Feel free to add it!

- [ ] Update `.env.development` and `.env.production` with real values
- [ ] Copy `.env.development.local.example` to `env.development.local` and populate any needed real values

## Database

Expand Down
65 changes: 18 additions & 47 deletions apps/testing-javascript/README.md
Expand Up @@ -8,20 +8,6 @@ the `{PROJECT_ROOT}/apps/testing-javascript` in your console.
cd apps/testing-javascript
```

## Validate your local environment

You need to ensure that you have all of the necessary system-level dependencies
installed.

From `apps/testing-javascript` you can run the following command to validate
your environment:

```shell
bin/validate
```

Missing system dependencies should be installed. They will be assumed below.

## Serverless Access

You may need access to the following serverless accounts to run the app:
Expand Down Expand Up @@ -59,9 +45,12 @@ to `.env`
local environment. Can be found in 1password.
* `STRIPE_SECRET_TOKEN`: Not required unless you need to make an end to end
purchase. Can be found in 1password.
* `STRIPE_WEBHOOK_SECRET`: Not required unless you need to make a purchase. This
value can be acquired by running `pnpm dev:stripe` and observing it there. The
value is stable for your local `stripe` cli installation.
* `SKILL_SECRET`: Required for interaction with any access-protected API
skill-api endpoint, such as `webhook/stripe-internal` used for any Stripe
interaction like making purchases. Add to `.env.local` using whatever secret
value (recommended: generate a value with this command `echo "sks_$(uuidgen |
tr '[:upper:]' '[:lower:]')"`). See _Stripe_ section for the rest of the
setup instructions.

👋 `.env` is **required by Prisma** and **only** contains `DATABASE_URL`. The
full contents
Expand Down Expand Up @@ -204,38 +193,20 @@ located in 1password or via Postmark and can be added to `.env.local`.

### Stripe CLI

#### Installation

You'll need to install the [Stripe CLI](https://stripe.com/docs/stripe-cli) to
capture web hooks locally and make test purchases.

#### Login

If you've just installed the Stripe CLI (or just been granted access to this
Stripe account), you'll need to login via the commandline. Run `stripe login`
and follow the prompts to connect your `stripe` CLI to the Testing JavaScript
Stripe account. To confirm your connection, you should see a _Restricted Keys_
entry for your machine in the _Developers_ > _API Keys_ section of the Stripe
Dashboard.

#### Listening to Webhook Events

Listen to webhook:

```shell
pnpm dev:stripe
```

The `dev:stripe` node script is a shorthand
for `stripe listen --forward-to localhost:3018/api/skill/webhook/stripe`.
This app works in coordination with `epic-web`'s stripe webhook handling API.
In order to go through a full purchase flow, process refunds, etc., the
`epic-web` app will also need to be running (`cd ../epic-web; pnpm dev`). The
`epic-web` `pnpm dev` command will run both the Next.js dev server (running its
API) and a local Stripe webhook listener. Any Testing JavaScript Stripe events
will hit the `epic-web` webhook endpoint and will be forwarded to
`testing-javascript`'s `api/skill/webhook/stripe-internal` endpoint.

`pnpm dev:stripe` starts listening for Stripe Webhook events. When it first
starts, it will output a _webhook signing secret_ (`whsec_....`). You'll need to
copy and paste this value into `.env.local` as the `STRIPE_WEBHOOK_SECRET`. It
is required to make test purchases
Prerequisites:

👋 If you aren't listening to webhooks you can still make a purchase but your
local environment will not be notified!
- Have `epic-web` fully setup and running locally
- Set the `SKILL_SECRET` value for this app in `.env.local`
- Use that same `SKILL_SECRET` value in `epic-web`'s `.env.development.local`
with the key `TJS_SKILL_SECRET`

### Connect to the Planetscale database

Expand Down
2 changes: 1 addition & 1 deletion apps/testing-javascript/package.json
Expand Up @@ -11,7 +11,7 @@
"db:studio": "prisma studio",
"dev": "next dev -p 3018",
"dev:sanity": "sanity dev",
"dev:stripe": "./scripts/check-stripe && stripe listen --forward-to localhost:3018/api/skill/webhook/stripe",
"dev:stripe": "echo 'Run epic-web `pnpm dev` to handle stripe webhooks for kcd-products' && exit 1",
"lint": "eslint src/**/*.{ts,tsx} --fix && tsc --noEmit",
"start": "next start -p 3018"
},
Expand Down