Skip to content
This repository has been archived by the owner on Feb 8, 2024. It is now read-only.

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
magemello committed Dec 20, 2016
2 parents b052beb + f556c54 commit 65dfb1d
Show file tree
Hide file tree
Showing 12 changed files with 694 additions and 322 deletions.
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[src/alfresco-activiti-rest-api/**.js]
indent_size = 2

[src/alfresco-core-rest-api/**.js]
indent_size = 2

[package.json]
indent_style = space
indent_size = 2
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,19 @@ Alfresco JS API

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

<a name="1.0.0"></a>
# [1.0.0](https://github.com/Alfresco/alfresco-js-api/releases/tag/1.0.0) (xx-xx-2016)
## fix
- [/api/enterprise/script-files/controllers sending wrong accept header #130](https://github.com/Alfresco/alfresco-js-api/pull/130)
- [CSRF Token is not working #128](https://github.com/Alfresco/alfresco-js-api/pull/128)
- [Timestamp timezones are ignored #134](https://github.com/Alfresco/alfresco-js-api/issues/134)

<a name="0.5.5"></a>
# [0.5.5](https://github.com/Alfresco/alfresco-js-api/releases/tag/0.5.5) (09-12-2016)
## fix
- [Added bable plugin for IE10 #121](https://github.com/Alfresco/alfresco-js-api/pull/122)

## Features
- [Add the report api inside the js api #124](https://github.com/Alfresco/alfresco-js-api/issues/124)

<a name="0.5.3"></a>
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ This project provides a JavaScript client API into the Alfresco REST API and Act
* [Models Api](#models-api)
+ [Get Model](#get-model)
* [Report Api](#report-api)
+ [Create Default reports](#create-default-reports)
+ [Create default Reports](#create-default-reports)
+ [Get Reports](#get-reports)
+ [Report Params](#report-params)
+ [Report Process Definitions](#report-process-definitions)
+ [Tasks of process definition](#tasks-of-process-definition)
+ [Generate reports](#generate-reports)
+ [Update report details](#update-report-details)
* [Report Process Definitions](#report-process-definitions)
* [Tasks of process definition](#tasks-of-process-definition)
* [Generate reports](#generate-reports)
* [Update report details](#update-report-details)
- [Development](#development)
- [Release History](#release-history)

Expand Down
800 changes: 512 additions & 288 deletions dist/alfresco-js-api.js

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions dist/alfresco-js-api.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "alfresco-js-api",
"version": "0.5.5",
"version": "1.0.0",
"description": "JavaScript client library for the Alfresco REST API",
"author": "Alfresco Software, Ltd.",
"main": "dist/alfresco-js-api.js",
"module": "main.js",
"typings": "index.d.ts",
"scripts": {
"clean": "rimraf dist/bundle.js node_modules",
"build": "grunt && npm run tslint && npm run test && npm run bundle && npm run minify && npm run toc && npm run webpack-test",
"webpack-test": "webpack main.js webpack-bundle-test.js",
"webpack-test": "webpack main.js package/webpack-bundle-test.js",
"test": "grunt test",
"coverage": "grunt coverage",
"generate": "mvn clean generate-sources",
Expand Down Expand Up @@ -38,6 +39,7 @@
"babel-plugin-transform-proto-to-assign": "^6.9.0",
"browserify": "^13.0.1",
"chai": "^3.5.0",
"chai-datetime": "^1.4.1",
"expect.js": "~0.3.1",
"grunt": "~0.4.0",
"grunt-cli": "^1.1.0",
Expand Down
4 changes: 2 additions & 2 deletions src/alfresco-activiti-rest-api/src/api/ScriptFileApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
};

var authNames = [];
var contentTypes = ['application/json'];
var accepts = ['application/json', 'application/javascript'];
var contentTypes = ['text/javascript'];
var accepts = [];
var returnType = 'String';

return this.apiClient.callApi(
Expand Down
35 changes: 33 additions & 2 deletions src/alfresco-core-rest-api/src/ApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,43 @@
* @returns {Date} The parsed date object.
*/
exports.parseDate = function(str) {
var dateLength = 10;
var separatorPos = str.substring(dateLength).search(/[\+\-]/) + dateLength;
var dateStr = separatorPos > dateLength ? str.substring(0, separatorPos) : str;
var tzStr = separatorPos > dateLength ? str.substring(separatorPos) : '';
var parsedDate = exports.parseDateTime(dateStr);
var tzOffsetMins = exports.parseDateTimeZone(tzStr);
parsedDate.setTime(parsedDate.getTime() + tzOffsetMins * 60000);
return parsedDate;
};

/**
* Parses the date component of a ISO-8601 string representation of a date value.
* @param {String} str The date value as a string.
* @returns {Date} The parsed date object.
*/
exports.parseDateTime = function(str) {
// TODO: review when Safari 10 is released
// return new Date(str.replace(/T/i, ' '));

// Compatible with Safari 9.1.2
var a = str.split(/[^0-9]/).map(function(s) { return parseInt(s, 10) });
return new Date(a[0], a[1]-1 || 0, a[2] || 1, a[3] || 0, a[4] || 0, a[5] || 0, a[6] || 0);
var parts = str.split('+');
var dateParts = str.split(/[^0-9]/).map(function(s) { return parseInt(s, 10) });
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));
};

