@croct/plug-react 0.5.2 → 0.5.3

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.
@@ -9,6 +9,6 @@ type ServerSideOptions<T extends JsonObject> = {
9
9
  };
10
10
  export type DynamicContentOptions<T extends JsonObject = JsonObject> = Omit<BaseDynamicOptions, 'version'> & ServerSideOptions<T>;
11
11
  export type StaticContentOptions<T extends JsonObject = JsonObject> = Omit<BaseStaticOptions, 'version'> & ServerSideOptions<T>;
12
- export type FetchOptions<T extends JsonObject = JsonObject> = DynamicContentOptions<T> | StaticContentOptions<T>;
12
+ export type FetchOptions<T extends JsonObject = SlotContent> = DynamicContentOptions<T> | StaticContentOptions<T>;
13
13
  export declare function fetchContent<I extends VersionedSlotId, C extends JsonObject>(slotId: I, options?: FetchOptions<SlotContent<I, C>>): Promise<Omit<FetchResponse<I, C>, 'payload'>>;
14
14
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/Slot/index.tsx"],"names":[],"mappings":";;;;AAAA,iCAAwD;AAGxD,uCAA0D;AA4BnD,MAAM,IAAI,GAAkB,CAAO,KAAkC,EAAgB,EAAE;IAC1F,MAAM,EAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAC,GAAG,KAAK,CAAC;IACzC,MAAM,IAAI,GAAgC,IAAA,kBAAU,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAElE,OAAO,uBAAC,gBAAQ,cAAE,QAAQ,CAAC,IAAI,CAAC,GAAY,CAAC;AACjD,CAAC,CAAC;AALW,QAAA,IAAI,QAKf"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/Slot/index.tsx"],"names":[],"mappings":";;;;AAAA,iCAAwD;AAGxD,uCAA0D;AA4BnD,MAAM,IAAI,GAAkB,CAAO,KAAkC,EAAgB,EAAE;IAC1F,MAAM,EAAC,EAAE,EAAE,QAAQ,EAAE,GAAG,OAAO,EAAC,GAAG,KAAK,CAAC;IACzC,MAAM,IAAI,GAAG,IAAA,kBAAU,EAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAErC,OAAO,uBAAC,gBAAQ,cAAE,QAAQ,CAAC,IAAI,CAAC,GAAY,CAAC;AACjD,CAAC,CAAC;AALW,QAAA,IAAI,QAKf"}
package/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from '@croct/plug/sdk/json';
2
2
  export * from '@croct/plug/slot';
3
+ export * from '@croct/plug/component';
3
4
  export * from './CroctProvider';
4
5
  export * from './hooks';
5
6
  export * from './components';
package/index.js CHANGED
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("@croct/plug/sdk/json"), exports);
18
18
  __exportStar(require("@croct/plug/slot"), exports);
19
+ __exportStar(require("@croct/plug/component"), exports);
19
20
  __exportStar(require("./CroctProvider"), exports);
20
21
  __exportStar(require("./hooks"), exports);
21
22
  __exportStar(require("./components"), exports);
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,mDAAiC;AACjC,kDAAgC;AAChC,0CAAwB;AACxB,+CAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,mDAAiC;AACjC,wDAAsC;AACtC,kDAAgC;AAChC,0CAAwB;AACxB,+CAA6B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@croct/plug-react",
3
- "version": "0.5.2",
3
+ "version": "0.5.3",
4
4
  "description": "React components and hooks to plug your React applications into Croct.",
5
5
  "author": {
6
6
  "name": "Croct",
@@ -37,8 +37,8 @@
37
37
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
38
38
  },
39
39
  "dependencies": {
40
- "@croct/plug": "^0.11.4",
41
- "@croct/sdk": "^0.12.0"
40
+ "@croct/plug": "^0.11.6",
41
+ "@croct/sdk": "^0.12.3"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@babel/core": "^7.20.2",
@@ -47,11 +47,11 @@
47
47
  "@babel/preset-typescript": "^7.18.6",
48
48
  "@croct/eslint-plugin": "^0.6.3",
49
49
  "@storybook/addon-actions": "^6.5.13",
50
- "@storybook/addon-essentials": "^6.5.13",
50
+ "@storybook/addon-essentials": "^6.4.22",
51
51
  "@storybook/addon-links": "^6.5.13",
52
52
  "@storybook/builder-webpack5": "^6.5.13",
53
53
  "@storybook/manager-webpack5": "^6.5.13",
54
- "@storybook/react": "^6.5.13",
54
+ "@storybook/react": "^6.1.21",
55
55
  "@testing-library/jest-dom": "^5.16.5",
56
56
  "@testing-library/react": "^13.4.0",
57
57
  "@types/jest": "^29.2.3",
@@ -1,5 +1,6 @@
1
1
  import {ContentFetcher} from '@croct/sdk/contentFetcher';
2
2
  import {FetchResponse} from '@croct/plug/plug';
3
+ import {SlotContent} from '@croct/plug/slot';
3
4
  import {fetchContent, FetchOptions} from './fetchContent';
4
5
 
5
6
  const mockFetch: ContentFetcher['fetch'] = jest.fn();
@@ -33,10 +34,14 @@ describe('fetchContent', () => {
33
34
  apiKey: apiKey,
34
35
  baseEndpointUrl: 'https://croct.example.com',
35
36
  timeout: 100,
37
+ fallback: {
38
+ _component: 'component-id',
39
+ },
36
40
  };
37
41
 
38
42
  const result: FetchResponse<typeof slotId> = {
39
43
  content: {
44
+ _component: 'component',
40
45
  id: 'test',
41
46
  },
42
47
  };
@@ -67,6 +72,7 @@ describe('fetchContent', () => {
67
72
 
68
73
  const result: FetchResponse<typeof slotId> = {
69
74
  content: {
75
+ _component: 'component',
70
76
  id: 'test',
71
77
  },
72
78
  };
@@ -97,6 +103,7 @@ describe('fetchContent', () => {
97
103
 
98
104
  const result: FetchResponse<typeof slotId> = {
99
105
  content: {
106
+ _component: 'component',
100
107
  id: 'test',
101
108
  },
102
109
  };
@@ -117,7 +124,8 @@ describe('fetchContent', () => {
117
124
  it('should return the fallback value on error', async () => {
118
125
  const slotId = 'slot-id';
119
126
 
120
- const fallback = {
127
+ const fallback: SlotContent = {
128
+ _component: 'component-id',
121
129
  id: 'fallback',
122
130
  };
123
131
 
@@ -19,7 +19,7 @@ export type DynamicContentOptions<T extends JsonObject = JsonObject> =
19
19
  export type StaticContentOptions<T extends JsonObject = JsonObject> =
20
20
  Omit<BaseStaticOptions, 'version'> & ServerSideOptions<T>;
21
21
 
22
- export type FetchOptions<T extends JsonObject = JsonObject> = DynamicContentOptions<T> | StaticContentOptions<T>;
22
+ export type FetchOptions<T extends JsonObject = SlotContent> = DynamicContentOptions<T> | StaticContentOptions<T>;
23
23
 
24
24
  export function fetchContent<I extends VersionedSlotId, C extends JsonObject>(
25
25
  slotId: I,
@@ -15,7 +15,7 @@ export type UseContentOptions<I, F> = FetchOptions & {
15
15
  function useCsrContent<I, F>(
16
16
  id: VersionedSlotId,
17
17
  options: UseContentOptions<I, F> = {},
18
- ): SlotContent<VersionedSlotId> | I | F {
18
+ ): SlotContent | I | F {
19
19
  const {fallback, initial, cacheKey, expiration, ...fetchOptions} = options;
20
20
  const croct = useCroct();
21
21
 
@@ -31,7 +31,7 @@ function useCsrContent<I, F>(
31
31
  function useSsrContent<I, F>(
32
32
  _: VersionedSlotId,
33
33
  {initial}: UseContentOptions<I, F> = {},
34
- ): SlotContent<VersionedSlotId> | I | F {
34
+ ): SlotContent | I | F {
35
35
  if (initial === undefined) {
36
36
  throw new Error('The initial value is required for server-side rendering (SSR).');
37
37
  }
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from '@croct/plug/sdk/json';
2
2
  export * from '@croct/plug/slot';
3
+ export * from '@croct/plug/component';
3
4
  export * from './CroctProvider';
4
5
  export * from './hooks';
5
6
  export * from './components';