@yanolja-next/ncp-bo-sdk 0.0.5 → 0.0.6

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("axios"),g=require("path-to-regexp"),i="/services/:id/backoffice",E="READY",d="INIT",I="INIT_ERROR";class w{constructor(){this.context=null}set(t){this.context=t}get(){return this.context}}const p=new w,R=(e,t=1e4)=>new Promise((r,c)=>{const s=setTimeout(()=>{window.removeEventListener("message",o),c(new Error("Timeout waiting for context"))},t),o=n=>{var a;!e.includes(n.origin)||((a=n.data)==null?void 0:a.type)!==d||typeof n.data.token!="string"||typeof n.data.projectId!="string"||(clearTimeout(s),window.removeEventListener("message",o),p.set({token:n.data.token,projectId:n.data.projectId}),r())};window.addEventListener("message",o);for(const n of e)window.parent.postMessage({type:E},n)}),T=(e,t)=>{for(const r of t)window.parent.postMessage({type:I,message:e},r)},_=g.match(i,{end:!1}),l=()=>{const e=_(window.location.pathname);return e?e.path:"/"},m=e=>`${e}-backoffice`,h="X-NCP-CLIENT-PROJECT-ID",S=(e,t,r)=>{const c=u.create({baseURL:`${t}/services/${e}`,headers:{"Content-Type":"application/json",...r==null?void 0:r.headers}});return c.interceptors.request.use(s=>{const o=p.get(),n=(o==null?void 0:o.projectId)??C(),a=(o==null?void 0:o.token)??localStorage.getItem("session_token");return s.headers[h]=n,a&&(s.headers.Authorization=`Bearer ${a}`),s}),c},C=()=>{const t=new URLSearchParams(window.location.search).get("project-id");if(!t)throw new Error("Missing project ID");return t};exports.INIT_ERROR_MESSAGE_TYPE=I;exports.INIT_MESSAGE_TYPE=d;exports.READY_MESSAGE_TYPE=E;exports.SERVICE_BACKOFFICE_ROUTE=i;exports.getApiClient=S;exports.getBasePath=l;exports.getComponentName=m;exports.notifyInitError=T;exports.waitForContext=R;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("axios"),E="READY",d="INIT",I="INIT_ERROR";class w{constructor(){this.context=null}set(t){this.context=t}get(){return this.context}}const T=new w,A=(e,t=1e4)=>{const o=Array.isArray(e)?e:[e];return new Promise((n,s)=>{const i=setTimeout(()=>{window.removeEventListener("message",a),s(new Error("Timeout waiting for context"))},t),a=r=>{var c;!o.includes(r.origin)||((c=r.data)==null?void 0:c.type)!==d||typeof r.data.token!="string"||typeof r.data.projectId!="string"||(clearTimeout(i),window.removeEventListener("message",a),T.set({token:r.data.token,projectId:r.data.projectId}),n())};window.addEventListener("message",a);for(const r of o)window.parent.postMessage({type:E},r)})},_=(e,t)=>{const o=Array.isArray(t)?t:[t];for(const n of o)window.parent.postMessage({type:I,message:e},n)},l="X-NCP-CLIENT-PROJECT-ID",p=(e,t,o)=>{const n=u.create({baseURL:`${t}/services/${e}`,headers:{"Content-Type":"application/json",...o==null?void 0:o.headers}});return n.interceptors.request.use(s=>{const i=T.get();if(!i)throw new Error("Context not initialized. Call waitForContext() first.");return s.headers[l]=i.projectId,s.headers.Authorization=`Bearer ${i.token}`,s}),n};exports.INIT_ERROR_MESSAGE_TYPE=I;exports.INIT_MESSAGE_TYPE=d;exports.READY_MESSAGE_TYPE=E;exports.getApiClient=p;exports.notifyInitError=_;exports.waitForContext=A;
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
- import d from "axios";
2
- import { match as E } from "path-to-regexp";
3
- const p = "/services/:id/backoffice", I = "READY", m = "INIT", u = "INIT_ERROR";
4
- class w {
1
+ import E from "axios";
2
+ const w = "READY", I = "INIT", p = "INIT_ERROR";
3
+ class u {
5
4
  constructor() {
6
5
  this.context = null;
7
6
  }
@@ -12,51 +11,46 @@ class w {
12
11
  return this.context;
13
12
  }
14
13
  }
15
- const i = new w(), T = (e, t = 1e4) => new Promise((n, c) => {
16
- const s = setTimeout(() => {
17
- window.removeEventListener("message", o), c(new Error("Timeout waiting for context"));
18
- }, t), o = (r) => {
19
- var a;
20
- !e.includes(r.origin) || ((a = r.data) == null ? void 0 : a.type) !== m || typeof r.data.token != "string" || typeof r.data.projectId != "string" || (clearTimeout(s), window.removeEventListener("message", o), i.set({
21
- token: r.data.token,
22
- projectId: r.data.projectId
23
- }), n());
24
- };
25
- window.addEventListener("message", o);
26
- for (const r of e)
27
- window.parent.postMessage({ type: I }, r);
28
- }), _ = (e, t) => {
29
- for (const n of t)
30
- window.parent.postMessage({ type: u, message: e }, n);
31
- }, g = E(p, { end: !1 }), C = () => {
32
- const e = g(window.location.pathname);
33
- return e ? e.path : "/";
34
- }, P = (e) => `${e}-backoffice`, h = "X-NCP-CLIENT-PROJECT-ID", S = (e, t, n) => {
35
- const c = d.create({
14
+ const d = new u(), m = (e, t = 1e4) => {
15
+ const o = Array.isArray(e) ? e : [e];
16
+ return new Promise((n, s) => {
17
+ const a = setTimeout(() => {
18
+ window.removeEventListener("message", i), s(new Error("Timeout waiting for context"));
19
+ }, t), i = (r) => {
20
+ var c;
21
+ !o.includes(r.origin) || ((c = r.data) == null ? void 0 : c.type) !== I || typeof r.data.token != "string" || typeof r.data.projectId != "string" || (clearTimeout(a), window.removeEventListener("message", i), d.set({
22
+ token: r.data.token,
23
+ projectId: r.data.projectId
24
+ }), n());
25
+ };
26
+ window.addEventListener("message", i);
27
+ for (const r of o)
28
+ window.parent.postMessage({ type: w }, r);
29
+ });
30
+ }, x = (e, t) => {
31
+ const o = Array.isArray(t) ? t : [t];
32
+ for (const n of o)
33
+ window.parent.postMessage({ type: p, message: e }, n);
34
+ }, T = "X-NCP-CLIENT-PROJECT-ID", A = (e, t, o) => {
35
+ const n = E.create({
36
36
  baseURL: `${t}/services/${e}`,
37
37
  headers: {
38
38
  "Content-Type": "application/json",
39
- ...n == null ? void 0 : n.headers
39
+ ...o == null ? void 0 : o.headers
40
40
  }
41
41
  });
42
- return c.interceptors.request.use((s) => {
43
- const o = i.get(), r = (o == null ? void 0 : o.projectId) ?? l(), a = (o == null ? void 0 : o.token) ?? localStorage.getItem("session_token");
44
- return s.headers[h] = r, a && (s.headers.Authorization = `Bearer ${a}`), s;
45
- }), c;
46
- }, l = () => {
47
- const t = new URLSearchParams(window.location.search).get("project-id");
48
- if (!t)
49
- throw new Error("Missing project ID");
50
- return t;
42
+ return n.interceptors.request.use((s) => {
43
+ const a = d.get();
44
+ if (!a)
45
+ throw new Error("Context not initialized. Call waitForContext() first.");
46
+ return s.headers[T] = a.projectId, s.headers.Authorization = `Bearer ${a.token}`, s;
47
+ }), n;
51
48
  };
52
49
  export {
53
- u as INIT_ERROR_MESSAGE_TYPE,
54
- m as INIT_MESSAGE_TYPE,
55
- I as READY_MESSAGE_TYPE,
56
- p as SERVICE_BACKOFFICE_ROUTE,
57
- S as getApiClient,
58
- C as getBasePath,
59
- P as getComponentName,
60
- _ as notifyInitError,
61
- T as waitForContext
50
+ p as INIT_ERROR_MESSAGE_TYPE,
51
+ I as INIT_MESSAGE_TYPE,
52
+ w as READY_MESSAGE_TYPE,
53
+ A as getApiClient,
54
+ x as notifyInitError,
55
+ m as waitForContext
62
56
  };
@@ -1,12 +1,9 @@
1
1
  import { AxiosInstance } from 'axios';
2
- export declare const SERVICE_BACKOFFICE_ROUTE = "/services/:id/backoffice";
3
2
  export declare const READY_MESSAGE_TYPE = "READY";
4
3
  export declare const INIT_MESSAGE_TYPE = "INIT";
5
4
  export declare const INIT_ERROR_MESSAGE_TYPE = "INIT_ERROR";
6
- export declare const waitForContext: (targetOrigins: string[], timeoutMs?: number) => Promise<void>;
7
- export declare const notifyInitError: (message: string, targetOrigins: string[]) => void;
8
- export declare const getBasePath: () => string;
9
- export declare const getComponentName: (serviceName: string) => string;
5
+ export declare const waitForContext: (targetOrigin: string | string[], timeoutMs?: number) => Promise<void>;
6
+ export declare const notifyInitError: (message: string, targetOrigin: string | string[]) => void;
10
7
  export declare const getApiClient: (serviceName: string, baseUrl: string, options?: ApiClientOptions) => AxiosInstance;
11
8
  interface ApiClientOptions {
12
9
  headers?: Record<string, string>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yanolja-next/ncp-bo-sdk",
3
3
  "private": false,
4
- "version": "0.0.5",
4
+ "version": "0.0.6",
5
5
  "description": "NCP Backoffice SDK - Build and deploy service backoffice UIs",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
@@ -17,7 +17,6 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "axios": "^1.7.2",
21
- "path-to-regexp": "^8.3.0"
20
+ "axios": "^1.7.2"
22
21
  }
23
22
  }