Advertisement
ThisIsMac

Untitled

Jan 2nd, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. /**
  4.  * @constructor
  5.  * Keymetrics
  6.  *
  7.  * @param {object} opts                 The options are passed to the children instances
  8.  * @param {string} opts.refresh_token   [Required] Refresh token (retrieved from Keymetrics dashboard)
  9.  * @param {string} opts.token_type      [Required] Type: 'refresh_token' or 'access_token'
  10.  * @param {string} opts.access_token    [Optional] Access token
  11.  * @param {string} opts.public_key      [Optional] Bucket public key
  12.  * @param {string} opts.realtime        [Optional] When true, attempts realtime connection on .init()
  13.  * @param {string} opts.public_key      [Optional] Bucket id
  14.  * @param {string} opts.host            [Optional] Base url used (default 'http://app.keymetrics.io:3000')
  15.  * @param {string} opts.basePath        [Optional] Base API path (default '/api')
  16.  * @param {function} opts.bus           [Optional] EventEmitter2 instance
  17.  */
  18. declare class Keymetrics {
  19.  
  20.   user: User;
  21.   bucket: Bucket;
  22.   realtime: Realtime;
  23.   auth: Authenticate;
  24.   bus: any;
  25.  
  26.   /**
  27.    * @constructor
  28.    * Keymetrics
  29.    *
  30.    * @param {object} opts                 The options are passed to the children instances
  31.    * @param {string} opts.refresh_token   [Required] Refresh token (retrieved from Keymetrics dashboard)
  32.    * @param {string} opts.token_type      [Required] Type: 'refresh_token' or 'access_token'
  33.    * @param {string} opts.access_token    [Optional] Access token
  34.    * @param {string} opts.public_key      [Optional] Bucket public key
  35.    * @param {string} opts.realtime        [Optional] When true, attempts realtime connection on .init()
  36.    * @param {string} opts.public_key      [Optional] Bucket id
  37.    * @param {string} opts.host            [Optional] Base url used (default 'http://app.keymetrics.io:3000')
  38.    * @param {string} opts.basePath        [Optional] Base API path (default '/api')
  39.    * @param {function} opts.bus           [Optional] EventEmitter2 instance
  40.    */
  41.   constructor(opts: { refresh_token: string,
  42.                       token_type: string,
  43.                       access_token: string,
  44.                       public_key: string,
  45.                       realtime: string,
  46.                       host: string,
  47.                       basePath: string,
  48.                       bus: (() => any)
  49.               });
  50.  
  51.   /**
  52.    * Start the Keymetrics connection
  53.    *
  54.    * @param {function} callback Runs once connection is complete
  55.    *
  56.    */
  57.   init(callback: (() => any)): void;
  58. }
  59.  
  60.  
  61.  
  62. /**
  63.  * Recursive cloning array.
  64.  */
  65. declare function deepCloneArray(): void;
  66.  
  67. /**
  68.  * Extening object that entered in first argument.
  69.  *
  70.  * Returns extended object or false if have no target object or incorrect type.
  71.  *
  72.  * If you wish to clone source object (without modify it), just use empty new
  73.  * object as first argument, like this:
  74.  *   deepExtend({}, yourObj_1, [yourObj_N]);
  75.  */
  76. declare var deepExtend: any;
  77.  
  78.  
  79. /**
  80.     * Bucket
  81.     * @constructor
  82.     * @memberof Keymetrics
  83.     * @alias bucket
  84.     *
  85.     * @param {object}      opts                Options
  86.     * @property {object}   _id          ID of currently selected bucket
  87.     * @property {object}   current_raw  Raw data from current selected Bucket
  88.     * @property {object}   servers      (Realtime) List of connected Bucket servers
  89.     * @property {object}   apps         (Realtime) List of connected Bucket applications
  90.     * @property {object}   apps_server  (Realtime) List of connected apps per server
  91.     * @property {object}   mini_metrics (Realtime) List of metrics per app per server
  92.     */
  93. declare class Bucket {
  94.  
  95.   Alert: AlertMethods;
  96.   User: UserMethods;
  97.   Data: DataMethods;
  98.   Action: ActionMethods;
  99.  
  100.   /**
  101.    * Bucket
  102.    * @constructor
  103.    * @memberof Keymetrics
  104.    * @alias bucket
  105.    *
  106.    * @param {object}      opts                Options
  107.    * @property {object}   _id          ID of currently selected bucket
  108.    * @property {object}   current_raw  Raw data from current selected Bucket
  109.    * @property {object}   servers      (Realtime) List of connected Bucket servers
  110.    * @property {object}   apps         (Realtime) List of connected Bucket applications
  111.    * @property {object}   apps_server  (Realtime) List of connected apps per server
  112.    * @property {object}   mini_metrics (Realtime) List of metrics per app per server
  113.    */
  114.   constructor(opts: Object);
  115.  
  116.   /**
  117.    * Retrieve Bucket from public key
  118.    *
  119.    * @param  {string} public_id   Bucket public key
  120.    * @param  {callback} cb        description
  121.    */
  122.   retrieve(public_id: string, cb: Function): void;
  123.  
  124.   /**
  125.    * Connect to bucket from public key
  126.    *
  127.    * @param  {string} public_id Public key
  128.    */
  129.   connect(public_id: string): void;
  130.  
  131.   /**
  132.    * Retrieve Bucket from ID
  133.    *
  134.    * @param  {string} raw_id      Bucket ID
  135.    * @param  {callback} cb        Callback
  136.    */
  137.   retrieveFromID(raw_id: string, cb: Function): void;
  138.  
  139.   /**
  140.    * Connect to bucket from id
  141.    *
  142.    * @param  {string} raw_id Bucket Id
  143.    */
  144.   connectFromID(raw_id: string): void;
  145.  
  146.   /**
  147.    * Populate all bucket information
  148.    *
  149.    * @param  {function} cb Callback
  150.    */
  151.   init(cb: (() => any)): void;
  152.  
  153.   /**
  154.    * Retrieve all bucket information
  155.    *
  156.    * @param  {function} cb Callback
  157.    */
  158.   all(cb: (() => any)): void;
  159.  
  160.   /**
  161.    * Find current user role
  162.    *
  163.    * @param  {function} cb Callback
  164.    */
  165.   fetchUserRole(cb: (() => any)): void;
  166.  
  167.   /**
  168.    * Retrieve current bucket information
  169.    *
  170.    * @param  {function} cb Callback
  171.    */
  172.   get(cb: (() => any)): void;
  173.  
  174.   /**
  175.    * Retrieve avalaible Keymetrics plans
  176.    *
  177.    * @param  {function} cb Callback
  178.    */
  179.   getPlans(cb: (() => any)): void;
  180.  
  181.   /**
  182.    * Retrieve probe data history
  183.    *
  184.    * @param  {object} opts Options
  185.    * @param  {object} opts.app_name Application name
  186.    * @param  {object} opts.server_name Server name
  187.    * @param  {object} opts.minutes Minutes
  188.    * @param  {object} opts.interval interval
  189.    * @param  {function} cb Callback
  190.    */
  191.   getProbesHistory(opts: { app_name: Object, server_name: Object, minutes: Object, interval: Object }, cb: (() => any)): void;
  192.  
  193.   /**
  194.    * Retrieve probe meta history
  195.    *
  196.    * @param  {object} opts Options
  197.    * @param  {object} opts.app_name Application name
  198.    * @param  {object} opts.server_name Server name
  199.    * @param  {object} opts.minutes Minutes
  200.    * @param  {function} cb Callback
  201.    */
  202.   getProbesMeta(opts: { app_name: Object, server_name: Object, minutes: Object }, cb: (() => any)): void;
  203.  
  204.   /**
  205.    * Retrieve servers metadata
  206.    *
  207.    * @param  {function} cb Callback
  208.    */
  209.   getMetaServers(cb: (() => any)): void;
  210.  
  211.   /**
  212.    * Save server metadata
  213.    *
  214.    * @param  {object} server  Server
  215.    * @param  {function} cb    Callback
  216.    */
  217.   saveMetaServer(server: Object, cb: (() => any)): void;
  218.  
  219.   /**
  220.    * Update server metadata
  221.    *
  222.    * @param  {object} server  Server
  223.    * @param  {function} cb    Callback
  224.    */
  225.   update(server: Object, cb: (() => any)): void;
  226.  
  227. }
  228.  
  229.  
  230. /**
  231.        * Action
  232.        * @memberof Keymetrics.bucket
  233.        * @constructor
  234.        *
  235.        * @param {object} opts Options
  236.        */
  237. declare class ActionMethods {
  238.   /**
  239.    * Action
  240.    * @memberof Keymetrics.bucket
  241.    * @constructor
  242.    *
  243.    * @param {object} opts Options
  244.    */
  245.   constructor(opts: Object);
  246.  
  247.   /**
  248.    * Trigger action
  249.    *
  250.    * @param  {object} opts              Options
  251.    * @param  {object} opts.server_name  Server Name
  252.    * @param  {object} opts.process_id   Process id
  253.    * @param  {object} opts.action_name  Action name
  254.    * @param  {function} cb              callback
  255.    */
  256.   trigger(opts: { server_name: Object, process_id: Object, action_name: Object }, cb: (() => any)): void;
  257.  
  258.   /**
  259.    * Trigger pm2 action
  260.    *
  261.    * @param  {type} opts              options
  262.    * @param  {type} opts.server_name  Server name
  263.    * @param  {type} opts.method_name  Method name
  264.    * @param  {type} cb                callback
  265.    */
  266.   triggerPM2action(opts: Object, cb: Function): void;
  267.  
  268.   /**
  269.    * Trigger scoped action
  270.    *
  271.    * @param  {object} opts              Options
  272.    * @param  {object} opts.server_name  Server Name
  273.    * @param  {object} opts.action_name  Action name
  274.    * @param  {object} opts.app_name  App name
  275.    * @param  {object} opts.pm_id        Process id
  276.    * @param  {function} cb              callback
  277.    */
  278.   triggerScopedAction(opts: { server_name: Object, action_name: Object, app_name: Object, pm_id: Object }, cb: (() => any)): void;
  279.  
  280.   /**
  281.    * Trigger pm2 scoped action
  282.    *
  283.    * @param  {type} opts              options
  284.    * @param  {type} cb                callback
  285.    */
  286.   triggerPm2ScopedAction(opts: Object, cb: Function): void;
  287.  
  288.   /**
  289.    * List scoped actions
  290.    *
  291.    * @param  {type} opts              options
  292.    * @param  {type} cb                callback
  293.    */
  294.   listScopedActions(opts: Object, cb: Function): void;
  295.  
  296.   /**
  297.    * Delete scoped actions
  298.    *
  299.    * @param  {type} opts              options
  300.    * @param  {type} cb                callback
  301.    */
  302.   deleteScopedAction(opts: Object, cb: Function): void;
  303.  
  304. }
  305.  
  306. /**
  307.  * Alert
  308.  * @memberof Keymetrics.bucket
  309.  * @constructor
  310.  *
  311.  * @param {object} opts Options
  312.  */
  313. declare class AlertMethods {
  314.   /**
  315.    * Alert
  316.    * @memberof Keymetrics.bucket
  317.    * @constructor
  318.    *
  319.    * @param {object} opts Options
  320.    */
  321.   constructor(opts: Object);
  322.  
  323.   /**
  324.    * Update alerts
  325.    *
  326.    * @param  {type} cb callback
  327.    */
  328.   update(cb: Function): void;
  329.  
  330.   /**
  331.    * Update Slack alerts
  332.    *
  333.    * @param  {type} cb callback
  334.    */
  335.   updateSlack(cb: Function): void;
  336.  
  337.   /**
  338.    * Update webhook alerts
  339.    *
  340.    * @param  {type} cb callback
  341.    */
  342.   updateWebhook(cb: Function): void;
  343.  
  344.   /**
  345.    * Remove event
  346.    *
  347.    * @param  {type} cb callback
  348.    */
  349.   removeEvent(cb: Function): void;
  350.  
  351.   /**
  352.    * Send report
  353.    *
  354.    * @param  {type} cb callback
  355.    */
  356.   sendReport(cb: Function): void;
  357.  
  358. }
  359.  
  360. /**
  361.  * Data
  362.  * @memberof Keymetrics.bucket
  363.  * @constructor
  364.  *
  365.  * @param {object} opts Options
  366.  */
  367. declare class DataMethods {
  368.   /**
  369.    * Data
  370.    * @memberof Keymetrics.bucket
  371.    * @constructor
  372.    *
  373.    * @param {object} opts Options
  374.    */
  375.   constructor(opts: Object);
  376.  
  377.   /**
  378.    * Retrieve latest pm2 version
  379.    *
  380.    * @param  {function} cb Callback
  381.    */
  382.   pm2Version(cb: (() => any)): void;
  383.  
  384.   /**
  385.    * Retrieves metadata
  386.    *
  387.    * @param  {function} cb Callback
  388.    */
  389.   meta(cb: (() => any)): void;
  390.  
  391.   /**
  392.    * Retrieves status
  393.    *
  394.    * @param  {function} cb Callback
  395.    */
  396.   status(cb: (() => any)): void;
  397.  
  398.   /**
  399.    * Retrieves logged events
  400.    *
  401.    * @param  {object} opts Events
  402.    * @param  {function} cb Callback
  403.    */
  404.   events(opts: Object, cb: (() => any)): void;
  405.  
  406.   /**
  407.    * Retrieves logged events statistics
  408.    *
  409.    * @param  {function} cb Callback
  410.    */
  411.   eventsStats(cb: (() => any)): void;
  412.  
  413.   /**
  414.    * Retrieves events
  415.    *
  416.    * @param  {object} opts Application
  417.    * @param  {function} cb Callback
  418.    */
  419.   eventsSummary(opts: Object, cb: (() => any)): void;
  420.  
  421.   /**
  422.    * Send events
  423.    *
  424.    * @param  {function} cb Callback
  425.    */
  426.   processEvents(cb: (() => any)): void;
  427.  
  428.   /**
  429.    * Retrieves monitoring values
  430.    *
  431.    * @param  {object} opts Options
  432.    * @param  {function} cb Callback
  433.    */
  434.   monitoring(opts: Object, cb: (() => any)): void;
  435.  
  436.   /**
  437.    * Retrieves exceptions
  438.    *
  439.    * @param  {object} opts Exceptions
  440.    * @param  {function} cb Callback
  441.    */
  442.   exceptions(opts: Object, cb: (() => any)): void;
  443.  
  444.   /**
  445.    * Retrieves list of deployments
  446.    *
  447.    * @param  {object} opts Exceptions
  448.    * @param {function} cb Callback
  449.    */
  450.   deploymentsListing(opts: Object, cb: (() => any)): void;
  451.  
  452.   /**
  453.    * Retrieves summary of exceptions
  454.    *
  455.    * @param  {object} opts Exceptions
  456.    * @param  {function} cb Callback
  457.    */
  458.   exceptionsSummary(opts: Object, cb: (() => any)): void;
  459.  
  460.   /**
  461.    * Delete all logged exceptions
  462.    *
  463.    * @param  {object} opts Exceptions
  464.    * @param  {function} cb Callback
  465.    */
  466.   deleteAllExceptions(opts: Object, cb: (() => any)): void;
  467.  
  468.   /**
  469.    * Delete selected exceptions
  470.    *
  471.    * @param  {object} opts Exceptions
  472.    * @param  {function} cb Callback
  473.    */
  474.   deleteExceptions(opts: Object, cb: (() => any)): void;
  475.  
  476.   /**
  477.    * Delete selected server
  478.    *
  479.    * @param  {object} opts Server
  480.    * @param  {function} cb Callback
  481.    */
  482.   deleteServer(opts: Object, cb: (() => any)): void;
  483.  
  484.   /**
  485.    * Retrieve httpTransactionsSummary
  486.    *
  487.    * @param  {object} opts Server
  488.    * @param  {function} cb Callback
  489.    */
  490.   httpTransactionsSummary(opts: Object, cb: (() => any)): void;
  491.  
  492.   /**
  493.    * Reset httpTransactionsSummary
  494.    *
  495.    * @param  {object} opts Server
  496.    * @param  {function} cb Callback
  497.    */
  498.   resethttpTransactions(opts: Object, cb: (() => any)): void;
  499.  
  500.   /**
  501.    * Retrieve Transactions Average
  502.    *
  503.    * @param  {function} cb Callback
  504.    */
  505.   getTransactionAVG(cb: (() => any)): void;
  506.  
  507.   /**
  508.    * Retrieve Transactions Histogram
  509.    *
  510.    * @param  {object} opts Server
  511.    * @param  {function} cb Callback
  512.    */
  513.   getTransactionHisto(opts: Object, cb: (() => any)): void;
  514.  
  515.   /**
  516.    * Retrieve Data Logs
  517.    *
  518.    * @param  {object} opts Server
  519.    * @param  {function} cb Callback
  520.    */
  521.   logs(opts: Object, cb: (() => any)): void;
  522.  
  523.   /**
  524.    * Flush Data Logs
  525.    *
  526.    * @param  {object} opts Server
  527.    * @param  {function} cb Callback
  528.    */
  529.   flushLogs(opts: Object, cb: (() => any)): void;
  530.  
  531. }
  532.  
  533. /**
  534.  * User
  535.  * @memberof Keymetrics.bucket
  536.  * @constructor
  537.  *
  538.  * @param {object} opts Options
  539.  */
  540. declare class UserMethods {
  541.   /**
  542.    * User
  543.    * @memberof Keymetrics.bucket
  544.    * @constructor
  545.    *
  546.    * @param {object} opts Options
  547.    */
  548.   constructor(opts: Object);
  549.  
  550.   /**
  551.    * Retrieve authorized users
  552.    *
  553.    * @param  {function} cb callback
  554.    */
  555.   authorized(cb: (() => any)): void;
  556.  
  557.   /**
  558.    * Send invitation to user
  559.    *
  560.    * @param  {function} cb callback
  561.    */
  562.   addUserToBucket(cb: (() => any)): void;
  563.  
  564.   /**
  565.    * Remove user from bucket
  566.    *
  567.    * @param  {function} cb callback
  568.    */
  569.   removeUser(cb: (() => any)): void;
  570.  
  571.   /**
  572.    * Remove yourself from bucket
  573.    *
  574.    * @param  {string} email User email
  575.    * @param  {function} cb callback
  576.    */
  577.   removeSelf(email: string, cb: (() => any)): void;
  578.  
  579.   /**
  580.    * Remove invitation
  581.    *
  582.    * @param  {string} email Invitation email
  583.    * @param  {function} cb callback
  584.    */
  585.   removeInvitation(email: string, cb: (() => any)): void;
  586.  
  587.   /**
  588.    * Upgrade user permissions
  589.    *
  590.    * @param  {string} email email
  591.    * @param  {string} role  Role
  592.    * @param  {string} cb    callback
  593.    */
  594.   upgradeUser(email: string, role: string, cb: string): void;
  595.  
  596.   /**
  597.    * Check if current user is admin
  598.    *
  599.    * @param  {object} user  email
  600.    * @param  {string} cb    callback
  601.    */
  602.   isAdmin(user: Object, cb: string): void;
  603.  
  604. }
  605.  
  606. /**
  607.     * Authenticate
  608.     * @alias auth
  609.     * @constructor
  610.     * @memberof Keymetrics
  611.     *
  612.     * @param {object} opts Options
  613.     */
  614. declare class Authenticate {
  615.   /**
  616.    * Authenticate
  617.    * @alias auth
  618.    * @constructor
  619.    * @memberof Keymetrics
  620.    *
  621.    * @param {object} opts Options
  622.    */
  623.   constructor(opts: Object);
  624.  
  625.   /**
  626.    * Get access token
  627.    *
  628.    * @param {string} token     Refresh token
  629.    * @param {function} callback Callback
  630.    */
  631.   refresh(token: string, callback: (() => any)): void;
  632.  
  633.   /**
  634.    * Starts the authentication process
  635.    *
  636.    * @param {object}    opts
  637.    * @param {function}  callback
  638.    */
  639.   init(opts: Object, callback: (() => any)): void;
  640.  
  641.   /**
  642.    * Revoke access token
  643.    *
  644.    * @param {function} callback
  645.    */
  646.   logout(callback: (() => any)): void;
  647.  
  648. }
  649.  
  650. /**
  651.  * Realtime
  652.  * @memberof Keymetrics
  653.  * @constructor
  654.  * @alias realtime
  655.  *
  656.  * @param {object} opts Options
  657.  */
  658. declare class Realtime {
  659.   /**
  660.    * Realtime
  661.    * @memberof Keymetrics
  662.    * @constructor
  663.    * @alias realtime
  664.    *
  665.    * @param {object} opts Options
  666.    */
  667.   constructor(opts: Object);
  668.  
  669.   /**
  670.    * Register bucket and start websocket
  671.    *
  672.    * @param {function} cb callback
  673.    */
  674.   init(cb: (() => any)): void;
  675.  
  676.   /**
  677.    * Unregister from bucket and destroy websocket connection
  678.    * @param {function} cb callback
  679.    */
  680.   unregister(cb: (() => any)): void;
  681.  
  682. }
  683.  
  684.  
  685.  
  686. /**
  687.  * User
  688.  * @memberof Keymetrics
  689.  * @constructor
  690.  * @alias user
  691.  *
  692.  * @param {object} opts Options
  693.  */
  694. declare class User {
  695.   /**
  696.    * User
  697.    * @memberof Keymetrics
  698.    * @constructor
  699.    * @alias user
  700.    *
  701.    * @param {object} opts Options
  702.    */
  703.   constructor(opts: Object);
  704.  
  705.   /**
  706.    * Retrieves current user from API
  707.    *
  708.    * @param {function} callback Callback
  709.    */
  710.   refreshUser(callback: (() => any)): void;
  711.  
  712.   /**
  713.    * set the User Object variable
  714.    *
  715.    * @param {object} user
  716.    */
  717.   setUser(user: Object): void;
  718.  
  719.   /**
  720.    * return the user object
  721.    * @return {object}
  722.    */
  723.   getUser(): Object;
  724.  
  725. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement