Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"dependencies": {
"@apify/consts": "^2.42.0",
"@apify/log": "^2.2.6",
"@apify/utilities": "^2.18.0",
"@apify/utilities": "^2.23.0",
"@crawlee/types": "^3.3.0",
"agentkeepalive": "^4.2.1",
"async-retry": "^1.3.3",
Expand Down
1 change: 1 addition & 0 deletions rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export default defineConfig({
externals: {
'node:util': 'node:util',
'node:zlib': 'node:zlib',
crypto: 'node:crypto',
},
},
tools: {
Expand Down
4 changes: 2 additions & 2 deletions src/resource_clients/dataset.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ow from 'ow';

import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
import { createStorageContentSignature } from '@apify/utilities';
import { createStorageContentSignatureAsync } from '@apify/utilities';

import type { ApifyApiError } from '../apify_api_error';
import type { ApiClientSubResourceOptions } from '../base/api_client';
Expand Down Expand Up @@ -204,7 +204,7 @@ export class DatasetClient<
let createdItemsPublicUrl = new URL(this._publicUrl('items'));

if (dataset?.urlSigningSecretKey) {
const signature = createStorageContentSignature({
const signature = await createStorageContentSignatureAsync({
resourceId: dataset.id,
urlSigningSecretKey: dataset.urlSigningSecretKey,
expiresInMillis: expiresInSecs ? expiresInSecs * 1000 : undefined,
Expand Down
6 changes: 3 additions & 3 deletions src/resource_clients/key_value_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { JsonValue } from 'type-fest';

import type { STORAGE_GENERAL_ACCESS } from '@apify/consts';
import log from '@apify/log';
import { createHmacSignature, createStorageContentSignature } from '@apify/utilities';
import { createHmacSignatureAsync, createStorageContentSignatureAsync } from '@apify/utilities';

import type { ApifyApiError } from '../apify_api_error';
import type { ApiClientSubResourceOptions } from '../base/api_client';
Expand Down Expand Up @@ -100,7 +100,7 @@ export class KeyValueStoreClient extends ResourceClient {
const recordPublicUrl = new URL(this._publicUrl(`records/${key}`));

if (store?.urlSigningSecretKey) {
const signature = createHmacSignature(store.urlSigningSecretKey, key);
const signature = await createHmacSignatureAsync(store.urlSigningSecretKey, key);
recordPublicUrl.searchParams.append('signature', signature);
}

Expand Down Expand Up @@ -138,7 +138,7 @@ export class KeyValueStoreClient extends ResourceClient {
let createdPublicKeysUrl = new URL(this._publicUrl('keys'));

if (store?.urlSigningSecretKey) {
const signature = createStorageContentSignature({
const signature = await createStorageContentSignatureAsync({
resourceId: store.id,
urlSigningSecretKey: store.urlSigningSecretKey,
expiresInMillis: expiresInSecs ? expiresInSecs * 1000 : undefined,
Expand Down
5 changes: 4 additions & 1 deletion test/_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ class Browser {
return this.browser;
}

async getInjectedPage(baseUrl, DEFAULT_OPTIONS) {
async getInjectedPage(baseUrl, DEFAULT_OPTIONS, gotoUrl = null) {
const page = await this.browser.newPage();
if (gotoUrl) await page.goto(gotoUrl);

await puppeteerUtils.injectFile(page, `${__dirname}/../dist/bundle.js`);

page.on('console', (msg) => console.log(msg.text()));
Expand All @@ -26,6 +28,7 @@ class Browser {
baseUrl,
DEFAULT_OPTIONS,
);

return page;
}

Expand Down
9 changes: 8 additions & 1 deletion test/datasets.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ describe('Dataset methods', () => {
let client;
let page;
beforeEach(async () => {
page = await browser.getInjectedPage(baseUrl, DEFAULT_OPTIONS);
// Navigate to localhost address to ensure secure context e.g. for Web Crypto API
page = await browser.getInjectedPage(baseUrl, DEFAULT_OPTIONS, baseUrl);
client = new ApifyClient({
baseUrl,
maxRetries: 0,
Expand Down Expand Up @@ -406,6 +407,9 @@ describe('Dataset methods', () => {
const url = new URL(res);
expect(url.searchParams.get('signature')).toBeDefined();
expect(url.pathname).toBe(`/v2/datasets/${datasetId}/items`);

const browserRes = await page.evaluate((id) => client.dataset(id).createItemsPublicUrl(), datasetId);
expect(browserRes).toEqual(res);
});

it('should not include a signature in the URL when the caller lacks permission to access the signing secret key', async () => {
Expand All @@ -415,6 +419,9 @@ describe('Dataset methods', () => {
const url = new URL(res);
expect(url.searchParams.get('signature')).toBeNull();
expect(url.pathname).toBe(`/v2/datasets/${datasetId}/items`);

const browserRes = await page.evaluate((id) => client.dataset(id).createItemsPublicUrl(), datasetId);
expect(browserRes).toEqual(res);
});

it('includes provided options (e.g., limit and prefix) as query parameters', async () => {
Expand Down
21 changes: 20 additions & 1 deletion test/key_value_stores.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ describe('Key-Value Store methods', () => {
let client;
let page;
beforeEach(async () => {
page = await browser.getInjectedPage(baseUrl, DEFAULT_OPTIONS);
// Navigate to localhost address to ensure secure context e.g. for Web Crypto API
page = await browser.getInjectedPage(baseUrl, DEFAULT_OPTIONS, baseUrl);
client = new ApifyClient({
baseUrl,
maxRetries: 0,
Expand Down Expand Up @@ -619,6 +620,12 @@ describe('Key-Value Store methods', () => {
const url = new URL(res);
expect(url.searchParams.get('signature')).toBeDefined();
expect(url.pathname).toBe(`/v2/key-value-stores/${storeId}/records/${key}`);

const browserRes = await page.evaluate(
({ storeId, key }) => client.keyValueStore(storeId).getRecordPublicUrl(key),
{ storeId, key },
);
expect(browserRes).toEqual(res);
});

it('should not include a signature in the URL when the caller lacks permission to access the signing secret key', async () => {
Expand All @@ -629,6 +636,12 @@ describe('Key-Value Store methods', () => {
const url = new URL(res);
expect(url.searchParams.get('signature')).toBeNull();
expect(url.pathname).toBe(`/v2/key-value-stores/${storeId}/records/${key}`);

const browserRes = await page.evaluate(
({ storeId, key }) => client.keyValueStore(storeId).getRecordPublicUrl(key),
{ storeId, key },
);
expect(browserRes).toEqual(res);
});
});

Expand Down Expand Up @@ -659,6 +672,9 @@ describe('Key-Value Store methods', () => {
const url = new URL(res);
expect(url.searchParams.get('signature')).toBeDefined();
expect(url.pathname).toBe(`/v2/key-value-stores/${storeId}/keys`);

const browserRes = await page.evaluate((id) => client.keyValueStore(id).createKeysPublicUrl(), storeId);
expect(browserRes).toEqual(res);
});

it('should not include a signature in the URL when the caller lacks permission to access the signing secret key', async () => {
Expand All @@ -668,6 +684,9 @@ describe('Key-Value Store methods', () => {
const url = new URL(res);
expect(url.searchParams.get('signature')).toBeNull();
expect(url.pathname).toBe(`/v2/key-value-stores/${storeId}/keys`);

const browserRes = await page.evaluate((id) => client.keyValueStore(id).createKeysPublicUrl(), storeId);
expect(browserRes).toEqual(res);
});

it('includes provided options (e.g., limit and prefix) as query parameters', async () => {
Expand Down
Loading