@prodantix/sdk 0.6.0 → 0.7.0-beta.437
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/README.md +19 -0
- package/dist/chat.cjs +19 -18
- package/dist/chat.d.cts +125 -7
- package/dist/chat.d.ts +125 -7
- package/dist/chat.js +21 -20
- package/dist/chunk-D6PMLUYA.js +2 -0
- package/dist/{client-BO7f6q5k.d.cts → client-CL6Xvhay.d.cts} +2 -1
- package/dist/{client-BQlU_3Dc.d.ts → client-QyKW0LFW.d.ts} +2 -1
- package/dist/{config-DqC0lcr7.d.ts → config-6ulvfBFp.d.ts} +33 -1
- package/dist/{config-CMF9zz1a.d.cts → config-g14Jiv1t.d.cts} +33 -1
- package/dist/csp.cjs +2 -2
- package/dist/csp.d.cts +9 -10
- package/dist/csp.d.ts +9 -10
- package/dist/csp.js +2 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1 -1
- package/dist/messenger-files.iife.js +2 -0
- package/dist/messenger-help.iife.js +3 -0
- package/dist/messenger.cjs +1 -1
- package/dist/messenger.d.cts +1 -1
- package/dist/messenger.d.ts +1 -1
- package/dist/messenger.iife.js +7 -6
- package/dist/messenger.js +1 -1
- package/dist/node.cjs +1 -1
- package/dist/node.d.cts +2 -2
- package/dist/node.d.ts +2 -2
- package/dist/node.js +1 -1
- package/dist/{transport-CqAmRbpQ.d.ts → transport-DKFvkfX4.d.ts} +1 -1
- package/dist/{transport-Cy42FY5A.d.cts → transport-DN9pXyrX.d.cts} +1 -1
- package/dist/{types-DjMXp6Wg.d.cts → types-Q2VNlJbG.d.cts} +1 -0
- package/dist/{types-DjMXp6Wg.d.ts → types-Q2VNlJbG.d.ts} +1 -0
- package/dist/web.cjs +1 -1
- package/dist/web.d.cts +9 -4
- package/dist/web.d.ts +9 -4
- package/dist/web.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-4RLPQZ5L.js +0 -2
|
@@ -30,6 +30,17 @@ type FileFetchLike = (url: string, init: {
|
|
|
30
30
|
headers: Record<string, string>;
|
|
31
31
|
method: string;
|
|
32
32
|
}) => Promise<FileResponseLike>;
|
|
33
|
+
interface ArticleHit {
|
|
34
|
+
id: string;
|
|
35
|
+
title: string;
|
|
36
|
+
trail: string[];
|
|
37
|
+
url: string;
|
|
38
|
+
embedUrl: string;
|
|
39
|
+
}
|
|
40
|
+
interface ArticleCollection {
|
|
41
|
+
title: string;
|
|
42
|
+
articles: number;
|
|
43
|
+
}
|
|
33
44
|
interface ChatThread {
|
|
34
45
|
id: string;
|
|
35
46
|
status: string;
|
|
@@ -43,6 +54,7 @@ interface ChatClientOptions {
|
|
|
43
54
|
fetchImpl?: FetchLike;
|
|
44
55
|
fileFetchImpl?: FileFetchLike;
|
|
45
56
|
onError?: (error: unknown) => void;
|
|
57
|
+
locale?: string;
|
|
46
58
|
}
|
|
47
59
|
interface ChatIdentity {
|
|
48
60
|
userId: string;
|
|
@@ -79,6 +91,7 @@ declare class ChatClient {
|
|
|
79
91
|
send(body: string, pageContext?: PageContext, attachmentIds?: string[]): Promise<ChatTurn | null>;
|
|
80
92
|
upload(file: File): Promise<ChatUpload | null>;
|
|
81
93
|
file(path: string): Promise<Blob | null>;
|
|
94
|
+
helpCentre<T>(suffix: string, params: Record<string, string>): Promise<T | null>;
|
|
82
95
|
load(): Promise<ChatThread | null>;
|
|
83
96
|
private readHandle;
|
|
84
97
|
private fileRequest;
|
|
@@ -149,6 +162,25 @@ interface MessengerConfig extends AppearanceSettings {
|
|
|
149
162
|
team: TeamFace[];
|
|
150
163
|
socketUrl: string;
|
|
151
164
|
attachments?: MessengerAttachments;
|
|
165
|
+
help?: MessengerHelp | null;
|
|
166
|
+
}
|
|
167
|
+
interface HelpWords {
|
|
168
|
+
messagesTab: string;
|
|
169
|
+
helpTab: string;
|
|
170
|
+
searchPlaceholder: string;
|
|
171
|
+
collections: string;
|
|
172
|
+
mostRead: string;
|
|
173
|
+
mightHelp: string;
|
|
174
|
+
noMatches: string;
|
|
175
|
+
back: string;
|
|
176
|
+
openOnSite: string;
|
|
177
|
+
stillNeedHelp: string;
|
|
178
|
+
messageUs: string;
|
|
179
|
+
readOnSite: string;
|
|
180
|
+
}
|
|
181
|
+
interface MessengerHelp {
|
|
182
|
+
placement: 'first_view' | 'tab' | 'while_typing';
|
|
183
|
+
words: HelpWords;
|
|
152
184
|
}
|
|
153
185
|
interface MessengerAttachments {
|
|
154
186
|
enabled: boolean;
|
|
@@ -169,4 +201,4 @@ declare const cacheKeyFor: (apiKey: string, locale: string | undefined) => strin
|
|
|
169
201
|
declare function cachedMessengerConfig(storage: ChatStorage | undefined, apiKey: string, locale?: string): MessengerConfig | null;
|
|
170
202
|
declare function fetchMessengerConfig(options: MessengerConfigOptions): Promise<MessengerConfig | null>;
|
|
171
203
|
|
|
172
|
-
export { type
|
|
204
|
+
export { type ArticleHit as A, type BubbleFill as B, type ChatThread as C, DEFAULT_APPEARANCE_SETTINGS as D, localeCandidates as E, type FileFetchLike as F, type HelpWords as H, type LauncherContent as L, type MessengerAttachments as M, type NamePlacement as N, type PageContext as P, type StampContent as S, type ArticleCollection as a, type AppearanceSettings as b, type ChatTurn as c, type ChatUpload as d, type MessengerConfig as e, type ChatIdentity as f, type ChatClientOptions as g, type BubbleShape as h, type ChatAttachment as i, ChatClient as j, type ChatStorage as k, type ComposerShape as l, type FileResponseLike as m, type LauncherFill as n, type LauncherShape as o, type LauncherSize as p, type MessengerSkin as q, type StampPlacement as r, resolveAppearance as s, MESSENGER_CACHE_KEY as t, type MessengerConfigOptions as u, type MessengerHelp as v, type StarterPrompt as w, cacheKeyFor as x, cachedMessengerConfig as y, fetchMessengerConfig as z };
|
|
@@ -30,6 +30,17 @@ type FileFetchLike = (url: string, init: {
|
|
|
30
30
|
headers: Record<string, string>;
|
|
31
31
|
method: string;
|
|
32
32
|
}) => Promise<FileResponseLike>;
|
|
33
|
+
interface ArticleHit {
|
|
34
|
+
id: string;
|
|
35
|
+
title: string;
|
|
36
|
+
trail: string[];
|
|
37
|
+
url: string;
|
|
38
|
+
embedUrl: string;
|
|
39
|
+
}
|
|
40
|
+
interface ArticleCollection {
|
|
41
|
+
title: string;
|
|
42
|
+
articles: number;
|
|
43
|
+
}
|
|
33
44
|
interface ChatThread {
|
|
34
45
|
id: string;
|
|
35
46
|
status: string;
|
|
@@ -43,6 +54,7 @@ interface ChatClientOptions {
|
|
|
43
54
|
fetchImpl?: FetchLike;
|
|
44
55
|
fileFetchImpl?: FileFetchLike;
|
|
45
56
|
onError?: (error: unknown) => void;
|
|
57
|
+
locale?: string;
|
|
46
58
|
}
|
|
47
59
|
interface ChatIdentity {
|
|
48
60
|
userId: string;
|
|
@@ -79,6 +91,7 @@ declare class ChatClient {
|
|
|
79
91
|
send(body: string, pageContext?: PageContext, attachmentIds?: string[]): Promise<ChatTurn | null>;
|
|
80
92
|
upload(file: File): Promise<ChatUpload | null>;
|
|
81
93
|
file(path: string): Promise<Blob | null>;
|
|
94
|
+
helpCentre<T>(suffix: string, params: Record<string, string>): Promise<T | null>;
|
|
82
95
|
load(): Promise<ChatThread | null>;
|
|
83
96
|
private readHandle;
|
|
84
97
|
private fileRequest;
|
|
@@ -149,6 +162,25 @@ interface MessengerConfig extends AppearanceSettings {
|
|
|
149
162
|
team: TeamFace[];
|
|
150
163
|
socketUrl: string;
|
|
151
164
|
attachments?: MessengerAttachments;
|
|
165
|
+
help?: MessengerHelp | null;
|
|
166
|
+
}
|
|
167
|
+
interface HelpWords {
|
|
168
|
+
messagesTab: string;
|
|
169
|
+
helpTab: string;
|
|
170
|
+
searchPlaceholder: string;
|
|
171
|
+
collections: string;
|
|
172
|
+
mostRead: string;
|
|
173
|
+
mightHelp: string;
|
|
174
|
+
noMatches: string;
|
|
175
|
+
back: string;
|
|
176
|
+
openOnSite: string;
|
|
177
|
+
stillNeedHelp: string;
|
|
178
|
+
messageUs: string;
|
|
179
|
+
readOnSite: string;
|
|
180
|
+
}
|
|
181
|
+
interface MessengerHelp {
|
|
182
|
+
placement: 'first_view' | 'tab' | 'while_typing';
|
|
183
|
+
words: HelpWords;
|
|
152
184
|
}
|
|
153
185
|
interface MessengerAttachments {
|
|
154
186
|
enabled: boolean;
|
|
@@ -169,4 +201,4 @@ declare const cacheKeyFor: (apiKey: string, locale: string | undefined) => strin
|
|
|
169
201
|
declare function cachedMessengerConfig(storage: ChatStorage | undefined, apiKey: string, locale?: string): MessengerConfig | null;
|
|
170
202
|
declare function fetchMessengerConfig(options: MessengerConfigOptions): Promise<MessengerConfig | null>;
|
|
171
203
|
|
|
172
|
-
export { type
|
|
204
|
+
export { type ArticleHit as A, type BubbleFill as B, type ChatThread as C, DEFAULT_APPEARANCE_SETTINGS as D, localeCandidates as E, type FileFetchLike as F, type HelpWords as H, type LauncherContent as L, type MessengerAttachments as M, type NamePlacement as N, type PageContext as P, type StampContent as S, type ArticleCollection as a, type AppearanceSettings as b, type ChatTurn as c, type ChatUpload as d, type MessengerConfig as e, type ChatIdentity as f, type ChatClientOptions as g, type BubbleShape as h, type ChatAttachment as i, ChatClient as j, type ChatStorage as k, type ComposerShape as l, type FileResponseLike as m, type LauncherFill as n, type LauncherShape as o, type LauncherSize as p, type MessengerSkin as q, type StampPlacement as r, resolveAppearance as s, MESSENGER_CACHE_KEY as t, type MessengerConfigOptions as u, type MessengerHelp as v, type StarterPrompt as w, cacheKeyFor as x, cachedMessengerConfig as y, fetchMessengerConfig as z };
|
package/dist/csp.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
'use strict';function r(n){let t=n?.trim()??"";if(t==="")return null;try{return new URL(t).origin}catch{return null}}function s(n){return n.startsWith("https://")?`wss://${n.slice(8)}`:n.startsWith("http://")?`ws://${n.slice(7)}`:null}function
|
|
2
|
-
exports.prodantixConnectSrc=o;exports.
|
|
1
|
+
'use strict';function r(n){let t=n?.trim()??"";if(t==="")return null;try{return new URL(t).origin}catch{return null}}function s(n){return n.startsWith("https://")?`wss://${n.slice(8)}`:n.startsWith("http://")?`ws://${n.slice(7)}`:null}function e(n){return [...new Set(["'self'",...n.filter(t=>t!==null)])].join(" ")}function o(n,t=[]){let i=r(n.edge);return e([...t,r(n.ingest),i,i===null?null:s(i),r(n.replay)])}function l(n,t=[]){return e([...t,r(n.edge)])}function g(n,t=[]){return e([...t,"blob:",r(n.edge)])}function u(n,t=[]){return e([...t,r(n.helpSite)])}
|
|
2
|
+
exports.prodantixConnectSrc=o;exports.prodantixFrameSrc=u;exports.prodantixImgSrc=g;exports.prodantixScriptSrc=l;//# sourceMappingURL=csp.cjs.map
|
|
3
3
|
//# sourceMappingURL=csp.cjs.map
|
package/dist/csp.d.cts
CHANGED
|
@@ -4,18 +4,14 @@
|
|
|
4
4
|
* anything that only resolves in the browser. A browser-only import here breaks
|
|
5
5
|
* the BUILD rather than the page, which is at least loud.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* and a script, and a policy that is too narrow fails only in a visitor's
|
|
11
|
-
* browser console: nine sites permitted the analytics host and would have
|
|
12
|
-
* blocked the messenger with nothing on our side to show for it.
|
|
7
|
+
* The messenger adds a websocket and a script to the analytics host, and a
|
|
8
|
+
* policy that is too narrow fails only in a visitor's browser console, with
|
|
9
|
+
* nothing on our side to show for it.
|
|
13
10
|
*
|
|
14
11
|
* Every app that installs the SDK posts to `${host}/v1/…`, and a policy of
|
|
15
12
|
* `'self'` blocks that in every environment, not only locally: these hosts are
|
|
16
|
-
* different origins from the site in staging and production too
|
|
17
|
-
*
|
|
18
|
-
* var the component reads.
|
|
13
|
+
* different origins from the site in staging and production too, so the
|
|
14
|
+
* sources derive from the same env var the component reads.
|
|
19
15
|
*/
|
|
20
16
|
interface ProdantixHosts {
|
|
21
17
|
/** Event ingest, e.g. `https://eu.api.prodantix.com`. */
|
|
@@ -24,6 +20,8 @@ interface ProdantixHosts {
|
|
|
24
20
|
edge?: string;
|
|
25
21
|
/** Session replay, when the app enables it. */
|
|
26
22
|
replay?: string;
|
|
23
|
+
/** The company's help site, which the messenger frames to read an article. */
|
|
24
|
+
helpSite?: string;
|
|
27
25
|
}
|
|
28
26
|
/** Everything the SDK CONNECTS to: ingest, the edge, replay, and the edge's
|
|
29
27
|
* websocket. */
|
|
@@ -34,5 +32,6 @@ declare function prodantixConnectSrc(hosts: ProdantixHosts, extra?: readonly str
|
|
|
34
32
|
* the one direction of CSP error that never announces itself. */
|
|
35
33
|
declare function prodantixScriptSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
36
34
|
declare function prodantixImgSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
35
|
+
declare function prodantixFrameSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
37
36
|
|
|
38
|
-
export { type ProdantixHosts, prodantixConnectSrc, prodantixImgSrc, prodantixScriptSrc };
|
|
37
|
+
export { type ProdantixHosts, prodantixConnectSrc, prodantixFrameSrc, prodantixImgSrc, prodantixScriptSrc };
|
package/dist/csp.d.ts
CHANGED
|
@@ -4,18 +4,14 @@
|
|
|
4
4
|
* anything that only resolves in the browser. A browser-only import here breaks
|
|
5
5
|
* the BUILD rather than the page, which is at least loud.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* and a script, and a policy that is too narrow fails only in a visitor's
|
|
11
|
-
* browser console: nine sites permitted the analytics host and would have
|
|
12
|
-
* blocked the messenger with nothing on our side to show for it.
|
|
7
|
+
* The messenger adds a websocket and a script to the analytics host, and a
|
|
8
|
+
* policy that is too narrow fails only in a visitor's browser console, with
|
|
9
|
+
* nothing on our side to show for it.
|
|
13
10
|
*
|
|
14
11
|
* Every app that installs the SDK posts to `${host}/v1/…`, and a policy of
|
|
15
12
|
* `'self'` blocks that in every environment, not only locally: these hosts are
|
|
16
|
-
* different origins from the site in staging and production too
|
|
17
|
-
*
|
|
18
|
-
* var the component reads.
|
|
13
|
+
* different origins from the site in staging and production too, so the
|
|
14
|
+
* sources derive from the same env var the component reads.
|
|
19
15
|
*/
|
|
20
16
|
interface ProdantixHosts {
|
|
21
17
|
/** Event ingest, e.g. `https://eu.api.prodantix.com`. */
|
|
@@ -24,6 +20,8 @@ interface ProdantixHosts {
|
|
|
24
20
|
edge?: string;
|
|
25
21
|
/** Session replay, when the app enables it. */
|
|
26
22
|
replay?: string;
|
|
23
|
+
/** The company's help site, which the messenger frames to read an article. */
|
|
24
|
+
helpSite?: string;
|
|
27
25
|
}
|
|
28
26
|
/** Everything the SDK CONNECTS to: ingest, the edge, replay, and the edge's
|
|
29
27
|
* websocket. */
|
|
@@ -34,5 +32,6 @@ declare function prodantixConnectSrc(hosts: ProdantixHosts, extra?: readonly str
|
|
|
34
32
|
* the one direction of CSP error that never announces itself. */
|
|
35
33
|
declare function prodantixScriptSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
36
34
|
declare function prodantixImgSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
35
|
+
declare function prodantixFrameSrc(hosts: ProdantixHosts, extra?: readonly string[]): string;
|
|
37
36
|
|
|
38
|
-
export { type ProdantixHosts, prodantixConnectSrc, prodantixImgSrc, prodantixScriptSrc };
|
|
37
|
+
export { type ProdantixHosts, prodantixConnectSrc, prodantixFrameSrc, prodantixImgSrc, prodantixScriptSrc };
|
package/dist/csp.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import'./chunk-5XGN7UAV.js';function r(n){let t=n?.trim()??"";if(t==="")return null;try{return new URL(t).origin}catch{return null}}function s(n){return n.startsWith("https://")?`wss://${n.slice(8)}`:n.startsWith("http://")?`ws://${n.slice(7)}`:null}function
|
|
2
|
-
export{o as prodantixConnectSrc,u as prodantixImgSrc,l as prodantixScriptSrc};//# sourceMappingURL=csp.js.map
|
|
1
|
+
import'./chunk-5XGN7UAV.js';function r(n){let t=n?.trim()??"";if(t==="")return null;try{return new URL(t).origin}catch{return null}}function s(n){return n.startsWith("https://")?`wss://${n.slice(8)}`:n.startsWith("http://")?`ws://${n.slice(7)}`:null}function e(n){return [...new Set(["'self'",...n.filter(t=>t!==null)])].join(" ")}function o(n,t=[]){let i=r(n.edge);return e([...t,r(n.ingest),i,i===null?null:s(i),r(n.replay)])}function l(n,t=[]){return e([...t,r(n.edge)])}function g(n,t=[]){return e([...t,"blob:",r(n.edge)])}function u(n,t=[]){return e([...t,r(n.helpSite)])}
|
|
2
|
+
export{o as prodantixConnectSrc,u as prodantixFrameSrc,g as prodantixImgSrc,l as prodantixScriptSrc};//# sourceMappingURL=csp.js.map
|
|
3
3
|
//# sourceMappingURL=csp.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var ue=Object.defineProperty;var pe=(n,e,t)=>e in n?ue(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var o=(n,e,t)=>pe(n,typeof e!="symbol"?e+"":e,t);var u=class extends Error{constructor(t,s,r){super(s,r);o(this,"code");this.code=t,this.name="ProdantixError";}},y=class extends u{constructor(e){super("config",e),this.name="ConfigError";}},h=class extends u{constructor(t,s){super("validation",s);o(this,"field");this.field=t,this.name="ValidationError";}},l=class extends u{constructor(t,s,r){super("transport",t,r);o(this,"status");this.status=s,this.name="TransportError";}};function v(n){if(n)return n;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function p(){let n=globalThis.AbortController;return n?new n:void 0}var G=n=>new Promise(e=>{setTimeout(e,n);});function f(n){return n.replace(/\/+$/,"")}var k=class{constructor(){o(this,"store",new Map);}getItem(e){return this.store.get(e)??null}removeItem(e){this.store.delete(e);}setItem(e,t){this.store.set(e,t);}};var J={now:()=>new Date};function F(n){return n.toISOString()}function he(){return globalThis.crypto}function fe(n){n[6]=n[6]&15|64,n[8]=n[8]&63|128;let e=[];for(let t=0;t<16;t+=1)e.push(n[t].toString(16).padStart(2,"0"));return `${e[0]}${e[1]}${e[2]}${e[3]}-${e[4]}${e[5]}-${e[6]}${e[7]}-${e[8]}${e[9]}-${e[10]}${e[11]}${e[12]}${e[13]}${e[14]}${e[15]}`}function ge(){let n=he();if(n?.randomUUID)return n.randomUUID();let e=new Uint8Array(16);if(n?.getRandomValues)n.getRandomValues(e);else for(let t=0;t<16;t+=1)e[t]=Math.floor(Math.random()*256);return fe(e)}var H={uuid:ge};var me=/^pdx_pub_(?:(?:live|test)_)?[a-z0-9]{32}$/;var ye=/^(?:\$|[a-z])[a-z0-9_.]*$/;function U(n){let e=0;for(let t of n)e+=1;return e}function B(n){return me.test(n)}function ve(n){return ye.test(n)}function z(n){let e=U(n);if(e<1||e>200)throw new h("distinct_id","distinct_id must be between 1 and 200 characters")}function Q(n){let e=U(n);if(e<1||e>200)throw new h("event_name","event_name must be between 1 and 200 characters");if(!ve(n))throw new h("event_name","event_name must match /^(\\$|[a-z])[a-z0-9_.]*$/")}var $="prodantix-js",N="0.0.1";var ke=n=>{};function Y(n){if(!n.apiKey||!B(n.apiKey))throw new y("apiKey must be a public project key of the form pdx_pub_<32 lowercase alphanumerics>");if(!n.host)throw new y("host is required (the ingest base URL)");let e=f(n.host),t=n.defaultProperties,s=n.storage??new k;return {apiKey:n.apiKey,autocapture:n.autocapture??false,clock:n.clock??J,consent:n.consent,defaultProperties:typeof t=="function"?t:()=>t??{},flagsHost:n.flagsHost?f(n.flagsHost):e,flushAt:n.flushAt??20,flushIntervalMs:n.flushIntervalMs??1e4,host:e,ids:n.ids??H,locale:n.locale,maxQueueSize:n.maxQueueSize??1e3,maxRetries:n.maxRetries??3,namespace:be(n.apiKey),onError:n.onError??ke,os:n.os,requestTimeoutMs:n.requestTimeoutMs??1e4,sdkName:n.sdkName??$,sdkVersion:n.sdkVersion??N,sessionTracking:n.sessionTracking??false,sharedStorage:n.sharedStorage??s,socketFactory:n.socketFactory,storage:s,streamFlags:n.streamFlags??false,transport:n.transport}}function be(n){return n.slice(0,16)}function W(n,e,t){Q(n.eventName),z(n.distinctId);let s={distinct_id:n.distinctId,event_id:n.eventId??t.uuid(),event_name:n.eventName,properties:n.properties??{},schema_version:1,timestamp:F(n.timestamp??e.now())};return n.context&&(s.context=n.context),n.sessionId&&(s.session_id=n.sessionId),s}var m=Symbol("absent");function Ee(n,e){if(n==="distinct_id")return e.distinctId;let t=e.properties??{};if(Object.prototype.hasOwnProperty.call(t,n))return t[n];let s=e.attributes??{};return Object.prototype.hasOwnProperty.call(s,n)?s[n]:m}function g(n){return n===m?"undefined":String(n)}function X(n){return n===m?Number.NaN:Number(n)}function Z(n){return n!==m&&n!==null&&n!==""}function ee(n,e){if(!Array.isArray(e))return false;let t=g(n);return e.map(s=>String(s)).includes(t)}function R(n,e){let t=Ee(n.attribute,e),s=n.value;switch(n.op){case "is_set":return Z(t);case "is_not_set":return !Z(t);case "eq":return g(t)===g(s===void 0?m:s);case "neq":return g(t)!==g(s===void 0?m:s);case "contains":return g(t).includes(g(s===void 0?m:s));case "in":return ee(t,s);case "not_in":return Array.isArray(s)?!ee(t,s):false;case "gt":return C(t,s,(r,i)=>r>i);case "gte":return C(t,s,(r,i)=>r>=i);case "lt":return C(t,s,(r,i)=>r<i);case "lte":return C(t,s,(r,i)=>r<=i);case "in_cohort":return typeof s=="string"&&s!==""&&(e.cohorts??[]).includes(s);case "not_in_cohort":return typeof s=="string"&&s!==""&&!(e.cohorts??[]).includes(s);default:return false}}function C(n,e,t){let s=X(n),r=e===void 0?Number.NaN:X(e);return Number.isNaN(s)||Number.isNaN(r)?false:t(s,r)}function M(n,e){let t=`${n}:${e}`,s=2166136261;for(let r=0;r<t.length;r++)s^=t.charCodeAt(r),s=Math.imul(s,16777619);return (s>>>0)%100}function O(n,e){return n.targeting.length===0||n.targeting.every(t=>R(t,e))}function te(n,e){let t=M(n.key,e.distinctId),s=n.variations??[];if(s.length===0)return n.rolloutPercentage>=100||t<n.rolloutPercentage?"true":"false";let r=0;for(let i=s.length-1;i>=0;i--)if(r+=s[i].weight,t<r)return s[i].key;return s[0].key}function q(n,e,t,s){for(let r of n.prerequisites??[]){if(s.includes(r.flagKey))return false;let i=e.find(d=>d.key===r.flagKey);if(!i||!i.enabled)return false;s.push(i.key);let a=q(i,e,t,s)&&O(i,t)&&te(i,t)===r.variationKey;if(s.pop(),!a)return false}return true}function b(n,e,t){return n.enabled?q(n,e,t,[n.key])?O(n,t)?n.rolloutPercentage>=100?{enabled:true,reason:"rollout_full"}:M(n.key,t.distinctId)<n.rolloutPercentage?{enabled:true,reason:"rollout"}:{enabled:false,reason:"rollout_excluded"}:{enabled:false,reason:"targeting"}:{enabled:false,reason:"prerequisite"}:{enabled:false,reason:"disabled"}}function xe(n,e){return b(n,[],e)}function K(n,e){let t={};for(let s of n)t[s.key]=b(s,n,e).enabled;return t}function E(n,e,t){let s=n.variations??[],r=s[0];if(!r)return null;if(!n.enabled||!q(n,e,t,[n.key])||!O(n,t))return r;let i=te(n,t);return s.find(a=>a.key===i)??r}function Se(n,e){return E(n,[],e)}function Ie(n,e,t){let s=n.find(r=>r.key===e);return s?E(s,n,t)?.value??null:null}function ne(n){return n.some(e=>e.targeting.some(t=>t.op==="in_cohort"||t.op==="not_in_cohort"))}function se(n){return `40${JSON.stringify(n)}`}function re(){return "3"}function ie(n){let e=n.charAt(0),t=n.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let a=L(t);return {kind:"open",pingInterval:typeof a?.pingInterval=="number"?a.pingInterval:25e3,pingTimeout:typeof a?.pingTimeout=="number"?a.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let s=t.charAt(0),r=t.slice(1);if(s==="0")return {kind:"connected"};if(s==="1")return {kind:"disconnect"};if(s==="4"){let a=L(r);return {kind:"connectError",message:typeof a?.message=="string"?a.message:"refused"}}if(s!=="2")return {kind:"other"};let i=L(r);return !Array.isArray(i)||typeof i[0]!="string"?{kind:"other"}:{kind:"event",name:i[0],payload:i[1]}}function L(n){try{return JSON.parse(n)}catch{return null}}var Fe="/socket.io/?EIO=4&transport=websocket",Ce=250,T=class{constructor(e){this.options=e;o(this,"socket",null);o(this,"heartbeat",null);o(this,"pending",null);o(this,"lastKey","");o(this,"ready",false);o(this,"closed",false);o(this,"heartbeatWindow",45e3);o(this,"factory");o(this,"setTimer");o(this,"clearTimer");this.factory=e.socketFactory??Te,this.setTimer=e.setTimer??((t,s)=>setTimeout(t,s)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Fe}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=s=>this.receive(String(s.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat(),this.pending!==null&&this.clearTimer(this.pending),this.pending=null;let e=this.socket;this.socket=null,e?.close();}receive(e){let t=ie(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(se({projectKey:this.options.projectKey}));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(re());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true;return}if(t.name==="flagChange"){let s=t.payload?.key;this.lastKey=typeof s=="string"?s:"",this.pending===null&&(this.pending=this.setTimer(()=>{this.pending=null,this.options.onChange(this.lastKey);},Ce));}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Te(n){let e=globalThis.WebSocket;if(!e)throw new l("no WebSocket");return new e(n)}var x=class{constructor(e){o(this,"fetch");o(this,"host");o(this,"projectKey");o(this,"requestTimeoutMs");this.fetch=v(e.fetch),this.host=f(e.host),this.projectKey=e.projectKey,this.requestTimeoutMs=e.requestTimeoutMs??1e4;}async fetchAll(e){return (await this.fetchDecisions(e)).flags}async fetchDecisions(e){let t=this.fetch;if(!t)throw new l("no fetch implementation available in this runtime");let s=`${this.host}/v1/flags?distinct_id=${encodeURIComponent(e)}`,r=p(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{let a=await t(s,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:r?.signal});if(!a.ok)throw new l(`flags request failed with status ${a.status}`,a.status);let d=JSON.parse(await a.text());return {flags:d.flags??{},variants:d.variants??{}}}finally{i!==void 0&&clearTimeout(i);}}async snapshot(){let e=this.fetch;if(!e)throw new l("no fetch implementation available in this runtime");let t=`${this.host}/v1/flags/snapshot`,s=p(),r=s?setTimeout(()=>s.abort(),this.requestTimeoutMs):void 0;try{let i=await e(t,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:s?.signal});if(!i.ok)throw new l(`flag snapshot request failed with status ${i.status}`,i.status);let a=JSON.parse(await i.text()),d={flags:a.flags??[],generatedAt:a.generatedAt};return typeof a.socketUrl=="string"&&a.socketUrl!==""&&(d.socketUrl=a.socketUrl),d}finally{r!==void 0&&clearTimeout(r);}}async memberships(e){let t=this.fetch;if(!t)throw new l("no fetch implementation available in this runtime");let s=`${this.host}/v1/flags/memberships?distinct_id=${encodeURIComponent(e)}`,r=p(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{let a=await t(s,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:r?.signal});if(!a.ok)throw new l(`memberships request failed with status ${a.status}`,a.status);return JSON.parse(await a.text()).cohorts??[]}finally{i!==void 0&&clearTimeout(i);}}};function D(n){if(typeof n!="string")return;let e=Array.from(n).length;return e>=1&&e<=200?n:void 0}function V(n,e){return `pdx.${n}.${e}`}var oe="consent";function we(n){if(typeof n!="string")return null;try{let e=JSON.parse(n);if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=e.identityLink;return typeof t=="boolean"?{identityLink:t}:null}catch{return null}}function _e(n,e){return we(n.getItem(V(e,oe)))}function Ae(n,e,t){let s=V(e,oe);if(typeof t.identityLink!="boolean"){n.removeItem(s);return}n.setItem(s,JSON.stringify({identityLink:t.identityLink}));}var w=class{constructor(e,t,s,r){this.storage=e;this.shared=t;this.ids=s;this.namespace=r;o(this,"anonymousId");o(this,"distinctId");o(this,"identified");this.refresh();}refresh(){let e=D(this.shared.getItem(this.key("anonymous_id"))),t=D(this.storage.getItem(this.key("anonymous_id")));e?(this.anonymousId=e,t!==e&&this.storage.setItem(this.key("anonymous_id"),e)):t?(this.anonymousId=t,this.shared.setItem(this.key("anonymous_id"),t)):(this.anonymousId=this.ids.uuid(),this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId));let s=D(this.storage.getItem(this.key("distinct_id")));s?(this.distinctId=s,this.identified=true):(this.distinctId=this.anonymousId,this.identified=false);}getAnonymousId(){return this.anonymousId}getDistinctId(){return this.distinctId}isIdentified(){return this.identified}snapshot(){return {anonymousId:this.anonymousId,distinctId:this.distinctId,identified:this.identified}}consent(){return _e(this.shared,this.namespace)}setConsent(e){Ae(this.shared,this.namespace,e);}identify(e){let t=!this.identified||this.distinctId!==e,s=this.storage.getItem(this.key("linked_anonymous_id")),r=t||s!==this.anonymousId;return this.distinctId=e,this.identified=true,t&&this.storage.setItem(this.key("distinct_id"),e),!r||this.consent()?.identityLink===false?{changed:t}:(this.storage.setItem(this.key("linked_anonymous_id"),this.anonymousId),{anonymousToLink:this.anonymousId,changed:t})}reset(){this.anonymousId=this.ids.uuid(),this.distinctId=this.anonymousId,this.identified=false,this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.removeItem(this.key("distinct_id")),this.storage.removeItem(this.key("linked_anonymous_id"));}key(e){return V(this.namespace,e)}};var S=class{constructor(e){o(this,"fetch");o(this,"host");o(this,"projectKey");o(this,"requestTimeoutMs");this.fetch=v(e.fetch),this.host=f(e.host),this.projectKey=e.projectKey,this.requestTimeoutMs=e.requestTimeoutMs??1e4;}async inbox(e){let t=this.requireFetch(),s=`${this.host}/v1/messages?distinct_id=${encodeURIComponent(e)}`,r=await this.request(t,s,{headers:this.authHeaders(),method:"GET"});if(!r.ok)throw new l(`inbox request failed with status ${r.status}`,r.status);return JSON.parse(await r.text()).messages??[]}async markRead(e,t){let s=this.requireFetch(),r=`${this.host}/v1/messages/read`,i=await this.request(s,r,{body:JSON.stringify({distinct_id:t,message_id:e}),headers:{...this.authHeaders(),"content-type":"application/json"},method:"POST"});if(!i.ok)throw new l(`mark-read request failed with status ${i.status}`,i.status)}requireFetch(){if(!this.fetch)throw new l("no fetch implementation available in this runtime");return this.fetch}authHeaders(){return {authorization:`Bearer ${this.projectKey}`}}async request(e,t,s){let r=p(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{return await e(t,{...s,signal:r?.signal})}finally{i!==void 0&&clearTimeout(i);}}};var _=class{constructor(e,t){this.maxSize=e;this.onOverflow=t;o(this,"events",[]);}get size(){return this.events.length}enqueue(e){this.events.push(e),this.enforceCap();}restore(e){this.events.push(...e),this.enforceCap();}requeue(e){this.events.unshift(...e),this.enforceCap();}drain(e){let t=e===void 0?this.events.length:Math.min(e,this.events.length);return this.events.splice(0,t)}snapshot(){return [...this.events]}enforceCap(){if(this.events.length<=this.maxSize)return;let e=this.events.splice(0,this.events.length-this.maxSize);this.onOverflow?.({dropped:e});}};var Pe={idleMs:18e5,maxMs:864e5,throttleMs:1e4};function $e(n){return `pdx.${n}.session`}var A=class{constructor(e,t,s,r,i=Pe){this.storage=e;this.ids=t;this.clock=s;this.namespace=r;this.options=i;}current(){return this.touch().id}startedAt(){return this.touch().startedAt}reset(){this.storage.removeItem(this.key());}touch(){let e=this.clock.now().getTime(),t=this.live(this.read(),e);if(t===void 0)return this.write({id:this.ids.uuid(),lastActivityAt:e,startedAt:e});if(e-t.lastActivityAt<=this.options.throttleMs)return t;let s=this.live(this.read(),e),r=s!==void 0&&s.id!==t.id?s:t;return this.write({...r,lastActivityAt:e})}live(e,t){if(e!==void 0&&!(t-e.lastActivityAt>this.options.idleMs||t-e.startedAt>this.options.maxMs))return e}write(e){return this.storage.setItem(this.key(),JSON.stringify(e)),e}read(){let e=this.storage.getItem(this.key());if(e)try{let t=JSON.parse(e);return typeof t.id=="string"&&typeof t.startedAt=="number"&&typeof t.lastActivityAt=="number"?{id:t.id,lastActivityAt:t.lastActivityAt,startedAt:t.startedAt}:void 0}catch{return}}key(){return $e(this.namespace)}};var c={autocapture:"$autocapture",createAlias:"$create_alias",featureFlagCalled:"$feature_flag_called",group:"$group",identify:"$identify",pageview:"$pageview",screen:"$screen",set:"$set"},ae=[{emittedBy:"web",meaning:"A click anywhere on the page, with the element that was clicked. The web SDK sends it by default; autocapture: false or autocaptureOptions.clicks: false turns it off.",name:c.autocapture,properties:["$event_type","$el_tag","$el_text","$el_id","$el_classes","$el_href","$current_url","$pathname","$host","$title","$referrer"]},{emittedBy:"web",meaning:"A page shown, including every client-side navigation the History API makes: one per distinct path and query.",name:c.pageview,properties:["$current_url","$pathname","$host","$title","$referrer"]},{emittedBy:"flutter",meaning:"A named route pushed or replaced in a Flutter app, the mobile counterpart of $pageview.",name:c.screen,properties:["screen"]},{emittedBy:"every",meaning:"A person becomes known by a distinct id. The anonymous trail before it is joined to them, and any traits ride along under $set.",name:c.identify,properties:["$anon_distinct_id","$set"]},{emittedBy:"every",meaning:"A second id for the same person, so events sent under either resolve to one profile.",name:c.createAlias,properties:["alias"]},{emittedBy:"every",meaning:"The person is placed in a group such as a company or a team; group properties ride along under $set.",name:c.group,properties:["$group_type","$group_key","$set"]},{emittedBy:"every",meaning:"Person properties written without an identify: $set overwrites, $set_once fills only what is still empty.",name:c.set,properties:["$set","$set_once"]},{emittedBy:"every",meaning:"A flag was evaluated for this person, sent once per distinct answer. Experiments attribute exposure from it.",name:c.featureFlagCalled,properties:["$feature_flag","$feature_flag_response"]}],Ne=n=>n.startsWith("$"),Re=n=>ae.find(e=>e.name===n);function le(n){return n>=400&&n<500&&n!==429}var I=class{constructor(e={}){o(this,"fetch");o(this,"maxRetries");o(this,"requestTimeoutMs");o(this,"baseDelayMs");o(this,"maxDelayMs");o(this,"sleep");o(this,"random");this.fetch=v(e.fetch),this.maxRetries=e.maxRetries??3,this.requestTimeoutMs=e.requestTimeoutMs??1e4,this.baseDelayMs=e.baseDelayMs??500,this.maxDelayMs=e.maxDelayMs??3e4,this.sleep=e.sleep??G,this.random=e.random??Math.random;}async send(e){let t=this.fetch;if(!t)throw new l("no fetch implementation available in this runtime");let s=JSON.stringify(e.body),r;for(let i=0;i<=this.maxRetries;i+=1){try{let a=await this.attempt(t,e,s);if(a.ok)return;if(le(a.status))throw new l(`ingest rejected batch with status ${a.status}`,a.status);r=new l(`ingest transient status ${a.status}`,a.status);}catch(a){if(a instanceof l&&a.status!==void 0&&le(a.status))throw a;r=a;}i<this.maxRetries&&await this.sleep(this.backoff(i));}throw new l("ingest delivery failed after retries",void 0,{cause:r})}async attempt(e,t,s){let r=p(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{return await e(t.url,{body:s,headers:{authorization:`Bearer ${t.projectKey}`,"content-type":"application/json"},method:"POST",signal:r?.signal})}finally{i!==void 0&&clearTimeout(i);}}backoff(e){return Math.min(this.maxDelayMs,this.baseDelayMs*2**e)+this.random()*this.baseDelayMs}};var Me="queue",Oe=1e3,ce=3e4,j=n=>{let e={};return n.avatar!==void 0&&(e.$avatar=n.avatar),n.email!==void 0&&(e.$email=n.email),n.name!==void 0&&(e.$name=n.name),n.phone!==void 0&&(e.$phone=n.phone),e},P=class{constructor(e){o(this,"config");o(this,"identity");o(this,"session");o(this,"queue");o(this,"transport");o(this,"flagsClient");o(this,"messagesClient");o(this,"context");o(this,"flushTimer");o(this,"flushing",false);o(this,"cachedFlags");o(this,"cachedSnapshot");o(this,"membershipCache");o(this,"stream");o(this,"shutDown",false);o(this,"exposures",new Set);this.config=Y(e),this.identity=new w(this.config.storage,this.config.sharedStorage,this.config.ids,this.config.namespace),this.config.consent!==void 0&&this.identity.setConsent(this.config.consent),this.session=this.config.sessionTracking?new A(this.config.sharedStorage,this.config.ids,this.config.clock,this.config.namespace):void 0,this.queue=new _(this.config.maxQueueSize,({dropped:t})=>{this.config.onError(new u("queue_overflow",`event queue overflow: dropped ${t.length} oldest event(s)`));}),this.transport=this.config.transport??new I({maxRetries:this.config.maxRetries,requestTimeoutMs:this.config.requestTimeoutMs}),this.flagsClient=new x({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.messagesClient=new S({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.context={sdk:this.config.sdkName,sdk_version:this.config.sdkVersion},this.config.os&&(this.context.os=this.config.os),this.config.locale&&(this.context.locale=this.config.locale),this.restoreQueue(),this.startTimer();}get distinctId(){return this.identity.getDistinctId()}get anonymousId(){return this.identity.getAnonymousId()}get isIdentified(){return this.identity.isIdentified()}get sessionId(){return this.session?.current()}get sessionStartedAt(){return this.session?.startedAt()}capture(e,t={}){try{this.identity.refresh();let s={...this.config.defaultProperties(),...t.properties??{}},r=W({context:this.context,distinctId:t.distinctId??this.identity.getDistinctId(),eventName:e,properties:s,sessionId:t.sessionId??this.session?.current(),timestamp:t.timestamp},this.config.clock,this.config.ids);this.enqueue(r);}catch(s){this.config.onError(s);}}identify(e,t={}){this.identity.refresh();let s=this.identity.identify(e),r={};s.anonymousToLink!==void 0&&(r.$anon_distinct_id=s.anonymousToLink);let i={...j(t.traits??{}),...t.set??{}};Object.keys(i).length>0&&(r.$set=i),this.capture(c.identify,{properties:r});}link(e,t,s){let r={$anon_distinct_id:t},i=j(s??{});Object.keys(i).length>0&&(r.$set=i),this.capture(c.identify,{distinctId:e,properties:r});}setConsent(e){this.identity.setConsent(e);}consent(){return this.identity.consent()}alias(e){this.capture(c.createAlias,{properties:{alias:e}});}group(e,t,s){let r={$group_key:t,$group_type:e};s&&(r.$set=s),this.capture(c.group,{properties:r});}setPersonProperties(e,t){let s={};e&&(s.$set=e),t&&(s.$set_once=t),this.capture(c.set,{properties:s});}setPersonTraits(e){let t=j(e);Object.keys(t).length!==0&&this.capture(c.set,{properties:{$set:t}});}async getAllFlags(){let e=this.identity.getDistinctId(),t=await this.flagsClient.fetchDecisions(e);return this.cachedFlags={distinctId:e,flags:t.flags,variants:t.variants??{}},t.flags}async isFeatureEnabled(e){let s=(await this.getAllFlags())[e]??false;return this.recordExposure(e,this.cachedFlags?.variants[e]?.key??String(s)),s}async getVariant(e){let t=await this.getAllFlags(),s=this.cachedFlags?.variants[e]??null;return this.recordExposure(e,s?.key??String(t[e]??false)),s}async getVariantLocal(e,t={}){let s=await this.flagSnapshot(),r=s.flags.find(de=>de.key===e),i=await this.localContext(t,s.flags),a=r?E(r,s.flags,i):null,d=r?b(r,s.flags,i).enabled:false;return this.recordExposure(e,a?.key??String(d)),a?{key:a.key,value:a.value}:null}recordExposure(e,t){let s=`${this.identity.getDistinctId()} ${e} ${t}`;this.exposures.has(s)||(this.exposures.add(s),this.capture(c.featureFlagCalled,{properties:{$feature_flag:e,$feature_flag_response:t}}));}getCachedFlag(e){if(!(!this.cachedFlags||this.cachedFlags.distinctId!==this.distinctId))return this.cachedFlags.flags[e]}async getLocalFlags(e={}){let t=await this.flagSnapshot();return K(t.flags,await this.localContext(e,t.flags))}async isFeatureEnabledLocal(e,t={}){let s=await this.flagSnapshot(),r=s.flags.find(d=>d.key===e),i=await this.localContext(t,s.flags),a=r?b(r,s.flags,i).enabled:false;return this.recordExposure(e,(r?E(r,s.flags,i)?.key:void 0)??String(a)),a}async localContext(e,t){let s=this.identity.getDistinctId(),r=e.cohorts;if(r===void 0&&ne(t)){let i=this.config.clock.now().getTime();this.membershipCache&&this.membershipCache.distinctId===s&&i-this.membershipCache.fetchedAt<ce?r=this.membershipCache.cohorts:(r=await this.flagsClient.memberships(s),this.membershipCache={cohorts:r,distinctId:s,fetchedAt:i});}return {attributes:e.attributes,cohorts:r,distinctId:s,properties:e.properties}}async flagSnapshot(){let e=this.config.clock.now().getTime();if(this.cachedSnapshot&&e-this.cachedSnapshot.fetchedAt<ce)return this.cachedSnapshot.snapshot;let t=await this.flagsClient.snapshot();return this.cachedSnapshot={fetchedAt:e,snapshot:t},this.maybeStream(t),t}maybeStream(e){if(!this.config.streamFlags||this.shutDown||this.stream||!e.socketUrl)return;let t=new T({host:e.socketUrl,onChange:()=>{this.cachedSnapshot=void 0,this.flagSnapshot().catch(s=>this.config.onError(s));},onClosed:s=>{this.stream=void 0,s&&this.maybeStream(e);},projectKey:this.config.apiKey,socketFactory:this.config.socketFactory});this.stream=t,t.open();}async getInbox(){return this.messagesClient.inbox(this.identity.getDistinctId())}async markMessageRead(e){await this.messagesClient.markRead(e,this.identity.getDistinctId());}async flush(){if(this.flushing||this.queue.size===0)return;this.flushing=true;let e=this.queue.drain(Oe);try{await this.transport.send({body:{events:e,sent_at:F(this.config.clock.now())},projectKey:this.config.apiKey,url:`${this.config.host}/v1/events`}),this.persistQueue();}catch(t){this.queue.requeue(e),this.persistQueue(),this.config.onError(t);}finally{this.flushing=false;}}reset(){this.session?.reset(),this.identity.reset(),this.cachedFlags=void 0,this.cachedSnapshot=void 0,this.membershipCache=void 0;}async shutdown(){this.shutDown=true,this.stopTimer(),this.stream?.close(),this.stream=void 0,await this.flush();}enqueue(e){this.queue.enqueue(e),this.persistQueue(),this.queue.size>=this.config.flushAt&&this.flush();}persistQueue(){try{this.config.storage.setItem(this.persistKey(),JSON.stringify(this.queue.snapshot()));}catch(e){this.config.onError(e);}}restoreQueue(){try{let e=this.config.storage.getItem(this.persistKey());if(!e)return;let t=JSON.parse(e);Array.isArray(t)&&this.queue.restore(t);}catch(e){this.config.onError(e);}}startTimer(){if(this.config.flushIntervalMs<=0)return;let e=setInterval(()=>{this.flush();},this.config.flushIntervalMs),t=e;typeof t.unref=="function"&&t.unref(),this.flushTimer=e;}stopTimer(){this.flushTimer!==void 0&&(clearInterval(this.flushTimer),this.flushTimer=void 0);}persistKey(){return `pdx.${this.config.namespace}.${Me}`}};function qe(n){return new P(n)}exports.ConfigError=y;exports.FetchTransport=I;exports.FlagsClient=x;exports.MemoryStorage=k;exports.MessagesClient=S;exports.ProdantixClient=P;exports.ProdantixError=u;exports.SDK_NAME=$;exports.SDK_VERSION=N;exports.SYSTEM_EVENT=c;exports.SYSTEM_EVENTS=ae;exports.TransportError=l;exports.ValidationError=h;exports.assignVariant=Se;exports.bucket=M;exports.createClient=qe;exports.evaluateAll=K;exports.evaluateFlag=xe;exports.getVariant=Ie;exports.isSystemEventName=Ne;exports.matches=R;exports.systemEvent=Re;//# sourceMappingURL=index.cjs.map
|
|
1
|
+
'use strict';var ue=Object.defineProperty;var pe=(n,e,t)=>e in n?ue(n,e,{enumerable:true,configurable:true,writable:true,value:t}):n[e]=t;var o=(n,e,t)=>pe(n,typeof e!="symbol"?e+"":e,t);var u=class extends Error{constructor(t,s,r){super(s,r);o(this,"code");this.code=t,this.name="ProdantixError";}},y=class extends u{constructor(e){super("config",e),this.name="ConfigError";}},h=class extends u{constructor(t,s){super("validation",s);o(this,"field");this.field=t,this.name="ValidationError";}},l=class extends u{constructor(t,s,r){super("transport",t,r);o(this,"status");this.status=s,this.name="TransportError";}};function v(n){if(n)return n;let e=globalThis.fetch;if(typeof e=="function")return e.bind(globalThis)}function p(){let n=globalThis.AbortController;return n?new n:void 0}var G=n=>new Promise(e=>{setTimeout(e,n);});function f(n){return n.replace(/\/+$/,"")}var k=class{constructor(){o(this,"store",new Map);}getItem(e){return this.store.get(e)??null}removeItem(e){this.store.delete(e);}setItem(e,t){this.store.set(e,t);}};var J={now:()=>new Date};function F(n){return n.toISOString()}function he(){return globalThis.crypto}function fe(n){n[6]=n[6]&15|64,n[8]=n[8]&63|128;let e=[];for(let t=0;t<16;t+=1)e.push(n[t].toString(16).padStart(2,"0"));return `${e[0]}${e[1]}${e[2]}${e[3]}-${e[4]}${e[5]}-${e[6]}${e[7]}-${e[8]}${e[9]}-${e[10]}${e[11]}${e[12]}${e[13]}${e[14]}${e[15]}`}function ge(){let n=he();if(n?.randomUUID)return n.randomUUID();let e=new Uint8Array(16);if(n?.getRandomValues)n.getRandomValues(e);else for(let t=0;t<16;t+=1)e[t]=Math.floor(Math.random()*256);return fe(e)}var H={uuid:ge};var me=/^pdx_pub_(?:(?:live|test)_)?[a-z0-9]{32}$/;var ye=/^(?:\$|[a-z])[a-z0-9_.]*$/;function U(n){let e=0;for(let t of n)e+=1;return e}function B(n){return me.test(n)}function ve(n){return ye.test(n)}function z(n){let e=U(n);if(e<1||e>200)throw new h("distinct_id","distinct_id must be between 1 and 200 characters")}function Q(n){let e=U(n);if(e<1||e>200)throw new h("event_name","event_name must be between 1 and 200 characters");if(!ve(n))throw new h("event_name","event_name must match /^(\\$|[a-z])[a-z0-9_.]*$/")}var P="prodantix-js",N="0.7.0";var ke=n=>{};function Y(n){if(!n.apiKey||!B(n.apiKey))throw new y("apiKey must be a public project key of the form pdx_pub_<32 lowercase alphanumerics>");if(!n.host)throw new y("host is required (the ingest base URL)");let e=f(n.host),t=n.defaultProperties,s=n.storage??new k;return {apiKey:n.apiKey,autocapture:n.autocapture??false,clock:n.clock??J,consent:n.consent,defaultProperties:typeof t=="function"?t:()=>t??{},describeElement:n.describeElement,flagsHost:n.flagsHost?f(n.flagsHost):e,flushAt:n.flushAt??20,flushIntervalMs:n.flushIntervalMs??1e4,host:e,ids:n.ids??H,locale:n.locale,maxQueueSize:n.maxQueueSize??1e3,maxRetries:n.maxRetries??3,namespace:be(n.apiKey),onError:n.onError??ke,os:n.os,requestTimeoutMs:n.requestTimeoutMs??1e4,sdkName:n.sdkName??P,sdkVersion:n.sdkVersion??N,sessionTracking:n.sessionTracking??false,sharedStorage:n.sharedStorage??s,socketFactory:n.socketFactory,storage:s,streamFlags:n.streamFlags??false,transport:n.transport}}function be(n){return n.slice(0,16)}function W(n,e,t){Q(n.eventName),z(n.distinctId);let s={distinct_id:n.distinctId,event_id:n.eventId??t.uuid(),event_name:n.eventName,properties:n.properties??{},schema_version:1,timestamp:F(n.timestamp??e.now())};return n.context&&(s.context=n.context),n.sessionId&&(s.session_id=n.sessionId),s}var m=Symbol("absent");function Ee(n,e){if(n==="distinct_id")return e.distinctId;let t=e.properties??{};if(Object.prototype.hasOwnProperty.call(t,n))return t[n];let s=e.attributes??{};return Object.prototype.hasOwnProperty.call(s,n)?s[n]:m}function g(n){return n===m?"undefined":String(n)}function X(n){return n===m?Number.NaN:Number(n)}function Z(n){return n!==m&&n!==null&&n!==""}function ee(n,e){if(!Array.isArray(e))return false;let t=g(n);return e.map(s=>String(s)).includes(t)}function R(n,e){let t=Ee(n.attribute,e),s=n.value;switch(n.op){case "is_set":return Z(t);case "is_not_set":return !Z(t);case "eq":return g(t)===g(s===void 0?m:s);case "neq":return g(t)!==g(s===void 0?m:s);case "contains":return g(t).includes(g(s===void 0?m:s));case "in":return ee(t,s);case "not_in":return Array.isArray(s)?!ee(t,s):false;case "gt":return C(t,s,(r,i)=>r>i);case "gte":return C(t,s,(r,i)=>r>=i);case "lt":return C(t,s,(r,i)=>r<i);case "lte":return C(t,s,(r,i)=>r<=i);case "in_cohort":return typeof s=="string"&&s!==""&&(e.cohorts??[]).includes(s);case "not_in_cohort":return typeof s=="string"&&s!==""&&!(e.cohorts??[]).includes(s);default:return false}}function C(n,e,t){let s=X(n),r=e===void 0?Number.NaN:X(e);return Number.isNaN(s)||Number.isNaN(r)?false:t(s,r)}function M(n,e){let t=`${n}:${e}`,s=2166136261;for(let r=0;r<t.length;r++)s^=t.charCodeAt(r),s=Math.imul(s,16777619);return (s>>>0)%100}function O(n,e){return n.targeting.length===0||n.targeting.every(t=>R(t,e))}function te(n,e){let t=M(n.key,e.distinctId),s=n.variations??[];if(s.length===0)return n.rolloutPercentage>=100||t<n.rolloutPercentage?"true":"false";let r=0;for(let i=s.length-1;i>=0;i--)if(r+=s[i].weight,t<r)return s[i].key;return s[0].key}function q(n,e,t,s){for(let r of n.prerequisites??[]){if(s.includes(r.flagKey))return false;let i=e.find(d=>d.key===r.flagKey);if(!i||!i.enabled)return false;s.push(i.key);let a=q(i,e,t,s)&&O(i,t)&&te(i,t)===r.variationKey;if(s.pop(),!a)return false}return true}function b(n,e,t){return n.enabled?q(n,e,t,[n.key])?O(n,t)?n.rolloutPercentage>=100?{enabled:true,reason:"rollout_full"}:M(n.key,t.distinctId)<n.rolloutPercentage?{enabled:true,reason:"rollout"}:{enabled:false,reason:"rollout_excluded"}:{enabled:false,reason:"targeting"}:{enabled:false,reason:"prerequisite"}:{enabled:false,reason:"disabled"}}function xe(n,e){return b(n,[],e)}function K(n,e){let t={};for(let s of n)t[s.key]=b(s,n,e).enabled;return t}function E(n,e,t){let s=n.variations??[],r=s[0];if(!r)return null;if(!n.enabled||!q(n,e,t,[n.key])||!O(n,t))return r;let i=te(n,t);return s.find(a=>a.key===i)??r}function Se(n,e){return E(n,[],e)}function Ie(n,e,t){let s=n.find(r=>r.key===e);return s?E(s,n,t)?.value??null:null}function ne(n){return n.some(e=>e.targeting.some(t=>t.op==="in_cohort"||t.op==="not_in_cohort"))}function se(n){return `40${JSON.stringify(n)}`}function re(){return "3"}function ie(n){let e=n.charAt(0),t=n.slice(1);if(e==="2")return {kind:"ping"};if(e==="1")return {kind:"disconnect"};if(e==="0"){let a=L(t);return {kind:"open",pingInterval:typeof a?.pingInterval=="number"?a.pingInterval:25e3,pingTimeout:typeof a?.pingTimeout=="number"?a.pingTimeout:2e4}}if(e!=="4")return {kind:"other"};let s=t.charAt(0),r=t.slice(1);if(s==="0")return {kind:"connected"};if(s==="1")return {kind:"disconnect"};if(s==="4"){let a=L(r);return {kind:"connectError",message:typeof a?.message=="string"?a.message:"refused"}}if(s!=="2")return {kind:"other"};let i=L(r);return !Array.isArray(i)||typeof i[0]!="string"?{kind:"other"}:{kind:"event",name:i[0],payload:i[1]}}function L(n){try{return JSON.parse(n)}catch{return null}}var Fe="/socket.io/?EIO=4&transport=websocket",Ce=250,T=class{constructor(e){this.options=e;o(this,"socket",null);o(this,"heartbeat",null);o(this,"pending",null);o(this,"lastKey","");o(this,"ready",false);o(this,"closed",false);o(this,"heartbeatWindow",45e3);o(this,"factory");o(this,"setTimer");o(this,"clearTimer");this.factory=e.socketFactory??Te,this.setTimer=e.setTimer??((t,s)=>setTimeout(t,s)),this.clearTimer=e.clearTimer??(t=>clearTimeout(t));}open(){if(this.socket||this.closed)return;let e=`${this.options.host.replace(/^http/,"ws").replace(/\/+$/,"")}${Fe}`,t;try{t=this.factory(e);}catch{this.options.onClosed(false);return}this.socket=t,t.onmessage=s=>this.receive(String(s.data)),t.onerror=()=>t.close(),t.onclose=()=>this.fell();}close(){this.closed=true,this.stopHeartbeat(),this.pending!==null&&this.clearTimer(this.pending),this.pending=null;let e=this.socket;this.socket=null,e?.close();}receive(e){let t=ie(e);if(t.kind==="open"){this.armHeartbeat(t.pingInterval+t.pingTimeout),this.socket?.send(se({projectKey:this.options.projectKey}));return}if(t.kind==="ping"){this.armHeartbeat(),this.socket?.send(re());return}if(t.kind==="connectError"||t.kind==="disconnect"){this.stopHeartbeat(),this.socket?.close();return}if(t.kind==="event"){if(t.name==="ready"){this.ready=true;return}if(t.name==="flagChange"){let s=t.payload?.key;this.lastKey=typeof s=="string"?s:"",this.pending===null&&(this.pending=this.setTimer(()=>{this.pending=null,this.options.onChange(this.lastKey);},Ce));}}}fell(){this.stopHeartbeat();let e=this.ready;this.socket=null,this.ready=false,this.closed||this.options.onClosed(e);}armHeartbeat(e){e!==void 0&&(this.heartbeatWindow=e),this.stopHeartbeat(),this.heartbeat=this.setTimer(()=>this.socket?.close(),this.heartbeatWindow);}stopHeartbeat(){this.heartbeat!==null&&this.clearTimer(this.heartbeat),this.heartbeat=null;}};function Te(n){let e=globalThis.WebSocket;if(!e)throw new l("no WebSocket");return new e(n)}var x=class{constructor(e){o(this,"fetch");o(this,"host");o(this,"projectKey");o(this,"requestTimeoutMs");this.fetch=v(e.fetch),this.host=f(e.host),this.projectKey=e.projectKey,this.requestTimeoutMs=e.requestTimeoutMs??1e4;}async fetchAll(e){return (await this.fetchDecisions(e)).flags}async fetchDecisions(e){let t=this.fetch;if(!t)throw new l("no fetch implementation available in this runtime");let s=`${this.host}/v1/flags?distinct_id=${encodeURIComponent(e)}`,r=p(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{let a=await t(s,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:r?.signal});if(!a.ok)throw new l(`flags request failed with status ${a.status}`,a.status);let d=JSON.parse(await a.text());return {flags:d.flags??{},variants:d.variants??{}}}finally{i!==void 0&&clearTimeout(i);}}async snapshot(){let e=this.fetch;if(!e)throw new l("no fetch implementation available in this runtime");let t=`${this.host}/v1/flags/snapshot`,s=p(),r=s?setTimeout(()=>s.abort(),this.requestTimeoutMs):void 0;try{let i=await e(t,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:s?.signal});if(!i.ok)throw new l(`flag snapshot request failed with status ${i.status}`,i.status);let a=JSON.parse(await i.text()),d={flags:a.flags??[],generatedAt:a.generatedAt};return typeof a.socketUrl=="string"&&a.socketUrl!==""&&(d.socketUrl=a.socketUrl),d}finally{r!==void 0&&clearTimeout(r);}}async memberships(e){let t=this.fetch;if(!t)throw new l("no fetch implementation available in this runtime");let s=`${this.host}/v1/flags/memberships?distinct_id=${encodeURIComponent(e)}`,r=p(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{let a=await t(s,{headers:{authorization:`Bearer ${this.projectKey}`},method:"GET",signal:r?.signal});if(!a.ok)throw new l(`memberships request failed with status ${a.status}`,a.status);return JSON.parse(await a.text()).cohorts??[]}finally{i!==void 0&&clearTimeout(i);}}};function D(n){if(typeof n!="string")return;let e=Array.from(n).length;return e>=1&&e<=200?n:void 0}function V(n,e){return `pdx.${n}.${e}`}var oe="consent";function we(n){if(typeof n!="string")return null;try{let e=JSON.parse(n);if(e===null||typeof e!="object"||Array.isArray(e))return null;let t=e.identityLink;return typeof t=="boolean"?{identityLink:t}:null}catch{return null}}function _e(n,e){return we(n.getItem(V(e,oe)))}function Ae(n,e,t){let s=V(e,oe);if(typeof t.identityLink!="boolean"){n.removeItem(s);return}n.setItem(s,JSON.stringify({identityLink:t.identityLink}));}var w=class{constructor(e,t,s,r){this.storage=e;this.shared=t;this.ids=s;this.namespace=r;o(this,"anonymousId");o(this,"distinctId");o(this,"identified");this.refresh();}refresh(){let e=D(this.shared.getItem(this.key("anonymous_id"))),t=D(this.storage.getItem(this.key("anonymous_id")));e?(this.anonymousId=e,t!==e&&this.storage.setItem(this.key("anonymous_id"),e)):t?(this.anonymousId=t,this.shared.setItem(this.key("anonymous_id"),t)):(this.anonymousId=this.ids.uuid(),this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId));let s=D(this.storage.getItem(this.key("distinct_id")));s?(this.distinctId=s,this.identified=true):(this.distinctId=this.anonymousId,this.identified=false);}getAnonymousId(){return this.anonymousId}getDistinctId(){return this.distinctId}isIdentified(){return this.identified}snapshot(){return {anonymousId:this.anonymousId,distinctId:this.distinctId,identified:this.identified}}consent(){return _e(this.shared,this.namespace)}setConsent(e){Ae(this.shared,this.namespace,e);}identify(e){let t=!this.identified||this.distinctId!==e,s=this.storage.getItem(this.key("linked_anonymous_id")),r=t||s!==this.anonymousId;return this.distinctId=e,this.identified=true,t&&this.storage.setItem(this.key("distinct_id"),e),!r||this.consent()?.identityLink===false?{changed:t}:(this.storage.setItem(this.key("linked_anonymous_id"),this.anonymousId),{anonymousToLink:this.anonymousId,changed:t})}reset(){this.anonymousId=this.ids.uuid(),this.distinctId=this.anonymousId,this.identified=false,this.shared.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.setItem(this.key("anonymous_id"),this.anonymousId),this.storage.removeItem(this.key("distinct_id")),this.storage.removeItem(this.key("linked_anonymous_id"));}key(e){return V(this.namespace,e)}};var S=class{constructor(e){o(this,"fetch");o(this,"host");o(this,"projectKey");o(this,"requestTimeoutMs");this.fetch=v(e.fetch),this.host=f(e.host),this.projectKey=e.projectKey,this.requestTimeoutMs=e.requestTimeoutMs??1e4;}async inbox(e){let t=this.requireFetch(),s=`${this.host}/v1/messages?distinct_id=${encodeURIComponent(e)}`,r=await this.request(t,s,{headers:this.authHeaders(),method:"GET"});if(!r.ok)throw new l(`inbox request failed with status ${r.status}`,r.status);return JSON.parse(await r.text()).messages??[]}async markRead(e,t){let s=this.requireFetch(),r=`${this.host}/v1/messages/read`,i=await this.request(s,r,{body:JSON.stringify({distinct_id:t,message_id:e}),headers:{...this.authHeaders(),"content-type":"application/json"},method:"POST"});if(!i.ok)throw new l(`mark-read request failed with status ${i.status}`,i.status)}requireFetch(){if(!this.fetch)throw new l("no fetch implementation available in this runtime");return this.fetch}authHeaders(){return {authorization:`Bearer ${this.projectKey}`}}async request(e,t,s){let r=p(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{return await e(t,{...s,signal:r?.signal})}finally{i!==void 0&&clearTimeout(i);}}};var _=class{constructor(e,t){this.maxSize=e;this.onOverflow=t;o(this,"events",[]);}get size(){return this.events.length}enqueue(e){this.events.push(e),this.enforceCap();}restore(e){this.events.push(...e),this.enforceCap();}requeue(e){this.events.unshift(...e),this.enforceCap();}drain(e){let t=e===void 0?this.events.length:Math.min(e,this.events.length);return this.events.splice(0,t)}snapshot(){return [...this.events]}enforceCap(){if(this.events.length<=this.maxSize)return;let e=this.events.splice(0,this.events.length-this.maxSize);this.onOverflow?.({dropped:e});}};var $e={idleMs:18e5,maxMs:864e5,throttleMs:1e4};function Pe(n){return `pdx.${n}.session`}var A=class{constructor(e,t,s,r,i=$e){this.storage=e;this.ids=t;this.clock=s;this.namespace=r;this.options=i;}current(){return this.touch().id}startedAt(){return this.touch().startedAt}reset(){this.storage.removeItem(this.key());}touch(){let e=this.clock.now().getTime(),t=this.live(this.read(),e);if(t===void 0)return this.write({id:this.ids.uuid(),lastActivityAt:e,startedAt:e});if(e-t.lastActivityAt<=this.options.throttleMs)return t;let s=this.live(this.read(),e),r=s!==void 0&&s.id!==t.id?s:t;return this.write({...r,lastActivityAt:e})}live(e,t){if(e!==void 0&&!(t-e.lastActivityAt>this.options.idleMs||t-e.startedAt>this.options.maxMs))return e}write(e){return this.storage.setItem(this.key(),JSON.stringify(e)),e}read(){let e=this.storage.getItem(this.key());if(e)try{let t=JSON.parse(e);return typeof t.id=="string"&&typeof t.startedAt=="number"&&typeof t.lastActivityAt=="number"?{id:t.id,lastActivityAt:t.lastActivityAt,startedAt:t.startedAt}:void 0}catch{return}}key(){return Pe(this.namespace)}};var c={autocapture:"$autocapture",createAlias:"$create_alias",featureFlagCalled:"$feature_flag_called",group:"$group",identify:"$identify",pageview:"$pageview",screen:"$screen",set:"$set"},ae=[{emittedBy:"web",meaning:"A click anywhere on the page, with the element that was clicked. The web SDK sends it by default; autocapture: false or autocaptureOptions.clicks: false turns it off.",name:c.autocapture,properties:["$event_type","$el_description","$el_description_source","$el_action","$el_tag","$el_text","$el_id","$el_classes","$el_href","$current_url","$pathname","$host","$title","$referrer"]},{emittedBy:"web",meaning:"A page shown, including every client-side navigation the History API makes: one per distinct path and query.",name:c.pageview,properties:["$current_url","$pathname","$host","$title","$referrer"]},{emittedBy:"flutter",meaning:"A named route pushed or replaced in a Flutter app, the mobile counterpart of $pageview.",name:c.screen,properties:["screen"]},{emittedBy:"every",meaning:"A person becomes known by a distinct id. The anonymous trail before it is joined to them, and any traits ride along under $set.",name:c.identify,properties:["$anon_distinct_id","$set"]},{emittedBy:"every",meaning:"A second id for the same person, so events sent under either resolve to one profile.",name:c.createAlias,properties:["alias"]},{emittedBy:"every",meaning:"The person is placed in a group such as a company or a team; group properties ride along under $set.",name:c.group,properties:["$group_type","$group_key","$set"]},{emittedBy:"every",meaning:"Person properties written without an identify: $set overwrites, $set_once fills only what is still empty.",name:c.set,properties:["$set","$set_once"]},{emittedBy:"every",meaning:"A flag was evaluated for this person, sent once per distinct answer. Experiments attribute exposure from it.",name:c.featureFlagCalled,properties:["$feature_flag","$feature_flag_response"]}],Ne=n=>n.startsWith("$"),Re=n=>ae.find(e=>e.name===n);function le(n){return n>=400&&n<500&&n!==429}var I=class{constructor(e={}){o(this,"fetch");o(this,"maxRetries");o(this,"requestTimeoutMs");o(this,"baseDelayMs");o(this,"maxDelayMs");o(this,"sleep");o(this,"random");this.fetch=v(e.fetch),this.maxRetries=e.maxRetries??3,this.requestTimeoutMs=e.requestTimeoutMs??1e4,this.baseDelayMs=e.baseDelayMs??500,this.maxDelayMs=e.maxDelayMs??3e4,this.sleep=e.sleep??G,this.random=e.random??Math.random;}async send(e){let t=this.fetch;if(!t)throw new l("no fetch implementation available in this runtime");let s=JSON.stringify(e.body),r;for(let i=0;i<=this.maxRetries;i+=1){try{let a=await this.attempt(t,e,s);if(a.ok)return;if(le(a.status))throw new l(`ingest rejected batch with status ${a.status}`,a.status);r=new l(`ingest transient status ${a.status}`,a.status);}catch(a){if(a instanceof l&&a.status!==void 0&&le(a.status))throw a;r=a;}i<this.maxRetries&&await this.sleep(this.backoff(i));}throw new l("ingest delivery failed after retries",void 0,{cause:r})}async attempt(e,t,s){let r=p(),i=r?setTimeout(()=>r.abort(),this.requestTimeoutMs):void 0;try{return await e(t.url,{body:s,headers:{authorization:`Bearer ${t.projectKey}`,"content-type":"application/json"},method:"POST",signal:r?.signal})}finally{i!==void 0&&clearTimeout(i);}}backoff(e){return Math.min(this.maxDelayMs,this.baseDelayMs*2**e)+this.random()*this.baseDelayMs}};var Me="queue",Oe=1e3,ce=3e4,j=n=>{let e={};return n.avatar!==void 0&&(e.$avatar=n.avatar),n.email!==void 0&&(e.$email=n.email),n.name!==void 0&&(e.$name=n.name),n.phone!==void 0&&(e.$phone=n.phone),e},$=class{constructor(e){o(this,"config");o(this,"identity");o(this,"session");o(this,"queue");o(this,"transport");o(this,"flagsClient");o(this,"messagesClient");o(this,"context");o(this,"flushTimer");o(this,"flushing",false);o(this,"cachedFlags");o(this,"cachedSnapshot");o(this,"membershipCache");o(this,"stream");o(this,"shutDown",false);o(this,"exposures",new Set);this.config=Y(e),this.identity=new w(this.config.storage,this.config.sharedStorage,this.config.ids,this.config.namespace),this.config.consent!==void 0&&this.identity.setConsent(this.config.consent),this.session=this.config.sessionTracking?new A(this.config.sharedStorage,this.config.ids,this.config.clock,this.config.namespace):void 0,this.queue=new _(this.config.maxQueueSize,({dropped:t})=>{this.config.onError(new u("queue_overflow",`event queue overflow: dropped ${t.length} oldest event(s)`));}),this.transport=this.config.transport??new I({maxRetries:this.config.maxRetries,requestTimeoutMs:this.config.requestTimeoutMs}),this.flagsClient=new x({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.messagesClient=new S({host:this.config.flagsHost,projectKey:this.config.apiKey,requestTimeoutMs:this.config.requestTimeoutMs}),this.context={sdk:this.config.sdkName,sdk_version:this.config.sdkVersion},this.config.os&&(this.context.os=this.config.os),this.config.locale&&(this.context.locale=this.config.locale),this.restoreQueue(),this.startTimer();}get distinctId(){return this.identity.getDistinctId()}get anonymousId(){return this.identity.getAnonymousId()}get isIdentified(){return this.identity.isIdentified()}get sessionId(){return this.session?.current()}get sessionStartedAt(){return this.session?.startedAt()}capture(e,t={}){try{this.identity.refresh();let s={...this.config.defaultProperties(),...t.element===void 0?{}:this.config.describeElement?.(t.element)??{},...t.properties??{}},r=W({context:this.context,distinctId:t.distinctId??this.identity.getDistinctId(),eventName:e,properties:s,sessionId:t.sessionId??this.session?.current(),timestamp:t.timestamp},this.config.clock,this.config.ids);this.enqueue(r);}catch(s){this.config.onError(s);}}identify(e,t={}){this.identity.refresh();let s=this.identity.identify(e),r={};s.anonymousToLink!==void 0&&(r.$anon_distinct_id=s.anonymousToLink);let i={...j(t.traits??{}),...t.set??{}};Object.keys(i).length>0&&(r.$set=i),this.capture(c.identify,{properties:r});}link(e,t,s){let r={$anon_distinct_id:t},i=j(s??{});Object.keys(i).length>0&&(r.$set=i),this.capture(c.identify,{distinctId:e,properties:r});}setConsent(e){this.identity.setConsent(e);}consent(){return this.identity.consent()}alias(e){this.capture(c.createAlias,{properties:{alias:e}});}group(e,t,s){let r={$group_key:t,$group_type:e};s&&(r.$set=s),this.capture(c.group,{properties:r});}setPersonProperties(e,t){let s={};e&&(s.$set=e),t&&(s.$set_once=t),this.capture(c.set,{properties:s});}setPersonTraits(e){let t=j(e);Object.keys(t).length!==0&&this.capture(c.set,{properties:{$set:t}});}async getAllFlags(){let e=this.identity.getDistinctId(),t=await this.flagsClient.fetchDecisions(e);return this.cachedFlags={distinctId:e,flags:t.flags,variants:t.variants??{}},t.flags}async isFeatureEnabled(e){let s=(await this.getAllFlags())[e]??false;return this.recordExposure(e,this.cachedFlags?.variants[e]?.key??String(s)),s}async getVariant(e){let t=await this.getAllFlags(),s=this.cachedFlags?.variants[e]??null;return this.recordExposure(e,s?.key??String(t[e]??false)),s}async getVariantLocal(e,t={}){let s=await this.flagSnapshot(),r=s.flags.find(de=>de.key===e),i=await this.localContext(t,s.flags),a=r?E(r,s.flags,i):null,d=r?b(r,s.flags,i).enabled:false;return this.recordExposure(e,a?.key??String(d)),a?{key:a.key,value:a.value}:null}recordExposure(e,t){let s=`${this.identity.getDistinctId()} ${e} ${t}`;this.exposures.has(s)||(this.exposures.add(s),this.capture(c.featureFlagCalled,{properties:{$feature_flag:e,$feature_flag_response:t}}));}getCachedFlag(e){if(!(!this.cachedFlags||this.cachedFlags.distinctId!==this.distinctId))return this.cachedFlags.flags[e]}async getLocalFlags(e={}){let t=await this.flagSnapshot();return K(t.flags,await this.localContext(e,t.flags))}async isFeatureEnabledLocal(e,t={}){let s=await this.flagSnapshot(),r=s.flags.find(d=>d.key===e),i=await this.localContext(t,s.flags),a=r?b(r,s.flags,i).enabled:false;return this.recordExposure(e,(r?E(r,s.flags,i)?.key:void 0)??String(a)),a}async localContext(e,t){let s=this.identity.getDistinctId(),r=e.cohorts;if(r===void 0&&ne(t)){let i=this.config.clock.now().getTime();this.membershipCache&&this.membershipCache.distinctId===s&&i-this.membershipCache.fetchedAt<ce?r=this.membershipCache.cohorts:(r=await this.flagsClient.memberships(s),this.membershipCache={cohorts:r,distinctId:s,fetchedAt:i});}return {attributes:e.attributes,cohorts:r,distinctId:s,properties:e.properties}}async flagSnapshot(){let e=this.config.clock.now().getTime();if(this.cachedSnapshot&&e-this.cachedSnapshot.fetchedAt<ce)return this.cachedSnapshot.snapshot;let t=await this.flagsClient.snapshot();return this.cachedSnapshot={fetchedAt:e,snapshot:t},this.maybeStream(t),t}maybeStream(e){if(!this.config.streamFlags||this.shutDown||this.stream||!e.socketUrl)return;let t=new T({host:e.socketUrl,onChange:()=>{this.cachedSnapshot=void 0,this.flagSnapshot().catch(s=>this.config.onError(s));},onClosed:s=>{this.stream=void 0,s&&this.maybeStream(e);},projectKey:this.config.apiKey,socketFactory:this.config.socketFactory});this.stream=t,t.open();}async getInbox(){return this.messagesClient.inbox(this.identity.getDistinctId())}async markMessageRead(e){await this.messagesClient.markRead(e,this.identity.getDistinctId());}async flush(){if(this.flushing||this.queue.size===0)return;this.flushing=true;let e=this.queue.drain(Oe);try{await this.transport.send({body:{events:e,sent_at:F(this.config.clock.now())},projectKey:this.config.apiKey,url:`${this.config.host}/v1/events`}),this.persistQueue();}catch(t){this.queue.requeue(e),this.persistQueue(),this.config.onError(t);}finally{this.flushing=false;}}reset(){this.session?.reset(),this.identity.reset(),this.cachedFlags=void 0,this.cachedSnapshot=void 0,this.membershipCache=void 0;}async shutdown(){this.shutDown=true,this.stopTimer(),this.stream?.close(),this.stream=void 0,await this.flush();}enqueue(e){this.queue.enqueue(e),this.persistQueue(),this.queue.size>=this.config.flushAt&&this.flush();}persistQueue(){try{this.config.storage.setItem(this.persistKey(),JSON.stringify(this.queue.snapshot()));}catch(e){this.config.onError(e);}}restoreQueue(){try{let e=this.config.storage.getItem(this.persistKey());if(!e)return;let t=JSON.parse(e);Array.isArray(t)&&this.queue.restore(t);}catch(e){this.config.onError(e);}}startTimer(){if(this.config.flushIntervalMs<=0)return;let e=setInterval(()=>{this.flush();},this.config.flushIntervalMs),t=e;typeof t.unref=="function"&&t.unref(),this.flushTimer=e;}stopTimer(){this.flushTimer!==void 0&&(clearInterval(this.flushTimer),this.flushTimer=void 0);}persistKey(){return `pdx.${this.config.namespace}.${Me}`}};function qe(n){return new $(n)}exports.ConfigError=y;exports.FetchTransport=I;exports.FlagsClient=x;exports.MemoryStorage=k;exports.MessagesClient=S;exports.ProdantixClient=$;exports.ProdantixError=u;exports.SDK_NAME=P;exports.SDK_VERSION=N;exports.SYSTEM_EVENT=c;exports.SYSTEM_EVENTS=ae;exports.TransportError=l;exports.ValidationError=h;exports.assignVariant=Se;exports.bucket=M;exports.createClient=qe;exports.evaluateAll=K;exports.evaluateFlag=xe;exports.getVariant=Ie;exports.isSystemEventName=Ne;exports.matches=R;exports.systemEvent=Re;//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { C as CaptureOptions, I as IdentifyOptions, L as LocalFlagContext, P as ProdantixClient, c as createClient } from './client-
|
|
2
|
-
import { J as JsonValue, F as FlagsResponse, I as InboxMessage, a as StorageAdapter } from './types-
|
|
3
|
-
export { C as Clock, b as Consent, E as EventBatch, c as EventContext, d as EventEnvelope, e as EventProperties, f as FlagVariant, g as IdFactory, h as InboxResponse, P as ProdantixConfig, T as Transport, i as TransportRequest } from './types-
|
|
1
|
+
export { C as CaptureOptions, I as IdentifyOptions, L as LocalFlagContext, P as ProdantixClient, c as createClient } from './client-CL6Xvhay.cjs';
|
|
2
|
+
import { J as JsonValue, F as FlagsResponse, I as InboxMessage, a as StorageAdapter } from './types-Q2VNlJbG.cjs';
|
|
3
|
+
export { C as Clock, b as Consent, E as EventBatch, c as EventContext, d as EventEnvelope, e as EventProperties, f as FlagVariant, g as IdFactory, h as InboxResponse, P as ProdantixConfig, T as Transport, i as TransportRequest } from './types-Q2VNlJbG.cjs';
|
|
4
4
|
import { F as FetchLike } from './http-BCh716Vs.cjs';
|
|
5
|
-
export { F as FetchTransport } from './transport-
|
|
5
|
+
export { F as FetchTransport } from './transport-DN9pXyrX.cjs';
|
|
6
6
|
|
|
7
7
|
type ProdantixErrorCode = 'config' | 'queue_overflow' | 'transport' | 'validation';
|
|
8
8
|
declare class ProdantixError extends Error {
|
|
@@ -144,6 +144,6 @@ declare const isSystemEventName: (name: string) => boolean;
|
|
|
144
144
|
declare const systemEvent: (name: string) => SystemEvent | undefined;
|
|
145
145
|
|
|
146
146
|
declare const SDK_NAME = "prodantix-js";
|
|
147
|
-
declare const SDK_VERSION = "0.0
|
|
147
|
+
declare const SDK_VERSION = "0.7.0";
|
|
148
148
|
|
|
149
149
|
export { ConfigError, type FlagCondition, type FlagDecision, type FlagEvalContext, type FlagOp, type FlagRule, type FlagSnapshot, type FlagVariation, FlagsClient, FlagsResponse, InboxMessage, JsonValue, MemoryStorage, MessagesClient, ProdantixError, type ProdantixErrorCode, SDK_NAME, SDK_VERSION, SYSTEM_EVENT, SYSTEM_EVENTS, StorageAdapter, type SystemEvent, type SystemEventEmitter, type SystemEventName, TransportError, ValidationError, assignVariant, bucket, evaluateAll, evaluateFlag, getVariant, isSystemEventName, matches, systemEvent };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { C as CaptureOptions, I as IdentifyOptions, L as LocalFlagContext, P as ProdantixClient, c as createClient } from './client-
|
|
2
|
-
import { J as JsonValue, F as FlagsResponse, I as InboxMessage, a as StorageAdapter } from './types-
|
|
3
|
-
export { C as Clock, b as Consent, E as EventBatch, c as EventContext, d as EventEnvelope, e as EventProperties, f as FlagVariant, g as IdFactory, h as InboxResponse, P as ProdantixConfig, T as Transport, i as TransportRequest } from './types-
|
|
1
|
+
export { C as CaptureOptions, I as IdentifyOptions, L as LocalFlagContext, P as ProdantixClient, c as createClient } from './client-QyKW0LFW.js';
|
|
2
|
+
import { J as JsonValue, F as FlagsResponse, I as InboxMessage, a as StorageAdapter } from './types-Q2VNlJbG.js';
|
|
3
|
+
export { C as Clock, b as Consent, E as EventBatch, c as EventContext, d as EventEnvelope, e as EventProperties, f as FlagVariant, g as IdFactory, h as InboxResponse, P as ProdantixConfig, T as Transport, i as TransportRequest } from './types-Q2VNlJbG.js';
|
|
4
4
|
import { F as FetchLike } from './http-BCh716Vs.js';
|
|
5
|
-
export { F as FetchTransport } from './transport-
|
|
5
|
+
export { F as FetchTransport } from './transport-DKFvkfX4.js';
|
|
6
6
|
|
|
7
7
|
type ProdantixErrorCode = 'config' | 'queue_overflow' | 'transport' | 'validation';
|
|
8
8
|
declare class ProdantixError extends Error {
|
|
@@ -144,6 +144,6 @@ declare const isSystemEventName: (name: string) => boolean;
|
|
|
144
144
|
declare const systemEvent: (name: string) => SystemEvent | undefined;
|
|
145
145
|
|
|
146
146
|
declare const SDK_NAME = "prodantix-js";
|
|
147
|
-
declare const SDK_VERSION = "0.0
|
|
147
|
+
declare const SDK_VERSION = "0.7.0";
|
|
148
148
|
|
|
149
149
|
export { ConfigError, type FlagCondition, type FlagDecision, type FlagEvalContext, type FlagOp, type FlagRule, type FlagSnapshot, type FlagVariation, FlagsClient, FlagsResponse, InboxMessage, JsonValue, MemoryStorage, MessagesClient, ProdantixError, type ProdantixErrorCode, SDK_NAME, SDK_VERSION, SYSTEM_EVENT, SYSTEM_EVENTS, StorageAdapter, type SystemEvent, type SystemEventEmitter, type SystemEventName, TransportError, ValidationError, assignVariant, bucket, evaluateAll, evaluateFlag, getVariant, isSystemEventName, matches, systemEvent };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{x as FetchTransport,o as FlagsClient,a as MemoryStorage,r as MessagesClient,y as ProdantixClient,f as SDK_NAME,g as SDK_VERSION,t as SYSTEM_EVENT,u as SYSTEM_EVENTS,m as assignVariant,j as bucket,z as createClient,l as evaluateAll,k as evaluateFlag,n as getVariant,v as isSystemEventName,i as matches,w as systemEvent}from'./chunk-
|
|
1
|
+
export{x as FetchTransport,o as FlagsClient,a as MemoryStorage,r as MessagesClient,y as ProdantixClient,f as SDK_NAME,g as SDK_VERSION,t as SYSTEM_EVENT,u as SYSTEM_EVENTS,m as assignVariant,j as bucket,z as createClient,l as evaluateAll,k as evaluateFlag,n as getVariant,v as isSystemEventName,i as matches,w as systemEvent}from'./chunk-D6PMLUYA.js';import'./chunk-V77KYPOF.js';export{b as ConfigError,a as ProdantixError,d as TransportError,c as ValidationError}from'./chunk-ODN4ZELX.js';import'./chunk-5XGN7UAV.js';//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
(function(){'use strict';var f=Object.defineProperty;var u=(t,r)=>{for(var l in r)f(t,l,{get:r[l],enumerable:true});};var x={};u(x,{attachField:()=>k,drawFile:()=>w,filesCss:()=>h,sizeOf:()=>m});var g=".att{display:block;width:180px;margin-bottom:6px;border-radius:8px;overflow:hidden}.att img{display:block;width:100%}.pdfc{display:inline-flex;gap:8px;align-items:center;margin-bottom:6px;padding:6px 8px;border-radius:8px;background:color-mix(in srgb,currentColor 16%,transparent);color:inherit;font-size:12.5px;text-decoration:none;overflow-wrap:anywhere}.pdfc b,.file b{flex:none;display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:4px;font-size:9px;letter-spacing:.04em;background:color-mix(in srgb,currentColor 22%,transparent)}.att:last-child,.pdfc:last-child{margin-bottom:0}";function b(t){let r=t==="round"?14:12;return `.field{position:relative;flex:1;min-width:0;display:flex}.composer .field input{padding-left:${r+26}px}.composer button.clip{position:absolute;top:50%;left:${r-5}px;right:auto;width:28px;min-width:28px;height:28px;padding:0;border-radius:7px;background:none;color:var(--ink-2);transform:translateY(-50%)}.composer button.clip:hover{background:color-mix(in srgb,currentColor 14%,transparent)}.clip svg{display:block;width:18px;height:18px}.file{display:inline-flex;gap:8px;align-items:center;align-self:flex-start;max-width:calc(100% - 20px);margin:0 10px 8px;padding:6px 10px 6px 6px;font-size:12.5px;color:var(--ink);border:1px solid var(--hairline);border-radius:8px}.file .th{flex:none;width:28px;height:28px;border-radius:4px;object-fit:cover}.file .name{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.file .sz,.file .x{flex:none;color:var(--ink-3)}.file .x{margin-left:4px;padding:0;border:0;background:none;font:inherit;font-size:16px;line-height:1;cursor:pointer}.ferr{margin:0 10px 6px;font-size:12px;color:oklch(60% 0.2 27)}`}var h=(t,r)=>`${g}${t?b(r):""}`;function m(t){return t<999500?`${Math.max(1,Math.round(t/1e3))} KB`:`${(t/1e6).toFixed(1)} MB`}var v='<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m16.5 6.5-7.8 7.8a2.1 2.1 0 0 0 3 3l8.1-8.1a4.2 4.2 0 0 0-6-6L5.7 11.3a6.3 6.3 0 0 0 8.9 8.9l6.6-6.6"/></svg>';function k(t,r,l,c,o){let s=document.createElement("span");s.className="field";let e=document.createElement("input");e.type="file",e.accept=o.accept.join(","),e.hidden=true,e.addEventListener("change",()=>{var p;let i=(p=e.files)==null?void 0:p[0];e.value="",i&&E(t,c,r,o,i);});let n=document.createElement("button");n.type="button",n.className="clip",n.setAttribute("aria-label",t.attachLabel),n.innerHTML=v,n.addEventListener("click",()=>e.click()),l.replaceWith(s),s.append(n,l,e);}function E(t,r,l,c,o){let s=o.size>c.maxBytes||!c.accept.includes(o.type);for(let a of t.root.querySelectorAll(s?".ferr":".file,.ferr"))a.remove();if(s){let a=document.createElement("p");a.className="ferr",a.setAttribute("role","alert"),a.textContent=t.fileRefusal(m(o.size),`${c.maxBytes/1e6} MB`),l.before(a),r.scrollTop=r.scrollHeight;return}t.hold(o);let e=document.createElement("span");e.className="file";let n;if(o.type==="application/pdf")n=document.createElement("b"),n.textContent="PDF";else {let a=document.createElement("img");a.className="th",a.alt="",a.src=t.objectUrl(o),n=a;}let i=document.createElement("span");i.className="name",i.textContent=o.name;let p=document.createElement("span");p.className="sz",p.textContent=`\xB7 ${m(o.size)}`;let d=document.createElement("button");d.type="button",d.className="x",d.setAttribute("aria-label",t.removeFileLabel),d.textContent="\xD7",d.addEventListener("click",()=>{t.hold(null),e.remove();}),e.append(n,i,p,d),l.before(e),r.scrollTop=r.scrollHeight;}function w(t,r,l,c,o,s){let e=document.createElement("a");if(l==="application/pdf"){e.className="pdfc",e.download=r;let n=document.createElement("b");n.textContent="PDF",e.append(n,`${r} \xB7 ${m(c)}`);}else {e.className="att",e.target="_blank",e.rel="noopener noreferrer";let n=document.createElement("img");n.alt=r,n.addEventListener("load",()=>{let i=e.closest(".log");i&&(i.scrollTop=i.scrollHeight);}),e.append(n);}t.append(e),o.then(n=>{var i;n&&(e.href=s(n),(i=e.querySelector("img"))==null||i.setAttribute("src",e.href));});}window.prodantixMessengerFiles=x;})();//# sourceMappingURL=messenger-files.iife.js.map
|
|
2
|
+
//# sourceMappingURL=messenger-files.iife.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
(function(){'use strict';var Y=Object.defineProperty;var W=(e,n)=>{for(var t in n)Y(e,t,{get:n[t],enumerable:true});};var M={};W(M,{HELP_CSS:()=>X,SEARCH_PAUSE_MS:()=>q,SUGGESTED:()=>I,TYPED_MINIMUM:()=>D,articleRows:()=>g,collectionRows:()=>R,emptyRows:()=>w,firstView:()=>te,frameAddress:()=>G,helpReads:()=>V,helpTab:()=>ne,helpTabs:()=>N,hostOf:()=>Z,isReadable:()=>H,paused:()=>k,reader:()=>U,searchBox:()=>L,setHelping:()=>A,showArticle:()=>y,suggestions:()=>_,whileTyping:()=>oe});var q=300,D=3,I=3,f=e=>`<svg viewBox="0 0 24 24" aria-hidden="true"><path d="${e}"/></svg>`,O=f("M15.5 14h-.79l-.28-.27A6.47 6.47 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"),B=f("M10 6 8.59 7.41 13.17 12l-4.58 4.59L10 18l6-6z"),$=f("M14 2H6c-1.1 0-2 .9-2 2v16c0 1.1.89 2 1.99 2H18c1.1 0 2-.9 2-2V8l-6-6zm2 16H8v-2h8v2zm0-4H8v-2h8v2zm-3-5V3.5L18.5 9H13z"),j=f("M20 2H4c-1.1 0-2 .9-2 2v18l4-4h14c1.1 0 2-.9 2-2V4c0-1.1-.9-2-2-2zm0 14H6l-2 2V4h16v12z"),K=f("M11 18h2v-2h-2v2zm1-16C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8zm0-14c-2.21 0-4 1.79-4 4h2c0-1.1.9-2 2-2s2 .9 2 2c0 2-3 1.75-3 5h2c0-2.25 3-2.5 3-5 0-2.21-1.79-4-4-4z"),F=f("M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"),J=f("M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z"),Q=f("M15.88 9.29 12 13.17 8.12 9.29a.996.996 0 0 0-1.41 0c-.39.39-.39 1.02 0 1.41l4.59 4.59c.39.39 1.02.39 1.41 0l4.59-4.59c.39-.39.39-1.02 0-1.41-.39-.38-1.03-.39-1.42 0"),X='[hidden]{display:none!important}.hsearch{display:flex;align-items:center;gap:8px;height:40px;padding:0 12px;color:var(--ink-3);border:1px solid var(--hairline);border-radius:10px}.hsearch:focus-within{border-color:var(--a);box-shadow:0 0 0 3px color-mix(in srgb,var(--a) 20%,transparent)}.hsearch input{flex:1;min-width:0;height:100%;padding:0;border:0;outline:0;background:none;font:inherit;font-size:14px;color:var(--ink)}.hsearch input::placeholder{color:var(--ink-3)}.hsearch svg,.hrow svg{display:block;flex:none;width:16px;height:16px;fill:currentColor}.hlabel{margin:6px 0 0;font-size:12px;font-weight:600;color:var(--ink-3)}.hrows{display:flex;flex-direction:column}.hrow{display:flex;align-items:center;gap:10px;width:100%;padding:10px 2px;font:inherit;font-size:14px;color:var(--ink);text-align:left;background:none;border:0;border-bottom:1px solid var(--hairline);cursor:pointer}.hrow span{flex:1;min-width:0}.hrow small{font-size:12px;color:var(--ink-3)}.hrow svg{color:var(--ink-3)}.hrow:focus-visible{outline:2px solid var(--a);outline-offset:-2px}.hnone{margin:0;padding:10px 2px;font-size:13.5px;color:var(--ink-2)}.hview{flex:1;min-height:0;overflow-y:auto;display:flex;flex-direction:column;gap:10px;padding:16px}.htabs{display:grid;grid-template-columns:1fr 1fr;border-top:1px solid var(--hairline)}.htab{display:flex;flex-direction:column;align-items:center;gap:2px;padding:8px 0 10px;font:inherit;font-size:11.5px;font-weight:550;color:var(--ink-3);background:none;border:0;cursor:pointer}.htab[aria-selected="true"]{color:var(--a)}.htab svg{display:block;width:22px;height:22px;fill:currentColor}.htab:focus-visible{outline:2px solid var(--a);outline-offset:-2px}.hsugg{margin:0 10px 8px;padding:10px 12px 4px;border:1px solid var(--hairline);border-radius:10px}.hsugg p{margin:0 0 4px;font-size:12px;font-weight:600;color:var(--ink-3)}.hsugg .hrow{padding:8px 0;font-size:13.5px}.hsugg .hrow:last-child{border-bottom:0}.hreader{flex:1;min-height:0;display:flex;flex-direction:column}.hbar{flex:none;display:flex;align-items:center;gap:6px;height:52px;padding:0 8px;border-bottom:1px solid var(--hairline)}.hbar b{flex:1;min-width:0;font-size:14px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.hbtn{display:grid;place-items:center;flex:none;width:32px;height:32px;padding:0;border:0;border-radius:8px;background:none;color:var(--ink);cursor:pointer}.hbtn svg{display:block;width:20px;height:20px;fill:currentColor}.hbtn:hover{background:color-mix(in srgb,currentColor 14%,transparent)}.hbtn:focus-visible{outline:2px solid var(--a)}.hreader iframe{flex:1;min-height:0;width:100%;border:0}.hblocked{flex:1;display:flex;flex-direction:column;gap:8px;padding:20px 18px}.hblocked h3{margin:0;font-size:18px;font-weight:640;letter-spacing:-.015em}.hblocked a{font-size:14px;color:var(--ink);text-decoration:underline}.hmore{flex:none;display:flex;align-items:center;justify-content:space-between;gap:10px;margin:6px 18px 16px;padding:12px 14px;font-size:13.5px;background:var(--fill);border-radius:10px}.hmore button{padding:7px 14px;font:inherit;font-size:13px;font-weight:600;color:#fff;white-space:nowrap;background:var(--a);border:0;border-radius:8px;cursor:pointer}.hmore button:focus-visible{outline:2px solid var(--ink);outline-offset:2px}.hrow,.htab,.hmore,.hlabel,.hnone,.hsugg p{line-height:1.45}';function L(e,n){let t=document.createElement("label");t.className="hsearch",t.innerHTML=O;let o=document.createElement("input");o.type="search",o.placeholder=e.searchPlaceholder,o.setAttribute("aria-label",e.searchPlaceholder);let i=k(n);return o.addEventListener("input",()=>i(o.value.trim())),t.append(o),t}function k(e){let n;return t=>{clearTimeout(n),n=setTimeout(()=>e(t),300);}}var P=/^https?:\/\//i,H=e=>P.test(e.url)&&P.test(e.embedUrl);function g(e,n,t,o){e.replaceChildren();let i=n.filter(H);if(i.length===0&&t!==null){let r=document.createElement("p");r.className="hnone",r.textContent=t,e.append(r);}for(let r of i){let c=document.createElement("button");c.type="button",c.className="hrow",c.innerHTML=$;let l=document.createElement("span");l.textContent=r.title,c.append(l),c.addEventListener("click",()=>o(r)),e.append(c);}return e}function R(e,n,t){e.replaceChildren();for(let o of n){let i=document.createElement("button");i.type="button",i.className="hrow";let r=document.createElement("span");r.textContent=o.title;let c=document.createElement("small");c.textContent=String(o.articles),i.append(r,c),i.insertAdjacentHTML("beforeend",B),i.addEventListener("click",()=>t(o)),e.append(i);}return e}function w(){let e=document.createElement("div");return e.className="hrows",e}function N(e,n){let t=document.createElement("div");t.className="htabs",t.setAttribute("role","tablist");let o=(i,r,c)=>{let l=document.createElement("button");return l.type="button",l.className="htab",l.setAttribute("role","tab"),l.setAttribute("aria-selected",String(!c)),l.innerHTML=r,l.append(i),l.addEventListener("click",()=>n(c)),l};return t.append(o(e.messagesTab,j,false),o(e.helpTab,K,true)),t}function _(e,n,t){let o=document.createElement("div");o.className="hsugg";let i=document.createElement("p");return i.textContent=e.mightHelp,o.append(i,...g(w(),n.filter(H).slice(0,3),null,t).children),o}function G(e,n){return `${e}${e.includes("?")?"&":"?"}scheme=${n}`}function U(e,n,t,o,i){var C;let r=document.createElement("section");r.className="hreader";let c=document.createElement("div");c.className="hbar";let l=(E,S,b)=>{let h=document.createElement("button");return h.type="button",h.className="hbtn",h.setAttribute("aria-label",E),h.title=E,h.innerHTML=S,h.addEventListener("click",b),h},u=document.createElement("b");u.textContent=(C=e.trail.at(-1))!=null?C:e.title;let s=document.createElement("a");s.className="hbtn",s.href=e.url,s.target="_blank",s.rel="noopener noreferrer",s.setAttribute("aria-label",n.openOnSite),s.title=n.openOnSite,s.innerHTML=J,c.append(l(n.back,F,i.back),u,s,l(t,Q,i.close));let d=document.createElement("iframe");d.title=e.title,d.setAttribute("sandbox","allow-popups allow-popups-to-escape-sandbox"),d.setAttribute("referrerpolicy","no-referrer"),d.setAttribute("src",G(e.embedUrl,o));let x=document.createElement("div");x.className="hmore";let a=document.createElement("span");a.textContent=n.stillNeedHelp;let p=document.createElement("button");p.type="button",p.textContent=n.messageUs,p.addEventListener("click",i.messageUs),x.append(a,p),r.append(c,d,x);let m=new URL(e.embedUrl).origin,T=E=>{var z;if(!r.isConnected){document.removeEventListener("securitypolicyviolation",T);return}if(!((z=E.blockedURI)!=null?z:"").startsWith(m)||!d.isConnected)return;let b=document.createElement("div");b.className="hblocked";let h=document.createElement("h3");h.textContent=e.title;let v=document.createElement("a");v.href=e.url,v.target="_blank",v.rel="noopener noreferrer",v.textContent=n.readOnSite,b.append(h,v),d.replaceWith(b);};return document.addEventListener("securitypolicyviolation",T),r}function V(e){let n=async(t,o="")=>{var i,r;return (r=(i=await e(o,t))==null?void 0:i.articles)!=null?r:[]};return {articles:t=>n({q:t}),collectionArticles:t=>n({collection:t}),collections:async()=>{var t,o;return (o=(t=await e("/collections",{}))==null?void 0:t.collections)!=null?o:[]},popularArticles:()=>n({},"/popular")}}function Z(e,n){let t=e.helpCentre?V(e.helpCentre.bind(e)):e;return t.articles&&t.popularArticles?{...n,source:t}:null}var ee=e=>{var n;return e==="dark"||e==="light"?e:(n=globalThis.matchMedia)!=null&&n.call(globalThis,"(prefers-color-scheme: dark)").matches?"dark":"light"};function A(e,n){e.classList.toggle("helping",n);for(let t of e.children)!(t instanceof HTMLElement)||t.matches(".header, .away, .htabs, .hreader")||(t.hidden=t.classList.contains("hview")?!n:n);e.querySelectorAll(".htab").forEach((t,o)=>t.setAttribute("aria-selected",String(o===1?n:!n)));}function y(e,n){var c;let{panel:t}=e,o=[...t.children].filter(l=>l instanceof HTMLElement&&!l.hidden),i=()=>{r.remove();for(let l of o)l.hidden=false;},r=U(n,e.words,e.closeLabel,ee(e.scheme),{back:i,close:e.close,messageUs:()=>{var l;i(),t.querySelector(".htabs")&&A(t,false),(l=t.querySelector('.composer input:not([type="file"])'))==null||l.focus();}});for(let l of o)l.hidden=true;t.append(r),(c=r.querySelector("button"))==null||c.focus();}function te(e,n){let t=w(),o=r=>y(e,r),i=async()=>{var r,c,l;g(t,((l=await((c=(r=e.source).popularArticles)==null?void 0:c.call(r)))!=null?l:[]).filter(H).slice(0,3),null,o);};n.append(L(e.words,async r=>{var c,l,u;if(!r)return i();g(t,(u=await((l=(c=e.source).articles)==null?void 0:l.call(c,r)))!=null?u:[],e.words.noMatches,o);}),t),i();}function ne(e){let{panel:n,source:t,words:o}=e,i=document.createElement("div");i.className="hview",i.hidden=true;let r=document.createElement("p");r.className="hlabel";let c=w(),l=a=>y(e,a),u=async a=>{var p,m;r.textContent=a.title,g(c,(m=await((p=t.collectionArticles)==null?void 0:p.call(t,a.title)))!=null?m:[],o.noMatches,l);},s=async()=>{var a,p;r.hidden=false,r.textContent=o.collections,R(c,(p=await((a=t.collections)==null?void 0:a.call(t)))!=null?p:[],m=>void u(m));};i.append(L(o,async a=>{var p,m;if(!a)return s();r.hidden=true,g(c,(m=await((p=t.articles)==null?void 0:p.call(t,a)))!=null?m:[],o.noMatches,l);}),r,c);let d=false,x=N(o,a=>{A(n,a),a&&!d&&(d=true,s());});n.append(i,x);}function oe(e,n,t){let o=k(async i=>{var c,l,u,s,d;if((c=e.panel.querySelector(".hsugg"))==null||c.remove(),i.length<3)return;let r=((s=await((u=(l=e.source).articles)==null?void 0:u.call(l,i)))!=null?s:[]).filter(H);n.value.trim()!==i||r.length===0||((d=e.panel.querySelector(".hsugg"))==null||d.remove(),t.before(_(e.words,r,x=>y(e,x))));});n.addEventListener("input",()=>o(n.value.trim()));}window.prodantixMessengerHelp=M;
|
|
2
|
+
})();//# sourceMappingURL=messenger-help.iife.js.map
|
|
3
|
+
//# sourceMappingURL=messenger-help.iife.js.map
|
package/dist/messenger.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var f=Object.defineProperty;var d=(e,t,r)=>t in e?f(e,t,{enumerable:true,configurable:true,writable:true,value:r}):e[t]=r;var c=(e,t,r)=>d(e,typeof t!="symbol"?t+"":t,r);var l=class extends Error{constructor(r,n,o){super(n,o);c(this,"code");this.code=r,this.name="ProdantixError";}};var i=class extends l{constructor(r,n,o){super("transport",r,o);c(this,"status");this.status=n,this.name="TransportError";}};function g(e){if(e)return e;let t=globalThis.fetch;if(typeof t=="function")return t.bind(globalThis)}function p(e){return e.replace(/\/+$/,"")}var h="prodantix.messenger.config",E=e=>{let t=e.navigator?.languages;return Array.isArray(t)&&t.length>0?t.join(","):e.navigator?.language||e.document?.documentElement?.lang||void 0},u=(e,t)=>`${h}:${e}:${t??""}`;function k(e,t,r){let n=e?.get(u(t,r));if(!n)return null;try{let o=JSON.parse(n);return o?.apiKey===t?o.config:null}catch{return null}}async function v(e){let t=g(e.fetchImpl);if(!t)return e.onError?.(new i("no fetch available for the prodantix messenger")),null;let r=p(e.host),n=u(e.apiKey,e.locale),o=e.locale?`?locale=${encodeURIComponent(e.locale)}`:"";try{let s=await t(`${r}/v1/messenger/config${o}`,{headers:{authorization:`Bearer ${e.apiKey}`},method:"GET"});if(!s.ok)return e.onError?.(new i(`prodantix messenger config: ${s.status}`,s.status)),null;let a=JSON.parse(await s.text());return a.enabled?(e.storage?.set(n,JSON.stringify({apiKey:e.apiKey,config:a})),a):(e.storage?.remove(n),a)}catch(s){return e.onError?.(s),null}}exports.MESSENGER_CACHE_KEY=h;exports.cacheKeyFor=u;exports.cachedMessengerConfig=k;exports.fetchMessengerConfig=v;exports.localeCandidates=E;//# sourceMappingURL=messenger.cjs.map
|
|
2
2
|
//# sourceMappingURL=messenger.cjs.map
|
package/dist/messenger.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { H as HelpWords, t as MESSENGER_CACHE_KEY, M as MessengerAttachments, e as MessengerConfig, u as MessengerConfigOptions, v as MessengerHelp, w as StarterPrompt, x as cacheKeyFor, y as cachedMessengerConfig, z as fetchMessengerConfig, E as localeCandidates } from './config-g14Jiv1t.cjs';
|
|
2
2
|
import './http-BCh716Vs.cjs';
|
package/dist/messenger.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { H as HelpWords, t as MESSENGER_CACHE_KEY, M as MessengerAttachments, e as MessengerConfig, u as MessengerConfigOptions, v as MessengerHelp, w as StarterPrompt, x as cacheKeyFor, y as cachedMessengerConfig, z as fetchMessengerConfig, E as localeCandidates } from './config-6ulvfBFp.js';
|
|
2
2
|
import './http-BCh716Vs.js';
|