@layerfi/components 0.1.1 → 0.1.2

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/esm/index.js CHANGED
@@ -9,7 +9,6 @@ var authenticate = ({
9
9
  appId,
10
10
  appSecret,
11
11
  authenticationUrl = "https://auth.layerfi.com/oauth2/token",
12
- clientId,
13
12
  scope
14
13
  }) => () => fetch(authenticationUrl, {
15
14
  method: "POST",
@@ -20,7 +19,7 @@ var authenticate = ({
20
19
  body: formStringFromObject({
21
20
  grant_type: "client_credentials",
22
21
  scope,
23
- client_id: clientId
22
+ client_id: appId
24
23
  })
25
24
  }).then((res) => res.json());
26
25
 
@@ -2940,7 +2939,7 @@ var LayerProvider = ({
2940
2939
  appSecret,
2941
2940
  businessId,
2942
2941
  children,
2943
- clientId,
2942
+ businessAccessToken,
2944
2943
  environment = "production",
2945
2944
  theme
2946
2945
  }) => {
@@ -2963,19 +2962,30 @@ var LayerProvider = ({
2963
2962
  apiUrl,
2964
2963
  theme
2965
2964
  });
2966
- const { data: auth } = useSWR5(
2967
- isBefore(state.auth.expires_at, /* @__PURE__ */ new Date()) && "authenticate",
2965
+ const { data: auth } = appId !== void 0 && appSecret !== void 0 ? useSWR5(
2966
+ businessAccessToken === void 0 && appId !== void 0 && appSecret !== void 0 && isBefore(state.auth.expires_at, /* @__PURE__ */ new Date()) && "authenticate",
2968
2967
  Layer.authenticate({
2969
2968
  appId,
2970
2969
  appSecret,
2971
2970
  authenticationUrl: url,
2972
- scope,
2973
- clientId
2971
+ scope
2974
2972
  }),
2975
2973
  defaultSWRConfig
2976
- );
2974
+ ) : { data: void 0 };
2977
2975
  useEffect4(() => {
2978
- if (auth?.access_token) {
2976
+ if (businessAccessToken) {
2977
+ dispatch({
2978
+ type: "LayerContext.setAuth" /* setAuth */,
2979
+ payload: {
2980
+ auth: {
2981
+ access_token: businessAccessToken,
2982
+ token_type: "Bearer",
2983
+ expires_in: 3600,
2984
+ expires_at: add2(/* @__PURE__ */ new Date(), { seconds: 3600 })
2985
+ }
2986
+ }
2987
+ });
2988
+ } else if (auth?.access_token) {
2979
2989
  dispatch({
2980
2990
  type: "LayerContext.setAuth" /* setAuth */,
2981
2991
  payload: {
@@ -2986,7 +2996,7 @@ var LayerProvider = ({
2986
2996
  }
2987
2997
  });
2988
2998
  }
2989
- }, [auth?.access_token]);
2999
+ }, [businessAccessToken, auth?.access_token]);
2990
3000
  const { data: categories } = useSWR5(
2991
3001
  businessId && auth?.access_token && `categories-${businessId}`,
2992
3002
  Layer.getCategories(apiUrl, auth?.access_token, { params: { businessId } }),