amplitude-client-node
Advanced tools
Comparing version 0.2.0 to 1.0.0
@@ -114,4 +114,4 @@ /// <reference types="node" /> | ||
} | ||
export interface AmplitudeEventRequestData extends ApiKeyData { | ||
event: string; | ||
export interface AmplitudeEventRequestData<T = string> extends ApiKeyData { | ||
events: AmplitudeEventData<T>[]; | ||
} | ||
@@ -118,0 +118,0 @@ export interface AmplitudeGroupIdentifyRequestData extends ApiKeyData { |
28
index.js
@@ -27,2 +27,3 @@ "use strict"; | ||
async track(event, reqOptions) { | ||
var _a; | ||
if (this.setTime) { | ||
@@ -39,8 +40,9 @@ event.time = Date.now(); | ||
api_key: this.apiKey, | ||
event: JSON.stringify(event), | ||
events: [event], | ||
}; | ||
const options = Object.assign({ method: 'POST', path: '/httpapi' }, reqOptions); | ||
const options = Object.assign(Object.assign({ method: 'POST', path: '/2/httpapi' }, reqOptions), { headers: Object.assign(Object.assign({}, (_a = reqOptions) === null || _a === void 0 ? void 0 : _a.headers), { 'Content-Type': 'application/json' }) }); | ||
return this.sendRequest(options, formData); | ||
} | ||
async identify(identify, reqOptions) { | ||
var _a; | ||
const formData = { | ||
@@ -50,6 +52,7 @@ api_key: this.apiKey, | ||
}; | ||
const options = Object.assign({ method: 'POST', path: '/identify' }, reqOptions); | ||
const options = Object.assign(Object.assign({ method: 'POST', path: '/identify' }, reqOptions), { headers: Object.assign(Object.assign({}, (_a = reqOptions) === null || _a === void 0 ? void 0 : _a.headers), { 'Content-Type': 'application/x-www-form-urlencoded' }) }); | ||
return this.sendRequest(options, formData); | ||
} | ||
async groupIdentify(groupType, groupValue, groupProps, reqOptions) { | ||
var _a; | ||
const formData = { | ||
@@ -63,3 +66,3 @@ api_key: this.apiKey, | ||
}; | ||
const options = Object.assign({ method: 'POST', path: '/groupidentify' }, reqOptions); | ||
const options = Object.assign(Object.assign({ method: 'POST', path: '/groupidentify' }, reqOptions), { headers: Object.assign(Object.assign({}, (_a = reqOptions) === null || _a === void 0 ? void 0 : _a.headers), { 'Content-Type': 'application/x-www-form-urlencoded' }) }); | ||
return this.sendRequest(options, formData); | ||
@@ -73,6 +76,17 @@ } | ||
options.timeout = this.timeoutMs; | ||
const postData = querystring.stringify(formData); | ||
const byteLength = Buffer.byteLength(postData); | ||
let byteLength; | ||
let postData; | ||
options.headers = options.headers || {}; | ||
options.headers['Content-Type'] = 'application/x-www-form-urlencoded'; | ||
switch (options.headers['Content-Type']) { | ||
case 'application/x-www-form-urlencoded': | ||
postData = querystring.stringify(formData); | ||
byteLength = Buffer.byteLength(postData); | ||
break; | ||
case 'application/json': | ||
postData = JSON.stringify(formData); | ||
byteLength = Buffer.byteLength(postData); | ||
break; | ||
default: | ||
throw new Error(`Unknown Content-Type header: "${options.headers['Content-Type']}"`); | ||
} | ||
options.headers['Content-Length'] = byteLength; | ||
@@ -79,0 +93,0 @@ if (!this.enabled) { |
{ | ||
"name": "amplitude-client-node", | ||
"version": "0.2.0", | ||
"version": "1.0.0", | ||
"description": "Simple, no-dependency wrapper around Amplitude's HTTP API", | ||
@@ -31,11 +31,11 @@ "repository": { | ||
"@types/expect.js": "0.3.29", | ||
"@types/express": "4.16.1", | ||
"@types/mocha": "5.2.6", | ||
"@types/node": "10.14.6", | ||
"@types/express": "4.17.2", | ||
"@types/mocha": "5.2.7", | ||
"@types/node": "12.12.17", | ||
"expect.js": "0.3.1", | ||
"express": "4.17.0", | ||
"mocha": "6.1.4", | ||
"ts-node": "8.1.0", | ||
"typescript": "3.4.5" | ||
"express": "4.17.1", | ||
"mocha": "6.2.2", | ||
"ts-node": "8.5.4", | ||
"typescript": "3.7.3" | ||
} | ||
} |
@@ -5,4 +5,6 @@ # amplitude-client-node | ||
A simple wrapper around Amplitude's Groups and HTTP APIs. | ||
A simple wrapper around Amplitude's Groups and HTTP (v2) APIs. | ||
For legacy v1 HTTP API, use `v0.2.0`. | ||
Features: | ||
@@ -12,3 +14,3 @@ - automatic, configurable retry with generated `insert_id` | ||
- No dependencies | ||
- event tracking (`/httpapi`) | ||
- event tracking (`/2/httpapi`) | ||
- group identification (`/groupidentify`) | ||
@@ -15,0 +17,0 @@ - user identification (`/identify`) |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20659
310
1
83
2