Skip to content

Commit

Permalink
feat(*): add hooks version
Browse files Browse the repository at this point in the history
  • Loading branch information
cley44 committed Oct 10, 2023
1 parent 567153b commit 039f15f
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 60 deletions.
2 changes: 2 additions & 0 deletions packages/screeb-sdk-angular-example/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ bootstrapApplication(AppComponent, {
ScreebModule.forRoot({
autoInit: true,
hooks: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
onReady: (payload: any) => {
// eslint-disable-next-line no-console
console.log("SDK is ready", payload);
},
version: "1.0.0",
},
userId: "dev@screeb.app",
userProperties: {
Expand Down
10 changes: 6 additions & 4 deletions packages/screeb-sdk-angular/docs/classes/Screeb.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ this.screeb.init(
authenticated: true
},
{
onReady: (payload) => {
"version": "1.0.0",
"onReady": (payload) => {
console.log("SDK is ready", payload);
},
},
Expand All @@ -385,7 +386,7 @@ this.screeb.init(
| `websiteId` | `string` | Your website/channel id. |
| `userId?` | `string` | The unique identifier of your user. |
| `userProperties?` | `PropertyRecord` | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date ``` |
| `hooks?` | `GlobalHooks` | - |
| `hooks?` | `Hooks` | - |

#### Returns

Expand Down Expand Up @@ -446,7 +447,8 @@ this.screeb.surveyStart(
article_id: 42
},
{
onSurveyShowed: (payload) => {
"version": "1.0.0",
"onSurveyShowed": (payload) => {
console.log("Survey showed", payload);
},
},
Expand All @@ -460,7 +462,7 @@ this.screeb.surveyStart(
| `surveyId` | `string` |
| `allowMultipleResponses` | `boolean` |
| `hiddenFields` | `PropertyRecord` |
| `hooks?` | `SurveyHooks` |
| `hooks?` | `Hooks` |

#### Returns

Expand Down
2 changes: 1 addition & 1 deletion packages/screeb-sdk-angular/docs/classes/ScreebConfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ___

### hooks

`Optional` **hooks**: `GlobalHooks`
`Optional` **hooks**: `Hooks`

Hooks to define callback for various event

Expand Down
3 changes: 2 additions & 1 deletion packages/screeb-sdk-angular/docs/classes/ScreebModule.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ ScreebModule.forRoot({
authenticated: true
},
{
onReady: (payload) => {
"version": "1.0.0",
"onReady": (payload) => {
console.log("SDK is ready", payload);
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { Injectable } from "@angular/core";
import {
GlobalHooks,
PropertyRecord,
ScreebOptions,
} from "@screeb/sdk-browser";
import { Hooks, PropertyRecord, ScreebOptions } from "@screeb/sdk-browser";

/** Configuration of Screeb module */
@Injectable({ providedIn: "root" })
Expand All @@ -15,7 +11,7 @@ export class ScreebConfig {
/** The properties of your user. */
userProperties?: PropertyRecord;
/** Hooks to define callback for various event */
hooks?: GlobalHooks;
hooks?: Hooks;
/**
* Indicates if Screeb should be automatically loaded.
* This will ping to the Screeb servers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export class ScreebModule {
* authenticated: true
* },
* {
* onReady: (payload) => {
* "version": "1.0.0",
* "onReady": (payload) => {
* console.log("SDK is ready", payload);
* },
* },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ export class Screeb {
* article_id: 42
* },
* {
* onSurveyShowed: (payload) => {
* "version": "1.0.0",
* "onSurveyShowed": (payload) => {
* console.log("Survey showed", payload);
* },
* },
Expand All @@ -322,7 +323,7 @@ export class Screeb {
surveyId: string,
allowMultipleResponses: boolean,
hiddenFields: _Screeb.PropertyRecord,
hooks?: _Screeb.SurveyHooks
hooks?: _Screeb.Hooks
) {
await this.ensureScreeb("surveyStart");

Expand Down Expand Up @@ -401,7 +402,8 @@ export class Screeb {
* authenticated: true
* },
* {
* onReady: (payload) => {
* "version": "1.0.0",
* "onReady": (payload) => {
* console.log("SDK is ready", payload);
* },
* },
Expand All @@ -412,7 +414,7 @@ export class Screeb {
websiteId: string,
userId?: string,
userProperties?: _Screeb.PropertyRecord,
hooks?: _Screeb.GlobalHooks
hooks?: _Screeb.Hooks
) {
await this.ensureScreeb("init", true);

Expand Down
1 change: 1 addition & 0 deletions packages/screeb-sdk-browser-example/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
// eslint-disable-next-line no-console
console.log("screeb ready", e)
},
version: "1.0.0",
}
)
Expand Down
32 changes: 12 additions & 20 deletions packages/screeb-sdk-browser/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

### Type Aliases

- [GlobalHooks](README.md#globalhooks)
- [HookType](README.md#hooktype)
- [Hooks](README.md#hooks)
- [PropertyRecord](README.md#propertyrecord)
- [PropertyType](README.md#propertytype)
- [ScreebIdentityGetReturn](README.md#screebidentitygetreturn)
- [ScreebObject](README.md#screebobject)
- [ScreebOptions](README.md#screeboptions)
- [SurveyHooks](README.md#surveyhooks)

### Functions

Expand All @@ -36,17 +34,15 @@

## Type Aliases

### GlobalHooks
### Hooks

Ƭ **GlobalHooks**: { [key in HookType \| "onReady"]?: Function }
Ƭ **Hooks**: `Object`

___

### HookType
Hooks

Ƭ **HookType**: ``"onSurveyShowed"`` \| ``"onSurveyStarted"`` \| ``"onQuestionReplied"`` \| ``"onSurveyCompleted"`` \| ``"onSurveyHidden"``
#### Index signature

Hooks
[key: `string`]: `any`

___

Expand Down Expand Up @@ -111,12 +107,6 @@ 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. |

___

### SurveyHooks

Ƭ **SurveyHooks**: { [key in HookType]?: Function }

## Functions

### close
Expand Down Expand Up @@ -435,7 +425,8 @@ Screeb.init(
authenticated: true
},
{
onReady: (payload) => {
"version": "1.0.0",
"onReady": (payload) => {
console.log("SDK is ready", payload);
},
},
Expand All @@ -449,7 +440,7 @@ Screeb.init(
| `websiteId` | `string` | Your website/channel id. |
| `userId?` | `string` | The unique identifier of your user. |
| `userProperties?` | [`PropertyRecord`](README.md#propertyrecord) | The properties of your user. ```text Requirements: - Property names must be limited to 128 characters - No more than 1000 attributes - Supported types for values: string, number, boolean and Date ``` |
| `hooks?` | [`GlobalHooks`](README.md#globalhooks) | Hooks to be called when SDK is ready or a survey is showed, started, completed, hidden or when a question is replied. |
| `hooks?` | [`Hooks`](README.md#hooks) | Hooks to be called when SDK is ready or a survey is showed, started, completed, hidden or when a question is replied. |

#### Returns

Expand Down Expand Up @@ -544,7 +535,8 @@ Screeb.surveyStart(
article_id: 42
},
{
onSurveyShowed: (payload) => {
"version": "1.0.0",
"onSurveyShowed": (payload) => {
console.log("Survey showed", payload);
},
},
Expand All @@ -558,7 +550,7 @@ Screeb.surveyStart(
| `surveyId` | `string` | `undefined` |
| `allowMultipleResponses` | `boolean` | `true` |
| `hiddenFields` | [`PropertyRecord`](README.md#propertyrecord) | `{}` |
| `hooks?` | [`SurveyHooks`](README.md#surveyhooks) | `undefined` |
| `hooks?` | [`Hooks`](README.md#hooks) | `undefined` |

#### Returns

Expand Down
27 changes: 9 additions & 18 deletions packages/screeb-sdk-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,9 @@ export type PropertyRecord = {
/**
* Hooks
*/
export type HookType =
| "onSurveyShowed"
| "onSurveyStarted"
| "onQuestionReplied"
| "onSurveyCompleted"
| "onSurveyHidden";

export type GlobalHooks = {
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-explicit-any
[key in HookType | "onReady"]?: (payload: any) => void;
};
export type SurveyHooks = {
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-explicit-any
[key in HookType]?: (payload: any) => void;
export type Hooks = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
};

/** This is the Screeb tag options object. */
Expand Down Expand Up @@ -156,7 +145,8 @@ export const load = (options: ScreebOptions = {}) =>
* authenticated: true
* },
* {
* onReady: (payload) => {
* "version": "1.0.0",
* "onReady": (payload) => {
* console.log("SDK is ready", payload);
* },
* },
Expand All @@ -167,7 +157,7 @@ export const init = (
websiteId: string,
userId?: string,
userProperties?: PropertyRecord,
hooks?: GlobalHooks
hooks?: Hooks
) => {
let identityObject;

Expand Down Expand Up @@ -465,7 +455,8 @@ export const surveyClose = () => callScreebCommand("survey.close");
* article_id: 42
* },
* {
* onSurveyShowed: (payload) => {
* "version": "1.0.0",
* "onSurveyShowed": (payload) => {
* console.log("Survey showed", payload);
* },
* },
Expand All @@ -476,7 +467,7 @@ export const surveyStart = (
surveyId: string,
allowMultipleResponses = true,
hiddenFields: PropertyRecord = {},
hooks?: SurveyHooks
hooks?: Hooks
) =>
callScreebCommand("survey.start", surveyId, {
allow_multiple_responses: allowMultipleResponses,
Expand Down
1 change: 1 addition & 0 deletions packages/screeb-sdk-react-example/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ReactDOM.createRoot(document.getElementById("root") as HTMLElement).render(
// eslint-disable-next-line no-console
console.log("onReady", payload);
},
version: "1.0.0",
}}
>
<App />
Expand Down
2 changes: 1 addition & 1 deletion packages/screeb-sdk-react/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ Properties of Screeb provider

| Name | Type | Description |
| :------ | :------ | :------ |
| `hooks?` | `GlobalHooks` | Hooks to define callback for various event |
| `hooks?` | `Hooks` | Hooks to define callback for various event |
| `userId?` | `string` | The unique identifier of your user. |
| `userProperties?` | `PropertyRecord` | The properties of your user. |
| `websiteId` | `string` | Your website/channel id. |
Expand Down
4 changes: 2 additions & 2 deletions packages/screeb-sdk-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export const ScreebProvider: React.FC<
websiteId: string,
userId?: string,
userProperties?: Screeb.PropertyRecord,
hooks?: Screeb.GlobalHooks
hooks?: Screeb.Hooks
) => {
await ensureScreeb(
"init",
Expand Down Expand Up @@ -191,7 +191,7 @@ export const ScreebProvider: React.FC<
surveyId: string,
allowMultipleResponses: boolean,
hiddenFields: Screeb.PropertyRecord,
hooks?: Screeb.SurveyHooks
hooks?: Screeb.Hooks
) =>
await ensureScreeb("surveyStart", () =>
Screeb.surveyStart(
Expand Down
4 changes: 2 additions & 2 deletions packages/screeb-sdk-react/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-unused-vars */
import {
GlobalHooks,
Hooks,
PropertyRecord,
ScreebIdentityGetReturn,
ScreebOptions,
Expand All @@ -15,7 +15,7 @@ export type ScreebProps = {
/** The properties of your user. */
userProperties?: PropertyRecord;
/** Hooks to define callback for various event */
hooks?: GlobalHooks;
hooks?: Hooks;
};

/**
Expand Down

0 comments on commit 039f15f

Please sign in to comment.