From 4495342590ddf7dac431d3f93868ce720baa4a4b Mon Sep 17 00:00:00 2001 From: MD4 Date: Fri, 1 Dec 2023 11:33:45 +0100 Subject: [PATCH] fix(*): make all packages common-js compatible --- packages/screeb-sdk-browser/docs/README.md | 278 +++++++++++++++++- packages/screeb-sdk-browser/package.json | 17 +- packages/screeb-sdk-browser/src/index.ts | 1 + packages/screeb-sdk-browser/tsconfig.json | 2 +- packages/screeb-sdk-react/package.json | 17 +- packages/screeb-sdk-react/tsconfig.json | 2 +- packages/screeb-template-lib/package.json | 17 +- packages/screeb-template-lib/tsconfig.json | 2 +- packages/screeb-typescript-config/README.md | 29 +- .../src/rollup.config.js | 13 +- .../src/tsconfig.json | 10 +- 11 files changed, 349 insertions(+), 39 deletions(-) diff --git a/packages/screeb-sdk-browser/docs/README.md b/packages/screeb-sdk-browser/docs/README.md index cf7c35c..6c3bb5a 100644 --- a/packages/screeb-sdk-browser/docs/README.md +++ b/packages/screeb-sdk-browser/docs/README.md @@ -6,13 +6,31 @@ ### Type Aliases +- [Channel](README.md#channel) +- [ChannelType](README.md#channeltype) +- [HookCommonProperties](README.md#hookcommonproperties) +- [HookOnQuestionReplied](README.md#hookonquestionreplied) +- [HookOnReady](README.md#hookonready) +- [HookOnSurveyCompleted](README.md#hookonsurveycompleted) +- [HookOnSurveyHidden](README.md#hookonsurveyhidden) +- [HookOnSurveyShowed](README.md#hookonsurveyshowed) +- [HookOnSurveyStarted](README.md#hookonsurveystarted) - [Hooks](README.md#hooks) - [PropertyRecord](README.md#propertyrecord) - [PropertyType](README.md#propertytype) +- [ResponseItem](README.md#responseitem) +- [ResponseItemAnswer](README.md#responseitemanswer) +- [ResponseItemQuestion](README.md#responseitemquestion) +- [ResponseStatus](README.md#responsestatus) - [ScreebFunction](README.md#screebfunction) - [ScreebIdentityGetReturn](README.md#screebidentitygetreturn) - [ScreebObject](README.md#screebobject) - [ScreebOptions](README.md#screeboptions) +- [Survey](README.md#survey) +- [SurveyFormat](README.md#surveyformat) +- [SurveyPosition](README.md#surveyposition) +- [SurveySize](README.md#surveysize) +- [User](README.md#user) ### Functions @@ -35,6 +53,161 @@ ## Type Aliases +### Channel + +Ƭ **Channel**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `id` | `string` | +| `type` | [`ChannelType`](README.md#channeltype) | + +___ + +### ChannelType + +Ƭ **ChannelType**: ``"widget"`` \| ``"ios"`` \| ``"android"`` + +___ + +### HookCommonProperties + +Ƭ **HookCommonProperties**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `channel` | [`Channel`](README.md#channel) | +| `survey` | [`Survey`](README.md#survey) | +| `user` | [`User`](README.md#user) | + +___ + +### HookOnQuestionReplied + +Ƭ **HookOnQuestionReplied**: (`data`: [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `answer`: [`ResponseItemAnswer`](README.md#responseitemanswer) ; `id`: `string` ; `items`: [`ResponseItem`](README.md#responseitem)[] ; `question`: [`ResponseItemQuestion`](README.md#responseitemquestion) ; `status`: ``null`` } }) => `void` + +#### Type declaration + +▸ (`data`): `void` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `data` | [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `answer`: [`ResponseItemAnswer`](README.md#responseitemanswer) ; `id`: `string` ; `items`: [`ResponseItem`](README.md#responseitem)[] ; `question`: [`ResponseItemQuestion`](README.md#responseitemquestion) ; `status`: ``null`` } } | + +##### Returns + +`void` + +___ + +### HookOnReady + +Ƭ **HookOnReady**: (`data`: { `channel`: [`Channel`](README.md#channel) ; `user`: [`User`](README.md#user) }) => `void` + +#### Type declaration + +▸ (`data`): `void` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `data` | `Object` | +| `data.channel` | [`Channel`](README.md#channel) | +| `data.user` | [`User`](README.md#user) | + +##### Returns + +`void` + +___ + +### HookOnSurveyCompleted + +Ƭ **HookOnSurveyCompleted**: (`data`: [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `id`: `string` ; `items`: [`ResponseItem`](README.md#responseitem)[] } }) => `void` + +#### Type declaration + +▸ (`data`): `void` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `data` | [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `id`: `string` ; `items`: [`ResponseItem`](README.md#responseitem)[] } } | + +##### Returns + +`void` + +___ + +### HookOnSurveyHidden + +Ƭ **HookOnSurveyHidden**: (`data`: [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `hide_reason`: [`ResponseStatus`](README.md#responsestatus) ; `id`: `string` ; `items`: [`ResponseItem`](README.md#responseitem)[] } }) => `void` + +#### Type declaration + +▸ (`data`): `void` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `data` | [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `hide_reason`: [`ResponseStatus`](README.md#responsestatus) ; `id`: `string` ; `items`: [`ResponseItem`](README.md#responseitem)[] } } | + +##### Returns + +`void` + +___ + +### HookOnSurveyShowed + +Ƭ **HookOnSurveyShowed**: (`data`: [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `id`: `string` ; `items`: [`ResponseItem`](README.md#responseitem)[] } }) => `void` + +#### Type declaration + +▸ (`data`): `void` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `data` | [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `id`: `string` ; `items`: [`ResponseItem`](README.md#responseitem)[] } } | + +##### Returns + +`void` + +___ + +### HookOnSurveyStarted + +Ƭ **HookOnSurveyStarted**: (`data`: [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `id`: `string` } }) => `void` + +#### Type declaration + +▸ (`data`): `void` + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `data` | [`HookCommonProperties`](README.md#hookcommonproperties) & { `response`: { `id`: `string` } } | + +##### Returns + +`void` + +___ + ### Hooks Ƭ **Hooks**: `Object` @@ -45,12 +218,12 @@ This is the Screeb tag hooks object. | Name | Type | Description | | :------ | :------ | :------ | -| `onQuestionReplied?` | `HookOnQuestionReplied` | This hook is triggered when a question is answered | -| `onReady?` | `HookOnReady` | This hook is triggered when Screeb SD is loaded, initialized and ready to rock | -| `onSurveyCompleted?` | `HookOnSurveyCompleted` | This hook is triggered when a survey is completed | -| `onSurveyHidden?` | `HookOnSurveyHidden` | This hook is triggered when a survey is hidden | -| `onSurveyShowed?` | `HookOnSurveyShowed` | This hook is triggered when a survey is displayed on screen (also triggered when page is reloaded) | -| `onSurveyStarted?` | `HookOnSurveyStarted` | This hook is triggered when a survey is started | +| `onQuestionReplied?` | [`HookOnQuestionReplied`](README.md#hookonquestionreplied) | This hook is triggered when a question is answered | +| `onReady?` | [`HookOnReady`](README.md#hookonready) | This hook is triggered when Screeb SD is loaded, initialized and ready to rock | +| `onSurveyCompleted?` | [`HookOnSurveyCompleted`](README.md#hookonsurveycompleted) | This hook is triggered when a survey is completed | +| `onSurveyHidden?` | [`HookOnSurveyHidden`](README.md#hookonsurveyhidden) | This hook is triggered when a survey is hidden | +| `onSurveyShowed?` | [`HookOnSurveyShowed`](README.md#hookonsurveyshowed) | This hook is triggered when a survey is displayed on screen (also triggered when page is reloaded) | +| `onSurveyStarted?` | [`HookOnSurveyStarted`](README.md#hookonsurveystarted) | This hook is triggered when a survey is started | | `version` | `string` | This defines the version of hooks and their data | ___ @@ -75,6 +248,53 @@ This is property types that are supported by Screeb. ___ +### ResponseItem + +Ƭ **ResponseItem**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `answer` | [`ResponseItemAnswer`](README.md#responseitemanswer) | +| `question` | [`ResponseItemQuestion`](README.md#responseitemquestion) | + +___ + +### ResponseItemAnswer + +Ƭ **ResponseItemAnswer**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `fields?` | { `boolean?`: `boolean` ; `number?`: `number` ; `text?`: `string` ; `time?`: `string` ; `type`: ``"string"`` \| ``"number"`` \| ``"boolean"`` \| ``"none"`` \| ``"time"`` \| ``"file"`` }[] | +| `replied_at?` | `string` | + +___ + +### ResponseItemQuestion + +Ƭ **ResponseItemQuestion**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `id` | `string` | +| `title` | `string` | +| `type` | ``"text"`` \| ``"video"`` | +| `url?` | `string` | + +___ + +### ResponseStatus + +Ƭ **ResponseStatus**: ``"displayed"`` \| ``"started"`` \| ``"ended"`` \| ``"closed"`` \| ``"interrupted"`` + +___ + ### ScreebFunction Ƭ **ScreebFunction**: (...`_`: `unknown`[]) => `void` \| `Promise`<`unknown`\> @@ -136,6 +356,52 @@ This is the Screeb tag options object. | `screebEndpoint?` | `string` | Please don't do this. | | `window?` | `Window` | If you're running Screeb tag in an iframe, please set the inner window here. | +___ + +### Survey + +Ƭ **Survey**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `id` | `string` | +| `survey_format` | [`SurveyFormat`](README.md#surveyformat) | +| `survey_position` | [`SurveyPosition`](README.md#surveyposition) | +| `survey_size` | ``100`` | + +___ + +### SurveyFormat + +Ƭ **SurveyFormat**: ``"conversationnal"`` \| ``"cards"`` + +___ + +### SurveyPosition + +Ƭ **SurveyPosition**: ``"center-left"`` \| ``"center-center"`` \| ``"center-right"`` \| ``"bottom-left"`` \| ``"bottom-center"`` \| ``"bottom-right"`` + +___ + +### SurveySize + +Ƭ **SurveySize**: ``25`` \| ``50`` \| ``75`` \| ``100`` \| ``125`` \| ``150`` + +___ + +### User + +Ƭ **User**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `anonymous_id` | `string` | +| `userId?` | `string` | + ## Functions ### close diff --git a/packages/screeb-sdk-browser/package.json b/packages/screeb-sdk-browser/package.json index 0feceee..b5a5146 100644 --- a/packages/screeb-sdk-browser/package.json +++ b/packages/screeb-sdk-browser/package.json @@ -28,11 +28,20 @@ "exports": { "./package.json": "./package.json", ".": { - "import": "./dist/es/index.js" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.es.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs.js" + } } }, - "module": "dist/es/index.js", - "types": "dist/es/index.d.ts", + "module": "dist/index.es.js", + "main": "dist/index.cjs.js", + "jsnext:main": "dist/index.es.js", + "types": "dist/index.d.ts", "files": [ "dist", "docs", @@ -67,4 +76,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/screeb-sdk-browser/src/index.ts b/packages/screeb-sdk-browser/src/index.ts index 60aaccd..476bfdb 100644 --- a/packages/screeb-sdk-browser/src/index.ts +++ b/packages/screeb-sdk-browser/src/index.ts @@ -8,6 +8,7 @@ import { } from "./types"; export * from "./types"; +export * from "./hooks.types"; declare const window: Window & { $screeb?: ScreebObject }; diff --git a/packages/screeb-sdk-browser/tsconfig.json b/packages/screeb-sdk-browser/tsconfig.json index f0f826a..5c272f8 100644 --- a/packages/screeb-sdk-browser/tsconfig.json +++ b/packages/screeb-sdk-browser/tsconfig.json @@ -3,7 +3,7 @@ "include": ["src"], "exclude": ["dist", "**/*.test.ts"], "compilerOptions": { - "outDir": "dist/es", + "outDir": "dist", "declaration": true, "declarationDir": "." } diff --git a/packages/screeb-sdk-react/package.json b/packages/screeb-sdk-react/package.json index b240104..945e24b 100644 --- a/packages/screeb-sdk-react/package.json +++ b/packages/screeb-sdk-react/package.json @@ -28,11 +28,20 @@ "exports": { "./package.json": "./package.json", ".": { - "import": "./dist/es/index.js" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.es.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs.js" + } } }, - "module": "dist/es/index.js", - "types": "dist/es/index.d.ts", + "module": "dist/index.es.js", + "main": "dist/index.cjs.js", + "jsnext:main": "dist/index.es.js", + "types": "dist/index.d.ts", "files": [ "dist", "docs", @@ -77,4 +86,4 @@ "publishConfig": { "access": "public" } -} +} \ No newline at end of file diff --git a/packages/screeb-sdk-react/tsconfig.json b/packages/screeb-sdk-react/tsconfig.json index f0f826a..5c272f8 100644 --- a/packages/screeb-sdk-react/tsconfig.json +++ b/packages/screeb-sdk-react/tsconfig.json @@ -3,7 +3,7 @@ "include": ["src"], "exclude": ["dist", "**/*.test.ts"], "compilerOptions": { - "outDir": "dist/es", + "outDir": "dist", "declaration": true, "declarationDir": "." } diff --git a/packages/screeb-template-lib/package.json b/packages/screeb-template-lib/package.json index a11bcd0..e71e494 100644 --- a/packages/screeb-template-lib/package.json +++ b/packages/screeb-template-lib/package.json @@ -20,11 +20,20 @@ "exports": { "./package.json": "./package.json", ".": { - "import": "./dist/es/index.js" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.es.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs.js" + } } }, - "module": "dist/es/index.js", - "types": "dist/es/index.d.ts", + "module": "dist/index.es.js", + "main": "dist/index.cjs.js", + "jsnext:main": "dist/index.es.js", + "types": "dist/index.d.ts", "files": [ "dist" ], @@ -48,4 +57,4 @@ "prettier": "^3.0.3", "rollup": "^4.0.2" } -} +} \ No newline at end of file diff --git a/packages/screeb-template-lib/tsconfig.json b/packages/screeb-template-lib/tsconfig.json index c57a229..91b5c2d 100644 --- a/packages/screeb-template-lib/tsconfig.json +++ b/packages/screeb-template-lib/tsconfig.json @@ -3,7 +3,7 @@ "include": ["src"], "exclude": ["dist"], "compilerOptions": { - "outDir": "dist/es", + "outDir": "dist", "declaration": true, "declarationDir": "." } diff --git a/packages/screeb-typescript-config/README.md b/packages/screeb-typescript-config/README.md index f653ca7..28c0e71 100644 --- a/packages/screeb-typescript-config/README.md +++ b/packages/screeb-typescript-config/README.md @@ -25,11 +25,11 @@ In your `tsconfig.json`: "include": ["src"], "exclude": ["dist"], "compilerOptions": { - "outDir": "dist/es", + "outDir": "dist", "declaration": true, "declarationDir": "." } - + // [..] } ``` @@ -42,24 +42,31 @@ In your `package.json`: // Mandatory "scripts": { - "build": "rollup -c ../../node_modules/@screeb/typescript-config/src/rollup.config.js", + "build": "rollup -c ../../node_modules/@screeb/typescript-config/src/rollup.config.js" // [..] }, // Recommended "sideEffects": false, "type": "module", - "module": "dist/es/index.js", - "types": "dist/es/index.d.ts", - "files": [ - "dist" - ], + "module": "dist/index.es.js", + "main": "dist/index.cjs.js", + "jsnext:main": "dist/index.es.js", + "types": "dist/index.d.ts", + "files": ["dist"], "exports": { "./package.json": "./package.json", ".": { - "import": "./dist/es/index.js" + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.es.js" + }, + "require": { + "types": "./dist/index.d.ts", + "default": "./dist/index.cjs.js" + } } - }, + } // [..] } @@ -67,4 +74,4 @@ In your `package.json`: ## License -Released under [MIT License](../../LICENSE). \ No newline at end of file +Released under [MIT License](../../LICENSE). diff --git a/packages/screeb-typescript-config/src/rollup.config.js b/packages/screeb-typescript-config/src/rollup.config.js index 2e88c4a..9cce7f1 100644 --- a/packages/screeb-typescript-config/src/rollup.config.js +++ b/packages/screeb-typescript-config/src/rollup.config.js @@ -2,10 +2,15 @@ import typescript from '@rollup/plugin-typescript'; export default { input: "src/index.ts", - output: [{ - file: "dist/es/index.js", - format: "es" - }, ], + output: [ + { + file: "dist/index.es.js", + format: "es" + }, { + file: "dist/index.cjs.js", + format: "cjs" + }, + ], plugins: [typescript({ tsconfig: './tsconfig.json' })] diff --git a/packages/screeb-typescript-config/src/tsconfig.json b/packages/screeb-typescript-config/src/tsconfig.json index 14d32bd..636266b 100644 --- a/packages/screeb-typescript-config/src/tsconfig.json +++ b/packages/screeb-typescript-config/src/tsconfig.json @@ -14,7 +14,7 @@ "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "esnext", - "moduleResolution": "node", + "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, @@ -26,6 +26,10 @@ "noImplicitOverride": true, "strictNullChecks": true, "strictPropertyInitialization": true, - "noUnusedParameters": true - } + "noUnusedParameters": true, + "declaration": true, + "declarationDir": "." + }, + "include": ["."], + "exclude": ["dist", "**/*.test.ts"], } \ No newline at end of file