diff --git a/README.md b/README.md index 94e4de3..32e8ed9 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ # Capture Node SDK -Node Library for Capture by Techulus -Get your API Key and Secret from https://capture.techulus.in/console +Node Library for [capture.page](https://capture.page) + +Get your API Key and Secret from [https://capture.page/console](https://capture.page/console) + +List of all capture options: [https://docs.capture.page](https://docs.capture.page) ## Installation @@ -11,17 +14,19 @@ npm install capture-node ## Usage -List of all capture options: https://docs.capture.techulus.in +List of all capture options: https://docs.capture.page ### Image ```javascript import { Capture } from 'capture-node'; const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET); +// or initialize with edge endpoint +// const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET, { useEdge: true }); // var url = capture.buildImageUrl(URL_TO_CAPTURE, CAPTURE_OPTIONS); -const url = capture.buildImageUrl('https://capture.techulus.in/', { +const url = capture.buildImageUrl('https://capture.page/', { full: true, delay: 3, t: Date.now() @@ -29,7 +34,7 @@ const url = capture.buildImageUrl('https://capture.techulus.in/', { // or -const image = await capture.fetchImage('https://capture.techulus.in/', { +const image = await capture.fetchImage('https://capture.page/', { full: true, delay: 3, t: Date.now() @@ -45,7 +50,7 @@ const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET); // var url = capture.buildPdfUrl(URL_TO_CAPTURE, CAPTURE_OPTIONS); -const url = capture.buildPdfUrl('https://capture.techulus.in/', { +const url = capture.buildPdfUrl('https://capture.page/', { full: true, delay: 3, t: Date.now() @@ -53,7 +58,7 @@ const url = capture.buildPdfUrl('https://capture.techulus.in/', { // or -const pdf = capture.fetchPdf('https://capture.techulus.in/', { +const pdf = capture.fetchPdf('https://capture.page/', { full: true, delay: 3, t: Date.now() @@ -68,11 +73,11 @@ const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET); // var url = capture.buildContentUrl(URL_TO_CAPTURE, CAPTURE_OPTIONS); -const url = capture.buildContentUrl('https://capture.techulus.in/'); +const url = capture.buildContentUrl('https://capture.page/'); // or -const content = await capture.fetchContent('https://capture.techulus.in/'); +const content = await capture.fetchContent('https://capture.page/'); ``` ### Metadata @@ -83,9 +88,9 @@ const capture = new Capture(YOUR_API_KEY, YOUR_API_SECRET); // var url = capture.buildMetadataUrl(URL_TO_CAPTURE, CAPTURE_OPTIONS); -const url = capture.buildMetadataUrl('https://capture.techulus.in/'); +const url = capture.buildMetadataUrl('https://capture.page/'); // or -const content = await capture.fetchMetadata('https://capture.techulus.in/'); +const content = await capture.fetchMetadata('https://capture.page/'); ``` \ No newline at end of file diff --git a/__tests__/test.ts b/__tests__/test.ts index dbc332f..ade218c 100644 --- a/__tests__/test.ts +++ b/__tests__/test.ts @@ -13,17 +13,17 @@ describe("Capture URL Builder", () => { const url = capture.buildImageUrl("https://news.ycombinator.com/"); console.log(url); expect(url).toBe( - "https://cdn.capture.techulus.in/test/f37d5fb3ee4540a05bf4ffeed6dffa28/image?url=https%3A%2F%2Fnews.ycombinator.com%2F", + "https://cdn.capture.page/test/f37d5fb3ee4540a05bf4ffeed6dffa28/image?url=https%3A%2F%2Fnews.ycombinator.com%2F", ); }); it("buildImageUrl with options should return valid url", () => { - const url = capture.buildImageUrl("https://capture.techulus.in/", { + const url = capture.buildImageUrl("https://capture.page/", { full: true, delay: 3, }); expect(url).toBe( - "https://cdn.capture.techulus.in/test/2cb8b7ed9dbdb5c0db4a5dc4523a0780/image?full=true&delay=3&url=https%3A%2F%2Fcapture.techulus.in%2F", + "https://cdn.capture.page/test/0e944abb6d823d0c8618dc22e508be6d/image?full=true&delay=3&url=https%3A%2F%2Fcapture.page%2F", ); }); }); @@ -37,17 +37,17 @@ describe("Capture URL Builder", () => { it("buildPdfUrl should return valid url", () => { const url = capture.buildPdfUrl("https://news.ycombinator.com/"); expect(url).toBe( - "https://cdn.capture.techulus.in/test/f37d5fb3ee4540a05bf4ffeed6dffa28/pdf?url=https%3A%2F%2Fnews.ycombinator.com%2F", + "https://cdn.capture.page/test/f37d5fb3ee4540a05bf4ffeed6dffa28/pdf?url=https%3A%2F%2Fnews.ycombinator.com%2F", ); }); it("buildPdfUrl with options should return valid url", () => { - const url = capture.buildPdfUrl("https://capture.techulus.in/", { + const url = capture.buildPdfUrl("https://capture.page/", { full: true, delay: 3, }); expect(url).toBe( - "https://cdn.capture.techulus.in/test/2cb8b7ed9dbdb5c0db4a5dc4523a0780/pdf?full=true&delay=3&url=https%3A%2F%2Fcapture.techulus.in%2F", + "https://cdn.capture.page/test/0e944abb6d823d0c8618dc22e508be6d/pdf?full=true&delay=3&url=https%3A%2F%2Fcapture.page%2F", ); }); }); @@ -61,7 +61,7 @@ describe("Capture URL Builder", () => { it("buildContentUrl should return valid url", () => { const url = capture.buildContentUrl("https://news.ycombinator.com/"); expect(url).toBe( - "https://cdn.capture.techulus.in/test/f37d5fb3ee4540a05bf4ffeed6dffa28/content?url=https%3A%2F%2Fnews.ycombinator.com%2F", + "https://cdn.capture.page/test/f37d5fb3ee4540a05bf4ffeed6dffa28/content?url=https%3A%2F%2Fnews.ycombinator.com%2F", ); }); }); @@ -75,8 +75,32 @@ describe("Capture URL Builder", () => { it("buildMetadataUrl should return valid url", () => { const url = capture.buildMetadataUrl("https://news.ycombinator.com/"); expect(url).toBe( - "https://cdn.capture.techulus.in/test/f37d5fb3ee4540a05bf4ffeed6dffa28/metadata?url=https%3A%2F%2Fnews.ycombinator.com%2F", + "https://cdn.capture.page/test/f37d5fb3ee4540a05bf4ffeed6dffa28/metadata?url=https%3A%2F%2Fnews.ycombinator.com%2F", ); }); }); }); + +describe("Capture URL Builder with useEdge", () => { + const edgeCapture = new Capture("test", "test", { useEdge: true }); + + it("buildImageUrl should use edge URL", () => { + const url = edgeCapture.buildImageUrl("https://news.ycombinator.com/"); + expect(url.startsWith("https://edge.capture.page/")).toBe(true); + }); + + it("buildPdfUrl should use edge URL", () => { + const url = edgeCapture.buildPdfUrl("https://news.ycombinator.com/"); + expect(url.startsWith("https://edge.capture.page/")).toBe(true); + }); + + it("buildContentUrl should use edge URL", () => { + const url = edgeCapture.buildContentUrl("https://news.ycombinator.com/"); + expect(url.startsWith("https://edge.capture.page/")).toBe(true); + }); + + it("buildMetadataUrl should use edge URL", () => { + const url = edgeCapture.buildMetadataUrl("https://news.ycombinator.com/"); + expect(url.startsWith("https://edge.capture.page/")).toBe(true); + }); +}); diff --git a/package.json b/package.json index 45eefa3..b89797e 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "capture-node", "version": "2.1.0", - "description": "Node Library for Capture by Techulus", + "description": "Node Library for capture.page", "main": "dist/index.js", "types": "dist/index.d.ts", "scripts": { diff --git a/src/index.ts b/src/index.ts index c88d010..a14b21c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,14 +5,17 @@ export type RequestType = "image" | "pdf" | "content" | "metadata"; export type RequestOptions = Record; export class Capture { - static API_URL = "https://cdn.capture.techulus.in"; + static API_URL = "https://cdn.capture.page"; + static EDGE_URL = "https://edge.capture.page"; key: string; secret: string; + options: { useEdge?: boolean }; - constructor(key: string, secret: string) { + constructor(key: string, secret: string, options?: { useEdge?: boolean }) { this.key = key; this.secret = secret; + this.options = options ?? { useEdge: false }; } private _generateToken(secret: string, url: string) { @@ -74,7 +77,7 @@ export class Capture { query = this._toQueryString(options); } const token = this._generateToken(this.secret, query); - return `${Capture.API_URL}/${this.key}/${token}/${type}?${query}`; + return `${this.options.useEdge ? Capture.EDGE_URL : Capture.API_URL}/${this.key}/${token}/${type}?${query}`; } buildImageUrl(url: string, options?: RequestOptions) {