kraken 1.0.1 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -18,20 +18,24 @@ jobs:
18
18
 
19
19
  strategy:
20
20
  matrix:
21
- node-version: [12.x, 14.x, 16.x, 17.x, 18.x, 20.x]
22
- # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
21
+ node-version: [12.x, 14.x, 16.x, 18.x, 20.x, 22.x, 24.x, 26.x]
22
+ # See supported Node.js release schedule at https://nodejs.org/en/about/previous-releases
23
23
 
24
24
  env:
25
25
  KRAKEN_API_KEY: ${{ secrets.KRAKEN_API_KEY }}
26
26
  KRAKEN_API_SECRET: ${{ secrets.KRAKEN_API_SECRET }}
27
27
 
28
28
  steps:
29
- - uses: actions/checkout@v2
29
+ - uses: actions/checkout@v7
30
30
  - name: Use Node.js ${{ matrix.node-version }}
31
- uses: actions/setup-node@v2
31
+ uses: actions/setup-node@v7
32
32
  with:
33
33
  node-version: ${{ matrix.node-version }}
34
34
  cache: 'npm'
35
+ # npm 6 (bundled with Node.js 12 and 14) cannot read lockfileVersion 3
36
+ - name: Use npm 8 on Node.js 12 and 14
37
+ if: matrix.node-version == '12.x' || matrix.node-version == '14.x'
38
+ run: npm install -g npm@8
35
39
  - run: npm ci
36
40
  - run: npm run build --if-present
37
41
  - run: npm test
@@ -12,19 +12,23 @@ jobs:
12
12
  runs-on: ubuntu-latest
13
13
  strategy:
14
14
  matrix:
15
- node-version: [14.x, 15.x, 16.x, 17.x, 18.x, 20.x]
16
-
15
+ node-version: [12.x, 14.x, 16.x, 18.x, 20.x, 22.x, 24.x, 26.x]
16
+
17
17
  env:
18
18
  KRAKEN_API_KEY: ${{ secrets.KRAKEN_API_KEY }}
19
19
  KRAKEN_API_SECRET: ${{ secrets.KRAKEN_API_SECRET }}
20
20
 
21
21
  steps:
22
- - uses: actions/checkout@v2
22
+ - uses: actions/checkout@v7
23
23
  - name: Use Node.js ${{ matrix.node-version }}
24
- uses: actions/setup-node@v2
24
+ uses: actions/setup-node@v7
25
25
  with:
26
26
  node-version: ${{ matrix.node-version }}
27
27
  cache: 'npm'
28
+ # npm 6 (bundled with Node.js 12 and 14) cannot read lockfileVersion 3
29
+ - name: Use npm 8 on Node.js 12 and 14
30
+ if: matrix.node-version == '12.x' || matrix.node-version == '14.x'
31
+ run: npm install -g npm@8
28
32
  - run: npm ci
29
33
  - run: npm run build --if-present
30
34
  - run: npm test
@@ -33,10 +37,10 @@ jobs:
33
37
  needs: build
34
38
  runs-on: ubuntu-latest
35
39
  steps:
36
- - uses: actions/checkout@v2
37
- - uses: actions/setup-node@v2
40
+ - uses: actions/checkout@v7
41
+ - uses: actions/setup-node@v7
38
42
  with:
39
- node-version: 18
43
+ node-version: 24
40
44
  registry-url: https://registry.npmjs.org/
41
45
  - run: npm ci
42
46
  - run: npm publish
package/README.md CHANGED
@@ -1,34 +1,36 @@
1
1
  # Node.js module for Kraken.io API
2
2
 
