@ah-oh/ao-workspaces-api-sdk 1.0.22 → 1.0.24
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/CHANGELOG.md +24 -0
- package/README.md +91 -3
- package/package.json +2 -2
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/auth.module.js +15 -22
- package/src/lib/auth.module.js.map +1 -1
- package/src/lib/customer-center.service.d.ts +42 -6
- package/src/lib/customer-center.service.js +136 -42
- package/src/lib/customer-center.service.js.map +1 -1
- package/src/lib/guards/auth.guard.js +3 -4
- package/src/lib/guards/auth.guard.js.map +1 -1
- package/src/lib/guards/company.guard.js +3 -0
- package/src/lib/guards/company.guard.js.map +1 -1
- package/src/lib/guards/sethub-permissions.guard.js +4 -1
- package/src/lib/guards/sethub-permissions.guard.js.map +1 -1
- package/src/lib/guards/super-admin.guard.js +3 -0
- package/src/lib/guards/super-admin.guard.js.map +1 -1
- package/src/lib/guards/szales-basic-auth.guard.js +33 -14
- package/src/lib/guards/szales-basic-auth.guard.js.map +1 -1
- package/src/lib/mail-settings.service.d.ts +3 -3
- package/src/lib/mail-settings.service.js +63 -251
- package/src/lib/mail-settings.service.js.map +1 -1
- package/src/lib/models/auth.options.d.ts +13 -0
- package/src/lib/print.client.d.ts +76 -0
- package/src/lib/print.client.js +154 -0
- package/src/lib/print.client.js.map +1 -0
- package/src/lib/utils/axios-error.handler.d.ts +11 -0
- package/src/lib/utils/axios-error.handler.js +24 -3
- package/src/lib/utils/axios-error.handler.js.map +1 -1
- package/src/lib/utils/http-client.d.ts +9 -0
- package/src/lib/utils/http-client.js +35 -0
- package/src/lib/utils/http-client.js.map +1 -0
- package/src/lib/utils/jwt.util.d.ts +6 -0
- package/src/lib/utils/jwt.util.js +21 -0
- package/src/lib/utils/jwt.util.js.map +1 -0
- package/src/lib/utils/ttl-cache.d.ts +26 -0
- package/src/lib/utils/ttl-cache.js +66 -0
- package/src/lib/utils/ttl-cache.js.map +1 -0
- package/src/lib/utils/url-path.d.ts +7 -0
- package/src/lib/utils/url-path.js +28 -0
- package/src/lib/utils/url-path.js.map +1 -0
|
@@ -8,6 +8,9 @@ let SuperAdminGuard = class SuperAdminGuard {
|
|
|
8
8
|
async canActivate(context) {
|
|
9
9
|
const request = context.switchToHttp().getRequest();
|
|
10
10
|
const session = request.session;
|
|
11
|
+
if (!session) {
|
|
12
|
+
throw new common_1.UnauthorizedException('No session; use AuthGuard first');
|
|
13
|
+
}
|
|
11
14
|
if (user_session_model_1.AllAccessRoles.includes(session.role)) {
|
|
12
15
|
return true;
|
|
13
16
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"super-admin.guard.js","sourceRoot":"","sources":["../../../../../../libs/api-sdk/src/lib/guards/super-admin.guard.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"super-admin.guard.js","sourceRoot":"","sources":["../../../../../../libs/api-sdk/src/lib/guards/super-admin.guard.ts"],"names":[],"mappings":";;;;AAAA,2CAOwB;AAExB,qEAA2E;AAGpE,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QAEpD,MAAM,OAAO,GAA4B,OAAO,CAAC,OAAO,CAAC;QACzD,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,8BAAqB,CAAC,iCAAiC,CAAC,CAAC;QACrE,CAAC;QACD,IAAI,mCAAc,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1C,OAAO,IAAI,CAAC;QACd,CAAC;QAED,MAAM,IAAI,sBAAa,CAAC,oBAAoB,EAAE,mBAAU,CAAC,WAAW,CAAC,CAAC;IACxE,CAAC;CACF,CAAA;AAdY,0CAAe;0BAAf,eAAe;IAD3B,IAAA,mBAAU,GAAE;GACA,eAAe,CAc3B"}
|
|
@@ -14,24 +14,38 @@ let SzalesBasicAuthGuard = class SzalesBasicAuthGuard {
|
|
|
14
14
|
async canActivate(context) {
|
|
15
15
|
const request = context.switchToHttp().getRequest();
|
|
16
16
|
const authHeader = request.headers.authorization;
|
|
17
|
-
if (!authHeader) {
|
|
17
|
+
if (typeof authHeader !== 'string' || !authHeader.length) {
|
|
18
18
|
throw new common_1.UnauthorizedException('Missing authorization header');
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
const match = /^Basic\s+(\S+)$/i.exec(authHeader);
|
|
21
|
+
if (!match) {
|
|
22
|
+
throw new common_1.UnauthorizedException('Invalid API key');
|
|
23
|
+
}
|
|
24
|
+
const credentials = Buffer.from(match[1], 'base64').toString('utf8');
|
|
25
|
+
// The key may contain ':'; only the first one separates id and key.
|
|
26
|
+
const separator = credentials.indexOf(':');
|
|
27
|
+
const tokenId = separator > 0 ? credentials.slice(0, separator) : '';
|
|
28
|
+
const tokenKey = separator > 0 ? credentials.slice(separator + 1) : '';
|
|
29
|
+
if (!tokenId || !tokenKey) {
|
|
30
|
+
throw new common_1.UnauthorizedException('Invalid API key');
|
|
31
|
+
}
|
|
32
|
+
let token;
|
|
33
|
+
try {
|
|
34
|
+
({ token } = await this.customerCenterService.tokenSignIn({
|
|
35
|
+
tokenId,
|
|
36
|
+
tokenKey,
|
|
28
37
|
product: user_session_model_1.Product.SZALES,
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
// The server answers unknown ids and wrong keys with 404.
|
|
42
|
+
if (error instanceof common_1.HttpException && isRejected(error.getStatus())) {
|
|
43
|
+
throw new common_1.UnauthorizedException('Invalid API key');
|
|
44
|
+
}
|
|
45
|
+
throw error;
|
|
33
46
|
}
|
|
34
|
-
|
|
47
|
+
request.session = await this.customerCenterService.verifyInstanceToken(token);
|
|
48
|
+
return true;
|
|
35
49
|
}
|
|
36
50
|
};
|
|
37
51
|
exports.SzalesBasicAuthGuard = SzalesBasicAuthGuard;
|
|
@@ -40,4 +54,9 @@ exports.SzalesBasicAuthGuard = SzalesBasicAuthGuard = tslib_1.__decorate([
|
|
|
40
54
|
tslib_1.__param(0, (0, common_1.Inject)(auth_module_1.AUTH_TOKEN)),
|
|
41
55
|
tslib_1.__metadata("design:paramtypes", [customer_center_service_1.CustomerCenterService])
|
|
42
56
|
], SzalesBasicAuthGuard);
|
|
57
|
+
function isRejected(status) {
|
|
58
|
+
return (status === common_1.HttpStatus.NOT_FOUND ||
|
|
59
|
+
status === common_1.HttpStatus.UNAUTHORIZED ||
|
|
60
|
+
status === common_1.HttpStatus.BAD_REQUEST);
|
|
61
|
+
}
|
|
43
62
|
//# sourceMappingURL=szales-basic-auth.guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"szales-basic-auth.guard.js","sourceRoot":"","sources":["../../../../../../libs/api-sdk/src/lib/guards/szales-basic-auth.guard.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"szales-basic-auth.guard.js","sourceRoot":"","sources":["../../../../../../libs/api-sdk/src/lib/guards/szales-basic-auth.guard.ts"],"names":[],"mappings":";;;;AAAA,2CAQwB;AAExB,gDAA4C;AAC5C,wEAAmE;AACnE,qEAAuD;AAGhD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAGZ;IAFnB,YAEmB,qBAA4C;QAA5C,0BAAqB,GAArB,qBAAqB,CAAuB;IAC5D,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;QACzC,MAAM,OAAO,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC,UAAU,EAAE,CAAC;QACpD,MAAM,UAAU,GAAY,OAAO,CAAC,OAAO,CAAC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AI,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,EAAE,CAAC;gBACpE,MAAM,IAAI,8BAAqB,CAAC,iBAAiB,CAAC,CAAC;YACrD,CAAC;YACD,MAAM,KAAK,CAAC;QACd,CAAC;QAED,OAAO,CAAC,OAAO,GAAG,MAAM,IAAI,CAAC,qBAAqB,CAAC,mBAAmB,CAAC,KAAK,CAAC,CAAC;QAE9E,OAAO,IAAI,CAAC;IACd,CAAC;CACF,CAAA;AA9CY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAGR,mBAAA,IAAA,eAAM,EAAC,wBAAU,CAAC,CAAA;6CACqB,+CAAqB;GAHpD,oBAAoB,CA8ChC;AAED,SAAS,UAAU,CAAC,MAAc;IAChC,OAAO,CACL,MAAM,KAAK,mBAAU,CAAC,SAAS;QAC/B,MAAM,KAAK,mBAAU,CAAC,YAAY;QAClC,MAAM,KAAK,mBAAU,CAAC,WAAW,CAClC,CAAC;AACJ,CAAC"}
|
|
@@ -13,11 +13,11 @@ interface ListMessagesQuery {
|
|
|
13
13
|
folderId?: string;
|
|
14
14
|
}
|
|
15
15
|
export declare class MailSettingsService {
|
|
16
|
-
private readonly options;
|
|
17
16
|
private readonly customerCenterService;
|
|
18
|
-
private readonly
|
|
17
|
+
private readonly http;
|
|
19
18
|
constructor(options: AuthModuleOptions, customerCenterService: CustomerCenterService);
|
|
20
|
-
|
|
19
|
+
/** Signs in with the credentials (token cached by `CustomerCenterService`) and sends the request. */
|
|
20
|
+
private request;
|
|
21
21
|
findMailSettings(args: {
|
|
22
22
|
companyId: string;
|
|
23
23
|
} & TokenCredentials): Promise<IMailSetting[]>;
|
|
@@ -3,322 +3,134 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MailSettingsService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const common_1 = require("@nestjs/common");
|
|
6
|
-
const axios_1 = require("axios");
|
|
7
6
|
const auth_constants_1 = require("./auth.constants");
|
|
8
7
|
const customer_center_service_1 = require("./customer-center.service");
|
|
9
8
|
const user_session_model_1 = require("./models/user-session.model");
|
|
10
9
|
const axios_error_handler_1 = require("./utils/axios-error.handler");
|
|
10
|
+
const http_client_1 = require("./utils/http-client");
|
|
11
|
+
const url_path_1 = require("./utils/url-path");
|
|
11
12
|
let MailSettingsService = class MailSettingsService {
|
|
12
|
-
options;
|
|
13
13
|
customerCenterService;
|
|
14
|
-
|
|
14
|
+
http;
|
|
15
15
|
constructor(options, customerCenterService) {
|
|
16
|
-
this.options = options;
|
|
17
16
|
this.customerCenterService = customerCenterService;
|
|
18
|
-
this.
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
this.http = (0, http_client_1.createHttpClient)(options);
|
|
18
|
+
}
|
|
19
|
+
/** Signs in with the credentials (token cached by `CustomerCenterService`) and sends the request. */
|
|
20
|
+
request(credentials, config) {
|
|
21
|
+
return this.customerCenterService.withToken({ tokenId: credentials.tokenId, tokenKey: credentials.tokenKey, product: user_session_model_1.Product.ADMIN }, async (authorization) => {
|
|
22
|
+
try {
|
|
23
|
+
const res = await this.http.request({
|
|
24
|
+
...config,
|
|
25
|
+
headers: { ...config.headers, authorization },
|
|
26
|
+
});
|
|
27
|
+
return res.data;
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
31
|
+
}
|
|
25
32
|
});
|
|
26
|
-
return `Bearer ${token}`;
|
|
27
33
|
}
|
|
28
34
|
async findMailSettings(args) {
|
|
29
|
-
|
|
30
|
-
const config = {
|
|
35
|
+
return this.request(args, {
|
|
31
36
|
method: 'GET',
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
headers: {
|
|
35
|
-
accept: 'application/json',
|
|
36
|
-
authorization,
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
try {
|
|
40
|
-
const res = await axios_1.default.request(config);
|
|
41
|
-
return res.data;
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
45
|
-
}
|
|
37
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}`,
|
|
38
|
+
});
|
|
46
39
|
}
|
|
47
40
|
async findOneMailSetting(args) {
|
|
48
|
-
|
|
49
|
-
const config = {
|
|
41
|
+
return this.request(args, {
|
|
50
42
|
method: 'GET',
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
headers: {
|
|
54
|
-
accept: 'application/json',
|
|
55
|
-
authorization,
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
try {
|
|
59
|
-
const res = await axios_1.default.request(config);
|
|
60
|
-
return res.data;
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
64
|
-
}
|
|
43
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.id}`,
|
|
44
|
+
});
|
|
65
45
|
}
|
|
66
46
|
async createMailSetting(args) {
|
|
67
|
-
|
|
68
|
-
const config = {
|
|
47
|
+
return this.request(args, {
|
|
69
48
|
method: 'PUT',
|
|
70
|
-
|
|
71
|
-
url: `/auth-api/mail-settings/${args.companyId}`,
|
|
72
|
-
headers: {
|
|
73
|
-
accept: 'application/json',
|
|
74
|
-
authorization,
|
|
75
|
-
},
|
|
49
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}`,
|
|
76
50
|
data: args.dto,
|
|
77
|
-
};
|
|
78
|
-
try {
|
|
79
|
-
const res = await axios_1.default.request(config);
|
|
80
|
-
return res.data;
|
|
81
|
-
}
|
|
82
|
-
catch (error) {
|
|
83
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
84
|
-
}
|
|
51
|
+
});
|
|
85
52
|
}
|
|
86
53
|
async updateMailSetting(args) {
|
|
87
|
-
|
|
88
|
-
const config = {
|
|
54
|
+
return this.request(args, {
|
|
89
55
|
method: 'POST',
|
|
90
|
-
|
|
91
|
-
url: `/auth-api/mail-settings/${args.companyId}/${args.id}`,
|
|
92
|
-
headers: {
|
|
93
|
-
accept: 'application/json',
|
|
94
|
-
authorization,
|
|
95
|
-
},
|
|
56
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.id}`,
|
|
96
57
|
data: args.dto,
|
|
97
|
-
};
|
|
98
|
-
try {
|
|
99
|
-
const res = await axios_1.default.request(config);
|
|
100
|
-
return res.data;
|
|
101
|
-
}
|
|
102
|
-
catch (error) {
|
|
103
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
104
|
-
}
|
|
58
|
+
});
|
|
105
59
|
}
|
|
106
60
|
async deleteMailSetting(args) {
|
|
107
|
-
|
|
108
|
-
const config = {
|
|
61
|
+
return this.request(args, {
|
|
109
62
|
method: 'DELETE',
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
headers: {
|
|
113
|
-
accept: 'application/json',
|
|
114
|
-
authorization,
|
|
115
|
-
},
|
|
116
|
-
};
|
|
117
|
-
try {
|
|
118
|
-
const res = await axios_1.default.request(config);
|
|
119
|
-
return res.data;
|
|
120
|
-
}
|
|
121
|
-
catch (error) {
|
|
122
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
123
|
-
}
|
|
63
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.id}`,
|
|
64
|
+
});
|
|
124
65
|
}
|
|
125
66
|
async setMicrosoftRefreshToken(args) {
|
|
126
|
-
|
|
127
|
-
const config = {
|
|
67
|
+
return this.request(args, {
|
|
128
68
|
method: 'POST',
|
|
129
|
-
|
|
130
|
-
url: `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/microsoft-refresh-token`,
|
|
131
|
-
headers: {
|
|
132
|
-
accept: 'application/json',
|
|
133
|
-
authorization,
|
|
134
|
-
},
|
|
69
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/microsoft-refresh-token`,
|
|
135
70
|
data: { accessCode: args.accessCode },
|
|
136
|
-
};
|
|
137
|
-
try {
|
|
138
|
-
const res = await axios_1.default.request(config);
|
|
139
|
-
return res.data;
|
|
140
|
-
}
|
|
141
|
-
catch (error) {
|
|
142
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
143
|
-
}
|
|
71
|
+
});
|
|
144
72
|
}
|
|
145
73
|
async testConnection(args) {
|
|
146
|
-
|
|
147
|
-
const config = {
|
|
74
|
+
return this.request(args, {
|
|
148
75
|
method: 'POST',
|
|
149
|
-
|
|
150
|
-
url: `/auth-api/mail-settings/${args.companyId}/test-connection`,
|
|
151
|
-
headers: {
|
|
152
|
-
accept: 'application/json',
|
|
153
|
-
authorization,
|
|
154
|
-
},
|
|
76
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/test-connection`,
|
|
155
77
|
data: args.dto,
|
|
156
|
-
};
|
|
157
|
-
try {
|
|
158
|
-
const res = await axios_1.default.request(config);
|
|
159
|
-
return res.data;
|
|
160
|
-
}
|
|
161
|
-
catch (error) {
|
|
162
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
163
|
-
}
|
|
78
|
+
});
|
|
164
79
|
}
|
|
165
80
|
async testSendMicrosoft(args) {
|
|
166
|
-
|
|
167
|
-
const config = {
|
|
81
|
+
return this.request(args, {
|
|
168
82
|
method: 'POST',
|
|
169
|
-
|
|
170
|
-
url: `/auth-api/mail-settings/${args.companyId}/test-send-microsoft`,
|
|
171
|
-
headers: {
|
|
172
|
-
accept: 'application/json',
|
|
173
|
-
authorization,
|
|
174
|
-
},
|
|
83
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/test-send-microsoft`,
|
|
175
84
|
data: {
|
|
176
85
|
mailSettingId: args.mailSettingId,
|
|
177
86
|
receiver: args.receiver,
|
|
178
87
|
},
|
|
179
|
-
};
|
|
180
|
-
try {
|
|
181
|
-
const res = await axios_1.default.request(config);
|
|
182
|
-
return res.data;
|
|
183
|
-
}
|
|
184
|
-
catch (error) {
|
|
185
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
186
|
-
}
|
|
88
|
+
});
|
|
187
89
|
}
|
|
188
90
|
async sendMail(args) {
|
|
189
|
-
|
|
190
|
-
const config = {
|
|
91
|
+
return this.request(args, {
|
|
191
92
|
method: 'POST',
|
|
192
|
-
|
|
193
|
-
url: `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/send-mail`,
|
|
194
|
-
headers: {
|
|
195
|
-
accept: 'application/json',
|
|
196
|
-
authorization,
|
|
197
|
-
},
|
|
93
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/send-mail`,
|
|
198
94
|
data: args.dto,
|
|
199
|
-
};
|
|
200
|
-
try {
|
|
201
|
-
const res = await axios_1.default.request(config);
|
|
202
|
-
return res.data;
|
|
203
|
-
}
|
|
204
|
-
catch (error) {
|
|
205
|
-
console.error('Error sending mail:', error);
|
|
206
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
207
|
-
}
|
|
95
|
+
});
|
|
208
96
|
}
|
|
209
97
|
async listFolders(args) {
|
|
210
|
-
|
|
211
|
-
const config = {
|
|
98
|
+
return this.request(args, {
|
|
212
99
|
method: 'GET',
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
headers: {
|
|
216
|
-
accept: 'application/json',
|
|
217
|
-
authorization,
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
try {
|
|
221
|
-
const res = await axios_1.default.request(config);
|
|
222
|
-
return res.data;
|
|
223
|
-
}
|
|
224
|
-
catch (error) {
|
|
225
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
226
|
-
}
|
|
100
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/folders`,
|
|
101
|
+
});
|
|
227
102
|
}
|
|
228
103
|
async listMessages(args) {
|
|
229
|
-
|
|
230
|
-
const config = {
|
|
104
|
+
return this.request(args, {
|
|
231
105
|
method: 'GET',
|
|
232
|
-
|
|
233
|
-
url: `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/messages`,
|
|
234
|
-
headers: {
|
|
235
|
-
accept: 'application/json',
|
|
236
|
-
authorization,
|
|
237
|
-
},
|
|
106
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/messages`,
|
|
238
107
|
params: args.query,
|
|
239
|
-
};
|
|
240
|
-
try {
|
|
241
|
-
const res = await axios_1.default.request(config);
|
|
242
|
-
return res.data;
|
|
243
|
-
}
|
|
244
|
-
catch (error) {
|
|
245
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
246
|
-
}
|
|
108
|
+
});
|
|
247
109
|
}
|
|
248
110
|
async getMessage(args) {
|
|
249
|
-
|
|
250
|
-
const config = {
|
|
111
|
+
return this.request(args, {
|
|
251
112
|
method: 'GET',
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
headers: {
|
|
255
|
-
accept: 'application/json',
|
|
256
|
-
authorization,
|
|
257
|
-
},
|
|
258
|
-
};
|
|
259
|
-
try {
|
|
260
|
-
const res = await axios_1.default.request(config);
|
|
261
|
-
return res.data;
|
|
262
|
-
}
|
|
263
|
-
catch (error) {
|
|
264
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
265
|
-
}
|
|
113
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/messages/${args.messageId}`,
|
|
114
|
+
});
|
|
266
115
|
}
|
|
267
116
|
async markAsRead(args) {
|
|
268
|
-
|
|
269
|
-
const config = {
|
|
117
|
+
return this.request(args, {
|
|
270
118
|
method: 'PATCH',
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
headers: {
|
|
274
|
-
accept: 'application/json',
|
|
275
|
-
authorization,
|
|
276
|
-
},
|
|
277
|
-
};
|
|
278
|
-
try {
|
|
279
|
-
await axios_1.default.request(config);
|
|
280
|
-
}
|
|
281
|
-
catch (error) {
|
|
282
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
283
|
-
}
|
|
119
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/messages/${args.messageId}/read`,
|
|
120
|
+
});
|
|
284
121
|
}
|
|
285
122
|
async deleteMessage(args) {
|
|
286
|
-
|
|
287
|
-
const config = {
|
|
123
|
+
return this.request(args, {
|
|
288
124
|
method: 'DELETE',
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
headers: {
|
|
292
|
-
accept: 'application/json',
|
|
293
|
-
authorization,
|
|
294
|
-
},
|
|
295
|
-
};
|
|
296
|
-
try {
|
|
297
|
-
await axios_1.default.request(config);
|
|
298
|
-
}
|
|
299
|
-
catch (error) {
|
|
300
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
301
|
-
}
|
|
125
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/messages/${args.messageId}`,
|
|
126
|
+
});
|
|
302
127
|
}
|
|
303
128
|
async moveMessage(args) {
|
|
304
|
-
|
|
305
|
-
const config = {
|
|
129
|
+
return this.request(args, {
|
|
306
130
|
method: 'POST',
|
|
307
|
-
|
|
308
|
-
url: `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/messages/${args.messageId}/move`,
|
|
309
|
-
headers: {
|
|
310
|
-
accept: 'application/json',
|
|
311
|
-
authorization,
|
|
312
|
-
},
|
|
131
|
+
url: (0, url_path_1.urlPath) `/auth-api/mail-settings/${args.companyId}/${args.mailSettingId}/messages/${args.messageId}/move`,
|
|
313
132
|
data: { destinationFolderId: args.destinationFolderId },
|
|
314
|
-
};
|
|
315
|
-
try {
|
|
316
|
-
const res = await axios_1.default.request(config);
|
|
317
|
-
return res.data;
|
|
318
|
-
}
|
|
319
|
-
catch (error) {
|
|
320
|
-
(0, axios_error_handler_1.handleAxiosError)(error);
|
|
321
|
-
}
|
|
133
|
+
});
|
|
322
134
|
}
|
|
323
135
|
};
|
|
324
136
|
exports.MailSettingsService = MailSettingsService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mail-settings.service.js","sourceRoot":"","sources":["../../../../../libs/api-sdk/src/lib/mail-settings.service.ts"],"names":[],"mappings":";;;;AAUA,2CAAoD;
|
|
1
|
+
{"version":3,"file":"mail-settings.service.js","sourceRoot":"","sources":["../../../../../libs/api-sdk/src/lib/mail-settings.service.ts"],"names":[],"mappings":";;;;AAUA,2CAAoD;AAGpD,qDAAuD;AACvD,uEAAkE;AAElE,oEAAsD;AACtD,qEAA+D;AAC/D,qDAAuD;AACvD,+CAA2C;AAgBpC,IAAM,mBAAmB,GAAzB,MAAM,mBAAmB;IAMX;IALF,IAAI,CAAgB;IAErC,YAEE,OAA0B,EACT,qBAA4C;QAA5C,0BAAqB,GAArB,qBAAqB,CAAuB;QAE7D,IAAI,CAAC,IAAI,GAAG,IAAA,8BAAgB,EAAC,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,qGAAqG;IAC7F,OAAO,CAAI,WAA6B,EAAE,MAA0B;QAC1E,OAAO,IAAI,CAAC,qBAAqB,CAAC,SAAS,CACzC,EAAE,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,QAAQ,EAAE,OAAO,EAAE,4BAAO,CAAC,KAAK,EAAE,EACxF,KAAK,EAAC,aAAa,EAAC,EAAE;YACpB,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,CAAI;oBACrC,GAAG,MAAM;oBACT,OAAO,EAAE,EAAE,GAAG,MAAM,CAAC,OAAO,EAAE,aAAa,EAAE;iBAC9C,CAAC,CAAC;gBACH,OAAO,GAAG,CAAC,IAAI,CAAC;YAClB,CAAC;YAAC,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AE;SACzG,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,WAAW,CACtB,IAKoB;QAEpB,OAAO,IAAI,CAAC,OAAO,CAAwB,IAAI,EAAE;YAC/C,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,IAAA,kBAAO,EAAA,2BAA2B,IAAI,CAAC,SAAS,IAAI,IAAI,CAAC,aAAa,aAAa,IAAI,CAAC,SAAS,OAAO;YAC7G,IAAI,EAAE,EAAE,mBAAmB,EAAE,IAAI,CAAC,mBAAmB,EAAE;SACxD,CAAC,CAAC;IACL,CAAC;CACF,CAAA;AApOY,kDAAmB;8BAAnB,mBAAmB;IAD/B,IAAA,mBAAU,GAAE;IAKR,mBAAA,IAAA,eAAM,EAAC,oCAAmB,CAAC,CAAA;qDAEY,+CAAqB;GANpD,mBAAmB,CAoO/B"}
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { InjectionToken, ModuleMetadata, Type } from '@nestjs/common';
|
|
2
2
|
export interface AuthModuleOptions {
|
|
3
3
|
baseUrl: string;
|
|
4
|
+
/** Timeout per request to the customer center. Default 30000 ms; print uploads allow at least 120000 ms. */
|
|
5
|
+
timeoutMs?: number;
|
|
6
|
+
/**
|
|
7
|
+
* Reuses the token of `tokenSignIn` for the same credentials until shortly
|
|
8
|
+
* before it expires (at most one hour). Default `true`.
|
|
9
|
+
*/
|
|
10
|
+
tokenCache?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Caches the session of `verifyInstanceToken` for this many milliseconds.
|
|
13
|
+
* Default `0` (off): a logout or a permission change only takes effect after
|
|
14
|
+
* this time, so keep it short (e.g. 30000).
|
|
15
|
+
*/
|
|
16
|
+
sessionCacheTtlMs?: number;
|
|
4
17
|
}
|
|
5
18
|
export interface AuthModuleFactory {
|
|
6
19
|
createHttpModuleOptions: () => Promise<AuthModuleOptions> | AuthModuleOptions;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { IPrintJob, PrintColorMode, PrintContentType, PrintPaperSize, Product } from '@ah-oh/ao-workspaces-types';
|
|
2
|
+
import { HttpException } from '@nestjs/common';
|
|
3
|
+
import { CustomerCenterService } from './customer-center.service';
|
|
4
|
+
import { TokenCredentials } from './mail-settings.service';
|
|
5
|
+
import { AuthModuleOptions } from './models/auth.options';
|
|
6
|
+
/**
|
|
7
|
+
* Credentials of a product app. `product` must be the calling app (e.g. `szales`),
|
|
8
|
+
* not `admin`: only app sessions may print on print targets without the admin
|
|
9
|
+
* permission `hardware`, and the job records the app as its origin.
|
|
10
|
+
*/
|
|
11
|
+
export interface PrintCredentials extends TokenCredentials {
|
|
12
|
+
product: Product;
|
|
13
|
+
}
|
|
14
|
+
export interface PrintArgs extends PrintCredentials {
|
|
15
|
+
companyId: string;
|
|
16
|
+
/** Key of a print target configured by the company, e.g. `shipping-label`. */
|
|
17
|
+
target: string;
|
|
18
|
+
contentType: PrintContentType;
|
|
19
|
+
/** Print-ready content: a PDF document or raw ZPL. At most 50 MB. */
|
|
20
|
+
content: Buffer | Uint8Array;
|
|
21
|
+
/** File name shown in the print history. Defaults to `content.<contentType>`. */
|
|
22
|
+
fileName?: string;
|
|
23
|
+
/** 1–99, default 1. */
|
|
24
|
+
copies?: number;
|
|
25
|
+
/** PDF only. */
|
|
26
|
+
paperSize?: PrintPaperSize;
|
|
27
|
+
/** PDF only. */
|
|
28
|
+
color?: PrintColorMode;
|
|
29
|
+
/** The same key within a company always returns the same job instead of printing again. */
|
|
30
|
+
idempotencyKey?: string;
|
|
31
|
+
/** 10–604800 seconds; the job expires unprinted afterwards. Default on the server: 3600. */
|
|
32
|
+
expiresInSeconds?: number;
|
|
33
|
+
}
|
|
34
|
+
export interface GetPrintJobArgs extends PrintCredentials {
|
|
35
|
+
companyId: string;
|
|
36
|
+
jobId: string;
|
|
37
|
+
}
|
|
38
|
+
export interface WaitForPrintJobArgs extends GetPrintJobArgs {
|
|
39
|
+
/** Maximum time to wait. Default 60000 ms. */
|
|
40
|
+
timeoutMs?: number;
|
|
41
|
+
/** Pause between two polls. Default 2000 ms. */
|
|
42
|
+
intervalMs?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Error of the hardware API. `code` is the machine-readable code of the body
|
|
46
|
+
* `{ type: 'error', code, message }` (e.g. `target_unassigned`,
|
|
47
|
+
* `target_not_found`, `option_not_allowed`, `content_too_large`). It is
|
|
48
|
+
* undefined for errors without such a body (validation, network).
|
|
49
|
+
*/
|
|
50
|
+
export declare class PrintClientError extends HttpException {
|
|
51
|
+
readonly code: string | undefined;
|
|
52
|
+
constructor(code: string | undefined, message: string, status: number);
|
|
53
|
+
}
|
|
54
|
+
/** Creates print jobs on the hardware connector API and reads their state (HC-12). */
|
|
55
|
+
export declare class PrintClient {
|
|
56
|
+
private readonly customerCenterService;
|
|
57
|
+
private readonly http;
|
|
58
|
+
private readonly uploadTimeoutMs;
|
|
59
|
+
constructor(options: AuthModuleOptions, customerCenterService: CustomerCenterService);
|
|
60
|
+
/** True once the job will not change anymore (completed, failed, expired, canceled). */
|
|
61
|
+
static isFinal(job: Pick<IPrintJob, 'state'>): boolean;
|
|
62
|
+
/** Creates a print job on a print target. Resolves as soon as the job is queued. */
|
|
63
|
+
print(args: PrintArgs): Promise<IPrintJob>;
|
|
64
|
+
getJob(args: GetPrintJobArgs): Promise<IPrintJob>;
|
|
65
|
+
/**
|
|
66
|
+
* Polls the job until it reaches a final state or `timeoutMs` has passed.
|
|
67
|
+
* On timeout the last known (non-final) job is returned; check it with
|
|
68
|
+
* `PrintClient.isFinal`. A job for an offline connector stays `queued` until
|
|
69
|
+
* it expires.
|
|
70
|
+
*/
|
|
71
|
+
waitForJob(args: WaitForPrintJobArgs): Promise<IPrintJob>;
|
|
72
|
+
private fetchJob;
|
|
73
|
+
/** Signs in with the credentials (token cached by `CustomerCenterService`) and sends the request. */
|
|
74
|
+
private request;
|
|
75
|
+
private send;
|
|
76
|
+
}
|