Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on:
push:
branches: main
pull_request:
branches: main

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [18, 20, 22]

steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v2
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: pnpm
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Run lint
run: pnpm lint
- name: Run tests
run: pnpm test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The package is available as open source under the terms of the [MIT License](htt

## Code of Conduct

Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/userlist/userlist-javascript/blob/master/CODE_OF_CONDUCT.md).
Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/userlist/userlist-javascript/blob/main/CODE_OF_CONDUCT.md).

## What is Userlist?

Expand Down
6 changes: 1 addition & 5 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
{
"packages": [
"packages/*"
],
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
"npmClient": "pnpm"
}
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
"name": "userlist-javascript",
"private": true,
"devDependencies": {
"lerna": "^3.20.2"
"lerna": "^8.0.0"
},
"scripts": {
"build": "lerna run build --stream --concurrency 1",
"test": "lerna run test --stream --concurrency 1",
"lint": "lerna run lint --stream --concurrency 1"
},
"workspaces": [
"packages/*"
],
"resolutions": {
"minimist": "^1.2.2"
}
},
"packageManager": "pnpm@10.6.4"
}
16 changes: 0 additions & 16 deletions packages/push/.eslintrc.js

This file was deleted.

7 changes: 7 additions & 0 deletions packages/push/.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extension": ["js"],
"package": "./package.json",
"require": "@babel/register",
"recursive": true,
"colors": true
}
12 changes: 12 additions & 0 deletions packages/push/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default {
overrides: [
{
files: '*.{js,ts,mjs,mts,cjs,cts}',
options: {
singleQuote: true,
trailingComma: 'es5',
printWidth: 120,
},
}
],
};
93 changes: 74 additions & 19 deletions packages/push/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