/**
* Parses the timezone component of a ISO-8601 string representation of a date value.
* @param {String} str The timezone offset as a string, e.g. '+0000', '+2000' or '-0500'.
* @returns {number} The number of minutes offset from UTC.
*/
exports.parseDateTimeZone = function(str) {
var match = /([\+\-])(\d{2}):?(\d{2})?/.exec(str);
if (match !== null) {
return (parseInt(match[1] + '1') * -1 * (parseInt(match[2]) * 60) + parseInt(match[3] || 0))
} else {
return 0;
}
};

/**
Expand Down
15 changes: 12 additions & 3 deletions src/alfrescoApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ class AlfrescoApiClient extends ApiClient {
if (this.isBpmRequest()) {
request._withCredentials = true;
if (this.authentications.cookie) {
request.set('Cookie', this.authentications.cookie);
if (this.isNodeEnv()) {
request.set('Cookie', this.authentications.cookie);
}
}
}

Expand Down Expand Up @@ -183,22 +185,29 @@ class AlfrescoApiClient extends ApiClient {
isCsrfEnabled() {
if (this.config) {
return !this.config.disableCsrf;
}else {
} else {
return true;
}
}

setCsrfToken(request) {
var token = this.token();
request.set('X-CSRF-TOKEN', token);
request.set('Cookie', 'CSRF-TOKEN=' + token + ';path=/');

if (this.isNodeEnv()) {
request.set('Cookie', 'CSRF-TOKEN=' + token + ';path=/');
}

try {
document.cookie = 'CSRF-TOKEN=' + token + ';path=/';
} catch (err) {
}
}

isNodeEnv() {
return (typeof process !== 'undefined') && (process.release && process.release.name === 'node');
}

token(a) {
return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) : ([1e16] + 1e16).replace(/[01]/g, this.token);
}
Expand Down
47 changes: 47 additions & 0 deletions test/alfrescoApiClient.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*global describe, it */

var ApiClient = require('../src/alfresco-core-rest-api/src/ApiClient');
var chai = require('chai');
var expect = chai.expect;

chai.use(require('chai-datetime'));

describe('Alfresco Core API Client', function () {

it('should convert dates falling in GMT without a timezone', function () {
expect(ApiClient.parseDate('2015-11-17T03:33:17')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 3, 33, 17)));
});

it('should convert dates falling in BST without a timezone', function () {
expect(ApiClient.parseDate('2015-10-17T03:33:17')).to.equalTime(new Date(Date.UTC(2015, 9, 17, 3, 33, 17)));
});

