@simplybusiness/services 1.5.0 → 1.6.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [12ff90a]
8
+ - @simplybusiness/mobius@6.9.7
9
+
10
+ ## 1.6.0
11
+
12
+ ### Minor Changes
13
+
14
+ - 170d1d0: Add AIRBRAKE_ENV environment variable for controlling Airbrake error routing.
15
+ - Add `getAirbrakeEnvironment()` helper that reads `process.env.AIRBRAKE_ENV` (defaults to "development")
16
+ - Only send real errors to Airbrake when `AIRBRAKE_ENV` is "staging" or "production"
17
+ - Support multiple Airbrake project instances via projectId
18
+ - Fix `forceSend` logic bug (was using OR instead of AND)
19
+ - Remove domain-based environment detection
20
+
21
+ **Breaking change:** Apps must now set `AIRBRAKE_ENV` at bundle time to enable error reporting.
22
+
23
+ - f51fa66: Add extra fields to trade selected event, when used in a US page
24
+
25
+ ### Patch Changes
26
+
27
+ - 9b68bf2: Fix "process is not defined" error in browser environments by adding safe access to process.env
28
+ - Updated dependencies [3f0ca52]
29
+ - Updated dependencies [67419b3]
30
+ - @simplybusiness/mobius@6.9.6
31
+
3
32
  ## 1.5.0
4
33
 
5
34
  ### Minor Changes
package/dist/cjs/index.js CHANGED
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  SnowplowProvider: () => SnowplowProvider,
26
26
  eventDefinitions: () => eventDefinitions,
27
27
  getAirbrake: () => getAirbrake,
28
+ getAirbrakeEnvironment: () => getAirbrakeEnvironment,
28
29
  getContexts: () => getContexts,
29
30
  getSnowplowConfig: () => getSnowplowConfig,
30
31
  interventionPageEvents: () => interventionPageEvents,