3
- [![Build Status](https://app.travis-ci.com/kraken-io/kraken-node.svg?branch=master)](https://app.travis-ci.com/kraken-io/kraken-node)
3
+ [![Node.js CI](https://github.com/kraken-io/kraken-node/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/kraken-io/kraken-node/actions/workflows/node.js.yml)
4
4
 
5
5
  With this Node module you can plug into the power and speed of [Kraken.io](http://kraken.io/) Image Optimizer.
6
6
 
7
- - [Node.js module for Kraken.io API](#nodejs-module-for-krakenio-api)
8
- - [Installation](#installation)
9
- - [Requirements](#requirements)
10
- - [Dependencies](#dependencies)
11
- - [Getting Started](#getting-started)
12
- - [Downloading Images](#downloading-images)
13
- - [How to use](#how-to-use)
14
- - [Wait and Callback URL](#wait-and-callback-url)
15
- - [Wait option](#wait-option)
16
- - [Callback URL](#callback-url)
17
- - [Promises](#promises)
18
- - [Async/Await](#asyncawait)
19
- - [Authentication](#authentication)
20
- - [Usage - Image URL](#usage---image-url)
21
- - [Usage - Image Upload](#usage---image-upload)
22
- - [Usage - User status](#usage---user-status)
23
- - [Lossy Optimization](#lossy-optimization)
24
- - [PNG Images](#png-images)
25
- - [JPEG Images](#jpeg-images)
26
- - [Image Resizing](#image-resizing)
27
- - [WebP Compression](#webp-compression)
28
- - [Amazon S3 and Rackspace Cloud Files](#amazon-s3-and-rackspace-cloud-files)
29
- - [Amazon S3](#amazon-s3)
30
- - [Rackspace Cloud Files](#rackspace-cloud-files)
31
- - [LICENSE - MIT](#license---mit)
7
+ - [Node.js module for Kraken.io API](#nodejs-module-for-krakenio-api)
8
+ - [Installation](#installation)
9
+ - [Requirements](#requirements)
10
+ - [Dependencies](#dependencies)
11
+ - [Getting Started](#getting-started)
12
+ - [Downloading Images](#downloading-images)
13
+ - [How to use](#how-to-use)
14
+ - [Wait and Callback URL](#wait-and-callback-url)
15
+ - [Wait option](#wait-option)
16
+ - [Callback URL](#callback-url)
17
+ - [Promises](#promises)
18
+ - [Async/Await](#asyncawait)
19
+ - [Authentication](#authentication)
20
+ - [Usage - Image URL](#usage---image-url)
21
+ - [Usage - Image Upload](#usage---image-upload)
22
+ - [Usage - User status](#usage---user-status)
23
+ - [Lossy Optimization](#lossy-optimization)
24
+ - [PNG Images](#png-images)
25
+ - [JPEG Images](#jpeg-images)
26
+ - [Image Resizing](#image-resizing)
27
+ - [WebP Compression](#webp-compression)
28
+ - [PDF Compression](#pdf-compression)
29
+ - [Amazon S3, Rackspace Cloud Files, and Google Cloud Storage](#amazon-s3-rackspace-cloud-files-and-google-cloud-storage)
30
+ - [Amazon S3](#amazon-s3)
31
+ - [Rackspace Cloud Files](#rackspace-cloud-files)
32
+ - [Google Cloud Storage](#google-cloud-storage)
33
+ - [LICENSE - MIT](#license---mit)
32
34
 
33
35
  ## Installation
34
36
 
@@ -212,11 +214,12 @@ kraken.url(opts, function (err, data) {
212
214
  })
213
215
 
214
216
  // with promises
215
- kraken.url(opts)
216
- .then(data => {
217
+ kraken
218
+ .url(opts)
219
+ .then((data) => {
217
220
  console.log('Success. Optimized image URL: %s', data.kraked_url)
218
221
  })
219
- .catch(err => {
222
+ .catch((err) => {
220
223
  console.log('Failed. Error message: %s', err)
221
224
  })
222
225
  ```
@@ -283,11 +286,12 @@ kraken.upload(opts, function (err, data) {
283
286
  })
284
287
 
285
288
  // with promise
286
- kraken.upload(opts)
287
- .then(data => {
289
+ kraken
290
+ .upload(opts)
291
+ .then((data) => {
288
292
  console.log('Success. Optimized image URL: %s', data.kraked_url)
289
293
  })
290
- .catch(err => {
294
+ .catch((err) => {
291
295
  console.log('Failed. Error message: %s', err)
292
296
  })
293
297
  ```
@@ -310,11 +314,12 @@ kraken.upload(opts, function (err, data) {
310
314
  })
311
315
 
312
316
  // with promise
313
- kraken.upload(opts)
314
- .then(data => {
317
+ kraken
318
+ .upload(opts)
319
+ .then((data) => {
315
320
  console.log('Success. Optimized image URL: %s', data.kraked_url)
316
321
  })
317
- .catch(err => {
322
+ .catch((err) => {
318
323
  console.log('Failed. Error message: %s', err)
319
324
  })
320
325
  ```
@@ -337,11 +342,12 @@ kraken.upload(opts, function (err, data) {
337
342
  })
338
343
 
339
344
  // with promise
340
- kraken.upload(opts)
341
- .then(data => {
345
+ kraken
346
+ .upload(opts)
347
+ .then((data) => {
342
348
  console.log('Success. Optimized image URL: %s', data.kraked_url)
343
349
  })
344
- .catch(err => {
350
+ .catch((err) => {
345
351
  console.log('Failed. Error message: %s', err)
346
352
  })
347
353
  ```
@@ -367,11 +373,12 @@ kraken.upload(opts, function (err, data) {
367
373
  })
368
374
 
369
375
  // with promise
370
- kraken.upload(opts)
371
- .then(data => {
376
+ kraken
377
+ .upload(opts)
378
+ .then((data) => {
372
379
  console.log('Success. Optimized image URL: %s', data.kraked_url)
373
380
  })
374
- .catch(err => {
381
+ .catch((err) => {
375
382
  console.log('Failed. Error message: %s', err)
376
383
  })
377
384
  ```
@@ -444,8 +451,9 @@ kraken.userStatus(function (err, data) {
444
451
  }) //formatBytes(data,2)
445
452
 
446
453
  // with promise
447
- kraken.userStatus()
448
- .then(data => {
454
+ kraken
455
+ .userStatus()
456
+ .then((data) => {
449
457
  console.log('Success', {
450
458
  success: data.success,
451
459
  active: data.active,
@@ -454,9 +462,9 @@ kraken.userStatus()
454
462
  quota_remaining: formatBytes(data.quota_remaining, 2)
455
463
  })
456
464
  })
457
- .catch(err => {
465
+ .catch((err) => {
458
466
  console.log('Failed. Error message: %s', err)
459
- })//formatBytes(data,2)
467
+ }) //formatBytes(data,2)
460
468
 
461
469
  // Optional function which will format the bytes value
462
470
  function formatBytes(value, decimal) {
@@ -523,11 +531,12 @@ kraken.upload(opts, function (err, data) {
523
531
  })
524
532
 
525
533
  // with promise
526
- kraken.upload(opts)
527
- .then(data => {
534
+ kraken
535
+ .upload(opts)
536
+ .then((data) => {
528
537
  console.log('Success. Optimized image URL: %s', data.kraked_url)
529
538
  })
530
- .catch(err => {
539
+ .catch((err) => {
531
540
  console.log('Failed. Error message: %s', err)
532
541
  })
533
542
  ```
@@ -535,8 +544,8 @@ kraken.upload(opts)
535
544
  The `strategy` property can have one of the following values:
536
545
 
537
546
  - `exact` - Resize by exact width/height. No aspect ratio will be maintained.
538
- - `portrait` - Exact width will be set, height will be adjusted according to aspect ratio.
539
- - `landscape` - Exact height will be set, width will be adjusted according to aspect ratio.
547
+ - `portrait` - Exact height will be set, width will be adjusted according to aspect ratio.
548
+ - `landscape` - Exact width will be set, height will be adjusted according to aspect ratio.
540
549
  - `auto` - The best strategy (portrait or landscape) will be selected for a given image according to aspect ratio.
541
550
  - `crop` - This option will crop your image to the exact size you specify with no distortion.
542
551
 
@@ -544,20 +553,67 @@ The `strategy` property can have one of the following values:
544
553
 
545
554
  WebP is a new image format introduced by Google in 2010 which supports both lossy and lossless compression. According to [Google](https://developers.google.com/speed/webp/), WebP lossless images are **26% smaller** in size compared to PNGs and WebP lossy images are **25-34% smaller** in size compared to JPEG images.
546
555
 
547
- To recompress your PNG or JPEG files into WebP format simply set `"webp": true` flag in your request JSON. You can also optionally set `"lossy": true` flag to leverage WebP's lossy compression:
556
+ WebP's lossy compression:WebP compression no longer requires setting `"webp": true` . Instead, you should make a standard optimization request, and Kraken.io will handle WebP conversion based on your configured settings.
557
+
558
+ ### Convert to WebP format
548
559
 
549
560
  ```javascript
550
561
  var opts = {
551
562
  file: '/path/to/image/file.jpg',
552
563
  wait: true,
553
- webp: true,
564
+ lossy: true,
565
+ convert: {
566
+ format: 'webp'
567
+ }
568
+ }
569
+ ```
570
+
571
+ ### Optimize WebP Image
572
+
573
+ ```javascript
574
+ var opts = {
575
+ file: '/path/to/image/file.webp',
576
+ wait: true,
554
577
  lossy: true
555
578
  }
556
579
  ```
557
580
 
558
- ## Amazon S3 and Rackspace Cloud Files
581
+ ## PDF Compression
582
+
583
+ Kraken.io now supports PDF compression, allowing you to optimize PDF files with minimal loss of quality.
584
+
585
+ Kraken API automatically determines the optimal compression settings based on the content type of the PDF (e.g., image-heavy, text-heavy, or mixed content). Additionally, users can optionally provide custom parameters to further control the compression process.
586
+
587
+ ```javascript
588
+ var opts = {
589
+ file: '/path/to/image/document.pdf',
590
+ wait: true
591
+ }
592
+ ```
593
+
594
+ **Optional Parameters:**
595
+
596
+ [API Docs for PDF Compression](https://kraken.io/docs/pdf-compression)
597
+
598
+ - `level` - Optimization level for the PDF. Available options are `screen`, `ebook`, `printer` and `prepress`. **Overrides DPI values**.
599
+ - `quality` - JPEG quality for embedded images. Acceptable values: **1-100**. Higher values preserve more detail but increase file size. Default is **65**.
600
+ - `dpi` - Resolution for images within the PDF. Default value is calculated based on the PDF type. Adjust this value based on your desired output quality.
601
+ - `downsampleType` - Method used to downsample images. Available options are `bicubic`, `average` and `subsample`
602
+
603
+ ```javascript
604
+ var opts = {
605
+ file: '/path/to/image/file.webp',
606
+ wait: true,
607
+ level: 'ebook',
608
+ quality: 60,
609
+ dpi: 150,
610
+ downsampleType: 'bicubic'
611
+ }
612
+ ```
613
+
614
+ ## Amazon S3, Rackspace Cloud Files and Google Cloud Storage
559
615
 
560
- Kraken API allows you to store optimized images directly in your S3 bucket or Cloud Files container. With just a few additional parameters your optimized images will be pushed to your external storage in no time.
616
+ Kraken API allows you to store optimized images directly in your S3 bucket, Google Cloud Storage or Cloud Files container. With just a few additional parameters your optimized images will be pushed to your external storage in no time.
561
617
 
562
618
  ### Amazon S3
563
619
 
@@ -604,11 +660,12 @@ kraken.upload(opts, function (err, data) {
604
660
  })
605
661
 
606
662
  // with promise
607
- kraken.upload(opts)
608
- .then(data => {
663
+ kraken
664
+ .upload(opts)
665
+ .then((data) => {
609
666
  console.log('Success. Optimized image URL: %s', data.kraked_url)
610
667
  })
611
- .catch(err => {
668
+ .catch((err) => {
612
669
  console.log('Failed. Error message: %s', err)
613
670
  })
614
671
  ```
@@ -653,7 +710,6 @@ var opts = {
653
710
  }
654
711
  }
655
712
 
656
-
657
713
  // with callback
658
714
  kraken.upload(opts, function (err, data) {
659
715
  if (err) {
@@ -664,11 +720,12 @@ kraken.upload(opts, function (err, data) {
664
720
  })
665
721
 
666
722
  // with promise
667
- kraken.upload(opts)
668
- .then(data => {
723
+ kraken
724
+ .upload(opts)
725
+ .then((data) => {
669
726
  console.log('Success. Optimized image URL: %s', data.kraked_url)
670
727
  })
671
- .catch(err => {
728
+ .catch((err) => {
672
729
  console.log('Failed. Error message: %s', err)
673
730
  })
674
731
  ```
@@ -685,6 +742,90 @@ If your container is not CDN-enabled `kraked_url` will point to the optimized im
685
742
  kraked_url: 'http://dl.kraken.io/ecdfa5c55d5668b1b5fe9e420554c4ee/file.jpg'
686
743
  ```
687
744
 
745
+ ### Google Cloud Storage
746
+
747
+ Kraken.io API allows you to store optimized images directly in your Google Cloud Storage (GCS) bucket. Follow the steps below to configure your GCS integration and securely store your optimized images.
748
+
749
+ #### Prerequisites:
750
+
751
+ Ensure you have access to Google Cloud Platform (GCP) and an active project where you will store your images.
752
+
753
+ #### Mandatory Parameters:
754
+
755
+ - `gcs_store.bucket` - Name of the destination bucket on your Google Cloud Storage account.
756
+ - `gcs_store.credentials` - Your service account credentials (JSON format) to authenticate with GCS.
757
+
758
+ #### Optional Parameters:
759
+
760
+ - `gcs_store.path` - Destination path in your GCS bucket (e.g., "images/layout/header.jpg"). Defaults to root `/`.
761
+ - `gcs_store.acl` - Permissions of the destination object. This can be "publicRead" or "private". Defaults to "private".
762
+ - `gcs_store.metadata` - Metadata you would like to assign to your GCS object (optimized image).
763
+
764
+ #### Important:
765
+
766
+ Make sure your Google Cloud Storage bucket has the appropriate permissions set to allow Kraken.io API to store images.
767
+
768
+ #### Step 1: Creating a Google Cloud Storage Bucket
769
+
770
+ 1. Log in to your Google Cloud Console.
771
+ 2. Navigate to the "Storage" section and select "Browser."
772
+ 3. Click "Create bucket" and follow the prompts.
773
+ 4. Note the bucket name for later use.
774
+
775
+ #### Step 2: Obtaining GCS Credentials
776
+
777
+ To interact with GCS through the API, you need appropriate credentials as a service account key:
778
+
779
+ 1. Go to "IAM & Admin" in Google Cloud Console.
780
+ 2. Select "Service Accounts" and click "Create Service Account."
781
+ 3. Enter a name and description for the service account.
782
+ 4. Assign necessary roles like "Storage Object Admin" or "Storage Object Creator."
783
+ 5. Click "Create Key" and choose JSON type. This will download a JSON file with your credentials.
784
+ 6. Securely store this JSON file. It contains sensitive information that allows access to your GCS resources.
785
+
786
+ #### Step 3: Configuring Your Kraken.io API Request
787
+
788
+ Include the necessary details in your Kraken.io API request to store the optimized image directly in your GCS bucket. Insert the JSON file's contents into the `credentials` property inside `gcs_store`.
789
+
790
+ ```javascript
791
+ const fs = require('fs').promises;
792
+ const Kraken = require("kraken");
793
+
794
+ (async () => {
795
+ try {
796
+ const kraken = new Kraken({
797
+ api_key: "your_api_key",
798
+ api_secret: "your_api_secret"
799
+ });
800
+
801
+ const credentials = JSON.parse(await fs.readFile('path/to/your/credentials.json', 'utf8'));
802
+
803
+ const params = {
804
+ url: "https://example.com/image.png",
805
+ wait: true,
806
+ lossy: true,
807
+ gcs_store: {
808
+ acl: "private",
809
+ bucket: "your-bucket-name",
810
+ path: "path/to/your/image.png",
811
+ credentials
812
+ }
813
+ };
814
+
815
+ kraken.url(params, function (status) {
816
+ if (status.success) {
817
+ console.log("Success. Optimized image URL: %s", status.kraked_url);
818
+ } else {
819
+ console.log("Fail. Error message: %s", status.message);
820
+ }
821
+ });
822
+ } catch (error) {
823
+ console.error("Error:", error);
824
+ }
825
+ })();
826
+ }
827
+ ```
828
+
688
829
  # LICENSE - MIT
689
830
 
690
831
  Copyright (c) 2013-2021 Nekkra UG
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kraken",
3
- "version": "1.0.1",
3
+ "version": "1.0.4",
4
4
  "author": {
5
5
  "name": "Kraken.io",
6
6
  "email": "support@kraken.io"
@@ -19,12 +19,12 @@
19
19
  "image optimiser"
20
20
  ],
21
21
  "license": "MIT",
22
- "engine": {
22
+ "engines": {
23
23
  "node": ">=12.20.0"
24
24
  },
25
25
  "dependencies": {
26
26
  "axios": "^0.24.0",
27
- "form-data": "^4.0.0"
27
+ "form-data": "^4.0.1"
28
28
  },
29
29
  "devDependencies": {
30
30
  "dotenv": "^16.3.1",