@vaadin/hilla-frontend 24.4.0-alpha4

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/CsrfUtils.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /** @internal */
2
+ export declare const VAADIN_CSRF_HEADER = "X-CSRF-Token";
3
+ /** @internal */
4
+ export declare const VAADIN_CSRF_COOKIE_NAME = "csrfToken";
5
+ /** @internal */
6
+ export declare const SPRING_CSRF_COOKIE_NAME = "XSRF-TOKEN";
7
+ /** @internal */
8
+ export declare function getSpringCsrfInfo(doc: Document): Record<string, string>;
9
+ /** @internal */
10
+ export declare function getSpringCsrfTokenHeadersForAuthRequest(doc: Document): Record<string, string>;
11
+ /** @internal */
12
+ export declare function getCsrfTokenHeadersForEndpointRequest(doc: Document): Record<string, string>;
13
+ //# sourceMappingURL=CsrfUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CsrfUtils.d.ts","sourceRoot":"","sources":["src/CsrfUtils.ts"],"names":[],"mappings":"AAEA,gBAAgB;AAChB,eAAO,MAAM,kBAAkB,iBAAiB,CAAC;AACjD,gBAAgB;AAChB,eAAO,MAAM,uBAAuB,cAAc,CAAC;AACnD,gBAAgB;AAChB,eAAO,MAAM,uBAAuB,eAAe,CAAC;AAwBpD,gBAAgB;AAChB,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAavE;AAED,gBAAgB;AAChB,wBAAgB,uCAAuC,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAO7F;AAED,gBAAgB;AAChB,wBAAgB,qCAAqC,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAW3F"}
package/CsrfUtils.js ADDED
@@ -0,0 +1,61 @@
1
+ import CookieManager from "./CookieManager.js";
2
+ const VAADIN_CSRF_HEADER = "X-CSRF-Token";
3
+ const VAADIN_CSRF_COOKIE_NAME = "csrfToken";
4
+ const SPRING_CSRF_COOKIE_NAME = "XSRF-TOKEN";
5
+ function extractContentFromMetaTag(element) {
6
+ if (element) {
7
+ const value = element.content;
8
+ if (value && value.toLowerCase() !== "undefined") {
9
+ return value;
10
+ }
11
+ }
12
+ return void 0;
13
+ }
14
+ function getSpringCsrfHeaderFromMetaTag(doc) {
15
+ const csrfHeader = doc.head.querySelector('meta[name="_csrf_header"]');
16
+ return extractContentFromMetaTag(csrfHeader);
17
+ }
18
+ function getSpringCsrfTokenFromMetaTag(doc) {
19
+ const csrfToken = doc.head.querySelector('meta[name="_csrf"]');
20
+ return extractContentFromMetaTag(csrfToken);
21
+ }
22
+ function getSpringCsrfInfo(doc) {
23
+ const csrfHeader = getSpringCsrfHeaderFromMetaTag(doc);
24
+ let csrf = CookieManager.get(SPRING_CSRF_COOKIE_NAME);
25
+ if (!csrf || csrf.length === 0) {
26
+ csrf = getSpringCsrfTokenFromMetaTag(doc);
27
+ }
28
+ const headers = {};
29
+ if (csrf && csrfHeader) {
30
+ headers._csrf = csrf;
31
+ headers._csrf_header = csrfHeader;
32
+ }
33
+ return headers;
34
+ }
35
+ function getSpringCsrfTokenHeadersForAuthRequest(doc) {
36
+ const csrfInfo = getSpringCsrfInfo(doc);
37
+ const headers = {};
38
+ if (csrfInfo._csrf && csrfInfo._csrf_header) {
39
+ headers[csrfInfo._csrf_header] = csrfInfo._csrf;
40
+ }
41
+ return headers;
42
+ }
43
+ function getCsrfTokenHeadersForEndpointRequest(doc) {
44
+ const headers = {};
45
+ const csrfInfo = getSpringCsrfInfo(doc);
46
+ if (csrfInfo._csrf && csrfInfo._csrf_header) {
47
+ headers[csrfInfo._csrf_header] = csrfInfo._csrf;
48
+ } else {
49
+ headers[VAADIN_CSRF_HEADER] = CookieManager.get(VAADIN_CSRF_COOKIE_NAME) ?? "";
50
+ }
51
+ return headers;
52
+ }
53
+ export {
54
+ SPRING_CSRF_COOKIE_NAME,
55
+ VAADIN_CSRF_COOKIE_NAME,
56
+ VAADIN_CSRF_HEADER,
57
+ getCsrfTokenHeadersForEndpointRequest,
58
+ getSpringCsrfInfo,
59
+ getSpringCsrfTokenHeadersForAuthRequest
60
+ };
61
+ //# sourceMappingURL=CsrfUtils.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/CsrfUtils.ts"],
4
+ "sourcesContent": ["import CookieManager from './CookieManager.js';\n\n/** @internal */\nexport const VAADIN_CSRF_HEADER = 'X-CSRF-Token';\n/** @internal */\nexport const VAADIN_CSRF_COOKIE_NAME = 'csrfToken';\n/** @internal */\nexport const SPRING_CSRF_COOKIE_NAME = 'XSRF-TOKEN';\n\nfunction extractContentFromMetaTag(element: HTMLMetaElement | null): string | undefined {\n if (element) {\n const value = element.content;\n if (value && value.toLowerCase() !== 'undefined') {\n return value;\n }\n }\n return undefined;\n}\n\n/** @internal */\nfunction getSpringCsrfHeaderFromMetaTag(doc: Document): string | undefined {\n const csrfHeader = doc.head.querySelector<HTMLMetaElement>('meta[name=\"_csrf_header\"]');\n return extractContentFromMetaTag(csrfHeader);\n}\n\n/** @internal */\nfunction getSpringCsrfTokenFromMetaTag(doc: Document): string | undefined {\n const csrfToken = doc.head.querySelector<HTMLMetaElement>('meta[name=\"_csrf\"]');\n return extractContentFromMetaTag(csrfToken);\n}\n\n/** @internal */\nexport function getSpringCsrfInfo(doc: Document): Record<string, string> {\n const csrfHeader = getSpringCsrfHeaderFromMetaTag(doc);\n let csrf = CookieManager.get(SPRING_CSRF_COOKIE_NAME);\n if (!csrf || csrf.length === 0) {\n csrf = getSpringCsrfTokenFromMetaTag(doc);\n }\n const headers: Record<string, string> = {};\n if (csrf && csrfHeader) {\n headers._csrf = csrf;\n // eslint-disable-next-line camelcase\n headers._csrf_header = csrfHeader;\n }\n return headers;\n}\n\n/** @internal */\nexport function getSpringCsrfTokenHeadersForAuthRequest(doc: Document): Record<string, string> {\n const csrfInfo = getSpringCsrfInfo(doc);\n const headers: Record<string, string> = {};\n if (csrfInfo._csrf && csrfInfo._csrf_header) {\n headers[csrfInfo._csrf_header] = csrfInfo._csrf;\n }\n return headers;\n}\n\n/** @internal */\nexport function getCsrfTokenHeadersForEndpointRequest(doc: Document): Record<string, string> {\n const headers: Record<string, string> = {};\n\n const csrfInfo = getSpringCsrfInfo(doc);\n if (csrfInfo._csrf && csrfInfo._csrf_header) {\n headers[csrfInfo._csrf_header] = csrfInfo._csrf;\n } else {\n headers[VAADIN_CSRF_HEADER] = CookieManager.get(VAADIN_CSRF_COOKIE_NAME) ?? '';\n }\n\n return headers;\n}\n"],
5
+ "mappings": "AAAA,OAAO,mBAAmB;AAGnB,MAAM,qBAAqB;AAE3B,MAAM,0BAA0B;AAEhC,MAAM,0BAA0B;AAEvC,SAAS,0BAA0B,SAAqD;AACtF,MAAI,SAAS;AACX,UAAM,QAAQ,QAAQ;AACtB,QAAI,SAAS,MAAM,YAAY,MAAM,aAAa;AAChD,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;AAGA,SAAS,+BAA+B,KAAmC;AACzE,QAAM,aAAa,IAAI,KAAK,cAA+B,2BAA2B;AACtF,SAAO,0BAA0B,UAAU;AAC7C;AAGA,SAAS,8BAA8B,KAAmC;AACxE,QAAM,YAAY,IAAI,KAAK,cAA+B,oBAAoB;AAC9E,SAAO,0BAA0B,SAAS;AAC5C;AAGO,SAAS,kBAAkB,KAAuC;AACvE,QAAM,aAAa,+BAA+B,GAAG;AACrD,MAAI,OAAO,cAAc,IAAI,uBAAuB;AACpD,MAAI,CAAC,QAAQ,KAAK,WAAW,GAAG;AAC9B,WAAO,8BAA8B,GAAG;AAAA,EAC1C;AACA,QAAM,UAAkC,CAAC;AACzC,MAAI,QAAQ,YAAY;AACtB,YAAQ,QAAQ;AAEhB,YAAQ,eAAe;AAAA,EACzB;AACA,SAAO;AACT;AAGO,SAAS,wCAAwC,KAAuC;AAC7F,QAAM,WAAW,kBAAkB,GAAG;AACtC,QAAM,UAAkC,CAAC;AACzC,MAAI,SAAS,SAAS,SAAS,cAAc;AAC3C,YAAQ,SAAS,YAAY,IAAI,SAAS;AAAA,EAC5C;AACA,SAAO;AACT;AAGO,SAAS,sCAAsC,KAAuC;AAC3F,QAAM,UAAkC,CAAC;AAEzC,QAAM,WAAW,kBAAkB,GAAG;AACtC,MAAI,SAAS,SAAS,SAAS,cAAc;AAC3C,YAAQ,SAAS,YAAY,IAAI,SAAS;AAAA,EAC5C,OAAO;AACL,YAAQ,kBAAkB,IAAI,cAAc,IAAI,uBAAuB,KAAK;AAAA,EAC9E;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,90 @@
1
+ /**
2
+ * An exception that gets thrown when the Vaadin backend responds
3
+ * with not ok status.
4
+ */
5
+ export declare class EndpointError extends Error {
6
+ /**
7
+ * The optional detail object, containing additional information sent
8
+ * from the backend
9
+ */
10
+ detail?: unknown;
11
+ /**
12
+ * The optional name of the exception that was thrown on a backend
13
+ */
14
+ type?: string;
15
+ /**
16
+ * @param message - the `message` property value
17
+ * @param type - the `type` property value
18
+ * @param detail - the `detail` property value
19
+ */
20
+ constructor(message: string, type?: string, detail?: unknown);
21
+ }
22
+ /**
23
+ * An exception that gets thrown if Vaadin endpoint responds
24
+ * with non-ok status and provides additional info
25
+ * on the validation errors occurred.
26
+ */
27
+ export declare class EndpointValidationError extends EndpointError {
28
+ /**
29
+ * An array of the validation errors.
30
+ */
31
+ validationErrorData: ValidationErrorData[];
32
+ /**
33
+ * An original validation error message.
34
+ */
35
+ validationErrorMessage: string;
36
+ /**
37
+ * @param message - the `message` property value
38
+ * @param validationErrorData - the `validationErrorData` property value
39
+ * @param type - the `type` property value
40
+ */
41
+ constructor(message: string, validationErrorData: ValidationErrorData[], type?: string);
42
+ }
43
+ /**
44
+ * An exception that gets thrown for unexpected HTTP response.
45
+ */
46
+ export declare class EndpointResponseError extends EndpointError {
47
+ /**
48
+ * The optional response object, containing the HTTP response error
49
+ */
50
+ response: Response;
51
+ /**
52
+ * @param message - the `message` property value
53
+ * @param response - the `response` property value
54
+ */
55
+ constructor(message: string, response: Response);
56
+ /**
57
+ * Convenience property to get the HTTP code status directly
58
+ */
59
+ get status(): number;
60
+ }
61
+ export declare class UnauthorizedResponseError extends EndpointResponseError {
62
+ constructor(message: string, response: Response);
63
+ }
64
+ export declare class ForbiddenResponseError extends EndpointResponseError {
65
+ constructor(message: string, response: Response);
66
+ }
67
+ /**
68
+ * An object, containing all data for the particular validation error.
69
+ */
70
+ export declare class ValidationErrorData {
71
+ /**
72
+ * The validation error message.
73
+ */
74
+ message: string;
75
+ /**
76
+ * The parameter name that caused the validation error.
77
+ */
78
+ parameterName?: string;
79
+ /**
80
+ * Validator original message
81
+ */
82
+ validatorMessage?: string;
83
+ /**
84
+ * @param message - The `message` property value
85
+ * @param parameterName - The `parameterName` property value
86
+ * @param validatorMessage - The `validatorMessage` property value
87
+ */
88
+ constructor(message: string, parameterName?: string, validatorMessage?: string);
89
+ }
90
+ //# sourceMappingURL=EndpointErrors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EndpointErrors.d.ts","sourceRoot":"","sources":["src/EndpointErrors.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,qBAAa,aAAc,SAAQ,KAAK;IACtC;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,OAAO;CAK7D;AAED;;;;GAIG;AACH,qBAAa,uBAAwB,SAAQ,aAAa;IACxD;;OAEG;IACH,mBAAmB,EAAE,mBAAmB,EAAE,CAAC;IAC3C;;OAEG;IACH,sBAAsB,EAAE,MAAM,CAAC;IAE/B;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM;CAMvF;AAED;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,aAAa;IACtD;;OAEG;IACH,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;;OAGG;gBACS,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;IAK/C;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;CACF;AAED,qBAAa,yBAA0B,SAAQ,qBAAqB;gBACtD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;CAIhD;AAED,qBAAa,sBAAuB,SAAQ,qBAAqB;gBACnD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ;CAIhD;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;;OAIG;gBACS,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,gBAAgB,CAAC,EAAE,MAAM;CAK/E"}
@@ -0,0 +1,107 @@
1
+ class EndpointError extends Error {
2
+ /**
3
+ * The optional detail object, containing additional information sent
4
+ * from the backend
5
+ */
6
+ detail;
7
+ /**
8
+ * The optional name of the exception that was thrown on a backend
9
+ */
10
+ type;
11
+ /**
12
+ * @param message - the `message` property value
13
+ * @param type - the `type` property value
14
+ * @param detail - the `detail` property value
15
+ */
16
+ constructor(message, type, detail) {
17
+ super(message);
18
+ this.type = type;
19
+ this.detail = detail;
20
+ }
21
+ }
22
+ class EndpointValidationError extends EndpointError {
23
+ /**
24
+ * An array of the validation errors.
25
+ */
26
+ validationErrorData;
27
+ /**
28
+ * An original validation error message.
29
+ */
30
+ validationErrorMessage;
31
+ /**
32
+ * @param message - the `message` property value
33
+ * @param validationErrorData - the `validationErrorData` property value
34
+ * @param type - the `type` property value
35
+ */
36
+ constructor(message, validationErrorData, type) {
37
+ super(message, type, validationErrorData);
38
+ this.validationErrorMessage = message;
39
+ this.detail = null;
40
+ this.validationErrorData = validationErrorData;
41
+ }
42
+ }
43
+ class EndpointResponseError extends EndpointError {
44
+ /**
45
+ * The optional response object, containing the HTTP response error
46
+ */
47
+ response;
48
+ /**
49
+ * @param message - the `message` property value
50
+ * @param response - the `response` property value
51
+ */
52
+ constructor(message, response) {
53
+ super(message, "EndpointResponseError", response);
54
+ this.response = response;
55
+ }
56
+ /**
57
+ * Convenience property to get the HTTP code status directly
58
+ */
59
+ get status() {
60
+ return this.response.status;
61
+ }
62
+ }
63
+ class UnauthorizedResponseError extends EndpointResponseError {
64
+ constructor(message, response) {
65
+ super(message, response);
66
+ this.type = "UnauthorizedResponseError";
67
+ }
68
+ }
69
+ class ForbiddenResponseError extends EndpointResponseError {
70
+ constructor(message, response) {
71
+ super(message, response);
72
+ this.type = "ForbiddenResponseError";
73
+ }
74
+ }
75
+ class ValidationErrorData {
76
+ /**
77
+ * The validation error message.
78
+ */
79
+ message;
80
+ /**
81
+ * The parameter name that caused the validation error.
82
+ */
83
+ parameterName;
84
+ /**
85
+ * Validator original message
86
+ */
87
+ validatorMessage;
88
+ /**
89
+ * @param message - The `message` property value
90
+ * @param parameterName - The `parameterName` property value
91
+ * @param validatorMessage - The `validatorMessage` property value
92
+ */
93
+ constructor(message, parameterName, validatorMessage) {
94
+ this.message = message;
95
+ this.parameterName = parameterName;
96
+ this.validatorMessage = validatorMessage;
97
+ }
98
+ }
99
+ export {
100
+ EndpointError,
101
+ EndpointResponseError,
102
+ EndpointValidationError,
103
+ ForbiddenResponseError,
104
+ UnauthorizedResponseError,
105
+ ValidationErrorData
106
+ };
107
+ //# sourceMappingURL=EndpointErrors.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/EndpointErrors.ts"],
4
+ "sourcesContent": ["/**\n * An exception that gets thrown when the Vaadin backend responds\n * with not ok status.\n */\nexport class EndpointError extends Error {\n /**\n * The optional detail object, containing additional information sent\n * from the backend\n */\n detail?: unknown;\n /**\n * The optional name of the exception that was thrown on a backend\n */\n type?: string;\n\n /**\n * @param message - the `message` property value\n * @param type - the `type` property value\n * @param detail - the `detail` property value\n */\n constructor(message: string, type?: string, detail?: unknown) {\n super(message);\n this.type = type;\n this.detail = detail;\n }\n}\n\n/**\n * An exception that gets thrown if Vaadin endpoint responds\n * with non-ok status and provides additional info\n * on the validation errors occurred.\n */\nexport class EndpointValidationError extends EndpointError {\n /**\n * An array of the validation errors.\n */\n validationErrorData: ValidationErrorData[];\n /**\n * An original validation error message.\n */\n validationErrorMessage: string;\n\n /**\n * @param message - the `message` property value\n * @param validationErrorData - the `validationErrorData` property value\n * @param type - the `type` property value\n */\n constructor(message: string, validationErrorData: ValidationErrorData[], type?: string) {\n super(message, type, validationErrorData);\n this.validationErrorMessage = message;\n this.detail = null;\n this.validationErrorData = validationErrorData;\n }\n}\n\n/**\n * An exception that gets thrown for unexpected HTTP response.\n */\nexport class EndpointResponseError extends EndpointError {\n /**\n * The optional response object, containing the HTTP response error\n */\n response: Response;\n\n /**\n * @param message - the `message` property value\n * @param response - the `response` property value\n */\n constructor(message: string, response: Response) {\n super(message, 'EndpointResponseError', response);\n this.response = response;\n }\n\n /**\n * Convenience property to get the HTTP code status directly\n */\n get status(): number {\n return this.response.status;\n }\n}\n\nexport class UnauthorizedResponseError extends EndpointResponseError {\n constructor(message: string, response: Response) {\n super(message, response);\n this.type = 'UnauthorizedResponseError';\n }\n}\n\nexport class ForbiddenResponseError extends EndpointResponseError {\n constructor(message: string, response: Response) {\n super(message, response);\n this.type = 'ForbiddenResponseError';\n }\n}\n\n/**\n * An object, containing all data for the particular validation error.\n */\nexport class ValidationErrorData {\n /**\n * The validation error message.\n */\n message: string;\n\n /**\n * The parameter name that caused the validation error.\n */\n parameterName?: string;\n\n /**\n * Validator original message\n */\n validatorMessage?: string;\n\n /**\n * @param message - The `message` property value\n * @param parameterName - The `parameterName` property value\n * @param validatorMessage - The `validatorMessage` property value\n */\n constructor(message: string, parameterName?: string, validatorMessage?: string) {\n this.message = message;\n this.parameterName = parameterName;\n this.validatorMessage = validatorMessage;\n }\n}\n"],
5
+ "mappings": "AAIO,MAAM,sBAAsB,MAAM;AAAA;AAAA;AAAA;AAAA;AAAA,EAKvC;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,SAAiB,MAAe,QAAkB;AAC5D,UAAM,OAAO;AACb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AAOO,MAAM,gCAAgC,cAAc;AAAA;AAAA;AAAA;AAAA,EAIzD;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,SAAiB,qBAA4C,MAAe;AACtF,UAAM,SAAS,MAAM,mBAAmB;AACxC,SAAK,yBAAyB;AAC9B,SAAK,SAAS;AACd,SAAK,sBAAsB;AAAA,EAC7B;AACF;AAKO,MAAM,8BAA8B,cAAc;AAAA;AAAA;AAAA;AAAA,EAIvD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,YAAY,SAAiB,UAAoB;AAC/C,UAAM,SAAS,yBAAyB,QAAQ;AAChD,SAAK,WAAW;AAAA,EAClB;AAAA;AAAA;AAAA;AAAA,EAKA,IAAI,SAAiB;AACnB,WAAO,KAAK,SAAS;AAAA,EACvB;AACF;AAEO,MAAM,kCAAkC,sBAAsB;AAAA,EACnE,YAAY,SAAiB,UAAoB;AAC/C,UAAM,SAAS,QAAQ;AACvB,SAAK,OAAO;AAAA,EACd;AACF;AAEO,MAAM,+BAA+B,sBAAsB;AAAA,EAChE,YAAY,SAAiB,UAAoB;AAC/C,UAAM,SAAS,QAAQ;AACvB,SAAK,OAAO;AAAA,EACd;AACF;AAKO,MAAM,oBAAoB;AAAA;AAAA;AAAA;AAAA,EAI/B;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA,EAKA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,YAAY,SAAiB,eAAwB,kBAA2B;AAC9E,SAAK,UAAU;AACf,SAAK,gBAAgB;AACrB,SAAK,mBAAmB;AAAA,EAC1B;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,38 @@
1
+ /// <reference types="atmosphere.js" />
2
+ import type { Subscription } from './Connect.js';
3
+ export declare enum State {
4
+ ACTIVE = "active",
5
+ INACTIVE = "inactive"
6
+ }
7
+ type ActiveEvent = CustomEvent<{
8
+ active: boolean;
9
+ }>;
10
+ interface EventMap {
11
+ 'state-changed': ActiveEvent;
12
+ }
13
+ type ListenerType<T extends keyof EventMap> = ((this: FluxConnection, ev: EventMap[T]) => any) | {
14
+ handleEvent(ev: EventMap[T]): void;
15
+ } | null;
16
+ /**
17
+ * A representation of the underlying persistent network connection used for subscribing to Flux type endpoint methods.
18
+ */
19
+ export declare class FluxConnection extends EventTarget {
20
+ #private;
21
+ state: State;
22
+ constructor(connectPrefix: string, atmosphereOptions?: Partial<Atmosphere.Request>);
23
+ /**
24
+ * Subscribes to the flux returned by the given endpoint name + method name using the given parameters.
25
+ *
26
+ * @param endpointName - the endpoint to connect to
27
+ * @param methodName - the method in the endpoint to connect to
28
+ * @param parameters - the parameters to use
29
+ * @returns a subscription
30
+ */
31
+ subscribe(endpointName: string, methodName: string, parameters?: unknown[]): Subscription<any>;
32
+ }
33
+ export interface FluxConnection {
34
+ addEventListener<T extends keyof EventMap>(type: T, listener: ListenerType<T>): void;
35
+ removeEventListener<T extends keyof EventMap>(type: T, listener: ListenerType<T>): void;
36
+ }
37
+ export {};
38
+ //# sourceMappingURL=FluxConnection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FluxConnection.d.ts","sourceRoot":"","sources":["src/FluxConnection.ts"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AASjD,oBAAY,KAAK;IACf,MAAM,WAAW;IACjB,QAAQ,aAAa;CACtB;AAED,KAAK,WAAW,GAAG,WAAW,CAAC;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AACpD,UAAU,QAAQ;IAChB,eAAe,EAAE,WAAW,CAAC;CAC9B;AAED,KAAK,YAAY,CAAC,CAAC,SAAS,MAAM,QAAQ,IACtC,CAAC,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,GAChD;IACE,WAAW,CAAC,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CACpC,GACD,IAAI,CAAC;AAET;;GAEG;AACH,qBAAa,cAAe,SAAQ,WAAW;;IAC7C,KAAK,EAAE,KAAK,CAAkB;gBASlB,aAAa,EAAE,MAAM,EAAE,iBAAiB,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC;IAKlF;;;;;;;OAOG;IACH,SAAS,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,OAAO,EAAE,GAAG,YAAY,CAAC,GAAG,CAAC;CA4I/F;AAED,MAAM,WAAW,cAAc;IAC7B,gBAAgB,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrF,mBAAmB,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;CACzF"}
@@ -0,0 +1,166 @@
1
+ import atmosphere from "atmosphere.js";
2
+ import { getCsrfTokenHeadersForEndpointRequest } from "./CsrfUtils.js";
3
+ import {
4
+ isClientMessage
5
+ } from "./FluxMessages.js";
6
+ var State = /* @__PURE__ */ ((State2) => {
7
+ State2["ACTIVE"] = "active";
8
+ State2["INACTIVE"] = "inactive";
9
+ return State2;
10
+ })(State || {});
11
+ class FluxConnection extends EventTarget {
12
+ state = "inactive" /* INACTIVE */;
13
+ #endpointInfos = /* @__PURE__ */ new Map();
14
+ #nextId = 0;
15
+ #onCompleteCallbacks = /* @__PURE__ */ new Map();
16
+ #onErrorCallbacks = /* @__PURE__ */ new Map();
17
+ #onNextCallbacks = /* @__PURE__ */ new Map();
18
+ #pendingMessages = [];
19
+ #socket;
20
+ constructor(connectPrefix, atmosphereOptions) {
21
+ super();
22
+ this.#connectWebsocket(connectPrefix.replace(/connect$/u, ""), atmosphereOptions ?? {});
23
+ }
24
+ /**
25
+ * Subscribes to the flux returned by the given endpoint name + method name using the given parameters.
26
+ *
27
+ * @param endpointName - the endpoint to connect to
28
+ * @param methodName - the method in the endpoint to connect to
29
+ * @param parameters - the parameters to use
30
+ * @returns a subscription
31
+ */
32
+ subscribe(endpointName, methodName, parameters) {
33
+ const id = this.#nextId.toString();
34
+ this.#nextId += 1;
35
+ const params = parameters ?? [];
36
+ const msg = { "@type": "subscribe", endpointName, id, methodName, params };
37
+ const endpointInfo = `${endpointName}.${methodName}(${JSON.stringify(params)})`;
38
+ this.#send(msg);
39
+ this.#endpointInfos.set(id, endpointInfo);
40
+ const hillaSubscription = {
41
+ cancel: () => {
42
+ if (!this.#endpointInfos.has(id)) {
43
+ return;
44
+ }
45
+ const closeMessage = { "@type": "unsubscribe", id };
46
+ this.#send(closeMessage);
47
+ this.#removeSubscription(id);
48
+ },
49
+ context(context) {
50
+ context.addController({
51
+ hostDisconnected() {
52
+ hillaSubscription.cancel();
53
+ }
54
+ });
55
+ return hillaSubscription;
56
+ },
57
+ onComplete: (callback) => {
58
+ this.#onCompleteCallbacks.set(id, callback);
59
+ return hillaSubscription;
60
+ },
61
+ onError: (callback) => {
62
+ this.#onErrorCallbacks.set(id, callback);
63
+ return hillaSubscription;
64
+ },
65
+ onNext: (callback) => {
66
+ this.#onNextCallbacks.set(id, callback);
67
+ return hillaSubscription;
68
+ }
69
+ };
70
+ return hillaSubscription;
71
+ }
72
+ #connectWebsocket(prefix, atmosphereOptions) {
73
+ const extraHeaders = getCsrfTokenHeadersForEndpointRequest(document);
74
+ const pushUrl = "HILLA/push";
75
+ const url = prefix.length === 0 ? pushUrl : (prefix.endsWith("/") ? prefix : `${prefix}/`) + pushUrl;
76
+ this.#socket = atmosphere.subscribe?.({
77
+ contentType: "application/json; charset=UTF-8",
78
+ enableProtocol: true,
79
+ fallbackTransport: "long-polling",
80
+ headers: extraHeaders,
81
+ maxReconnectOnClose: 1e7,
82
+ onClose: (_) => {
83
+ if (this.state === "active" /* ACTIVE */) {
84
+ this.state = "inactive" /* INACTIVE */;
85
+ this.dispatchEvent(new CustomEvent("state-changed", { detail: { active: false } }));
86
+ }
87
+ },
88
+ onError: (response) => {
89
+ console.error("error in push communication", response);
90
+ },
91
+ onMessage: (response) => {
92
+ if (response.responseBody) {
93
+ this.#handleMessage(JSON.parse(response.responseBody));
94
+ }
95
+ },
96
+ onOpen: (_response) => {
97
+ if (this.state === "inactive" /* INACTIVE */) {
98
+ this.state = "active" /* ACTIVE */;
99
+ this.dispatchEvent(new CustomEvent("state-changed", { detail: { active: true } }));
100
+ this.#sendPendingMessages();
101
+ }
102
+ },
103
+ onReopen: (_response) => {
104
+ if (this.state === "inactive" /* INACTIVE */) {
105
+ this.state = "active" /* ACTIVE */;
106
+ this.dispatchEvent(new CustomEvent("state-changed", { detail: { active: true } }));
107
+ this.#sendPendingMessages();
108
+ }
109
+ },
110
+ reconnectInterval: 5e3,
111
+ timeout: -1,
112
+ trackMessageLength: true,
113
+ transport: "websocket",
114
+ url,
115
+ ...atmosphereOptions
116
+ });
117
+ }
118
+ #handleMessage(message) {
119
+ if (isClientMessage(message)) {
120
+ const { id } = message;
121
+ const endpointInfo = this.#endpointInfos.get(id) ?? "unknown";
122
+ if (message["@type"] === "update") {
123
+ const callback = this.#onNextCallbacks.get(id);
124
+ if (callback) {
125
+ callback(message.item);
126
+ }
127
+ } else if (message["@type"] === "complete") {
128
+ this.#onCompleteCallbacks.get(id)?.();
129
+ this.#removeSubscription(id);
130
+ } else {
131
+ const callback = this.#onErrorCallbacks.get(id);
132
+ if (callback) {
133
+ callback();
134
+ }
135
+ this.#removeSubscription(id);
136
+ if (!callback) {
137
+ throw new Error(`Error in ${endpointInfo}: ${message.message}`);
138
+ }
139
+ }
140
+ } else {
141
+ throw new Error(`Unknown message from server: ${String(message)}`);
142
+ }
143
+ }
144
+ #removeSubscription(id) {
145
+ this.#onNextCallbacks.delete(id);
146
+ this.#onCompleteCallbacks.delete(id);
147
+ this.#onErrorCallbacks.delete(id);
148
+ this.#endpointInfos.delete(id);
149
+ }
150
+ #send(message) {
151
+ if (this.state === "inactive" /* INACTIVE */) {
152
+ this.#pendingMessages.push(message);
153
+ } else {
154
+ this.#socket?.push?.(JSON.stringify(message));
155
+ }
156
+ }
157
+ #sendPendingMessages() {
158
+ this.#pendingMessages.forEach((msg) => this.#send(msg));
159
+ this.#pendingMessages = [];
160
+ }
161
+ }
162
+ export {
163
+ FluxConnection,
164
+ State
165
+ };
166
+ //# sourceMappingURL=FluxConnection.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/FluxConnection.ts"],
4
+ "sourcesContent": ["import type { ReactiveControllerHost } from '@lit/reactive-element';\nimport atmosphere from 'atmosphere.js';\nimport type { Subscription } from './Connect.js';\nimport { getCsrfTokenHeadersForEndpointRequest } from './CsrfUtils.js';\nimport {\n isClientMessage,\n type ServerCloseMessage,\n type ServerConnectMessage,\n type ServerMessage,\n} from './FluxMessages.js';\n\nexport enum State {\n ACTIVE = 'active',\n INACTIVE = 'inactive',\n}\n\ntype ActiveEvent = CustomEvent<{ active: boolean }>;\ninterface EventMap {\n 'state-changed': ActiveEvent;\n}\n\ntype ListenerType<T extends keyof EventMap> =\n | ((this: FluxConnection, ev: EventMap[T]) => any)\n | {\n handleEvent(ev: EventMap[T]): void;\n }\n | null;\n\n/**\n * A representation of the underlying persistent network connection used for subscribing to Flux type endpoint methods.\n */\nexport class FluxConnection extends EventTarget {\n state: State = State.INACTIVE;\n readonly #endpointInfos = new Map<string, string>();\n #nextId = 0;\n readonly #onCompleteCallbacks = new Map<string, () => void>();\n readonly #onErrorCallbacks = new Map<string, () => void>();\n readonly #onNextCallbacks = new Map<string, (value: any) => void>();\n #pendingMessages: ServerMessage[] = [];\n #socket?: Atmosphere.Request;\n\n constructor(connectPrefix: string, atmosphereOptions?: Partial<Atmosphere.Request>) {\n super();\n this.#connectWebsocket(connectPrefix.replace(/connect$/u, ''), atmosphereOptions ?? {});\n }\n\n /**\n * Subscribes to the flux returned by the given endpoint name + method name using the given parameters.\n *\n * @param endpointName - the endpoint to connect to\n * @param methodName - the method in the endpoint to connect to\n * @param parameters - the parameters to use\n * @returns a subscription\n */\n subscribe(endpointName: string, methodName: string, parameters?: unknown[]): Subscription<any> {\n const id: string = this.#nextId.toString();\n this.#nextId += 1;\n const params = parameters ?? [];\n\n const msg: ServerConnectMessage = { '@type': 'subscribe', endpointName, id, methodName, params };\n const endpointInfo = `${endpointName}.${methodName}(${JSON.stringify(params)})`;\n this.#send(msg);\n this.#endpointInfos.set(id, endpointInfo);\n const hillaSubscription: Subscription<any> = {\n cancel: () => {\n if (!this.#endpointInfos.has(id)) {\n // Subscription already closed or canceled\n return;\n }\n\n const closeMessage: ServerCloseMessage = { '@type': 'unsubscribe', id };\n this.#send(closeMessage);\n this.#removeSubscription(id);\n },\n context(context: ReactiveControllerHost): Subscription<any> {\n context.addController({\n hostDisconnected() {\n hillaSubscription.cancel();\n },\n });\n return hillaSubscription;\n },\n onComplete: (callback: () => void): Subscription<any> => {\n this.#onCompleteCallbacks.set(id, callback);\n return hillaSubscription;\n },\n onError: (callback: () => void): Subscription<any> => {\n this.#onErrorCallbacks.set(id, callback);\n return hillaSubscription;\n },\n onNext: (callback: (value: any) => void): Subscription<any> => {\n this.#onNextCallbacks.set(id, callback);\n return hillaSubscription;\n },\n };\n return hillaSubscription;\n }\n\n #connectWebsocket(prefix: string, atmosphereOptions: Partial<Atmosphere.Request>) {\n const extraHeaders = getCsrfTokenHeadersForEndpointRequest(document);\n const pushUrl = 'HILLA/push';\n const url = prefix.length === 0 ? pushUrl : (prefix.endsWith('/') ? prefix : `${prefix}/`) + pushUrl;\n this.#socket = atmosphere.subscribe?.({\n contentType: 'application/json; charset=UTF-8',\n enableProtocol: true,\n fallbackTransport: 'long-polling',\n headers: extraHeaders,\n maxReconnectOnClose: 10000000,\n onClose: (_) => {\n // https://socket.io/docs/v4/client-api/#event-disconnect\n if (this.state === State.ACTIVE) {\n this.state = State.INACTIVE;\n this.dispatchEvent(new CustomEvent('state-changed', { detail: { active: false } }));\n }\n },\n onError: (response) => {\n // eslint-disable-next-line no-console\n console.error('error in push communication', response);\n },\n onMessage: (response) => {\n if (response.responseBody) {\n this.#handleMessage(JSON.parse(response.responseBody));\n }\n },\n onOpen: (_response: any) => {\n if (this.state === State.INACTIVE) {\n this.state = State.ACTIVE;\n this.dispatchEvent(new CustomEvent('state-changed', { detail: { active: true } }));\n this.#sendPendingMessages();\n }\n },\n onReopen: (_response: any) => {\n if (this.state === State.INACTIVE) {\n this.state = State.ACTIVE;\n this.dispatchEvent(new CustomEvent('state-changed', { detail: { active: true } }));\n this.#sendPendingMessages();\n }\n },\n reconnectInterval: 5000,\n timeout: -1,\n trackMessageLength: true,\n transport: 'websocket',\n url,\n ...atmosphereOptions,\n } satisfies Atmosphere.Request);\n }\n\n #handleMessage(message: unknown) {\n if (isClientMessage(message)) {\n const { id } = message;\n const endpointInfo = this.#endpointInfos.get(id) ?? 'unknown';\n\n if (message['@type'] === 'update') {\n const callback = this.#onNextCallbacks.get(id);\n if (callback) {\n callback(message.item);\n }\n } else if (message['@type'] === 'complete') {\n this.#onCompleteCallbacks.get(id)?.();\n this.#removeSubscription(id);\n } else {\n const callback = this.#onErrorCallbacks.get(id);\n if (callback) {\n callback();\n }\n this.#removeSubscription(id);\n if (!callback) {\n throw new Error(`Error in ${endpointInfo}: ${message.message}`);\n }\n }\n } else {\n throw new Error(`Unknown message from server: ${String(message)}`);\n }\n }\n\n #removeSubscription(id: string) {\n this.#onNextCallbacks.delete(id);\n this.#onCompleteCallbacks.delete(id);\n this.#onErrorCallbacks.delete(id);\n this.#endpointInfos.delete(id);\n }\n\n #send(message: ServerMessage) {\n if (this.state === State.INACTIVE) {\n this.#pendingMessages.push(message);\n } else {\n this.#socket?.push?.(JSON.stringify(message));\n }\n }\n\n #sendPendingMessages() {\n this.#pendingMessages.forEach((msg) => this.#send(msg));\n this.#pendingMessages = [];\n }\n}\n\nexport interface FluxConnection {\n addEventListener<T extends keyof EventMap>(type: T, listener: ListenerType<T>): void;\n removeEventListener<T extends keyof EventMap>(type: T, listener: ListenerType<T>): void;\n}\n"],
5
+ "mappings": "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",
6
+ "names": ["State"]
7
+ }
@@ -0,0 +1,30 @@
1
+ export interface AbstractMessage {
2
+ '@type': string;
3
+ id: string;
4
+ }
5
+ export interface ClientErrorMessage extends AbstractMessage {
6
+ '@type': 'error';
7
+ message: string;
8
+ }
9
+ export interface ClientCompleteMessage extends AbstractMessage {
10
+ '@type': 'complete';
11
+ }
12
+ export interface ClientUpdateMessage extends AbstractMessage {
13
+ '@type': 'update';
14
+ item: any;
15
+ }
16
+ export type ClientMessage = ClientCompleteMessage | ClientErrorMessage | ClientUpdateMessage;
17
+ export declare function isClientMessage(value: unknown): value is ClientMessage;
18
+ export interface ServerConnectMessage extends AbstractMessage {
19
+ id: string;
20
+ '@type': 'subscribe';
21
+ endpointName: string;
22
+ methodName: string;
23
+ params?: any;
24
+ }
25
+ export interface ServerCloseMessage extends AbstractMessage {
26
+ id: string;
27
+ '@type': 'unsubscribe';
28
+ }
29
+ export type ServerMessage = ServerCloseMessage | ServerConnectMessage;
30
+ //# sourceMappingURL=FluxMessages.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FluxMessages.d.ts","sourceRoot":"","sources":["src/FluxMessages.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AACD,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,OAAO,EAAE,UAAU,CAAC;CACrB;AACD,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC1D,OAAO,EAAE,QAAQ,CAAC;IAClB,IAAI,EAAE,GAAG,CAAC;CACX;AAED,MAAM,MAAM,aAAa,GAAG,qBAAqB,GAAG,kBAAkB,GAAG,mBAAmB,CAAC;AAE7F,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,aAAa,CAEtE;AAED,MAAM,WAAW,oBAAqB,SAAQ,eAAe;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,WAAW,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,GAAG,CAAC;CACd;AACD,MAAM,WAAW,kBAAmB,SAAQ,eAAe;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,aAAa,CAAC;CACxB;AAED,MAAM,MAAM,aAAa,GAAG,kBAAkB,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1,7 @@
1
+ function isClientMessage(value) {
2
+ return value != null && typeof value === "object" && "@type" in value;
3
+ }
4
+ export {
5
+ isClientMessage
6
+ };
7
+ //# sourceMappingURL=FluxMessages.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["src/FluxMessages.ts"],
4
+ "sourcesContent": ["export interface AbstractMessage {\n '@type': string;\n id: string;\n}\n\nexport interface ClientErrorMessage extends AbstractMessage {\n '@type': 'error';\n message: string;\n}\nexport interface ClientCompleteMessage extends AbstractMessage {\n '@type': 'complete';\n}\nexport interface ClientUpdateMessage extends AbstractMessage {\n '@type': 'update';\n item: any;\n}\n\nexport type ClientMessage = ClientCompleteMessage | ClientErrorMessage | ClientUpdateMessage;\n\nexport function isClientMessage(value: unknown): value is ClientMessage {\n return value != null && typeof value === 'object' && '@type' in value;\n}\n\nexport interface ServerConnectMessage extends AbstractMessage {\n id: string;\n '@type': 'subscribe';\n endpointName: string;\n methodName: string;\n params?: any;\n}\nexport interface ServerCloseMessage extends AbstractMessage {\n id: string;\n '@type': 'unsubscribe';\n}\n\nexport type ServerMessage = ServerCloseMessage | ServerConnectMessage;\n"],
5
+ "mappings": "AAmBO,SAAS,gBAAgB,OAAwC;AACtE,SAAO,SAAS,QAAQ,OAAO,UAAU,YAAY,WAAW;AAClE;",
6
+ "names": []
7
+ }