@@ -112,35 +113,36 @@ var AddressLookup = class _AddressLookup {
112
113
  var import_browser = require("@airbrake/browser");
113
114
  var defaultProjectId = 512949;
114
115
  var defaultProjectKey = "4e25197d8faea61c10fbb97702200780";
115
- var notifierInstance;
116
- var fakeNotify = () => {
117
- if (false) {
118
- return jest.fn();
119
- }
120
- return console.error;
121
- };
116
+ var notifierInstances = /* @__PURE__ */ new Map();
122
117
  var fakeAirbrake = {
123
- notify: fakeNotify()
118
+ notify: globalThis.process?.env?.NODE_ENV === "test" ? jest.fn() : console.error.bind(console)
124
119
  };
120
+ var getAirbrakeEnvironment = () => globalThis.process?.env?.AIRBRAKE_ENV ?? "development";
125
121
  var shouldUseAirbrake = () => {
126
- const { location } = globalThis;
127
- const isTest = false;
128
- return isTest || location?.hostname.indexOf("quote.") > -1;
122
+ const env = getAirbrakeEnvironment();
123
+ return env === "staging" || env === "production";
129
124
  };
130
- function getAirbrake(options) {
131
- const { projectId, projectKey, forceSend } = options;
132
- if (!forceSend || !shouldUseAirbrake()) {
125
+ function getAirbrake(options = {}) {
126
+ const {
127
+ projectId = defaultProjectId,
128
+ projectKey = defaultProjectKey,
129
+ forceSend
130
+ } = options;
131
+ if (!forceSend && !shouldUseAirbrake()) {
133
132
  return fakeAirbrake;
134
133
  }
134
+ let notifierInstance = notifierInstances.get(projectId);
135
135
  if (!notifierInstance) {
136
136
  notifierInstance = new import_browser.Notifier({
137
- projectId: projectId ?? defaultProjectId,
138
- projectKey: projectKey ?? defaultProjectKey,
139
- environment: "development",
137
+ projectId,
138
+ projectKey,
139
+ environment: getAirbrakeEnvironment(),
140
140
  instrumentation: {
141
- onerror: false
141
+ onerror: false,
142
+ unhandledrejection: false
142
143
  }
143
144
  });
145
+ notifierInstances.set(projectId, notifierInstance);
144
146
  }
145
147
  return notifierInstance;
146
148
  }
@@ -951,20 +953,41 @@ var questionnaireEventDefinitions = [
951
953
  name: "primaryDetailSelected",
952
954
  type: "unstructured",
953
955
  makePayload: (params) => {
954
- const { context, answer, vertical } = params;
956
+ const {
957
+ context,
958
+ answer,
959
+ vertical,
960
+ searchId,
961
+ selectedListPosition,
962
+ selectionMethod
963
+ } = params;
955
964
  const { site } = context;
965
+ const isUSPage = site === "simplybusiness_us";
956
966
  let verticalName = vertical || context.vertical;
957
967
  if (verticalName.toLowerCase().indexOf("landlord") > -1) {
958
968
  verticalName = answer === "residential" ? "Landlord" : "Commercial landlord";
959
969
  }
970
+ const data = {
971
+ site,
972
+ vertical: verticalName,
973
+ primary_detail: answer,
974
+ selected_type: "trade_selector",
975
+ location: window?.location?.pathname ?? ""
976
+ };
977
+ if (searchId) {
978
+ data.search_id = searchId;
979
+ }
980
+ if (selectionMethod) {
981
+ data.selection_method = selectionMethod;
982
+ }
983
+ if (isUSPage) {
984
+ data.selected_list_position = selectedListPosition !== void 0 ? (selectedListPosition + 1).toString() : null;
985
+ data.selected_location = "trade_selector_vertical";
986
+ data.business_unit = site;
987
+ }
960
988
  return {
961
989
  schema: "iglu:com.simplybusiness/primary_detail_selected/jsonschema/1-4-0",
962
- data: {
963
- site,
964
- vertical: verticalName,
965
- primary_detail: answer,
966
- selected_type: "trade_selector"
967
- }
990
+ data
968
991
  };
969
992
  },
970
993
  contexts: ["distributionChannelContext", "serviceChannelContext"]
package/dist/esm/index.js CHANGED
@@ -72,35 +72,36 @@ var AddressLookup = class _AddressLookup {
72
72
  import { Notifier } from "@airbrake/browser";
73
73
  var defaultProjectId = 512949;
74
74
  var defaultProjectKey = "4e25197d8faea61c10fbb97702200780";
75
- var notifierInstance;
76
- var fakeNotify = () => {
77
- if (false) {
78
- return jest.fn();
79
- }
80
- return console.error;
81
- };
75
+ var notifierInstances = /* @__PURE__ */ new Map();
82
76
  var fakeAirbrake = {
83
- notify: fakeNotify()
77
+ notify: globalThis.process?.env?.NODE_ENV === "test" ? jest.fn() : console.error.bind(console)
84
78
  };
79
+ var getAirbrakeEnvironment = () => globalThis.process?.env?.AIRBRAKE_ENV ?? "development";
85
80
  var shouldUseAirbrake = () => {
86
- const { location } = globalThis;
87
- const isTest = false;
88
- return isTest || location?.hostname.indexOf("quote.") > -1;
81
+ const env = getAirbrakeEnvironment();
82
+ return env === "staging" || env === "production";
89
83
  };
90
- function getAirbrake(options) {
91
- const { projectId, projectKey, forceSend } = options;
92
- if (!forceSend || !shouldUseAirbrake()) {
84
+ function getAirbrake(options = {}) {
85
+ const {
86
+ projectId = defaultProjectId,
87
+ projectKey = defaultProjectKey,
88
+ forceSend
89
+ } = options;
90
+ if (!forceSend && !shouldUseAirbrake()) {
93
91
  return fakeAirbrake;
94
92
  }
93
+ let notifierInstance = notifierInstances.get(projectId);
95
94
  if (!notifierInstance) {
96
95
  notifierInstance = new Notifier({
97
- projectId: projectId ?? defaultProjectId,
98
- projectKey: projectKey ?? defaultProjectKey,
99
- environment: "development",
96
+ projectId,
97
+ projectKey,
98
+ environment: getAirbrakeEnvironment(),
100
99
  instrumentation: {
101
- onerror: false
100
+ onerror: false,
101
+ unhandledrejection: false
102
102
  }
103
103
  });
104
+ notifierInstances.set(projectId, notifierInstance);
104
105
  }
105
106
  return notifierInstance;
106
107
  }
@@ -911,20 +912,41 @@ var questionnaireEventDefinitions = [
911
912
  name: "primaryDetailSelected",
912
913
  type: "unstructured",
913
914
  makePayload: (params) => {
914
- const { context, answer, vertical } = params;
915
+ const {
916
+ context,
917
+ answer,
918
+ vertical,
919
+ searchId,
920
+ selectedListPosition,
921
+ selectionMethod
922
+ } = params;
915
923
  const { site } = context;
924
+ const isUSPage = site === "simplybusiness_us";
916
925
  let verticalName = vertical || context.vertical;
917
926
  if (verticalName.toLowerCase().indexOf("landlord") > -1) {
918
927
  verticalName = answer === "residential" ? "Landlord" : "Commercial landlord";
919
928
  }
929
+ const data = {
930
+ site,
931
+ vertical: verticalName,
932
+ primary_detail: answer,
933
+ selected_type: "trade_selector",
934
+ location: window?.location?.pathname ?? ""
935
+ };
936
+ if (searchId) {
937
+ data.search_id = searchId;
938
+ }
939
+ if (selectionMethod) {
940
+ data.selection_method = selectionMethod;
941
+ }
942
+ if (isUSPage) {
943
+ data.selected_list_position = selectedListPosition !== void 0 ? (selectedListPosition + 1).toString() : null;
944
+ data.selected_location = "trade_selector_vertical";
945
+ data.business_unit = site;
946
+ }
920
947
  return {
921
948
  schema: "iglu:com.simplybusiness/primary_detail_selected/jsonschema/1-4-0",
922
- data: {
923
- site,
924
- vertical: verticalName,
925
- primary_detail: answer,
926
- selected_type: "trade_selector"
927
- }
949
+ data
928
950
  };
929
951
  },
930
952
  contexts: ["distributionChannelContext", "serviceChannelContext"]
@@ -1306,6 +1328,7 @@ export {
1306
1328
  SnowplowProvider,
1307
1329
  eventDefinitions,
1308
1330
  getAirbrake,
1331
+ getAirbrakeEnvironment,
1309
1332
  getContexts,
1310
1333
  getSnowplowConfig,
1311
1334
  interventionPageEvents,