Skip to content

Commit e93a7ae

Browse files
authored
[P-830] make userId optional, and address required for identify; update the docs (#8)
* fix: remove trailing comma in package.json for valid JSON * refactor: replace SDKServerSide with Formo client in analytics and event queue * feat: Replace Stainless SDK client with direct HTTP event submission and introduce new internal event types. * tests: Consolidate integration tests for track/identify and batching * fix: Update test script paths from `src/` to `test/` directory. * docs: Remove Stainless SDK generation details and enhance testing instructions and README examples. * fix: Update Authorization header from Basic to Bearer in event queue and its tests. * chore: make userId optional, address required for identify, update the docs * chore: switch to npm for dependency management * fix: default user_id to null instead of an empty string when undefined * feat: add MIT license file and declare it in package.json
1 parent 4a9c857 commit e93a7ae

11 files changed

Lines changed: 148 additions & 3316 deletions

File tree

CONTRIBUTING.md

Lines changed: 70 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,142 +1,119 @@
1-
# Contributing to Formo Node SDK
1+
# How to contribute
22

3-
Thank you for your interest in contributing to the Formo Node SDK! This guide will help you get started.
3+
If you want to contribute or run a local version of the Formo Node SDK, follow these steps:
44

5-
## Table of Contents
5+
## Build the SDK Locally
66

7-
- [Project Structure](#project-structure)
8-
- [Setting Up the Development Environment](#setting-up-the-development-environment)
9-
- [Making Changes](#making-changes)
10-
- [Running Tests](#running-tests)
11-
- [Code Style](#code-style)
7+
Run the following command to build both CommonJS and ESM versions of the SDK:
128

13-
## Project Structure
14-
15-
```
16-
sdk-node/
17-
├── src/ # Main SDK source code
18-
│ ├── FormoAnalytics.ts # Main SDK class
19-
│ ├── queue/ # Event batching and retry logic
20-
│ ├── types/ # TypeScript type definitions
21-
│ ├── utils/ # Utilities (address checksumming, etc.)
22-
│ └── validators/ # Input validation
23-
├── test/ # Tests
24-
│ ├── __tests__/ # Integration tests
25-
│ └── queue/ # Unit tests for queue/events
26-
├── scripts/ # Utility and test scripts
27-
└── package.json
9+
```bash
10+
pnpm install
11+
pnpm build
12+
pnpm test
2813
```
2914

30-
## Setting Up the Development Environment
15+
## Testing Locally
3116

32-
1. **Clone the repository:**
17+
### Link the Local Package
3318

34-
```bash
35-
git clone <repo-url>
36-
cd sdk-node
37-
```
19+
To test your SDK changes in a test app, you can link the package locally using `npm link` or `pnpm link`.
3820

39-
2. **Install dependencies:**
21+
For example, if your projects are in the same directory:
4022

41-
This project uses [pnpm](https://pnpm.io/). Other package managers may work but are not officially supported.
23+
```
24+
~/
25+
├── your-app/
26+
└── sdk-node/
27+
```
4228

43-
```bash
44-
pnpm install
45-
```
29+
Run the following commands:
4630

47-
3. **Build the project:**
31+
```bash
32+
# In ~/your-app
33+
pnpm link ../sdk-node
34+
```
4835

49-
```bash
50-
pnpm build
51-
```
36+
Or with npm:
5237

53-
## Making Changes
38+
```bash
39+
# In ~/your-app
40+
npm link ../sdk-node
41+
```
5442

55-
The core SDK logic in `src/` is manually maintained.
43+
### Apply Changes
5644

57-
Key components:
45+
Any changes you make to your local package require rebuilding to be reflected:
5846

59-
- `FormoAnalytics.ts`: Main entry point and public API.
60-
- `queue/`: Handles event buffering, batching, and retrying.
61-
- `types/`: Use this for all shared interfaces and types.
47+
```bash
48+
# In ~/sdk-node
49+
pnpm build
50+
```
6251

63-
When making changes:
52+
The changes will automatically be available in the linked project.
6453

65-
1. Create a feature branch from `main`.
66-
2. Make your changes with appropriate tests.
67-
3. Ensure all unit tests pass: `npm test`.
68-
4. If modifying API interactions, verify with integration tests (see below).
69-
5. Submit a pull request.
54+
### Unlink the Package
7055

71-
## Running Tests
56+
To remove the link:
7257

73-
### Unit Tests
58+
```bash
59+
# In ~/your-app
60+
pnpm unlink ../sdk-node
61+
```
7462

75-
Run the full unit test suite:
63+
Or with npm:
7664

7765
```bash
78-
npm test
66+
# In ~/your-app
67+
npm unlink ../sdk-node
7968
```
8069

81-
Or just the queue/logic tests:
70+
## Running Tests
71+
72+
Run the test suite:
8273

8374
```bash
84-
npm run test:queue
75+
pnpm test
8576
```
8677

8778
### Integration Tests
8879

89-
These tests make real network requests to the Formo API. You need a valid Write Key.
80+
These tests make real network requests to the Formo API. You need a valid Write Key:
9081

9182
```bash
92-
FORMO_WRITE_KEY=your-key npm run test:integration
83+
FORMO_WRITE_KEY=your-key pnpm run test:integration
9384
```
9485

95-
### Manual Testing Script
96-
97-
To verify functionality with a real script in a separate environment:
86+
## Linting
9887

99-
1. Create a `.env` file with `FORMO_WRITE_KEY=your-key`
100-
2. Run the manual test script:
101-
```bash
102-
pnpm run script:test-analytics
103-
```
88+
Check code style and types:
10489

105-
### Testing Packaging
90+
```bash
91+
pnpm lint
92+
```
10693

107-
To simulate consuming the package as a real user:
94+
## Publishing
10895

109-
1. Create a tarball:
96+
1. **Update the version** using npm:
11097

11198
```bash
112-
npm pack
99+
npm version patch # For bug fixes
100+
npm version minor # For new features
101+
npm version major # For breaking changes
113102
```
114103

115-
This creates a file like `formo-analytics-node-1.0.0.tgz`.
104+
This automatically:
116105

117-
2. Install it in another project:
106+
- Updates `package.json` with the new version
107+
- Creates a git commit with the change
108+
- Creates a version tag (e.g., `v1.0.1`)
109+
110+
2. **Push the commit and tag**:
118111

119112
```bash
120-
npm install /path/to/sdk-node/formo-analytics-node-1.0.0.tgz
113+
git push --follow-tags
121114
```
122115

123-
3. Verify usage works as expected.
124-
125-
## Code Style
126-
127-
This project uses:
128-
129-
- [Prettier](https://prettier.io/) for code formatting
130-
- [ESLint](https://eslint.org/) for linting
131-
132-
```bash
133-
# Check linting
134-
pnpm lint
135-
136-
# Fix linting and formatting issues
137-
pnpm fix
138-
```
139-
140-
## Questions?
141-
142-
If you have questions or need help, please open an issue on GitHub.
116+
3. **Automatic workflow execution**:
117+
- GitHub Actions workflow triggers on the `v*` tag
118+
- Builds and tests the package
119+
- Publishes to npm

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Formo
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

0 commit comments

Comments
 (0)