Skip to content

Commit 323980c

Browse files
authored
lint + format (#247)
* Initial formatting * Initial formatting + linting * Github actions * no-var * Correct export * Fixed
1 parent e5742a3 commit 323980c

36 files changed

+5881
-4918
lines changed

.github/workflows/tests.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,26 @@ name: Tests
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [master]
66
pull_request:
7-
branches: [ master ]
7+
branches: [master]
88

99
jobs:
1010
build:
11-
1211
runs-on: ubuntu-latest
1312

1413
strategy:
1514
matrix:
1615
node-version: [20.x, 22.x, 24.x]
1716

1817
steps:
19-
- uses: actions/checkout@v4
20-
- name: Use Node.js ${{ matrix.node-version }}
21-
uses: actions/setup-node@v4
22-
with:
23-
node-version: ${{ matrix.node-version }}
24-
- run: npm ci
25-
- run: npm test -- run --coverage
26-
- run: npx tsc
18+
- uses: actions/checkout@v4
19+
- name: Use Node.js ${{ matrix.node-version }}
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: ${{ matrix.node-version }}
23+
- run: npm ci
24+
- run: npm run check-format
25+
- run: npm run lint
26+
- run: npm test -- run --coverage
27+
- run: npx tsc

.oxlintrc.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"no-var": "error"
4+
}
5+
}

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
history.md

example.js

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
11
// grab the Mixpanel factory
2-
var Mixpanel = require('./lib/mixpanel-node');
2+
const Mixpanel = require("./lib/mixpanel-node");
33

44
// create an instance of the mixpanel client
5-
var mixpanel = Mixpanel.init('962dbca1bbc54701d402c94d65b4a20e');
5+
const mixpanel = Mixpanel.init("962dbca1bbc54701d402c94d65b4a20e");
66
mixpanel.set_config({ debug: true });
77

88
// track an event with optional properties
99
mixpanel.track("my event", {
10-
distinct_id: "some unique client id",
11-
as: "many",
12-
properties: "as",
13-
you: "want"
10+
distinct_id: "some unique client id",
11+
as: "many",
12+
properties: "as",
13+
you: "want",
1414
});
1515
mixpanel.track("played_game");
1616

1717
// create or update a user in Mixpanel Engage
1818
mixpanel.people.set("billybob", {
19-
$first_name: "Billy",
20-
$last_name: "Bob",
21-
$created: (new Date('jan 1 2013')).toISOString(),
22-
plan: "premium",
23-
games_played: 1,
24-
points: 0
19+
$first_name: "Billy",
20+
$last_name: "Bob",
21+
$created: new Date("jan 1 2013").toISOString(),
22+
plan: "premium",
23+
games_played: 1,
24+
points: 0,
2525
});
2626

2727
// create or update a user in Mixpanel Engage without altering $last_seen
2828
// - pass option `$ignore_time: true` to prevent the $last_seen property from being updated
29-
mixpanel.people.set("billybob", {
29+
mixpanel.people.set(
30+
"billybob",
31+
{
3032
plan: "premium",
31-
games_played: 1
32-
}, {
33-
$ignore_time: true
34-
});
33+
games_played: 1,
34+
},
35+
{
36+
$ignore_time: true,
37+
},
38+
);
3539

3640
// set a single property on a user
3741
mixpanel.people.set("billybob", "plan", "free");
3842

3943
// set a single property on a user, don't override
40-
mixpanel.people.set_once("billybob", "first_game_play", (new Date('jan 1 2013')).toISOString());
44+
mixpanel.people.set_once(
45+
"billybob",
46+
"first_game_play",
47+
new Date("jan 1 2013").toISOString(),
48+
);
4149

4250
// increment a numeric property
4351
mixpanel.people.increment("billybob", "games_played");
@@ -46,13 +54,16 @@ mixpanel.people.increment("billybob", "games_played");
4654
mixpanel.people.increment("billybob", "points", 15);
4755

4856
// increment multiple properties
49-
mixpanel.people.increment("billybob", {"points": 10, "games_played": 1});
57+
mixpanel.people.increment("billybob", { points: 10, games_played: 1 });
5058

5159
// append value to a list
5260
mixpanel.people.append("billybob", "awards", "Great Player");
5361

5462
// append multiple values to a list
55-
mixpanel.people.append("billybob", {"awards": "Great Player", "levels_finished": "Level 4"});
63+
mixpanel.people.append("billybob", {
64+
awards: "Great Player",
65+
levels_finished: "Level 4",
66+
});
5667

5768
// record a transaction for revenue analytics
5869
mixpanel.people.track_charge("billybob", 39.99);
@@ -65,38 +76,42 @@ mixpanel.people.delete_user("billybob");
6576

6677
// all functions that send data to mixpanel take an optional
6778
// callback as the last argument
68-
mixpanel.track("test", function(err) { if (err) { throw err; } });
79+
mixpanel.track("test", function (err) {
80+
if (err) {
81+
throw err;
82+
}
83+
});
6984

