UNPKG

aws-cloudfront-sign

Version:

Utility module for signing AWS CloudFront URLs

44 lines 1.99 kB
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) { if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter"); if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it"); return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver); }; var _CannedPolicy_instances, _CannedPolicy_validate; import { assert } from './utils'; class CannedPolicy { constructor(url, expireTime, ipRange) { _CannedPolicy_instances.add(this); this.url = url; this.expireTime = Math.round(expireTime / 1000) || undefined; this.ipRange = ipRange; } toJSON() { __classPrivateFieldGet(this, _CannedPolicy_instances, "m", _CannedPolicy_validate).call(this); const policy = { Statement: [{ Resource: this.url, Condition: { DateLessThan: { 'AWS:EpochTime': this.expireTime } } }] }; if (this.ipRange) { policy.Statement[0].Condition.IpAddress = { 'AWS:SourceIp': this.ipRange }; } return JSON.stringify(policy); } } _CannedPolicy_instances = new WeakSet(), _CannedPolicy_validate = function _CannedPolicy_validate() { assert(!!this.url, 'Missing param: url'); assert(!!this.expireTime, 'Missing param: expireTime'); assert(this.expireTime < 2147483647, 'expireTime must be less than January 19, 2038 03:14:08 GMT ' + 'due to the limits of UNIX time'); assert(this.expireTime > (new Date().getTime() / 1000), 'expireTime must be after the current time'); return true; }; export default CannedPolicy; //# sourceMappingURL=canned-policy.js.map