@hackler/hackle-sdk
Advanced tools
Comparing version 0.0.4 to 0.1.0
import AutoCloseable from "./external/js/lang/AutoCloseable"; | ||
export default interface HackleClient extends AutoCloseable { | ||
/** | ||
* Decide the variation to expose to the user for experiment. | ||
* Returns the default variation if the variation cannot be decided. | ||
* | ||
* @param experimentKey the unique key for the experiment. | ||
* @param userId the identifier of your customer (e.g. user_email, account_id, etc.) MUST NOT be null. | ||
* @param defaultVariation the default variation of the experiment. (Optional) | ||
* | ||
* @return the decided variation for the user, or the default variation. | ||
*/ | ||
variation(experimentKey: number, userId: string, defaultVariation?: string): string; | ||
/** | ||
* Records the event performed by the user. | ||
* | ||
* @param eventKey the unique key of the event. MUST NOT be null. | ||
* @param userId the identifier of user that performed the event. MUST NOT be null. | ||
* @param value additional numeric value of the event (e.g. purchase_amount, api_latency, etc.) (Optional) | ||
*/ | ||
track(eventKey: string, userId: string, value?: number): void; | ||
} |
@@ -65,4 +65,2 @@ "use strict"; | ||
var eventType = workspace.getEventTypeOrNull(eventKey); | ||
if (!eventType) | ||
return; | ||
this.eventProcessor.process(Event_1.default.track(eventType, userId, value)); | ||
@@ -69,0 +67,0 @@ }; |
@@ -8,4 +8,4 @@ import { EventKey, EventType, Experiment, ExperimentKey } from "../model/model"; | ||
getExperimentOrNull(experimentKey: ExperimentKey): Experiment | undefined; | ||
getEventTypeOrNull(eventKey: EventKey): EventType | undefined; | ||
getEventTypeOrNull(eventKey: EventKey): EventType; | ||
static from(dto: WorkspaceDto): Workspace; | ||
} |
@@ -33,3 +33,9 @@ "use strict"; | ||
Workspace.prototype.getEventTypeOrNull = function (eventKey) { | ||
return this.eventTypes.get(eventKey); | ||
var eventType = this.eventTypes.get(eventKey); | ||
if (eventType) { | ||
return eventType; | ||
} | ||
else { | ||
return new model_1.EventType(0, eventKey); | ||
} | ||
}; | ||
@@ -36,0 +42,0 @@ Workspace.from = function (dto) { |
142
package.json
{ | ||
"name": "@hackler/hackle-sdk", | ||
"version": "0.0.4", | ||
"description": "JavaScript SDK for Hackle", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
"test": "jest --coverage", | ||
"start": "tsnd --respawn server.ts", | ||
"build": "rm -rf dist && tsc", | ||
"copypackage": "cp -rf package.json dist", | ||
"copyreadme": "cp -rf README.md dist", | ||
"pub": "cd ./dist && npm publish", | ||
"verdaccio": "pm2 start ./node_modules/verdaccio/bin/verdaccio" | ||
"name": "@hackler/hackle-sdk", | ||
"version": "0.1.0", | ||
"description": "JavaScript SDK for Hackle", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
"test": "jest --coverage", | ||
"start": "tsnd --respawn server.ts", | ||
"build": "rm -rf dist && tsc", | ||
"copypackage": "cp -rf package.json dist", | ||
"copyreadme": "cp -rf README.md dist", | ||
"pub": "cd ./dist && npm publish", | ||
"verdaccio": "pm2 start ./node_modules/verdaccio/bin/verdaccio" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hackle-io/hackle-javascript-sdk.git" | ||
}, | ||
"keywords": ["hackle","sdk","abtest"], | ||
"author": { | ||
"name": "Hackle", | ||
"email": "admin@hackle.io", | ||
"url": "http://dashboard.hackle.io/" | ||
}, | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/hackle-io/hackle-javascript-sdk/issues" | ||
}, | ||
"typings": "lib/index.d.ts", | ||
"homepage": "https://dashboard.hackle.io", | ||
"devDependencies": { | ||
"@types/jest": "^26.0.4", | ||
"@types/node": "^14.0.20", | ||
"@types/node-fetch": "^2.5.7", | ||
"@typescript-eslint/eslint-plugin": "^3.6.0", | ||
"@typescript-eslint/parser": "^3.6.0", | ||
"eslint": "^7.4.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-import": "^2.22.0", | ||
"jest": "^26.1.0", | ||
"pm2": "^4.4.0", | ||
"ts-jest": "^26.1.1", | ||
"ts-node": "^8.10.2", | ||
"ts-node-dev": "^1.0.0-pre.59", | ||
"typescript": "^3.9.6", | ||
"verdaccio": "^4.7.2" | ||
}, | ||
"dependencies": { | ||
"@js-joda/core": "3.0.0", | ||
"murmurhash3js": "3.0.1", | ||
"node-fetch": "^2.6.0" | ||
}, | ||
"engines": { | ||
"node": ">= 12.18.2" | ||
}, | ||
"jest": { | ||
"transform": { | ||
"^.+\\.ts$": "ts-jest" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hackle-io/hackle-javascript-sdk.git" | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js" | ||
], | ||
"globals": { | ||
"ts-jest": { | ||
"diagnostics": true | ||
} | ||
}, | ||
"keywords": ["hackle", "sdk", "abtest"], | ||
"author": { | ||
"name": "Hackle", | ||
"email": "admin@hackle.io", | ||
"url": "http://dashboard.hackle.io/" | ||
}, | ||
"license": "ISC", | ||
"bugs": { | ||
"url": "https://github.com/hackle-io/hackle-javascript-sdk/issues" | ||
}, | ||
"typings": "lib/index.d.ts", | ||
"homepage": "https://dashboard.hackle.io", | ||
"devDependencies": { | ||
"@types/jest": "^26.0.4", | ||
"@types/node": "^14.0.20", | ||
"@types/node-fetch": "^2.5.7", | ||
"@typescript-eslint/eslint-plugin": "^3.6.0", | ||
"@typescript-eslint/parser": "^3.6.0", | ||
"eslint": "^7.4.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-import": "^2.22.0", | ||
"jest": "^26.1.0", | ||
"pm2": "^4.4.0", | ||
"ts-jest": "^26.1.1", | ||
"ts-node": "^8.10.2", | ||
"ts-node-dev": "^1.0.0-pre.59", | ||
"typescript": "^3.9.6", | ||
"verdaccio": "^4.7.2" | ||
}, | ||
"dependencies": { | ||
"@js-joda/core": "3.0.0", | ||
"murmurhash3js": "3.0.1", | ||
"node-fetch": "^2.6.0" | ||
}, | ||
"engines": { | ||
"node": ">= 12.18.2" | ||
}, | ||
"jest": { | ||
"transform": { | ||
"^.+\\.ts$": "ts-jest" | ||
}, | ||
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$", | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js" | ||
], | ||
"globals": { | ||
"ts-jest": { | ||
"diagnostics": true | ||
} | ||
}, | ||
"preset": "ts-jest", | ||
"testEnvironment": "node" | ||
}, | ||
"files": ["package.json", "README.md", "/lib"] | ||
"preset": "ts-jest", | ||
"testEnvironment": "node" | ||
}, | ||
"files": ["package.json", "README.md", "/lib"] | ||
} |
@@ -9,4 +9,4 @@ #Hackle JavaScript SDK | ||
##Usage | ||
## Usage | ||
### Install & Decide the variation | ||
```javascript | ||
@@ -16,11 +16,15 @@ const Hackle = require("@hackler/hackle-sdk"); | ||
const hackleClient = Hackle.createInstance("YOUR_SDK_KEY"); | ||
const variation = hackleClient.activate(AB_TEST_KEY, USER_ID); | ||
const variation = hackleClient.variation(AB_TEST_KEY, USER_ID); | ||
if (variation === "A") { | ||
// AS-IS Code | ||
} else if (variation === "B") { | ||
// TO-BE Code | ||
} | ||
``` | ||
### Records the event | ||
```javascript | ||
hackleClient.track(EVENT_KEY, USER_ID); | ||
``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
91384
1647
29