Skip to content

Commit

Permalink
Enable third party debugging in prod (#90)
Browse files Browse the repository at this point in the history
* Enable third party debugging in prod
  • Loading branch information
esme authored Mar 28, 2023
1 parent 961f2d3 commit 75f3058
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ Here is a description of the events:
import CallingExtensions from "@hubspot/calling-extensions-sdk";

const options = {
// Whether to log various inbound/outbound messages to console
/** @property {boolean} debugMode - Whether to log various inbound/outbound debug messages to the console. If false, console.debug will be used instead of console.log */
debugMode: true | false,
// eventHandlers handle inbound messages
eventHandlers: {
onReady: () => {
/* HubSpot is ready to receive messages. */
},
onDialNumber: event => {
/* Dial a number */
/* HubSpot sends a dial number from the contact */
},
onEngagementCreated: event => {
/* HubSpot has created an engagement for this call. */
Expand Down
4 changes: 2 additions & 2 deletions SHIP_WITH_CARE.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Ship with Care - how to deploy changes safely

**Reliability is a fundamental feature** that customers expect when choosing HubSpot. We are all responsible for meeting this expectation as we continue to delight our customers by shipping code. To help provide guidance on how to achieve this, we have compiled a handful of best practices we call the BRAVE checklist. These guidelines aren’t meant to stop you from shipping, but to make it easier and more efficient to ship changes without fear of what might break whether you're deploying something new, changing config, ungating a feature, refactoring code, or running a migration.
**Reliability is a fundamental feature** that customers expect when choosing HubSpot. We are all responsible for meeting this expectation as we continue to delight our customers by shipping code. To help provide guidance on how to achieve this, we have compiled a handful of best practices we call the **BRAVE** checklist. These guidelines aren’t meant to stop you from shipping, but to make it easier and more efficient to ship changes without fear of what might break whether you're deploying something new, changing config, ungating a feature, refactoring code, or running a migration.

Make your changes Backward compatible. There's no such thing as an atomic deployment at HubSpot. You will have multiple versions of your code running at once even if it's only for a short time. Prefer incremental and backward compatible rollouts of risky changes over "deploy the world" changesets. While sometimes this requires additional time and effort, the benefits of avoiding potential disruptions and preserving customer experience make it the preferred approach. The best way to move fast is to take your time and do the job right - Slow is smooth and smooth is fast. We will continue to build infrastructure and tooling to make these types of changes faster and simpler.
Make your changes **Backward compatible**. There's no such thing as an atomic deployment at HubSpot. You will have multiple versions of your code running at once even if it's only for a short time. Prefer incremental and backward compatible rollouts of risky changes over "deploy the world" changesets. While sometimes this requires additional time and effort, the benefits of avoiding potential disruptions and preserving customer experience make it the preferred approach. The best way to move fast is to take your time and do the job right - Slow is smooth and smooth is fast. We will continue to build infrastructure and tooling to make these types of changes faster and simpler.

Have a **Rollout (and Rollback!) plan**. The act of thinking through the rollout and anticipating a rollback will help you understand and manage the risk. Consider rolling out incrementally to reduce the customer impact of an issue with your changes. Roll-outs should be slow, roll-backs fast. Put your plan in your PR description if the rollout and rollback are non-obvious or non-trivial for your change. In case of non-obvious or non-trivial rollbacks, consider testing your rollbacks. Rollback early and often, it is better to have a false rollback than a critsit.

Expand Down
19 changes: 19 additions & 0 deletions src/CallingExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,29 @@
import IFrameManager from "./IFrameManager";
import { messageType, errorType } from "./Constants";

/**
* @typedef {Object} EventHandlers
* @property {function} onReady - Called when HubSpot is ready to receive messages.
* @property {function} onDialNumber - Called when the HubSpot sends a dial number from the contact.
* @property {function} onEngagementCreated - Called when HubSpot creates an engagement
* for the call.
* @property {function} onVisibilityChanged - Called when the call widget's visibility changes.
*/

/**
* @typedef {Object} Options
* @property {boolean} debugMode - Whether to log various inbound/outbound debug messages
* to the console.
* @property {EventHandlers} eventHandlers - Event handlers handle inbound messages.
*/

/*
* CallingExtensions allows call providers to communicate with HubSpot.
*/
class CallingExtensions {
/**
* @param {Options} options
*/
constructor(options) {
if (!options || !options.eventHandlers) {
throw new Error("Invalid options or missing eventHandlers.");
Expand Down
6 changes: 4 additions & 2 deletions src/IFrameManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,13 @@ class IFrameManager {
}

logDebugMessage(...args) {
const msg = this.isIFrameHost ? "IFrame host" : "IFrame";
args.unshift(msg);
if (this.debugMode) {
const msg = this.isIFrameHost ? "IFrame host" : "IFrame";
args.unshift(msg);
console.log.call(null, args);
return;
}
console.debug.call(null, args);
}
}

Expand Down

0 comments on commit 75f3058

Please sign in to comment.