@simplybusiness/services 1.4.5 → 1.6.0

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,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 170d1d0: Add AIRBRAKE_ENV environment variable for controlling Airbrake error routing.
8
+ - Add `getAirbrakeEnvironment()` helper that reads `process.env.AIRBRAKE_ENV` (defaults to "development")
9
+ - Only send real errors to Airbrake when `AIRBRAKE_ENV` is "staging" or "production"
10
+ - Support multiple Airbrake project instances via projectId
11
+ - Fix `forceSend` logic bug (was using OR instead of AND)
12
+ - Remove domain-based environment detection
13
+
14
+ **Breaking change:** Apps must now set `AIRBRAKE_ENV` at bundle time to enable error reporting.
15
+
16
+ - f51fa66: Add extra fields to trade selected event, when used in a US page
17
+
18
+ ### Patch Changes
19
+
20
+ - 9b68bf2: Fix "process is not defined" error in browser environments by adding safe access to process.env
21
+ - Updated dependencies [3f0ca52]
22
+ - Updated dependencies [67419b3]
23
+ - @simplybusiness/mobius@6.9.6
24
+
25
+ ## 1.5.0
26
+
27
+ ### Minor Changes
28
+
29
+ - d0940fa: cleanup of voucher intervention
30
+
31
+ ### Patch Changes
32
+
33
+ - @simplybusiness/mobius@6.9.5
34
+
3
35
  ## 1.4.5
4
36
 
5
37
  ### Patch 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
  }
@@ -920,16 +922,6 @@ var qcpEventDefinitions = [
920
922
  property: window.location.href
921
923
  };
922
924
  }
923
- },
924
- {
925
- name: "voucherClaimClicked",
926
- type: "structured",
927
- makePayload: () => ({
928
- category: "uk-25-06-hyrdra-voucher-intervention-qcp-page",
929
- action: "voucher_claim_clicked",
930
- label: "voucher_claim_clicked",
931
- property: window.location.href
932
- })
933
925
  }
934
926
  ];
935
927
 
@@ -961,20 +953,41 @@ var questionnaireEventDefinitions = [
961
953
  name: "primaryDetailSelected",
962
954
  type: "unstructured",
963
955
  makePayload: (params) => {
964
- const { context, answer, vertical } = params;
956
+ const {
957
+ context,
958
+ answer,
959
+ vertical,
960
+ searchId,
961
+ selectedListPosition,
962
+ selectionMethod
963
+ } = params;
965
964
  const { site } = context;
965
+ const isUSPage = site === "simplybusiness_us";
966
966
  let verticalName = vertical || context.vertical;
967
967
  if (verticalName.toLowerCase().indexOf("landlord") > -1) {
968
968
  verticalName = answer === "residential" ? "Landlord" : "Commercial landlord";
969
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
+ }
970
988
  return {
971
989
  schema: "iglu:com.simplybusiness/primary_detail_selected/jsonschema/1-4-0",
972
- data: {
973
- site,
974
- vertical: verticalName,
975
- primary_detail: answer,
976
- selected_type: "trade_selector"
977
- }
990
+ data
978
991
  };
979
992
  },
980
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
  }
@@ -880,16 +881,6 @@ var qcpEventDefinitions = [
880
881
  property: window.location.href
881
882
  };
882
883
  }
883
- },
884
- {
885
- name: "voucherClaimClicked",
886
- type: "structured",
887
- makePayload: () => ({
888
- category: "uk-25-06-hyrdra-voucher-intervention-qcp-page",
889
- action: "voucher_claim_clicked",
890
- label: "voucher_claim_clicked",
891
- property: window.location.href
892
- })
893
884
  }
894
885
  ];
895
886
 
@@ -921,20 +912,41 @@ var questionnaireEventDefinitions = [
921
912
  name: "primaryDetailSelected",
922
913
  type: "unstructured",
923
914
  makePayload: (params) => {
924
- const { context, answer, vertical } = params;
915
+ const {
916
+ context,
917
+ answer,
918
+ vertical,
919
+ searchId,
920
+ selectedListPosition,
921
+ selectionMethod
922
+ } = params;
925
923
  const { site } = context;
924
+ const isUSPage = site === "simplybusiness_us";
926
925
  let verticalName = vertical || context.vertical;
927
926
  if (verticalName.toLowerCase().indexOf("landlord") > -1) {
928
927
  verticalName = answer === "residential" ? "Landlord" : "Commercial landlord";
929
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
+ }
930
947
  return {
931
948
  schema: "iglu:com.simplybusiness/primary_detail_selected/jsonschema/1-4-0",
932
- data: {
933
- site,
934
- vertical: verticalName,
935
- primary_detail: answer,
936
- selected_type: "trade_selector"
937
- }
949
+ data
938
950
  };
939
951
  },
940
952
  contexts: ["distributionChannelContext", "serviceChannelContext"]
@@ -1316,6 +1328,7 @@ export {
1316
1328
  SnowplowProvider,
1317
1329
  eventDefinitions,
1318
1330
  getAirbrake,
1331
+ getAirbrakeEnvironment,
1319
1332
  getContexts,
1320
1333
  getSnowplowConfig,
1321
1334
  interventionPageEvents,