UNPKG

aws-cloudfront-sign

Version:

Utility module for signing AWS CloudFront URLs

46 lines 2.13 kB
"use strict"; 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; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./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() { (0, utils_1.assert)(!!this.url, 'Missing param: url'); (0, utils_1.assert)(!!this.expireTime, 'Missing param: expireTime'); (0, utils_1.assert)(this.expireTime < 2147483647, 'expireTime must be less than January 19, 2038 03:14:08 GMT ' + 'due to the limits of UNIX time'); (0, utils_1.assert)(this.expireTime > (new Date().getTime() / 1000), 'expireTime must be after the current time'); return true; }; exports.default = CannedPolicy; //# sourceMappingURL=canned-policy.js.map