@channel.io/channel-web-sdk-loader
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -92,3 +92,5 @@ declare global { | ||
/** | ||
* Load the Channel SDK script. | ||
* - Load the Channel SDK script. | ||
* - This method is only executable on browser. | ||
* - You can’t execute this method on the server-side. | ||
*/ | ||
@@ -95,0 +97,0 @@ export declare function loadScript(): void; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.setAppearance = exports.hideChannelButton = exports.showChannelButton = exports.resetPage = exports.setPage = exports.removeTags = exports.addTags = exports.updateUser = exports.clearCallbacks = exports.onUrlClicked = exports.onFollowUpChanged = exports.onChatCreated = exports.onBadgeChanged = exports.onHideMessenger = exports.onShowMessenger = exports.track = exports.openChat = exports.hideMessenger = exports.showMessenger = exports.shutdown = exports.boot = exports.loadScript = void 0; | ||
const isSSR = typeof window === 'undefined'; | ||
/** | ||
* Load the Channel SDK script. | ||
* - Load the Channel SDK script. | ||
* - This method is only executable on browser. | ||
* - You can’t execute this method on the server-side. | ||
*/ | ||
function loadScript() { | ||
(function () { var w = window; if (w.ChannelIO) { | ||
return w.console.error("ChannelIO script included twice."); | ||
} var ch = function () { var _a; (_a = ch.c) === null || _a === void 0 ? void 0 : _a.call(ch, arguments); }; ch.q = []; ch.c = function (args) { var _a; (_a = ch.q) === null || _a === void 0 ? void 0 : _a.push(args); }; w.ChannelIO = ch; function l() { if (w.ChannelIOInitialized) { | ||
if (isSSR) { | ||
console.error('loadScript is only executable on browser.'); | ||
return; | ||
} w.ChannelIOInitialized = true; var s = document.createElement("script"); s.type = "text/javascript"; s.async = true; s.src = "https://cdn.channel.io/plugin/ch-plugin-web.js"; var x = document.getElementsByTagName("script")[0]; if (x.parentNode) { | ||
x.parentNode.insertBefore(s, x); | ||
} } if (document.readyState === "complete") { | ||
l(); | ||
} | ||
else { | ||
w.addEventListener("DOMContentLoaded", l); | ||
w.addEventListener("load", l); | ||
} })(); | ||
(function () { | ||
var w = window; | ||
if (w.ChannelIO) { | ||
return w.console.error('ChannelIO script included twice.'); | ||
} | ||
var ch = function () { | ||
var _a; | ||
(_a = ch.c) === null || _a === void 0 ? void 0 : _a.call(ch, arguments); | ||
}; | ||
ch.q = []; | ||
ch.c = function (args) { | ||
var _a; | ||
(_a = ch.q) === null || _a === void 0 ? void 0 : _a.push(args); | ||
}; | ||
w.ChannelIO = ch; | ||
function l() { | ||
if (w.ChannelIOInitialized) { | ||
return; | ||
} | ||
w.ChannelIOInitialized = true; | ||
var s = document.createElement('script'); | ||
s.type = 'text/javascript'; | ||
s.async = true; | ||
s.src = 'https://cdn.channel.io/plugin/ch-plugin-web.js'; | ||
var x = document.getElementsByTagName('script')[0]; | ||
if (x.parentNode) { | ||
x.parentNode.insertBefore(s, x); | ||
} | ||
} | ||
if (document.readyState === 'complete') { | ||
l(); | ||
} | ||
else { | ||
w.addEventListener('DOMContentLoaded', l); | ||
w.addEventListener('load', l); | ||
} | ||
})(); | ||
} | ||
@@ -33,4 +64,11 @@ exports.loadScript = loadScript; | ||
function boot(option, callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'boot', option, callback); | ||
if (isSSR) { | ||
console.error('boot is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before boot().'); | ||
return; | ||
} | ||
window.ChannelIO('boot', option, callback); | ||
} | ||
@@ -42,4 +80,11 @@ exports.boot = boot; | ||
function shutdown() { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'shutdown'); | ||
if (isSSR) { | ||
console.error('shutdown is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before shutdown().'); | ||
return; | ||
} | ||
window.ChannelIO('shutdown'); | ||
} | ||
@@ -52,4 +97,11 @@ exports.shutdown = shutdown; | ||
function showMessenger() { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'showMessenger'); | ||
if (isSSR) { | ||
console.error('showMessenger is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before showMessenger().'); | ||
return; | ||
} | ||
window.ChannelIO('showMessenger'); | ||
} | ||
@@ -62,4 +114,11 @@ exports.showMessenger = showMessenger; | ||
function hideMessenger() { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'hideMessenger'); | ||
if (isSSR) { | ||
console.error('hideMessenger is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before hideMessenger().'); | ||
return; | ||
} | ||
window.ChannelIO('hideMessenger'); | ||
} | ||
@@ -76,4 +135,11 @@ exports.hideMessenger = hideMessenger; | ||
function openChat(chatId, message) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'openChat', chatId, message); | ||
if (isSSR) { | ||
console.error('openChat is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before openChat().'); | ||
return; | ||
} | ||
window.ChannelIO('openChat', chatId, message); | ||
} | ||
@@ -90,4 +156,11 @@ exports.openChat = openChat; | ||
function track(eventName, eventProperty) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'track', eventName, eventProperty); | ||
if (isSSR) { | ||
console.error('track is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before track().'); | ||
return; | ||
} | ||
window.ChannelIO('track', eventName, eventProperty); | ||
} | ||
@@ -100,4 +173,11 @@ exports.track = track; | ||
function onShowMessenger(callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'onShowMessenger', callback); | ||
if (isSSR) { | ||
console.error('onShowMessenger is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before onShowMessenger().'); | ||
return; | ||
} | ||
window.ChannelIO('onShowMessenger', callback); | ||
} | ||
@@ -110,4 +190,11 @@ exports.onShowMessenger = onShowMessenger; | ||
function onHideMessenger(callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'onHideMessenger', callback); | ||
if (isSSR) { | ||
console.error('onHideMessenger is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before onHideMessenger().'); | ||
return; | ||
} | ||
window.ChannelIO('onHideMessenger', callback); | ||
} | ||
@@ -122,4 +209,11 @@ exports.onHideMessenger = onHideMessenger; | ||
function onBadgeChanged(callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'onBadgeChanged', callback); | ||
if (isSSR) { | ||
console.error('onBadgeChanged is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before onBadgeChanged().'); | ||
return; | ||
} | ||
window.ChannelIO('onBadgeChanged', callback); | ||
} | ||
@@ -132,4 +226,11 @@ exports.onBadgeChanged = onBadgeChanged; | ||
function onChatCreated(callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'onChatCreated', callback); | ||
if (isSSR) { | ||
console.error('onChatCreated is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before onChatCreated().'); | ||
return; | ||
} | ||
window.ChannelIO('onChatCreated', callback); | ||
} | ||
@@ -142,4 +243,11 @@ exports.onChatCreated = onChatCreated; | ||
function onFollowUpChanged(callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'onFollowUpChanged', callback); | ||
if (isSSR) { | ||
console.error('onFollowUpChanged is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before onFollowUpChanged().'); | ||
return; | ||
} | ||
window.ChannelIO('onFollowUpChanged', callback); | ||
} | ||
@@ -155,4 +263,11 @@ exports.onFollowUpChanged = onFollowUpChanged; | ||
function onUrlClicked(callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'onUrlClicked', callback); | ||
if (isSSR) { | ||
console.error('onUrlClicked is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before onUrlClicked().'); | ||
return; | ||
} | ||
window.ChannelIO('onUrlClicked', callback); | ||
} | ||
@@ -170,4 +285,11 @@ exports.onUrlClicked = onUrlClicked; | ||
function clearCallbacks() { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'clearCallbacks'); | ||
if (isSSR) { | ||
console.error('clearCallbacks is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before clearCallbacks().'); | ||
return; | ||
} | ||
window.ChannelIO('clearCallbacks'); | ||
} | ||
@@ -182,4 +304,11 @@ exports.clearCallbacks = clearCallbacks; | ||
function updateUser(userInfo, callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'updateUser', userInfo, callback); | ||
if (isSSR) { | ||
console.error('updateUser is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before updateUser().'); | ||
return; | ||
} | ||
window.ChannelIO('updateUser', userInfo, callback); | ||
} | ||
@@ -194,4 +323,11 @@ exports.updateUser = updateUser; | ||
function addTags(tags, callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'addTags', tags, callback); | ||
if (isSSR) { | ||
console.error('addTags is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before addTags().'); | ||
return; | ||
} | ||
window.ChannelIO('addTags', tags, callback); | ||
} | ||
@@ -206,4 +342,11 @@ exports.addTags = addTags; | ||
function removeTags(tags, callback) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'removeTags', tags, callback); | ||
if (isSSR) { | ||
console.error('removeTags is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before removeTags().'); | ||
return; | ||
} | ||
window.ChannelIO('removeTags', tags, callback); | ||
} | ||
@@ -219,4 +362,11 @@ exports.removeTags = removeTags; | ||
function setPage(page) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'setPage', page); | ||
if (isSSR) { | ||
console.error('setPage is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before setPage().'); | ||
return; | ||
} | ||
window.ChannelIO('setPage', page); | ||
} | ||
@@ -231,4 +381,11 @@ exports.setPage = setPage; | ||
function resetPage() { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'resetPage'); | ||
if (isSSR) { | ||
console.error('resetPage is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before resetPage().'); | ||
return; | ||
} | ||
window.ChannelIO('resetPage'); | ||
} | ||
@@ -243,4 +400,11 @@ exports.resetPage = resetPage; | ||
function showChannelButton() { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'showChannelButton'); | ||
if (isSSR) { | ||
console.error('showChannelButton is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before showChannelButton().'); | ||
return; | ||
} | ||
window.ChannelIO('showChannelButton'); | ||
} | ||
@@ -253,4 +417,11 @@ exports.showChannelButton = showChannelButton; | ||
function hideChannelButton() { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'hideChannelButton'); | ||
if (isSSR) { | ||
console.error('hideChannelButton is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before hideChannelButton().'); | ||
return; | ||
} | ||
window.ChannelIO('hideChannelButton'); | ||
} | ||
@@ -263,5 +434,12 @@ exports.hideChannelButton = hideChannelButton; | ||
function setAppearance(appearance) { | ||
var _a; | ||
(_a = window.ChannelIO) === null || _a === void 0 ? void 0 : _a.call(window, 'setAppearance', appearance); | ||
if (isSSR) { | ||
console.error('setAppearance is only executable on browser.'); | ||
return; | ||
} | ||
if (!window.ChannelIO) { | ||
console.error('ChannelIO is not loaded. Please call loadScript() before setAppearance().'); | ||
return; | ||
} | ||
window.ChannelIO('setAppearance', appearance); | ||
} | ||
exports.setAppearance = setAppearance; |
{ | ||
"name": "@channel.io/channel-web-sdk-loader", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "Channel Web SDK Loader for web", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -14,2 +14,4 @@ # channel-web-sdk-loader | ||
## Usage | ||
> ⚠️ **Use the SDK on client-side only.** | ||
You can’t execute the SDK beforehand on the server-side. | ||
@@ -16,0 +18,0 @@ ### Step1: Import ChannelService |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
44544
798
35
0