pyrus-api 2.0.0 → 2.2.0
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.
- package/build/cjs/index.cjs +35 -8
- package/build/esm/index.js +34 -9
- package/build/types/index.d.ts +4 -0
- package/package.json +48 -48
package/build/cjs/index.cjs
CHANGED
|
@@ -122,7 +122,13 @@ function packDates(key, value) {
|
|
|
122
122
|
}
|
|
123
123
|
return value;
|
|
124
124
|
}
|
|
125
|
-
function
|
|
125
|
+
function toJson(obj) {
|
|
126
|
+
return JSON.stringify(obj, packDates);
|
|
127
|
+
}
|
|
128
|
+
function fromJson(str) {
|
|
129
|
+
return JSON.parse(str, extractDates);
|
|
130
|
+
}
|
|
131
|
+
function trimTrailingSlash(url) {
|
|
126
132
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
127
133
|
}
|
|
128
134
|
function toDateTimeString(date) {
|
|
@@ -455,8 +461,8 @@ class BaseApi {
|
|
|
455
461
|
const { access_token, api_url, files_url } = yield this._authRequest;
|
|
456
462
|
this._token = access_token;
|
|
457
463
|
if (api_url && files_url) {
|
|
458
|
-
this._settings.apiUrl =
|
|
459
|
-
this._settings.filesUrl =
|
|
464
|
+
this._settings.apiUrl = trimTrailingSlash(api_url);
|
|
465
|
+
this._settings.filesUrl = trimTrailingSlash(files_url);
|
|
460
466
|
}
|
|
461
467
|
else {
|
|
462
468
|
this._settings.apiUrl =
|
|
@@ -485,7 +491,7 @@ class BaseApi {
|
|
|
485
491
|
if (resp.ok) {
|
|
486
492
|
const contentType = resp.headers.get("Content-Type");
|
|
487
493
|
if (contentType && contentType.includes("application/json")) {
|
|
488
|
-
return
|
|
494
|
+
return fromJson(yield resp.text());
|
|
489
495
|
}
|
|
490
496
|
return yield resp.blob();
|
|
491
497
|
}
|
|
@@ -664,6 +670,12 @@ class ListsApi extends BaseApi {
|
|
|
664
670
|
return yield this.fetchApi(yield this.getModulePath(), "PUT", JSON.stringify(request));
|
|
665
671
|
});
|
|
666
672
|
}
|
|
673
|
+
get(request) {
|
|
674
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
675
|
+
return yield this.fetchApi((yield this.getModulePath()) +
|
|
676
|
+
`/${request.id}`, "GET");
|
|
677
|
+
});
|
|
678
|
+
}
|
|
667
679
|
delete(request) {
|
|
668
680
|
return __awaiter(this, void 0, void 0, function* () {
|
|
669
681
|
return yield this.fetchApi((yield this.getModulePath()) + `/${request.id}`, "DELETE", JSON.stringify(request));
|
|
@@ -789,12 +801,12 @@ class TasksApi extends BaseApi {
|
|
|
789
801
|
}
|
|
790
802
|
create(request) {
|
|
791
803
|
return __awaiter(this, void 0, void 0, function* () {
|
|
792
|
-
return yield this.fetchApi(yield this.getModulePath(), "POST",
|
|
804
|
+
return yield this.fetchApi(yield this.getModulePath(), "POST", toJson(request));
|
|
793
805
|
});
|
|
794
806
|
}
|
|
795
807
|
addComment(id, request) {
|
|
796
808
|
return __awaiter(this, void 0, void 0, function* () {
|
|
797
|
-
return yield this.fetchApi((yield this.getModulePath()) + `/${id}` + Endpoints.TasksComments, "POST",
|
|
809
|
+
return yield this.fetchApi((yield this.getModulePath()) + `/${id}` + Endpoints.TasksComments, "POST", toJson(request));
|
|
798
810
|
});
|
|
799
811
|
}
|
|
800
812
|
}
|
|
@@ -819,7 +831,7 @@ class FormsApi extends BaseApi {
|
|
|
819
831
|
const processedRequest = Object.assign(Object.assign({}, request), processFilters(request && request.filters));
|
|
820
832
|
if (processedRequest.filters)
|
|
821
833
|
delete processedRequest.filters;
|
|
822
|
-
return yield this.fetchApi((yield this.getModulePath()) + `/${id}` + Endpoints.FormsRegister, "POST",
|
|
834
|
+
return yield this.fetchApi((yield this.getModulePath()) + `/${id}` + Endpoints.FormsRegister, "POST", toJson(processedRequest));
|
|
823
835
|
});
|
|
824
836
|
}
|
|
825
837
|
getPermissions(_a) {
|
|
@@ -926,7 +938,8 @@ class BotApi extends BaseApi {
|
|
|
926
938
|
class PyrusApiClient extends BaseApi {
|
|
927
939
|
constructor(auth, settings) {
|
|
928
940
|
const currentSettings = !!settings
|
|
929
|
-
?
|
|
941
|
+
? PyrusApiClient.extendDefaults(settings)
|
|
942
|
+
: defaults;
|
|
930
943
|
super({ settings: currentSettings });
|
|
931
944
|
if (typeof auth === "string")
|
|
932
945
|
this._token = auth;
|
|
@@ -940,6 +953,18 @@ class PyrusApiClient extends BaseApi {
|
|
|
940
953
|
});
|
|
941
954
|
});
|
|
942
955
|
}
|
|
956
|
+
static extendDefaults(settings) {
|
|
957
|
+
const extendedSettings = Object.assign(Object.assign({}, defaults), settings);
|
|
958
|
+
const needTrimKeys = [
|
|
959
|
+
"apiUrl",
|
|
960
|
+
"authUrl",
|
|
961
|
+
"filesUrl",
|
|
962
|
+
];
|
|
963
|
+
for (const key of needTrimKeys) {
|
|
964
|
+
extendedSettings[key] = trimTrailingSlash(extendedSettings[key]);
|
|
965
|
+
}
|
|
966
|
+
return extendedSettings;
|
|
967
|
+
}
|
|
943
968
|
get initParams() {
|
|
944
969
|
return {
|
|
945
970
|
authRequest: this._authRequest,
|
|
@@ -1034,6 +1059,8 @@ exports.PyrusApiClient = PyrusApiClient;
|
|
|
1034
1059
|
exports.SendSmsError = SendSmsError;
|
|
1035
1060
|
exports.SendSmsStatus = SendSmsStatus;
|
|
1036
1061
|
exports.SourceType = SourceType;
|
|
1062
|
+
exports.fromJson = fromJson;
|
|
1037
1063
|
exports.toDateString = toDateString;
|
|
1038
1064
|
exports.toDateTimeString = toDateTimeString;
|
|
1065
|
+
exports.toJson = toJson;
|
|
1039
1066
|
exports.toTimeString = toTimeString;
|
package/build/esm/index.js
CHANGED
|
@@ -120,7 +120,13 @@ function packDates(key, value) {
|
|
|
120
120
|
}
|
|
121
121
|
return value;
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function toJson(obj) {
|
|
124
|
+
return JSON.stringify(obj, packDates);
|
|
125
|
+
}
|
|
126
|
+
function fromJson(str) {
|
|
127
|
+
return JSON.parse(str, extractDates);
|
|
128
|
+
}
|
|
129
|
+
function trimTrailingSlash(url) {
|
|
124
130
|
return url.endsWith("/") ? url.slice(0, -1) : url;
|
|
125
131
|
}
|
|
126
132
|
function toDateTimeString(date) {
|
|
@@ -453,8 +459,8 @@ class BaseApi {
|
|
|
453
459
|
const { access_token, api_url, files_url } = yield this._authRequest;
|
|
454
460
|
this._token = access_token;
|
|
455
461
|
if (api_url && files_url) {
|
|
456
|
-
this._settings.apiUrl =
|
|
457
|
-
this._settings.filesUrl =
|
|
462
|
+
this._settings.apiUrl = trimTrailingSlash(api_url);
|
|
463
|
+
this._settings.filesUrl = trimTrailingSlash(files_url);
|
|
458
464
|
}
|
|
459
465
|
else {
|
|
460
466
|
this._settings.apiUrl =
|
|
@@ -483,7 +489,7 @@ class BaseApi {
|
|
|
483
489
|
if (resp.ok) {
|
|
484
490
|
const contentType = resp.headers.get("Content-Type");
|
|
485
491
|
if (contentType && contentType.includes("application/json")) {
|
|
486
|
-
return
|
|
492
|
+
return fromJson(yield resp.text());
|
|
487
493
|
}
|
|
488
494
|
return yield resp.blob();
|
|
489
495
|
}
|
|
@@ -662,6 +668,12 @@ class ListsApi extends BaseApi {
|
|
|
662
668
|
return yield this.fetchApi(yield this.getModulePath(), "PUT", JSON.stringify(request));
|
|
663
669
|
});
|
|
664
670
|
}
|
|
671
|
+
get(request) {
|
|
672
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
673
|
+
return yield this.fetchApi((yield this.getModulePath()) +
|
|
674
|
+
`/${request.id}`, "GET");
|
|
675
|
+
});
|
|
676
|
+
}
|
|
665
677
|
delete(request) {
|
|
666
678
|
return __awaiter(this, void 0, void 0, function* () {
|
|
667
679
|
return yield this.fetchApi((yield this.getModulePath()) + `/${request.id}`, "DELETE", JSON.stringify(request));
|
|
@@ -787,12 +799,12 @@ class TasksApi extends BaseApi {
|
|
|
787
799
|
}
|
|
788
800
|
create(request) {
|
|
789
801
|
return __awaiter(this, void 0, void 0, function* () {
|
|
790
|
-
return yield this.fetchApi(yield this.getModulePath(), "POST",
|
|
802
|
+
return yield this.fetchApi(yield this.getModulePath(), "POST", toJson(request));
|
|
791
803
|
});
|
|
792
804
|
}
|
|
793
805
|
addComment(id, request) {
|
|
794
806
|
return __awaiter(this, void 0, void 0, function* () {
|
|
795
|
-
return yield this.fetchApi((yield this.getModulePath()) + `/${id}` + Endpoints.TasksComments, "POST",
|
|
807
|
+
return yield this.fetchApi((yield this.getModulePath()) + `/${id}` + Endpoints.TasksComments, "POST", toJson(request));
|
|
796
808
|
});
|
|
797
809
|
}
|
|
798
810
|
}
|
|
@@ -817,7 +829,7 @@ class FormsApi extends BaseApi {
|
|
|
817
829
|
const processedRequest = Object.assign(Object.assign({}, request), processFilters(request && request.filters));
|
|
818
830
|
if (processedRequest.filters)
|
|
819
831
|
delete processedRequest.filters;
|
|
820
|
-
return yield this.fetchApi((yield this.getModulePath()) + `/${id}` + Endpoints.FormsRegister, "POST",
|
|
832
|
+
return yield this.fetchApi((yield this.getModulePath()) + `/${id}` + Endpoints.FormsRegister, "POST", toJson(processedRequest));
|
|
821
833
|
});
|
|
822
834
|
}
|
|
823
835
|
getPermissions(_a) {
|
|
@@ -924,7 +936,8 @@ class BotApi extends BaseApi {
|
|
|
924
936
|
class PyrusApiClient extends BaseApi {
|
|
925
937
|
constructor(auth, settings) {
|
|
926
938
|
const currentSettings = !!settings
|
|
927
|
-
?
|
|
939
|
+
? PyrusApiClient.extendDefaults(settings)
|
|
940
|
+
: defaults;
|
|
928
941
|
super({ settings: currentSettings });
|
|
929
942
|
if (typeof auth === "string")
|
|
930
943
|
this._token = auth;
|
|
@@ -938,6 +951,18 @@ class PyrusApiClient extends BaseApi {
|
|
|
938
951
|
});
|
|
939
952
|
});
|
|
940
953
|
}
|
|
954
|
+
static extendDefaults(settings) {
|
|
955
|
+
const extendedSettings = Object.assign(Object.assign({}, defaults), settings);
|
|
956
|
+
const needTrimKeys = [
|
|
957
|
+
"apiUrl",
|
|
958
|
+
"authUrl",
|
|
959
|
+
"filesUrl",
|
|
960
|
+
];
|
|
961
|
+
for (const key of needTrimKeys) {
|
|
962
|
+
extendedSettings[key] = trimTrailingSlash(extendedSettings[key]);
|
|
963
|
+
}
|
|
964
|
+
return extendedSettings;
|
|
965
|
+
}
|
|
941
966
|
get initParams() {
|
|
942
967
|
return {
|
|
943
968
|
authRequest: this._authRequest,
|
|
@@ -1017,4 +1042,4 @@ class PyrusApiClient extends BaseApi {
|
|
|
1017
1042
|
}
|
|
1018
1043
|
}
|
|
1019
1044
|
|
|
1020
|
-
export { ActivityAction, ApiError, ApprovalChoice, CallEventType, ErrorCodeType, FilterMask, Flag, FormFieldType, ListType, OperatorId, PermissionLevel, PersonRights, PersonType, PyrusApiClient, SendSmsError, SendSmsStatus, SourceType, toDateString, toDateTimeString, toTimeString };
|
|
1045
|
+
export { ActivityAction, ApiError, ApprovalChoice, CallEventType, ErrorCodeType, FilterMask, Flag, FormFieldType, ListType, OperatorId, PermissionLevel, PersonRights, PersonType, PyrusApiClient, SendSmsError, SendSmsStatus, SourceType, fromJson, toDateString, toDateTimeString, toJson, toTimeString };
|
package/build/types/index.d.ts
CHANGED
|
@@ -13,6 +13,8 @@ declare module "pyrus-api" {
|
|
|
13
13
|
operator_id: OperatorId;
|
|
14
14
|
values: string[];
|
|
15
15
|
};
|
|
16
|
+
export function toJson(obj: any): string;
|
|
17
|
+
export function fromJson<T = any>(str: string): T;
|
|
16
18
|
export function toDateTimeString(date: Date | string): string;
|
|
17
19
|
export function toDateString(date: Date | string): string;
|
|
18
20
|
export function toTimeString(date: Date | string): string;
|
|
@@ -951,6 +953,7 @@ declare module "pyrus-api" {
|
|
|
951
953
|
getTasksInList(listId: number, request?: TaskListRequest): Promise<TaskListResponse>;
|
|
952
954
|
getInbox(request?: InboxRequest): Promise<TaskListResponse>;
|
|
953
955
|
create(request: CreateListRequest): Promise<PlainTaskList>;
|
|
956
|
+
get(request: ById): Promise<TaskList>;
|
|
954
957
|
delete(request: ById): Promise<void>;
|
|
955
958
|
update(request: UpdateListRequest): Promise<PlainTaskList>;
|
|
956
959
|
}
|
|
@@ -1404,6 +1407,7 @@ declare module "pyrus-api" {
|
|
|
1404
1407
|
*/
|
|
1405
1408
|
constructor(auth: AuthRequest | string, settings?: Settings);
|
|
1406
1409
|
private _authenticateClient;
|
|
1410
|
+
private static extendDefaults;
|
|
1407
1411
|
private get initParams();
|
|
1408
1412
|
get role(): RoleApi;
|
|
1409
1413
|
get profile(): ProfileApi;
|
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "pyrus-api",
|
|
3
|
-
"version": "2.
|
|
4
|
-
"description": "Pyrus API client for TypeScript",
|
|
5
|
-
"repository": {
|
|
6
|
-
"type": "git",
|
|
7
|
-
"url": "https://github.com/simplygoodsoftware/pyrusapi-typescript.git"
|
|
8
|
-
},
|
|
9
|
-
"type": "module",
|
|
10
|
-
"main": "./build/cjs/index.js",
|
|
11
|
-
"module": "./build/esm/index.js",
|
|
12
|
-
"types": "./build/types/index.d.ts",
|
|
13
|
-
"exports": {
|
|
14
|
-
"require": {
|
|
15
|
-
"default": "./build/cjs/index.cjs"
|
|
16
|
-
},
|
|
17
|
-
"import": {
|
|
18
|
-
"default": "./build/esm/index.js"
|
|
19
|
-
},
|
|
20
|
-
"types": {
|
|
21
|
-
"default": "./build/types/index.d.ts"
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
"scripts": {
|
|
25
|
-
"build": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript && dts-bundle-generator --project tsconfig.types.json --no-banner -o ./build/types/index.d.ts index.ts && node ./module-wrapper.js",
|
|
26
|
-
"prepare": "husky"
|
|
27
|
-
},
|
|
28
|
-
"author": {
|
|
29
|
-
"name": "Pyrus",
|
|
30
|
-
"email": "contact@pyrus.com"
|
|
31
|
-
},
|
|
32
|
-
"license": "MIT",
|
|
33
|
-
"devDependencies": {
|
|
34
|
-
"@rollup/plugin-typescript": "^11.1.6",
|
|
35
|
-
"@types/node": "^22.5.4",
|
|
36
|
-
"@types/rollup": "^0.54.0",
|
|
37
|
-
"dts-bundle-generator": "^9.5.1",
|
|
38
|
-
"husky": "^9.1.6",
|
|
39
|
-
"lint-staged": "^15.2.10",
|
|
40
|
-
"prettier": "2.5.1",
|
|
41
|
-
"rollup": "^4.21.2",
|
|
42
|
-
"rollup-plugin-cleandir": "^3.0.0",
|
|
43
|
-
"rollup-plugin-typescript2": "^0.36.0"
|
|
44
|
-
},
|
|
45
|
-
"lint-staged": {
|
|
46
|
-
"**/*": "prettier --write --ignore-unknown"
|
|
47
|
-
}
|
|
48
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "pyrus-api",
|
|
3
|
+
"version": "2.2.0",
|
|
4
|
+
"description": "Pyrus API client for TypeScript",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/simplygoodsoftware/pyrusapi-typescript.git"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"main": "./build/cjs/index.js",
|
|
11
|
+
"module": "./build/esm/index.js",
|
|
12
|
+
"types": "./build/types/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
"require": {
|
|
15
|
+
"default": "./build/cjs/index.cjs"
|
|
16
|
+
},
|
|
17
|
+
"import": {
|
|
18
|
+
"default": "./build/esm/index.js"
|
|
19
|
+
},
|
|
20
|
+
"types": {
|
|
21
|
+
"default": "./build/types/index.d.ts"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"build": "rollup --config rollup.config.ts --configPlugin @rollup/plugin-typescript && dts-bundle-generator --project tsconfig.types.json --no-banner -o ./build/types/index.d.ts index.ts && node ./module-wrapper.js",
|
|
26
|
+
"prepare": "husky"
|
|
27
|
+
},
|
|
28
|
+
"author": {
|
|
29
|
+
"name": "Pyrus",
|
|
30
|
+
"email": "contact@pyrus.com"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@rollup/plugin-typescript": "^11.1.6",
|
|
35
|
+
"@types/node": "^22.5.4",
|
|
36
|
+
"@types/rollup": "^0.54.0",
|
|
37
|
+
"dts-bundle-generator": "^9.5.1",
|
|
38
|
+
"husky": "^9.1.6",
|
|
39
|
+
"lint-staged": "^15.2.10",
|
|
40
|
+
"prettier": "2.5.1",
|
|
41
|
+
"rollup": "^4.21.2",
|
|
42
|
+
"rollup-plugin-cleandir": "^3.0.0",
|
|
43
|
+
"rollup-plugin-typescript2": "^0.36.0"
|
|
44
|
+
},
|
|
45
|
+
"lint-staged": {
|
|
46
|
+
"**/*": "prettier --write --ignore-unknown"
|
|
47
|
+
}
|
|
48
|
+
}
|