@commercelayer/app-elements 0.0.31 → 0.0.33
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/{Async-281227f9.js → Async-3dedb4f0.js} +2 -2
- package/dist/{InputDateComponent-46bccbbd.js → InputDateComponent-a8f9b68b.js} +1 -1
- package/dist/{Select-d4f2a4fe.js → Select-f4bb0837.js} +2 -2
- package/dist/{main-1a232919.js → main-f4e7240e.js} +818 -826
- package/dist/main.d.ts +1 -1
- package/dist/main.js +1 -1
- package/dist/{overrides-5c1474c7.js → overrides-2ea823f6.js} +1 -1
- package/dist/providers/CoreSdkProvider/useCoreApi.d.ts +2 -33
- package/dist/providers/TokenProvider/index.d.ts +12 -7
- package/dist/providers/TokenProvider/reducer.d.ts +4 -1
- package/dist/providers/TokenProvider/storage.d.ts +6 -6
- package/dist/providers/TokenProvider/types.d.ts +36 -5
- package/dist/providers/TokenProvider/validateToken.d.ts +5 -4
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ export { CoreSdkProvider, useCoreSdkProvider } from './providers/CoreSdkProvider
|
|
|
6
6
|
export { useCoreApi } from './providers/CoreSdkProvider/useCoreApi';
|
|
7
7
|
export { ErrorBoundary } from './providers/ErrorBoundary';
|
|
8
8
|
export { TokenProvider, useTokenProvider } from './providers/TokenProvider';
|
|
9
|
-
export type { TokenProviderAllowedApp, TokenProviderPermissionItem,
|
|
9
|
+
export type { TokenProviderAllowedApp, TokenProviderPermissionItem, TokenProviderRoleActions, TokenProviderRolePermissions, TokenProviderTokenApplicationKind } from './providers/TokenProvider/types';
|
|
10
10
|
export { A } from './ui/atoms/A';
|
|
11
11
|
export { Avatar } from './ui/atoms/Avatar';
|
|
12
12
|
export { Badge } from './ui/atoms/Badge';
|
package/dist/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { X as o, Y as r, Z as n, _ as i, $ as l, a0 as u, a1 as d, a2 as p, ar as g, a3 as S, R as T, al as D, am as I, an as m, a4 as k, U as c, a5 as B, a6 as y, a7 as C, ay as L, az as P, aA as b, aB as x, aC as A, aD as R, aE as f, aF as v, aG as w, aK as F, aL as h, aM as M, aN as E, a8 as V, aQ as J, aR as H, aS as N, aT as O, aU as G, as as K, a9 as Q, at as U, au as W, aa as X, ab as j, aO as q, av as z, aV as Y, aw as Z, ac as _, ad as $, af as aa, ag as sa, ah as ea, ai as ta, aW as oa, aX as ra, aj as na, ao as ia, ak as la, ap as ua, ax as da, aP as pa, V as ga, aq as Sa, N as Ta, aH as Da, J as Ia, O as ma, aI as ka, K as ca, L as Ba, aJ as ya, M as Ca, T as La, S as Pa, Q as ba, W as xa, ae as Aa } from "./main-
|
|
1
|
+
import { X as o, Y as r, Z as n, _ as i, $ as l, a0 as u, a1 as d, a2 as p, ar as g, a3 as S, R as T, al as D, am as I, an as m, a4 as k, U as c, a5 as B, a6 as y, a7 as C, ay as L, az as P, aA as b, aB as x, aC as A, aD as R, aE as f, aF as v, aG as w, aK as F, aL as h, aM as M, aN as E, a8 as V, aQ as J, aR as H, aS as N, aT as O, aU as G, as as K, a9 as Q, at as U, au as W, aa as X, ab as j, aO as q, av as z, aV as Y, aw as Z, ac as _, ad as $, af as aa, ag as sa, ah as ea, ai as ta, aW as oa, aX as ra, aj as na, ao as ia, ak as la, ap as ua, ax as da, aP as pa, V as ga, aq as Sa, N as Ta, aH as Da, J as Ia, O as ma, aI as ka, K as ca, L as Ba, aJ as ya, M as Ca, T as La, S as Pa, Q as ba, W as xa, ae as Aa } from "./main-f4e7240e.js";
|
|
2
2
|
import "react";
|
|
3
3
|
import "@commercelayer/sdk";
|
|
4
4
|
export {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as V from "react";
|
|
2
2
|
import fe, { useLayoutEffect as yn, createContext as Et, forwardRef as Cr, useContext as Te, createElement as pe, Fragment as Ne, useRef as ue, useState as me, useMemo as Ce, useCallback as Y, Component as Ar, useEffect as En } from "react";
|
|
3
|
-
import { H as yr } from "./main-
|
|
3
|
+
import { H as yr } from "./main-f4e7240e.js";
|
|
4
4
|
import { createPortal as Er } from "react-dom";
|
|
5
5
|
var Ue = {}, xr = {
|
|
6
6
|
get exports() {
|
|
@@ -1,35 +1,4 @@
|
|
|
1
1
|
import type { CommerceLayerClient } from '@commercelayer/sdk';
|
|
2
2
|
import type { ListableResourceType } from '@commercelayer/sdk/lib/cjs/api';
|
|
3
|
-
import { type
|
|
4
|
-
export declare
|
|
5
|
-
errorRetryInterval?: number | undefined;
|
|
6
|
-
errorRetryCount?: number | undefined;
|
|
7
|
-
loadingTimeout?: number | undefined;
|
|
8
|
-
focusThrottleInterval?: number | undefined;
|
|
9
|
-
dedupingInterval?: number | undefined;
|
|
10
|
-
refreshInterval?: number | ((latestData: Output | undefined) => number) | undefined;
|
|
11
|
-
refreshWhenHidden?: boolean | undefined;
|
|
12
|
-
refreshWhenOffline?: boolean | undefined;
|
|
13
|
-
revalidateOnFocus: boolean;
|
|
14
|
-
revalidateOnReconnect?: boolean | undefined;
|
|
15
|
-
revalidateOnMount?: boolean | undefined;
|
|
16
|
-
revalidateIfStale?: boolean | undefined;
|
|
17
|
-
shouldRetryOnError?: boolean | ((err: any) => boolean) | undefined;
|
|
18
|
-
keepPreviousData?: boolean | undefined;
|
|
19
|
-
suspense?: boolean | undefined;
|
|
20
|
-
fallbackData?: Output | undefined;
|
|
21
|
-
fetcher?: BareFetcher<Output> | undefined;
|
|
22
|
-
use?: import("swr/_internal").Middleware[] | undefined;
|
|
23
|
-
fallback?: {
|
|
24
|
-
[key: string]: any;
|
|
25
|
-
} | undefined;
|
|
26
|
-
isPaused?: (() => boolean) | undefined;
|
|
27
|
-
onLoadingSlow?: ((key: string, config: Readonly<import("swr/_internal").PublicConfiguration<Output, any, BareFetcher<Output>>>) => void) | undefined;
|
|
28
|
-
onSuccess?: ((data: Output, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<Output, any, BareFetcher<Output>>>) => void) | undefined;
|
|
29
|
-
onError?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<Output, any, BareFetcher<Output>>>) => void) | undefined;
|
|
30
|
-
onErrorRetry?: ((err: any, key: string, config: Readonly<import("swr/_internal").PublicConfiguration<Output, any, BareFetcher<Output>>>, revalidate: import("swr/_internal").Revalidator, revalidateOpts: Required<import("swr/_internal").RevalidatorOptions>) => void) | undefined;
|
|
31
|
-
onDiscarded?: ((key: string) => void) | undefined;
|
|
32
|
-
compare?: ((a: Output | undefined, b: Output | undefined) => boolean) | undefined;
|
|
33
|
-
isOnline?: (() => boolean) | undefined;
|
|
34
|
-
isVisible?: (() => boolean) | undefined;
|
|
35
|
-
}>;
|
|
3
|
+
import { type Fetcher, type SWRConfiguration, type SWRResponse } from 'swr';
|
|
4
|
+
export declare function useCoreApi<Resource extends ListableResourceType, Action extends 'list' | 'retrieve', Method extends CommerceLayerClient[Resource][Action], Output extends Awaited<ReturnType<Method>>, SWROptions extends SWRConfiguration<Output, any, Fetcher<Output>>>(resource: Resource, action: Action, args: Parameters<Method>, config?: SWROptions): SWRResponse<Output, any, SWROptions>;
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import { type
|
|
2
|
+
import { type TokenProviderTokenApplicationKind } from '../TokenProvider/types';
|
|
3
|
+
import { type ListableResourceType } from '@commercelayer/sdk/lib/cjs/api';
|
|
4
|
+
import { type TokenProviderAllowedApp, type TokenProviderAuthSettings, type TokenProviderAuthUser, type TokenProviderRoleActions } from './types';
|
|
3
5
|
interface TokenProviderValue {
|
|
4
6
|
dashboardUrl?: string;
|
|
5
7
|
settings: TokenProviderAuthSettings;
|
|
6
8
|
user: TokenProviderAuthUser | null;
|
|
7
|
-
canUser: (action: TokenProviderRoleActions, resource:
|
|
9
|
+
canUser: (action: TokenProviderRoleActions, resource: ListableResourceType) => boolean;
|
|
10
|
+
canAccess: (appSlug: TokenProviderAllowedApp) => boolean;
|
|
8
11
|
emitInvalidAuth: (reason: string) => void;
|
|
9
12
|
}
|
|
10
13
|
export interface TokenProviderProps {
|
|
11
14
|
/**
|
|
12
15
|
* Token kind (will be validated)
|
|
16
|
+
* Eg. `integration` or `webapp` but also `imports` or `orders` in case of dashboard-generated token
|
|
13
17
|
*/
|
|
14
|
-
|
|
18
|
+
kind: TokenProviderTokenApplicationKind;
|
|
15
19
|
/**
|
|
16
|
-
* Slug of the current app
|
|
20
|
+
* Slug of the current app. Can be one of imports, exports, webhooks, resources, orders or custom.
|
|
21
|
+
* Will be used to persist token for current app only.
|
|
17
22
|
*/
|
|
18
|
-
|
|
23
|
+
appSlug: TokenProviderAllowedApp;
|
|
19
24
|
/**
|
|
20
25
|
* Base domain to be used for Commerce Layer API requests (eg. `commercelayer.io`)
|
|
21
26
|
*/
|
|
@@ -59,8 +64,8 @@ declare function MockTokenProvider({ children }: TokenProviderProps): JSX.Elemen
|
|
|
59
64
|
declare namespace MockTokenProvider {
|
|
60
65
|
var displayName: string;
|
|
61
66
|
}
|
|
62
|
-
declare function TokenProvider({
|
|
67
|
+
declare function TokenProvider({ appSlug, kind, domain, onInvalidAuth, reauthenticateOnInvalidAuth, loadingElement, errorElement, devMode, children, accessToken: accessTokenFromProp }: TokenProviderProps): JSX.Element;
|
|
63
68
|
declare namespace TokenProvider {
|
|
64
69
|
var displayName: string;
|
|
65
70
|
}
|
|
66
|
-
export {
|
|
71
|
+
export { MockTokenProvider, TokenProvider };
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type TokenProviderAllowedApp } from '../TokenProvider/types';
|
|
2
|
+
import { type TokenProviderAuthSettings, type TokenProviderAuthUser, type TokenProviderRolePermissions } from './types';
|
|
2
3
|
interface TokenProviderInternalState {
|
|
3
4
|
validAuthToken?: string;
|
|
4
5
|
dashboardUrl: string;
|
|
5
6
|
isLoading: boolean;
|
|
6
7
|
isTokenError: boolean;
|
|
7
8
|
rolePermissions: TokenProviderRolePermissions;
|
|
9
|
+
accessibleApps: TokenProviderAllowedApp[];
|
|
8
10
|
settings: TokenProviderAuthSettings;
|
|
9
11
|
user: TokenProviderAuthUser | null;
|
|
10
12
|
}
|
|
@@ -17,6 +19,7 @@ type Action = {
|
|
|
17
19
|
settings: TokenProviderAuthSettings;
|
|
18
20
|
user: TokenProviderAuthUser | null;
|
|
19
21
|
rolePermissions: TokenProviderRolePermissions;
|
|
22
|
+
accessibleApps: TokenProviderAllowedApp[];
|
|
20
23
|
};
|
|
21
24
|
};
|
|
22
25
|
export declare const reducer: (state: TokenProviderInternalState, action: Action) => TokenProviderInternalState;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { type TokenProviderAllowedApp } from './types';
|
|
2
2
|
type PersistentItem = 'accessToken';
|
|
3
|
-
export declare function makeStorageKey({
|
|
4
|
-
|
|
3
|
+
export declare function makeStorageKey({ appSlug, item }: {
|
|
4
|
+
appSlug: TokenProviderAllowedApp;
|
|
5
5
|
item: PersistentItem;
|
|
6
6
|
}): string;
|
|
7
|
-
export declare function getPersistentAccessToken({
|
|
8
|
-
|
|
7
|
+
export declare function getPersistentAccessToken({ appSlug }: {
|
|
8
|
+
appSlug: TokenProviderAllowedApp;
|
|
9
9
|
}): string | null;
|
|
10
|
-
export declare function savePersistentAccessToken({
|
|
11
|
-
|
|
10
|
+
export declare function savePersistentAccessToken({ appSlug, accessToken }: {
|
|
11
|
+
appSlug: TokenProviderAllowedApp;
|
|
12
12
|
accessToken: string;
|
|
13
13
|
}): void;
|
|
14
14
|
export {};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
export type
|
|
1
|
+
import { type ListableResourceType } from '@commercelayer/sdk/lib/cjs/api';
|
|
2
|
+
export type TokenProviderTokenApplicationKind = 'integration' | 'sales_channel' | 'webapp' | ListableResourceType;
|
|
3
|
+
export type TokenProviderAllowedApp = ListableResourceType | 'resources';
|
|
3
4
|
export type TokenProviderRoleActions = 'create' | 'destroy' | 'read' | 'update';
|
|
4
5
|
export type TokenProviderPermissionItem = Record<TokenProviderRoleActions, boolean>;
|
|
5
|
-
export type TokenProviderRolePermissions = Partial<Record<
|
|
6
|
+
export type TokenProviderRolePermissions = Partial<Record<ListableResourceType, TokenProviderPermissionItem>>;
|
|
6
7
|
interface CoreApiOwnerUser {
|
|
7
8
|
type: 'User';
|
|
8
9
|
id: string;
|
|
@@ -31,14 +32,44 @@ export interface TokenProviderTokenInfo {
|
|
|
31
32
|
};
|
|
32
33
|
application: {
|
|
33
34
|
id: string;
|
|
34
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Token application kind.
|
|
37
|
+
*/
|
|
38
|
+
kind: 'integration' | 'sales_channel' | 'webapp' | ListableResourceType;
|
|
39
|
+
/**
|
|
40
|
+
* The name of the application.
|
|
41
|
+
* When token is generated from the dashboard hub it could be 'Imports', 'Orders', etc...
|
|
42
|
+
* When is a standard token (`integration`, `sales_channel` or `webapp`) it will be the name assigned when the application was created.
|
|
43
|
+
*/
|
|
35
44
|
name: string;
|
|
45
|
+
/**
|
|
46
|
+
* This will be `true` when the token is generated from the dashboard hub.
|
|
47
|
+
* Only dashboard hub can generate a `core` token.
|
|
48
|
+
*/
|
|
36
49
|
core: boolean;
|
|
37
50
|
};
|
|
38
|
-
|
|
51
|
+
/**
|
|
52
|
+
* List of resources with specific permissions for current token.
|
|
53
|
+
*/
|
|
54
|
+
permissions: Record<ListableResourceType, {
|
|
39
55
|
actions: TokenProviderRoleActions[];
|
|
40
56
|
}>;
|
|
57
|
+
/**
|
|
58
|
+
* Owner is only present when the token is generated with a logged-in user
|
|
59
|
+
*/
|
|
41
60
|
owner?: CoreApiOwnerUser | CoreApiOwnerCustomer;
|
|
61
|
+
/**
|
|
62
|
+
* This will contain the list of hub applications that the token can access.
|
|
63
|
+
* Example:
|
|
64
|
+
* ```
|
|
65
|
+
* [{name: 'Orders', kind: 'orders', core: true}, {name: 'Imports', kind: 'imports', core: true}]
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
accessible_apps?: Array<{
|
|
69
|
+
name: string;
|
|
70
|
+
kind: ListableResourceType;
|
|
71
|
+
core: boolean;
|
|
72
|
+
}>;
|
|
42
73
|
}
|
|
43
74
|
export type Mode = 'live' | 'test';
|
|
44
75
|
export interface TokenProviderAuthSettings {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type TokenProviderAllowedApp, type TokenProviderTokenApplicationKind } from '../TokenProvider/types';
|
|
2
|
+
import { type Mode, type TokenProviderAuthUser, type TokenProviderRolePermissions } from './types';
|
|
2
3
|
export declare function isTokenExpired({ accessToken, compareTo }: {
|
|
3
4
|
accessToken: string;
|
|
4
5
|
compareTo: Date;
|
|
@@ -9,15 +10,15 @@ interface ValidToken {
|
|
|
9
10
|
mode: Mode;
|
|
10
11
|
organizationSlug: string;
|
|
11
12
|
permissions?: TokenProviderRolePermissions;
|
|
13
|
+
accessibleApps?: TokenProviderAllowedApp[];
|
|
12
14
|
user: TokenProviderAuthUser | null;
|
|
13
15
|
}
|
|
14
16
|
interface InvalidToken {
|
|
15
17
|
isValidToken: false;
|
|
16
18
|
}
|
|
17
|
-
export declare function isValidTokenForCurrentApp({ accessToken,
|
|
19
|
+
export declare function isValidTokenForCurrentApp({ accessToken, kind, domain, isProduction }: {
|
|
18
20
|
accessToken: string;
|
|
19
|
-
|
|
20
|
-
currentApp: string;
|
|
21
|
+
kind: TokenProviderTokenApplicationKind;
|
|
21
22
|
domain: string;
|
|
22
23
|
isProduction: boolean;
|
|
23
24
|
}): Promise<ValidToken | InvalidToken>;
|