@priceos/react 0.0.30 → 0.0.32
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 +10 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -36,12 +36,12 @@ __export(index_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
var import_react = require("react");
|
|
38
38
|
var import_swr = __toESM(require("swr"), 1);
|
|
39
|
-
var
|
|
39
|
+
var DEFAULT_BACKEND_URL = "/api/priceos";
|
|
40
40
|
var PriceOSContext = (0, import_react.createContext)({});
|
|
41
41
|
var normalizeBaseUrl = (baseUrl) => baseUrl.replace(/\/$/, "");
|
|
42
|
-
var buildUrl = (
|
|
43
|
-
const normalizedBase = normalizeBaseUrl(
|
|
44
|
-
return `${normalizedBase}/v1/
|
|
42
|
+
var buildUrl = (backendUrl) => {
|
|
43
|
+
const normalizedBase = normalizeBaseUrl(backendUrl);
|
|
44
|
+
return `${normalizedBase}/v1/customer`;
|
|
45
45
|
};
|
|
46
46
|
var requestCustomer = async (fetchFn, url, bearerToken) => {
|
|
47
47
|
const headers = bearerToken ? { Authorization: `Bearer ${bearerToken}` } : void 0;
|
|
@@ -54,18 +54,18 @@ var requestCustomer = async (fetchFn, url, bearerToken) => {
|
|
|
54
54
|
}
|
|
55
55
|
return data;
|
|
56
56
|
};
|
|
57
|
-
function PriceOSProvider({ children, getBearerToken }) {
|
|
58
|
-
return (0, import_react.createElement)(PriceOSContext.Provider, { value: { getBearerToken } }, children);
|
|
57
|
+
function PriceOSProvider({ children, getBearerToken, backendUrl }) {
|
|
58
|
+
return (0, import_react.createElement)(PriceOSContext.Provider, { value: { getBearerToken, backendUrl } }, children);
|
|
59
59
|
}
|
|
60
|
-
function useCustomer(options) {
|
|
61
|
-
const {
|
|
62
|
-
const { getBearerToken } = (0, import_react.useContext)(PriceOSContext);
|
|
60
|
+
function useCustomer(options = {}) {
|
|
61
|
+
const { swr } = options;
|
|
62
|
+
const { getBearerToken, backendUrl } = (0, import_react.useContext)(PriceOSContext);
|
|
63
63
|
const fetcher = async (url) => {
|
|
64
64
|
const bearerToken = getBearerToken ? await getBearerToken() : void 0;
|
|
65
65
|
return requestCustomer(fetch, url, bearerToken);
|
|
66
66
|
};
|
|
67
67
|
const { data, error, isLoading, mutate } = (0, import_swr.default)(
|
|
68
|
-
buildUrl(
|
|
68
|
+
buildUrl(backendUrl ?? DEFAULT_BACKEND_URL),
|
|
69
69
|
fetcher,
|
|
70
70
|
swr
|
|
71
71
|
);
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createContext, createElement, useContext, type ReactNode } from \"react\";\nimport useSWR, { type SWRConfiguration } from \"swr\";\nimport type { GetCustomerResponse } from \"priceos\";\n\nexport type UseCustomerOptions = {\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createContext, createElement, useContext, type ReactNode } from \"react\";\nimport useSWR, { type SWRConfiguration } from \"swr\";\nimport type { GetCustomerResponse } from \"priceos\";\n\nexport type UseCustomerOptions = {\n swr?: SWRConfiguration<GetCustomerResponse | null, Error>;\n};\n\nexport type PriceOSProviderProps = {\n children: ReactNode;\n getBearerToken?: () => Promise<string | null | undefined>;\n backendUrl?: string;\n};\n\nexport type UseCustomerResult = {\n customer: GetCustomerResponse | null;\n error: Error | null;\n loading: boolean;\n refetch: () => Promise<void>;\n};\n\nconst DEFAULT_BACKEND_URL = \"/api/priceos\";\n\ntype PriceOSContextValue = {\n getBearerToken?: () => Promise<string | null | undefined>;\n backendUrl?: string;\n};\n\nconst PriceOSContext = createContext<PriceOSContextValue>({});\n\nconst normalizeBaseUrl = (baseUrl: string) => baseUrl.replace(/\\/$/, \"\");\n\nconst buildUrl = (backendUrl: string) => {\n const normalizedBase = normalizeBaseUrl(backendUrl);\n return `${normalizedBase}/v1/customer`;\n};\n\nconst requestCustomer = async (\n fetchFn: typeof fetch,\n url: string,\n bearerToken?: string | null\n): Promise<GetCustomerResponse | null> => {\n const headers = bearerToken ? { Authorization: `Bearer ${bearerToken}` } : undefined;\n const response = await fetchFn(url, headers ? { headers } : undefined);\n const text = await response.text();\n const data = text ? (JSON.parse(text) as unknown) : null;\n if (!response.ok) {\n const message =\n data && typeof data === \"object\" && \"error\" in data\n ? String((data as { error?: unknown }).error)\n : response.statusText;\n throw new Error(message || \"Request failed\");\n }\n return data as GetCustomerResponse | null;\n};\n\nexport function PriceOSProvider({ children, getBearerToken, backendUrl }: PriceOSProviderProps) {\n return createElement(PriceOSContext.Provider, { value: { getBearerToken, backendUrl } }, children);\n}\n\nexport function useCustomer(options: UseCustomerOptions = {}): UseCustomerResult {\n const { swr } = options;\n const { getBearerToken, backendUrl } = useContext(PriceOSContext);\n const fetcher = async (url: string) => {\n const bearerToken = getBearerToken ? await getBearerToken() : undefined;\n return requestCustomer(fetch, url, bearerToken);\n };\n const { data, error, isLoading, mutate } = useSWR(\n buildUrl(backendUrl ?? DEFAULT_BACKEND_URL),\n fetcher,\n swr\n );\n\n return {\n customer: data ?? null,\n error,\n loading: isLoading,\n refetch: async () => {\n await mutate();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAyE;AACzE,iBAA8C;AAoB9C,IAAM,sBAAsB;AAO5B,IAAM,qBAAiB,4BAAmC,CAAC,CAAC;AAE5D,IAAM,mBAAmB,CAAC,YAAoB,QAAQ,QAAQ,OAAO,EAAE;AAEvE,IAAM,WAAW,CAAC,eAAuB;AACvC,QAAM,iBAAiB,iBAAiB,UAAU;AAClD,SAAO,GAAG,cAAc;AAC1B;AAEA,IAAM,kBAAkB,OACtB,SACA,KACA,gBACwC;AACxC,QAAM,UAAU,cAAc,EAAE,eAAe,UAAU,WAAW,GAAG,IAAI;AAC3E,QAAM,WAAW,MAAM,QAAQ,KAAK,UAAU,EAAE,QAAQ,IAAI,MAAS;AACrE,QAAM,OAAO,MAAM,SAAS,KAAK;AACjC,QAAM,OAAO,OAAQ,KAAK,MAAM,IAAI,IAAgB;AACpD,MAAI,CAAC,SAAS,IAAI;AAChB,UAAM,UACJ,QAAQ,OAAO,SAAS,YAAY,WAAW,OAC3C,OAAQ,KAA6B,KAAK,IAC1C,SAAS;AACf,UAAM,IAAI,MAAM,WAAW,gBAAgB;AAAA,EAC7C;AACA,SAAO;AACT;AAEO,SAAS,gBAAgB,EAAE,UAAU,gBAAgB,WAAW,GAAyB;AAC9F,aAAO,4BAAc,eAAe,UAAU,EAAE,OAAO,EAAE,gBAAgB,WAAW,EAAE,GAAG,QAAQ;AACnG;AAEO,SAAS,YAAY,UAA8B,CAAC,GAAsB;AAC/E,QAAM,EAAE,IAAI,IAAI;AAChB,QAAM,EAAE,gBAAgB,WAAW,QAAI,yBAAW,cAAc;AAChE,QAAM,UAAU,OAAO,QAAgB;AACrC,UAAM,cAAc,iBAAiB,MAAM,eAAe,IAAI;AAC9D,WAAO,gBAAgB,OAAO,KAAK,WAAW;AAAA,EAChD;AACA,QAAM,EAAE,MAAM,OAAO,WAAW,OAAO,QAAI,WAAAA;AAAA,IACzC,SAAS,cAAc,mBAAmB;AAAA,IAC1C;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AAAA,IACL,UAAU,QAAQ;AAAA,IAClB;AAAA,IACA,SAAS;AAAA,IACT,SAAS,YAAY;AACnB,YAAM,OAAO;AAAA,IACf;AAAA,EACF;AACF;","names":["useSWR"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -4,12 +4,12 @@ import { SWRConfiguration } from 'swr';
|
|
|
4
4
|
import { GetCustomerResponse } from 'priceos';
|
|
5
5
|
|
|
6
6
|
type UseCustomerOptions = {
|
|
7
|
-
customerId: string;
|
|
8
7
|
swr?: SWRConfiguration<GetCustomerResponse | null, Error>;
|
|
9
8
|
};
|
|
10
9
|
type PriceOSProviderProps = {
|
|
11
10
|
children: ReactNode;
|
|
12
11
|
getBearerToken?: () => Promise<string | null | undefined>;
|
|
12
|
+
backendUrl?: string;
|
|
13
13
|
};
|
|
14
14
|
type UseCustomerResult = {
|
|
15
15
|
customer: GetCustomerResponse | null;
|
|
@@ -19,8 +19,9 @@ type UseCustomerResult = {
|
|
|
19
19
|
};
|
|
20
20
|
type PriceOSContextValue = {
|
|
21
21
|
getBearerToken?: () => Promise<string | null | undefined>;
|
|
22
|
+
backendUrl?: string;
|
|
22
23
|
};
|
|
23
|
-
declare function PriceOSProvider({ children, getBearerToken }: PriceOSProviderProps): react.FunctionComponentElement<react.ProviderProps<PriceOSContextValue>>;
|
|
24
|
-
declare function useCustomer(options
|
|
24
|
+
declare function PriceOSProvider({ children, getBearerToken, backendUrl }: PriceOSProviderProps): react.FunctionComponentElement<react.ProviderProps<PriceOSContextValue>>;
|
|
25
|
+
declare function useCustomer(options?: UseCustomerOptions): UseCustomerResult;
|
|
25
26
|
|
|
26
27
|
export { PriceOSProvider, type PriceOSProviderProps, type UseCustomerOptions, type UseCustomerResult, useCustomer };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,12 +4,12 @@ import { SWRConfiguration } from 'swr';
|
|
|
4
4
|
import { GetCustomerResponse } from 'priceos';
|
|
5
5
|
|
|
6
6
|
type UseCustomerOptions = {
|
|
7
|
-
customerId: string;
|
|
8
7
|
swr?: SWRConfiguration<GetCustomerResponse | null, Error>;
|
|
9
8
|
};
|
|
10
9
|
type PriceOSProviderProps = {
|
|
11
10
|
children: ReactNode;
|
|
12
11
|
getBearerToken?: () => Promise<string | null | undefined>;
|
|
12
|
+
backendUrl?: string;
|
|
13
13
|
};
|
|
14
14
|
type UseCustomerResult = {
|
|
15
15
|
customer: GetCustomerResponse | null;
|
|
@@ -19,8 +19,9 @@ type UseCustomerResult = {
|
|
|
19
19
|
};
|
|
20
20
|
type PriceOSContextValue = {
|
|
21
21
|
getBearerToken?: () => Promise<string | null | undefined>;
|
|
22
|
+
backendUrl?: string;
|
|
22
23
|
};
|
|
23
|
-
declare function PriceOSProvider({ children, getBearerToken }: PriceOSProviderProps): react.FunctionComponentElement<react.ProviderProps<PriceOSContextValue>>;
|
|
24
|
-
declare function useCustomer(options
|
|
24
|
+
declare function PriceOSProvider({ children, getBearerToken, backendUrl }: PriceOSProviderProps): react.FunctionComponentElement<react.ProviderProps<PriceOSContextValue>>;
|
|
25
|
+
declare function useCustomer(options?: UseCustomerOptions): UseCustomerResult;
|
|
25
26
|
|
|
26
27
|
export { PriceOSProvider, type PriceOSProviderProps, type UseCustomerOptions, type UseCustomerResult, useCustomer };
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
2
|
import { createContext, createElement, useContext } from "react";
|
|
3
3
|
import useSWR from "swr";
|
|
4
|
-
var
|
|
4
|
+
var DEFAULT_BACKEND_URL = "/api/priceos";
|
|
5
5
|
var PriceOSContext = createContext({});
|
|
6
6
|
var normalizeBaseUrl = (baseUrl) => baseUrl.replace(/\/$/, "");
|
|
7
|
-
var buildUrl = (
|
|
8
|
-
const normalizedBase = normalizeBaseUrl(
|
|
9
|
-
return `${normalizedBase}/v1/
|
|
7
|
+
var buildUrl = (backendUrl) => {
|
|
8
|
+
const normalizedBase = normalizeBaseUrl(backendUrl);
|
|
9
|
+
return `${normalizedBase}/v1/customer`;
|
|
10
10
|
};
|
|
11
11
|
var requestCustomer = async (fetchFn, url, bearerToken) => {
|
|
12
12
|
const headers = bearerToken ? { Authorization: `Bearer ${bearerToken}` } : void 0;
|
|
@@ -19,18 +19,18 @@ var requestCustomer = async (fetchFn, url, bearerToken) => {
|
|
|
19
19
|
}
|
|
20
20
|
return data;
|
|
21
21
|
};
|
|
22
|
-
function PriceOSProvider({ children, getBearerToken }) {
|
|
23
|
-
return createElement(PriceOSContext.Provider, { value: { getBearerToken } }, children);
|
|
22
|
+
function PriceOSProvider({ children, getBearerToken, backendUrl }) {
|
|
23
|
+
return createElement(PriceOSContext.Provider, { value: { getBearerToken, backendUrl } }, children);
|
|
24
24
|
}
|
|
25
|
-
function useCustomer(options) {
|
|
26
|
-
const {
|
|
27
|
-
const { getBearerToken } = useContext(PriceOSContext);
|
|
25
|
+
function useCustomer(options = {}) {
|
|
26
|
+
const { swr } = options;
|
|
27
|
+
const { getBearerToken, backendUrl } = useContext(PriceOSContext);
|
|
28
28
|
const fetcher = async (url) => {
|
|
29
29
|
const bearerToken = getBearerToken ? await getBearerToken() : void 0;
|
|
30
30
|
return requestCustomer(fetch, url, bearerToken);
|
|
31
31
|
};
|
|
32
32
|
const { data, error, isLoading, mutate } = useSWR(
|
|
33
|
-
buildUrl(
|
|
33
|
+
buildUrl(backendUrl ?? DEFAULT_BACKEND_URL),
|
|
34
34
|
fetcher,
|
|
35
35
|
swr
|
|
36
36
|
);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createContext, createElement, useContext, type ReactNode } from \"react\";\nimport useSWR, { type SWRConfiguration } from \"swr\";\nimport type { GetCustomerResponse } from \"priceos\";\n\nexport type UseCustomerOptions = {\n
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { createContext, createElement, useContext, type ReactNode } from \"react\";\nimport useSWR, { type SWRConfiguration } from \"swr\";\nimport type { GetCustomerResponse } from \"priceos\";\n\nexport type UseCustomerOptions = {\n swr?: SWRConfiguration<GetCustomerResponse | null, Error>;\n};\n\nexport type PriceOSProviderProps = {\n children: ReactNode;\n getBearerToken?: () => Promise<string | null | undefined>;\n backendUrl?: string;\n};\n\nexport type UseCustomerResult = {\n customer: GetCustomerResponse | null;\n error: Error | null;\n loading: boolean;\n refetch: () => Promise<void>;\n};\n\nconst DEFAULT_BACKEND_URL = \"/api/priceos\";\n\ntype PriceOSContextValue = {\n getBearerToken?: () => Promise<string | null | undefined>;\n backendUrl?: string;\n};\n\nconst PriceOSContext = createContext<PriceOSContextValue>({});\n\nconst normalizeBaseUrl = (baseUrl: string) => baseUrl.replace(/\\/$/, \"\");\n\nconst buildUrl = (backendUrl: string) => {\n const normalizedBase = normalizeBaseUrl(backendUrl);\n return `${normalizedBase}/v1/customer`;\n};\n\nconst requestCustomer = async (\n fetchFn: typeof fetch,\n url: string,\n bearerToken?: string | null\n): Promise<GetCustomerResponse | null> => {\n const headers = bearerToken ? { Authorization: `Bearer ${bearerToken}` } : undefined;\n const response = await fetchFn(url, headers ? { headers } : undefined);\n const text = await response.text();\n const data = text ? (JSON.parse(text) as unknown) : null;\n if (!response.ok) {\n const message =\n data && typeof data === \"object\" && \"error\" in data\n ? String((data as { error?: unknown }).error)\n : response.statusText;\n throw new Error(message || \"Request failed\");\n }\n return data as GetCustomerResponse | null;\n};\n\nexport function PriceOSProvider({ children, getBearerToken, backendUrl }: PriceOSProviderProps) {\n return createElement(PriceOSContext.Provider, { value: { getBearerToken, backendUrl } }, children);\n}\n\nexport function useCustomer(options: UseCustomerOptions = {}): UseCustomerResult {\n const { swr } = options;\n const { getBearerToken, backendUrl } = useContext(PriceOSContext);\n const fetcher = async (url: string) => {\n const bearerToken = getBearerToken ? await getBearerToken() : undefined;\n return requestCustomer(fetch, url, bearerToken);\n };\n const { data, error, isLoading, mutate } = useSWR(\n buildUrl(backendUrl ?? DEFAULT_BACKEND_URL),\n fetcher,\n swr\n );\n\n return {\n customer: data ?? null,\n error,\n loading: isLoading,\n refetch: async () => {\n await mutate();\n },\n };\n}\n"],"mappings":";AAAA,SAAS,eAAe,eAAe,kBAAkC;AACzE,OAAO,YAAuC;AAoB9C,IAAM,sBAAsB;AAO5B,IAAM,iBAAiB,cAAmC,CAAC,CAAC;AAE5D,IAAM,mBAAmB,CAAC,YAAoB,QAAQ,QAAQ,OAAO,EAAE;AAEvE,IAAM,W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