@openmeter/sdk 1.0.0-beta.60 → 1.0.0-beta.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/clients/client.js +194 -0
- package/dist/cjs/clients/client.js.map +1 -0
- package/dist/cjs/clients/event.js +137 -0
- package/dist/cjs/clients/event.js.map +1 -0
- package/dist/cjs/clients/meter.js +139 -0
- package/dist/cjs/clients/meter.js.map +1 -0
- package/dist/cjs/clients/portal.js +109 -0
- package/dist/cjs/clients/portal.js.map +1 -0
- package/dist/cjs/clients/subject.js +141 -0
- package/dist/cjs/clients/subject.js.map +1 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/schemas/openapi.js +7 -0
- package/dist/cjs/schemas/openapi.js.map +1 -0
- package/dist/cjs/test/agent.js +266 -0
- package/dist/cjs/test/agent.js.map +1 -0
- package/dist/cjs/test/mocks.js +44 -0
- package/dist/cjs/test/mocks.js.map +1 -0
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
- package/dist/esm/clients/client.js +191 -0
- package/dist/esm/clients/client.js.map +1 -0
- package/dist/esm/clients/event.js +131 -0
- package/dist/esm/clients/event.js.map +1 -0
- package/dist/esm/clients/meter.js +136 -0
- package/dist/esm/clients/meter.js.map +1 -0
- package/dist/esm/clients/portal.js +106 -0
- package/dist/esm/clients/portal.js.map +1 -0
- package/dist/esm/clients/subject.js +138 -0
- package/dist/esm/clients/subject.js.map +1 -0
- package/dist/{index.js → esm/index.js} +6 -7
- package/dist/esm/index.js.map +1 -0
- package/dist/{schemas → esm/schemas}/openapi.js +1 -0
- package/dist/esm/schemas/openapi.js.map +1 -0
- package/dist/{test → esm/test}/agent.js +8 -7
- package/dist/esm/test/agent.js.map +1 -0
- package/dist/{test → esm/test}/mocks.js +5 -4
- package/dist/esm/test/mocks.js.map +1 -0
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/{clients → types/clients}/client.d.ts +1 -2
- package/dist/{schemas → types/schemas}/openapi.d.ts +5 -2
- package/package.json +25 -20
- package/tsconfig.base.json +24 -0
- package/tsconfig.cjs.json +8 -0
- package/tsconfig.esm.json +8 -0
- package/dist/clients/client.js +0 -111
- package/dist/clients/event.js +0 -60
- package/dist/clients/meter.js +0 -64
- package/dist/clients/portal.js +0 -36
- package/dist/clients/subject.js +0 -55
- package/dist/tsconfig.tsbuildinfo +0 -1
- /package/dist/{clients → types/clients}/event.d.ts +0 -0
- /package/dist/{clients → types/clients}/meter.d.ts +0 -0
- /package/dist/{clients → types/clients}/portal.d.ts +0 -0
- /package/dist/{clients → types/clients}/subject.d.ts +0 -0
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{test → types/test}/agent.d.ts +0 -0
- /package/dist/{test → types/test}/mocks.d.ts +0 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __assign = (this && this.__assign) || function () {
|
|
18
|
+
__assign = Object.assign || function(t) {
|
|
19
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
+
s = arguments[i];
|
|
21
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
+
t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
29
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
30
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
31
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
32
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
33
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
34
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
38
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
39
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
40
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
41
|
+
function step(op) {
|
|
42
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
43
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
44
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
45
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
46
|
+
switch (op[0]) {
|
|
47
|
+
case 0: case 1: t = op; break;
|
|
48
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
49
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
50
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
51
|
+
default:
|
|
52
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
53
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
54
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
55
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
56
|
+
if (t[2]) _.ops.pop();
|
|
57
|
+
_.trys.pop(); continue;
|
|
58
|
+
}
|
|
59
|
+
op = body.call(thisArg, _);
|
|
60
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
61
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
65
|
+
exports.HttpError = exports.BaseClient = void 0;
|
|
66
|
+
var undici_1 = require("undici");
|
|
67
|
+
var BaseClient = /** @class */ (function () {
|
|
68
|
+
function BaseClient(config) {
|
|
69
|
+
this.config = config;
|
|
70
|
+
}
|
|
71
|
+
BaseClient.prototype.request = function (_a) {
|
|
72
|
+
return __awaiter(this, arguments, void 0, function (_b) {
|
|
73
|
+
var url, reqHeaders, reqOpts, resp, problem;
|
|
74
|
+
var path = _b.path, method = _b.method, searchParams = _b.searchParams, headers = _b.headers, body = _b.body, options = _b.options;
|
|
75
|
+
return __generator(this, function (_c) {
|
|
76
|
+
switch (_c.label) {
|
|
77
|
+
case 0:
|
|
78
|
+
url = this.getUrl(path, searchParams);
|
|
79
|
+
reqHeaders = __assign(__assign(__assign(__assign({ Accept: 'application/json' }, headers), this.getAuthHeaders()), this.config.headers), options === null || options === void 0 ? void 0 : options.headers);
|
|
80
|
+
reqOpts = {
|
|
81
|
+
method: method,
|
|
82
|
+
headers: reqHeaders,
|
|
83
|
+
};
|
|
84
|
+
// Optional body
|
|
85
|
+
if (body) {
|
|
86
|
+
if (!reqHeaders['Content-Type'] && !reqHeaders['content-type']) {
|
|
87
|
+
throw new Error('Content Type is required with body');
|
|
88
|
+
}
|
|
89
|
+
reqOpts.body = body;
|
|
90
|
+
}
|
|
91
|
+
return [4 /*yield*/, (0, undici_1.request)(url, reqOpts)
|
|
92
|
+
// Error handling
|
|
93
|
+
];
|
|
94
|
+
case 1:
|
|
95
|
+
resp = _c.sent();
|
|
96
|
+
if (!(resp.statusCode > 399)) return [3 /*break*/, 4];
|
|
97
|
+
if (!(resp.headers['content-type'] === 'application/problem+json')) return [3 /*break*/, 3];
|
|
98
|
+
return [4 /*yield*/, resp.body.json()];
|
|
99
|
+
case 2:
|
|
100
|
+
problem = (_c.sent());
|
|
101
|
+
throw new HttpError({
|
|
102
|
+
statusCode: resp.statusCode,
|
|
103
|
+
problem: problem,
|
|
104
|
+
});
|
|
105
|
+
case 3:
|
|
106
|
+
// Requests can fail before API, in this case we only have a status code
|
|
107
|
+
throw new HttpError({
|
|
108
|
+
statusCode: resp.statusCode,
|
|
109
|
+
});
|
|
110
|
+
case 4:
|
|
111
|
+
// Response parsing
|
|
112
|
+
if (resp.statusCode === 204 || resp.headers['content-length'] === '0') {
|
|
113
|
+
return [2 /*return*/, undefined];
|
|
114
|
+
}
|
|
115
|
+
if (!(resp.headers['content-type'] === 'application/json')) return [3 /*break*/, 6];
|
|
116
|
+
return [4 /*yield*/, resp.body.json()];
|
|
117
|
+
case 5: return [2 /*return*/, (_c.sent())];
|
|
118
|
+
case 6:
|
|
119
|
+
if (!resp.headers['content-type']) {
|
|
120
|
+
throw new Error('Missing content type');
|
|
121
|
+
}
|
|
122
|
+
throw new Error("Unknown content type: ".concat(resp.headers['content-type']));
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
BaseClient.prototype.getUrl = function (path, searchParams) {
|
|
128
|
+
var qs = searchParams ? searchParams.toString() : '';
|
|
129
|
+
qs = qs.length > 0 ? "?".concat(qs) : '';
|
|
130
|
+
var url = new URL("".concat(path).concat(qs), this.config.baseUrl);
|
|
131
|
+
return url;
|
|
132
|
+
};
|
|
133
|
+
BaseClient.prototype.getAuthHeaders = function () {
|
|
134
|
+
if (this.config.token) {
|
|
135
|
+
return {
|
|
136
|
+
authorization: "Bearer ".concat(this.config.token),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
if (this.config.username && this.config.password) {
|
|
140
|
+
var encoded = Buffer.from("".concat(this.config.username, ":").concat(this.config.password)).toString('base64');
|
|
141
|
+
return {
|
|
142
|
+
authorization: "Basic ".concat(encoded),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {};
|
|
146
|
+
};
|
|
147
|
+
BaseClient.toURLSearchParams = function (params) {
|
|
148
|
+
var searchParams = new URLSearchParams();
|
|
149
|
+
var _loop_1 = function (key, value) {
|
|
150
|
+
if (value === undefined) {
|
|
151
|
+
return "continue";
|
|
152
|
+
}
|
|
153
|
+
if (Array.isArray(value)) {
|
|
154
|
+
for (var _c = 0, value_1 = value; _c < value_1.length; _c++) {
|
|
155
|
+
var item = value_1[_c];
|
|
156
|
+
searchParams.append(key, item);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else if (value instanceof Date) {
|
|
160
|
+
searchParams.append(key, value.toISOString());
|
|
161
|
+
}
|
|
162
|
+
else if (typeof value === 'object') {
|
|
163
|
+
Object.entries(value).forEach(function (_a) {
|
|
164
|
+
var k = _a[0], v = _a[1];
|
|
165
|
+
searchParams.append("".concat(key, "[").concat(k, "]"), v);
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
searchParams.append(key, value.toString());
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
for (var _i = 0, _a = Object.entries(params); _i < _a.length; _i++) {
|
|
173
|
+
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
174
|
+
_loop_1(key, value);
|
|
175
|
+
}
|
|
176
|
+
return searchParams;
|
|
177
|
+
};
|
|
178
|
+
return BaseClient;
|
|
179
|
+
}());
|
|
180
|
+
exports.BaseClient = BaseClient;
|
|
181
|
+
var HttpError = /** @class */ (function (_super) {
|
|
182
|
+
__extends(HttpError, _super);
|
|
183
|
+
function HttpError(_a) {
|
|
184
|
+
var statusCode = _a.statusCode, problem = _a.problem;
|
|
185
|
+
var _this = _super.call(this, (problem === null || problem === void 0 ? void 0 : problem.type) || 'unexpected status code') || this;
|
|
186
|
+
_this.name = 'HttpError';
|
|
187
|
+
_this.statusCode = statusCode;
|
|
188
|
+
_this.problem = problem;
|
|
189
|
+
return _this;
|
|
190
|
+
}
|
|
191
|
+
return HttpError;
|
|
192
|
+
}(Error));
|
|
193
|
+
exports.HttpError = HttpError;
|
|
194
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../clients/client.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,iCAA4C;AAuB5C;IAGE,oBAAY,MAAuB;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAEe,4BAAO,GAAvB;4DAA2B,EAc1B;;gBAbC,IAAI,UAAA,EACJ,MAAM,YAAA,EACN,YAAY,kBAAA,EACZ,OAAO,aAAA,EACP,IAAI,UAAA,EACJ,OAAO,aAAA;;;;wBAUD,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,CAAA;wBAGrC,UAAU,yCACd,MAAM,EAAE,kBAAkB,IACvB,OAAO,GACP,IAAI,CAAC,cAAc,EAAE,GACrB,IAAI,CAAC,MAAM,CAAC,OAAO,GACnB,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,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AAK;IAIlC,mBAAY,EAMX;YALC,UAAU,gBAAA,EACV,OAAO,aAAA;QAKP,YAAA,MAAK,YAAC,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,KAAI,wBAAwB,CAAC,SAAA;QAChD,KAAI,CAAC,IAAI,GAAG,WAAW,CAAA;QACvB,KAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,KAAI,CAAC,OAAO,GAAG,OAAO,CAAA;;IACxB,CAAC;IACH,gBAAC;AAAD,CAAC,AAhBD,CAA+B,KAAK,GAgBnC;AAhBY,8BAAS"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
54
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
55
|
+
};
|
|
56
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
57
|
+
exports.EventsClient = void 0;
|
|
58
|
+
var crypto_1 = __importDefault(require("crypto"));
|
|
59
|
+
var client_js_1 = require("./client.js");
|
|
60
|
+
var EventsClient = /** @class */ (function (_super) {
|
|
61
|
+
__extends(EventsClient, _super);
|
|
62
|
+
function EventsClient(config) {
|
|
63
|
+
return _super.call(this, config) || this;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Ingest usage event in a CloudEvents format
|
|
67
|
+
* @see https://cloudevents.io
|
|
68
|
+
*/
|
|
69
|
+
EventsClient.prototype.ingest = function (usageEvent, options) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var isBatch, cloudEvents, contentType, body;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
isBatch = Array.isArray(usageEvent);
|
|
76
|
+
cloudEvents = (isBatch ? usageEvent : [usageEvent]).map(function (ev) {
|
|
77
|
+
var _a, _b, _c, _d;
|
|
78
|
+
// Validate content type
|
|
79
|
+
if (ev.datacontenttype &&
|
|
80
|
+
ev.datacontenttype !== 'application/json') {
|
|
81
|
+
throw new TypeError("Unsupported datacontenttype: ".concat(ev.datacontenttype));
|
|
82
|
+
}
|
|
83
|
+
// We default where we can to lower the barrier to use CloudEvents
|
|
84
|
+
var cloudEvent = {
|
|
85
|
+
specversion: (_a = ev.specversion) !== null && _a !== void 0 ? _a : '1.0',
|
|
86
|
+
id: (_b = ev.id) !== null && _b !== void 0 ? _b : crypto_1.default.randomUUID(),
|
|
87
|
+
source: (_c = ev.source) !== null && _c !== void 0 ? _c : '@openmeter/sdk',
|
|
88
|
+
type: ev.type,
|
|
89
|
+
subject: ev.subject,
|
|
90
|
+
time: (_d = ev.time) === null || _d === void 0 ? void 0 : _d.toISOString(),
|
|
91
|
+
datacontenttype: ev.datacontenttype,
|
|
92
|
+
dataschema: ev.dataschema,
|
|
93
|
+
data: ev.data,
|
|
94
|
+
};
|
|
95
|
+
return cloudEvent;
|
|
96
|
+
});
|
|
97
|
+
contentType = isBatch ? 'application/cloudevents-batch+json' : 'application/cloudevents+json';
|
|
98
|
+
body = isBatch ? JSON.stringify(cloudEvents) : JSON.stringify(cloudEvents[0]);
|
|
99
|
+
return [4 /*yield*/, this.request({
|
|
100
|
+
path: '/api/v1/events',
|
|
101
|
+
method: 'POST',
|
|
102
|
+
body: body,
|
|
103
|
+
headers: {
|
|
104
|
+
'Content-Type': contentType,
|
|
105
|
+
},
|
|
106
|
+
options: options,
|
|
107
|
+
})];
|
|
108
|
+
case 1:
|
|
109
|
+
// Making Request
|
|
110
|
+
return [2 /*return*/, _a.sent()];
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* List raw events
|
|
117
|
+
*/
|
|
118
|
+
EventsClient.prototype.list = function (params, options) {
|
|
119
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
+
var searchParams;
|
|
121
|
+
return __generator(this, function (_a) {
|
|
122
|
+
searchParams = params
|
|
123
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
124
|
+
: undefined;
|
|
125
|
+
return [2 /*return*/, this.request({
|
|
126
|
+
method: 'GET',
|
|
127
|
+
path: "/api/v1/events",
|
|
128
|
+
searchParams: searchParams,
|
|
129
|
+
options: options,
|
|
130
|
+
})];
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
return EventsClient;
|
|
135
|
+
}(client_js_1.BaseClient));
|
|
136
|
+
exports.EventsClient = EventsClient;
|
|
137
|
+
//# sourceMappingURL=event.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../clients/event.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kDAA2B;AAE3B,yCAAyE;AAuEzE;IAAkC,gCAAU;IAC1C,sBAAY,MAAuB;QACjC,OAAA,MAAK,YAAC,MAAM,CAAC,SAAA;IACf,CAAC;IAED;;;OAGG;IACU,6BAAM,GAAnB,UACE,UAA2B,EAC3B,OAAwB;;;;;;wBAElB,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;wBACnC,WAAW,GAAkB,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,UAAC,EAAE;;4BAC9E,wBAAwB;4BACxB,IACE,EAAE,CAAC,eAAe;gCAClB,EAAE,CAAC,eAAe,KAAK,kBAAkB,EACzC,CAAC;gCACD,MAAM,IAAI,SAAS,CACjB,uCAAgC,EAAE,CAAC,eAAe,CAAE,CACrD,CAAA;4BACH,CAAC;4BAED,kEAAkE;4BAClE,IAAM,UAAU,GAAgB;gCAC9B,WAAW,EAAE,MAAA,EAAE,CAAC,WAAW,mCAAI,KAAK;gCACpC,EAAE,EAAE,MAAA,EAAE,CAAC,EAAE,mCAAI,gBAAM,CAAC,UAAU,EAAE;gCAChC,MAAM,EAAE,MAAA,EAAE,CAAC,MAAM,mCAAI,gBAAgB;gCACrC,IAAI,EAAE,EAAE,CAAC,IAAI;gCACb,OAAO,EAAE,EAAE,CAAC,OAAO;gCACnB,IAAI,EAAE,MAAA,EAAE,CAAC,IAAI,0CAAE,WAAW,EAAE;gCAC5B,eAAe,EAAE,EAAE,CAAC,eAAe;gCACnC,UAAU,EAAE,EAAE,CAAC,UAAU;gCACzB,IAAI,EAAE,EAAE,CAAC,IAAI;6BACd,CAAA;4BAED,OAAO,UAAU,CAAA;wBACnB,CAAC,CAAC,CAAA;wBAEI,WAAW,GAAG,OAAO,CAAC,CAAC,CAAC,oCAAoC,CAAC,CAAC,CAAC,8BAA8B,CAAA;wBAC7F,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAA;wBAG5E,qBAAM,IAAI,CAAC,OAAO,CAAC;gCACxB,IAAI,EAAE,gBAAgB;gCACtB,MAAM,EAAE,MAAM;gCACd,IAAI,MAAA;gCACJ,OAAO,EAAE;oCACP,cAAc,EAAE,WAAW;iCAC5B;gCACD,OAAO,SAAA;6BACR,CAAC,EAAA;;oBATF,iBAAiB;oBACjB,sBAAO,SAQL,EAAA;;;;KACH;IAED;;OAEG;IACU,2BAAI,GAAjB,UACE,MAA0B,EAC1B,OAAwB;;;;gBAElB,YAAY,GAAG,MAAM;oBACzB,CAAC,CAAC,sBAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC;oBACtC,CAAC,CAAC,SAAS,CAAA;gBACb,sBAAO,IAAI,CAAC,OAAO,CAAkB;wBACnC,MAAM,EAAE,KAAK;wBACb,IAAI,EAAE,gBAAgB;wBACtB,YAAY,cAAA;wBACZ,OAAO,SAAA;qBACR,CAAC,EAAA;;;KACH;IACH,mBAAC;AAAD,CAAC,AAzED,CAAkC,sBAAU,GAyE3C;AAzEY,oCAAY"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.MetersClient = exports.MeterAggregation = exports.WindowSize = void 0;
|
|
55
|
+
var client_js_1 = require("./client.js");
|
|
56
|
+
var WindowSize;
|
|
57
|
+
(function (WindowSize) {
|
|
58
|
+
WindowSize["MINUTE"] = "MINUTE";
|
|
59
|
+
WindowSize["HOUR"] = "HOUR";
|
|
60
|
+
WindowSize["DAY"] = "DAY";
|
|
61
|
+
})(WindowSize || (exports.WindowSize = WindowSize = {}));
|
|
62
|
+
var MeterAggregation;
|
|
63
|
+
(function (MeterAggregation) {
|
|
64
|
+
MeterAggregation["SUM"] = "SUM";
|
|
65
|
+
MeterAggregation["COUNT"] = "COUNT";
|
|
66
|
+
MeterAggregation["AVG"] = "AVG";
|
|
67
|
+
MeterAggregation["MIN"] = "MIN";
|
|
68
|
+
MeterAggregation["MAX"] = "MAX";
|
|
69
|
+
})(MeterAggregation || (exports.MeterAggregation = MeterAggregation = {}));
|
|
70
|
+
var MetersClient = /** @class */ (function (_super) {
|
|
71
|
+
__extends(MetersClient, _super);
|
|
72
|
+
function MetersClient(config) {
|
|
73
|
+
return _super.call(this, config) || this;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Get one meter by slug
|
|
77
|
+
*/
|
|
78
|
+
MetersClient.prototype.get = function (slug, options) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
80
|
+
return __generator(this, function (_a) {
|
|
81
|
+
return [2 /*return*/, this.request({
|
|
82
|
+
method: 'GET',
|
|
83
|
+
path: "/api/v1/meters/".concat(slug),
|
|
84
|
+
options: options,
|
|
85
|
+
})];
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* List meters
|
|
91
|
+
*/
|
|
92
|
+
MetersClient.prototype.list = function (options) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
94
|
+
return __generator(this, function (_a) {
|
|
95
|
+
return [2 /*return*/, this.request({
|
|
96
|
+
method: 'GET',
|
|
97
|
+
path: "/api/v1/meters",
|
|
98
|
+
options: options,
|
|
99
|
+
})];
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Query a meter
|
|
105
|
+
*/
|
|
106
|
+
MetersClient.prototype.query = function (slug, params, options) {
|
|
107
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
+
var searchParams;
|
|
109
|
+
return __generator(this, function (_a) {
|
|
110
|
+
searchParams = params
|
|
111
|
+
? client_js_1.BaseClient.toURLSearchParams(params)
|
|
112
|
+
: undefined;
|
|
113
|
+
return [2 /*return*/, this.request({
|
|
114
|
+
method: 'GET',
|
|
115
|
+
path: "/api/v1/meters/".concat(slug, "/query"),
|
|
116
|
+
searchParams: searchParams,
|
|
117
|
+
options: options,
|
|
118
|
+
})];
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* List subjects of a meter
|
|
124
|
+
*/
|
|
125
|
+
MetersClient.prototype.subjects = function (slug, options) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
127
|
+
return __generator(this, function (_a) {
|
|
128
|
+
return [2 /*return*/, this.request({
|
|
129
|
+
method: 'GET',
|
|
130
|
+
path: "/api/v1/meters/".concat(slug, "/subjects"),
|
|
131
|
+
options: options,
|
|
132
|
+
})];
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
return MetersClient;
|
|
137
|
+
}(client_js_1.BaseClient));
|
|
138
|
+
exports.MetersClient = MetersClient;
|
|
139
|
+
//# sourceMappingURL=meter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"meter.js","sourceRoot":"","sources":["../../../clients/meter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAyE;AAEzE,IAAY,UAIX;AAJD,WAAY,UAAU;IACpB,+BAAiB,CAAA;IACjB,2BAAa,CAAA;IACb,yBAAW,CAAA;AACb,CAAC,EAJW,UAAU,0BAAV,UAAU,QAIrB;AAED,IAAY,gBAMX;AAND,WAAY,gBAAgB;IAC1B,+BAAW,CAAA;IACX,mCAAe,CAAA;IACf,+BAAW,CAAA;IACX,+BAAW,CAAA;IACX,+BAAW,CAAA;AACb,CAAC,EANW,gBAAgB,gCAAhB,gBAAgB,QAM3B;AAgDD;IAAkC,gCAAU;IAC1C,sBAAY,MAAuB;QACjC,OAAA,MAAK,YAAC,MAAM,CAAC,SAAA;IACf,CAAC;IAED;;OAEG;IACU,0BAAG,GAAhB,UAAiB,IAAY,EAAE,OAAwB;;;gBACrD,sBAAO,IAAI,CAAC,OAAO,CAAQ;wBACzB,MAAM,EAAE,KAAK;wBACb,IAAI,EAAE,yBAAkB,IAAI,CAAE;wBAC9B,OAAO,SAAA;qBACR,CAAC,EAAA;;;KACH;IAED;;OAEG;IACU,2BAAI,GAAjB,UAAkB,OAAwB;;;gBACxC,sBAAO,IAAI,CAAC,OAAO,CAAU;wBAC3B,MAAM,EAAE,KAAK;wBACb,IAAI,EAAE,gBAAgB;wBACtB,OAAO,SAAA;qBACR,CAAC,EAAA;;;KACH;IAED;;OAEG;IACU,4BAAK,GAAlB,UACE,IAAY,EACZ,MAAyB,EACzB,OAAwB;;;;gBAElB,YAAY,GAAG,MAAM;oBACzB,CAAC,CAAC,sBAAU,CAAC,iBAAiB,CAAC,MAAM,CAAC;oBACtC,CAAC,CAAC,SAAS,CAAA;gBACb,sBAAO,IAAI,CAAC,OAAO,CAAqB;wBACtC,MAAM,EAAE,KAAK;wBACb,IAAI,EAAE,yBAAkB,IAAI,WAAQ;wBACpC,YAAY,cAAA;wBACZ,OAAO,SAAA;qBACR,CAAC,EAAA;;;KACH;IAED;;OAEG;IACU,+BAAQ,GAArB,UACE,IAAY,EACZ,OAAwB;;;gBAExB,sBAAO,IAAI,CAAC,OAAO,CAAW;wBAC5B,MAAM,EAAE,KAAK;wBACb,IAAI,EAAE,yBAAkB,IAAI,cAAW;wBACvC,OAAO,SAAA;qBACR,CAAC,EAAA;;;KACH;IACH,mBAAC;AAAD,CAAC,AA3DD,CAAkC,sBAAU,GA2D3C;AA3DY,oCAAY"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __extends = (this && this.__extends) || (function () {
|
|
3
|
+
var extendStatics = function (d, b) {
|
|
4
|
+
extendStatics = Object.setPrototypeOf ||
|
|
5
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
+
return extendStatics(d, b);
|
|
8
|
+
};
|
|
9
|
+
return function (d, b) {
|
|
10
|
+
if (typeof b !== "function" && b !== null)
|
|
11
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
+
extendStatics(d, b);
|
|
13
|
+
function __() { this.constructor = d; }
|
|
14
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
+
};
|
|
16
|
+
})();
|
|
17
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
18
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
19
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
20
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
21
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
22
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
23
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
27
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
28
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
29
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
30
|
+
function step(op) {
|
|
31
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
32
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
33
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
34
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
35
|
+
switch (op[0]) {
|
|
36
|
+
case 0: case 1: t = op; break;
|
|
37
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
38
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
39
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
40
|
+
default:
|
|
41
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
42
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
43
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
44
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
45
|
+
if (t[2]) _.ops.pop();
|
|
46
|
+
_.trys.pop(); continue;
|
|
47
|
+
}
|
|
48
|
+
op = body.call(thisArg, _);
|
|
49
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
50
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
54
|
+
exports.PortalClient = void 0;
|
|
55
|
+
var client_js_1 = require("./client.js");
|
|
56
|
+
var PortalClient = /** @class */ (function (_super) {
|
|
57
|
+
__extends(PortalClient, _super);
|
|
58
|
+
function PortalClient(config) {
|
|
59
|
+
return _super.call(this, config) || this;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Create portal token
|
|
63
|
+
* Useful for creating a token sharable with your customer to query their own usage
|
|
64
|
+
*/
|
|
65
|
+
PortalClient.prototype.createToken = function (token, options) {
|
|
66
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0: return [4 /*yield*/, this.request({
|
|
70
|
+
path: '/api/v1/portal/tokens',
|
|
71
|
+
method: 'POST',
|
|
72
|
+
headers: {
|
|
73
|
+
'Content-Type': 'application/json',
|
|
74
|
+
},
|
|
75
|
+
body: JSON.stringify(token),
|
|
76
|
+
options: options,
|
|
77
|
+
})];
|
|
78
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Invalidate portal token
|
|
85
|
+
* @note OpenMeter Cloud only feature
|
|
86
|
+
*/
|
|
87
|
+
PortalClient.prototype.invalidateTokens = function () {
|
|
88
|
+
return __awaiter(this, arguments, void 0, function (invalidate, options) {
|
|
89
|
+
if (invalidate === void 0) { invalidate = {}; }
|
|
90
|
+
return __generator(this, function (_a) {
|
|
91
|
+
switch (_a.label) {
|
|
92
|
+
case 0: return [4 /*yield*/, this.request({
|
|
93
|
+
path: '/api/v1/portal/tokens/invalidate',
|
|
94
|
+
method: 'POST',
|
|
95
|
+
headers: {
|
|
96
|
+
'Content-Type': 'application/json',
|
|
97
|
+
},
|
|
98
|
+
body: JSON.stringify(invalidate),
|
|
99
|
+
options: options,
|
|
100
|
+
})];
|
|
101
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
return PortalClient;
|
|
107
|
+
}(client_js_1.BaseClient));
|
|
108
|
+
exports.PortalClient = PortalClient;
|
|
109
|
+
//# sourceMappingURL=portal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"portal.js","sourceRoot":"","sources":["../../../clients/portal.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,yCAAyE;AAIzE;IAAkC,gCAAU;IAC1C,sBAAY,MAAuB;QACjC,OAAA,MAAK,YAAC,MAAM,CAAC,SAAA;IACf,CAAC;IAED;;;OAGG;IACU,kCAAW,GAAxB,UACE,KAIC,EACD,OAAwB;;;;4BAEjB,qBAAM,IAAI,CAAC,OAAO,CAAC;4BACxB,IAAI,EAAE,uBAAuB;4BAC7B,MAAM,EAAE,MAAM;4BACd,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;6BACnC;4BACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;4BAC3B,OAAO,SAAA;yBACR,CAAC,EAAA;4BARF,sBAAO,SAQL,EAAA;;;;KACH;IAED;;;OAGG;IACU,uCAAgB,GAA7B;4DACE,UAAqC,EACrC,OAAwB;YADxB,2BAAA,EAAA,eAAqC;;;4BAG9B,qBAAM,IAAI,CAAC,OAAO,CAAC;4BACxB,IAAI,EAAE,kCAAkC;4BACxC,MAAM,EAAE,MAAM;4BACd,OAAO,EAAE;gCACP,cAAc,EAAE,kBAAkB;6BACnC;4BACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC;4BAChC,OAAO,SAAA;yBACR,CAAC,EAAA;4BARF,sBAAO,SAQL,EAAA;;;;KACH;IACH,mBAAC;AAAD,CAAC,AA9CD,CAAkC,sBAAU,GA8C3C;AA9CY,oCAAY"}
|