@atlassian/clientside-extensions-registry 2.4.1 → 2.5.0-84fa90d-kwd5ix2w
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/LocationsSubject.js.map +1 -1
- package/dist/cjs/RegisterWebItemElement.js +3 -2
- package/dist/cjs/RegisterWebItemElement.js.map +1 -1
- package/dist/cjs/RegisterWebPanelElements.js +3 -2
- package/dist/cjs/RegisterWebPanelElements.js.map +1 -1
- package/dist/cjs/WebFragmentElements.js +9 -8
- package/dist/cjs/WebFragmentElements.js.map +1 -1
- package/dist/cjs/__mocks__/httpUtils.mock.js +8 -0
- package/dist/cjs/__mocks__/httpUtils.mock.js.map +1 -0
- package/dist/cjs/httpUtils.js +9 -9
- package/dist/cjs/httpUtils.js.map +1 -1
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/registry.js +12 -12
- package/dist/cjs/registry.js.map +1 -1
- package/dist/esm/LocationsSubject.js.map +1 -1
- package/dist/esm/__mocks__/httpUtils.mock.js +4 -0
- package/dist/esm/__mocks__/httpUtils.mock.js.map +1 -0
- package/dist/esm/httpUtils.js.map +1 -1
- package/dist/esm/registry.js.map +1 -1
- package/dist/esm/types.js +1 -0
- package/dist/types/LocationsSubject.d.ts.map +1 -1
- package/dist/types/__mocks__/httpUtils.mock.d.ts +5 -0
- package/dist/types/__mocks__/httpUtils.mock.d.ts.map +1 -0
- package/lib/LocationsSubject.ts +1 -1
- package/lib/httpUtils.ts +2 -2
- package/package.json +8 -7
- package/dist/cjs/LocationsSubject.test.js +0 -43
- package/dist/cjs/LocationsSubject.test.js.map +0 -1
- package/dist/cjs/httpUtils.test.js +0 -102
- package/dist/cjs/httpUtils.test.js.map +0 -1
- package/dist/cjs/registry.test.js +0 -307
- package/dist/cjs/registry.test.js.map +0 -1
- package/dist/esm/LocationsSubject.test.js +0 -40
- package/dist/esm/LocationsSubject.test.js.map +0 -1
- package/dist/esm/httpUtils.test.js +0 -99
- package/dist/esm/httpUtils.test.js.map +0 -1
- package/dist/esm/registry.test.js +0 -304
- package/dist/esm/registry.test.js.map +0 -1
- package/dist/types/LocationsSubject.test.d.ts +0 -2
- package/dist/types/LocationsSubject.test.d.ts.map +0 -1
- package/dist/types/httpUtils.test.d.ts +0 -2
- package/dist/types/httpUtils.test.d.ts.map +0 -1
- package/dist/types/registry.test.d.ts +0 -2
- package/dist/types/registry.test.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocationsSubject.js","sourceRoot":"","sources":["../../lib/LocationsSubject.ts"],"names":[],"mappings":";;AAAA,sFAAwE;AAGxE;;GAEG;AACH,MAAqB,gBAAiB,SAAQ,4CAAwC;IAAtF;;QACc,yBAAoB,GAAY,IAAI,CAAC;IAWnD,CAAC;
|
|
1
|
+
{"version":3,"file":"LocationsSubject.js","sourceRoot":"","sources":["../../lib/LocationsSubject.ts"],"names":[],"mappings":";;AAAA,sFAAwE;AAGxE;;GAEG;AACH,MAAqB,gBAAiB,SAAQ,4CAAwC;IAAtF;;QACc,yBAAoB,GAAY,IAAI,CAAC;IAWnD,CAAC;IATY,MAAM,CAAC,OAAgC;QAC5C,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,YAAY,CAAC;QAEjD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,eAAe;QACX,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACrC,CAAC;CACJ;AAZD,mCAYC","sourcesContent":["import { DeferredSubject } from '@atlassian/clientside-extensions-base';\nimport type { LocationsSubjectPayload } from './types';\n\n/**\n * LocationsSubject used by the client extension registry to keep track of extension points\n */\nexport default class LocationsSubject extends DeferredSubject<LocationsSubjectPayload> {\n protected previousLoadingState: boolean = true;\n\n override notify(payload: LocationsSubjectPayload) {\n this.previousLoadingState = payload.loadingState;\n\n super.notify(payload);\n }\n\n getLoadingState() {\n return this.previousLoadingState;\n }\n}\n"]}
|
|
@@ -4,7 +4,8 @@ exports.registerWebItemsElement = exports.customElementName = void 0;
|
|
|
4
4
|
const WebFragmentElements_1 = require("./WebFragmentElements");
|
|
5
5
|
exports.customElementName = 'cse-register-web-items-element';
|
|
6
6
|
/** @since 2.1.0 */
|
|
7
|
-
|
|
8
|
-
WebFragmentElements_1.registerCustomElement(registry, exports.customElementName);
|
|
7
|
+
const registerWebItemsElement = (registry) => {
|
|
8
|
+
(0, WebFragmentElements_1.registerCustomElement)(registry, exports.customElementName);
|
|
9
9
|
};
|
|
10
|
+
exports.registerWebItemsElement = registerWebItemsElement;
|
|
10
11
|
//# sourceMappingURL=RegisterWebItemElement.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisterWebItemElement.js","sourceRoot":"","sources":["../../lib/RegisterWebItemElement.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAKjD,QAAA,iBAAiB,GAAG,gCAAgC,CAAC;AAElE,mBAAmB;
|
|
1
|
+
{"version":3,"file":"RegisterWebItemElement.js","sourceRoot":"","sources":["../../lib/RegisterWebItemElement.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAKjD,QAAA,iBAAiB,GAAG,gCAAgC,CAAC;AAElE,mBAAmB;AACZ,MAAM,uBAAuB,GAAG,CAAC,QAAkB,EAAE,EAAE;IAC1D,IAAA,2CAAqB,EAA0B,QAAQ,EAAE,yBAAiB,CAAC,CAAC;AAChF,CAAC,CAAC;AAFW,QAAA,uBAAuB,2BAElC","sourcesContent":["import { registerCustomElement } from './WebFragmentElements';\n\nimport type Registry from './registry';\nimport type { ParsedWebItemDescriptor } from './types';\n\nexport const customElementName = 'cse-register-web-items-element';\n\n/** @since 2.1.0 */\nexport const registerWebItemsElement = (registry: Registry) => {\n registerCustomElement<ParsedWebItemDescriptor>(registry, customElementName);\n};\n"]}
|
|
@@ -4,7 +4,8 @@ exports.registerWebPanelsElement = exports.customElementName = void 0;
|
|
|
4
4
|
const WebFragmentElements_1 = require("./WebFragmentElements");
|
|
5
5
|
exports.customElementName = 'cse-register-web-panels-element';
|
|
6
6
|
/** @since 2.1.0 */
|
|
7
|
-
|
|
8
|
-
WebFragmentElements_1.registerCustomElement(registry, exports.customElementName);
|
|
7
|
+
const registerWebPanelsElement = (registry) => {
|
|
8
|
+
(0, WebFragmentElements_1.registerCustomElement)(registry, exports.customElementName);
|
|
9
9
|
};
|
|
10
|
+
exports.registerWebPanelsElement = registerWebPanelsElement;
|
|
10
11
|
//# sourceMappingURL=RegisterWebPanelElements.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RegisterWebPanelElements.js","sourceRoot":"","sources":["../../lib/RegisterWebPanelElements.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAKjD,QAAA,iBAAiB,GAAG,iCAAiC,CAAC;AAEnE,mBAAmB;
|
|
1
|
+
{"version":3,"file":"RegisterWebPanelElements.js","sourceRoot":"","sources":["../../lib/RegisterWebPanelElements.ts"],"names":[],"mappings":";;;AAAA,+DAA8D;AAKjD,QAAA,iBAAiB,GAAG,iCAAiC,CAAC;AAEnE,mBAAmB;AACZ,MAAM,wBAAwB,GAAG,CAAC,QAAkB,EAAE,EAAE;IAC3D,IAAA,2CAAqB,EAA2B,QAAQ,EAAE,yBAAiB,CAAC,CAAC;AACjF,CAAC,CAAC;AAFW,QAAA,wBAAwB,4BAEnC","sourcesContent":["import { registerCustomElement } from './WebFragmentElements';\n\nimport type Registry from './registry';\nimport type { ParsedWebPanelDescriptor } from './types';\n\nexport const customElementName = 'cse-register-web-panels-element';\n\n/** @since 2.1.0 */\nexport const registerWebPanelsElement = (registry: Registry) => {\n registerCustomElement<ParsedWebPanelDescriptor>(registry, customElementName);\n};\n"]}
|
|
@@ -7,10 +7,10 @@ const DEBUG_NAME = 'Registry - Web-fragment Element';
|
|
|
7
7
|
// Sadly there is no good way to pass constructor params to custom elements - so this is all one big ugly function.
|
|
8
8
|
/** @since 2.1.0 */
|
|
9
9
|
// eslint-disable-next-line import/prefer-default-export
|
|
10
|
-
|
|
10
|
+
const registerCustomElement = (registry, customElementName) => {
|
|
11
11
|
// already defined
|
|
12
12
|
if (customElements.get(customElementName)) {
|
|
13
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
13
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
14
14
|
level: debug,
|
|
15
15
|
message: `The custom-element "${customElementName}" has already been registered. Skipping registration…`,
|
|
16
16
|
components: DEBUG_NAME,
|
|
@@ -32,7 +32,7 @@ exports.registerCustomElement = (registry, customElementName) => {
|
|
|
32
32
|
const handler = this.attributesMap.get('handler');
|
|
33
33
|
// ensure we have all the attributes
|
|
34
34
|
if (!location) {
|
|
35
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
35
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
36
36
|
level: error,
|
|
37
37
|
message: `No location specified. Aborting registration…`,
|
|
38
38
|
components: DEBUG_NAME,
|
|
@@ -40,7 +40,7 @@ exports.registerCustomElement = (registry, customElementName) => {
|
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
if (!handler) {
|
|
43
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
43
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
44
44
|
level: error,
|
|
45
45
|
message: `No handler specified. Aborting registration…`,
|
|
46
46
|
components: DEBUG_NAME,
|
|
@@ -49,7 +49,7 @@ exports.registerCustomElement = (registry, customElementName) => {
|
|
|
49
49
|
}
|
|
50
50
|
// something is wrong
|
|
51
51
|
if (!parentNode) {
|
|
52
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
52
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
53
53
|
level: error,
|
|
54
54
|
message: `No parent element found for registration of handler: "${handler}" at location: "${location}". Aborting registration…`,
|
|
55
55
|
components: DEBUG_NAME,
|
|
@@ -69,7 +69,7 @@ exports.registerCustomElement = (registry, customElementName) => {
|
|
|
69
69
|
extensions = JSON.parse(this.attributesMap.get('extensions'));
|
|
70
70
|
}
|
|
71
71
|
catch (e) {
|
|
72
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
72
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
73
73
|
level: error,
|
|
74
74
|
message: `Error with extensions payload at location: "${location}". Failed to parse extensions as JSON.
|
|
75
75
|
Please ensure you provide your Web-Fragments correctly formatted!`,
|
|
@@ -88,7 +88,7 @@ Please ensure you provide your Web-Fragments correctly formatted!`,
|
|
|
88
88
|
renderHandler(parentNode, location, extensions);
|
|
89
89
|
}
|
|
90
90
|
catch (e) {
|
|
91
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
91
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
92
92
|
level: error,
|
|
93
93
|
message: `Execution of render-handler "${handler}" at location "${location}" failed.`,
|
|
94
94
|
components: DEBUG_NAME,
|
|
@@ -101,7 +101,7 @@ Please ensure you provide your Web-Fragments correctly formatted!`,
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
else {
|
|
104
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
104
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
105
105
|
level: error,
|
|
106
106
|
message: `No handler registered with name: "${handler}". Failed to complete registration…`,
|
|
107
107
|
components: DEBUG_NAME,
|
|
@@ -118,4 +118,5 @@ Please ensure you provide your Web-Fragments correctly formatted!`,
|
|
|
118
118
|
RegisterWebFragmentElement._observedAttributes = ['extensions', 'location', 'handler'];
|
|
119
119
|
customElements.define(customElementName, RegisterWebFragmentElement);
|
|
120
120
|
};
|
|
121
|
+
exports.registerCustomElement = registerCustomElement;
|
|
121
122
|
//# sourceMappingURL=WebFragmentElements.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebFragmentElements.js","sourceRoot":"","sources":["../../lib/WebFragmentElements.ts"],"names":[],"mappings":";;;AAAA,wFAAiE;AAKjE,MAAM,UAAU,GAAG,iCAAiC,CAAC;AAErD,gIAAgI;AAChI,mHAAmH;AACnH,mBAAmB;AACnB,wDAAwD;
|
|
1
|
+
{"version":3,"file":"WebFragmentElements.js","sourceRoot":"","sources":["../../lib/WebFragmentElements.ts"],"names":[],"mappings":";;;AAAA,wFAAiE;AAKjE,MAAM,UAAU,GAAG,iCAAiC,CAAC;AAErD,gIAAgI;AAChI,mHAAmH;AACnH,mBAAmB;AACnB,wDAAwD;AACjD,MAAM,qBAAqB,GAAG,CACjC,QAAkB,EAClB,iBAAyB,EAE3B,EAAE;IACA,kBAAkB;IAClB,IAAI,cAAc,CAAC,GAAG,CAAC,iBAAiB,CAAC,EAAE;QACvC,IAAA,qCAAO,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;YACpB,KAAK,EAAE,KAAK;YACZ,OAAO,EAAE,uBAAuB,iBAAiB,uDAAuD;YACxG,UAAU,EAAE,UAAU;SACzB,CAAC,CAAC,CAAC;QACJ,OAAO;KACV;IAED,MAAM,0BAA2B,SAAQ,WAAW;QAApD;;YAGY,kBAAa,GAAG,IAAI,GAAG,EAAkB,CAAC;QAoGtD,CAAC;QAlGG,MAAM,KAAK,kBAAkB;YACzB,gDAAgD;YAChD,OAAO,0BAA0B,CAAC,mBAAmB,CAAC;QAC1D,CAAC;QAED,iBAAiB;YACb,MAAM,UAAU,GAAG,IAAI,CAAC,UAAyB,CAAC;YAElD,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;YACpD,MAAM,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YAElD,oCAAoC;YACpC,IAAI,CAAC,QAAQ,EAAE;gBACX,IAAA,qCAAO,EAAC,CAAC,EAAE,KAAK,EAAE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;4BACR,OAAO;yBACV;qBACJ,CAAC,CAAC,CAAC;iBACP;aACJ;YAED,MAAM,aAAa,GAAG,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACnD,IAAI,aAAa,EAAE;gBACf,IAAI;oBACA,aAAa,CAAC,UAAU,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;iBACnD;gBAAC,OAAO,CAAC,EAAE;oBACR,IAAA,qCAAO,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;wBACpB,KAAK,EAAE,KAAK;wBACZ,OAAO,EAAE,gCAAgC,OAAO,kBAAkB,QAAQ,WAAW;wBACrF,UAAU,EAAE,UAAU;wBACtB,IAAI,EAAE;4BACF,QAAQ;4BACR,OAAO;4BACP,KAAK,EAAE,CAAC;yBACX;qBACJ,CAAC,CAAC,CAAC;iBACP;aACJ;iBAAM;gBACH,IAAA,qCAAO,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;oBACpB,KAAK,EAAE,KAAK;oBACZ,OAAO,EAAE,qCAAqC,OAAO,qCAAqC;oBAC1F,UAAU,EAAE,UAAU;iBACzB,CAAC,CAAC,CAAC;aACP;QACL,CAAC;QAED,wBAAwB,CAAC,IAAY,EAAE,QAAgB,EAAE,QAAgB;YACrE,IAAI,QAAQ,KAAK,QAAQ,EAAE;gBACvB,OAAO;aACV;YACD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC3C,CAAC;;IArGc,8CAAmB,GAAG,CAAC,YAAY,EAAE,UAAU,EAAE,SAAS,CAAU,CAAC;IAwGxF,cAAc,CAAC,MAAM,CAAC,iBAAiB,EAAE,0BAA0B,CAAC,CAAC;AACzE,CAAC,CAAC;AAzHW,QAAA,qBAAqB,yBAyHhC","sourcesContent":["import { onDebug } from '@atlassian/clientside-extensions-debug';\n\nimport type Registry from './registry';\nimport type { ParsedWebFragmentDescriptor } from './types';\n\nconst DEBUG_NAME = 'Registry - Web-fragment Element';\n\n// This is a little sub-optimal - but we need the registry singleton here - and the best way to get it is to have it as a param.\n// Sadly there is no good way to pass constructor params to custom elements - so this is all one big ugly function.\n/** @since 2.1.0 */\n// eslint-disable-next-line import/prefer-default-export\nexport const registerCustomElement = <DescriptorType extends ParsedWebFragmentDescriptor>(\n registry: Registry,\n customElementName: string,\n // eslint-disable-next-line sonarjs/cognitive-complexity\n) => {\n // already defined\n if (customElements.get(customElementName)) {\n onDebug(({ debug }) => ({\n level: debug,\n message: `The custom-element \"${customElementName}\" has already been registered. Skipping registration…`,\n components: DEBUG_NAME,\n }));\n return;\n }\n\n class RegisterWebFragmentElement extends HTMLElement {\n private static _observedAttributes = ['extensions', 'location', 'handler'] as const;\n\n private attributesMap = new Map<string, string>();\n\n static get observedAttributes() {\n // eslint-disable-next-line no-underscore-dangle\n return RegisterWebFragmentElement._observedAttributes;\n }\n\n connectedCallback(): void {\n const parentNode = this.parentNode as HTMLElement;\n\n const location = this.attributesMap.get('location');\n const handler = this.attributesMap.get('handler');\n\n // ensure we have all the attributes\n if (!location) {\n onDebug(({ error }) => ({\n level: error,\n message: `No location specified. Aborting registration…`,\n components: DEBUG_NAME,\n }));\n return;\n }\n if (!handler) {\n onDebug(({ error }) => ({\n level: error,\n message: `No handler specified. Aborting registration…`,\n components: DEBUG_NAME,\n }));\n return;\n }\n\n // something is wrong\n if (!parentNode) {\n onDebug(({ error }) => ({\n level: error,\n\n message: `No parent element found for registration of handler: \"${handler}\" at location: \"${location}\". Aborting registration…`,\n components: DEBUG_NAME,\n meta: {\n location,\n handler,\n },\n }));\n return;\n }\n\n // we dont need to be in the dom\n parentNode.removeChild(this);\n\n // technically we dont need extensions - so we can just pass an empty array\n let extensions: DescriptorType[] = [];\n if (this.attributesMap.has('extensions')) {\n try {\n extensions = JSON.parse(this.attributesMap.get('extensions')!);\n } catch (e) {\n onDebug(({ error }) => ({\n level: error,\n message: `Error with extensions payload at location: \"${location}\". Failed to parse extensions as JSON.\nPlease ensure you provide your Web-Fragments correctly formatted!`,\n components: DEBUG_NAME,\n meta: {\n extensions,\n location,\n handler,\n },\n }));\n }\n }\n\n const renderHandler = registry.getHandler(handler);\n if (renderHandler) {\n try {\n renderHandler(parentNode, location, extensions);\n } catch (e) {\n onDebug(({ error }) => ({\n level: error,\n message: `Execution of render-handler \"${handler}\" at location \"${location}\" failed.`,\n components: DEBUG_NAME,\n meta: {\n location,\n handler,\n error: e,\n },\n }));\n }\n } else {\n onDebug(({ error }) => ({\n level: error,\n message: `No handler registered with name: \"${handler}\". Failed to complete registration…`,\n components: DEBUG_NAME,\n }));\n }\n }\n\n attributeChangedCallback(name: string, oldValue: string, newValue: string): void {\n if (oldValue === newValue) {\n return;\n }\n this.attributesMap.set(name, newValue);\n }\n }\n\n customElements.define(customElementName, RegisterWebFragmentElement);\n};\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocationResources = exports.getLocationExtensions = void 0;
|
|
4
|
+
const getLocationExtensions = jest.fn();
|
|
5
|
+
exports.getLocationExtensions = getLocationExtensions;
|
|
6
|
+
const getLocationResources = jest.fn();
|
|
7
|
+
exports.getLocationResources = getLocationResources;
|
|
8
|
+
//# sourceMappingURL=httpUtils.mock.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils.mock.js","sourceRoot":"","sources":["../../../lib/__mocks__/httpUtils.mock.ts"],"names":[],"mappings":";;;AAAA,MAAM,qBAAqB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAG/B,sDAAqB;AAF9B,MAAM,oBAAoB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEP,oDAAoB","sourcesContent":["const getLocationExtensions = jest.fn();\nconst getLocationResources = jest.fn();\n\nexport { getLocationExtensions, getLocationResources };\n"]}
|
package/dist/cjs/httpUtils.js
CHANGED
|
@@ -4,17 +4,17 @@ exports.getLocationResources = exports.getLocationExtensions = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const clientside_extensions_debug_1 = require("@atlassian/clientside-extensions-debug");
|
|
6
6
|
/* eslint-disable import/no-unresolved, node/no-missing-import */
|
|
7
|
-
const require_1 = tslib_1.__importDefault(require("wrm/require"));
|
|
8
|
-
const context_path_1 = tslib_1.__importDefault(require("wrm/context-path"));
|
|
7
|
+
const require_1 = (0, tslib_1.__importDefault)(require("wrm/require"));
|
|
8
|
+
const context_path_1 = (0, tslib_1.__importDefault)(require("wrm/context-path"));
|
|
9
9
|
const getClientExtensionsRestURL = (location) => {
|
|
10
|
-
const baseURL = `${context_path_1.default()}/rest/client-plugins/1.0/client-plugins`;
|
|
10
|
+
const baseURL = `${(0, context_path_1.default)()}/rest/client-plugins/1.0/client-plugins`;
|
|
11
11
|
return `${baseURL}/items?location=${location}`;
|
|
12
12
|
};
|
|
13
13
|
const deferBy = async (timeout) => {
|
|
14
14
|
return new Promise((resolve) => setTimeout(() => resolve(), timeout));
|
|
15
15
|
};
|
|
16
16
|
async function getLocationExtensions(location) {
|
|
17
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
17
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
18
18
|
level: debug,
|
|
19
19
|
message: `Loading legacy web-items for "${location}" extension location...`,
|
|
20
20
|
components: 'Registry',
|
|
@@ -33,7 +33,7 @@ async function getLocationExtensions(location) {
|
|
|
33
33
|
});
|
|
34
34
|
const response = await request.json();
|
|
35
35
|
webItems = response.webItems || [];
|
|
36
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
36
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
37
37
|
level: debug,
|
|
38
38
|
message: `Loaded legacy web-components for "${location}" extension location`,
|
|
39
39
|
components: 'Registry',
|
|
@@ -45,7 +45,7 @@ async function getLocationExtensions(location) {
|
|
|
45
45
|
// eslint-disable-next-line no-empty
|
|
46
46
|
}
|
|
47
47
|
catch (e) {
|
|
48
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
48
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
49
49
|
level: error,
|
|
50
50
|
message: `Couldn't load the legacy web-components for "${location}" extension location`,
|
|
51
51
|
components: 'Registry',
|
|
@@ -72,7 +72,7 @@ function getEnvDeferTime(isAtlassianDevModeEnabled = false) {
|
|
|
72
72
|
return isLocalWatchModeEnabled || isAtlassianDevModeEnabled ? 1500 : 0;
|
|
73
73
|
}
|
|
74
74
|
async function getLocationResources(location, isAtlassianDevModeEnabled) {
|
|
75
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
75
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
76
76
|
level: debug,
|
|
77
77
|
message: `Loading web-resources for "${location}" extension location...`,
|
|
78
78
|
components: 'Registry',
|
|
@@ -81,7 +81,7 @@ async function getLocationResources(location, isAtlassianDevModeEnabled) {
|
|
|
81
81
|
},
|
|
82
82
|
}));
|
|
83
83
|
// We need to use Promise wrapper since different WRM versions can return a jQuery-based thenable object.
|
|
84
|
-
await new Promise((resolve, reject) => require_1.default(`wrc!${location}`).then(() => resolve(), () => reject()));
|
|
84
|
+
await new Promise((resolve, reject) => (0, require_1.default)(`wrc!${location}`).then(() => resolve(), () => reject()));
|
|
85
85
|
/**
|
|
86
86
|
We can not assume we actually loaded the extension's resources yet. Check the {@see getEnvDeferTime} for more details.
|
|
87
87
|
We need to defer the initialization of the extension point depending on the runtime environment:
|
|
@@ -90,7 +90,7 @@ async function getLocationResources(location, isAtlassianDevModeEnabled) {
|
|
|
90
90
|
- local refapp with webpack-dev-server
|
|
91
91
|
*/
|
|
92
92
|
await deferBy(getEnvDeferTime(isAtlassianDevModeEnabled));
|
|
93
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
93
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
94
94
|
level: debug,
|
|
95
95
|
message: `Loaded web-resources for "${location}" extension location`,
|
|
96
96
|
components: 'Registry',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpUtils.js","sourceRoot":"","sources":["../../lib/httpUtils.ts"],"names":[],"mappings":";;;;AAAA,wFAAiE;AAEjE,iEAAiE;AACjE,
|
|
1
|
+
{"version":3,"file":"httpUtils.js","sourceRoot":"","sources":["../../lib/httpUtils.ts"],"names":[],"mappings":";;;;AAAA,wFAAiE;AAEjE,iEAAiE;AACjE,uEAAqC;AACrC,iFAA2C;AAI3C,MAAM,0BAA0B,GAAG,CAAC,QAAgB,EAAE,EAAE;IACpD,MAAM,OAAO,GAAG,GAAG,IAAA,sBAAW,GAAE,yCAAyC,CAAC;IAE1E,OAAO,GAAG,OAAO,mBAAmB,QAAQ,EAAE,CAAC;AACnD,CAAC,CAAC;AAEF,MAAM,OAAO,GAAG,KAAK,EAAE,OAAe,EAAE,EAAE;IACtC,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,OAAO,CAAC,CAAC,CAAC;AAChF,CAAC,CAAC;AAEK,KAAK,UAAU,qBAAqB,CAAC,QAAgB;IACxD,IAAA,qCAAO,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QACpB,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,iCAAiC,QAAQ,yBAAyB;QAC3E,UAAU,EAAE,UAAU;QACtB,IAAI,EAAE;YACF,QAAQ;SACX;KACJ,CAAC,CAAC,CAAC;IAEJ,IAAI,QAAQ,GAA0B,EAAE,CAAC;IAEzC,IAAI;QACA,MAAM,OAAO,GAAG,MAAM,KAAK,CAAC,0BAA0B,CAAC,QAAQ,CAAC,EAAE;YAC9D,MAAM,EAAE,KAAK;YACb,WAAW,EAAE,SAAS;YAC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AAK,EAAE,EAAE,EAAE,CAAC,CAAC;QACpB,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,8BAA8B,QAAQ,yBAAyB;QACxE,UAAU,EAAE,UAAU;QACtB,IAAI,EAAE;YACF,QAAQ;SACX;KACJ,CAAC,CAAC,CAAC;IAEJ,yGAAyG;IACzG,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CACxC,IAAA,iBAAU,EAAC,OAAO,QAAQ,EAAE,CAAC,CAAC,IAAI,CAC9B,GAAG,EAAE,CAAC,OAAO,EAAE,EACf,GAAG,EAAE,CAAC,MAAM,EAAE,CACjB,CACJ,CAAC;IAEF;;;;;;MAME;IACF,MAAM,OAAO,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAE1D,IAAA,qCAAO,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QACpB,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,6BAA6B,QAAQ,sBAAsB;QACpE,UAAU,EAAE,UAAU;QACtB,IAAI,EAAE;YACF,QAAQ;SACX;KACJ,CAAC,CAAC,CAAC;AACR,CAAC;AAnCD,oDAmCC","sourcesContent":["import { onDebug } from '@atlassian/clientside-extensions-debug';\n\n/* eslint-disable import/no-unresolved, node/no-missing-import */\nimport wrmRequire from 'wrm/require';\nimport contextPath from 'wrm/context-path';\n/* eslint-enable import/no-unresolved, node/no-missing-import */\nimport type { ExtensionDescriptor } from './types';\n\nconst getClientExtensionsRestURL = (location: string) => {\n const baseURL = `${contextPath()}/rest/client-plugins/1.0/client-plugins`;\n\n return `${baseURL}/items?location=${location}`;\n};\n\nconst deferBy = async (timeout: number) => {\n return new Promise<void>((resolve) => setTimeout(() => resolve(), timeout));\n};\n\nexport async function getLocationExtensions(location: string): Promise<ExtensionDescriptor[]> {\n onDebug(({ debug }) => ({\n level: debug,\n message: `Loading legacy web-items for \"${location}\" extension location...`,\n components: 'Registry',\n meta: {\n location,\n },\n }));\n\n let webItems: ExtensionDescriptor[] = [];\n\n try {\n const request = await fetch(getClientExtensionsRestURL(location), {\n method: 'get',\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n const response = await request.json();\n\n webItems = (response.webItems as ExtensionDescriptor[]) || [];\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Loaded legacy web-components for \"${location}\" extension location`,\n components: 'Registry',\n meta: {\n location,\n webItems,\n },\n }));\n // eslint-disable-next-line no-empty\n } catch (e) {\n onDebug(({ error }) => ({\n level: error,\n message: `Couldn't load the legacy web-components for \"${location}\" extension location`,\n components: 'Registry',\n meta: {\n location,\n webItems,\n error: (e as Error).message,\n },\n }));\n }\n\n return webItems;\n}\n\nfunction getEnvDeferTime(isAtlassianDevModeEnabled: boolean = false): number {\n // In the local refapp with watch mode and webpack-dev-server (WDS), we can not assume we actually loaded the resources\n // by calling \"WRM.require\". The loaded web-resource includes only a proxy code that will load actual assets from the WDS.\n // However, we can just artificially try to force it by deferring the call by some milliseconds.\n //\n // Once we create the CSE P2 runtime Java plugin, we have a similar issue. Inside the product runtime, the resources can be\n // loaded with or without WDS. When we run this code in product runtime we can't determine if the product is using WDS.\n // What we can do instead is to leverage the \"atlassian.dev.mode\" flag and assume that if the mode is enabled we are running WDS.\n // This is not perfect, but it gives us a good enough solution to simulate more or less deterministic behaviour of \"WRM.require\".\n const isLocalWatchModeEnabled = typeof module !== 'undefined' && (module as unknown as { hot: boolean }).hot;\n\n return isLocalWatchModeEnabled || isAtlassianDevModeEnabled ? 1500 : 0;\n}\n\nexport async function getLocationResources(location: string, isAtlassianDevModeEnabled?: boolean): Promise<void> {\n onDebug(({ debug }) => ({\n level: debug,\n message: `Loading web-resources for \"${location}\" extension location...`,\n components: 'Registry',\n meta: {\n location,\n },\n }));\n\n // We need to use Promise wrapper since different WRM versions can return a jQuery-based thenable object.\n await new Promise<void>((resolve, reject) =>\n wrmRequire(`wrc!${location}`).then(\n () => resolve(),\n () => reject(),\n ),\n );\n\n /**\n We can not assume we actually loaded the extension's resources yet. Check the {@see getEnvDeferTime} for more details.\n We need to defer the initialization of the extension point depending on the runtime environment:\n - product in production mode\n - product in dev mode (with or without webpack-dev-server)\n - local refapp with webpack-dev-server\n */\n await deferBy(getEnvDeferTime(isAtlassianDevModeEnabled));\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Loaded web-resources for \"${location}\" extension location`,\n components: 'Registry',\n meta: {\n location,\n },\n }));\n}\n"]}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const registry_1 = tslib_1.__importDefault(require("./registry"));
|
|
4
|
+
const registry_1 = (0, tslib_1.__importDefault)(require("./registry"));
|
|
5
5
|
const RegisterWebItemElement_1 = require("./RegisterWebItemElement");
|
|
6
6
|
const RegisterWebPanelElements_1 = require("./RegisterWebPanelElements");
|
|
7
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
7
|
+
(0, tslib_1.__exportStar)(require("./types"), exports);
|
|
8
8
|
// Create a singleton instance for the default export and ensure it can only ever exist once by sharing it globally
|
|
9
9
|
// eslint-disable-next-line no-multi-assign, no-underscore-dangle
|
|
10
10
|
const registry = (window.____c_p_r = window.____c_p_r || new registry_1.default());
|
|
11
|
-
RegisterWebItemElement_1.registerWebItemsElement(registry);
|
|
12
|
-
RegisterWebPanelElements_1.registerWebPanelsElement(registry);
|
|
11
|
+
(0, RegisterWebItemElement_1.registerWebItemsElement)(registry);
|
|
12
|
+
(0, RegisterWebPanelElements_1.registerWebPanelsElement)(registry);
|
|
13
13
|
exports.default = registry;
|
|
14
14
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":";;;AAAA,uEAAkD;AAClD,qEAAmE;AACnE,yEAAsE;AAEtE,uDAAwB;AAUxB,mHAAmH;AACnH,iEAAiE;AACjE,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,IAAI,kBAAwB,EAAE,CAAC,CAAC;AAEzF,IAAA,gDAAuB,EAAC,QAAQ,CAAC,CAAC;AAClC,IAAA,mDAAwB,EAAC,QAAQ,CAAC,CAAC;AACnC,kBAAe,QAAQ,CAAC","sourcesContent":["import ClientExtensionsRegistry from './registry';\nimport { registerWebItemsElement } from './RegisterWebItemElement';\nimport { registerWebPanelsElement } from './RegisterWebPanelElements';\n\nexport * from './types';\n\ndeclare global {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n interface Window {\n // Due to historical name changes the \"p\" still represents the old \"plugin\" nomenclature\n ____c_p_r: ClientExtensionsRegistry;\n }\n}\n\n// Create a singleton instance for the default export and ensure it can only ever exist once by sharing it globally\n// eslint-disable-next-line no-multi-assign, no-underscore-dangle\nconst registry = (window.____c_p_r = window.____c_p_r || new ClientExtensionsRegistry());\n\nregisterWebItemsElement(registry);\nregisterWebPanelsElement(registry);\nexport default registry;\n"]}
|
package/dist/cjs/registry.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
const clientside_extensions_debug_1 = require("@atlassian/clientside-extensions-debug");
|
|
5
|
-
const LocationsSubject_1 = tslib_1.__importDefault(require("./LocationsSubject"));
|
|
5
|
+
const LocationsSubject_1 = (0, tslib_1.__importDefault)(require("./LocationsSubject"));
|
|
6
6
|
const httpUtils_1 = require("./httpUtils");
|
|
7
7
|
/**
|
|
8
8
|
* Registry of Client-side Extensions and Client Locations
|
|
@@ -32,7 +32,7 @@ class ClientExtensionsRegistry {
|
|
|
32
32
|
*/
|
|
33
33
|
getLocation(locationName) {
|
|
34
34
|
if (!locationName) {
|
|
35
|
-
clientside_extensions_debug_1.onDebug(({ warn }) => ({
|
|
35
|
+
(0, clientside_extensions_debug_1.onDebug)(({ warn }) => ({
|
|
36
36
|
level: warn,
|
|
37
37
|
message: 'No location name specified. Creating empty subject.',
|
|
38
38
|
components: 'Registry',
|
|
@@ -68,7 +68,7 @@ class ClientExtensionsRegistry {
|
|
|
68
68
|
if (!extensionDescriptor) {
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
71
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
72
72
|
level: debug,
|
|
73
73
|
message: `Registering a new extension for "${extensionDescriptor.location}" extension location`,
|
|
74
74
|
components: 'Registry',
|
|
@@ -78,7 +78,7 @@ class ClientExtensionsRegistry {
|
|
|
78
78
|
},
|
|
79
79
|
}));
|
|
80
80
|
if (!initialDescriptor) {
|
|
81
|
-
clientside_extensions_debug_1.onDebug(({ deprecation }) => ({
|
|
81
|
+
(0, clientside_extensions_debug_1.onDebug)(({ deprecation }) => ({
|
|
82
82
|
level: deprecation,
|
|
83
83
|
message: `Registering an extension without initial attributes is deprecated. Please update your extensions.
|
|
84
84
|
Please either:
|
|
@@ -107,7 +107,7 @@ Please either:
|
|
|
107
107
|
toggleDevMode(isEnabled) {
|
|
108
108
|
const prevIsAtlassianDevModeEnabled = this.isAtlassianDevModeEnabled;
|
|
109
109
|
this.isAtlassianDevModeEnabled = isEnabled;
|
|
110
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
110
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
111
111
|
level: debug,
|
|
112
112
|
message: `The dev mode flag was ${isEnabled ? 'enabled' : 'disabled'}`,
|
|
113
113
|
components: 'Registry',
|
|
@@ -132,7 +132,7 @@ Please either:
|
|
|
132
132
|
*/
|
|
133
133
|
getHandler(identifier) {
|
|
134
134
|
if (!this.handlers.has(identifier)) {
|
|
135
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
135
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
136
136
|
level: error,
|
|
137
137
|
message: `No handler found for identifier: "${identifier}".`,
|
|
138
138
|
components: 'Registry',
|
|
@@ -149,7 +149,7 @@ Please either:
|
|
|
149
149
|
// Someone did not specify a deprecated web-fragment but also did not pass any initial attributes on registration.
|
|
150
150
|
// We don't handle this case and just ignore it!
|
|
151
151
|
if (!attributes && !extension) {
|
|
152
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
152
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
153
153
|
level: error,
|
|
154
154
|
message: `Incompatible extension registration found. Neither deprecated definitions nor attributes on registration found.
|
|
155
155
|
Ignoring extension "${key}"`,
|
|
@@ -218,7 +218,7 @@ Ignoring extension "${key}"`,
|
|
|
218
218
|
if (this.initializedLocations.has(locationName)) {
|
|
219
219
|
return;
|
|
220
220
|
}
|
|
221
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
221
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
222
222
|
level: debug,
|
|
223
223
|
message: `Initialize and load "${locationName}" extension location...`,
|
|
224
224
|
components: 'Registry',
|
|
@@ -230,11 +230,11 @@ Ignoring extension "${key}"`,
|
|
|
230
230
|
const locationsSubject = this.ensureLocationsSubject(locationName);
|
|
231
231
|
try {
|
|
232
232
|
// With the CSE 3.0 we could potentially remove the need of loading the legacy web-items but fot now we need to do that...
|
|
233
|
-
const legacyWebItemsDescriptors = await httpUtils_1.getLocationExtensions(locationName);
|
|
233
|
+
const legacyWebItemsDescriptors = await (0, httpUtils_1.getLocationExtensions)(locationName);
|
|
234
234
|
this.addExtension(...legacyWebItemsDescriptors);
|
|
235
235
|
// load resources for location and notify
|
|
236
|
-
await httpUtils_1.getLocationResources(locationName, this.isAtlassianDevModeEnabled);
|
|
237
|
-
clientside_extensions_debug_1.onDebug(({ debug }) => ({
|
|
236
|
+
await (0, httpUtils_1.getLocationResources)(locationName, this.isAtlassianDevModeEnabled);
|
|
237
|
+
(0, clientside_extensions_debug_1.onDebug)(({ debug }) => ({
|
|
238
238
|
level: debug,
|
|
239
239
|
message: `Finished initializing and loading "${locationName}" extension location.`,
|
|
240
240
|
components: 'Registry',
|
|
@@ -250,7 +250,7 @@ Ignoring extension "${key}"`,
|
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
252
|
catch (err) {
|
|
253
|
-
clientside_extensions_debug_1.onDebug(({ error }) => ({
|
|
253
|
+
(0, clientside_extensions_debug_1.onDebug)(({ error }) => ({
|
|
254
254
|
level: error,
|
|
255
255
|
message: `Failed to load extensions for location ${locationName}`,
|
|
256
256
|
components: 'Registry',
|
package/dist/cjs/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../lib/registry.ts"],"names":[],"mappings":";;;AAAA,wFAAiE;AAUjE,kFAAkD;AAClD,2CAA0E;AAE1E;;GAEG;AACH,MAAqB,wBAAwB;IAA7C;QACY,8BAAyB,GAAY,KAAK,CAAC;QAEnD;;WAEG;QACK,cAAS,GAAG,IAAI,GAAG,EAA4B,CAAC;QAExD;;WAEG;QACK,eAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;QAE5D;;WAEG;QACK,yBAAoB,GAAG,IAAI,GAAG,EAAmB,CAAC;QAE1D;;WAEG;QACK,aAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IAyR3D,CAAC;IAvRG;;OAEG;IACH,WAAW,CAAC,YAAoB;QAC5B,IAAI,CAAC,YAAY,EAAE;YACf,qCAAO,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;gBACnB,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE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E,IAAI,CAAC,yBAAyB,CAAC,CAAC;YAEzE,qCAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;gBACpB,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,sCAAsC,YAAY,uBAAuB;gBAClF,UAAU,EAAE,UAAU;gBACtB,IAAI,EAAE;oBACF,YAAY;iBACf;aACJ,CAAC,CAAC,CAAC;YAEJ,oFAAoF;YACpF,MAAM,oBAAoB,GAAG,IAAI,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC;YAExE,gBAAgB,CAAC,MAAM,CAAC;gBACpB,WAAW,EAAE,oBAAoB;gBACjC,YAAY,EAAE,KAAK;aACtB,CAAC,CAAC;SACN;QAAC,OAAO,GAAG,EAAE;YACV,qCAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;gBACpB,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,0CAA0C,YAAY,EAAE;gBACjE,UAAU,EAAE,UAAU;gBACtB,IAAI,EAAE;oBACF,QAAQ,EAAE,YAAY;oBACtB,KAAK,EAAE,GAAY;iBACtB;aACJ,CAAC,CAAC,CAAC;YACJ,gBAAgB,CAAC,MAAM,CAAC;gBACpB,WAAW,EAAE,EAAE;gBACf,YAAY,EAAE,KAAK;aACtB,CAAC,CAAC;SACN;IACL,CAAC;CACJ;AA9SD,2CA8SC","sourcesContent":["import { onDebug } from '@atlassian/clientside-extensions-debug';\nimport type { Observable } from '@atlassian/clientside-extensions-base';\nimport type {\n InitialAttributes,\n LocationsSubjectPayload,\n ExtensionAttributesProvider,\n ExtensionDescriptor,\n ExtensionHandler,\n} from './types';\n\nimport LocationsSubject from './LocationsSubject';\nimport { getLocationExtensions, getLocationResources } from './httpUtils';\n\n/**\n * Registry of Client-side Extensions and Client Locations\n */\nexport default class ClientExtensionsRegistry {\n private isAtlassianDevModeEnabled: boolean = false;\n\n /**\n * Map of locations and their subjects.\n */\n private locations = new Map<string, LocationsSubject>();\n\n /**\n * Map of registered extensions.\n */\n private extensions = new Map<string, ExtensionDescriptor>();\n\n /**\n * Internal cache to check which locations have received an initialization call\n */\n private initializedLocations = new Map<string, boolean>();\n\n /**\n * Map of registered handlers.\n */\n private handlers = new Map<string, ExtensionHandler>();\n\n /**\n * Get a Location observable. The observer will be notified when new descriptors are available to render.\n */\n getLocation(locationName: string): Observable<LocationsSubjectPayload> {\n if (!locationName) {\n onDebug(({ warn }) => ({\n level: warn,\n message: 'No location name specified. Creating empty subject.',\n components: 'Registry',\n }));\n\n // notify subject with an empty list and finish loading state\n const emptySubject = new LocationsSubject();\n emptySubject.notify({\n descriptors: [],\n loadingState: false,\n });\n\n return emptySubject.asObservable();\n }\n\n // If the location subject is already initialized we want to return the existing one\n if (this.hasSubjectForLocation(locationName)) {\n return (this.locations.get(locationName) as LocationsSubject).asObservable();\n }\n\n const locationsSubject = this.ensureLocationsSubject(locationName);\n\n // send a loading signal to the consumer to notify we're loading the descriptors and resources\n locationsSubject.notify({\n descriptors: [],\n loadingState: locationsSubject.getLoadingState(),\n });\n\n // Fire-up the async code!\n this.initializeExtensionLocation(locationName);\n\n // Return the Observable right away and let the Fetch notify the LocationsSubject when the descriptors are fetched.\n return locationsSubject.asObservable();\n }\n\n /**\n * Extension entry-points use this API to register their attribute providers.\n */\n registerExtension(key: string, attributesProvider: ExtensionAttributesProvider, initialDescriptor?: InitialAttributes) {\n const extensionDescriptor = this.createOrGetExtension(key, initialDescriptor);\n\n if (!extensionDescriptor) {\n return;\n }\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Registering a new extension for \"${extensionDescriptor.location}\" extension location`,\n components: 'Registry',\n meta: {\n key,\n extensionDescriptor,\n },\n }));\n\n if (!initialDescriptor) {\n onDebug(({ deprecation }) => ({\n level: deprecation,\n message: `Registering an extension without initial attributes is deprecated. Please update your extensions.\nPlease either:\n- Update to the latest version of @atlassian/clientside-extensions including the webpack-plugin. Or…\n- Ensure you provide a third parameter of initial attributes. Examples can be found here: https://bitbucket.org/atlassian/atlassian-clientside-extensions/src/master/environments/refapp/src/main/resources/`,\n components: 'Registry',\n meta: {\n key,\n },\n }));\n }\n\n extensionDescriptor.attributesProvider = attributesProvider;\n\n const locationsSubject = this.ensureLocationsSubject(extensionDescriptor.location);\n\n locationsSubject.notify({\n descriptors: this.getExtensionsByLocation(extensionDescriptor.location),\n loadingState: locationsSubject.getLoadingState(),\n });\n }\n\n /**\n * Toggles the {@link ClientExtensionsRegistry#isAtlassianDevModeEnabled} flag.\n * Check the {@link getLocationResources} function for more details about the dev mode.\n *\n * @since 2.1.0\n * @param isEnabled\n */\n toggleDevMode(isEnabled: boolean) {\n const prevIsAtlassianDevModeEnabled = this.isAtlassianDevModeEnabled;\n\n this.isAtlassianDevModeEnabled = isEnabled;\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `The dev mode flag was ${isEnabled ? 'enabled' : 'disabled'}`,\n components: 'Registry',\n meta: {\n prevIsAtlassianDevModeEnabled,\n isAtlassianDevModeEnabled: this.isAtlassianDevModeEnabled,\n },\n }));\n }\n\n /**\n * Registers a handler for web-fragments that can be referenced via the custom-elements provided since 2.1.0\n * see {@link registerCustomElement}\n *\n * @since 2.1.0\n */\n registerHandler(identifier: string, handler: ExtensionHandler): void {\n this.handlers.set(identifier, handler as ExtensionHandler);\n }\n\n /**\n * Retrieve a registered web-fragment handler {@link registerCustomElement}\n * @since 2.1.0\n */\n getHandler(identifier: string): ExtensionHandler | null {\n if (!this.handlers.has(identifier)) {\n onDebug(({ error }) => ({\n level: error,\n message: `No handler found for identifier: \"${identifier}\".`,\n components: 'Registry',\n meta: {\n identifier,\n },\n }));\n return null;\n }\n\n return this.handlers.get(identifier)!;\n }\n\n private createOrGetExtension(key: string, attributes?: InitialAttributes): ExtensionDescriptor | null {\n const extension = this.getExtensionByKey(key);\n\n // Someone did not specify a deprecated web-fragment but also did not pass any initial attributes on registration.\n // We don't handle this case and just ignore it!\n if (!attributes && !extension) {\n onDebug(({ error }) => ({\n level: error,\n message: `Incompatible extension registration found. Neither deprecated definitions nor attributes on registration found.\nIgnoring extension \"${key}\"`,\n components: 'Registry',\n meta: {\n key,\n },\n }));\n return null;\n }\n\n // Deprecated registration of an extension. No initial attributes available\n if (!attributes && extension) {\n return extension;\n }\n\n const { location, weight, label } = attributes as InitialAttributes;\n const extensionDescriptor = { key, location, attributes: { label, weight: weight ?? Infinity } };\n // update if extension is already registered\n if (extension && attributes) {\n return this.updateExtensionByKey(key, extensionDescriptor);\n }\n\n this.addExtension(extensionDescriptor);\n return extensionDescriptor;\n }\n\n private getExtensionsByLocation(locationName: string): ExtensionDescriptor[] {\n const extensionsOfLocation: ExtensionDescriptor[] = [];\n this.extensions.forEach((value) => {\n if (value.location === locationName) {\n extensionsOfLocation.push(value);\n }\n });\n return ClientExtensionsRegistry.sortByWeight(extensionsOfLocation);\n }\n\n private getExtensionByKey(key: string): ExtensionDescriptor | undefined {\n return this.extensions.get(key);\n }\n\n private updateExtensionByKey(key: string, newDescriptor: ExtensionDescriptor): ExtensionDescriptor {\n const extension = this.getExtensionByKey(key);\n const newExtension = { ...extension, ...newDescriptor };\n this.extensions.set(key, newExtension);\n return newExtension;\n }\n\n private ensureLocationsSubject(location: string): LocationsSubject {\n if (this.hasSubjectForLocation(location)) {\n return this.locations.get(location) as LocationsSubject;\n }\n\n this.locations.set(location, new LocationsSubject());\n\n return this.locations.get(location) as LocationsSubject;\n }\n\n private hasSubjectForLocation(location: string): boolean {\n return this.locations.has(location);\n }\n\n private addExtension(...newExtensions: ExtensionDescriptor[]): void {\n newExtensions.forEach((extensionDescriptor) => {\n this.extensions.set(extensionDescriptor.key, extensionDescriptor);\n });\n }\n\n private static sortByWeight(extensions: ExtensionDescriptor[]): ExtensionDescriptor[] {\n extensions.sort((a, b) => {\n // @ts-expect-error TODO: Weight might be undefined\n return a.attributes?.weight - b.attributes?.weight;\n });\n return extensions;\n }\n\n private async initializeExtensionLocation(locationName: string) {\n if (this.initializedLocations.has(locationName)) {\n return;\n }\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Initialize and load \"${locationName}\" extension location...`,\n components: 'Registry',\n meta: {\n locationName,\n },\n }));\n\n this.initializedLocations.set(locationName, true);\n\n const locationsSubject = this.ensureLocationsSubject(locationName);\n\n try {\n // With the CSE 3.0 we could potentially remove the need of loading the legacy web-items but fot now we need to do that...\n const legacyWebItemsDescriptors = await getLocationExtensions(locationName);\n this.addExtension(...legacyWebItemsDescriptors);\n\n // load resources for location and notify\n await getLocationResources(locationName, this.isAtlassianDevModeEnabled);\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Finished initializing and loading \"${locationName}\" extension location.`,\n components: 'Registry',\n meta: {\n locationName,\n },\n }));\n\n // Get all the extensions that were registered with the `registerExtension` function\n const extensionDescriptors = this.getExtensionsByLocation(locationName);\n\n locationsSubject.notify({\n descriptors: extensionDescriptors,\n loadingState: false,\n });\n } catch (err) {\n onDebug(({ error }) => ({\n level: error,\n message: `Failed to load extensions for location ${locationName}`,\n components: 'Registry',\n meta: {\n location: locationName,\n error: err as Error,\n },\n }));\n locationsSubject.notify({\n descriptors: [],\n loadingState: false,\n });\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../lib/registry.ts"],"names":[],"mappings":";;;AAAA,wFAAiE;AAUjE,uFAAkD;AAClD,2CAA0E;AAE1E;;GAEG;AACH,MAAqB,wBAAwB;IAA7C;QACY,8BAAyB,GAAY,KAAK,CAAC;QAEnD;;WAEG;QACK,cAAS,GAAG,IAAI,GAAG,EAA4B,CAAC;QAExD;;WAEG;QACK,eAAU,GAAG,IAAI,GAAG,EAA+B,CAAC;QAE5D;;WAEG;QACK,yBAAoB,GAAG,IAAI,GAAG,EAAmB,CAAC;QAE1D;;WAEG;QACK,aAAQ,GAAG,IAAI,GAAG,EAA4B,CAAC;IAyR3D,CAAC;IAvRG;;OAEG;IACH,WAAW,CAAC,YAAoB;QAC5B,IAAI,CAAC,YAAY,E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AAM,yBAAyB,GAAG,MAAM,IAAA,iCAAqB,EAAC,YAAY,CAAC,CAAC;YAC5E,IAAI,CAAC,YAAY,CAAC,GAAG,yBAAyB,CAAC,CAAC;YAEhD,yCAAyC;YACzC,MAAM,IAAA,gCAAoB,EAAC,YAAY,EAAE,IAAI,CAAC,yBAAyB,CAAC,CAAC;YAEzE,IAAA,qCAAO,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;gBACpB,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,sCAAsC,YAAY,uBAAuB;gBAClF,UAAU,EAAE,UAAU;gBACtB,IAAI,EAAE;oBACF,YAAY;iBACf;aACJ,CAAC,CAAC,CAAC;YAEJ,oFAAoF;YACpF,MAAM,oBAAoB,GAAG,IAAI,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAC;YAExE,gBAAgB,CAAC,MAAM,CAAC;gBACpB,WAAW,EAAE,oBAAoB;gBACjC,YAAY,EAAE,KAAK;aACtB,CAAC,CAAC;SACN;QAAC,OAAO,GAAG,EAAE;YACV,IAAA,qCAAO,EAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;gBACpB,KAAK,EAAE,KAAK;gBACZ,OAAO,EAAE,0CAA0C,YAAY,EAAE;gBACjE,UAAU,EAAE,UAAU;gBACtB,IAAI,EAAE;oBACF,QAAQ,EAAE,YAAY;oBACtB,KAAK,EAAE,GAAY;iBACtB;aACJ,CAAC,CAAC,CAAC;YACJ,gBAAgB,CAAC,MAAM,CAAC;gBACpB,WAAW,EAAE,EAAE;gBACf,YAAY,EAAE,KAAK;aACtB,CAAC,CAAC;SACN;IACL,CAAC;CACJ;AA9SD,2CA8SC","sourcesContent":["import { onDebug } from '@atlassian/clientside-extensions-debug';\nimport type { Observable } from '@atlassian/clientside-extensions-base';\nimport type {\n InitialAttributes,\n LocationsSubjectPayload,\n ExtensionAttributesProvider,\n ExtensionDescriptor,\n ExtensionHandler,\n} from './types';\n\nimport LocationsSubject from './LocationsSubject';\nimport { getLocationExtensions, getLocationResources } from './httpUtils';\n\n/**\n * Registry of Client-side Extensions and Client Locations\n */\nexport default class ClientExtensionsRegistry {\n private isAtlassianDevModeEnabled: boolean = false;\n\n /**\n * Map of locations and their subjects.\n */\n private locations = new Map<string, LocationsSubject>();\n\n /**\n * Map of registered extensions.\n */\n private extensions = new Map<string, ExtensionDescriptor>();\n\n /**\n * Internal cache to check which locations have received an initialization call\n */\n private initializedLocations = new Map<string, boolean>();\n\n /**\n * Map of registered handlers.\n */\n private handlers = new Map<string, ExtensionHandler>();\n\n /**\n * Get a Location observable. The observer will be notified when new descriptors are available to render.\n */\n getLocation(locationName: string): Observable<LocationsSubjectPayload> {\n if (!locationName) {\n onDebug(({ warn }) => ({\n level: warn,\n message: 'No location name specified. Creating empty subject.',\n components: 'Registry',\n }));\n\n // notify subject with an empty list and finish loading state\n const emptySubject = new LocationsSubject();\n emptySubject.notify({\n descriptors: [],\n loadingState: false,\n });\n\n return emptySubject.asObservable();\n }\n\n // If the location subject is already initialized we want to return the existing one\n if (this.hasSubjectForLocation(locationName)) {\n return (this.locations.get(locationName) as LocationsSubject).asObservable();\n }\n\n const locationsSubject = this.ensureLocationsSubject(locationName);\n\n // send a loading signal to the consumer to notify we're loading the descriptors and resources\n locationsSubject.notify({\n descriptors: [],\n loadingState: locationsSubject.getLoadingState(),\n });\n\n // Fire-up the async code!\n this.initializeExtensionLocation(locationName);\n\n // Return the Observable right away and let the Fetch notify the LocationsSubject when the descriptors are fetched.\n return locationsSubject.asObservable();\n }\n\n /**\n * Extension entry-points use this API to register their attribute providers.\n */\n registerExtension(key: string, attributesProvider: ExtensionAttributesProvider, initialDescriptor?: InitialAttributes) {\n const extensionDescriptor = this.createOrGetExtension(key, initialDescriptor);\n\n if (!extensionDescriptor) {\n return;\n }\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Registering a new extension for \"${extensionDescriptor.location}\" extension location`,\n components: 'Registry',\n meta: {\n key,\n extensionDescriptor,\n },\n }));\n\n if (!initialDescriptor) {\n onDebug(({ deprecation }) => ({\n level: deprecation,\n message: `Registering an extension without initial attributes is deprecated. Please update your extensions.\nPlease either:\n- Update to the latest version of @atlassian/clientside-extensions including the webpack-plugin. Or…\n- Ensure you provide a third parameter of initial attributes. Examples can be found here: https://bitbucket.org/atlassian/atlassian-clientside-extensions/src/master/environments/refapp/src/main/resources/`,\n components: 'Registry',\n meta: {\n key,\n },\n }));\n }\n\n extensionDescriptor.attributesProvider = attributesProvider;\n\n const locationsSubject = this.ensureLocationsSubject(extensionDescriptor.location);\n\n locationsSubject.notify({\n descriptors: this.getExtensionsByLocation(extensionDescriptor.location),\n loadingState: locationsSubject.getLoadingState(),\n });\n }\n\n /**\n * Toggles the {@link ClientExtensionsRegistry#isAtlassianDevModeEnabled} flag.\n * Check the {@link getLocationResources} function for more details about the dev mode.\n *\n * @since 2.1.0\n * @param isEnabled\n */\n toggleDevMode(isEnabled: boolean) {\n const prevIsAtlassianDevModeEnabled = this.isAtlassianDevModeEnabled;\n\n this.isAtlassianDevModeEnabled = isEnabled;\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `The dev mode flag was ${isEnabled ? 'enabled' : 'disabled'}`,\n components: 'Registry',\n meta: {\n prevIsAtlassianDevModeEnabled,\n isAtlassianDevModeEnabled: this.isAtlassianDevModeEnabled,\n },\n }));\n }\n\n /**\n * Registers a handler for web-fragments that can be referenced via the custom-elements provided since 2.1.0\n * see {@link registerCustomElement}\n *\n * @since 2.1.0\n */\n registerHandler(identifier: string, handler: ExtensionHandler): void {\n this.handlers.set(identifier, handler as ExtensionHandler);\n }\n\n /**\n * Retrieve a registered web-fragment handler {@link registerCustomElement}\n * @since 2.1.0\n */\n getHandler(identifier: string): ExtensionHandler | null {\n if (!this.handlers.has(identifier)) {\n onDebug(({ error }) => ({\n level: error,\n message: `No handler found for identifier: \"${identifier}\".`,\n components: 'Registry',\n meta: {\n identifier,\n },\n }));\n return null;\n }\n\n return this.handlers.get(identifier)!;\n }\n\n private createOrGetExtension(key: string, attributes?: InitialAttributes): ExtensionDescriptor | null {\n const extension = this.getExtensionByKey(key);\n\n // Someone did not specify a deprecated web-fragment but also did not pass any initial attributes on registration.\n // We don't handle this case and just ignore it!\n if (!attributes && !extension) {\n onDebug(({ error }) => ({\n level: error,\n message: `Incompatible extension registration found. Neither deprecated definitions nor attributes on registration found.\nIgnoring extension \"${key}\"`,\n components: 'Registry',\n meta: {\n key,\n },\n }));\n return null;\n }\n\n // Deprecated registration of an extension. No initial attributes available\n if (!attributes && extension) {\n return extension;\n }\n\n const { location, weight, label } = attributes as InitialAttributes;\n const extensionDescriptor = { key, location, attributes: { label, weight: weight ?? Infinity } };\n // update if extension is already registered\n if (extension && attributes) {\n return this.updateExtensionByKey(key, extensionDescriptor);\n }\n\n this.addExtension(extensionDescriptor);\n return extensionDescriptor;\n }\n\n private getExtensionsByLocation(locationName: string): ExtensionDescriptor[] {\n const extensionsOfLocation: ExtensionDescriptor[] = [];\n this.extensions.forEach((value) => {\n if (value.location === locationName) {\n extensionsOfLocation.push(value);\n }\n });\n return ClientExtensionsRegistry.sortByWeight(extensionsOfLocation);\n }\n\n private getExtensionByKey(key: string): ExtensionDescriptor | undefined {\n return this.extensions.get(key);\n }\n\n private updateExtensionByKey(key: string, newDescriptor: ExtensionDescriptor): ExtensionDescriptor {\n const extension = this.getExtensionByKey(key);\n const newExtension = { ...extension, ...newDescriptor };\n this.extensions.set(key, newExtension);\n return newExtension;\n }\n\n private ensureLocationsSubject(location: string): LocationsSubject {\n if (this.hasSubjectForLocation(location)) {\n return this.locations.get(location) as LocationsSubject;\n }\n\n this.locations.set(location, new LocationsSubject());\n\n return this.locations.get(location) as LocationsSubject;\n }\n\n private hasSubjectForLocation(location: string): boolean {\n return this.locations.has(location);\n }\n\n private addExtension(...newExtensions: ExtensionDescriptor[]): void {\n newExtensions.forEach((extensionDescriptor) => {\n this.extensions.set(extensionDescriptor.key, extensionDescriptor);\n });\n }\n\n private static sortByWeight(extensions: ExtensionDescriptor[]): ExtensionDescriptor[] {\n extensions.sort((a, b) => {\n // @ts-expect-error TODO: Weight might be undefined\n return a.attributes?.weight - b.attributes?.weight;\n });\n return extensions;\n }\n\n private async initializeExtensionLocation(locationName: string) {\n if (this.initializedLocations.has(locationName)) {\n return;\n }\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Initialize and load \"${locationName}\" extension location...`,\n components: 'Registry',\n meta: {\n locationName,\n },\n }));\n\n this.initializedLocations.set(locationName, true);\n\n const locationsSubject = this.ensureLocationsSubject(locationName);\n\n try {\n // With the CSE 3.0 we could potentially remove the need of loading the legacy web-items but fot now we need to do that...\n const legacyWebItemsDescriptors = await getLocationExtensions(locationName);\n this.addExtension(...legacyWebItemsDescriptors);\n\n // load resources for location and notify\n await getLocationResources(locationName, this.isAtlassianDevModeEnabled);\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Finished initializing and loading \"${locationName}\" extension location.`,\n components: 'Registry',\n meta: {\n locationName,\n },\n }));\n\n // Get all the extensions that were registered with the `registerExtension` function\n const extensionDescriptors = this.getExtensionsByLocation(locationName);\n\n locationsSubject.notify({\n descriptors: extensionDescriptors,\n loadingState: false,\n });\n } catch (err) {\n onDebug(({ error }) => ({\n level: error,\n message: `Failed to load extensions for location ${locationName}`,\n components: 'Registry',\n meta: {\n location: locationName,\n error: err as Error,\n },\n }));\n locationsSubject.notify({\n descriptors: [],\n loadingState: false,\n });\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocationsSubject.js","sourceRoot":"","sources":["../../lib/LocationsSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGxE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,eAAwC;IAAtF;;QACc,yBAAoB,GAAY,IAAI,CAAC;IAWnD,CAAC;
|
|
1
|
+
{"version":3,"file":"LocationsSubject.js","sourceRoot":"","sources":["../../lib/LocationsSubject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AAGxE;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,eAAwC;IAAtF;;QACc,yBAAoB,GAAY,IAAI,CAAC;IAWnD,CAAC;IATY,MAAM,CAAC,OAAgC;QAC5C,IAAI,CAAC,oBAAoB,GAAG,OAAO,CAAC,YAAY,CAAC;QAEjD,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;IAED,eAAe;QACX,OAAO,IAAI,CAAC,oBAAoB,CAAC;IACrC,CAAC;CACJ","sourcesContent":["import { DeferredSubject } from '@atlassian/clientside-extensions-base';\nimport type { LocationsSubjectPayload } from './types';\n\n/**\n * LocationsSubject used by the client extension registry to keep track of extension points\n */\nexport default class LocationsSubject extends DeferredSubject<LocationsSubjectPayload> {\n protected previousLoadingState: boolean = true;\n\n override notify(payload: LocationsSubjectPayload) {\n this.previousLoadingState = payload.loadingState;\n\n super.notify(payload);\n }\n\n getLoadingState() {\n return this.previousLoadingState;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"httpUtils.mock.js","sourceRoot":"","sources":["../../../lib/__mocks__/httpUtils.mock.ts"],"names":[],"mappings":"AAAA,MAAM,qBAAqB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AACxC,MAAM,oBAAoB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC;AAEvC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,CAAC","sourcesContent":["const getLocationExtensions = jest.fn();\nconst getLocationResources = jest.fn();\n\nexport { getLocationExtensions, getLocationResources };\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpUtils.js","sourceRoot":"","sources":["../../lib/httpUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MA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AC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,QAAgB,EAAE,yBAAmC;IAC5F,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QACpB,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,8BAA8B,QAAQ,yBAAyB;QACxE,UAAU,EAAE,UAAU;QACtB,IAAI,EAAE;YACF,QAAQ;SACX;KACJ,CAAC,CAAC,CAAC;IAEJ,yGAAyG;IACzG,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE,CACxC,UAAU,CAAC,OAAO,QAAQ,EAAE,CAAC,CAAC,IAAI,CAC9B,GAAG,EAAE,CAAC,OAAO,EAAE,EACf,GAAG,EAAE,CAAC,MAAM,EAAE,CACjB,CACJ,CAAC;IAEF;;;;;;MAME;IACF,MAAM,OAAO,CAAC,eAAe,CAAC,yBAAyB,CAAC,CAAC,CAAC;IAE1D,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAC;QACpB,KAAK,EAAE,KAAK;QACZ,OAAO,EAAE,6BAA6B,QAAQ,sBAAsB;QACpE,UAAU,EAAE,UAAU;QACtB,IAAI,EAAE;YACF,QAAQ;SACX;KACJ,CAAC,CAAC,CAAC;AACR,CAAC","sourcesContent":["import { onDebug } from '@atlassian/clientside-extensions-debug';\n\n/* eslint-disable import/no-unresolved, node/no-missing-import */\nimport wrmRequire from 'wrm/require';\nimport contextPath from 'wrm/context-path';\n/* eslint-enable import/no-unresolved, node/no-missing-import */\nimport type { ExtensionDescriptor } from './types';\n\nconst getClientExtensionsRestURL = (location: string) => {\n const baseURL = `${contextPath()}/rest/client-plugins/1.0/client-plugins`;\n\n return `${baseURL}/items?location=${location}`;\n};\n\nconst deferBy = async (timeout: number) => {\n return new Promise<void>((resolve) => setTimeout(() => resolve(), timeout));\n};\n\nexport async function getLocationExtensions(location: string): Promise<ExtensionDescriptor[]> {\n onDebug(({ debug }) => ({\n level: debug,\n message: `Loading legacy web-items for \"${location}\" extension location...`,\n components: 'Registry',\n meta: {\n location,\n },\n }));\n\n let webItems: ExtensionDescriptor[] = [];\n\n try {\n const request = await fetch(getClientExtensionsRestURL(location), {\n method: 'get',\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n });\n const response = await request.json();\n\n webItems = (response.webItems as ExtensionDescriptor[]) || [];\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Loaded legacy web-components for \"${location}\" extension location`,\n components: 'Registry',\n meta: {\n location,\n webItems,\n },\n }));\n // eslint-disable-next-line no-empty\n } catch (e) {\n onDebug(({ error }) => ({\n level: error,\n message: `Couldn't load the legacy web-components for \"${location}\" extension location`,\n components: 'Registry',\n meta: {\n location,\n webItems,\n error: (e as Error).message,\n },\n }));\n }\n\n return webItems;\n}\n\nfunction getEnvDeferTime(isAtlassianDevModeEnabled: boolean = false): number {\n // In the local refapp with watch mode and webpack-dev-server (WDS), we can not assume we actually loaded the resources\n // by calling \"WRM.require\". The loaded web-resource includes only a proxy code that will load actual assets from the WDS.\n // However, we can just artificially try to force it by deferring the call by some milliseconds.\n //\n // Once we create the CSE P2 runtime Java plugin, we have a similar issue. Inside the product runtime, the resources can be\n // loaded with or without WDS. When we run this code in product runtime we can't determine if the product is using WDS.\n // What we can do instead is to leverage the \"atlassian.dev.mode\" flag and assume that if the mode is enabled we are running WDS.\n // This is not perfect, but it gives us a good enough solution to simulate more or less deterministic behaviour of \"WRM.require\".\n const isLocalWatchModeEnabled = typeof module !== 'undefined' && (module as unknown as { hot: boolean }).hot;\n\n return isLocalWatchModeEnabled || isAtlassianDevModeEnabled ? 1500 : 0;\n}\n\nexport async function getLocationResources(location: string, isAtlassianDevModeEnabled?: boolean): Promise<void> {\n onDebug(({ debug }) => ({\n level: debug,\n message: `Loading web-resources for \"${location}\" extension location...`,\n components: 'Registry',\n meta: {\n location,\n },\n }));\n\n // We need to use Promise wrapper since different WRM versions can return a jQuery-based thenable object.\n await new Promise<void>((resolve, reject) =>\n wrmRequire(`wrc!${location}`).then(\n () => resolve(),\n () => reject(),\n ),\n );\n\n /**\n We can not assume we actually loaded the extension's resources yet. Check the {@see getEnvDeferTime} for more details.\n We need to defer the initialization of the extension point depending on the runtime environment:\n - product in production mode\n - product in dev mode (with or without webpack-dev-server)\n - local refapp with webpack-dev-server\n */\n await deferBy(getEnvDeferTime(isAtlassianDevModeEnabled));\n\n onDebug(({ debug }) => ({\n level: debug,\n message: `Loaded web-resources for \"${location}\" extension location`,\n components: 'Registry',\n meta: {\n location,\n },\n }));\n}\n"]}
|