7085
// import an old event
71-
var mixpanel_importer = Mixpanel.init('valid mixpanel token', {
72-
secret: "valid api secret for project"
86+
const mixpanel_importer = Mixpanel.init("valid mixpanel token", {
87+
secret: "valid api secret for project",
7388
});
7489
mixpanel_importer.set_config({ debug: true });
7590

7691
// needs to be in the system once for it to show up in the interface
77-
mixpanel_importer.track('old event', { gender: '' });
92+
mixpanel_importer.track("old event", { gender: "" });
7893

7994
mixpanel_importer.import("old event", new Date(2012, 4, 20, 12, 34, 56), {
80-
distinct_id: 'billybob',
81-
gender: 'male'
95+
distinct_id: "billybob",
96+
gender: "male",
8297
});
8398

8499
// import multiple events at once
85100
mixpanel_importer.import_batch([
86-
{
87-
event: 'old event',
88-
properties: {
89-
time: new Date(2012, 4, 20, 12, 34, 56),
90-
distinct_id: 'billybob',
91-
gender: 'male'
92-
}
101+
{
102+
event: "old event",
103+
properties: {
104+
time: new Date(2012, 4, 20, 12, 34, 56),
105+
distinct_id: "billybob",
106+
gender: "male",
107+
},
108+
},
109+
{
110+
event: "another old event",
111+
properties: {
112+
time: new Date(2012, 4, 21, 11, 33, 55),
113+
distinct_id: "billybob",
114+
color: "red",
93115
},
94-
{
95-
event: 'another old event',
96-
properties: {
97-
time: new Date(2012, 4, 21, 11, 33, 55),
98-
distinct_id: 'billybob',
99-
color: 'red'
100-
}
101-
}
116+
},
102117
]);

lib/flags/flags.d.ts

Lines changed: 41 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,60 @@
22
* TypeScript type definitions for Base Feature Flags Provider
33
*/
44

5-
import { CustomLogger } from '../mixpanel-node';
6-
import { SelectedVariant, FlagContext } from './types';
5+
import { CustomLogger } from "../mixpanel-node";
6+
import { SelectedVariant, FlagContext } from "./types";
77

88
/**
99
* Configuration for feature flags API requests
1010
*/
1111
export interface FeatureFlagsConfig {
12-
token: string;
13-
api_host: string;
14-
request_timeout_in_seconds: number;
12+
token: string;
13+
api_host: string;
14+
request_timeout_in_seconds: number;
1515
}
1616

1717
/**
1818
* Base Feature Flags Provider
1919
* Contains common methods for feature flag evaluation
2020
*/
2121
export class FeatureFlagsProvider {
22-
providerConfig: FeatureFlagsConfig;
23-
endpoint: string;
24-
logger: CustomLogger | null;
22+
providerConfig: FeatureFlagsConfig;
23+
endpoint: string;
24+
logger: CustomLogger | null;
2525

26-
/**
27-
* @param config - Common configuration for feature flag providers
28-
* @param endpoint - API endpoint path (i.e., '/flags' or '/flags/definitions')
29-
* @param logger - Logger instance
30-
*/
31-
constructor(config: FeatureFlagsConfig, endpoint: string, logger: CustomLogger | null);
26+
/**
27+
* @param config - Common configuration for feature flag providers
28+
* @param endpoint - API endpoint path (i.e., '/flags' or '/flags/definitions')
29+
* @param logger - Logger instance
30+
*/
31+
constructor(
32+
config: FeatureFlagsConfig,
33+
endpoint: string,
34+
logger: CustomLogger | null,
35+
);
3236

33-
/**
34-
* Common HTTP request handler for flags API endpoints
35-
* @param additionalParams - Additional query parameters to append
36-
* @returns Parsed JSON response
37-
*/
38-
callFlagsEndpoint(additionalParams?: Record<string, any> | null): Promise<any>;
37+
/**
38+
* Common HTTP request handler for flags API endpoints
39+
* @param additionalParams - Additional query parameters to append
40+
* @returns Parsed JSON response
41+
*/
42+
callFlagsEndpoint(
43+
additionalParams?: Record<string, any> | null,
44+
): Promise<any>;
3945

40-
/**
41-
* Manually tracks a feature flag exposure event to Mixpanel
42-
* This provides flexibility for reporting individual exposure events when using getAllVariants
43-
* If using getVariantValue or getVariant, exposure events are tracked automatically by default.
44-
* @param {string} flagKey - The key of the feature flag
45-
* @param {SelectedVariant} variant - The selected variant for the feature flag
46-
* @param {FlagContext} context - The user context used to evaluate the feature flag
47-
* @param {number|null} latencyMs - Optionally included latency in milliseconds that assignment took.
48-
*/
49-
trackExposureEvent(flagKey: string, variant: SelectedVariant, context: FlagContext, latencyMs?: number | null): void;
46+
/**
47+
* Manually tracks a feature flag exposure event to Mixpanel
48+
* This provides flexibility for reporting individual exposure events when using getAllVariants
49+
* If using getVariantValue or getVariant, exposure events are tracked automatically by default.
50+
* @param {string} flagKey - The key of the feature flag
51+
* @param {SelectedVariant} variant - The selected variant for the feature flag
52+
* @param {FlagContext} context - The user context used to evaluate the feature flag
53+
* @param {number|null} latencyMs - Optionally included latency in milliseconds that assignment took.
54+
*/
55+
trackExposureEvent(
56+
flagKey: string,
57+
variant: SelectedVariant,
58+
context: FlagContext,
59+
latencyMs?: number | null,
60+
): void;
5061
}

0 commit comments

Comments
 (0)