Skip to content

Commit 8f42d36

Browse files
authored
only new endpoint (#239)
1 parent b26ccb9 commit 8f42d36

10 files changed

+24
-96
lines changed

STREAMING_INGESTION.md

-9
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22

33
## Configurations
44

5-
We introduce a new option to opt-in our new JavaScript endpoint, named `useNewJavaScriptEndpoint`, which has a `true` or `false` value.
6-
When you enable this option, you need to change the `host` configuration as well, so that it will point to our new endpoint
7-
8-
:information_source: This new feature won't impact the server side cookie and the personalization features
9-
105
The `host` configuration will have the following values, depending on which environment you want to ingest data.
116

127
- AP02 Region
@@ -21,16 +16,12 @@ The `host` configuration will have the following values, depending on which envi
2116
- EU01 Region
2217
- **eu01.records.in.treasuredata.com**
2318

24-
When you opt-out of this feature by either setting the `useNewJavaScriptEndpoint` to `false` or not setting it, please make sure that
25-
you update the host to the old configuration, as mentioned in [this section](README.md#api)
26-
2719
Example:
2820

2921
```javascript
3022
var foo = new Treasure({
3123
database: 'foo',
3224
writeKey: 'your_write_only_key',
33-
useNewJavaScriptEndpoint: true,
3425
host: 'us01.records.in.treasuredata.com'
3526
});
3627
```

bin/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )"
66
VERSION=$(cat $ROOT_DIR/package.json | jq -r '.version')
77
HOST='in.treasuredata.com'
88
DATABASE=""
9-
PATHNAME="/js/v3/event/"
9+
PATHNAME="/"
1010
GLOBAL="Treasure"
1111
FILENAME="td"
1212
TO_VERSION=$(echo $VERSION | sed 's/\.[-a-zA-Z0-9]*$//g')

lib/config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ module.exports = {
33
VERSION: '3.1.2',
44
HOST: 'in.treasuredata.com',
55
DATABASE: '',
6-
PATHNAME: '/js/v3/event/'
6+
PATHNAME: '/'
77
}

lib/configurator.js

-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ var defaultSSCCookieDomain = function () {
4545
exports.DEFAULT_CONFIG = {
4646
database: config.DATABASE,
4747
development: false,
48-
useNewJavaScriptEndpoint: false,
4948
globalIdCookie: '_td_global',
5049
host: config.HOST,
5150
logging: true,
@@ -87,10 +86,6 @@ exports.configure = function configure (options) {
8786

8887
validateOptions(this.client)
8988

90-
if (this.client.useNewJavaScriptEndpoint) {
91-
this.client.pathname = '/'
92-
}
93-
9489
if (!this.client.endpoint) {
9590
this.client.endpoint = 'https://' + this.client.host + this.client.pathname
9691
}

lib/plugins/globalid.js

+6-13
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,17 @@ function fetchGlobalID (success, error, forceFetch, options) {
9393
options.sameSite = 'None'
9494
}
9595

96-
var url = 'https://' + this.client.host + '/js/v3/enable_global_id'
96+
var url = 'https://' + this.client.host
9797
var requestHeaders = {}
98-
var ignoreDefaultHeaders = false
9998

100-
if (this.client.useNewJavaScriptEndpoint) {
101-
url = 'https://' + this.client.host
102-
103-
requestHeaders['Authorization'] = 'TD1 ' + this.client.writeKey
104-
requestHeaders['User-Agent'] = navigator.userAgent
105-
requestHeaders['Content-Type'] = misc.globalIdAdlHeaders['Content-Type']
106-
requestHeaders['Accept'] = misc.globalIdAdlHeaders['Accept']
107-
ignoreDefaultHeaders = true
108-
}
99+
requestHeaders['Authorization'] = 'TD1 ' + this.client.writeKey
100+
requestHeaders['User-Agent'] = navigator.userAgent
101+
requestHeaders['Content-Type'] = misc.globalIdAdlHeaders['Content-Type']
102+
requestHeaders['Accept'] = misc.globalIdAdlHeaders['Accept']
109103

110104
api.get(url,
111105
{
112-
headers: requestHeaders,
113-
ignoreDefaultHeaders: ignoreDefaultHeaders
106+
headers: requestHeaders
114107
})
115108
.then(function (res) {
116109
var cachedId = cacheSuccess(res, cookieName, options)

lib/plugins/personalization.js

-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ function fetchUserSegments (tokenOrConfig, successCallback, errorCallback) {
8787

8888
api
8989
.get(url, {
90-
ignoreDefaultHeaders: true,
9190
headers: {
9291
'Content-Type': 'application/json'
9392
}

lib/plugins/servercookie.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,7 @@ function fetchServerCookie (success, error, forceFetch) {
5959
}, 0)
6060
}
6161

62-
api.get(url, {
63-
ignoreDefaultHeaders: true
64-
})
62+
api.get(url)
6563
.then(function (res) {
6664
success(res.td_ssc_id)
6765
})

lib/plugins/track.js

-7
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,5 @@ exports.getTrackValues = function getTrackValues () {
296296
}
297297
})
298298

299-
if (!this.client.useNewJavaScriptEndpoint) {
300-
result['td_ip'] = 'td_ip'
301-
result['td_browser'] = 'td_browser'
302-
result['td_browser_version'] = 'td_browser_version'
303-
result['td_os'] = 'td_os'
304-
result['td_os_version'] = 'td_os_version'
305-
}
306299
return result
307300
}

lib/record.js

+11-21
Original file line numberDiff line numberDiff line change
@@ -194,28 +194,20 @@ exports._sendRecord = function _sendRecord (request, success, error, blockedEven
194194

195195
var requestHeaders = {}
196196
var payload
197-
var ignoreDefaultHeaders = false
198197

199-
if (this.client.useNewJavaScriptEndpoint) {
200-
requestHeaders['Authorization'] = 'TD1 ' + request.apikey
201-
requestHeaders['User-Agent'] = navigator.userAgent
198+
requestHeaders['Authorization'] = 'TD1 ' + request.apikey
199+
requestHeaders['User-Agent'] = navigator.userAgent
202200

203-
if (this.isGlobalIdEnabled()) {
204-
requestHeaders['Content-Type'] = misc.globalIdAdlHeaders['Content-Type']
205-
requestHeaders['Accept'] = misc.globalIdAdlHeaders['Accept']
206-
} else {
207-
requestHeaders['Content-Type'] = misc.adlHeaders['Content-Type']
208-
requestHeaders['Accept'] = misc.adlHeaders['Accept']
209-
}
210-
211-
ignoreDefaultHeaders = true
212-
213-
payload = {
214-
events: [request.record]
215-
}
201+
if (this.isGlobalIdEnabled()) {
202+
requestHeaders['Content-Type'] = misc.globalIdAdlHeaders['Content-Type']
203+
requestHeaders['Accept'] = misc.globalIdAdlHeaders['Accept']
216204
} else {
217-
requestHeaders['X-TD-Write-Key'] = request.apikey
218-
payload = request.record
205+
requestHeaders['Content-Type'] = misc.adlHeaders['Content-Type']
206+
requestHeaders['Accept'] = misc.adlHeaders['Accept']
207+
}
208+
209+
payload = {
210+
events: [request.record]
219211
}
220212

221213
if (window.fetch && (this._windowBeingUnloaded || isClickedLink)) {
@@ -228,7 +220,6 @@ exports._sendRecord = function _sendRecord (request, success, error, blockedEven
228220
method: 'POST',
229221
keepalive: true,
230222
credentials: 'include',
231-
ignoreDefaultHeaders: ignoreDefaultHeaders,
232223
headers: requestHeaders
233224
}
234225
)
@@ -240,7 +231,6 @@ exports._sendRecord = function _sendRecord (request, success, error, blockedEven
240231
url,
241232
payload,
242233
{
243-
ignoreDefaultHeaders: ignoreDefaultHeaders,
244234
headers: requestHeaders
245235
}
246236
)

lib/utils/xhr.js

+4-35
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
// (C) Treasure Data 2020
22
/* global XMLHttpRequest fetch */
33
var win = require('global/window')
4-
var assign = require('./lodash').assign
54

65
var OK_STATUS = 200
76
var NOT_MODIFIED = 304
87

9-
var defaultHeaders = {
10-
'Content-Type': 'application/json',
11-
'X-TD-Fetch-Api': 'true'
12-
}
13-
148
var FETCH_CREDENTIALS = {
159
'same-origin': 'same-origin',
1610
include: 'include',
@@ -33,26 +27,10 @@ function toJSON (text) {
3327
return result
3428
}
3529

36-
function getHeaders (headers, ignoreDefaultHeaders) {
37-
headers = headers || {}
38-
39-
if (ignoreDefaultHeaders) {
40-
return assign({}, headers)
41-
}
42-
43-
return assign({}, defaultHeaders, headers)
44-
}
45-
4630
function isFetchSupported () {
4731
return 'fetch' in win
4832
}
4933

50-
function isDefaultHeadersIgnored (options) {
51-
options = options || {}
52-
53-
return options.ignoreDefaultHeaders || false
54-
}
55-
5634
function getCredentials (options) {
5735
options = options || {}
5836

@@ -66,7 +44,7 @@ function postWithFetch (url, body, options) {
6644

6745
return fetch(url, {
6846
method: 'POST',
69-
headers: getHeaders(headers, isDefaultHeadersIgnored(options)),
47+
headers: headers,
7048
credentials: getCredentials(options),
7149
body: JSON.stringify(body)
7250
}).then(function (response) {
@@ -76,9 +54,7 @@ function postWithFetch (url, body, options) {
7654
return response.text()
7755
})
7856
.then(function (text) {
79-
if (!text) return {}
80-
81-
return JSON.parse(text)
57+
return toJSON(text)
8258
})
8359
}
8460

@@ -89,7 +65,7 @@ function getWithFetch (url, options) {
8965

9066
return fetch(url, {
9167
method: method,
92-
headers: getHeaders(headers, isDefaultHeadersIgnored(options)),
68+
headers: headers,
9369
credentials: getCredentials(options)
9470
})
9571
.then(function (response) {
@@ -100,9 +76,7 @@ function getWithFetch (url, options) {
10076
return response.text()
10177
})
10278
.then(function (text) {
103-
if (!text) return {}
104-
105-
return JSON.parse(text)
79+
return toJSON(text)
10680
})
10781
}
10882

@@ -127,7 +101,6 @@ function createXHR (method, url, options) {
127101

128102
xhr.withCredentials = Boolean(getCredentials(options))
129103

130-
headers = getHeaders(options.headers, isDefaultHeadersIgnored(options))
131104
var headerKey
132105
for (headerKey in headers) {
133106
if (headers.hasOwnProperty(headerKey)) {
@@ -150,10 +123,6 @@ function postWithTimeout (url, body, milliseconds, options) {
150123
if (window.AbortController) {
151124
var controller = new window.AbortController()
152125

153-
var headers = getHeaders(options.headers, isDefaultHeadersIgnored(options))
154-
155-
options.headers = headers
156-
157126
var promise = window.fetch(url, Object.assign({}, options, {signal: controller.signal}))
158127
var timeoutId = setTimeout(function () {
159128
controller.abort()

0 commit comments

Comments
 (0)