@getuserfeedback/sdk 0.15.1 → 0.16.0
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 +2 -16
- package/dist/index.js +2 -2
- package/dist/index.js.map +5 -5
- package/dist/internal/inline-flow.d.ts +1 -15
- package/dist/internal/inline-flow.js +2 -2
- package/dist/internal/inline-flow.js.map +3 -3
- package/dist/internal/open-request-dispatcher.d.ts +34 -0
- package/dist/internal/open-request-dispatcher.js +4 -0
- package/dist/internal/open-request-dispatcher.js.map +10 -0
- package/package.json +5 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OpenRequestedDetail } from '@getuserfeedback/protocol/host';
|
|
2
|
+
|
|
3
|
+
type OpenRequestedPayload = OpenRequestedDetail;
|
|
4
|
+
type OpenRequestedDecision = {
|
|
5
|
+
allowed: true;
|
|
6
|
+
} | {
|
|
7
|
+
allowed: false;
|
|
8
|
+
reason: string;
|
|
9
|
+
};
|
|
10
|
+
type OpenRequestedSource = OpenRequestedPayload["source"];
|
|
11
|
+
type OpenRequestedEvent = {
|
|
12
|
+
/**
|
|
13
|
+
* Origin of this open request.
|
|
14
|
+
* - `"command"`: requested by an explicit open command, e.g. when you call `client.flow(flowId).open()`.
|
|
15
|
+
* - `"targeting"`: requested by targeting plan evaluation.
|
|
16
|
+
*/
|
|
17
|
+
readonly source: OpenRequestedSource;
|
|
18
|
+
/** Flow identifier that is about to be opened. */
|
|
19
|
+
readonly flowId: string;
|
|
20
|
+
readonly defaultPrevented: boolean;
|
|
21
|
+
preventDefault: () => void;
|
|
22
|
+
};
|
|
23
|
+
type OpenRequestListener = (event: OpenRequestedEvent) => void;
|
|
24
|
+
type OpenRequestDispatcher = {
|
|
25
|
+
subscribe: (listener: OpenRequestListener) => () => void;
|
|
26
|
+
dispatch: (payload: OpenRequestedPayload, options?: {
|
|
27
|
+
onListenerError?: (error: unknown) => void;
|
|
28
|
+
preventHostDefault?: () => void;
|
|
29
|
+
}) => OpenRequestedDecision;
|
|
30
|
+
};
|
|
31
|
+
declare const createOpenRequestDispatcher: () => OpenRequestDispatcher;
|
|
32
|
+
|
|
33
|
+
export { createOpenRequestDispatcher };
|
|
34
|
+
export type { OpenRequestDispatcher };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
var u=()=>{let t=new Set;return{subscribe:(e)=>(t.add(e),()=>{t.delete(e)}),dispatch:(e,r)=>{let n=!1,o={source:e.source,flowId:e.flowId,get defaultPrevented(){return n},preventDefault:()=>{n=!0}};for(let p of t)try{p(o)}catch(s){try{if(r?.onListenerError)r.onListenerError(s);else console.error("Open request listener failed",s)}catch{}}if(n)return r?.preventHostDefault?.(),{allowed:!1,reason:"prevented_by_listener"};return{allowed:!0}}}};export{u as createOpenRequestDispatcher};
|
|
2
|
+
|
|
3
|
+
//# debugId=602291E1BD9747C064756E2164756E21
|
|
4
|
+
//# sourceMappingURL=open-request-dispatcher.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/open-request-dispatcher.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"import type { OpenRequestedDetail } from \"@getuserfeedback/protocol/host\";\n\nexport type OpenRequestedPayload = OpenRequestedDetail;\n\nexport type OpenRequestedDecision =\n\t| { allowed: true }\n\t| { allowed: false; reason: string };\n\ntype OpenRequestedSource = OpenRequestedPayload[\"source\"];\n\nexport type OpenRequestedEvent = {\n\t/**\n\t * Origin of this open request.\n\t * - `\"command\"`: requested by an explicit open command, e.g. when you call `client.flow(flowId).open()`.\n\t * - `\"targeting\"`: requested by targeting plan evaluation.\n\t */\n\treadonly source: OpenRequestedSource;\n\t/** Flow identifier that is about to be opened. */\n\treadonly flowId: string;\n\treadonly defaultPrevented: boolean;\n\tpreventDefault: () => void;\n};\n\ntype OpenRequestListener = (event: OpenRequestedEvent) => void;\n\nexport type OpenRequestDispatcher = {\n\tsubscribe: (listener: OpenRequestListener) => () => void;\n\tdispatch: (\n\t\tpayload: OpenRequestedPayload,\n\t\toptions?: {\n\t\t\tonListenerError?: (error: unknown) => void;\n\t\t\tpreventHostDefault?: () => void;\n\t\t},\n\t) => OpenRequestedDecision;\n};\n\nexport const createOpenRequestDispatcher = (): OpenRequestDispatcher => {\n\tconst listeners = new Set<OpenRequestListener>();\n\n\tconst subscribe = (listener: OpenRequestListener): (() => void) => {\n\t\tlisteners.add(listener);\n\t\treturn () => {\n\t\t\tlisteners.delete(listener);\n\t\t};\n\t};\n\n\tconst dispatch = (\n\t\tpayload: OpenRequestedPayload,\n\t\toptions?: {\n\t\t\tonListenerError?: (error: unknown) => void;\n\t\t\tpreventHostDefault?: () => void;\n\t\t},\n\t): OpenRequestedDecision => {\n\t\tlet prevented = false;\n\t\tconst event: OpenRequestedEvent = {\n\t\t\tsource: payload.source,\n\t\t\tflowId: payload.flowId,\n\t\t\tget defaultPrevented() {\n\t\t\t\treturn prevented;\n\t\t\t},\n\t\t\tpreventDefault: () => {\n\t\t\t\tprevented = true;\n\t\t\t},\n\t\t};\n\n\t\tfor (const listener of listeners) {\n\t\t\ttry {\n\t\t\t\tlistener(event);\n\t\t\t} catch (error) {\n\t\t\t\ttry {\n\t\t\t\t\tif (options?.onListenerError) {\n\t\t\t\t\t\toptions.onListenerError(error);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tconsole.error(\"Open request listener failed\", error);\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Error reporting must not become open-request authority.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (prevented) {\n\t\t\toptions?.preventHostDefault?.();\n\t\t\treturn {\n\t\t\t\tallowed: false,\n\t\t\t\treason: \"prevented_by_listener\",\n\t\t\t};\n\t\t}\n\t\treturn { allowed: true };\n\t};\n\n\treturn {\n\t\tsubscribe,\n\t\tdispatch,\n\t};\n};\n"
|
|
6
|
+
],
|
|
7
|
+
"mappings": "AAoCO,IAAM,EAA8B,IAA6B,CACvE,IAAM,EAAY,IAAI,IAsDtB,MAAO,CACN,UArDiB,CAAC,KAClB,EAAU,IAAI,CAAQ,EACf,IAAM,CACZ,EAAU,OAAO,CAAQ,IAmD1B,SA/CgB,CAChB,EACA,IAI2B,CAC3B,IAAI,EAAY,GACV,EAA4B,CACjC,OAAQ,EAAQ,OAChB,OAAQ,EAAQ,UACZ,iBAAgB,EAAG,CACtB,OAAO,GAER,eAAgB,IAAM,CACrB,EAAY,GAEd,EAEA,QAAW,KAAY,EACtB,GAAI,CACH,EAAS,CAAK,EACb,MAAO,EAAO,CACf,GAAI,CACH,GAAI,GAAS,gBACZ,EAAQ,gBAAgB,CAAK,EAE7B,aAAQ,MAAM,+BAAgC,CAAK,EAEnD,KAAM,GAMV,GAAI,EAEH,OADA,GAAS,qBAAqB,EACvB,CACN,QAAS,GACT,OAAQ,uBACT,EAED,MAAO,CAAE,QAAS,EAAK,EAMxB",
|
|
8
|
+
"debugId": "602291E1BD9747C064756E2164756E21",
|
|
9
|
+
"names": []
|
|
10
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getuserfeedback/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.0",
|
|
4
4
|
"description": "getuserfeedback Typescript SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"getuserfeedback",
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
"import": "./dist/internal/flow-open-request-controller.js",
|
|
33
33
|
"types": "./dist/internal/flow-open-request-controller.d.ts"
|
|
34
34
|
},
|
|
35
|
+
"./internal/open-request-dispatcher": {
|
|
36
|
+
"import": "./dist/internal/open-request-dispatcher.js",
|
|
37
|
+
"types": "./dist/internal/open-request-dispatcher.d.ts"
|
|
38
|
+
},
|
|
35
39
|
"./internal/inline-flow": {
|
|
36
40
|
"import": "./dist/internal/inline-flow.js",
|
|
37
41
|
"types": "./dist/internal/inline-flow.d.ts"
|