@spotify/backstage-plugin-search-backend-module-skill-exchange 0.1.0

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/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @spotify/backstage-plugin-search-backend-module-skill-exchange
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Initial release
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ # Commercial License
2
+
3
+ Copyright (c) 2023 Spotify. All rights reserved.
4
+
5
+ This software is part of the "Spotify Plugins for Backstage" bundle. "Spotify
6
+ Plugins for Backstage" is commercial software. To use it, you must obtain a
7
+ license and agree to the [License
8
+ Terms](https://backstage.spotify.com/spotify-plugins-for-backstage-terms).
9
+ Commercial licenses can be obtained at https://backstage.spotify.com/.
package/README.md ADDED
@@ -0,0 +1,3 @@
1
+ # @spotify/backstage-plugin-search-backend-module-skill-exchange
2
+
3
+ Backstage search backend module for the [Skill-Exchange](https://backstage.spotify.com/plugins/skill-exchange) plugin. Decorates `UserEntities` with self-reported skill information.
@@ -0,0 +1,13 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var B=require("@backstage/backend-common"),g=require("@backstage/backend-plugin-api"),J=require("@backstage/plugin-catalog-node/alpha"),A=require("@backstage/plugin-search-backend-node/alpha"),I=require("@backstage/catalog-model"),G=require("@backstage/plugin-search-backend-node"),H=require("@spotify/backstage-plugin-skill-exchange-node"),D=(a,e,t)=>{if(!e.has(a))throw TypeError("Cannot "+t)},o=(a,e,t)=>(D(a,e,"read from private field"),t?t.call(a):e.get(a)),l=(a,e,t)=>{if(e.has(a))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(a):e.set(a,t)},c=(a,e,t,i)=>(D(a,e,"write to private field"),i?i.call(a,t):e.set(a,t),t),K=(a,e,t,i)=>({set _(r){c(a,e,r,t)},get _(){return o(a,e,i)}}),Q=(a,e,t)=>(D(a,e,"access private method"),t),d,v,E,b,W,f,u,T,O,U;const N=class extends G.DecoratorBase{constructor({cacheClient:e,catalogClient:t,logger:i,skillExchangeClient:r,tokenManager:n}){super(),l(this,O),l(this,d,void 0),l(this,v,void 0),l(this,E,void 0),l(this,b,void 0),l(this,W,void 0),l(this,f,0),l(this,u,void 0),c(this,v,e),c(this,d,i),c(this,E,t),c(this,b,r),c(this,W,n)}async initialize(){c(this,f,0),c(this,u,await Q(this,O,U).call(this)),o(this,d).info(`Found ${Object.keys(o(this,u)).length} skill profiles available for decorating`)}async getUserEntity(e){const t=`SkillProfileDecorator:${e}`,i=await o(this,v).get(t),{token:r}=await o(this,W).getToken();if(i)return i;const n=await o(this,E).getEntityByRef(e,{token:r}).catch(h=>{o(this,d).error(`Error while retrieving entity with ref: ${e}`,h)});if(n)return await o(this,v).set(t,JSON.parse(JSON.stringify(n))),n}async decorate(e){var t,i,r,n,h,m,L;if(!o(this,u)||e.kind!=="User")return e;const S=((t=e.authorization)==null?void 0:t.resourceRef)||I.stringifyEntityRef({namespace:e.namespace,kind:e.kind,name:e.location.split("/").at(-1)}),p=await this.getUserEntity(S);if(!S||!p)return o(this,d).error(`Could not find user entity to decorate, skipping over this document ${S}`),e;const j=(r=(i=o(this,u)[S.toLowerCase()])==null?void 0:i.map(({name:s})=>s))!=null?r:[],M=(h=(n=p.relations)==null?void 0:n.filter(({type:s})=>s==="memberOf"))==null?void 0:h.map(({targetRef:s})=>I.parseEntityRef(s)).filter(({kind:s})=>s==="group").map(({name:s})=>s),C=[];return e.text&&C.push(e.text),j.length&&C.push(j.join(", ")),M!=null&&M.length&&C.push(M.join(", ")),e.text=C.join(" || "),e.displayName=(m=p.spec.profile)==null?void 0:m.displayName,e.picture=(L=p.spec.profile)==null?void 0:L.picture,e.name=p.metadata.name,e.skills=j,e.teams=M||[],K(this,f)._++,e}async finalize(){c(this,u,void 0),o(this,d).info(`Decorated ${o(this,f)} documents with skill profile data`)}};d=new WeakMap,v=new WeakMap,E=new WeakMap,b=new WeakMap,W=new WeakMap,f=new WeakMap,u=new WeakMap,T=new WeakMap,O=new WeakSet,U=async function(){var a;const e=await o(this,b).doPost("/graphql",{query:o(N,T)});let t={};return e.ok?t=(((a=(await e.json()).data)==null?void 0:a.getPublicSelfReportedSkill)||[]).reduce((i,{user:r,skill:n})=>({...i,[r.toLowerCase()]:[...i[r.toLowerCase()]||[],n]}),t):o(this,d).error(`Error fetching self reported skills: ${await e.text()}`),t},l(N,T,`
2
+ query SelfReportedSkills {
3
+ getPublicSelfReportedSkill {
4
+ skill {
5
+ id
6
+ name
7
+ category
8
+ }
9
+ user
10
+ }
11
+ }
12
+ `);let V=N;var X=Object.defineProperty,Y=(a,e,t)=>e in a?X(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,_=(a,e,t)=>(Y(a,typeof e!="symbol"?e+"":e,t),t),z=(a,e,t)=>{if(!e.has(a))throw TypeError("Cannot "+t)},k=(a,e,t)=>(z(a,e,"read from private field"),t?t.call(a):e.get(a)),y=(a,e,t)=>{if(e.has(a))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(a):e.set(a,t)},w=(a,e,t,i)=>(z(a,e,"write to private field"),i?i.call(a,t):e.set(a,t),t),x,$,P,R,q;const Z=class F{constructor({cache:e,config:t,logger:i,discovery:r,tokenManager:n,catalog:h}){_(this,"types",["software-catalog"]),y(this,x,void 0),y(this,$,void 0),y(this,P,void 0),y(this,R,void 0),y(this,q,void 0),_(this,"discovery"),w(this,$,i),this.discovery=r,w(this,x,e.getClient({defaultTtl:60*60*1e3})),w(this,P,h),w(this,R,new H.SkillExchangeClient({config:t,discovery:r,tokenManager:n})),w(this,q,n)}static fromConfig(e,t){return new F({config:e,...t})}async getDecorator(){return new V({cacheClient:k(this,x),catalogClient:k(this,P),logger:k(this,$),skillExchangeClient:k(this,R),tokenManager:k(this,q)})}};x=new WeakMap,$=new WeakMap,P=new WeakMap,R=new WeakMap,q=new WeakMap;let ee=Z;const te=g.createBackendModule({pluginId:"search",moduleId:"skill-exchange",register(a){a.registerInit({deps:{config:g.coreServices.rootConfig,cache:g.coreServices.cache,discovery:g.coreServices.discovery,logger:g.coreServices.logger,tokenManager:g.coreServices.tokenManager,envScheduler:g.coreServices.scheduler,catalog:J.catalogServiceRef,registry:A.searchIndexRegistryExtensionPoint},async init({registry:e,config:t,cache:i,discovery:r,logger:n,tokenManager:h,catalog:m}){e.addDecorator({factory:ee.fromConfig(t,{catalog:m,discovery:r,tokenManager:h,logger:B.loggerToWinstonLogger(n),cache:B.cacheToPluginCacheManager(i)})})}})}});exports.default=te;
13
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1,6 @@
1
+ import * as _backstage_backend_plugin_api from '@backstage/backend-plugin-api';
2
+
3
+ /** @public */
4
+ declare const searchModuleSkillExchange: () => _backstage_backend_plugin_api.BackendFeature;
5
+
6
+ export { searchModuleSkillExchange as default };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@spotify/backstage-plugin-search-backend-module-skill-exchange",
3
+ "description": "The skill-exchange backend module for the search plugin.",
4
+ "version": "0.1.0",
5
+ "license": "SEE LICENSE IN LICENSE.md",
6
+ "homepage": "https://backstage.spotify.com",
7
+ "main": "dist/index.cjs.js",
8
+ "types": "dist/index.d.ts",
9
+ "publishConfig": {
10
+ "main": "dist/index.cjs.js",
11
+ "types": "dist/index.d.ts"
12
+ },
13
+ "backstage": {
14
+ "role": "backend-plugin-module"
15
+ },
16
+ "scripts": {
17
+ "start": "backstage-cli package start",
18
+ "build": "backstage-cli package build --minify",
19
+ "lint": "backstage-cli package lint",
20
+ "test": "backstage-cli package test",
21
+ "clean": "backstage-cli package clean",
22
+ "prepack": "backstage-cli package prepack",
23
+ "postpack": "backstage-cli package postpack"
24
+ },
25
+ "dependencies": {
26
+ "@backstage/backend-common": "^0.21.0",
27
+ "@backstage/backend-plugin-api": "^0.6.10",
28
+ "@backstage/catalog-client": "^1.6.0",
29
+ "@backstage/catalog-model": "^1.4.4",
30
+ "@backstage/config": "^1.1.1",
31
+ "@backstage/plugin-catalog-node": "^1.7.0",
32
+ "@backstage/plugin-search-backend-node": "^1.2.14",
33
+ "@backstage/plugin-search-common": "^1.2.10",
34
+ "@spotify/backstage-plugin-skill-exchange-common": "^0.0.9",
35
+ "@spotify/backstage-plugin-skill-exchange-node": "^0.0.8",
36
+ "winston": "^3.2.1"
37
+ },
38
+ "devDependencies": {
39
+ "@backstage/backend-test-utils": "^0.3.0",
40
+ "@backstage/cli": "^0.25.2",
41
+ "node-fetch": "^2.6.7"
42
+ },
43
+ "files": [
44
+ "dist",
45
+ "!dist/**/*.map"
46
+ ]
47
+ }