Skip to content

Commit a2a501c

Browse files
authored
Merge pull request #9 from bufferapp/update-structure
Move sample apps into samples/ and tidy up docs
2 parents e005f1a + 09c0bd3 commit a2a501c

28 files changed

Lines changed: 79 additions & 75 deletions

‎.github/dependabot.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2
22
updates:
33
# Each sample app needs its own entry, pointing at the folder that holds its package.json.
44
- package-ecosystem: npm
5-
directory: /app-client-starter-app
5+
directory: /samples/app-client-starter-app
66
schedule:
77
interval: weekly
88
groups:

‎.github/workflows/ci.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ jobs:
1313
runs-on: ubuntu-latest
1414
defaults:
1515
run:
16-
working-directory: app-client-starter-app
16+
working-directory: samples/app-client-starter-app
1717
steps:
1818
- uses: actions/checkout@v4
1919
- uses: actions/setup-node@v4
2020
with:
2121
node-version: 22
2222
cache: npm
23-
cache-dependency-path: app-client-starter-app/package-lock.json
23+
cache-dependency-path: samples/app-client-starter-app/package-lock.json
2424
- run: npm ci
2525
- run: npm test
2626
- run: npm run lint

‎CONTRIBUTING.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Contributing
2+
3+
Thanks for helping improve the Buffer sample apps.
4+
5+
## What we accept
6+
7+
- **Pull requests for fixes and improvements** to the existing samples are welcome.
8+
- **New samples** aren't accepted at the moment. If you have an idea for one, please [open an issue](../../issues) instead.
9+
- **Bugs and suggestions** can be reported by [opening an issue](../../issues).
10+
11+
## Guidelines
12+
13+
- Keep each sample small and copyable. A change should teach one clear Buffer API practice.
14+
- Include a test when you change behavior.
15+
- Avoid adding frameworks or dependencies unless they make the example clearer.
16+
- Before opening a pull request, run the sample's checks. For the Node.js samples, that's `npm test` and `npm run lint`.
17+
- Never commit `.env` files, certificates, client secrets, sessions, or real tokens.

‎README.md‎

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,69 @@
11
# Buffer Sample Apps
2+
23
A collection of sample applications that show how to build on the Buffer API. Each sample is a small, self-contained project you can clone, run, and use as a starting point for your own build.
34

