@interopio/utils 1.1.3 → 1.2.1

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.
@@ -1,5 +1,6 @@
1
1
  import { Decoder } from "decoder-validate";
2
2
  import { FDC3DefinitionV1, FDC3DefinitionV2 } from "../fdc3/types";
3
+ import { INTENTS_ERRORS } from "../errors/errors";
3
4
  interface FDC3Decoders {
4
5
  allDefinitionsDecoder: Decoder<FDC3DefinitionV1 | FDC3DefinitionV2>;
5
6
  v1DefinitionDecoder: Decoder<FDC3DefinitionV1>;
@@ -13,4 +14,7 @@ export interface Decoders {
13
14
  fdc3: FDC3Decoders;
14
15
  common: CommonDecoders;
15
16
  }
17
+ export interface Errors {
18
+ intents: typeof INTENTS_ERRORS;
19
+ }
16
20
  export {};
@@ -0,0 +1,13 @@
1
+ export declare enum INTENTS_ERRORS {
2
+ USER_CANCELLED = "User Closed Intents Resolver UI without choosing a handler",
3
+ CALLER_NOT_DEFINED = "Caller Id is not defined",
4
+ TIMEOUT_HIT = "Timeout hit",
5
+ INTENT_NOT_FOUND = "Cannot find Intent",
6
+ HANDLER_NOT_FOUND = "Cannot find Intent Handler",
7
+ TARGET_INSTANCE_UNAVAILABLE = "Cannot start Target Instance",
8
+ INTENT_DELIVERY_FAILED = "Target Instance did not add a listener",
9
+ RESOLVER_UNAVAILABLE = "Intents Resolver UI unavailable",
10
+ RESOLVER_TIMEOUT = "User did not choose a handler",
11
+ INVALID_RESOLVER_RESPONSE = "Intents Resolver UI returned invalid response",
12
+ INTENT_HANDLER_REJECTION = "Intent Handler function processing the raised intent threw an error or rejected the promise it returned"
13
+ }
@@ -157,6 +157,7 @@ export interface IOConnectBrowserBaseAppData {
157
157
  export interface IsFdc3DefinitionResult {
158
158
  isFdc3: boolean;
159
159
  version?: SupportedVersions;
160
+ reason?: string;
160
161
  }
161
162
  export interface Fdc3Intent {
162
163
  contexts: string[];
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import { Decoders } from "./decoders/types";
1
+ import { Decoders, Errors } from "./decoders/types";
2
2
  import { FDC3 } from "./fdc3/types";
3
3
  export declare const fdc3: FDC3;
4
4
  export declare const decoders: Decoders;
5
+ export declare const errors: Errors;
@@ -1,8 +1,10 @@
1
1
  import { FDC3 } from "../fdc3/types";
2
- import { Decoders } from "../decoders/types";
2
+ import { Decoders, Errors } from "../decoders/types";
3
3
  export declare class IoC {
4
4
  private _fdc3;
5
5
  private _decoders;
6
+ private _errors;
6
7
  get fdc3(): FDC3;
7
8
  get decoders(): Decoders;
9
+ get errors(): Errors;
8
10
  }
@@ -3,4 +3,9 @@ import { FDC3 } from "../fdc3/types";
3
3
  export interface Utils {
4
4
  fdc3: FDC3;
5
5
  decoders: Decoders;
6
+ errors: {
7
+ intents: {
8
+ [key: string]: string;
9
+ };
10
+ };
6
11
  }
package/dist/utils.es.js CHANGED
@@ -919,15 +919,13 @@ const parseDecoderErrorToStringMessage = (error) => {
919
919
  };
920
920
 
921
921
  class FDC3Service {
922
- constructor() {
923
- this.fdc3ToDesktopDefinitionType = {
924
- web: "window",
925
- native: "exe",
926
- citrix: "citrix",
927
- onlineNative: "clickonce",
928
- other: "window"
929
- };
930
- }
922
+ fdc3ToDesktopDefinitionType = {
923
+ web: "window",
924
+ native: "exe",
925
+ citrix: "citrix",
926
+ onlineNative: "clickonce",
927
+ other: "window"
928
+ };
931
929
  toApi() {
932
930
  return {
933
931
  isFdc3Definition: this.isFdc3Definition.bind(this),
@@ -938,7 +936,7 @@ class FDC3Service {
938
936
  isFdc3Definition(definition) {
939
937
  const decodeRes = allDefinitionsDecoder.run(definition);
940
938
  if (!decodeRes.ok) {
941
- return { isFdc3: false };
939
+ return { isFdc3: false, reason: parseDecoderErrorToStringMessage(decodeRes.error) };
942
940
  }
943
941
  if (definition.appId && definition.details) {
944
942
  return { isFdc3: true, version: "2.0" };
@@ -946,10 +944,9 @@ class FDC3Service {
946
944
  if (definition.manifest) {
947
945
  return { isFdc3: true, version: "1.2" };
948
946
  }
949
- return { isFdc3: false };
947
+ return { isFdc3: false, reason: "The passed definition is not FDC3" };
950
948
  }
951
949
  parseToBrowserBaseAppData(definition) {
952
- var _a;
953
950
  const { isFdc3, version } = this.isFdc3Definition(definition);
954
951
  if (!isFdc3) {
955
952
  throw new Error("The passed definition is not FDC3");
@@ -964,16 +961,20 @@ class FDC3Service {
964
961
  name: definition.appId,
965
962
  type: "window",
966
963
  createOptions,
967
- userProperties: Object.assign(Object.assign({}, userProperties), { intents: version === "1.2"
964
+ userProperties: {
965
+ ...userProperties,
966
+ intents: version === "1.2"
968
967
  ? userProperties.intents
969
- : this.getIntentsFromV2AppDefinition(definition), details: createOptions }),
968
+ : this.getIntentsFromV2AppDefinition(definition),
969
+ details: createOptions
970
+ },
970
971
  title: definition.title,
971
972
  version: definition.version,
972
973
  icon: this.getIconFromDefinition(definition, version),
973
974
  caption: definition.description,
974
- fdc3: version === "2.0" ? Object.assign(Object.assign({}, definition), { definitionVersion: "2.0" }) : undefined,
975
+ fdc3: version === "2.0" ? { ...definition, definitionVersion: "2.0" } : undefined,
975
976
  };
976
- if ((_a = definition.hostManifests) === null || _a === void 0 ? void 0 : _a["Glue42"]) {
977
+ if (definition.hostManifests?.["Glue42"]) {
977
978
  const decodeRes = glue42HostManifestsBrowserDecoder.run(definition.hostManifests["Glue42"]);
978
979
  if (!decodeRes.ok) {
979
980
  throw new Error(`Invalid FDC3 ${version} definition. Error: ${parseDecoderErrorToStringMessage(decodeRes.error)}`);
@@ -986,7 +987,6 @@ class FDC3Service {
986
987
  return baseApplicationData;
987
988
  }
988
989
  parseToDesktopAppConfig(definition) {
989
- var _a, _b, _c;
990
990
  const { isFdc3, version } = this.isFdc3Definition(definition);
991
991
  if (!isFdc3) {
992
992
  throw new Error("The passed definition is not FDC3");
@@ -1007,7 +1007,7 @@ class FDC3Service {
1007
1007
  title: fdc3v1Definition.title,
1008
1008
  tooltip: fdc3v1Definition.tooltip,
1009
1009
  caption: fdc3v1Definition.description,
1010
- icon: (_a = fdc3v1Definition.icons) === null || _a === void 0 ? void 0 : _a[0].icon,
1010
+ icon: fdc3v1Definition.icons?.[0].icon,
1011
1011
  intents: fdc3v1Definition.intents,
1012
1012
  customProperties: {
1013
1013
  manifestType: fdc3v1Definition.manifestType,
@@ -1031,13 +1031,13 @@ class FDC3Service {
1031
1031
  caption: fdc3v2Definition.description,
1032
1032
  icon: this.getIconFromDefinition(fdc3v2Definition, "2.0"),
1033
1033
  intents: this.getIntentsFromV2AppDefinition(fdc3v2Definition),
1034
- fdc3: Object.assign(Object.assign({}, fdc3v2Definition), { definitionVersion: "2.0" })
1034
+ fdc3: { ...fdc3v2Definition, definitionVersion: "2.0" }
1035
1035
  };
1036
- if ((_b = fdc3v2Definition.hostManifests) === null || _b === void 0 ? void 0 : _b["Glue42"]) {
1036
+ if (fdc3v2Definition.hostManifests?.["Glue42"]) {
1037
1037
  if (typeof fdc3v2Definition.hostManifests["Glue42"] !== "object" || Array.isArray(fdc3v2Definition.hostManifests["Glue42"])) {
1038
1038
  throw new Error("Invalid 'hostManifests['Glue42]' key");
1039
1039
  }
1040
- desktopDefinition = this.mergeDesktopConfigWithGlueManifest(desktopDefinition, (_c = fdc3v2Definition.hostManifests) === null || _c === void 0 ? void 0 : _c["Glue42"]);
1040
+ desktopDefinition = this.mergeDesktopConfigWithGlueManifest(desktopDefinition, fdc3v2Definition.hostManifests?.["Glue42"]);
1041
1041
  }
1042
1042
  return desktopDefinition;
1043
1043
  }
@@ -1048,14 +1048,13 @@ class FDC3Service {
1048
1048
  return Object.fromEntries(Object.entries(definition).filter(([key]) => !connectBrowserAppProps.includes(key) && !fdc3v2AppProps.includes(key)));
1049
1049
  }
1050
1050
  getUrl(definition, version) {
1051
- var _a, _b;
1052
1051
  let url;
1053
1052
  if (version === "1.2") {
1054
1053
  const parsedManifest = JSON.parse(definition.manifest);
1055
- url = ((_a = parsedManifest.details) === null || _a === void 0 ? void 0 : _a.url) || parsedManifest.url;
1054
+ url = parsedManifest.details?.url || parsedManifest.url;
1056
1055
  }
1057
1056
  else {
1058
- url = (_b = definition.details) === null || _b === void 0 ? void 0 : _b.url;
1057
+ url = definition.details?.url;
1059
1058
  }
1060
1059
  if (!url || typeof url !== "string") {
1061
1060
  throw new Error(`Invalid FDC3 ${version} definition. Provide valid 'url' under '${version === "1.2" ? "manifest" : "details"}' key`);
@@ -1063,41 +1062,42 @@ class FDC3Service {
1063
1062
  return url;
1064
1063
  }
1065
1064
  getIntentsFromV2AppDefinition(definition) {
1066
- var _a, _b;
1067
- const fdc3Intents = (_b = (_a = definition.interop) === null || _a === void 0 ? void 0 : _a.intents) === null || _b === void 0 ? void 0 : _b.listensFor;
1065
+ const fdc3Intents = definition.interop?.intents?.listensFor;
1068
1066
  if (!fdc3Intents) {
1069
1067
  return;
1070
1068
  }
1071
1069
  const intents = Object.entries(fdc3Intents).map((fdc3Intent) => {
1072
1070
  const [intentName, intentData] = fdc3Intent;
1073
- return Object.assign({ name: intentName }, intentData);
1071
+ return {
1072
+ name: intentName,
1073
+ ...intentData
1074
+ };
1074
1075
  });
1075
1076
  return intents;
1076
1077
  }
1077
1078
  getIconFromDefinition(definition, version) {
1078
- var _a, _b, _c, _d;
1079
1079
  if (version === "1.2") {
1080
- return ((_b = (_a = definition.icons) === null || _a === void 0 ? void 0 : _a.find((iconDef) => iconDef.icon)) === null || _b === void 0 ? void 0 : _b.icon) || undefined;
1080
+ return definition.icons?.find((iconDef) => iconDef.icon)?.icon || undefined;
1081
1081
  }
1082
- return ((_d = (_c = definition.icons) === null || _c === void 0 ? void 0 : _c.find((iconDef) => iconDef.src)) === null || _d === void 0 ? void 0 : _d.src) || undefined;
1082
+ return definition.icons?.find((iconDef) => iconDef.src)?.src || undefined;
1083
1083
  }
1084
1084
  mergeBaseAppDataWithGlueManifest(baseAppData, hostManifestDefinition) {
1085
1085
  let baseApplicationDefinition = baseAppData;
1086
1086
  if (hostManifestDefinition.details) {
1087
- const details = Object.assign(Object.assign({}, baseAppData.createOptions), hostManifestDefinition.details);
1087
+ const details = { ...baseAppData.createOptions, ...hostManifestDefinition.details };
1088
1088
  baseApplicationDefinition.createOptions = details;
1089
1089
  baseApplicationDefinition.userProperties.details = details;
1090
1090
  }
1091
1091
  if (Array.isArray(hostManifestDefinition.intents)) {
1092
1092
  baseApplicationDefinition.userProperties.intents = (baseApplicationDefinition.userProperties.intents || []).concat(hostManifestDefinition.intents);
1093
1093
  }
1094
- baseApplicationDefinition = Object.assign(Object.assign({}, baseApplicationDefinition), hostManifestDefinition);
1094
+ baseApplicationDefinition = { ...baseApplicationDefinition, ...hostManifestDefinition };
1095
1095
  delete baseApplicationDefinition.details;
1096
1096
  delete baseApplicationDefinition.intents;
1097
1097
  return baseApplicationDefinition;
1098
1098
  }
1099
1099
  mergeDesktopConfigWithGlueManifest(config, desktopDefinition) {
1100
- const appConfig = Object.assign({}, config, desktopDefinition, { details: Object.assign(Object.assign({}, config.details), desktopDefinition.details) });
1100
+ const appConfig = Object.assign({}, config, desktopDefinition, { details: { ...config.details, ...desktopDefinition.details } });
1101
1101
  if (Array.isArray(desktopDefinition.intents)) {
1102
1102
  appConfig.intents = (config.intents || []).concat(desktopDefinition.intents);
1103
1103
  }
@@ -1117,10 +1117,27 @@ const decoders$1 = {
1117
1117
  }
1118
1118
  };
1119
1119
 
1120
+ var INTENTS_ERRORS;
1121
+ (function (INTENTS_ERRORS) {
1122
+ INTENTS_ERRORS["USER_CANCELLED"] = "User Closed Intents Resolver UI without choosing a handler";
1123
+ INTENTS_ERRORS["CALLER_NOT_DEFINED"] = "Caller Id is not defined";
1124
+ INTENTS_ERRORS["TIMEOUT_HIT"] = "Timeout hit";
1125
+ INTENTS_ERRORS["INTENT_NOT_FOUND"] = "Cannot find Intent";
1126
+ INTENTS_ERRORS["HANDLER_NOT_FOUND"] = "Cannot find Intent Handler";
1127
+ INTENTS_ERRORS["TARGET_INSTANCE_UNAVAILABLE"] = "Cannot start Target Instance";
1128
+ INTENTS_ERRORS["INTENT_DELIVERY_FAILED"] = "Target Instance did not add a listener";
1129
+ INTENTS_ERRORS["RESOLVER_UNAVAILABLE"] = "Intents Resolver UI unavailable";
1130
+ INTENTS_ERRORS["RESOLVER_TIMEOUT"] = "User did not choose a handler";
1131
+ INTENTS_ERRORS["INVALID_RESOLVER_RESPONSE"] = "Intents Resolver UI returned invalid response";
1132
+ INTENTS_ERRORS["INTENT_HANDLER_REJECTION"] = "Intent Handler function processing the raised intent threw an error or rejected the promise it returned";
1133
+ })(INTENTS_ERRORS || (INTENTS_ERRORS = {}));
1134
+
1120
1135
  class IoC {
1121
- constructor() {
1122
- this._decoders = decoders$1;
1123
- }
1136
+ _fdc3;
1137
+ _decoders = decoders$1;
1138
+ _errors = {
1139
+ intents: INTENTS_ERRORS
1140
+ };
1124
1141
  get fdc3() {
1125
1142
  if (!this._fdc3) {
1126
1143
  this._fdc3 = new FDC3Service().toApi();
@@ -1130,11 +1147,15 @@ class IoC {
1130
1147
  get decoders() {
1131
1148
  return this._decoders;
1132
1149
  }
1150
+ get errors() {
1151
+ return this._errors;
1152
+ }
1133
1153
  }
1134
1154
 
1135
1155
  const ioc = new IoC();
1136
1156
  const fdc3 = ioc.fdc3;
1137
1157
  const decoders = ioc.decoders;
1158
+ const errors = ioc.errors;
1138
1159
 
1139
- export { decoders, fdc3 };
1160
+ export { decoders, errors, fdc3 };
1140
1161
  //# sourceMappingURL=utils.es.js.map