@@ -5,7 +5,7 @@ import type { JsonValue } from 'type-fest';
5
5
6
6
import type { STORAGE_GENERAL_ACCESS } from '@apify/consts' ;
7
7
import log from '@apify/log' ;
8
- import { createStorageContentSignature } from '@apify/utilities' ;
8
+ import { createHmacSignature , createStorageContentSignature } from '@apify/utilities' ;
9
9
10
10
import type { ApifyApiError } from '../apify_api_error' ;
11
11
import type { ApiClientSubResourceOptions } from '../base/api_client' ;
@@ -86,10 +86,31 @@ export class KeyValueStoreClient extends ResourceClient {
86
86
}
87
87
88
88
/**
89
- * Generates a URL that can be used to access key-value store keys .
89
+ * Generates a URL that can be used to access key-value store record .
90
90
*
91
91
* If the client has permission to access the key-value store's URL signing key,
92
92
* the URL will include a signature to verify its authenticity.
93
+ */
94
+ async getRecordPublicUrl ( key : string ) : Promise < string > {
95
+ ow ( key , ow . string . nonEmpty ) ;
96
+
97
+ const store = await this . get ( ) ;
98
+
99
+ const recordPublicUrl = new URL ( this . _url ( `records/${ key } ` ) ) ;
100
+
101
+ if ( store ?. urlSigningSecretKey ) {
102
+ const signature = createHmacSignature ( store . urlSigningSecretKey , key ) ;
103
+ recordPublicUrl . searchParams . append ( 'signature' , signature ) ;
104
+ }
105
+
106
+ return recordPublicUrl . toString ( ) ;
107
+ }
108
+
109
+ /**
110
+ * Generates a URL that can be used to access key-value store keys.
111
+ *
112
+ * If the client has permission to access the key-value store's URL signing key,
113
+ * the URL will include a signature which will allow the link to work even without authentication.
93
114
*
94
115
* You can optionally control how long the signed URL should be valid using the `expiresInMillis` option.
95
116
* This value sets the expiration duration in milliseconds from the time the URL is generated.
0 commit comments