backlog-js 0.12.1 → 0.12.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Issue = exports.Project = exports.User = exports.ActivityType = void 0;
4
- var ActivityType;
5
- (function (ActivityType) {
6
- ActivityType[ActivityType["Undefined"] = -1] = "Undefined";
7
- ActivityType[ActivityType["IssueCreated"] = 1] = "IssueCreated";
8
- ActivityType[ActivityType["IssueUpdated"] = 2] = "IssueUpdated";
9
- ActivityType[ActivityType["IssueCommented"] = 3] = "IssueCommented";
10
- ActivityType[ActivityType["IssueDeleted"] = 4] = "IssueDeleted";
11
- ActivityType[ActivityType["WikiCreated"] = 5] = "WikiCreated";
12
- ActivityType[ActivityType["WikiUpdated"] = 6] = "WikiUpdated";
13
- ActivityType[ActivityType["WikiDeleted"] = 7] = "WikiDeleted";
14
- ActivityType[ActivityType["FileAdded"] = 8] = "FileAdded";
15
- ActivityType[ActivityType["FileUpdated"] = 9] = "FileUpdated";
16
- ActivityType[ActivityType["FileDeleted"] = 10] = "FileDeleted";
17
- ActivityType[ActivityType["SvnCommitted"] = 11] = "SvnCommitted";
18
- ActivityType[ActivityType["GitPushed"] = 12] = "GitPushed";
19
- ActivityType[ActivityType["GitRepositoryCreated"] = 13] = "GitRepositoryCreated";
20
- ActivityType[ActivityType["IssueMultiUpdated"] = 14] = "IssueMultiUpdated";
21
- ActivityType[ActivityType["ProjectUserAdded"] = 15] = "ProjectUserAdded";
22
- ActivityType[ActivityType["ProjectUserRemoved"] = 16] = "ProjectUserRemoved";
23
- ActivityType[ActivityType["NotifyAdded"] = 17] = "NotifyAdded";
24
- ActivityType[ActivityType["PullRequestAdded"] = 18] = "PullRequestAdded";
25
- ActivityType[ActivityType["PullRequestUpdated"] = 19] = "PullRequestUpdated";
26
- ActivityType[ActivityType["PullRequestCommented"] = 20] = "PullRequestCommented";
27
- ActivityType[ActivityType["PullRequestMerged"] = 21] = "PullRequestMerged";
28
- })(ActivityType = exports.ActivityType || (exports.ActivityType = {}));
29
- var User;
30
- (function (User) {
31
- var RoleType;
32
- (function (RoleType) {
33
- RoleType[RoleType["Admin"] = 1] = "Admin";
34
- RoleType[RoleType["User"] = 2] = "User";
35
- RoleType[RoleType["Reporter"] = 3] = "Reporter";
36
- RoleType[RoleType["Viewer"] = 4] = "Viewer";
37
- RoleType[RoleType["GuestReporter"] = 5] = "GuestReporter";
38
- RoleType[RoleType["GuestViewer"] = 6] = "GuestViewer";
39
- })(RoleType = User.RoleType || (User.RoleType = {}));
40
- })(User = exports.User || (exports.User = {}));
41
- var Project;
42
- (function (Project) {
43
- var FieldType;
44
- (function (FieldType) {
45
- FieldType[FieldType["Text"] = 1] = "Text";
46
- FieldType[FieldType["TextArea"] = 2] = "TextArea";
47
- FieldType[FieldType["Numeric"] = 3] = "Numeric";
48
- FieldType[FieldType["Date"] = 4] = "Date";
49
- FieldType[FieldType["SingleList"] = 5] = "SingleList";
50
- FieldType[FieldType["MultipleList"] = 6] = "MultipleList";
51
- FieldType[FieldType["CheckBox"] = 7] = "CheckBox";
52
- FieldType[FieldType["Radio"] = 8] = "Radio";
53
- })(FieldType = Project.FieldType || (Project.FieldType = {}));
54
- })(Project = exports.Project || (exports.Project = {}));
55
- var Issue;
56
- (function (Issue) {
57
- var ParentChildType;
58
- (function (ParentChildType) {
59
- ParentChildType[ParentChildType["All"] = 0] = "All";
60
- ParentChildType[ParentChildType["NotChild"] = 1] = "NotChild";
61
- ParentChildType[ParentChildType["Child"] = 2] = "Child";
62
- ParentChildType[ParentChildType["NotChildNotParent"] = 3] = "NotChildNotParent";
63
- ParentChildType[ParentChildType["Parent"] = 4] = "Parent";
64
- })(ParentChildType = Issue.ParentChildType || (Issue.ParentChildType = {}));
65
- })(Issue = exports.Issue || (exports.Issue = {}));
@@ -1,93 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var Error = require("./error");
4
- var qs = require("qs");
5
- var Request = (function () {
6
- function Request(configure) {
7
- this.configure = configure;
8
- }
9
- Request.prototype.get = function (path, params) {
10
- return this.request({ method: 'GET', path: path, params: params }).then(this.parseJSON);
11
- };
12
- Request.prototype.post = function (path, params) {
13
- return this.request({ method: 'POST', path: path, params: params }).then(this.parseJSON);
14
- };
15
- Request.prototype.put = function (path, params) {
16
- return this.request({ method: 'PUT', path: path, params: params }).then(this.parseJSON);
17
- };
18
- Request.prototype.patch = function (path, params) {
19
- return this.request({ method: 'PATCH', path: path, params: params }).then(this.parseJSON);
20
- };
21
- Request.prototype.delete = function (path, params) {
22
- return this.request({ method: 'DELETE', path: path, params: params }).then(this.parseJSON);
23
- };
24
- Request.prototype.request = function (options) {
25
- var method = options.method, path = options.path, _a = options.params, params = _a === void 0 ? {} : _a;
26
- var _b = this.configure, apiKey = _b.apiKey, accessToken = _b.accessToken, timeout = _b.timeout;
27
- var query = apiKey ? { apiKey: apiKey } : {};
28
- var init = { method: method, headers: {} };
29
- if (timeout) {
30
- init['timeout'] = timeout;
31
- }
32
- if (!apiKey && accessToken) {
33
- init.headers['Authorization'] = 'Bearer ' + accessToken;
34
- }
35
- if (typeof window !== 'undefined') {
36
- init.mode = 'cors';
37
- }
38
- if (method !== 'GET') {
39
- if (params instanceof FormData) {
40
- init.body = params;
41
- }
42
- else {
43
- init.headers['Content-type'] = 'application/x-www-form-urlencoded';
44
- init.body = this.toQueryString(params);
45
- }
46
- }
47
- else {
48
- Object.keys(params).forEach(function (key) { return query[key] = params[key]; });
49
- }
50
- var queryStr = this.toQueryString(query);
51
- var url = this.restBaseURL + "/" + path + (queryStr.length > 0 ? "?" + queryStr : '');
52
- return fetch(url, init).then(this.checkStatus);
53
- };
54
- Request.prototype.checkStatus = function (response) {
55
- return new Promise(function (resolve, reject) {
56
- if (200 <= response.status && response.status < 300) {
57
- resolve(response);
58
- }
59
- else {
60
- response.json().then(function (data) {
61
- if (response.status === 401) {
62
- reject(new Error.BacklogAuthError(response, data));
63
- }
64
- else {
65
- reject(new Error.BacklogApiError(response, data));
66
- }
67
- }).catch(function (err) { return reject(new Error.UnexpectedError(response)); });
68
- }
69
- });
70
- };
71
- Request.prototype.parseJSON = function (response) {
72
- return response.json();
73
- };
74
- Request.prototype.toQueryString = function (params) {
75
- return qs.stringify(params, { arrayFormat: 'brackets' });
76
- };
77
- Object.defineProperty(Request.prototype, "webAppBaseURL", {
78
- get: function () {
79
- return "https://" + this.configure.host;
80
- },
81
- enumerable: false,
82
- configurable: true
83
- });
84
- Object.defineProperty(Request.prototype, "restBaseURL", {
85
- get: function () {
86
- return this.webAppBaseURL + "/api/v2";
87
- },
88
- enumerable: false,
89
- configurable: true
90
- });
91
- return Request;
92
- }());
93
- exports.default = Request;
@@ -1,3 +0,0 @@
1
- export * from './oauth2';
2
- export * from './space';
3
- export * from './project';
@@ -1,15 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
- };
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./oauth2"), exports);
14
- __exportStar(require("./space"), exports);
15
- __exportStar(require("./project"), exports);
@@ -1,6 +0,0 @@
1
- export declare const access_token: {
2
- access_token: string;
3
- token_type: string;
4
- expires_in: number;
5
- refresh_token: string;
6
- };
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.access_token = void 0;
4
- exports.access_token = {
5
- access_token: 'YOUR_ACCESS_TOKEN',
6
- token_type: 'Bearer',
7
- expires_in: 3600,
8
- refresh_token: 'YOUR_REFRESH_TOKEN'
9
- };
@@ -1,10 +0,0 @@
1
- export declare const projects: {
2
- id: number;
3
- projectKey: string;
4
- name: string;
5
- chartEnabled: boolean;
6
- subtaskingEnabled: boolean;
7
- projectLeaderCanEditProjectLeader: boolean;
8
- textFormattingRule: string;
9
- archived: boolean;
10
- }[];
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.projects = void 0;
4
- exports.projects = [
5
- {
6
- id: 1,
7
- projectKey: "TEST",
8
- name: "test",
9
- chartEnabled: false,
10
- subtaskingEnabled: false,
11
- projectLeaderCanEditProjectLeader: false,
12
- textFormattingRule: "markdown",
13
- archived: false
14
- }
15
- ];
@@ -1,11 +0,0 @@
1
- export declare const space: {
2
- spaceKey: string;
3
- name: string;
4
- ownerId: number;
5
- lang: string;
6
- timezone: string;
7
- reportSendTime: string;
8
- textFormattingRule: string;
9
- created: string;
10
- updated: string;
11
- };
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.space = void 0;
4
- exports.space = {
5
- spaceKey: 'nulab',
6
- name: 'nulab',
7
- ownerId: 99999,
8
- lang: 'ja',
9
- timezone: 'Asia/Tokyo',
10
- reportSendTime: '18:00:00',
11
- textFormattingRule: 'backlog',
12
- created: '2016-05-01T05:45:52Z',
13
- updated: '2016-08-16T02:27:40Z'
14
- };
@@ -1,2 +0,0 @@
1
- import 'isomorphic-form-data';
2
- import 'isomorphic-fetch';
package/dist/test/test.js DELETED
@@ -1,183 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var assert = require("power-assert");
4
- var nock = require("nock");
5
- var dotenv = require("dotenv");
6
- var backlogjs = require("../src/index");
7
- var Fixtures = require("./fixtures/index");
8
- require("isomorphic-form-data");
9
- require("isomorphic-fetch");
10
- require('es6-promise').polyfill();
11
- dotenv.config();
12
- var host = process.env.BACKLOG_HOST || 'example.backlog.jp';
13
- var apiKey = process.env.BACKLOG_API_KEY || 'apiKey';
14
- var clientId = process.env.BACKLOG_CLIENT_ID || 'clientId';
15
- var clientSecret = process.env.BACKLOG_CLIENT_SECRET || 'clientSecret';
16
- var redirectUri = process.env.BACKLOG_REDIRECT_URI || 'redirectUri';
17
- var state = process.env.BACKLOG_STATE || 'state';
18
- var code = process.env.BACKLOG_CODE || 'code';
19
- var refreshToken = process.env.BACKLOG_REFRESH_TOKEN || 'refreshToken';
20
- var accessToken = process.env.BACKLOG_ACCESS_TOKEN || 'accessToken';
21
- var configure = { host: host, apiKey: apiKey };
22
- var credentials = { clientId: clientId, clientSecret: clientSecret };
23
- describe("OAuth2 API", function () {
24
- var oauth2;
25
- beforeEach(function () {
26
- oauth2 = new backlogjs.OAuth2(credentials);
27
- });
28
- afterEach(function () {
29
- oauth2 = null;
30
- nock.cleanAll();
31
- });
32
- it('should get web app base url.', function (done) {
33
- var expected = "https://" + host + "/OAuth2AccessRequest.action?client_id=" + clientId + "&response_type=code&redirect_uri=" + redirectUri + "&state=" + state;
34
- assert(expected === oauth2.getAuthorizationURL({ host: host, redirectUri: redirectUri, state: state }));
35
- done();
36
- });
37
- it('should get access token.', function (done) {
38
- nock("https://" + host)
39
- .post("/api/v2/oauth2/token", function (body) {
40
- return JSON.stringify(body) === JSON.stringify({
41
- grant_type: 'authorization_code',
42
- code: code,
43
- client_id: clientId,
44
- client_secret: clientSecret,
45
- redirect_uri: redirectUri
46
- });
47
- })
48
- .once()
49
- .reply(200, Fixtures.access_token);
50
- oauth2.getAccessToken({
51
- host: host, code: code, redirectUri: redirectUri
52
- }).then(function (data) {
53
- assert.deepEqual(data, Fixtures.access_token);
54
- done();
55
- }).catch(function (err) {
56
- throw err;
57
- });
58
- });
59
- it('should refresh access token.', function (done) {
60
- nock("https://" + host)
61
- .post("/api/v2/oauth2/token", function (body) {
62
- return JSON.stringify(body) === JSON.stringify({
63
- grant_type: 'refresh_token',
64
- client_id: clientId,
65
- client_secret: clientSecret,
66
- refresh_token: refreshToken
67
- });
68
- })
69
- .once()
70
- .reply(200, Fixtures.access_token);
71
- oauth2.refreshAccessToken({
72
- host: host, refreshToken: refreshToken
73
- }).then(function (data) {
74
- assert.deepEqual(data, Fixtures.access_token);
75
- done();
76
- }).catch(function (err) {
77
- throw err;
78
- });
79
- });
80
- });
81
- describe("Backlog API", function () {
82
- var backlog;
83
- beforeEach(function () {
84
- backlog = new backlogjs.Backlog(configure);
85
- });
86
- afterEach(function () {
87
- backlog = null;
88
- nock.cleanAll();
89
- });
90
- it('should get web app base url.', function (done) {
91
- assert("https://" + configure.host === backlog.webAppBaseURL);
92
- done();
93
- });
94
- it('should get rest base url.', function (done) {
95
- assert("https://" + configure.host + "/api/v2" === backlog.restBaseURL);
96
- done();
97
- });
98
- it('should convert object to query string.', function (done) {
99
- var query = backlog.toQueryString({
100
- userId: 'test01',
101
- password: 'pazzword',
102
- name: 'testuser',
103
- mailAddress: 'testuser@example.com',
104
- roleType: backlogjs.Option.User.RoleType.Admin
105
- });
106
- assert('userId=test01&password=pazzword&name=testuser&mailAddress=testuser%40example.com&roleType=1' === query);
107
- done();
108
- });
109
- it('should convert object(array) to query string.', function (done) {
110
- var query = backlog.toQueryString({
111
- activityTypeId: [
112
- backlogjs.Option.ActivityType.IssueCreated,
113
- backlogjs.Option.ActivityType.IssueUpdated,
114
- backlogjs.Option.ActivityType.IssueCommented
115
- ],
116
- minId: 1,
117
- maxId: 2,
118
- count: 3,
119
- order: 'asc'
120
- });
121
- assert('activityTypeId%5B%5D=1&activityTypeId%5B%5D=2&activityTypeId%5B%5D=3&minId=1&maxId=2&count=3&order=asc' === query);
122
- done();
123
- });
124
- it('should get space.', function (done) {
125
- nock("https://" + host)
126
- .get("/api/v2/space")
127
- .query({ apiKey: apiKey })
128
- .once()
129
- .reply(200, Fixtures.space);
130
- backlog.getSpace().then(function (data) {
131
- assert.deepEqual(data, Fixtures.space);
132
- done();
133
- }).catch(function (err) {
134
- throw err;
135
- });
136
- });
137
- it('should get projects.', function (done) {
138
- nock("https://" + host)
139
- .get("/api/v2/projects")
140
- .query({ apiKey: apiKey })
141
- .once()
142
- .reply(200, Fixtures.projects);
143
- backlog.getProjects().then(function (data) {
144
- assert.deepEqual(data, Fixtures.projects);
145
- done();
146
- }).catch(function (err) {
147
- throw err;
148
- });
149
- });
150
- it('should get space activities.', function (done) {
151
- var query = {
152
- activityTypeId: [
153
- backlogjs.Option.ActivityType.IssueCreated,
154
- backlogjs.Option.ActivityType.IssueUpdated,
155
- backlogjs.Option.ActivityType.IssueCommented
156
- ],
157
- minId: 1,
158
- maxId: 10,
159
- count: 5,
160
- order: "desc"
161
- };
162
- query['apiKey'] = apiKey;
163
- nock("https://" + host)
164
- .get("/api/v2/space/activities")
165
- .query(function (queryObj) {
166
- return queryObj["activityTypeId[]"].length === 3
167
- && queryObj["activityTypeId[]"][0] === "1"
168
- && queryObj["activityTypeId[]"][1] === "2"
169
- && queryObj["activityTypeId[]"][2] === "3"
170
- && queryObj.minId === "1"
171
- && queryObj.maxId === "10"
172
- && queryObj.count === "5"
173
- && queryObj.order === "desc";
174
- })
175
- .once()
176
- .reply(200, []);
177
- backlog.getSpaceActivities(query).then(function (data) {
178
- done();
179
- }).catch(function (err) {
180
- throw err;
181
- });
182
- });
183
- });