@@ -31,11 +31,11 @@ export default defineApp({
3131 type : "string" ,
3232 label : "Business Unit ID" ,
3333 description : "The unique identifier for your business unit on Trustpilot" ,
34- async options ( ) {
34+ async options ( page , prevContext , query ) {
3535 try {
3636 const businessUnits = await this . searchBusinessUnits ( {
37- query : "" ,
38- limit : 20 ,
37+ query,
38+ page ,
3939 } ) ;
4040 return businessUnits . map ( ( {
4141 id, displayName, name : { identifying } ,
@@ -54,6 +54,18 @@ export default defineApp({
5454 label : "Review ID" ,
5555 description : "The unique identifier for a review" ,
5656 } ,
57+ sku : {
58+ type : "string" ,
59+ label : "SKU" ,
60+ description : "Filter by SKU" ,
61+ optional : true ,
62+ } ,
63+ productUrl : {
64+ type : "string" ,
65+ label : "Product URL" ,
66+ description : "Filter by product URL" ,
67+ optional : true ,
68+ } ,
5769 stars : {
5870 type : "integer" ,
5971 label : "Star Rating" ,
@@ -106,25 +118,50 @@ export default defineApp({
106118 } ,
107119 methods : {
108120 // Authentication and base request methods
109- _getAuthHeaders ( ) {
121+ _isPrivateURL ( url ) {
122+ return url . includes ( "private" ) ;
123+ } ,
124+
125+ _getAuthHeadersForPrivateURL ( ) {
126+ if ( ! this . $auth ?. oauth_access_token ) {
127+ throw new Error ( "Authentication required: OAuth token is required for private requests" ) ;
128+ } else {
129+ return {
130+ "Authorization" : `Bearer ${ this . $auth . oauth_access_token } ` ,
131+ } ;
132+ }
133+ } ,
134+
135+ _getAuthHeadersForPublicURL ( ) {
136+ if ( ! this . $auth ?. api_key ) {
137+ throw new Error ( "Authentication required: API key is required for public requests" ) ;
138+ } else {
139+ return {
140+ "apikey" : this . $auth . api_key ,
141+ } ;
142+ }
143+ } ,
144+
145+ _getAuthHeaders ( url ) {
110146 const headers = {
111147 "Content-Type" : "application/json" ,
112148 "User-Agent" : "Pipedream/1.0" ,
113149 } ;
114150
115- if ( ! this . $auth ?. api_key && ! this . $auth ?. oauth_access_token ) {
116- throw new Error ( "Authentication required: Configure either API key or OAuth token" ) ;
117- }
118-
119- if ( this . $auth ?. api_key ) {
120- headers [ "apikey" ] = this . $auth . api_key ;
121- }
151+ const isPrivate = this . _isPrivateURL ( url ) ;
152+ console . log ( "isPrivate" , isPrivate ) ;
122153
123- if ( this . $auth ?. oauth_access_token ) {
124- headers [ "Authorization" ] = `Bearer ${ this . $auth . oauth_access_token } ` ;
154+ if ( isPrivate ) {
155+ return {
156+ ...headers ,
157+ ...this . _getAuthHeadersForPrivateURL ( ) ,
158+ } ;
159+ } else {
160+ return {
161+ ...headers ,
162+ ...this . _getAuthHeadersForPublicURL ( ) ,
163+ } ;
125164 }
126-
127- return headers ;
128165 } ,
129166
130167 async _makeRequest ( {
@@ -182,14 +219,13 @@ export default defineApp({
182219 } ,
183220
184221 async searchBusinessUnits ( {
185- query = "" , limit = DEFAULT_LIMIT , offset = 0 ,
222+ query = "" , page = 1 ,
186223 } = { } ) {
187224 const response = await this . _makeRequest ( {
188225 endpoint : ENDPOINTS . BUSINESS_UNITS ,
189226 params : {
190227 query,
191- limit,
192- offset,
228+ page,
193229 } ,
194230 } ) ;
195231
@@ -265,6 +301,8 @@ export default defineApp({
265301 async _getReviews ( {
266302 endpoint,
267303 businessUnitId,
304+ sku = null ,
305+ productUrl = null ,
268306 stars = null ,
269307 sortBy = SORT_OPTIONS . CREATED_AT_DESC ,
270308 limit = DEFAULT_LIMIT ,
@@ -277,7 +315,13 @@ export default defineApp({
277315 throw new Error ( "Invalid business unit ID" ) ;
278316 }
279317
318+ if ( sku === null && productUrl === null ) {
319+ throw new Error ( "Either SKU or product URL is required" ) ;
320+ }
321+
280322 const params = {
323+ sku,
324+ productUrl,
281325 stars,
282326 orderBy : sortBy ,
283327 perPage : limit ,
0 commit comments