bruce-models 2.5.1 → 2.5.3

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.
@@ -3122,45 +3122,24 @@
3122
3122
  // Need to see if our api is generally good at setting content-type headers.
3123
3123
  // Make it less specific to CSV.
3124
3124
  function parseResult(data) {
3125
+ var _a, _b;
3125
3126
  return __awaiter(this, void 0, void 0, function* () {
3126
- if (data.status == 200) {
3127
- let type = data.headers.get("Content-Type");
3128
- if (type) {
3129
- type = type.trim().toLowerCase();
3130
- }
3131
- let encoding = "";
3132
- const charset = type ? type.split(";").find((x) => x.startsWith("charset=")) : "";
3133
- if (charset && charset.includes("=")) {
3134
- encoding = charset.split("=")[1];
3135
- encoding = encoding.toLowerCase();
3136
- }
3137
- // Our API has a very specific utf-16 encoding.
3138
- if (encoding == "utf-16") {
3139
- encoding = exports.Api.EEncoding.UTF16;
3140
- }
3141
- if (!encoding || encoding == "utf-8") {
3142
- const text = yield data.text();
3143
- if (!text || !text.trim()) {
3144
- return null;
3145
- }
3146
- if (type && type.includes("text/csv")) {
3147
- return text;
3148
- }
3149
- return JSON.parse(text);
3150
- }
3151
- else {
3152
- const buffer = yield data.arrayBuffer();
3153
- const text = new TextDecoder(encoding).decode(buffer);
3154
- if (type && type.includes("text/csv")) {
3155
- return text;
3156
- }
3157
- return JSON.parse(text);
3158
- }
3159
- }
3160
- else {
3127
+ if (data.status !== 200) {
3161
3128
  const error = yield data.json();
3162
3129
  throw (error);
3163
3130
  }
3131
+ let type = (_a = data.headers.get("Content-Type")) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
3132
+ let encoding = (_b = type === null || type === void 0 ? void 0 : type.split(";").find((x) => x.startsWith("charset="))) === null || _b === void 0 ? void 0 : _b.split("=")[1].toLowerCase();
3133
+ if (encoding === "utf-16") {
3134
+ encoding = exports.Api.EEncoding.UTF16;
3135
+ }
3136
+ const text = yield (encoding && encoding !== "utf-8"
3137
+ ? new TextDecoder(encoding).decode(yield data.arrayBuffer())
3138
+ : data.text());
3139
+ if (!(text === null || text === void 0 ? void 0 : text.trim())) {
3140
+ return null;
3141
+ }
3142
+ return (type === null || type === void 0 ? void 0 : type.includes("text/csv")) ? text : JSON.parse(text);
3164
3143
  });
3165
3144
  }
3166
3145
  /**
@@ -11360,7 +11339,7 @@
11360
11339
  }
11361
11340
  Plugin.GetList = GetList;
11362
11341
  function GetLoadUrl(params) {
11363
- let { api, pluginId, req, cacheKey } = params;
11342
+ let { api, pluginId, cacheKey } = params;
11364
11343
  if (!api) {
11365
11344
  api = exports.ENVIRONMENT.Api().GetBruceApi();
11366
11345
  }
@@ -11372,8 +11351,92 @@
11372
11351
  };
11373
11352
  }
11374
11353
  Plugin.GetLoadUrl = GetLoadUrl;
11354
+ /**
11355
+ * Returns a run function to call that'll load a plugin within your provided container element.
11356
+ * The run function will return a dispose function to call to remove the plugin.
11357
+ * @param params
11358
+ * @returns
11359
+ */
11360
+ function GetRunFunction(params) {
11361
+ return __awaiter(this, void 0, void 0, function* () {
11362
+ let { containerId, container, pluginParams, pluginId, plugin, api } = params;
11363
+ if (!containerId && container) {
11364
+ containerId = container.id;
11365
+ if (!containerId) {
11366
+ containerId = exports.ObjectUtils.UId();
11367
+ container.id = containerId;
11368
+ }
11369
+ }
11370
+ if (!plugin && pluginId) {
11371
+ plugin = (yield Plugin.Get({
11372
+ pluginId,
11373
+ api
11374
+ })).plugin;
11375
+ }
11376
+ const { indexFileUrl } = GetLoadUrl({
11377
+ api,
11378
+ pluginId,
11379
+ cacheKey: plugin.Version
11380
+ });
11381
+ let fileContent = yield fetch(indexFileUrl).then((res) => res.text());
11382
+ const start = fileContent.indexOf("{");
11383
+ const end = fileContent.lastIndexOf("}");
11384
+ fileContent = fileContent.substring(start + 1, end);
11385
+ const paramsId = exports.ObjectUtils.UId();
11386
+ window[paramsId] = pluginParams ? pluginParams : {};
11387
+ const disposeId = exports.ObjectUtils.UId();
11388
+ let script = `
11389
+ function run() {
11390
+ ${fileContent}
11391
+
11392
+ const paramsId = "${paramsId}";
11393
+ const containerId = "${container.id}";
11394
+ let container;
11395
+ if (containerId) {
11396
+ container = document.getElementById("${container.id}");
11397
+ }
11398
+ {TEMPLATE_CODE}
11399
+ const params = window["${paramsId}"];
11400
+
11401
+ window["${disposeId}"] = Run({
11402
+ container,
11403
+ pluginParams: params
11404
+ });
11405
+ }
11406
+ run();
11407
+ `;
11408
+ if (script.includes("var template")) {
11409
+ script = script.replace("{TEMPLATE_CODE}", `
11410
+ if (container && template) {
11411
+ container.innerHTML = template;
11412
+ }
11413
+ `);
11414
+ }
11415
+ else {
11416
+ script = script.replace("{TEMPLATE_CODE}", "");
11417
+ }
11418
+ return {
11419
+ run: () => {
11420
+ const eval2 = eval;
11421
+ eval2(script);
11422
+ // Ensure a function is returned, even if the plugin is not configured properly to return one.
11423
+ if (!window[disposeId] || typeof window[disposeId] !== "function") {
11424
+ window[disposeId] = () => {
11425
+ console.warn("Plugin called to be disposed but no dispose function was found.");
11426
+ };
11427
+ }
11428
+ const callDispose = window[disposeId];
11429
+ return () => callDispose();
11430
+ }
11431
+ };
11432
+ });
11433
+ }
11434
+ Plugin.GetRunFunction = GetRunFunction;
11375
11435
  })(exports.Plugin || (exports.Plugin = {}));
11376
11436
 
11437
+ const VERSION$1 = "2.5.2";
11438
+
11439
+ exports.VERSION = VERSION$1;
11377
11440
  exports.AbstractApi = AbstractApi;
11378
11441
  exports.ApiGetters = ApiGetters;
11379
11442
  exports.BruceEvent = BruceEvent;