it('should convert dates with a UTC Zulu-time timezone', function () {
expect(ApiClient.parseDate('2015-11-17T03:33:17Z')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 3, 33, 17)));
});

it('should convert dates with a UTC zero-offset timezone', function () {
expect(ApiClient.parseDate('2015-11-17T03:33:17+0000')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 3, 33, 17)));
});

it('should convert dates with a positive offset timezone', function () {
expect(ApiClient.parseDate('2015-11-17T03:33:17+0200')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 1, 33, 17)));
});

it('should convert dates with a negative offset timezone', function () {
expect(ApiClient.parseDate('2015-11-17T03:33:17-0200')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 5, 33, 17)));
});

it('should convert dates with a part-hour offset', function () {
expect(ApiClient.parseDate('2015-11-17T03:23:17-0930')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 12, 53, 17)));
});

it('should convert dates with a timezone HH:MM separator', function () {
expect(ApiClient.parseDate('2015-11-17T03:33:17+02:00')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 1, 33, 17)));
});

it('should convert dates with a timezone with hours only', function () {
expect(ApiClient.parseDate('2015-11-17T03:33:17+02')).to.equalTime(new Date(Date.UTC(2015, 10, 17, 1, 33, 17)));
});

});
30 changes: 30 additions & 0 deletions test/mockObjects/alfresco/nodeMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,36 @@ class NodeMock extends BaseMock {
});
}

get200ResponseChildrenNonUTCTimes() {
nock(this.host, {'encodedQueryParams': true})
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1320/children')
.reply(200, {
'list': {
'pagination': {
'count': 5,
'hasMoreItems': false,
'totalItems': 5,
'skipCount': 0,
'maxItems': 100
},
'entries': [{
'entry': {
'createdAt': '2011-03-15T12:04:54.290-0500',
'isFolder': true,
'isFile': false,
'createdByUser': {'id': 'mjackson', 'displayName': 'Mike Jackson'},
'modifiedAt': '2011-03-15T12:04:54.290-0500',
'modifiedByUser': {'id': 'mjackson', 'displayName': 'Mike Jackson'},
'name': 'discussions',
'id': '059c5bc7-2d38-4dc5-96b8-d09cd3c69b4c',
'nodeType': 'cm:folder',
'parentId': 'b4cff62a-664d-4d45-9302-98723eac1320'
}
}]
}
});
}

get404ChildrenNotExist() {
nock(this.host, {'encodedQueryParams': true})
.get('/alfresco/api/-default-/public/alfresco/versions/1/nodes/b4cff62a-664d-4d45-9302-98723eac1319/children')
Expand Down
16 changes: 15 additions & 1 deletion test/nodeApi.spec.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*global describe, it, beforeEach */

var AlfrescoApi = require('../main');
var expect = require('chai').expect;
var chai = require('chai');
var expect = chai.expect;
var AuthResponseMock = require('../test/mockObjects/mockAlfrescoApi').Auth;
var NodeMock = require('../test/mockObjects/mockAlfrescoApi').Node;
var fs = require('fs');

chai.use(require('chai-datetime'));

describe('Node', function () {
beforeEach(function (done) {
this.hostEcm = 'http://127.0.0.1:8080';
Expand Down Expand Up @@ -111,6 +114,17 @@ describe('Node', function () {
done();
});
});

it('should return dates as timezone-aware', function (done) {
this.nodeMock.get200ResponseChildrenNonUTCTimes();

this.alfrescoJsApi.nodes.getNodeChildren('b4cff62a-664d-4d45-9302-98723eac1320').then(function (data) {
expect(data.list.entries.length).to.be.equal(1);
expect(data.list.entries[0].entry.createdAt).to.equalTime(new Date(Date.UTC(2011, 2, 15, 17, 4, 54, 290)));
done();
});

});
});

describe('Delete', function () {
Expand Down

0 comments on commit 65dfb1d

Please sign in to comment.