Skip to content

Commit 2995920

Browse files
committed
changed some properties name
1 parent fe98cde commit 2995920

8 files changed

Lines changed: 54 additions & 54 deletions

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ npm install @imgproxy/imgproxy-node
3030
import { generateImageUrl } from '@imgproxy/imgproxy-node';
3131

3232
const url = generateImageUrl(
33-
baseUrl: "https://imgproxy.example.com/",
33+
endpoint: "https://imgproxy.example.com/",
3434
url: "https://example.com/image.jpg",
3535
options: {
3636
resizing_type: "fit",
@@ -50,35 +50,35 @@ const url = generateImageUrl(
5050
This method generates an imgproxy URL.
5151
It takes the following arguments:
5252

53-
- `baseUrl` (`string`) - (required) the base URL of your imgproxy instance
54-
- `url` (`Object | string`) - (required) a string with url value or an object that contains the value and resultType properties. You can specify only url if you agree with default `url.resultType` = "base64" or you have to specify `url.value` and `url.resultType`.
53+
- `endpoint` (`string`) - (required) the base URL of your imgproxy instance
54+
- `url` (`Object | string`) - (required) a string with url value or an object that contains the value and displayAs properties. You can specify only url if you agree with default `url.displayAs` = "base64" or you have to specify `url.value` and `url.displayAs`.
5555
- `value` (`string`) - (required) the plain text URL of the image.
56-
- `resultType` (`"base64" | "encrypted" | "plain"`) - (optional) the final type of URL you will receive . Deafult value is `"base64"`.
56+
- `displayAs` (`"base64" | "encrypted" | "plain"`) - (optional) how the image URL should be presented in the resulting imgproxy request URL. Deafult value is `"base64"`.
5757
Can be one of the following:
5858
- `"base64"` - a base64 encoded URL. Default value.
5959
- `"encrypted"` - (**PRO feature**) an AES-CBC encrypted URL.
6060
- `"plain"` - a plain text URL. We strongly recommend using `base64` or `encrypted` type.
6161
- `options` (`Object | undefined`) - (optional) an object that contains the resizing options. You can see all options in [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=processing-options) or in [Options types in imgproxy-js-core library](https://github.com/imgproxy/imgproxy-js-core/blob/main/src/types/index.ts).
62-
- `salt` (`string | undefined`) - (optional) the salt used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_SALT environment variable from process.env for this call.
63-
- `key` (`string | undefined`) - (optional) the key used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_KEY environment variable from process.env for this call.
64-
- `encryptKey` (`string | undefined`) - (optional, **PRO feature**) the key used to encrypt the URL. The key should be either 16, 24, or 32 bytes long for AES-128-CBC, AES-192-CBC, or AES-256-CBC, respectively. This option overrides IMGPROXY_SOURCE_URL_ENCRYPTION_KEY environment variable from process.env for this call.
65-
- `encryptIV` (`string | undefined`) - (optional, **PRO feature**) the IV used to encrypt the URL. The IV should be 16 bytes long. If not specified, the IV will be generated randomly. But we strongly recommend to specify it.
62+
- `salt` (`string | undefined`) - (optional) hex-encoded salt used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_SALT environment variable from process.env for this call.
63+
- `key` (`string | undefined`) - (optional) hex-encoded key used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_KEY environment variable from process.env for this call.
64+
- `encryptKey` (`string | undefined`) - (optional, **PRO feature**) hex-encoded key used to encrypt the URL. The key should be either 16, 24, or 32 bytes long for AES-128-CBC, AES-192-CBC, or AES-256-CBC, respectively. This option overrides IMGPROXY_SOURCE_URL_ENCRYPTION_KEY environment variable from process.env for this call.
65+
- `encryptIV` (`string | undefined`) - (optional, **PRO feature**) hex-encoded 16-bytes length IV for encrypting url. If not specified, the IV will be generated randomly. But it's better if you specify it yourself. Read more in [imgproxy docs iv-generation](https://docs.imgproxy.net/usage/encrypting_source_url#iv-generation).
6666

6767
### generateImageInfoUrl
6868

6969
This method generates an imgproxy URL to get a source image info.
7070
It takes the following arguments:
7171

72-
- `baseUrl` (`string`) - (required) the base URL of your imgproxy instance
73-
- `url` (`Object | string`) - (required) a string with url value or an object that contains the value and resultType properties. You can specify only url if you agree with default `url.resultType` = "base64" or you will have to specify `url.value` and `url.resultType`.
72+
- `endpoint` (`string`) - (required) the base URL of your imgproxy instance
73+
- `url` (`Object | string`) - (required) a string with url value or an object that contains the value and displayAs properties. You can specify only url if you agree with default `url.displayAs` = "base64" or you will have to specify `url.value` and `url.displayAs`.
7474
- `value` (`string`) - (required) the plain text URL of the image.
75-
- `resultType` (`"base64" | "encrypted" | "plain"`) - (optional) the final type of URL you will receive. Deafult value is `"base64"`.
75+
- `displayAs` (`"base64" | "encrypted" | "plain"`) - (optional) how the image URL should be presented in the resulting imgproxy request URL. Deafult value is `"base64"`.
7676
Can be one of the following:
7777
- `"base64"` - a base64 encoded URL. Default value.
7878
- `"encrypted"` - (**PRO feature**) an AES-CBC encrypted URL.
7979
- `"plain"` - a plain text URL. We strongly recommend using `base64` or `encrypted` type.
8080
- `options` (`Object | undefined`) - (optional) an object that contains the resizing options. You can see all options in [imgproxy docs](https://docs.imgproxy.net/getting_the_image_info?id=info-options) or in [OptionsImageInfo types in imgproxy-js-core library](https://github.com/imgproxy/imgproxy-js-core/blob/main/src/types/index.ts).
81-
- `salt` (`string | undefined`) - (optional) the salt used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_SALT from process.env for one request.
82-
- `key` (`string | undefined`) - (optional) the key used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_KEY from process.env for one request.
83-
- `encryptKey` (`string | undefined`) - (optional, **PRO feature**) the key used to encrypt the URL. The key should be either 16, 24, or 32 bytes long for AES-128-CBC, AES-192-CBC, or AES-256-CBC, respectively. This option overrides IMGPROXY_SOURCE_URL_ENCRYPTION_KEY from process.env for one request.
84-
- `encryptIV` (`string | undefined`) - (optional, **PRO feature**) the IV used to encrypt the URL. The IV should be 16 bytes long. If not specified, the IV will be generated randomly. But we strongly recommend to specify it.
81+
- `salt` (`string | undefined`) - (optional) hex-encoded salt used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_SALT from process.env for one request.
82+
- `key` (`string | undefined`) - (optional) hex-encoded key used to encode the URL. It must be a hex-encoded 16-byte string. This option overrides IMGPROXY_KEY from process.env for one request.
83+
- `encryptKey` (`string | undefined`) - (optional, **PRO feature**) hex-encoded key used to encrypt the URL. The key should be either 16, 24, or 32 bytes long for AES-128-CBC, AES-192-CBC, or AES-256-CBC, respectively. This option overrides IMGPROXY_SOURCE_URL_ENCRYPTION_KEY from process.env for one request.
84+
- `encryptIV` (`string | undefined`) - (optional, **PRO feature**) hex-encoded 16-bytes length IV for encrypting url. If not specified, the IV will be generated randomly. But it's better if you specify it yourself. Read more in [imgproxy docs iv-generation](https://docs.imgproxy.net/usage/encrypting_source_url#iv-generation).

src/methods/generateImageInfoUrl.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ describe("generateImageInfourl", () => {
1313
};
1414

1515
const result = generateImageInfoUrl({
16-
baseUrl: "https://imgproxy.example.com/",
16+
endpoint: "https://imgproxy.example.com/",
1717
url: {
1818
value: "https://example.com/image.jpg",
19-
resultType: "encrypted",
19+
displayAs: "encrypted",
2020
},
2121
options,
2222
salt: "520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5",
@@ -37,7 +37,7 @@ describe("generateImageInfourl", () => {
3737
};
3838

3939
const result = generateImageInfoUrl({
40-
baseUrl: "https://imgproxy.example.com",
40+
endpoint: "https://imgproxy.example.com",
4141
url: { value: "https://example.com/image.jpg" },
4242
options,
4343
});
@@ -49,7 +49,7 @@ describe("generateImageInfourl", () => {
4949

5050
it("should generate a valid encoded URL withouth options", () => {
5151
const result = generateImageInfoUrl({
52-
baseUrl: "https://imgproxy.example.com/",
52+
endpoint: "https://imgproxy.example.com/",
5353
url: "https://example.com/image.jpg",
5454
salt: "520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5",
5555
key: "943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881",
@@ -69,8 +69,8 @@ describe("generateImageInfourl", () => {
6969
};
7070

7171
const result = generateImageInfoUrl({
72-
baseUrl: "https://imgproxy.example.com/",
73-
url: { value: "https://example.com/image.jpg", resultType: "plain" },
72+
endpoint: "https://imgproxy.example.com/",
73+
url: { value: "https://example.com/image.jpg", displayAs: "plain" },
7474
options,
7575
});
7676

src/methods/generateImageInfoUrl.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import type { IGenerateImageInfoUrl } from "../types";
88

99
/**
1010
* Generate image info url. **PRO feature**
11-
* @param {string} baseUrl - Base url
12-
* @param {Object | string} url - you can specify only url if you agree with default url.resultType = "base64" or you have to specify url.value and url.resultType
11+
* @param {string} endpoint - Base url
12+
* @param {Object | string} url - you can specify only url if you agree with default url.displayAs = "base64" or you have to specify url.value and url.displayAs
1313
* @param {string} url.value - url value
14-
* @param {string} url.resultType - (optional) here you specify in what type of image URL is required in the generated.
14+
* @param {string} url.displayAs - (optional) here you specify in what type of image URL is required in the generated.
1515
* Imgproxy request URL: "plain", "base64" or "encrypted" (encrypted is PRO feature). We strongly recommend to use "base64" or "encrypted" kind of url. default: `"base64"`.
1616
* @param {Object} [options] - (optional) options. You can see all options in [imgproxy docs](https://docs.imgproxy.net/getting_the_image_info?id=info-options)
1717
* or in OptionsImageInfo types in imgproxy-js-core.d.ts
@@ -26,7 +26,7 @@ import type { IGenerateImageInfoUrl } from "../types";
2626
*
2727
* @example
2828
* const url = generateImageInfoUrl({
29-
* baseUrl: "https://imgproxy.example",
29+
* endpoint: "https://imgproxy.example",
3030
* url: "https://example.com/image.jpg",
3131
* options: {
3232
* average: { average: 1, ignore_transparent: "f" },
@@ -40,7 +40,7 @@ import type { IGenerateImageInfoUrl } from "../types";
4040
* });
4141
*/
4242
const generateImageInfoUrl = ({
43-
baseUrl: paramsBaseUrl,
43+
endpoint: paramsEndpoint,
4444
url,
4545
options,
4646
salt,
@@ -54,14 +54,14 @@ const generateImageInfoUrl = ({
5454
const optionsString = generateImageInfoUrlCore(changedUrl, options);
5555

5656
//changing base url
57-
const baseUrl = paramsBaseUrl.endsWith("/")
58-
? paramsBaseUrl.slice(0, -1)
59-
: paramsBaseUrl;
57+
const endpoint = paramsEndpoint.endsWith("/")
58+
? paramsEndpoint.slice(0, -1)
59+
: paramsEndpoint;
6060

6161
//adding base url and signature if it exists
6262
const path = finalizePath({ options: optionsString, salt, key });
6363

64-
return `${baseUrl}${INFO_PREFIX}${path}`;
64+
return `${endpoint}${INFO_PREFIX}${path}`;
6565
};
6666

6767
export default generateImageInfoUrl;

src/methods/generateImageUrl.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ describe("generateImageUrl", () => {
1414
};
1515

1616
const result = generateImageUrl({
17-
baseUrl: "https://imgproxy.example.com",
18-
url: { value: "https://example.com/image.jpg", resultType: "base64" },
17+
endpoint: "https://imgproxy.example.com",
18+
url: { value: "https://example.com/image.jpg", displayAs: "base64" },
1919
options,
2020
salt: "520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5",
2121
key: "943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881",
@@ -38,7 +38,7 @@ describe("generateImageUrl", () => {
3838
};
3939

4040
const result = generateImageUrl({
41-
baseUrl: "https://imgproxy.example.com/",
41+
endpoint: "https://imgproxy.example.com/",
4242
url: "https://example.com/image.jpg",
4343
options,
4444
});
@@ -50,7 +50,7 @@ describe("generateImageUrl", () => {
5050

5151
it("should generate a valid URL withouth options", () => {
5252
const result = generateImageUrl({
53-
baseUrl: "https://imgproxy.example.com/",
53+
endpoint: "https://imgproxy.example.com/",
5454
url: { value: "https://example.com/image.jpg" },
5555
salt: "520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5",
5656
key: "943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881",
@@ -70,8 +70,8 @@ describe("generateImageUrl", () => {
7070
};
7171

7272
const result = generateImageUrl({
73-
baseUrl: "https://imgproxy.example.com/",
74-
url: { value: "https://example.com/image.jpg", resultType: "encrypted" },
73+
endpoint: "https://imgproxy.example.com/",
74+
url: { value: "https://example.com/image.jpg", displayAs: "encrypted" },
7575
options,
7676
salt: "520f986b998545b4785e0defbc4f3c1203f22de2374a3d53cb7a7fe9fea309c5",
7777
key: "943b421c9eb07c830af81030552c86009268de4e532ba2ee2eab8247c6da0881",

src/methods/generateImageUrl.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type { IGenerateImageUrl } from "../types";
55

66
/**
77
* Generate image url
8-
* @param {string} baseUrl - Base url
9-
* @param {Object | string} url - you can specify only url if you agree with default url.resultType = "base64" or you have to specify url.value and url.resultType
8+
* @param {string} endpoint - Base url
9+
* @param {Object | string} url - you can specify only url if you agree with default url.displayAs = "base64" or you have to specify url.value and url.displayAs
1010
* @param {string} url.value - url value
11-
* @param {string} url.resultType - (optional) here you specify in what type of image URL is required in the generated.
11+
* @param {string} url.displayAs - (optional) how the image URL should be presented in the resulting imgproxy request URL.
1212
* Imgproxy request URL: "plain", "base64" or "encrypted" (encrypted is PRO feature). We strongly recommend to use "base64" or "encrypted" kind of url. default: `"base64"`
1313
* @param {Object} [options] - (optional) options. You can see all options in [imgproxy docs](https://docs.imgproxy.net/generating_the_url?id=processing-options)
1414
* or in Options types in imgproxy-js-core.d.ts
@@ -23,7 +23,7 @@ import type { IGenerateImageUrl } from "../types";
2323
*
2424
* @example
2525
* const url = generateImageUrl({
26-
* baseUrl: "https://imgproxy.example",
26+
* endpoint: "https://imgproxy.example",
2727
* url: "https://example.com/image.jpg",
2828
* options: {
2929
* resize: { width: 100, height: 100, type: "fill", enlarge: 1, extend: { extend: 1 } },
@@ -36,7 +36,7 @@ import type { IGenerateImageUrl } from "../types";
3636
* });
3737
*/
3838
const generateImageUrl = ({
39-
baseUrl: paramsBaseUrl,
39+
endpoint: paramsEndpoint,
4040
url,
4141
options,
4242
salt,
@@ -50,14 +50,14 @@ const generateImageUrl = ({
5050
const optionsString = generateUrl(changedUrl, options);
5151

5252
//changing base url
53-
const baseUrl = paramsBaseUrl.endsWith("/")
54-
? paramsBaseUrl.slice(0, -1)
55-
: paramsBaseUrl;
53+
const endpoint = paramsEndpoint.endsWith("/")
54+
? paramsEndpoint.slice(0, -1)
55+
: paramsEndpoint;
5656

5757
//adding base url and signature if it exists
5858
const path = finalizePath({ options: optionsString, salt, key });
5959

60-
return `${baseUrl}${path}`;
60+
return `${endpoint}${path}`;
6161
};
6262

6363
export default generateImageUrl;

src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ export interface ICryptPair {
2121

2222
export interface IRawUrl {
2323
value: string;
24-
resultType?: URL["type"];
24+
displayAs?: URL["type"];
2525
}
2626

2727
interface BaseGenerateImageUrl {
28-
baseUrl: string;
28+
endpoint: string;
2929
url: string | IRawUrl;
3030
salt?: string;
3131
key?: string;

src/utils/normalizeUrl.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
22
import normalizeUrl from "./normalizeUrl";
33

44
describe("normalizeUrl", () => {
5-
it("should return a throw error if resultType is 'encrypted' and encryptKey is not provided", () => {
5+
it("should return a throw error if displayAs is 'encrypted' and encryptKey is not provided", () => {
66
expect(() =>
77
normalizeUrl({
88
url: {
99
value: "https://example.com/image.jpg",
10-
resultType: "encrypted",
10+
displayAs: "encrypted",
1111
},
1212
})
1313
).toThrowError(
@@ -17,7 +17,7 @@ describe("normalizeUrl", () => {
1717

1818
it("should return a changed url type if encryptKey is provided", () => {
1919
const result = normalizeUrl({
20-
url: { value: "https://example.com/image.jpg", resultType: "encrypted" },
20+
url: { value: "https://example.com/image.jpg", displayAs: "encrypted" },
2121
encryptKey:
2222
"52dd01d54fcbd79ff247fcff1d2f200ce6b95546f960b084faa1d269fb95d600",
2323
});
@@ -35,7 +35,7 @@ describe("normalizeUrl", () => {
3535
expect(result.type).toBe("base64");
3636
});
3737

38-
it("should return a url type is 'base64' if url is object without url.resultType", () => {
38+
it("should return a url type is 'base64' if url is object without url.displayAs", () => {
3939
const result = normalizeUrl({
4040
url: {
4141
value: "https://example.com/image.jpg",
@@ -45,11 +45,11 @@ describe("normalizeUrl", () => {
4545
expect(result.type).toBe("base64");
4646
});
4747

48-
it("should return a url type is 'plain' if url is object with url.resultType === 'plain'", () => {
48+
it("should return a url type is 'plain' if url is object with url.displayAs === 'plain'", () => {
4949
const result = normalizeUrl({
5050
url: {
5151
value: "https://example.com/image.jpg",
52-
resultType: "plain",
52+
displayAs: "plain",
5353
},
5454
});
5555

src/utils/normalizeUrl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ interface INormalizeUrl {
1212
const normalizeUrl = ({ url, encryptKey, encryptIV }: INormalizeUrl): URL => {
1313
const changedUrl = {
1414
value: typeof url === "string" ? url : url.value,
15-
type: (typeof url === "string" ? "base64" : url.resultType) || "base64",
15+
type: (typeof url === "string" ? "base64" : url.displayAs) || "base64",
1616
};
1717

1818
//encoded url to base64

0 commit comments

Comments
 (0)