Skip to content

Commit

Permalink
fix(javascript): auth via query parameters (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts authored Feb 8, 2022
1 parent d40a1eb commit fcbf773
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 378 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export const createAbtestingApi = (
hosts: options?.hosts ?? getDefaultHosts(options.region),
baseHeaders: {
'content-type': 'application/x-www-form-urlencoded',
...auth.headers(),
},
baseQueryParameters: auth.queryParameters(),
userAgent: getUserAgent({
userAgents: options.userAgents,
client: 'Abtesting',
Expand Down Expand Up @@ -89,10 +91,7 @@ export const createAbtestingApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -124,10 +123,7 @@ export const createAbtestingApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -157,10 +153,7 @@ export const createAbtestingApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -195,10 +188,7 @@ export const createAbtestingApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -228,10 +218,7 @@ export const createAbtestingApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export const createAnalyticsApi = (
hosts: options?.hosts ?? getDefaultHosts(options.region),
baseHeaders: {
'content-type': 'application/x-www-form-urlencoded',
...auth.headers(),
},
baseQueryParameters: auth.queryParameters(),
userAgent: getUserAgent({
userAgents: options.userAgents,
client: 'Analytics',
Expand Down Expand Up @@ -110,10 +112,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -166,10 +165,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -222,10 +218,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -278,10 +271,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -334,10 +324,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -390,10 +377,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -446,10 +430,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -514,10 +495,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -582,10 +560,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -618,10 +593,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -686,10 +658,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -760,10 +729,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -845,10 +811,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -919,10 +882,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -1001,10 +961,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -1089,10 +1046,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down Expand Up @@ -1145,10 +1099,7 @@ export const createAnalyticsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,22 @@ import {
stackFrameWithoutCredentials,
} from './stackTrace';
import type {
EndRequest,
Headers,
Host,
QueryParameters,
Request,
RequestOptions,
Response,
StackFrame,
Timeouts,
Response,
EndRequest,
UserAgent,
} from './types';

export class Transporter {
private hosts: Host[];
private baseHeaders: Headers;
private baseQueryParameters: QueryParameters;
private hostsCache: Cache;
private userAgent: UserAgent;
private timeouts: Timeouts;
Expand All @@ -38,19 +40,22 @@ export class Transporter {
constructor({
hosts,
baseHeaders,
baseQueryParameters,
userAgent,
timeouts,
requester,
}: {
hosts: Host[];
baseHeaders: Headers;
baseQueryParameters: QueryParameters;
userAgent: UserAgent;
timeouts: Timeouts;
requester: Requester;
}) {
this.hosts = hosts;
this.hostsCache = new MemoryCache();
this.baseHeaders = baseHeaders;
this.baseQueryParameters = baseQueryParameters;
this.userAgent = userAgent;
this.timeouts = timeouts;
this.requester = requester;
Expand Down Expand Up @@ -135,6 +140,7 @@ export class Transporter {

const queryParameters = {
'x-algolia-agent': this.userAgent.value,
...this.baseQueryParameters,
...dataQueryParameters,
...requestOptions.queryParameters,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type EchoResponse = Request & {
};

export type Headers = Record<string, string>;
export type QueryParameters = Record<string, string>;

export type Host = {
url: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ export const createInsightsApi = (
hosts: options?.hosts ?? getDefaultHosts(options.region),
baseHeaders: {
'content-type': 'application/x-www-form-urlencoded',
...auth.headers(),
},
baseQueryParameters: auth.queryParameters(),
userAgent: getUserAgent({
userAgents: options.userAgents,
client: 'Insights',
Expand Down Expand Up @@ -77,10 +79,7 @@ export const createInsightsApi = (

return transporter.request(request, {
queryParameters,
headers: {
...headers,
...auth.headers(),
},
headers,
});
}

Expand Down
Loading

0 comments on commit fcbf773

Please sign in to comment.