@ezeep/ezeep-js 1.0.272 → 1.0.284
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/dist/cjs/{app-globals-D7ISNeUi.js → app-globals-L_3XPZxT.js} +7 -1
- package/dist/cjs/ezeep.cjs.js +4 -4
- package/dist/cjs/ezp-auth_15.cjs.entry.js +7338 -3700
- package/dist/cjs/{index-dv_gozsq.js → index-DM5v_sge.js} +3 -2
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/collection/collection-manifest.json +1 -1
- package/dist/collection/components/ezp-auth/ezp-auth.css +0 -12
- package/dist/collection/components/ezp-auth/ezp-auth.js +78 -18
- package/dist/collection/components/ezp-backdrop/ezp-backdrop.js +5 -5
- package/dist/collection/components/ezp-dialog/ezp-dialog.js +85 -13
- package/dist/collection/components/ezp-icon/assets/glyph-cloud-upload.svg +4 -0
- package/dist/collection/components/ezp-icon/assets/glyph-file.svg +3 -0
- package/dist/collection/components/ezp-icon/ezp-icon.js +8 -3
- package/dist/collection/components/ezp-icon-button/ezp-icon-button.js +5 -2
- package/dist/collection/components/ezp-input/ezp-input.css +19 -38
- package/dist/collection/components/ezp-input/ezp-input.js +16 -14
- package/dist/collection/components/ezp-printer-selection/ezp-printer-selection.css +175 -48
- package/dist/collection/components/ezp-printer-selection/ezp-printer-selection.js +215 -329
- package/dist/collection/components/ezp-printing/ezp-printing.css +23 -23
- package/dist/collection/components/ezp-printing/ezp-printing.js +119 -35
- package/dist/collection/components/ezp-select/ezp-select.css +56 -38
- package/dist/collection/components/ezp-select/ezp-select.js +93 -14
- package/dist/collection/components/ezp-status/ezp-status.css +94 -9
- package/dist/collection/components/ezp-status/ezp-status.js +42 -13
- package/dist/collection/components/ezp-stepper/ezp-stepper.css +37 -35
- package/dist/collection/components/ezp-stepper/ezp-stepper.js +14 -7
- package/dist/collection/components/ezp-text-button/ezp-text-button.css +3 -3
- package/dist/collection/components/ezp-text-button/ezp-text-button.js +1 -1
- package/dist/collection/components/ezp-upload/ezp-upload.css +243 -77
- package/dist/collection/components/ezp-upload/ezp-upload.js +80 -10
- package/dist/collection/components/ezp-user-menu/ezp-user-menu.css +2 -1
- package/dist/collection/components/ezp-user-menu/ezp-user-menu.js +15 -15
- package/dist/collection/services/auth.js +37 -36
- package/dist/collection/services/http.js +11 -0
- package/dist/collection/services/print-job.js +72 -0
- package/dist/collection/services/print.js +21 -69
- package/dist/collection/services/user.js +2 -9
- package/dist/collection/shared/constants.js +55 -0
- package/dist/collection/shared/global.js +7 -1
- package/dist/collection/shared/storage.js +71 -0
- package/dist/collection/types/shared/types.d.ts +42 -9
- package/dist/collection/utils/printer.js +68 -0
- package/dist/collection/utils/utils.js +24 -9
- package/dist/components/auth.js +1 -1
- package/dist/components/ezp-auth2.js +1 -1
- package/dist/components/ezp-backdrop2.js +1 -1
- package/dist/components/ezp-dialog2.js +1 -1
- package/dist/components/ezp-icon-button2.js +1 -1
- package/dist/components/ezp-icon2.js +1 -1
- package/dist/components/ezp-input2.js +1 -1
- package/dist/components/ezp-printer-selection2.js +1 -1
- package/dist/components/ezp-printing.js +1 -1
- package/dist/components/ezp-select2.js +1 -1
- package/dist/components/ezp-status2.js +1 -1
- package/dist/components/ezp-stepper2.js +1 -1
- package/dist/components/ezp-text-button2.js +1 -1
- package/dist/components/ezp-upload2.js +1 -1
- package/dist/components/ezp-user-menu.js +1 -1
- package/dist/components/ezp-user-menu2.js +1 -1
- package/dist/components/index.js +1 -1
- package/dist/components/utils.js +1 -0
- package/dist/directives/proxies.ts +74 -47
- package/dist/esm/{app-globals-CpP67t2l.js → app-globals-C0WTlb31.js} +7 -1
- package/dist/esm/ezeep.js +5 -5
- package/dist/esm/ezp-auth_15.entry.js +7338 -3700
- package/dist/esm/{index-BTfWEHH9.js → index-BButrLnB.js} +3 -3
- package/dist/esm/loader.js +4 -4
- package/dist/esm-es5/{app-globals-CpP67t2l.js → app-globals-C0WTlb31.js} +1 -1
- package/dist/esm-es5/ezeep.js +1 -1
- package/dist/esm-es5/ezp-auth_15.entry.js +2 -2
- package/dist/esm-es5/{index-BTfWEHH9.js → index-BButrLnB.js} +3 -3
- package/dist/esm-es5/loader.js +1 -1
- package/dist/ezeep/assets/glyph-cloud-upload.svg +4 -0
- package/dist/ezeep/assets/glyph-file.svg +3 -0
- package/dist/ezeep/ezeep.esm.js +1 -1
- package/dist/ezeep/ezeep.js +1 -1
- package/dist/ezeep/p-1e286bd1.system.entry.js +7 -0
- package/dist/ezeep/{p-BTfWEHH9.js → p-BButrLnB.js} +2 -2
- package/dist/ezeep/{p-CpP67t2l.js → p-C0WTlb31.js} +1 -1
- package/{www/build/p-DhXN1yGM.system.js → dist/ezeep/p-CYpousxy.system.js} +2 -2
- package/dist/ezeep/{p-5ok9OZMg.system.js → p-D4aCr1OK.system.js} +1 -1
- package/dist/ezeep/p-DCznw2Ee.system.js +1 -0
- package/dist/ezeep/p-a2b688f0.entry.js +1 -0
- package/dist/ezeep/types/shared/types.d.ts +42 -9
- package/dist/types/components/ezp-auth/ezp-auth.d.ts +8 -5
- package/dist/types/components/ezp-backdrop/ezp-backdrop.d.ts +2 -2
- package/dist/types/components/ezp-dialog/ezp-dialog.d.ts +14 -3
- package/dist/types/components/ezp-input/ezp-input.d.ts +17 -14
- package/dist/types/components/ezp-printer-selection/ezp-printer-selection.d.ts +23 -7
- package/dist/types/components/ezp-printing/ezp-printing.d.ts +26 -2
- package/dist/types/components/ezp-select/ezp-select.d.ts +10 -4
- package/dist/types/components/ezp-status/ezp-status.d.ts +7 -4
- package/dist/types/components/ezp-stepper/ezp-stepper.d.ts +1 -1
- package/dist/types/components/ezp-upload/ezp-upload.d.ts +13 -1
- package/dist/types/components/ezp-user-menu/ezp-user-menu.d.ts +5 -2
- package/dist/types/components.d.ts +47 -39
- package/dist/types/services/auth.d.ts +10 -0
- package/dist/types/services/http.d.ts +4 -0
- package/dist/types/services/print-job.d.ts +48 -0
- package/dist/types/services/print.d.ts +10 -9
- package/dist/types/services/user.d.ts +13 -2
- package/dist/types/shared/constants.d.ts +51 -0
- package/dist/types/shared/storage.d.ts +24 -0
- package/dist/types/shared/types.d.ts +42 -9
- package/dist/types/stencil-public-runtime.d.ts +1 -0
- package/dist/types/utils/printer.d.ts +22 -0
- package/dist/types/utils/utils.d.ts +22 -10
- package/package.json +30 -18
- package/readme.md +1 -0
- package/www/build/assets/glyph-cloud-upload.svg +4 -0
- package/www/build/assets/glyph-file.svg +3 -0
- package/www/build/ezeep.esm.js +1 -1
- package/www/build/ezeep.js +1 -1
- package/www/build/p-1e286bd1.system.entry.js +7 -0
- package/www/build/p-544b7033.js +1 -0
- package/www/build/{p-BTfWEHH9.js → p-BButrLnB.js} +2 -2
- package/www/build/{p-CpP67t2l.js → p-C0WTlb31.js} +1 -1
- package/{dist/ezeep/p-DhXN1yGM.system.js → www/build/p-CYpousxy.system.js} +2 -2
- package/www/build/{p-5ok9OZMg.system.js → p-D4aCr1OK.system.js} +1 -1
- package/www/build/p-DCznw2Ee.system.js +1 -0
- package/www/build/p-a2b688f0.entry.js +1 -0
- package/www/data/locales/de.json +14 -5
- package/www/data/locales/en.json +14 -5
- package/www/index.html +2 -5
- package/dist/components/i18next.js +0 -1
- package/dist/ezeep/p-2177b8f4.system.entry.js +0 -7
- package/dist/ezeep/p-CfQRcOh8.system.js +0 -1
- package/dist/ezeep/p-de8f6583.entry.js +0 -1
- package/www/build/p-2177b8f4.system.entry.js +0 -7
- package/www/build/p-256870db.js +0 -1
- package/www/build/p-CfQRcOh8.system.js +0 -1
- package/www/build/p-de8f6583.entry.js +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Host, h } from "@stencil/core";
|
|
2
2
|
import authStore from "../../services/auth";
|
|
3
3
|
import userStore from "../../services/user";
|
|
4
|
+
import { storage } from "../../shared/storage";
|
|
5
|
+
import { subscribeToLanguageChange } from "../../utils/utils";
|
|
4
6
|
import i18next from "i18next";
|
|
5
7
|
export class EzpUserMenu {
|
|
6
8
|
constructor() {
|
|
@@ -29,11 +31,7 @@ export class EzpUserMenu {
|
|
|
29
31
|
this.userMenuClosure.emit();
|
|
30
32
|
};
|
|
31
33
|
this.logOut = () => {
|
|
32
|
-
|
|
33
|
-
localStorage.removeItem('refreshToken');
|
|
34
|
-
localStorage.removeItem('access_token');
|
|
35
|
-
localStorage.removeItem('printer');
|
|
36
|
-
localStorage.removeItem('isAuthorized');
|
|
34
|
+
storage.clearSession();
|
|
37
35
|
authStore.state.isAuthorized = false;
|
|
38
36
|
this.logoutEmitter.emit();
|
|
39
37
|
};
|
|
@@ -64,11 +62,9 @@ export class EzpUserMenu {
|
|
|
64
62
|
this.userMenuClosure.emit();
|
|
65
63
|
}
|
|
66
64
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
*
|
|
71
|
-
*/
|
|
65
|
+
connectedCallback() {
|
|
66
|
+
this.unsubscribeLanguage = subscribeToLanguageChange(this);
|
|
67
|
+
}
|
|
72
68
|
componentWillLoad() {
|
|
73
69
|
this.container = this.component.closest('[data-backdrop-surface]');
|
|
74
70
|
this.backdrop.addEventListener('backdropHideStart', () => {
|
|
@@ -78,13 +74,17 @@ export class EzpUserMenu {
|
|
|
78
74
|
this.container.removeChild(this.backdrop);
|
|
79
75
|
});
|
|
80
76
|
}
|
|
77
|
+
disconnectedCallback() {
|
|
78
|
+
var _a;
|
|
79
|
+
(_a = this.unsubscribeLanguage) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
80
|
+
}
|
|
81
81
|
/**
|
|
82
82
|
*
|
|
83
83
|
* Render method
|
|
84
84
|
*
|
|
85
85
|
*/
|
|
86
86
|
render() {
|
|
87
|
-
return (h(Host, { key: '
|
|
87
|
+
return (h(Host, { key: 'ce0f05bb5ae8d4350d688b234c0a913b338a39c1', class: this.open ? 'is-open' : '' }, h("div", { key: '58448dac0a9d08e7d1bdaaaefae308dc32792837', id: "header" }, h("ezp-label", { key: '741b8f779bd0365452f83cd51030c621b87d9112', ellipsis: true, id: "name", weight: "heavy", text: this.name }), h("ezp-icon-button", { key: '7bb08461ef32207f533abfae0c11fa1b35796ad5', id: "close", level: "tertiary", icon: "close", onClick: this.handleClose })), h("div", { key: '047a83ce4d3f7ae3f955dfb078effd95d151b0c1', id: "links" }, this.links.map((link) => (h("a", { class: "link", href: link.href, target: "_blank", rel: "noopener noreferrer" }, h("ezp-icon", { class: "link__icon", name: link.icon }), h("ezp-label", { text: link.title })))), h("a", { key: 'b8d940d65aa2602c6b6c227ab13eb20b9047ae26', class: "link", onClick: this.logOut }, h("ezp-icon", { key: 'dc72f40d565077333ae95520ae156669c1aa41a9', class: "link__icon", name: "logout" }), h("ezp-label", { key: 'b9aef15622e67f60c7948dca008a2724be44c680', text: i18next.t('user_menu.logout') }))), h("div", { key: 'a4d0768275f2f9546381ba0cad73357c5e8b37e5', id: "theme" }, h("ezp-label", { key: '0b934d478dfb405b5349a782ea5f47f6b8ae6082', class: "caption", text: `${i18next.t('user_menu.theme')}:`, weight: "heavy" }), h("div", { key: '7c1665c4dcea007dd605229e001676312ef90f04', id: "swatches" }, this.themes.map((theme) => (h("button", { class: `swatch swatch--${theme} ${theme === userStore.state.theme ? 'selected' : ''}`, onClick: () => this.handleTheme(theme) }, h("span", { class: "dot" })))))), h("div", { key: '68d4809c7872102eed4cbd104e1c42ad324c66b1', id: "appearance" }, h("ezp-label", { key: '2886504538c9dbfb1b92539f9ed85f604a2b834d', class: "caption", text: `${i18next.t('user_menu.appearance')}:`, weight: "heavy" }), h("div", { key: 'e614f865638be0007e726d02934a34c54e9f6e58', id: "tabs" }, this.appearances.map((appearance) => (h("button", { class: `tab ${appearance.name === userStore.state.appearance ? 'selected' : ''}`, onClick: () => this.handleAppearance(appearance.name) }, h("ezp-icon", { name: appearance.name }), h("ezp-label", { text: appearance.title, level: "tertiary", weight: "strong" }))))))));
|
|
88
88
|
}
|
|
89
89
|
static get is() { return "ezp-user-menu"; }
|
|
90
90
|
static get encapsulation() { return "shadow"; }
|
|
@@ -154,8 +154,8 @@ export class EzpUserMenu {
|
|
|
154
154
|
"text": "\nEvents"
|
|
155
155
|
},
|
|
156
156
|
"complexType": {
|
|
157
|
-
"original": "
|
|
158
|
-
"resolved": "
|
|
157
|
+
"original": "void",
|
|
158
|
+
"resolved": "void",
|
|
159
159
|
"references": {}
|
|
160
160
|
}
|
|
161
161
|
}, {
|
|
@@ -169,8 +169,8 @@ export class EzpUserMenu {
|
|
|
169
169
|
"text": ""
|
|
170
170
|
},
|
|
171
171
|
"complexType": {
|
|
172
|
-
"original": "
|
|
173
|
-
"resolved": "
|
|
172
|
+
"original": "void",
|
|
173
|
+
"resolved": "void",
|
|
174
174
|
"references": {}
|
|
175
175
|
}
|
|
176
176
|
}];
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { createStore } from "@stencil/store";
|
|
2
2
|
import { encodeFormData } from "../utils/utils";
|
|
3
|
+
import { storage } from "../shared/storage";
|
|
3
4
|
export class EzpAuthorizationService {
|
|
4
5
|
constructor(redirectURI, clientID) {
|
|
5
6
|
this.urlParams = new URLSearchParams();
|
|
6
7
|
this.isAuthorized = false;
|
|
7
8
|
this.redirectURI = redirectURI;
|
|
8
9
|
this.clientID = clientID;
|
|
10
|
+
// Mirror the client id into the store so a token refresh can be triggered
|
|
11
|
+
// centrally (e.g. from the fetch helper) without a service instance.
|
|
12
|
+
authStore.state.clientID = clientID;
|
|
9
13
|
this.oauthUrl = authStore.state.authApiHostUrl;
|
|
10
14
|
this.authURI = new URL(`https://${this.oauthUrl}/oauth/authorize/`);
|
|
11
15
|
this.accessTokenURL = `https://${this.oauthUrl}/oauth/access_token/`;
|
|
@@ -26,7 +30,7 @@ export class EzpAuthorizationService {
|
|
|
26
30
|
const encoder = new TextEncoder();
|
|
27
31
|
const codeData = encoder.encode(codeVerifier);
|
|
28
32
|
const digest = await crypto.subtle.digest('SHA-256', codeData);
|
|
29
|
-
const base64Digest = btoa(String.fromCharCode
|
|
33
|
+
const base64Digest = btoa(String.fromCharCode(...new Uint8Array(digest)));
|
|
30
34
|
this.codeChallenge = base64Digest.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
31
35
|
}
|
|
32
36
|
buildAuthURI() {
|
|
@@ -38,13 +42,33 @@ export class EzpAuthorizationService {
|
|
|
38
42
|
this.authURI.search = this.urlParams.toString();
|
|
39
43
|
authStore.state.authUri = this.authURI.toString();
|
|
40
44
|
}
|
|
45
|
+
/** Shared auth headers for the OAuth token endpoints (Basic auth, form body). */
|
|
46
|
+
oauthHeaders() {
|
|
47
|
+
return {
|
|
48
|
+
Authorization: 'Basic ' + btoa(this.clientID + ':'),
|
|
49
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Persist tokens. The access token is kept in memory only (auth store +
|
|
54
|
+
* instance field) — it is deliberately NOT written to localStorage, so an XSS
|
|
55
|
+
* on the host page can't read it. Only the refresh token (needed to re-auth
|
|
56
|
+
* after a reload) and the isAuthorized hint are persisted.
|
|
57
|
+
*/
|
|
58
|
+
persistTokens(accessToken, refreshToken) {
|
|
59
|
+
this.accessToken = accessToken;
|
|
60
|
+
authStore.state.accessToken = accessToken;
|
|
61
|
+
this.refreshToken = refreshToken;
|
|
62
|
+
authStore.state.refreshToken = refreshToken;
|
|
63
|
+
storage.setRefreshToken(refreshToken);
|
|
64
|
+
this.isAuthorized = true;
|
|
65
|
+
authStore.state.isAuthorized = true;
|
|
66
|
+
storage.setIsAuthorized(true);
|
|
67
|
+
}
|
|
41
68
|
getAccessToken() {
|
|
42
69
|
return fetch(this.accessTokenURL, {
|
|
43
70
|
credentials: 'include',
|
|
44
|
-
headers:
|
|
45
|
-
Authorization: 'Basic ' + btoa(this.clientID + ':'),
|
|
46
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
47
|
-
},
|
|
71
|
+
headers: this.oauthHeaders(),
|
|
48
72
|
method: 'POST',
|
|
49
73
|
body: encodeFormData({
|
|
50
74
|
grant_type: 'authorization_code',
|
|
@@ -54,31 +78,17 @@ export class EzpAuthorizationService {
|
|
|
54
78
|
code_verifier: authStore.state.codeVerifier,
|
|
55
79
|
}),
|
|
56
80
|
})
|
|
57
|
-
.then((response) =>
|
|
58
|
-
return response.json(); // parse response
|
|
59
|
-
})
|
|
81
|
+
.then((response) => response.json())
|
|
60
82
|
.then((data) => {
|
|
61
|
-
// actual object
|
|
62
83
|
if (data.access_token) {
|
|
63
|
-
|
|
64
|
-
this.isAuthorized = authStore.state.isAuthorized;
|
|
65
|
-
localStorage.setItem('isAuthorized', this.isAuthorized.toString());
|
|
66
|
-
this.accessToken = data.access_token;
|
|
67
|
-
localStorage.setItem('access_token', this.accessToken);
|
|
68
|
-
authStore.state.accessToken = this.accessToken;
|
|
69
|
-
this.refreshToken = data.refresh_token;
|
|
70
|
-
localStorage.setItem('refreshToken', this.refreshToken);
|
|
71
|
-
authStore.state.refreshToken = this.refreshToken;
|
|
84
|
+
this.persistTokens(data.access_token, data.refresh_token);
|
|
72
85
|
}
|
|
73
86
|
});
|
|
74
87
|
}
|
|
75
88
|
refreshTokens() {
|
|
76
89
|
return fetch(this.accessTokenURL, {
|
|
77
90
|
credentials: 'include',
|
|
78
|
-
headers:
|
|
79
|
-
Authorization: 'Basic ' + btoa(this.clientID + ':'),
|
|
80
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
81
|
-
},
|
|
91
|
+
headers: this.oauthHeaders(),
|
|
82
92
|
method: 'POST',
|
|
83
93
|
body: encodeFormData({
|
|
84
94
|
grant_type: 'refresh_token',
|
|
@@ -89,14 +99,7 @@ export class EzpAuthorizationService {
|
|
|
89
99
|
.then((response) => response.json())
|
|
90
100
|
.then((data) => {
|
|
91
101
|
if (data.access_token) {
|
|
92
|
-
this.
|
|
93
|
-
localStorage.setItem('access_token', this.accessToken);
|
|
94
|
-
authStore.state.accessToken = this.accessToken;
|
|
95
|
-
this.refreshToken = data.refresh_token;
|
|
96
|
-
localStorage.setItem('refreshToken', this.refreshToken);
|
|
97
|
-
authStore.state.refreshToken = this.refreshToken;
|
|
98
|
-
authStore.state.isAuthorized = true;
|
|
99
|
-
localStorage.setItem('isAuthorized', 'true');
|
|
102
|
+
this.persistTokens(data.access_token, data.refresh_token);
|
|
100
103
|
}
|
|
101
104
|
});
|
|
102
105
|
}
|
|
@@ -104,16 +107,13 @@ export class EzpAuthorizationService {
|
|
|
104
107
|
if (authStore.state.refreshToken)
|
|
105
108
|
fetch(`https://${this.oauthUrl}/oauth/revoke/`, {
|
|
106
109
|
credentials: 'include',
|
|
107
|
-
headers:
|
|
108
|
-
Authorization: 'Basic ' + btoa(this.clientID + ':'),
|
|
109
|
-
'Content-Type': 'application/x-www-form-urlencoded',
|
|
110
|
-
},
|
|
110
|
+
headers: this.oauthHeaders(),
|
|
111
111
|
method: 'POST',
|
|
112
112
|
body: encodeFormData({
|
|
113
113
|
token: authStore.state.refreshToken,
|
|
114
114
|
}),
|
|
115
|
-
}).catch((
|
|
116
|
-
|
|
115
|
+
}).catch(() => {
|
|
116
|
+
// Revocation is best-effort; ignore network failures.
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
119
|
}
|
|
@@ -127,6 +127,7 @@ const authStore = createStore({
|
|
|
127
127
|
authApiHostUrl: '',
|
|
128
128
|
redirectUri: '',
|
|
129
129
|
authUri: '',
|
|
130
|
+
clientID: '',
|
|
130
131
|
});
|
|
131
132
|
export default authStore;
|
|
132
133
|
export function sendCodeToParentWindow() {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Authorization header for a Bearer-token request. */
|
|
2
|
+
export function bearer(accessToken) {
|
|
3
|
+
return { Authorization: 'Bearer ' + accessToken };
|
|
4
|
+
}
|
|
5
|
+
/** GET a URL with a Bearer token and parse the JSON body. */
|
|
6
|
+
export function authGetJson(url, accessToken) {
|
|
7
|
+
return fetch(url, {
|
|
8
|
+
method: 'GET',
|
|
9
|
+
headers: bearer(accessToken),
|
|
10
|
+
}).then((response) => response.json());
|
|
11
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { classifyJobStatus } from "../utils/printer";
|
|
2
|
+
import { BLOB_UPLOAD_CREATED, PRINT_REJECTED_CODE, HUB_DRIVER_ERROR_CODES, POLL_INTERVAL_MS, MAX_POLL_ATTEMPTS, } from "../shared/constants";
|
|
3
|
+
/** Lower-cased file extension, or '' when there is none. */
|
|
4
|
+
export function fileExtension(filename) {
|
|
5
|
+
const ext = filename.split('.').pop();
|
|
6
|
+
return ext ? ext.toLowerCase() : '';
|
|
7
|
+
}
|
|
8
|
+
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
9
|
+
/**
|
|
10
|
+
* Poll the print status until the job reaches a terminal state. Resolves on
|
|
11
|
+
* success; throws on failure, a hub-driver error, or when the polling budget is
|
|
12
|
+
* exhausted (so a stuck job fails instead of polling forever). Unknown statuses
|
|
13
|
+
* are treated as failures for safety.
|
|
14
|
+
*/
|
|
15
|
+
export async function waitForJobCompletion(getStatus, isQueue, pollIntervalMs = POLL_INTERVAL_MS, maxAttempts = MAX_POLL_ATTEMPTS) {
|
|
16
|
+
let attempts = 0;
|
|
17
|
+
// eslint-disable-next-line no-constant-condition
|
|
18
|
+
while (true) {
|
|
19
|
+
const data = await getStatus();
|
|
20
|
+
attempts++;
|
|
21
|
+
const outcome = classifyJobStatus(data.jobstatus, isQueue);
|
|
22
|
+
if (outcome === 'success')
|
|
23
|
+
return;
|
|
24
|
+
if (outcome === 'hub-error') {
|
|
25
|
+
throw new Error('Hub printer driver error: ' + (data.jobstatusstring || data.jobstatus));
|
|
26
|
+
}
|
|
27
|
+
if (outcome === 'failed') {
|
|
28
|
+
throw new Error('Print job failed: ' + (data.jobstatusstring || data.jobstatus));
|
|
29
|
+
}
|
|
30
|
+
// 'processing' — keep waiting until the polling budget is exhausted.
|
|
31
|
+
if (attempts >= maxAttempts) {
|
|
32
|
+
throw new Error(`Print job timed out after ${attempts} status checks`);
|
|
33
|
+
}
|
|
34
|
+
await sleep(pollIntervalMs);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Upload one file then print it, waiting for the job to finish. Throws (with a
|
|
39
|
+
* message that includes "Hub printer driver error" for queue-driver failures) on
|
|
40
|
+
* any failure, so callers can aggregate per-file outcomes.
|
|
41
|
+
*/
|
|
42
|
+
export async function uploadAndPrintFile(ctx, file, hooks = {}) {
|
|
43
|
+
var _a, _b, _c, _d, _e;
|
|
44
|
+
(_a = hooks.onPreparing) === null || _a === void 0 ? void 0 : _a.call(hooks, true);
|
|
45
|
+
const response = await ctx.service.prepareFileUpload(ctx.accessToken);
|
|
46
|
+
(_b = hooks.onPreparing) === null || _b === void 0 ? void 0 : _b.call(hooks, false);
|
|
47
|
+
const fileid = response.fileid;
|
|
48
|
+
const sasUri = response.sasUri;
|
|
49
|
+
const filetype = fileExtension(file.name);
|
|
50
|
+
(_c = hooks.onUploading) === null || _c === void 0 ? void 0 : _c.call(hooks, true);
|
|
51
|
+
try {
|
|
52
|
+
const res = await ctx.service.uploadBlobFiles(sasUri, file);
|
|
53
|
+
if (res._response.status !== BLOB_UPLOAD_CREATED) {
|
|
54
|
+
throw new Error(`Upload failed for file: ${file.name}`);
|
|
55
|
+
}
|
|
56
|
+
const data = await ctx.service.printByFileID(ctx.accessToken, fileid, filetype, ctx.printerId, ctx.properties, file.name);
|
|
57
|
+
if (data.code === PRINT_REJECTED_CODE) {
|
|
58
|
+
throw new Error(`Print failed for file: ${file.name}`);
|
|
59
|
+
}
|
|
60
|
+
if (ctx.isQueue && data.code !== undefined && HUB_DRIVER_ERROR_CODES.includes(data.code)) {
|
|
61
|
+
throw new Error(`Hub printer driver error for file: ${file.name}`);
|
|
62
|
+
}
|
|
63
|
+
if (!data.jobid) {
|
|
64
|
+
throw new Error(`No job ID returned for file: ${file.name}`);
|
|
65
|
+
}
|
|
66
|
+
(_d = hooks.onJobId) === null || _d === void 0 ? void 0 : _d.call(hooks, data.jobid);
|
|
67
|
+
await waitForJobCompletion(() => ctx.service.getPrintStatus(), ctx.isQueue, ctx.pollIntervalMs);
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
(_e = hooks.onUploading) === null || _e === void 0 ? void 0 : _e.call(hooks, false);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -2,15 +2,13 @@ import { createStore } from "@stencil/store";
|
|
|
2
2
|
import authStore, { EzpAuthorizationService } from "./auth";
|
|
3
3
|
import fetchIntercept from "fetch-intercept";
|
|
4
4
|
import { AnonymousCredential, BlockBlobClient, newPipeline } from "@azure/storage-blob";
|
|
5
|
+
import { authGetJson, bearer } from "./http";
|
|
6
|
+
import { storage } from "../shared/storage";
|
|
5
7
|
export class EzpPrintService {
|
|
6
8
|
constructor(redirectURI, clientID) {
|
|
7
9
|
this.abortController = null;
|
|
8
10
|
this.getPrintStatus = () => {
|
|
9
|
-
return
|
|
10
|
-
headers: {
|
|
11
|
-
Authorization: 'Bearer ' + authStore.state.accessToken,
|
|
12
|
-
},
|
|
13
|
-
}).then((response) => response.json());
|
|
11
|
+
return authGetJson(`https://${this.printingApi}/sfapi/Status/?id=${encodeURIComponent(printStore.state.jobID)}`, authStore.state.accessToken);
|
|
14
12
|
};
|
|
15
13
|
this.redirectURI = redirectURI;
|
|
16
14
|
this.clientID = clientID;
|
|
@@ -18,15 +16,11 @@ export class EzpPrintService {
|
|
|
18
16
|
this.checkStoredRefreshToken();
|
|
19
17
|
}
|
|
20
18
|
checkStoredRefreshToken() {
|
|
19
|
+
var _a;
|
|
21
20
|
if (authStore.state.refreshToken !== '') {
|
|
22
21
|
return;
|
|
23
22
|
}
|
|
24
|
-
|
|
25
|
-
authStore.state.refreshToken = '';
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
authStore.state.refreshToken = localStorage.getItem('refreshToken');
|
|
29
|
-
}
|
|
23
|
+
authStore.state.refreshToken = (_a = storage.getRefreshToken()) !== null && _a !== void 0 ? _a : '';
|
|
30
24
|
}
|
|
31
25
|
registerFetchInterceptor() {
|
|
32
26
|
fetchIntercept.register({
|
|
@@ -57,52 +51,23 @@ export class EzpPrintService {
|
|
|
57
51
|
});
|
|
58
52
|
}
|
|
59
53
|
getPrinterList(accessToken) {
|
|
60
|
-
return
|
|
61
|
-
method: 'GET',
|
|
62
|
-
headers: {
|
|
63
|
-
Authorization: 'Bearer ' + accessToken,
|
|
64
|
-
},
|
|
65
|
-
}).then((response) => response.json());
|
|
54
|
+
return authGetJson(`https://${this.printingApi}/sfapi/GetPrinter/`, accessToken);
|
|
66
55
|
}
|
|
67
56
|
async getConfig(accessToken) {
|
|
68
57
|
return fetch(`https://${this.printingApi}/sfapi/GetConfiguration/`, {
|
|
69
58
|
method: 'GET',
|
|
70
|
-
headers:
|
|
71
|
-
Authorization: 'Bearer ' + accessToken,
|
|
72
|
-
},
|
|
59
|
+
headers: bearer(accessToken),
|
|
73
60
|
});
|
|
74
61
|
}
|
|
75
62
|
getPrinterProperties(accessToken, printerID) {
|
|
76
|
-
return
|
|
77
|
-
method: 'GET',
|
|
78
|
-
headers: {
|
|
79
|
-
Authorization: 'Bearer ' + accessToken,
|
|
80
|
-
},
|
|
81
|
-
}).then((response) => {
|
|
82
|
-
return response.json();
|
|
83
|
-
});
|
|
63
|
+
return authGetJson(`https://${this.printingApi}/sfapi/GetPrinterProperties/?id=${printerID}`, accessToken);
|
|
84
64
|
}
|
|
85
65
|
getAllPrinterProperties(accessToken) {
|
|
86
|
-
return
|
|
87
|
-
method: 'GET',
|
|
88
|
-
headers: {
|
|
89
|
-
Authorization: 'Bearer ' + accessToken,
|
|
90
|
-
},
|
|
91
|
-
}).then((response) => {
|
|
92
|
-
return response.json();
|
|
93
|
-
});
|
|
66
|
+
return authGetJson(`https://${this.printingApi}/sfapi/GetPrinterProperties/`, accessToken);
|
|
94
67
|
}
|
|
95
68
|
printFileByUrl(accessToken, fileUrl, fileType, printerID, properties, filename, printAndDelete) {
|
|
96
69
|
this.abortController = new AbortController();
|
|
97
|
-
return
|
|
98
|
-
method: 'POST',
|
|
99
|
-
headers: {
|
|
100
|
-
Authorization: 'Bearer ' + accessToken,
|
|
101
|
-
'Content-Type': 'application/json',
|
|
102
|
-
},
|
|
103
|
-
body: JSON.stringify(Object.assign(Object.assign(Object.assign({ fileurl: fileUrl, type: fileType, printerid: printerID }, (filename && { alias: filename })), (printAndDelete && { printanddelete: printAndDelete })), { properties })),
|
|
104
|
-
signal: this.abortController.signal
|
|
105
|
-
});
|
|
70
|
+
return this.printRequest(accessToken, Object.assign(Object.assign(Object.assign({ fileurl: fileUrl, type: fileType, printerid: printerID }, (filename && { alias: filename })), (printAndDelete && { printanddelete: printAndDelete })), { properties }), this.abortController.signal);
|
|
106
71
|
}
|
|
107
72
|
abortPrint() {
|
|
108
73
|
if (this.abortController) {
|
|
@@ -110,33 +75,20 @@ export class EzpPrintService {
|
|
|
110
75
|
this.abortController = null;
|
|
111
76
|
}
|
|
112
77
|
}
|
|
113
|
-
|
|
78
|
+
/** Shared POST to the `Print` endpoint. Returns the raw response. */
|
|
79
|
+
printRequest(accessToken, body, signal) {
|
|
114
80
|
return fetch(`https://${this.printingApi}/sfapi/Print/`, {
|
|
115
81
|
method: 'POST',
|
|
116
|
-
headers: {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
body: JSON.stringify(Object.assign(Object.assign(Object.assign({ fileid: fileID, type: fileType, printerid: printerID }, (filename && { alias: filename })), (printAndDelete && { printanddelete: printAndDelete })), { properties })),
|
|
121
|
-
}).then((response) => response.json());
|
|
82
|
+
headers: Object.assign(Object.assign({}, bearer(accessToken)), { 'Content-Type': 'application/json' }),
|
|
83
|
+
body: JSON.stringify(body),
|
|
84
|
+
signal,
|
|
85
|
+
});
|
|
122
86
|
}
|
|
123
|
-
|
|
124
|
-
return
|
|
125
|
-
method: 'GET',
|
|
126
|
-
headers: {
|
|
127
|
-
Authorization: 'Bearer ' + accessToken,
|
|
128
|
-
},
|
|
129
|
-
}).then((response) => response.json());
|
|
87
|
+
printByFileID(accessToken, fileID, fileType, printerID, properties, filename, printAndDelete) {
|
|
88
|
+
return this.printRequest(accessToken, Object.assign(Object.assign(Object.assign({ fileid: fileID, type: fileType, printerid: printerID }, (filename && { alias: filename })), (printAndDelete && { printanddelete: printAndDelete })), { properties })).then((response) => response.json());
|
|
130
89
|
}
|
|
131
|
-
|
|
132
|
-
return
|
|
133
|
-
method: 'PUT',
|
|
134
|
-
headers: {
|
|
135
|
-
'x-ms-blob-type': 'BlockBlob',
|
|
136
|
-
'Content-Type:': 'multipart/form-data', // try and not set it, see if it does it automatically
|
|
137
|
-
},
|
|
138
|
-
body: formData,
|
|
139
|
-
}).then((response) => response.json());
|
|
90
|
+
prepareFileUpload(accessToken) {
|
|
91
|
+
return authGetJson(`https://${this.printingApi}/sfapi/PrepareUpload/`, accessToken);
|
|
140
92
|
}
|
|
141
93
|
async uploadBlobFiles(sasUri, file) {
|
|
142
94
|
printStore.state.uploadProgress = 0;
|
|
@@ -153,7 +105,7 @@ export class EzpPrintService {
|
|
|
153
105
|
blockSize: 4 * 1024 * 1024, //4mb blocksize
|
|
154
106
|
concurrency: 20,
|
|
155
107
|
onProgress: (e) => {
|
|
156
|
-
|
|
108
|
+
const progress = (100 * e.loadedBytes) / file.size;
|
|
157
109
|
printStore.state.uploadProgress = progress;
|
|
158
110
|
},
|
|
159
111
|
blobHTTPHeaders: { blobContentType: 'application/octet-stream' },
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
import { createStore } from "@stencil/store";
|
|
2
2
|
import authStore from "./auth";
|
|
3
|
+
import { authGetJson } from "./http";
|
|
3
4
|
export class EzpUserService {
|
|
4
5
|
getUserInfo() {
|
|
5
|
-
return
|
|
6
|
-
headers: {
|
|
7
|
-
Authorization: 'Bearer ' + authStore.state.accessToken,
|
|
8
|
-
'Content-Type': 'application/json',
|
|
9
|
-
},
|
|
10
|
-
method: 'GET',
|
|
11
|
-
}).then((response) => {
|
|
12
|
-
return response.json();
|
|
13
|
-
});
|
|
6
|
+
return authGetJson(`https://${authStore.state.authApiHostUrl}/v1/users/me`, authStore.state.accessToken);
|
|
14
7
|
}
|
|
15
8
|
}
|
|
16
9
|
const userStore = createStore({
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralised magic numbers used across the print/auth flow.
|
|
3
|
+
*
|
|
4
|
+
* These previously appeared as inline literals in `ezp-printer-selection`,
|
|
5
|
+
* `print.ts` and `utils.ts`, with the same job-status codes duplicated across
|
|
6
|
+
* three separate state machines. Keep them here so the meaning is explicit and
|
|
7
|
+
* there is a single source of truth.
|
|
8
|
+
*/
|
|
9
|
+
/** Print-job status codes returned by `sfapi/Status`. */
|
|
10
|
+
export var JobStatus;
|
|
11
|
+
(function (JobStatus) {
|
|
12
|
+
JobStatus[JobStatus["Success"] = 0] = "Success";
|
|
13
|
+
/** Job accepted / spooling — keep polling. */
|
|
14
|
+
JobStatus[JobStatus["Processing"] = 1246] = "Processing";
|
|
15
|
+
/** Job rendering — keep polling. */
|
|
16
|
+
JobStatus[JobStatus["Rendering"] = 129] = "Rendering";
|
|
17
|
+
JobStatus[JobStatus["Failed"] = 3011] = "Failed";
|
|
18
|
+
/** Generic failure. */
|
|
19
|
+
JobStatus[JobStatus["Error"] = 2] = "Error";
|
|
20
|
+
})(JobStatus || (JobStatus = {}));
|
|
21
|
+
/** Status codes that mean "still working — keep polling". */
|
|
22
|
+
export const PROCESSING_JOB_STATUSES = [
|
|
23
|
+
JobStatus.Processing,
|
|
24
|
+
JobStatus.Rendering,
|
|
25
|
+
];
|
|
26
|
+
/** Status codes that mean "terminal failure". */
|
|
27
|
+
export const FAILED_JOB_STATUSES = [JobStatus.Failed, JobStatus.Error];
|
|
28
|
+
/**
|
|
29
|
+
* Status/error codes that, for hub (queue) printers, indicate the print driver
|
|
30
|
+
* is missing or misconfigured rather than a transient failure. Surfaced to the
|
|
31
|
+
* user as a distinct "driver error" message.
|
|
32
|
+
*/
|
|
33
|
+
export const HUB_DRIVER_ERROR_CODES = [412, 500, 503, 1048579];
|
|
34
|
+
/** `Print` response `code` meaning the upload expired and a fileid re-print is required. */
|
|
35
|
+
export const FILE_EXPIRED_STATUS = 412;
|
|
36
|
+
/** `Print` response `code` meaning the job was rejected outright. */
|
|
37
|
+
export const PRINT_REJECTED_CODE = 804;
|
|
38
|
+
/** Successful Azure Blob upload (`uploadData`) HTTP status. */
|
|
39
|
+
export const BLOB_UPLOAD_CREATED = 201;
|
|
40
|
+
/** Paper-format id that represents a custom (user-defined width/length) size. */
|
|
41
|
+
export const PAPER_ID = 256;
|
|
42
|
+
/** Print-status polling cadence and bounds. */
|
|
43
|
+
export const POLL_INTERVAL_MS = 2000;
|
|
44
|
+
/**
|
|
45
|
+
* Overall polling budget before a still-processing job is treated as failed.
|
|
46
|
+
* Prevents polling the status endpoint indefinitely on a stuck job (only hub
|
|
47
|
+
* printers had a timeout before). Generous — 10 minutes — to tolerate slow
|
|
48
|
+
* server-side rendering of large documents.
|
|
49
|
+
*/
|
|
50
|
+
export const POLL_TIMEOUT_MS = 10 * 60 * 1000;
|
|
51
|
+
export const MAX_POLL_ATTEMPTS = Math.ceil(POLL_TIMEOUT_MS / POLL_INTERVAL_MS);
|
|
52
|
+
/** Fallback timeout for hub printers so the UI never hangs indefinitely. */
|
|
53
|
+
export const HUB_TIMEOUT_MS = 30000;
|
|
54
|
+
/** How often the access token is proactively refreshed, in seconds. */
|
|
55
|
+
export const TOKEN_REFRESH_INTERVAL_S = 1800;
|
|
@@ -3,7 +3,13 @@ export default async () => {
|
|
|
3
3
|
style: 'normal',
|
|
4
4
|
weight: '400 600',
|
|
5
5
|
});
|
|
6
|
-
font
|
|
6
|
+
font
|
|
7
|
+
.load()
|
|
8
|
+
.then(() => {
|
|
7
9
|
document.fonts.add(font);
|
|
10
|
+
})
|
|
11
|
+
.catch(() => {
|
|
12
|
+
// The remote webfont is a progressive enhancement; if it can't be
|
|
13
|
+
// fetched (offline, blocked, CI without egress) fall back silently.
|
|
8
14
|
});
|
|
9
15
|
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single typed entry point for the `localStorage` keys this library persists.
|
|
3
|
+
*
|
|
4
|
+
* Previously these keys were referenced as string literals in ~30 places across
|
|
5
|
+
* services and components, with inconsistent naming (`access_token` vs
|
|
6
|
+
* `refreshToken`). The literal key strings are preserved here exactly so that
|
|
7
|
+
* users who are already signed in keep their session across an upgrade.
|
|
8
|
+
*/
|
|
9
|
+
/** Persisted localStorage keys. Do not change the string values — see note above. */
|
|
10
|
+
const KEY = {
|
|
11
|
+
accessToken: 'access_token',
|
|
12
|
+
refreshToken: 'refreshToken',
|
|
13
|
+
isAuthorized: 'isAuthorized',
|
|
14
|
+
properties: 'properties',
|
|
15
|
+
printer: 'printer',
|
|
16
|
+
};
|
|
17
|
+
function getJSON(key) {
|
|
18
|
+
const raw = localStorage.getItem(key);
|
|
19
|
+
if (raw === null)
|
|
20
|
+
return null;
|
|
21
|
+
try {
|
|
22
|
+
return JSON.parse(raw);
|
|
23
|
+
}
|
|
24
|
+
catch (_a) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export const storage = {
|
|
29
|
+
// Note: the access token is intentionally NOT persisted (kept in memory only,
|
|
30
|
+
// for XSS defense-in-depth). `clearSession` still removes any legacy value.
|
|
31
|
+
getRefreshToken() {
|
|
32
|
+
return localStorage.getItem(KEY.refreshToken);
|
|
33
|
+
},
|
|
34
|
+
setRefreshToken(token) {
|
|
35
|
+
localStorage.setItem(KEY.refreshToken, token);
|
|
36
|
+
},
|
|
37
|
+
getIsAuthorized() {
|
|
38
|
+
return localStorage.getItem(KEY.isAuthorized) === 'true';
|
|
39
|
+
},
|
|
40
|
+
setIsAuthorized(value) {
|
|
41
|
+
localStorage.setItem(KEY.isAuthorized, value.toString());
|
|
42
|
+
},
|
|
43
|
+
hasIsAuthorized() {
|
|
44
|
+
return localStorage.getItem(KEY.isAuthorized) !== null;
|
|
45
|
+
},
|
|
46
|
+
getProperties() {
|
|
47
|
+
return getJSON(KEY.properties);
|
|
48
|
+
},
|
|
49
|
+
setProperties(properties) {
|
|
50
|
+
localStorage.setItem(KEY.properties, JSON.stringify(properties));
|
|
51
|
+
},
|
|
52
|
+
getPrinter() {
|
|
53
|
+
return getJSON(KEY.printer);
|
|
54
|
+
},
|
|
55
|
+
setPrinter(printer) {
|
|
56
|
+
localStorage.setItem(KEY.printer, JSON.stringify(printer));
|
|
57
|
+
},
|
|
58
|
+
/** Remove everything tied to the current session (used on logout). */
|
|
59
|
+
clearSession() {
|
|
60
|
+
localStorage.removeItem(KEY.properties);
|
|
61
|
+
localStorage.removeItem(KEY.refreshToken);
|
|
62
|
+
localStorage.removeItem(KEY.accessToken);
|
|
63
|
+
localStorage.removeItem(KEY.printer);
|
|
64
|
+
localStorage.removeItem(KEY.isAuthorized);
|
|
65
|
+
},
|
|
66
|
+
/** Remove just the saved printer + its properties (used when the saved printer is gone). */
|
|
67
|
+
clearSavedPrinter() {
|
|
68
|
+
localStorage.removeItem(KEY.printer);
|
|
69
|
+
localStorage.removeItem(KEY.properties);
|
|
70
|
+
},
|
|
71
|
+
};
|