@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/index.d.ts CHANGED
@@ -4,10 +4,9 @@ declare module '@layerfi/components/api/layer/authenticate' {
4
4
  appId: string;
5
5
  appSecret: string;
6
6
  authenticationUrl?: string;
7
- clientId: string;
8
7
  scope: string;
9
8
  };
10
- export const authenticate: ({ appId, appSecret, authenticationUrl, clientId, scope, }: AuthenticationArguments) => () => Promise<OAuthResponse>;
9
+ export const authenticate: ({ appId, appSecret, authenticationUrl, scope, }: AuthenticationArguments) => () => Promise<OAuthResponse>;
11
10
  export {};
12
11
 
13
12
  }
@@ -104,11 +103,10 @@ declare module '@layerfi/components/api/layer/profit_and_loss' {
104
103
  }
105
104
  declare module '@layerfi/components/api/layer' {
106
105
  export const Layer: {
107
- authenticate: ({ appId, appSecret, authenticationUrl, clientId, scope, }: {
106
+ authenticate: ({ appId, appSecret, authenticationUrl, scope, }: {
108
107
  appId: string;
109
108
  appSecret: string;
110
109
  authenticationUrl?: string | undefined;
111
- clientId: string;
112
110
  scope: string;
113
111
  }) => () => Promise<import("@layerfi/components/types").OAuthResponse>;
114
112
  categorizeBankTransaction: (baseUrl: string, accessToken: string | undefined, options?: {
@@ -1025,13 +1023,13 @@ declare module '@layerfi/components/providers/LayerProvider/LayerProvider' {
1025
1023
  export const LayerEnvironment: Record<string, LayerEnvironmentConfig>;
1026
1024
  export type Props = {
1027
1025
  businessId: string;
1028
- appId: string;
1029
- appSecret: string;
1030
- clientId: string;
1026
+ appId?: string;
1027
+ appSecret?: string;
1028
+ businessAccessToken?: string;
1031
1029
  environment?: keyof typeof LayerEnvironment;
1032
1030
  theme?: LayerThemeConfig;
1033
1031
  };
1034
- export const LayerProvider: ({ appId, appSecret, businessId, children, clientId, environment, theme, }: PropsWithChildren<Props>) => React.JSX.Element;
1032
+ export const LayerProvider: ({ appId, appSecret, businessId, children, businessAccessToken, environment, theme, }: PropsWithChildren<Props>) => React.JSX.Element;
1035
1033
  export {};
1036
1034
 
1037
1035
  }
package/dist/index.js CHANGED
@@ -50,7 +50,6 @@ var authenticate = ({
50
50
  appId,
51
51
  appSecret,
52
52
  authenticationUrl = "https://auth.layerfi.com/oauth2/token",
53
- clientId,
54
53
  scope
55
54
  }) => () => fetch(authenticationUrl, {
56
55
  method: "POST",
@@ -61,7 +60,7 @@ var authenticate = ({
61
60
  body: formStringFromObject({
62
61
  grant_type: "client_credentials",
63
62
  scope,
64
- client_id: clientId
63
+ client_id: appId
65
64
  })
66
65
  }).then((res) => res.json());
67
66
 
@@ -2951,7 +2950,7 @@ var LayerProvider = ({
2951
2950
  appSecret,
2952
2951
  businessId,
2953
2952
  children,
2954
- clientId,
2953
+ businessAccessToken,
2955
2954
  environment = "production",
2956
2955
  theme
2957
2956
  }) => {
@@ -2974,19 +2973,30 @@ var LayerProvider = ({
2974
2973
  apiUrl,
2975
2974
  theme
2976
2975
  });
2977
- const { data: auth } = (0, import_swr5.default)(
2978
- (0, import_date_fns10.isBefore)(state.auth.expires_at, /* @__PURE__ */ new Date()) && "authenticate",
2976
+ const { data: auth } = appId !== void 0 && appSecret !== void 0 ? (0, import_swr5.default)(
2977
+ businessAccessToken === void 0 && appId !== void 0 && appSecret !== void 0 && (0, import_date_fns10.isBefore)(state.auth.expires_at, /* @__PURE__ */ new Date()) && "authenticate",
2979
2978
  Layer.authenticate({
2980
2979
  appId,
2981
2980
  appSecret,
2982
2981
  authenticationUrl: url,
2983
- scope,
2984
- clientId
2982
+ scope
2985
2983
  }),
2986
2984
  defaultSWRConfig
2987
- );
2985
+ ) : { data: void 0 };
2988
2986
  (0, import_react39.useEffect)(() => {
2989
- if (auth?.access_token) {
2987
+ if (businessAccessToken) {
2988
+ dispatch({
2989
+ type: "LayerContext.setAuth" /* setAuth */,
2990
+ payload: {
2991
+ auth: {
2992
+ access_token: businessAccessToken,
2993
+ token_type: "Bearer",
2994
+ expires_in: 3600,
2995
+ expires_at: (0, import_date_fns10.add)(/* @__PURE__ */ new Date(), { seconds: 3600 })
2996
+ }
2997
+ }
2998
+ });
2999
+ } else if (auth?.access_token) {
2990
3000
  dispatch({
2991
3001
  type: "LayerContext.setAuth" /* setAuth */,
2992
3002
  payload: {
@@ -2997,7 +3007,7 @@ var LayerProvider = ({
2997
3007
  }
2998
3008
  });
2999
3009
  }
3000
- }, [auth?.access_token]);
3010
+ }, [businessAccessToken, auth?.access_token]);
3001
3011
  const { data: categories } = (0, import_swr5.default)(
3002
3012
  businessId && auth?.access_token && `categories-${businessId}`,
3003
3013
  Layer.getCategories(apiUrl, auth?.access_token, { params: { businessId } }),