@thescaffold/jsx-flags 0.0.10

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.
@@ -0,0 +1,752 @@
1
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
2
+ try {
3
+ var i = n[a](c),
4
+ u = i.value;
5
+ } catch (n) {
6
+ return void e(n);
7
+ }
8
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
9
+ }
10
+ function _asyncToGenerator(n) {
11
+ return function () {
12
+ var t = this,
13
+ e = arguments;
14
+ return new Promise(function (r, o) {
15
+ var a = n.apply(t, e);
16
+ function _next(n) {
17
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
18
+ }
19
+ function _throw(n) {
20
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
21
+ }
22
+ _next(void 0);
23
+ });
24
+ };
25
+ }
26
+ function _extends() {
27
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
28
+ for (var e = 1; e < arguments.length; e++) {
29
+ var t = arguments[e];
30
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
31
+ }
32
+ return n;
33
+ }, _extends.apply(null, arguments);
34
+ }
35
+ function _regeneratorRuntime() {
36
+ _regeneratorRuntime = function () {
37
+ return e;
38
+ };
39
+ var t,
40
+ e = {},
41
+ r = Object.prototype,
42
+ n = r.hasOwnProperty,
43
+ o = Object.defineProperty || function (t, e, r) {
44
+ t[e] = r.value;
45
+ },
46
+ i = "function" == typeof Symbol ? Symbol : {},
47
+ a = i.iterator || "@@iterator",
48
+ c = i.asyncIterator || "@@asyncIterator",
49
+ u = i.toStringTag || "@@toStringTag";
50
+ function define(t, e, r) {
51
+ return Object.defineProperty(t, e, {
52
+ value: r,
53
+ enumerable: !0,
54
+ configurable: !0,
55
+ writable: !0
56
+ }), t[e];
57
+ }
58
+ try {
59
+ define({}, "");
60
+ } catch (t) {
61
+ define = function (t, e, r) {
62
+ return t[e] = r;
63
+ };
64
+ }
65
+ function wrap(t, e, r, n) {
66
+ var i = e && e.prototype instanceof Generator ? e : Generator,
67
+ a = Object.create(i.prototype),
68
+ c = new Context(n || []);
69
+ return o(a, "_invoke", {
70
+ value: makeInvokeMethod(t, r, c)
71
+ }), a;
72
+ }
73
+ function tryCatch(t, e, r) {
74
+ try {
75
+ return {
76
+ type: "normal",
77
+ arg: t.call(e, r)
78
+ };
79
+ } catch (t) {
80
+ return {
81
+ type: "throw",
82
+ arg: t
83
+ };
84
+ }
85
+ }
86
+ e.wrap = wrap;
87
+ var h = "suspendedStart",
88
+ l = "suspendedYield",
89
+ f = "executing",
90
+ s = "completed",
91
+ y = {};
92
+ function Generator() {}
93
+ function GeneratorFunction() {}
94
+ function GeneratorFunctionPrototype() {}
95
+ var p = {};
96
+ define(p, a, function () {
97
+ return this;
98
+ });
99
+ var d = Object.getPrototypeOf,
100
+ v = d && d(d(values([])));
101
+ v && v !== r && n.call(v, a) && (p = v);
102
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
103
+ function defineIteratorMethods(t) {
104
+ ["next", "throw", "return"].forEach(function (e) {
105
+ define(t, e, function (t) {
106
+ return this._invoke(e, t);
107
+ });
108
+ });
109
+ }
110
+ function AsyncIterator(t, e) {
111
+ function invoke(r, o, i, a) {
112
+ var c = tryCatch(t[r], t, o);
113
+ if ("throw" !== c.type) {
114
+ var u = c.arg,
115
+ h = u.value;
116
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
117
+ invoke("next", t, i, a);
118
+ }, function (t) {
119
+ invoke("throw", t, i, a);
120
+ }) : e.resolve(h).then(function (t) {
121
+ u.value = t, i(u);
122
+ }, function (t) {
123
+ return invoke("throw", t, i, a);
124
+ });
125
+ }
126
+ a(c.arg);
127
+ }
128
+ var r;
129
+ o(this, "_invoke", {
130
+ value: function (t, n) {
131
+ function callInvokeWithMethodAndArg() {
132
+ return new e(function (e, r) {
133
+ invoke(t, n, e, r);
134
+ });
135
+ }
136
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
137
+ }
138
+ });
139
+ }
140
+ function makeInvokeMethod(e, r, n) {
141
+ var o = h;
142
+ return function (i, a) {
143
+ if (o === f) throw Error("Generator is already running");
144
+ if (o === s) {
145
+ if ("throw" === i) throw a;
146
+ return {
147
+ value: t,
148
+ done: !0
149
+ };
150
+ }
151
+ for (n.method = i, n.arg = a;;) {
152
+ var c = n.delegate;
153
+ if (c) {
154
+ var u = maybeInvokeDelegate(c, n);
155
+ if (u) {
156
+ if (u === y) continue;
157
+ return u;
158
+ }
159
+ }
160
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
161
+ if (o === h) throw o = s, n.arg;
162
+ n.dispatchException(n.arg);
163
+ } else "return" === n.method && n.abrupt("return", n.arg);
164
+ o = f;
165
+ var p = tryCatch(e, r, n);
166
+ if ("normal" === p.type) {
167
+ if (o = n.done ? s : l, p.arg === y) continue;
168
+ return {
169
+ value: p.arg,
170
+ done: n.done
171
+ };
172
+ }
173
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
174
+ }
175
+ };
176
+ }
177
+ function maybeInvokeDelegate(e, r) {
178
+ var n = r.method,
179
+ o = e.iterator[n];
180
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
181
+ var i = tryCatch(o, e.iterator, r.arg);
182
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
183
+ var a = i.arg;
184
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
185
+ }
186
+ function pushTryEntry(t) {
187
+ var e = {
188
+ tryLoc: t[0]
189
+ };
190
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
191
+ }
192
+ function resetTryEntry(t) {
193
+ var e = t.completion || {};
194
+ e.type = "normal", delete e.arg, t.completion = e;
195
+ }
196
+ function Context(t) {
197
+ this.tryEntries = [{
198
+ tryLoc: "root"
199
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
200
+ }
201
+ function values(e) {
202
+ if (e || "" === e) {
203
+ var r = e[a];
204
+ if (r) return r.call(e);
205
+ if ("function" == typeof e.next) return e;
206
+ if (!isNaN(e.length)) {
207
+ var o = -1,
208
+ i = function next() {
209
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
210
+ return next.value = t, next.done = !0, next;
211
+ };
212
+ return i.next = i;
213
+ }
214
+ }
215
+ throw new TypeError(typeof e + " is not iterable");
216
+ }
217
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
218
+ value: GeneratorFunctionPrototype,
219
+ configurable: !0
220
+ }), o(GeneratorFunctionPrototype, "constructor", {
221
+ value: GeneratorFunction,
222
+ configurable: !0
223
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
224
+ var e = "function" == typeof t && t.constructor;
225
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
226
+ }, e.mark = function (t) {
227
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
228
+ }, e.awrap = function (t) {
229
+ return {
230
+ __await: t
231
+ };
232
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
233
+ return this;
234
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
235
+ void 0 === i && (i = Promise);
236
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
237
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
238
+ return t.done ? t.value : a.next();
239
+ });
240
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
241
+ return this;
242
+ }), define(g, "toString", function () {
243
+ return "[object Generator]";
244
+ }), e.keys = function (t) {
245
+ var e = Object(t),
246
+ r = [];
247
+ for (var n in e) r.push(n);
248
+ return r.reverse(), function next() {
249
+ for (; r.length;) {
250
+ var t = r.pop();
251
+ if (t in e) return next.value = t, next.done = !1, next;
252
+ }
253
+ return next.done = !0, next;
254
+ };
255
+ }, e.values = values, Context.prototype = {
256
+ constructor: Context,
257
+ reset: function (e) {
258
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
259
+ },
260
+ stop: function () {
261
+ this.done = !0;
262
+ var t = this.tryEntries[0].completion;
263
+ if ("throw" === t.type) throw t.arg;
264
+ return this.rval;
265
+ },
266
+ dispatchException: function (e) {
267
+ if (this.done) throw e;
268
+ var r = this;
269
+ function handle(n, o) {
270
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
271
+ }
272
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
273
+ var i = this.tryEntries[o],
274
+ a = i.completion;
275
+ if ("root" === i.tryLoc) return handle("end");
276
+ if (i.tryLoc <= this.prev) {
277
+ var c = n.call(i, "catchLoc"),
278
+ u = n.call(i, "finallyLoc");
279
+ if (c && u) {
280
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
281
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
282
+ } else if (c) {
283
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
284
+ } else {
285
+ if (!u) throw Error("try statement without catch or finally");
286
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
287
+ }
288
+ }
289
+ }
290
+ },
291
+ abrupt: function (t, e) {
292
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
293
+ var o = this.tryEntries[r];
294
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
295
+ var i = o;
296
+ break;
297
+ }
298
+ }
299
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
300
+ var a = i ? i.completion : {};
301
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
302
+ },
303
+ complete: function (t, e) {
304
+ if ("throw" === t.type) throw t.arg;
305
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
306
+ },
307
+ finish: function (t) {
308
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
309
+ var r = this.tryEntries[e];
310
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
311
+ }
312
+ },
313
+ catch: function (t) {
314
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
315
+ var r = this.tryEntries[e];
316
+ if (r.tryLoc === t) {
317
+ var n = r.completion;
318
+ if ("throw" === n.type) {
319
+ var o = n.arg;
320
+ resetTryEntry(r);
321
+ }
322
+ return o;
323
+ }
324
+ }
325
+ throw Error("illegal catch attempt");
326
+ },
327
+ delegateYield: function (e, r, n) {
328
+ return this.delegate = {
329
+ iterator: values(e),
330
+ resultName: r,
331
+ nextLoc: n
332
+ }, "next" === this.method && (this.arg = t), y;
333
+ }
334
+ }, e;
335
+ }
336
+
337
+ var config = {
338
+ server: '',
339
+ credential: '',
340
+ sourceId: ''
341
+ };
342
+ var getConfig = function getConfig() {
343
+ return config;
344
+ };
345
+
346
+ var isObject = function isObject(x) {
347
+ return typeof x === 'object' && !Array.isArray(x) && x !== null;
348
+ };
349
+ var _recursiveMerge = function recursiveMerge(target) {
350
+ for (var _len = arguments.length, sources = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
351
+ sources[_key - 1] = arguments[_key];
352
+ }
353
+ for (var _i = 0, _sources = sources; _i < _sources.length; _i++) {
354
+ var source = _sources[_i];
355
+ for (var key in source) {
356
+ if (isObject(source[key])) {
357
+ if (!target[key]) {
358
+ target[key] = {};
359
+ }
360
+ _recursiveMerge(target[key], source[key]);
361
+ } else {
362
+ target[key] = source[key];
363
+ }
364
+ }
365
+ }
366
+ return target;
367
+ };
368
+ var managedLog = function managedLog(title, message, config) {
369
+ var _config$logs;
370
+ for (var _len2 = arguments.length, types = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
371
+ types[_key2 - 3] = arguments[_key2];
372
+ }
373
+ (_config$logs = config.logs) == null || _config$logs.forEach(function (allowed) {
374
+ if (types.includes(allowed)) {
375
+ if (config.debug === true) {
376
+ console[allowed](title, message);
377
+ } else {
378
+ console[allowed](title);
379
+ }
380
+ }
381
+ });
382
+ };
383
+ var isFunction = function isFunction(value) {
384
+ return typeof value === 'function';
385
+ };
386
+ var isString = function isString(value) {
387
+ return typeof value === 'string';
388
+ };
389
+ var _arrayDepth = function arrayDepth(value) {
390
+ if (!Array.isArray(value)) return 0;
391
+ return 1 + Math.max.apply(Math, [0].concat(value.map(_arrayDepth)));
392
+ };
393
+
394
+ var CategoryType;
395
+ (function (CategoryType) {
396
+ CategoryType["Form"] = "form";
397
+ CategoryType["File"] = "file";
398
+ CategoryType["Webhook"] = "webhook";
399
+ CategoryType["Job"] = "job";
400
+ CategoryType["Event"] = "event";
401
+ CategoryType["Log"] = "log";
402
+ CategoryType["Motion"] = "motion";
403
+ CategoryType["Message"] = "message";
404
+ CategoryType["Others"] = "others";
405
+ })(CategoryType || (CategoryType = {}));
406
+ var LogType;
407
+ (function (LogType) {
408
+ LogType["INFO"] = "info";
409
+ LogType["WARN"] = "warn";
410
+ LogType["ERROR"] = "error";
411
+ })(LogType || (LogType = {}));
412
+
413
+ var axios = /*#__PURE__*/require('axios');
414
+ var raw = axios;
415
+ var request = /*#__PURE__*/function () {
416
+ var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(method, url, body, queries, headers) {
417
+ var config, _request, response, _response;
418
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
419
+ while (1) switch (_context.prev = _context.next) {
420
+ case 0:
421
+ config = getConfig();
422
+ _context.prev = 1;
423
+ _request = {
424
+ method: method,
425
+ url: url,
426
+ headers: _extends({
427
+ 'content-type': 'application/json',
428
+ authorization: "bearer " + config.credential
429
+ }, headers),
430
+ data: body,
431
+ params: queries
432
+ };
433
+ managedLog('BATCH REQUEST', _request, config, LogType.INFO);
434
+ _context.next = 6;
435
+ return raw.request(_request, {
436
+ validateStatus: function validateStatus(status) {
437
+ return status < 500;
438
+ }
439
+ });
440
+ case 6:
441
+ response = _context.sent;
442
+ managedLog('BATCH RESPONSE', response.data, config, LogType.INFO);
443
+ return _context.abrupt("return", [true, response.status, response.statusText, null, response.data]);
444
+ case 11:
445
+ _context.prev = 11;
446
+ _context.t0 = _context["catch"](1);
447
+ managedLog('BATCH ERROR', _context.t0, config, LogType.ERROR);
448
+ if (!_context.t0.response) {
449
+ _context.next = 19;
450
+ break;
451
+ }
452
+ // The request was made and the server responded with a status code
453
+ // that falls out of the range of 2xx
454
+ _response = _context.t0.response;
455
+ return _context.abrupt("return", [false, _response.status, _response.statusText, null, _response.data]);
456
+ case 19:
457
+ if (!_context.t0.request) {
458
+ _context.next = 23;
459
+ break;
460
+ }
461
+ return _context.abrupt("return", [false, 503, 'Service is Down', 'Unable to get any response from the ', _context.t0]);
462
+ case 23:
463
+ return _context.abrupt("return", [false, 403, 'Service is Down', 'Could not make the request, check and try again.', _context.t0]);
464
+ case 24:
465
+ case "end":
466
+ return _context.stop();
467
+ }
468
+ }, _callee, null, [[1, 11]]);
469
+ }));
470
+ return function request(_x, _x2, _x3, _x4, _x5) {
471
+ return _ref.apply(this, arguments);
472
+ };
473
+ }();
474
+ var requestWithError = /*#__PURE__*/function () {
475
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(method, url, body, queries, headers) {
476
+ var _yield$request, status, httpStatus, title, message, response, _response$message;
477
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
478
+ while (1) switch (_context2.prev = _context2.next) {
479
+ case 0:
480
+ _context2.next = 2;
481
+ return request(method, url, body, queries, headers);
482
+ case 2:
483
+ _yield$request = _context2.sent;
484
+ status = _yield$request[0];
485
+ httpStatus = _yield$request[1];
486
+ title = _yield$request[2];
487
+ message = _yield$request[3];
488
+ response = _yield$request[4];
489
+ if (!(status !== true)) {
490
+ _context2.next = 10;
491
+ break;
492
+ }
493
+ throw new Error(httpStatus + ": " + title + " " + ((_response$message = response == null ? void 0 : response.message) != null ? _response$message : message));
494
+ case 10:
495
+ return _context2.abrupt("return", response);
496
+ case 11:
497
+ case "end":
498
+ return _context2.stop();
499
+ }
500
+ }, _callee2);
501
+ }));
502
+ return function requestWithError(_x6, _x7, _x8, _x9, _x10) {
503
+ return _ref2.apply(this, arguments);
504
+ };
505
+ }();
506
+ var post = function post(url, body, queries, headers) {
507
+ return request('POST', url, body, queries, headers);
508
+ };
509
+ var get = function get(url, queries, headers) {
510
+ return request('GET', url, null, queries, headers);
511
+ };
512
+ var patch = function patch(url, body, queries, headers) {
513
+ return request('PATCH', url, body, queries, headers);
514
+ };
515
+ var put = function put(url, body, queries, headers) {
516
+ return request('PUT', url, body, queries, headers);
517
+ };
518
+ var remove = function remove(url, body, queries, headers) {
519
+ return request('DELETE', url, body, queries, headers);
520
+ };
521
+
522
+ var register = /*#__PURE__*/function () {
523
+ var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(flags, environmentTypeName) {
524
+ var config, _yield$post, status, httpStatus, title, message, response;
525
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
526
+ while (1) switch (_context.prev = _context.next) {
527
+ case 0:
528
+ if (environmentTypeName === void 0) {
529
+ environmentTypeName = 'Javascript';
530
+ }
531
+ config = getConfig();
532
+ _context.next = 4;
533
+ return post(config.server + "/apps/flags/register", {
534
+ environmentType: {
535
+ name: environmentTypeName
536
+ },
537
+ environment: {
538
+ name: config.sourceId
539
+ },
540
+ flags: flags
541
+ });
542
+ case 4:
543
+ _yield$post = _context.sent;
544
+ status = _yield$post[0];
545
+ httpStatus = _yield$post[1];
546
+ title = _yield$post[2];
547
+ message = _yield$post[3];
548
+ response = _yield$post[4];
549
+ if (!(status !== true)) {
550
+ _context.next = 13;
551
+ break;
552
+ }
553
+ console.error('REGISTER ERROR', title, message, httpStatus);
554
+ return _context.abrupt("return", null);
555
+ case 13:
556
+ return _context.abrupt("return", response == null ? void 0 : response.data);
557
+ case 14:
558
+ case "end":
559
+ return _context.stop();
560
+ }
561
+ }, _callee);
562
+ }));
563
+ return function register(_x, _x2) {
564
+ return _ref.apply(this, arguments);
565
+ };
566
+ }();
567
+ var log = /*#__PURE__*/function () {
568
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(name, limit, level, userId, clientId, workspaceId) {
569
+ var config, _yield$post2, status, httpStatus, title, message, response;
570
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
571
+ while (1) switch (_context2.prev = _context2.next) {
572
+ case 0:
573
+ config = getConfig();
574
+ _context2.next = 3;
575
+ return post(config.server + "/apps/flags/log", {
576
+ environment: {
577
+ name: config.sourceId
578
+ },
579
+ name: name,
580
+ limit: limit,
581
+ level: level,
582
+ userId: userId,
583
+ clientId: clientId,
584
+ workspaceId: workspaceId
585
+ });
586
+ case 3:
587
+ _yield$post2 = _context2.sent;
588
+ status = _yield$post2[0];
589
+ httpStatus = _yield$post2[1];
590
+ title = _yield$post2[2];
591
+ message = _yield$post2[3];
592
+ response = _yield$post2[4];
593
+ if (!(status !== true)) {
594
+ _context2.next = 12;
595
+ break;
596
+ }
597
+ console.error('STATUS ERROR', title, message, httpStatus);
598
+ return _context2.abrupt("return", null);
599
+ case 12:
600
+ return _context2.abrupt("return", response == null ? void 0 : response.data);
601
+ case 13:
602
+ case "end":
603
+ return _context2.stop();
604
+ }
605
+ }, _callee2);
606
+ }));
607
+ return function log(_x3, _x4, _x5, _x6, _x7, _x8) {
608
+ return _ref2.apply(this, arguments);
609
+ };
610
+ }();
611
+ var status = /*#__PURE__*/function () {
612
+ var _ref3 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(names, level, userId, clientId, workspaceId) {
613
+ var config, _yield$post3, status, httpStatus, title, message, response;
614
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
615
+ while (1) switch (_context3.prev = _context3.next) {
616
+ case 0:
617
+ config = getConfig();
618
+ if (!isString(names)) {
619
+ _context3.next = 5;
620
+ break;
621
+ }
622
+ names = [[names]];
623
+ _context3.next = 14;
624
+ break;
625
+ case 5:
626
+ if (!(_arrayDepth(names) === 1)) {
627
+ _context3.next = 9;
628
+ break;
629
+ }
630
+ names = [names];
631
+ _context3.next = 14;
632
+ break;
633
+ case 9:
634
+ if (!(_arrayDepth(names) === 2)) {
635
+ _context3.next = 13;
636
+ break;
637
+ }
638
+ names = names;
639
+ _context3.next = 14;
640
+ break;
641
+ case 13:
642
+ return _context3.abrupt("return", false);
643
+ case 14:
644
+ _context3.next = 16;
645
+ return post(config.server + "/apps/flags/status", {
646
+ environment: {
647
+ name: config.sourceId
648
+ },
649
+ names: names,
650
+ level: level,
651
+ userId: userId,
652
+ clientId: clientId,
653
+ workspaceId: workspaceId
654
+ });
655
+ case 16:
656
+ _yield$post3 = _context3.sent;
657
+ status = _yield$post3[0];
658
+ httpStatus = _yield$post3[1];
659
+ title = _yield$post3[2];
660
+ message = _yield$post3[3];
661
+ response = _yield$post3[4];
662
+ if (!(status !== true)) {
663
+ _context3.next = 25;
664
+ break;
665
+ }
666
+ console.error('STATUS ERROR', title, message, httpStatus);
667
+ return _context3.abrupt("return", null);
668
+ case 25:
669
+ return _context3.abrupt("return", response == null ? void 0 : response.data);
670
+ case 26:
671
+ case "end":
672
+ return _context3.stop();
673
+ }
674
+ }, _callee3);
675
+ }));
676
+ return function status(_x9, _x10, _x11, _x12, _x13) {
677
+ return _ref3.apply(this, arguments);
678
+ };
679
+ }();
680
+ var limit = /*#__PURE__*/function () {
681
+ var _ref4 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee4(name, level, userId, clientId, workspaceId) {
682
+ var config, _yield$post4, status, httpStatus, title, message, response;
683
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
684
+ while (1) switch (_context4.prev = _context4.next) {
685
+ case 0:
686
+ config = getConfig();
687
+ _context4.next = 3;
688
+ return post(config.server + "/apps/flags/limit", {
689
+ environment: {
690
+ name: config.sourceId
691
+ },
692
+ name: name,
693
+ level: level,
694
+ userId: userId,
695
+ clientId: clientId,
696
+ workspaceId: workspaceId
697
+ });
698
+ case 3:
699
+ _yield$post4 = _context4.sent;
700
+ status = _yield$post4[0];
701
+ httpStatus = _yield$post4[1];
702
+ title = _yield$post4[2];
703
+ message = _yield$post4[3];
704
+ response = _yield$post4[4];
705
+ if (!(status !== true)) {
706
+ _context4.next = 12;
707
+ break;
708
+ }
709
+ console.error('STATUS ERROR', title, message, httpStatus);
710
+ return _context4.abrupt("return", null);
711
+ case 12:
712
+ return _context4.abrupt("return", response == null ? void 0 : response.data);
713
+ case 13:
714
+ case "end":
715
+ return _context4.stop();
716
+ }
717
+ }, _callee4);
718
+ }));
719
+ return function limit(_x14, _x15, _x16, _x17, _x18) {
720
+ return _ref4.apply(this, arguments);
721
+ };
722
+ }();
723
+
724
+ var init = function init(c) {
725
+ var cf = isFunction(c) ? c() : c;
726
+ var config = _recursiveMerge(getConfig(), cf);
727
+ if (!config.server || config.server == '') {
728
+ managedLog('INIT CONFIG VALIDATION', config, config, LogType.ERROR);
729
+ throw new Error('Invalid configuration - server not defined');
730
+ }
731
+ if (!config.sourceId || config.sourceId == '') {
732
+ managedLog('INIT CONFIG VALIDATION', config, config, LogType.ERROR);
733
+ throw new Error('Invalid configuration - sourceId not defined');
734
+ }
735
+ managedLog('INIT ACTIVE CONFIG', config, config, LogType.INFO);
736
+ // register SDK as source
737
+ // push({
738
+ // category: CategoryType.Event,
739
+ // payload: {
740
+ // id: sourceId,
741
+ // category: CategoryType.Event,
742
+ // key: 'sdk',
743
+ // typeKey: 'javascript',
744
+ // name: 'Flags SDK Javascript',
745
+ // desc: null,
746
+ // },
747
+ // type: 'apps.polylog.source.register',
748
+ // });
749
+ };
750
+
751
+ export { CategoryType, LogType, get, init, limit, log, patch, post, put, raw, register, remove, request, requestWithError, status };
752
+ //# sourceMappingURL=jsx-flags.esm.js.map