@ludens-reklame/profiler-client
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -9,2 +9,10 @@ interface Opts { | ||
} | ||
interface UpdateContactData { | ||
name?: string; | ||
email?: string; | ||
} | ||
interface UpdateContactOpts { | ||
data: UpdateContactData; | ||
contactRef?: string; | ||
} | ||
declare class Profiler { | ||
@@ -15,4 +23,5 @@ private organization; | ||
push(opts: PushOpts): Promise<void>; | ||
updateContact(opts: UpdateContactOpts): Promise<void>; | ||
private network; | ||
} | ||
export default Profiler; |
@@ -75,12 +75,40 @@ "use strict"; | ||
}; | ||
Profiler.prototype.network = function (endpoint, data) { | ||
Profiler.prototype.updateContact = function (opts) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response, json, error_2; | ||
var endpoint, error_2; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 2, , 3]); | ||
endpoint = 'contacts/' + (opts.contactRef || this.contactRef); | ||
return [4 /*yield*/, this.network(endpoint, opts.data, true)]; | ||
case 1: | ||
_a.sent(); | ||
return [3 /*break*/, 3]; | ||
case 2: | ||
error_2 = _a.sent(); | ||
console.error(error_2); | ||
return [3 /*break*/, 3]; | ||
case 3: return [2 /*return*/]; | ||
} | ||
}); | ||
}); | ||
}; | ||
Profiler.prototype.network = function (endpoint, data, asJSON) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var url, response, json, error_3; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
_a.trys.push([0, 3, , 4]); | ||
url = profilerURL + "/" + endpoint + "?" + qs.stringify(data); | ||
url = profilerURL + "/" + endpoint; | ||
if (!asJSON) { | ||
url = url + ("?" + qs.stringify(data)); | ||
} | ||
return [4 /*yield*/, fetch(url, { | ||
method: 'POST' | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: asJSON ? JSON.stringify(data) : null | ||
})]; | ||
@@ -98,4 +126,4 @@ case 1: | ||
case 3: | ||
error_2 = _a.sent(); | ||
console.error(error_2); | ||
error_3 = _a.sent(); | ||
console.error(error_3); | ||
return [3 /*break*/, 4]; | ||
@@ -102,0 +130,0 @@ case 4: return [2 /*return*/]; |
{ | ||
"name": "@ludens-reklame/profiler-client", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "Profiler for all", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
9932
166