@@ -39,13 +39,19 @@ import {
39
39
* password: "xyz_pw"
40
40
* });
41
41
*
42
+ * const threeDaysFromToday = new Date();
43
+ * threeDaysFromToday.setDate(threeDaysFromToday.getDate() + 3);
44
+ * threeDaysFromToday.setHours(23, 59, 59, 999);
45
+ *
42
46
* updateApiKey({
43
47
* itemId: "xyz_itemId",
44
- * privileges: [Privileges.Geocode ],
48
+ * privileges: ["premium:user:geocode:temporary" ],
45
49
* httpReferrers: [], // httpReferrers will be set to be empty
46
50
* authentication: authSession
51
+ * generateToken1: true, // optional,generate a new token
52
+ * apiToken1ExpirationDate: threeDaysFromToday // optional, update expiration date
47
53
* }).then((updatedAPIKey: IApiKeyResponse) => {
48
- * // => {apiKey : "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
54
+ * // => {accessToken1 : "xyz_key", item: {tags: ["xyz_tag1", "xyz_tag2"], ...}, ...}
49
55
* }).catch(e => {
50
56
* // => an exception object
51
57
* });
@@ -81,29 +87,31 @@ export async function updateApiKey(
81
87
/**
82
88
* step 2: update privileges and httpReferrers if provided. Build the object up to avoid overwriting any existing properties.
83
89
*/
84
- const getAppOption : IGetAppInfoOptions = {
85
- ...baseRequestOptions ,
86
- authentication : requestOptions . authentication ,
87
- itemId : requestOptions . itemId
88
- } ;
89
- const appResponse = await getRegisteredAppInfo ( getAppOption ) ;
90
- const clientId = appResponse . client_id ;
91
- const options = appendCustomParams (
92
- { ...appResponse , ...requestOptions } , // object with the custom params to look in
93
- [ "privileges" , "httpReferrers" ] // keys you want copied to the params object
94
- ) ;
95
- options . params . f = "json" ;
90
+ if ( requestOptions . privileges || requestOptions . httpReferrers ) {
91
+ const getAppOption : IGetAppInfoOptions = {
92
+ ...baseRequestOptions ,
93
+ authentication : requestOptions . authentication ,
94
+ itemId : requestOptions . itemId
95
+ } ;
96
+ const appResponse = await getRegisteredAppInfo ( getAppOption ) ;
97
+ const clientId = appResponse . client_id ;
98
+ const options = appendCustomParams (
99
+ { ...appResponse , ...requestOptions } , // object with the custom params to look in
100
+ [ "privileges" , "httpReferrers" ] // keys you want copied to the params object
101
+ ) ;
102
+ options . params . f = "json" ;
96
103
97
- // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly
98
- stringifyArrays ( options ) ;
104
+ // encode special params value (e.g. array type...) in advance in order to make encodeQueryString() works correctly
105
+ stringifyArrays ( options ) ;
99
106
100
- const url = getPortalUrl ( options ) + `/oauth2/apps/${ clientId } /update` ;
107
+ const url = getPortalUrl ( options ) + `/oauth2/apps/${ clientId } /update` ;
101
108
102
- // Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.
103
- const updateResponse : IRegisteredAppResponse = await request ( url , {
104
- ...options ,
105
- authentication : requestOptions . authentication
106
- } ) ;
109
+ // Raw response from `/oauth2/apps/${clientId}/update`, apiKey not included because key is same.
110
+ const updateResponse : IRegisteredAppResponse = await request ( url , {
111
+ ...options ,
112
+ authentication : requestOptions . authentication
113
+ } ) ;
114
+ }
107
115
108
116
/**
109
117
* step 3: get the updated item info to return to the user.
0 commit comments