Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 65dfb1d

Browse files
committed
Merge branch 'development'
* development: 1.0.0 Update package.json Make parsing of dates from ECM timezone-aware (#133) #128 CSRF Token set in cookie only in node env #130 fix header controllers api (#131) Update CHANGELOG.md 0.5.5 Update package.json improve npmignore and pointing for the pacakge #126 (#127) Add Report API - dev (#125) #121 - modified changelog #121 - fix babelify for IE10
2 parents b052beb + f556c54 commit 65dfb1d

File tree

12 files changed

+694
-322
lines changed

12 files changed

+694
-322
lines changed

.editorconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ end_of_line = lf
1010
insert_final_newline = true
1111
trim_trailing_whitespace = true
1212

13+
[src/alfresco-activiti-rest-api/**.js]
14+
indent_size = 2
15+
16+
[src/alfresco-core-rest-api/**.js]
17+
indent_size = 2
18+
1319
[package.json]
1420
indent_style = space
1521
indent_size = 2

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ Alfresco JS API
66

77
_This project provides a JavaScript client API into the v1 Alfresco REST API_
88

9+
<a name="1.0.0"></a>
10+
# [1.0.0](https://github.com/Alfresco/alfresco-js-api/releases/tag/1.0.0) (xx-xx-2016)
11+
## fix
12+
- [/api/enterprise/script-files/controllers sending wrong accept header #130](https://github.com/Alfresco/alfresco-js-api/pull/130)
13+
- [CSRF Token is not working #128](https://github.com/Alfresco/alfresco-js-api/pull/128)
14+
- [Timestamp timezones are ignored #134](https://github.com/Alfresco/alfresco-js-api/issues/134)
15+
916
<a name="0.5.5"></a>
1017
# [0.5.5](https://github.com/Alfresco/alfresco-js-api/releases/tag/0.5.5) (09-12-2016)
1118
## fix
1219
- [Added bable plugin for IE10 #121](https://github.com/Alfresco/alfresco-js-api/pull/122)
20+
21+
## Features
1322
- [Add the report api inside the js api #124](https://github.com/Alfresco/alfresco-js-api/issues/124)
1423

1524
<a name="0.5.3"></a>

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,13 @@ This project provides a JavaScript client API into the Alfresco REST API and Act
7272
* [Models Api](#models-api)
7373
+ [Get Model](#get-model)
7474
* [Report Api](#report-api)
75-
+ [Create Default reports](#create-default-reports)
75+
+ [Create default Reports](#create-default-reports)
7676
+ [Get Reports](#get-reports)
7777
+ [Report Params](#report-params)
78-
+ [Report Process Definitions](#report-process-definitions)
79-
+ [Tasks of process definition](#tasks-of-process-definition)
80-
+ [Generate reports](#generate-reports)
81-
+ [Update report details](#update-report-details)
78+
* [Report Process Definitions](#report-process-definitions)
79+
* [Tasks of process definition](#tasks-of-process-definition)
80+
* [Generate reports](#generate-reports)
81+
* [Update report details](#update-report-details)
8282
- [Development](#development)
8383
- [Release History](#release-history)
8484

dist/alfresco-js-api.js

Lines changed: 512 additions & 288 deletions
Large diffs are not rendered by default.

dist/alfresco-js-api.min.js

Lines changed: 19 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "alfresco-js-api",
3-
"version": "0.5.5",
3+
"version": "1.0.0",
44
"description": "JavaScript client library for the Alfresco REST API",
5+
"author": "Alfresco Software, Ltd.",
56
"main": "dist/alfresco-js-api.js",
67
"module": "main.js",
78
"typings": "index.d.ts",
89
"scripts": {
910
"clean": "rimraf dist/bundle.js node_modules",
1011
"build": "grunt && npm run tslint && npm run test && npm run bundle && npm run minify && npm run toc && npm run webpack-test",
11-
"webpack-test": "webpack main.js webpack-bundle-test.js",
12+
"webpack-test": "webpack main.js package/webpack-bundle-test.js",
1213
"test": "grunt test",
1314
"coverage": "grunt coverage",
1415
"generate": "mvn clean generate-sources",
@@ -38,6 +39,7 @@
3839
"babel-plugin-transform-proto-to-assign": "^6.9.0",
3940
"browserify": "^13.0.1",
4041
"chai": "^3.5.0",
42+
"chai-datetime": "^1.4.1",
4143
"expect.js": "~0.3.1",
4244
"grunt": "~0.4.0",
4345
"grunt-cli": "^1.1.0",

src/alfresco-activiti-rest-api/src/api/ScriptFileApi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
};
5757

5858
var authNames = [];
59-
var contentTypes = ['application/json'];
60-
var accepts = ['application/json', 'application/javascript'];
59+
var contentTypes = ['text/javascript'];
60+
var accepts = [];
6161
var returnType = 'String';
6262

6363
return this.apiClient.callApi(

src/alfresco-core-rest-api/src/ApiClient.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,12 +400,43 @@
400400
* @returns {Date} The parsed date object.
401401
*/
402402
exports.parseDate = function(str) {
403+
var dateLength = 10;
404+
var separatorPos = str.substring(dateLength).search(/[\+\-]/) + dateLength;
405+
var dateStr = separatorPos > dateLength ? str.substring(0, separatorPos) : str;
406+
var tzStr = separatorPos > dateLength ? str.substring(separatorPos) : '';
407+
var parsedDate = exports.parseDateTime(dateStr);
408+
var tzOffsetMins = exports.parseDateTimeZone(tzStr);
409+
parsedDate.setTime(parsedDate.getTime() + tzOffsetMins * 60000);
410+
return parsedDate;
411+
};
412+
413+
/**
414+
* Parses the date component of a ISO-8601 string representation of a date value.
415+
* @param {String} str The date value as a string.
416+
* @returns {Date} The parsed date object.
417+
*/
418+
exports.parseDateTime = function(str) {
403419
// TODO: review when Safari 10 is released
404420
// return new Date(str.replace(/T/i, ' '));
405421

406422
// Compatible with Safari 9.1.2
407-
var a = str.split(/[^0-9]/).map(function(s) { return parseInt(s, 10) });
408-
return new Date(a[0], a[1]-1 || 0, a[2] || 1, a[3] || 0, a[4] || 0, a[5] || 0, a[6] || 0);
423+
var parts = str.split('+');
424+
var dateParts = str.split(/[^0-9]/).map(function(s) { return parseInt(s, 10) });
425+
return new Date(Date.UTC(dateParts[0], dateParts[1]-1 || 0, dateParts[2] || 1, dateParts[3] || 0, dateParts[4] || 0, dateParts[5] || 0, dateParts[6] || 0));
426+
};
427+
428+
/**
429+
* Parses the timezone component of a ISO-8601 string representation of a date value.
430+
* @param {String} str The timezone offset as a string, e.g. '+0000', '+2000' or '-0500'.
431+
* @returns {number} The number of minutes offset from UTC.
432+
*/
433+
exports.parseDateTimeZone = function(str) {
434+
var match = /([\+\-])(\d{2}):?(\d{2})?/.exec(str);
435+
if (match !== null) {
436+
return (parseInt(match[1] + '1') * -1 * (parseInt(match[2]) * 60) + parseInt(match[3] || 0))
437+
} else {
438+
return 0;
439+
}
409440
};
410441

411442
/**

src/alfrescoApiClient.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ class AlfrescoApiClient extends ApiClient {
6666
if (this.isBpmRequest()) {
6767
request._withCredentials = true;
6868
if (this.authentications.cookie) {
69-
request.set('Cookie', this.authentications.cookie);
69+
if (this.isNodeEnv()) {
70+
request.set('Cookie', this.authentications.cookie);
71+
}
7072
}
7173
}
7274

@@ -183,22 +185,29 @@ class AlfrescoApiClient extends ApiClient {
183185
isCsrfEnabled() {
184186
if (this.config) {
185187
return !this.config.disableCsrf;
186-
}else {
188+
} else {
187189
return true;
188190
}
189191
}
190192

191193
setCsrfToken(request) {
192194
var token = this.token();
193195
request.set('X-CSRF-TOKEN', token);
194-
request.set('Cookie', 'CSRF-TOKEN=' + token + ';path=/');
196+
197+
if (this.isNodeEnv()) {
198+
request.set('Cookie', 'CSRF-TOKEN=' + token + ';path=/');
199+
}
195200

196201
try {
197202
document.cookie = 'CSRF-TOKEN=' + token + ';path=/';
198203
} catch (err) {
199204
}
200205
}
201206

207+
isNodeEnv() {
208+
return (typeof process !== 'undefined') && (process.release && process.release.name === 'node');
209+
}
210+
202211
token(a) {
203212
return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) : ([1e16] + 1e16).replace(/[01]/g, this.token);
204213
}

test/alfrescoApiClient.spec.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*global describe, it */
2+
3+
var ApiClient = require('../src/alfresco-core-rest-api/src/ApiClient');
4+
var chai = require('chai');
5+
var expect = chai.expect;
6+
7+
chai.use(require('chai-datetime'));
8+
9+
describe('Alfresco Core API Client', function () {
10+
11+
it('should convert dates falling in GMT without a timezone', function () {
12+
expect(ApiClient.parseDate('2015-11-17T03:33:17')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 3, 33, 17)));
13+
});
14+
15+
it('should convert dates falling in BST without a timezone', function () {
16+
expect(ApiClient.parseDate('2015-10-17T03:33:17')).to.equalTime(new Date(Date.UTC(2015, 9, 17, 3, 33, 17)));
17+
});
18+
19+
it('should convert dates with a UTC Zulu-time timezone', function () {
20+
expect(ApiClient.parseDate('2015-11-17T03:33:17Z')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 3, 33, 17)));
21+
});
22+
23+
it('should convert dates with a UTC zero-offset timezone', function () {
24+
expect(ApiClient.parseDate('2015-11-17T03:33:17+0000')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 3, 33, 17)));
25+
});
26+
27+
it('should convert dates with a positive offset timezone', function () {
28+
expect(ApiClient.parseDate('2015-11-17T03:33:17+0200')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 1, 33, 17)));
29+
});
30+
31+
it('should convert dates with a negative offset timezone', function () {
32+
expect(ApiClient.parseDate('2015-11-17T03:33:17-0200')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 5, 33, 17)));
33+
});
34+
35+
it('should convert dates with a part-hour offset', function () {
36+
expect(ApiClient.parseDate('2015-11-17T03:23:17-0930')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 12, 53, 17)));
37+
});
38+
39+
it('should convert dates with a timezone HH:MM separator', function () {
40+
expect(ApiClient.parseDate('2015-11-17T03:33:17+02:00')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 1, 33, 17)));
41+
});
42+
43+
it('should convert dates with a timezone with hours only', function () {
44+
expect(ApiClient.parseDate('2015-11-17T03:33:17+02')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 1, 33, 17)));
45+
});
46+
47+
});

0 commit comments

Comments
 (0)