Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating fullstory module and adding rollup-based build #1

Merged
merged 2 commits into from Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
dist
18 changes: 16 additions & 2 deletions package.json
Expand Up @@ -2,10 +2,17 @@
"name": "@sentry/fullstory",
"version": "0.0.1",
"description": "The Sentry-FullStory integration creates a link from the Sentry Error to the FullStory replay. It also creates a link from the FullStory event to the Sentry error.",
"main": "src/index.js",
"main": "./dist/index.js",
"module": "./dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"clean": "rimraf dist",
"build": "npm run clean && rollup -c"
},
"files": [
"dist",
"src"
],
"repository": {
"type": "git",
"url": "git+https://github.com/getsentry/sentry-fullstory.git"
Expand All @@ -18,5 +25,12 @@
"homepage": "https://github.com/getsentry/sentry-fullstory#readme",
"peerDependencies": {
"@sentry/browser": ">=4.0.0"
},
"dependencies": {},
"devDependencies": {
"@babel/core": "^7.7.2",
"rimraf": "^3.0.0",
"rollup": "^1.26.3",
"rollup-plugin-babel": "^4.3.3"
}
}
14 changes: 14 additions & 0 deletions rollup.config.js
@@ -0,0 +1,14 @@
import babel from 'rollup-plugin-babel';
import pkg from './package.json';

export default [
{
input: 'src/index.js',
output: [{ file: pkg.main, format: 'esm' }],
plugins: [
babel({
exclude: ['node_modules/**']
})
]
}
];
63 changes: 0 additions & 63 deletions src/FullStoryWrapper.js

This file was deleted.

3 changes: 2 additions & 1 deletion src/SentryFullStory.js
@@ -1,6 +1,7 @@
import * as Sentry from '@sentry/browser';

import * as FullStory from './FullStoryWrapper';
// NOTE: this will be a package hosted on NPM soon
import FullStory from './fullstory';

/**
* This integration creates a link from the Sentry Error to the FullStory replay.
Expand Down
53 changes: 53 additions & 0 deletions src/fullstory.js
@@ -0,0 +1,53 @@
import snippet from './snippet';

const fs = () => window[window._fs_namespace];

const ensureSnippetLoaded = () => {
const snippetLoaded = !!fs();
if (!snippetLoaded) {
throw Error('FullStory is not loaded, please ensure the init function is invoked before calling FullStory API functions');
}
};

const hasFullStoryWithFunction = (...testNames) => {
ensureSnippetLoaded();
return testNames.every(current => fs()[current]);
};

const wrapFunction = name => (...args) => {
if (hasFullStoryWithFunction(name)) {
return fs()[name](...args);
}
console.warn(`FS.${name} not ready`); // eslint-disable-line no-console
return null;
};

const wrappedFS = ['event', 'log', 'getCurrentSessionURL', 'identify', 'setUserVars', 'consent', 'shutdown', 'restart'].reduce((acc, current) => {
acc[current] = wrapFunction(current);
return acc;
}, {});

const init = (options) => {
if (fs()) {
// eslint-disable-next-line no-console
console.warn('The FullStory snippet has already been defined elsewhere (likely in the <head> element)');
return;
}

snippet(options);
};

const initOnce = (fn, message) => (...args) => {
if (window._fs_initialized) {
// eslint-disable-next-line no-console
if (message) console.warn(message);
return;
}
fn(...args);
window._fs_initialized = true;
};

wrappedFS.init = initOnce(init, 'FullStory init has already been called once, additional invocations are ignored');
wrappedFS.anonymize = () => wrappedFS.identify(false);

export default wrappedFS;
2 changes: 2 additions & 0 deletions src/index.js
@@ -1,3 +1,5 @@
import SentryFullStory from './SentryFullStory';
import FullStory from './fullstory';

export default SentryFullStory;
export { FullStory };
70 changes: 70 additions & 0 deletions src/snippet.js
@@ -0,0 +1,70 @@
/* eslint-disable */
const snippet = ({
orgId,
namespace = 'FS',
debug = false,
host = 'fullstory.com',
script = 'edge.fullstory.com/s/fs.js'
}) => {
if (!orgId) {
throw new Error('FullStory orgId is a required parameter');
}
/* begin FullStory snippet */
window._fs_debug = debug;
window._fs_host = host;
window._fs_script = script;
window._fs_org = orgId;
window._fs_namespace = namespace;
(function(m, n, e, t, l, o, g, y) {
if (e in m) {
if (m.console && m.console.log) {
m.console.log(
'FullStory namespace conflict. Please set window["_fs_namespace"].'
);
}
return;
}
g = m[e] = function(a, b, s) {
g.q ? g.q.push([a, b, s]) : g._api(a, b, s);
};
g.q = [];
o = n.createElement(t);
o.async = 1;
o.crossOrigin = 'anonymous';
o.src = 'https://' + m._fs_script;
y = n.getElementsByTagName(t)[0];
y.parentNode.insertBefore(o, y);
g.identify = function(i, v, s) {
g(l, { uid: i }, s);
if (v) g(l, v, s);
};
g.setUserVars = function(v, s) {
g(l, v, s);
};
g.event = function(i, v, s) {
g('event', { n: i, p: v }, s);
};
g.shutdown = function() {
g('rec', !1);
};
g.restart = function() {
g('rec', !0);
};
g.log = function(a, b) {
g('log', [a, b]);
};
g.consent = function(a) {
g('consent', !arguments.length || a);
};
g.identifyAccount = function(i, v) {
o = 'account';
v = v || {};
v.acctId = i;
g(o, v);
};
g.clearUserCookie = function() {};
})(window, document, window['_fs_namespace'], 'script', 'user');
/* end FullStory snippet */
};

export default snippet;