Comparing version 5.0.1-next.2 to 5.0.1-next.3
# Amplitude Change Log | ||
## v5.0.1-next.0 | ||
## v5.0.1-next | ||
- Convert to typescript (this shouldn't break anything as it's being exported just like before) | ||
@@ -5,0 +5,0 @@ |
@@ -1,3 +0,3 @@ | ||
import * as request from 'superagent'; | ||
import './interfaces'; | ||
import { AxiosResponse } from 'axios'; | ||
import { AmplitudeOptions, AmplitudeResponseBody, AmplitudeRequestData, AmplitudeUserActivityOptions, AmplitudeExportOptions, AmplitudeRequestDataOptions, AmplitudeSegmentationOptions } from './public'; | ||
export default class Amplitude { | ||
@@ -12,8 +12,7 @@ private readonly token; | ||
identify(data: AmplitudeRequestData | [AmplitudeRequestData]): Promise<AmplitudeResponseBody>; | ||
track(data: AmplitudeRequestData | Array<AmplitudeRequestData>): Promise<AmplitudeResponseBody>; | ||
export(options: AmplitudeExportOptions): request.SuperAgentRequest; | ||
track(data: AmplitudeRequestData | Array<AmplitudeRequestData>, options?: AmplitudeRequestDataOptions): Promise<AmplitudeResponseBody>; | ||
export(options: AmplitudeExportOptions): Promise<AxiosResponse>; | ||
userSearch(userSearchId: string): Promise<AmplitudeResponseBody>; | ||
userActivity(amplitudeId: string | number, data?: AmplitudeUserActivityOptions): Promise<AmplitudeResponseBody>; | ||
eventSegmentation(data: AmplitudeSegmentationOptions): Promise<AmplitudeResponseBody>; | ||
userActivity(amplitudeId: string | number, params?: AmplitudeUserActivityOptions): Promise<AmplitudeResponseBody>; | ||
eventSegmentation(params: AmplitudeSegmentationOptions): Promise<AmplitudeResponseBody>; | ||
} | ||
//# sourceMappingURL=amplitude.d.ts.map |
@@ -11,24 +11,8 @@ "use strict"; | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const request = __importStar(require("superagent")); | ||
require("./interfaces"); | ||
function postBody(url, params) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const encodedParams = Object.keys(params).map(key => { | ||
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]); | ||
}).join('&'); | ||
const res = yield request.post(url) | ||
.send(encodedParams) | ||
.type('application/x-www-form-urlencoded') | ||
.set('Accept', 'application/json'); | ||
return res.body; | ||
}); | ||
} | ||
const axios_1 = __importDefault(require("axios")); | ||
const errors_1 = require("./errors"); | ||
const AMPLITUDE_TOKEN_ENDPOINT = 'https://api.amplitude.com'; | ||
@@ -45,6 +29,6 @@ const AMPLITUDE_DASHBOARD_ENDPOINT = 'https://amplitude.com/api/2'; | ||
osName: 'os_name', | ||
osVersion: 'os_version', | ||
deviceBrand: 'device_brand', | ||
deviceManufacturer: 'device_manufacturer', | ||
deviceModel: 'device_model', | ||
deviceType: 'device_type', | ||
locationLat: 'location_lat', | ||
@@ -54,7 +38,6 @@ locationLng: 'location_lng' | ||
class Amplitude { | ||
constructor(token, options) { | ||
constructor(token, options = {}) { | ||
if (!token) { | ||
throw new Error('No token provided'); | ||
} | ||
options = options || {}; | ||
this.token = token; | ||
@@ -74,2 +57,4 @@ this.secretKey = options.secretKey; | ||
const transformedKey = camelCaseToSnakeCasePropertyMap[key] || key; | ||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore | ||
// @ts-ignore | ||
obj[transformedKey] = item[key]; | ||
@@ -93,5 +78,16 @@ return obj; | ||
}; | ||
return postBody(AMPLITUDE_TOKEN_ENDPOINT + '/identify', params); | ||
const encodedParams = Object.keys(params) | ||
.map(key => { | ||
return encodeURIComponent(key) + '=' + encodeURIComponent(params[key]); | ||
}) | ||
.join('&'); | ||
return errors_1.axiosErrorCatcher(axios_1.default | ||
.post(`${AMPLITUDE_TOKEN_ENDPOINT}/identify`, encodedParams, { | ||
headers: { | ||
'content-type': 'application/x-www-form-urlencoded' | ||
} | ||
}) | ||
.then(res => res.data)); | ||
} | ||
track(data) { | ||
track(data, options) { | ||
const transformedData = this._generateRequestData(data); | ||
@@ -101,18 +97,36 @@ const params = { | ||
api_key: this.token, | ||
event: JSON.stringify(transformedData) | ||
events: transformedData, | ||
options | ||
}; | ||
return postBody(AMPLITUDE_TOKEN_ENDPOINT + '/httpapi', params); | ||
return errors_1.axiosErrorCatcher(axios_1.default | ||
.post(`${AMPLITUDE_TOKEN_ENDPOINT}/2/httpapi`, params) | ||
.then(res => res.data)); | ||
} | ||
export(options) { | ||
if (!this.secretKey) { | ||
throw new Error('secretKey must be set to use the export method'); | ||
} | ||
if (!options.start || !options.end) { | ||
throw new Error('`start` and `end` are required options'); | ||
} | ||
return request.get(AMPLITUDE_DASHBOARD_ENDPOINT + '/export') | ||
.auth(this.token, this.secretKey) | ||
.query({ | ||
start: options.start, | ||
end: options.end | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
if (!this.secretKey) { | ||
throw new Error('secretKey must be set to use the export method'); | ||
} | ||
if (!options.start || !options.end) { | ||
throw new Error('`start` and `end` are required options'); | ||
} | ||
const res = yield axios_1.default.get(`${AMPLITUDE_DASHBOARD_ENDPOINT}/export`, { | ||
auth: { | ||
username: this.token, | ||
password: this.secretKey | ||
}, | ||
params: { | ||
start: options.start, | ||
end: options.end | ||
} | ||
}); | ||
return res; | ||
} | ||
catch (err) { | ||
if (err.response) { | ||
throw new errors_1.AmplitudeErrorResponse(err); | ||
} | ||
throw err; | ||
} | ||
}); | ||
@@ -127,13 +141,17 @@ } | ||
} | ||
return request.get(AMPLITUDE_DASHBOARD_ENDPOINT + '/usersearch') | ||
.auth(this.token, this.secretKey) | ||
.query({ | ||
user: userSearchId | ||
return errors_1.axiosErrorCatcher(axios_1.default | ||
.get(`${AMPLITUDE_DASHBOARD_ENDPOINT}/usersearch`, { | ||
auth: { | ||
username: this.token, | ||
password: this.secretKey | ||
}, | ||
params: { | ||
user: userSearchId | ||
} | ||
}) | ||
.set('Accept', 'application/json') | ||
.then(res => res.body); | ||
.then(res => res.data)); | ||
} | ||
userActivity(amplitudeId, data) { | ||
if (!data) { | ||
data = { | ||
userActivity(amplitudeId, params) { | ||
if (!params) { | ||
params = { | ||
user: amplitudeId | ||
@@ -143,3 +161,3 @@ }; | ||
else { | ||
data.user = amplitudeId; | ||
params.user = amplitudeId; | ||
} | ||
@@ -152,23 +170,31 @@ if (!this.secretKey) { | ||
} | ||
return request.get(AMPLITUDE_DASHBOARD_ENDPOINT + '/useractivity') | ||
.auth(this.token, this.secretKey) | ||
.query(data) | ||
.set('Accept', 'application/json') | ||
.then(res => res.body); | ||
return errors_1.axiosErrorCatcher(axios_1.default | ||
.get(`${AMPLITUDE_DASHBOARD_ENDPOINT}/useractivity`, { | ||
auth: { | ||
username: this.token, | ||
password: this.secretKey | ||
}, | ||
params | ||
}) | ||
.then(res => res.data)); | ||
} | ||
eventSegmentation(data) { | ||
eventSegmentation(params) { | ||
if (!this.secretKey) { | ||
throw new Error('secretKey must be set to use the eventSegmentation method'); | ||
} | ||
if (!data || !data.e || !data.start || !data.end) { | ||
if (!params || !params.e || !params.start || !params.end) { | ||
throw new Error('`e`, `start` and `end` are required data properties'); | ||
} | ||
if (typeof data.e === 'object') { | ||
data.e = JSON.stringify(data.e); | ||
if (typeof params.e === 'object') { | ||
params.e = JSON.stringify(params.e); | ||
} | ||
return request.get(AMPLITUDE_DASHBOARD_ENDPOINT + '/events/segmentation') | ||
.auth(this.token, this.secretKey) | ||
.query(data) | ||
.set('Accept', 'application/json') | ||
.then(res => res.body); | ||
return errors_1.axiosErrorCatcher(axios_1.default | ||
.get(`${AMPLITUDE_DASHBOARD_ENDPOINT}/events/segmentation`, { | ||
auth: { | ||
username: this.token, | ||
password: this.secretKey | ||
}, | ||
params | ||
}) | ||
.then(res => res.data)); | ||
} | ||
@@ -175,0 +201,0 @@ } |
import './types'; | ||
import Amplitude from './amplitude'; | ||
export = Amplitude; | ||
//# sourceMappingURL=index.d.ts.map | ||
export default Amplitude; | ||
export * from './public'; | ||
export { AmplitudeErrorResponse } from './errors'; |
@@ -5,5 +5,8 @@ "use strict"; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
require("./types"); | ||
const amplitude_1 = __importDefault(require("./amplitude")); | ||
module.exports = amplitude_1.default; | ||
exports.default = amplitude_1.default; | ||
var errors_1 = require("./errors"); | ||
exports.AmplitudeErrorResponse = errors_1.AmplitudeErrorResponse; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,3 @@ | ||
interface AmplitudePostRequestData extends AmplitudeRequestData { | ||
import { AmplitudeRequestData } from './public'; | ||
export interface AmplitudePostRequestData extends AmplitudeRequestData { | ||
user_id: string; | ||
@@ -6,2 +7,1 @@ device_id: string; | ||
} | ||
//# sourceMappingURL=interfaces.d.ts.map |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=interfaces.js.map |
@@ -1,33 +0,4 @@ | ||
declare type AmplitudeResponseBody = object; | ||
declare type AmplitudeQueryParams = { | ||
[key: string]: object | string | number | boolean | undefined; | ||
export declare type StringMap = { | ||
[key: string]: string; | ||
}; | ||
declare type AmplitudeRequestData = { | ||
eventType?: string; | ||
event_type?: string; | ||
[key: string]: object | string | number | boolean | undefined; | ||
}; | ||
declare type AmplitudeOptions = { | ||
secretKey?: string; | ||
userId?: string; | ||
deviceId?: string; | ||
sessionId?: string; | ||
user_id?: string; | ||
device_id?: string; | ||
session_id?: string; | ||
}; | ||
declare type AmplitudeExportOptions = { | ||
start?: Date; | ||
end?: Date; | ||
}; | ||
declare type AmplitudeSegmentationOptions = { | ||
start?: Date; | ||
end?: Date; | ||
e?: string | object; | ||
}; | ||
declare type AmplitudeUserActivityOptions = { | ||
user?: string | number; | ||
offset?: number; | ||
limit?: number; | ||
}; | ||
//# sourceMappingURL=types.d.ts.map | ||
export declare type AvailableCamelCaseToSnakeCasePropertyMap = 'user_id' | 'device_id' | 'session_id' | 'event_type' | 'event_properties' | 'user_properties' | 'app_version' | 'os_name' | 'os_version' | 'device_brand' | 'device_manufacturer' | 'device_model' | 'location_lat' | 'location_lng'; |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=types.js.map |
{ | ||
"name": "amplitude", | ||
"version": "5.0.1-next.2", | ||
"version": "5.0.1-next.3", | ||
"description": "A node wrapper for Amplitude analytics http api", | ||
"author": "Blade Barringer <blade@crookedneighbor.com>", | ||
"main": "dist/index.js", | ||
"main": "entry.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
"dist", | ||
"entry.js" | ||
], | ||
@@ -47,3 +48,3 @@ "engines": { | ||
"prepublishOnly": "npm run test", | ||
"test": "npm run lint && npm run build && nyc --reporter=lcov --reporter=text mocha", | ||
"test": "npm run lint && nyc --reporter=lcov --reporter=text mocha", | ||
"tdd": "mocha --watch" | ||
@@ -63,4 +64,3 @@ }, | ||
"dependencies": { | ||
"@types/superagent": "^4.1.7", | ||
"superagent": "^5.2.1" | ||
"axios": "^0.19.2" | ||
}, | ||
@@ -80,6 +80,11 @@ "devDependencies": { | ||
"eslint": "^6.8.0", | ||
"eslint-config-prettier": "^6.10.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"glob": "^7.1.6", | ||
"husky": "^4.2.3", | ||
"lint-staged": "^10.0.7", | ||
"mocha": "^7.0.1", | ||
"nock": "^11.8.2", | ||
"nyc": "^15.0.0", | ||
"prettier": "^1.19.1", | ||
"sinon": "^8.1.1", | ||
@@ -100,3 +105,2 @@ "sinon-chai": "^3.4.0", | ||
"timeout": 8000, | ||
"growl": true, | ||
"check-leaks": true, | ||
@@ -109,3 +113,11 @@ "recursive": true, | ||
] | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.{js,ts}": "eslint --cache --fix" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
38008
1
22
490
25
1
+ Addedaxios@^0.19.2
+ Addedaxios@0.19.2(transitive)
+ Addedfollow-redirects@1.5.10(transitive)
- Removed@types/superagent@^4.1.7
- Removedsuperagent@^5.2.1
- Removed@types/cookiejar@2.1.5(transitive)
- Removed@types/node@22.9.1(transitive)
- Removed@types/superagent@4.1.24(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcomponent-emitter@1.3.1(transitive)
- Removedcookiejar@2.1.4(transitive)
- Removeddebug@4.3.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfast-safe-stringify@2.1.1(transitive)
- Removedform-data@3.0.2(transitive)
- Removedformidable@1.2.6(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedinherits@2.0.4(transitive)
- Removedmethods@1.1.2(transitive)
- Removedmime@2.6.0(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedms@2.1.3(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedqs@6.13.1(transitive)
- Removedreadable-stream@3.6.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsemver@7.6.3(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedstring_decoder@1.3.0(transitive)
- Removedsuperagent@5.3.1(transitive)
- Removedundici-types@6.19.8(transitive)
- Removedutil-deprecate@1.0.2(transitive)