{"version":3,"sources":["meteor://💻app/packages/ddp-rate-limiter/ddp-rate-limiter.js"],"names":["module","export","DDPRateLimiter","RateLimiter","link","v","errorMessage","rateLimitResult","Math","ceil","timeToReset","rateLimiter","getErrorMessage","setErrorMessage","message","addRule","matcher","numRequests","timeInterval","callback","printRules","rules","removeRule","id","_increment","input","increment","_check","check"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAAA,MAAM,CAACC,MAAP,CAAc;AAACC,gBAAc,EAAC,MAAIA;AAApB,CAAd;AAAmD,IAAIC,WAAJ;AAAgBH,MAAM,CAACI,IAAP,CAAY,mBAAZ,EAAgC;AAACD,aAAW,CAACE,CAAD,EAAG;AAACF,eAAW,GAACE,CAAZ;AAAc;;AAA9B,CAAhC,EAAgE,CAAhE;AAEnE;AACA;AACA,MAAMH,cAAc,GAAG,EAAvB;;AAEA,IAAII,YAAY,GAAIC,eAAD,IAAqB;AACtC,SAAO,yEACFC,IAAI,CAACC,IAAL,CAAUF,eAAe,CAACG,WAAhB,GAA8B,IAAxC,CADE,wBAEL,eAFF;AAGD,CAJD;;AAMA,MAAMC,WAAW,GAAG,IAAIR,WAAJ,EAApB;;AAEAD,cAAc,CAACU,eAAf,GAAkCL,eAAD,IAAqB;AACpD,MAAI,OAAOD,YAAP,KAAwB,UAA5B,EAAwC;AACtC,WAAOA,YAAY,CAACC,eAAD,CAAnB;AACD,GAFD,MAEO;AACL,WAAOD,YAAP;AACD;AACF,CAND;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAJ,cAAc,CAACW,eAAf,GAAkCC,OAAD,IAAa;AAC5CR,cAAY,GAAGQ,OAAf;AACD,CAFD;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAZ,cAAc,CAACa,OAAf,GAAyB,CAACC,OAAD,EAAUC,WAAV,EAAuBC,YAAvB,EAAqCC,QAArC,KACvBR,WAAW,CAACI,OAAZ,CAAoBC,OAApB,EAA6BC,WAA7B,EAA0CC,YAA1C,EAAwDC,QAAxD,CADF;;AAGAjB,cAAc,CAACkB,UAAf,GAA4B,MAAMT,WAAW,CAACU,KAA9C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACAnB,cAAc,CAACoB,UAAf,GAA4BC,EAAE,IAAIZ,WAAW,CAACW,UAAZ,CAAuBC,EAAvB,CAAlC,C,CAEA;AACA;;;AACArB,cAAc,CAACsB,UAAf,GAA6BC,KAAD,IAAW;AACrCd,aAAW,CAACe,SAAZ,CAAsBD,KAAtB;AACD,CAFD;;AAIAvB,cAAc,CAACyB,MAAf,GAAwBF,KAAK,IAAId,WAAW,CAACiB,KAAZ,CAAkBH,KAAlB,CAAjC,C","file":"/packages/ddp-rate-limiter.js","sourcesContent":["import { RateLimiter } from 'meteor/rate-limit';\n\n// Rate Limiter built into DDP with a default error message. See README or\n// online documentation for more details.\nconst DDPRateLimiter = {};\n\nlet errorMessage = (rateLimitResult) => {\n return 'Error, too many requests. Please slow down. You must wait ' +\n `${Math.ceil(rateLimitResult.timeToReset / 1000)} seconds before ` +\n 'trying again.';\n};\n\nconst rateLimiter = new RateLimiter();\n\nDDPRateLimiter.getErrorMessage = (rateLimitResult) => {\n if (typeof errorMessage === 'function') {\n return errorMessage(rateLimitResult);\n } else {\n return errorMessage;\n }\n};\n\n/**\n * @summary Set error message text when method or subscription rate limit\n * exceeded.\n * @param {string|function} message Functions are passed in an object with a\n * `timeToReset` field that specifies the number of milliseconds until the next\n * method or subscription is allowed to run. The function must return a string\n * of the error message.\n * @locus Server\n */\nDDPRateLimiter.setErrorMessage = (message) => {\n errorMessage = message;\n};\n\n/**\n * @summary\n * Add a rule that matches against a stream of events describing method or\n * subscription attempts. Each event is an object with the following\n * properties:\n *\n * - `type`: Either \"method\" or \"subscription\"\n * - `name`: The name of the method or subscription being called\n * - `userId`: The user ID attempting the method or subscription\n * - `connectionId`: A string representing the user's DDP connection\n * - `clientAddress`: The IP address of the user\n *\n * Returns unique `ruleId` that can be passed to `removeRule`.\n *\n * @param {Object} matcher\n * Matchers specify which events are counted towards a rate limit. A matcher\n * is an object that has a subset of the same properties as the event objects\n * described above. Each value in a matcher object is one of the following:\n *\n * - a string: for the event to satisfy the matcher, this value must be equal\n * to the value of the same property in the event object\n *\n * - a function: for the event to satisfy the matcher, the function must\n * evaluate to true when passed the value of the same property\n * in the event object\n *\n * Here's how events are counted: Each event that satisfies the matcher's\n * filter is mapped to a bucket. Buckets are uniquely determined by the\n * event object's values for all properties present in both the matcher and\n * event objects.\n *\n * @param {number} numRequests number of requests allowed per time interval.\n * Default = 10.\n * @param {number} timeInterval time interval in milliseconds after which\n * rule's counters are reset. Default = 1000.\n * @param {function} callback function to be called after a rule is executed.\n * @locus Server\n */\nDDPRateLimiter.addRule = (matcher, numRequests, timeInterval, callback) => \n rateLimiter.addRule(matcher, numRequests, timeInterval, callback);\n\nDDPRateLimiter.printRules = () => rateLimiter.rules;\n\n/**\n * @summary Removes the specified rule from the rate limiter. If rule had\n * hit a rate limit, that limit is removed as well.\n * @param {string} id 'ruleId' returned from `addRule`\n * @return {boolean} True if a rule was removed.\n * @locus Server\n */\nDDPRateLimiter.removeRule = id => rateLimiter.removeRule(id);\n\n// This is accessed inside livedata_server.js, but shouldn't be called by any\n// user.\nDDPRateLimiter._increment = (input) => {\n rateLimiter.increment(input);\n};\n\nDDPRateLimiter._check = input => rateLimiter.check(input);\n\nexport { DDPRateLimiter };\n"]}