Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sls-next/cloudfront

Package Overview
Dependencies
Maintainers
2
Versions
84
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sls-next/cloudfront - npm Package Compare versions

Comparing version 3.1.0-alpha.7 to 3.1.0-alpha.11

tests/check-cf-distribution-ready.test.ts

6

CHANGELOG.md

@@ -6,2 +6,8 @@ # Change Log

# [3.1.0-alpha.11](https://github.com/serverless-nextjs/serverless-next.js/compare/v3.1.0-alpha.10...v3.1.0-alpha.11) (2021-06-23)
### Bug Fixes
- **nextjs-component, cloudfront:** wait for distribution to be ready before creating invalidations ([#1281](https://github.com/serverless-nextjs/serverless-next.js/issues/1281)) ([3091c7c](https://github.com/serverless-nextjs/serverless-next.js/commit/3091c7c634986121c4943931c7ffd6303732c957))
# [3.1.0-alpha.7](https://github.com/serverless-nextjs/serverless-next.js/compare/v3.1.0-alpha.6...v3.1.0-alpha.7) (2021-06-22)

@@ -8,0 +14,0 @@

9

dist/index.d.ts

@@ -9,2 +9,9 @@ import AWS from "aws-sdk";

declare const createInvalidation: (options: CreateInvalidationOptions) => Promise<AWS.CloudFront.CreateInvalidationResult>;
export default createInvalidation;
export declare type CheckCloudFrontDistributionReadyOptions = {
credentials: Credentials;
distributionId: string;
waitDuration: number;
pollInterval: number;
};
declare const checkCloudFrontDistributionReady: (options: CheckCloudFrontDistributionReadyOptions) => Promise<boolean>;
export { createInvalidation, checkCloudFrontDistributionReady };

@@ -15,4 +15,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.checkCloudFrontDistributionReady = exports.createInvalidation = void 0;
const cloudfront_1 = __importDefault(require("./lib/cloudfront"));
const createInvalidation = (options) => __awaiter(void 0, void 0, void 0, function* () {
const createInvalidation = (options) => {
const { credentials, distributionId, paths } = options;

@@ -23,3 +24,22 @@ const cf = cloudfront_1.default({

return cf.createInvalidation({ distributionId, paths });
};
exports.createInvalidation = createInvalidation;
const checkCloudFrontDistributionReady = (options) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
const { credentials, distributionId, waitDuration, pollInterval } = options;
const startDate = new Date();
const startTime = startDate.getTime();
const waitDurationMillis = waitDuration * 1000;
const cf = cloudfront_1.default({
credentials
});
while (new Date().getTime() - startTime < waitDurationMillis) {
const result = yield cf.getDistribution(distributionId);
if (((_a = result.Distribution) === null || _a === void 0 ? void 0 : _a.Status) === "Deployed") {
return true;
}
yield new Promise((r) => setTimeout(r, pollInterval * 1000));
}
return false;
});
exports.default = createInvalidation;
exports.checkCloudFrontDistributionReady = checkCloudFrontDistributionReady;

@@ -12,2 +12,3 @@ import AWS from "aws-sdk";

createInvalidation: (options: CreateInvalidationOptions) => Promise<AWS.CloudFront.CreateInvalidationResult>;
getDistribution: (distributionId: string) => Promise<AWS.CloudFront.GetDistributionResult>;
};

@@ -14,0 +15,0 @@ export declare type Credentials = {

@@ -35,4 +35,11 @@ "use strict";

.promise();
}),
getDistribution: (distributionId) => __awaiter(void 0, void 0, void 0, function* () {
return yield cloudFront
.getDistribution({
Id: distributionId
})
.promise();
})
};
};

4

package.json
{
"name": "@sls-next/cloudfront",
"version": "3.1.0-alpha.7",
"version": "3.1.0-alpha.11",
"description": "Handles CloudFront invalidation",

@@ -41,3 +41,3 @@ "publishConfig": {

},
"gitHead": "cc5f9deaa8373fb8d1ad5e204aede3c0bcd0b7fd"
"gitHead": "5b4943f2f3650bf3b441a5b221d5b0a7b89bd25b"
}

@@ -10,3 +10,3 @@ import AWS from "aws-sdk";

const createInvalidation = async (
const createInvalidation = (
options: CreateInvalidationOptions

@@ -22,2 +22,34 @@ ): Promise<AWS.CloudFront.CreateInvalidationResult> => {

export default createInvalidation;
export type CheckCloudFrontDistributionReadyOptions = {
credentials: Credentials;
distributionId: string;
waitDuration: number;
pollInterval: number;
};
const checkCloudFrontDistributionReady = async (
options: CheckCloudFrontDistributionReadyOptions
): Promise<boolean> => {
const { credentials, distributionId, waitDuration, pollInterval } = options;
const startDate = new Date();
const startTime = startDate.getTime();
const waitDurationMillis = waitDuration * 1000;
const cf = CloudFrontClientFactory({
credentials
});
while (new Date().getTime() - startTime < waitDurationMillis) {
const result = await cf.getDistribution(distributionId);
if (result.Distribution?.Status === "Deployed") {
return true;
}
await new Promise((r) => setTimeout(r, pollInterval * 1000));
}
return false;
};
export { createInvalidation, checkCloudFrontDistributionReady };

@@ -18,2 +18,5 @@ import AWS from "aws-sdk";

) => Promise<AWS.CloudFront.CreateInvalidationResult>;
getDistribution: (
distributionId: string
) => Promise<AWS.CloudFront.GetDistributionResult>;
};

@@ -55,4 +58,13 @@

.promise();
},
getDistribution: async (
distributionId: string
): Promise<AWS.CloudFront.GetDistributionResult> => {
return await cloudFront
.getDistribution({
Id: distributionId
})
.promise();
}
};
};
declare module "aws-sdk" {
const mockCreateInvalidation: jest.Mock;
const mockCreateInvalidationPromise: jest.Mock;
const mockGetDistribution: jest.Mock;
const mockGetDistributionPromise: jest.Mock;
}

@@ -17,4 +19,8 @@

export const mockGetDistribution = jest.fn();
export const mockGetDistributionPromise = promisifyMock(mockGetDistribution);
const MockCloudFront = jest.fn(() => ({
createInvalidation: mockCreateInvalidation
createInvalidation: mockCreateInvalidation,
getDistribution: mockGetDistribution
}));

@@ -21,0 +27,0 @@

import AWS, { mockCreateInvalidation } from "aws-sdk";
import createInvalidation, { CreateInvalidationOptions } from "../src/index";
import { createInvalidation, CreateInvalidationOptions } from "../src/index";
import { ALL_FILES_PATH } from "../src/lib/constants";

@@ -4,0 +4,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc