/*** Generated by streamline 0.10.17 (callbacks) - DO NOT EDIT ***/ var __rt=require('streamline/lib/callbacks/runtime').runtime(__filename, false),__func=__rt.__func,__cb=__rt.__cb,__catch=__rt.__catch,__tryCatch=__rt.__tryCatch; var fs = require("fs");
















var path = require("path");
var uuid = require("node-uuid");
var async = require("async");
var azureCommon = require("azure-common");

var profile = require("../../util/profile");
var utils = require("../../util/utils");
var PipelineChannel = require("./mobile/pipelineChannel");
var WebResource = azureCommon.WebResource;

var util = require("util");
var __ = require("underscore");
var $ = utils.getLocaleString;

exports.init = function(cli) {

  var log = cli.output;

  function serviceFilter(service, platform, externalPushEntity) {
    servicePlatform = (service.platform || "node");
    servicePushEntity = (service.enableExternalPushEntity || "false");

    if (((platform != "any") && (servicePlatform != platform))) {
      return false; } ;


    if (((externalPushEntity != "any") && (servicePushEntity != externalPushEntity))) {
      return false; } ;


    return true; };


  function nodeFilter(service) {
    return serviceFilter(service, "node", "any"); };


  function defaultFilter(service) {
    return serviceFilter(service, "any", "any"); };


  function promptServiceNameIfNotGiven(options, servicename, serviceFilter, _) { var result; var __frame = { name: "promptServiceNameIfNotGiven", line: 59 }; return __func(_, this, arguments, promptServiceNameIfNotGiven, 3, __frame, function __$promptServiceNameIfNotGiven() {
      return cli.interaction.chooseIfNotGiven($("Mobile Service: "), $("Retrieving choices"), servicename, function(cb) {

        mobile.listServices(options, function(error, services) {
          if (error) { cb(error); } ;
          cb(null, services.filter(serviceFilter).map(function(service) { return service.name; })); }); }, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;



        return _(null, result); }, true)); }); };


  function promptTableNameIfNotGiven(options, tableName, _) { var result; var __frame = { name: "promptTableNameIfNotGiven", line: 71 }; return __func(_, this, arguments, promptTableNameIfNotGiven, 2, __frame, function __$promptTableNameIfNotGiven() {
      return cli.interaction.chooseIfNotGiven($("Table: "), $("Retrieving choices"), tableName, function(cb) {

        mobile.listTables(options, function(error, tables) {
          if (error) { cb(error); } ;
          cb(null, tables.map(function(table) { return table.name; })); }); }, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;



        return _(null, result); }, true)); }); };


  function promptDomainIfNotGiven(options, domain, _) { var result; var __frame = { name: "promptDomainIfNotGiven", line: 83 }; return __func(_, this, arguments, promptDomainIfNotGiven, 2, __frame, function __$promptDomainIfNotGiven() {
      return cli.interaction.chooseIfNotGiven($("Domain: "), $("Retrieving choices"), domain, function(cb) {

        mobile.getDomains(options, function(error, domains) {
          if (error) { cb(error); } ;
          cb(null, domains.map(function(domain) { return domain; })); }); }, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;



        return _(null, result); }, true)); }); };


  function promptThumbprintIfNotGiven(options, thumbprint, _) { var result; var __frame = { name: "promptThumbprintIfNotGiven", line: 95 }; return __func(_, this, arguments, promptThumbprintIfNotGiven, 2, __frame, function __$promptThumbprintIfNotGiven() {
      return cli.interaction.chooseIfNotGiven($("Thumbprint: "), $("Retrieving choices"), thumbprint, function(cb) {

        mobile.getCertificates(options, function(error, certificates) {
          if (error) { cb(error); } ;
          cb(null, certificates.map(function(certificate) { return certificate.thumbprint; })); }); }, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;



        return _(null, result); }, true)); }); };


  function promptIfNotGiven(prompt, value, _) { var result; var __frame = { name: "promptIfNotGiven", line: 107 }; return __func(_, this, arguments, promptIfNotGiven, 2, __frame, function __$promptIfNotGiven() {
      return cli.interaction.promptIfNotGiven(prompt, value, __cb(_, __frame, 1, 33, function ___(__0, __1) { result = __1;
        if ((result.length === 0)) {
          return _(new Error(util.format($("%s must be specified"), prompt.split(":")[0]))); } ;

        return _(null, result); }, true)); }); };


  function promptString(prompt, callback) {
    cli.prompt(prompt, function(text) {
      if ((text.length > 0)) {
        callback(text); }
       else {
        throw (new Error(util.format($("%s must be specified"), prompt.split(":")[0]))); } ; }); };




  function getWebResource(options) {

    var currentSubscription = profile.current.getSubscription(options.subscription), httpRequest = new WebResource();


    options.subscription = currentSubscription.id;

    httpRequest.url = ((currentSubscription.managementEndpointUrl + "/") + options.subscription);
    httpRequest = httpRequest.withHeader("x-ms-version", "2014-01-01");

    return httpRequest; };


  function createClient(options) {
    var currentSubscription = profile.current.getSubscription(options.subscription);
    return utils.createMobileClient(currentSubscription); };


  function getMobileChannel(options) {
    var client = createClient(options), webResource = getWebResource(options);


    webResource.json = true;

    var channel = new PipelineChannel(client, webResource, log).path("services").path("mobileservices").header("Accept", "application/json");




    return channel; };


  function getAppManagerChannel(options) {
    var client = createClient(options), webResource = getWebResource(options);


    webResource.json = false;
    var channel = new PipelineChannel(client, webResource, log).header("Accept", "application/xml").path("applications");



    return channel; };


  function getOperationChannel(options, requestId) {
    var client = createClient(options), webResource = getWebResource(options);

    webResource.json = true;

    var channel = new PipelineChannel(client, webResource, log).path("operations").path(requestId).header("Accept", "application/json");




    return channel; };


  var mobile = cli.category("mobile").description($("Commands to manage your Mobile Services"));


  mobile.getRegions = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("regions");


    channel.get(callback); };


  mobile.listServices = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices");


    channel.get(callback); };


  mobile.getService = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename);



    channel.get(callback); };


  mobile.recover = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("recover").query("targetMobileService", options.targetservicename);





    channel.post(null, callback); };


  mobile.migrate = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("migrate").query("targetMobileService", options.targetservicename);





    channel.post(null, callback); };


  mobile.getMigrationState = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("migrate").query("operationId", options.orchestrationId);





    channel.get(callback); };


  mobile.getScaleSettings = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scalesettings");




    channel.get(function(error, scalesettings) {
      if (scalesettings) {
        scalesettings.numberOfInstances = (scalesettings.numberOfInstances || 1);
        scalesettings.tier = findScale((scalesettings.tier || "tier1"), true); } ;


      callback(error, scalesettings); }); };



  mobile.setScaleSettings = function(options, settings, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scalesettings").header("Content-Type", "application/json");





    log.silly($("New scale settings:"));
    log.json("silly", settings);

    channel.put(JSON.stringify(settings), callback); };


  mobile.getServiceSettings = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("settings");




    channel.get(callback); };







  function formatCrossDomainWhitelistForDisplay(crossDomainWhitelist) {
    var result = "";
    if (crossDomainWhitelist) {
      if (Array.isArray(crossDomainWhitelist)) {
        var data = [];
        crossDomainWhitelist.forEach(function(host) { data.push(host.host); });
        result = data.join(","); } ; }

     else {
      result = "localhost"; } ;


    return result; };








  function formatCrossDomainWhitelistForSaving(crossDomainWhitelist) {
    var result = [];
    crossDomainWhitelist.split(",").forEach(function(host) {
      result.push({ host: host }); });

    return result; };


  mobile.setServiceSettings = function(options, settings, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("settings").header("Content-Type", "application/json");





    log.silly($("New service settings:"));
    log.json("silly", settings);

    channel.patch(JSON.stringify(settings), callback); };


  mobile.getAuthSettings = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("authsettings");




    channel.get(callback); };


  mobile.setAuthSettings = function(options, settings, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("authsettings").header("Content-Type", "application/json");





    log.silly($("New auth settings:"));
    log.json("silly", settings);

    channel.put(JSON.stringify(settings), callback); };


  mobile.getApnsSettings = function(options, callback) {
    mobile.getPushSettings(options, function(err, settings) {
      if (err) {
        callback(err); }
       else {
        var apns = settings.apnsCredentials;
        var result = {
          mode: "none" };


        if (apns.apnsCertificate) {
          if ((apns.endpoint === "gateway.push.apple.com")) {
            result.mode = "prod"; }
           else if ((apns.endpoint === "gateway.sandbox.push.apple.com")) {
            result.mode = "dev"; }  ; } ;



        callback(null, result); } ; }); };




  mobile.setApnsSettings = function(options, settings, callback) {
    var apnsSettings = {
      apnsCredentials: {
        endpoint: "None",
        apnsCertificate: settings.data,
        certificateKey: settings.password } };



    if ((settings.mode === "dev")) {
      apnsSettings.apnsCredentials.endpoint = "gateway.sandbox.push.apple.com"; }
     else if ((settings.mode === "prod")) {
      apnsSettings.apnsCredentials.endpoint = "gateway.push.apple.com"; }  ;


    mobile.patchPushSettings(options, apnsSettings, callback); };


  mobile.getPushSettings = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushsettings");




    channel.get(callback); };


  mobile.patchPushSettings = function(options, settings, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushsettings").header("Content-Type", "application/json");





    log.silly($("patch push settings:"));
    log.json("silly", settings);

    channel.patch(JSON.stringify(settings), callback); };


  mobile.getPushEntity = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushentity");




    channel.get(callback); };


  mobile.waitForPushEnabling = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushentity");




    channel.poll(function(error, body) {
      var retry = false;

      if (error) {
        callback(new Error($("Unable to determine the status of the async operation. Please check the status on the management portal."))); }
       else {
        log.silly($("push entity status"));
        log.json("silly", body);

        var status = body.externalPushEntitySettingsPropertyBag.externalPushEntityState;

        if ((status === "healthy")) {
          callback(); }
         else if ((status === "unhealthy")) {
          callback(new Error($("Operation failed. Please confirm the status on the management portal"))); }
         else {
          retry = true; }  ; } ;



      return retry; }); };



  mobile.setPushEntity = function(options, settings, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("pushentity").header("Content-Type", "application/json");





    log.silly($("push entity settings"));
    log.json("silly", settings);

    channel.put(JSON.stringify(settings), callback); };


  mobile.getPreviews = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("previewfeatures");




    channel.get(callback); };


  mobile.enablePreview = function(options, feature, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("previewfeatures").header("Content-Type", "application/json");





    log.silly($("Enabling preview feature"));
    log.json("silly", feature);

    channel.post(JSON.stringify(feature), callback); };


  mobile.regenerateKey = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("regenerateKey").query("type", options.type);





    channel.post(null, callback); };


  mobile.setKey = function(options, key, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("keys").header("Content-Type", "application/json");





    log.silly($("Setting key"));
    log.json("silly", key);

    channel.put(JSON.stringify(key), callback); };


  mobile.restartService = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("restart");




    channel.post(null, callback); };


  mobile.redeployService = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("redeploy");




    channel.post(null, callback); };


  mobile.getLogs = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("logs");




    if (options.query) {
      options.query.split("&").forEach(function(keyvalue) {
        var kv = keyvalue.split("=");
        if ((kv.length === 2)) {
          channel.query(kv[0], kv[1]); }

         else {
          return callback(new Error($("Invalid format of query parameter"))); } ; }); }


     else {
      if (options.continuationToken) {
        channel.query("continuationToken", options.continuationToken); } ;


      channel.query("$top", (options.top || 10));

      var filter = [];
      if (options.type) {
        filter.push((("Type eq '" + options.type) + "'")); } ;

      if (options.source) {
        filter.push((("Source eq '" + options.source) + "'")); } ;

      if ((filter.length > 0)) {
        channel.query("$filter", filter.join(" and ")); } ; } ;



    channel.get(callback); };


  mobile.listTables = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables");




    channel.get(callback); };


  mobile.getRepositorySharedFolder = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("repository").path("service").path("shared");






    channel.get(callback); };


  mobile.getSharedScripts = function mobile_getSharedScripts__1(options, _) { var files; var __frame = { name: "mobile_getSharedScripts__1", line: 606 }; return __func(_, this, arguments, mobile_getSharedScripts__1, 1, __frame, function __$mobile_getSharedScripts__1() {
      return mobile.getRepositorySharedFolder(options, __cb(_, __frame, 1, 23, function ___(__0, __1) { files = __1;
        return _(null, __.filter(files, function(file) { return (file.name.indexOf(".js", (file.length - 3)) !== -1); })); }, true)); }); };


  mobile.getSharedScript = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("repository").path("service").path("shared").path((options.script.shared.name + ".js"));







    channel.get(callback); };


  mobile.setSharedScript = function(options, script, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("repository").path("service").path("shared").path((options.script.shared.name + ".js")).header("Content-Type", "text/plain").header("If-Match", "*");









    channel.put(script, callback); };


  mobile.loadAllScripts = function mobile_loadAllScripts__2(options, _) { var results; var __frame = { name: "mobile_loadAllScripts__2", line: 639 }; return __func(_, this, arguments, mobile_loadAllScripts__2, 1, __frame, function __$mobile_loadAllScripts__2() {
      return async.parallel({
        table: function table__1(_) { var __frame = { name: "table__1", line: 641 }; return __func(_, this, arguments, table__1, 0, __frame, function __$table__1() { return mobile.getAllTableScripts(options, __cb(_, __frame, 0, 42, _, true)); }); },
        shared: function shared__2(_) { var __frame = { name: "shared__2", line: 642 }; return __func(_, this, arguments, shared__2, 0, __frame, function __$shared__2() { return mobile.getSharedScripts(options, __cb(_, __frame, 0, 43, _, true)); }); },
        scheduler: function scheduler__3(_) { var __frame = { name: "scheduler__3", line: 643 }; return __func(_, this, arguments, scheduler__3, 0, __frame, function __$scheduler__3() { return mobile.getSchedulerScripts(options, __cb(_, __frame, 0, 46, _, true)); }); },
        api: function api__4(_) { var __frame = { name: "api__4", line: 644 }; return __func(_, this, arguments, api__4, 0, __frame, function __$api__4() { return mobile.getCustomApis(options, __cb(_, __frame, 0, 40, _, true)); }); } }, __cb(_, __frame, 1, 24, function ___(__0, __5) { results = __5;


        return _(null, results); }, true)); }); };


  mobile.deleteSharedScript = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("repository").path("service").path("shared").path((options.script.shared.name + ".js")).header("If-Match", "*");








    channel.delete(callback); };




  mobile.getCustomApis = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis");




    channel.get(callback); };


  mobile.createApi = function(options, settings, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").header("Content-Type", "application/json");





    log.silly($("New api settings:"));
    log.json("silly", settings);

    channel.post(JSON.stringify(settings), callback); };


  mobile.getCustomApi = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name));





    channel.get(callback); };


  mobile.setCustomApi = function(options, settings, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name)).header("Content-Type", "application/json");






    log.silly($("Updated api settings:"));
    log.json("silly", settings);

    channel.put(JSON.stringify(settings), callback); };


  mobile.getCustomApiScript = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name)).path("script");






    channel.get(callback); };


  mobile.setCustomApiScript = function(options, script, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name)).path("script").header("Content-Type", "text/plain");







    channel.put(script, callback); };


  mobile.deleteCustomApi = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("apis").path((options.apiname || options.script.api.name));





    channel.delete(callback); };




  mobile.getSchedulerScripts = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs");





    channel.get(callback); };


  mobile.getJob = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path(options.jobname);






    channel.get(callback); };


  mobile.getSchedulerScript = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path(options.script.scheduler.name).path("script");







    channel.get(callback); };


  mobile.setSchedulerScript = function(options, script, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path(options.script.scheduler.name).path("script").header("Content-Type", "text/plain");








    channel.put(script, callback); };


  mobile.deleteSchedulerScript = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path((options.jobname || options.script.scheduler.name));






    channel.delete(callback); };


  mobile.createJob = function(options, job, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").header("Content-Type", "application/json");






    channel.post(job, callback); };


  mobile.setJob = function(options, job, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("scheduler").path("jobs").path(options.jobname).header("Content-Type", "application/json");







    log.silly($("New job settings:"));
    log.json("silly", job);

    channel.put(JSON.stringify(job), callback); };


  mobile.getTableScripts = function(options, table, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(table).path("scripts");






    channel.get(callback); };


  mobile.getTableScript = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.script.table.name).path("scripts").path(options.script.table.operation).path("code");








    channel.get(callback); };


  mobile.setTableScript = function(options, script, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.script.table.name).path("scripts").path(options.script.table.operation).path("code").header("Content-Type", "text/plain");









    channel.put(script, callback); };


  mobile.deleteTableScript = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.script.table.name).path("scripts").path(options.script.table.operation);







    channel.delete(callback); };


  mobile.getAllTableScripts = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var results = [];
    mobile.listTables(options, function(error, tables) {
      if ((error || (tables.length === 0))) {
        return callback(error, tables); } ;


      var resultCount = 0;
      var finalError;
      tables.forEach(function(table) {
        mobile.getTableScripts(options, table.name, function(error, scripts) {
          finalError = (finalError || error);
          if (Array.isArray(scripts)) {
            scripts.forEach(function(script) {
              script.table = table.name;
              results.push(script); }); } ;



          if ((++resultCount == tables.length)) {
            callback(finalError, results); } ; }); }); }); };






  mobile.getTable = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename);





    channel.get(callback); };


  mobile.createTable = function(options, settings, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").header("Content-Type", "application/json");





    log.silly($("Create table:"));
    log.json("silly", settings);

    channel.post(JSON.stringify(settings), callback); };


  mobile.deleteTable = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename);





    channel.delete(callback); };


  mobile.truncateTable = function(options, payload, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("truncate").header("Content-Type", "application/json");







    channel.post(payload, callback); };


  mobile.deleteTableRecord = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("data").query("id", options.recordid);







    channel.delete(callback); };


  mobile.getPermissions = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("permissions");






    channel.get(callback); };


  mobile.updatePermissions = function(options, newPermissions, callback) {
    log.verbose("Subscription", options.subscription);
    mobile.getPermissions(options, function(error, currentPermissions) {
      if (error) {
        return callback(error); } ;


      for (var i in currentPermissions) {
        if (!newPermissions[i]) {
          newPermissions[i] = currentPermissions[i]; } ; };



      log.silly(util.format($("Update table permissions for %s:"), options.tablename));
      log.json("silly", newPermissions);

      var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("permissions").header("Content-Type", "application/json");







      channel.put(JSON.stringify(newPermissions), callback); }); };



  mobile.getScripts = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("scripts");






    channel.get(callback); };


  mobile.getColumns = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("columns");






    channel.get(callback); };


  mobile.addColumn = function(options, column, payload, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("columns").path(column).header("Content-Type", "application/json");








    log.silly(util.format($("Adding column %s:"), column));
    log.json("silly", payload);

    channel.post(JSON.stringify(payload), callback); };


  mobile.deleteColumn = function(options, column, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("columns").path(column);







    channel.delete(callback); };


  mobile.createIndex = function(options, column, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("indexes").path(column);







    channel.put(null, callback); };


  mobile.deleteIndex = function(options, column, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("indexes").path(column);







    channel.delete(callback); };


  mobile.getMobileServiceApplication = function(options, callback) {
    var channel = getAppManagerChannel(options).path((options.servicename + "mobileservice")).header("Content-Type", "application/xml");



    channel.get(callback); };


  mobile.deleteMobileServiceApplication = function(options, callback) {
    var channel = getAppManagerChannel(options).path((options.servicename + "mobileservice")).header("Content-Type", "application/xml");



    channel.delete(function(error, body, res) {
      if (error) {
        log.silly(util.format($("Delete mobile service application error: %s"), JSON.stringify(error, null, 2)));
        return callback(error); } ;


      mobile.trackAsyncOperation(options, res.headers["x-ms-request-id"], function(error) {
        log.silly(util.format($("Delete mobile service application result: %s"), (error ? JSON.stringify(error, null, 2) : "ok")));
        callback(error); }); }); };




  mobile.getData = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("tables").path(options.tablename).path("data");






    if (options.query) {
      options.query.split("&").forEach(function(keyvalue) {
        var kv = keyvalue.split("=");
        if ((kv.length === 2)) {
          channel.query(kv[0], kv[1]); }

         else {
          return callback(new Error($("Invalid format of query parameter"))); } ; }); }


     else {
      channel.query("$top", (options.top || 10));

      if (options.skip) {
        channel.query("$skip", options.skip); } ; } ;



    channel.get(callback); };


  mobile.trackAsyncOperation = function(options, requestId, callback) {
    var channel = getOperationChannel(options, requestId);

    var errorCounter = 0;
    channel.poll(function(error, body) {
      var retry = false;

      if (error) {
        if ((++errorCounter < 3)) {
          retry = true; }
         else {
          callback(new Error($("Unable to determine the status of the async operation. Please check the status on the management portal."))); } ; }

       else {
        log.silly(util.format($("Operation status: %s"), body.Status));

        if ((body.Status === "Failed")) {
          callback(new Error($("Operation failed. Please confirm the status on the management portal"))); }
         else if ((body.Status === "InProgress")) {
          retry = true; }
         else if ((body.Status === "Succeeded")) {
          callback(); }
         else {
          callback(new Error($(("Unexpected response from Microsoft Azure. " + "Please confirm the status of the mobile service in the management portal")))); }   ; } ;




      return retry; }); };



  var resourceTypeView = {
  "Microsoft.WindowsAzure.MobileServices.MobileService": "Mobile service",
  "Microsoft.WindowsAzure.SQLAzure.DataBase": "SQL database",
  "Microsoft.WindowsAzure.SQLAzure.Server": "SQL server" };


  mobile.getFlatApplicationDescription = function(description) {
    var result = {
      State: description.State,
      Name: description.Name,
      Label: description.Label,
      Resources: [] };


    function flatten(resource) {
      var list;
      if (Array.isArray(resource)) {
        list = resource; } else {
        if ((typeof resource == "object")) {
          list = [resource,]; } };

      if (list) {
        list.forEach(function(item) {
          result.Resources.push(item);
          item.TypeView = resourceTypeView[item.Type];
          item.NameView = (item.Label || item.Name);
          if ((typeof item.FailureCode === "string")) {
            var match = item.FailureCode.match(/<Message\>([^<]*)<\/Message\>/);
            item.Error = (match ? match[1] : item.FailureCode); } ; }); } ; };





    flatten(description.InternalResources.InternalResource);
    flatten(description.ExternalResources.ExternalResource);

    return result; };


  mobile.deleteService = function(options, callback) {
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename);



    if (options.deleteData) {
      channel.query("deletedata", "true"); } ;


    if (options.deleteNotificationHubNamespace) {
      channel.query("deleteServiceBusNamespace", "true"); } ;


    channel.delete(function(error, body, response) {
      log.silly($("Delete mobile service:"));
      log.silly(JSON.stringify(error, null, 2));
      log.silly(JSON.stringify(body, null, 2));


      if (((error && response) && (response.statusCode === 404))) {
        error = null; } ;

      callback(error); }); };



  mobile.deleteSqlServer = function(options, resource, callback) {
    var sqlService = utils.createSqlClient(profile.current.getSubscription(options.subscription));
    sqlService.servers.deleteMethod(resource.Name, callback); };


  mobile.register = function mobile_register__3(options, _) { var subscription, progress; var __frame = { name: "mobile_register__3", line: 1267 }; return __func(_, this, arguments, mobile_register__3, 1, __frame, function __$mobile_register__3() {
      subscription = profile.current.getSubscription(options.subscription);
      progress = cli.interaction.progress($("Registering for mobile services")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$mobile_register__3() {


            return subscription.registerAsmProvider("mobileservice", __cb(_, __frame, 5, 19, function __$mobile_register__3() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$mobile_register__3() {


              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$mobile_register__3() { _(); }); }); }); };



  mobile.getDomains = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames");




    channel.get(callback); };


  mobile.addDomain = function(options, domain, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain);





    channel.post(null, callback); };


  mobile.deleteDomain = function(options, domain, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain);





    channel.delete(callback); };


  mobile.getSslState = function(options, domain, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain).path("ssl");






    channel.get(callback); };


  mobile.enableSsl = function(options, domain, thumbprint, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain).path("ssl").path(thumbprint);







    channel.post(null, callback); };


  mobile.disableSsl = function(options, domain, thumbprint, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("hostnames").path(domain).path("ssl").path(thumbprint);







    channel.delete(callback); };


  mobile.getCertificates = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("certificates");




    channel.get(callback); };


  mobile.addCertificate = function(options, certificate, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("certificates").header("Content-Type", "application/json");





    channel.post(JSON.stringify(certificate), callback); };


  mobile.deleteCertificate = function(options, thumbprint, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("certificates").path(thumbprint);





    channel.delete(callback); };


  var createMobileServiceApplicationTemplate = (((((("<?xml version=\"1.0\" encoding=\"utf-8\"?>" + "<Application xmlns=\"http://schemas.microsoft.com/windowsazure\">") + "<Name>##name##</Name>") + "<Label>##label##</Label>") + "<Description>##description##</Description>") + "<Configuration>##spec##</Configuration>") + "</Application>");








  mobile.createService = function(options, callback) {
    var subscription = profile.current.getSubscription(options.subscription);

    var channel = getAppManagerChannel(options).header("Content-Type", "application/xml");


    var serverRefName = ("ZumoSqlServer_" + uuid.v4().replace(/-/g, ""));
    var serverSpec;

    if (options.sqlServer) {

      serverSpec = {
        Name: serverRefName,
        Type: "Microsoft.WindowsAzure.SQLAzure.Server",
        URI: (((subscription.sqlManagementEndpointUrl + subscription.id) + "/services/sqlservers/servers/") + options.sqlServer) }; }


     else {

      serverSpec = {
        ProvisioningParameters: {
          AdministratorLogin: options.username,
          AdministratorLoginPassword: options.password,
          Location: options.sqlLocation },

        ProvisioningConfigParameters: {
          FirewallRules: [{

            Name: "AllowAllWindowsAzureIps",
            StartIPAddress: "0.0.0.0",
            EndIPAddress: "0.0.0.0" },] },



        Version: "1.0",
        Name: serverRefName,
        Type: "Microsoft.WindowsAzure.SQLAzure.Server" }; } ;



    var dbRefName = ("ZumoSqlDatabase_" + uuid.v4().replace(/-/g, ""));
    var dbSpec;

    if (options.sqlDb) {


      dbSpec = {
        Name: dbRefName,
        Type: "Microsoft.WindowsAzure.SQLAzure.DataBase",
        URI: (((((subscription.sqlManagementEndpointUrl + subscription.id) + "/services/sqlservers/servers/") + options.sqlServer) + "/databases/") + options.sqlDb) }; }



     else {


      dbSpec = {
        ProvisioningParameters: {
          Name: (options.servicename + "_db"),
          Edition: "WEB",
          MaxSizeInGB: "1",
          DBServer: {
            ResourceReference: (serverRefName + ".Name") },

          CollationName: "SQL_Latin1_General_CP1_CI_AS" },

        Version: "1.0",
        Name: dbRefName,
        Type: "Microsoft.WindowsAzure.SQLAzure.DataBase" }; } ;



    var spec = {
      SchemaVersion: "2012-05.1.0",
      Location: "West US",
      ExternalResources: { },
      InternalResources: {
        ZumoMobileService: {
          ProvisioningParameters: {
            Name: options.servicename,
            Location: options.location,
            Platform: options.backend,
            ProvisioningVersion: "2014-1-1",
            EnableExternalPush: options.enhancedPush },

          ProvisioningConfigParameters: {
            Server: {
              StringConcat: [{

                ResourceReference: (serverRefName + ".Name")

              },subscription.sqlServerHostnameSuffix,] },


            Database: {
              ResourceReference: (dbRefName + ".Name") },

            AdministratorLogin: options.username,
            AdministratorLoginPassword: options.password },

          Version: "2012-05-21.1.0",
          Name: "ZumoMobileService",
          Type: "Microsoft.WindowsAzure.MobileServices.MobileService" } } };




    if (options.sqlServer) {

      spec.ExternalResources[serverRefName] = serverSpec; }
     else {

      spec.InternalResources[serverRefName] = serverSpec; } ;


    if (options.sqlDb) {
      spec.ExternalResources[dbRefName] = dbSpec; }
     else {

      spec.InternalResources[dbRefName] = dbSpec; } ;


    log.silly($("New mobile service application specification:"));
    log.silly(JSON.stringify(spec, null, 2));

    var encodedSpec = new Buffer(JSON.stringify(spec)).toString("base64");
    var payload = createMobileServiceApplicationTemplate.replace("##name##", (options.servicename + "mobileservice")).replace("##label##", options.servicename).replace("##description##", options.servicename).replace("##spec##", encodedSpec);





    log.silly($("New mobile service request body:"));
    log.silly(payload);

    var progress = cli.interaction.progress($("Creating mobile service"));
    try {
      channel.post(payload, function(error, body, res) {
        if (error) {
          progress.end();
          return callback(error); } ;


        log.silly(util.format($("Create mobile app HTTP response: %s"), res.statusCode));
        log.silly(JSON.stringify(res.headers, null, 2));


        mobile.trackAsyncOperation(options, res.headers["x-ms-request-id"], function(error) {
          if (error) {
            progress.end();
            return callback(error); } ;



          var channel = getAppManagerChannel(options).path((options.servicename + "mobileservice"));


          channel.get(function(error, body) {
            progress.end();
            if (error) {
              return callback(error); } ;


            if (log.format().json) {
              log.json(body); }
             else {
              log.silly(JSON.stringify(body, null, 2));
              var flat = mobile.getFlatApplicationDescription(body);
              var logger = ((flat.State == "Healthy") ? log.info : log.error);
              log.silly(JSON.stringify(flat, null, 2));
              logger(util.format($("Overall application state: %s"), flat.State));
              flat.Resources.forEach(function(resource) {
                logger((((resource.TypeView + ((resource.NameView ? ((" (" + resource.NameView) + ")") : ""))) + " state: ") + resource.State));
                if (resource.Error) {
                  logger(resource.Error); } ; }); } ;




            callback(((body.State === "Healthy") ? null : new Error($("Creation of a mobile service failed")))); }); }); });




    } catch (e) {
      progress.end();
      throw e; }; };



  mobile.command("locations").description($("List available mobile service locations")).option("-s, --subscription <id>", $("the subscription id")).execute(function __4(options, _) { var progress, result; var __frame = { name: "__4", line: 1583 }; return __func(_, this, arguments, __4, 1, __frame, function __$__4() {



      progress = cli.interaction.progress($("Getting mobile service locations")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__4() {


            return mobile.getRegions(options, __cb(_, __frame, 4, 28, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__4() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__4() {


          cli.interaction.formatOutput(result, function(locations) {
            locations.forEach(function(region, index) {
              log.info((region.region + (((index === 0) ? " (default)" : "")))); }); }); _(); }); }); }); });




  mobile.command("create [servicename] [username] [password]").usage("[options] [servicename] [sqlAdminUsername] [sqlAdminPassword]").description($("Create a new mobile service")).option("-r, --sqlServer <sqlServer>", $("use existing SQL server")).option("-d, --sqlDb <sqlDb>", $("use existing SQL database")).option("-l, --location <location>", $("create the service in a particular location; run azure mobile locations to get available locations")).option("--sqlLocation <location>", $("create the SQL server in a particular location; defaults to mobile service location")).option("-s, --subscription <id>", $("the subscription id")).option("-b, --backend <backend>", $("backend of mobile service. \"node\" and \"dotnet\" are examples.")).option("-p, --push <push>", $("type of push; \"nh\" or \"legacy\" are allowed. \"nh\" will soon be the default for node service. ignored for dotnet services.")).execute(function __5(servicename, username, password, options, _) { var result;




































































    function isPasswordValid(username, password) {








      var matches = 0;
      [new RegExp("[A-Z]"),new RegExp("[a-z]"),new RegExp("[0-9]"),new RegExp("[\\~\\`\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\-\\+\\=\\{\\[\\}\\]\\|\\\\:\\;\\\"\\'\\<\\,\\>\\.\\?\\/]"),].forEach(function(regex) {




        if (password.match(regex)) {
          matches++; }; });


      if ((((password.length >= 8) && (password.indexOf(username) == -1)) && (matches > 2))) {
        return true; }
       else {
        log.warn($("Password must:"));
        log.warn($("- be 8 or more characters long,"));
        log.warn($("- not contain the username,"));
        log.warn($("- contain characters from at least 3 of the categories:"));
        log.warn($("  - uppercase letter [A-Z],"));
        log.warn($("  - lowercase letter [a-z],"));
        log.warn($("  - digit [0-9],"));
        log.warn($("  - special character (e.g. !@#$%^&)."));
        return false; } ; };



    function isUsernameValid(username) {
      if ((username.length > 0)) {
        return true; }
       else {
        log.warn($("User name cannot be empty"));
        return false; } ; }; var __frame = { name: "__5", line: 1609 }; return __func(_, this, arguments, __5, 4, __frame, function __$__5() { if (!options.backend) { options.backend = "Node"; } else { if (((options.backend.toLowerCase() !== "node") && (options.backend.toLowerCase() !== "dotnet"))) { return _(new Error("Backend can only have two values: \"Node\" or \"DotNet\"")); } ; } ; if ((options.sqlDb && !options.sqlServer)) { return _(new Error($("To use an existing SQL database, you must specify the name of an existing SQL server using the --sqlServer parameter."))); } ; options.enhancedPush = true; if ((options.backend.toLowerCase() === "node")) { if ((!options.push || (((options.push.toLowerCase() !== "legacy") && (options.push.toLowerCase() !== "nh"))))) { return _(new Error("-p/--push is required and can only have two values: \"legacy\" or \"nh\"")); } ; options.enhancedPush = ((options.push.toLowerCase() === "nh")); } ; return (function __$__5(__then) { if (!options.location) { return mobile.getRegions(options, __cb(_, __frame, 26, 32, function ___(__0, __1) { result = __1; if (((!Array.isArray(result) || (result.length === 0)) || !result[0].region)) { return _(new Error($("Unable to determine the default mobile service location."))); } ; options.location = result[0].region; __then(); }, true)); } else { __then(); } ; })(function __$__5() { options.sqlLocation = (options.sqlLocation || options.location); return cli.interaction.promptIfNotGiven($("Mobile service name: "), servicename, __cb(_, __frame, 34, 48, function ___(__0, __2) { options.servicename = __2; if (((options.servicename.length < 2) || (options.servicename.length > 48))) { return _(new Error($("Service name must be between 2 and 48 characters."))); } else { if (!options.servicename.match(/^[a-zA-Z][0-9a-zA-Z-]*[0-9a-zA-Z]$/)) { return _(new Error($("Service name must start with a letter, contain only letters, numbers, and hyphens, and end with a letter or number."))); } ; } ; return cli.interaction.promptIfNotGiven($("SQL administrator user name: "), username, __cb(_, __frame, 42, 45, function ___(__0, __3) { options.username = __3; if (!isUsernameValid(options.username)) { return _(new Error($("Invalid username"))); } ; return (function __$__5(__then) { if (options.sqlServer) { return cli.interaction.promptPasswordOnceIfNotGiven($("SQL administrator password: "), password, __cb(_, __frame, 48, 47, function ___(__0, __4) { options.password = __4; __then(); }, true)); } else { return cli.interaction.promptPasswordIfNotGiven($("SQL administrator password: "), password, __cb(_, __frame, 50, 47, function ___(__0, __5) { options.password = __5; __then(); }, true)); } ; })(function __$__5() { if (!isPasswordValid(options.username, options.password)) { return _(new Error($("Invalid password"))); } ; return mobile.register(options, __cb(_, __frame, 56, 17, function __$__5() { return mobile.createService(options, __cb(_, __frame, 57, 17, function __$__5() { _(); }, true)); }, true)); }); }, true)); }, true)); }); }); });





  mobile.command("delete [servicename] [username] [password]").description($("Delete a mobile service")).option("-d, --deleteData", $("delete all data from the database")).option("-a, --deleteAll", $("delete all data, SQL database, and SQL server")).option("-n, --deleteNotificationHubNamespace", $("delete associated Notification Hub namespace and entities")).option("-s, --subscription <id>", $("the subscription id")).option("-q, --quiet", $("do not prompt for confirmation")).execute(function __6(servicename, username, password, options, _) { var prompt, progress, result, resources, flat, proceed, success; var __frame = { name: "__6", line: 1720 }; return __func(_, this, arguments, __6, 4, __frame, function __$__6() {








      if (options.deleteAll) {
        prompt = $("with all data, SQL database, and the SQL server");
        options.deleteSqlDb = options.deleteData = true; } else {
        if (options.deleteSqlDb) {
          prompt = $("with all data and the SQL database, but leave SQL server intact");
          options.deleteData = true; } else {
          if (options.deleteData) {
            prompt = $("with all data but leave SQL database and SQL server intact"); }
           else {
            prompt = $("but leave all data, SQL database, and SQL server intact"); } ; } ; } ;


      if (options.deleteNotificationHubNamespace) {
        prompt += $(" and delete associated Notification Hub Namespaces and its entities"); } ;


      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 18, 32, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress($("Getting mobile service details")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {


              return mobile.getMobileServiceApplication(options, __cb(_, __frame, 23, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__6() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__6() {


            resources = { };
            flat = mobile.getFlatApplicationDescription(result);
            log.silly(JSON.stringify(flat, null, 2));
            flat.Resources.forEach(function(resource) {
              if (!log.format().json) {
                log.data(resource.TypeView, (resource.NameView ? resource.NameView.green : "N/A".green)); } ;


              resources[resource.Type] = resource; }); return (function __$__6(__then) {


              if (!options.quiet) {
                return cli.interaction.confirm(util.format($("Do you want to delete the mobile service %s? [y/n]: "), prompt), __cb(_, __frame, 40, 42, function ___(__0, __3) { proceed = __3;
                  if (!proceed) {
                    log.info($("Deletion cancelled with no changes made.")); return _(null); } ; __then(); }, true)); } else { __then(); } ; })(function __$__6() {





              progress = cli.interaction.progress($("Deleting mobile service")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {

                    return mobile.deleteService(options, __cb(_, __frame, 50, 19, __then, true)); }); })(function ___(e, __result) { __catch(function __$__6() { if (e) {

                      progress.end();
                      log.error($("Failed to delete the mobile service."));
                      if (options.deleteAll) {
                        log.error($("The deletion of the SQL server was cancelled.")); } ;

                      return _((e)); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__6() {



                  progress.end();
                  log.info($("Deleted mobile service."));


                  success = true; return (function __$__6(__then) {
                    if (options.deleteAll) {
                      progress = cli.interaction.progress($("Deleting SQL server")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {

                            return mobile.deleteSqlServer(options, resources["Microsoft.WindowsAzure.SQLAzure.Server"], __cb(_, __frame, 69, 21, __then, true)); }); })(function ___(e, __result) { __catch(function __$__6() { if (e) {


                              progress.end();
                              success = false;
                              log.error($("Failed to delete SQL server"));
                              log.error(e); __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__6() {

                          progress.end();

                          if (success) {
                            log.info($("Deleted SQL server")); } ; __then(); }); }); } else { __then(); } ; })(function __$__6() {




                    progress = cli.interaction.progress($("Deleting mobile application")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__6() {

                          return mobile.deleteMobileServiceApplication(options, __cb(_, __frame, 87, 19, __then, true)); }); })(function ___(e, __result) { __catch(function __$__6() { if (e) {

                            progress.end();
                            log.error($("Failed to delete mobile application."));
                            return _((e)); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__6() {


                        progress.end();

                        log.info($("Deleted mobile application.")); _(); }); }); }); }); }); }); }); }); }, true)); }); });


  var scaleInformation = {
    tier1: { name: "free", maxInstances: 1, oldKey: "free" },
    tier2: { name: "basic", maxInstances: 6, oldKey: "standard" },
    tier3: { name: "standard", maxInstances: 25, oldKey: "premium" } };


  function displayScaleSettings(scalesettings) {
    log.data("tier", scaleInformation[scalesettings.tier].name.green);
    log.data("numberOfInstances", scalesettings.numberOfInstances.toString().green); };


  function findScale(scaleValueOrDisplayName, useOldKey) {
    scaleValueOrDisplayName = scaleValueOrDisplayName.toLowerCase();

    var scale = scaleInformation[scaleValueOrDisplayName];
    if (!__.isUndefined(scale)) {
      return scaleValueOrDisplayName; } ;


    var scaleValue, comparisonValue;

    __.every(scaleInformation, function(value, key) {
      comparisonValue = (useOldKey ? value.oldKey : value.name);
      if ((comparisonValue === scaleValueOrDisplayName)) {
        scaleValue = key;
        return false; } ;

      return true; });


    return scaleValue; };


  mobile.command("list").usage("[options]").description($("List your mobile services")).option("-s, --subscription <id>", $("the subscription id")).execute(function __7(options, _) { var progress, result; var __frame = { name: "__7", line: 1856 }; return __func(_, this, arguments, __7, 1, __frame, function __$__7() {




      progress = cli.interaction.progress($("Getting list of mobile services")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__7() {


            return mobile.listServices(options, __cb(_, __frame, 4, 28, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__7() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__7() {


          cli.interaction.formatOutput(result, function(services) {
            if ((services && (services.length > 0))) {
              log.table(services, function(row, s) {
                row.cell($("Name"), s.name);
                row.cell($("State"), s.state);
                row.cell($("URL"), s.applicationUrl); }); }

             else {
              log.info($("No mobile services created yet. You can create new mobile services using the 'azure mobile create' command.")); } ; }); _(); }); }); }); });




  mobile.command("show [servicename]").usage("[servicename] [options]").description($("Show details for a mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __8(servicename, options, _) {








    function ensuredServiceName(callback) {
      var results = { };
      var resultCount = 0;

      var progress = cli.interaction.progress($("Getting information"));

      function tryFinish() {
        if ((++resultCount < 3)) {
          return; } ;


        progress.end();

        log.silly($("Results:"));
        log.silly(JSON.stringify(results, null, 2));

        if (log.format().json) {
          log.json(results); }
         else {
          if (results.application) {
            log.info($("Mobile application").blue);
            var flat = mobile.getFlatApplicationDescription(results.application);
            log.silly(JSON.stringify(flat, null, 2));
            log.data($("status"), ((flat.State == "Healthy") ? $("Healthy").green : flat.State.red));
            flat.Resources.forEach(function(resource) {
              log.data((resource.TypeView + " name"), (resource.NameView ? resource.NameView.green : "N/A".green));
              if (resource.Error) {
                log.data((resource.TypeView + " status"), resource.State.red);
                log.data((resource.TypeView + " error"), resource.Error.red); }

               else {
                log.data((resource.TypeView + " status"), resource.State.green); } ; }); } ;




          if (results.service) {
            log.info("Mobile service".blue);
            ["name","state","applicationUrl","applicationKey","masterKey","scalesettings","region",].forEach(function(item) {

              if (results.service[item]) {
                log.data(item, results.service[item].toString().green); } ; });



            if (nodeFilter(results.service)) {
              if ((results.service.tables.length > 0)) {
                var tables = "";
                results.service.tables.forEach(function(table) { tables += ((((tables.length > 0) ? "," : "")) + table.name); });
                log.data("tables", tables.green); }
               else {
                log.info($("No tables are created. Use azure mobile table command to create tables.")); } ; } ; } ;




          if (results.scalesettings) {
            log.info("Scale".blue);
            displayScaleSettings(results.scalesettings); } ; } ;



        if ((!results.service && !results.application)) {
          return callback((("Cannot obtain informaton about the service " + options.servicename) + ". Use azure mobile list to check if it exists.")); }

         else {
          return callback(); } ; };



      function createCallback(name) {
        return function(error, result) {
          log.silly(name, error);
          if (!error) {
            results[name] = result; } ;


          if ((name === "service")) {
            if (result) {
              mobile.getScaleSettings(options, createCallback("scalesettings")); }
             else {
              resultCount++; } ; } ;



          tryFinish(); }; };



      try {
        mobile.getService(options, createCallback("service"));
        mobile.getMobileServiceApplication(options, createCallback("application"));
      } catch (e) {
        progress.end();
        callback(e); }; }; var __frame = { name: "__8", line: 1882 }; return __func(_, this, arguments, __8, 2, __frame, function __$__8() { return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1; return ensuredServiceName(__cb(_, __frame, 3, 10, function __$__8() { _(); }, true)); }, true)); }); });




  mobile.command("restart [servicename]").description($("Restart a mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __9(servicename, options, _) { var progress, result; var __frame = { name: "__9", line: 1989 }; return __func(_, this, arguments, __9, 2, __frame, function __$__9() {



      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress(util.format($("Restarting mobile service: '%s'"), options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__9() {


              return mobile.restartService(options, __cb(_, __frame, 6, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__9() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__9() {


            if (log.format().json) {
              log.json({ }); }
             else {
              log.info($("Service was restarted.")); } ; _(); }); }); }, true)); }); });



  mobile.command("redeploy [servicename]").description($("Redeploy a mobile service with most recent runtime version")).option("-s, --subscription <id>", $("the subscription id")).execute(function __10(servicename, options, _) { var progress, result; var __frame = { name: "__10", line: 2010 }; return __func(_, this, arguments, __10, 2, __frame, function __$__10() {



      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress(util.format($("Redeploying mobile service: '%s'"), options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__10() {


              return mobile.redeployService(options, __cb(_, __frame, 6, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__10() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__10() {


            if (log.format().json) {
              log.json({ }); }
             else {
              log.info($("Service was redeployed.")); } ; _(); }); }); }, true)); }); });



  var mobileKey = mobile.category("key").description($("Commands to manage your Mobile Service keys"));


  var keyTypes = ["application","master",];

  function promptKeyFields(options, servicename, type, _) { var __frame = { name: "promptKeyFields", line: 2033 }; return __func(_, this, arguments, promptKeyFields, 3, __frame, function __$promptKeyFields() {
      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 26, function ___(__0, __1) { options.servicename = __1;
        return cli.interaction.chooseIfNotGiven($("Key type: "), $("Retrieving choices"), type, function(cb) {

          cb(null, keyTypes); }, __cb(_, __frame, 2, 35, function ___(__0, __2) { options.type = __2;


          if (!__.contains(keyTypes, options.type)) {
            return _(new Error($("The key type must be 'application' or 'master'."))); } ; _(); }, true)); }, true)); }); };



  mobileKey.command("regenerate [servicename] [type]").description($("Regenerate the mobile service key")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __11(servicename, type, options, _) { var result, progress; var __frame = { name: "__11", line: 2048 }; return __func(_, this, arguments, __11, 3, __frame, function __$__11() {



      return promptKeyFields(options, servicename, type, __cb(_, __frame, 1, 10, function __$__11() {


        progress = cli.interaction.progress($("Regenerating key")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__11() {


              return mobile.regenerateKey(options, __cb(_, __frame, 7, 28, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__11() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__11() {


            cli.interaction.formatOutput(result, function(keyData) {
              log.info(util.format($("New %s key is %s"), options.type, keyData[(options.type + "Key")])); }); _(); }); }); }, true)); }); });



  mobileKey.command("set [servicename] [type] [value]").description($("Set the mobile service key to a specific value")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __12(servicename, type, value, options, _) { var result, progress; var __frame = { name: "__12", line: 2068 }; return __func(_, this, arguments, __12, 4, __frame, function __$__12() {



      return promptKeyFields(options, servicename, type, __cb(_, __frame, 1, 10, function __$__12() {
        return cli.interaction.promptIfNotGiven($("Key value: "), value, __cb(_, __frame, 2, 42, function ___(__0, __1) { options.value = __1;


          progress = cli.interaction.progress($("Setting key")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__12() {


                return mobile.setKey(options, { Type: options.type, Value: options.value }, __cb(_, __frame, 8, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__12() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__12() {


              cli.interaction.formatOutput(result, function(keyData) {
                log.info(util.format($("New %s key is %s"), options.type, keyData[(options.type + "Key")])); }); _(); }); }); }, true)); }, true)); }); });



  mobile.command("log [servicename]").usage("[options] [servicename]").description($("Get mobile service logs")).option("-r, --query <query>", $("log query; takes precedence over --type, --source, --continuationToken, and --top")).option("-t, --type <type>", $("filter entry by type")).option("--source <source>", $("filter entry by source")).option("-c, --continuationToken <token>", $("show logs starting from the specified continuation token")).option("-p, --top <top>", $("return the first <top> number of remaining rows")).option("-s, --subscription <id>", $("the subscription id")).execute(function __13(servicename, options, _) { var result, progress; var __frame = { name: "__13", line: 2095 }; return __func(_, this, arguments, __13, 2, __frame, function __$__13() {









      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;


        progress = cli.interaction.progress($("Retrieving logs")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__13() {


              return mobile.getLogs(options, __cb(_, __frame, 7, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__13() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__13() {


            cli.interaction.formatOutput(result, function(logs) {
              if (((logs && logs.results) && (logs.results.length > 0))) {
                logs.results.forEach(function(entry) {
                  log.data("", "");

                  for (var i in entry) {
                    log.data(i, entry[i]); }; });



                log.data("", "");
                if (logs.continuationToken) {
                  log.data($("Continuation token to receive the next result set:"), logs.continuationToken.green); } ; }

               else {
                log.info($("There are no matching log entries.")); } ; }); _(); }); }); }, true)); }); });




  mobile.command("recover [unhealthyservicename] [healthyservicename]").usage("[options] [unhealthyservicename] [healthyservicename]").description($("Recovers an unhealthy mobile service using the capacity reserved by a healthy mobile service in a different region.")).option("-q, --quiet", $("do not prompt for confirmation of recovery")).option("-s, --subscription <id>", $("the subscription id")).execute(function(unhealthyservice, healthyservice, options, callback) {





    if (unhealthyservice) {
      ensuredUnhealthyServiceName(unhealthyservice); }
     else {
      promptString($("Name of the unhealthy mobile service to recover: "), ensuredUnhealthyServiceName); } ;


    function ensuredUnhealthyServiceName(unhealthyservice) {
      options.servicename = unhealthyservice;

      if (healthyservice) {
        ensuredHealthyServiceName(healthyservice); }
       else {
        promptString($("Name of the healthy mobile service to use for capacity: "), ensuredHealthyServiceName); } ;


      function ensuredHealthyServiceName(healthyservice) {
        options.targetservicename = healthyservice;

        if (options.quiet) {
          doProceed(true); }
         else {
          cli.confirm(util.format($("Warning: this action will use the capacity from the mobile service '%s' and delete it. Do you want to recover the mobile service '%s'? [y/n]: "), healthyservice), doProceed); } ;


        function doProceed(decision) {
          if (!decision) {
            log.info($("Recovery terminated with no changes made"));
            callback(); }
           else {
            var progress = cli.interaction.progress($("Performing recovery"));
            mobile.recover(options, function(error) {
              if (error) {
                progress.end();
                callback(error); }
               else {
                progress = cli.interaction.progress($("Cleaning up"));
                options.servicename = healthyservice;
                mobile.deleteMobileServiceApplication(options, function(error) {
                  progress.end();
                  if (error) {
                    callback(error); }

                   else {
                    log.info($("Recovery complete"));
                    callback(); } ; }); } ; }); } ; }; }; }; });










  mobile.command("migrate [sourceservicename] [destinationservicename]").usage("[options] [sourceservicename] [destinationservicename]").description($("Migrates the source mobile service using the capacity reserved by the destination mobile service in a different region. This command is for disaster recover scenarios and it may result in up to 30 minutes of downtime as the migration completes.")).option("-q, --quiet", $("do not prompt for confirmation of migration")).option("-s, --subscription <id>", $("the subscription id")).execute(function(sourceservicename, destinationservicename, options, callback) {





    if (sourceservicename) {
      ensuredSourceServiceName(sourceservicename); }
     else {
      promptString($("Name of the source mobile service to migrate: "), ensuredSourceServiceName); } ;


    function ensuredSourceServiceName(sourceservice) {
      options.servicename = sourceservice;

      if (destinationservicename) {
        ensuredDestinationServiceName(destinationservicename); }
       else {
        promptString($("Name of the destination mobile service to use for capacity: "), ensuredDestinationServiceName); } ;


      function ensuredDestinationServiceName(destinationservice) {
        options.targetservicename = destinationservice;

        if (options.quiet) {
          doProceed(true); }
         else {
          cli.confirm(util.format($("Warning: this action will use the capacity from the mobile service '%s' and delete it and the host name for '%s' may not resolve for up to 30 minutes. Do you want to migrate the mobile service '%s'? [y/n]: "), destinationservice, sourceservice, sourceservice), doProceed); } ;



        function doProceed(decision) {
          if (!decision) {
            log.info($("Migration canceled with no changes made"));
            callback(); }
           else {
            var progress = cli.interaction.progress($("Performing migration"));
            mobile.migrate(options, function(error, body) {
              progress.end();
              if (error) {
                callback(error); }
               else {
                progress = cli.interaction.progress(util.format($("Migration with id '%s' started. The migration may take several minutes to complete."), body));
                options.orchestrationId = body;
                mobile.waitForMigration(options, function(error) {
                  progress.end();
                  if (error) {
                    callback(error);
                    return; } ;

                  progress = cli.interaction.progress($("Cleaning up"));
                  options.servicename = destinationservice;
                  mobile.deleteMobileServiceApplication(options, function(error) {
                    progress.end();
                    if (error) {
                      callback(error); }

                     else {
                      log.info($("Migration complete. It may take 30 minutes for DNS to resolve to the migrated site."));
                      callback(); } ; }); }); } ; }); } ; }; }; }; });











  mobile.waitForMigration = function(options, callback) {
    log.verbose("Subscription", options.subscription);
    var channel = getMobileChannel(options).path("mobileservices").path(options.servicename).path("migrate").query("operationId", options.orchestrationId);





    function pollMigration() {
      channel.poll(function(error, body) {
        var retry = false;

        if (error) {
          callback(new Error($("Unable to determine the status of the async operation. Please check the status on the management portal."))); }
         else {
          var status = body;

          log.silly($("Migration status"));
          log.json("silly", status);

          if ((status === "Completed")) {
            callback(); }
           else if ((status === "Failed")) {
            callback(new Error($("Operation failed. Please confirm the status on the management portal."))); }
           else {
            retry = true; }  ; } ;



        return retry; }); };





    var sleepTime = (channel.azureService.longRunningOperationRetryTimeout * 2);
    setTimeout(pollMigration, sleepTime); };


  var mobileConfig = mobile.category("config").description($("Commands to manage your Mobile Service configuration"));


  mobileConfig.command("list [servicename]").usage("[options] [servicename]").description($("Show your mobile service configuration settings")).option("-s, --subscription <id>", $("the subscription id")).execute(function __14(servicename, options, _) { var progress, results;





























    function displayConfiguration(results) {
      var settings = { };
      ["dynamicSchemaEnabled","microsoftAccountClientSecret","microsoftAccountClientId","microsoftAccountPackageSID","facebookClientId","facebookClientSecret","twitterClientId","twitterClientSecret","googleClientId","googleClientSecret","apns","crossDomainWhitelist","gcm",].forEach(function(name) {













        settings[name] = $("Unable to obtain the value of this setting"); });


      if (results.service) {
        if ((typeof results.service.dynamicSchemaEnabled == "boolean")) {
          settings.dynamicSchemaEnabled = results.service.dynamicSchemaEnabled.toString(); }
         else {
          settings.dynamicSchemaEnabled = $("Not configured"); } ;


        settings.crossDomainWhitelist = formatCrossDomainWhitelistForDisplay(results.service.crossDomainWhitelist); } ;


      if (results.live) {
        settings.microsoftAccountClientSecret = (results.live.secret || $("Not configured"));
        settings.microsoftAccountClientId = (results.live.appId || $("Not configured"));
        settings.microsoftAccountPackageSID = (results.live.packageSid || $("Not configured")); } ;


      if (results.apns) {
        settings.apns = (results.apns.mode || $("Not configured")); } ;


      if (results.gcm) {
        settings.gcm = (results.gcm.apiKey || $("Not configured")); } ;


      if (Array.isArray(results.auth)) {
        ["twitter","facebook","google",].forEach(function(provider) {
          settings[(provider + "ClientId")] = $("Not configured");
          settings[(provider + "ClientSecret")] = $("Not configured"); });


        results.auth.forEach(function(creds) {
          settings[(creds.provider + "ClientId")] = creds.appId;
          settings[(creds.provider + "ClientSecret")] = creds.secret; }); } ;



      log.table(settings, function(row, item) {
        row.cell("Setting", item);
        if (((settings[item] === undefined) || (settings[item] === $("Not configured")))) {
          row.cell("Value", $("Not configured").blue); }
         else if ((settings[item] === $("Unable to obtain the value of this setting"))) {
          row.cell("Value", settings[item].red); }
         else {
          row.cell("Value", settings[item].green); }  ; }); }; var __frame = { name: "__14", line: 2305 }; return __func(_, this, arguments, __14, 2, __frame, function __$__14() { return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1; progress = cli.interaction.progress($("Getting mobile service configuration")); results = { }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__14() { return mobile.getServiceSettings(options, __cb(_, __frame, 7, 37, function ___(__0, __2) { results.service = __2; return mobile.getAuthSettings(options, __cb(_, __frame, 8, 34, function ___(__0, __3) { results.auth = __3; return mobile.getApnsSettings(options, __cb(_, __frame, 9, 34, function ___(__0, __4) { results.apns = __4; return mobile.getPushSettings(options, __cb(_, __frame, 10, 33, function ___(__0, __5) { results.gcm = __5; results.live = (__.find(results.auth, function(authSettings) { return (authSettings.provider === "microsoft"); }) || { }); results.auth = __.reject(results.auth, function(authSettings) { return (authSettings.provider === "microsoft"); }); if ((results.gcm && results.gcm["gcmCredentials"])) { results.gcm = (results.gcm["gcmCredentials"] || { }); delete results.gcm.endpoint; } ; _(null, null, true); }, true)); }, true)); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__14() { progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__14() { cli.interaction.formatOutput(results, displayConfiguration); _(); }); }); }, true)); }); });





  function createSetConfigHandler(coreGetHandler, coreSetHandler, picker1, picker2, deprecated) {
    return function(options, newValue, callback) {
      if (deprecated) {
        log.info(deprecated.yellow); } ;


      coreGetHandler(options, function(error, result) {
        if (error) {
          return callback(error); } ;



        if (picker2) {
          if (Array.isArray(result)) {

            var found;
            for (var i = 0; (i < result.length); i++) {
              if ((result[i].provider == picker1)) {
                result[i][picker2] = newValue;
                found = true;
                break; } ; };




            if (!found) {
              var newProvider = { provider: picker1, appId: "", secret: "" };
              newProvider[picker2] = newValue;
              result.push(newProvider); } ; } ; }


         else {
          result[picker1] = newValue; } ;


        coreSetHandler(options, result, callback); }); }; };




  var setConfigHandlers = {
    dynamicSchemaEnabled: createSetConfigHandler(mobile.getServiceSettings, mobile.setServiceSettings, "dynamicSchemaEnabled"),
    crossDomainWhitelist: createSetConfigHandler(mobile.getServiceSettings, mobile.setServiceSettings, "crossDomainWhitelist"),
    microsoftAccountClientSecret: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "microsoft", "secret", $("\"azure mobile config set <servicename> microsoftAccountClientSecret\" is obsolete. Use \"azure mobile auth microsoftaccount set\"")),
    microsoftAccountClientId: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "microsoft", "appId", $("\"azure mobile config set <servicename> microsoftAccountClientId\" is obsolete. Use \"azure mobile auth microsoftaccount set\"")),
    microsoftAccountPackageSID: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "microsoft", "packageSid", $("\"azure mobile config set <servicename> microsoftAccountPackageSID\" is obsolete. Use \"azure mobile auth microsoftaccount set\"")),
    facebookClientId: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "facebook", "appId", $("\"azure mobile config set <servicename> facebookClientId\" is obsolete. Use \"azure mobile auth facebook set\"")),
    facebookClientSecret: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "facebook", "secret", $("\"azure mobile config set <servicename> facebookClientSecret\" is obsolete. Use \"azure mobile auth facebook set\"")),
    twitterClientId: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "twitter", "appId", $("\"azure mobile config set <servicename> twitterClientId\" is obsolete. Use \"azure mobile auth twitter set\"")),
    twitterClientSecret: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "twitter", "secret", $("\"azure mobile config set <servicename> twitterClientSecret\" is obsolete. Use \"azure mobile auth twitter set\"")),
    googleClientId: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "google", "appId", $("\"azure mobile config set <servicename> googleClientId\" is obsolete. Use \"azure mobile auth google set\"")),
    googleClientSecret: createSetConfigHandler(mobile.getAuthSettings, mobile.setAuthSettings, "google", "secret", $("\"azure mobile config set <servicename> googleClientSecret\" is obsolete. Use \"azure mobile auth google set\"")),
    apns: parseAndSetApnsSettings,
    gcm: setGcmSettings };


  function parseAndSetApnsSettings(options, value, callback) {
    log.info($("\"azure mobile config set <servicename> apns\" is obsolete. Use \"azure mobile push apns set\"").yellow);

    var match = value.match(/^(dev|prod):((?::{2}|[^:])*):(.+)/);
    if (!match) {
      return callback(new Error($(("The value of the apns setting must be in the format (dev|prod):<password>:<pkcs12CertificateFile>, " + "e.g. dev:abc!123:./mycertificate.pfx. If the password contains : (colon) characters, they must be escaped as :: (double colon).")))); } ;



    var settings = {
      mode: match[1],
      password: match[2].replace(/::/g, ":") };


    if (settings.password.match(/:/)) {
      log.warn(util.format($("Password was unescaped to %s"), settings.password)); } ;


    settings.data = fs.readFileSync(match[3], "base64");

    mobile.setApnsSettings(options, settings, callback); };


  function setGcmSettings(options, value, callback) {
    log.info($("\"azure mobile config set <servicename> apns\" is obsolete. Use \"azure mobile push apns set\"").yellow);
    var settings = {
      gcmCredentials: {
        apiKey: value,
        endpoint: "https://android.googleapis.com/gcm/send" } };



    mobile.patchPushSettings(options, settings, callback); };


  mobileConfig.command("set <servicename> <key> [value]").usage("[options] <servicename> <key> [value]").description($("Set a mobile service configuration setting")).option("-f, --file <file>", $("read the value of the setting from a file")).option("-s, --subscription <id>", $("the subscription id")).execute(function(servicename, key, value, options, callback) {





    if (!setConfigHandlers[key]) {
      log.info("Supported keys:");
      for (var i in getConfigHandlers) {
        log.info(i.blue); };

      return callback(("Unsupported key " + key.red)); }
     else if ((!value && !options.file)) {
      return callback(new Error($("Either value parameter must be provided or --file option specified"))); }
     else {
      if ((!value && options.file)) {
        value = fs.readFileSync(options.file, "utf8");
        log.info(("Value was read from " + options.file)); } ;


      if ((key === "dynamicSchemaEnabled")) {
        if ((value === "true")) {
          value = true; }
         else if ((value === "false")) {
          value = false; }
         else {
          return callback(new Error($("The value must be either true or false"))); }  ; }

       else if ((key === "crossDomainWhitelist")) {
        value = formatCrossDomainWhitelistForSaving(value); }  ;


      options.servicename = servicename;
      setConfigHandlers[key](options, value, callback); }  ; });



  function createGetConfigHandler(coreHandler, picker1, picker2, deprecated) {
    return function(options, callback) {
      if (deprecated) {
        log.info(deprecated.yellow); } ;


      coreHandler(options, function(error, result) {
        if (error) {
          return callback(error); } ;


        if (picker2) {
          if (Array.isArray(result)) {
            for (var i = 0; (i < result.length); i++) {
              if ((result[i].provider == picker1)) {
                return callback(null, result[i][picker2]); } ; }; }


           else {
            return callback(null, result[picker1][picker2]); } ;


          callback(); }
         else {
          callback(null, result[picker1]); } ; }); }; };





  var getConfigHandlers = {
    dynamicSchemaEnabled: createGetConfigHandler(mobile.getServiceSettings, "dynamicSchemaEnabled"),
    crossDomainWhitelist: createGetConfigHandler(mobile.getServiceSettings, "crossDomainWhitelist"),
    microsoftAccountClientSecret: createGetConfigHandler(mobile.getAuthSettings, "microsoft", "secret", $("\"azure mobile config get <servicename> microsoftAccountClientSecret\" is obsolete. Use \"azure mobile auth microsoftaccount get\"")),
    microsoftAccountClientId: createGetConfigHandler(mobile.getAuthSettings, "microsoft", "appId", $("\"azure mobile config get <servicename> microsoftAccountClientId\" is obsolete. Use \"azure mobile auth microsoftaccount get\"")),
    microsoftAccountPackageSID: createGetConfigHandler(mobile.getAuthSettings, "microsoft", "packageSid", $("\"azure mobile config get <servicename> microsoftAccountPackageSID\" is obsolete. Use \"azure mobile auth microsoftaccount get\"")),
    facebookClientId: createGetConfigHandler(mobile.getAuthSettings, "facebook", "appId", $("\"azure mobile config get <servicename> facebookClientId\" is obsolete. Use \"azure mobile auth facebook get\"")),
    facebookClientSecret: createGetConfigHandler(mobile.getAuthSettings, "facebook", "secret", $("\"azure mobile config get <servicename> microsoftAccountClientSecret\" is obsolete. Use \"azure mobile auth facebook get\"")),
    twitterClientId: createGetConfigHandler(mobile.getAuthSettings, "twitter", "appId", $("\"azure mobile config get <servicename> twitterClientId\" is obsolete. Use \"azure mobile auth twitter get\"")),
    twitterClientSecret: createGetConfigHandler(mobile.getAuthSettings, "twitter", "secret", $("\"azure mobile config get <servicename> twitterClientSecret\" is obsolete. Use \"azure mobile auth twitter get\"")),
    googleClientId: createGetConfigHandler(mobile.getAuthSettings, "google", "appId", $("\"azure mobile config get <servicename> googleClientId\" is obsolete. Use \"azure mobile auth google get\"")),
    googleClientSecret: createGetConfigHandler(mobile.getAuthSettings, "google", "secret", $("\"azure mobile config get <servicename> googleClientSecret\" is obsolete. Use \"azure mobile auth google get\"")),
    apns: createGetConfigHandler(mobile.getApnsSettings, "mode", null, $("\"azure mobile config get <servicename> apns\" is obsolete. Use \"azure mobile push apns get\"")),
    gcm: createGetConfigHandler(mobile.getPushSettings, "gcmCredentials", "apiKey", $("\"azure mobile config get <servicename> gcm\" is obsolete. Use \"azure mobile push gcm get\"")) };


  mobileConfig.command("get [servicename] [key]").usage("[options] [servicename] [key]").description($("Get a mobile service configuration setting")).option("-f, --file <file>", $("save the value of the setting to a file")).option("-s, --subscription <id>", $("the subscription id")).execute(function __15(servicename, key, options, _) { var i, result, progress, value; var __frame = { name: "__15", line: 2578 }; return __func(_, this, arguments, __15, 3, __frame, function __$__15() {





      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return cli.interaction.chooseIfNotGiven($("Setting key: "), $("Getting choices"), key, function(cb) {

          cb(null, __.keys(getConfigHandlers)); }, __cb(_, __frame, 2, 32, function ___(__0, __2) { key = __2;


          if (!getConfigHandlers[key]) {
            log.info($("Supported keys:"));
            for (i in getConfigHandlers) {
              log.info(i.blue); };


            return _(new Error(util.format($("Unsupported key %s"), key.red))); } ;



          progress = cli.interaction.progress(util.format($("Retrieving setting: %s"), key)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__15() {

                return getConfigHandlers[key](options, __cb(_, __frame, 19, 21, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__15() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__15() {


              value = { };
              value[key] = result;

              cli.interaction.formatOutput(value, function(output) {
                if (output[key]) {
                  if ((key === "crossDomainWhitelist")) {
                    output[key] = formatCrossDomainWhitelistForDisplay(output[key]); } ;


                  if ((typeof options.file === "string")) {
                    fs.writeFileSync(options.file, output[key], "utf8");
                    log.info(util.format($("Written value to %s"), options.file)); }
                   else {
                    log.data(key, output[key].toString().green); } ; }

                 else {
                  log.warn($("Setting is not configured").blue); } ; }); _(); }); }); }, true)); }, true)); }); });




  var mobileDomain = mobile.category("domain").description($("Commands to manage your Mobile Service Domains"));


  mobileDomain.command("list [servicename]").usage("[options] [servicename]").description($("List domains for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __16(servicename, options, _) { var progress; var __frame = { name: "__16", line: 2630 }; return __func(_, this, arguments, __16, 2, __frame, function __$__16() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress(util.format($("Listing domains for %s mobile service"), options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__16() {

              return mobile.getDomains(options, __cb(_, __frame, 5, 26, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__16() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__16() {


            cli.interaction.formatOutput(result, function(output) {
              output.forEach(function(domain) {
                log.data($("Domain"), domain.green); }); }); _(); }); }); }, true)); }); });




  mobileDomain.command("add [servicename] [domain]").usage("[options] [servicename] [domain]").description($("Add domain to mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __17(servicename, domain, options, _) { var progress; var __frame = { name: "__17", line: 2651 }; return __func(_, this, arguments, __17, 3, __frame, function __$__17() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return promptIfNotGiven($("Domain: "), domain, __cb(_, __frame, 3, 17, function ___(__0, __2) { domain = __2;

          progress = cli.interaction.progress(util.format($("Adding %s domain to %s mobile service"), domain, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__17() {

                return mobile.addDomain(options, domain, __cb(_, __frame, 7, 26, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__17() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__17() { _(); }); }); }, true)); }, true)); }); });



  mobileDomain.command("delete [servicename] [domain]").usage("[options] [servicename]").description($("Delete domain from mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __18(servicename, domain, options, _) { var progress; var __frame = { name: "__18", line: 2668 }; return __func(_, this, arguments, __18, 3, __frame, function __$__18() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return promptDomainIfNotGiven(options, domain, __cb(_, __frame, 3, 17, function ___(__0, __2) { domain = __2;

          progress = cli.interaction.progress(util.format($("Deleting %s domain from %s mobile service"), domain, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__18() {

                return mobile.deleteDomain(options, domain, __cb(_, __frame, 7, 26, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__18() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__18() { _(); }); }); }, true)); }, true)); }); });



  var mobileDomainSsl = mobileDomain.category("ssl").description($("Commands to manage SSL for your Mobile Service Domains"));


  mobileDomainSsl.command("show [servicename] [domain]").usage("[options] [servicename] [domain]").description($("Show SSL state for domain")).option("-s, --subscription <id>", $("the subscription id")).execute(function __19(servicename, domain, options, _) { var progress; var __frame = { name: "__19", line: 2688 }; return __func(_, this, arguments, __19, 3, __frame, function __$__19() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return promptDomainIfNotGiven(options, domain, __cb(_, __frame, 3, 17, function ___(__0, __2) { domain = __2;

          progress = cli.interaction.progress(util.format($("Show SSL state for %s domain from %s mobile service"), domain, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__19() {

                return mobile.getSslState(options, domain, __cb(_, __frame, 7, 26, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__19() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__19() {


              cli.interaction.formatOutput(result, function(output) {
                if (output.sslState) {
                  log.data($("SSL State"), output.sslState.green);
                  log.data($("Certificate Thumbprint"), output.thumbprint.green); }
                 else {
                  log.data($("SSL State"), $("Disabled").green); } ; }); _(); }); }); }, true)); }, true)); }); });




  mobileDomainSsl.command("enable [servicename] [domain] [thumbprint]").usage("[options] [servicename] [domain] [thumbprint]").description($("Enable SSL for domain by attaching an SSL Certificate.  To add SSL Certificates use the \"azure mobile cert add\" command")).option("-s, --subscription <id>", $("the subscription id")).execute(function __20(servicename, domain, thumbprint, options, _) { var progress; var __frame = { name: "__20", line: 2714 }; return __func(_, this, arguments, __20, 4, __frame, function __$__20() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptDomainIfNotGiven(options, domain, __cb(_, __frame, 2, 17, function ___(__0, __2) { domain = __2;
          return promptThumbprintIfNotGiven(options, thumbprint, __cb(_, __frame, 3, 21, function ___(__0, __3) { thumbprint = __3.toUpperCase();

            progress = cli.interaction.progress(util.format($("Enabling SSL for %s domain using certificate with thumbprint %s for %s mobile service"), domain, thumbprint, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__20() {

                  return mobile.enableSsl(options, domain, thumbprint, __cb(_, __frame, 7, 26, function ___(__0, __4) { result = __4; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__20() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__20() { _(); }); }); }, true)); }, true)); }, true)); }); });



  mobileDomainSsl.command("disable [servicename] [domain] [thumbprint]").usage("[options] [servicename] [domain] [thumbprint]").description($("Disable SSL for domain by detaching SSL Certificate.")).option("-s, --subscription <id>", $("the subscription id")).execute(function __21(servicename, domain, thumbprint, options, _) { var progress; var __frame = { name: "__21", line: 2731 }; return __func(_, this, arguments, __21, 4, __frame, function __$__21() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptDomainIfNotGiven(options, domain, __cb(_, __frame, 2, 17, function ___(__0, __2) { domain = __2;
          return promptThumbprintIfNotGiven(options, thumbprint, __cb(_, __frame, 3, 21, function ___(__0, __3) { thumbprint = __3.toUpperCase();

            progress = cli.interaction.progress(util.format($("Disabling SSL for %s domain using certificate with thumbprint %s for %s mobile service"), domain, thumbprint, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__21() {

                  return mobile.disableSsl(options, domain, thumbprint, __cb(_, __frame, 7, 26, function ___(__0, __4) { result = __4; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__21() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__21() { _(); }); }); }, true)); }, true)); }, true)); }); });



  var mobileCert = mobile.category("cert").description($("Commands to manage your Mobile Service Certificates for Domains"));


  mobileCert.command("list [servicename]").usage("[options] [servicename]").description($("List certificates for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __22(servicename, options, _) { var progress; var __frame = { name: "__22", line: 2751 }; return __func(_, this, arguments, __22, 2, __frame, function __$__22() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress(util.format($("Listing certificates for %s mobile service"), options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__22() {

              return mobile.getCertificates(options, __cb(_, __frame, 5, 26, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__22() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__22() {


            cli.interaction.formatOutput(result, function(output) {
              output.forEach(function(certificate) {
                log.data($("Certificate"), null);
                log.data($("Thumbprint"), certificate.thumbprint.green);
                log.data($("Subject Name"), certificate.subjectName.green);
                log.data($("Issuer"), certificate.issuer.green);
                log.data($("Expiration Date"), certificate.expirationDate.green);
                log.data($("Issue Date"), certificate.issueDate.green); }); }); _(); }); }); }, true)); }); });




  mobileCert.command("add [servicename] [certificate-path] [key]").usage("[options] [servicename] [certificate-path] [key]").description($("Add certificate to mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __23(servicename, certificatePath, key, options, _) { var progress, certificateContent, cert; var __frame = { name: "__23", line: 2777 }; return __func(_, this, arguments, __23, 4, __frame, function __$__23() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return cli.interaction.promptIfNotGiven($("Certificate path: "), certificatePath, __cb(_, __frame, 3, 42, function ___(__0, __2) { certificatePath = __2;

          if (!fs.existsSync(certificatePath)) {
            return _(new Error(util.format($("Invalid certificate file path %s"), certificatePath))); } ;


          if ((path.extname(certificatePath) !== ".pfx")) {
            return _(new Error($("Only pfx certificates are supported"))); } ;


          return promptIfNotGiven($("Certificate key: "), key, __cb(_, __frame, 13, 14, function ___(__0, __3) { key = __3;

            progress = cli.interaction.progress(util.format($("Adding certificate with path %s for %s mobile service"), certificatePath, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__23() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__23() {

                        return fs.readFile(certificatePath, __cb(_, __frame, 17, 38, function ___(__0, __4) { certificateContent = __4;
                          cert = {
                            PfxBlob: certificateContent.toString("base64"),
                            Password: key };

                          return mobile.addCertificate(options, cert, __cb(_, __frame, 22, 26, function ___(__0, __5) { result = __5; __then(); }, true)); }, true)); }); })(function ___(exception, __result) { __catch(function __$__23() { if (exception) {

                          log.error("Ensure that you are using a valid .pfx certificate file");
                          return _(exception); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__23() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__23() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__23() { _(); }); }); }, true)); }, true)); }, true)); }); });



  mobileCert.command("delete [servicename] [thumbprint]").usage("[options] [servicename] [thumbprint]").description($("Delete certificate from mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __24(servicename, thumbprint, options, _) { var progress; var __frame = { name: "__24", line: 2812 }; return __func(_, this, arguments, __24, 3, __frame, function __$__24() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return promptThumbprintIfNotGiven(options, thumbprint, __cb(_, __frame, 3, 21, function ___(__0, __2) { thumbprint = __2.toUpperCase();

          progress = cli.interaction.progress(util.format($("Deleting certificate with %s thumbprint for %s mobile service"), thumbprint, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__24() {

                return mobile.deleteCertificate(options, thumbprint, __cb(_, __frame, 7, 26, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__24() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__24() { _(); }); }); }, true)); }, true)); }); });



  var mobilePush = mobile.category("push").description($("Commands to manage your Mobile Service Push Settings"));


  var mobilePushNh = mobilePush.category("nh").description($("Manage notification hub settings for mobile service"));


  mobilePushNh.command("get [servicename]").usage("[options] [servicename]").description($("Get notification hub settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __25(servicename, options, _) { var progress; var __frame = { name: "__25", line: 2835 }; return __func(_, this, arguments, __25, 2, __frame, function __$__25() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress($("Getting notification hub settings for mobile service")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__25() {

              return mobile.getPushEntity(options, __cb(_, __frame, 5, 26, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__25() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__25() {


            cli.interaction.formatOutput(result, function(output) {
              if ((output.enableExternalPushEntity === true)) {
                log.info($("Enhanced Push is enabled"));
                log.data($("Notification Hub State"), output.externalPushEntitySettingsPropertyBag.externalPushEntityState);
                log.data($("Notification Hub Namespace"), output.externalPushEntitySettingsPropertyBag.pushEntityNamespace);
                log.data($("Notification Hub Entity"), output.externalPushEntitySettingsPropertyBag.pushEntityPath);
                log.data($("Notification Hub ConnectionString"), output.externalPushEntitySettingsPropertyBag.pushEntityConnectionString); }
               else {
                log.info($("Enhanced push is disabled. Run \"azure mobile push nh enable [servicename]\" to enable enhanced push")); } ; }); _(); }); }); }, true)); }); });




  mobilePushNh.command("enable [servicename]").usage("[options] [servicename]").description($("Create notification hub for mobile service")).option("-s, --subscription <id>", $("the subscription id")).option("--nowait", $("Do not wait for push operation to complete")).execute(function __26(servicename, options, _) { var progress, settings; var __frame = { name: "__26", line: 2863 }; return __func(_, this, arguments, __26, 2, __frame, function __$__26() {





      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress($("Enabling enhanced push for mobile service"));
        settings = {
          enableExternalPushEntity: true,
          externalPushEntitySettingsPropertyBag: { } }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__26() {



              return mobile.getPushEntity(options, __cb(_, __frame, 10, 26, function ___(__0, __2) { result = __2;
                if (((result.enableExternalPushEntity === true) && (result.externalPushEntitySettingsPropertyBag.externalPushEntityState === "healthy"))) {
                  log.error($("Enhanced push for mobile service is already enabled.")); return _(null); } ;



                return mobile.setPushEntity(options, settings, __cb(_, __frame, 16, 17, function __$__26() { return (function __$__26(__then) {
                    if (!options.nowait) {
                      return mobile.waitForPushEnabling(options, __cb(_, __frame, 18, 19, __then, true)); } else { __then(); } ; })(function __$__26() { _(null, null, true); }); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__26() {


                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__26() { _(); }); }); }, true)); }); });



  mobilePushNh.command("disable [servicename]").usage("[options] [servicename]").description($("Create notification hub for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __27(servicename, options, _) { var progress, settings; var __frame = { name: "__27", line: 2892 }; return __func(_, this, arguments, __27, 2, __frame, function __$__27() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 28, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress($("Disabling enhanced push for mobile service"));
        settings = {
          enableExternalPushEntity: false }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__27() {



              return mobile.setPushEntity(options, settings, __cb(_, __frame, 9, 17, function __$__27() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__27() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__27() { _(); }); }); }, true)); }); });



  function setColorOrDefault(value) {
    if (value) {
      return value.green; }
     else {
      return $("Not configured").blue; } ; };



  function getPushSettings(options, progressInfo, settingsName, resultFormatter, _) { var result, progress; var __frame = { name: "getPushSettings", line: 2915 }; return __func(_, this, arguments, getPushSettings, 4, __frame, function __$getPushSettings() {

      progress = cli.interaction.progress(util.format($("Getting %s settings for %s mobile service"), progressInfo, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getPushSettings() {

            return mobile.getPushSettings(options, __cb(_, __frame, 4, 22, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getPushSettings() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getPushSettings() {


          cli.interaction.formatOutput(result[settingsName], resultFormatter); _(); }); }); }); };


  function setPushSettings(options, progressInfo, settings, _) { var progress; var __frame = { name: "setPushSettings", line: 2927 }; return __func(_, this, arguments, setPushSettings, 3, __frame, function __$setPushSettings() {
      progress = cli.interaction.progress(util.format($("Setting %s settings for %s mobile service"), progressInfo, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$setPushSettings() {

            return mobile.patchPushSettings(options, settings, __cb(_, __frame, 3, 13, function __$setPushSettings() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$setPushSettings() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$setPushSettings() { _(); }); }); }); };



  function deletePushSettings(options, progressInfo, settings, _) { var progress; var __frame = { name: "deletePushSettings", line: 2936 }; return __func(_, this, arguments, deletePushSettings, 3, __frame, function __$deletePushSettings() {
      progress = cli.interaction.progress(util.format($("Deleting %s settings for %s mobile service"), progressInfo, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deletePushSettings() {

            return mobile.patchPushSettings(options, settings, __cb(_, __frame, 3, 13, function __$deletePushSettings() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deletePushSettings() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deletePushSettings() { _(); }); }); }); };



  var mobilePushGcm = mobilePush.category("gcm").description($("Manage GCM settings for mobile service"));


  mobilePushGcm.command("get [servicename]").usage("[options] [servicename]").description($("Get google cloud API key for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __28(servicename, options, _) { var __frame = { name: "__28", line: 2952 }; return __func(_, this, arguments, __28, 2, __frame, function __$__28() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getPushSettings(options, $("GCM"), "gcmCredentials", function(result) {
          log.data($("API Key"), setColorOrDefault(result.apiKey)); }, __cb(_, __frame, 3, 8, function __$__28() { _(); }, true)); }, true)); }); });



  mobilePushGcm.command("set [servicename] [apiKey]").usage("[options] [servicename] [apiKey]").description($("Set google cloud API key for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __29(servicename, apiKey, options, _) { var settings; var __frame = { name: "__29", line: 2964 }; return __func(_, this, arguments, __29, 3, __frame, function __$__29() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven("API Key", apiKey, __cb(_, __frame, 2, 25, function ___(__0, __2) { options.apiKey = __2;

          settings = {
            gcmCredentials: {
              apiKey: options.apiKey,
              endpoint: "https://android.googleapis.com/gcm/send" } };



          return setPushSettings(options, $("GCM"), settings, __cb(_, __frame, 11, 8, function __$__29() { _(); }, true)); }, true)); }, true)); }); });


  mobilePushGcm.command("delete [servicename]").usage("[options] [servicename]").description($("Delete google cloud API key for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __30(servicename, options, _) { var settings; var __frame = { name: "__30", line: 2982 }; return __func(_, this, arguments, __30, 2, __frame, function __$__30() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        settings = {
          gcmCredentials: { } };



        return deletePushSettings(options, $("GCM"), settings, __cb(_, __frame, 8, 8, function __$__30() { _(); }, true)); }, true)); }); });


  var mobilePushApns = mobilePush.category("apns").description($("Manage APNS settings for mobile service"));


  mobilePushApns.command("get [servicename]").usage("[options] [servicename]").description($("Get Apple push notification settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).option("-f, --file <file>", $("save the certificate to file")).execute(function __31(servicename, options, _) { var __frame = { name: "__31", line: 3001 }; return __func(_, this, arguments, __31, 2, __frame, function __$__31() {





      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getPushSettings(options, $("APNS"), "apnsCredentials", function(result) {
          if ((result.apnsCertificate && options.file)) {
            fs.writeFileSync(options.file, result.apnsCertificate, "base64");
            log.data($("Certificate"), setColorOrDefault(util.format($("Certificate saved to %s"), options.file))); } ;


          if (result.apnsCertificate) {
            if ((result.endpoint === "gateway.push.apple.com")) {
              log.info(setColorOrDefault($("Production certificate is present"))); }
             else if ((result.endpoint === "gateway.sandbox.push.apple.com")) {
              log.info(setColorOrDefault($("Development certificate is present"))); }  ; }

           else {
            log.info(setColorOrDefault($("No certificate present"))); } ; }, __cb(_, __frame, 3, 8, function __$__31() { _(); }, true)); }, true)); }); });




  mobilePushApns.command("set [servicename] [mode] [certificateFile]").usage("[options] [servicename] [mode] [certificateFile]").description($("Set Apple push notification settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).option("-p, --password <password>", $("password for certificateFile")).execute(function __32(servicename, mode, certificateFile, password, options, _) { var settings; var __frame = { name: "__32", line: 3027 }; return __func(_, this, arguments, __32, 5, __frame, function __$__32() {





      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("Mode"), mode, __cb(_, __frame, 2, 23, function ___(__0, __2) { options.mode = __2;

          if ((options.mode.toLowerCase() === "sandbox")) {
            options.mode = "gateway.sandbox.push.apple.com"; } else {
            if ((options.mode.toLowerCase() === "production")) {
              options.mode = "gateway.push.apple.com"; }
             else {
              log.error($("Mode can only have two values : \"sandbox\" or \"production\"")); return _(null); } ; } ;



          return promptIfNotGiven($("Certificate File"), certificateFile, __cb(_, __frame, 13, 34, function ___(__0, __3) { options.certificateFile = __3;
            options.certificateData = fs.readFileSync(options.certificateFile, "base64");

            settings = {
              apnsCredentials: {
                endpoint: options.mode,
                apnsCertificate: options.certificateData,
                certificateKey: options.password } };



            return setPushSettings(options, $("APNS"), settings, __cb(_, __frame, 24, 8, function __$__32() { _(); }, true)); }, true)); }, true)); }, true)); }); });


  mobilePushApns.command("delete [servicename]").usage("[options] [servicename]").description($("Delete Apple push notification settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __33(servicename, options, _) { var settings; var __frame = { name: "__33", line: 3058 }; return __func(_, this, arguments, __33, 2, __frame, function __$__33() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        settings = {
          apnsCredentials: { } };



        return deletePushSettings(options, $("APNS"), settings, __cb(_, __frame, 8, 8, function __$__33() { _(); }, true)); }, true)); }); });


  var mobilePushMpns = mobilePush.category("mpns").description($("Manage Windows Phone notification settings for mobile service"));


  mobilePushMpns.command("get [servicename]").usage("[options] [servicename]").description($("Get windows phone notification settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).option("-f, --file <file>", $("save the certificate to file")).execute(function __34(servicename, options, _) { var __frame = { name: "__34", line: 3077 }; return __func(_, this, arguments, __34, 2, __frame, function __$__34() {





      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getPushSettings(options, $("windows phone notification"), "mpnsCredentials", function(result) {
          if ((result.mpnsCertificate && options.file)) {
            fs.writeFileSync(options.file, result.mpnsCertificate, "base64");
            log.data($("Certificate"), setColorOrDefault(util.format($("Certificate saved to %s"), options.file))); } ;


          if (result.mpnsCertificate) {
            log.info(setColorOrDefault($("Certificate is present"))); } ;


          if (result.enableUnauthenticatedSettings) {
            log.info(setColorOrDefault($("Unauthenticated push notifications is enabled"))); }
           else {
            log.info(setColorOrDefault($("Unauthenticated push notifications is disabled"))); } ; }, __cb(_, __frame, 3, 8, function __$__34() { _(); }, true)); }, true)); }); });




  mobilePushMpns.command("set [servicename] [certificateFile] [password]").usage("[options] [servicename] [certificateFile] [password]").description($("Set windows phone notification settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __35(servicename, certificateFile, password, options, _) { var settings; var __frame = { name: "__35", line: 3102 }; return __func(_, this, arguments, __35, 4, __frame, function __$__35() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;


        return promptIfNotGiven($("Certificate File"), certificateFile, __cb(_, __frame, 4, 34, function ___(__0, __2) { options.certificateFile = __2;
          options.certificateData = fs.readFileSync(options.certificateFile, "base64");
          return promptIfNotGiven($("Certificate Password"), password, __cb(_, __frame, 6, 27, function ___(__0, __3) { options.password = __3;

            settings = {
              mpnsCredentials: {
                enableUnauthenticatedSettings: true,
                mpnsCertificate: options.certificateData,
                certificateKey: options.password } };



            return setPushSettings(options, $("windows phone notification"), settings, __cb(_, __frame, 16, 8, function __$__35() { _(); }, true)); }, true)); }, true)); }, true)); }); });


  mobilePushMpns.command("delete [servicename]").usage("[options] [servicename]").description($("Delete windows phone notification settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __36(servicename, options, _) { var settings; var __frame = { name: "__36", line: 3125 }; return __func(_, this, arguments, __36, 2, __frame, function __$__36() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        settings = {
          mpnsCredentials: {
            enableUnauthenticatedSettings: false } };



        return deletePushSettings(options, $("windows phone notification"), settings, __cb(_, __frame, 9, 8, function __$__36() { _(); }, true)); }, true)); }); });


  var mobilePushWns = mobilePush.category("wns").description($("Manage windows application credentials for mobile service"));


  mobilePushWns.command("get [servicename]").usage("[options] [servicename]").description($("Get windows application credentials for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __37(servicename, options, _) { var __frame = { name: "__37", line: 3144 }; return __func(_, this, arguments, __37, 2, __frame, function __$__37() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getPushSettings(options, $("windows application credential"), "wnsCredentials", function(result) {
          log.data($("Client Secret"), setColorOrDefault(result.clientSecret));
          log.data($("Package SID"), setColorOrDefault(result.packageSID)); }, __cb(_, __frame, 3, 8, function __$__37() { _(); }, true)); }, true)); }); });



  mobilePushWns.command("set [servicename] [clientSecret] [packageSID]").usage("[options] [servicename] [clientSecret] [packageSID]").description($("Set windows application credentials for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __38(servicename, clientSecret, packageSID, options, _) { var settings; var __frame = { name: "__38", line: 3157 }; return __func(_, this, arguments, __38, 4, __frame, function __$__38() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("Client Secret"), clientSecret, __cb(_, __frame, 2, 31, function ___(__0, __2) { options.clientSecret = __2;
          return promptIfNotGiven($("Package SID"), packageSID, __cb(_, __frame, 3, 29, function ___(__0, __3) { options.packageSID = __3;

            settings = {
              wnsCredentials: {
                clientSecret: options.clientSecret,
                packageSID: options.packageSID } };



            return setPushSettings(options, $("windows application credential"), settings, __cb(_, __frame, 12, 8, function __$__38() { _(); }, true)); }, true)); }, true)); }, true)); }); });


  mobilePushWns.command("delete [servicename]").usage("[options] [servicename]").description($("Delete windows application credentials for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __39(servicename, options, _) { var settings; var __frame = { name: "__39", line: 3176 }; return __func(_, this, arguments, __39, 2, __frame, function __$__39() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        settings = {
          wnsCredentials: { } };


        return deletePushSettings(options, $("windows application credentials"), settings, __cb(_, __frame, 7, 8, function __$__39() { _(); }, true)); }, true)); }); });


  var mobileAuth = mobile.category("auth").description($("Commands to manage authentication settings for mobile service"));


  function getAuthSettingAndOutput(options, progressInfo, authType, resultHandler, _) { var result, progress, settingsForAuthType; var __frame = { name: "getAuthSettingAndOutput", line: 3189 }; return __func(_, this, arguments, getAuthSettingAndOutput, 4, __frame, function __$getAuthSettingAndOutput() {

      progress = cli.interaction.progress(util.format($("Getting %s settings for %s mobile service"), progressInfo, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$getAuthSettingAndOutput() {

            return mobile.getAuthSettings(options, __cb(_, __frame, 4, 22, function ___(__0, __1) { result = __1; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$getAuthSettingAndOutput() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$getAuthSettingAndOutput() {


          settingsForAuthType = (__.find(result, function(authSettings) { return (authSettings.provider === authType); }) || { });

          cli.interaction.formatOutput(settingsForAuthType, resultHandler); _(); }); }); }); };


  function setAuthSettingsCore(options, progressInfo, authType, newAuthSettings, _) { var progress, result; var __frame = { name: "setAuthSettingsCore", line: 3203 }; return __func(_, this, arguments, setAuthSettingsCore, 4, __frame, function __$setAuthSettingsCore() {
      progress = cli.interaction.progress(util.format($("Setting %s settings for %s mobile service"), progressInfo, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$setAuthSettingsCore() {

            return mobile.getAuthSettings(options, __cb(_, __frame, 3, 26, function ___(__0, __1) { result = __1;

              result = __.reject(result, function(authSettings) { return (authSettings.provider == authType); });
              result.push(newAuthSettings);

              return mobile.setAuthSettings(options, result, __cb(_, __frame, 8, 13, function __$setAuthSettingsCore() { _(null, null, true); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$setAuthSettingsCore() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$setAuthSettingsCore() { _(); }); }); }); };



  function deleteAuthSettingsCore(options, progressInfo, authType, _) { var progress, result; var __frame = { name: "deleteAuthSettingsCore", line: 3217 }; return __func(_, this, arguments, deleteAuthSettingsCore, 3, __frame, function __$deleteAuthSettingsCore() {
      progress = cli.interaction.progress(util.format($("Deleting %s settings for %s mobile service"), progressInfo, options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$deleteAuthSettingsCore() {

            return mobile.getAuthSettings(options, __cb(_, __frame, 3, 26, function ___(__0, __1) { result = __1;
              return mobile.setAuthSettings(options, __.reject(result, function(authSettings) { return (authSettings.provider === authType); }), __cb(_, __frame, 4, 13, function __$deleteAuthSettingsCore() { _(null, null, true); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$deleteAuthSettingsCore() {

              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$deleteAuthSettingsCore() { _(); }); }); }); };



  var mobileAuthMicrosoft = mobileAuth.category("microsoftaccount").description($("Manage microsoft account settings for mobile service"));


  mobileAuthMicrosoft.command("get [servicename]").usage("[options] [servicename]").description($("Get microsoft account settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __40(servicename, options, _) { var __frame = { name: "__40", line: 3234 }; return __func(_, this, arguments, __40, 2, __frame, function __$__40() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getAuthSettingAndOutput(options, $("microsoft account"), "microsoft", function(output) {
          log.data($("Client Id"), setColorOrDefault(output.appId));
          log.data($("Client Secret"), setColorOrDefault(output.secret));
          log.data($("Package SID "), setColorOrDefault(output.packageSid)); }, __cb(_, __frame, 3, 8, function __$__40() { _(); }, true)); }, true)); }); });



  mobileAuthMicrosoft.command("set [servicename] [clientId] [clientSecret]").usage("[options] [servicename] [clientId] [clientSecret]").description($("Set microsoft account settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).option("--packageSid <packageSid>", $("Package SID to be set")).execute(function __41(servicename, clientId, clientSecret, options, _) { var progress, result, existingSettings, updatedSettings; var __frame = { name: "__41", line: 3249 }; return __func(_, this, arguments, __41, 4, __frame, function __$__41() {





      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1; return (function __$__41(__then) {

          if (!options.packageSid) {
            return promptIfNotGiven($("ClientId"), clientId, __cb(_, __frame, 4, 29, function ___(__0, __2) { options.clientId = __2;
              return promptIfNotGiven($("ClientSecret"), clientSecret, __cb(_, __frame, 5, 33, function ___(__0, __3) { options.clientSecret = __3; __then(); }, true)); }, true)); } else { __then(); } ; })(function __$__41() {


          progress = cli.interaction.progress(util.format($("Setting microsoft account settings for %s mobile service"), options.servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__41() {

                return mobile.getAuthSettings(options, __cb(_, __frame, 10, 30, function ___(__0, __4) { result = __4;

                  existingSettings = __.find(result, function(authSettings) { return (authSettings.provider === "microsoft"); });
                  if (existingSettings) {
                    result = __.reject(result, function(authSettings) { return (authSettings.provider == "microsoft"); }); }
                   else {
                    existingSettings = { }; } ;


                  updatedSettings = {
                    provider: "microsoft",
                    appId: (((options.clientId || clientId) || existingSettings.appId) || ""),
                    secret: (((options.clientSecret || clientSecret) || existingSettings.secret) || ""),
                    packageSid: ((options.packageSid || existingSettings.packageSid) || "") };


                  result.push(updatedSettings);

                  return mobile.setAuthSettings(options, result, __cb(_, __frame, 28, 17, function __$__41() { _(null, null, true); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__41() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__41() { _(); }); }); }); }, true)); }); });



  mobileAuthMicrosoft.command("delete [servicename]").usage("[options] [servicename]").description($("Delete microsoft account settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __42(servicename, options, _) { var __frame = { name: "__42", line: 3287 }; return __func(_, this, arguments, __42, 2, __frame, function __$__42() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return deleteAuthSettingsCore(options, $("microsoft account"), "microsoft", __cb(_, __frame, 3, 8, function __$__42() { _(); }, true)); }, true)); }); });


  var mobileAuthFacebook = mobileAuth.category("facebook").description($("Manage facebook settings for mobile service"));


  mobileAuthFacebook.command("get [servicename]").usage("[options] [servicename]").description($("Get facebook identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __43(servicename, options, _) { var __frame = { name: "__43", line: 3300 }; return __func(_, this, arguments, __43, 2, __frame, function __$__43() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getAuthSettingAndOutput(options, $("facebook"), "facebook", function(output) {
          log.data($("API Key"), setColorOrDefault(output.appId));
          log.data($("App Secret"), setColorOrDefault(output.secret)); }, __cb(_, __frame, 3, 8, function __$__43() { _(); }, true)); }, true)); }); });



  mobileAuthFacebook.command("set [servicename] [apiKey] [appSecret]").usage("[options] [servicename] [apiKey] [appSecret]").description($("Set facebook identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __44(servicename, apiKey, appSecret, options, _) { var authSettings; var __frame = { name: "__44", line: 3313 }; return __func(_, this, arguments, __44, 4, __frame, function __$__44() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("API Key"), apiKey, __cb(_, __frame, 2, 25, function ___(__0, __2) { options.apiKey = __2;
          return promptIfNotGiven($("App Secret"), appSecret, __cb(_, __frame, 3, 28, function ___(__0, __3) { options.appSecret = __3;

            authSettings = {
              provider: "facebook",
              appId: options.apiKey,
              secret: options.appSecret };


            return setAuthSettingsCore(options, $("facebook"), "facebook", authSettings, __cb(_, __frame, 11, 8, function __$__44() { _(); }, true)); }, true)); }, true)); }, true)); }); });


  mobileAuthFacebook.command("delete [servicename]").usage("[options] [servicename]").description($("Delete facebook identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __45(servicename, options, _) { var __frame = { name: "__45", line: 3331 }; return __func(_, this, arguments, __45, 2, __frame, function __$__45() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return deleteAuthSettingsCore(options, $("facebook"), "facebook", __cb(_, __frame, 3, 8, function __$__45() { _(); }, true)); }, true)); }); });


  var mobileAuthTwitter = mobileAuth.category("twitter").description($("Manage twitter settings for mobile service"));


  mobileAuthTwitter.command("get [servicename]").usage("[options] [servicename]").description($("Get twitter identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __46(servicename, options, _) { var __frame = { name: "__46", line: 3344 }; return __func(_, this, arguments, __46, 2, __frame, function __$__46() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getAuthSettingAndOutput(options, $("twitter"), "twitter", function(output) {
          log.data($("API Key"), setColorOrDefault(output.appId));
          log.data($("API Secret"), setColorOrDefault(output.secret)); }, __cb(_, __frame, 3, 8, function __$__46() { _(); }, true)); }, true)); }); });



  mobileAuthTwitter.command("set [servicename] [apiKey] [apiSecret]").usage("[options] [servicename] [apiKey] [apiSecret]").description($("Set twitter identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __47(servicename, apiKey, apiSecret, options, _) { var authSettings; var __frame = { name: "__47", line: 3357 }; return __func(_, this, arguments, __47, 4, __frame, function __$__47() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("ClientId"), apiKey, __cb(_, __frame, 2, 25, function ___(__0, __2) { options.apiKey = __2;
          return promptIfNotGiven($("ClientSecret"), apiSecret, __cb(_, __frame, 3, 28, function ___(__0, __3) { options.apiSecret = __3;

            authSettings = {
              provider: "twitter",
              appId: options.apiKey,
              secret: options.apiSecret };


            return setAuthSettingsCore(options, $("twitter"), "twitter", authSettings, __cb(_, __frame, 11, 8, function __$__47() { _(); }, true)); }, true)); }, true)); }, true)); }); });


  mobileAuthTwitter.command("delete [servicename]").usage("[options] [servicename]").description($("Delete twitter identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __48(servicename, options, _) { var __frame = { name: "__48", line: 3375 }; return __func(_, this, arguments, __48, 2, __frame, function __$__48() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return deleteAuthSettingsCore(options, $("twitter"), "twitter", __cb(_, __frame, 3, 8, function __$__48() { _(); }, true)); }, true)); }); });


  var mobileAuthGoogle = mobileAuth.category("google").description($("Manage Google settings for mobile service"));


  mobileAuthGoogle.command("get [servicename]").usage("[options] [servicename]").description($("Get google identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __49(servicename, options, _) { var __frame = { name: "__49", line: 3388 }; return __func(_, this, arguments, __49, 2, __frame, function __$__49() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getAuthSettingAndOutput(options, $("google"), "google", function(output) {
          log.data($("Client Id"), setColorOrDefault(output.appId));
          log.data($("Client Secret"), setColorOrDefault(output.secret)); }, __cb(_, __frame, 3, 8, function __$__49() { _(); }, true)); }, true)); }); });



  mobileAuthGoogle.command("set [servicename] [clientId] [clientSecret]").usage("[options] [servicename] [clientId] [clientSecret]").description($("Set google identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __50(servicename, clientId, clientSecret, options, _) { var authSettings; var __frame = { name: "__50", line: 3401 }; return __func(_, this, arguments, __50, 4, __frame, function __$__50() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("ClientId"), clientId, __cb(_, __frame, 2, 27, function ___(__0, __2) { options.clientId = __2;
          return promptIfNotGiven($("ClientSecret"), clientSecret, __cb(_, __frame, 3, 31, function ___(__0, __3) { options.clientSecret = __3;

            authSettings = {
              provider: "google",
              appId: options.clientId,
              secret: options.clientSecret };


            return setAuthSettingsCore(options, $("google"), "google", authSettings, __cb(_, __frame, 11, 8, function __$__50() { _(); }, true)); }, true)); }, true)); }, true)); }); });


  mobileAuthGoogle.command("delete [servicename]").usage("[options] [servicename]").description($("Delete google identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __51(servicename, options, _) { var __frame = { name: "__51", line: 3419 }; return __func(_, this, arguments, __51, 2, __frame, function __$__51() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return deleteAuthSettingsCore(options, $("google"), "google", __cb(_, __frame, 3, 8, function __$__51() { _(); }, true)); }, true)); }); });


  var mobileAuthAad = mobileAuth.category("aad").description($("Manage azure Active Directory settings for mobile service"));


  mobileAuthAad.command("get [servicename]").usage("[options] [servicename]").description($("Get azure Active Directory identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __52(servicename, options, _) { var __frame = { name: "__52", line: 3432 }; return __func(_, this, arguments, __52, 2, __frame, function __$__52() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        return getAuthSettingAndOutput(options, $("AAD"), "aad", function(output) {
          log.data($("Client Id"), setColorOrDefault(output.appId));
          aadTenantResultHandler(output); }, __cb(_, __frame, 3, 8, function __$__52() { _(); }, true)); }, true)); }); });



  mobileAuthAad.command("set [servicename] [clientId]").usage("[options] [servicename] [clientId]").description($("Set azure Active Directory identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __53(servicename, clientId, options, _) { var authSettings; var __frame = { name: "__53", line: 3445 }; return __func(_, this, arguments, __53, 3, __frame, function __$__53() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("ClientId"), clientId, __cb(_, __frame, 2, 27, function ___(__0, __2) { options.clientId = __2;

          authSettings = {
            provider: "aad",
            appId: options.clientId,
            secret: "",
            tenants: [] };


          return setAuthSettingsCore(options, $("AAD"), "aad", authSettings, __cb(_, __frame, 11, 8, function __$__53() { _(); }, true)); }, true)); }, true)); }); });


  mobileAuthAad.command("delete [servicename]").usage("[options] [servicename]").description($("Delete azure Active Directory identity settings for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __54(servicename, options, _) { var __frame = { name: "__54", line: 3463 }; return __func(_, this, arguments, __54, 2, __frame, function __$__54() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 28, function ___(__0, __1) { options.servicename = __1;

        return deleteAuthSettingsCore(options, $("AAD"), "aad", __cb(_, __frame, 3, 6, function __$__54() { _(); }, true)); }, true)); }); });


  function aadTenantResultHandler(aad) {
    if (((typeof aad.tenants === "undefined") || (aad.tenants.length === 0))) {
      log.data($("Tenants"), setColorOrDefault($("None"))); }
     else {
      aad.tenants.forEach(function(tenant) {
        log.data($("Tenant"), setColorOrDefault(tenant)); }); } ; };




  function extractAadSettings(authObject) {
    var aad = __.find(authObject, function(authSettings) { return (authSettings.provider == "aad"); });
    aad.secret = "";
    if ((typeof aad.tenants === "undefined")) {
      aad.tenants = []; } ;

    return aad; };


  var mobileAuthAadTenant = mobileAuthAad.category("tenant").description($("Manage azure Active Directory tenants for mobile service"));


  mobileAuthAadTenant.command("list [servicename]").usage("[options] [servicename]").description($("List azure Active Directory tenants for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __55(servicename, options, _) { var result, progress, aad; var __frame = { name: "__55", line: 3495 }; return __func(_, this, arguments, __55, 2, __frame, function __$__55() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress(util.format($("Getting AAD tenant settings for mobile service"), servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__55() {

              return mobile.getAuthSettings(options, __cb(_, __frame, 5, 26, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__55() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__55() {


            aad = extractAadSettings(result);

            cli.interaction.formatOutput(aad.tenants, function() {
              return aadTenantResultHandler(aad); }); _(); }); }); }, true)); }); });



  mobileAuthAadTenant.command("add [servicename] [tenant]").usage("[options] [servicename] [tenant]").description($("Add azure Active Directory tenant for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __56(servicename, tenant, options, _) { var progress, result, aad; var __frame = { name: "__56", line: 3516 }; return __func(_, this, arguments, __56, 3, __frame, function __$__56() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 30, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("Tenant: "), tenant, __cb(_, __frame, 2, 17, function ___(__0, __2) { tenant = __2;

          progress = cli.interaction.progress(util.format($("Adding %s tenant to %s mobile service"), tenant, servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__56() {

                return mobile.getAuthSettings(options, __cb(_, __frame, 6, 30, function ___(__0, __3) { result = __3;

                  aad = extractAadSettings(result); return (function __$__56(__then) {
                    if (!__.contains(aad.tenants, tenant)) {
                      aad.tenants.push(tenant);
                      return mobile.setAuthSettings(options, result, __cb(_, __frame, 11, 19, __then, true)); } else { __then(); } ; })(function __$__56() { _(null, null, true); }); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__56() {


                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__56() {


              log.info($("The tenant was successfully added.").green); _(); }); }); }, true)); }, true)); }); });


  mobileAuthAadTenant.command("delete [servicename] [tenant]").usage("[options] [servicename] [tenant]").description($("Remove azure Active Directory tenant for mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __57(servicename, tenant, options, _) { var progress, result, aad; var __frame = { name: "__57", line: 3540 }; return __func(_, this, arguments, __57, 3, __frame, function __$__57() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 28, function ___(__0, __1) { options.servicename = __1;

        return cli.interaction.chooseIfNotGiven($("Tenant: "), $("Getting choices"), tenant, function(cb) {

          mobile.getAuthSettings(options, function(error, auth) {
            if (error) { cb(error); } ;
            cb(null, extractAadSettings(auth).tenants.map(function(tenant) { return tenant; })); }); }, __cb(_, __frame, 3, 31, function ___(__0, __2) { tenant = __2;



          progress = cli.interaction.progress(util.format($("Removing %s tenant from %s mobile service"), tenant, servicename)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__57() {

                return mobile.getAuthSettings(options, __cb(_, __frame, 13, 28, function ___(__0, __3) { result = __3;

                  aad = extractAadSettings(result);

                  aad.tenants = __.reject(aad.tenants, function(authTenant) { return (authTenant == tenant); });
                  return mobile.setAuthSettings(options, result, __cb(_, __frame, 18, 15, function __$__57() { _(null, null, true); }, true)); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__57() {


                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__57() {


              log.info($("The tenant was successfully removed.").green); _(); }); }); }, true)); }, true)); }); });


  var mobileTable = mobile.category("table").description($("Commands to manage your Mobile Service tables"));


  mobileTable.command("list [servicename]").usage("[options] [servicename]").description($("List mobile service tables")).option("-s, --subscription <id>", $("the subscription id")).execute(function __58(servicename, options, _) { var result, progress; var __frame = { name: "__58", line: 3574 }; return __func(_, this, arguments, __58, 2, __frame, function __$__58() {




      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;


        progress = cli.interaction.progress($("Getting table information")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__58() {


              return mobile.listTables(options, __cb(_, __frame, 7, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__58() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__58() {


            cli.interaction.formatOutput(result, function(tables) {
              if ((tables && (tables.length > 0))) {
                log.table(tables, function(row, s) {
                  row.cell($("Name"), s.name);
                  row.cell($("Indexes"), s.metrics.indexCount); }); }

               else {
                log.info($("No tables created yet. You can create a mobile service table using azure mobile table create command")); } ; }); _(); }); }); }, true)); }); });




  function loadTableMetaData(options, callback) {
    var results = { };
    var operationCount = 0;

    function tryFinish() {
      if ((++operationCount < 4)) {
        return; } ;


      callback(null, results); };


    function createCallback(name) {
      return function(error, result) {
        log.silly(name, error);
        if (!error) {
          results[name] = result; } ;


        tryFinish(); }; };




    try {
      mobile.getTable(options, createCallback("table"));
      mobile.getPermissions(options, createCallback("permissions"));
      mobile.getColumns(options, createCallback("columns"));
      mobile.getScripts(options, createCallback("scripts"));
    } catch (e) {
      callback(e); }; };



  mobileTable.command("show [servicename] [tablename]").usage("[options] [servicename] [tablename]").description($("Show details for a mobile service table")).option("-s, --subscription <id>", $("the subscription id")).execute(function __59(servicename, tablename, options, _) { var result, progress; var __frame = { name: "__59", line: 3636 }; return __func(_, this, arguments, __59, 3, __frame, function __$__59() {




      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptTableNameIfNotGiven(options, tablename, __cb(_, __frame, 2, 30, function ___(__0, __2) { options.tablename = __2;


          progress = cli.interaction.progress($("Getting table information")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__59() {


                return loadTableMetaData(options, __cb(_, __frame, 8, 21, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__59() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__59() {


              if (!result.table) {
                return _(new Error(util.format($("Table %s or mobile service %s does not exist"), tablename, servicename))); } ;

              cli.interaction.formatOutput(result, function(results) {
                log.info($("Table statistics:").green);
                log.data($("Number of records"), results.table.metrics.recordCount.toString().green);
                log.info($("Table operations:").green);
                log.table(["insert","read","update","delete",], function(row, s) {
                  row.cell($("Operation"), s);

                  var script;
                  if (results.scripts) {
                    for (var i = 0; (i < results.scripts.length); i++) {
                      if ((results.scripts[i].operation === s)) {
                        script = results.scripts[i];
                        break; } ; };



                    row.cell("Script", (script ? (script.sizeBytes.toString() + " bytes") : "Not defined")); }
                   else {
                    row.cell("Script", "N/A"); } ;


                  if (results.permissions) {
                    row.cell("Permissions", (results.permissions[s] || "default")); }
                   else {
                    row.cell("Permissions", "N/A"); } ; });



                if (results.columns) {
                  log.info($("Table columns:").green);
                  log.table(results.columns, function(row, s) {
                    row.cell($("Name"), s.name);
                    row.cell($("Type"), s.type);
                    row.cell($("Indexed"), (s.indexed ? "Yes" : "")); }); }

                 else {
                  log.error($("Unable to obtain table columns")); } ; }); _(); }); }); }, true)); }, true)); }); });




  var roles = ["user","public","application","admin",];
  var operations = ["insert","read","update","delete",];
  var methods = ["get","put","post","patch","delete",];
  function parsePermissions(permissions, keys) {
    var result = { };
    if (__.isString(permissions)) {
      permissions = permissions.toLowerCase();
      permissions.split(",").forEach(function(pair) {
        var match = pair.match(/^([^\=]+)\=(.+)$/);
        if (!match) {
          throw new Error(util.format($("Syntax error in parsing the permission pair \"%s\""), pair)); } ;


        if (((match[1] !== "*") && !keys.some(function(key) { return (key === match[1]); }))) {
          throw new Error(util.format($("Unsupported operation name '%s'. Operation must be one of *, %s"), match[1], keys.join(", "))); } ;


        if (!roles.some(function(role) { return (role === match[2]); })) {
          throw new Error(util.format($("Unsupported permission value '%s'. Permission must be one of %s"), match[2].red, roles.join(", "))); } ;


        if ((match[1] === "*")) {
          keys.forEach(function(key) {
            result[key] = match[2]; }); }

         else {
          result[match[1]] = match[2]; } ; }); } ;




    return result; };


  mobileTable.command("create [servicename] [tablename]").usage("[options] [servicename] [tablename]").description($("Create a new mobile service table")).option("-p, --permissions <permissions>", $("comma delimited list of <operation>=<permission> pairs")).option("-s, --subscription <id>", $("the subscription id")).option("--integerId", $("Create a table with an integer id column")).execute(function __60(servicename, tablename, options, _) { var settings, progress; var __frame = { name: "__60", line: 3733 }; return __func(_, this, arguments, __60, 3, __frame, function __$__60() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__60() {








            settings = parsePermissions(options.permissions, operations); __then(); }); })(function ___(e, __result) { __catch(function __$__60() { if (e) {


              log.error($("Permissions must be specified as a comma delimited list of <operation>=<permission> pairs."));
              log.error(util.format($("<operation> must be one of %s"), operations.join(", ")));
              log.error(util.format($("<permission> must be one of %s"), roles.join(", ")));

              return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__60() {



          operations.forEach(function(operation) {
            if (!settings[operation]) {
              settings[operation] = "application"; } ; });



          return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 20, 32, function ___(__0, __1) { options.servicename = __1;
            return promptIfNotGiven($("Table name: "), tablename, __cb(_, __frame, 21, 26, function ___(__0, __2) { settings.name = __2;

              if (options.integerId) {
                settings.idType = "integer"; }
               else {
                settings.idType = "string"; } ;


              progress = cli.interaction.progress($("Creating table")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__60() {

                    return mobile.createTable(options, settings, __cb(_, __frame, 31, 19, function __$__60() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__60() {

                      progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__60() { _(); }); }); }, true)); }, true)); }); }); }); });



  mobileTable.command("update [servicename] [tablename]").usage("[options] [servicename] [tablename]").description($("Update mobile service table properties")).option("-p, --permissions <permissions>", $("comma delimited list of <operation>=<permission> pairs")).option("--addColumn <columns>", $("comma separated list of <name>=<type> to add")).option("--deleteColumn <columns>", $("comma separated list of columns to delete")).option("-q, --quiet", $("do not prompt for confirmation of column deletion")).option("--addIndex <columns>", $("comma separated list of columns to create an index on")).option("--deleteIndex <columns>", $("comma separated list of columns to delete an index from")).option("-s, --subscription <id>", $("the subscription id")).execute(function __61(servicename, tablename, options, _) { var plan, failures, i, step, progress; var __frame = { name: "__61", line: 3780 }; return __func(_, this, arguments, __61, 3, __frame, function __$__61() {










      if (((((!options.deleteIndex && !options.addIndex) && !options.permissions) && !options.deleteColumn) && !options.addColumn)) {
        return _(new Error($("No updates specified. Check the list of available updates with --help and specify at least one."))); } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__61() {



            options.permissions = parsePermissions(options.permissions, operations); __then(); }); })(function ___(e, __result) { __catch(function __$__61() { if (e) {

              log.error($("Permissions must be specified as a comma delimited list of <operation>=<permission> pairs."));
              log.error(util.format($("<operation> must be one of %s"), operations.join(", ")));
              log.error(util.format($("<permission> must be one of %s"), roles.join(", ")));

              return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__61() {


          return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 15, 32, function ___(__0, __1) { options.servicename = __1;
            return promptTableNameIfNotGiven(options, tablename, __cb(_, __frame, 16, 30, function ___(__0, __2) { options.tablename = __2; return (function __$__61(__then) {

                if ((__.isString(options.deleteColumn) && !options.quiet)) {
                  return cli.interaction.confirm($("Do you really want to delete the column(s)? [y/n]: "), __cb(_, __frame, 19, 32, function ___(__0, __4) { var __3 = (__4 === false); return (function __$__61(__then) { if (__3) {
                        log.info($("Update terminated with no changes made")); return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$__61() {




                plan = [];


                if ((Object.getOwnPropertyNames(options.permissions).length > 0)) {
                  plan.push({
                    progress: $("Updating permissions"),
                    success: $("Updated permissions"),
                    failure: $("Failed to update permissions"),
                    handler: function(callback) {
                      mobile.updatePermissions(options, options.permissions, callback); } }); } ;





                if (options.deleteIndex) {
                  options.deleteIndex.split(",").forEach(function(column) {
                    plan.push({
                      progress: util.format($("Deleting index from column %s"), column),
                      success: util.format($("Deleted index from column %s"), column),
                      failure: util.format($("Failed to delete index from column %s"), column),
                      handler: function(callback) {
                        mobile.deleteIndex(options, column, callback); } }); }); } ;






                if (options.addColumn) {
                  options.addColumn.split(",").forEach(function(columnPair) {
                    var columnInfo = columnPair.split("=");


                    if ((columnInfo[0].substr(0, 2) === "__")) {
                      columnInfo[1] = "auto"; } ;


                    plan.push({
                      progress: util.format($("Adding column %s"), columnInfo[0]),
                      success: util.format($("Added column %s"), columnInfo[0]),
                      failure: util.format($("Failed to add column %s"), columnInfo[0]),
                      handler: function(callback) {
                        mobile.addColumn(options, columnInfo[0], { type: columnInfo[1] }, callback); } }); }); } ;






                if (options.addIndex) {
                  options.addIndex.split(",").forEach(function(column) {
                    plan.push({
                      progress: util.format($("Adding index to column %s"), column),
                      success: util.format($("Added index to column %s"), column),
                      failure: util.format($("Failed to add index to column %s"), column),
                      handler: function(callback) {
                        mobile.createIndex(options, column, callback); } }); }); } ;






                if (options.deleteColumn) {
                  options.deleteColumn.split(",").forEach(function(column) {
                    plan.push({
                      progress: util.format($("Deleting column %s"), column),
                      success: util.format($("Deleted column %s"), column),
                      failure: util.format($("Failed to delete column %s"), column),
                      handler: function(callback) {
                        mobile.deleteColumn(options, column, callback); } }); }); } ;






                failures = 0;
                i = 0; var __9 = false; return (function ___(__break) { var __more; var __loop = __cb(_, __frame, 0, 0, function __$__61() { __more = false; if (__9) { i++; } else { __9 = true; } ; var __8 = (i < plan.length); if (__8) {
                      step = plan[i];
                      progress = cli.interaction.progress(step.progress); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__61() { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__61() {


                                  return step.handler(__cb(_, __frame, 109, 19, function __$__61() {
                                    log.info(step.success); __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__61() { if (e) {

                                    log.error(step.failure);
                                    failures++; __then(); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__61() { _(null, null, true); }); }); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__61() {

                              progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__61() { while (__more) { __loop(); }; __more = true; }); }); } else { __break(); } ; }); do { __loop(); } while (__more); __more = true; })(function __$__61() {



                  if ((failures !== 0)) {
                    return _(new Error($("Not all update operations completed successfully"))); } ; _(); }); }); }, true)); }, true)); }); }); }); });



  mobileTable.command("delete [servicename] [tablename]").usage("[options] [servicename] [tablename]").description($("Delete a mobile service table")).option("-q, --quiet", $("do not prompt for confirmation")).option("-s, --subscription <id>", $("the subscription id")).execute(function __62(servicename, tablename, options, _) { var progress; var __frame = { name: "__62", line: 3909 }; return __func(_, this, arguments, __62, 3, __frame, function __$__62() {





      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptTableNameIfNotGiven(options, tablename, __cb(_, __frame, 2, 30, function ___(__0, __2) { options.tablename = __2; return (function __$__62(__then) {

            if (!options.quiet) {
              return cli.interaction.confirm($("Do you really want to delete the table? [y/n]: "), __cb(_, __frame, 5, 32, function ___(__0, __4) { var __3 = (__4 === false); return (function __$__62(__then) { if (__3) {
                    log.info($("Table was not deleted")); return _(null); } else { __then(); } ; })(__then); }, true)); } else { __then(); } ; })(function __$__62() {




            progress = cli.interaction.progress($("Deleting table")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__62() {

                  return mobile.deleteTable(options, __cb(_, __frame, 13, 19, function __$__62() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__62() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__62() { _(); }); }); }); }, true)); }, true)); }); });



  var mobileData = mobile.category("data").description($("Commands to manage your Mobile Service tables data"));


  mobileData.command("read [servicename] [tablename] [query]").usage("[options] [servicename] [tablename] [query]").description($("Query data from a mobile service table")).option("-k, --skip <top>", $("skip the first <skip> number of rows")).option("-t, --top <top>", $("return the first <top> number of remaining rows")).option("-l, --list", $("display results in list format")).option("-s, --subscription <id>", $("the subscription id")).execute(function __63(servicename, tablename, query, options, _) { var result, progress; var __frame = { name: "__63", line: 3938 }; return __func(_, this, arguments, __63, 4, __frame, function __$__63() {







      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptTableNameIfNotGiven(options, tablename, __cb(_, __frame, 2, 30, function ___(__0, __2) { options.tablename = __2;
          options.query = query;


          progress = cli.interaction.progress($("Reading table data")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__63() {


                return mobile.getData(options, __cb(_, __frame, 9, 28, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__63() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__63() {


              cli.interaction.formatOutput(result, function(data) {
                if ((!Array.isArray(data) || (data.length === 0))) {
                  log.info($("No matching records found")); }
                 else if (options.list) {
                  data.forEach(function(record) {
                    log.data("", "");
                    for (var i in record) {
                      log.data(i, ((record[i] === null) ? "<null>".green : record[i].toString().green)); }; });


                  log.data("", ""); }
                 else {
                  log.table(data, function(row, s) {
                    for (var i in s) {
                      row.cell(i, s[i]); }; }); }  ; }); _(); }); }); }, true)); }, true)); }); });






  mobileData.command("truncate [servicename] [tablename]").usage("[options] [servicename] [tablename]").description($("Delete all data from a mobile service table")).option("-q, --quiet", $("do not prompt for confirmation")).option("-s, --subscription <id>", $("the subscription id")).execute(function __64(servicename, tablename, options, _) { var result, progress; var __frame = { name: "__64", line: 3978 }; return __func(_, this, arguments, __64, 3, __frame, function __$__64() {





      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptTableNameIfNotGiven(options, tablename, __cb(_, __frame, 2, 30, function ___(__0, __2) { options.tablename = __2; return (function __$__64(__then) {




            if (!options.quiet) {
              progress = cli.interaction.progress($("Retrieving table information")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__64() {

                    return mobile.truncateTable(options, JSON.stringify({ confirm: false }), __cb(_, __frame, 10, 30, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__64() {

                      progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__64() {


                  if ((result.rowCount === 0)) {
                    log.info($("There is no data in the table.")); return _(null); } ;



                  log.info(util.format($("There are %s data rows in the table"), result.rowCount));
                  return cli.interaction.confirm($("Do you really want to delete all data from the table? [y/n]: "), __cb(_, __frame, 21, 33, function ___(__0, __5) { var __4 = !__5; return (function __$__64(__then) { if (__4) {
                        log.info($("No data was deleted.")); return _(null); } else { __then(); } ; })(__then); }, true)); }); }); } else { __then(); } ; })(function __$__64() {




            progress = cli.interaction.progress($("Truncating table data")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__64() {

                  return mobile.truncateTable(options, JSON.stringify({ confirm: true }), __cb(_, __frame, 29, 28, function ___(__0, __6) { result = __6; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__64() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__64() {


                cli.interaction.formatOutput(result, function(data) {
                  log.info(util.format($("Deleted %s rows"), data.rowCount)); }); _(); }); }); }); }, true)); }, true)); }); });



  mobileData.command("delete [servicename] [tablename] [recordid]").description($("Delete a record from the mobile service table")).option("-q, --quiet", $("do not prompt for confirmation")).option("-s, --subscription <id>", $("the subscription id")).execute(function __65(servicename, tablename, recordid, options, _) { var progress; var __frame = { name: "__65", line: 4021 }; return __func(_, this, arguments, __65, 4, __frame, function __$__65() {




      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptTableNameIfNotGiven(options, tablename, __cb(_, __frame, 2, 30, function ___(__0, __2) { options.tablename = __2;
          return promptIfNotGiven($("Record id: "), recordid, __cb(_, __frame, 3, 29, function ___(__0, __3) { options.recordid = __3;

            progress = cli.interaction.progress($("Deleting record")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__65() {

                  return mobile.deleteTableRecord(options, __cb(_, __frame, 7, 19, function __$__65() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__65() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__65() { _(); }); }); }, true)); }, true)); }, true)); }); });



  function displayScheduledJob(row, s) {
    row.cell($("Job name"), s.name);
    row.cell($("Script name"), ("scheduler/" + s.name));
    row.cell($("Status"), s.status);
    row.cell($("Interval"), (s.intervalUnit ? ((((s.intervalPeriod + " [") + s.intervalUnit) + "]")) : "on demand"));
    row.cell($("Last run"), (s.lastRun || "N/A"));
    row.cell($("Next run"), (s.nextRun || "N/A")); };


  var mobileScript = mobile.category("script").description($("Commands to manage your Mobile Service scripts"));


  mobileScript.command("list [servicename]").description($("List mobile service scripts")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __66(servicename, options, _) { var progress, results; var __frame = { name: "__66", line: 4049 }; return __func(_, this, arguments, __66, 2, __frame, function __$__66() {



      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress($("Retrieving script information"));
        results = { }; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__66() {

              return mobile.loadAllScripts(options, __cb(_, __frame, 6, 29, function ___(__0, __2) { results = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__66() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__66() {


            cli.interaction.formatOutput(results, function(scripts) {
              if (!scripts.table) {
                log.error($("Unable to get table scripts")); }
               else if ((!Array.isArray(scripts.table) || (scripts.table.length === 0))) {
                log.info($("There are no table scripts. Create scripts using the 'azure mobile script upload' command.")); }
               else {
                log.info($("Table scripts").green);
                log.table(scripts.table, function(row, s) {
                  row.cell($("Name"), ((("table/" + s.table) + ".") + s.operation));
                  row.cell($("Size"), s.sizeBytes); }); }  ;



              if (!scripts.shared) {
                log.error($("Unable to get shared scripts")); }
               else if ((!Array.isArray(scripts.shared) || (scripts.shared.length === 0))) {
                log.info($("There are no shared scripts. Create scripts using the 'azure mobile script upload' command.")); }
               else {
                log.info($("Shared scripts").green);
                log.table(scripts.shared, function(row, s) {
                  row.cell($("Name"), ("shared/" + s.name));
                  row.cell($("Size"), s.size); }); }  ;



              if (!scripts.scheduler) {
                log.error($("Unable to get scheduled job scripts")); }
               else if ((!Array.isArray(scripts.scheduler) || (scripts.scheduler.length === 0))) {
                log.info($("There are no scheduled job scripts. Create scheduled jobs using the 'azure mobile job' command.")); }
               else {
                log.info($("Scheduled job scripts").green);
                log.table(scripts.scheduler, displayScheduledJob); }  ;


              if (!scripts.api) {
                log.error($("Unable to get custom API scripts")); }
               else if ((!Array.isArray(scripts.api) || (scripts.api.length === 0))) {
                log.info($("There are no custom API scripts. Create APIs using the 'azure mobile api' command.")); }
               else {
                log.info($("Custom API scripts").green);
                log.table(scripts.api, displayCustomApi);
                if (scripts.api.some(function(api) { return (api.hasAdditionalPermissions === true); })) {
                  log.info($("* indicates the permissions metadata file has been manually modified.")); } ; }  ; }); _(); }); }); }, true)); }); });





  function checkScriptName(options) {
    if (!options.script) {
      log.info($("For table scripts, specify table/<tableName>.{insert|read|update|delete}"));
      log.info($("For shared scripts, specify shared/<scriptname>"));
      log.info($("For scheduler scripts, specify scheduler/<scriptName>"));
      log.info($("For custom API scripts, specify api/<scriptName>"));

      throw new Error(util.format($("Invalid script name '%s'"), options.scriptname)); } ; };



  function parseScriptName(scriptname) {
    var result = null, match = scriptname.match(/^(table|scheduler|shared|api)\/([^\.]+)/);


    if (!match) {
      return result; } ;


    var parts;
    if ((match[1] === "table")) {
      parts = scriptname.match(/^table\/([^\.]+)\.(insert|read|update|delete)(?:$|\.js$)/);
      if (parts) {
        result = { type: "table", table: { name: parts[1], operation: parts[2] } }; } ; }

     else {
      parts = match[2].match(/([a-zA-Z0-9_]+)(?:$|\.js$)/);
      if (parts) {
        result = { type: match[1] };
        result[match[1]] = { name: parts[1] }; } ; } ;



    return result; };


  function saveScriptFile(scriptSpec, script, output, force) {
    var file;
    var dir;

    if (output) {
      file = output; }
     else {
      dir = ("./" + scriptSpec.type);
      file = (dir + "/");
      if ((scriptSpec.type === "table")) {
        file += (((scriptSpec.table.name + ".") + scriptSpec.table.operation) + ".js"); }
       else {
        file += (scriptSpec[scriptSpec.type].name + ".js"); } ; } ;



    if ((utils.pathExistsSync(file) && !force)) {
      throw new Error(util.format($("File %s already exists. Use --override to override."), file)); }
     else {
      try {
        if (!output) {
          if (!utils.pathExistsSync(dir)) {
            fs.mkdirSync(dir); } ; } ;



        fs.writeFileSync(file, script, "utf8");
        log.info(util.format($("Saved script to %s"), file));

      } catch (e) {
        throw new Error(util.format($("Unable to save file '%s'"), file)); }; } ;



    return null; };


  var getScriptHandlers = {
    table: mobile.getTableScript,
    scheduler: mobile.getSchedulerScript,
    shared: mobile.getSharedScript,
    api: mobile.getCustomApiScript };


  mobileScript.command("download [servicename] [scriptname]").description($("Downloads a mobile service script")).option("-s, --subscription <id>", $("use the subscription id")).option("-f, --file <file>", $("file to save the script to")).option("-o, --override", $("override existing files")).option("-c, --console", $("write the script to the console instead of a file")).execute(function __67(servicename, scriptname, options, _) { var progress, script; var __frame = { name: "__67", line: 4194 }; return __func(_, this, arguments, __67, 3, __frame, function __$__67() {






      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("Script: "), scriptname, __cb(_, __frame, 2, 31, function ___(__0, __2) { options.scriptname = __2;
          options.script = parseScriptName(options.scriptname);
          checkScriptName(options);

          progress = cli.interaction.progress(util.format($("Downloading script: '%s'"), options.scriptname)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__67() {


                return getScriptHandlers[options.script.type](options, __cb(_, __frame, 9, 21, function ___(__0, __3) { script = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__67() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__67() {


              script = script.toString();

              if (options.console) {
                console.log(script); }
               else {
                saveScriptFile(options.script, script, options.file, options.override); } ; _(); }); }); }, true)); }, true)); }); });



  var setScriptHandlers = {
    table: mobile.setTableScript,
    scheduler: mobile.setSchedulerScript,
    shared: mobile.setSharedScript,
    api: mobile.setCustomApiScript };


  mobileScript.command("upload [servicename] [scriptname]").description($("Uploads a mobile service script")).option("-s, --subscription <id>", $("use the subscription id")).option("-f, --file <file>", $("file to read the script from")).execute(function __68(servicename, scriptname, options, _) { var script, progress; var __frame = { name: "__68", line: 4228 }; return __func(_, this, arguments, __68, 3, __frame, function __$__68() {




      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("Script: "), scriptname, __cb(_, __frame, 2, 31, function ___(__0, __2) { options.scriptname = __2;
          options.script = parseScriptName(options.scriptname);
          checkScriptName(options);

          if (!options.file) {
            options.file = (("./" + options.script.type) + "/");
            if (options.script.table) {
              options.file += (((options.script.table.name + ".") + options.script.table.operation) + ".js"); }
             else {
              options.file += (options.script[options.script.type].name + ".js"); } ; } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__68() {





                script = fs.readFileSync(options.file, "utf8"); __then(); }); })(function ___(e, __result) { __catch(function __$__68() { if (e) {


                  return _(new Error(util.format($("Unable to read script from file %s"), options.file))); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__68() {


              progress = cli.interaction.progress(util.format($("Uploading script: '%s'"), options.scriptname)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__68() {

                    return setScriptHandlers[options.script.type](options, script, __cb(_, __frame, 25, 12, function __$__68() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__68() {

                      progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__68() { _(); }); }); }); }); }, true)); }, true)); }); });



  var deleteScriptHandlers = {
    table: mobile.deleteTableScript,
    scheduler: mobile.deleteSchedulerScript,
    shared: mobile.deleteSharedScript,
    api: mobile.deleteCustomApi };


  mobileScript.command("delete [servicename] [scriptname]").description($("Deletes a mobile service script")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __69(servicename, scriptname, options, _) { var progress; var __frame = { name: "__69", line: 4269 }; return __func(_, this, arguments, __69, 3, __frame, function __$__69() {



      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("Script: "), scriptname, __cb(_, __frame, 2, 31, function ___(__0, __2) { options.scriptname = __2;
          options.script = parseScriptName(options.scriptname);
          checkScriptName(options);

          progress = cli.interaction.progress(util.format($("Deleting script: '%s'"), options.scriptname)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__69() {

                return deleteScriptHandlers[options.script.type](options, __cb(_, __frame, 8, 12, function __$__69() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__69() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__69() { _(); }); }); }, true)); }, true)); }); });



  var mobileScale = mobile.category("scale").description($("Commands to manage your Mobile Service scaling"));


  mobileScale.command("show [servicename]").description($("Show the scale settings of a mobile service")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __70(servicename, options, _) { var result, progress; var __frame = { name: "__70", line: 4289 }; return __func(_, this, arguments, __70, 2, __frame, function __$__70() {



      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;


        progress = cli.interaction.progress($("Retrieving scale settings")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__70() {

              return mobile.getScaleSettings(options, __cb(_, __frame, 6, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__70() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__70() {


            cli.interaction.formatOutput(result, displayScaleSettings); _(); }); }); }, true)); }); });


  mobileScale.command("change [servicename]").description($("Change the scale settings of a mobile service")).option("-s, --subscription <id>", $("use the subscription id")).option("-t, --tier <tier>", $("choose the free, basic or standard tier")).option("-i, --numberOfInstances <count>", $("number of instances in basic or standard mode")).option("-q, --quiet", $("do not prompt for confirmation")).execute(function __71(servicename, options, _) { var userSpecifiedTier, proceed, progress, scalesettings, newScaleSettings, scaleInfo; var __frame = { name: "__71", line: 4309 }; return __func(_, this, arguments, __71, 2, __frame, function __$__71() {






      userSpecifiedTier = options.tier;
      if ((!options.tier && !options.numberOfInstances)) {
        return _(new Error($("Specify at least one option. Type --help for more information."))); } ;



      if (!__.isUndefined(options.tier)) {
        options.tier = findScale(options.tier);
        if ((options.tier === undefined)) {
          return _(new Error(util.format($("Allowed values for tier are %s, %s or %s."), scaleInformation["tier1"].name, scaleInformation["tier2"].name, scaleInformation["tier3"].name))); } ;




        if (((options.tier === "tier1") && __.isUndefined(options.numberOfInstances))) {
          options.numberOfInstances = 1; } ; } ;




      if ((!__.isUndefined(options.numberOfInstances) && isNaN(options.numberOfInstances))) {
        return _(new Error($("Number of instances must be a positive integer."))); } ;


      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 25, 32, function ___(__0, __1) { options.servicename = __1; return (function __$__71(__then) {
          if (((userSpecifiedTier === "standard") && !options.quiet)) {
            return cli.interaction.confirm($("Mobile service scale tiers have changed, set scale to Standard (previously Premium)? [y/n]: "), __cb(_, __frame, 27, 42, function ___(__0, __2) { proceed = __2;
              if (!proceed) {
                log.info($("Change scale cancelled with no changes made.")); return _(null); } ; __then(); }, true)); } else { __then(); } ; })(function __$__71() {




          progress = cli.interaction.progress($("Rescaling the mobile service")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__71() {


                return mobile.getScaleSettings(options, __cb(_, __frame, 37, 35, function ___(__0, __3) { scalesettings = __3;
                  scalesettings.tier = findScale(scalesettings.tier, true); __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__71() { if (e) {


                  progress.end();
                  return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__71() {


              newScaleSettings = {
                tier: (options.tier || scalesettings.tier),
                numberOfInstances: (options.numberOfInstances || scalesettings.numberOfInstances) };


              if (((newScaleSettings.tier === scalesettings.tier) && (newScaleSettings.numberOfInstances == scalesettings.numberOfInstances))) {


                progress.end();
                log.info($("Current scale settings of the mobile service already match the requested settings. No changes are made.")); return _(null); } ;




              scaleInfo = scaleInformation[newScaleSettings.tier];
              if ((scaleInfo.maxInstances < newScaleSettings.numberOfInstances)) {
                progress.end();
                if ((scaleInfo.maxInstances === 1)) {
                  return _(new Error(util.format($("Number of instances must be set to 1 when the mobile service is in the %s tier."), scaleInfo.name))); } ;



                return _(new Error(util.format($("Cannot set number of instances to %d when the mobile service is in the %s tier. Valid values for this tier are 1 to %d."), newScaleSettings.numberOfInstances, scaleInfo.name, scaleInfo.maxInstances))); } ; return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__71() {




                    return mobile.setScaleSettings(options, newScaleSettings, __cb(_, __frame, 72, 19, function __$__71() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__71() {

                      progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__71() { _(); }); }); }); }); }); }, true)); }); });



  var mobileJob = mobile.category("job").description($("Commands to manage your Mobile Service scheduled jobs"));


  mobileJob.command("list [servicename]").usage("[options] [servicename]").description($("List mobile service scheduled jobs")).option("-s, --subscription <id>", $("the subscription id")).execute(function(servicename, options, callback) {





    if (servicename) {
      ensuredServiceName(servicename); }
     else {
      promptString($("Mobile service name: "), ensuredServiceName); } ;


    function ensuredServiceName(servicename) {
      options.servicename = servicename;

      mobile.getSchedulerScripts(options, function(error, results) {
        if (error) {
          return callback(error); } ;


        if (log.format().json) {
          log.json(results); }
         else {
          if ((!Array.isArray(results) || (results.length === 0))) {
            log.info($("There are no scheduled jobs. Create scheduled jobs using the 'azure mobile job create' command")); }
           else {
            log.info($("Scheduled jobs").green);
            log.table(results, displayScheduledJob);
            log.info($("You can manipulate scheduled job scripts using the 'azure mobile script' command.").green); } ; } ;



        callback(); }); }; });




  var intervalUnits = ["second","minute","hour","day","month","year","none",];

  mobileJob.command("create [servicename] [jobname]").usage("[options] [servicename] [jobname]").description($("Create a mobile service scheduled job")).option("-i, --interval <number>", $("job interval as an integer; defaults to 15")).option("-u, --intervalUnit <unit>", $("specify one of: minute, hour, day, month or none for on-demand jobs; defaults to minute")).option("-t, --startTime <time>", $("time of the first run of the script in ISO format; defaults to now")).option("-s, --subscription <id>", $("the subscription id")).execute(function(servicename, jobname, options, callback) {







    options.interval = ((typeof options.interval === "undefined") ? 15 : +options.interval);
    options.intervalUnit = (options.intervalUnit || "minute");

    if ((isNaN(options.interval) || (options.interval < 0))) {
      return callback(new Error($("The --interval must be a positive integer"))); } ;


    if (!intervalUnits.some(function(unit) { return (unit === options.intervalUnit); })) {
      return callback(util.format($("The --intervalUnit must be one of %s"), intervalUnits.join(", "))); } ;


    if (servicename) {
      ensuredServiceName(servicename); }
     else {
      promptString($("Mobile service name: "), ensuredServiceName); } ;


    function ensuredServiceName(servicename) {
      options.servicename = servicename;

      if (jobname) {
        ensuredJobName(jobname); }
       else {
        promptString($("Scheduled job name: "), ensuredJobName); } ;


      function ensuredJobName(jobname) {
        options.jobname = jobname;

        var job = {
          name: options.jobname };


        if ((options.intervalUnit !== "none")) {
          job.intervalUnit = options.intervalUnit;
          job.intervalPeriod = options.interval;
          job.startTime = (options.startTime || new Date().toISOString()); } ;


        mobile.createJob(options, JSON.stringify(job), function(error) {
          if (error) {
            return callback(error); } ;


          log.info($("Job was created in disabled state. You can enable the job using the 'azure mobile job update' command").green);
          log.info($("You can manipulate the scheduled job script using the 'azure mobile script' command").green);
          callback(); }); }; }; });





  mobileJob.command("update [servicename] [jobname]").usage("[options] [servicename] [jobname]").description($("Update a mobile service scheduled job")).option("-i, --interval <number>", $("job interval as an integer")).option("-u, --intervalUnit <unit>", $("specify one of: minute, hour, day, month or none for on-demand jobs")).option("-t, --startTime <time>", $("time of the first run of the script in ISO format")).option("-a, --status <status>", $("enabled or disabled")).option("-s, --subscription <id>", $("the subscription id")).execute(function __72(servicename, jobname, options, _) { var progress, job, newJob, changed, i; var __frame = { name: "__72", line: 4497 }; return __func(_, this, arguments, __72, 3, __frame, function __$__72() {









      if ((((typeof options.interval !== "undefined") && isNaN(options.interval)) || (options.interval < 0))) {
        return _(new Error($("The --interval must be a positive integer"))); } ;


      if (((typeof options.intervalUnits !== "undefined") && !intervalUnits.some(function(unit) { return (unit === options.intervalUnit); }))) {
        return _(new Error(util.format($("The --intervalUnit must be one of %s"), intervalUnits.join(", ")))); } ;


      if ((((typeof options.status !== "undefined") && (options.status !== "enabled")) && (options.status !== "disabled"))) {
        return _(new Error($("The --status must be either enabled or disabled"))); } ;


      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 14, 32, function ___(__0, __1) { options.servicename = __1;
        return cli.interaction.chooseIfNotGiven($("Scheduled job name: "), $("Getting choices"), jobname, function(cb) {

          mobile.getSchedulerScripts(options, function(error, jobs) {
            if (error) { return cb(error); } ;
            log.silly(JSON.stringify(jobs));

            cb(null, jobs.map(function(job) { return job.name; })); }); }, __cb(_, __frame, 15, 44, function ___(__0, __2) { options.jobname = __2;



          progress = cli.interaction.progress($("Updating job settings")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__72() {


                return mobile.getJob(options, __cb(_, __frame, 28, 25, function ___(__0, __3) { job = __3; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__72() { if (e) {

                  progress.end();
                  return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__72() {


              log.silly($("Current settings for job: "));
              log.json("silly", job);

              if ((options.intervalUnit === "none")) {
                newJob = {
                  status: "disabled",
                  intervalUnit: undefined }; }

               else {
                newJob = {
                  intervalPeriod: (+options.interval || job.intervalPeriod),
                  intervalUnit: (options.intervalUnit || job.intervalUnit),
                  startTime: ((options.startTime || job.startTime) || "1900-01-01T00:00:00Z"),
                  status: (options.status || job.status) }; } ;



              changed = false;
              for (i in newJob) {
                if ((newJob[i] !== job[i])) {
                  changed = true;
                  break; } ; }; return (function __$__72(__then) {



                if (changed) { return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__72() {

                        return mobile.setJob(options, newJob, __cb(_, __frame, 61, 21, __then, true)); }); })(function ___(e, __result) { __catch(function __$__72() { if (e) {

                          progress.end();
                          return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, __then); }); } else {


                  log.info($("The scheduled job settings already match the requested settings. No changes made")); __then(); } ; })(function __$__72() {

                progress.end(); _(); }); }); }); }, true)); }, true)); }); });



  mobileJob.command("delete [servicename] [jobname]").usage("[options] [servicename] [jobname]").description($("Delete a mobile service scheduled job")).option("-s, --subscription <id>", $("the subscription id")).execute(function(servicename, jobname, options, callback) {





    if (servicename) {
      ensuredServiceName(servicename); }
     else {
      promptString($("Mobile service name: "), ensuredServiceName); } ;


    function ensuredServiceName(servicename) {
      options.servicename = servicename;

      if (jobname) {
        ensuredJobName(jobname); }
       else {
        promptString($("Scheduled job name: "), ensuredJobName); } ;


      function ensuredJobName(jobname) {
        options.jobname = jobname;
        mobile.deleteSchedulerScript(options, callback); }; }; });




  var mobilePreview = mobile.category("preview").description($("Commands to enable preview features for your Mobile Service"));


  mobilePreview.command("list [servicename]").description($("Show the preview features enabled for a mobile service")).option("-s, --subscription <id>", $("the subscription id")).execute(function __73(servicename, options, _) { var progress, result; var __frame = { name: "__73", line: 4604 }; return __func(_, this, arguments, __73, 2, __frame, function __$__73() {



      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress($("Getting preview features")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__73() {


              return mobile.getPreviews(options, __cb(_, __frame, 6, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__73() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__73() {


            cli.interaction.formatOutput(result, function(features) {
              if (((features && ((features.enabled && (features.enabled.length > 0)))) || ((features.available && (features.available.length > 0))))) {
                var combinedFeatures = __.union(features.enabled, features.available);
                log.table(combinedFeatures, function(row, f) {
                  row.cell($("Preview feature"), f);
                  row.cell($("Enabled"), (__.contains(features.enabled, f) ? "Yes".green : "No")); });

                log.info($("You can enable preview features using the 'azure mobile preview enable' command.")); }
               else {
                log.data($("There are no preview features available.")); } ; }); _(); }); }); }, true)); }); });




  mobilePreview.command("enable [servicename] [featurename]").usage("[options] [servicename] [featurename]").description($("Enable a preview feature for a mobile service. Note that preview features cannot be disabled for a mobile service!")).option("-s, --subscription <id>", $("the subscription id")).execute(function __74(servicename, featurename, options, _) { var progress, result; var __frame = { name: "__74", line: 4633 }; return __func(_, this, arguments, __74, 3, __frame, function __$__74() {




      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return cli.interaction.chooseIfNotGiven($("Preview feature: "), $("Getting choices"), featurename, function(cb) {

          mobile.getPreviews(options, function(error, features) {
            if (error) { return cb(error); } ;
            cb(null, features.available); }); }, __cb(_, __frame, 2, 48, function ___(__0, __2) { options.featurename = __2;



          progress = cli.interaction.progress($("Enabling preview feature for mobile service")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__74() {


                return mobile.enablePreview(options, { enable: options.featurename }, __cb(_, __frame, 13, 28, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__74() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__74() {


              cli.interaction.formatOutput(result, function(feature) {
                log.info($("Result of enabling feature:").green);
                log.info(feature.summary);

                Object.keys(feature.data).forEach(function(property) {
                  var value = feature.data[property];
                  if (__.isObject(value)) {
                    value = JSON.stringify(value); } ;

                  log.data(util.format($("data.%s"), property), value.green); });


                log.verbose(util.format($("Detailed information: %s"), result.details)); }); _(); }); }); }, true)); }, true)); }); });



  var mobileApi = mobile.category("api").description($("Commands to manage your mobile service APIs"));


  mobileApi.command("list [servicename]").description($("List mobile service custom APIs")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __75(servicename, options, _) { var progress, result; var __frame = { name: "__75", line: 4673 }; return __func(_, this, arguments, __75, 2, __frame, function __$__75() {



      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress($("Retrieving list of APIs")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__75() {


              return mobile.getCustomApis(options, __cb(_, __frame, 6, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__75() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__75() {


            cli.interaction.formatOutput(result, function(apis) {
              if ((!Array.isArray(apis) || (apis.length === 0))) {
                log.info($("There are no custom APIs. Create an API using the 'azure mobile api create' command.")); }
               else {
                log.info($("APIs").green);
                log.table(apis, displayCustomApi);
                if (apis.some(function(api) { return (api.hasAdditionalPermissions === true); })) {
                  log.info($("* indicates the permissions metadata file has been manually modified.")); } ;

                log.info($("You can manipulate API scripts using the 'azure mobile script' command.").green); } ; }); _(); }); }); }, true)); }); });




  function displayCustomApi(row, s) {
    var name = s.name;
    if ((s.hasAdditionalPermissions === true)) {
      name += "*"; } ;


    row.cell($("Name"), name);
    row.cell("Get", (s.get || "admin"));
    row.cell("Put", (s.put || "admin"));
    row.cell("Post", (s.post || "admin"));
    row.cell("Patch", (s.patch || "admin"));
    row.cell("Delete", (s.delete || "admin")); };


  mobileApi.command("create [servicename] [apiname]").description($("Creates a mobile service custom API")).option("-s, --subscription <id>", $("use the subscription id")).option("-p, --permissions <permissions>", $("comma delimited list of <method>=<permission> pairs")).execute(function __76(servicename, apiname, options, _) { var settings, progress; var __frame = { name: "__76", line: 4716 }; return __func(_, this, arguments, __76, 3, __frame, function __$__76() {




      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("API name: "), apiname, __cb(_, __frame, 2, 28, function ___(__0, __2) { options.apiname = __2;

          settings = parsePermissions(options.permissions, methods);


          methods.forEach(function(method) {
            if (!settings[method]) {
              settings[method] = "application"; } ; });


          settings["name"] = options.apiname;


          progress = cli.interaction.progress(util.format($("Creating custom API: '%s'"), options.apiname)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__76() {

                return mobile.createApi(options, settings, __cb(_, __frame, 17, 19, function __$__76() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__76() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__76() {


              log.info($("API was created successfully. You can modify the API using the 'azure mobile script' command.").green); _(); }); }); }, true)); }, true)); }); });


  mobileApi.command("update [servicename] [apiname]").description($("Updates a mobile service custom API")).option("-s, --subscription <id>", $("use the subscription id")).option("-p, --permissions <permissions>", $("comma delimited list of <method>=<permission> pairs")).option("-f, --force", $("override any custom changes to the permissions metadata file")).execute(function __77(servicename, apiname, options, _) { var settings, progress, result; var __frame = { name: "__77", line: 4746 }; return __func(_, this, arguments, __77, 3, __frame, function __$__77() {





      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("API name: "), apiname, __cb(_, __frame, 2, 28, function ___(__0, __2) { options.apiname = __2;
          if (!options.permissions) {
            return _(new Error($("No updates specified. Check the list of available updates with '--help' and specify at least one."))); } ;


          settings = parsePermissions(options.permissions, methods);
          progress = cli.interaction.progress(util.format($("Updating API: '%s'"), options.apiname)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__77() {




                return mobile.getCustomApi(options, __cb(_, __frame, 13, 28, function ___(__0, __3) { result = __3; __then(); }, true)); }); })(function ___(e, __result) { __catch(function __$__77() { if (e) {


                  progress.end();
                  return _(e); } else { _(null, __result); } ; }, _); }); })(function ___() { __tryCatch(_, function __$__77() {


              log.silly($("Existing api settings:"));
              log.json("silly", result);


              if (((result.hasAdditionalPermissions === true) && (options.force !== true))) {
                progress.end();
                return _(new Error($("The permissions for this custom API cannot be changed because the metadata file has been edited directly. To change the permissions and overwrite the existing metadata use the '--force' option."))); } ;



              methods.forEach(function(method) {
                if (!settings[method]) {
                  settings[method] = result[method]; } ; }); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__77() {





                    return mobile.setCustomApi(options, settings, __cb(_, __frame, 38, 19, function __$__77() { _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__77() {

                      progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__77() { _(); }); }); }); }); }, true)); }, true)); }); });



  mobileApi.command("delete [servicename] [apiname]").description($("Deletes a mobile service custom API")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __78(servicename, apiname, options, _) { var progress; var __frame = { name: "__78", line: 4793 }; return __func(_, this, arguments, __78, 3, __frame, function __$__78() {



      return promptServiceNameIfNotGiven(options, servicename, nodeFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("API name: "), apiname, __cb(_, __frame, 2, 28, function ___(__0, __2) { options.apiname = __2;

          progress = cli.interaction.progress(util.format($("Deleting API: '%s'"), options.apiname)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__78() {

                return mobile.deleteCustomApi(options, __cb(_, __frame, 6, 28, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__78() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__78() { _(); }); }); }, true)); }, true)); }); });



  var mobileAppSetting = mobile.category("appsetting").description($("Commands to manage your mobile application app settings"));


  mobileAppSetting.command("list [servicename]").description($("Show your mobile application app settings")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __79(servicename, options, _) { var progress; var __frame = { name: "__79", line: 4811 }; return __func(_, this, arguments, __79, 2, __frame, function __$__79() {



      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;

        progress = cli.interaction.progress($("Retrieving app settings")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__79() {

              return mobile.getServiceSettings(options, __cb(_, __frame, 5, 28, function ___(__0, __2) { result = __2; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__79() {

                progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__79() {


            if ((result.customApplicationSettings === undefined)) {
              result.customApplicationSettings = []; } ;


            cli.interaction.formatOutput(result.customApplicationSettings, function(appSettings) {
              if ((appSettings.length > 0)) {
                log.table(appSettings, function(row, item) {
                  row.cell($("Name"), item.name);
                  row.cell($("Value"), item.value); }); }

               else {
                log.info($("No app settings are defined")); } ; }); _(); }); }); }, true)); }); });




  mobileAppSetting.command("add [servicename] [name] [value]").description($("Add an application setting for your mobile service")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __80(servicename, name, value, options, _) { var result, progress, lowerCaseName, setting; var __frame = { name: "__80", line: 4840 }; return __func(_, this, arguments, __80, 4, __frame, function __$__80() {



      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("App setting name: "), name, __cb(_, __frame, 2, 32, function ___(__0, __2) { options.settingName = __2;
          return promptIfNotGiven($("App setting value: "), value, __cb(_, __frame, 3, 33, function ___(__0, __3) { options.settingValue = __3;


            progress = cli.interaction.progress($("Retrieving app settings")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__80() {

                  return mobile.getServiceSettings(options, __cb(_, __frame, 8, 28, function ___(__0, __4) { result = __4; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__80() {

                    progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__80() {


                if ((result.customApplicationSettings === undefined)) {
                  result.customApplicationSettings = []; } ;


                lowerCaseName = options.settingName.toLowerCase();
                setting = __.find(result.customApplicationSettings, function(setting) {
                  return (setting.name.toLowerCase() === lowerCaseName); });


                if ((setting !== undefined)) {
                  return _(new Error(util.format($("App setting with key '%s' already exists"), setting.name))); } ;


                result.customApplicationSettings.push({ name: options.settingName, value: options.settingValue });

                progress = cli.interaction.progress($("Adding app setting")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__80() {

                      return mobile.setServiceSettings(options, result, __cb(_, __frame, 30, 28, function ___(__0, __5) { result = __5; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__80() {

                        progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__80() { _(); }); }); }); }); }, true)); }, true)); }, true)); }); });



  mobileAppSetting.command("delete [servicename] [name]").description($("Remove an application setting for your mobile service")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __81(servicename, name, options, _) { var result, progress, lowerCaseName, newAppSettings; var __frame = { name: "__81", line: 4879 }; return __func(_, this, arguments, __81, 3, __frame, function __$__81() {



      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("App setting name: "), name, __cb(_, __frame, 2, 32, function ___(__0, __2) { options.settingName = __2;


          progress = cli.interaction.progress($("Retrieving app settings")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__81() {

                return mobile.getServiceSettings(options, __cb(_, __frame, 7, 28, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__81() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__81() {


              if ((result.customApplicationSettings === undefined)) {
                result.customApplicationSettings = []; } ;


              lowerCaseName = options.settingName.toLowerCase();
              newAppSettings = __.reject(result.customApplicationSettings, function(setting) {
                return (setting.name.toLowerCase() === lowerCaseName); });


              if ((newAppSettings.length === result.customApplicationSettings.length)) {
                return _(new Error(util.format($("App setting with key '%s' doesn't exist"), options.settingName))); } ;


              result.customApplicationSettings = newAppSettings;
              progress = cli.interaction.progress(util.format($("Removing app setting '%s'"), options.settingName)); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__81() {

                    return mobile.setServiceSettings(options, result, __cb(_, __frame, 28, 28, function ___(__0, __4) { result = __4; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__81() {

                      progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__81() { _(); }); }); }); }); }, true)); }, true)); }); });



  mobileAppSetting.command("show [servicename] [name]").description($("Show an application setting for your mobile service")).option("-s, --subscription <id>", $("use the subscription id")).execute(function __82(servicename, name, options, _) { var result, progress, lowerCaseName, setting; var __frame = { name: "__82", line: 4916 }; return __func(_, this, arguments, __82, 3, __frame, function __$__82() {



      return promptServiceNameIfNotGiven(options, servicename, defaultFilter, __cb(_, __frame, 1, 32, function ___(__0, __1) { options.servicename = __1;
        return promptIfNotGiven($("App setting name: "), name, __cb(_, __frame, 2, 32, function ___(__0, __2) { options.settingName = __2;


          progress = cli.interaction.progress($("Retrieving app settings")); return (function ___(__then) { (function ___(_) { __tryCatch(_, function __$__82() {

                return mobile.getServiceSettings(options, __cb(_, __frame, 7, 28, function ___(__0, __3) { result = __3; _(null, null, true); }, true)); }); })(function ___(__e, __r, __cont) { (function ___(__then) { __tryCatch(_, function __$__82() {

                  progress.end(); __then(); }); })(function ___() { __tryCatch(_, function ___() { if (__cont) { __then(); } else { _(__e, __r); }; }); }); }); })(function ___() { __tryCatch(_, function __$__82() {


              lowerCaseName = options.settingName.toLowerCase();
              setting = __.find(result.customApplicationSettings, function(setting) {
                return (setting.name.toLowerCase() === lowerCaseName); });


              cli.interaction.formatOutput(setting, function(data) {
                if ((data === undefined)) {
                  log.error(util.format($("App setting with key '%s' doesn't exist"), options.settingName)); }
                 else {
                  log.info(util.format($("%s: %s"), data.name, data.value)); } ; }); _(); }); }); }, true)); }, true)); }); });};
