Skip to content

Commit c128d1f

Browse files
authored
feat: add support for premium plan and client param (deprecated) (#86)
1 parent cc506f2 commit c128d1f

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

src/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ test.each([
4545
"https://example.com/js?callback=__googleMapsCallback",
4646
],
4747
[
48-
{ channel: "foo" },
49-
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&channel=foo",
48+
{ client: "bar", channel: "foo" },
49+
"https://maps.googleapis.com/maps/api/js?callback=__googleMapsCallback&channel=foo&client=bar",
5050
],
5151
])("createUrl is correct", (options: LoaderOptions, expected: string) => {
5252
const loader = new Loader(options);

src/index.ts

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,32 +42,13 @@ export interface LoaderOptions {
4242
*/
4343
apiKey: string;
4444
/**
45-
* To track usage across different applications using the same client ID,
46-
* you may provide an optional channel parameter with your requests. By
47-
* specifying different channel values for different aspects of your
48-
* application, you can determine precisely how your application is used.
49-
*
50-
* For example, your externally-facing website may access the API using a
51-
* channel set to customer while your internal marketing department may use
52-
* a channel set to mkting. Your reports will break down usage by those
53-
* channel values.
54-
*
55-
* Channel reporting is available for applications using the Maps JavaScript
56-
* API, the image APIs or any of the Google Maps Platform web services.
57-
*
58-
* The channel parameter must use the following format:
59-
*
60-
* - Must be an ASCII alphanumeric string.
61-
* - Period (.), underscore (_) and hyphen (-) characters are allowed.
62-
* - The channel parameter is case-insensitive; upper-case, mixed-case, and
63-
* lower-cased channel parameters will be merged into their lower-case
64-
* equivalent. For example, usage on the `CUSTOMER` channel will be combined
65-
* with the usage on the `customer` channel.
66-
* - The channel value must be a static value assigned per application
67-
* instance, and must not be generated dynamically. You may not use
68-
* channel values to track individual users, for example.
45+
* @deprecated See https://developers.google.com/maps/premium/overview.
6946
*/
7047
channel?: string;
48+
/**
49+
* @deprecated See https://developers.google.com/maps/premium/overview, use `apiKey` instead.
50+
*/
51+
client?: string;
7152
/**
7253
* In your application you can specify release channels or version numbers:
7354
*
@@ -205,11 +186,15 @@ export class Loader {
205186
*/
206187
apiKey: string;
207188
/**
208-
* See [[LoaderOptions.id]]
189+
* See [[LoaderOptions.channel]]
209190
*/
210191
channel: string;
211192
/**
212-
* See [[LoaderOptions.channel]]
193+
* See [[LoaderOptions.client]]
194+
*/
195+
client: string;
196+
/**
197+
* See [[LoaderOptions.id]]
213198
*/
214199
id: string;
215200
/**
@@ -259,6 +244,7 @@ export class Loader {
259244
constructor({
260245
apiKey,
261246
channel,
247+
client,
262248
id = "__googleMapsScriptId",
263249
libraries = [],
264250
language,
@@ -271,6 +257,7 @@ export class Loader {
271257
this.version = version;
272258
this.apiKey = apiKey;
273259
this.channel = channel;
260+
this.client = client;
274261
this.id = id;
275262
this.libraries = libraries;
276263
this.language = language;
@@ -297,6 +284,10 @@ export class Loader {
297284
url += `&channel=${this.channel}`;
298285
}
299286

287+
if (this.client) {
288+
url += `&client=${this.client}`;
289+
}
290+
300291
if (this.libraries.length > 0) {
301292
url += `&libraries=${this.libraries.join(",")}`;
302293
}

0 commit comments

Comments
 (0)