@digipair/skill-keycloak 0.48.1 → 0.49.0

Sign up to get free protection for your applications and to get access to all the features.
package/index.cjs.js CHANGED
@@ -5629,8 +5629,10 @@ let KeycloakService = class KeycloakService {
5629
5629
  });
5630
5630
  return pinsSettings;
5631
5631
  }
5632
- async decodedToken(url, realm, token) {
5633
- const response = await fetch(`${url}/realms/${realm}/protocol/openid-connect/certs`);
5632
+ async decodedToken(url, realm, token, signal) {
5633
+ const response = await fetch(`${url}/realms/${realm}/protocol/openid-connect/certs`, {
5634
+ signal
5635
+ });
5634
5636
  const infos = await response.json();
5635
5637
  const publicKey = `-----BEGIN CERTIFICATE-----\n${infos.keys.find(({ alg })=>alg === 'RS256').x5c[0]}\n-----END CERTIFICATE-----`;
5636
5638
  const decodedtoken = jsonwebtoken.verify(token, publicKey, {
@@ -5657,37 +5659,26 @@ let KeycloakService = class KeycloakService {
5657
5659
  }
5658
5660
  return output;
5659
5661
  }
5660
- async pins2html(pins) {
5662
+ async pins2html(pins, context) {
5661
5663
  const dom = new jsdom.JSDOM();
5662
5664
  const element = dom.window.document.createElement('section');
5663
- await this.generateElementsFromPins(pins, element, dom);
5665
+ await this.generateElementsFromPins(pins, element, {
5666
+ config: {
5667
+ VERSIONS: context.config.VERSIONS || {}
5668
+ },
5669
+ variables: context.variables || {},
5670
+ request: context.request || {}
5671
+ }, dom.window.document);
5664
5672
  return element.innerHTML;
5665
5673
  }
5666
- async generateElementsFromPins(pinsList, parent, dom) {
5674
+ async generateElementsFromPins(pinsList, parent, context, document) {
5667
5675
  for(let i = 0; i < pinsList.length; i++){
5668
5676
  const item = pinsList[i];
5669
- await this.generateElementFromPins(item, parent, dom);
5677
+ await engine.generateElementFromPins(item, parent, context, document, {
5678
+ import: false
5679
+ });
5670
5680
  }
5671
5681
  }
5672
- async generateElementFromPins(pinsSettings, parent, dom) {
5673
- const element = dom.window.document.createElement(pinsSettings.element);
5674
- element.setAttribute('data-ssr', '1');
5675
- const settings = pinsSettings;
5676
- Object.entries(settings.properties || {}).forEach(([key, value])=>{
5677
- if (key === 'textContent') {
5678
- element.textContent = value;
5679
- } else if (key === 'innerHTML') {
5680
- element.innerHTML = value;
5681
- } else if (typeof value === 'string') {
5682
- element.setAttribute(key, value);
5683
- } else {
5684
- element[key] = value;
5685
- }
5686
- });
5687
- const pinsList = settings.pins || [];
5688
- await this.generateElementsFromPins(pinsList, element, dom);
5689
- parent.appendChild(element);
5690
- }
5691
5682
  async page(params, _pinsSettingsList, context) {
5692
5683
  var _context_request_body;
5693
5684
  const { body, head, ssr = false, styleHtml = '', styleBody = '', baseUrl = 'https://cdn.jsdelivr.net/npm', url = context.privates.KEYCLOAK_URL, realm = context.privates.KEYCLOAK_REALM, clientId = context.privates.KEYCLOAK_CLIENTID, factoryInitialize = [], browserInitialize = [], browserLoad = [], logged = [], unlogged = [], factoryUrl = context.privates.FACTORY_URL || process.env['FACTORY_URL'] || 'https://factory.digipair.ai' } = params;
@@ -5700,9 +5691,10 @@ let KeycloakService = class KeycloakService {
5700
5691
  const pinsSettingsList = ((_pinsSettings_properties = pinsSettings.properties) == null ? void 0 : _pinsSettings_properties['execute']) || [];
5701
5692
  const token = /^Bearer /g.test(context.request.headers.authorization) && ((_context_request_headers_authorization = context.request.headers.authorization) == null ? void 0 : _context_request_headers_authorization.replace(/^Bearer /g, ''));
5702
5693
  if (token) {
5694
+ var _context_protected;
5703
5695
  context.keycloak = {
5704
5696
  isLogged: true,
5705
- decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''))
5697
+ decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''), (_context_protected = context.protected) == null ? void 0 : _context_protected.signal)
5706
5698
  };
5707
5699
  } else {
5708
5700
  context.keycloak = {
@@ -5719,7 +5711,7 @@ let KeycloakService = class KeycloakService {
5719
5711
  <!DOCTYPE html>
5720
5712
  <html style="${styleHtml}">
5721
5713
  <head>
5722
- ${head ? await this.pins2html(head) : `
5714
+ ${head ? await this.pins2html(head, context) : `
5723
5715
  <meta charset="UTF-8" />
5724
5716
  <title>Digipair</title>
5725
5717
  <meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -5799,7 +5791,7 @@ let KeycloakService = class KeycloakService {
5799
5791
  await executePinsList(${JSON.stringify(this.prepareBrowserPinsSettings('browserInitialize', browserInitialize))}, context);
5800
5792
 
5801
5793
  const pinsList = ${JSON.stringify(this.prepareBrowserPinsSettings('body', body))};
5802
- document.querySelectorAll('body > [data-ssr]').forEach((element) => element.remove()); // Remove SSR elements
5794
+ document.querySelectorAll('body > [data-digipair-pins]').forEach((element) => element.remove()); // Remove SSR elements
5803
5795
  for (let i = 0; i < pinsList.length; i++) {
5804
5796
  const item = pinsList[i];
5805
5797
  await generateElementFromPins(item, document.body, { ...context, data: ${JSON.stringify(preparedData)} });
@@ -5810,7 +5802,7 @@ let KeycloakService = class KeycloakService {
5810
5802
  }, 1);
5811
5803
  </script>
5812
5804
 
5813
- ${ssr ? await this.pins2html(body) : ''}
5805
+ ${ssr ? await this.pins2html(body, context) : ''}
5814
5806
  </body>
5815
5807
  </html>
5816
5808
  `;
@@ -5821,9 +5813,10 @@ let KeycloakService = class KeycloakService {
5821
5813
  const { execute, secured = true, url = context.privates.KEYCLOAK_URL, realm = context.privates.KEYCLOAK_REALM } = params;
5822
5814
  const token = /^Bearer /g.test(context.request.headers.authorization) && ((_context_request_headers_authorization = context.request.headers.authorization) == null ? void 0 : _context_request_headers_authorization.replace(/^Bearer /g, ''));
5823
5815
  if (token) {
5816
+ var _context_protected;
5824
5817
  context.keycloak = {
5825
5818
  isLogged: true,
5826
- decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''))
5819
+ decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''), (_context_protected = context.protected) == null ? void 0 : _context_protected.signal)
5827
5820
  };
5828
5821
  } else {
5829
5822
  context.keycloak = {
@@ -5845,9 +5838,10 @@ let KeycloakService = class KeycloakService {
5845
5838
  const { steps, secured = true, url = context.privates.KEYCLOAK_URL, realm = context.privates.KEYCLOAK_REALM } = params;
5846
5839
  const token = /^Bearer /g.test(context.request.headers.authorization) && ((_context_request_headers_authorization = context.request.headers.authorization) == null ? void 0 : _context_request_headers_authorization.replace(/^Bearer /g, ''));
5847
5840
  if (token) {
5841
+ var _context_protected;
5848
5842
  context.keycloak = {
5849
5843
  isLogged: true,
5850
- decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''))
5844
+ decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''), (_context_protected = context.protected) == null ? void 0 : _context_protected.signal)
5851
5845
  };
5852
5846
  } else {
5853
5847
  context.keycloak = {
package/index.esm.js CHANGED
@@ -27940,6 +27940,74 @@ const executePinsList = async (pinsSettingsList, context)=>{
27940
27940
  }
27941
27941
  return previous;
27942
27942
  };
27943
+ const generateElementFromPins = async (pinsSettings, parent, context, document = typeof window !== 'undefined' ? window.document : global.document, options = {
27944
+ import: true
27945
+ })=>{
27946
+ var _settings_conditions, _settings_conditions1;
27947
+ let settings = await preparePinsSettings(pinsSettings, context);
27948
+ const alias = _config.ALIAS.find((alias)=>settings.library.split(':')[0] === alias.name);
27949
+ if (alias) {
27950
+ settings = await preparePinsSettings(_extends({}, settings, alias), {
27951
+ settings
27952
+ });
27953
+ }
27954
+ if ((_settings_conditions = settings.conditions) == null ? void 0 : _settings_conditions.each) {
27955
+ for(let index = 0; index < settings.conditions.each.length; index++){
27956
+ const item = settings.conditions.each[index];
27957
+ await generateElementFromPins(_extends({}, pinsSettings, {
27958
+ conditions: _extends({}, pinsSettings.conditions, {
27959
+ each: undefined
27960
+ })
27961
+ }), parent, _extends({}, context, {
27962
+ item,
27963
+ index,
27964
+ parent: {
27965
+ item: context.item,
27966
+ index: context.index,
27967
+ parent: context.parent
27968
+ }
27969
+ }), document, options);
27970
+ }
27971
+ return;
27972
+ }
27973
+ if (typeof ((_settings_conditions1 = settings.conditions) == null ? void 0 : _settings_conditions1.if) !== 'undefined' && !settings.conditions.if) {
27974
+ return;
27975
+ }
27976
+ const element = document.createElement(pinsSettings.element);
27977
+ element.setAttribute('data-digipair-pins', '');
27978
+ const library = pinsSettings.library;
27979
+ if (options.import && library !== 'web' && !_config.LIBRARIES[library]) {
27980
+ const config = context.config || {};
27981
+ const version = (config.VERSIONS || {})[library] || 'latest';
27982
+ import(isRemoteVersion.test(version) ? `${version}` : `${_config.BASE_URL}/${library}@${version}/index.esm.js`);
27983
+ }
27984
+ Object.entries(settings.properties || {}).forEach(([key, value])=>{
27985
+ if (key === 'textContent') {
27986
+ element.textContent = value;
27987
+ } else if (key === 'innerHTML') {
27988
+ element.innerHTML = value;
27989
+ } else if (typeof value === 'string') {
27990
+ element.setAttribute(key, value);
27991
+ } else {
27992
+ element[key] = value;
27993
+ }
27994
+ });
27995
+ Object.entries(settings.events || {}).forEach(([key, pinsList])=>{
27996
+ element.addEventListener(key, (_event)=>{
27997
+ const event = _event;
27998
+ executePinsList(pinsList, _extends({}, context, {
27999
+ event: event.detail
28000
+ }));
28001
+ });
28002
+ });
28003
+ const pinsList = settings.pins || [];
28004
+ for(let i = 0; i < pinsList.length; i++){
28005
+ const item = pinsList[i];
28006
+ await generateElementFromPins(item, element, context, document, options);
28007
+ }
28008
+ parent == null ? void 0 : parent.appendChild(element);
28009
+ return element;
28010
+ };
27943
28011
  const preparePinsSettings = async (settings, context)=>{
27944
28012
  const localContext = _extends({}, context, {
27945
28013
  variables: context.variables || {},
@@ -33561,8 +33629,10 @@ let KeycloakService = class KeycloakService {
33561
33629
  });
33562
33630
  return pinsSettings;
33563
33631
  }
33564
- async decodedToken(url, realm, token) {
33565
- const response = await fetch(`${url}/realms/${realm}/protocol/openid-connect/certs`);
33632
+ async decodedToken(url, realm, token, signal) {
33633
+ const response = await fetch(`${url}/realms/${realm}/protocol/openid-connect/certs`, {
33634
+ signal
33635
+ });
33566
33636
  const infos = await response.json();
33567
33637
  const publicKey = `-----BEGIN CERTIFICATE-----\n${infos.keys.find(({ alg })=>alg === 'RS256').x5c[0]}\n-----END CERTIFICATE-----`;
33568
33638
  const decodedtoken = jsonwebtoken.verify(token, publicKey, {
@@ -33589,36 +33659,25 @@ let KeycloakService = class KeycloakService {
33589
33659
  }
33590
33660
  return output;
33591
33661
  }
33592
- async pins2html(pins) {
33662
+ async pins2html(pins, context) {
33593
33663
  const dom = new JSDOM();
33594
33664
  const element = dom.window.document.createElement('section');
33595
- await this.generateElementsFromPins(pins, element, dom);
33665
+ await this.generateElementsFromPins(pins, element, {
33666
+ config: {
33667
+ VERSIONS: context.config.VERSIONS || {}
33668
+ },
33669
+ variables: context.variables || {},
33670
+ request: context.request || {}
33671
+ }, dom.window.document);
33596
33672
  return element.innerHTML;
33597
33673
  }
33598
- async generateElementsFromPins(pinsList, parent, dom) {
33674
+ async generateElementsFromPins(pinsList, parent, context, document) {
33599
33675
  for(let i = 0; i < pinsList.length; i++){
33600
33676
  const item = pinsList[i];
33601
- await this.generateElementFromPins(item, parent, dom);
33602
- }
33603
- }
33604
- async generateElementFromPins(pinsSettings, parent, dom) {
33605
- const element = dom.window.document.createElement(pinsSettings.element);
33606
- element.setAttribute('data-ssr', '1');
33607
- const settings = pinsSettings;
33608
- Object.entries(settings.properties || {}).forEach(([key, value])=>{
33609
- if (key === 'textContent') {
33610
- element.textContent = value;
33611
- } else if (key === 'innerHTML') {
33612
- element.innerHTML = value;
33613
- } else if (typeof value === 'string') {
33614
- element.setAttribute(key, value);
33615
- } else {
33616
- element[key] = value;
33617
- }
33618
- });
33619
- const pinsList = settings.pins || [];
33620
- await this.generateElementsFromPins(pinsList, element, dom);
33621
- parent.appendChild(element);
33677
+ await generateElementFromPins(item, parent, context, document, {
33678
+ import: false
33679
+ });
33680
+ }
33622
33681
  }
33623
33682
  async page(params, _pinsSettingsList, context) {
33624
33683
  var _context_request_body;
@@ -33632,9 +33691,10 @@ let KeycloakService = class KeycloakService {
33632
33691
  const pinsSettingsList = ((_pinsSettings_properties = pinsSettings.properties) == null ? void 0 : _pinsSettings_properties['execute']) || [];
33633
33692
  const token = /^Bearer /g.test(context.request.headers.authorization) && ((_context_request_headers_authorization = context.request.headers.authorization) == null ? void 0 : _context_request_headers_authorization.replace(/^Bearer /g, ''));
33634
33693
  if (token) {
33694
+ var _context_protected;
33635
33695
  context.keycloak = {
33636
33696
  isLogged: true,
33637
- decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''))
33697
+ decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''), (_context_protected = context.protected) == null ? void 0 : _context_protected.signal)
33638
33698
  };
33639
33699
  } else {
33640
33700
  context.keycloak = {
@@ -33651,7 +33711,7 @@ let KeycloakService = class KeycloakService {
33651
33711
  <!DOCTYPE html>
33652
33712
  <html style="${styleHtml}">
33653
33713
  <head>
33654
- ${head ? await this.pins2html(head) : `
33714
+ ${head ? await this.pins2html(head, context) : `
33655
33715
  <meta charset="UTF-8" />
33656
33716
  <title>Digipair</title>
33657
33717
  <meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -33731,7 +33791,7 @@ let KeycloakService = class KeycloakService {
33731
33791
  await executePinsList(${JSON.stringify(this.prepareBrowserPinsSettings('browserInitialize', browserInitialize))}, context);
33732
33792
 
33733
33793
  const pinsList = ${JSON.stringify(this.prepareBrowserPinsSettings('body', body))};
33734
- document.querySelectorAll('body > [data-ssr]').forEach((element) => element.remove()); // Remove SSR elements
33794
+ document.querySelectorAll('body > [data-digipair-pins]').forEach((element) => element.remove()); // Remove SSR elements
33735
33795
  for (let i = 0; i < pinsList.length; i++) {
33736
33796
  const item = pinsList[i];
33737
33797
  await generateElementFromPins(item, document.body, { ...context, data: ${JSON.stringify(preparedData)} });
@@ -33742,7 +33802,7 @@ let KeycloakService = class KeycloakService {
33742
33802
  }, 1);
33743
33803
  </script>
33744
33804
 
33745
- ${ssr ? await this.pins2html(body) : ''}
33805
+ ${ssr ? await this.pins2html(body, context) : ''}
33746
33806
  </body>
33747
33807
  </html>
33748
33808
  `;
@@ -33753,9 +33813,10 @@ let KeycloakService = class KeycloakService {
33753
33813
  const { execute, secured = true, url = context.privates.KEYCLOAK_URL, realm = context.privates.KEYCLOAK_REALM } = params;
33754
33814
  const token = /^Bearer /g.test(context.request.headers.authorization) && ((_context_request_headers_authorization = context.request.headers.authorization) == null ? void 0 : _context_request_headers_authorization.replace(/^Bearer /g, ''));
33755
33815
  if (token) {
33816
+ var _context_protected;
33756
33817
  context.keycloak = {
33757
33818
  isLogged: true,
33758
- decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''))
33819
+ decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''), (_context_protected = context.protected) == null ? void 0 : _context_protected.signal)
33759
33820
  };
33760
33821
  } else {
33761
33822
  context.keycloak = {
@@ -33777,9 +33838,10 @@ let KeycloakService = class KeycloakService {
33777
33838
  const { steps, secured = true, url = context.privates.KEYCLOAK_URL, realm = context.privates.KEYCLOAK_REALM } = params;
33778
33839
  const token = /^Bearer /g.test(context.request.headers.authorization) && ((_context_request_headers_authorization = context.request.headers.authorization) == null ? void 0 : _context_request_headers_authorization.replace(/^Bearer /g, ''));
33779
33840
  if (token) {
33841
+ var _context_protected;
33780
33842
  context.keycloak = {
33781
33843
  isLogged: true,
33782
- decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''))
33844
+ decodedToken: await this.decodedToken(url, realm, context.request.headers.authorization.replace(/^Bearer /, ''), (_context_protected = context.protected) == null ? void 0 : _context_protected.signal)
33783
33845
  };
33784
33846
  } else {
33785
33847
  context.keycloak = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-keycloak",
3
- "version": "0.48.1",
3
+ "version": "0.49.0",
4
4
  "dependencies": {},
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js"
File without changes