45
> **Note:** These samples are meant for learning and prototyping. Make sure to review and adapt them to your own security, error-handling, and scaling needs before using them in production.
56
6-
### Prerequisites
7-
7+
## Samples
8+
9+
| Sample | What it shows | Stack |
10+
| --- | --- | --- |
11+
| [App client starter app](samples/app-client-starter-app) | A third-party app that connects a Buffer account over OAuth 2.0 with PKCE, lists its channels, and adds a draft post to a channel's queue. | Node.js, Express |
12+
13+
## Prerequisites
14+
815
- A [Buffer](https://buffer.com) account
9-
- API access credentials - see the [Buffer developer docs](https://developers.buffer.com/guides/authentication.html) for how to get them
16+
- API access credentials. See the [Buffer developer docs](https://developers.buffer.com/guides/authentication.html) for how to get them.
1017
- Any language-specific tooling listed in the sample's own README
1118

1219
## Repository structure
13-
14-
Each sample app lives in its own folder with everything it needs to run:
15-
20+
21+
All sample apps live in the `samples/` directory. Each one has its own folder with everything it needs to run:
22+
1623
```
1724
.
18-
├── sample-app-name/
19-
│ ├── README.md # Setup and usage instructions for this sample
20-
│ ├── .env.example # Environment variables the sample needs
21-
│ └── ... # Source code
22-
├── another-sample/
23-
│ └── ...
25+
├── samples/
26+
│ ├── sample-app-name/
27+
│ │ ├── README.md # Setup and usage instructions for this sample
28+
│ │ ├── .env.example # Environment variables the sample needs
29+
│ │ └── ... # Source code
30+
│ └── another-sample/
31+
│ └── ...
32+
├── CONTRIBUTING.md
2433
├── LICENSE
2534
└── README.md
2635
```
2736

28-
### Run a sample app
29-
37+
## Run a sample app
38+
3039
1. Clone the repository:
31-
```bash
40+
41+
```bash
3242
git clone https://github.com/bufferapp/buffer-sample-apps.git
3343
cd buffer-sample-apps
34-
```
35-
44+
```
45+
3646
2. Move into the sample you want to try:
37-
```bash
38-
cd sample-app-name
39-
```
40-
47+
48+
```bash
49+
cd samples/sample-app-name
50+
```
51+
4152
3. Follow the setup instructions in that sample's `README.md`.
42-
Never commit your API credentials. Each sample reads them from environment variables - copy `.env.example` to `.env` and fill in your own values.
4353

54+
Never commit your API credentials. Each sample reads them from environment variables: copy `.env.example` to `.env` and fill in your own values.
4455

4556
## Resources
46-
57+
4758
- [Buffer developer docs](https://developers.buffer.com)
4859
- [Buffer Help Center](https://support.buffer.com)
4960

5061
## Contributing
51-
52-
These sample apps are provided as-is for educational purposes. They're maintained on a best-effort basis and aren't covered by Buffer's product support or service-level agreements.
5362

54-
We welcome issues and suggestions for improvements. If you spot a bug or have an idea for a new sample, please [open an issue](../../issues). At the moment we don't accept direct contributions of new samples.
63+
These sample apps are provided as-is for educational purposes. They're maintained on a best-effort basis and aren't covered by Buffer's product support or service-level agreements.
64+
65+
See [CONTRIBUTING.md](CONTRIBUTING.md) for what we accept and how to contribute.
5566

5667
## License
57-
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.
5868

69+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

‎app-client-starter-app/CONTRIBUTING.md‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎app-client-starter-app/LICENSE‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

app-client-starter-app/.env.example renamed to samples/app-client-starter-app/.env.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,3 @@ REDIRECT_URI=https://localhost:3000/callback
99
# the app generates one into .session-key on first boot. Required in production:
1010
# openssl rand -hex 32
1111
SESSION_SECRET=
12-
13-
PORT=3000
File renamed without changes.
Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Draft Queue: a Buffer app client example
22

3-
A small, runnable example of a third-party app built on the [Buffer API](https://developers.buffer.com).
4-
3+
A small, runnable example of a third-party app built on the [Buffer API](https://developers.buffer.com).
54

65
## What it does
6+
77
It's a small starter app called Draft Queue which covers key components of an app client:
88

99
1. A user connects their own Buffer account over OAuth 2.0 (Authorization Code + PKCE).
@@ -14,7 +14,6 @@ It's a small starter app called Draft Queue which covers key components of an ap
1414

1515
Use it as a starting point for your own integration. Clone it, configure it with your own app client, build new features on top, or share it with your AI coding agent as a reference.
1616

17-
1817
## Prerequisites
1918

2019
- Node.js 22
@@ -27,7 +26,7 @@ Use it as a starting point for your own integration. Clone it, configure it with
2726
1. From the root of the repository, move into this sample:
2827

2928
```bash
30-
cd app-client-starter-app
29+
cd samples/app-client-starter-app
3130
```
3231

3332
2. Install dependencies:
@@ -61,11 +60,11 @@ Use it as a starting point for your own integration. Clone it, configure it with
6160

6261
5. Run the app locally:
6362

64-
```bash
65-
npm start
66-
```
63+
```bash
64+
npm start
65+
```
6766

68-
Open `https://localhost:3000` and accept the self-signed development certificate in your browser.
67+
Open `https://localhost:3000` and accept the self-signed development certificate in your browser.
6968

7069
## Project structure
7170

@@ -76,27 +75,21 @@ Open `https://localhost:3000` and accept the self-signed development certificate
7675
| `server.js` | Local HTTPS dev server. |
7776
| `api/index.js`, `vercel.json` | Serverless entry point and routing, using Vercel as an example host. |
7877
| `test/` | Regression tests for the protocol and security-critical helpers. |
79-
| `docs/` | Architecture notes and the production OAuth guide. |
78+
| `docs/` | The demo GIF used in this README. |
8079
| `scripts/` | Generates the self-signed certificate for local HTTPS. |
8180

8281
## What this example covers
83-
82+
8483
- **OAuth 2.0 with PKCE:** the full Authorization Code flow with PKCE. It sends the user to Buffer to authorize the app, handles the redirect back, and exchanges the authorization code for tokens. See `lib/buffer.js`.
8584
- **GraphQL requests:** authenticated calls to the Buffer GraphQL API. The app reads the user's organization and channels, then runs a mutation that creates a draft post in a channel's queue.
8685
- **Refresh tokens:** the app requests the `offline_access` scope, so Buffer returns a refresh token alongside the access token. When the access token expires, the app renews it without asking the user to sign in again. Both tokens are sealed inside an HttpOnly cookie, so browser JavaScript can never read them.
87-
- **Staying within rate limits:** the app reads the rate limit headers on each response and uses them to stay within the limits applied to the client.
88-
- **Deployment:** a working setup for Vercel (`api/index.js` and `vercel.json`) shows how to run the same app as a serverless deployment. You can adapt it to any Node.js host.
89-
90-
## Further reading
91-
92-
- [Buffer developer docs](https://developers.buffer.com)
93-
- [Architecture notes](docs/architecture.md)
94-
- [Production OAuth guide](docs/production-oauth.md)
86+
- **Handling rate limits:** rate limits apply per app client, so every user of the app shares one quota. When Buffer responds with HTTP 429, the app reads the `Retry-After` header. If the wait is 5 seconds or less, it waits and retries the request once. Otherwise it returns the error to the user with the wait time. See `graphql()` in `lib/buffer.js`.
87+
- **Deployment:** a working setup for Vercel (`api/index.js` and `vercel.json`) shows how to run the same app as a serverless deployment. If you deploy from this repository, set the project's root directory to `samples/app-client-starter-app`. You can adapt it to any Node.js host.
9588

9689
## Support and contributing
9790

98-
This sample is provided as-is for educational purposes and isn't covered by Buffer's product support or service-level agreements. If you find a bug or something out of date, please [open an issue](../../../issues). See the [repository README](../README.md#contributing) for how we handle contributions.
91+
This sample is provided as-is for educational purposes and isn't covered by Buffer's product support or service-level agreements. If you find a bug or something out of date, please [open an issue](../../../../issues). See [CONTRIBUTING.md](../../CONTRIBUTING.md) for how we handle contributions.
9992

10093
## License
10194

102-
This sample is licensed under the MIT License. See the [LICENSE](../LICENSE) file at the root of the repository.
95+
This sample is licensed under the MIT License. See the [LICENSE](../../LICENSE) file at the root of the repository.

0 commit comments

Comments
 (0)