UNPKG

nativescript-zendesk-sdk

Version:
167 lines (166 loc) 7.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var color_1 = require("tns-core-modules/color/color"); var platform_1 = require("tns-core-modules/platform"); var frame_1 = require("tns-core-modules/ui/frame"); var ZendeskSdk = (function () { function ZendeskSdk() { } ZendeskSdk.initialize = function (config) { ZDKConfig.instance().initializeWithAppIdZendeskUrlClientId(config.applicationId, config.zendeskUrl, config.clientId); if (config.userLocale) { ZendeskSdk.setUserLocale(config.userLocale); } if (config.identity === null) { ZendeskSdk.setAnonymousIdentity(); } else if (typeof config.identity === 'object') { ZendeskSdk.setAnonymousIdentity(config.identity); } else if (typeof config.identity === 'string') { ZendeskSdk.setJwtIdentity(config.identity); } return ZendeskSdk; }; ZendeskSdk.setUserLocale = function (locale) { ZDKConfig.instance().userLocale = locale; return ZendeskSdk; }; ZendeskSdk.setAnonymousIdentity = function (anonUserIdentity) { if (anonUserIdentity === void 0) { anonUserIdentity = {}; } var identity = ZDKAnonymousIdentity.new(); if (anonUserIdentity.name) { identity.name = anonUserIdentity.name; } if (anonUserIdentity.email) { identity.email = anonUserIdentity.email; } ZDKConfig.instance().userIdentity = identity; return ZendeskSdk; }; ZendeskSdk.setJwtIdentity = function (jwtUserIdentifier) { ZDKConfig.instance().userIdentity = ZDKJwtIdentity.alloc().initWithJwtUserIdentifier(jwtUserIdentifier); return ZendeskSdk; }; ZendeskSdk.configureRequests = function (config) { config.addDeviceInfo = config.addDeviceInfo != null ? config.addDeviceInfo : true; var tagsNSArray = null; if (config.tags) { tagsNSArray = NSMutableArray.alloc().initWithCapacity(config.tags.length); config.tags.forEach(function (value) { tagsNSArray.addObject(value); }); } var deviceInfo = config.addDeviceInfo ? '\n\n' + platform_1.device.language + '-' + platform_1.device.region + '\n' + platform_1.device.manufacturer + ' ' + platform_1.device.model + '\n' + platform_1.device.os + ' ' + platform_1.device.osVersion + '(' + platform_1.device.sdkVersion + ')' : ''; ZDKRequests.configure(function (account, requestCreationConfig) { requestCreationConfig.subject = config.requestSubject; requestCreationConfig.additionalRequestInfo = !!config.additionalInfo || config.addDeviceInfo ? '\n\n------------------------------' + (!!config.additionalInfo ? '\n\n' + config.additionalInfo : '') + deviceInfo : ''; requestCreationConfig.tags = tagsNSArray; }); return ZendeskSdk; }; ZendeskSdk.showHelpCenter = function (options) { if (options === void 0) { options = {}; } var contentModel = ZDKHelpCenterOverviewContentModel.defaultContent(); ZendeskSdk._initHelpCenter(options, contentModel); }; ZendeskSdk.showHelpCenterForCategoryIds = function (categoryIds, options) { if (options === void 0) { options = {}; } var contentModel = ZDKHelpCenterOverviewContentModel.defaultContent(); contentModel.groupType = 2; ZendeskSdk._initHelpCenter(options, contentModel); }; ZendeskSdk.showHelpCenterForLabelNames = function (labelNames, options) { if (options === void 0) { options = {}; } var contentModel = ZDKHelpCenterOverviewContentModel.defaultContent(); var nsArray = NSMutableArray.alloc().initWithCapacity(labelNames.length); labelNames.forEach(function (value) { nsArray.addObject(value); }); contentModel.labels = nsArray; ZendeskSdk._initHelpCenter(options, contentModel); }; ZendeskSdk.showHelpCenterForSectionIds = function (sectionIds, options) { if (options === void 0) { options = {}; } var contentModel = ZDKHelpCenterOverviewContentModel.defaultContent(); contentModel.groupType = 1; ZendeskSdk._initHelpCenter(options, contentModel); }; ZendeskSdk.showArticle = function (articleId) { var provider = ZDKHelpCenterProvider.alloc() .initWithLocale(ZDKConfig.instance().userLocale); provider.getArticleByIdWithCallback(articleId, function (items, error) { if (items.count > 0) { var vc = ZDKArticleViewController.alloc() .initWithArticle(items.firstObject); frame_1.topmost() .ios .controller .pushViewControllerAnimated(vc, true); } }); }; ZendeskSdk.createRequest = function () { ZDKRequests.presentRequestCreationWithViewController(frame_1.topmost().ios.controller); }; ZendeskSdk.setIosTheme = function (theme) { var baseTheme = ZDKTheme.baseTheme(); if (theme.primaryTextColor) { baseTheme.primaryTextColor = new color_1.Color(theme.primaryTextColor).ios; } if (theme.secondaryTextColor) { baseTheme.secondaryTextColor = new color_1.Color(theme.secondaryTextColor).ios; } if (theme.primaryBackgroundColor) { baseTheme.primaryBackgroundColor = new color_1.Color(theme.primaryBackgroundColor).ios; } if (theme.secondaryBackgroundColor) { baseTheme.secondaryBackgroundColor = new color_1.Color(theme.secondaryBackgroundColor).ios; } if (theme.emptyBackgroundColor) { baseTheme.emptyBackgroundColor = new color_1.Color(theme.emptyBackgroundColor).ios; } if (theme.metaTextColor) { baseTheme.metaTextColor = new color_1.Color(theme.metaTextColor).ios; } if (theme.separatorColor) { baseTheme.separatorColor = new color_1.Color(theme.separatorColor).ios; } if (theme.inputFieldTextColor) { baseTheme.inputFieldTextColor = new color_1.Color(theme.inputFieldTextColor).ios; } if (theme.inputFieldBackgroundColor) { baseTheme.inputFieldBackgroundColor = new color_1.Color(theme.inputFieldBackgroundColor).ios; } if (theme.fontName) { baseTheme.fontName = theme.fontName; } if (theme.boldFontName) { baseTheme.boldFontName = theme.boldFontName; } baseTheme.apply(); }; ZendeskSdk._initHelpCenter = function (options, helpCenterContentModel) { if (options.conversationsMenuIos != null ? !options.conversationsMenuIos : false) { ZDKHelpCenter.setNavBarConversationsUIType(2); } if (options.showAsModalForIos != null ? options.showAsModalForIos : false) { frame_1.topmost().ios.controller.modalPresentationStyle = 2; ZDKHelpCenter.presentHelpCenterOverviewWithContentModel(frame_1.topmost().ios.controller, helpCenterContentModel); } else { ZDKHelpCenter.pushHelpCenterOverviewWithContentModel(frame_1.topmost().ios.controller, helpCenterContentModel); } }; return ZendeskSdk; }()); exports.ZendeskSdk = ZendeskSdk;