This package helps with integrating [Userlist](http://userlist.com) into Node.js applications for _server side tracking_.

> For client side tracking, please use [@userlist/web](https://github.com/userlist/userlist-javascript/tree/master/packages/web).
> For client side tracking, please use [@userlist/web](https://github.com/userlist/userlist-javascript/tree/main/packages/web).

## Installation

Expand Down Expand Up @@ -35,52 +35,107 @@ USERLIST_PUSH_KEY=401e5c498be718c0a38b7da7f1ce5b409c56132a49246c435ee296e07bf2be
Configuration via an constructor:

```javascript
var Userlist = require('@userlist/push');
import Userlist from "@userlist/push";

var userlist = new Userlist({ pushKey: '401e5c498be718c0a38b7da7f1ce5b409c56132a49246c435ee296e07bf2be39' });
const userlist = new Userlist({
pushKey: "401e5c498be718c0a38b7da7f1ce5b409c56132a49246c435ee296e07bf2be39",
});
```

## Usage

### Tracking Users

To manually send user data into Userlist, use the `userlist.users.create` method.
To send user data into Userlist, use the `userlist.users.push` method. This method will create a new user if the user doesn't exist yet, or update the existing user if it does. Properties that aren't present in the payload are ignored and remain unchanged.

```javascript
var userlist = new Userlist();

userlist.users.create({
userlist.users.push({
identifier: user.id,
email: user.email,
properties: {
first_name: user.first_name,
last_name: user.last_name
}
last_name: user.last_name,
},
});
```

It's also possible to delete a user from Userlist, using the `userlist.users.delete` method.

```javascript
userlist.users.delete(user.id)
userlist.users.delete({ identifier: user.id, email: user.email });
```

### Tracking Events
### Tracking Companies

To send company data into Userlist, use the `userlist.companies.push` method. This method will create a new company if the company doesn't exist yet, or update the existing company if it does. Properties that aren't present in the payload are ignored and remain unchanged.

```javascript
userlist.companies.push({
identifier: company.id,
name: company.name,
properties: {
plan: company.plan,
trial_ends_at: company.trial_ends_at,
},
});
```

It's also possible to delete a company from Userlist, using the `userlist.companies.delete` method.

```javascript
userlist.companies.delete({ identifier: company.id });
```

### Tracking Relationships

To create or update relationships between users and companies, use the `userlist.relationships.push` method. You need to specify both the user and company identifiers.

```javascript
userlist.relationships.push({
user: user.id,
company: company.id,
properties: {
role: "admin",
},
});
```

To track custom events use the `userlist.events.create` method.
It's also possible to delete a relationship using the `userlist.relationships.delete` method.

```javascript
var userlist = new Userlist();
userlist.relationships.delete({
user: user.id,
company: company.id,
});
```

### Tracking Events

To track custom events use the `userlist.events.push` method.

userlist.events.create({
name: 'project_created',
```javascript
userlist.events.push({
name: "project_created",
user: user.id,
properties: {
project_name: project.name
}
})
project_name: project.name,
},
});
```

### Sending Messages

To send messages to your users, use the `userlist.messages.push` method. You can specify the user, template name, and any properties needed for the message template.

```javascript
userlist.messages.push({
user: user.id,
template: "welcome_message",
properties: {
project_name: project.name,
},
});
```

## Contributing

Expand All @@ -92,7 +147,7 @@ The package is available as open source under the terms of the [MIT License](htt

## Code of Conduct

Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/userlist/userlist-javascript/blob/master/CODE_OF_CONDUCT.md).
Everyone interacting in this project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/userlist/userlist-javascript/blob/main/CODE_OF_CONDUCT.md).

## What is Userlist?

Expand Down
File renamed without changes.
31 changes: 31 additions & 0 deletions packages/push/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import globals from "globals";

import js from "@eslint/js";
import prettier from "eslint-plugin-prettier/recommended";

import babelParser from "@babel/eslint-parser";

export default [
js.configs.recommended,
prettier,
{
languageOptions: {
globals: {
...globals.node,
...globals.mocha,
},

parser: babelParser,
ecmaVersion: 2018,
sourceType: "module",
},
},
{
linterOptions: {
reportUnusedDisableDirectives: "error",
},
},
{
ignores: ["node_modules", "!**/.*"],
},
];
55 changes: 35 additions & 20 deletions packages/push/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
"userlist"
],
"author": "Benedikt Deicke <benedikt@userlist.com>",
"homepage": "https://github.com/userlistio/userlist-javascript/tree/master/packages/push",
"homepage": "https://github.com/userlist/userlist-javascript/tree/main/packages/push",
"license": "MIT",
"type": "module",
"main": "dist/index.cjs.js",
"module": "dist/index.esm.js",
"files": [
Expand All @@ -16,43 +17,57 @@
"src",
"test"
],
"exports": {
".": {
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
}
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "git+https://github.com/userlistio/userlist-javascript.git"
"url": "git+https://github.com/userlist/userlist-javascript.git"
},
"scripts": {
"lint": "eslint src test",
"build": "rollup -c",
"test": "mocha --require @babel/register --recursive --colors",
"test:watch": "yarn test --watch",
"prepublish": "yarn lint && yarn test && yarn build"
"test": "mocha",
"test:watch": "pnpm test --watch",
"prepublish": "pnpm lint && pnpm test && pnpm build"
},
"bugs": {
"url": "https://github.com/userlistio/userlist-javascript/issues"
"url": "https://github.com/userlist/userlist-javascript/issues"
},
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/eslint-parser": "^7.26.10",
"@babel/preset-env": "^7.9.0",
"@babel/register": "^7.9.0",
"@babel/runtime": "^7.9.2",
"@rollup/plugin-commonjs": "^11.0.2",
"@rollup/plugin-node-resolve": "^7.1.1",
"babel-eslint": "^10.1.0",
"chai": "^4.2.0",
"eslint": "^6.8.0",
"eslint-config-standard": "^14.1.1",
"@eslint/js": "^9.22.0",
"@rollup/plugin-babel": "^6.0.0",
"@rollup/plugin-commonjs": "^28.0.0",
"@rollup/plugin-node-resolve": "^16.0.0",
"builtin-modules": "^5.0.0",
"chai": "^5.0.0",
"eslint": "^9.0.0",
"eslint-config-prettier": "^10.1.1",
"eslint-config-standard": "^17.0.0",
"eslint-plugin-import": "^2.20.1",
"eslint-plugin-node": "^11.0.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^4.0.1",
"mocha": "^7.1.1",
"nock": "^12.0.3",
"rollup": "^2.2.0",
"rollup-plugin-babel": "^4.4.0",
"sinon": "^9.0.1",
"sinon-chai": "^3.5.0"
"eslint-plugin-prettier": "^5.2.3",
"eslint-plugin-promise": "^7.0.0",
"globals": "^16.0.0",
"mocha": "^11.0.0",
"nock": "^14.0.0",
"prettier": "^3.5.3",
"rollup": "^4.0.0",
"sinon": "^19.0.0",
"sinon-chai": "^4.0.0"
},
"volta": {
"node": "14.21.3"
}
}
8 changes: 4 additions & 4 deletions packages/push/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import babel from 'rollup-plugin-babel';
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import builtins from 'builtin-modules'
import builtins from 'builtin-modules';

import pkg from './package.json';
import pkg from './package.json' with { type: 'json' };

export default {
input: 'src/push.js',
Expand All @@ -23,7 +23,7 @@ export default {
}),
commonjs(),
babel({
runtimeHelpers: true
babelHelpers: 'runtime'
})
],
external: builtins,
Expand Down
Loading