@ezeep/ezeep-js 1.0.148 → 1.0.154
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/ezeep.cjs.js +3 -3
- package/dist/cjs/ezp-auth_14.cjs.entry.js +118 -67
- package/dist/cjs/{index-62fc857c.js → index-d547be4e.js} +23 -0
- package/dist/cjs/loader.cjs.js +3 -3
- package/dist/collection/collection-manifest.json +2 -2
- package/dist/collection/components/ezp-auth/ezp-auth.js +1 -3
- package/dist/collection/components/ezp-dialog/ezp-dialog.js +0 -2
- package/dist/collection/components/ezp-printer-selection/ezp-printer-selection.js +87 -52
- package/dist/collection/components/ezp-printing/ezp-printing.js +24 -3
- package/dist/collection/components/ezp-status/ezp-status.js +0 -2
- package/dist/collection/components/ezp-upload/ezp-upload.js +0 -2
- package/dist/collection/components/ezp-user-menu/ezp-user-menu.js +0 -2
- package/dist/collection/services/auth.js +2 -0
- package/dist/collection/utils/utils.js +20 -8
- package/dist/components/auth.js +504 -0
- package/dist/components/ezp-auth.d.ts +11 -0
- package/dist/components/ezp-auth.js +6 -0
- package/dist/components/ezp-auth2.js +141 -0
- package/dist/components/ezp-backdrop.d.ts +11 -0
- package/dist/components/ezp-backdrop.js +6 -0
- package/dist/components/ezp-backdrop2.js +46 -0
- package/dist/components/ezp-dialog.d.ts +11 -0
- package/dist/components/ezp-dialog.js +6 -0
- package/dist/components/ezp-dialog2.js +92 -0
- package/dist/components/ezp-icon-button.d.ts +11 -0
- package/dist/components/ezp-icon-button.js +6 -0
- package/dist/components/ezp-icon-button2.js +70 -0
- package/dist/components/ezp-icon.d.ts +11 -0
- package/dist/components/ezp-icon.js +6 -0
- package/dist/components/ezp-icon2.js +58 -0
- package/dist/components/ezp-label.d.ts +11 -0
- package/dist/components/ezp-label.js +6 -0
- package/dist/components/ezp-label2.js +57 -0
- package/dist/components/ezp-printer-selection.d.ts +11 -0
- package/dist/components/ezp-printer-selection.js +6 -0
- package/dist/{custom-elements/index.js → components/ezp-printer-selection2.js} +8225 -12189
- package/dist/components/ezp-printing.d.ts +11 -0
- package/dist/components/ezp-printing.js +271 -0
- package/dist/components/ezp-select.d.ts +11 -0
- package/dist/components/ezp-select.js +6 -0
- package/dist/components/ezp-select2.js +194 -0
- package/dist/components/ezp-status.d.ts +11 -0
- package/dist/components/ezp-status.js +6 -0
- package/dist/components/ezp-status2.js +94 -0
- package/dist/components/ezp-stepper.d.ts +11 -0
- package/dist/components/ezp-stepper.js +6 -0
- package/dist/components/ezp-stepper2.js +119 -0
- package/dist/components/ezp-text-button.d.ts +11 -0
- package/dist/components/ezp-text-button.js +6 -0
- package/dist/components/ezp-text-button2.js +73 -0
- package/dist/components/ezp-upload.d.ts +11 -0
- package/dist/components/ezp-upload.js +6 -0
- package/dist/components/ezp-upload2.js +95 -0
- package/dist/components/ezp-user-menu.d.ts +11 -0
- package/dist/components/ezp-user-menu.js +6 -0
- package/dist/components/ezp-user-menu2.js +159 -0
- package/dist/components/i18next.js +2653 -0
- package/dist/components/index.d.ts +26 -0
- package/dist/components/index.js +15 -0
- package/dist/directives/proxies.ts +2 -2
- package/dist/esm/ezeep.js +3 -3
- package/dist/esm/ezp-auth_14.entry.js +118 -67
- package/dist/esm/{index-265d8cca.js → index-485041ac.js} +23 -0
- package/dist/esm/loader.js +3 -3
- package/dist/esm/polyfills/css-shim.js +1 -1
- package/dist/esm-es5/ezeep.js +1 -1
- package/dist/esm-es5/ezp-auth_14.entry.js +3 -3
- package/dist/esm-es5/index-485041ac.js +1 -0
- package/dist/esm-es5/loader.js +1 -1
- package/dist/ezeep/ezeep.esm.js +1 -1
- package/dist/ezeep/ezeep.js +1 -1
- package/dist/ezeep/p-0b51d725.system.entry.js +21 -0
- package/dist/ezeep/{p-a7b7b386.entry.js → p-b6ec69dc.entry.js} +2 -2
- package/dist/ezeep/p-cc2bb341.system.js +1 -0
- package/dist/ezeep/p-d4dae139.system.js +1 -0
- package/dist/ezeep/{p-f3065800.js → p-fa808a39.js} +0 -0
- package/dist/types/components/ezp-printer-selection/ezp-printer-selection.d.ts +1 -1
- package/dist/types/components/ezp-printing/ezp-printing.d.ts +1 -0
- package/dist/types/components.d.ts +2 -0
- package/dist/types/stencil-public-runtime.d.ts +6 -4
- package/dist/types/utils/utils.d.ts +1 -1
- package/package.json +4 -4
- package/readme.md +6 -3
- package/www/build/ezeep.esm.js +1 -1
- package/www/build/ezeep.js +1 -1
- package/www/build/p-0b51d725.system.entry.js +21 -0
- package/www/build/{p-a7b7b386.entry.js → p-b6ec69dc.entry.js} +2 -2
- package/www/build/p-cc2bb341.system.js +1 -0
- package/www/build/p-d4dae139.system.js +1 -0
- package/www/build/{p-f3065800.js → p-fa808a39.js} +0 -0
- package/www/data/locales/en.json +6 -1
- package/www/index.html +1 -1
- package/dist/custom-elements/index.d.ts +0 -123
- package/dist/esm-es5/index-265d8cca.js +0 -1
- package/dist/ezeep/p-98ec6965.system.js +0 -1
- package/dist/ezeep/p-a1b0d17a.system.entry.js +0 -21
- package/dist/ezeep/p-f89804ee.system.js +0 -1
- package/www/build/p-98ec6965.system.js +0 -1
- package/www/build/p-a1b0d17a.system.entry.js +0 -21
- package/www/build/p-f89804ee.system.js +0 -1
|
@@ -0,0 +1,504 @@
|
|
|
1
|
+
import { getRenderingRef, forceUpdate } from '@stencil/core/internal/client';
|
|
2
|
+
import { i as i18next } from './i18next.js';
|
|
3
|
+
|
|
4
|
+
const appendToMap = (map, propName, value) => {
|
|
5
|
+
const items = map.get(propName);
|
|
6
|
+
if (!items) {
|
|
7
|
+
map.set(propName, [value]);
|
|
8
|
+
}
|
|
9
|
+
else if (!items.includes(value)) {
|
|
10
|
+
items.push(value);
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const debounce = (fn, ms) => {
|
|
14
|
+
let timeoutId;
|
|
15
|
+
return (...args) => {
|
|
16
|
+
if (timeoutId) {
|
|
17
|
+
clearTimeout(timeoutId);
|
|
18
|
+
}
|
|
19
|
+
timeoutId = setTimeout(() => {
|
|
20
|
+
timeoutId = 0;
|
|
21
|
+
fn(...args);
|
|
22
|
+
}, ms);
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Check if a possible element isConnected.
|
|
28
|
+
* The property might not be there, so we check for it.
|
|
29
|
+
*
|
|
30
|
+
* We want it to return true if isConnected is not a property,
|
|
31
|
+
* otherwise we would remove these elements and would not update.
|
|
32
|
+
*
|
|
33
|
+
* Better leak in Edge than to be useless.
|
|
34
|
+
*/
|
|
35
|
+
const isConnected = (maybeElement) => !('isConnected' in maybeElement) || maybeElement.isConnected;
|
|
36
|
+
const cleanupElements = debounce((map) => {
|
|
37
|
+
for (let key of map.keys()) {
|
|
38
|
+
map.set(key, map.get(key).filter(isConnected));
|
|
39
|
+
}
|
|
40
|
+
}, 2000);
|
|
41
|
+
const stencilSubscription = ({ on }) => {
|
|
42
|
+
const elmsToUpdate = new Map();
|
|
43
|
+
if (typeof getRenderingRef === 'function') {
|
|
44
|
+
// If we are not in a stencil project, we do nothing.
|
|
45
|
+
// This function is not really exported by @stencil/core.
|
|
46
|
+
on('dispose', () => {
|
|
47
|
+
elmsToUpdate.clear();
|
|
48
|
+
});
|
|
49
|
+
on('get', (propName) => {
|
|
50
|
+
const elm = getRenderingRef();
|
|
51
|
+
if (elm) {
|
|
52
|
+
appendToMap(elmsToUpdate, propName, elm);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
on('set', (propName) => {
|
|
56
|
+
const elements = elmsToUpdate.get(propName);
|
|
57
|
+
if (elements) {
|
|
58
|
+
elmsToUpdate.set(propName, elements.filter(forceUpdate));
|
|
59
|
+
}
|
|
60
|
+
cleanupElements(elmsToUpdate);
|
|
61
|
+
});
|
|
62
|
+
on('reset', () => {
|
|
63
|
+
elmsToUpdate.forEach((elms) => elms.forEach(forceUpdate));
|
|
64
|
+
cleanupElements(elmsToUpdate);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const createObservableMap = (defaultState, shouldUpdate = (a, b) => a !== b) => {
|
|
70
|
+
let states = new Map(Object.entries(defaultState !== null && defaultState !== void 0 ? defaultState : {}));
|
|
71
|
+
const handlers = {
|
|
72
|
+
dispose: [],
|
|
73
|
+
get: [],
|
|
74
|
+
set: [],
|
|
75
|
+
reset: [],
|
|
76
|
+
};
|
|
77
|
+
const reset = () => {
|
|
78
|
+
states = new Map(Object.entries(defaultState !== null && defaultState !== void 0 ? defaultState : {}));
|
|
79
|
+
handlers.reset.forEach((cb) => cb());
|
|
80
|
+
};
|
|
81
|
+
const dispose = () => {
|
|
82
|
+
// Call first dispose as resetting the state would
|
|
83
|
+
// cause less updates ;)
|
|
84
|
+
handlers.dispose.forEach((cb) => cb());
|
|
85
|
+
reset();
|
|
86
|
+
};
|
|
87
|
+
const get = (propName) => {
|
|
88
|
+
handlers.get.forEach((cb) => cb(propName));
|
|
89
|
+
return states.get(propName);
|
|
90
|
+
};
|
|
91
|
+
const set = (propName, value) => {
|
|
92
|
+
const oldValue = states.get(propName);
|
|
93
|
+
if (shouldUpdate(value, oldValue, propName)) {
|
|
94
|
+
states.set(propName, value);
|
|
95
|
+
handlers.set.forEach((cb) => cb(propName, value, oldValue));
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
const state = (typeof Proxy === 'undefined'
|
|
99
|
+
? {}
|
|
100
|
+
: new Proxy(defaultState, {
|
|
101
|
+
get(_, propName) {
|
|
102
|
+
return get(propName);
|
|
103
|
+
},
|
|
104
|
+
ownKeys(_) {
|
|
105
|
+
return Array.from(states.keys());
|
|
106
|
+
},
|
|
107
|
+
getOwnPropertyDescriptor() {
|
|
108
|
+
return {
|
|
109
|
+
enumerable: true,
|
|
110
|
+
configurable: true,
|
|
111
|
+
};
|
|
112
|
+
},
|
|
113
|
+
has(_, propName) {
|
|
114
|
+
return states.has(propName);
|
|
115
|
+
},
|
|
116
|
+
set(_, propName, value) {
|
|
117
|
+
set(propName, value);
|
|
118
|
+
return true;
|
|
119
|
+
},
|
|
120
|
+
}));
|
|
121
|
+
const on = (eventName, callback) => {
|
|
122
|
+
handlers[eventName].push(callback);
|
|
123
|
+
return () => {
|
|
124
|
+
removeFromArray(handlers[eventName], callback);
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
const onChange = (propName, cb) => {
|
|
128
|
+
const unSet = on('set', (key, newValue) => {
|
|
129
|
+
if (key === propName) {
|
|
130
|
+
cb(newValue);
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
const unReset = on('reset', () => cb(defaultState[propName]));
|
|
134
|
+
return () => {
|
|
135
|
+
unSet();
|
|
136
|
+
unReset();
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
const use = (...subscriptions) => subscriptions.forEach((subscription) => {
|
|
140
|
+
if (subscription.set) {
|
|
141
|
+
on('set', subscription.set);
|
|
142
|
+
}
|
|
143
|
+
if (subscription.get) {
|
|
144
|
+
on('get', subscription.get);
|
|
145
|
+
}
|
|
146
|
+
if (subscription.reset) {
|
|
147
|
+
on('reset', subscription.reset);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
const forceUpdate = (key) => {
|
|
151
|
+
const oldValue = states.get(key);
|
|
152
|
+
handlers.set.forEach((cb) => cb(key, oldValue, oldValue));
|
|
153
|
+
};
|
|
154
|
+
return {
|
|
155
|
+
state,
|
|
156
|
+
get,
|
|
157
|
+
set,
|
|
158
|
+
on,
|
|
159
|
+
onChange,
|
|
160
|
+
use,
|
|
161
|
+
dispose,
|
|
162
|
+
reset,
|
|
163
|
+
forceUpdate,
|
|
164
|
+
};
|
|
165
|
+
};
|
|
166
|
+
const removeFromArray = (array, item) => {
|
|
167
|
+
const index = array.indexOf(item);
|
|
168
|
+
if (index >= 0) {
|
|
169
|
+
array[index] = array[array.length - 1];
|
|
170
|
+
array.length--;
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const createStore = (defaultState, shouldUpdate) => {
|
|
175
|
+
const map = createObservableMap(defaultState, shouldUpdate);
|
|
176
|
+
stencilSubscription(map);
|
|
177
|
+
return map;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const login_dialog$1 = {
|
|
181
|
+
heading: "Drucke mit ezeep Blue",
|
|
182
|
+
description: "Melde dich mit deinem ezeep Blue-Konto an, um zu drucken.",
|
|
183
|
+
action: "Anmelden"
|
|
184
|
+
};
|
|
185
|
+
const no_document_dialog$1 = {
|
|
186
|
+
heading: "Keine Datei ausgewählt",
|
|
187
|
+
description: "Wähle zunächst eine Datei zum Drucken aus.",
|
|
188
|
+
action: "OK"
|
|
189
|
+
};
|
|
190
|
+
const printer_selection$1 = {
|
|
191
|
+
loading: "Lade meine Drucker…",
|
|
192
|
+
print: "Drucken",
|
|
193
|
+
printer: "Drucker",
|
|
194
|
+
print_processing: "Drucken…",
|
|
195
|
+
print_success: "Erfolgreich gedruckt.",
|
|
196
|
+
print_failed: "Druck fehlgeschlagen",
|
|
197
|
+
not_supported: "Der ausgewählte Dateityp wird nicht unterstützt.",
|
|
198
|
+
color: "Farbe",
|
|
199
|
+
orientation: "Ausrichtung",
|
|
200
|
+
size: "Papierformat",
|
|
201
|
+
duplex: "Beidseitig",
|
|
202
|
+
quality: "Druckqualität",
|
|
203
|
+
select_printer: "Wähle einen Drucker",
|
|
204
|
+
select_color: "Wähle Farbe/Graustufen",
|
|
205
|
+
select_size: "Wähle Papierformat",
|
|
206
|
+
select_orientation: "Wähle Ausrichtung",
|
|
207
|
+
select_quality: "Wähle Druckqualität",
|
|
208
|
+
select_duplex: "Wähle Beidseitig",
|
|
209
|
+
color_color: "Farbe",
|
|
210
|
+
color_grayscale: "Graustufen",
|
|
211
|
+
orientation_portrait: "Hochformat",
|
|
212
|
+
orientation_landscape: "Querformat",
|
|
213
|
+
unknown_location: "Unbekannter Standort",
|
|
214
|
+
no_printers: "Keine Drucker gefunden.",
|
|
215
|
+
prepare_upload: "Vorbereiten…",
|
|
216
|
+
uploading: "Hochladen…"
|
|
217
|
+
};
|
|
218
|
+
const button_actions$1 = {
|
|
219
|
+
login: "Anmelden",
|
|
220
|
+
print: "Drucken",
|
|
221
|
+
cancel: "Abbrechen",
|
|
222
|
+
close: "Schließen",
|
|
223
|
+
retry: "Wiederholen"
|
|
224
|
+
};
|
|
225
|
+
const upload$1 = {
|
|
226
|
+
description: "Ziehe eine Datei hier in den Browser ",
|
|
227
|
+
meta_leading: "oder",
|
|
228
|
+
meta_select: "wähle eine Datei aus",
|
|
229
|
+
meta_trailing: "um mit ezeep Blue zu drucken."
|
|
230
|
+
};
|
|
231
|
+
const user_menu$1 = {
|
|
232
|
+
theme: "Farbschema",
|
|
233
|
+
appearance: "Erscheinungsbild",
|
|
234
|
+
system: "System",
|
|
235
|
+
light: "Hell",
|
|
236
|
+
dark: "Dunkel",
|
|
237
|
+
account: "Account verwalten",
|
|
238
|
+
help: "Hilfe & Support",
|
|
239
|
+
logout: "Ausloggen"
|
|
240
|
+
};
|
|
241
|
+
const translationsDE = {
|
|
242
|
+
login_dialog: login_dialog$1,
|
|
243
|
+
no_document_dialog: no_document_dialog$1,
|
|
244
|
+
printer_selection: printer_selection$1,
|
|
245
|
+
button_actions: button_actions$1,
|
|
246
|
+
upload: upload$1,
|
|
247
|
+
user_menu: user_menu$1
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const login_dialog = {
|
|
251
|
+
heading: "Print with ezeep Blue",
|
|
252
|
+
description: "Sign in with your ezeep Blue account to print.",
|
|
253
|
+
action: "Sign in"
|
|
254
|
+
};
|
|
255
|
+
const no_document_dialog = {
|
|
256
|
+
heading: "No file selected",
|
|
257
|
+
description: "Select a file first to print.",
|
|
258
|
+
action: "OK"
|
|
259
|
+
};
|
|
260
|
+
const printer_selection = {
|
|
261
|
+
loading: "Loading My Printers…",
|
|
262
|
+
print_processing: "Printing…",
|
|
263
|
+
print_success: "Successfully printed.",
|
|
264
|
+
print_failed: "Print failed",
|
|
265
|
+
not_supported: "The selected file type is not supported.",
|
|
266
|
+
prepare_upload: "Preparing…",
|
|
267
|
+
uploading: "Uploading…",
|
|
268
|
+
print: "Print",
|
|
269
|
+
printer: "Printer",
|
|
270
|
+
color: "Color",
|
|
271
|
+
orientation: "Orientation",
|
|
272
|
+
size: "Paper Size",
|
|
273
|
+
duplex: "Double-sided",
|
|
274
|
+
duplex_none: "None",
|
|
275
|
+
duplex_long: "Long edge binding",
|
|
276
|
+
duplex_short: "Short edge binding",
|
|
277
|
+
quality: "Print Quality",
|
|
278
|
+
select_printer: "Select a printer",
|
|
279
|
+
select_color: "Select Color/Grayscale",
|
|
280
|
+
select_orientation: "Select Orientation",
|
|
281
|
+
select_size: "Select Paper Size",
|
|
282
|
+
select_quality: "Select Print Quality",
|
|
283
|
+
select_duplex: "Select Double-sided",
|
|
284
|
+
color_color: "Color",
|
|
285
|
+
color_grayscale: "Grayscale",
|
|
286
|
+
orientation_portrait: "Portrait",
|
|
287
|
+
orientation_landscape: "Landscape",
|
|
288
|
+
unknown_location: "Unknown location",
|
|
289
|
+
no_printers: "No printers found.",
|
|
290
|
+
copies: "Copies"
|
|
291
|
+
};
|
|
292
|
+
const button_actions = {
|
|
293
|
+
login: "Sign In",
|
|
294
|
+
print: "Print",
|
|
295
|
+
cancel: "Cancel",
|
|
296
|
+
close: "Close",
|
|
297
|
+
retry: "Retry"
|
|
298
|
+
};
|
|
299
|
+
const upload = {
|
|
300
|
+
description: "Drop a file here into the browser ",
|
|
301
|
+
meta_leading: "or",
|
|
302
|
+
meta_select: "select a file",
|
|
303
|
+
meta_trailing: "to print with ezeep Blue."
|
|
304
|
+
};
|
|
305
|
+
const user_menu = {
|
|
306
|
+
theme: "Color theme",
|
|
307
|
+
appearance: "Appearance",
|
|
308
|
+
system: "System",
|
|
309
|
+
light: "Light",
|
|
310
|
+
dark: "Dark",
|
|
311
|
+
account: "Manage account",
|
|
312
|
+
help: "Help & support",
|
|
313
|
+
logout: "Logout"
|
|
314
|
+
};
|
|
315
|
+
const translationsEN = {
|
|
316
|
+
login_dialog: login_dialog,
|
|
317
|
+
no_document_dialog: no_document_dialog,
|
|
318
|
+
printer_selection: printer_selection,
|
|
319
|
+
button_actions: button_actions,
|
|
320
|
+
upload: upload,
|
|
321
|
+
user_menu: user_menu
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
function encodeFormData(data) {
|
|
325
|
+
return Object.keys(data)
|
|
326
|
+
.map((key) => encodeURIComponent(key) + '=' + encodeURIComponent(data[key]))
|
|
327
|
+
.join('&');
|
|
328
|
+
}
|
|
329
|
+
function initi18n(language) {
|
|
330
|
+
const resources = {
|
|
331
|
+
en: {
|
|
332
|
+
translation: translationsEN,
|
|
333
|
+
},
|
|
334
|
+
de: {
|
|
335
|
+
translation: translationsDE,
|
|
336
|
+
},
|
|
337
|
+
};
|
|
338
|
+
// override browserlanguage if language is provided
|
|
339
|
+
if (language != '') {
|
|
340
|
+
i18next.init({
|
|
341
|
+
resources,
|
|
342
|
+
lng: language,
|
|
343
|
+
// allow keys to be phrases having `:`, `.`
|
|
344
|
+
nsSeparator: false,
|
|
345
|
+
fallbackLng: 'en',
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
i18next.init({
|
|
350
|
+
resources,
|
|
351
|
+
lng: navigator.language,
|
|
352
|
+
// allow keys to be phrases having `:`, `.`
|
|
353
|
+
nsSeparator: false,
|
|
354
|
+
fallbackLng: 'en',
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
const poll = async ({ fn, validate, interval, maxAttempts }) => {
|
|
359
|
+
let attempts = 0;
|
|
360
|
+
const executePoll = async (resolve, reject) => {
|
|
361
|
+
const result = await fn();
|
|
362
|
+
attempts++;
|
|
363
|
+
if (validate(result)) {
|
|
364
|
+
return resolve(result);
|
|
365
|
+
}
|
|
366
|
+
else if (maxAttempts && attempts === maxAttempts) {
|
|
367
|
+
return reject(new Error('Exceeded max attempts.'));
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
370
|
+
setTimeout(executePoll, interval, resolve, reject);
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
return new Promise(executePoll);
|
|
374
|
+
};
|
|
375
|
+
const removeEmptyStrings = (obj) => {
|
|
376
|
+
let newObj = {};
|
|
377
|
+
Object.keys(obj).forEach((prop) => {
|
|
378
|
+
if (obj[prop] !== '') {
|
|
379
|
+
newObj[prop] = obj[prop];
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
return newObj;
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
class EzpAuthorizationService {
|
|
386
|
+
constructor(redirectURI, clientID) {
|
|
387
|
+
this.urlParams = new URLSearchParams();
|
|
388
|
+
this.isAuthorized = false;
|
|
389
|
+
this.redirectURI = redirectURI;
|
|
390
|
+
this.clientID = clientID;
|
|
391
|
+
this.oauthUrl = authStore.state.authApiHostUrl;
|
|
392
|
+
this.authURI = new URL(`https://${this.oauthUrl}/oauth/authorize/`);
|
|
393
|
+
this.accessTokenURL = `https://${this.oauthUrl}/oauth/access_token/`;
|
|
394
|
+
}
|
|
395
|
+
generateCodeVerifier() {
|
|
396
|
+
if (authStore.state.codeVerifier !== '') {
|
|
397
|
+
this.codeVerifier = authStore.state.codeVerifier;
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
const arr = new Uint8Array(128);
|
|
401
|
+
const randomValueArray = crypto.getRandomValues(arr);
|
|
402
|
+
const codeVerifier = btoa(randomValueArray.toString()).substr(0, 128);
|
|
403
|
+
this.codeVerifier = codeVerifier;
|
|
404
|
+
authStore.state.codeVerifier = this.codeVerifier;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
async generateCodeChallenge(codeVerifier) {
|
|
408
|
+
const encoder = new TextEncoder();
|
|
409
|
+
const codeData = encoder.encode(codeVerifier);
|
|
410
|
+
const digest = await crypto.subtle.digest('SHA-256', codeData);
|
|
411
|
+
const base64Digest = btoa(String.fromCharCode.apply(null, new Uint8Array(digest)));
|
|
412
|
+
this.codeChallenge = base64Digest.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
413
|
+
}
|
|
414
|
+
buildAuthURI() {
|
|
415
|
+
this.urlParams.append('response_type', 'code');
|
|
416
|
+
this.urlParams.append('client_id', this.clientID);
|
|
417
|
+
this.urlParams.append('redirect_uri', this.redirectURI);
|
|
418
|
+
this.urlParams.append('code_challenge', this.codeChallenge);
|
|
419
|
+
this.urlParams.append('code_challenge_method', 'S256');
|
|
420
|
+
this.authURI.search = this.urlParams.toString();
|
|
421
|
+
}
|
|
422
|
+
getAccessToken() {
|
|
423
|
+
return fetch(this.accessTokenURL, {
|
|
424
|
+
credentials: 'include',
|
|
425
|
+
headers: {
|
|
426
|
+
Authorization: 'Basic ' + btoa(this.clientID + ':'),
|
|
427
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
428
|
+
},
|
|
429
|
+
method: 'POST',
|
|
430
|
+
body: encodeFormData({
|
|
431
|
+
grant_type: 'authorization_code',
|
|
432
|
+
scope: 'printing',
|
|
433
|
+
code: this.code,
|
|
434
|
+
redirect_uri: this.redirectURI,
|
|
435
|
+
code_verifier: this.codeVerifier,
|
|
436
|
+
}),
|
|
437
|
+
})
|
|
438
|
+
.then((response) => {
|
|
439
|
+
return response.json(); // parse response
|
|
440
|
+
})
|
|
441
|
+
.then((data) => {
|
|
442
|
+
// actual object
|
|
443
|
+
if (data.access_token) {
|
|
444
|
+
authStore.state.isAuthorized = true;
|
|
445
|
+
this.isAuthorized = authStore.state.isAuthorized;
|
|
446
|
+
localStorage.setItem('isAuthorized', this.isAuthorized.toString());
|
|
447
|
+
this.accessToken = data.access_token;
|
|
448
|
+
localStorage.setItem('access_token', this.accessToken);
|
|
449
|
+
authStore.state.accessToken = this.accessToken;
|
|
450
|
+
this.refreshToken = data.refresh_token;
|
|
451
|
+
localStorage.setItem('refreshToken', this.refreshToken);
|
|
452
|
+
authStore.state.refreshToken = this.refreshToken;
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
refreshTokens() {
|
|
457
|
+
fetch(this.accessTokenURL, {
|
|
458
|
+
credentials: 'include',
|
|
459
|
+
headers: {
|
|
460
|
+
Authorization: 'Basic ' + btoa(this.clientID + ':'),
|
|
461
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
462
|
+
},
|
|
463
|
+
method: 'POST',
|
|
464
|
+
body: encodeFormData({
|
|
465
|
+
grant_type: 'refresh_token',
|
|
466
|
+
scope: 'printing',
|
|
467
|
+
refresh_token: authStore.state.refreshToken,
|
|
468
|
+
}),
|
|
469
|
+
})
|
|
470
|
+
.then((response) => response.json())
|
|
471
|
+
.then((data) => {
|
|
472
|
+
if (data.access_token) {
|
|
473
|
+
this.accessToken = data.access_token;
|
|
474
|
+
localStorage.setItem('access_token', this.accessToken);
|
|
475
|
+
authStore.state.accessToken = this.accessToken;
|
|
476
|
+
this.refreshToken = data.refresh_token;
|
|
477
|
+
localStorage.setItem('refreshToken', this.refreshToken);
|
|
478
|
+
authStore.state.refreshToken = this.refreshToken;
|
|
479
|
+
authStore.state.isAuthorized = true;
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
const authStore = createStore({
|
|
485
|
+
codeVerifier: '',
|
|
486
|
+
accessToken: '',
|
|
487
|
+
refreshToken: '',
|
|
488
|
+
isAuthorized: false,
|
|
489
|
+
devApi: false,
|
|
490
|
+
authApiHostUrl: '',
|
|
491
|
+
redirectUri: '',
|
|
492
|
+
});
|
|
493
|
+
function sendCodeToParentWindow() {
|
|
494
|
+
// get the URL parameters which will include the auth code
|
|
495
|
+
const params = new URLSearchParams(window.location.search);
|
|
496
|
+
const code = params.get('code');
|
|
497
|
+
if (window.opener) {
|
|
498
|
+
// send them to the opening window
|
|
499
|
+
window.opener.postMessage(code, authStore.state.redirectUri);
|
|
500
|
+
window.close();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
export { EzpAuthorizationService as E, authStore as a, createStore as c, initi18n as i, poll as p, removeEmptyStrings as r, sendCodeToParentWindow as s };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Components, JSX } from "../types/components";
|
|
2
|
+
|
|
3
|
+
interface EzpAuth extends Components.EzpAuth, HTMLElement {}
|
|
4
|
+
export const EzpAuth: {
|
|
5
|
+
prototype: EzpAuth;
|
|
6
|
+
new (): EzpAuth;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Used to define this component and all nested components recursively.
|
|
10
|
+
*/
|
|
11
|
+
export const defineCustomElement: () => void;
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { HTMLElement, createEvent, h, Host, proxyCustomElement } from '@stencil/core/internal/client';
|
|
2
|
+
import { E as EzpAuthorizationService, a as authStore } from './auth.js';
|
|
3
|
+
import { i as i18next } from './i18next.js';
|
|
4
|
+
import { d as defineCustomElement$6 } from './ezp-dialog2.js';
|
|
5
|
+
import { d as defineCustomElement$5 } from './ezp-icon2.js';
|
|
6
|
+
import { d as defineCustomElement$4 } from './ezp-icon-button2.js';
|
|
7
|
+
import { d as defineCustomElement$3 } from './ezp-label2.js';
|
|
8
|
+
import { d as defineCustomElement$2 } from './ezp-status2.js';
|
|
9
|
+
import { d as defineCustomElement$1 } from './ezp-text-button2.js';
|
|
10
|
+
|
|
11
|
+
const ezpAuthCss = ":host{--ezp-color-theme-solid:var(--ezp-color-cyan-solid);--ezp-color-theme-translucent:var(--ezp-color-cyan-translucent);display:block}";
|
|
12
|
+
|
|
13
|
+
let EzpAuth = class extends HTMLElement {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.__registerHost();
|
|
17
|
+
this.__attachShadow();
|
|
18
|
+
this.authCancel = createEvent(this, "authCancel", 7);
|
|
19
|
+
this.authSuccess = createEvent(this, "authSuccess", 7);
|
|
20
|
+
this.windowObjectReference = null;
|
|
21
|
+
this.previousUrl = null;
|
|
22
|
+
}
|
|
23
|
+
listenDialogAction() {
|
|
24
|
+
this.openSignInWindow(this.auth.authURI.toString(), 'ezeep Login');
|
|
25
|
+
}
|
|
26
|
+
listenDialogClose() {
|
|
27
|
+
this.authCancel.emit();
|
|
28
|
+
}
|
|
29
|
+
openSignInWindow(url, name) {
|
|
30
|
+
// remove any existing event listeners
|
|
31
|
+
window.removeEventListener('message', this.receiveMessage);
|
|
32
|
+
// window features
|
|
33
|
+
const strWindowFeatures = 'toolbar=no, menubar=no, width=600, height=7000, top=100, left=100';
|
|
34
|
+
if (this.windowObjectReference === null || this.windowObjectReference.closed) {
|
|
35
|
+
/* if the pointer to the window object in memory does not exist
|
|
36
|
+
or if such pointer exists but the window was closed */
|
|
37
|
+
this.windowObjectReference = window.open(url, name, strWindowFeatures);
|
|
38
|
+
}
|
|
39
|
+
else if (this.previousUrl !== this.auth.authURI.toString()) {
|
|
40
|
+
/* if the resource to load is different,
|
|
41
|
+
then we load it in the already opened secondary window and then
|
|
42
|
+
we bring such window back on top/in front of its parent window. */
|
|
43
|
+
this.windowObjectReference = window.open(url, name, strWindowFeatures);
|
|
44
|
+
this.windowObjectReference.focus();
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
/* else the window reference must exist and the window
|
|
48
|
+
is not closed; therefore, we can bring it back on top of any other
|
|
49
|
+
window with the focus() method. There would be no need to re-create
|
|
50
|
+
the window or to reload the referenced resource. */
|
|
51
|
+
this.windowObjectReference.focus();
|
|
52
|
+
}
|
|
53
|
+
// check if the window was closed and cancel login accordingly
|
|
54
|
+
if (this.hidelogin) {
|
|
55
|
+
let checkClosedTimer = setInterval(() => {
|
|
56
|
+
if (this.windowObjectReference.closed) {
|
|
57
|
+
this.authCancel.emit();
|
|
58
|
+
clearInterval(checkClosedTimer);
|
|
59
|
+
}
|
|
60
|
+
}, 500);
|
|
61
|
+
}
|
|
62
|
+
// add the listener for receiving a message from the popup
|
|
63
|
+
window.addEventListener('message', (event) => this.receiveMessage(event), false);
|
|
64
|
+
this.previousUrl = this.auth.authURI;
|
|
65
|
+
}
|
|
66
|
+
receiveMessage(event) {
|
|
67
|
+
this.auth.code = event.data;
|
|
68
|
+
this.auth.getAccessToken().then(() => {
|
|
69
|
+
this.authCancel.emit();
|
|
70
|
+
this.authSuccess.emit();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
async componentWillLoad() {
|
|
74
|
+
this.auth = new EzpAuthorizationService(this.redirectURI, this.clientID);
|
|
75
|
+
if (authStore.state.isAuthorized === false) {
|
|
76
|
+
this.auth.generateCodeVerifier();
|
|
77
|
+
await this.auth.generateCodeChallenge(authStore.state.codeVerifier);
|
|
78
|
+
this.auth.buildAuthURI();
|
|
79
|
+
}
|
|
80
|
+
if (this.hidelogin) {
|
|
81
|
+
this.openSignInWindow(this.auth.authURI.toString(), 'ezeep Login');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
render() {
|
|
85
|
+
return this.hidelogin ? (h("ezp-status", { description: i18next.t('login_dialog.action'), processing: true })) : (h(Host, null, h("ezp-dialog", { heading: i18next.t('login_dialog.heading'), description: i18next.t('login_dialog.description'), action: i18next.t('login_dialog.action'), iconName: "logo", iconSize: "huge", iconFramed: false, instance: "login" })));
|
|
86
|
+
}
|
|
87
|
+
static get style() { return ezpAuthCss; }
|
|
88
|
+
};
|
|
89
|
+
EzpAuth = /*@__PURE__*/ proxyCustomElement(EzpAuth, [1, "ezp-auth", {
|
|
90
|
+
"clientID": [1025, "client-i-d"],
|
|
91
|
+
"redirectURI": [1025, "redirect-u-r-i"],
|
|
92
|
+
"hidelogin": [4],
|
|
93
|
+
"auth": [32],
|
|
94
|
+
"authURI": [32],
|
|
95
|
+
"accessToken": [32]
|
|
96
|
+
}, [[0, "dialogAction", "listenDialogAction"], [0, "dialogClose", "listenDialogClose"]]]);
|
|
97
|
+
function defineCustomElement() {
|
|
98
|
+
if (typeof customElements === "undefined") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const components = ["ezp-auth", "ezp-dialog", "ezp-icon", "ezp-icon-button", "ezp-label", "ezp-status", "ezp-text-button"];
|
|
102
|
+
components.forEach(tagName => { switch (tagName) {
|
|
103
|
+
case "ezp-auth":
|
|
104
|
+
if (!customElements.get(tagName)) {
|
|
105
|
+
customElements.define(tagName, EzpAuth);
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case "ezp-dialog":
|
|
109
|
+
if (!customElements.get(tagName)) {
|
|
110
|
+
defineCustomElement$6();
|
|
111
|
+
}
|
|
112
|
+
break;
|
|
113
|
+
case "ezp-icon":
|
|
114
|
+
if (!customElements.get(tagName)) {
|
|
115
|
+
defineCustomElement$5();
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case "ezp-icon-button":
|
|
119
|
+
if (!customElements.get(tagName)) {
|
|
120
|
+
defineCustomElement$4();
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
case "ezp-label":
|
|
124
|
+
if (!customElements.get(tagName)) {
|
|
125
|
+
defineCustomElement$3();
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
case "ezp-status":
|
|
129
|
+
if (!customElements.get(tagName)) {
|
|
130
|
+
defineCustomElement$2();
|
|
131
|
+
}
|
|
132
|
+
break;
|
|
133
|
+
case "ezp-text-button":
|
|
134
|
+
if (!customElements.get(tagName)) {
|
|
135
|
+
defineCustomElement$1();
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
} });
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export { EzpAuth as E, defineCustomElement as d };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Components, JSX } from "../types/components";
|
|
2
|
+
|
|
3
|
+
interface EzpBackdrop extends Components.EzpBackdrop, HTMLElement {}
|
|
4
|
+
export const EzpBackdrop: {
|
|
5
|
+
prototype: EzpBackdrop;
|
|
6
|
+
new (): EzpBackdrop;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Used to define this component and all nested components recursively.
|
|
10
|
+
*/
|
|
11
|
+
export const defineCustomElement: () => void;
|