Skip to content

Commit 0edf031

Browse files
Generate latest bundle
1 parent eb54009 commit 0edf031

File tree

4 files changed

+470
-155
lines changed

4 files changed

+470
-155
lines changed

dist/mparticle-data-planning.common.js

Lines changed: 152 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
44

55
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
66

7+
var path = _interopDefault(require('path'));
8+
var url = require('url');
9+
var url__default = _interopDefault(url);
710
var http = _interopDefault(require('http'));
811
var https = _interopDefault(require('https'));
9-
var url = _interopDefault(require('url'));
1012
var assert = _interopDefault(require('assert'));
1113
var stream = _interopDefault(require('stream'));
1214
var tty = _interopDefault(require('tty'));
@@ -1762,7 +1764,7 @@ RedirectableRequest.prototype._performRequest = function () {
17621764
// Create the native request
17631765
var request = this._currentRequest =
17641766
nativeProtocol.request(this._options, this._onNativeResponse);
1765-
this._currentUrl = url.format(this._options);
1767+
this._currentUrl = url__default.format(this._options);
17661768

17671769
// Set up event handlers
17681770
request._redirectable = this;
@@ -1848,9 +1850,9 @@ RedirectableRequest.prototype._processResponse = function (response) {
18481850
}
18491851

18501852
// Perform the redirected request
1851-
var redirectUrl = url.resolve(this._currentUrl, location);
1853+
var redirectUrl = url__default.resolve(this._currentUrl, location);
18521854
debug$1("redirecting to", redirectUrl);
1853-
Object.assign(this._options, url.parse(redirectUrl));
1855+
Object.assign(this._options, url__default.parse(redirectUrl));
18541856
this._isRedirect = true;
18551857
this._performRequest();
18561858

@@ -1886,7 +1888,7 @@ function wrap(protocols) {
18861888
// Executes a request, following redirects
18871889
wrappedProtocol.request = function (options, callback) {
18881890
if (typeof options === "string") {
1889-
options = url.parse(options);
1891+
options = url__default.parse(options);
18901892
options.maxRedirects = exports.maxRedirects;
18911893
}
18921894
else {
@@ -2154,7 +2156,7 @@ var http_1 = function httpAdapter(config) {
21542156
}
21552157

21562158
// Parse url
2157-
var parsed = url.parse(config.url);
2159+
var parsed = url__default.parse(config.url);
21582160
var protocol = parsed.protocol || 'http:';
21592161

21602162
if (!auth && parsed.auth) {
@@ -2191,7 +2193,7 @@ var http_1 = function httpAdapter(config) {
21912193
var proxyEnv = protocol.slice(0, -1) + '_proxy';
21922194
var proxyUrl = process.env[proxyEnv] || process.env[proxyEnv.toUpperCase()];
21932195
if (proxyUrl) {
2194-
var parsedProxyUrl = url.parse(proxyUrl);
2196+
var parsedProxyUrl = url__default.parse(proxyUrl);
21952197
var noProxyEnv = process.env.no_proxy || process.env.NO_PROXY;
21962198
var shouldProxy = true;
21972199

@@ -3175,15 +3177,72 @@ var ApiClient = /** @class */ (function () {
31753177
ApiClient.prototype.fetch = function () {
31763178
var headers = {};
31773179
if (this.token) {
3178-
headers['Authorization'] = "bearer " + this.token;
3180+
if (this.token.type.toUpperCase() === 'BEARER') {
3181+
headers['Authorization'] = this.token.type + " " + this.token.value;
3182+
}
3183+
else {
3184+
console.error('Received non-Bearer Token', this.token);
3185+
throw new Error('Invalid Auth token type');
3186+
}
31793187
}
31803188
return axios$1.get("" + this.rootUrl, {
31813189
headers: headers,
31823190
});
31833191
};
3192+
// tslint:disable-next-line: no-any
3193+
ApiClient.prototype.post = function (body) {
3194+
return axios$1.post("" + this.rootUrl, body);
3195+
};
31843196
return ApiClient;
31853197
}());
31863198

3199+
var config = {
3200+
apiRoot: 'https://api.mparticle.com',
3201+
dataPlanningPath: 'planning/v1',
3202+
auth: {
3203+
url: 'https://sso.auth.mparticle.com/oauth/token',
3204+
apiRoot: 'https://sso.auth.mparticle.com',
3205+
path: 'oauth/token',
3206+
audienceUrl: 'https://api.mparticle.com',
3207+
grant_type: 'client_credentials',
3208+
},
3209+
};
3210+
3211+
var AuthClient = /** @class */ (function () {
3212+
function AuthClient(clientId, clientSecret) {
3213+
this.clientId = clientId;
3214+
this.clientSecret = clientSecret;
3215+
}
3216+
AuthClient.prototype.getToken = function () {
3217+
return __awaiter(this, void 0, Promise, function () {
3218+
var api, body;
3219+
return __generator(this, function (_a) {
3220+
api = new ApiClient(config.auth.url);
3221+
body = {
3222+
client_id: this.clientId,
3223+
client_secret: this.clientSecret,
3224+
audience: config.auth.audienceUrl,
3225+
grant_type: config.auth.grant_type,
3226+
};
3227+
try {
3228+
return [2 /*return*/, api.post(body).then(function (response) {
3229+
var _a, _b, _c, _d;
3230+
return ({
3231+
type: (_b = (_a = response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.token_type,
3232+
value: (_d = (_c = response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.access_token,
3233+
});
3234+
})];
3235+
}
3236+
catch (error) {
3237+
return [2 /*return*/, error.response];
3238+
}
3239+
return [2 /*return*/];
3240+
});
3241+
});
3242+
};
3243+
return AuthClient;
3244+
}());
3245+
31873246
var validation_error_type = createCommonjsModule(function (module, exports) {
31883247
Object.defineProperty(exports, "__esModule", { value: true });
31893248
var ValidationErrorType;
@@ -11203,68 +11262,109 @@ var DataPlanEventValidator = /** @class */ (function () {
1120311262
return DataPlanEventValidator;
1120411263
}());
1120511264

11206-
var config = {
11207-
apiRoot: 'https://api.mparticle.com',
11208-
dataPlanningPath: 'planning/v1',
11209-
};
11210-
1121111265
var DataPlanService = /** @class */ (function () {
11212-
function DataPlanService() {
11213-
}
11214-
DataPlanService.prototype.getAPIURL = function (orgId, accountId, workspaceId) {
11215-
return [
11216-
config.apiRoot + "/" + config.dataPlanningPath + "/",
11217-
orgId + "/",
11218-
accountId + "/",
11219-
workspaceId + "/",
11220-
"plans/",
11221-
].join('');
11222-
};
11223-
DataPlanService.prototype.getPlan = function (orgId, accountId, dataPlanId, workspaceId, token) {
11266+
function DataPlanService(credentials) {
11267+
if (credentials) {
11268+
var orgId = credentials.orgId, accountId = credentials.accountId, workspaceId = credentials.workspaceId, clientId = credentials.clientId, clientSecret = credentials.clientSecret;
11269+
this.orgId = orgId;
11270+
this.accountId = accountId;
11271+
this.workspaceId = workspaceId;
11272+
this.clientId = clientId;
11273+
this.clientSecret = clientSecret;
11274+
this.apiURL = this.getAPIURL();
11275+
}
11276+
}
11277+
DataPlanService.prototype.getToken = function () {
1122411278
return __awaiter(this, void 0, Promise, function () {
11225-
var url, api;
1122611279
return __generator(this, function (_a) {
11227-
url = this.getAPIURL(orgId, accountId, workspaceId);
11228-
api = new ApiClient(url + dataPlanId, token);
11229-
try {
11230-
return [2 /*return*/, api.fetch().then(function (response) { return response.data; })];
11280+
if (this.clientId && this.clientSecret) {
11281+
return [2 /*return*/, new AuthClient(this.clientId, this.clientSecret).getToken()];
1123111282
}
11232-
catch (error) {
11233-
return [2 /*return*/, error.response];
11283+
else {
11284+
return [2 /*return*/, undefined];
1123411285
}
11235-
return [2 /*return*/];
1123611286
});
1123711287
});
1123811288
};
11239-
DataPlanService.prototype.getAllPlans = function (orgId, accountId, workspaceId, token) {
11289+
DataPlanService.prototype.buildUrl = function (base, path) {
11290+
return new url.URL(path, base).toString();
11291+
};
11292+
DataPlanService.prototype.getAPIURL = function () {
11293+
var _a = this, orgId = _a.orgId, accountId = _a.accountId, workspaceId = _a.workspaceId;
11294+
if (orgId && accountId && workspaceId) {
11295+
var urlPath = path.join(config.dataPlanningPath, "" + orgId, "" + accountId, "" + workspaceId, "plans/");
11296+
return this.buildUrl(config.apiRoot, urlPath);
11297+
}
11298+
throw new Error('Invalid Credentials for generating API Request');
11299+
};
11300+
DataPlanService.prototype.getPlan = function (dataPlanId) {
1124011301
return __awaiter(this, void 0, Promise, function () {
11241-
var url, api;
11302+
var token, api;
1124211303
return __generator(this, function (_a) {
11243-
url = this.getAPIURL(orgId, accountId, workspaceId);
11244-
api = new ApiClient(url, token);
11245-
try {
11246-
return [2 /*return*/, api.fetch().then(function (response) { return response.data; })];
11247-
}
11248-
catch (error) {
11249-
return [2 /*return*/, error.response];
11304+
switch (_a.label) {
11305+
case 0:
11306+
if (!this.apiURL) {
11307+
throw new Error('Invalid API URL');
11308+
}
11309+
return [4 /*yield*/, this.getToken()];
11310+
case 1:
11311+
token = _a.sent();
11312+
api = new ApiClient(this.buildUrl(this.apiURL, dataPlanId), token);
11313+
try {
11314+
return [2 /*return*/, api.fetch().then(function (response) { return response.data; })];
11315+
}
11316+
catch (error) {
11317+
return [2 /*return*/, error.response];
11318+
}
11319+
return [2 /*return*/];
1125011320
}
11251-
return [2 /*return*/];
1125211321
});
1125311322
});
1125411323
};
11255-
DataPlanService.prototype.getVersionDocument = function (orgId, accountId, dataPlanId, workspaceId, versionNumber, token) {
11324+
DataPlanService.prototype.getAllPlans = function () {
1125611325
return __awaiter(this, void 0, Promise, function () {
11257-
var url, api;
11326+
var token, api;
1125811327
return __generator(this, function (_a) {
11259-
url = this.getAPIURL(orgId, accountId, workspaceId);
11260-
api = new ApiClient("" + url + dataPlanId + "/versions/" + versionNumber, token);
11261-
try {
11262-
return [2 /*return*/, api.fetch().then(function (response) { return response.data; })];
11328+
switch (_a.label) {
11329+
case 0: return [4 /*yield*/, this.getToken()];
11330+
case 1:
11331+
token = _a.sent();
11332+
if (!this.apiURL) {
11333+
throw new Error('Invalid API URL');
11334+
}
11335+
api = new ApiClient(this.apiURL, token);
11336+
try {
11337+
return [2 /*return*/, api.fetch().then(function (response) { return response.data; })];
11338+
}
11339+
catch (error) {
11340+
return [2 /*return*/, error.response];
11341+
}
11342+
return [2 /*return*/];
1126311343
}
11264-
catch (error) {
11265-
return [2 /*return*/, error.response];
11344+
});
11345+
});
11346+
};
11347+
DataPlanService.prototype.getVersionDocument = function (dataPlanId, versionNumber) {
11348+
return __awaiter(this, void 0, Promise, function () {
11349+
var token, api;
11350+
return __generator(this, function (_a) {
11351+
switch (_a.label) {
11352+
case 0:
11353+
if (!this.apiURL) {
11354+
throw new Error('Invalid API URL');
11355+
}
11356+
return [4 /*yield*/, this.getToken()];
11357+
case 1:
11358+
token = _a.sent();
11359+
api = new ApiClient(this.buildUrl(this.apiURL, dataPlanId + "/versions/" + versionNumber), token);
11360+
try {
11361+
return [2 /*return*/, api.fetch().then(function (response) { return response.data; })];
11362+
}
11363+
catch (error) {
11364+
return [2 /*return*/, error.response];
11365+
}
11366+
return [2 /*return*/];
1126611367
}
11267-
return [2 /*return*/];
1126811368
});
1126911369
});
1127011370
};

0 commit comments

Comments
 (0)